summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/nicetext/run/fddial0g.sty
blob: 3e3a56ab83081b12856fab1998b42d49122abd90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
\ProvidesPackage{fddial0g}[2011/09/13 v0.2 dialogues with fifinddo (UL)] 
%% copyright (C) 2011 Uwe L\"uck, 
%%
%%   http://www.contact-ednotes.sty.de.vu 
%%
%% -- author-maintained in the sense of LPPL below -- 
%% This file can be redistributed and/or modified under 
%% the terms of the LaTeX Project Public License; either 
%% version 1.3c of the License, or any later version.
%% The latest version of this license is in
%%
%%     http://www.latex-project.org/lppl.txt
%%
%% We did our best to help you, but there is NO WARRANTY. 
%% Please report bugs, problems, and suggestions via 
%% 
%%   http://www.contact-ednotes.sty.de.vu 
%%
\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. 
\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 
    `\UseSet{cfg-f}.cfg'.^^J}%
}
%% |\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%
    ===========================================================}
%% 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.}%
    \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