-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcweav-extensions.ch
More file actions
200 lines (172 loc) · 5.56 KB
/
cweav-extensions.ch
File metadata and controls
200 lines (172 loc) · 5.56 KB
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
193
194
195
196
197
198
199
200
Changes for CWEAVE.W by Andreas Scherer et al.
This set of changes introduces several extensions to the standard behaviour
of the CWEB system. Several new command line options are provided here.
See CWEBMAN-EXTENSIONS.CH for details about these new features.
For a complete history of the changes made to CWEAVE.W see CWEAV-PATCH.CH.
Section 89.
@x l.1396
@ In particular, the |finish_line| procedure is called near the very
beginning of phase two. We initialize the output variables in a slightly
tricky way so that the first line of the output file will be
`\.{\\input cwebmac}'.
@<Start \9{t}\TEX/...@>=
out_ptr=out_buf+1; out_line=1; active_file=tex_file;
tex_printf("\\input cwebma"); *out_ptr='c';
@y
@ In particular, the |finish_line| procedure is called near the very
beginning of phase two. We initialize the output variables in a slightly
tricky way so that the first line of the output file will be dependent of
the user language set by the `\.{+l}' option and its argument. If you call
\.{CWEAVE} with `\.{+lX}' (or `\.{-lX}' as well), where `\.X' is the
(possibly empty) string of characters to the right of~`\.l', `\.X'~will be
prepended to `\.{cwebmac.tex}', e.g., if you call \.{CWEAVE} with
`\.{+ldeutsch}', you will receive the line `\.{\\input deutschcwebmac}'.
Without this option the first line of the output file will be
`\.{\\input cwebmac}'.
@<Start \9{t}\TEX/...@>=
out_ptr=out_buf+1; out_line=1; active_file=tex_file;
tex_puts("\\input ");
tex_printf(use_language);
tex_puts("cwebma");
*out_ptr='c';
@z
Section 110.
@x l.2128
@i prod.w
@y
@i prod-cweave.w
@z
Section 128.
@x l.2650
@<Cases for |exp|@>=
if (cat1==lbrace || cat1==int_like || cat1==decl) {
make_underlined(pp); big_app(dindent); big_app1(pp);
reduce(pp,1,fn_decl,0,1);
}
@y
@<Cases for |exp|@>=
if(cat1==lbrace || cat1==int_like || cat1==decl) {
make_underlined(pp); if (indent_param_decl) big_app(dindent); big_app1(pp);
reduce(pp,1,fn_decl,0,1);
}
@z
Section 138.
@x l.2754
@ @<Cases for |decl_head|@>=
if (cat1==comma) {
big_app2(pp); app(opt); app('9'); reduce(pp,2,decl_head,-1,33);
}
else if (cat1==ubinop) {
big_app1_insert(pp,'{'); big_app('}'); reduce(pp,2,decl_head,-1,34);
}
else if (cat1==exp && cat2!=lpar && cat2!=lbrack && cat2!=exp && cat2!=cast) {
make_underlined(pp+1); squash(pp,2,decl_head,-1,35);
}
else if ((cat1==binop||cat1==colon) && cat2==exp && (cat3==comma ||
cat3==semi || cat3==rpar))
squash(pp,3,decl_head,-1,36);
else if (cat1==cast) squash(pp,2,decl_head,-1,37);
else if (cat1==int_like || cat1==lbrace || cat1==decl) {
big_app(dindent); squash(pp,1,fn_decl,0,38);
}
else if (cat1==semi) squash(pp,2,decl,-1,39);
@y
@ @<Cases for |decl_head|@>=
if (cat1==comma) {
big_app2(pp); app(opt); app('9'); reduce(pp,2,decl_head,-1,33);
}
else if (cat1==ubinop) {
big_app1_insert(pp,'{'); big_app('}');
reduce(pp,2,decl_head,-1,34);
}
else if (cat1==exp && cat2!=lpar && cat2!=lbrack && cat2!=exp && cat2!=cast) {
make_underlined(pp+1); squash(pp,2,decl_head,-1,35);
}
else if ((cat1==binop||cat1==colon) && cat2==exp && (cat3==comma ||
cat3==semi || cat3==rpar))
squash(pp,3,decl_head,-1,36);
else if (cat1==cast) squash(pp,2,decl_head,-1,37);
else if (cat1==int_like || cat1==lbrace || cat1==decl) {
if (indent_param_decl) big_app(dindent);
squash(pp,1,fn_decl,0,38);
}
else if (cat1==semi) squash(pp,2,decl,-1,39);
@z
Section 139.
@x l.2776
@ @<Cases for |decl|@>=
if (cat1==decl) {
big_app1_insert(pp,force); reduce(pp,2,decl,-1,40);
}
else if (cat1==stmt || cat1==function) {
big_app1_insert(pp,big_force); reduce(pp,2,cat1,-1,41);
}
@y
@ @<Cases for |decl|@>=
if (cat1==decl) {
big_app1_insert(pp,force); reduce(pp,2,decl,-1,40);
}
else if (cat1==stmt || cat1==function) {
big_app1_insert(pp,order_decl_stmt ? big_force : force);
reduce(pp,2,cat1,-1,41);
}
@z
Section 143.
@x l.2833
@ @<Cases for |fn_decl|@>=
if (cat1==decl) {
big_app1_insert(pp,force); reduce(pp,2,fn_decl,0,51);
}
else if (cat1==stmt) {
big_app1(pp); app(outdent); app(outdent); big_app(force);
big_app1(pp+1); reduce(pp,2,function,-1,52);
}
@y
@ @<Cases for |fn_decl|@>=
if (cat1==decl) {
big_app1_insert(pp,force); reduce(pp,2,fn_decl,0,51);
}
else if (cat1==stmt) {
big_app1(pp);
if (indent_param_decl) {
app(outdent); app(outdent);
}
big_app(force); big_app1(pp+1); reduce(pp,2,function,-1,52);
}
@z
Section 153.
@x l.2937
big_app1_insert(pp,dindent); reduce(pp,2,fn_decl,0,73);
@y
big_app1(pp); if (indent_param_decl) big_app(dindent);
big_app1(pp+1); reduce(pp,2,fn_decl,0,73);
@z
Section 156.
@x l.2963
big_app1_insert(pp, (cat1==decl || cat1==function) ? big_force :
force_lines ? force : break_space); reduce(pp,2,cat1,-1,76);
@y
big_app1_insert(pp, (cat1==decl || cat1==function) ? @|
( order_decl_stmt ? big_force : force ) : @|
( force_lines ? force : break_space ) ); reduce(pp,2,cat1,-1,76);
@z
Addendum.
@x l.4886
@** Index.
@y
@* Formatting alternatives.
\.{CWEAVE} indents declarations after old-style function definitions and
long parameter lists of modern function definitions.
With the \.{-i} option they will come out flush left.
@d indent_param_decl flags['i'] /* should formal parameter declarations be indented? */
@<Set init...@>=
indent_param_decl=true;
@ The original manual described the \.{-o} option for \.{CWEAVE}, but this was
not yet present. Here is a simple implementation. The purpose is to suppress
the extra space between local variable declarations and the first statement in
a function block.
@d order_decl_stmt flags['o'] /* should declarations and statements be separated? */
@<Set init...@>=
order_decl_stmt=true;
@** Index.
@z