diff options
Diffstat (limited to 'tex/context/base/java-ini.tex')
-rw-r--r-- | tex/context/base/java-ini.tex | 279 |
1 files changed, 139 insertions, 140 deletions
diff --git a/tex/context/base/java-ini.tex b/tex/context/base/java-ini.tex index 7fdef5345..f9cd778af 100644 --- a/tex/context/base/java-ini.tex +++ b/tex/context/base/java-ini.tex @@ -8,22 +8,22 @@ %D copyright={PRAGMA / Hans Hagen \& Ton Otten}] %C %C This module is part of the \CONTEXT\ macro||package and is -%C therefore copyrighted by \PRAGMA. See mreadme.pdf for -%C details. +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. \writestatus{loading}{Context JavaScript Macros / Initialization} -% BUG: preamble zonder used/used en split +% BUG: preamble zonder used/used en split % JavaScript support is under development. In the near future -% a slightly different model will be used. The JScode stuff -% will probably become just auto function inclusion and the -% JS_* things will disappear. First I have to find a way to +% a slightly different model will be used. The JScode stuff +% will probably become just auto function inclusion and the +% JS_* things will disappear. First I have to find a way to % deal with global variables so the 'uses' thing will remain. % ook p{ref} % documentation should be corrected to JS( - + % Also, obeylines will be supported. \unprotect @@ -31,7 +31,7 @@ %D \JAVA\ support is not implemented as a generic support %D module. The main reason for this is that passing system %D variables to a \JAVASCRIPT\ is closely related to other core -%D macros. First some messages: +%D macros. First some messages: \startmessages dutch library: javascript title: javascript @@ -76,7 +76,7 @@ \stopmessages %D \TEX\ is not the right tool to check the \JAVA\ code; the -%D most we can do is reporting some passed variables: +%D most we can do is reporting some passed variables: \newif\iftraceJScode \traceJScodefalse @@ -86,11 +86,11 @@ \bgroup \catcode127=\@@letter -\gdef\delcharacter{^^7f} +\gdef\delcharacter{^^7f} \egroup %D The number of passed variables is minimalized by setting the -%D next switch. +%D next switch. \newif\ifminimalizeJScode \minimalizeJScodetrue @@ -100,108 +100,108 @@ %D Because \JAVASCRIPT's are activated by the user, for %D instance by activating on a button, their support is closely %D related to the referencing mechanism. Integration takes -%D place by -%D +%D place by +%D %D \starttypen %D \naar{calculate total}[Sum()] %D \stoptypen -%D +%D %D The \type{()} classify this as a script. If they are absent, -%D the keyword is treated as a normal reference. -%D +%D the keyword is treated as a normal reference. +%D %D One can pass arguments to such a script by saying: -%D +%D %D \starttypen %D \naar{calculate total}[Sum(1.5,2.3)] %D \stoptypen -%D -%D References are passed by using the \type{R{}} classifier. -%D +%D +%D References are passed by using the \type{R{}} classifier. +%D %D \starttypen %D \naar{calculate total}[Sum(1.5,2.3,R{overflow})] %D \stoptypen -%D +%D %D The last call calls the script \type{Sum} and passes the -%D next set of variables: -%D +%D next set of variables: +%D %D \starttypen %D JS_S_1="1.5"; %D JS_S_2="2.3"; %D JS_R_3="overflow"; %D JS_P_3=3; %D \stoptypen -%D +%D %D The first two parameters are just strings, the third one %D however is treated as a reference and results in passing the %D reference (if needed this references is prefixed) and the -%D (real) page number. The alternative: -%D +%D (real) page number. The alternative: +%D %D \starttypen %D \naar{calculate total}[JS(Sum{V{1.5},V{2.3},R{overflow}})] %D \stoptypen -%D +%D %D does a verbose passing: -%D +%D %D \starttypen %D JS_V_1=1.5; %D JS_V_2=2.3; %D JS_R_3="overflow"; %D JS_P_3=3; %D \stoptypen -% %D -% %D Finally we have a counter that tells\JAVA\ how many +% %D +% %D Finally we have a counter that tells\JAVA\ how many % %D arguments were passed, % %D % %D \starttypen % %D JS_N % %D \stoptypen -%D We will also support direct function calls. In that case -%D no intermediate variables are used. +%D We will also support direct function calls. In that case +%D no intermediate variables are used. %D \macros %D {startJScode} %D %D A piece of \JAVASCRIPT\ code is defined by saying: -%D +%D %D \starttypen %D \startJScode{SomeScript} -%D var Item=this.getField("item"); +%D var Item=this.getField("item"); %D N=Item.getArray(); -%D Total=this.getField("total"); +%D Total=this.getField("total"); %D Total.value=0; %D for (j=0; j<N.length; j++) %D { if (N[j].value!="") %D { Total.value += N[j].value } } ; -%D if ((JS_N>0) && (JS_R_1!="")) +%D if ((JS_N>0) && (JS_R_1!="")) %D { gotoNamedDest(JS_R_1) }; %D \stopJScode %D \stoptypen -%D +%D %D Such a piece of code is closely related to the interpreter %D used. Watch the last two lines, here the script adapts -%D itself to the presence of a reference. +%D itself to the presence of a reference. %D -%D While +%D While %D %D \starttypen -%D \startJScode{name} +%D \startJScode{name} %D name = 4 ; -%D \stopJScode +%D \stopJScode %D \stoptypen %D -%D assumes uses no preamble or presumes that the preamble is -%D always loaded, the next definition also tells \CONTEXT\ to -%D actually include the preamble needed. +%D assumes uses no preamble or presumes that the preamble is +%D always loaded, the next definition also tells \CONTEXT\ to +%D actually include the preamble needed. %D %D \starttypen -%D \startJScode{uses} uses {later} +%D \startJScode{uses} uses {later} %D uses = 6 ; -%D \stopJScode +%D \stopJScode %D \stoptypen -\long\def\startJScode#1 #2 - {\doifelse{#2}{uses} +\long\def\startJScode#1 #2 + {\doifelse{#2}{uses} {\dostartJScodeA{#1}} {\dostartJScodeB{#1} #2 }} @@ -216,22 +216,22 @@ %D \macros %D {presetJScode} %D -%D The code can be retrieved by saying -%D +%D The code can be retrieved by saying +%D %D \starttypen %D \presetJScode{SomeScript}{template} %D \stoptypen -%D -%D Such a template is a comma separated list, where -%D individual entries can optionally be transformed by -%D \type{R{}} and \type{V{}}. %D -%D After this call, the code is available in \type{\JScode}. +%D Such a template is a comma separated list, where +%D individual entries can optionally be transformed by +%D \type{R{}} and \type{V{}}. +%D +%D After this call, the code is available in \type{\JScode}. \def\setverbosecscharacter#1% {\edef#1{\string#1}} -\def\setverbosecscharacters % temporary hack +\def\setverbosecscharacters % temporary hack {\setverbosecscharacter |\setverbosecscharacter ~% \setverbosecscharacter\:\setverbosecscharacter\;% \setverbosecscharacter\+\setverbosecscharacter\-% @@ -243,14 +243,14 @@ \setverbosecscharacter\4\setverbosecscharacter\5% \setverbosecscharacter\6\setverbosecscharacter\7% \setverbosecscharacter\8\setverbosecscharacter\9% - \setverbosecscharacter\n\setverbosecscharacter\s% + \setverbosecscharacter\n\setverbosecscharacter\s% \setverbosecscharacter\/} \newif\ifdirectJScode \def\presetJScode#1#2% #1=operation #2=arguments {\setverbosecscharacters - \def\par{\delcharacter}% was: { } + \def\par{\delcharacter}% was: { } \scratchcounter\zerocount \globallet\JScode\empty \def\do##1##2% @@ -278,16 +278,16 @@ \dodopresetJSvariables#1\end}% \def\dodopresetJSvariables - {\doifnextcharelse{R}\dodopresetJSrefvariables - {\doifnextcharelse{V}\dodopresetJSvervariables - {\doifnextcharelse{S}\dodopresetJSstrvariables - \dodopresetJSrawvariables}}} + {\doifnextcharelse R\dodopresetJSrefvariables + {\doifnextcharelse V\dodopresetJSvervariables + {\doifnextcharelse S\dodopresetJSstrvariables + \dodopresetJSrawvariables}}} \def\dodopresetJSrefvariables R#1\end {\doifreferencefoundelse{#1} {\donetrue \dododopresetJSvariables R{\referenceprefix#1}% \donefalse\dododopresetJSvariables P{\currentrealreference}} - {\unknownreference{#1}}% + {\unknownreference{#1}}% \ifminimalizeJScode \else \donetrue\dododopresetJSvariables S{#1}% \fi} @@ -297,13 +297,13 @@ \ifminimalizeJScode \else \donetrue\dododopresetJSvariables S{#1}% \fi} - + \def\dodopresetJSstrvariables S#1\end {\donetrue\dododopresetJSvariables S{#1}} \def\dodopresetJSrawvariables #1\end {\donetrue\dododopresetJSvariables S{#1}} - + \def\JSprefix#1% {JS\string_#1\string_\the\scratchcounter} @@ -320,35 +320,35 @@ %D \macros %D {startJSpreamble, flushJSpreamble} -%D +%D %D One can define insert \JAVASCRIPT\ code at the document level %D by using: -%D +%D %D \starttypen -%D \startJSpreamble{oeps} +%D \startJSpreamble{oeps} %D oeps = 1 ; -%D \stopJSpreamble +%D \stopJSpreamble %D \stoptypen -%D -%D which is the same as: +%D +%D which is the same as: %D %D \starttypen -%D \startJSpreamble{now} used now -%D now = 2 ; -%D \stopJSpreamble +%D \startJSpreamble{now} used now +%D now = 2 ; +%D \stopJSpreamble %D \stoptypen -%D -%D while the next definition is only included when actually +%D +%D while the next definition is only included when actually %D used. %D %D \starttypen -%D \startJSpreamble{later} used later -%D later = 3 ; -%D \stopJSpreamble +%D \startJSpreamble{later} used later +%D later = 3 ; +%D \stopJSpreamble %D \stoptypen -%D -%D This command may be used more that once, but always before -%D the first page is shipped out. +%D +%D This command may be used more that once, but always before +%D the first page is shipped out. \newif\ifoneJSpreamble \oneJSpreambletrue @@ -357,7 +357,7 @@ \newcounter\currentJSpreamble \long\def\startJSpreamble#1 #2 % - {\bgroup % we need to restore the catcodes + {\bgroup % we need to restore the catcodes \popendofline % just in case it happens while reading lists \doifelse{#2}{used} {\dostartJSpreamble#1 } @@ -365,7 +365,7 @@ \long\def\dostartJSpreamble#1 #2 #3\stopJSpreamble {\processaction - [#2] + [#2] [ later=>\chardef\JSstatus\zerocount,% now=>\chardef\JSstatus\plusone ,% \s!default=>\chardef\JSstatus\plustwo ,% @@ -374,15 +374,15 @@ \long\setgvalue{\r!java\r!java#1}{#3}% \ifcase\JSstatus \else \useJSpreamblenow{#1}% - \fi + \fi \egroup} -%D \macros +%D \macros %D {setJSpreamble, addtoJSpreamble} -%D -%D In addition to the previous preamble definitions, we can -%D set a preamble \citeer {in||line} and add tokens to a -%D preamble. +%D +%D In addition to the previous preamble definitions, we can +%D set a preamble \citeer {in||line} and add tokens to a +%D preamble. \def\setJSpreamble#1#2% {\doifundefined{\r!java\r!java#1} @@ -393,22 +393,22 @@ \def\addtoJSpreamble#1#2% {\doifdefinedelse{\r!java\r!java#1} {\edef\!!stringa{\r!java\r!java#1}% - \edef\!!stringb{\csname\!!stringa\endcsname}% + \edef\!!stringb{\csname\!!stringa\endcsname}% \@EA\setgvalue\@EA\!!stringa\@EA{\!!stringb #2;}} {\setJSpreamble{#1}{#2}}} -%D \macros +%D \macros %D {useJSpreamblenow} %D %D The next macro can be used to force inclusion of postponed -%D \JAVASCRIPT\ preambles. +%D \JAVASCRIPT\ preambles. \def\useJSpreamblenow#1% {\doglobal\increment\currentJSpreamble \doglobal\addtocommalist{#1}\allJSpreambles} -%D Because we want to check for valid calls, we preload the -%D functions. This means that we can call them directly as +%D Because we want to check for valid calls, we preload the +%D functions. This means that we can call them directly as %D well as indirectly when defined by \type {\startJScode} etc. \long\def\presetJSfunctions#1function #2(#3)% @@ -425,18 +425,17 @@ {\ifx\allJSpreambles\empty\else \bgroup \setverbosecscharacters - \def\par{\delcharacter}% was: { } + \def\par{\delcharacter}% was: { } \globallet\JSpreamble\empty \def\@@collectedJSpreamble{\r!java\r!java collected}% \letvalue{\@@collectedJSpreamble}=\empty \def\docommando##1% {\xdef\JScode{\getvalue{\r!java\r!java##1}}% - \ifoneJSpreamble + \ifoneJSpreamble % \global\letcdcsname \@EA\setxvalue\@EA\@@collectedJSpreamble\@EA {\csname\@@collectedJSpreamble\endcsname\JScode}% \else - \setxvalue{\r!java\r!java##1}% - {\JScode}% + \setxvalue{\r!java\r!java##1}{\JScode}% \fi}% \processcommacommand[\allJSpreambles]\docommando \ifoneJSpreamble @@ -468,19 +467,19 @@ \fi} \prependtoks \flushJSpreamble \to \everyshipout -\prependtoks \finalflushJSpreamble \to \everylastshipout +\prependtoks \finalflushJSpreamble \to \everylastshipout %D \macros %D {doPSsanitizeJScode} -%D +%D %D Before the code can be passed to the (\POSTSCRIPT\ or \PDF) %D output file, some precautions must be made concerning the -%D use of \type{(} and~\type{)}. Here we use a beautiful -%D \type{\aftergroup} trick I discovered in the \TABLE\ format. +%D use of \type{(} and~\type{)}. Here we use a beautiful +%D \type{\aftergroup} trick I discovered in the \TABLE\ format. -\def\doPSsanitizeJScode#1\to#2% +\def\doPSsanitizeJScode#1\to#2% {\begingroup - \scratchcounter\zerocount % \aftergroup counter + \scratchcounter\zerocount % \aftergroup counter \aftergroup\xdef \aftergroup#2% \aftergroup{% @@ -493,25 +492,25 @@ \fi} %D I started with: -%D +%D %D \starttypen -%D \def\dodoPSsanitizeJScode#1% +%D \def\dodoPSsanitizeJScode#1% %D {\aftergroup\string %D \if#1(% %D \expandafter\aftergroup\csname#1\endcsname %D \else\if#1)% %D \expandafter\aftergroup\csname#1\endcsname %D \else\if#1;% -%D \aftergroup;\aftergroup\string\expandafter\aftergroup\ +%D \aftergroup;\aftergroup\string\expandafter\aftergroup\ %D \else %D \expandafter\aftergroup#1% %D \fi\fi\fi %D \advance\scratchcounter by 1 -%D \ifnum\scratchcounter=500 +%D \ifnum\scratchcounter=500 %D \expandafter\dododoPSsanitizeJScode %D \fi} %D \stoptypen -%D +%D %D For pretty printing purposes, we need some way to signal %D \TEX\ macros. Therefore we introduce a special keyword %D \type{TEX}. When followed by a space, this keyword is @@ -520,7 +519,7 @@ \chardef\JSisTEX =0 \chardef\JScomment=0 -\newif\ifaddJSlinebreaks +\newif\ifaddJSlinebreaks \def\flushJSisTEX {\ifcase\JSisTEX @@ -540,25 +539,25 @@ \ifnum\JScomment=0 \chardef\JScomment\plusone \else\ifnum\JScomment=1 - \chardef\JScomment\plustwo + \chardef\JScomment\plustwo \fi\fi \else \ifnum\JScomment=1 \aftergroup/% - \chardef\JScomment\zerocount + \chardef\JScomment\zerocount \fi \ifnum\JScomment=2 \if#1\delcharacter - \chardef\JScomment\zerocount - \fi + \chardef\JScomment\zerocount + \fi \else - \if#1\delcharacter + \if#1\delcharacter \flushJSisTEX\doJSlinebreak \else\if#1(% \flushJSisTEX\aftergroup\string\expandafter\aftergroup\csname#1\endcsname \else\if#1)% \flushJSisTEX\aftergroup\string\expandafter\aftergroup\csname#1\endcsname - \else\if#1;% + \else\if#1;% \flushJSisTEX\aftergroup;\doJSlinebreak \else\if#1T% \ifnum\JSisTEX=0 \chardef\JSisTEX\plusone \else\flushJSisTEX\aftergroup T\fi @@ -567,7 +566,7 @@ \else\if#1X% \ifnum\JSisTEX=2 \chardef\JSisTEX\plusthree \else\flushJSisTEX\aftergroup X\fi \else\if#1\normalspace - \ifnum\JSisTEX=3 \chardef\JSisTEX\zerocount \else\flushJSisTEX\aftergroup#1\fi + \ifnum\JSisTEX=3 \chardef\JSisTEX\zerocount \else\flushJSisTEX\aftergroup#1\fi \else \flushJSisTEX\aftergroup\string\expandafter\aftergroup#1% \fi\fi\fi\fi\fi\fi\fi\fi @@ -575,13 +574,13 @@ \fi \dododoPSsanitizeJScode} -%D Close reading learns that one line comments (\type{// ...}) -%D are removed from the stream. This permits switching in -%D pretty printing \JAVASCRIPT\ sources as well as saves -%D some bytes. +%D Close reading learns that one line comments (\type{// ...}) +%D are removed from the stream. This permits switching in +%D pretty printing \JAVASCRIPT\ sources as well as saves +%D some bytes. -%D The magic 500 in the next hack prevents the input stack from -%D overflowing when large scripts are sanitized. +%D The magic 500 in the next hack prevents the input stack from +%D overflowing when large scripts are sanitized. %\beginTEX @@ -589,8 +588,8 @@ {\ifcase\JSisTEX\ifcase\JScomment \advance\scratchcounter \plusone \fi\fi - \ifnum\scratchcounter=500 - \expandafter\dodododoPSsanitizeJScode + \ifnum\scratchcounter=500 + \expandafter\dodododoPSsanitizeJScode \fi} \def\dodododoPSsanitizeJScode @@ -600,13 +599,13 @@ \begingroup \aftergroup\xdef \aftergroup\sanitizedJScode - \aftergroup{% + \aftergroup{% \aftergroup\sanitizedJScode \let\next=}} %\endTEX % -% Why is \aftergroup not doing what I expect? +% Why is \aftergroup not doing what I expect? % % \beginETEX \aftergroup % @@ -614,17 +613,17 @@ % % \endETEX -%D The macro \type{\doPSsanitizeJScode} converts its argument -%D into the macro \type{\sanitizedJScode}, thereby prefixing -%D each \type{(} and \type{)} by a slash. +%D The macro \type{\doPSsanitizeJScode} converts its argument +%D into the macro \type{\sanitizedJScode}, thereby prefixing +%D each \type{(} and \type{)} by a slash. %D Hooking this mechanism into the general \CONTEXT\ reference -%D mechanism does not take much effort: +%D mechanism does not take much effort: \definespecialtest{JS}% {\doifdefinedelse{\r!java\currentreferenceoperation}} -\definespeciallocation{JS}#1#2% +\definespeciallocation{JS}#1#2% {\iflocation \bgroup \bgroup @@ -645,21 +644,21 @@ {#2}% \fi} -%D \macros +%D \macros %D {useJSscripts} -%D +%D %D In due time, users will build their collections of scripts, %D which can be used (loaded) when applicable. Although not all %D public, we will provide some general purpose scripts, %D collected in files with names like \type{java-...}. One can -%D load these scripts with \type{\useJSscripts}, like: -%D +%D load these scripts with \type{\useJSscripts}, like: +%D %D \starttypen %D \useJSscripts[fld] %D \stoptypen -%D +%D %D The not so complicated implementation of this macro is: - + \def\dodouseJSscripts#1% {\doifelse{#1}\v!reset {\let\allJSpreambles\empty} @@ -680,4 +679,4 @@ \def\useJSscripts {\dodoubleempty\douseJSscripts} -\protect \endinput +\protect \endinput |