diff options
| author | Mike Smith <msmith@FreeBSD.org> | 1999-01-18 19:05:27 +0000 |
|---|---|---|
| committer | Mike Smith <msmith@FreeBSD.org> | 1999-01-18 19:05:27 +0000 |
| commit | 378972ac6b9bac0123dec09f613bfcba7210933b (patch) | |
| tree | 477744460b631ee7f7c67e754791367fde46a5bc /sys/boot/common | |
| parent | e2be51399dbb80c70187282aa00c851985c0c465 (diff) | |
Notes
Diffstat (limited to 'sys/boot/common')
| -rw-r--r-- | sys/boot/common/merge_help.awk | 101 | ||||
| -rw-r--r-- | sys/boot/common/merge_help.pl | 182 |
2 files changed, 101 insertions, 182 deletions
diff --git a/sys/boot/common/merge_help.awk b/sys/boot/common/merge_help.awk new file mode 100644 index 000000000000..1376c53aee3c --- /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"; +} diff --git a/sys/boot/common/merge_help.pl b/sys/boot/common/merge_help.pl deleted file mode 100644 index cfeb6cabb40b..000000000000 --- a/sys/boot/common/merge_help.pl +++ /dev/null @@ -1,182 +0,0 @@ -#!/usr/bin/perl -# -# Copyright (c) 1998 Nick Hibma -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# -# -# Reads all the files mentioned on the command line (or stdin) and combines -# them into one. -# -# The files must have the following format: -# -# ######################### (line is ignored) -# # Ttopic Dhello world (short description) -# This is the long description and can span -# multiple lines and empty -# -# ones. -# ########################### (this line is again ignored) -# # Ttopic Ssubtopic Dagain a short description -# a subtopic is a topic that will connected under the subtree of -# topic. - -# Declaration of constants -# -$SOD = 'D'; # Start of description character -$SLABEL = '_sdescr'; # Short description label -$LLABEL = '_ldescr'; # Long description label - -# Global variables -# - -# Read the command line parameters -# -while ( $arg = shift @ARGV ) { - if ( $arg eq '-h' ) { - die "$0 [-h] [files ...]\nno filenames or '-' as a filename reads stdin\n"; - } else { - push @files, $arg; - } -} - -# No files to process? Read STDIN -# -push @files, '-' # no files found? Process STDIN - if $#files == -1; - -# Perform processing on each file -# -foreach $filename ( @files ) { - if ( $filename eq '-' ) { - $file = STDIN; - } else { - die "Could not open file $filename, $!" - unless open FILE, $filename; - } - - # Process one file and add it to the hash - # - &add_file(FILE); -} - -# Print the results of our processing -# -&print_topic($topics, '#'x80 . "\n# "); -print '#'x80 . "\n"; - -#require 'z39.50/PerlieZ/debug.pm'; -#debug::Dump($topics, '$topics'); - -# Make like a tree and leave. -# -exit 0; - -sub add_file { - my ($file) = @_; - - # process a file and add it to the hash - - $line = <$file>; - while ( !eof($file) ) { - if ( $line =~ s/^#\s+// ) { - - # the line contains a number of parts (separated by whitespace): - # (Cl+ )+ Dd+ - # C is a character not equal to D - # l+ is a word without spaces - # (Cl+ )+ is a list of words preceded by C and separated by spaces - # d+ is a description (can contain spaces) - # D is the character in $SOD - # - # we split it into multiple l+ parts and one d+ part - # after that we insert the d+ part at the right point in the tree - # (after reading also the long descrescription in the next lines) - - @ar = (); - while ( $line =~ s/^([^$SOD]\S+)\s+//o ) { - $label = $1; - $label .= ' ' # avoid conflicts with hash labels - if $label eq $SLABEL or $label eq $LLABEL; - push @ar, $label; - } - $sdescr = $line; # short descr. is rest of line - - my $ldescr = ''; # read the long description - $line = <$file>; - while ( !eof($file) and $line !~ m/^#/ ) { - $ldescr .= $line; - $line = <$file>; - } - - $topics = &add_to_hash($topics, $sdescr, $ldescr, @ar); - } else { - $line = <$file>; - } - } -} - -sub add_to_hash { - my ($hash, $sdescr, $ldescr, @ar) = @_; - - # bit more complicated than usual, because we want to insert - # value into an existing tree if possible, or otherwise build it. - # Probably could be done with references as well, but this seems neater. - - if ( $#ar == -1 ) { - # Create a new leaf (reference to descriptions hash) - - return {$SLABEL=>$sdescr, $LLABEL=>$ldescr}; - } else { - # Add subtree to node and if node does not exist, create an empty one - # (reference to a hash of subnodes) - - $hash = {} # create a new ref to hash on the fly - if !$hash; - my $label = shift @ar; # next label in tree to be used - $hash->{$label} = &add_to_hash($hash->{$label}, $sdescr, $ldescr, @ar); - return $hash; - } -} - -sub print_topic { - my ($topic, $preprint) = @_; - - # print out a topic and its subtopics recursively - # preprint is the string before the current subtopic hash - # and is the same for all the subtopics in the current hash - - if ( $topic->{$SLABEL} or $topic->{$LLABEL} ) { - # leaf found - print $preprint . "$topic->{$SLABEL}$topic->{$LLABEL}"; - } - - # iterate over all the subtopics - my ($label); - foreach $label ( sort keys %{ $topic } ) { - next - if $label eq $SLABEL or $label eq $LLABEL; - &print_topic($topic->{$label}, $preprint . $label . ' '); - } -} |
