summaryrefslogtreecommitdiff
path: root/web/schemeweb2
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/schemeweb2
Initial commit
Diffstat (limited to 'web/schemeweb2')
-rw-r--r--web/schemeweb2/Makefile42
-rw-r--r--web/schemeweb2/README132
-rw-r--r--web/schemeweb2/example/Makefile5
-rw-r--r--web/schemeweb2/example/SampleOfInclusion.sw3
-rw-r--r--web/schemeweb2/example/main.sw43
-rw-r--r--web/schemeweb2/sweb.1186
-rw-r--r--web/schemeweb2/sweb.c488
-rw-r--r--web/schemeweb2/sweb.make53
8 files changed, 952 insertions, 0 deletions
diff --git a/web/schemeweb2/Makefile b/web/schemeweb2/Makefile
new file mode 100644
index 0000000000..b179ad706c
--- /dev/null
+++ b/web/schemeweb2/Makefile
@@ -0,0 +1,42 @@
+# SchemeWEB Makefile
+# $Id: Makefile,v 2.0 1994/02/25 13:50:51 ramsdell Exp $
+
+CC=gcc
+CFLAGS = -O -ansi
+srcdir = .
+VPATH = .
+INSTALL = cp
+INSTALL_PROGRAM = $(INSTALL)
+INSTALL_DATA = $(INSTALL)
+
+prefix = $(HOME)
+exec_prefix = $(prefix)
+bindir = $(exec_prefix)/bin
+mandir = $(prefix)/man
+manext = 1
+
+SHELL=/bin/sh
+DISTFILES=Makefile README sweb.c sweb.1 reader.sw
+
+all: sweb
+
+sweb: sweb.c
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(srcdir)/sweb.c
+
+install: sweb sweb.1
+ $(INSTALL_PROGRAM) sweb $(bindir)/sweb
+ $(INSTALL_DATA) sweb.1 $(mandir)/man$(manext)/sweb.$(manext)
+
+uninstall:
+ rm $(bindir)/sweb
+ rm $(mandir)/man$(manext)/sweb.$(manext)
+
+dist: schemeweb.sh
+
+schemeweb.sh: $(DISTFILES)
+ shar $(DISTFILES) > $@
+
+clean:
+ -rm sweb
+
+.PHONY: all install uninstall dist clean
diff --git a/web/schemeweb2/README b/web/schemeweb2/README
new file mode 100644
index 0000000000..59db18a1e3
--- /dev/null
+++ b/web/schemeweb2/README
@@ -0,0 +1,132 @@
+SchemeWEB2 is largely based on SchemeWEB.
+
+The only change for installation is that the default prefix directory
+is $HOME. For other changes, refer to the man page.
+
+Here is what the README of SchemeWEB says :
+
+--------------------------------------------------------------------
+
+$Id: README,v 2.1 94/07/22 07:00:10 ramsdell Exp $
+
+SchemeWEB---Simple support for literate programming in Lisp.
+
+SchemeWEB is a Unix filter that allows you to generate both Lisp and
+LaTeX code from one source file. The generated LaTeX code formats
+Lisp programs in typewriter font obeying the spacing in the source
+file. Comments can include arbitrary LaTeX commands. SchemeWEB was
+originally developed for the Scheme dialect of Lisp, but it can easily
+be used with most other dialects.
+
+Version 2.1 implements several improvements over the version 1.2 which
+was released in 1990.
+
+* The LaTeX source generated from a SchemeWEB file no longer requires
+the use of a style option, such as the astyped option required by the
+previous version. The output is similar to that produced by c2latex.
+
+* By default, Lisp source generated from a SchemeWEB file includes all
+comments. As a result, the filter can translate the Lisp source
+generated from a SchemeWEB file directly into LaTeX source.
+
+* The filter can translate the Lisp source generated from a SchemeWEB
+file into the original SchemeWEB file.
+
+As a result of these changes, a SchemeWEB file can be stored and
+distributed as a standard Lisp file by tangling the SchemeWEB file.
+For the purposes of editing comments, the SchemeWEB file can be
+recovered by untangling the Lisp file. LaTeX documentation can be
+generated from both the Lisp file or the SchemeWEB file.
+
+Version 2.1 patches version 2.0 so it now correctly formats strings
+which span more than one line of text.
+
+Installation:
+
+1) Create the executable by typing:
+
+ make
+
+2) Install the executable and the manual page by typing:
+
+ make install
+
+By default the makefile will install the executable in $(prefix)/bin
+and the manual page in $(prefix)/man/man1, where prefix=/usr/local.
+You can change the prefix by typing:
+
+ make prefix=<Your path> install
+
+You can also change the installation targets by editing the makefile.
+
+3) You can modify the reader used by your Lisp system's standard LOAD
+so that it can read SchemeWEB files directly. To make this change,
+follow the model given in "reader.sw", a reader of SchemeWEB source
+for the R4RS dialect of Scheme.
+
+A formatted version of the manual page follows.
+
+-----------------------------------------------------------------
+
+sweb(1) USER COMMANDS sweb(1)
+
+
+
+NAME
+ sweb - Simple support for literate programming in Lisp.
+
+SYNOPSIS
+ sweb [-stuvwx] [input_file [output_file]]
+
+DESCRIPTION
+ A SchemeWEB file is a Lisp source file which contains code
+ sections and comment sections, but each section is identi-
+ fied in a novel way. A code section begins with a line
+ whose first character is a left parenthesis. It continues
+ until a line is found which contains the parenthesis that
+ matches the one which started the code section. The remain-
+ ing lines of text in the source file are treated as com-
+ ments.
+
+ Several operations involving SchemeWEB files are provided by
+ the sweb program.
+
+ The -t option translates a SchemeWEB file into a standard
+ Lisp file. It simply adds an initial semicolon to comment
+ lines that lack them, and passes code sections through
+ unchanged. This process is called tangling the SchemeWEB
+ file.
+
+ The -w option translates a SchemeWEB file into a LaTeX
+ source file. Text is added to code sections so that LaTeX
+ will print the code verbatim. Comment sections are passed
+ through unchanged except that if the first character of a
+ line is a semicolon, it is excised. This makes it possible
+ to process a SchemeWEB file which has been tangled. This
+ process is called weaving the SchemeWEB file. This is the
+ default action of sweb.
+
+ The -x option weaves a SchemeWEB file as above, except the
+ LaTeX source produced inhibits page breaks in code sections.
+
+ The -u option translates a Lisp file which has been produced
+ from a SchemeWEB file back into a SchemeWEB file. It simply
+ removes the first semicolon in every line that starts with
+ one as its first character. This process is called untan-
+ gling a sweb produced Lisp file.
+
+ The -s option tangles a SchemeWEB file and strips all com-
+ ments from the file.
+
+ The -v option prints version information.
+
+ A SchemeWEB file can be stored and distributed as a standard
+ Lisp file by tangling the SchemeWEB file. For the purposes
+ of editing comments, the SchemeWEB file can be recovered by
+ untangling the Lisp file. LaTeX documentation can be
+ generated from both the Lisp file or the SchemeWEB file.
+
+ SchemeWEB was originally developed for the Scheme dialect of
+ Lisp; however, it became obvious that no changes were
+ required to support most other dialects. SchemeWEB's name
+ reflects its heritage.
diff --git a/web/schemeweb2/example/Makefile b/web/schemeweb2/example/Makefile
new file mode 100644
index 0000000000..2a07565d8a
--- /dev/null
+++ b/web/schemeweb2/example/Makefile
@@ -0,0 +1,5 @@
+TEXFILE = main.tex
+
+include ../sweb.make
+
+
diff --git a/web/schemeweb2/example/SampleOfInclusion.sw b/web/schemeweb2/example/SampleOfInclusion.sw
new file mode 100644
index 0000000000..b72be34c00
--- /dev/null
+++ b/web/schemeweb2/example/SampleOfInclusion.sw
@@ -0,0 +1,3 @@
+This is an example of inclusion within SchemeWEB document, which ends
+right here.
+
diff --git a/web/schemeweb2/example/main.sw b/web/schemeweb2/example/main.sw
new file mode 100644
index 0000000000..a6da8ec3fc
--- /dev/null
+++ b/web/schemeweb2/example/main.sw
@@ -0,0 +1,43 @@
+\documentclass[a4paper]{article}
+
+\title{Example of SchemeWEB file}
+
+\begin{document}
+
+\maketitle
+
+\section{Introduction}
+Welcome to SchemeWEB.
+
+\section{Comment sections}
+Here, we are in comment section, so, the text can be formated with
+LaTeX.
+
+For example, we can say that ${(a + b)}^2 = a^2 + 2ab + b^2$, and use
+any other commands.
+
+\section{Code section}
+
+If a line begins with a '(', then, a code section begins, like in
+
+(define (foo bar)
+ #f)
+
+The comments inside code section are also considered as LaTeX source,
+so, you can write things like
+
+(define (f alpha) ; Returns $2 * \alpha$
+ (* alpha 2))
+
+\section{File inclusion}
+
+Off course, you can include other documents as usual with
+\verb!\input! :
+
+\input{SampleOfInclusion}
+
+Enjoy yourself with SchemeWEB !
+
+\tableofcontents
+
+\end{document}
diff --git a/web/schemeweb2/sweb.1 b/web/schemeweb2/sweb.1
new file mode 100644
index 0000000000..81c160c0b6
--- /dev/null
+++ b/web/schemeweb2/sweb.1
@@ -0,0 +1,186 @@
+.TH sweb 1
+
+.SH NAME
+sweb \- Simple support for literate programming in Lisp.
+.SH SYNOPSIS
+.B sweb
+[-stuvwxh]|[-ss] [input_file [output_file]]
+.SH DESCRIPTION
+A SchemeWEB2 file is a Lisp source file which contains code sections
+and comment sections, but each section is identified in a novel way.
+A code section begins with a line whose first character is a left
+parenthesis.
+It continues until a line is found which contains the
+parenthesis that matches the one which started the code section.
+The remaining lines of text in the source file are treated as comments.
+
+Several operations involving SchemeWEB2 files are provided by the
+.B sweb
+program.
+.PP
+The
+.B \-t
+option translates a SchemeWEB2 file into a standard Lisp file.
+It simply adds an initial semicolon to comment lines that lack them, and
+passes code sections through unchanged.
+This process is called tangling the SchemeWEB2 file.
+.PP
+The
+.B \-w
+option translates a SchemeWEB2 file into a LaTeX source file.
+Text is added to code sections so that LaTeX will print the code verbatim.
+Comment sections are passed through unchanged except that if the first
+character of a line is a semicolon, it is excised.
+This makes it possible to process a SchemeWEB2 file which has been tangled.
+This process is called weaving the SchemeWEB2 file.
+This is the default action of
+.B sweb.
+Inside code, the comments, as in
+.P
+ (define (foo x y) ; Returns ${x + y \\over 2}$
+ (/ (+ x y) 2))
+.P
+are threated as LaTeX source code, and will be properly formated when
+you call LaTeX on the weaved file.
+The exception to this is that any '#' character inside code section
+will be backslashify-ed (transformed into '\\#'). This makes it
+possible to write things like
+.P
+ (define (false) #f) ; Allways returns #f
+
+ (define debug #t)
+ ;(define debug #f)
+.P
+without having to care about the '#'. You still can use the '#' as a
+special character inside comment section.
+.P
+The '%' inside comments, like in
+.P
+ (define foo bar) ; % This is a comment \\anything $
+.P
+Are threated as real comments, e.g. any text between it and the end of
+line is ignored. This is the best way for commenting portions of
+unused code.
+.PP
+The
+.B \-x
+option weaves a SchemeWEB2 file as above, except the LaTeX source
+produced inhibits page breaks in code sections.
+.PP
+The
+.B \-u
+option translates a Lisp file which has been produced from a
+SchemeWEB2 file back into a SchemeWEB2 file.
+It simply removes the first semicolon in every line that starts with
+one as its first character.
+This process is called untangling a
+.B sweb
+produced Lisp file.
+.PP
+The
+.B \-s
+option tangles a SchemeWEB2 file and strips all comments from the file.
+.PP
+The
+.B \-ss
+option tangles a SchemeWEB2 as with
+.B \-s
+but the comments inside a code section are kept. This is usefull if your scheme code has to be read, and if
+you think the comment section is too large.
+.PP
+The
+.B \-v
+option prints version information.
+.PP
+A SchemeWEB2 file can be stored and distributed as a standard Lisp
+file by tangling the SchemeWEB2 file.
+For the purposes of editing comments, the SchemeWEB2 file can be
+recovered by untangling the Lisp file.
+LaTeX documentation can be generated from both the Lisp file or the
+SchemeWEB2 file.
+.PP
+If you use Emacs as a text editor, I suggest that you add the
+following lines to your
+.B .emacs
+.P
+ (add-to-list 'auto-mode-alist
+ (cons "\\.sw\\'" 'scheme-mode))
+ (add-hook 'latex-mode-hook
+ '(lambda () (local-set-key [f12] 'scheme-mode)))
+ (add-hook 'scheme-mode-hook
+ '(lambda () (local-set-key [f12] 'latex-mode)))
+.P
+Then, you will automatically load the scheme mode on SchemeWEB2 files
+(*.sw). You will swap from scheme mode to latex mode by pressing f12.
+.PP
+SchemeWEB2 was originally developed for the Scheme dialect of Lisp;
+however, it became obvious that no changes were required to support
+most other dialects.
+SchemeWEB2's name reflects its heritage.
+
+.SH SAMPLE OF MAKEFILE FOR SchemeWEB2
+
+You will find with the sources of SchemeWEB2 a file called sweb.make.
+
+This is a sample Makefile for use with SchemeWEB(2)
+To use it, create a new file called Makefile in the directory
+containing the SchemeWEB files, whose name should end by '.sw'
+inside this file, add the line
+
+TEXFILE = XXX.tex [ YYY.tex ZZZ.tex ... ]
+
+Where XXX.tex YYY.tex and ZZZ.tex are the name of your main tex
+files (those you which to compile with 'LaTeX XXX.tex')
+
+then, add the line
+
+include <prefix-dir>/sweb.make
+
+where <prefix-dir> is the name of the directory containing the
+present file. You can now compile with 'make', 'make dvi',
+'make ps', 'make html', or clean the directory with 'make clean' (but be
+carefull with this option !)
+
+
+.SH CHANGES FROM SchemeWEB TO SchemeWEB2
+
+The
+.B \-ss
+option has been added.
+.P
+A comment has been added to the begining of any generated files to
+prevent accidental modification of them.
+.P
+The '#' characters are backslashifyed when weaving comments inside
+code section.
+.P
+The end of line inside strings are now correctly managed while
+weaving.
+.P
+The '%' characters inside comments are considered as LaTeX comments.
+.P
+The
+.B \-h
+option has been added to show the help message.
+.P
+A sample Makefile is provided to make it easy to keep
+.B .scm
+and
+.B .tex
+files up to date, and generate dvi, ps, and html documentation.
+.P
+The error messages have been reformated for compatibility with Emacs
+compilation mode. (<file name>:<line nb>: ...)
+.P
+The program has been renamed to keep the old version availlable in
+case people prefer it.
+
+
+.SH BUG REPORT and COMMENTS
+
+If you have any comments about this new version of SchemeWEB, please
+contact me at matthieu.moy@ensimag.imag.fr.
+
+
+
+
diff --git a/web/schemeweb2/sweb.c b/web/schemeweb2/sweb.c
new file mode 100644
index 0000000000..4f9ba55900
--- /dev/null
+++ b/web/schemeweb2/sweb.c
@@ -0,0 +1,488 @@
+/* SchemeWEB2 --- Matthieu MOY matthieu.moy@ensimag.imag.fr
+ * Largely based on
+ * SchemeWEB -- WEB for Lisp. John D. Ramsdell.
+ * Simple support for literate programming in Lisp.
+ */
+
+/* Any people who want to include pretty print to this software is welcome */
+
+/* $Id: sweb.c,v 2.1 94/07/21 11:30:36 ramsdell Exp $ */
+
+#ifndef lint
+static char vcid[] = "$Id: sweb.c,v 2.1 94/07/21 11:30:36 ramsdell Exp $";
+static char copyright[] = "Copyright 1994 by The MITRE Corporation.";
+#endif /* lint */
+
+#define VERSION "2.1"
+
+/*
+ * Copyright 1994 by The MITRE Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 1, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * For a copy of the GNU General Public License, write to the
+ * Free Software Foundation, Inc., 675 Mass Ave,
+ * Cambridge, MA 02139, USA.
+ */
+
+/*
+This program processes SchemeWEB files. A SchemeWEB file is a Lisp
+source file which contains code sections and comment sections, but
+each section is identified in a novel way. A code section begins with
+a line whose first character is a left parenthesis. It continues
+until a line is found which contains the parenthesis that matches the
+one which started the code section. The remaining lines of text in
+the source file are treated as comments. Several operations involving
+SchemeWEB files are provided by the this program. See the manual
+page for a complete description of the various operations.
+*/
+
+/* SchemeWEB is currently set up for use with LaTeX. */
+
+/* Define TANGLE to make a program which translates SchemeWEB source
+into Scheme source by default. */
+
+#define SAVE_LEADING_SEMICOLON
+/* Define SAVE_LEADING_SEMICOLON if you want text lines to be copied
+with any leading semicolon while weaving. */
+
+#include <stdio.h>
+
+typedef
+enum
+{myFALSE, myTRUE}
+bool
+;
+
+/* Runtime flags */
+bool weaving; /* Weaving or tangling? */
+bool strip_comments; /* Strip comments while tangling except inside code section. */
+bool strip_all_comments; /* Strip all comments while tangling. */
+
+/* Formatting commands added into weaved documents. */
+char *begin_comment = "\\mbox{"; /* This pair is used */
+char *end_comment = "}"; /* to surround comments in code. */
+char *begin_code = "\\begin{flushleft}\n"; /* This pair is used */
+char *end_code = "\\end{flushleft}\n"; /* to surround code. */
+char *code_line_separator = "\\\\ ";
+char *begin_code_line = "\\verb|"; /* This pair is used */
+char *end_code_line = "|"; /* to surround code lines. */
+
+/* Information for error messages. */
+char *prog = NULL; /* Name of program. */
+char *src = NULL; /* Name of input file. */
+int lineno = 1; /* Line number. */
+
+/* Output occurs through putchar, putstring, and code_putchar. */
+
+#define putstring(s) (fputs(s, stdout))
+
+int /* Used while printing */
+code_putchar(c) /* a code section. */
+ int c;
+{
+ if (c == '|' && weaving) return putstring("|\\verb-|-\\verb|");
+ else return putchar(c);
+}
+
+/* All input occurs in the following routines so that TAB characters
+can be expanded while weaving. TeX treats TAB characters as a
+space--not what is wanted. */
+
+int ch_buf; /* Used to implement */
+bool buf_used = myFALSE; /* one character push back. */
+
+int
+getchr()
+{
+ int c;
+ static int spaces = 0; /* Spaces left to print a TAB. */
+ static int column = 0; /* Current input column. */
+ if (buf_used) {
+ buf_used = myFALSE;
+ return ch_buf;
+ }
+ if (spaces > 0) {
+ spaces--;
+ return ' ';
+ }
+ switch (c = getc(stdin)) {
+ case '\t':
+ if (!weaving) return c;
+ spaces = 7 - (7&column); /* Maybe this should be 7&(~column). */
+ column += spaces + 1;
+ return ' ';
+ case '\n':
+ lineno++;
+ column = 0;
+ return c;
+ default:
+ column++;
+ return c;
+ }
+}
+
+void
+ungetchr(c)
+ int c;
+{
+ buf_used = myTRUE;
+ ch_buf = c;
+}
+
+/* Error message for end of file found in code. */
+bool
+report_eof_in_code()
+{
+ fprintf(stderr, "End of file within a code section.\n");
+ return myTRUE;
+}
+
+bool
+copy_text_saw_eof() /* Copies a line of text out. */
+{ /* Used while printing */
+ int c; /* a text section. */
+ while (1) {
+ c = getchr();
+ if (c == EOF) return myTRUE;
+ if (c == '\n') return myFALSE;
+ putchar(c);
+ }
+}
+
+
+/* Added by Matthieu MOY */
+bool
+copy_text_saw_eof_strip_tex_comments() /* Copies a line of text out. */
+{ /* Used while printing */
+ int c; /* a text section. */
+ while (1) {
+ c = getchr();
+ if (c == EOF) return myTRUE;
+ if (c == '\n') return myFALSE;
+ if (c == '%')
+ while (1) {
+ c = getchr();
+ switch(c) {
+ case '\n': return myFALSE;
+ case EOF: return myTRUE;
+ }
+ }
+ /* Added by Matthieu MOY */
+ if (c == '#') putchar('\\');
+ putchar(c);
+ }
+}
+
+bool
+strip_text_saw_eof() /* Gobbles up a line of input. */
+{
+ int c;
+ while (1) {
+ c = getchr();
+ if (c == EOF) return myTRUE;
+ if (c == '\n') return myFALSE;
+ }
+}
+
+bool /* This copies comments */
+copy_comment_saw_eof() /* within code sections. */
+{
+ if (weaving) putstring(begin_comment);
+ putchar(';');
+ if (copy_text_saw_eof_strip_tex_comments()) return myTRUE;
+ if (weaving) putstring(end_comment);
+ return myFALSE;
+}
+
+bool /* Copies a string found */
+copy_string_saw_eof() /* within a code section. */
+{
+ int c;
+ while (1) {
+ c = getchr();
+ if (c == EOF) return myTRUE;
+ if (c == '\n') { /* Found a string which continues on */
+ if (weaving) /* Added by Matthieu MOY */
+ putstring(end_code_line); /* a new line. */
+ putchar(c); /* Close existing line, and then */
+ if (weaving) { /* Added by Matthie MOY */
+ putstring(code_line_separator); /* begin copying the rest of */
+ putstring(begin_code_line); /* on the next line. */
+ }
+ continue;
+ }
+ code_putchar(c);
+ switch (c) {
+ case '"': return myFALSE;
+ case '\\':
+ c = getchr();
+ if (c == EOF) return myTRUE;
+ code_putchar(c);
+ }
+ }
+}
+
+bool
+maybe_char_syntax_saw_eof()
+{ /* Makes sure that the character */
+ int c; /* #\( does not get counted in */
+ c = getchr(); /* balancing parentheses. */
+ if (c == EOF) return myTRUE;
+ if (c != '\\') {
+ ungetchr(c);
+ return myFALSE;
+ }
+ code_putchar(c);
+ c = getchr();
+ if (c == EOF) return myTRUE;
+ code_putchar(c);
+ return myFALSE;
+}
+
+bool /* Copies a code section */
+copy_code_failed() /* containing S-exprs. */
+{
+ int parens = 1; /* Used to balance parentheses. */
+ int c;
+ while (1) { /* While parens are not balanced, */
+ c = getchr();
+ if (c == EOF) /* Report failure on EOF. */
+ return report_eof_in_code();
+ if (c == '\n' && weaving)
+ putstring(end_code_line);
+ if (c == ';') { /* Report failure on EOF in a comment. */
+ if (weaving) putstring(end_code_line);
+ if (strip_comments
+ /* Modifyed by Matthieu MOY */
+ ? (strip_all_comments ? strip_text_saw_eof() : copy_comment_saw_eof())
+ : copy_comment_saw_eof())
+ return report_eof_in_code();
+ else
+ c = '\n';
+ }
+ code_putchar(c); /* Write the character and then see */
+ switch (c) { /* if it requires special handling. */
+ case '(':
+ parens++;
+ break;
+ case ')':
+ parens--;
+ if (parens < 0) {
+ fprintf(stderr, "Too many right parentheses found.\n");
+ return myTRUE;
+ }
+ break;
+ case '"': /* Report failure on EOF in a string. */
+ if (copy_string_saw_eof()) {
+ fprintf(stderr, "End of file found within a string.\n");
+ return myTRUE;
+ }
+ break;
+ case '#': /* Report failure on EOF in a character. */
+ if (maybe_char_syntax_saw_eof())
+ return report_eof_in_code();
+ break;
+ case '\n':
+ if (parens == 0) return myFALSE;
+ if (weaving) {
+ putstring(code_line_separator);
+ putstring(begin_code_line);
+ }
+ }
+ }
+}
+
+int
+schemeweb()
+{
+ int c;
+ if(weaving)
+ {
+ putstring("\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\
+\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\n");
+ putstring("\% Code generated by SchemeWeb from a .sw file. \%\n");
+ putstring("\% Any change will be lost ! \%\n");
+ putstring("\% DO NOT EDIT please. \%\n");
+ putstring("\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\
+\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\n");
+ }
+ else
+ {
+ putstring(";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n");
+ putstring(";; Code generated by SchemeWeb from a .sw file. ;;\n");
+ putstring(";; Any change will be lost ! ;;\n");
+ putstring(";; DO NOT EDIT please. ;;\n");
+ putstring(";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n");
+ }
+ while (1) { /* At loop start it's in text mode */
+ c = getchr(); /* and at the begining of a line. */
+ if (c == '(') { /* text mode changed to code mode. */
+ if (weaving) putstring(begin_code);
+ do { /* Copy code. */
+ if (weaving) putstring(begin_code_line);
+ putchar(c);
+ if (copy_code_failed()) {
+ /* fputs(prog, stderr); */
+ if (src != NULL)
+ fprintf(stderr, "%s:", src);
+ else
+ fputs("<stdin>:", stderr);
+ fprintf(stderr,
+ "%d: Error in a code section.\n",
+ lineno);
+ return 1;
+ }
+ c = getchr(); /* Repeat when there is code */
+ } while (c == '('); /* immediately after some code. */
+ if (weaving) putstring(end_code);
+ }
+ /* Found a text line--now in text mode. */
+#if !defined SAVE_LEADING_SEMICOLON
+ if (c == ';' && weaving)
+ c = getchr();
+#endif
+ if (c == EOF) return 0; /* Files that do not end with */
+ ungetchr(c); /* a newline are okay. */
+
+ if (strip_comments) {
+ if (strip_text_saw_eof()) return 0;
+ }
+ else {
+ if (c != '\n' && !weaving) putchar(';');
+ if (copy_text_saw_eof()) return 0; /* Copy a text line. */
+ putchar('\n');
+ }
+ }
+}
+
+int /* Removes any semicolons */
+untangle() /* than start a line of text. */
+{
+ int c;
+
+ while (1) { /* At a beginning of a line of text */
+ c = getchar(); /* when at this point in the code. */
+ if (c == EOF) return 0;
+ if (c != ';') putchar(c);
+ while (c != '\n') {
+ c = getchar();
+ if (c == EOF) return 0;
+ putchar(c);
+ }
+ }
+}
+
+bool /* Open the file arguments */
+open_file_args_failed(argc, argv)
+ int argc;
+ char *argv[];
+{
+ switch (argc) {
+ case 2:
+ case 1:
+ src = argv[0]; /* Save for error messages. */
+ if (NULL == freopen(argv[0], "r", stdin)) {
+ fprintf(stderr, "Cannot open %s for reading.\n", argv[0]);
+ break;
+ }
+ if (argc == 2 && NULL == freopen(argv[1], "w", stdout)) {
+ fprintf(stderr, "Cannot open %s for writing.\n", argv[1]);
+ break;
+ }
+ case 0:
+ return myFALSE;
+ }
+ return myTRUE;
+}
+
+int
+usage()
+{
+ fprintf(stderr,
+ "Usage: %s [-stuvwx] [input_file [output_file]]\n%s%s%s%s%s%s%s%s",
+ prog,
+ "\t-h: print this help message\n",
+ "\t-s: tangle input stripping all comments\n",
+ "\t-ss: tangle input stripping comments except inside code\n",
+ "\t-t: tangle input retaining comments\n",
+ "\t-u: untangle input\n",
+ "\t-v: print version information\n",
+ "\t-w: weave input\n",
+ "\t-x: weave input and exclude line breaks in code sections\n");
+ fprintf(stderr, "The default option is %s.\n",
+#if defined TANGLE
+ "-t"
+#else
+ "-w"
+#endif
+ );
+ return 1;
+}
+
+int
+main (argc, argv)
+ int argc;
+ char *argv[];
+{
+ bool untangling = myFALSE;
+#if defined TANGLE
+ weaving = myFALSE;
+#else
+ weaving = myTRUE;
+#endif
+ strip_comments = myFALSE;
+ strip_all_comments = myTRUE;
+
+ prog = argv[0]; /* Save program name for error messages. */
+
+ /* Option processing. Note only one option can be requested at a time. */
+ /* -s: tangle input stripping comments. */
+ /* -ss: tangle input stripping comments except inside code section. */
+ /* -t: tangle input retaining comments. */
+ /* -u: untangle input. */
+ /* -v: print version information. */
+ /* -w: weave input. */
+ /* -x: weave input and exclude line breaks in code sections. */
+ if (argc > 1 && argv[1][0] == '-') {
+ switch (argv[1][1]) {
+ case 's': weaving = myFALSE; strip_comments = myTRUE;
+ if (argv[1][2] == 's') {
+ strip_all_comments = myFALSE;
+ argv[1][2] = argv[1][3]; /* Simulate one argument */
+ }
+ break;
+ case 't': weaving = myFALSE; break;
+ case 'u': untangling = myTRUE; break;
+ case 'v':
+ fprintf(stderr, "This is SchemeWEB version %s.\n", VERSION);
+ return 0;
+ case 'w': weaving = myTRUE; break;
+ case 'x': weaving = myTRUE; code_line_separator = "\\\\* "; break;
+ case 'h': return usage(); break;
+ default:
+ fprintf(stderr, "Bad option: -%c.\n", argv[1][1]);
+ return usage();
+ }
+ if (argv[1][2] != '\0') {
+ fprintf(stderr, "Only one option allowed.\n");
+ return usage();
+ }
+ argc--; argv++;
+ }
+
+ if (open_file_args_failed(argc - 1, argv + 1)) return usage();
+
+ if (untangling) return untangle();
+ return schemeweb();
+}
+
+
diff --git a/web/schemeweb2/sweb.make b/web/schemeweb2/sweb.make
new file mode 100644
index 0000000000..1ffa750288
--- /dev/null
+++ b/web/schemeweb2/sweb.make
@@ -0,0 +1,53 @@
+# This is a sample Makefile for use with SchemeWEB(2)
+# To use it, create a new file called Makefile in the directory
+# containing the SchemeWEB files, whose name should end by .sw
+# inside this file, add the line
+# TEXFILE = XXX.tex [ YYY.tex ZZZ.tex ... ]
+# Where XXX.tex YYY.tex and ZZZ.tex are the name of your main tex
+# files (those you which to compile with 'LaTeX XXX.tex')
+
+# then, add the line
+# include <prefix-dir>/sweb.make
+# where <prefix-dir> is the name of the directory containing the
+# present file. You can now compile with 'make', 'make dvi',
+# 'make ps', 'make html', or clean the directory with 'make clean' (be
+# carefull with this option !)
+
+SWFILE := $(wildcard *.sw)
+
+normal : tex scm
+
+all : tex scm dvi html ps
+
+clean :
+ rm -f `echo *.sw | sed 's/.sw$//.scm/g'`
+ rm -f `echo *.sw | sed 's/.sw$//.tex/g'`
+ rm -f *.toc *.aux *.log
+ rm -f $(TEXFILE:.tex=.dvi)
+ rm -f $(TEXFILE:.tex=.ps)
+
+tex : $(SWFILE:.sw=.tex)
+
+scm : $(SWFILE:.sw=.scm)
+
+dvi : $(TEXFILE:.tex=.dvi)
+
+ps : $(TEXFILE:.tex=.ps)
+
+html : $(TEXFILE)
+ latex2html $<
+
+%.tex : %.sw
+ sweb -w $< $@
+
+%.scm : %.sw
+ sweb -s $< $@
+
+# Sometimes, you have to compile twice. This is the reason of the sleep and touch.
+$(TEXFILE:.tex=.dvi) : $(wildcard *.tex)
+ latex $(@:.dvi=.tex)
+ sleep 1
+ touch $(@:.dvi=.tex)
+
+$(TEXFILE:.tex=.ps) : $(TEXFILE:.tex=.dvi)
+ dvips $< -o $@