loader: updates from review
[unleashed.git] / usr / src / boot / sys / boot / common / merge_help.awk
blob1070f73f1fe9694d88532c01ea88c3016d48ec55
1 #!/usr/bin/awk -f
3 # $FreeBSD$
5 # Merge two boot loader help files for FreeBSD 3.0
6 # Joe Abley <jabley@patho.gen.nz>
8 BEGIN \
10 state = 0;
11 first = -1;
12 ind = 0;
15 # beginning of first command
16 /^###/ && (state == 0) \
18 state = 1;
19 next;
22 # entry header
23 /^# T[[:graph:]]+ (S[[:graph:]]+ )*D[[:graph:]][[:print:]]*$/ && (state == 1) \
25 match($0, " T[[:graph:]]+");
26 T = substr($0, RSTART + 2, RLENGTH - 2);
27 match($0, " S[[:graph:]]+");
28 SSTART = RSTART
29 S = (RLENGTH == -1) ? "" : substr($0, RSTART + 2, RLENGTH - 2);
30 match($0, " D[[:graph:]][[:print:]]*$");
31 D = substr($0, RSTART + 2);
32 if (SSTART > RSTART)
33 S = "";
35 # find a suitable place to store this one...
36 ind++;
37 if (ind == 1)
39 first = ind;
40 help[ind, "T"] = T;
41 help[ind, "S"] = S;
42 help[ind, "link"] = -1;
43 } else {
44 i = first; j = -1;
45 while (help[i, "T"] help[i, "S"] < T S)
47 j = i;
48 i = help[i, "link"];
49 if (i == -1) break;
52 if (i == -1)
54 help[j, "link"] = ind;
55 help[ind, "link"] = -1;
56 } else {
57 help[ind, "link"] = i;
58 if (j == -1)
59 first = ind;
60 else
61 help[j, "link"] = ind;
64 help[ind, "T"] = T;
65 help[ind, "S"] = S;
66 help[ind, "D"] = D;
68 # set our state
69 state = 2;
70 help[ind, "text"] = 0;
71 next;
74 # end of last command, beginning of next one
75 /^###/ && (state == 2) \
77 state = 1;
80 (state == 2) \
82 sub("[[:blank:]]+$", "");
83 if (help[ind, "text"] == 0 && $0 ~ /^[[:blank:]]*$/) next;
84 help[ind, "text", help[ind, "text"]] = $0;
85 help[ind, "text"]++;
86 next;
89 # show them what we have (it's already sorted in help[])
90 END \
92 node = first;
93 while (node != -1)
95 printf "################################################################################\n";
96 printf "# T%s ", help[node, "T"];
97 if (help[node, "S"] != "") printf "S%s ", help[node, "S"];
98 printf "D%s\n\n", help[node, "D"];
99 for (i = 0; i < help[node, "text"]; i++)
100 printf "%s\n", help[node, "text", i];
101 node = help[node, "link"];
103 printf "################################################################################\n";