5
# Extract MIB modules from text files, like RFCs or I-Ds.
7
# This is variant of smistrip from libsmi-0.2, modified to be somewhat
8
# more aggressive in suppressing blank lines, and support the -x option.
10
# Copyright (c) 1999 Frank Strauss, Technical University of Braunschweig.
11
# Modified by Niels Baggesen
13
# See the file "COPYING" for information on usage and redistribution
14
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16
# $Id: smistrip,v 5.0 2002/04/20 07:30:17 hardaker Exp $
18
# NOTE, that this script relies on awk (tested with GNU awk) and getopts
19
# (shell builtin like in bash or standalone).
28
echo "smistrip $VERSION"
34
echo "Usage: smistrip [-Vhn] [-d dir] [-s suffix] [-m modules] file ..."
35
echo "-V show version and license information"
36
echo "-h show usage information"
37
echo "-n do not write module files"
38
echo "-d dir write module to directory dir"
39
echo "-x suffix append suffix to the module file name"
40
echo "-m modules strip only the specified modules. For a list of modules"
41
echo " use : as a separator"
42
echo "file ... input files to parse (RFCs, I-Ds, ...)"
48
cat $1 | $AWK -vtest="$test" -vdir="$dir" -vsingle="$single" -vsuffix="$suffix" '
51
/^[ \t]*[A-Za-z0-9-]* *DEFINITIONS */ {
58
# page footer - start skipping
59
/\[Page [iv0-9]*\] */ {
64
/^[ \t]*(::=|DESCRIPTION|SYNTAX|(MAX-|MIN-|)ACCESS|STATUS|REFERENCE|INDEX|AUGMENTS|DEFVAL|UNITS|DISPLAY|")/ {
66
if (line[n-1] == "") n--
69
# a blank line - suppress multiple
72
if (line[n-1] != "" && line[n-1] !~ /,[ \t\r]*$/) line[n++] = ""
76
# collect non-blank line when inside mib module
78
if (length(module) > 0) {
80
collect = 1 # page header, stop skipping
86
# remember when we enter a macro definition
92
/^[ \t]*END[ \t\r]*$/ {
95
else if (length(single) == 0 || match(":"single":", ":"module":")) {
97
for (i = 0 ; i < n ; i++) {
98
# find the minimum column that contains non-blank characters
99
# in order to cut a blank prefix off.
100
p = match(line[i], "[^ ]")
101
if (p < strip && length(line[i]) > p) strip = p
106
f = dir "/" module suffix
109
for (i = 0 ; i < n ; i++)
110
print substr(line[i], strip) >f
113
print module ": " n " lines."
118
print module ": ignored."
124
while $GETOPTS Vhnm:d:x: c ; do
146
shift `expr $OPTIND - 1`
149
if [ $# -eq 0 ] ; then