diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/nicetext/run/fddial0g.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/nicetext/run/fddial0g.sty | 196 |
1 files changed, 157 insertions, 39 deletions
diff --git a/Master/texmf-dist/tex/latex/nicetext/run/fddial0g.sty b/Master/texmf-dist/tex/latex/nicetext/run/fddial0g.sty index 6c9b255c6e6..3e3a56ab830 100644 --- a/Master/texmf-dist/tex/latex/nicetext/run/fddial0g.sty +++ b/Master/texmf-dist/tex/latex/nicetext/run/fddial0g.sty @@ -1,4 +1,4 @@ -\ProvidesPackage{fddial0g}[2011/08/23 dialogues with fifinddo (UL)] +\ProvidesPackage{fddial0g}[2011/09/13 v0.2 dialogues with fifinddo (UL)] %% copyright (C) 2011 Uwe L\"uck, %% %% http://www.contact-ednotes.sty.de.vu @@ -16,59 +16,177 @@ %% %% http://www.contact-ednotes.sty.de.vu %% -%% T0D0: more abstract setting and using of variables -%% so the user must not invent names and see underscores. -%% (Probably use namemod.) -%% \RequirePackage{fifinddo} \catcode`\_=11 +%% == Setting and Using Variables == +%% %% aus `fddialog.sty' in `blog/convert/' 2011/09/12: +\newcommand*{\FDD_set}{set:} +\newcommand*{\FDD_use}{use:} +%% |\MakeSet{<id>}{<set>}| declares an internal variable `<id>' +%% and defines a command `<set>' so that `<set>{<value>}' +%% will assign <value> to <id>: +\newcommand*{\MakeSet}[2]{% + \@namedef{\FDD_set#1}{#2}% + \newcommand*{#2}{\@namedef{\FDD_use#1}} +} +%% It would be nice if there were a warning when in an evaluation +%% of a variable it turns out that it has not been ``declared" by +%% `\MakeSet' or not been set by the according setting command. +%% However, all the evaluations seem to happen in expansion +%% (e.g., during `\typeout'), so \LaTeX's `\PackageError' +%% (not even `\GenericError') is not helpful, +%% and `\errhelp' cannot be set specifically (in time). +%% It may tell more generally about `\MakeSet', but I am not sure +%% about what errors can occur in processing the dialogues at all. +%% At least we can get a real `\errmessage' using something else +%% that has not been defined: +\newcommand*{\FDD_check_use}[1]{% + \@ifundefined{\FDD_use#1}% + {\@ifundefined{\FDD_set#1}% + {\FDD_undeclared_variable `#1'}% + {\FDD_undefined_variable `#1'}}% +} +%% |\UseSet{<id>}| expands to <id>'s value. +\newcommand*{\UseSet}[1]{% + \FDD_check_use{#1}{\csname\FDD_use#1\endcsname}} +%% |\EvalBooleanSet{<id>}|: +\newcommand*{\EvalBooleanSet}[1]{% + \FDD_check_use{#1}{% + \csname + \FDD_on_setstring\@gobble{#1}%% \if id + \csname\FDD_use#1\endcsname %% true/false + \endcsname + }% +} +\newcommand*{\FDD_on_setstring}[2]{% + \expandafter\FDD_double_xpa\expandafter + #1\expandafter\expandafter\expandafter + \string\csname\FDD_set#2\endcsname} +\def\FDD_double_xpa{\expandafter\expandafter\expandafter} +%% |\IfEmptySet{<id>}{<if>}{<unless>}|: +\newcommand*{\IfEmptySet}[1]{% + \if^^J\UseSet{#1}^^J\expandafter\@firstoftwo + \else\expandafter\@secondoftwo\fi} +%% TODO present variable names by tokens!? (namemod) +%% +%% |\DebugShowSet{<id>}|: +\newcommand*{\DebugShowVar}[1]{% + \expandafter\show\csname\FDD_use#1\endcsname} +%% +%% == In/Out Variables == %% |\ResultFile| gets a different meaning here %% in order to keep the dialogue nice. -%% `\result_file_name' must be reserved for the original -%% meaning of `\ResultFile'. -\let\UseResultFile\ResultFile -\def\ResultFile{\def\result_file_dialogue} -\newcommand\InputFile{\def\input_file_name} -\newif\iftoscreen - -\def\Announce#1#2{% +\let\UseResultFile\ResultFile +\let\ResultFile\relax +\MakeSet{out-f}{\ResultFile} +\MakeSet {in-f}{\InputFile} +\MakeSet{cfg-f}{\CFGname} +%% == `.cfg' == +%% |\TryDialogue{<file-name-base>}{<settings>}| +%% loads file `<file-name-base>.cfg' if \TeX\ can find it, +%% otherwise executes <settings>: +\newcommand*{\TryDialogueCFG}[2]{% + \CFGname{#1}% + \InputIfFileExists{#1.cfg}% + {\typeout{^^J + * using settings from `#1.cfg'. * + ^^J}}% + {#2}% +} +%% +%% == Screen == +\newcommand*{\Announce}[1]{% \typeout{% \FD_dialogue_double_line ^^J#1^^J% The screen shows most recent settings commands.^^J% - You can modify initial settings in #2.^^J% - }% + You can modify initial settings in + `\UseSet{cfg-f}.cfg'.^^J}% } -\def\FD_dialogue_screen#1{% - \typeout{% - \FD_dialogue_double_line^^J% - #1% - \FD_dialogue_double_line - }% - \typein[\action]% - {Run with these settings? (Y)es? (C)hange? (Otherwise quit.)}% - \csname action_\action \endcsname +%% |\DialogueLoop| is the last mandatory command in the +%% main script file. It needs an earlier definition of +%% |\VarShowSettings|. |\LBrk| can be used for a +%% screen line break: %% TODO \MessageBreak \relax!? +\newcommand*{\DialogueLoop}{% + {\def\LBrk{^^J}% + \typeout{% + \FD_dialogue_double_line^^J% + \VarShowSettings %% specific to purpose + \FD_dialogue_double_line}% + }% + \typein[\action]% + {Run with these settings? + (Y)es? (C)hange? (Otherwise quit.)}% + \csname FDD_action_\action \endcsname } \def\FD_dialogue_double_line{% ^^J% ===========================================================} -\def\run_with_settings_gen#1{% - \UseResultFile{\result_file_dialogue}% - #1% +%% For defining |\VarShowSettings|: +\newcommand*{\ShowSet}[1]{% + \FDD_check_use{#1}{% +% \expandafter\expandafter\expandafter +% \string\csname\FDD_set#1\endcsname + \FDD_on_setstring\@empty{#1}% + {\UseSet{#1}}% + }% +} +\newcommand*{\TimesDo}[2]{% + \ifnum\number#1>\z@ + #2\expandafter\@firstofone + \else + \expandafter\@gobble + \fi + {\expandafter\TimesDo\expandafter + {\number\predecessor_of{#1} }{#2}}% +} +\newcommand*{\predecessor_of}[1]{% + \ifnum#1>9 + \expandafter\twodig_predecessor_of + \else + \expandafter\onedig_predecessor_of + \fi + #1} +\newcommand*{\onedig_predecessor_of}[1]{% + \ifcase #1\or0\or1\or2\or3\or4\or5\or6\or7\or8\or9\fi} +\newcommand*{\twodig_predecessor_of}[2]{% + \ifcase #2 + \onedig_predecessor_of#19\or + #10\or#11\or#12\or#13\or#14\or#15\or#16\or#17\or#18\or#19\fi} + +\newcommand*{\Spaces}[1]{\TimesDo{#1}{\space}} + +%% +%% == Changing Settings == +%% When the user types `c' or `C', she is asked to input +%% replacement text for the macro |\change|. +%% This macro then is executed, and |\DialogueLoop| +%% is invoked again: +\newcommand*{\FDD_action_c}{\FDD_change_settings} +\newcommand*{\FDD_action_C}{\FDD_change_settings} +\newcommand*{\FDD_change_settings}{% + \typein[\change]{^^JType setting command(s).}% + \change \DialogueLoop} +%% == Running with Current Settings == +\newcommand*{\FDD_action_y}{\FDD_run_with_settings} +\newcommand*{\FDD_action_Y}{\FDD_run_with_settings} +%% When the user types `y' or `Y', the following macro is executed. +%% It invokes |\VarRunSettings| that must be defined +%% before `\DialogueLoop' is executed: +\newcommand*{\FDD_run_with_settings}{% + \VarRunSettings %% specific to purpose \CloseResultFile \typeout{Done.}% - \Dialogue -} -\def\FD_corrected_input_line{% - \expandafter \MakeDocCorrectHook \expandafter{\fdInputLine}} -\@namedef{action_y}{\RunWithSettings} -\@namedef{action_Y}{\RunWithSettings} -\def\change_settings{% - \typein[\change]{^^JType setting command(s).}% - \change \Dialogue} -\expandafter\let\csname action_c\endcsname \change_settings -\expandafter\let\csname action_C\endcsname \change_settings - + \DialogueLoop} +%% +%% == The End == \endinput + +== VERSION HISTORY == + +v0.1 2011/08/23 first, uploaded with NICETEXT r0.43 +v0.2 2011/09/12 merged with something earlier/better, messages + 2011/09/13 messages more carefully: ...undefined_var..., + \EvalBooleanSet, \TimesDo with two digits |