5 # Extract MIB and PIB modules from text files, like RFCs or I-Ds.
7 # Copyright (c) 1999 Frank Strauss, Technical University of Braunschweig.
9 # See the file "COPYING" for information on usage and redistribution
10 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 # $Id: smistrip.in 3434 2006-04-07 07:02:51Z strauss $
14 # NOTE, that this script relies on awk (tested with GNU awk) and getopts
15 # (shell builtin like in bash or standalone).
24 echo "smistrip $VERSION"
30 echo "Usage: smistrip [-Vhn] [-i dir] [-d dir] [-m module] file1 [file2 [...]]"
31 echo "-V show version and license information"
32 echo "-h show usage information"
33 echo "-n do not write module files"
34 echo "-i dir try to read files from directory dir"
35 echo "-d dir write module to directory dir"
36 echo "-m module strip only the specified module"
37 echo "file1 ... input files to parse (RFCs, I-Ds, ...)"
43 if [ "$indir" ] ; then
48 if [ ! -f "$FILE" -a -f "$FILE.gz" ] ; then
51 echo "$FILE" | grep -q '\.gz$'
52 if [ $? -ne 0 ] ; then
60 grep -i -v '^[ ]*Internet[ \-]Draft' | \
61 $AWK -vtest="$test" -vdir="$dir" -vsingle="$single" '
64 /^[ \t]*[A-Za-z0-9-]* *(PIB-)?DEFINITIONS *(::=)? *(BEGIN)? *$/ {
74 # at the end of a page we go back one line (which is expected to
75 # be a separator line), and start the counter skipped to skip the
77 if ($0 ~ /\[[pP]age [iv0-9]*\] */) {
78 # some drafts do not use that separator line. so keep it if
79 # there are non-blank characters.
80 if (!(line[n] ~ /^[ \t]*$/)) { print "WARNING: the line ::"line[n]":: should be a separator before a page break. It was kept. " ; n-- }
84 # if we are skipping...
88 # if we have skipped enough lines to the top of the next page...
89 if (skipped >= skip) {
93 # finish skipping, if we find a non-empty line, but not before
94 # we have skipped four lines. remember the miminum of lines
95 # we have ever skipped to keep empty lines in a modules that
96 # appear near the top of a page.
97 if ((skipped >= 4) && ($0 ~ /[^ \t]/)) {
98 if (skipped < skip) { skip = skipped }
104 # so, if we are not skipping and inside a module, remember the line.
105 if ((skipped == -1) && (length(module) > 0)) {
110 # remember when we enter a macro definition
111 /^[ \t]*[A-Za-z0-9-]* *MACRO *::=/ {
116 /^[ \t]*END[ \t]*$/ {
118 if ((length(single) == 0) || (single == module)) {
120 for (i=0 ; i < n ; i++) {
121 # find the minimum column that contains non-blank characters
122 # in order to cut a blank prefix off. Ignore lines that only
123 # contain white spaces.
124 if (!(line[i] ~ /^[ \t]*$/)) {
125 p = match(line[i], "[^ ]")
126 if ((p < strip) && (length(line[i]) > p)) { strip = p }
136 for (i=0 ; i < n ; i++) {
137 print substr(line[i], strip) >f
141 print module ": " n " lines."
153 while $GETOPTS Vhnm:i:d: c ; do
175 shift `expr $OPTIND - 1`
179 if [ $# -eq 0 ] ; then