-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml.awk
146 lines (129 loc) · 3 KB
/
html.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
140
141
142
143
144
145
function append() {
if (getline) {
remain = remain RS $0;
printf("remain: %s\n", remain);
} else {
printf("EOF\n");
exit;
}
}
function in_section(sec_bg, sec_ed) {
if (remain !~ "^" sec_bg)
return 0;
while (remain !~ sec_ed "$") {
append();
}
printf("in section\n");
printf("<%s>\n", remain);
return 1;
}
function begin_with_a_tag(str) {
return 1;
}
BEGIN {
RS = ">";
FS = "";
ptag = "";
remain = "";
contain = "";
while (getline) {
remain = $0;
before = "";
printf("remain: %s\n", remain);
while (index(remain, "<") == 0) {
append();
}
lab = index(remain, "<");
if (begin_with_a_tag(substr(remain, lab))) {
} else {
if (before != "") {
before = before
sub("^[^<]*<", "", remain);
printf("remain: %s\n", remain);
printf("before: %s\n", before);
continue;
########
printf("remain: %s\n", remain);
if (in_section("!--", "--") ||
in_section("!", "") ||
in_section("?", "?"))
continue;
tag = remain;
sub("[ \t\n\r][ \t\n\r]*.*$", "", tag);
printf("tag: %s\n", tag);
if (substr(tag, 1, 1) == "/") {
tag = substr(tag, 2);
printf("tag: %s\n", tag);
printf("ptag: %s\n", ptag);
sli = index(ptag, "/");
while (sli > 1 && substr(ptag, 1, sli - 1) != tag) {
ptag = substr(ptag, sli + 1);
printf("ptag: %s\n", ptag);
sli = index(ptag, "/");
}
if (sli > 1) {
if (before !~ "^[ \t\n\r]*$")
printf("%s\n", before);
printf("TAG_ED: %s\n", ptag);
ptag = substr(ptag, sli + 1);
} else {
printf("no match\n");
exit;
}
} else {
if (tag != "")
ptag = tag "/" ptag;
printf("TAG_BG: %s\n", ptag);
}
sub("[^ \t\n\r][^ \t\n\r]*[ \t\n\r]*", "", remain);
printf("remain: %s\n", remain);
#system("echo " remain " | od -a -b");
if (remain == "") {
printf("continue\n");
continue;
}
while (remain != "") {
if (remain ~ /[A-Za-z][^"]*=[ \t\n\r]*"/) {
att = remain;
sub("[ \t\n\r]*=.*$", "", att);
#printf("att: %s\n", att);
remain = substr(remain, index(remain, "\"") + 1);
#printf("remain: %s\n", remain);
rqd = index(remain, "\"");
while (rqd == 0) {
if (getline)
remain = remain ">" $0;
else
exit;
rqd = index(remain, "\"");
}
quo = substr(remain, 1, rqd - 1);
printf(" TAG_AT: %s='%s'\n", att, quo);
sub(/[^"]*"[ \t\n\r]*/, "", remain);
#printf("remain: %s\n", remain);
} else if (remain ~ /[A-Za-z][^']*=[ \t\n\r]*'/) {
att = remain;
sub("[ \t\n\r]*=.*$", "", att);
#printf("att: %s\n", att);
remain = substr(remain, index(remain, "'") + 1);
#printf("remain: %s\n", remain);
rqd = index(remain, "'");
while (rqd == 0) {
if (getline)
remain = remain ">" $0;
else
exit;
rqd = index(remain, "'");
}
quo = substr(remain, 1, rqd - 1);
printf(" TAG_AT: %s='%s'\n", att, quo);
sub(/[^']*'[ \t\n\r]*/, "", remain);
#printf("remain: %s\n", remain);
} else {
remain = "";
#printf("why\n");
}
}
}
printf("EOF\n");
}