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