From d50a41b6ab3d05fe5605a3a3b50ff68f61059296 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 16 Mar 2020 03:01:06 +0000 Subject: CTAN sync 202003160301 --- obsolete/support/detex/Flex-patch | 9 + obsolete/support/detex/Makefile | 102 ++ obsolete/support/detex/README | 189 ++ obsolete/support/detex/detex.1l | 126 ++ obsolete/support/detex/detex.h | 44 + obsolete/support/detex/detex.l | 683 ++++++++ obsolete/support/detex/lexout.c | 2855 +++++++++++++++++++++++++++++++ obsolete/support/detex/os2/README | 7 + obsolete/support/detex/os2/detex-32.def | 3 + obsolete/support/detex/os2/detex.def | 2 + obsolete/support/detex/os2/makefile.os2 | 96 ++ obsolete/support/detex/states.sed | 17 + 12 files changed, 4133 insertions(+) create mode 100644 obsolete/support/detex/Flex-patch create mode 100644 obsolete/support/detex/Makefile create mode 100644 obsolete/support/detex/README create mode 100644 obsolete/support/detex/detex.1l create mode 100644 obsolete/support/detex/detex.h create mode 100644 obsolete/support/detex/detex.l create mode 100644 obsolete/support/detex/lexout.c create mode 100644 obsolete/support/detex/os2/README create mode 100644 obsolete/support/detex/os2/detex-32.def create mode 100644 obsolete/support/detex/os2/detex.def create mode 100644 obsolete/support/detex/os2/makefile.os2 create mode 100644 obsolete/support/detex/states.sed (limited to 'obsolete') diff --git a/obsolete/support/detex/Flex-patch b/obsolete/support/detex/Flex-patch new file mode 100644 index 0000000000..dd12337433 --- /dev/null +++ b/obsolete/support/detex/Flex-patch @@ -0,0 +1,9 @@ +From the DeTeX Home Page... + +Flex patch + +This patch has been incorporated into detex 2.7, so it is no longer +necessary. However, if you are using flex, you'll probably need to +change the link line in the make file to be + + ${CC} ${CFLAGS} -o $@ ${D_OBJ} -lfl diff --git a/obsolete/support/detex/Makefile b/obsolete/support/detex/Makefile new file mode 100644 index 0000000000..14db5fdabd --- /dev/null +++ b/obsolete/support/detex/Makefile @@ -0,0 +1,102 @@ +# Makefile for detex and delatex +# +# Daniel Trinkle +# Computer Science Department +# Purdue University +# +# Detex is a program to remove TeX and LaTeX constructs from text source. + +# Installation directory +# +DESTDIR = /usr/local/bin + +# Specify you favorite compiler +# +#CC = gcc + +# Compile time flags, just uncomment the necessary lines +# Some say GNU make does not correctly handle += -- you may have to use := +# +DEFS = +# +# Add -traditional for GNU cc on ISC 386/ix system and possibly others +# (reported by pinard@iro.umontreal.ca) +# +#DEFS += ${DEFS} -traditional +# +# Add -DHAVE_STRING_H for the SysV string manipulation routines +# +#DEFS += ${DEFS} -DHAVE_STRING_H +# +# Add -DMAXPATHLEN= if it is not defined in /usr/include/sys/param.h +# +#DEFS += ${DEFS} -DMAXPATHLEN=1024 +# +# Add -DNO_MALLOC_DECL if your system does not like the malloc() declaration +# in detex.l (reported by pinard@iro.umontreal.ca) +# +#DEFS += ${DEFS} -DNO_MALLOC_DECL +# +CFLAGS = -O ${DEFS} + +# Use your favorite lexical scanner +# +LEX = lex +#LEX = flex + +#LFLAGS = -8 -C + +LPR = lpr -p + +# Program names +# +PROGS = detex + +# Header files +# +HDR = detex.h + +# Sources +# +SRC = detex.l + +# Objects for various programs +# +D_OBJ = detex.o + +all: ${PROGS} + +detex: ${D_OBJ} + ${CC} ${CFLAGS} -o $@ ${D_OBJ} -ll + +detex.c: + sed -f states.sed detex.l > xxx.l + ${LEX} ${LFLAGS} xxx.l + rm -f xxx.l + mv lex.yy.c detex.c + +lexout.c: detex.c + mv detex.c lexout.c + +man-page: + troff -man detex.1l + +# If you want detex available as delatex, uncomment the last two lines of +# this target +install: detex + rm -f ${DESTDIR}/detex + install -c -m 775 -o binary -g staff -s detex ${DESTDIR} +# rm -f ${DESTDIR}/delatex +# ln ${DESTDIR}/detex ${DESTDIR}/delatex + +clean: + -rm -f a.out core *.s *.o ERRS errs .,* .emacs_[0-9]* + -rm -f ${PROGS} xxx.l lex.yy.c + +print: ${HDR} ${SRC} + ${LPR} Makefile ${HDR} ${SRC} + +# Dependencies +# +detex.c: detex.h +detex.c: detex.l diff --git a/obsolete/support/detex/README b/obsolete/support/detex/README new file mode 100644 index 0000000000..59fb6b558c --- /dev/null +++ b/obsolete/support/detex/README @@ -0,0 +1,189 @@ +Detex - Version 2.7 + +Detex is a program to remove TeX constructs from a text file. It recognizes +the \input command. + +This program assumes it is dealing with LaTeX input if it sees the string +"\begin{document}" in the text. It recognizes the \include and \includeonly +commands. + +This directory contains the following files: + +README - you're looking at it. + +Makefile - makefile for generating detex on a 4.2BSD Unix system. + +detex.1l - troff source for the detex manual page. + Assuming you have the -man macros, use "make man-page" to + generate it. + +detex.h - Various global definitions. These should be modified to suit + the local installation. + +detex.l - Lex and C source for the detex program. + +lexout.c - C code generated from detex.l using lex on a Sun (SunOS 4.1.1) + This can be useful for DOS, OS/2 or systems that don't have + lex. + +states.sed - sed(1) script to munge the state names in detex.l so that + reasonable names can be used in the source without causing + lex(1) to overflow. + +os2 - subdirectory containing support for compilation on + OS/2 and DOS systems + + +Feel free to redistribute this program, but distribute the complete contents +of this directory. The latest version is available at +http://www.cs.purdue.edu/homes/trinkle/detex/ Send comments and fixes +to me via email. + +Daniel Trinkle +Department of Computer Sciences +Purdue University +West Lafayette, IN 47907-1398 + +April 26, 1986 + +Modified -- June 4, 1986 +Changed so that it automatically recognizes LaTeX source and ignores several +environment modes such as array. + + +Modified (Version 2.0) -- June 30, 1984 +Now handles white space in sequences like "\begin { document }". Detex is not +as easily confused by such things as display mode ends and begins that don't +match up. + + +Modified -- September 19, 1986 +Added the "-e " option to ignore specified LaTeX +environments. + + +Modified -- June 30, 1987 +Added the "-n" no-follow option, to allow detex to ignore \input and \include +commands. Also changed the algorithm for locating the input files. It now +interprets the "." more reasonably (i.e. it is not always the beginning of an +extension). + + +Modified -- December 15, 1988 +Added handling of verbatim environment in LaTeX mode and added it to the list +of modes ignored by default. Because of limitations with lex, it was +necessary to shorten the names of some of the existing start states before +adding a new one (ugh). + + +Modified -- January 3, 1988 +Added ignore of \$ inside $$ (math) pair. + + +Modified (Version 2.2) -- June 25, 1990 +Control sequences are no longer replaced by space, but just removed. This +means accents no longer cause output words to be broken. The "-c" option was +added to show the arguments of \cite, \ref, and \pageref macros. This is +useful when using something like style on the output. + + +Modified (Version 2.3) -- September 7, 1990 +Fixed the handling of Ctl mode a little better and added an exception +for \index on suggestions from kcb@hss.caltech.edu (KC Border). Also +changed the value for DEFAULTINPUTS to coincide with a local change. + + +Modified -- February 10, 1991 +Added -t option to force TeX mode even when seeing the "\begin{document}" +string in the input. + + +Modified -- February 23, 1991 +Based on suggestions from pinard@iro.umontreal.ca (Francois Pinard), I +added support for the SysV string routines (-DUSG), added defines for +the flex lexical scanner (-DFLEX_SCANNER), changed NULL to '\0' when +using it as a character (his sys defined NULL as (void *)0), changed +the Makefile to use ${CC} instead of cc, and added comments about the +new compile time options. + + +Modified (Version 2.4) -- September 2, 1992 +Corrected the way CITEBEGIN worked. Due to serious braindeath I had +the condition wrong in the if test. It should be (fLatex && !fCite). +This solves the problem a couple people reported with amstex style +\ref entries. + +Added a preprocessing sed(1) command to replace all the long, easy to +read state names with short two letter state names (SA-S?) so that lex +won't overflow and I don't have to keep shortening the state names +every time I add one. If a state is added, it must also be added to +states.sed (order is important) along with its unique S? replacement. + +Added \pagestyle, \setcounter, and \verb handling from +K.Sattar@cs.exeter.ac.uk (Khalid Sattar). Also allows invocation as +"delatex" to force LaTeX mode. + +Applied patches from queinnec@cenatls.cena.dgac.fr (Philippe Queinnec) +to handle nested {}s in state (\bibitem, \cite, \index). + +Added special ligature handling (\aa, \ae, \oe, \l, \o, \i, \j, \ss) +at the suggestion of gwp@dido.caltech.edu (G. W. Pigman II). + +Cleaned up the comments on detex.h, added mathmatica to DEFAULTENV. + + +Modified (Version 2.5) -- January 28, 1993 +Leading spaces in macros are no longer stripped. This means +"foo\footnote{ bar}" comes out as "foo bar" instead of "foobar". + +Fixed special ligature handling so it works in cases line {\ss} instead of +just when followed by a space. + + +Modified (Version 2.6) -- July 30, 1993 +Added OS/2 port from hankedr@mail.auburn.edu (Darrel R Hankerson). + +Added handling of leading and trailing ':' in TEXINPUTS per the latest +TeX as suggested by jnp@tfl.dk (J|rgen N|rgaard). + +Changed the way the input path is constructed in SetInputPaths() so we +never try to modify a constant string. + +Changed the way the the ignore environment list is contructed in +SetEnvIgnore() so we never try to modify a constant string. + +Changed the USG define to HAVE_STRING_H. + +Fixed the states.sed script so it only replaces "Input" in the correct +places. I would like to use the \< \> word separator patterns but +they are not supported by all versions of sed. This as least works. + +Changed the detex.c target in the Makefile to use a temporary file +because I experienced problems (segmentation fault) with lex on +Solaris 2.1 when input was from stdin. + + +Modified (Version 2.7) -- September 10, 1997 +Removed line breaks in detex.l between a few patterns and actions. It +appears that flex is no longer able to handle this. Thanks to Anthony +Harris and Marty Leisner + for reporting this. + + +Porting notes -- March 30, 1992 +When using gcc, or compiling on a NeXT, you should compile with +-fwritable-strings. With the change to SetInputPaths() in 2.6 this +should no longer be necessary. + +On a NeXT, it has been reported that lex replaces the '\0' with NULL, +and then the compiler complains about it. I think this is an old bug +that is no longer applicable. + +July 30, 1993 +The flex scanner generator does not work because it does not handle +input buffering the same way as lex. I don't know of any reasonable +way to rewrite detex to get around this problem. + +May 25, 1995 +According to alain@ia1.u-strasbg.fr (Alain Ketterlin), using flex +allows 8-bit characters to be handled correctly. diff --git a/obsolete/support/detex/detex.1l b/obsolete/support/detex/detex.1l new file mode 100644 index 0000000000..93e7100574 --- /dev/null +++ b/obsolete/support/detex/detex.1l @@ -0,0 +1,126 @@ +.TH DETEX 1L "12 August 1993" "Purdue University" +.SH NAME +detex \- a filter to strip \fITeX\fP commands from a .tex file. +.SH SYNOPSIS +.B detex +[ \fB\-clnstw\fR ] [ \fB\-e\fI environment-list\fR ] [ \fIfilename\fR[.tex] ... ] +.SH DESCRIPTION +.I Detex +(Version 2.6) +reads each file in sequence, removes all comments and +.I TeX +control sequences +and writes the remainder on the standard output. +All text in math mode and display mode is removed. +By default, +.I detex +follows \\input commands. +If a file cannot be opened, a warning message is +printed and the command is ignored. +If the +.B \-n +option is used, no \\input or \\include commands will be processed. +This allows single file processing. +If no input file is given on the command line, +.I detex +reads from standard input. +.PP +If the magic sequence ``\\begin{document}'' appears in the text, +.I detex +assumes it is dealing with +.I LaTeX +source and +.I detex +recognizes additional constructs used in +.IR LaTeX . +These include the \\include and \\includeonly commands. +The +.B \-l +option can be used to force +.I LaTeX +mode and the +.B \-t +option can be used to force +.I TeX +mode regardless of input content. +.PP +Text in various environment modes of +.I LaTeX +is ignored. The default modes are array, eqnarray, equation, figure, +mathmatica, picture, table and verbatim. The +.B \-e +option can be used to specify a comma separated +.I environment-list +of environments to ignore. The list replaces the defaults so specifying an +empty list effectively causes no environments to be ignored. +.PP +The +.B \-c +option can be used in +.I LaTeX +mode to have detex echo the arguments to \\cite, +\\ref, and \\pageref macros. This can be useful when sending the output to +a style checker. +.PP +.I Detex +assumes the standard character classes are being used for +.IR TeX . +.I Detex +allows white space between control sequences +and magic characters like `{' when recognizing things like +.I LaTeX +environments. +.PP +If the +.B \-w +flag is given, the output is a word list, one `word' (string of two or more +letters and apostrophes beginning with a letter) +per line, and all other characters ignored. +Without \fB\-w\fR the output follows the original, +with the deletions mentioned above. Newline characters are +preserved where possible +so that the lines of output match the input as closely as possible. +.PP +The TEXINPUTS environment variable is used to find \\input and \\include +files. Like \fITeX\fP, it interprets a leading or trailing `:' as the default +TEXINPUTS. It does \fInot\fP support the `//' directory expansion magic sequence. +.PP +Detex now handles the basic \fITeX\fP ligatures as a special case, replacing the +ligatures with acceptable charater substitutes. This eliminates +spelling errors introduced by merely removing them. The ligatures are +\\aa, \\ae, \\oe, \\ss, \\o, \\l (and their upper-case +equivalents). The special "dotless" characters \\i and \\j are also +replaced with i and j respectively. +.PP +Note that previous versions of +.I detex +would replace control sequences with a space character to prevent words +from running together. +However, this caused accents in the middle of words to break words, generating +"spelling errors" that were not desirable. +Therefore, the new version merely removes these accents. +The old functionality can be essentially duplicated by using the +.B \-s +option. +.SH SEE ALSO +tex(1L) +.SH DIAGNOSTICS +Nesting of \\input is allowed but the number of opened files must not +exceed the system's limit on the number of simultaneously opened files. +.I Detex +ignores unrecognized option characters after printing a warning message. +.SH AUTHOR +Daniel Trinkle, Computer Science Department, Purdue University +.SH BUGS +.I Detex +is not a complete +.I TeX +interpreter, so it can be confused by some constructs. +Most errors result in too much rather than too little output. +.PP +Running \fILaTeX\fR +source without a ``\\begin{document}'' +through \fIdetex\fR may produce +errors. +.PP +Suggestions for improvements are (mildly) encouraged. diff --git a/obsolete/support/detex/detex.h b/obsolete/support/detex/detex.h new file mode 100644 index 0000000000..2ed7fbf1eb --- /dev/null +++ b/obsolete/support/detex/detex.h @@ -0,0 +1,44 @@ +/****** +** The following parameters should be modified as necessary +** MAXINCLIST - maximum number of files allowed in an \includeonly list +** +** DEFAULTINPUTS - this should be the same as the default TEXINPUTS +** CHPATHSEP - the path separator character in TEXINPUTS +** MAXINPUTPATHS - (arbitrary) number of separate paths in TEXINPUTS +** +** DEFAULTENV - list of LaTeX environments ignored +** CHENVSEP - the list separator character in the ignore envronment list +** MAXENVS - maximum number of environments listed in the ignore list +** CCHMAXENV - maximum count of characters in an environment name (LaTex) +******/ + +#define MAXINCLIST 40 + +#ifdef OS2 +#define DEFAULTINPUTS ".;/emtex/texinput" +#define CHPATHSEP ';' +#else +#define DEFAULTINPUTS ".:/usr/local/tex/inputs" +#define CHPATHSEP ':' +#endif +#define MAXINPUTPATHS 10 + +#define DEFAULTENV "array,eqnarray,equation,figure,mathmatica,picture,table,verbatim" +#define CHENVSEP ',' +#define MAXENVS 10 +#define CCHMAXENV 100 + +/****** +** These probably should not be changed +******/ + +#define CHOPT '-' +#define CHCITEOPT 'c' +#define CHENVOPT 'e' +#define CHLATEXOPT 'l' +#define CHNOFOLLOWOPT 'n' +#define CHSPACEOPT 's' +#define CHTEXOPT 't' +#define CHWORDOPT 'w' + +#define ERROR -1 diff --git a/obsolete/support/detex/detex.l b/obsolete/support/detex/detex.l new file mode 100644 index 0000000000..67b0266b61 --- /dev/null +++ b/obsolete/support/detex/detex.l @@ -0,0 +1,683 @@ +%{ +#ifndef lint +static char rcsid[] = "$Header: /p/src/local/bin/detex/RCS/detex.l,v 2.19 1997/09/10 18:12:37 trinkle Exp $"; +#endif + +/* + * detex [-e environment-list] [-c] [-l] [-n] [-s] [-t] [-w] [file[.tex]] + * + * This program is used to remove TeX or LaTeX constructs from a text + * file. + * + * Written by: + * Daniel Trinkle + * Department of Computer Science + * Purdue University + * + */ + +#include "detex.h" +#ifdef HAVE_STRING_H +#include +#define index strchr +#define rindex strrchr +#else +#include +#endif +#ifndef MAXPATHLEN +#include +#endif +#ifdef OS2 +#include +#endif + +#define LaBEGIN if (fLatex) BEGIN +#define CITEBEGIN if (fLatex && !fCite) BEGIN +#define IGNORE if (fSpace && !fWord) putchar(' ') +#define SPACE if (!fWord) putchar(' ') +#define NEWLINE if (!fWord) putchar('\n') + +char *SafeMalloc(); +#ifndef NO_MALLOC_DECL +char *malloc(); +#endif +#ifdef OS2 +void yyless(int); +#endif + +char *rgsbEnvIgnore[MAXENVS]; /* list of environments ignored */ +char *rgsbIncList[MAXINCLIST]; /* list of includeonly files */ +char *rgsbInputPaths[MAXINPUTPATHS]; /* list of input paths in order */ +char sbCurrentEnv[CCHMAXENV]; /* current environment being ignored */ +char *sbProgName; /* name we were invoked with */ +FILE *rgfp[NOFILE+1]; /* stack of input/include files */ +int cfp = 0; /* count of files in stack */ +int cOpenBrace = 0; /* count of `{' in */ +int csbEnvIgnore; /* count of environments ignored */ +int csbIncList = 0; /* count of includeonly files */ +int csbInputPaths; /* count of input paths */ +int fLatex = 0; /* flag to indicated delatex */ +int fWord = 0; /* flag for -w option */ +int fFollow = 1; /* flag to follow input/include */ +int fCite = 0; /* flag to echo \cite and \ref args */ +int fSpace = 0; /* flag to replace \cs with space */ +int fForcetex = 0; /* flag to inhibit latex mode */ +%} + +S [ \t\n]* +W [a-zA-Z]+ + +%Start Define Display IncludeOnly Input Math Normal Control +%Start LaBegin LaDisplay LaEnd LaEnv LaFormula LaInclude +%Start LaMacro LaMacro2 LaVerbatim + +%% +"%".* /* ignore comments */ ; + +"\\begin"{S}"{"{S}"document"{S}"}" {fLatex = !fForcetex; IGNORE;} + +"\\begin" /* environment start */ {LaBEGIN LaBegin; IGNORE;} + +{S}"{"{S}"verbatim"{S}"}" { if (BeginEnv("verbatim")) + BEGIN LaEnv; + else + BEGIN LaVerbatim; + IGNORE; + } + +"\\end"{S}"{"{S}"verbatim"{S}"}" /* verbatim mode */ {BEGIN Normal; IGNORE;} +. ECHO; + +{W} { if (BeginEnv(yytext)) + BEGIN LaEnv; + else + BEGIN LaMacro; + IGNORE; + } +"\n" NEWLINE; +. ; + +"\\end" /* absorb some environments */ {LaBEGIN LaEnd; IGNORE;} +"\n" NEWLINE; +. ; + +{W} /* end environment */ { if (EndEnv(yytext)) + BEGIN Normal; + IGNORE; + } +"}" {BEGIN LaEnv; IGNORE;} +"\n" NEWLINE; +. ; + +"\\bibitem" /* ignore args */ {LaBEGIN LaMacro2; IGNORE;} +"\\bibliography" /* of these \cs */ {LaBEGIN LaMacro; IGNORE;} +"\\bibstyle" {LaBEGIN LaMacro; IGNORE;} +"\\cite" {CITEBEGIN LaMacro2; IGNORE;} +"\\documentstyle" {LaBEGIN LaMacro; IGNORE;} +"\\end" {LaBEGIN LaMacro; IGNORE;} +"\\footnote" {SPACE;} +"\\index" {LaBEGIN LaMacro2; SPACE;} +"\\label" {LaBEGIN LaMacro; IGNORE;} +"\\pageref" {CITEBEGIN LaMacro; IGNORE;} +"\\pagestyle" {LaBEGIN LaMacro; IGNORE;} +"\\ref" {CITEBEGIN LaMacro; IGNORE;} +"\\setcounter" {LaBEGIN LaMacro; IGNORE;} +"\\verb" /* ignore \verb... */ { if (fLatex) { + char verbchar, c; + verbchar = input(); + while ((c = input()) != verbchar) + if (c == '\n') + NEWLINE; + } + IGNORE; + } +"}" BEGIN Normal; +"\n" NEWLINE; +. ; +"{" { cOpenBrace++; } +"}" { cOpenBrace--; + if (cOpenBrace == 0) + BEGIN Normal; + } +"\n" NEWLINE; +. ; + +"\\def" /* ignore def begin */ {BEGIN Define; IGNORE;} +"{" BEGIN Normal; +"\n" NEWLINE; +. ; + +"\\(" /* formula mode */ {LaBEGIN LaFormula; IGNORE;} +"\\)" BEGIN Normal; +"\n" NEWLINE; +. ; + +"\\[" /* display mode */ {LaBEGIN LaDisplay; IGNORE;} +"\\]" BEGIN Normal; +"\n" NEWLINE; +. ; + +"$$" /* display mode */ {BEGIN Display; IGNORE;} +"$$" BEGIN Normal; +"\n" NEWLINE; +. ; + +"$" /* math mode */ {BEGIN Math; IGNORE;} +"$" BEGIN Normal; +"\n" NEWLINE; +"\\$" ; +. ; + +"\\include" /* process files */ {LaBEGIN LaInclude; IGNORE;} +[^{ \t\n}]+ { IncludeFile(yytext); + BEGIN Normal; + } +"\n" NEWLINE; +. ; + +"\\includeonly" {BEGIN IncludeOnly; IGNORE;} +[^{ \t,\n}]+ AddInclude(yytext); +"}" { if (csbIncList == 0) + rgsbIncList[csbIncList++] = '\0'; + BEGIN Normal; + } +"\n" NEWLINE; +. ; + +"\\input" {BEGIN Input; IGNORE;} +