summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2010-10-11 00:24:56 +0000
committerKarl Berry <karl@freefriends.org>2010-10-11 00:24:56 +0000
commitdf4c7d3e395c9b22ace64dbbf61191ac43beea3f (patch)
tree15d4350ce1147556781eabb0d8b436754816efb0 /Master/texmf-dist/tex/context
parent6d35fc8476c39b632c9dd7bb53b2bb979c93f8d2 (diff)
context-filter update (10oct10)
git-svn-id: svn://tug.org/texlive/trunk@20050 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context')
-rw-r--r--Master/texmf-dist/tex/context/third/filter/t-filter.tex80
1 files changed, 62 insertions, 18 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 9ae777aa3b7..1d31bbf16f7 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.09.26,
+%D version=2010.10.09
%D title=\CONTEXT\ User Module,
%D subtitle=Filter,
%D author=Aditya Mahajan,
@@ -27,6 +27,8 @@
\def\currentexternalfilter{}
\def\externalfiltercountername{\??externalfilter??-\currentexternalfilter-counter}
+\newwrite\externalfilterwrite
+
\def\externalfilterparameter#1%
{\csname
\docheckparentparameter{\??externalfilter??\currentexternalfilter}{#1}%
@@ -67,9 +69,8 @@
{\expandafter\newcounter\csname\externalfiltercountername\endcsname}%
\setvalue{\e!start#1}{\bgroup\obeylines\dodoubleargument\dostartexternalfilter[#1]}%
\setvalue{\e!stop#1}{\doprocessexternalfilter}%
- \setvalue{process#1file}{\dodoubleargument\doprocessexternalfile[#1]}%
- %TODO: Inline.
- %\setvalue{#1}##1{\save ##1 to file}
+ \setvalue{process#1file}{\dodoubleargument\doprocessexternalfiler[#1]}%
+ \setvalue{inline#1}{\doinlineexternalfilter[#1]}
}
@@ -79,10 +80,15 @@
\begingroup % to keep assignments local
\edef\currentexternalfilter {#1}%
\getparameters[\??externalfilter??#1][\c!name=,#2]%
- % Set the name of temp file for os filter
+ \setexternalfilterfilenames
+ % Capture the contents of the buffer
+ \dostartbuffer[\externalfiltertmpfile][\e!start#1][\e!stop#1]}
+
+\def\setexternalfilterfilenames
+ {% Set the name of temp file for os filter
\doifelse{\externalfilterparameter\c!continue}\v!yes
- {\edef\externalfiltertmpfile{\??externalfilter??-#1-\csname\externalfiltercountername\endcsname}}
- {\edef\externalfiltertmpfile{\??externalfilter??-#1}}
+ {\edef\externalfiltertmpfile{\??externalfilter??-\currentexternalfilter-\csname\externalfiltercountername\endcsname}}
+ {\edef\externalfiltertmpfile{\??externalfilter??-\currentexternalfilter}}
\doifsomething{\externalfilterparameter\c!name}
{\edef\externalfiltertmpfile{\externalfilterparameter\c!name}}
% The following macros are useful for filter= and filtercommand= options
@@ -92,10 +98,9 @@
\edef\externalfilterinputfile {\externalfilterbasefile.tmp}%
% The name of the file to which the output is written
\edef\externalfilteroutputfile{\externalfilterparameter\c!output}%
- % Capture the contents of the buffer
- \dostartbuffer[\externalfiltertmpfile][\e!start#1][\e!stop#1]}
+ }
-\def\doprocessexternalfilter%
+\def\doprocessexternalfilter
{% By defualt, buffers are in memory in MkIV
\doifmode\s!mkiv{\savebuffer[\externalfiltertmpfile]}%
% Run external command
@@ -112,7 +117,7 @@
{\doifmode{*first}
{\executesystemcommand
{mtxrun --ifchanged=\externalfilterinputfile\space
- bin:\externalfilterparameter\c!filtercommand}}}
+ --direct \externalfilterparameter\c!filtercommand}}}
{\executesystemcommand
{\externalfilterparameter\c!filtercommand}}}
@@ -120,7 +125,8 @@
{\doif{\externalfilterparameter\c!read}\v!yes
{\doiffileelse{\externalfilteroutputfile}
{\dodoreadprocessedfile}
- {{\tttf TODO: File \externalfilteroutputfile\ not found! Check your definition}}}}
+ %TODO: Proper error message
+ {{\tttf File \externalfilteroutputfile\ not found! Check your definition}}}}
\def\dodoreadprocessedfile
{\begingroup
@@ -130,16 +136,54 @@
\externalfilterparameter\c!after
\endgroup}
-\def\doprocessexternalfile[#1][#2]%
- {\edef\currentexternalfilter {#1}%
- \edef\externalfilterinputfile {#2}%
- \splitfiletype {#2}%
+\def\doprocessexternalfiler[#1][#2]#3%
+ {\begingroup
+ \edef\currentexternalfilter {#1}%
+ \getparameters[\??externalfilter??#1][\c!name=,#2]% TODO: Add continue=yes
+ % Currently filters with a pipe (|) fail with continue=yes
+ \edef\externalfilterinputfile {#3}%
+ \splitfiletype {#3}%
%BEWARE. \edef doesn not work
- \def\externalfilterbasefile {\splitoffname}
+ \def\externalfilterbasefile {\splitoffname}%
\def\externalfilteroutputfile{\externalfilterparameter\c!output}%
\doexecuteexternalfilter
- \doreadprocessedfile}
+ \doreadprocessedfile
+ \endgroup}
+\def\doinlineexternalfilter[#1]%
+ {\begingroup % to keep assignments local
+ \edef\currentexternalfilter {#1}%
+ \getparameters[\??externalfilter??#1][\c!name=,\c!continue=\v!no]%
+ \setexternalfilterfilenames
+ \pushcatcodetable
+ \futurelet\next\dodoinlineexternalfilter}
+
+\def\dodoinlineexternalfilter
+ {\ifx\next\bgroup
+ \expandafter\dodoinlineexternalfilterA
+ \else
+ \expandafter\dodoinlineexternalfilterB
+ \fi}
+
+\def\dodoinlineexternalfilterA
+ {\setcatcodetable \typcatcodesa
+ \redoinlineexternalfilter}
+
+\def\dodoinlineexternalfilterB#1%
+ {\setcatcodetable \vrbcatcodes
+ \def\dododoinlineexternalfilterB##1#1{\redoinlineexternalfilter{##1}}%
+ \dododoinlineexternalfilterB}
+
+\def\redoinlineexternalfilter#1%
+ {\immediate\openout \externalfilterwrite\externalfilterinputfile
+ \immediate\write \externalfilterwrite{\detokenize{#1}}%
+ \immediate\closeout\externalfilterwrite
+ \popcatcodetable
+ \doexecuteexternalfilter
+ \doreadprocessedfile
+ \endgroup}
+
+
\setupexternalfilters
[