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