fcomment.awk - randomcrap - random crap programs of varying quality
(HTM) git clone git://git.codemadness.org/randomcrap
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
fcomment.awk (1205B)
---
1 # grep C-style functions and check if it has a comment.
2
3 BEGIN {
4 siz = 5; # ringbuffer size
5 }
6 {
7 head = i % siz;
8 }
9 # index to ringbuffer position.
10 function iter(p) {
11 if (p < 0 || p < siz)
12 return -1;
13 return p % siz;
14 }
15 # function definition, but not a function prototype declaration.
16 /^[^ ]+\(/ && ! /;/ {
17 fn = 1;
18 name = $0;
19 next;
20 }
21 #function showline(s) {
22 # print "// " s;
23 #}
24 fn {
25 # find end of function, look in reverse direction.
26 end = 0;
27 for (j = siz; j >= 0; j--) {
28 if ((pos = iter(j + i - 1)) != -1) {
29 # showline(b[pos]);
30 if (b[pos] == "}") {
31 end = j + 1;
32 break;
33 }
34 }
35 }
36
37 # header of function.
38 hascomment = 0;
39 for (j = end; j < siz; j++) {
40 pos = iter(j + i);
41 if (pos != -1) {
42 # non-foolproof check if it has a comment
43 if (index(b[pos], "//"))
44 hascomment = 1;
45 else if (index(b[pos], "/*"))
46 hascomment = 1;
47 else if (index(b[pos], "*/"))
48 hascomment = 1;
49 # showline(b[pos]);
50 }
51 }
52 print hascomment " " name;
53 fn = 0;
54
55 # ringbuffer head: was full print previous
56 #if (i >= siz) {
57 # for (j = head; j < siz; j++)
58 # showline(b[j]);
59 #}
60 # ringbuffer tail
61 #for (j = 0; j < head; j++)
62 # showline(b[j]);
63 }
64 {
65 fn = 0;
66 b[head] = $0;
67 i++;
68 }