-
Notifications
You must be signed in to change notification settings - Fork 0
/
scr.sh
executable file
·165 lines (140 loc) · 3.34 KB
/
scr.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/sh
#fxme identifier surned by spaces!needle
#fxme unsafe lookahed may find comments - actually safe
#fxme nf index?
awk -F "" '
BEGIN {kwd=0; multiline_comment=0; singleline_comment=0;
ident_wanted = 0; ident = ""; ident_len = 0;
terminate_ctor = 0; terminate_ctor_left_paren = 0;
terminate_paren_right_paren = 0; internal_counter=0;
ns_kwd = 0; parse_ident = 0;}
{
for (i=1;i<=NF;i++)
{
# comments processing block
if (i == 1) {singleline_comment = 0}
if ($i$(i+1) == "//") {singleline_comment=1;}
if ($i$(i+1) == "/*") {multiline_comment=1;}
if ($i$(i+1) == "*/") {multiline_comment=0; i++; printf "*/"; continue;}
if (multiline_comment == 1 || singleline_comment == 1) {printf "%s", $i; continue;}
# keywords processing
if ($i$(i+1)$(i+2)$(i+3)$(i+4) == "class")
{
printf "%s", $i$(i+1)$(i+2)$(i+3)$(i+4);
kwd=1; i = i + 4; ns_kwd = 0; parse_ident = 1;
continue;
}
if (parse_ident == 1)
{
j = i;
while ($j == " " && j <= NF)
{
printf " ";
j++;
}
while ($(j) != " " && $(j) != "{" && $(j) != ";" && j <= NF)
{
ident = ident$j;
j++;
ident_len++;
}
printf "%s", ident
if (ident != "" && ident_len > 0) {parse_ident = 0;}
# so that next cycle starts from
# the ; or { or [[:blank:]]
i = j - 1;
continue;
}
if ($i$(i+1)$(i+2)$(i+3)$(i+4)$(i+5)$(i+6)$(i+7)$(i+8) == "namespace")
{
printf "%s", $i$(i+1)$(i+2)$(i+3)$(i+4)$(i+5)$(i+6)$(i+7)$(i+8);
kwd=1; i = i + 8;
ns_kwd = 1;
continue;
}
#this part does not havetogiveidentifiertheremaybenone
if (ident_wanted == 1)
{
# printf "[want %s]", ident;
needle = "";
for (j = i; j <= NF && j < i + ident_len; j++)
{
needle = needle$j;
}
# printf "/NEEDlE_%s_", needle;
if (needle == ident)
{
# todo maybe indexing error?
j = i + ident_len - 1;
ident = "";
ident_len = 0;
ident_wanted = 0;
terminate_ctor_left_par = 1;
}
if ($i == "{") {internal_counter++;}
if ($i == "}") {internal_counter--;}
printf "%s", $i;
# printf "%sIW", $i;
# printf "%d", count;
if (internal_counter == 0)
{
ident_wanted = 0;
count = 0;
ident = "";
ident_len = 0;
}
continue;
}
if (terminate_ctor_left_par)
{
if ($i == "(")
{
terminate_ctor_left_par = 0;
terminate_ctor_right_par = 1;
}
printf "%s", $i;
# printf "%sLP", $i;
continue;
}
if (terminate_ctor_right_par)
{
if ($i == ")")
{
terminate_ctor_right_par = 0;
terminate_ctor = 1;
}
printf "%s", $i;
# printf "%sRP", $i;
continue;
}
# final step of ctor logging
if (terminate_ctor == 1)
{
if ($i == "{") {$i="{ PROCESSED CTOR;"; terminate_ctor = 0;}
if ($i == ";") {terminate_ctor = 0;}
printf "%s", $i;
# printf "%sTT", $i;
continue;
}
# either dealing with declaration or with
# the beginning of definition; silently handle
# this case and continue with next characters;
if (($i == ";" || $i == "{") && kwd == 1)
{
if ($i == "{" && ns_kwd == 0) {count++; ident_wanted = 1; internal_counter = 1;}
kwd=0
printf "%s", $i
# printf "%sCM", $i
continue
}
# printf "!!%d", count
# if we reached these lines, we can safely filter
# brackets, it means application logic has been
# satisfied
if ($i == "}" && count > 0) {count--}
if ($i == "{" ) if (count++ == 0) {$i="{ PROCESSED;"}
printf "%s", $i
}
printf "%s", ORS
}
'