~ubuntu-branches/ubuntu/karmic/fweb/karmic

« back to all changes in this revision

Viewing changes to Web/typedefs.web

  • Committer: Bazaar Package Importer
  • Author(s): Yann Dirson
  • Date: 2002-01-04 23:20:22 UTC
  • Revision ID: james.westby@ubuntu.com-20020104232022-330ad4iyzpvb5bm4
Tags: upstream-1.62
ImportĀ upstreamĀ versionĀ 1.62

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
@z --- typedefs.web ---
 
2
 
 
3
FWEB version 1.62 (September 25, 1998)
 
4
 
 
5
Based on version 0.5 of S. Levy's CWEB [copyright (C) 1987 Princeton University]
 
6
 
 
7
@x-----------------------------------------------------------------------------
 
8
 
 
9
@Lv[-Tv] @% This file can't be processed by \FWEAVE\ in it's present form!
 
10
 
 
11
@* COMMON DEFINITIONS and TYPEDEFS. Here are definitions and typedefs
 
12
common to all of \.{common.web}, \.{tangle.web}, and \.{weave.web}.
 
13
 
 
14
@a
 
15
@o typedefs.hweb
 
16
@<Macro definitions@>@;
 
17
 
 
18
@ Write a header at the top of \.{typedefs.h}.
 
19
@a
 
20
/* Created automatically from typedefs.web. */
 
21
#include "os.h"
 
22
 
 
23
@ The debug mode includes some extra code, but it probably doesn't slow
 
24
things down too much.
 
25
 
 
26
@d DEBUG 1
 
27
 
 
28
@<Mac...@>=
 
29
@@I formats.hweb
 
30
 
 
31
@@ The actual names of the processors.
 
32
 
 
33
@@m TANGLE "FTANGLE"
 
34
@@m WEAVE "FWEAVE"
 
35
 
 
36
 
37
@<Mac...@>=
 
38
@@ Some compilers can't handle files as large as \.{ftangle} or \.{fweave}.
 
39
Therefore, if the C~preprocessor macros |part| are defined from the
 
40
compiler's command line to have the value~1, 2, or~3, the other parts of
 
41
those files are commented out.
 
42
 
 
43
@@<Possibly split into parts@@>=
 
44
 
 
45
#ifndef part
 
46
        #define part 0 /* Standard value, when the files aren't split. */
 
47
#else
 
48
        #if(part != 1 && part != 2 && part != 3)
 
49
                #define part 1 /* Should issue error message here. */
 
50
        #endif
 
51
#endif /* |part| */
 
52
 
 
53
@ Now we have macros that ensure that stuff needed for \FTANGLE\ or \FWEAVE\
 
54
is defined and allocated in only one place.
 
55
 
 
56
@f EXTERN extern
 
57
 
 
58
@f com $_COMMA_
 
59
@D com ,
 
60
 
 
61
@a
 
62
 
 
63
#ifdef _FWEB_h
 
64
        #define EXTERN part1_or_extern /* This is further redefined below,
 
65
                                depending on the setting of |part|. */
 
66
        #define SET SET1
 
67
#else
 
68
        #define EXTERN extern
 
69
        #define SET(stuff)
 
70
#endif
 
71
 
 
72
@
 
73
@<Mac...@>=
 
74
@@
 
75
@@F EXTERN extern
 
76
 
 
77
@@f IN_TANGLE extern
 
78
@@f IN_COMMON extern
 
79
@@f IN_RATFOR extern
 
80
@@f IN_EVAL extern
 
81
@@f IN_MACS extern
 
82
@@f IN_PROD extern
 
83
@@f IN_STYLE extern
 
84
 
 
85
 
 
86
@@f SET $_EXPR
 
87
@@f CSET $_EXPR
 
88
 
 
89
@@<Possibly split...@@>=
 
90
 
 
91
#if(part == 0 || part == 1)
 
92
        #define part1_or_extern 
 
93
        #define SET1(stuff) @@e = stuff
 
94
        #define TSET1(stuff) @@e = stuff
 
95
#else 
 
96
        #define part1_or_extern extern
 
97
        #define SET1(stuff)
 
98
        #define TSET1(stuff)
 
99
#endif
 
100
 
 
101
@ Next, we have some macros to help us allocate and define stuff in just one
 
102
place. The philosophy here is that there should be no explicit |extern|
 
103
statements; they should be replaced by something like |IN_COMMON| to remind
 
104
one exactly where that variable is defined.
 
105
 
 
106
@f IN_TANGLE extern
 
107
@f IN_COMMON extern
 
108
@f IN_RATFOR extern
 
109
@f IN_EVAL extern
 
110
@f IN_MACS extern
 
111
@f IN_PROD extern
 
112
@f IN_STYLE extern
 
113
 
 
114
@f SET $_EXPR
 
115
@f CSET $_EXPR
 
116
 
 
117
@a
 
118
 
 
119
#ifdef _FTANGLE_h
 
120
        #define IN_TANGLE part1_or_extern
 
121
        #define TSET TSET1
 
122
#else
 
123
        #define IN_TANGLE extern
 
124
        #define TSET(stuff)
 
125
#endif /* |_TANGLE_h| */
 
126
 
 
127
#ifdef _COMMON_h
 
128
        #define IN_COMMON part1_or_extern
 
129
        #define CSET SET1
 
130
#else
 
131
        #define IN_COMMON extern
 
132
        #define CSET(stuff)
 
133
#endif /* |_COMMON_h| */
 
134
 
 
135
#ifdef _PROD_h
 
136
        #define IN_PROD part1_or_extern
 
137
        #define PSET SET1
 
138
#else
 
139
        #define IN_PROD extern
 
140
        #define PSET(stuff)
 
141
#endif /* |_PROD_h| */
 
142
 
 
143
#ifdef _RATFOR_h
 
144
        #define IN_RATFOR part1_or_extern
 
145
        #define RSET SET1
 
146
#else
 
147
        #define IN_RATFOR extern
 
148
        #define RSET(stuff)
 
149
#endif /* |_RATFOR_h| */
 
150
 
 
151
#ifdef _EVAL_h
 
152
        #define IN_EVAL
 
153
        #define ESET(stuff) = stuff
 
154
#else
 
155
        #define IN_EVAL extern
 
156
        #define ESET(stuff)
 
157
#endif /* |_EVAL_h| */
 
158
 
 
159
#ifdef _MACS_h
 
160
        #define IN_MACS
 
161
#else
 
162
        #define IN_MACS extern
 
163
#endif /* |_MACS_h| */
 
164
 
 
165
#ifdef _STYLE_h
 
166
        #define IN_STYLE
 
167
        #define SSET(stuff) = stuff
 
168
#else
 
169
        #define IN_STYLE extern
 
170
        #define SSET(stuff)
 
171
#endif /* |_STYLE_h| */
 
172
 
 
173
@ We have an enumerated type for the kind of machine.
 
174
 
 
175
@<Unused@>=
 
176
 
 
177
@#if 0
 
178
typedef enum{Unknown,Apollo,Dsu,IBMPc,Mac,Misc,Sgi,Sun,Vax} MACHINE;
 
179
 
 
180
IN_COMMON MACHINE Machine
 
181
@#ifdef _COMMON_
 
182
  =
 
183
        @#if APOLLO
 
184
                Apollo  /* Apollo/UNIX */
 
185
        @#elif DSU
 
186
                Dsu     /* DECstation/ULTRIX */
 
187
        @#elif IBMPC
 
188
                IBMPc   /* IBM-PC/DOS */
 
189
        @#elif MAC
 
190
                Mac     /* Macintosh */
 
191
        @#elif MISC
 
192
                Misc    /* Vanilla */
 
193
        @#elif SGI
 
194
                Sgi     /* Silicon Graphics/IRIX */
 
195
        @#elif SUN
 
196
                Sun     /* SunOS/UNIX */
 
197
        @#elif VAX
 
198
                Vax     /* VAX/VMS */
 
199
        @#else
 
200
                Unknown
 
201
        @#endif /* |APOLLO| */
 
202
@#endif /* |_COMMON_| */
 
203
;
 
204
@#endif
 
205
 
 
206
@ Various miscellaneous definitions, and the fundamental typedefs.
 
207
 
 
208
/* True and false. */
 
209
@D YES 1
 
210
@D NO 0
 
211
 
 
212
/* Infinite loop. */
 
213
@D WHILE() for(;;) /* Use ``|for(;;)|'' instead of ``|while(1)|'' to avoid
 
214
                        warnings from Microsoft compiler. */
 
215
@f WHILE while
 
216
 
 
217
/* Minima and maxima. */
 
218
@D MAX(a,b) ((a)>(b) ? (a) : (b))
 
219
@D MIN(a,b) ((a)<(b) ? (a) : (b))
 
220
 
 
221
@d SAVE_MACRO(text) save_macro(OC("m!"),(outer_char *)text)
 
222
        /* Note that this protects the macros against redefinition. */
 
223
@d CHK_ARGS(name,num) chk_args(OC(name),num,n,pargs) 
 
224
        /* Right \# of arguments? */
 
225
 
 
226
@D tab_mark @'\t' /* The |ASCII| tab. */
 
227
 
 
228
/* Subtraction of huge pointers; needed for pc's. We first cast to |long|,
 
229
then to the final target type. */
 
230
@d PTR_DIFF(type,p,q) ((type)(long)((p) - (q)))
 
231
@d SUB_PTRS(p,q) PTR_DIFF(unsigned long,p,q) /* Used in the statistics
 
232
                                                output. */
 
233
 
 
234
/* Here are some macros to determine the identifier number in the name
 
235
directory. */ 
 
236
@d ID_NUM_ptr(ptr,start,end) ID_NUM0(ptr = @e,start,end) /* Set a
 
237
        pointer as well as the number. */
 
238
@d ID_NUM(start,end) ID_NUM0(DUMMY,start,end) /* Just the number. */
 
239
@d DUMMY /* This kludge for an empty argument shouldn't be necessary, but
 
240
        Microsoft didn't like the construction |ID_NUM0(,start,end)|. */
 
241
 
 
242
/* Set both a pointer and the number. */
 
243
@f ptr_equals $EXPR_
 
244
@d ID_NUM0(ptr_equals,start,end) PTR_DIFF(sixteen_bits,
 
245
        (ptr_equals id_lookup(start,end,0)),name_dir)
 
246
 
 
247
/* Terminate a string. */
 
248
@d TERMINATE(p,offset) *(p+offset) = '\0'
 
249
 
 
250
@d BOOLEAN(b) ((boolean)(b)) /* Explicit cast to make some compilers happy. */
 
251
 
 
252
@d CHOICE(flag,yes,no) (((int)(flag)) ? yes : no)
 
253
 
 
254
@
 
255
 
 
256
@m OCTAL0(n)$ASCII(#'n) 
 
257
@m OCTAL(n)(eight_bits)OCTAL0(\@&n) /* Make octal constant. */
 
258
 
 
259
@<Mac...@>=
 
260
@@ Here's a somewhat sophisticated use of \WEB\ macros.
 
261
@@f WHILE while
 
262
@@f ptr_equals $EXPR_
 
263
@@m @!OCTAL0(n) @!$ASCII(#'n) /* Single-quote the argument and send to
 
264
                                \.{\@!$ASCII}. */ 
 
265
@@m @!OCTAL(n) (eight_bits)@!OCTAL0(\@@&n) /* Make octal constant. */
 
266
@@m @!HEX(n) (eight_bits)@!OCTAL0(\@@&x##n) /* Make hex constant. */
 
267
 
 
268
@
 
269
@a
 
270
 
 
271
typedef unsigned char eight_bits; /* The fundamental single-byte token. If
 
272
        your machine does not support |unsigned char| you should change 
 
273
        the definition of |eight_bits| to |unsigned short|. */ 
 
274
@^system dependencies@>
 
275
 
 
276
typedef unsigned short sixteen_bits; /* Identifiers and similar things take
 
277
                                        up two bytes. */
 
278
 
 
279
typedef unsigned char outer_char; /* Type of characters outside \.{WEB}. */
 
280
 
 
281
typedef eight_bits boolean; /* The logical type. (\CWEB\ had |short| here.
 
282
        Indeed, some compilers give warnings about type conversions because the
 
283
        result of logical operations is an |int|, not a |char|.) */
 
284
 
 
285
typedef unsigned long BUF_SIZE; /* Size of dynamic arrays. */
 
286
 
 
287
typedef long STMT_LBL; /* \Fortran\ statement label.  (Negative is allowed.) */
 
288
 
 
289
typedef unsigned short LINE_NUMBER; /* Line number of \WEB\ source or output.*/
 
290
 
 
291
typedef long CASE_TYPE; /* The type for |case| values in \Ratfor.  */
 
292
 
 
293
/* For |web_strcmp|. {\bfit Web's convention differs from C's}!
 
294
        If you don't pay attention to this, you'll get bugs that are
 
295
        hard to track down. */
 
296
typedef enum {LESS=0, /* first name is lexicographically less than the second*/
 
297
        EQUAL=1, /* the first name is equal to the second */
 
298
        GREATER=2, /* first name is lexicographically greater than the
 
299
second */
 
300
        PREFIX=3, /* the first name is a proper prefix of the second */
 
301
        EXTENSION=4} LEXI; /* first name is a proper extension of the
 
302
second. */
 
303
 
 
304
@ In certain cases \.{TANGLE} and \.{WEAVE} should do almost, but not
 
305
quite, the same thing.  In these case we've written common code for
 
306
both, differentiating between the two by means of the global variable
 
307
|program|.
 
308
 
 
309
@a
 
310
typedef enum {tangle=0,weave=1} PROGRAM; /* The two processors. */
 
311
 
 
312
IN_COMMON PROGRAM program;
 
313
 
 
314
@ The \FWEB\ version number, and the system name.
 
315
 
 
316
@a
 
317
 
 
318
IN_COMMON outer_char version[] CSET(VERSION); /* \FWEB\ version number. */
 
319
IN_COMMON outer_char release_date[] CSET(RELEASE_DATE); 
 
320
        /* Release date for this version. */
 
321
IN_COMMON outer_char *the_system, *local_banner; /* Name of the
 
322
        machine/operating system; and a possible additional local banner. */
 
323
 
 
324
@ \.{WEAVE} operates in three phases: first it inputs the source file and
 
325
stores cross-reference data, then it inputs the source once again and
 
326
produces the \TeX\ output file, and finally it sorts and outputs the index.
 
327
Similarly, \.{TANGLE} operates in two phases.  The global variable |phase|
 
328
tells which phase we are in.
 
329
 
 
330
@a
 
331
 
 
332
IN_COMMON short phase CSET(0); /* Which phase are we in? */
 
333
 
 
334
@ Especially in \RATFOR, we distinguish between warning and error messages.
 
335
 
 
336
@d EAT_AUTO_SEMI {if(auto_semi && next_byte() != @';') BACK_UP@;}
 
337
@d BACK_UP {saved_token = NO; cur_byte -= last_bytes;}
 
338
 
 
339
@d NOT_BEFORE OCTAL(177)
 
340
@d NOT_AFTER NOT_BEFORE
 
341
 
 
342
@d SAVE_BEFORE(pp,nmax,r_before) save_out(pp,nmax,r_before,NOT_AFTER)
 
343
@d SAVE_AFTER(pp,nmax,r_after) save_out(pp,nmax,NOT_BEFORE,r_after)
 
344
 
 
345
@<Mac...@>=
 
346
@@
 
347
@@m IS_NEXT(c0,keyword)
 
348
{
 
349
eight_bits c;
 
350
 
 
351
if((c=next_byte()) != c0)
 
352
        {
 
353
        didnt_expand(c0,c,#*keyword);
 
354
        return;
 
355
        }
 
356
}
 
357
 
 
358
@@m IS_NEXT_PAREN(keyword) IS_NEXT(@'(',keyword)
 
359
 
 
360
@
 
361
@a
 
362
typedef enum {OK,WARNING,ERROR} ERR_TYPE;
 
363
 
 
364
@ A major extension to \.{CWEB} is support for the syntaxes of several
 
365
languages. We need to know what language we're dealing with at the moment.
 
366
 
 
367
@d NUM_LANGUAGES 8 /* |C|, |RATFOR|, |FORTRAN|, |TEX|, |LITERAL|,
 
368
                |C_PLUS_PLUS|, |RATFOR_90|, |FORTRAN_90| */
 
369
@d NUM_DISTINCT_LANGUAGES (NUM_LANGUAGES-2)
 
370
 
 
371
@d GLOBAL_LANGUAGE FORTRAN
 
372
@d global_language global_params.Language /* The language in force at the
 
373
                                        beginning of each module. */
 
374
 
 
375
@d is_C_(Language) (Language==C)
 
376
@d is_RATFOR_(Language) (Language==RATFOR || Language==RATFOR_90)
 
377
@d is_FORTRAN_(Language) (Language==FORTRAN || Language==FORTRAN_90)
 
378
 
 
379
@d FORTRAN_LIKE(Language) (is_RATFOR_(Language) || is_FORTRAN_(Language))
 
380
@d FORTRAN90_LIKE(Language) (Language==FORTRAN_90 || Language==RATFOR_90)
 
381
@d C_LIKE(Language) (Language==C || Language==C_PLUS_PLUS)
 
382
 
 
383
@d R66 (is_RATFOR_(language) && !Ratfor77) /* Non-expandable \Ratfor;
 
384
obsolete. */
 
385
@d R77 (Ratfor77 && is_RATFOR_(language) && xpn_Ratfor) /* Expandable
 
386
\Ratfor. */
 
387
@d R77_or_F (R77 || is_FORTRAN_(language)) /* Expandable \Ratfor\ or
 
388
\Fortran. */
 
389
 
 
390
@d IS_WHITE(a) ((a) == @' ' || (a) == tab_mark)
 
391
 
 
392
@d LANGUAGE_CODE(l) OC(lang_codes[lan_num(l)]) /*  String
 
393
        abbreviation for the language name. */
 
394
 
 
395
@a
 
396
 
 
397
 /* The highest bit sets the basic language. */
 
398
typedef enum
 
399
        {
 
400
        NO_LANGUAGE =   0,
 
401
 
 
402
        C =             0x1,
 
403
        RATFOR =        0x2,
 
404
        FORTRAN =       0x4,
 
405
        TEX =           0x8,
 
406
        LITERAL =       0x10,
 
407
 
 
408
        C_PLUS_PLUS =   0x20,
 
409
        RATFOR_90 =     0x40,
 
410
        FORTRAN_90 =    0x80,
 
411
 
 
412
        NUWEB_OFF =     0xF0, /* Not a language, but used in |send_single|. */
 
413
        NUWEB_ON =      0xF1
 
414
        } LANGUAGE;
 
415
 
 
416
IN_COMMON LANGUAGE cmd_language CSET(NO_LANGUAGE);/* To check against
 
417
override. */
 
418
IN_COMMON boolean column_mode CSET(NO);
 
419
 
 
420
/* These names are used for error messages from the processors. */
 
421
IN_COMMON CONST char HUGE *languages[NUM_LANGUAGES] 
 
422
#ifdef _COMMON_h
 
423
#if(part == 0 || part == 1)
 
424
        = {"C","RATFOR","FORTRAN","TEX","VERBATIM",
 
425
          "C++","RATFOR--90","FORTRAN--90"}
 
426
#endif /* |part == 1| */
 
427
#endif /* |defined _COMMON_h| */
 
428
;
 
429
 
 
430
/* The following are used with \.{\\Winfo}. */
 
431
IN_COMMON CONST char HUGE *Xlanguages[NUM_LANGUAGES] 
 
432
#ifdef _COMMON_h
 
433
#if(part == 0 || part == 1)
 
434
        = {"C","\\Ratfor","\\Fortran","\\TeX","VERBATIM",
 
435
          "\\Cpp","\\Ratfor--90","\\Fortran--90"}
 
436
#endif /* |part == 1| */
 
437
#endif /* |defined _COMMON_h| */
 
438
;
 
439
 
 
440
/* These abbreviations are short-hands for the language---they are used,
 
441
for example, in the index. */
 
442
IN_COMMON CONST char HUGE *lang_codes[NUM_LANGUAGES] 
 
443
#ifdef _COMMON_h
 
444
#if(part == 0 || part == 1)
 
445
        = {"C","R","N","X","V","C++","R90","N90"}
 
446
#endif
 
447
#endif
 
448
;
 
449
 
 
450
@ The following sets the delimiters for the module number stuff in the
 
451
code output.
 
452
 
 
453
@a
 
454
 
 
455
IN_COMMON outer_char begin_comment_char[NUM_LANGUAGES]
 
456
#ifdef _COMMON_h
 
457
#if(part == 0 || part == 1)
 
458
        = {'/','#','C','%','/', '/','#','C'}
 
459
#endif
 
460
#endif
 
461
; /* |C|, |RATFOR|, |FORTRAN|, |TEX|, |LITERAL|, \dots. */
 
462
 
 
463
IN_COMMON CONST outer_char end_comment_char[NUM_LANGUAGES]
 
464
#ifdef _COMMON_h
 
465
#if(part == 0 || part == 1)
 
466
        = {'/',' ',' ',' ','/', '/',' ',' '}
 
467
#endif
 
468
#endif
 
469
;
 
470
 
 
471
@
 
472
@<Mac...@>=
 
473
@@
 
474
@@<Specific language cases@@>=
 
475
 
 
476
case begin_C:
 
477
case begin_RATFOR:
 
478
case begin_FORTRAN:
 
479
case begin_LITERAL@@: @@;
 
480
 
 
481
@ The following readably abbreviate the control letters for language
 
482
switches.  These are just the basic languages; dialects are set by the
 
483
optional arguments.  We need to worry about the distinction between |ASCII|
 
484
and |outer_char|.
 
485
 
 
486
@<Mac...@>=
 
487
 
 
488
@@ 
 
489
@@f @@<|ASCII| cases for |C|@@> case
 
490
@@f @@<|ASCII| cases for |RATFOR|@@> case
 
491
@@f @@<|ASCII| cases for |FORTRAN|@@> case
 
492
@@f @@<|ASCII| cases for |TEX|@@> case
 
493
@@f @@<|ASCII| cases for |LITERAL|@@> case
 
494
@@<|ASCII| cases for |C|@@>=
 
495
case @@'c'@@: @@;
 
496
 
 
497
@@ @@<|ASCII| cases for |RATFOR|@@>=
 
498
case @@'r'@@: @@;
 
499
 
 
500
@@ @@<|ASCII| cases for |FORTRAN|@@>=
 
501
case @@'n'@@: @@;
 
502
 
 
503
@@ @@<|ASCII| cases for |TEX|@@>=
 
504
case @@'x'@@: @@;
 
505
 
 
506
@@ @@<|ASCII| cases for |LITERAL|@@>=
 
507
case @@'v'@@: @@;
 
508
 
 
509
@ Same stuff for |outer_char|.
 
510
 
 
511
@<Mac...@>=
 
512
 
 
513
@@ 
 
514
@@f @@<|outer_char| cases for |C|@@> case
 
515
@@f @@<|outer_char| cases for |RATFOR|@@> case
 
516
@@f @@<|outer_char| cases for |FORTRAN|@@> case
 
517
@@f @@<|outer_char| cases for |TEX|@@> case
 
518
@@f @@<|outer_char| cases for |LITERAL|@@> case
 
519
@@<|outer_char| cases for |C|@@>=
 
520
case 'c'@@:  @@;
 
521
 
 
522
@@ @@<|outer_char| cases for |RATFOR|@@>=
 
523
case 'r'@@:  @@;
 
524
 
 
525
@@ @@<|outer_char| cases for |FORTRAN|@@>=
 
526
case 'n'@@:  @@;
 
527
 
 
528
@@ @@<|outer_char| cases for |TEX|@@>=
 
529
case 'x'@@:  @@;
 
530
 
 
531
@@ @@<|outer_char| cases for |LITERAL|@@>=
 
532
case 'v'@@:  @@;
 
533
 
 
534
 
535
 
 
536
@<Mac...@>=
 
537
 
 
538
@@ Read the basic language letter and set the language.  We must check for
 
539
dialects before we call |opt_args| because the first thing that does is
 
540
to set the language based on the values of the dialect flags. 
 
541
 
 
542
@@<Set |language|@@>=
 
543
{
 
544
ASCII l = *loc++; /* The basic language letter. */
 
545
 
 
546
switch(l)
 
547
        {
 
548
   @@<|ASCII| cases for |C|@@>:
 
549
        Cpp = BOOLEAN(*loc == @@'+');
 
550
        break;
 
551
 
 
552
   @@<|ASCII| cases for |RATFOR|@@>:
 
553
   @@<|ASCII| cases for |FORTRAN|@@>:
 
554
        Fortran88 = BOOLEAN(*loc == @@'9');
 
555
        break;
 
556
 
 
557
   @@<|ASCII| cases for |LITERAL|@@>:
 
558
   @@<|ASCII| cases for |TEX|@@>:
 
559
        break;
 
560
 
 
561
   default:
 
562
        err_print(C,"! Invalid language command `@@@@L%c' ignored",XCHR(l));
 
563
        break;
 
564
        }
 
565
 
 
566
opt_args(l); /* Set the language, and parse optional arguments after
 
567
                language command. */ 
 
568
}
 
569
 
 
570
@ Dynamic memory allocation.
 
571
 
 
572
@d SET_VAL(val,abbrev) val = find_abbrev((outer_char *)abbrev)->nunits
 
573
@d MAX_VAL(abbrev) find_abbrev((outer_char *)abbrev)->max
 
574
 
 
575
@
 
576
@<Mac...@>=
 
577
@@ 
 
578
@@m UPPER(var) smin0(MAX_VAL(ABBREV(var))),ABBREV(var)
 
579
 
 
580
@
 
581
@a
 
582
 
 
583
typedef struct
 
584
        {
 
585
        outer_char abbrev[3]; /* Two-character abbreviation for the
 
586
variable. */
 
587
        short bytes;    /* Number of bytes in one unit. */
 
588
        BUF_SIZE min,   /* Minimum possible value. */
 
589
                nunits, /* How many units to allocate, or the default
 
590
value. */
 
591
                max;    /* Maximum possible value. */
 
592
        } MEM;
 
593
 
 
594
@ Masks for \FWEAVE\ stuff that may not want to be printed.
 
595
 
 
596
@a
 
597
 
 
598
typedef struct
 
599
        {
 
600
        unsigned@/
 
601
                formats:1, Formats:1, /* Print \.{@@f}, \.{@@F}. */
 
602
                limbo:1, /* Print \.{@@l}. */
 
603
                macros:1, /* Print \.{@@m}. */
 
604
                outer_macros:1, /* Print \.{@@d}. */
 
605
                v:1, /* Print \.{@@v}. */
 
606
                w:1 /* Print \.{@@w}. */
 
607
                ;
 
608
        } DEFN_MASK;
 
609
 
 
610
@ A number of unrelated parameters need to be saved simultaneously at
 
611
various points. Thus, we collect them into a structure, |params|. Since we
 
612
also need to be able to refer to them effectively, we use macro definitions
 
613
to help us.
 
614
 
 
615
@d LN lan_num
 
616
 
 
617
@D language params.Language
 
618
@D language_index params.Language_index
 
619
@D language_num params.Language_num
 
620
 
 
621
@D in_format params.In_format
 
622
@D in_data params.In_data
 
623
@D intermingle params.Intermingle
 
624
@%@D sharp_include_line params.Include_line
 
625
 
 
626
@D active_brackets params.Active_brackets
 
627
@D all_cmnts_verbatim params.All_cmnts_verbatim
 
628
@D all_includes params.All_includes
 
629
@D auto_app_semi params.Auto_app_semi
 
630
@D auto_semi params.Auto_semi[language_num]
 
631
@D auto_line params.Auto_line
 
632
@D auto_pseudo_semis params.Auto_pseudo_semis[language_num]
 
633
@D beeps params.Beeps
 
634
@D block_nums params.Block_nums[language_num]
 
635
@D bslash_continued_strings params.Bslash_continued_strings
 
636
@D color_mode params.Color_mode
 
637
@D chk_ifelse params.Chk_ifelse
 
638
@D chk_stmts params.Chk_stmts
 
639
@D compare_outfiles params.Compare_outfiles
 
640
@D compound_assignments params.Compound_assignments
 
641
@D Cpp params.CPP
 
642
@D Cpp_comments params.CPP_comments[language_num]
 
643
@D dbg_output params.Dbg_output
 
644
@D deferred_macros params.Deferred_macros
 
645
@D defn_mask params.Defn_mask
 
646
@D dot_constants params.Dot_constants
 
647
@D Fortran88 params.ForTran88
 
648
@D Fortran_label params.Fortran_Label
 
649
@D free_form_input params.Free_form_input[language_num]
 
650
@D ignore_C params.Ignore_C
 
651
@D in_escape params.In_escape[language_num]
 
652
@D index_hidden params.Index_hidden
 
653
@D index_one params.Index_one
 
654
@D input_macros params.Input_macros
 
655
@D keep_trailing_comments params.Keep_trailing_comments
 
656
@D lc_keywords params.Lc_keywords
 
657
@D line_info params.Line_info
 
658
@D lowercase_tokens params.Lowercase_tokens
 
659
@D m4 params.M4
 
660
@D makeindex params.Makeindex
 
661
@D no_xref params.No_xref
 
662
@D number_dos params.Number_dos
 
663
@D nuweb_mode params.Nuweb_mode
 
664
@D overload_ops params.Overload_ops
 
665
@D point_comments params.Point_comments[language_num]
 
666
@D prn_input_lines params.Prn_input_lines
 
667
@D prn_input_addresses params.Prn_input_addresses
 
668
@D prn_contents params.Prn_contents
 
669
@D prn_index params.Prn_index
 
670
@D prn_modules params.Prn_modules
 
671
@D prn_semis params.Prn_semis
 
672
@D prn_version params.Prn_version
 
673
@D quoted_includes params.Quoted_includes
 
674
@D Ratfor77 params.RatFor77
 
675
@D read_iformats params.Read_iformats
 
676
@D redefine_builtins params.Redefine_builtins
 
677
@D redefine_macros params.Redefine_macros
 
678
@D reverse_indices params.Reverse_indices[language_num]
 
679
@D rmv_files params.Rmv_files
 
680
@D skip_ifiles params.Skip_ifiles
 
681
@D skip_includes params.Skip_includes
 
682
@D statistics params.Statistics
 
683
@D subscript_fcns params.Subscript_fcns
 
684
@D suppress_cmds params.Suppress_cmds
 
685
@D TeX_processor params.TeX_Processor
 
686
@D toggle_includes params.Toggle_includes
 
687
@D top_version params.Top_version
 
688
@D translate_ASCII params.Translate_ASCII
 
689
@D translate_brackets params.Translate_brackets
 
690
@D truncate_ids params.Truncate_ids
 
691
@D try_extensions params.Try_extensions
 
692
@D xref_unnamed params.Xref_unnamed
 
693
 
 
694
@a
 
695
 
 
696
typedef enum {TeX_p,LaTeX_p} TeX_PROCESSOR; /* What to use with \FWEAVE. */
 
697
 
 
698
typedef enum
 
699
        {
 
700
        NO_COLOR, ANSI_COLOR, BILEVEL, TRILEVEL, USER_COLORS
 
701
        } COLOR_MODE;
 
702
 
 
703
typedef struct
 
704
        {
 
705
        LANGUAGE Language; /* The current language. May be set by encountering
 
706
a module name, or by explicit \.{@@n}, \.{@@r}, or \.{@@c} commands. */
 
707
        short Language_num,Language_index; /* These are set by
 
708
|ini_language|. */
 
709
        short uses; /* Number of times module is used.  Incremented by
 
710
                        \FWEAVE\ in \.{@@<Append a module name@@>}. */
 
711
 
 
712
boolean@/
 
713
/* Flags for really current state. */
 
714
        In_format, /* Inside a |@@r format| statement. */
 
715
        In_data, /* Inside a |@@r data| statement. */
 
716
        Intermingle, /* Inside something like a |@@r data|
 
717
statement. */
 
718
        Include_line, /* Inside an \&{include} line. */
 
719
/* Options flags.  Some of these apply to all languages, others differ from
 
720
language to language and are thus arrays. */
 
721
        Active_brackets, /* Special array handling? */
 
722
        All_cmnts_verbatim, /* Should \.{TANGLE} copy all comments? . */
 
723
        All_includes, /* Cross-reference all include files? */
 
724
        Auto_app_semi, /* For \.{WEAVE}, automatically
 
725
append a pseudo-semi to the end of \.{WEB} macro definitions? */
 
726
        Auto_semi[NUM_LANGUAGES], /* Fill in semicolon at end of source line? */
 
727
        Auto_line, /* Auto-insert line number after \.{@@\%}? */
 
728
        Auto_pseudo_semis[NUM_LANGUAGES], 
 
729
                /* F90 code:  append pseudo-semis, not semis. */
 
730
        Beeps, /* Do we beep the terminal for certain errors? */
 
731
        Block_nums[NUM_LANGUAGES], /* */
 
732
        Bslash_continued_strings, /* Do the continuations of
 
733
strings require a starting backslash? */ 
 
734
        Chk_ifelse, /* Protect parenthesized strings? */
 
735
        Chk_stmts, /* Check statement syntax in \Ratfor? */
 
736
        Compare_outfiles, /* Check new (temporary) vs.\ old output? */
 
737
        Compound_assignments, /* Do we allow things like \.{+=}? */
 
738
        CPP, /* Do we recognize \.{C++}? */
 
739
        CPP_comments[NUM_LANGUAGES], /* Allow short comments? */
 
740
        Dbg_output, /* Print each character fired at output? */
 
741
        Deferred_macros, /* Allow deferred macros? */
 
742
        Dot_constants, /* Recognize dot constants like `\.{.eq.}'? */
 
743
        ForTran88, /* Turn on stuff for Fortran-88? */
 
744
        Fortran_Label, /* Label on same line? */
 
745
        Free_form_input[NUM_LANGUAGES], /* Free-form syntax. */
 
746
        Ignore_C, /* Throw away single \Fortran\ comment lines. */
 
747
        In_escape[NUM_LANGUAGES], /* (|outer_char|) continuation character
 
748
for end-of-lines. */
 
749
        Index_hidden, /* Index skipped include files. */
 
750
        Index_one, /* Index single-character identifiers? */
 
751
        Input_macros, /* Generate the default ``\.{\\input fwebmac}'' line? */
 
752
        Keep_trailing_comments, /* For \TeX, retain comments that don't
 
753
start a line. */
 
754
        Lc_keywords, /* Lower-case \Fortran\ and \Ratfor\ I/O keywords? */
 
755
        Line_info, /* Should \FTANGLE\ print out line information? */ 
 
756
        Lowercase_tokens, /* Output lower-case tokens (\Ratfor). */
 
757
        M4, /* Recognize \.{M4} preprocessor commands? */
 
758
        Makeindex, /* Output \.{makeindex} file? */
 
759
        No_xref, /* Should \.{WEAVE} print an index? */
 
760
        Number_dos, /* */
 
761
        Nuweb_mode, /* Emulate \.{nuweb}? */
 
762
        Overload_ops, /* Is operator overloading allowed? */
 
763
        Point_comments[NUM_LANGUAGES], /* Does \.! signify a \Fortran\ or
 
764
\Ratfor\ comment? */
 
765
        Prn_contents, /* Print table of contents? */
 
766
        Prn_index, /* Print index? */
 
767
        Prn_input_lines, /* Used in |input_ln| to print out the lines sent
 
768
back. */ 
 
769
        Prn_input_addresses, /* Print out the buffer addresses. */
 
770
        Prn_modules, /* Print module list? */
 
771
        Prn_semis, /* Print semicolons in \Fortran\ output. */
 
772
        Prn_version, /* Print the \FWEB\ version? */
 
773
        Quoted_includes, /* Cross-reference quoted include files? */
 
774
        RatFor77, /* Expand \Ratfor\ code directly to \Fortran-77? */  
 
775
        Read_iformats, /* Read include files for formats. */
 
776
        Redefine_builtins, /* Permit built-in functions to be redefined. */
 
777
        Redefine_macros, /* Permit user macros to be redefined. */
 
778
        Reverse_indices[NUM_LANGUAGES], /* C-style indexing in \Fortran? */
 
779
        Rmv_files, /* Remove temporary files related to \.{-H}? */
 
780
        Skip_ifiles, /* \.{-j} --- skip files already included. */
 
781
        Skip_includes, /* For \.{WEAVE}, don't read in \.{@@I} commands.
 
782
(Uppercase '\.{I}' only.) */ 
 
783
        Statistics, /* Print statistics about memory usage? */
 
784
        Subscript_fcns, /* Put module references on functions? */
 
785
        Suppress_cmds, /* ??? */
 
786
        Toggle_includes, /* For \.{WEAVE}, read in \.{@@I} commands, but
 
787
don't print them out. */ 
 
788
        Top_version, /* Header info at top of output? */
 
789
        Translate_ASCII, /* Do we bother with the |xchr|--|xord|
 
790
conversions? */ 
 
791
        Translate_brackets, /* Brackets to parentheses in \Fortran? */
 
792
        Truncate_ids, /* Shorten identifiers? */
 
793
        Try_extensions, /* Search through list of possible file names? */
 
794
        Xref_unnamed; /* Cross-reference unnamed references? */
 
795
 
 
796
COLOR_MODE Color_mode; /* The color setting. */
 
797
DEFN_MASK Defn_mask; /* What defn's to print by \FWEAVE. */
 
798
TeX_PROCESSOR TeX_Processor; /* Processor to be used with \FWEAVE. */
 
799
 
 
800
outer_char HUGE*outp_nm[NUM_LANGUAGES]; /* Current output file names. */
 
801
FILE *outp_file[NUM_LANGUAGES]; /* File ptrs associated with above. */
 
802
        } PARAMS;
 
803
 
 
804
IN_COMMON PARAMS params,global_params;
 
805
IN_COMMON boolean stop_the_scan;
 
806
 
 
807
@ We need to know what kind of construction is being parsed, so the
 
808
|get_line| routine can distinguish various input formats (for \FORTRAN). 
 
809
 
 
810
@a
 
811
 
 
812
typedef enum {OUTER,INNER} PARSING_MODE;
 
813
 
 
814
IN_COMMON PARSING_MODE parsing_mode CSET(OUTER);
 
815
 
 
816
@ More stuff related to parsing the input line.
 
817
 
 
818
@d preprocessing parse_params.Preprocessing
 
819
@d at_beginning parse_params.At_beginning
 
820
@d sharp_include_line parse_params.Sharp_include_line
 
821
@d sharp_pragma_line parse_params.Sharp_pragma_line
 
822
 
 
823
@a
 
824
 
 
825
typedef struct
 
826
        {
 
827
        boolean Preprocessing; /* Are we scanning a preprocessor command? */
 
828
        boolean At_beginning;  /* Are we at logical beginning of line? */
 
829
        boolean Sharp_include_line; /* Does line start with ``|#include|''? */
 
830
        boolean Sharp_pragma_line; /* Starts with ``|#pragma|''? */
 
831
        } PARSE_PARAMS;
 
832
 
 
833
IN_COMMON PARSE_PARAMS parse_params 
 
834
#ifdef _COMMON_h
 
835
#if(part == 0 || part == 1)
 
836
        = {NO,YES}
 
837
#endif
 
838
#endif
 
839
;
 
840
 
 
841
@ On an |ASCII| machine, we can speed things up by not bothering with the
 
842
translations. (The flag |TRANSLATE_ASCII| is set in \.{os.hweb}.)
 
843
 
 
844
/* |ASCII| case changes. */
 
845
@d isAupper(c) (c<=@'Z' && c>=@'A')
 
846
@d isAlower(c) (c<=@'z' && c>=@'a')
 
847
 
 
848
@d SET_CASE(c) upper_case_code = BOOLEAN(isAupper(c))
 
849
         /* Watch out for side effects. */
 
850
@d lower_case_code BOOLEAN(!upper_case_code)
 
851
 
 
852
@d A_TO_LOWER(c) (ASCII)(isAupper(c) ? (int)c+040 : c)
 
853
@d A_TO_UPPER(c) (ASCII)(isAlower(c) ? (int)c-040 : c)
 
854
 
 
855
/* Handle the difference between |ASCII| and |outer_char|. */
 
856
@d isAlpha(c) isalpha(XCHR(c))
 
857
@d isDigit(c) isdigit(XCHR(c)) /* We're working on |ASCII| input. */
 
858
@d isBdigit(c) ((c)==@'0' || (c)==@'1') /* Is it a binary numeral? */
 
859
@d isOdigit(c) (isDigit(c) && c!=@'8' && c!=@'9') /* Octal numeral? */
 
860
@d isXdigit(c) isxdigit(XCHR(c)) /* Hex numeral? */
 
861
 
 
862
@a
 
863
 
 
864
EXTERN boolean upper_case_code SET(NO);
 
865
 
 
866
/* For debugging of target machines with a different character set than
 
867
that of the present machine, use the |DEBUG_XCHR| flag to force the
 
868
internal representation to be ``scrambled |ASCII|'', which replaces the
 
869
array~|xchr| with |wt_style.xchr|. */
 
870
#if(DEBUG_XCHR)
 
871
        #define XCHR_ wt_style.xchr /* Scrambled mapping. */
 
872
#else
 
873
        #define XCHR_ xchr /* The mapping for this machine. */
 
874
#endif /* |DEBUG_XCHR| */
 
875
 
 
876
#if(TRANSLATE_ASCII)
 
877
        #define XORD(outer) xord[outer]
 
878
        #define XCHR(inner) XCHR_[inner]
 
879
#else /* Don't bother with the translations. */
 
880
        #define XORD(outr) (outr) /* Funny spelling from Dethier's changes. */
 
881
        #define XCHR(innr) (innr)
 
882
#endif /* |TRANSLATE_ASCII| */
 
883
 
 
884
typedef unsigned char ASCII; /* Type of characters inside \.{WEB}. */
 
885
 
 
886
@ Here is how reserved words are stored.
 
887
 
 
888
@a
 
889
 
 
890
typedef struct
 
891
        {
 
892
        CONST char HUGE *reserved_word;
 
893
        eight_bits type;
 
894
        } RESERVED_WORD;
 
895
 
 
896
@ A global variable called |history| will contain one of four values
 
897
at the end of every run: 
 
898
\begin{itemize}
 
899
 
 
900
\item
 
901
|SPOTLESS| means that no unusual messages were printed; 
 
902
 
 
903
\item
 
904
|HARMLESS_MESSAGE| means that a message of possible interest
 
905
was printed but no serious errors were detected; 
 
906
 
 
907
\item
 
908
|ERROR_MESSAGE| means that at least one error was found; 
 
909
 
 
910
\item
 
911
|FATAL_MESSAGE| means that the program terminated abnormally. 
 
912
 
 
913
\end{itemize}
 
914
 
 
915
The value of |history| does not influence the behavior of the program; it
 
916
is simply computed for the convenience of systems that might want to use
 
917
such information.
 
918
 
 
919
@d mark_harmless 
 
920
        {
 
921
        SET_COLOR(ordinary); 
 
922
        if (history==SPOTLESS) 
 
923
                history = HARMLESS_MESSAGE;
 
924
        } 
 
925
 
 
926
@d mark_error 
 
927
        {
 
928
        SET_COLOR(ordinary);
 
929
        history = ERROR_MESSAGE;
 
930
        }
 
931
 
 
932
 
 
933
@a
 
934
 
 
935
typedef enum
 
936
        {
 
937
        SPOTLESS, /*  Normal jobs */
 
938
        HARMLESS_MESSAGE, /*  Non-serious info was printed */ 
 
939
        ERROR_MESSAGE, /*  An error was noted */
 
940
        FATAL_MESSAGE /*  We had to stop prematurely */
 
941
        } HISTORY;
 
942
 
 
943
IN_COMMON HISTORY history CSET(SPOTLESS); /* indicates how bad this run was */
 
944
 
 
945
typedef enum
 
946
        {
 
947
        ALWAYS,
 
948
        NOTHING = 0,
 
949
        ERRORS_ONLY,
 
950
        WARNINGS,
 
951
        SHORT_INFO,
 
952
        EVERYTHING
 
953
        } MSG_LEVEL;
 
954
 
 
955
IN_COMMON MSG_LEVEL msg_level CSET(EVERYTHING); /* When to print. */
 
956
 
 
957
typedef enum
 
958
        {
 
959
        NONE,
 
960
        BRIEF,
 
961
        VERBOSE
 
962
        } TRACING_LEVEL;
 
963
 
 
964
IN_COMMON TRACING_LEVEL tracing CSET(NONE); /* For debugging \.{WEAVE}. */
 
965
 
 
966
 
967
 
 
968
@<Mac...@>=
 
969
@@ A simple error message with no arguments is used frequently.  Error
 
970
messages now carry an indication of their origin.
 
971
 
 
972
@@m err_print(origin,msg,...) 
 
973
        err0_print(ERR_##origin,OC(msg),#0,#.)
 
974
@@m err_print_(origin,msg,...) 
 
975
        err0_print(ERR_##origin,OC(msg),-1-#0,#.)
 
976
@@m ERR_PRINT(origin,msg) err_print(origin,msg) 
 
977
 
 
978
@@m MACRO_ERR(msg,trail,...) 
 
979
        macro_err(OC(msg),trail,#.)
 
980
 
 
981
@
 
982
@a
 
983
 
 
984
typedef enum {ERR_NULL,ERR_C,ERR_T,ERR_W,ERR_R,ERR_M,ERR_S,ERR_F} ERR_ORIGIN;
 
985
IN_COMMON boolean err_happened CSET(NO);
 
986
 
 
987
 
 
988
@ Code related to file handling. The open input files are maintained on a
 
989
stack, with the |WEB_FILE| at the top~(0).  For every input file, there is
 
990
an associated change file.
 
991
 
 
992
@f line x /* Make |line| an unreserved word. */
 
993
 
 
994
@d OUTPUT_LINE outp_line[lan_num(language)]
 
995
@d OUTPUT_FILE_NAME outp_nm[lan_num(out_language)]
 
996
@d OUT_LANGUAGE(language)
 
997
        (R77_or_F ? (Fortran88 ? FORTRAN_90 : FORTRAN) : language)
 
998
@d OUT_FILE_NAME outp_nm[lan_num(OUT_LANGUAGE(language))]
 
999
 
 
1000
@D PUTC(c) 
 
1001
        {
 
1002
        CHECK_OPEN;
 
1003
        if(putc((int)(c),out_file) == EOF) 
 
1004
                out_error(OC("putc"));
 
1005
        }
 
1006
 
 
1007
@d MAX_FILE_NAME_LENGTH 200
 
1008
 
 
1009
@D WEB_FILE 0
 
1010
@D web_file_name prms[WEB_FILE].web.File_name /* Main source file name. */
 
1011
@D web_file prms[WEB_FILE].web.File /* Main source file. */
 
1012
 
 
1013
@D CUR_FILE incl_depth
 
1014
@D cur_file_name prms[CUR_FILE].web.File_name /* Current input file name. */
 
1015
@D cur_file prms[CUR_FILE].web.File /* Current input file. */
 
1016
 
 
1017
@D cur_line cur0_prms->Line /* Number of current line in current file. */
 
1018
 
 
1019
@D change_file_name prms[CUR_FILE].change.File_name
 
1020
@D change_file prms[CUR_FILE].change.File
 
1021
@D change_line prms[CUR_FILE].change.Line
 
1022
 
 
1023
/* --- Stuff used mostly within |input_ln| --- */
 
1024
@D num_in_buffer cur0_prms->Num_in_buffer
 
1025
@D comment_in_buffer cur0_prms->Comment_in_buffer
 
1026
@D scanning_C_cmnt cur0_prms->Scanning_C_cmnt
 
1027
@D start_C cur0_prms->Start_C
 
1028
@D last_was_empty cur0_prms->Last_was_empty
 
1029
@D continuing_line cur0_prms->Continuing_line
 
1030
@D last_was_continued cur0_prms->Last_was_continued
 
1031
 
 
1032
/* The following are used as arguments to |input_ln|. */
 
1033
@D INPUT_FILE &prms[CUR_FILE].web
 
1034
@D CHANGE_FILE &prms[CUR_FILE].change
 
1035
 
 
1036
/* --- Buffers --- */
 
1037
@D cur_buffer cur0_prms->Buffer
 
1038
@D buffer_end cur0_prms->Buffer_end
 
1039
@D limit cur0_prms->Limit /* points to the last character in the buffer. */
 
1040
 
 
1041
@D change_buffer (cur_prms.change)->Buffer
 
1042
@D change_buffer_end (cur_prms.change)->Buffer_end
 
1043
@D change_limit (cur_prms.change)->Limit
 
1044
 
 
1045
@a
 
1046
 
 
1047
IN_COMMON LANGUAGE out_language; /* Current language for output file. */
 
1048
IN_COMMON FILE *out_file; /* Current output file pointer. */
 
1049
IN_COMMON int incl_depth; /* Current level of file nesting. */
 
1050
 
 
1051
typedef struct
 
1052
        {
 
1053
        FILE *File;     /* Pointer to file. */
 
1054
        LINE_NUMBER Line;       /* Line number. */
 
1055
        ASCII HUGE *Buffer; /* Input buffer. */
 
1056
        ASCII HUGE *Buffer_end;
 
1057
        ASCII HUGE *K0;
 
1058
        ASCII HUGE *Limit; /* Next unfilled position. */
 
1059
        int Num_in_buffer; /* Number remaining to be read. */
 
1060
        boolean Comment_in_buffer; 
 
1061
        boolean Found_at,At_line;
 
1062
        boolean Scanning_C_cmnt,Start_C,Last_was_empty;
 
1063
        boolean Continuing_line,Last_was_continued;
 
1064
        outer_char File_name[MAX_FILE_NAME_LENGTH]; 
 
1065
        } INPUT_PRMS0;
 
1066
 
 
1067
IN_COMMON INPUT_PRMS0 HUGE *cur0_prms; /* Pointer to current parameters. */
 
1068
 
 
1069
typedef struct
 
1070
        {
 
1071
        INPUT_PRMS0 HUGE *web, HUGE *change;
 
1072
        } CUR_PRMS;
 
1073
 
 
1074
IN_COMMON CUR_PRMS cur_prms; /* Address of current input parameters. */
 
1075
 
 
1076
typedef struct
 
1077
        {
 
1078
        LANGUAGE Language;
 
1079
        PARSING_MODE Parsing_mode;
 
1080
        boolean Column_mode;
 
1081
        } INPUT_PARAMS;
 
1082
 
 
1083
typedef struct Rcs
 
1084
        {
 
1085
        ASCII HUGE *keyword, HUGE *txt;
 
1086
        struct Rcs HUGE *next;
 
1087
        } RCS;
 
1088
 
 
1089
typedef struct
 
1090
        {
 
1091
        RCS HUGE *start, HUGE *end;
 
1092
        } RCS_LIST;
 
1093
 
 
1094
typedef struct
 
1095
        {
 
1096
        INPUT_PRMS0 web, change;
 
1097
        INPUT_PARAMS input_params;
 
1098
        RCS_LIST rcs_list; /* RCS keywords. */
 
1099
        } INPUT_PRMS;
 
1100
 
 
1101
IN_COMMON BUF_SIZE max_include_depth;
 
1102
IN_COMMON INPUT_PRMS *prms; /* Stack of |max_include_depth+1| open files. */
 
1103
 
 
1104
IN_COMMON outer_char HUGE *tex_fname; /* Name of |tex_file|. */
 
1105
#define tex_file out_file /* Where output of \.{WEAVE} goes. */
 
1106
 
 
1107
IN_COMMON outer_char HUGE *fwebmac; /* The default macro package. */
 
1108
 
 
1109
IN_COMMON boolean input_has_ended; /* If there is no more input. */
 
1110
IN_COMMON boolean changing; /* If the current line is from |change_file|. */
 
1111
 
 
1112
typedef struct
 
1113
        {
 
1114
        outer_char HUGE *name; /* The ultimate output file name. */
 
1115
        outer_char HUGE *tmp_name; /* Temporary file name, so new results
 
1116
                                        can be compared with old ones. */
 
1117
        FILE *ptr; /* A pointer to |tmp_name|. */
 
1118
        eight_bits previously_opened; /* Possibly opened, but now closed. */
 
1119
        eight_bits global_scope; /* To control closing at end of each sectn. */
 
1120
        } OPEN_FILE; /* Info about previously opened files. */
 
1121
 
 
1122
@ Short-hand for arguments to built-in functions.
 
1123
 
 
1124
@a
 
1125
typedef eight_bits HUGE *PARGS[];
 
1126
 
 
1127
@
 
1128
To recognize the various built-in functions, we must search through
 
1129
a list.  
 
1130
 
 
1131
@d MAX_DOT_LENGTH 31 /* Don't have to scan farther than this to see if it's
 
1132
                        a dot constant. The~31 is a \FORTRAN-90 limit. */
 
1133
 
 
1134
@a
 
1135
 
 
1136
IN_COMMON ASCII HUGE *id_first; /* Where the current identifier begins in
 
1137
                                        the buffer */  
 
1138
IN_COMMON ASCII HUGE *id_loc; /* Just after the current identifier in the
 
1139
                                        buffer */  
 
1140
 
 
1141
typedef struct
 
1142
        {
 
1143
        ASCII *name;
 
1144
        int n;
 
1145
        } BUILT_IN;
 
1146
 
 
1147
IN_COMMON BUILT_IN incl_likes[]
 
1148
#ifdef _COMMON_h
 
1149
#if(part == 0 || part == 1)
 
1150
        = {
 
1151
        {(ASCII *)"changequote",11},
 
1152
        {(ASCII *)"ifelse",6},
 
1153
        {(ASCII *)"include",7},
 
1154
        {(ASCII *)"index",5},
 
1155
        {(ASCII *)"len",3},
 
1156
        {(ASCII *)"maketemp",8},
 
1157
        {(ASCII *)"sinclude",8},
 
1158
        {(ASCII *)"substr",6},
 
1159
        {(ASCII *)"syscmd",6},
 
1160
        {(ASCII *)"translit",8},
 
1161
        {(ASCII *)"",0}
 
1162
        }
 
1163
#endif
 
1164
#endif
 
1165
;
 
1166
 
 
1167
IN_COMMON BUILT_IN WEB_incl_likes[]
 
1168
#ifdef _COMMON_h
 
1169
#if(part == 0 || part == 1)
 
1170
        = {
 
1171
        {(ASCII *)"@!$COMMENT",8},
 
1172
        {(ASCII *)"@!$DEFINE",7},
 
1173
        {(ASCII *)"@!$ERROR",6},
 
1174
        {(ASCII *)"@!$IF",3},
 
1175
        {(ASCII *)"@!$IFCASE",7},
 
1176
        {(ASCII *)"@!$IFELSE",7},
 
1177
        {(ASCII *)"@!$LEN",4},
 
1178
        {(ASCII *)"@!$M",2},
 
1179
        {(ASCII *)"@!_COMMENT",8},
 
1180
        {(ASCII *)"@!_DEFINE",7},
 
1181
        {(ASCII *)"@!_ERROR",6},
 
1182
        {(ASCII *)"@!_IF",3},
 
1183
        {(ASCII *)"@!_IFCASE",7},
 
1184
        {(ASCII *)"@!_IFELSE",7},
 
1185
        {(ASCII *)"@!_LEN",4},
 
1186
        {(ASCII *)"@!_M",2},
 
1187
        {(ASCII *)"",0}
 
1188
        }
 
1189
#endif
 
1190
#endif
 
1191
;
 
1192
 
 
1193
@ A similar list takes care of \Ratfor-90 statements that mustn't be
 
1194
considered as statement labels.
 
1195
 
 
1196
@a
 
1197
 
 
1198
IN_COMMON BUILT_IN non_labels[]
 
1199
#ifdef _COMMON_h
 
1200
#if(part == 0 || part == 1)
 
1201
        = {
 
1202
        {(ASCII *)"contains",8},
 
1203
        {(ASCII *)"default",7},
 
1204
        {(ASCII *)"private",7},
 
1205
        {(ASCII *)"protected",9},
 
1206
        {(ASCII *)"public",6},
 
1207
        {(ASCII *)"sequence",8},
 
1208
        {(ASCII *)"",0}
 
1209
        }
 
1210
#endif
 
1211
#endif
 
1212
;
 
1213
 
 
1214
 
1215
 
 
1216
@D dot_const OCTAL(23)
 
1217
 
 
1218
@<Mac...@>=
 
1219
@@ FORTRAN uses constructions such as~|@@r .true.| or~|@@r .and.|, which we
 
1220
have to parse separately.
 
1221
 
 
1222
@@m PREDEFINED_DOTS 14 /* \# of pre-initialized entries in the |dots| table. */
 
1223
 
 
1224
@
 
1225
@a
 
1226
 
 
1227
typedef struct
 
1228
        {
 
1229
        ASCII *symbol;
 
1230
        short len;
 
1231
        eight_bits code; /* Something like |dot_const|. */
 
1232
        eight_bits cat; /* Category code for special constants and
 
1233
operators. */
 
1234
        eight_bits token; /* The tokenized meaning of this operator. */
 
1235
        } DOTS;
 
1236
 
 
1237
typedef struct
 
1238
        {
 
1239
        ASCII name[MAX_DOT_LENGTH+3]; /* Holds the macro name to be
 
1240
appended. */ 
 
1241
        eight_bits cat; /* Category of the operator. */
 
1242
        eight_bits num; /* Position in the table. */
 
1243
        } DOT_OP;
 
1244
 
 
1245
IN_COMMON DOT_OP dot_op 
 
1246
#ifdef _COMMON_h
 
1247
#if(part == 0 || part == 1)
 
1248
        = {"\\",0,0}
 
1249
#endif
 
1250
#endif
 
1251
;
 
1252
 
 
1253
@ The |macrobuf| is a character buffer used for expanding macros, or for
 
1254
holding macros defined from the input line. The present position in the
 
1255
|macrobuf| is~|mp|.  For |macrobuf|, see \.{stacks.hweb} (\FTANGLE) or \FWEAVE.
 
1256
 
 
1257
@d MAKE_RECURSIVE @'*' /* To allow a WEB macro to be recursive, preface its
 
1258
        definition by this symbol, as in `\.{@@m *R R}'.  (Recursive macros
 
1259
        are not presently implemented.) */
 
1260
 
 
1261
@d AUTO_INSERT @'['
 
1262
@d END_AUTO_INSERT @']'
 
1263
 
 
1264
@d PROTECTED @'!' /* A protected macro ---`\.{@@m!}'---may not be redefined. */
 
1265
 
 
1266
@a
 
1267
 
 
1268
IN_COMMON boolean in_macro CSET(NO);
 
1269
        
 
1270
IN_COMMON BUF_SIZE mbuf_size; /* Set dynamically. */
 
1271
IN_COMMON eight_bits HUGE *mp; /* Next available position in |macrobuf|. */
 
1272
 
 
1273
IN_COMMON boolean from_buffer CSET(NO); /* Are we reading from a buffer? */
 
1274
 
 
1275
@ Stuff related to command-line arguments.
 
1276
 
 
1277
@a
 
1278
 
 
1279
IN_COMMON int argc; /* copy of |ac| parameter to |main| */
 
1280
IN_COMMON outer_char **argv; /* copy of |av| parameter to |main| */
 
1281
IN_COMMON outer_char HUGE *pa, *pa_begin; /* Current/init value of |*argv|. */
 
1282
 
 
1283
@ Defaults for |boolean| flags, etc.
 
1284
 
 
1285
/* MACROS here. */
 
1286
@d ACTIVE_BRACKETS NO
 
1287
@d ALL_CMNTS_VERBATIM NO
 
1288
@d ALL_INCLUDES NO
 
1289
@d AUTO_APP_SEMI NO
 
1290
@d AUTO_LINE YES
 
1291
@d AUTO_PSEUDO_SEMIS YES
 
1292
@d BEEPS YES
 
1293
@d BLOCK_NUMS NO
 
1294
@d BSLASH_CONTINUED_STRINGS NO
 
1295
@d CHK_IFELSE NO
 
1296
@d CHK_STMTS NO
 
1297
@d COLOR_MODE0 NO_COLOR
 
1298
@d COMPARE_OUTFILES NO
 
1299
@d COMPOUND_ASSIGNMENTS YES
 
1300
@d CPP_COMMENTS YES
 
1301
@d DBG_OUTPUT NO
 
1302
@d DEFERRED_MACROS NO
 
1303
@d DOT_CONSTANTS YES
 
1304
@d FORTRAN88 NO /* By default, it's \FORTRAN-77. */
 
1305
@d FORTRAN_LABEL YES
 
1306
@d FREE_FORM_INPUT YES
 
1307
@d FREE_FORTRAN NO
 
1308
@d IGNORE_C NO
 
1309
@d IN_ESCAPE '\\'
 
1310
@d INDEX_HIDDEN NO
 
1311
@d INDEX_ONE NO
 
1312
@d INPUT_MACROS YES
 
1313
@d KEEP_TRAILING_COMMENTS YES
 
1314
@d LC_KEYWORDS YES /* Changed 1/11/98 */
 
1315
@d LINE_INFO YES
 
1316
@d LOWERCASE_TOKENS NO
 
1317
@d M4_ NO
 
1318
@d MAKEINDEX NO
 
1319
@d NO_XREF NO
 
1320
@d NUMBER_DOS NO
 
1321
@d NUWEB_MODE NO
 
1322
@d OVERLOAD_OPS YES
 
1323
@d POINT_COMMENTS NO
 
1324
@d PRN_CONTENTS YES
 
1325
@d PRN_OUTER_MACROS YES
 
1326
@d PRN_fORMATS YES
 
1327
@d PRN_FORMATS YES
 
1328
@d PRN_LIMBO YES
 
1329
@d PRN_INDEX YES
 
1330
@d PRN_MACROS YES
 
1331
@d PRN_MODULES YES
 
1332
@d PRN_SEMIS NO
 
1333
@d PRN_V YES
 
1334
@d PRN_VERSION NO
 
1335
@d PRN_W YES
 
1336
@d QUOTED_INCLUDES NO
 
1337
@d RATFOR77 YES
 
1338
@d READ_IFORMATS NO
 
1339
@d REDEFINE_BUILTINS NO
 
1340
@d REDEFINE_MACROS NO
 
1341
@d REVERSE_INDICES NO
 
1342
@d RMV_FILES YES
 
1343
@d SKIP_IFILES NO
 
1344
@d SKIP_INCLUDES NO
 
1345
@d STATISTICS NO
 
1346
@d SUBSCRIPT_FCNS YES
 
1347
@d TOGGLE_INCLUDES NO
 
1348
@d TOP_VERSION YES
 
1349
@d TRANSLATE_ASCII0 NO
 
1350
@d TRANSLATE_BRACKETS YES
 
1351
@d TRY_EXTENSIONS NO
 
1352
@d TEX_PROCESSOR LaTeX_p
 
1353
@d XREF_UNNAMED YES
 
1354
 
 
1355
@d CCHAR '&' /* Default \FORTRAN\ continuation character. */
 
1356
 
 
1357
@d NUM_RATFOR_CMDS 20 /* The total number of reserved \RATFOR\ keywords.
 
1358
        This is used for an array size later on. */
 
1359
 
 
1360
@ A structure used for |see_reserved| and |id_info|.
 
1361
@a
 
1362
 
 
1363
typedef struct
 
1364
        {
 
1365
        outer_char HUGE *args;
 
1366
        boolean intrinsics, keywords, reserveds;
 
1367
        } RSRVD;
 
1368
 
 
1369
@
 
1370
@a
 
1371
 
 
1372
IN_COMMON outer_char cchar CSET(CCHAR); /* Fortran's continuation
 
1373
character. */
 
1374
 
 
1375
IN_COMMON ASCII cont_char CSET(@'\\'); /* Current continuation char for eol. */
 
1376
IN_COMMON boolean free_Fortran CSET(NO); /* Free-form syntax in \Fortran.  */
 
1377
IN_COMMON boolean free_90 CSET(NO); /* \Fortran/\Ratfor-90 and free-form syntax. */
 
1378
 
 
1379
IN_COMMON unsigned short tr_max[NUM_LANGUAGES]
 
1380
#ifdef _COMMON_h
 
1381
#if(part == 0 || part == 1)
 
1382
        = {0,0,0,0,0,0,0,0}
 
1383
#endif
 
1384
#endif
 
1385
;
 
1386
 
 
1387
IN_COMMON CONST char HUGE *filter_char[NUM_LANGUAGES] 
 
1388
#ifdef _COMMON_h
 
1389
#if(part == 0 || part == 1)
 
1390
        = {"","_","_","","", "","_","_"}
 
1391
#endif
 
1392
#endif
 
1393
;
 
1394
 
 
1395
IN_COMMON outer_char abbrev_cmds[NUM_RATFOR_CMDS+1] CSET(""); /* Nothing
 
1396
        suppressed by default. */ 
 
1397
 
 
1398
@ Holds the command-line arguments, after expansion from the ini file.
 
1399
@a
 
1400
 
 
1401
IN_COMMON outer_char HUGE *cmd_ln_buf;
 
1402
 
 
1403
@ The global variable |word_type| holds the type of identifier that
 
1404
|id_lookup| will work on next. This comes into play when the |last|
 
1405
argument to |id_lookup| is |NULL|. In this case, |id_lookup| finds its own
 
1406
end of the identifier.
 
1407
 
 
1408
@D mod_info info.mod
 
1409
@D mod_ilk mod_info->Ilk
 
1410
@D macro_type info.Macro_type
 
1411
 
 
1412
@D defined_in(languag) dummy.defined_info[lan_num(languag)].section
 
1413
@D defined_type(languag) dummy.defined_info[lan_num(languag)].type
 
1414
@D ilk Ilk[language_num]
 
1415
@D expandable dummy.RX.Expandable
 
1416
@D rlink dummy.RX.Rlink
 
1417
@D x_translate dummy.RX.Expand
 
1418
 
 
1419
@f HUGE_FCN_PTR huge
 
1420
 
 
1421
@a
 
1422
 
 
1423
typedef enum {NO_TYPE,ORDINARY_ID,RESERVED_WD,INTRINSIC_FCN,KEYWD} WORD_TYPE;
 
1424
 
 
1425
IN_COMMON WORD_TYPE word_type CSET(ORDINARY_ID);
 
1426
 
 
1427
#define X_FCN SRTN      /* |typedef| didn't work on the VAX. */
 
1428
 
 
1429
typedef struct RX_link
 
1430
        {
 
1431
        struct name_info HUGE *Rlink; /* right link in binary search tree for
 
1432
                                        module names */  
 
1433
        X_FCN (HUGE_FCN_PTR * HUGE *Expand)(VOID); /* Array of functions
 
1434
for keyword expansion (one for each language). */
 
1435
        boolean Expandable; /* For which language is this expandable? */
 
1436
        } RX_LINK;
 
1437
 
 
1438
typedef struct
 
1439
        {
 
1440
        char Ilk;
 
1441
        PARAMS params;  
 
1442
        } MOD_INFO;
 
1443
 
 
1444
IN_COMMON boolean index_flag; /* Print identifier in index? */
 
1445
 
 
1446
typedef boolean NAME_TYPE; /* Type of identifier, enumerated below. */
 
1447
 
 
1448
enum {NEVER_DEFINED=0,
 
1449
        GENERIC_NAME,FUNCTION_NAME,M_MACRO,D_MACRO,IMPLICIT_RESERVED,
 
1450
        TYPEDEF_NAME,
 
1451
        NEVER_DEFINED0=0x80,
 
1452
        GENERIC_NAME0,FUNCTION_NAME0,M_MACRO0,D_MACRO0,IMPLICIT_RESERVED0,
 
1453
        TYPEDEF_NAME0};
 
1454
 
 
1455
/* Maybe the |defined_type| is already marked to not appear in the index.
 
1456
(It's $> 128$.)  To properly set a new type, we use a macro to keep the
 
1457
flag and attach it to the new type. */ 
 
1458
#define SET_TYPE(p,type) p->defined_type(language) =\
 
1459
         ((boolean)(type) | (boolean)((p->defined_type(language) & 0x80)))
 
1460
 
 
1461
/* To recover the base type, use the following, which strips off the flag: */
 
1462
#define DEFINED_TYPE(p) (p->defined_type(language) & 0x7F)
 
1463
 
 
1464
typedef struct
 
1465
        {
 
1466
        sixteen_bits section; /* Section number where identifier defined. */
 
1467
        NAME_TYPE type; /* Kind of identifier, such as function name. */
 
1468
        } DEFINED_INFO;
 
1469
 
 
1470
typedef struct
 
1471
        {
 
1472
        ASCII HUGE *text; /* The replacement text for the macro. */
 
1473
        unsigned int len; /* Length of replacement text. */
 
1474
        eight_bits cat; /* Category code. */
 
1475
        } WV_MACRO;
 
1476
 
 
1477
typedef struct name_info 
 
1478
        {
 
1479
        ASCII HUGE *byte_start; /* Beginning of the name in |byte_mem|. */
 
1480
        struct name_info HUGE *link; /* Used for hashing. */
 
1481
        union 
 
1482
                {
 
1483
                struct RX_link RX; /* For \FTANGLE. */
 
1484
                DEFINED_INFO defined_info[NUM_LANGUAGES]; /* For \FWEAVE. */
 
1485
                } dummy;
 
1486
        boolean reserved_word,intrinsic_word,keyword;
 
1487
        boolean Language;
 
1488
        union
 
1489
                {
 
1490
                char Macro_type; /* For \FTANGLE. */
 
1491
                boolean upper_case; /* For \FWEAVE\ identifiers. */
 
1492
                MOD_INFO HUGE *mod; /* For \FWEAVE\ module names */
 
1493
                } info;
 
1494
        eight_bits Ilk[NUM_LANGUAGES];/* Used by ident.'s in \WEAVE\ only. */
 
1495
        ASCII HUGE *equiv_or_xref; /* Info corresponding to names. */
 
1496
        WV_MACRO HUGE *wv_macro; /* For fancy identifiers. */
 
1497
        } NAME_INFO; /* Contains information about an identifier or mod
 
1498
name. */
 
1499
 
 
1500
typedef NAME_INFO HUGE *name_pointer; /* pointer into array of |name_info|s. */
 
1501
 
 
1502
@
 
1503
@<Mac...@>=
 
1504
@@
 
1505
@@f HUGE_FCN_PTR huge
 
1506
@@<Initialize |mod_info| and |Language|@@>=
 
1507
{
 
1508
/* We allocate |MOD_INFO| structures only for module names, not for
 
1509
        identifiers. */
 
1510
node->mod_info = GET_MEM("mod_info",1,MOD_INFO);
 
1511
 
 
1512
node->mod_info->Ilk = expr;
 
1513
node->mod_info->params = params; /* Freeze parameters at this point in time. */
 
1514
node->mod_info->params.uses = 0; /* Uses are counted in |new_mod_xref|. */
 
1515
 
 
1516
node->Language = (boolean)language; /* Redundant. */
 
1517
}
 
1518
 
 
1519
@
 
1520
@<Globals@>=
 
1521
 
 
1522
IN_COMMON BUF_SIZE max_bytes;
 
1523
IN_COMMON ASCII HUGE *byte_mem; /* Dynamic array: characters of names. */
 
1524
IN_COMMON ASCII HUGE *byte_end; /* End of |byte_mem|. */
 
1525
 
 
1526
IN_COMMON BUF_SIZE max_names;
 
1527
IN_COMMON NAME_INFO HUGE *name_dir; /* Dynamic array: information about
 
1528
names. */
 
1529
IN_COMMON name_pointer name_end; /* End of |name_dir|. */
 
1530
IN_COMMON name_pointer npmax; /* |name_ptr - 1|. */
 
1531
 
 
1532
IN_COMMON BUF_SIZE longest_name;
 
1533
IN_COMMON ASCII HUGE *mod_text; /* Dynamic array: name being sought for. */
 
1534
IN_COMMON ASCII HUGE *mod_end; /* End of |mod_text|. */
 
1535
 
 
1536
 
 
1537
 
1538
 
 
1539
@d USED_BY_NEITHER ((eight_bits)0xFF)
 
1540
@d USED_BY_OTHER ignore
 
1541
 
 
1542
@<Mac...@>=
 
1543
@@ For initializing |ccodes|.
 
1544
 
 
1545
@@m INI_CCODE(defaults,code)
 
1546
        ini_ccode((outer_char *)#code,(outer_char *)defaults,code)
 
1547
                /* We use the same keyword name as the \FWEB\ code. */
 
1548
 
 
1549
@@m REASSIGNABLE(d,c) INI_CCODE(d,c) /* For stuff that must later be
 
1550
reassigned for  \FTANGLE. */
 
1551
 
 
1552
@@m SAME_CCODE(d,c) INI_CCODE(d,c)
 
1553
 
 
1554
 
1555
 
 
1556
@<Mac...@>=
 
1557
@@ Macros to guard against overflow during |sprintf| or |vprintf|. The function
 
1558
|nsprintf| is defined in \.{common.web} to handle non-ANSI return values from
 
1559
|sprintf|. 
 
1560
 
 
1561
@@m NSPRINTF(buf_name,fmt,...) 
 
1562
        nsprintf(buf_name,OC(fmt),#0,#.)
 
1563
@@m NVSPRINTF(buf_name,fmt,...) 
 
1564
        nvsprintf(buf_name,OC(fmt),#0,#.)
 
1565
 
 
1566
@@m SPRINTF(nmax,buf_name,args) 
 
1567
        if(NSPRINTF(buf_name,args) >= (int)(nmax)) OVERFLW(#buf_name,"")@@;
 
1568
 
 
1569
@@m VSPRINTF(nmax,buf_name,args) 
 
1570
        if(NVSPRINTF(buf_name,args) >= (int)(nmax)) OVERFLW(#buf_name,"")@@;
 
1571
 
 
1572
@@m vsprintf_(out,fmt,arg_ptr) 
 
1573
        @!$P if(NUM_VA_ARGS == 1)
 
1574
                {
 
1575
                char *fmt0 = va_arg(arg_ptr,char *);
 
1576
 
 
1577
                va_arg(arg_ptr,int); /* Skip over~$n$. */
 
1578
                vsprintf((char *)out,fmt0,arg_ptr);
 
1579
                }
 
1580
        @!$P else
 
1581
                vsprintf(out,fmt,arg_ptr);
 
1582
        @!$P endif
 
1583
 
 
1584
@@m vprintf_(fmt,arg_ptr) 
 
1585
        @!$P if(NUM_VA_ARGS == 1)
 
1586
                {
 
1587
                char *fmt0 = va_arg(arg_ptr,char *);
 
1588
 
 
1589
                va_arg(arg_ptr,int);
 
1590
                vprintf(out,fmt0,arg_ptr);
 
1591
                }
 
1592
        @!$P else
 
1593
                vprintf(fmt,arg_ptr);
 
1594
        @!$P endif
 
1595
 
 
1596
@@f VA_ARGS $_EXPR
 
1597
@@f VA_DECL int
 
1598
@@f VA_LIST int
 
1599
 
 
1600
 
1601
 
 
1602
@<Mac...@>=
 
1603
@@ Abbreviations for buffer allocations.
 
1604
 
 
1605
@@m ABBREV(name) V_##name
 
1606
 
 
1607
@@m V_buf_size "bs"
 
1608
@@m V_C_buf_size "cb"
 
1609
@@m V_cmd_fsize "cf"
 
1610
@@m V_cmd_size "cg"
 
1611
@@m V_delta_dots "d"
 
1612
@@m V_line_length "ll"
 
1613
@@m V_longest_name "ln"
 
1614
@@m V_max_bytes "b"
 
1615
@@m V_dtexts_max "dx"
 
1616
@@m V_max_dtoks "dt"
 
1617
@@m V_max_expr_chars "lx"
 
1618
@@m V_max_lbls "lb"
 
1619
@@m V_max_margs "ma"
 
1620
@@m V_max_ifiles "if"
 
1621
@@m V_max_include_depth "id"
 
1622
@@m V_max_keywords "rk" 
 
1623
@@m V_max_modules "m"
 
1624
@@m V_max_names "n"
 
1625
@@m V_max_refs "r"
 
1626
@@m V_max_scraps "s"
 
1627
@@m V_max_texts "x"
 
1628
@@m V_max_toks_t "tt"
 
1629
@@m V_max_toks_w "tw"
 
1630
@@m V_mbuf_size "mb"
 
1631
@@m V_op_entries "op"
 
1632
@@m V_num_files "nf"
 
1633
@@m V_sbuf_len "sb"
 
1634
@@m V_stck_size_t "kt"
 
1635
@@m V_stck_size_w "kw"
 
1636
@@m V_X_buf_size "xb"
 
1637
 
 
1638
@ Operator overloading.
 
1639
@a
 
1640
 
 
1641
/* Information for each language. */
 
1642
typedef struct
 
1643
        {
 
1644
        CONST outer_char *op_macro; /* The default \FWEB\ macro. */
 
1645
        boolean overloaded; /* Has it been overloaded? */
 
1646
        eight_bits cat; /* Category code for this operator. */
 
1647
        outer_char HUGE *defn; /* Replacement text for the \Fortran\ macro. */
 
1648
        } OP_INFO;
 
1649
 
 
1650
/* The description of an operator. */
 
1651
typedef struct
 
1652
        {
 
1653
        ASCII HUGE *op_name; /* \Fortran-like name of operator. Not |const|
 
1654
because it's converted to |ASCII|. */
 
1655
        OP_INFO info[NUM_LANGUAGES];
 
1656
        } OPERATOR;
 
1657
 
 
1658
@ Colors.
 
1659
 
 
1660
@D ESC 0x1b
 
1661
@D MD "[1m" /* High intensity */
 
1662
@D US "[4m" /* Underline */
 
1663
@D MR "[7m" /* Reverse video */
 
1664
@D MO "[m"  /* Revert to normal */
 
1665
 
 
1666
/* In the following, the |ordinary| setting is necessary to kill off
 
1667
underlining.  Should do this for |sset_color| as well. */
 
1668
@d SET_COLOR(field) 
 
1669
        set_color(wt_style.color.ordinary.value),
 
1670
        set_color(wt_style.color.field.value)
 
1671
 
 
1672
@d SSET_COLOR(field) sset_color(wt_style.color.field.value)
 
1673
 
 
1674
@d CLR_PRINTF(when, field, args) 
 
1675
        {
 
1676
        if(msg_level >= when)
 
1677
                {
 
1678
                SET_COLOR(field); 
 
1679
                printf args; fflush(stdout);
 
1680
                set_color(color0.last);
 
1681
                }
 
1682
        }
 
1683
 
 
1684
@a
 
1685
 
 
1686
typedef enum
 
1687
        {
 
1688
        NULL_COLOR,
 
1689
        BLACK,RED,GREEN,YELLOW,BLUE,MAGENTA,CYAN,WHITE,NORMAL,HIGHEST_COLOR
 
1690
        } COLOR;
 
1691
 
 
1692
IN_STYLE CONST char *clr_name[]
 
1693
#ifdef _STYLE_h
 
1694
        = {"NULL",
 
1695
           "black","red","green","yellow","blue","magenta","cyan", "white",
 
1696
            "default"}
 
1697
#endif
 
1698
;
 
1699
 
 
1700
typedef struct
 
1701
        {
 
1702
        COLOR last,present;
 
1703
        } COLOR0;
 
1704
 
 
1705
IN_COMMON COLOR0 color0
 
1706
#ifdef _COMMON_h
 
1707
#if(part == 0 || part == 1)
 
1708
        = {NORMAL,NORMAL}
 
1709
#endif
 
1710
#endif
 
1711
;
 
1712
 
 
1713
typedef struct
 
1714
        {
 
1715
        short n;        /* Number of escape sequences attached to this color. */
 
1716
        outer_char **string;    /* Array of pointers to those sequences. */
 
1717
        } SEQUENCES;
 
1718
 
 
1719
/* A buffer for an array of strings. */
 
1720
typedef struct
 
1721
{
 
1722
int num;
 
1723
int n;
 
1724
outer_char **s;
 
1725
} BUF;
 
1726
 
 
1727
BUF buf;
 
1728
 
 
1729
IN_STYLE outer_char HUGE *termcap; /* Name of termcap file. */
 
1730
IN_STYLE BUF sput_buf; /* For temporary color strings. */
 
1731
IN_COMMON BUF c_buf; /* For commas. */
 
1732
 
 
1733
@* \TeX\ MODE.
 
1734
 
 
1735
@a
 
1736
 
 
1737
typedef enum
 
1738
        {
 
1739
        TeX_escape,TeX_bgroup,TeX_egroup,TeX_math_shift,TeX_alignment_tab,
 
1740
        TeX_eol,TeX_parameter,TeX_superscript,TeX_subscript,TeX_ignored,
 
1741
        TeX_space,TeX_letter,TeX_other,TeX_active,TeX_comment,TeX_invalid
 
1742
        } TeX_CATEGORY; 
 
1743
 
 
1744
IN_COMMON TeX_CATEGORY TeX[128];
 
1745
 
 
1746
@ Because we must compare tokens to see if they're the special ones, and we
 
1747
don't know where they are in the table, we'll initialize individual
 
1748
variables with the appropriate values returned from |id_lookup|.
 
1749
 
 
1750
@f X_FCN void
 
1751
 
 
1752
@a
 
1753
 
 
1754
EXTERN sixteen_bits id_defined;
 
1755
 
 
1756
typedef struct
 
1757
        {
 
1758
        CONST char HUGE *name; /* Identifier. */
 
1759
        int len;        /* Length of identifier. */
 
1760
        X_FCN (HUGE_FCN_PTR *expand)(VOID); /* Function that expands this
 
1761
token. */ 
 
1762
        sixteen_bits HUGE *pid; /* Address of the |sixteen_bits| that is to be
 
1763
initialized. */
 
1764
        } SPEC;
 
1765
 
 
1766
@ Here we define the text that may be inserted automatically after a
 
1767
\Ratfor\ program unit.
 
1768
 
 
1769
@a
 
1770
 
 
1771
typedef struct
 
1772
        {
 
1773
        eight_bits *start; /* Macro to be inserted. */
 
1774
        eight_bits *end; /* End of |start|. */
 
1775
        } INSERT_TEXT;
 
1776
 
 
1777
typedef struct
 
1778
        {
 
1779
        INSERT_TEXT program,module,subroutine,function,blockdata,interface;
 
1780
        } INSERT_MATERIAL;
 
1781
 
 
1782
@
 
1783
@a
 
1784
 
 
1785
boolean Rat_OK PROTO((outer_char *msg));
 
1786
IN_COMMON boolean Rat_is_loaded; /* Set by call to |is_Rat_present|. */
 
1787
IN_COMMON boolean xpn_Ratfor CSET(YES);
 
1788
 
 
1789
IN_TANGLE int spcs_after_cmnt TSET(0);/* Turned on for Ratfor error
 
1790
messages. */
 
1791
IN_TANGLE int brace_level TSET(0);
 
1792
IN_TANGLE boolean checking_label TSET(NO);
 
1793
IN_TANGLE INSERT_MATERIAL insert; /* For automatic insertions. */
 
1794
 
 
1795
@ The following structure is used to remember where loops etc.\ began.
 
1796
 
 
1797
When we encounter the beginning of a program, module, subroutine, or
 
1798
function, we store the identifier token of the program unit's name in
 
1799
|cur_fcn|. This can be used by the built-in |$ROUTINE|, or in various error
 
1800
messages.
 
1801
 
 
1802
@D cur_fcn begun[rlevel-1].name
 
1803
@D NO_FCN (sixteen_bits)0
 
1804
        /* Value of |cur_fcn| when function name is unknown. */
 
1805
 
 
1806
@D cur_struct begun[rlevel-1].name
 
1807
@D is_function begun[rlevel-1].function
 
1808
@D symbolic_label begun[rlevel-1].symbolic
 
1809
 
 
1810
@<Typedefs@>=
 
1811
 
 
1812
typedef enum
 
1813
        {
 
1814
        _DO_CMD,
 
1815
        block_CMD,blockdata_CMD,
 
1816
        break_CMD,case_CMD,contains_CMD,
 
1817
        default_CMD,do_CMD,for_CMD,function_CMD,
 
1818
        if_CMD,interface_CMD,module_CMD,next_CMD,program_CMD,
 
1819
        repeat_CMD,return_CMD,type_CMD,subroutine_CMD,switch_CMD,until_CMD,
 
1820
        where_CMD,while_CMD
 
1821
        } CMD;
 
1822
 
 
1823
typedef struct
 
1824
        {
 
1825
        CMD cmd; /* Type of keyword being expanded. */
 
1826
        sixteen_bits name; /* Identifier for this program unit. */
 
1827
        sixteen_bits symbolic; /* Symbolic loop label. */
 
1828
        boolean function; /* Is this a function? */
 
1829
        LINE_NUMBER line; /* Line number at which expansion started. */
 
1830
        int level; /* Expansion level. */
 
1831
        } BEGUN;
 
1832
 
 
1833
IN_TANGLE BEGUN HUGE *begun; /* Dynamic array. */
 
1834
IN_TANGLE int rlevel TSET(0); /* Current level of \Ratfor\ expansion.  This is
 
1835
                incremented for each expandable \Ratfor\ keyword. */
 
1836
 
 
1837
@ The routine |prsw_regular_code| has various nifty branches that the
 
1838
outside world needs to access.
 
1839
@<Typedef...@>=
 
1840
 
 
1841
@#ifdef MVS
 
1842
/* The C370 compiler will do strange integer promotions, if we
 
1843
    don't force it to do better.  (Thorsten Ohl.) */
 
1844
typedef enum 
 
1845
        {MORE_PARSE=-1,GOTO_MISTAKE=-2,GOTO_GET_IDENTIFIER=-3,
 
1846
         GOTO_GET_A_STRING=-4,GOTO_SKIP_A_COMMENT=-5,GOTO_MVS_KLUDGE=32000}
 
1847
                 @[GOTO_CODE;
 
1848
@#else /* Not |MVS|. */
 
1849
typedef enum 
 
1850
        {MORE_PARSE=-1,GOTO_MISTAKE=-2,GOTO_GET_IDENTIFIER=-3,
 
1851
         GOTO_GET_A_STRING=-4,GOTO_SKIP_A_COMMENT=-5} @[GOTO_CODE;
 
1852
@#endif /* Not |MVS|. */
 
1853
  
 
1854
 
 
1855
@ Here we identify which part of the code we're dealing with.
 
1856
 
 
1857
@d mark_defined w_style.misc.mark
 
1858
 
 
1859
@<Typedef...@>=
 
1860
 
 
1861
typedef enum {LIMBO,TEX_,DEFINITION,CODE} PART;
 
1862
 
 
1863
IN_COMMON PART the_part CSET(LIMBO);
 
1864
 
 
1865
typedef struct
 
1866
        {
 
1867
        int generic_name,fcn_name,WEB_macro,outer_macro,imp_reserved_name,
 
1868
                typedef_name;
 
1869
        } MARK_DEFINED;
 
1870
 
 
1871
@ What macros to use to format identifiers.
 
1872
 
 
1873
@<Typedef...@>=
 
1874
 
 
1875
typedef struct
 
1876
        {
 
1877
        outer_char *reserved, *RESERVED;
 
1878
        outer_char *short_id;
 
1879
        outer_char *id, *ID;
 
1880
        outer_char *id_outer, *ID_OUTER;
 
1881
        outer_char *id_inner, *ID_INNER;
 
1882
        outer_char *intrinsic;
 
1883
        outer_char *keyword, *KEYWORD;
 
1884
        outer_char *typewritr;
 
1885
        outer_char *wildcrd;
 
1886
        } FORMAT;
 
1887
 
 
1888
@ Options for \LaTeX.
 
1889
 
 
1890
@<Typedef...@>=
 
1891
 
 
1892
typedef struct
 
1893
{
 
1894
outer_char *options;
 
1895
outer_char *file;
 
1896
} OPTIONS_FILE;
 
1897
 
 
1898
typedef struct
 
1899
        {
 
1900
        OPTIONS_FILE class, package;
 
1901
        } LATEX;
 
1902
 
 
1903
@ Stuff for the style file.
 
1904
@<Typedef...@>=
 
1905
 
 
1906
typedef char CC_BUF[2][40]; /*  One line of output for the control codes. */
 
1907
 
 
1908
@
 
1909
@<Glob...@>=
 
1910
 
 
1911
IN_STYLE outer_char HUGE *sbuf, HUGE *sbuf_end;/* One line of style file. */
 
1912
IN_STYLE CONST outer_char HUGE *sloc; /* Position in |sbuffer|. */
 
1913
IN_STYLE outer_char HUGE *slimit; /* Next available position in buffer. */
 
1914
IN_STYLE LINE_NUMBER s_line SSET(0); /* Input line number. */
 
1915
 
 
1916
@ Additional macros for compatibility between |char| and |outer_char|.
 
1917
@d OC(s) ((outer_char HUGE *)(s))
 
1918
 
 
1919
@d STAT0(name,size,num,max_num,abs_max_num,abbrev,ctrl_chars)
 
1920
        stat0(OC(name),size,num,max_num,abs_max_num,
 
1921
                OC(abbrev),OC(ctrl_chars))
 
1922
 
 
1923
@d OVERFLW(msg,abbrev) overflow(OC(msg),OC(abbrev))
 
1924
@d NEW_SPRM(name, value) new_sprm(OC(name), value)
 
1925
@d SPRM_LEN 1500
 
1926
 
 
1927
@d RAT_OK(msg) Rat_OK(OC(msg))
 
1928
 
 
1929
@
 
1930
 
 
1931
@d APP_STR(s) app_str(OC(s))
 
1932
 
 
1933
@<Mac...@>=
 
1934
@@
 
1935
@@f X_FCN void
 
1936
@@m RAT_ERROR(err_type, msg, n, ...) 
 
1937
        RAT_error(err_type, OC(msg), n, #.)
 
1938
@@m CONFUSION(where, fmt0, ...)
 
1939
        confusion(OC(where), OC(fmt0), #.)
 
1940
@@m FATAL(origin, msg1, fmt, ...) 
 
1941
        fatal(ERR_##origin, OC(msg1), OC(fmt), #.)
 
1942
 
 
1943
@* DEFINITIONS for TANGLE and WEAVE. Here's stuff required for
 
1944
\.{tangle.web} and \.{weave.web}. 
 
1945
 
 
1946
@ As much as possible, we adhere to ANSI conventions. However, to support
 
1947
pre-ANSI compilers such as \.{gcc}, we must make some modifications. It is
 
1948
assumed that the compilers predefine macros such as |vax|, |sun|, or |mac|,
 
1949
in \It{lower case}; if they do not, then these macros must be defined from
 
1950
the command line. In addition, the \WEB\ files must be tangled with
 
1951
\It{upper case} macros such as |VAX|, |SUN|, or |MAC| defined from the
 
1952
command line, as in \.{ftangle tangle -m"SUN"}. It is conventional to put
 
1953
the machine macro command into the ini file \.{.fweb}, as in ``\.{+mSUN}''.
 
1954
 
 
1955
@ The following flag is used for \Cpp. (??)
 
1956
@%@<Common...@>=
 
1957
@a
 
1958
EXTERN boolean long_comment;
 
1959
 
 
1960
@ Code related to the character set. \It{Mess around here only at your own
 
1961
risk.} 
 
1962
 
 
1963
@D and_and OCTAL(4) /* `|&&|'.*/
 
1964
@D star_star OCTAL(5) /* `|@@r x**y|' .*/
 
1965
 
 
1966
/* The next two only occur in different languages, so they can have the same
 
1967
value. */  
 
1968
@D neqv OCTAL(10) /* `|@@r .neqv.|'.*/
 
1969
@D ellipsis neqv /* `|...|'.*/
 
1970
 
 
1971
@D stmt_label OCTAL(30)
 
1972
 
 
1973
@D slash_slash OCTAL(26)  /* Concatenation `|@@r \/|' .*/
 
1974
 
 
1975
@D bell OCTAL(7) /* |ASCII| code for ringing the bell.*/
 
1976
@D tab_mark @'\t' /* |ASCII| code used as tab-skip.*/
 
1977
@D line_feed OCTAL(12) /* |ASCII| code thrown away at end of line; $\equiv$
 
1978
                        \.{'\\n'}. */
 
1979
@D form_feed OCTAL(14) /* |ASCII| code used at end of page.*/
 
1980
@D carriage_return OCTAL(15) /* |ASCII| code used at end of line.*/
 
1981
 
 
1982
@D gt_gt OCTAL(20) /* `|>>|'; this doesn't exist in MIT.*/
 
1983
@D lt_lt OCTAL(22) /* `|<<|'; this doesn't exist in MIT.*/
 
1984
 
 
1985
@D plus_plus OCTAL(13) /* `|++|'; this corresponds to MIT's up-arrow.*/
 
1986
@D minus_minus OCTAL(1) /* `|--|'; this corresponds to MIT's down-arrow.*/
 
1987
 
 
1988
@D minus_gt OCTAL(31) /* `|->|'.*/
 
1989
@D eqv minus_gt /* `|@@r .eqv.|'.*/
 
1990
 
 
1991
@D not_eq OCTAL(32) /* `|!=|'.*/
 
1992
 
 
1993
@D paste OCTAL(33) /* `|##|'.*/
 
1994
 
 
1995
@D lt_eq OCTAL(34) /* `|<=|'.*/
 
1996
@D gt_eq OCTAL(35) /* `|>=|'.*/
 
1997
 
 
1998
@D eq_eq OCTAL(36) /* `|==|'.*/
 
1999
 
 
2000
@D or_or OCTAL(37) /* `||| |'.*/
 
2001
 
 
2002
@D begin_language OCTAL(16) /* Mark a language switch.*/
 
2003
 
 
2004
@D left_array OCTAL(21)  /* `$\LS$'.*/
 
2005
@D right_array OCTAL(25) /* `$\SR$'.*/
 
2006
 
 
2007
@D interior_semi OCTAL(24) /* `\.;'.  In \Fortran, a semicolon that's already
 
2008
        present in the input line, as opposed to one that's inserted by
 
2009
        \FWEB. */
 
2010
 
 
2011
@
 
2012
@a
 
2013
 
 
2014
IN_COMMON ASCII xord[]; /* specifies conversion of input characters. */
 
2015
#ifdef scramble_ASCII
 
2016
        IN_COMMON ASCII xxord[];
 
2017
#endif
 
2018
IN_COMMON outer_char xchr[]; /* specifies conversion of output characters. */
 
2019
 
 
2020
@ Code related to input routines:
 
2021
 
 
2022
@a
 
2023
 
 
2024
IN_COMMON BUF_SIZE buf_size; /* Used for \FWEAVE; see \.{common.web}. */
 
2025
IN_COMMON ASCII HUGE *loc; /* points to the next character to be read from the
 
2026
                                buffer*/ 
 
2027
 
 
2028
typedef struct
 
2029
        {
 
2030
        unsigned size; /* Length of |list|. */
 
2031
        unsigned num; /* Number of entries (e.g., number of colons). */
 
2032
        outer_char HUGE *list; /* Colon-delimited List of include files. */
 
2033
        } INCL_PATHS;
 
2034
 
 
2035
@ Code related to identifier and module name storage:
 
2036
 
 
2037
@d ID_FLAG 10240 /* \bf DON'T MONKEY WITH THIS NUMBER!. */
 
2038
 
 
2039
@d length(c) ((c+1)->byte_start-(c)->byte_start) /* the length of a name. */
 
2040
 
 
2041
@d llink link /* left link in binary search tree for module names. */
 
2042
@d root CAST(name_pointer,name_dir)->rlink /* the root of the binary search
 
2043
                                                tree  for module names */
 
2044
 
 
2045
@d is_intrinsic(n) (n->intrinsic_word & (boolean)language)
 
2046
@d is_keyword(n) (n->keyword & (boolean)language)
 
2047
 
 
2048
@a
 
2049
 
 
2050
IN_COMMON name_pointer name_ptr; /* first unused position in |byte_start|. */
 
2051
IN_COMMON ASCII HUGE *byte_ptr; /* first unused position in |byte_mem|. */
 
2052
 
 
2053
typedef name_pointer HUGE *hash_pointer;
 
2054
IN_COMMON hash_pointer hash, /* heads of hash lists */
 
2055
        hash_end, /* end of |hash| */
 
2056
        h; /* index into hash-head array */
 
2057
 
 
2058
 
 
2059
@ To distinguish between the constructions \.{@@<\dots@@>} and
 
2060
\.{\#<\dots@@>}, both of which return |module_name|, we introduce the flag
 
2061
|mac_mod_name|. 
 
2062
 
 
2063
@a
 
2064
 
 
2065
EXTERN boolean mac_mod_name;
 
2066
 
 
2067
@ Module-name level:
 
2068
 
 
2069
@a
 
2070
 
 
2071
IN_COMMON int mod_level CSET(0);
 
2072
 
 
2073
@ Code related to module numbers:
 
2074
 
 
2075
@d BTRANS mod_trans(OC("beginning in section"),module_count) /* English! */
 
2076
@d MTRANS mod_trans(OC("section"),module_count) /* String including section and
 
2077
                                                page info.  English! */ 
 
2078
@d MTRANS0 mod_trans(OC(""),module_count)
 
2079
@d MOD_TRANS(mnum) mod_trans(OC("section"), mnum) /* English! */
 
2080
 
 
2081
@a
 
2082
 
 
2083
IN_COMMON sixteen_bits module_count; /* The current module number. */
 
2084
IN_COMMON boolean HUGE *chngd_module; /* Dynamic array: Is the module/
 
2085
                                        changed? */
 
2086
IN_COMMON boolean prn_where; /* Tells \.{TANGLE} to print line and file
 
2087
                                        info. */
 
2088
 
 
2089
@ Code relating to output:
 
2090
 
 
2091
@d UPDATE_TERMINAL fflush(stdout) /* Empty the terminal output buffer. */
 
2092
@d new_line putchar('\n') @d putxchar putchar
 
2093
@d ASCII_write(p0,n) fflush(stdout),
 
2094
                ASCII_file_write(stdout,p0,(int)(n))@;
 
2095
        /* Write on the standard output, converting from |ASCII|. */ 
 
2096
 
 
2097
@ For FORTRAN, \&{format} commands are annoying, because the use of slashes
 
2098
doesn't fit with the rest of the \Fortran\ syntax. Thus, we'll deal with the
 
2099
|format| statement something like a preprocessor statement, in that we'll
 
2100
raise a special flag when we're inside it, and issue special tokens to
 
2101
indicate the start and the end of the statement.
 
2102
 
 
2103
@D begin_format_stmt OCTAL(171)
 
2104
@D end_format_stmt OCTAL(172)
 
2105
 
 
2106
 
2107
 
 
2108
@d is_identifier(c) (isAlpha(c) || c==@'_' || c==@'$' ||
 
2109
        (c==@'%' && !C_LIKE(language) && !Fortran88) ) 
 
2110
                /* This defines the starting character of an identifier. */ 
 
2111
 
 
2112
@d is_kind(c) (isDigit(c) || isAlpha(c) || c==@'_' || c==@'$') 
 
2113
        /* \Fortran-90 kind parameter. */
 
2114
 
 
2115
@<Mac...@>=
 
2116
@@ For~C, getting an identifier is simple. For FORTRAN, we treat \&{format}
 
2117
statements much like C's preprocessor statement. However, there's no
 
2118
special character to start a \&{format} line; we have to actually check the
 
2119
identifier. Furthermore, it looks nicer if constructions such as \\{f6.2}
 
2120
are treated as one identifier, so when we're inside a \&{format} statement
 
2121
we allow the period to be an acceptable (internal) character for an
 
2122
identifier.
 
2123
 
 
2124
@@<Get an identifier@@>= 
 
2125
{
 
2126
IN_COMMON ASCII HUGE *pformat, HUGE *pdata;
 
2127
 
 
2128
get_identifier:
 
2129
        @@<Make |id_first| and |id_loc| point to the identifier@@>@@;
 
2130
 
 
2131
if(FORTRAN_LIKE(language))
 
2132
        {
 
2133
        if(web_strcmp(pformat,pformat+6,id_first,id_loc) == EQUAL)
 
2134
                { /* Raise special flag to say we're inside a |@@r format|
 
2135
statement. */ 
 
2136
                in_format = YES;
 
2137
                return begin_format_stmt; 
 
2138
                }
 
2139
        else if(program==weave)
 
2140
                {
 
2141
                if(web_strcmp(pdata,pdata+4,id_first,id_loc) == EQUAL)
 
2142
                        { /* Inside a |@@r data| statement. */
 
2143
                        in_data = YES;
 
2144
                        return identifier;
 
2145
                        }
 
2146
                else if(at_beginning && *loc==@':' &&
 
2147
                                !is_in(non_labels,id_first,id_loc))
 
2148
                        return stmt_label;  
 
2149
                }
 
2150
        }
 
2151
 
 
2152
if(is_include_like()) 
 
2153
        sharp_include_line = YES;
 
2154
 
 
2155
return identifier;
 
2156
}
 
2157
 
 
2158
@
 
2159
@<Mac...@>=
 
2160
@@ 
 
2161
@@<Make |id_first|...@@>=
 
2162
{
 
2163
id_first = --loc;
 
2164
 
 
2165
/* Scan over subsequent elements of an identifier. */
 
2166
for(++loc; isAlpha(*loc) || isDigit(*loc)
 
2167
        || *loc==@@'_' || *loc==@@'$' || (in_format && *loc==@@'.'); loc++)
 
2168
                ;
 
2169
 
 
2170
upcoming_kind = BOOLEAN(Fortran88 && (*loc == @'"' || *loc == @'\'')
 
2171
                && loc[-1] == @'_');
 
2172
 
 
2173
id_loc = loc - upcoming_kind;  /* End plus one of the identifier.  If a
 
2174
        kind subscript is coming up, don't include the underscore. */
 
2175
}
 
2176
 
 
2177
 
2178
@<Mac...@>=
 
2179
@@ Here we obtain the file name after an \.{@@@@o}~command.
 
2180
@@<Scan the output file name@@>=
 
2181
{
 
2182
while(*loc == @' ' || *loc == tab_mark)
 
2183
        {
 
2184
        loc++;
 
2185
        if(loc > limit) return ignore;
 
2186
        }
 
2187
 
 
2188
id_first = loc;
 
2189
while(*loc != @' ' && *loc != tab_mark) loc++; /* Absorb file name. */
 
2190
id_loc = loc;
 
2191
if(*id_first == @'"') id_first++;
 
2192
if(*(id_loc-1) == @'"') id_loc--;
 
2193
if(id_loc - id_first >= MAX_FILE_NAME_LENGTH)
 
2194
        {
 
2195
        err_print(T,"Output file name too long; allowed only %d characters",
 
2196
                MAX_FILE_NAME_LENGTH - 1);
 
2197
        id_loc = id_first + MAX_FILE_NAME_LENGTH - 1;
 
2198
        }
 
2199
}
 
2200
 
 
2201
@ These tables are initialized during |common_init|.
 
2202
 
 
2203
@a
 
2204
 
 
2205
#undef expr
 
2206
#define expr 1
 
2207
 
 
2208
#undef unop
 
2209
#define unop 2
 
2210
 
 
2211
#undef binop
 
2212
#define binop 3
 
2213
 
 
2214
extern DOTS HUGE *dots; /* The dynamic table; see \.{common.web}. */
 
2215
 
 
2216
#ifdef _FWEB_h
 
2217
 
 
2218
        EXTERN DOTS dots0[]
 
2219
   #if(part == 0 || part == 1)
 
2220
            = {
 
2221
                {(ASCII *)"@@@@@@",3,dot_const,expr,0}, /* Dummy */
 
2222
                {(ASCII *)"AND",3,dot_const,binop,and_and}, /* |and_and| */
 
2223
                {(ASCII *)"EQ",2,dot_const,binop,eq_eq}, /* |eq_eq| */
 
2224
                {(ASCII *)"EQV",3,dot_const,binop,eqv}, /* |eqv| */
 
2225
                {(ASCII *)"FALSE",5,dot_const,expr,0},
 
2226
                {(ASCII *)"GE",2,dot_const,binop,gt_eq}, /* |gt_eq| */
 
2227
                {(ASCII *)"GT",2,dot_const,binop,@'>'}, /* |@'>'| */
 
2228
                {(ASCII *)"LE",2,dot_const,binop,lt_eq}, /* |lt_eq| */
 
2229
                {(ASCII *)"LT",2,dot_const,binop,@'<'}, /* |@'<'| */
 
2230
                {(ASCII *)"NE",2,dot_const,binop,not_eq}, /* |not_eq| */
 
2231
                {(ASCII *)"NEQV",4,dot_const,binop,neqv}, /* |neqv| */
 
2232
                {(ASCII *)"NOT",3,dot_const,unop,@'!'}, /* |@'!'| */
 
2233
                {(ASCII *)"OR",2,dot_const,binop,or_or}, /* |or_or| */
 
2234
                {(ASCII *)"TRUE",4,dot_const,expr,1},
 
2235
                {(ASCII *)"XOR",3,dot_const,binop,neqv}, /* |neqv| */
 
2236
                {(ASCII *)"",0,0,0,0}
 
2237
                }
 
2238
        #endif /* |part == 1| */
 
2239
                ;
 
2240
#endif /* |_FWEB_h| */
 
2241
 
 
2242
@ The preprocessor commands have a similar format.
 
2243
@a
 
2244
 
 
2245
#ifdef _FWEB_h
 
2246
 
 
2247
        EXTERN DOTS mcmds[] 
 
2248
   #if(part ==0 || part == 1)
 
2249
         = {
 
2250
                {(ASCII *)"define",6,WEB_definition},
 
2251
                {(ASCII *)"elif",4,m_elif},
 
2252
                {(ASCII *)"elseif",6,m_elif},
 
2253
                {(ASCII *)"else",4,m_else},
 
2254
                {(ASCII *)"endfor",6,m_endfor},
 
2255
                {(ASCII *)"endif",5,m_endif},
 
2256
                {(ASCII *)"for",3,m_for},
 
2257
                {(ASCII *)"if",2,m_if},
 
2258
                {(ASCII *)"ifdef",5,m_ifdef},
 
2259
                {(ASCII *)"ifndef",6,m_ifndef},
 
2260
                {(ASCII *)"line",4,m_line},
 
2261
                {(ASCII *)"undef",5,m_undef},
 
2262
                {(ASCII *)"",0,0}
 
2263
            }
 
2264
        #endif /* |part == 1| */
 
2265
                ;
 
2266
#endif /* |_FWEB_h| */
 
2267
 
 
2268
 
2269
@<Mac...@>=
 
2270
@@ The preprocessor commands are piggy-backed on the \.{@@@@\#} command. If
 
2271
there's text after that command, then we hunt through the above table.
 
2272
If we find a processor command, any subsequent white space is skipped.
 
2273
(This was added for nuweb mode, which otherwise takes each blank one at a
 
2274
time.)  Otherwise, it's a |big_line_break|.
 
2275
 
 
2276
@@<Process possible preprocessor command@@>=
 
2277
{
 
2278
boolean mcode;
 
2279
 
 
2280
*limit = @' '; /* Terminator for identifier search. */
 
2281
id_first = loc;
 
2282
 
 
2283
while(isAlpha(*loc)) 
 
2284
        loc++; /* Find end of identifier. */
 
2285
 
 
2286
if((mcode=is_mcmd(mcmds,id_first,loc)) != 0) 
 
2287
        {
 
2288
        while(loc < limit && (*loc == @@' ' || *loc == tab_mark))
 
2289
                loc++;
 
2290
 
 
2291
        #ifdef _FWEAVE_h
 
2292
                defd_switch = NO; /* Don't let \.{@@@@[} propagate. */
 
2293
        #endif
 
2294
 
 
2295
        return mcode;
 
2296
        }
 
2297
 
 
2298
loc = id_first; /* Failed to recognize preprocessor command. */
 
2299
}
 
2300
 
 
2301
@ Here are macros for use with memory allocation.
 
2302
 
 
2303
@d GET_MEM(why,nunits,type) 
 
2304
        (type HUGE *)get_mem0((outer_char *)why,(unsigned long)(nunits),
 
2305
                sizeof(type)) 
 
2306
 
 
2307
@d FREE_MEM(p,why,nunits,type) 
 
2308
        free_mem0((void HUGE *)p,(outer_char *)why,(unsigned long)(nunits),
 
2309
                sizeof(type))
 
2310
 
 
2311
@d ALLOC(type,ptr,abbrev,nunits,dn) 
 
2312
        ptr = (type HUGE *)alloc((outer_char *)abbrev,(BUF_SIZE HUGE *)&nunits,
 
2313
                sizeof(*ptr),dn)
 
2314
 
 
2315
 
 
2316
@a
 
2317
 
 
2318
IN_COMMON sixteen_bits HUGE *args; /* For macro processing. */
 
2319
IN_COMMON BUF_SIZE max_margs;
 
2320
 
 
2321
IN_COMMON boolean upcoming_kind CSET(NO); 
 
2322
        /* For use after dot constant or character kind. */
 
2323
 
 
2324
@ Miscellaneous definitions.
 
2325
 
 
2326
        @D MCHECK0(n,reason) mcheck0((unsigned long)(n),(outer_char *)reason)
 
2327
 
 
2328
        @d EVALUATE(val,p0,p1) 
 
2329
          {unsigned long nbytes;
 
2330
          val_ptr = val_heap = 
 
2331
          GET_MEM("val_heap",nbytes=2*((p1)-(p0)),VAL); 
 
2332
                evaluate(&val,p0,p1); 
 
2333
          if(val_heap) FREE_MEM(val_heap,"val_heap",nbytes,VAL);
 
2334
          }
 
2335
 
 
2336
        @d DONE_LEVEL (cur_byte >= cur_end) /* Do we need to pop? */
 
2337
 
 
2338
@<Mac...@>=
 
2339
@@
 
2340
@@<Glob...@@>=
 
2341
 
 
2342
/* The shorter length here is primarily to keep the stack under control.
 
2343
Now that |N_MSGBUF| is used  dynamically, maybe this statement isn't
 
2344
necessary. */ 
 
2345
#ifdef SMALL_MEMORY
 
2346
        #define N_MSGBUF 2000
 
2347
#else
 
2348
        #define N_MSGBUF 10000
 
2349
#endif 
 
2350
 
 
2351
 
 
2352
@ The following helps insert spaces in the output.
 
2353
@<Typedef...@>=
 
2354
 
 
2355
typedef enum
 
2356
        {
 
2357
        MISCELLANEOUS, /* ``normal'' state */
 
2358
        NUM_OR_ID, /* state associated with numbers and identifiers */
 
2359
        UNBREAKABLE, /* state associated with \.{@@\&} */
 
2360
        VERBATIM /* state in the middle of a string */
 
2361
        } OUTPUT_STATE;
 
2362
 
 
2363
@ For debugging and error messages, we need a routine that gives the name
 
2364
of a control code.
 
2365
 
 
2366
@A
 
2367
#ifdef _FWEB_h
 
2368
#if(part == 0 || part == 1)
 
2369
 
 
2370
@[outer_char *ccode_name FCN((code))
 
2371
        eight_bits code C1("")@;
 
2372
{
 
2373
switch(code)
 
2374
        {
 
2375
   case begin_FORTRAN: return (outer_char *)"begin_FORTRAN";
 
2376
   case begin_RATFOR: return (outer_char *)"begin_RATFOR";
 
2377
   case begin_C: return (outer_char *)"begin_C";
 
2378
   case ascii_constant: return (outer_char *)"ascii_constant";
 
2379
   case big_line_break: return (outer_char *)"big_line_break";
 
2380
   case begin_meta: return (outer_char *)"begin_meta";
 
2381
   case end_meta: return (outer_char *)"end_meta";
 
2382
   case TeX_string: return (outer_char *)"TeX_string";
 
2383
   case xref_roman: return (outer_char *)"xref_roman";
 
2384
   case xref_typewriter: return (outer_char *)"xref_typewriter";
 
2385
   case xref_wildcard: return (outer_char *)"xref_wildcard";
 
2386
   case formatt: return (outer_char *)"formatt";
 
2387
   case definition: return (outer_char *)"definition";
 
2388
   case WEB_definition: return (outer_char *)"WEB_definition";
 
2389
   case begin_code: return (outer_char *)"begin_code";
 
2390
   case module_name: return (outer_char *)"module_name";
 
2391
   case new_module: return (outer_char *)"new_module";
 
2392
   case m_ifdef: return (outer_char *)"m_ifdef";
 
2393
   case m_ifndef: return (outer_char *)"m_ifndef";
 
2394
   case m_if: return (outer_char *)"m_if";
 
2395
   case m_else: return (outer_char *)"m_else";
 
2396
   case m_elif: return (outer_char *)"m_elif";
 
2397
   case m_endif: return (outer_char *)"m_endif";
 
2398
   case m_undef: return (outer_char *)"m_undef";
 
2399
   case m_line: return (outer_char *)"m_line";
 
2400
 
 
2401
#ifdef _FTANGLE_h
 
2402
   case begin_vcmnt: return (outer_char *)"begin_vcmnt";
 
2403
   case begin_bp: return (outer_char *)"begin_bp";
 
2404
   case insert_bp: return (outer_char *)"insert_bp";
 
2405
   case control_text: return (outer_char *)"control_text";
 
2406
#endif /* |_FTANGLE_h| */
 
2407
 
 
2408
#ifdef _FWEAVE_h
 
2409
   case dont_expand: return (outer_char *)"dont_expand";
 
2410
   case auto_label: return (outer_char *)"auto_label";
 
2411
   case macro_module_name: return (outer_char *)"macro_module_name";
 
2412
   case switch_math_flag: return (outer_char *)"switch_math_flag";
 
2413
   case underline: return (outer_char *)"underline";
 
2414
   case thin_space: return (outer_char *)"thin_space";
 
2415
   case math_break: return (outer_char *)"math_break";
 
2416
   case line_break: return (outer_char *)"line_break";
 
2417
   case no_line_break: return (outer_char *)"no_line_break";
 
2418
   case pseudo_semi: return (outer_char *)"pseudo_semi";
 
2419
   case macro_space: return (outer_char *)"macro_space";
 
2420
   case copy_mode: return (outer_char *)"copy_mode";
 
2421
   case toggle_output: return (outer_char *)"toggle_output";
 
2422
   case pseudo_expr: return (outer_char *)"pseudo_expr";
 
2423
   case pseudo_colon: return (outer_char *)"pseudo_colon";
 
2424
   case trace: return (outer_char *)"trace";
 
2425
#endif /* |_FWEAVE_h| */
 
2426
   default: return OC("UNKNOWN");
 
2427
        }       
 
2428
}
 
2429
#endif /* |part == 1| */
 
2430
#endif /* |_FWEB_h| */
 
2431
 
 
2432
@ Wrapping it up.
 
2433
@a
 
2434
@<Glob...@>@;
 
2435
@<Typedef...@>@;
 
2436
 
 
2437
@
 
2438
@<Mac...@>=
 
2439
@@
 
2440
@@<Include...@@>=
 
2441
#include "typedefs.h"
 
2442
 
 
2443
@* INDEX.