diff options
Diffstat (limited to 'support/latex')
-rw-r--r-- | support/latex/scaladefs.sty | 73 | ||||
-rw-r--r-- | support/latex/scaladoc.sty | 249 | ||||
-rwxr-xr-x | support/latex/scalatex.scm | 223 | ||||
-rw-r--r-- | support/latex/tweaklist.sty | 38 | ||||
-rw-r--r-- | support/latex/verbfilterScala.java | 324 |
5 files changed, 0 insertions, 907 deletions
diff --git a/support/latex/scaladefs.sty b/support/latex/scaladefs.sty deleted file mode 100644 index 9fa86e130d..0000000000 --- a/support/latex/scaladefs.sty +++ /dev/null @@ -1,73 +0,0 @@ -%% $Id$ - -\setlength{\parindent}{0pt} -\setlength{\parskip}{5pt} - -\renewcommand{\thesubsubsection}{\thesubsection.\arabic{subsubsection}} -\newcommand{\ssubsection}[1]{\refstepcounter{subsubsection} -\subsubsection{\thesubsubsection\quad #1}} -\newcommand{\prog}[1]{{\sl #1}} -\newenvironment{program}{\begin{quote}\begin{minipage}{\textwidth}\renewcommand{\baselinestretch}{1.0}\sl\begin{tabbing}}{\end{tabbing}\end{minipage}\end{quote}} -\newcommand{\vem}{\bfseries} - -%\newcommand{\expand}{\simeq} -\newcommand{\tup}{\overline} -\renewcommand{\mathem}{\sl\bfseries} -\newcommand{\ABSTRACT}{\mbox{\mathem abstract}} -\newcommand{\FINAL}{\mbox{\mathem final}} -\newcommand{\CASE}{\mbox{\mathem case}} -\newcommand{\WHEN}{\mbox{\mathem when}} -\newcommand{\GUARD}{\mbox{\mathem guard}} -%\newcommand{\THIS}{\mbox{\mathem This}} -\newcommand{\This}{\mbox{\mathem this}} -\newcommand{\CLASS}{\mbox{\mathem class}} -\newcommand{\CONSTR}{\mbox{\sl constr}} -%\newcommand{\INFIXR}{\mbox{\mathem infixr}} -%\newcommand{\INFIXRsub}{\mbox{\small infixr}} -\newcommand{\ASPECT}{\mbox{\mathem aspect}} -\newcommand{\IF}{\mbox{\mathem if}} -\newcommand{\THEN}{\mbox{\mathem then}} -\newcommand{\ELSE}{\mbox{\mathem else}} -\newcommand{\extends}{;\EXTENDS;} -\newcommand{\conforms}{<:} -\newcommand{\EXTENDS}{\mbox{\mathem extends}} -\newcommand{\PRIVATE}{\mbox{\mathem private}} -\newcommand{\PACKAGE}{\mbox{\mathem package}} -\newcommand{\DEF}{\mbox{\mathem def}} -\newcommand{\IMPORT}{\mbox{\mathem import}} -\renewcommand{\LET}{\mbox{\mathem let}} -\newcommand{\NEWTYPE}{\mbox{\mathem newtype}} -\newcommand{\NEW}{\mbox{\mathem new}} -%\newcommand{\NIL}{\mbox{\mathem nil}} -\newcommand{\NULL}{\mbox{\mathem null}} -\newcommand{\OVERRIDE}{\mbox{\mathem override}} -\newcommand{\MODULE}{\mbox{\mathem module}} -\newcommand{\DATA}{\mbox{\mathem data}} -\newcommand{\TYPE}{\mbox{\mathem type}} -\newcommand{\VAL}{\mbox{\mathem val}} -\newcommand{\VAR}{\mbox{\mathem var}} -\newcommand{\WITH}{\mbox{\mathem with}} -\newcommand{\PROTECTED}{\mbox{\mathem protected}} -\newcommand{\QUALIFIED}{\mbox{\mathem qualified}} -\newcommand{\VIRTUAL}{\mbox{\mathem virtual}} -\newcommand{\STATIC}{\mbox{\mathem static}} -\newcommand{\SUPER}{\mbox{\mathem super}} -\newcommand{\BYTE}{\mbox{\mathem byte}} -\newcommand{\CHAR}{\mbox{\mathem char}} -\newcommand{\SHORT}{\mbox{\mathem short}} -\newcommand{\INT}{\mbox{\mathem int}} -\newcommand{\LONG}{\mbox{\mathem long}} -\newcommand{\FLOAT}{\mbox{\mathem float}} -\newcommand{\DOUBLE}{\mbox{\mathem double}} -\newcommand{\BOOLEAN}{\mbox{\mathem boolean}} -\newcommand{\UNIT}{\mbox{\mathem unit}} -\newcommand{\Object}{\mbox{\sf Object}} -\newcommand{\BOXED}{\mbox{\sl boxed}} -\newcommand{\qex}{\mbox{::}} - -\newcommand{\EOL}{\la\mbox{EOL}\ra} -\newcommand{\syntax}{{\bf Syntax:}} -\newcommand{\todo}[1]{$\clubsuit$ {\bf #1} $\spadesuit$} -\newcommand{\Dollar}{\mbox{\$}}%$ -\newcommand{\sref}[1]{\S\ref{#1}} -\newcommand{\nyi}[1]{\footnote{#1 not yet implemented.}}
\ No newline at end of file diff --git a/support/latex/scaladoc.sty b/support/latex/scaladoc.sty deleted file mode 100644 index 4408f50af0..0000000000 --- a/support/latex/scaladoc.sty +++ /dev/null @@ -1,249 +0,0 @@ -%% $Id$ - -\NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{scaladoc}[2003/08/27 v0.1 Scala style customization] -\RequirePackage{fourier} -\RequirePackage[scaled=0.8]{luximono} -\RequirePackage{helvet} -\RequirePackage{color} -\RequirePackage{colortbl} - -% produce an acceptable typing area -\RequirePackage{a4} -\setlength{\textheight}{22.5cm} - -% support for generating PDF files -\newif\ifpdf - \ifx\pdfoutput\undefined - \pdffalse -\else - \pdftrue - \pdfoutput=1 -\fi - -% produce nice captions -\RequirePackage[hang,small,bf]{caption2} - -% include titlesec -\RequirePackage[clearempty]{titlesec} -\newcommand{\mytitlerule}{\titlerule[.5pt]} -\newcommand{\mychaptername}{Chapter} -\newcommand{\setupBookStyle}{% - \titleformat{name=\part}% - [block]% - {\thispagestyle{empty}\centering\scshape\huge}% - {\Roman{part}}% - {1ex}% - {}% - [\vspace*{0.5\textheight}]% - \titleformat{name=\chapter}% - [display]% - {\sffamily\bfseries\huge}% - {\textnormal{\sffamily\LARGE\mychaptername{} \thechapter}}% - {0pt}% - {\vspace*{2.5mm}}% - [\vspace*{8mm}]% - \titleformat{name=\chapter,numberless}% - [display]% - {\vspace*{-30mm}\sffamily\bfseries\huge}% - {}% - {0pt}% - {}% - [\vspace*{2mm}]% -} -\@ifundefined{part}{}{\setupBookStyle} -\titleformat{name=\section} - {\sffamily\bfseries\large} - {\thesection} - {1em} - {} -\titlespacing{\section}{0pt}{*4}{*2} -\titleformat{name=\subsection} - {\sffamily\bfseries\normalsize} - {\thesubsection} - {0.666em} - {} -\titlespacing{\subsection}{0pt}{*2}{*1} -\titleformat{name=\subsubsection} - {\sffamily\bfseries\normalsize} - {\thesubsubsection} - {0.55em} - {} -\titleformat{name=\paragraph} - [runin] - {\rmfamily\normalsize\bfseries} - {} - {opt} - {} - [.\ ] -\titleformat{name=\subparagraph} - [runin] - {\itshape} - {} - {0pt} - {} - [.\ ] -\addtocounter{secnumdepth}{1} - -% produce nice footers -\RequirePackage[bottom,multiple,stable]{footmisc} % flushmargin,norule removed - -% produce nice headings -\RequirePackage{fancyhdr} -\pagestyle{fancy} -\fancypagestyle{plain}{\fancyhf{}% - \renewcommand{\headrulewidth}{0pt}% - \renewcommand{\footrulewidth}{0pt}} - -%%% required on Fedora Core 2 (why?!) -%%% (hint found at http://www.opennet.ru/docs/FAQ/soft/tex-faq.html) -\makeatletter -%%% -\@ifundefined{chaptermark}{}{\renewcommand{\chaptermark}[1]{\markboth{#1}{}}} -%%% -\makeatother -%%% -\renewcommand{\sectionmark}[1]{\markright{\thesection\ \ #1}} -\fancyhf{} -\fancyhead[LE,RO]{\sffamily\footnotesize\thepage} -\fancyhead[RE]{\sffamily\footnotesize\leftmark} -\fancyhead[LO]{\sffamily\footnotesize\rightmark} -\renewcommand{\headrulewidth}{0.5pt} - -% tweak list environments to customize the spacing between items -\RequirePackage{tweaklist} -\renewcommand{\enumhooki}{\addtolength{\itemsep}{-0.32\baselineskip}} -\renewcommand{\enumhookii}{\addtolength{\itemsep}{-0.13\baselineskip}} -\renewcommand{\enumhookiii}{\addtolength{\itemsep}{-0.1\baselineskip}} -\renewcommand{\enumhookiv}{\addtolength{\itemsep}{-0.08\baselineskip}} -\renewcommand{\itemhooki}{\addtolength{\itemsep}{-0.32\baselineskip}} -\renewcommand{\itemhookii}{\addtolength{\itemsep}{-0.13\baselineskip}} -\renewcommand{\itemhookiii}{\addtolength{\itemsep}{-0.1\baselineskip}} -\renewcommand{\itemhookiv}{\addtolength{\itemsep}{-0.08\baselineskip}} - -%% set latex/pdflatex specific stuff -\ifpdf - \RequirePackage[pdftex, - hyperindex, - plainpages=false, - breaklinks, - colorlinks, - citecolor=black, - filecolor=black, - linkcolor=black, - pagecolor=black, - urlcolor=blue]{hyperref} - \RequirePackage[pdftex]{graphicx} - \DeclareGraphicsExtensions{.jpg,.pdf} - \pdfcatalog { - /PageMode (/UseNone) - } - \RequirePackage{thumbpdf} -\else - \RequirePackage[ps2pdf]{hyperref} - \RequirePackage{graphicx} - \DeclareGraphicsExtensions{.eps,.jpg} -\fi - -\RequirePackage{listings} - -% scala language description -\lstdefinelanguage{Scala}{ - morekeywords={% - abstract,case,catch,class,def,do,else,extends,% - false,final,finally,for,if,implicit,import,match,new,null,% - object,override,package,private,protected,% - return,sealed,super,this,throw,trait,true,try,type,% - val,var,while,with,yield},% - sensitive,% - morecomment=[l]//,% - morecomment=[s]{/*}{*/},% -}[keywords,comments]% - -% activate the language and predefine settings -\lstset{ - language=Scala,% - xleftmargin=4mm,% - aboveskip=3mm,% - belowskip=3mm,% - fontadjust=true,% - columns=[c]fixed,% - keepspaces=true,% - basewidth={0.58em, 0.53em},% - tabsize=2,% - basicstyle=\renewcommand{\baselinestretch}{0.95}\ttfamily,% - commentstyle=\itshape,% - keywordstyle=\bfseries,% - mathescape=true,% - escapechar=¤,% - captionpos=b,% - framerule=0.3pt,% - firstnumber=0,% - numbersep=1.5mm,% - numberstyle=\tiny,% -} - -\lstdefinestyle{floating}{% - xleftmargin=10pt,% - xrightmargin=5pt,% - aboveskip=4mm,% - belowskip=4mm,% - fontadjust=true,% - columns=[c]flexible,% - keepspaces=true,% - basewidth={0.5em, 0.425em},% - tabsize=2,% - basicstyle=\renewcommand{\baselinestretch}{0.95}\ttfamily,% - commentstyle=\rm,% - keywordstyle=\bfseries,% - mathescape=true,% - captionpos=b,% - framerule=0.3pt,% - firstnumber=0,% - numbersep=1.5mm,% - numberstyle=\tiny,% - float=tbp,% - frame=tblr,% - framesep=5pt,% - framexleftmargin=3pt,% - abovecaptionskip=\smallskipamount,% - belowcaptionskip=\smallskipamount,% -} % to define: caption, label - -\newcommand{\code}[1]{% - \lstinline[%keywordstyle=,% - flexiblecolumns=true,% - basicstyle=\ttfamily]£#1£} - - - - -\newcommand{\clearemptydoublepage}{\newpage{\pagestyle{empty}\cleardoublepage}} - -\newcommand{\docauthor}{Author} -\newcommand{\doctitle}{Title} -\newcommand{\docsubtitle}{DRAFT} -\newcommand{\docdate}{\today} -\newcommand{\makedoctitle}{% - \begin{titlepage}% - \begin{center}% - \begin{tabular}{p{0.6\textwidth}>{\columncolor[gray]{.82}[\tabcolsep]}p{0.327\textwidth}}% - \rowcolor[gray]{.82}\ & \ \\% - \ & \ \\[35mm]% - \hspace*{4mm}{\sffamily\LARGE\bfseries\parbox{0.55\textwidth}{\doctitle}} & \ \\[42mm]% - \ & {\sffamily\normalsize \docsubtitle} \\[.5ex]% - \ & {\sffamily\normalsize \docdate} \\[16mm]% - \ & {\sffamily\normalsize\bfseries\parbox{0.31\textwidth}{\docauthor}} \\% - \rowcolor[gray]{.82} \ & \ \\% - \multicolumn{2}{>{\columncolor[gray]{.82}[\tabcolsep]}r}{% - \small\sc Programming Methods Laboratory}\\[-.2ex]% - \multicolumn{2}{>{\columncolor[gray]{.82}[\tabcolsep]}r}{% - \small\sc EPFL}\\[-.2ex]% - \multicolumn{2}{>{\columncolor[gray]{.82}[\tabcolsep]}r}{% - \small\sc Switzerland}\\[-.6ex]% - \rowcolor[gray]{.82} \ & \ % - \end{tabular}% - \end{center}% - \end{titlepage}} - -\endinput diff --git a/support/latex/scalatex.scm b/support/latex/scalatex.scm deleted file mode 100755 index a5fb5a2b6d..0000000000 --- a/support/latex/scalatex.scm +++ /dev/null @@ -1,223 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Embedded Scala Script Evaluator -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; $Id$ - -;; Commands: -;; \begin{scalaprogram}{<name>} ... \end{scalaprogram} -;; begin a complete Scala program with given name -;; \beginscalaprogram{<name>} ... \endscalaprogram -;; begin a Scala program with given name, which can be omitted in -;; which case the program is anonymous -;; \scalaprogramoutput{<name>} -;; insert the output of the given program, which must be ended -;; \begin{scalacode} ... \end{scalacode} -;; begin a section of Scala code which is added to the current -;; program, and printed in the final result -;; \begin{scalainvisiblecode} ... \end{scalainvisiblecode} -;; like \begin{scalacode}, but the code doesn't get printed - -;; TODO -;; - add interaction with siris using commands like: -;; \beginscalainteraction, \endscalainteraction, visible/invisible code, -;; visible code whose result is not visible - -;; Diagnostics -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(define fast? #f) - -(define verbose? #t) - -(define (message str . args) - (when verbose? - (apply format (error-output-port) str args) - (newline (error-output-port)))) - -(define (fail line-num msg . args) - (format #t "~a:~a: ~a" "<in-file>" line-num (apply format #f msg args))) - -;; Syntax -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(define-syntax when - (syntax-rules () - ((when cond body1 body2 ...) - (if cond (begin body1 body2 ...))))) - -(define-syntax unless - (syntax-rules () - ((unless cond body1 body2 ...) - (if (not cond) (begin body1 body2 ...))))) - -;; Temporary directories / files -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;; AList associating temporary directories with program names. -(define temp-dirs '()) - -(define (get-temp-dir prog-name) - (cond ((assoc prog-name temp-dirs) => cdr) - (else - (let ((dir (temp-file-iterate (lambda (dir) (create-directory dir) dir) - "/tmp/temp-~a"))) - (set! temp-dirs (alist-cons prog-name dir temp-dirs)) - dir)))) - -(define (clean-temp-dirs) - (for-each (lambda (file/dir) - (let ((dir (cdr file/dir))) - (message "Cleaning up temporary class directory (~a)" dir) - (run (rm -rf ,dir)))) - temp-dirs)) - -(define (scala-file-name prog-name) - (expand-file-name (replace-extension prog-name ".scala") - (get-temp-dir prog-name))) - -(define (open-scala-program name) - (open-output-file (scala-file-name name))) - -(define (close-scala-program name port) - (unless fast? (compile-scala-program name)) - (close-output-port port)) - -;; Compiling and running Scala programs -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(define (compile-scala-program prog-name) - (let ((file-name (scala-file-name prog-name)) - (classes-dir (get-temp-dir prog-name))) - (message "Compiling file ~a to directory ~a" file-name classes-dir) - (run (scalac -d ,classes-dir ,file-name)))) - -(define (append-scala-program-output prog-name out-port) - (let ((classes-dir (get-temp-dir prog-name))) - (message "Running program ~a" prog-name) - (with-env (("CLASSPATH" . ,(string-append classes-dir ":" (getenv "CLASSPATH")))) - (write-string (run/string (scala ,prog-name)) out-port)))) - - -;; Main iteration -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(define (begin-scala-code port) - (format port "\\begin{lstlisting}\n")) -(define (end-scala-code port) - (format port "\\end{lstlisting}\n")) - -(define (begin-program-output port) - (format port "\\begin{verbatim}\n")) -(define (end-program-output port) - (format port "\\end{verbatim}\n")) - -(define (scala-rx contents) - (rx bos (* space) ,@contents (* space))) - -(define (scala-begin-rx env-name) - (scala-rx (string-append "\\begin{" env-name "}"))) -(define (scala-end-rx env-name) - (scala-rx (string-append "\\end{" env-name "}"))) - -(define scalatex - (let ((prog-name-rx (rx (* (| alphanum ("_")))))) - (lambda (in-port out-port) - (awk (read-line in-port) (line) line-num ((prog-name #f) - (prog-port #f) - (expr #f) - (in-fragment? #f) - (copy? #t)) - ;; Program. - ((regexp-search (scala-rx (rx "\\beginscalaprogram" - "{" (submatch ,prog-name-rx) "}")) - line) - => (lambda (match) - (let ((prog-name (or (match:substring match 1) "anonymous"))) - (values prog-name - (open-scala-program prog-name) - #f - #f - copy?)))) - - ((regexp-search (scala-rx "\\endscalaprogram") line) - (close-scala-program prog-name prog-port) - (values #f #f #f #f copy?)) - - ((regexp-search (scala-rx (rx "\\begin{scalaprogram}" - "{" (submatch ,prog-name-rx) "}")) - line) - => (lambda (match) - (begin-scala-code out-port) - (let ((prog-name (or (match:substring match 1) "anonymous"))) - (values prog-name - (open-scala-program prog-name) - #f - #t - #t)))) - - ((regexp-search (scala-end-rx "scalaprogram") line) - (end-scala-code out-port) - (close-scala-program prog-name prog-port) - (values #f #f #f #f copy?)) - - ;; Insertion of program output. - ((regexp-search (scala-rx (rx "\\scalaprogramoutput" - "{" (submatch ,prog-name-rx) "}")) - line) - => (lambda (match) - (let ((prog-name (match:substring match 1))) - (begin-program-output out-port) - (if fast? - (format out-port "!!! NO OUTPUT !!!") - (append-scala-program-output prog-name out-port)) - (end-program-output out-port)) - (values prog-name prog-port #f in-fragment? copy?))) - - ;; Visible code fragment. - ((regexp-search (scala-begin-rx "scalacode") line) - (begin-scala-code out-port) - (values prog-name prog-port #f #t #t)) - - ((regexp-search (scala-end-rx "scalacode") line) - (end-scala-code out-port) - (values prog-name prog-port #f #f #t)) - - ;; Invisible code fragment. - ((regexp-search (scala-begin-rx "scalainvisiblecode") line) - (values prog-name prog-port #f #t #f)) - - ((regexp-search (scala-end-rx "scalainvisiblecode") line) - (values prog-name prog-port #f #f #t)) - - (else - (when in-fragment? - (write-string line prog-port) - (newline prog-port)) - (when copy? - (write-string line out-port) - (newline out-port)) - (values prog-name - prog-port - (and expr (string-append expr line)) - in-fragment? - copy?)))))) - -(define (display-usage-and-exit prog) - (format #t "Usage: ~a [--no-compile] <in-file> <out-file>\n" prog)) - -(define (main cmd-line) - (let ((prog (car cmd-line)) - (args (cdr cmd-line))) - (if (>= 2 (length args)) - (call-with-input-file (first args) - (lambda (in-port) - (call-with-output-file (second args) - (lambda (out-port) - (format out-port "%% DO NOT EDIT - AUTOMATICALLY GENERATED FILE\n") - (format out-port "%% Generated from \"~a\" on ~a by ~a\n\n" - (first args) - (format-date "~Y-~m-~d [~H:~M]" (date)) - (user-login-name)) - (scalatex in-port out-port) - (clean-temp-dirs))))) - (display-usage-and-exit prog)))) diff --git a/support/latex/tweaklist.sty b/support/latex/tweaklist.sty deleted file mode 100644 index fb02a32810..0000000000 --- a/support/latex/tweaklist.sty +++ /dev/null @@ -1,38 +0,0 @@ -%% $Id$ - -\def\enumhook{} -\def\enumhooki{} -\def\enumhookii{} -\def\enumhookiii{} -\def\enumhookiv{} -\def\itemhook{} -\def\itemhooki{} -\def\itemhookii{} -\def\itemhookiii{} -\def\itemhookiv{} -\def\descripthook{} -\def\enumerate{% - \ifnum \@enumdepth >\thr@@\@toodeep\else - \advance\@enumdepth\@ne - \edef\@enumctr{enum\romannumeral\the\@enumdepth}% - \expandafter - \list - \csname label\@enumctr\endcsname - {\usecounter\@enumctr\def\makelabel##1{\hss\llap{##1}}% - \enumhook \csname enumhook\romannumeral\the\@enumdepth\endcsname}% - \fi} -\def\itemize{% - \ifnum \@itemdepth >\thr@@\@toodeep\else - \advance\@itemdepth\@ne - \edef\@itemitem{labelitem\romannumeral\the\@itemdepth}% - \expandafter - \list - \csname\@itemitem\endcsname - {\def\makelabel##1{\hss\llap{##1}}% - \itemhook \csname itemhook\romannumeral\the\@itemdepth\endcsname}% - \fi} -\renewenvironment{description} - {\list{}{\labelwidth\z@ \itemindent-\leftmargin - \let\makelabel\descriptionlabel\descripthook}} - {\endlist} - diff --git a/support/latex/verbfilterScala.java b/support/latex/verbfilterScala.java deleted file mode 100644 index f65c0e7ba0..0000000000 --- a/support/latex/verbfilterScala.java +++ /dev/null @@ -1,324 +0,0 @@ -// $Id$ - -import java.io.*; - -public class verbfilterScala { - - static String[] reserved = { - "abstract", "case", "catch", "class", "def", - "do", "else", "extends", "false", "final", - "finally", "for", "if", "import", "new", - "null", "object", "override", "package", "private", - "protected", "requires", "return", "sealed", "super", "this", "throw", - "trait", "true", "try", "type", "val", - "var", "while", "with", "yield"}; - - static final int TABINC = 8; - - final static String beginVerbatim = "\\begin{verbatim}"; - final static String endVerbatim = "\\end{verbatim}"; - final static String verb = "\\verb"; - - static int lineCount, verbLine; - - static boolean startsWith(byte[] buf, int offset, String s) { - int i = 0; - while (i < s.length() && buf[offset+i] == s.charAt(i)) i++; - return i == s.length(); - } - - static void writeString(OutputStream out, String s) throws IOException { - for (int i = 0; i < s.length(); i++) - out.write(s.charAt(i)); - } - - static int skipBlanks(byte[] buf, int offset) { - while (buf[offset] == ' ') offset++; - return offset; - } - - static int compare(byte[] buf, int i, String key) { - int j = 0; - int l = key.length(); - while (i < buf.length && j < l) { - char bch = (char)buf[i]; - char kch = key.charAt(j); - if (bch < kch) return -1; - else if (bch > kch) return 1; - i++; - j++; - } - if (j < l) - return -1; - else if (i < buf.length && - ('A' <= buf[i] && buf[i] <= 'Z' || - 'a' <= buf[i] && buf[i] <= 'z' || - '0' <= buf[i] && buf[i] <= '9' || - buf[i] == '_')) - return 1; - else - return 0; - } - - static int keyIndex(byte[] buf, int i, String[] keys) { - int lo = 0; - int hi = keys.length - 1; - while (lo <= hi) { - int mid = (hi + lo) / 2; - int diff = compare(buf, i, keys[mid]); - if (diff < 0) hi = mid - 1; - else if (diff > 0) lo = mid + 1; - else return mid; - } - return -1; - } - - static int processLeadingWhitespace(byte[] buf, - int i, - OutputStream out) throws IOException { - int col = 0; - while (true) { - if (buf[i] == ' ') { - writeString(out, "~~"); i++; col++; - } else if (buf[i] == '\t') { - i++; - do { - writeString(out, "~~"); col++; - } while (col % TABINC != 0); - } else { - return i; - } - } - } - - static int processVerbatim(byte[] buf, - int i, - OutputStream out, - String delimiter) throws IOException { - - verbLine = lineCount; - int delimiter0 = delimiter.charAt(0); - int j = skipBlanks(buf, i); - if (buf[j] == '\n') { i = j+1; lineCount++; } - i = processLeadingWhitespace(buf, i, out); - while (true) { - if (buf[i] == delimiter0 && startsWith(buf, i, delimiter)) - return i + delimiter.length(); - switch (buf[i]) { - case ' ': - writeString(out, "~"); - break; - case '\n': - writeString(out, "\n"); - j = i+1; - lineCount++; - if (buf[j] == delimiter0 && startsWith(buf, j, delimiter)) - return j + delimiter.length(); - writeString(out, "\\\\"); - if (buf[i+1] == '\n') { - writeString(out, "[0.5em]"); i++; - lineCount++; - } - i = processLeadingWhitespace(buf, i+1, out)-1; - break; - case '^': - writeString(out, "\\^~$\\!\\!$"); - break; - case '&': - writeString(out, "\\&"); - break; - case '*': - writeString(out, "$*$"); - break; - case '%': - writeString(out, "$\\%$"); - break; - case '_': - writeString(out, "\\_"); - break; - case '~': - writeString(out, "\\~~$\\!\\!$"); - break; - case '{': - writeString(out, "{\\small\\{}"); - break; - case '}': - writeString(out, "{\\small\\}}"); - break; - case '[': - writeString(out, "$[$"); - //if (buf[i+1] == ']') out.write('~'); - break; - case ']': - writeString(out, "$]$"); - break; - case '(': - writeString(out, "$($"); - break; - case ')': - writeString(out, "$)$"); - break; - case ':': - if (i > 0 && Character.isJavaIdentifierPart((char)buf[i-1])) - writeString(out, "\\,"); - writeString(out, "{\\rm :}"); - break; - case '<': - if (buf[i+1] == '=') { - writeString(out, "$\\leq$"); i++; - } else if (buf[i+1] == '-') { - writeString(out, "$\\leftarrow$"); i++; - } else if (buf[i+1] == '<') { - writeString(out, "$<\\!$"); - } else { - writeString(out, "$<$"); - } - break; - case '>': - if (buf[i+1] == '=') { - writeString(out, "$\\geq$"); i++; - } else if (buf[i+1] == '>') { - writeString(out, "$>\\!$"); - } else { - writeString(out, "$>$"); - } - break; - case '=': - if (buf[i+1] == '=') { - writeString(out, "$==$"); i++; - } else if (buf[i+1] == '>') { - writeString(out, "$\\Rightarrow$"); i++; - } else { - out.write('='); - } - break; - case '/': - if (buf[i+1] == '/') { - out.write ('/'); - do { - out.write(buf[i+1]); - i++; - } while (buf[i+1] != '\n' && - (buf[i+1] != delimiter0 || - !startsWith(buf, i+1, delimiter))); - } else { - out.write('/'); - } - break; - case '-': - if (buf[i+1] == '>') { - writeString(out, "$\\rightarrow$"); - i++; - } else { - writeString(out, "$-$"); - } - break; - case '+': - writeString(out, "$+$"); - break; - case '|': - writeString(out, "$\\,|$"); - break; - case '#': - writeString(out, "\\#"); - break; - case '\\': - if (buf[i+1] == '=' || buf[i+1] == '>') { - out.write(buf[i]); - i++; - out.write(buf[i]); - } else if (buf[i+1] == '$') { - writeString(out, "\\$"); - i++; - } else if (buf[i+1] == 'R') { - writeString(out, "\\color{red}"); i++; - } else if (buf[i+1] == 'S') { - writeString(out, "\\color{black}"); i++; - } else if (buf[i+1] == 'B') { - writeString(out, "\\color{blue}"); i++; - } else if (buf[i+1] == 'G') { - writeString(out, "\\color{green}"); i++; - } else { - writeString(out, "$\\backslash$"); - } - break; - case '$': - out.write(buf[i]); - do { - i++; - out.write(buf[i]); - } while (i + 1 < buf.length && buf[i] != '$'); - break; - default: - if (i == 0 || !Character.isJavaIdentifierPart((char)buf[i-1])) { - int k = keyIndex(buf, i, reserved); - if (k >= 0) { - writeString(out, "{\\vem " + reserved[k] + "}"); - i = i + reserved[k].length() - 1; - break; - } - } - out.write(buf[i]); - break; - } - i++; - } - } - - static void process(byte[] buf, OutputStream out) throws IOException { - int i = 0; - while (i < buf.length - 1) { - if (buf[i] == '%') { - do { - out.write(buf[i]); - i++; - } while (buf[i] != '\n' && buf[i] != 0); - } else if (startsWith(buf, i, beginVerbatim)) { - writeString(out, "\\begin{program}"); - i = processVerbatim(buf, i + beginVerbatim.length(), out, - endVerbatim); - writeString(out, "\\end{program}"); - } else if (startsWith(buf, i, verb)) { - writeString(out, "\\prog{"); - i = i + verb.length(); - char[] delimiterArray = {(char)buf[i]}; - String delimiter = new String(delimiterArray); - i = processVerbatim(buf, i + 1, out, delimiter); - writeString(out, "}"); - } else { - if (buf[i] == '\n') lineCount++; - out.write(buf[i]); - i++; - } - } - } - - public static void main(String[] argv) throws IOException { - if (argv.length != 2) { - String classname = new Error().getStackTrace()[0].getClassName(); - System.err.println( - "Usage: " + classname + " <source-file> <destination-file>"); - System.exit(1); - } - InputStream in = new FileInputStream(new File(argv[0])); - byte[] buf = new byte[in.available() + 1]; - in.read(buf, 0, buf.length-1); - in.close(); - OutputStream out = - new BufferedOutputStream( - new FileOutputStream( - new File(argv[1]))); - try { - writeString(out,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"); - writeString(out,"% DO NOT EDIT. Automatically generated file! %\n"); - writeString(out,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"); - writeString(out,"\n"); - lineCount = 1; - process(buf, out); - } catch (RuntimeException ex) { - System.err.println ("\n **** error at line " + verbLine); - throw ex; - } - out.close(); - } -} |