summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2010-11-01 22:56:55 +0000
committerKarl Berry <karl@freefriends.org>2010-11-01 22:56:55 +0000
commit7a633c81ad29409737208c24b0e92dd258862fcd (patch)
treeb977f4df249bab8d76ea1230a0c42727c0eb1b9a /Master/texmf-dist/tex
parent124ab1aa006529a0f1a3fa7c5fa7712e8eb558bf (diff)
context-filter (1nov10)
git-svn-id: svn://tug.org/texlive/trunk@20288 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r--Master/texmf-dist/tex/context/third/filter/t-filter.tex73
1 files changed, 58 insertions, 15 deletions
diff --git a/Master/texmf-dist/tex/context/third/filter/t-filter.tex b/Master/texmf-dist/tex/context/third/filter/t-filter.tex
index e2391a63619..5f7ba878e5c 100644
--- a/Master/texmf-dist/tex/context/third/filter/t-filter.tex
+++ b/Master/texmf-dist/tex/context/third/filter/t-filter.tex
@@ -1,6 +1,6 @@
%D \module
%D [ file=t-filter,
-%D version=2010.10.09
+%D version=2010.10.30
%D title=\CONTEXT\ User Module,
%D subtitle=Filter,
%D author=Aditya Mahajan,
@@ -36,9 +36,10 @@
%D \subsubject {Messages}
-\setinterfacemessage{externalfilter}{title} {\m!externalfilter}
-\setinterfacemessage{externalfilter}{notfound}{file -- cannot be found}
-\setinterfacemessage{externalfilter}{missing} {output file missing}
+\setinterfacemessage{externalfilter}{title} {\m!externalfilter}
+\setinterfacemessage{externalfilter}{notfound} {file -- cannot be found}
+\setinterfacemessage{externalfilter}{missing} {output file missing}
+\setinterfacemessage{externalfilter}{forbidden} {Fatal Error: Cannot use absolute path -- as directory}
%D \subsubject {Name space}
%D
@@ -88,6 +89,11 @@
\fi
\stoptexdefinition
+\def\doshowfilterstatus#1%
+ {\iftraceexternalfilters
+ \writestatus\m!externalfilter{#1}%
+ \fi}
+
\starttexdefinition doshowfiltercommand
\writestatus\m!externalfilter{command : \externalfilterparameter\c!filtercommand}
\stoptexdefinition
@@ -113,8 +119,9 @@
{\dodoubleargument\dodefineexternalfilter}
\def\dodefineexternalfilter[#1][#2]%
- {\edef\currentexternalfilter{#1}%
- \getparameters[\??externalfilter??#1][\s!parent=\??externalfilter??,#2]%
+ {\doshowfilterstatus{defining filter : #1}%
+ \edef\currentexternalfilter{#1}%
+ \getparameters[\??externalfilter??#1][\s!parent=\??externalfilter??,#2]%
\doif{\externalfilterparameter\c!continue}\v!yes
{\expandafter\newcounter\csname\externalfiltercountername\endcsname}%
\setvalue{\e!start#1}{\bgroup\obeylines\dodoubleargument\dostartexternalfilter[#1]}%
@@ -126,8 +133,8 @@
\def\dostartexternalfilter[#1][#2]% filter options
{% Initializations
\egroup %\bgroup in \start#1
- \begingroup % to keep assignments local
\edef\currentexternalfilter {#1}%
+ \begingroup % to keep assignments local
\getparameters[\??externalfilter??#1][\c!name=,#2]%
\setexternalfilterfilenames
% Capture the contents of the buffer
@@ -138,11 +145,14 @@
\edef\currentexternalfilter {#1}%
\getparameters[\??externalfilter??#1][\c!name=,#2]% TODO: Add continue=yes
% Currently filters with a pipe (|) fail with continue=yes
+ \setexternalfilterdirectory
\edef\externalfilterinputfile {#3}%
\splitfiletype {#3}%
%BEWARE. \edef doesn not work
\def\externalfilterbasefile {\splitoffname}%
- \def\externalfilteroutputfile{\externalfilterparameter\c!output}%
+ % The output is always in the directory specified by
+ % \c!directory; even if the input is from some other directory
+ \def\externalfilteroutputfile{\getexternalfilterdirectory\externalfilterparameter\c!output}%
\doshowfilterstate
\doexecuteexternalfilter
\doreadprocessedfile
@@ -192,14 +202,36 @@
%D \section {Helper Functions}
%D
+%D \subsubject {Set the name of output directory}
+
+\def\setexternalfilterdirectory
+ {\edef\getexternalfilterdirectory{\externalfilterparameter\c!directory}%
+ \doifsomething{\getexternalfilterdirectory}\dosetexternalfilterdirectory}
+
+\def\dosetexternalfilterdirectory
+ {\expandafter\docheckdirectorystart\getexternalfilterdirectory\@nil
+ \expandafter\docheckdirectorystop\getexternalfilterdirectory/\@nil}
+
+\def\docheckdirectorystart#1#2\@nil
+ {\doif{#1}{/}
+ {\writeline
+ \showmessage\??externalfilter??{forbidden}\getexternalfilterdirectory
+ \batchmode
+ \normalend}}
+
+\def\docheckdirectorystop#1#2/#3\@nil
+ {\edef\getexternalfilterdirectory{#1#2/}}
+
+
%D \subsubject {Set file names}
%D
%D \type{\externalfilterbasefile} is the name of the temporary file without
-%D extesion. Its actual value depends on the state of \type{continue} key as
+%D extension. Its actual value depends on the state of \type{continue} key as
%D well as the value of \type{name} key.
\def\setexternalfilterfilenames
- {% Set the name of temp file for os filter
+ {\setexternalfilterdirectory
+ % Set the name of temp file for the filter
\doifelse{\externalfilterparameter\c!continue}\v!yes
{\edef\externalfiltertmpfile{\??externalfilter??-\currentexternalfilter-\csname\externalfiltercountername\endcsname}}
{\edef\externalfiltertmpfile{\??externalfilter??-\currentexternalfilter}}
@@ -208,10 +240,20 @@
% The following macros are useful for filter= and filtercommand= options
% The basename of the external file
\edef\externalfilterbasefile {\jobname-\externalfiltertmpfile}%
- % The name of the buffer to which data is written
- \edef\externalfilterinputfile {\externalfilterbasefile.tmp}%
- % The name of the file to which the output is written
- \edef\externalfilteroutputfile{\externalfilterparameter\c!output}%
+ % In MkII, the buffer output is written to \TEXbufferfile{buffername} where
+ % the macro \TEXbufferfile is defined as
+ %
+ % \def\TEXbufferfile #1{\bufferprefix#1.\f!temporaryextension}
+ %
+ % We redefine bufferprefix to include the directory name.
+ \doifmode{\s!mkii}
+ {\edef\bufferprefix{\getexternalfilterdirectory\jobname-}}
+ % In MkIV, we do not need to do such jugglary, because we can specify the
+ % name of the file where the buffer has to be saved. This file is
+ % \externalfilterinputfile (because it is the input to the filter).
+ \edef\externalfilterinputfile {\getexternalfilterdirectory\externalfilterbasefile.\f!temporaryextension}%
+ % The name of the file to which the filter output is written
+ \edef\externalfilteroutputfile{\getexternalfilterdirectory\externalfilterparameter\c!output}%
\doshowfilterstate
}
@@ -222,7 +264,7 @@
\def\doprocessexternalfilter
{% By defualt, buffers are in memory in MkIV
- \doifmode\s!mkiv{\savebuffer[\externalfiltertmpfile]}%
+ \doifmode\s!mkiv{\savebuffer[\externalfiltertmpfile][\externalfilterinputfile]}%
% Run external command
\doexecuteexternalfilter
\doreadprocessedfile
@@ -274,6 +316,7 @@
\c!continue=\v!no,
\c!read=\v!yes,
\c!readcommand=\ReadFile,
+ \c!directory=,
\c!output=\externalfilterbasefile.tex,
\c!filter=,
\c!filtercommand={\externalfilterparameter\c!filter\space \externalfilterinputfile},