-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathh264.awk
executable file
·139 lines (115 loc) · 3.05 KB
/
h264.awk
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
#!/usr/bin/awk -f
BEGIN {
in_function=0;
function_name="";
}
/[_a-z]+[[:space:]]*(.*)[[:space:]]*{[[:space:]]*C[[:space:]]*Descriptor/ {
#name=$0;
#sub("\\(.*$", "", name);
#print "function name: ", name;
indented=0;
line=$0;
indented += gsub("{", "{", line);
indented -= gsub("}", "}", line);
sub("[[:space:]]*C[[:space:]]*Descriptor$", "");
sub("^[[:space:]]+", "");
gsub("[[:space:]]+", " ");
print $0;
indent_tmp=0;
while (getline)
{
# remove initial space
sub("^[[:space:]]+", "");
# remove page seperator
sub("--.+---$", "");
if ($0 == "© ISO/IEC 2004 – All rights reserved")
{
do
{
if (!getline)
break;
sub("^[[:space:]]+", "");
#print $0;
}
while ($0 != "ISO/IEC 14496-10:2004(E)");
continue;
}
if (sub("^Copyright International Organization", ""))
{
do
{
if (!getline)
break;
sub("^[[:space:]]+", "");
#print $0;
}
while ($0 != "Reproduced by IHS under license with ISO" &&
$0 != "ISO/IEC 14496-10:2004(E)");
continue;
}
# remove empty line
if ($0 == "")
continue;
# remove single line comment
gsub("\\/\\*.*\\*\\/", "");
# reduce space
gsub("[[:space:]]+", " ");
gsub("\\[ ", "[");
gsub(" \\]", "]");
gsub("\\( ", "(");
gsub(" \\)", ")");
gsub(", ", ",");
gsub(" \\| ", "|");
gsub(" \\+ ", "+");
gsub(" \\* ", "*");
gsub("\\| \\|", "||");
gsub("= =", "==");
gsub("–", "-");
line=$0;
# bits description
# in vim,
# /[_a-zA-Z0-9]\+\(\[.\+\]\)*\( \(All\|\d\(|\d\)*\)\)\? \(ae\|b\|ce\|f\|i\|me\|se\|te\|u\|ue\)(\(\d\+\|v\))\(|\(ae\|b\|ce\|f\|i\|me\|se\|te\|u\|ue\)(\(\d\+\|v\))\)*
# function call with category
# /[_a-zA-Z0-9]\+(\([_a-zA-Z0-9]\+\(\[[^\]]\+\]\)*\(,[_a-zA-z0-9]\+\(\[[^\]]\+\]\)*\)*\)\?) \(All\|\d\(|\d\)*\)
tmp=line;
bits_desc = sub("^[_a-zA-Z0-9]+(\\[[^\\]]+\\])*( (All|([[:digit:]](\\|[[:digit:]])*)))? (ae|b|ce|f|i|me|se|te|u|ue)\\(([[:digit:]]+|v)\\)(\\|(ae|b|ce|f|i|me|se|te|u|ue)\\(([[:digit:]]+|v)\\))*", "", tmp);
func_c = sub("^[_a-zA-Z0-9]+\\(([_a-zA-Z0-9]+(\\[[^\\]]+\\])*(,[_a-zA-z0-9]+(\\[[^\\]]+\\])*)*)?\\) (All|[[:digit:]](|[[:digit:]])*)", "", tmp);
indent_minus = gsub("}", "}", line);
indent_plus = gsub("{", "{", line);
if (indent_plus>0)
indent_tmp=0;
indented -= indent_minus;
for (a=0; a<indented+indent_tmp; a++)
printf "\t";
if (bits_desc > 0)
{
desc=line;
sub("^[_a-zA-Z0-9]+(\\[[^\\]]+\\])*", "&,", desc);
if (sub(" (All|([[:digit:]](\\|[[:digit:]])*))", "&,", desc) == 0)
# without category
sub(", ", ", All, ", desc);
# with category
printf "h264_bitsdesc (";
printf desc;
printf ")\n";
}
else if (func_c > 0)
{
desc=line;
sub("^[_a-zA-Z0-9]+\\(([_a-zA-Z0-9]+(\\[[^\\]]+\\])*(,[_a-zA-z0-9]+(\\[[^\\]]+\\])*)*)?\\)", "&,", desc);
printf "h264_func_cat (";
printf desc;
printf ")\n";
}
else
print $0;
indent_tmp = 0;
indented += indent_plus;
if (indented <= 0)
break;
if (indent_plus == 0 &&
sub("\\<if\\>|\\<else\\>|\\<while\\>|\\<for\\>", "", line) > 0)
indent_tmp=1;
}
print "";
}