summaryrefslogtreecommitdiffstats
path: root/sys/boot/common/merge_help.awk
diff options
context:
space:
mode:
authormsmith <msmith@FreeBSD.org>1999-01-18 19:05:27 +0000
committermsmith <msmith@FreeBSD.org>1999-01-18 19:05:27 +0000
commit488523664e6d8f8ba7619929d491d54a689f4d47 (patch)
tree4f17d3133651137b304e82c8e592a00039970aa6 /sys/boot/common/merge_help.awk
parent8972dd7aad428319c0aedd99a7cb0519b3b784e8 (diff)
downloadFreeBSD-src-488523664e6d8f8ba7619929d491d54a689f4d47.zip
FreeBSD-src-488523664e6d8f8ba7619929d491d54a689f4d47.tar.gz
Transition from using Perl to using awk for our text-manipulation
needs. This removes the dependancy on Perl for the generation of the loader, allowing the world to be built on a perl-free system. Submitted by: Joe Abley <jabley@clear.co.nz>
Diffstat (limited to 'sys/boot/common/merge_help.awk')
-rw-r--r--sys/boot/common/merge_help.awk101
1 files changed, 101 insertions, 0 deletions
diff --git a/sys/boot/common/merge_help.awk b/sys/boot/common/merge_help.awk
new file mode 100644
index 0000000..1376c53
--- /dev/null
+++ b/sys/boot/common/merge_help.awk
@@ -0,0 +1,101 @@
+#!/usr/bin/awk -f
+#
+# $Id: mergehelp.awk,v 1.3 1999/01/13 20:06:52 jabley Exp $
+#
+# Merge two boot loader help files for FreeBSD 3.0
+# Joe Abley <jabley@patho.gen.nz>
+
+BEGIN \
+{
+ state = 0;
+ first = 0;
+ ind = 0;
+}
+
+# beginning of first command
+/^###/ && (state == 0) \
+{
+ state = 1;
+ next;
+}
+
+# entry header
+/^# T[[:graph:]]+ (S[[:graph:]]+ )*D[[:graph:]][[:print:]]*$/ && (state == 1) \
+{
+ match($0, " T[[:graph:]]+");
+ T = substr($0, RSTART + 2, RLENGTH - 2);
+ match($0, " S[[:graph:]]+");
+ S = (RLENGTH == -1) ? "" : substr($0, RSTART + 2, RLENGTH - 2);
+ match($0, " D[[:graph:]][[:print:]]*$");
+ D = substr($0, RSTART + 2);
+
+ # find a suitable place to store this one...
+ ind++;
+ if (ind == 1)
+ {
+ first = ind;
+ help[ind, "T"] = T;
+ help[ind, "S"] = S;
+ help[ind, "link"] = -1;
+ } else {
+ i = first; j = -1;
+ while (help[i, "T"] help[i, "S"] < T S)
+ {
+ j = i;
+ i = help[i, "link"];
+ if (i == -1) break;
+ }
+
+ if (i == -1)
+ {
+ help[j, "link"] = ind;
+ help[ind, "link"] = -1;
+ } else {
+ help[ind, "link"] = i;
+ if (j == -1)
+ first = ind;
+ else
+ help[j, "link"] = ind;
+ }
+ }
+ help[ind, "T"] = T;
+ help[ind, "S"] = S;
+ help[ind, "D"] = D;
+
+ # set our state
+ state = 2;
+ help[ind, "text"] = 0;
+ next;
+}
+
+# end of last command, beginning of next one
+/^###/ && (state == 2) \
+{
+ state = 1;
+}
+
+(state == 2) \
+{
+ sub("[[:blank:]]+$", "");
+ if (help[ind, "text"] == 0 && $0 ~ /^[[:blank:]]*$/) next;
+ help[ind, "text", help[ind, "text"]] = $0;
+ help[ind, "text"]++;
+ next;
+}
+
+# show them what we have (it's already sorted in help[])
+END \
+{
+ node = first;
+ while (node != -1)
+ {
+ printf "################################################################################\n";
+ printf "# T%s ", help[node, "T"];
+ if (help[node, "S"] != "") printf "S%s ", help[node, "S"];
+ printf "D%s\n\n", help[node, "D"];
+ for (i = 0; i < help[node, "text"]; i++)
+ printf "%s\n", help[node, "text", i];
+ node = help[node, "link"];
+ }
+ printf "################################################################################\n";
+}
OpenPOWER on IntegriCloud