summaryrefslogtreecommitdiff
path: root/support/xtrcode
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 /support/xtrcode
Initial commit
Diffstat (limited to 'support/xtrcode')
-rw-r--r--support/xtrcode/README15
-rwxr-xr-xsupport/xtrcode/xtrcode150
-rw-r--r--support/xtrcode/xtrcode.pdfbin0 -> 55445 bytes
-rw-r--r--support/xtrcode/xtrcode.tex74
4 files changed, 239 insertions, 0 deletions
diff --git a/support/xtrcode/README b/support/xtrcode/README
new file mode 100644
index 0000000000..4b9ff70556
--- /dev/null
+++ b/support/xtrcode/README
@@ -0,0 +1,15 @@
+This is xtrcode v.0.2 (Jan 12, 2000)
+To install, simply move the Perl script xtrcode to an appropriate directory
+and make it executable. You may have to change the first line of xtrcode to
+fit your Perl installation; the program has been tested with Perl 5.005_03.
+
+xtrcode.tex contains a short documentation of the usage. Just run it through
+latex. You can try the example in it with xtrcode.tex itself.
+
+xtrcode is released under the GNU Public License. v.0.2 is the first public
+release.
+
+
+Thomas Ruedas
+ruedas@geophysik.uni-frankfurt.de
+http://www.geophysik.uni-frankfurt.de/~ruedas/progs.html
diff --git a/support/xtrcode/xtrcode b/support/xtrcode/xtrcode
new file mode 100755
index 0000000000..c21875eba4
--- /dev/null
+++ b/support/xtrcode/xtrcode
@@ -0,0 +1,150 @@
+#!/usr/local/bin/perl
+#
+# xtrcode - extract contents of LaTeX environments from a LaTeX file
+# Copyright (C) 2000 Thomas Ruedas
+#
+# 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 2 of the License, 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+# xtrcode extracts contents of LaTeX environments from a LaTeX file,
+# e.g. program code in verbatim environments from a program documentation.
+# Version: 0.2 (Jan 12, 2000)
+# Author: Thomas Ruedas (ruedas@geophysik.uni-frankfurt.de)
+# URL: http://www.geophysik.uni-frankfurt.de/~ruedas/progs.html
+#
+# NOTE: This program requires Perl 5. You may need modify the first line
+# according to the location of Perl 5 on your system.
+$|=1;
+$all=0;
+$ncode=0;
+unless (defined @ARGV) { &usage; }
+foreach (@ARGV) {
+ OPTION: {
+ ($_ eq "-a") && do { $all=1; last OPTION; }; # extract all
+ ($_ =~ /^-e/) && do { # choose non-default environment type
+ $envtype=substr($_,2);
+ last OPTION;
+ };
+ ($_ =~ /^-p/) && do { # choose non-default marker pattern
+ $mpatt=substr($_,2);
+ $mpatt =~ s/\@/\\\@/g;
+ $mpatt =~ s/\+/\\\+/g;
+ last OPTION;
+ };
+ ($_ eq "-h") && do { &usage; }; # show help
+ if (defined $texfile) { # specify a codefile name (together w/ marker)
+ if ($all == 1) { print "<codefile> $_ ignored.\n"; last OPTION; }
+ $codefile=$_;
+ } else { # LaTeX source file
+ $texfile=$_;
+ };
+ };
+}
+# check arguments, set defaults if necessary
+unless (defined $texfile) { die "Error: No <texfile> specified.\n"; }
+unless (defined $envtype) { $envtype="verbatim"; }
+unless (defined $mpatt) { $mpatt="%%\@"; }
+# process LaTeX file
+open(TEX,"$texfile");
+if ($all == 0) {
+# search with specific codefile or extract all into one file
+# if no codefile name is given, the default name is "xtrcode.out"
+ if (defined $codefile) {
+ $fpatt="$mpatt $codefile";
+ } else {
+ $codefile="xtrcode.out";
+ $fpatt=$mpatt;
+ }
+ open(CODE,">$codefile");
+ while ($line = <TEX>) {
+ if ($line =~ /^$fpatt/) {
+ unless ($fpatt eq "") { $line = <TEX>; } # null pattern is special
+ if ($line =~ /\\begin\{$envtype\}/gi) {
+ $nested=1;
+ while ($line = <TEX>) {
+ if ($line =~ /\\end\{$envtype\}/gi) {
+ --$nested;
+ if ($nested == 0) { last; }
+ } elsif ($line =~ /\\begin\{$envtype\}/gi) { ++$nested; }
+ ++$ncode;
+ print CODE $line;
+ }
+ }
+ }
+ }
+ close(CODE);
+ print "$ncode lines of extracted code written to $codefile.\n";
+} else {
+# extract and put into individual codefiles
+ while ($line = <TEX>) {
+ if ($line =~ /^$mpatt/) {
+ $codefile=substr($line,(length $mpatt));
+ chomp $codefile;
+ unless (defined $ncode{$codefile}) { ++$nfiles; }
+ open(CODE,"+>>$codefile");
+ $line = <TEX>;
+ if ($line =~ /\\begin\{$envtype\}/gi) {
+ $nested{$codefile}=1;
+ while ($line = <TEX>) {
+ if ($line =~ /\\end\{$envtype\}/gi) {
+ --$nested{$codefile};
+ if ($nested{$codefile} == 0) { last; }
+ } elsif ($line =~ /\\begin\{$envtype\}/gi) {
+ ++$nested{$codefile};
+ }
+ ++$ncode{$codefile};
+ print CODE $line;
+ }
+ }
+ close(CODE);
+ }
+ }
+ print "$nfiles files have been extracted from $texfile:\n\n";
+ format STDOUT_TOP=
+@<<<file@>>>>>>>>>>>>>>>>>>>>>>>>>>>> no. of lines
+
+--------------------------------------------------
+.
+ write;
+ format STDOUT=
+ @<<<<<<<<<<<<<<<<<<<<<<<<<<@>>>>>>>>>>>>>>>>>>>
+$outfile,$nlines
+.
+ foreach (keys %ncode) {
+ $outfile=$_;
+ $nlines=$ncode{$_};
+ write;
+ }
+}
+close(TEX);
+exit;
+
+sub usage {
+ print "Usage: xtrcode <options> texfile <codefile>
+\tOptions:
+\t -a - extract all code; this is for code which is supposed to be
+\t distributed over different target files, so do not use it
+\t together with <codefile>
+\t -e<environment> - extract content of <environment>; default is
+\t [Vv]erbatim
+\t -p<pattern> - marker pattern for environments to extract (see below)
+\t a null pattern is possible
+\t -h - show this help
+
+texfile is a TeX source file containing code in some kind of LaTeX environment.
+The environment containing the code must be preceded by a line beginning with
+a marker pattern (%%\@ by default), optionally followed by a program source
+name <codefile>.\n";
+ exit;
+}
diff --git a/support/xtrcode/xtrcode.pdf b/support/xtrcode/xtrcode.pdf
new file mode 100644
index 0000000000..a3c1bd6485
--- /dev/null
+++ b/support/xtrcode/xtrcode.pdf
Binary files differ
diff --git a/support/xtrcode/xtrcode.tex b/support/xtrcode/xtrcode.tex
new file mode 100644
index 0000000000..2428cfd856
--- /dev/null
+++ b/support/xtrcode/xtrcode.tex
@@ -0,0 +1,74 @@
+\documentclass[11pt]{article}
+\usepackage[T1]{fontenc}
+\usepackage[dvips]{geometry}
+\usepackage{isolatin1,url,verbatim}
+\usepackage[english]{babel}
+\geometry{paper=a4paper,top=2cm,bottom=1.5cm,hdivide={1.5cm,*,2cm}}
+\jot0.3cm
+\frenchspacing
+\newenvironment{vverbatim}%
+ {\endgraf\verbatim}%\noindent
+ {\endverbatim}
+\title{\texttt{xtrcode} v.0.2 --- extract contents of \LaTeX\ environments from a file}
+\author{Thomas Ruedas\thanks{e-mail: \texttt{ruedas@geophysik.uni-frankfurt.de}}}
+\date{January 12, 2000}
+\begin{document}
+\maketitle
+\section{Description}
+This is a small Perl program I originally made when I was writing a program documentation for a large program consisting of several files; I wanted to extract the code out of the \LaTeX\ verbatim environments containing the whole code portionwise and have it put into a file which could then be compiled directly. This is how it works:\bigskip\par\noindent
+\texttt{xtrcode} $<$\textit{options}$>$ \textit{texfile} $<$\textit{codefile}$>$\bigskip\par\noindent
+Options:
+\begin{description}
+\item[\texttt{-a}] extract all code; this is for code which is supposed to be distributed over different target files, so do not use it together with \textit{codefile}
+\item[\texttt{-e}\textit{environment}] extract content of \textit{environment}; default is [Vv]erbatim
+\item[\texttt{-p}\textit{pattern}] marker pattern for environments to extract; default is \verb/%%@/. A null pattern is possible.
+\item[-h] show help
+\end{description}
+You can download it together with a short documentation as a tar.gz file from \url{http://www.geophysik.uni-frankfurt.de/~ruedas/download/xtrcode.tar.gz}.
+In the following I assume that \textit{texfile} is a program documentation.
+\begin{description}
+\item[\textit{codefile}:] \texttt{xtrcode} \textit{texfile} \textit{codefile} searches for a marker pattern followed by a blank and \textit{codefile} and copies the content of the following environment into the target file \textit{codefile}. This can be used to extract only the contents corresponding to a certain part of the program instead of the whole lot.---If no \textit{codefile} is given, the default output file is ``xtrcode.out''.
+\item[Option -a:] \texttt{xtrcode -a} \textit{texfile} extracts all contents of an environment from \textit{texfile} and writes it into the output file which is expected to be specified by the use of the marker pattern. This is useful if you have program code which is intended to come into separate files; when documenting it you will use a kind of extra pattern line, e.g. \verb/%%@ code1.f/ preceding each verbatim environment containing parts of \texttt{code1.f}, and similarly with the other files. With the \texttt{-a} option, \texttt{xtrcode} will interpret \texttt{code1.f} as the name of the file which shall contain the content of the following environment, and will copy the contents of all environments of the selected type into the respective target files.---The use of a marker pattern is necessary here, and no \textit{codefile} should be specified.
+\item[Option -e:] \texttt{xtrcode -e}\textit{environment texfile} searches for \textit{environment} instead of the default verbatim or Verbatim.
+\item[Option -p:] \texttt{xtrcode -p}\textit{pattern texfile} uses \textit{pattern} instead of the default \verb/%%@/ as a marker. If \texttt{-p} is used without a pattern, no marker patterns are taken into account.
+\end{description}
+If there are nested environments of the same type, the outermost is assumed to be the one to extract.
+
+\section{Example}
+Consider a \LaTeX\ file \texttt{progdoc.tex} with the following description of two programs:
+\begin{vverbatim}
+In the following I describe my sophisticated program which consists of a
+main program and a subroutine.\par
+In the main part, the subroutine is called:
+%%@ main.f
+\begin{verbatim}
+ program main
+ open(10,file="dat1",status="new")
+ write (*,*) 'Enter number to be squared:'
+ read (*,*) zin
+ call sub1(zin,zout)
+\end{verbatim}
+Then the result is written to a file.
+%%@ main.f
+\begin{verbatim}
+ write (10,*) zout
+ close(10)
+ end
+\end{verbatim}
+The subroutine calculates the result by
+\begin{equation}
+y=x^2.
+\end{equation}
+\verb/x*x/ was used instead of \verb/x**2/ to increase efficiency.
+%%@ sub1.f
+\begin{verbatim}
+ subroutine sub1(x,y)
+ y=x*x
+ return
+ end
+\end{verbatim}
+A further subroutine for calculation of cubes is under development.
+\end{vverbatim}
+With \texttt{xtrcode -a progdoc.tex}, all the code in the verbatim environments will be extracted, copying everything marked with \verb/%%@ main.f/ into a file \texttt{main.f} and everything marked with \verb/%%@ sub1.f/ into a file \texttt{sub1.f}. With \texttt{xtrcode progdoc.tex sub1.f} you can extract everything marked with \verb/%%@ sub1.f/; with \texttt{xtrcode -eequation -p progdoc.tex} you can extract all lines of all equation environments.
+\end{document}
+