1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
Fix for #558128. smistrip enhancements.
--- a/tools/smistrip.in 2009-11-25 13:01:14.000000000 +0100
+++ b/tools/smistrip.in 2009-11-26 16:41:57.000000000 +0100
@@ -5,6 +5,13 @@
# Extract MIB and PIB modules from text files, like RFCs or I-Ds.
#
# Copyright (c) 1999 Frank Strauss, Technical University of Braunschweig.
+# Copyright (c) Niels Baggesen, Jochen Friedrich
+#
+# Modified by Niels Baggesen to be somewhat more aggressive in suppressing
+# blank lines, and support the -x option.
+#
+# Modified by Jochen Friedrich to merge the changes of libsmi back in and
+# make the aggressive suppressing of blank lines optional.
#
# See the file "COPYING" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
@@ -27,13 +34,17 @@
do_usage () {
- echo "Usage: smistrip [-Vhn] [-i dir] [-d dir] [-m module] file1 [file2 [...]]"
+ echo "Usage: smistrip [-Vvhna] [-i dir] [-d dir] [-s suffix] [-m modules] file1 [file2 [...]]"
echo "-V show version and license information"
+ echo "-v verbose"
echo "-h show usage information"
echo "-n do not write module files"
+ echo "-a strip blank lines more aggressively"
echo "-i dir try to read files from directory dir"
echo "-d dir write module to directory dir"
- echo "-m module strip only the specified module"
+ echo "-x suffix append suffix to the module file name"
+ echo "-m modules strip only the specified modules. For a list of modules"
+ echo " use : as a separator"
echo "file1 ... input files to parse (RFCs, I-Ds, ...)"
}
@@ -57,65 +68,90 @@
$CMD "$FILE" | \
tr -d '\015' | \
- grep -i -v '^[ ]*Internet[ \-]Draft' | \
- $AWK -vtest="$test" -vdir="$dir" -vsingle="$single" '
+ $AWK -vtest="$test" -vdir="$dir" -vsingle="$single" -vsuffix="$suffix" -vverbose="$verbose" -vaggressive="$aggressive" '
+
+ BEGIN {
+ if (length(single) != 0) {
+ single = ":"single":"
+ }
+ else {
+ single = ""
+ }
+ }
+
+ END {
+ if (single != "" && single != ":") {
+ gsub(":", " ", single)
+ print "WARNING: Module(s) not found:" single
+ }
+ }
# start of module
/^[ \t]*[A-Za-z0-9-]* *(PIB-)?DEFINITIONS *(::=)? *(BEGIN)? *$/ {
module = $1
- skip = 9
- skipped = -1
+ collect = 1
macro = 0
+ skip = 0
n = 0
}
- # process each line
- {
- # at the end of a page we go back one line (which is expected to
- # be a separator line), and start the counter skipped to skip the
- # next few lines.
- if ($0 ~ /\[[pP]age [iv0-9]*\] */) {
- # some drafts do not use that separator line. so keep it if
- # there are non-blank characters.
- if (!(line[n] ~ /^[ \t]*$/)) { print "WARNING: the line ::"line[n]":: should be a separator before a page break. It was kept. " ; n-- }
- skipped = 0
- }
-
- # if we are skipping...
- if (skipped >= 0) {
- skipped++
-
- # if we have skipped enough lines to the top of the next page...
- if (skipped >= skip) {
- skipped = -1
- } else {
-
- # finish skipping, if we find a non-empty line, but not before
- # we have skipped four lines. remember the miminum of lines
- # we have ever skipped to keep empty lines in a modules that
- # appear near the top of a page.
- if ((skipped >= 4) && ($0 ~ /[^ \t]/)) {
- if (skipped < skip) { skip = skipped }
- skipped = -1
- }
+ # at the end of a page we go back one line (which is expected to
+ # be a separator line), and start the counter skipped to skip the
+ # next few lines.
+ /\[[pP]age [iv0-9]*\] */ {
+ # some drafts do not use that separator line. so keep it if
+ # there are non-blank characters.
+ if (!aggressive && n && collect) {
+ if (!(line[n-1] == ""))
+ print "WARNING: the line ::"line[n-1]":: should be a separator before a page break. It was kept. ";
+ else n--;
+ skip = 3
+ }
+ collect = 0
+ next
+ }
+
+ /^[ \t]*(::=|DESCRIPTION|SYNTAX|MAX-ACCESS|MIN-ACCESS|ACCESS|STATUS|REFERENCE|INDEX|AUGMENTS|DEFVAL|UNITS|DISPLAY|")/ {
+ skip = 0
+ if (collect && aggressive)
+ if (line[n-1] == "") n--
+ }
+
+ # a blank line - suppress multiple
+ /^[ \t\r]*$/ {
+ if (collect && (skip == 0)) {
+ if (aggressive && n) {
+ if (line[n-1] != "" && line[n-1] !~ /,[ \t\r]*$/) line[n++] = ""
}
+ else line[n++] = ""
}
+ if (skip > 0) skip--;
+ next
+ }
- # so, if we are not skipping and inside a module, remember the line.
- if ((skipped == -1) && (length(module) > 0)) {
- line[n++] = $0
+ # collect non-blank line when inside mib module
+ /[^ \f\t]/ {
+ if (length(module) > 0) {
+ if (!collect)
+ collect = 1 # page header, stop skipping
+ else if (skip == 0)
+ line[n++] = $0
}
+ if (skip > 0) skip--;
}
# remember when we enter a macro definition
/^[ \t]*[A-Za-z0-9-]* *MACRO *::=/ {
macro = 1
+ skip = 0
}
# end of module
/^[ \t]*END[ \t]*$/ {
+ skip = 0
if (macro == 0) {
- if ((length(single) == 0) || (single == module)) {
+ if (single == "" || match(single, ":"module":")) {
+ sub(":"module, "", single)
strip = 99
for (i=0 ; i < n ; i++) {
# find the minimum column that contains non-blank characters
@@ -129,17 +165,21 @@
if (test != "1") {
if (dir) {
- f = dir"/"module
+ f = dir"/"module suffix
} else {
- f = module
+ f = module suffix
}
for (i=0 ; i < n ; i++) {
print substr(line[i], strip) >f
}
}
+ if (verbose) {
+ print module ": " n " lines."
+ }
- print module ": " n " lines."
}
+ else
+ print "NOTE: " module ": ignored."
module = ""
} else {
macro = 0
@@ -150,16 +190,22 @@
-while $GETOPTS Vhnm:i:d: c ; do
+while $GETOPTS Vvhnam:i:d:x: c ; do
case $c in
+ v) verbose=1
+ ;;
n) test=1
;;
+ a) aggressive=1
+ ;;
m) single=$OPTARG
;;
i) indir=$OPTARG
;;
d) dir=$OPTARG
;;
+ x) suffix=$OPTARG
+ ;;
h) do_usage
exit 0
;;
|