summaryrefslogtreecommitdiff
path: root/web/spiderweb/tools/excerpt
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /web/spiderweb/tools/excerpt
Initial commit
Diffstat (limited to 'web/spiderweb/tools/excerpt')
-rw-r--r--web/spiderweb/tools/excerpt/excerpt54
-rw-r--r--web/spiderweb/tools/excerpt/excerpt.doc31
-rw-r--r--web/spiderweb/tools/excerpt/filesplit.web163
-rw-r--r--web/spiderweb/tools/excerpt/section.c70
4 files changed, 318 insertions, 0 deletions
diff --git a/web/spiderweb/tools/excerpt/excerpt b/web/spiderweb/tools/excerpt/excerpt
new file mode 100644
index 0000000000..8a956d80c4
--- /dev/null
+++ b/web/spiderweb/tools/excerpt/excerpt
@@ -0,0 +1,54 @@
+#!/bin/sh
+# Take excerpts from a TeX file generated by Weave
+
+LIB=$HOME/lib/`cputype`
+
+if [ $# -ne 1 ]; then
+ echo "Usage: excerpt name" 1>&2
+ exit 1
+fi
+
+if [ -r $1.tex ]; then
+ lines=`sed '/^ *\([0-9]*\).*\\N[0-9]*[.] *\([^ ]\)\([^.]*\)[.].*$/!d
+/^ *\([0-9]*\).*\\N[0-9]*[.] *\([^ ]\)\([^.]*\)[.].*$/=
+s/^.*\\N[0-9]*[.] *\([^ ]\)\([^.]*\)[.].*$/\1 \2/
+' $1.tex | awk 'BEGIN { FS=" " # tab
+ OFS=" " # tab
+ level["="]=-1
+ level["1"]=1
+ level["2"]=2
+ level["3"]=3
+ level["4"]=4
+ }
+NF==1 {line=$1}
+NF==2 {
+# print "\"" $1 "\"", level[$1]
+ if (level[$1]==0) {
+ name = $1 $2
+ } else {
+ name = $2
+ }
+
+ print line
+ print level[$1]+1
+ print name
+ }' | $LIB/section`
+ while true; do
+ echo -n "Did you include the index in the excerpts [ny]? " 1>&2
+ read reply
+ if [ "$reply" = "" ]; then reply="n" ; fi
+ case $reply in
+ [ny]) break ;;
+ *) echo "respond with y or n" 1>&2 ;;
+ esac
+ done
+ echo Splitting $1.tex... 1>&2
+ $LIB/filesplit - $lines < $1.tex > $1-excerpts.tex
+ if [ "$reply" = "n" ]; then
+ echo \\inx\\fin\\con >> $1-excerpts.tex
+ fi
+else
+ echo "I can't find the file $1.tex" 1>&2
+ exit 1
+fi
+
diff --git a/web/spiderweb/tools/excerpt/excerpt.doc b/web/spiderweb/tools/excerpt/excerpt.doc
new file mode 100644
index 0000000000..1a0839cbb5
--- /dev/null
+++ b/web/spiderweb/tools/excerpt/excerpt.doc
@@ -0,0 +1,31 @@
+excerpt allows you to extract pieces of a tex file generated by weave.
+Like the TeX macros, excerpt recognizes the following hierarchy of
+section names:
+ In Text In Contents
+ #*= major division new page Bold title
+ #* ordinary section new page standard title
+ #*1 subsection new page indented
+ #*2 subsection same page indented
+ #*3 subsection new page double-indented
+ #*4 subsection same page double-indented
+
+Each kind of section is said to ``contain'' all sections below it in
+the table. Thus if you have a WEB file with a section called
+``#*=Abstract Syntax.'', that section will contain all of the sections
+up to (and not including) the next #*=. excerpt makes heavy use of
+containment.
+
+If you type `excerpt vcgen', the program will go through a list of all
+of the sections in vcgen.tex, asking you whether you want to include
+each one. You may reply `y' (yes), `n' (no), or `a' (all). Or you
+may hit the carriage return and get the default (all). The replies
+have the following meanings:
+
+ y include the section, and ask about contained subsections
+ n omit this section, along with all the sections it contains
+ a include this section and all the sections it contains
+
+The output is written to `vcgen-excerpts.tex', and must be run through
+TeX and dvi in the usual way. Of course you can use any name, not
+just vcgen.
+
diff --git a/web/spiderweb/tools/excerpt/filesplit.web b/web/spiderweb/tools/excerpt/filesplit.web
new file mode 100644
index 0000000000..23e37eaac9
--- /dev/null
+++ b/web/spiderweb/tools/excerpt/filesplit.web
@@ -0,0 +1,163 @@
+@*Splitting mailing lists.
+The object of the game is to split mailing lists into multiple files.
+Usage is
+$$\hbox{\tt filesplit prefix numbers}$$
+where {\tt prefix} is the prefix of all the output file names, and
+{\tt numbers} is a list of line numbers on which pieces of the file begin.
+The first line of the file is considered line~1
+(for compatibility with {\tt awk(1)}).
+The numbers must be sorted in increasing order.
+A section consists of material from one number to the next.
+The material is printed in a file whose name begins with the {\tt prefix},
+and which ends with a unique suffix (e.g. {\tt 00001, 00002, ...}).
+
+If a section number is preceded by a minus sign,
+the section beginning with that line number gets thrown on the floor
+instead of printed.
+
+If the prefix is |"-"|, we write all the writable sections to standard
+output.
+This makes it posssible to extract just pieces of a file.
+@<Print usage message and exit@>=
+fprintf(stderr,"Usage:\n");
+fprintf(stderr,"\tfilesplit prefix numbers...\n");
+exit(1);
+
+
+@ @c
+#include <stdio.h>
+main (argc, argv)
+ int argc;
+ char ** argv;
+{
+ char *prefix;
+ @<Variable declarations@>;
+
+
+ if (argc--<3) {
+ @<Print usage message and exit@>;
+ }
+
+ prefix = *++argv;
+ argc--, argv++;
+ @<With |argc=number count| and |argv| pointing to list, process
+ standard input into files@>;
+ exit(0);
+}
+
+@ With only one number left in the list, our job is to print from that
+line to end of file.
+Otherwise, we have two numbers, which we'll call |from_line| and |to_line|.
+We'll track the current line with |this_line|, which will be the number of
+next line schedule to be written to the output (or thrown on the floor).
+We have an implicit initial {\tt -1}, i.e. we don't print the initial
+segment of the file.
+@<Variable dec...@>=
+ int from_line, to_line;
+ int this_line; /* the number of the next line scheduled to be
+ printed */
+
+@
+@<With |argc=number count| and |argv| pointing to list, process
+ standard input into files@>=
+multi_output=1;
+@<If |prefix=="-"|, make |stdout| the output file and set |multi_output=0|@>;
+printing=0;
+from_line=0;
+this_line=1;
+while (argc!=0) {
+ @<Read an argument into |to_line|, set |next_printing|,
+ check for order,
+ and advance |argv|@>;
+ @<If |printing && multi_output|,
+ choose a name for the output file and open it@>;
+ while (this_line != to_line) {
+ @<Copy current line to output file
+ (or throw out if not |printing|)
+ and advance |this_line|,
+ jumping to |finish| on end of file@>;
+ }
+ @<If |printing && multi_output|, close the output file@>;
+ from_line = to_line;
+ printing = next_printing;
+ }
+@<If |printing && multi_output|,
+ choose a name for the output file and open it@>;
+while (1) {
+ @<Copy current line to output file...@>;
+ }
+finish:
+ @<Yelp if we ended prematurely@>;
+
+
+@ We ended prematurely if |from_line!=to_line|.
+@<Yelp...@>=
+if (from_line != to_line)
+ fprintf(stderr,"filesplit: premature end of file\n");
+
+
+
+
+@ We might as well get the details of the output files done with now.
+@<Variable dec...@>=
+ FILE *output;
+ char filename[255];
+ int sequence_number=0;
+ int multi_output;
+@ @<If |prefix=="-"|, make |stdout| the output file and set |multi_output=0|@>=
+if (!strcmp(prefix,"-")) {
+ output=stdout;
+ multi_output=0;
+ }
+
+@ @<If |printing && multi_output|, choose a name...@>=
+if (printing && multi_output) {
+ sprintf(filename,"%s%05d", prefix, sequence_number++);
+ if ((output=fopen(filename,"w"))==NULL) {
+ @<Print an error message and exit@>;
+ }
+ }
+
+@ @<If |printing && multi_output|, close the output file@>=
+if (printing && multi_output) fclose(output);
+
+@ Here's how the copying works
+@<Copy current line to output file...@>=
+while ((c=getchar())!=EOF) {
+ if (printing) putc(c,output);
+ if (c=='\n') {
+ this_line++;
+ break;
+ }
+ }
+if (c==EOF) goto finish;
+@ @<Variable dec...@>=char c;
+
+@ Since we determine sign when we read the target, we save the sign to set
+|printing| the next time around.
+@<Variable dec...@>=int printing, next_printing;
+
+
+
+@ Here's our argument processing:
+@ @<Read an argument into |to_line|...@>=
+sscanf(*argv++,"%d",&to_line); argc--;
+if (to_line<0) {
+ to_line = - to_line;
+ next_printing = 0;
+ }
+else {
+ next_printing=1;
+ }
+
+if (to_line <= from_line) {
+ fprintf(stderr,"filesplit: numbers out of order\n");
+ exit(-1);
+ }
+
+
+@ @<Print an error message and exit@>=
+fprintf(stderr,"filesplit: I couldn't open a file or something\n");
+exit(-1);
+
+@*Index.
diff --git a/web/spiderweb/tools/excerpt/section.c b/web/spiderweb/tools/excerpt/section.c
new file mode 100644
index 0000000000..355cf9a2a9
--- /dev/null
+++ b/web/spiderweb/tools/excerpt/section.c
@@ -0,0 +1,70 @@
+#include <stdio.h>
+main() {
+ FILE * ttyin, *ttyout;
+ char buffer[800];
+ char ttybuffer[80];
+ int line;
+ int level,skiplevel;
+ int skipping=0;
+ int all=0;
+ char *name = buffer;
+
+#define barf fprintf(stderr,"section: file error\n"); exit(1);
+ if (NULL==(ttyin=fopen("/dev/tty","r"))) {
+ barf;
+ }
+ if (NULL==(ttyout=fopen("/dev/tty","w"))) {
+ barf;
+ }
+ printf("1 ");
+ level=skiplevel=99;
+ while (gets(buffer)!=NULL) {
+ sscanf(buffer,"%d", &line);
+ if (gets(buffer)==NULL) {barf;}
+ sscanf(buffer,"%d", &level);
+ if (gets(buffer)==NULL) {barf;}
+/* fprintf(ttyout,"Checking level %d section on line %4d \"%s\"\n",
+/* level, line, name);
+/* fprintf(ttyout,"skipping=%d and skiplevel=%d\n", skipping,skiplevel);
+ */
+ if ((!skipping) || level <= skiplevel) {
+ if (all && level>skiplevel) {
+ fprintf(ttyout," includes \"%s\"...\n", name);
+ } else {
+ int querycount=0;
+ skiplevel=level;
+ *ttybuffer='X';
+ while (*ttybuffer !='y' && *ttybuffer != 'n' && *ttybuffer != 'a'
+ && *ttybuffer != '\0') {
+ fprintf(ttyout,"Print level %d section \"%s\" [ayn]? ",
+ level, name);
+ fflush(ttyout);
+ fgets(ttybuffer,80,ttyin);
+ if (++querycount>10) {
+ fprintf(ttyout,
+ "If you won't type 'y', 'n', 'a', or <CR>, I'll just quit\n");
+ exit(8);
+ }
+
+ }
+ if (*ttybuffer=='n') {
+ if (!skipping) printf ("%d ", -line);
+ skipping = 1;
+ all = 0;
+ } else if (*ttybuffer=='a' || *ttybuffer=='\0') {
+ if (skipping) printf ("%d ", line);
+ skipping = 0;
+ all=1;
+ } else {
+ if (skipping) printf ("%d ", line);
+ skipping = 0;
+ all=0;
+ }
+ }
+ }
+ }
+}
+
+
+
+