[netfilter-cvslog] r3405 - in trunk/nfsim: . core doc

jk at netfilter.org jk at netfilter.org
Thu Dec 16 06:27:03 CET 2004


Author: jk at netfilter.org
Date: 2004-12-16 06:27:02 +0100 (Thu, 16 Dec 2004)
New Revision: 3405

Added:
   trunk/nfsim/doc/gen-usage
   trunk/nfsim/doc/usage.xsl
Modified:
   trunk/nfsim/Makefile.in
   trunk/nfsim/core/core.c
   trunk/nfsim/doc/autogen-docs
   trunk/nfsim/doc/gen-help
   trunk/nfsim/doc/simulator.xml
   trunk/nfsim/doc/text.xsl
Log:
Add autogenerated usage, clean up gen-help a little


Modified: trunk/nfsim/Makefile.in
===================================================================
--- trunk/nfsim/Makefile.in	2004-12-16 03:18:54 UTC (rev 3404)
+++ trunk/nfsim/Makefile.in	2004-12-16 05:27:02 UTC (rev 3405)
@@ -20,11 +20,14 @@
 
 export
 
-OBJS:=  kernelenv/kernelenv.o
+OBJS:=  kernelenv/kernelenv.o core/usage.o
 
 # OBJS which need help functions extracted
 HELP_OBJS:=
 
+# files which we can extract command line usage from
+USAGE_SOURCES := core/core.c
+
 all:	simulator core/fakesockopt.so.1.0
 
 include core/Makefile
@@ -37,9 +40,9 @@
 # link the netfilter object last
 OBJS += netfilter/netfilter.o
 
-simulator: kernelenv/include/linux/config.h$(HELP_OBJS) $(OBJS) 
+simulator: kernelenv/include/linux/config.h $(HELP_OBJS) $(OBJS) $(USAGE)
 	$(CC) $(GCOVFLAGS) $(CFLAGS) $(LDFLAGS) -lreadline -lcurses -o $@ \
-		$(HELP_OBJS) $(OBJS)
+		$(HELP_OBJS) $(OBJS) $(USAGE)
 
 kernelenv/include/linux/config.h: .config
 	awk \
@@ -54,6 +57,10 @@
 		-o $@ $^
 	ln -sf core/fakesockopt.so.1.0 ./
 
+core/usage.o: core/usage.c
+core/usage.c: $(USAGE_SOURCES) doc/gen-usage
+	doc/gen-usage $(USAGE_SOURCES) >$@
+
 docs:
 	@[ -L doc/link-dtd ] || \
 		(echo "No docbook installation: see README"; exit 1)

Modified: trunk/nfsim/core/core.c
===================================================================
--- trunk/nfsim/core/core.c	2004-12-16 03:18:54 UTC (rev 3404)
+++ trunk/nfsim/core/core.c	2004-12-16 05:27:02 UTC (rev 3405)
@@ -24,6 +24,7 @@
 #include "message.h"
 #include "tui.h"
 #include "utils.h"
+#include "usage.h"
 
 
 #include <unistd.h>
@@ -171,12 +172,48 @@
 	{"quiet",  0, 0, 'q'},
 	{"exit",  0, 0, 'e'},
 	{"no-modules",  0, 0, 'N'},
+/*** XML Argument:
+    <section id="a:no-modules">
+     <title><option>--no-modules</option></title>
+     <subtitle>Don't load all available modules on startup</subtitle>
+    </section>
+*/
 	{"version",  0, 0, 'V'},
+/*** XML Argument:
+    <section id="a:version">
+     <title><option>--version</option></title>
+     <subtitle>Print the version of the simulator and kernel</subtitle>
+    </section>
+*/
 	{"failtest",  0, 0, 1},
+/*** XML Argument:
+    <section id="a:failtest">
+     <title><option>--failtest</option></title>
+     <subtitle>Try every combination of external failures</subtitle>
+     <para>This option will <function>fork()</function> the simulator
+      whenever a possible failure point is reacked (eg
+      <function>kmalloc</function>. The child process will fail the function,
+      while the parent will succeed. If the simulator reaches an error, the
+      pattern of successes/failures will be printed out, which can be replayed
+      using <option>--failpattern</option></para>
+    </section>
+*/
+
 	{"failpattern",  1, 0, 2},
+/*** XML Argument:
+    <section id="a:failpattern">
+     <title><option>--failpattern
+      <replaceable>pattern</replaceable></option></title>
+     <subtitle>Replay a failure pattern</subtitle>
+     <para>Given a failure pattern, (from <option>failtest</option>), this will
+      replay the sequence of sucesses/failures, allowing debugging of a
+      command</para>
+    </section>
+*/
 	{0,        0, 0, 0 }
 };
 
+
 int main(int argc, char **argv)
 {
 	bool failtest = false, load_modules = true;
@@ -212,6 +249,7 @@
 			break;
 		default:
 			fprintf(stderr, "Unknown argument %c\n", c);
+			print_usage(argv[0]);
 			return EXIT_FAILURE;
 		}
 	}

Modified: trunk/nfsim/doc/autogen-docs
===================================================================
--- trunk/nfsim/doc/autogen-docs	2004-12-16 03:18:54 UTC (rev 3404)
+++ trunk/nfsim/doc/autogen-docs	2004-12-16 05:27:02 UTC (rev 3405)
@@ -3,18 +3,40 @@
 # The SGML is inside the code itself: we extract it for the
 # documentation here.
 
-exec > $2
+tmphelpf=`mktemp /tmp/nfsim_gen-docs.XXXXXX`
+tmpusagef=`mktemp /tmp/nfsim_gen-docs.XXXXXX`
+trap "rm -f $tmphelpf $tmpusagef" EXIT
 
-HELPLINE=`grep -n 'AUTOGENERATED HELP GOES HERE'  $1 | cut -d: -f1`
-head -n $HELPLINE < $1
+for f in `find .. -name '*.c' |
+    xargs awk '/\/\*\*\* XML (Help|Argument)/ {print FILENAME":"FNR":"$3; }'`
+do
+    file=`echo $f | cut -d: -f1`
+    line=`echo $f | cut -d: -f2`
+    type=`echo $f | cut -d: -f3`
 
-for f in `find .. -name '*.c' | xargs fgrep -n '/*** XML Help:' | cut -d: -f1,2`; do
-    FILE=`echo $f | cut -d: -f1`
-    LINE=`echo $f | cut -d: -f2`
+    case "$type" in
+    Help|help)
+	echo Extracting help from ${file}:$line >&2
+	./extract-help $file $line >> $tmphelpf
+    ;;
+    Argument|argument)
+	echo Extracting usage from ${file}:$line >&2
+	./extract-help $file $line >> $tmpusagef
+    ;;
+    esac
 
-    echo Extracting help from ${FILE}:$LINE >&2
-
-    ./extract-help $FILE $LINE
 done
 
-tail +`expr $HELPLINE + 1` $1
+while read line
+do
+    case "$line" in
+    '<!-- AUTOGENERATED HELP GOES HERE -->')
+	cat $tmphelpf
+	;;
+    '<!-- AUTOGENERATED USAGE GOES HERE -->')
+	cat $tmpusagef
+	;;
+    *)
+    	echo "$line"
+    esac
+done < $1 > $2

Modified: trunk/nfsim/doc/gen-help
===================================================================
--- trunk/nfsim/doc/gen-help	2004-12-16 03:18:54 UTC (rev 3404)
+++ trunk/nfsim/doc/gen-help	2004-12-16 05:27:02 UTC (rev 3405)
@@ -5,12 +5,14 @@
 
 TMPF=`mktemp /tmp/nfsim_gen-help.XXXXXX`
 trap "rm -f $TMPF*" EXIT
+cmdsed='s,.*<command>[ 	]*\([^ 	]*\)[ 	]*</command>.*,\1,p'
 
 STARTLINE=1
 for LINE in `fgrep -n '/*** XML Help:' < $FILE | cut -d: -f1`; do
     if [ -L doc/link-dtd ]; then
 	echo '<?xml version="1.0"?>' > $TMPF
-	echo '<!DOCTYPE article PUBLIC "-//OASIS//DTD Docbook XML V4.1.2//EN"' >> $TMPF
+	echo '<!DOCTYPE article PUBLIC "-//OASIS//DTD Docbook XML V4.1.2//EN"' \
+	    >> $TMPF
 	echo '"'`pwd`'/doc/link-dtd/docbookx.dtd">' >> $TMPF
 	echo '<article><section>' >> $TMPF
 	doc/extract-help $FILE $LINE >> $TMPF
@@ -19,7 +21,7 @@
 	tr '\n' ' ' < $TMPF | sed -e 's/[[:space:]]\{2,\}/ /g' |
         xsltproc doc/text.xsl - | fold -w80 -s > $TMPF.txt
 
-	COMMAND=`sed -n 's,.*<command>[ 	]*\([^ 	]*\)[ 	]*</command>.*,\1,p' < $TMPF | head -1`
+	COMMAND=`sed -n "$cmdsed" < $TMPF | head -1`
 	COMMAND_FILE=`basename $FILE .c`-help:$COMMAND
 	echo Creating $COMMAND_FILE
 
@@ -28,18 +30,21 @@
     
 	TXTSTART=`grep -n '^  1\.1\.' $TMPF.txt | cut -d: -f1`
 	tail +`expr $TXTSTART + 2` $TMPF.txt | while read -r TXTLINE; do
-	    echo "$TXTLINE" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/^/"/' -e 's/$/\\n"/' >> $COMMAND_FILE
+	    echo "$TXTLINE" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/^/"/' \
+		-e 's/$/\\n"/' >> $COMMAND_FILE
 	done
 	echo ');' >> $COMMAND_FILE
     else
 	doc/extract-help $FILE $LINE > $TMPF
 
-	COMMAND=`sed -n 's,.*<command>[ 	]*\([^ 	]*\)[ 	]*</command>.*,\1,p' < $TMPF | head -1`
+	COMMAND=`sed -n "$cmdsed" < $TMPF | head -1`
 	COMMAND_FILE=`basename $FILE .c`-help:$COMMAND
 	echo Faking up $COMMAND_FILE
 
 	echo 'nfsim_log(LOG_ALWAYS,' > $COMMAND_FILE
-	sed 's/<arg [^>]*>/   /;s/<[^>]*>//g' < $TMPF | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/^/"/' -e 's/$/\\n"/' >> $COMMAND_FILE
+	sed 's/<arg [^>]*>/   /;s/<[^>]*>//g' < $TMPF |
+	    sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/^/"/' -e 's/$/\\n"/' \
+		>> $COMMAND_FILE
 	echo ');' >> $COMMAND_FILE
     fi
 

Added: trunk/nfsim/doc/gen-usage
===================================================================
--- trunk/nfsim/doc/gen-usage	2004-12-16 03:18:54 UTC (rev 3404)
+++ trunk/nfsim/doc/gen-usage	2004-12-16 05:27:02 UTC (rev 3405)
@@ -0,0 +1,58 @@
+#! /bin/sh
+
+# read a list of C files with inline XML usage given on the command line, and
+# write a usage function on stdout
+
+tmpf=`mktemp /tmp/nfsim_gen-help.XXXXXX`
+trap "rm -f $tmpf*" EXIT
+quote() {
+    sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/^/"/' -e 's/$/\\n"/'
+}
+
+cat <<EOF
+#include <stdio.h>
+#include "usage.h"
+
+static const char *usagestr =
+"Usage %s [options]\n"
+"Options available:\n"
+"\n"
+EOF
+
+for file in "$@"
+do
+    echo "Extracting usage from $file" >&2
+    for line in `fgrep -n '/*** XML Argument:' < $file | cut -d: -f1`;
+    do
+	if [ -L doc/link-dtd ]; then
+
+	    cat > $tmpf <<EOF
+<?xml version="1.0"?>
+<!DOCTYPE article PUBLIC "-//OASIS//DTD Docbook XML V4.1.2//EN"
+"`pwd`/doc/link-dtd/docbookx.dtd">
+<article>
+EOF
+	    doc/extract-help $file $line >> $tmpf
+	    echo '</article>' >> $tmpf
+
+	    tr '\n' ' ' < $tmpf | sed -e 's/[[:space:]]\{2,\}/ /g' |
+		xsltproc doc/usage.xsl - | fold -w80 -s > $tmpf.txt
+
+	    quote < $tmpf.txt
+	else
+	    # if we don't have docbook, just strip out the tags and grab
+	    # the first two lines
+	    doc/extract-help $file $line > $tmpf
+	    sed 's/<arg [^>]*>/   /;s/<[^>]*>//g;' < $tmpf | head -3 | quote
+	fi
+
+    done   
+done
+
+cat <<EOF
+;
+
+void print_usage(const char *progname) {
+	fprintf(stderr, usagestr, progname);
+}
+EOF


Property changes on: trunk/nfsim/doc/gen-usage
___________________________________________________________________
Name: svn:executable
   + *

Modified: trunk/nfsim/doc/simulator.xml
===================================================================
--- trunk/nfsim/doc/simulator.xml	2004-12-16 03:18:54 UTC (rev 3404)
+++ trunk/nfsim/doc/simulator.xml	2004-12-16 05:27:02 UTC (rev 3405)
@@ -179,6 +179,10 @@
     192.168.0.0/24 eth0      
     192.168.1.0/24 eth1
 ]]></screen>
+   <section id="arguments">
+    <title>Command-line arguments</title>
+    <!-- AUTOGENERATED USAGE GOES HERE -->
+   </section>
 
    <section id="commands">
     <title>Commands</title>

Modified: trunk/nfsim/doc/text.xsl
===================================================================
--- trunk/nfsim/doc/text.xsl	2004-12-16 03:18:54 UTC (rev 3404)
+++ trunk/nfsim/doc/text.xsl	2004-12-16 05:27:02 UTC (rev 3405)
@@ -23,10 +23,19 @@
 </xsl:text>
  </xsl:template>
 
+ <xsl:template match="subtitle">
+  <xsl:apply-templates/><xsl:text>
+</xsl:text>
+ </xsl:template>
+
  <xsl:template match="command|filename|varname|computeroutput|constant">
-  <xsl:apply-templates/><xsl:text> </xsl:text>
+  <xsl:apply-templates/>
  </xsl:template>
 
+ <xsl:template match="option">
+  <xsl:text>--</xsl:text><xsl:apply-templates/>
+ </xsl:template>
+
  <xsl:template match="screen">
   <xsl:text>
 </xsl:text><xsl:apply-templates/><xsl:text>
@@ -79,7 +88,8 @@
  <xsl:template match="replaceable">{<xsl:apply-templates/>}</xsl:template>
 
  
- <xsl:template match="sbr"><xsl:text>
+ <xsl:template match="sbr">
+  <xsl:text>
 </xsl:text>
 </xsl:template>
 

Added: trunk/nfsim/doc/usage.xsl
===================================================================
--- trunk/nfsim/doc/usage.xsl	2004-12-16 03:18:54 UTC (rev 3404)
+++ trunk/nfsim/doc/usage.xsl	2004-12-16 05:27:02 UTC (rev 3405)
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version="1.0">
+ <xsl:output method="text"/>
+ <xsl:strip-space elements="*"/>
+ <xsl:include href="text.xsl"/>
+		
+ <xsl:template match="section">
+  <xsl:apply-templates select="title"/>
+  <xsl:text>    </xsl:text><xsl:apply-templates select="subtitle"/>
+ </xsl:template>
+
+ <xsl:template match="para">
+  <xsl:apply-templates/>
+ </xsl:template>
+
+</xsl:stylesheet>




More information about the netfilter-cvslog mailing list