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