merge_help.awk revision 1.1.4.2 1 1.1.4.2 elad #!/usr/bin/awk -f
2 1.1.4.2 elad #
3 1.1.4.2 elad # $FreeBSD$
4 1.1.4.2 elad #
5 1.1.4.2 elad # Merge two boot loader help files for FreeBSD 3.0
6 1.1.4.2 elad # Joe Abley <jabley (at] patho.gen.nz>
7 1.1.4.2 elad
8 1.1.4.2 elad BEGIN \
9 1.1.4.2 elad {
10 1.1.4.2 elad state = 0;
11 1.1.4.2 elad first = -1;
12 1.1.4.2 elad ind = 0;
13 1.1.4.2 elad }
14 1.1.4.2 elad
15 1.1.4.2 elad # beginning of first command
16 1.1.4.2 elad /^###/ && (state == 0) \
17 1.1.4.2 elad {
18 1.1.4.2 elad state = 1;
19 1.1.4.2 elad next;
20 1.1.4.2 elad }
21 1.1.4.2 elad
22 1.1.4.2 elad # entry header
23 1.1.4.2 elad /^# T[[:graph:]]+ (S[[:graph:]]+ )*D[[:graph:]][[:print:]]*$/ && (state == 1) \
24 1.1.4.2 elad {
25 1.1.4.2 elad match($0, " T[[:graph:]]+");
26 1.1.4.2 elad T = substr($0, RSTART + 2, RLENGTH - 2);
27 1.1.4.2 elad match($0, " S[[:graph:]]+");
28 1.1.4.2 elad S = (RLENGTH == -1) ? "" : substr($0, RSTART + 2, RLENGTH - 2);
29 1.1.4.2 elad match($0, " D[[:graph:]][[:print:]]*$");
30 1.1.4.2 elad D = substr($0, RSTART + 2);
31 1.1.4.2 elad
32 1.1.4.2 elad # find a suitable place to store this one...
33 1.1.4.2 elad ind++;
34 1.1.4.2 elad if (ind == 1)
35 1.1.4.2 elad {
36 1.1.4.2 elad first = ind;
37 1.1.4.2 elad help[ind, "T"] = T;
38 1.1.4.2 elad help[ind, "S"] = S;
39 1.1.4.2 elad help[ind, "link"] = -1;
40 1.1.4.2 elad } else {
41 1.1.4.2 elad i = first; j = -1;
42 1.1.4.2 elad while (help[i, "T"] help[i, "S"] < T S)
43 1.1.4.2 elad {
44 1.1.4.2 elad j = i;
45 1.1.4.2 elad i = help[i, "link"];
46 1.1.4.2 elad if (i == -1) break;
47 1.1.4.2 elad }
48 1.1.4.2 elad
49 1.1.4.2 elad if (i == -1)
50 1.1.4.2 elad {
51 1.1.4.2 elad help[j, "link"] = ind;
52 1.1.4.2 elad help[ind, "link"] = -1;
53 1.1.4.2 elad } else {
54 1.1.4.2 elad help[ind, "link"] = i;
55 1.1.4.2 elad if (j == -1)
56 1.1.4.2 elad first = ind;
57 1.1.4.2 elad else
58 1.1.4.2 elad help[j, "link"] = ind;
59 1.1.4.2 elad }
60 1.1.4.2 elad }
61 1.1.4.2 elad help[ind, "T"] = T;
62 1.1.4.2 elad help[ind, "S"] = S;
63 1.1.4.2 elad help[ind, "D"] = D;
64 1.1.4.2 elad
65 1.1.4.2 elad # set our state
66 1.1.4.2 elad state = 2;
67 1.1.4.2 elad help[ind, "text"] = 0;
68 1.1.4.2 elad next;
69 1.1.4.2 elad }
70 1.1.4.2 elad
71 1.1.4.2 elad # end of last command, beginning of next one
72 1.1.4.2 elad /^###/ && (state == 2) \
73 1.1.4.2 elad {
74 1.1.4.2 elad state = 1;
75 1.1.4.2 elad }
76 1.1.4.2 elad
77 1.1.4.2 elad (state == 2) \
78 1.1.4.2 elad {
79 1.1.4.2 elad sub("[[:blank:]]+$", "");
80 1.1.4.2 elad if (help[ind, "text"] == 0 && $0 ~ /^[[:blank:]]*$/) next;
81 1.1.4.2 elad help[ind, "text", help[ind, "text"]] = $0;
82 1.1.4.2 elad help[ind, "text"]++;
83 1.1.4.2 elad next;
84 1.1.4.2 elad }
85 1.1.4.2 elad
86 1.1.4.2 elad # show them what we have (it's already sorted in help[])
87 1.1.4.2 elad END \
88 1.1.4.2 elad {
89 1.1.4.2 elad node = first;
90 1.1.4.2 elad while (node != -1)
91 1.1.4.2 elad {
92 1.1.4.2 elad printf "################################################################################\n";
93 1.1.4.2 elad printf "# T%s ", help[node, "T"];
94 1.1.4.2 elad if (help[node, "S"] != "") printf "S%s ", help[node, "S"];
95 1.1.4.2 elad printf "D%s\n\n", help[node, "D"];
96 1.1.4.2 elad for (i = 0; i < help[node, "text"]; i++)
97 1.1.4.2 elad printf "%s\n", help[node, "text", i];
98 1.1.4.2 elad node = help[node, "link"];
99 1.1.4.2 elad }
100 1.1.4.2 elad printf "################################################################################\n";
101 1.1.4.2 elad }
102