summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2012-03-10 23:34:45 +0000
committerKarl Berry <karl@freefriends.org>2012-03-10 23:34:45 +0000
commit23bc2839e583571da662eee773fad32e73c06e92 (patch)
treee18c848606498f13fdb95401de4f060fa0d0ba42
parent82e25e064ddf4debd7223a07bcd6312fbbb23333 (diff)
bashful 0.93 (10mar12)
git-svn-id: svn://tug.org/texlive/trunk@25597 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/latex/bashful/Makefile16
-rw-r--r--Master/texmf-dist/doc/latex/bashful/README2
-rw-r--r--Master/texmf-dist/doc/latex/bashful/bashful.pdfbin470434 -> 568694 bytes
-rw-r--r--Master/texmf-dist/doc/latex/bashful/bashful.tex246
-rw-r--r--Master/texmf-dist/tex/latex/bashful/bashful.sty329
5 files changed, 419 insertions, 174 deletions
diff --git a/Master/texmf-dist/doc/latex/bashful/Makefile b/Master/texmf-dist/doc/latex/bashful/Makefile
index 1cf8a1d9cb2..aa090be88d9 100644
--- a/Master/texmf-dist/doc/latex/bashful/Makefile
+++ b/Master/texmf-dist/doc/latex/bashful/Makefile
@@ -1,16 +1,26 @@
PACKAGE=bashful
+ARTICLE=00
SOURCES=${PACKAGE}.tex ${PACKAGE}.sty Makefile README
${PACKAGE}.pdf: ${SOURCES}
pdflatex -shell-esc ${PACKAGE}.tex
pdflatex -shell-esc ${PACKAGE}.tex
+${ARTICLE}.pdf: ${ARTICLE}.tex
+ xelatex -shell-esc ${ARTICLE}.tex
+ xelatex -shell-esc ${ARTICLE}.tex
+
wrap: ${PACKAGE}.zip
-${PACKAGE}.zip: ${PACKAGE}.pdf $(SOURCES)
+${PACKAGE}.zip: ${PACKAGE}.pdf $(SOURCES) ${ARTICLE}.tex ${ARTICLE}.pdf
+ zip $@ $?
+
+${ARTICLE}.zip: *.sty *.tex *.sh *.stderr *.stdout error.*
zip $@ $?
clean:
rm -rf [dD]elme* *.aux *.sh *.osh *.toc *~ *.log *.out *.dvi *.lsh *.stderr \
- *.stdout *.toc *.c minimal* date bashful.date *.exitCode condition.* \
- temperature.* _00 _bashful
+ *.stdout *.toc *.c minimal.* error.* date bashful.date *.exitCode \
+ condition.* temperature.* _00 _bashful bashful.pdf *.pdf *.backup *.ps \
+ begins.tex examining.tex good.* morning.* evening.* *.lst init.tex \
+ lines.tex weather.tex words.tex ls.* _rev.tex
diff --git a/Master/texmf-dist/doc/latex/bashful/README b/Master/texmf-dist/doc/latex/bashful/README
index d3a28c02793..347c72834ac 100644
--- a/Master/texmf-dist/doc/latex/bashful/README
+++ b/Master/texmf-dist/doc/latex/bashful/README
@@ -1,4 +1,4 @@
-The bashful package, v 0.92
+The bashful package, v 0.93
This package makes it possible to execute bash scripts from within LaTeX. The
main application is in writing computer-science texts, in which you want to
diff --git a/Master/texmf-dist/doc/latex/bashful/bashful.pdf b/Master/texmf-dist/doc/latex/bashful/bashful.pdf
index b8cd348bc61..3dea2a9acf2 100644
--- a/Master/texmf-dist/doc/latex/bashful/bashful.pdf
+++ b/Master/texmf-dist/doc/latex/bashful/bashful.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/bashful/bashful.tex b/Master/texmf-dist/doc/latex/bashful/bashful.tex
index c2247d1266f..9bca08b88d7 100644
--- a/Master/texmf-dist/doc/latex/bashful/bashful.tex
+++ b/Master/texmf-dist/doc/latex/bashful/bashful.tex
@@ -1,5 +1,5 @@
\documentclass{ltxdoc} % Process with xelatex -shell-escape
-\usepackage[verbose]{bashful}
+\usepackage[verbose,unique]{bashful}
\usepackage[colorlinks=true]{hyperref}
\usepackage{gensymb}
@@ -12,14 +12,23 @@
\newcommand\me{bashful}
\newcommand\bashful{\textsf{\me}\xspace}
- \lstdefinestyle{input}{
- basicstyle=\ttfamily,
- showstringspaces=false,
- aboveskip=0pt,
- belowskip=0pt}%
+\lstdefinestyle{input}{basicstyle=\ttfamily\footnotesize,
+ keywords={},upquote=true,extendedchars=false,
+ showstringspaces=false,aboveskip=0pt,belowskip=0pt}
+\lstdefinestyle{scriptsize}{style=input,basicstyle=\ttfamily\scriptsize}
+
+% listings style for the script, standard output file, and standard error file.
+\lstdefinestyle{bashfulScript}{style=input}
+\lstdefinestyle{bashfulStdout}{style=input}
+\lstdefinestyle{bashfulStderr}{style=input,
+ basicstyle=\ttfamily\footnotesize\color{red}}
+\newcommand\listFile[1]{%
+ \vspace{0.8em plus 0.3em minus 0.3em}%
+ \lstinputlisting[style=input,frameround=ftttt,frame=trBL]{#1}%
+ \vspace{0.8em plus 0.3em minus 0.3em}}
\title{The \bashful Package\thanks{
- Copyright \copyright{} 2011 by Yossi Gil
+ Copyright \copyright{} 2011, 2012 by Yossi Gil
\url{mailto:yogi@cs.technion.ac.il}.
This work may be distributed and/or modified under the conditions of the
\emph{\LaTeX{} Project Public License} (LPPL), either version 1.3 of this
@@ -46,10 +55,9 @@ This work consists of the files \texttt{\me.tex} and \texttt{\me.sty}
\makeatother
\begin{document}
-
\bash
cat << EOF > README
-The bashful package, v 0.92
+The bashful package, v 0.93
This package makes it possible to execute bash scripts from within LaTeX. The
main application is in writing computer-science texts, in which you want to
@@ -71,7 +79,6 @@ stat -c %y bashful.sty | sed -e s+-+/+g -e 's/ .*//g' > date
\maketitle
-
\begin{abstract}
\parindent 1.5ex
\parskip 0.5em
@@ -146,7 +153,44 @@ You may not care so much about these bits of truly
but you may be surprised that they were produced
by the very process of \LaTeX{}ing the input.
-How did I do that? Well, the first step was to write
+\bash
+cat << EOF > ls.tex
+\documentclass{article}
+\usepackage[a6paper]{geometry}
+\usepackage{bashful}
+\pagestyle{empty}
+\begin{document}
+The directories in my \texttt{/usr} directory are:
+\bash[stdout]
+ls -F /usr
+EOF
+echo "\\END" >> ls.tex
+cat << EOF >> ls.tex
+That's it!
+\end{document}
+EOF
+xelatex -shell-escape ls.tex
+\END
+
+Before I tell you how I generated this information,
+ let me demonstrate the use of the \bashful package for the purpose of
+ incorporating the list of files in a folder into your output.
+
+This simple \LaTeX{} file generates a listing of all files
+ in the \texttt{/usr} directory, using the UNIX \texttt{ls}
+ command:
+
+\begin{minipage}{\textwidth}
+\listFile{ls.tex}
+\end{minipage}
+
+The printed output of this file is then
+
+\begin{center}
+ \fbox{\includegraphics[scale=0.8,trim=20 200 40 50]{ls.pdf}}
+\end{center}
+
+To generate the weather information, I wrote
a series of shell commands that retrieve the current temperature,
and another such series to obtain the current
weather conditions.
@@ -237,7 +281,6 @@ When \LaTeX{} encountered these, it executed the bash commands and
Subsequently, I could use the content of these files by writing:
-
\begin{quote}
\bash
sed -n "/^At the time/,/^You may not/ p" bashful.tex > init.tex
@@ -246,16 +289,16 @@ sed -n "/^At the time/,/^You may not/ p" bashful.tex > init.tex
\lstinputlisting[style=input,belowskip=0pt]{init.tex}\ldots
\end{quote}
-\section{An Easy to Digest Example}
-If you were intimidated by technicalities of the
- above description, let's try another example
- that might be easier to digest.
-
-I will start by telling a simple story
+\section{Application for Teaching Programming}
+\bashful primary application is for writing documents which describe
+ computer programming.
+You can include the programs in your text, and have them compiled
+ and executed as part of the \LaTeX{} processing.
+To demonstrated I will first tell a simple story
of writing, compiling and executing and
- a simple program.
+ a short program.
Then, I will explain how I used the \verb+\bash+
- command to not only tell a story, but
+ command to not only tell the story, but
also to play it live: that is, authoring
a simple~C program, compiling it and executing
it, all from within \LaTeX{}.
@@ -380,7 +423,7 @@ The \texttt{stdout} adds to my listing
the string \texttt{Hello, World!} that this
execution produces to the standard output.
-\section{Dealing with Shell Command Errors}
+\section{Dealing With Errors}
Using \bashful{} to demonstrate
my \emph{Hello, World!} program, made
sure that the story I told is accurate:
@@ -423,13 +466,16 @@ Since \texttt{minimal.tex} contains \verb+\END+,
\item Creating the header of \texttt{minimal.tex}:
\bash[script]
cat << EOF > minimal.tex
-\documentclass{standalone}
+\documentclass{article}
+\usepackage[a6paper]{geometry}
\usepackage{bashful}
+\pagestyle{empty}
\begin{document}
This document creates a simple erroneous C program
and then compiles it:
\bash[script,stdout]
-echo "main(){return int;}" > error.c; cc error.c
+echo "main(){return int;}" > error.c
+cc error.c
EOF
\END
\item Adding \verb+\END+ to \texttt{minimal.tex}
@@ -450,20 +496,18 @@ cat minimal.tex
\END
\end{minipage}
-I am now ready to run \texttt{minimal.tex} through \LaTeX{},
- but since I will not run the \texttt{latex} command myself,
- I will make sure a \texttt{q} character is sent to it
- when the anticipated error occurs.
+I am now ready to run \texttt{minimal.tex} through \LaTeX{},
+ but since I will not run the \texttt{latex} command myself,
+ I will send a ``\texttt{q}'' character
+ to it to abort execution when the anticipated error occurs.
-\begin{minipage}{\textwidth}
- \lstdefinestyle{bashfulStdout}{
- showstringspaces=false,
- basicstyle=\small\ttfamily,
- }%
+\lstdefinestyle{bashfulScript}{style=scriptsize}
+\lstdefinestyle{bashfulStdout}{style=scriptsize}
\bash[script,stdout]
-yes q | pdflatex -shell-esc minimal.tex | fmt -s -w 55
+yes q | xelatex -shell-esc minimal.tex | sed /texmf-dist/d
\END
-\end{minipage}
+\lstdefinestyle{bashfulScript}{style=input}
+\lstdefinestyle{bashfulStdout}{style=input}
You can see that when \LaTeX{} tried to process \texttt{minimal.tex},
it stopped execution while indicating that file
@@ -485,9 +529,93 @@ Note that the failure to compile \texttt{hello.c},
Here is what \texttt{minimal.pdf} looks like:
\begin{center}
- \includegraphics[scale=0.9]{minimal.pdf}
+ \fbox{\includegraphics[scale=0.8,trim=30 300 10 40]{minimal.pdf}}
\end{center}
+\section{Other Commands}
+\begin{description}
+\item[\texttt{\textbackslash{}bashStdout}]
+After each execution of \verb+\bash+, the macro \verb+\bashStdout+
+is defined to entire contents of
+ the standard output of the executed script.
+
+For example, I can write
+\begin{quote}
+\begin{verbatim}
+To obtain the following sentence:
+\bash
+uname -o
+\END
+\begin{quote}
+``This document was prepared on \emph{\bashStdout}''
+\end{quote}
+\end{verbatim}
+\end{quote}
+To obtain the following sentence:
+\bash
+uname -o
+\END
+\begin{quote}
+``This document was prepared on \emph{\bashStdout}''
+\end{quote}
+
+\item[\texttt{\textbackslash{}bashStderr}]
+Similar to \verb+\bashStderr+, except that it
+ is defined is defined to the standard error of the executed script.
+(Be ware that you must apply error tolerance flags
+ to use this command, since normally,
+ if the script generates anything to the standard error stream,
+ \LaTeX{} processing will halt, asking for your attention.)
+
+\item[\texttt{\textbackslash{}splice}]
+Shell commands passed to the \verb+\splice+
+ macro are executed in a similar fashion to
+ commands enclosed between \verb+\bash+
+ and \verb+\END+, but, in addition to this execution,
+ \bashful incorporates the standard output into the main file.
+For example, I can write
+\begin{quote}
+\begin{verbatim}
+Here is a nice quote for you to remember.
+\begin{quote}
+\emph{\splice{fortune}}
+\end{quote}
+\end{verbatim}
+\end{quote}
+To obtain
+\begin{quote}
+Here is a nice quote for you to remember.
+\begin{quote}
+\emph{\splice{fortune}}
+\end{quote}
+\end{quote}
+
+Unlike the \verb+\bash+\ldots\verb+\END+,
+ \verb+\splice+ does not treat its argument
+ as if it was \texttt{verbatim}.
+Using special characters can therefore be
+ tricky with \verb+\splice+.
+On the positive side, macro expansion within
+ this argument can be handy.
+\end{description}
+
+\bash
+cat 00.tex |\
+tr -c "a-zA-Z\\\\" "\012" |\
+tr "\\\\" "@" |
+sed "s/@/ @/g" |\
+tr " " "\012" |\
+sed "/^@$/d" |\
+grep @ | sort |\
+uniq -c |\
+sort -n |\
+awk '{print$1}' | uniq -c
+\END
+
+
+
+
+
\section{Customization}
@@ -519,6 +647,36 @@ Note that if you use \TeX{}live 2010, you have to configure certain
\option{verbose}{\texttt{true}/\texttt{false}}{\texttt{false}}
If \texttt{true}, be chatty.
+\option{unique}{\texttt{true}/\texttt{false}}{\texttt{false}}
+If \texttt{true}, then \bashful uses
+ unique names for the files it generates in each
+ invocation of the \verb+\bash+ command: \textsf{XX}\texttt{.sh},
+ \textsf{XX}\texttt{.stdout}, \textsf{XX}\texttt{.stderr} and
+ \textsf{XX}\texttt{.exitCode}.
+These names then follow the pattern
+ \textsf{JOB}\texttt{@}\textsf{LINE}\texttt{.}\textsf{EXTENSION},
+ where \textsf{JOB} is the job's name (i.e., \verb+\jobname+),
+ \textsf{LINE} is the number of the line in the input file in
+ which the \verb+\bash+ command was invoked, and
+ \textsf{EXTENSION} is one of ``\texttt{sh}'',
+ ``\texttt{stdout}", ``\texttt{stderr}'' and
+ ``\texttt{exitCode}.
+
+If \texttt{false}, then these files follow the pattern
+ \textsf{JOB}\texttt{.}\textsf{EXTENSION}.
+
+You should use this option your input invokes
+ \verb+\bash+ more than once.
+
+\option{dir}{\sl directoryName}{}
+If \texttt{hide} option is \texttt{true}, then
+ scripts are executed in this directory.
+Initial value of this options is \verb+_00+.
+Note that if you use \TeX{}live, you have to configure certain
+ security flags to make it possible to write to directories
+ whose name start with a dot, or to directories
+ which are not below the current working directory.
+
\subsection{Command Options}
Options to \verb+\bash+ command
@@ -669,15 +827,21 @@ Also, in case bidirectional \TeX{}ing is in effect,
Renamed \texttt{list} to \texttt{script}.
\item
Added \texttt{hide} and \texttt{dir} package options.
- \end{itemize}
+\end{itemize}
+\item[Version 0.93]
+\begin{itemize}
+ \item Added the \texttt{unique} package flag.
+ \item Added the \verb+\splice+, \verb+\bashStdout+ and \verb+\bashStderr+
+ commands.
+ \item Enclosed in the packaging the Prac\TeX{} article
+ source and \texttt{.pdf} file.
+\end{itemize}
\end{description}
\section{Future}
The following may get implemented some day.
\begin{enumerate}
-\item \emph{Package options.} Currently all options are
- passed to the command itself.
\item \emph{A \texttt{clean} option.} This option
will automatically erase files
generated for storing the script, and its standard
@@ -686,7 +850,6 @@ The following may get implemented some day.
\item \emph{A \texttt{noclobber} option.} This option
will make this package safer, by reducing the risk
of accidentally erasing existing files.
-
\end{enumerate}
\section{Acknowledgments}
@@ -697,6 +860,11 @@ The manner by which \verb+\bash+
{\textsf{tobiShell}}.
Martin Scharrer tips on \TeX{} internals
were invaluable.
+I pay tribute to the insight and encouragement offered by Francisco Reinaldo
+ which lead to the Prac\TeX{} journal publication entitled
+ \emph{Bashful Writing and Active Documents} that describes
+ sophisticated applications of this package.
+
\appendix
\section{Source of \texttt{\jobname.sty}}
diff --git a/Master/texmf-dist/tex/latex/bashful/bashful.sty b/Master/texmf-dist/tex/latex/bashful/bashful.sty
index fab73a2de26..21b6f43402e 100644
--- a/Master/texmf-dist/tex/latex/bashful/bashful.sty
+++ b/Master/texmf-dist/tex/latex/bashful/bashful.sty
@@ -1,4 +1,4 @@
-% Copyright (C) 2011 by Yossi Gil yogi@cs.technion.ac.il
+% Copyright (C) 2011,2012 by Yossi Gil yogi@cs.technion.ac.il
% ---------------------------------------------------------------------------
% This work may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3 of this license or
@@ -8,7 +8,7 @@
%
% This work has the LPPL maintenance status `maintained'.
%
-% The Current Maintainer of this work is Yossi Gil.
+% The Current Maintainer of this work is Yossi Gil.
%
% This work consists of the files bashful.tex and bashful.sty and the derived
% bashful.pdf
@@ -16,148 +16,168 @@
\NeedsTeXFormat{LaTeX2e}%
% Auxiliary identification information
-\newcommand\date@bashful{2011/03/12}%
-\newcommand\version@bashful{V 0.92}%
+\newcommand\date@bashful{2012/03/08}%
+\newcommand\version@bashful{V 0.93}%
\newcommand\author@bashful{Yossi Gil}%
\newcommand\mail@bashful{yogi@cs.technion.ac.il}%
\newcommand\signature@bashful{%
- bashful \version@bashful{} by
+ bashful \version@bashful{} by
\author@bashful{} \mail@bashful
}%
-
+
% Identify this package
\ProvidesPackage{bashful}[\date@bashful{} \signature@bashful:
- Write and execute a bash script within LaTeX, with, or
- without displaying the script and/or its output.
+ Write and execute a bash script within LaTeX, with, or
+ without displaying the script and/or its output.
]
\PackageInfo{bashful}{This is bashful, \signature@bashful}%
+\RequirePackage{xcolor}
\RequirePackage{catchfile}
-% Use xkeyval for retrieving parameters
-\RequirePackage{xkeyval}%
+\RequirePackage{xkeyval} % Use xkeyval for retrieving parameters
+\RequirePackage{textcomp} % For upquote
% If true, all activities take place in a designated directory.
\newif\if@hide@BL@\@hide@BL@false
+% \if@unique@BL@ is a Boolean flag, telling us whether unique names should be
+% generated for the auxiliary files (XX.sh, XX.stdout, XX.stderr and
+% XX.exitCode) in each invocation of the \bash command.
+\newif\if@unique@BL@\@unique@BL@false
+\def\unique@BL{\if@unique@BL@ @\the\inputlineno\fi}
+
% This is the default name for a directory in which processing should
% take place if \@hide@BL@true.
\def\directory@BL{_00}
-% Use listing to display bash scripts.
+% Use listing to display bash scripts.
\RequirePackage{listings}%
% listings style for the script, can be redefined by client
\lstdefinestyle{bashfulScript}{
basicstyle=\ttfamily,
keywords={},
+ upquote=true,
showstringspaces=false}%
- % listings style for the stdoutFile, can be redefined by client
+ % listings style for the standard output file, can be redefined by client
\lstdefinestyle{bashfulStdout}{
basicstyle=\sl\ttfamily,
keywords={},
+ upquote=true,
showstringspaces=false
}%
- % listings style for the stderrFile, can be redefined by client
+ % listings style for the standard error file, can be redefined by client
\lstdefinestyle{bashfulStderr}{
basicstyle=\sl\ttfamily\color{red},
keywords={},
+ upquote=true,
showstringspaces=false
}%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % File Name keys in alphabetical order:
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
- % scriptFile: String = \BL@exitCodeFile: Where should the exit code be stored
- % if it is not zero.
- \edef\BL@exitCodeFile{\jobname.exitCode}%
- \define@cmdkey{bashful}[BL@]{exitCodeFile}{}%
-
- % scriptFile: String = \BL@scriptFile: Where should the script be saved?
- \edef\BL@scriptFile{\jobname.sh}%
- \define@cmdkey{bashful}[BL@]{scriptFile}{}%
-
- % stderrFile: String = \BL@stderrFile: Where should the standard error
- % sream be saved?
- \edef\BL@stderrFile{\jobname.stderr}%
- \define@cmdkey{bashful}[BL@]{stderrFile}{}%
-
- % stdoutFile: String = \BL@stdoutFile: Where should the standard output stream
- % be saved?
- \edef\BL@stdoutFile{\jobname.stdout}%
- \define@cmdkey{bashful}[BL@]{stdoutFile}{}%
-
- % dir: String = \directory@BL: name of directory in which execution is going to take
- % place
- \define@cmdkey{bashful}[BL@]{dir}{\def\directory@BL{#1}}%
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % List configuration boolean keys
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
- % list: Boolean = \ifBL@script: Should we list the script we generate?
- \define@boolkey{bashful}[BL@]{script}[true]{}%
-
- % stdout: Boolean = \ifBL@stderr: Should we list the standard error?
- \define@boolkey{bashful}[BL@]{stderr}[true]{}%
-
- % stdout: Boolean = \ifBL@stdout: Should we list the standard output?
- \define@boolkey{bashful}[BL@]{stdout}[true]{}
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % Error checking Boolean keys.
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
- % stdout: Boolean = \ifBL@ignoreExitCode: Should we ignore the exit
- % code?
- \define@boolkey{bashful}[BL@]{ignoreExitCode}[true]{}
-
- % stdout: Boolean = \ifBL@ignoreStderr: Should we ignore the exit
- % code?
- \define@boolkey{bashful}[BL@]{ignoreStderr}[true]{}
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % Miscelaneous keys
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
- % environment: String = \BL@environment: Which environment should we wrap
- % the listings
- \def\BL@environment{none@BL}%
- \define@cmdkey{bashful}[BL@]{environment}{}%
- \newenvironment{none@BL}{}{} % Default, empty environment for wrapping the listings
-
- % prefix: String = \BL@prefix: What prefix should be printed before a listing.
- \def\BL@prefix{\@percentchar\space}%
- \define@cmdkey{bashful}[BL@]{prefix}{}%
-
- % shell: String = \BL@shell: Which shell should be used for execution?
- \def\BL@shell{bash}%
- \define@cmdkey{bashful}[BL@]{shell}{}%
-
- % verbose: Boolean = \ifBL@verbose: Log every step we do
- \define@boolkey{bashful}[BL@]{verbose}[true]{}%
-
-
-\DeclareOptionX{hide}{\@hide@BL@true}
-\DeclareOptionX{dir}{\@hide@BL@true\def\directory@BL{#1}}
-\DeclareOptionX{verbose}{\BL@verbosetrue}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Keys generating file names in alphabetical order:
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% dir: String = \directory@BL: Name of directory in which execution is going
+% to take place
+\define@cmdkey{bashful}[BL@]{dir}{\def\directory@BL{#1}}%
+
+% exitCodeFile: String = \BL@exitCodeFile: In which file should the exit code
+% be stored if it is not zero.
+\def\BL@exitCodeFile{\jobname\unique@BL.exitCode}%
+\define@cmdkey{bashful}[BL@]{exitCodeFile}{}%
+
+% scriptFile: String = \BL@scriptFile: In which file should the script be
+% saved?
+\def\BL@scriptFile{\jobname\unique@BL.sh}%
+\define@cmdkey{bashful}[BL@]{scriptFile}{}%
+
+% stderrFile: String = \BL@stderrFile: In which file should the standard
+% error stream be saved?
+\def\BL@stderrFile{\jobname\unique@BL.stderr}%
+\define@cmdkey{bashful}[BL@]{stderrFile}{}%
+
+% stdoutFile: String = \BL@stdoutFile: In which file should the standard
+% output stream be saved?
+\def\BL@stdoutFile{\jobname\unique@BL.stdout}%
+\define@cmdkey{bashful}[BL@]{stdoutFile}{}%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% List configuration boolean keys
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% list: Boolean = \ifBL@script: Should we list the script we generate?
+\define@boolkey{bashful}[BL@]{script}[true]{}%
+
+% stdout: Boolean = \ifBL@stderr: Should we list the standard error?
+\define@boolkey{bashful}[BL@]{stderr}[true]{}%
+
+% stdout: Boolean = \ifBL@stdout: Should we list the standard output?
+\define@boolkey{bashful}[BL@]{stdout}[true]{}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Error checking Boolean keys.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% stdout: Boolean = \ifBL@ignoreExitCode: Should we ignore the exit
+% code?
+\define@boolkey{bashful}[BL@]{ignoreExitCode}[true]{}
+
+% stdout: Boolean = \ifBL@ignoreStderr: Should we ignore the exit
+% code?
+\define@boolkey{bashful}[BL@]{ignoreStderr}[true]{}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Miscelaneous keys
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% environment: String = \BL@environment: Which environment should we wrap
+% the listings
+\def\BL@environment{none@BL}%
+\define@cmdkey{bashful}[BL@]{environment}{}%
+\newenvironment{none@BL}{}{} % Default, empty environment for wrapping
+ % the listings
+
+% prefix: String = \BL@prefix: What prefix should be printed before a listing.
+\def\BL@prefix{\@percentchar\space}%
+\define@cmdkey{bashful}[BL@]{prefix}{}%
+
+% shell: String = \BL@shell: Which shell should be used for execution?
+\def\BL@shell{bash}%
+\define@cmdkey{bashful}[BL@]{shell}{}%
+
+% verbose: Boolean = \ifBL@verbose: Log every step we do
+\define@boolkey{bashful}[BL@]{verbose}[true]{}%
+
+% The "unique" package flag that tells the package to generated unique names
+% for the auxiliary files. If true the generated files (XX.sh, XX.stdout,
+% XX.stderr and XX.exitCode) are given unique names in each invocation of the
+% \bash command. Unique names are generated by the pattern JOB@LINE.EXTENSION,
+% where JOB is the job's name, LINE is the number of the line in the input in
+% which the \bash command was invoked, and EXTENSION is one of "sh", "stdout",
+% "stderr" and "exitCode".
+\DeclareOptionX{unique} {\@unique@BL@true}
+\DeclareOptionX{hide} {\@hide@BL@true}
+\DeclareOptionX{dir} {\@hide@BL@true\def\directory@BL{#1}}
+\DeclareOptionX{verbose} {\BL@verbosetrue}
+
\ExecuteOptionsX{}
-\ProcessOptionsX\relax
+\ProcessOptionsX\relax
% \bash: the main command we define. It chains to \bashI which chains to
% \bashII, etc.
\begingroup
%\where@BL
\catcode`\^^M\active%
- \gdef\bash{%
+ \gdef\bash{%
\logBL{Beginning a group so that all cat code changes are local}%
\begingroup%
\logBL{Making \^\^M a true newline}%
\catcode`\^^M\active%
\def^^M{^^J}%
\logBL{Checking for optional arguments}%
- \@ifnextchar[\bashI{\bashI[]}%
+ \@ifnextchar[{\bashI}{\bashI[]}%
}%
\endgroup
@@ -168,28 +188,26 @@
\begingroup
\catcode`\^^M\active%
\gdef\bashII{%
- \logBL{bashII: Making \^\^M a true new line}%
+ \logBL{bashII: Making \^\^M a true new line}%
\catcode`\^^M\active%
\def^^M{^^J}%
- \logBL{bashII: Making all characters other}%
+ \logBL{bashII: Making all characters other}%
\let\do\@makeother%
\dospecials%
\bashIII}%
\endgroup
-% \bashIII: Consume all tokens until \END (but ignoring the preceding and
-% terminating newline), and proceed.
+% \bashIII: Consume all tokens until \END (but ignoring the preceding and
+% terminating newline), and proceed.
\begingroup
\catcode`\@=0\relax
\catcode`\^^M\active
@catcode`@\=12@relax%
- @gdef@bashIII^^M#1^^M\END{@bashIV{#1}@bashV{#1}@logBL{bashV: Done!}@endgroup}@endgroup
-%
-
-\newcommand\logBL[1]{\ifBL@verbose\typeout{L\the\inputlineno: #1}\fi}
+ @gdef@bashIII^^M#1^^M%
+ \END{@bashIV{#1}@bashV{#1}@logBL{bashV: Done!}@endgroup}@endgroup
-% \bashIV: Process the tokens by storing them in a script file, and executing
-% this file,
+% \bashIV: Process the tokens by storing them in a script file, and executing
+% this file,
\newcommand\bashIV[1]{%
\logBL{BashIV: begin}%
\makeDirectory@BL
@@ -197,6 +215,11 @@
\executeScriptFile@BL
\logBL{BashIV: done}%
}%
+
+% \logBL: record a log message in verbose mode
+\newcommand\logBL[1]{\ifBL@verbose\typeout{L\the\inputlineno: #1}\fi}
+
+% A macro to create a new directory
\def\makeDirectory@BL{%
\if@hide@BL@
\logBL{Making directory \directory@BL}%
@@ -214,7 +237,7 @@
}
% listing the script file if required, and presenting the standard output and
-% standar error if required.
+% standard error files if required.
\newcommand\bashV[1]{%
\logBL{Wrapping up after execution}%
\storeToFile@BL{\BL@prefix#1}{\BL@scriptFile}%
@@ -222,12 +245,12 @@
\expandFileName@BL\BL@stdoutFile
\expandFileName@BL\BL@stderrFile
\logBL{Files are: \BL@scriptFile, \BL@stdoutFile, and \BL@stderrFile}%
- %\checkScriptErrors@BL
+ \checkScriptErrors@BL
\listEverything@BL
+ \defineMacros@BL
\logBL{Wrap up done}}
\def\expandFileName@BL#1{%
- \logBL{expandFileName}%
\logBL{Setting, if necessary, correct path of \noexpand#1 }%
\if@hide@BL@
\logBL{Prepending path (\directory@BL) to #1}%
@@ -243,13 +266,14 @@
% Store the list of tokens in the first argument into our script file
\newcommand\generateScriptFile@BL[1]{%
+ \logBL{Generating script file \BL@scriptFile}
\storeToFile@BL{#1}{\BL@scriptFile}%
}%
-\newwrite\writer@BL
+\newwrite\writer@BL
% Store the list of tokens in the first argument into the file given
% in the second argument; prepend directory if necessary
-\newcommand\storeToFile@BL[2]{%
+\newcommand\storeToFile@BL[2]{%
\logBL{ #2 :=^^J#1^^J}%
\if@hide@BL@
\logBL{File #2 will be created in \directory@BL}%
@@ -262,9 +286,9 @@
}%
% Store the list of tokens in the first argument into the file given
-% in the second argument; the second argument could be qualified with
+% in the second argument; the second argument could be qualified with
% a directory name.
-\newcommand\storeToFileI@BL[2]{%
+\newcommand\storeToFileI@BL[2]{%
\logBL{Writing to file #2...}%
\immediate\openout\writer@BL#2%
\immediate\write\writer@BL{#1}%
@@ -290,46 +314,53 @@
% Issue an error message if errors found during execution
\newcommand\checkScriptErrors@BL{%
\logBL{Checking for script errors}%
- \begingroup
+% \begingroup
\newif\ifErrorsFound@\ErrorsFound@false
\checkExitCodeFile@BL
\ifdefined\exitCode@BL
- \logBL{Non zero exit code found (\exitCode@BL), and I was not instructed to ignore it}
+ \logBL{Non zero exit code found (\exitCode@BL), and I was not instructed to
+ ignore it}
\ErrorsFound@true
\fi
\def\eoln{\par}
\def\firstErrorLine{\par}
\checkStderrFile@BL
- \logBL{I will print content of \BL@stderrFile\space (if found)}
+ \logBL{I will now print the contents of file \BL@stderrFile\space (if found)}
\ifx\firstErrorLine\eoln
\relax
\else
\logBL{Standard error was not empty, and I was not instructed to ignore it}
- \message{Standard error not empty. Here is how
+ \message{Standard error not empty. Here is how
^^Jfile \BL@stderrFile\space begins:
- ^^J>>>>\space
+ ^^J>>>>\firstErrorLine
+ ^^J>>>>\space
^^Jbut, you really ought to examine this file yourself!}
\ErrorsFound@true
\fi
\ifErrorsFound@
\logBL{Issuing an error message since \BL@stderrFile\space was not empty}%
- \errmessage{Your shell script failed....}
+ \errmessage{Your shell script failed...}%
+ \BL@verbosetrue
+ \logBL{Switching to verbose mode}%
\else
+ \logBL{File \BL@stderrFile\space was empty}%
\logBL{Proceeding as usual}%
\fi
- \endgroup
+% \endgroup
}%
\newcommand\checkExitCodeFile@BL{%
+ \logBL{Considering \BL@exitCodeFile}%
\ifBL@ignoreExitCode
\logBL{Ignoring \BL@exitCodeFile, as per command flag}%
\else
\logBL{Opening \BL@exitCodeFile}%
\openin\reader@BL=\BL@exitCodeFile
\ifeof\reader@BL
- \logBL{File \BL@exitCodeFile\space missing, exit code was probably 0}
+ \logBL{File \BL@exitCodeFile\space is missing, exit code was probably 0}
+ \closein\reader@BL
\else
- \logBL{File \BL@exitCodeFile\space exists, let's get the exit code}%
+ \logBL{File \BL@exitCodeFile\space exists, let's get the exit code}%
\logBL{Reading first line of \BL@exitCodeFile}%
\catcode`\^^M=5
\read\reader@BL to \exitCode@BL
@@ -354,9 +385,9 @@
\logBL{Opening \BL@stderrFile}%
\openin\reader@BL=\BL@stderrFile\relax
\ifeof\reader@BL
- \BL@verbosetrue
\logBL{Hmm... \BL@stderrFile\space does not exist (probably a package bug)}%
\logBL{Switching to verbose mode}%
+ \BL@verbosetrue
\else
\logBL{Reading first line of \BL@stderrFile}%
\catcode`\^^M=5
@@ -369,12 +400,13 @@
\ErrorsFound@true
\fi
\else
- \logBL{File \BL@stderrFile\space has two lines or more}%
- \ErrorsFound@true
+ \logBL{File \BL@stderrFile\space has two lines or more}%
+ \ErrorsFound@true
+ \fi
\fi
\closein\reader@BL
}
-
+
% List the contents of the script, stdout and stderr, as per the flags.
\newcommand\listEverything@BL{%
\logBL{Checking whether any listings are required}%
@@ -384,16 +416,16 @@
\ifBL@stderr\@listSomething@BL@true\fi
\if@listSomething@BL@
\beginWrappingEnvironment@BL
- \listEverythingI@BL
+ \listEverythingWithinEnvironment@BL
\endWrappingEnvironment@BL
\else
\logBL{Nothing has to be listed}%
\fi
}
-% Auxiliary macro to list the contents of the script, stdout and stderr, as per
+% Auxiliary macro to list the contents of the script, stdout and stderr, as per
% the flags.
-\newcommand\listEverythingI@BL{%
+\newcommand\listEverythingWithinEnvironment@BL{%
\logBL{Laying out the correct \noexpand\lstinputlisting commands}%1
\ifBL@script\listScript@BL\BL@scriptFile\fi
\ifBL@stdout\listStdout@BL\BL@stdoutFile\fi
@@ -432,7 +464,7 @@
\expandafter\lstset\expandafter{#2}%
\lstinputlisting{#1}%
}%
-
+
\def\beginWrappingEnvironment@BL{%
\logBL{Beginning environment \BL@environment}%
\expandafter\csname\BL@environment\endcsname
@@ -444,6 +476,45 @@
\expandafter\csname end\BL@environment\endcsname
}%
+% Define the \bashStdout and \bashStderr macro.
+\newcommand\defineMacros@BL{%
+ \logBL{Defining macro for the contents of the standard output file}%
+ \immediate\openin\reader@BL=\BL@stdoutFile
+ \logBL{Opened file \BL@stdoutFile}%
+ \begingroup
+ \endlinechar=-1%
+ \ifeof\reader@BL
+ \logBL{File \BL@stdoutFile was empty}%
+ \global\let\bashStdout\relax
+ \else
+ \logBL{Reading contents of \BL@stdoutFile}%
+ \immediate\read\reader@BL to \BL@temp
+ \global\let\bashStdout\BL@temp
+ \fi
+ \typeout{after EOF}%
+ \logBL{bashStdout :=^^J\bashStdout^^J}%
+ \endgroup
+ \logBL{Closing file \BL@stdoutFile}%
+ \immediate\closein\reader@BL
+ \logBL{Defining macro for the contents of the standard error file}%
+ \immediate\openin\reader@BL=\BL@stderrFile
+ \logBL{Opened file \BL@stderrFile}%
+ \begingroup
+ \endlinechar=-1%
+ \ifeof\reader@BL
+ \logBL{File \BL@stdoutFile was empty}%
+ \global\let\bashStdout\relax
+ \else
+ \logBL{Reading contents of \BL@stderrFile}%
+ \immediate\read\reader@BL to \BL@temp
+ \global\let\bashStderr\BL@temp
+ \fi
+ \logBL{bashStderr :=^^J\bashStderr^^J}%
+ \endgroup
+ \logBL{Closing file \BL@stderrFile}%
+ \immediate\closein\reader@BL
+}
+
\newcommand\fixPolyglossiaBug@BL{%
\logBL{Trying to fix a Polyglossia package bug}%
\ifdefined\ttfamilylatin
@@ -471,7 +542,3 @@
\relax
\fi
}%
-
-
-
-