Debian Codegraph @

testsuite/systemtap.unprivileged/embeddedc.awk

raw
1 #!/bin/awk -f
2
3 BEGIN {
4 isfunc = 0
5 block = 0
6 embedded = 0
7 }
8
9 # print the function prototype, all on one line.
10 /^function/ {
11 if (block != 0 || embedded != 0) {
12 printf "Unterminated block at: %s: %d %d\n",$0,block,embedded > "/dev/stderr"
13 exit 1
14 }
15 isfunc = 1
16 unprivileged = -1
17 myproc_unprivileged = -1
18 }
19
20 /^function/,/\)/ {
21 # Strip characters after the ')'.
22 temp = $0
23 sub("\\).*", ")", temp)
24 # print "after stripping trailing chars: " temp
25
26 # Strip the the return type.
27 temp = gensub("^function[[:space:]]*([\\$_[:alpha:]][\\$_[:alnum:]]*)[[:space:]]*:[[:space:]]*[[:alpha:]]*",
28 "function \\1", 1, temp)
29 # print "after stripping return type: " temp
30
31 # Strip the 'function'.
32 temp = gensub("^function[[:space:]]*", "", 1, temp)
33 # print "after stripping function: " temp
34
35 # Add the default type where it has been omitted.
36 do {
37 temp1 = temp
38 temp = gensub("([(,][[:space:]]*[\\$_[:alpha:]][\\$_[:alnum:]]*)[[:space:]]*([,)])",
39 "\\1:long\\2", "g", temp)
40 # print "after adding a default type: " temp
41 } while (temp != temp1)
42
43 # Strip paramater names.
44 temp = gensub("[\\$_[:alpha:]][\\$_[:alnum:]]*[[:space:]]*:[[:space:]]*([[:alpha:]])",
45 "\\1", "g", temp)
46 # print "after stripping parm names: "
47
48 printf "%s",temp
49 fflush()
50 }
51
52 # Beginning of a preprocessor block
53 (! /^.*\/\/.*%\(/) && /%\(/ {
54 if (isfunc)
55 block += 1
56 # printf "%s",$0
57 # print ": preprocessor start:" block " " embedded
58 }
59
60 # Beginning of an embedded C block
61 (! /^.*\/\/.*%{/) && /%{/ {
62 block += 1
63 embedded += 1
64 # printf "%s",$0
65 # print ": embedded start:" block " " embedded
66 }
67
68 # Beginning of a code block
69 /^{/ {
70 block += 1
71 # printf "%s",$0
72 # print ": block start:" block " " embedded
73 }
74 (! /^.*\/\/.*{/) && (! /[^%]{.*[^%]{/) && /[^%]{/ {
75 block += 1
76 # printf "%s",$0
77 # print ": block start:" block " " embedded
78 }
79 (! /^.*\/\/.*{/) && /[^%]{.*[^%]{/ {
80 block += 2
81 # printf "%s",$0
82 # print ": block start:" block " " embedded
83 }
84
85 # unprivileged?
86 /\/\* unprivileged \*\// {
87 if (embedded && unprivileged != 0)
88 unprivileged = 1
89 }
90 /\/\* myproc-unprivileged \*\// {
91 if (embedded && myproc_unprivileged != 0)
92 myproc_unprivileged = 1
93 }
94
95 # Process the end of a tapset function.
96 function finish_function() {
97 if (block == 0 && isfunc) {
98 if (unprivileged == 1)
99 print ";unprivileged"
100 else if (myproc_unprivileged == 1)
101 print ";myproc-unprivileged"
102 else if (unprivileged != -1 || myproc_unprivileged != -1)
103 print ";privileged"
104 else
105 print ";no embedded C"
106 fflush()
107 isfunc = 0
108 }
109 }
110
111 # End of a preprocessor C block
112 (! /^.*\/\/.*%\)/) && /%\)/ {
113 if (isfunc)
114 block -= 1
115 # printf "%s",$0
116 # print ": embedded end:" block " " embedded
117 finish_function()
118 }
119
120 # End of an embedded C block
121 (! /^.*\/\/.*%}/) && /%}/ {
122 embedded -= 1
123 block -= 1
124 if (unprivileged == -1)
125 unprivileged = 0
126 if (myproc_unprivileged == -1)
127 myproc_unprivileged = 0
128 # printf "%s",$0
129 # print ": embedded end:" block " " embedded
130 finish_function()
131 }
132
133 # End of a code block
134 /^}/ {
135 block -= 1
136 # printf "%s",$0
137 # print ": block end:" block " " embedded
138 finish_function()
139 }
140 (! /^.*\/\/.*}/) && (! /[^%]}.*[^%]}/) && /[^%]}/ {
141 block -= 1
142 # printf "%s",$0
143 # print ": block end:" block " " embedded
144 finish_function()
145 }
146 (! /^.*\/\/.*}/) && /[^%]}.*[^%]}/ {
147 block -= 2
148 # printf "%s",$0
149 # print ": block end:" block " " embedded
150 finish_function()
151 }
152
153 END {
154 if (block != 0 || embedded != 0) {
155 printf "Unterminated block at EOF: %d %d\n",block,embedded > "/dev/stderr"
156 exit 1
157 }
158 }