[pdftex] Experiment with a new TeX primitive
Taco Hoekwater
taco at elvenkind.com
Wed Feb 4 21:49:18 CET 2004
Hi,
How about this:
begin
scan_toks(false, true);
str_toks(str_start[experiment(tokens_to_string(def_ref))]);
ins_list(link(temp_head));
delete_token_ref(def_ref);
end
- I don't understand why these call_func's in the pdftex code exist.
(If anybody knows and can explain that would be great ;))
- str_toks() expects a pool_pointer as argument, not a str_number.
this was the main problem with your code.
- ins_list() is somewhat more accurate than back_list().
- you need to call tokens_to_string() so that experiment receives
a tex string (instead of a token list)
Good luck, Taco
On Wed, 04 Feb 2004 17:40:21 +0100
Hans Hagen <pragma at wxs.nl> wrote:
> At 12:03 31/01/2004, Nagy Bence wrote:
> >Dear developers,
> >
> >I made a small experiment to understand better how web2c works
> >(calling pascal<->C codes), so i defined a new TeX primitive
> >(\experiment). It calls an external C-function to print out its
> >parameter, and this function gives back a new string (like a search and
> >replace engine).
> >
> >The code from the C-file:
> >
> >strnumber experiment(integer t)
> >{
> > tex_printf("<%s>",makecstring(tokenstostring(t)));
> > return maketexstring("apple");
> >}
> >
> >The main inserted code from pdftex.ch:
> >
> >@ @<Implement \.{\\experiment}@>=
> >begin
> > call_func(scan_toks(false, true));
> > back_list(link(experiment(def_ref)));
> > delete_token_ref(def_ref);
> >end
> >
> >All works fine except that I can not put back the new string ("apple")
> >to the token list. The function back_list causes a segmentation
> >fault, but it should work like the \lowercase or \uppercase primitive
> >(the experiment C-function gives back an integer value well). What is
> >wrong?
>
> You need to simulate something:
>
> \ifx\scratchread \undefined \newread \scratchread \fi
> \ifx\scratchwrite\undefined \newwrite\scratchwrite \fi
>
> \let\endofresultline\relax
> \let\resultofrun \empty
>
> \def\resultrunfile {\jobname.src.tmp}
> \def\resultrunerror{no result}
>
> \def\runsystemcommand#1%
> {\bgroup
> % reset results
> \global\let\endofresultline\relax
> \global\let\resultofrun\empty
> % erase resultfile
> \immediate\openout\scratchwrite\resultrunfile
> \immediate\write\scratchwrite{\resultrunerror}%
> \immediate\closeout\scratchwrite
> % run command
> \immediate\write18{#1 > \resultrunfile}%
> % define collector
> \def\runsystemcommand
> {\ifeof\scratchread \else
> \endlinechar -1
> \readline\scratchread to \next
> \xdef\resultofrun{\resultofrun\next\endofresultline}%
> \expandafter\runsystemcommand
> \fi}%
> % fetch result
> \openin\scratchread\resultrunfile\relax
> \runsystemcommand
> \closein\scratchread
> % done
> \egroup}
>
> \starttext
>
> \runsystemcommand{dir /s} \let\endofresultline\par \tt \resultofrun
>
> \stoptext
>
> so, the best place to look is in the etex code and see how the \readline
> results end up in tex
>
> Hans
>
> _______________________________________________
> pdftex mailing list
> pdftex at tug.org
> http://tug.org/mailman/listinfo/pdftex
More information about the pdftex
mailing list