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