\documentclass{article}% ===> this file was generated automatically by noweave --- better not edit it
\usepackage{axiom}
\begin{document}
\title{Autodoc}
\author{Tim Daly}
\maketitle
\begin{abstract}
We want to generate the reference information from axiom source
files automatically.
\end{abstract}
\eject
\tableofcontents
\eject
By design the chunk name has 3 fields. 
The first field is one of \{category, domain, package\}.
The second field is the abbreviation.
The third field is the full name.
This routine will return two lists, the first is the list of
abbreviations and the second is the list of full names.

We keep looping until we run out of input, at which point we
throw out of the loop and catch it here.
\nwfilename{PamphletExample.pamphlet}\nwbegincode{1}\moddef{until done}\endmoddef\nwstartdeflinemarkup\nwenddeflinemarkup
  (catch 'done
\nwendcode{}\nwbegindocs{2}\nwdocspar
We open the source file
\nwenddocs{}\nwbegincode{3}\moddef{open source file}\endmoddef\nwstartdeflinemarkup\nwenddeflinemarkup
   (with-open-file (in sourcefile)
\nwendcode{}\nwbegindocs{4}\nwdocspar
We read each line, trimming off trailing spaces
\nwenddocs{}\nwbegincode{5}\moddef{for each line do}\endmoddef\nwstartdeflinemarkup\nwenddeflinemarkup
    (loop
     (setq expr (read-line in nil 'done))
     (when (eq expr 'done) (throw 'done nil))
     (setq expr (string-trim '(#\\space) expr))
\nwendcode{}\nwbegindocs{6}\nwdocspar
We look for lines that begin with a chunk name that
starts with package, domain, or category and end with an
equal sign (which indicates a chunk definition).
\nwenddocs{}\nwbegincode{7}\moddef{when package domain or category definition}\endmoddef\nwstartdeflinemarkup\nwenddeflinemarkup
     (when 
      (and (> (length expr) 4)
           (or
            (string= "<<pa" (subseq expr 0 4))
            (string= "<<do" (subseq expr 0 4))
            (string= "<<ca" (subseq expr 0 4)))
           (char= (elt expr (1- (length expr))) #\\=))
\nwendcode{}\nwbegindocs{8}\nwdocspar
We remove the 3 characters, two $>$ and an $=$ which make up the chunk name.
\nwenddocs{}\nwbegincode{9}\moddef{remove the trailing chunk characters}\endmoddef\nwstartdeflinemarkup\nwenddeflinemarkup
      (setq expr (subseq expr 0 (- (length expr) 3)))
\nwendcode{}\nwbegindocs{10}\nwdocspar
We get the third field from the string which is the long name.
\nwenddocs{}\nwbegincode{11}\moddef{capture the long name}\endmoddef\nwstartdeflinemarkup\nwenddeflinemarkup
      (setq point (position #\\space expr :from-end t :test #'char=))
\nwendcode{}\nwbegindocs{12}\nwdocspar
We get the second field from the string which is the abbreviation.
\nwenddocs{}\nwbegincode{13}\moddef{capture the abbreviation}\endmoddef\nwstartdeflinemarkup\nwenddeflinemarkup
      (setq mark
       (position #\\space 
        (string-right-trim '(#\\space)
         (subseq expr 0 (1- point))) :from-end t))
      (push (string-trim '(#\\space) (subseq expr mark point)) names)))))
\nwendcode{}\nwbegindocs{14}\nwdocspar
\nwenddocs{}\nwbegincode{15}\moddef{srcabbrevs}\endmoddef\nwstartdeflinemarkup\nwenddeflinemarkup
(defun srcabbrevs (sourcefile)
 (let (in expr start end names longnames)
\LA{}until done\RA{}
\LA{}open source file\RA{}
\LA{}for each line do\RA{}
\LA{}when package domain or category definition\RA{}
\LA{}remove the trailing chunk characters\RA{}
\LA{}capture the long name\RA{}
      (format t "~a ~a ~a~%" expr point longnames)
\LA{}capture the abbreviation\RA{}
  (values names longnames))))

\nwendcode{}\nwbegindocs{16}\nwdocspar
\section{Doit}
\nwenddocs{}\nwbegincode{17}\moddef{doit}\endmoddef\nwstartdeflinemarkup\nwenddeflinemarkup
(srcabbrevs "/new/patch38/src/algebra/acplot.spad.pamphlet")

\nwendcode{}\nwbegindocs{18}\nwdocspar
\section{Autodoc}
\nwenddocs{}\nwbegincode{19}\moddef{autodoc}\endmoddef\nwstartdeflinemarkup\nwenddeflinemarkup
\LA{}srcabbrevs\RA{}
\LA{}doit\RA{}
\nwendcode{}\nwbegindocs{20}\nwdocspar
\section{Makefile}
\nwenddocs{}\nwbegincode{21}\moddef{*}\endmoddef\nwstartdeflinemarkup\nwenddeflinemarkup
TANGLE=/usr/local/bin/notangle -t8 
WEAVE=/usr/local/bin/noweave -delay
LISP=/new/patch38/obj/linux/bin/lisp

all: code doc run

code: autodoc.lisp.pamphlet
        @$\{TANGLE\} -Rautodoc autodoc.lisp.pamphlet >autodoc.lisp

doc: autodoc.lisp.pamphlet
        @$\{WEAVE\} autodoc.lisp.pamphlet >autodoc.tex
        @latex autodoc.tex
        @latex autodoc.tex

run: autodoc.lisp
        @cat autodoc.lisp | $\{LISP\}

remake:
        @$\{TANGLE\} autodoc.lisp.pamphlet >Makefile

\nwendcode{}\nwbegindocs{22}\nwdocspar
\eject
\begin{thebibliography}{99}
\bibitem{1} nothing
\end{thebibliography}
\end{document}
\nwenddocs{}
