Unit tests for CWEB
[ohcount] / test / expected_dir / cweb.w / documentation / comment
1 % Sample CWEB file, excerpts from the libmp source code
2 @* \[1] Introduction.
3 A large piece of software like \MP\ has inherent complexity that cannot
4 be reduced below a certain level of difficulty, although each individual
5 part is fairly simple by itself. The \.{WEB} language is intended to make
6 the algorithms as readable as possible, by reflecting the way the
7 individual program pieces fit together and by providing the
8 cross-references that connect different parts. Detailed comments about
9 what is going on, and about why things were done in certain ways, have
10 been liberally sprinkled throughout the program.  These comments explain
11 features of the implementation, but they rarely attempt to explain the
12 \MP\ language itself, since the reader is supposed to be familiar with
13 {\sl The {\logos METAFONT\/}book} as well as the manual
14 @.WEB@>
15 @:METAFONTbook}{\sl The {\logos METAFONT\/}book@>
16 {\sl A User's Manual for MetaPost}, Computing Science Technical Report 162,
17 AT\AM T Bell Laboratories.
18 @ The present implementation is a preliminary version, but the possibilities
19 for new features are limited by the desire to remain as nearly compatible
20 with \MF\ as possible.
21 On the other hand, the \.{WEB} description can be extended without changing
22 the core of the program, and it has been designed so that such
23 extensions are not extremely difficult to make.
24 The |banner| string defined here should be changed whenever \MP\
25 undergoes any modifications, so that it will be clear which version of
26 \MP\ might be the guilty party when a problem arises.
27 @^extensions to \MP@>
28 @^system dependencies@>
29 @ The external library header for \MP\ is |mplib.h|. It contains a
30 few typedefs and the header defintions for the externally used
31 fuctions.
32 The most important of the typedefs is the definition of the structure 
33 |MP_options|, that acts as a small, configurable front-end to the fairly 
34 large |MP_instance| structure.
35 @(mplib.h@>=
36 @<Exported types@>
37 @<Option variables@>
38 @<Exported function headers@>
39 @ The internal header file is much longer: it not only lists the complete
40 |MP_instance|, but also a lot of functions that have to be available to
41 the \ps\ backend, that is defined in a separate \.{WEB} file. 
42 The variables from |MP_options| are included inside the |MP_instance| 
43 wholesale.
44 @(mpmp.h@>=
45 @<Internal library declarations@>
46 @ @c 
47 @<Declarations@>
48 @<Basic printing procedures@>
49 @<Error handling procedures@>
50 @ The |__attribute__| pragma is gcc-only.
51 @<Internal library ... @>=
52 @ @c
53 @<Local variables for initialization@>
54 @<Set initial values of key variables@>
55 @<Install and test the non-local jump buffer@>;
56 @<Check the ``constant'' values...@>;
57 @.Ouch...clobbered@>
58 @<Run inimpost commands@>;
59 @<Initialize the output routines@>;
60 @<Get the first line of input and prepare to start@>;
61 @ The following system-independent code makes the |xord| array contain a
62 suitable inverse to the information in |xchr|. Note that if |xchr[i]=xchr[j]|
63 where |i<j<0177|, the value of |xord[xchr[i]]| will turn out to be
64 |j| or more; hence, standard ASCII code numbers will be used instead of
65 codes below 040 in case there is a coincidence.
66 @<Set initial ...@>=
67 @* \[3] Input and output.
68 The bane of portability is the fact that different operating systems treat
69 input and output quite differently, perhaps because computer scientists
70 have not given sufficient attention to this problem. People have felt somehow
71 that input and output are not part of ``real'' programming. Well, it is true
72 that some kinds of programming are more fun than others. With existing
73 input/output conventions being so diverse and so messy, the only sources of
74 joy in such parts of the code are the rare occasions when one can find a
75 way to make the program a little less bad than it might have been. We have
76 two choices, either to attack I/O now and get it over with, or to postpone
77 I/O until near the end. Neither prospect is very attractive, so let's
78 get it over with.
79 Different systems have different ways to get started. But regardless of
80 what conventions are adopted, the routine that initializes the terminal
81 should satisfy the following specifications:
82 \yskip\textindent{1)}It should open file |term_in| for input from the
83 terminal. (The file |term_out| will already be open for output to the
84 terminal.)
85 \textindent{2)}If the user has given a command line, this line should be
86 considered the first line of terminal input. Otherwise the
87 user should be prompted with `\.{**}', and the first line of input
88 should be whatever is typed in response.
89 \textindent{3)}The first line of input, which might or might not be a
90 command line, should appear in locations |first| to |last-1| of the
91 |buffer| array.
92 \textindent{4)}The global variable |loc| should be set so that the
93 character to be read next by \MP\ is in |buffer[loc]|. This
94 character should not be blank, and we should have |loc<last|.
95 \yskip\noindent(It may be necessary to prompt the user several times
96 before a non-blank line comes in. The prompt is `\.{**}' instead of the
97 later `\.*' because the meaning is slightly different: `\.{input}' need
98 not be typed immediately after~`\.{**}'.)
99 @ The following program does the required initialization
100 without retrieving a possible command line.
101 It should be clear how to modify this routine to deal with command lines,
102 if the system permits them.
103 @^system dependencies@>
104 @c 
105 @.**@>
106 @.End of file on the terminal@>
107 @ @<Declarations@>=
108 @ The symbolic names for internal quantities are put into \MP's hash table
109 by using a routine called |primitive|, which will be defined later. Let us
110 enter them now, so that we don't have to list all those names again
111 anywhere else.
112 @<Put each of \MP's primitives into the hash table@>=
113 @:tracingtitles_}{\&{tracingtitles} primitive@>
114 @:mp_tracing_equations_}{\&{tracingequations} primitive@>
115 @:mp_tracing_capsules_}{\&{tracingcapsules} primitive@>
116 @:mp_tracing_choices_}{\&{tracingchoices} primitive@>
117 @:mp_tracing_specs_}{\&{tracingspecs} primitive@>
118 @:mp_tracing_commands_}{\&{tracingcommands} primitive@>
119 @:mp_tracing_restores_}{\&{tracingrestores} primitive@>
120 @:mp_tracing_macros_}{\&{tracingmacros} primitive@>
121 @:mp_tracing_output_}{\&{tracingoutput} primitive@>
122 @:mp_tracing_stats_}{\&{tracingstats} primitive@>
123 @:mp_tracing_lost_chars_}{\&{tracinglostchars} primitive@>
124 @:mp_tracing_online_}{\&{tracingonline} primitive@>
125 @:mp_year_}{\&{year} primitive@>
126 @:mp_month_}{\&{month} primitive@>
127 @:mp_day_}{\&{day} primitive@>
128 @:time_}{\&{time} primitive@>
129 @:mp_char_code_}{\&{charcode} primitive@>
130 @:mp_char_ext_}{\&{charext} primitive@>
131 @:mp_char_wd_}{\&{charwd} primitive@>
132 @:mp_char_ht_}{\&{charht} primitive@>
133 @:mp_char_dp_}{\&{chardp} primitive@>
134 @:mp_char_ic_}{\&{charic} primitive@>
135 @:mp_design_size_}{\&{designsize} primitive@>
136 @:mp_pausing_}{\&{pausing} primitive@>
137 @:mp_showstopping_}{\&{showstopping} primitive@>
138 @:mp_fontmaking_}{\&{fontmaking} primitive@>
139 @:mp_linejoin_}{\&{linejoin} primitive@>
140 @:mp_linecap_}{\&{linecap} primitive@>
141 @:mp_miterlimit_}{\&{miterlimit} primitive@>
142 @:mp_warning_check_}{\&{warningcheck} primitive@>
143 @:mp_boundary_char_}{\&{boundarychar} primitive@>
144 @:mp_prologues_}{\&{prologues} primitive@>
145 @:mp_true_corners_}{\&{truecorners} primitive@>
146 @:mp_procset_}{\&{mpprocset} primitive@>
147 @:troffmode_}{\&{troffmode} primitive@>
148 @:mp_default_color_model_}{\&{defaultcolormodel} primitive@>
149 @:mp_restore_clip_color_}{\&{restoreclipcolor} primitive@>
150 @* \[47] Debugging.
151 Once \MP\ is working, you should be able to diagnose most errors with
152 the \.{show} commands and other diagnostic features. But for the initial
153 stages of debugging, and for the revelation of really deep mysteries, you
154 can compile \MP\ with a few more aids. An additional routine called |debug_help|
155 will also come into play when you type `\.D' after an error message;
156 |debug_help| also occurs just before a fatal error causes \MP\ to succumb.
157 @^debugging@>
158 @^system dependencies@>
159 The interface to |debug_help| is primitive, but it is good enough when used
160 with a debugger that allows you to set breakpoints and to read
161 variables and change their values. After getting the prompt `\.{debug \#}', you
162 type either a negative number (this exits |debug_help|), or zero (this
163 goes to a location where you can set a breakpoint, thereby entering into
164 dialog with the debugger), or a positive number |m| followed by
165 an argument |n|. The meaning of |m| and |n| will be clear from the
166 program below. (If |m=13|, there is an additional argument, |l|.)
167 @.debug \#@>
168 @<Last-minute...@>=
169 @.debug \#@>
170 @<Numbered cases for |debug_help|@>;
171 @ @<Numbered cases...@>=
172 @ Saving the filename template
173 @<Save the filename template@>=
174 @* \[48] System-dependent changes.
175 This section should be replaced, if necessary, by any special
176 modification of the program
177 that are necessary to make \MP\ work at a particular installation.
178 It is usually best to design your change file so that all changes to
179 previous sections preserve the section numbering; then everybody's version
180 will be consistent with the published program. More extensive changes,
181 which introduce new sections, can be inserted here; then only the index
182 itself will get a new section number.
183 @^system dependencies@>
184 @* \[49] Index.
185 Here is where you can find all uses of each identifier in the program,
186 with underlined entries pointing to where the identifier was defined.
187 If the identifier is only one letter long, however, you get to see only
188 the underlined entries. {\sl All references are to section numbers instead of
189 page numbers.}
190 This index also lists error messages and other aspects of the program
191 that you might want to look up some day. For example, the entry
192 for ``system dependencies'' lists all sections that should receive
193 special attention from people who are installing \MP\ in a new
194 operating environment. A list of various things that can't happen appears
195 under ``this can't happen''.
196 Approximately 25 sections are listed under ``inner loop''; these account
197 for more than 60\pct! of \MP's running time, exclusive of input and output.