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