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