home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / fweb153.zip / fweb-1.53 / web / fweave.web < prev    next >
Text File  |  1995-09-23  |  219KB  |  8,963 lines

  1. @z --- fweave.web ---
  2.  
  3. FWEB version 1.53 (September 23, 1995)
  4.  
  5. Based on version 0.5 of S. Levy's CWEB [copyright (C) 1987 Princeton University]
  6.  
  7. @x-----------------------------------------------------------------------------
  8.  
  9.  
  10. \Title{FWEAVE.WEB} % The FWEAVE processor.
  11.  
  12. @c
  13.  
  14. @* INTRODUCTION.  \WEAVE\ has a fairly straightforward outline.  It
  15. operates in three phases: first it inputs the source file and stores
  16. cross-reference data, then it inputs the source once again and produces the
  17. \TeX\ output file, and finally it sorts and outputs the index.  It can be
  18. compiled with the optional flag |DEBUG| (defined in \.{typedefs.web}).
  19.  
  20. Some compilers may not be able to handle a module this big. In that case,
  21. compile this twice, defining from the compiler's command line the macro
  22. |part| to have the value of either~1 or~2: e.g., `\.{-Dpart=1}'. See the make
  23. file for complete details.
  24.  
  25. For the text of the modules that aren't printed out here, such as
  26. \.{typedefs.web}, see \.{common.web}.
  27.  
  28. @m _FWEAVE_ // Identify the module for various \FWEB\ macros.
  29. @d _FWEAVE_h
  30. @d _FWEB_h
  31.  
  32. @A 
  33. @<Possibly split into parts@>@; // Defines |part|.
  34.  
  35. @<Include files@>@;
  36. @<Typedef declarations@>@;
  37. @<Prototypes@>@;
  38. @<Global variables@>@;
  39.  
  40. /* For pc's, the file is split into three compilable parts using the
  41. compiler-line macro |part|, which must equal either~1, 2, or~3. */
  42. #if(part == 0 || part == 1)
  43.     @<Part 1@>@;
  44. #endif // |Part == 1|
  45.  
  46. #if(part == 0 || part == 2)
  47.     @<Part 2@>@;
  48. #endif // |part == 2|
  49.  
  50. #if(part == 0 || part == 3)
  51.     @<Part 3@>@;
  52. #endif // |part == 3|
  53.  
  54. @ Here is the main program.  See the user's manual for a detailed
  55. description of the command line.
  56.  
  57. @<Part 1@>=@[
  58.  
  59. int main FCN((ac, av))
  60.     int ac C0("Number of command-line arguments.")@;
  61.     outer_char **av C1("Array of pointers to command-line arguments.")@;
  62. {
  63. /* --- Various initializations --- */
  64. #if TIMING
  65.     ini_timer(); /* Start timing the run. */
  66. #endif // |TIMING|
  67.  
  68. argc=ac; @~ argv=av; /* Remember the arguments as global variables. */
  69.  
  70. ini_program(weave);
  71.  
  72.   common_init();
  73.   @<Set initial values@>;
  74.  
  75. /* --- Do the processing --- */
  76.   phase1(); /* read all the user's text and store the cross-references */
  77.   phase2(); /* read all the text again and translate it to \TeX\ form */
  78.   phase3(); /* output the cross-reference index */
  79.  
  80. /* --- Finish up --- */
  81.   if(statistics) see_wstatistics(); // Invoked by command-line option~\.{-s}.
  82.  
  83. return wrap_up(); /* We actually |exit| from here. */
  84. }
  85.  
  86. @I typedefs.hweb
  87.  
  88. @ Here we open the \.{.tex} output file.  This routine is called from
  89. |common_init|. 
  90.  
  91. @<Part 1@>=@[
  92.  
  93. SRTN open_tex_file(VOID)
  94. {
  95. if(STRCMP(tex_fname,"stdout") == 0) tex_file = stdout;
  96. else if((tex_file=FOPEN(tex_fname,"w"))==NULL)
  97.     FATAL(W, "!! Can't open output file ", tex_fname);
  98. else @<Print header information to beginning of output file@>@;
  99. }
  100.  
  101. @ The command line was formatted up with newlines; these must be followed
  102. by a \TeX\ comment character.
  103. @<Print header...@>=
  104. {
  105. fprintf(tex_file,"%% FWEAVE v%s (%s)\n\n", 
  106.     (char *)version, (char *)release_date);
  107. }
  108.  
  109.  
  110. @
  111. @<Set init...@>=
  112.  
  113. @<Allocate dynamic memory@>@;
  114.  
  115. @ The function prototypes must appear before the global variables.
  116. @<Proto...@>=
  117.  
  118. #include "w_type.h" /* Function prototypes for \FWEAVE. */
  119.  
  120. @i xrefs.hweb /* Declarations for cross-referencing. */
  121.  
  122. @
  123. @<Alloc...@>=
  124.  
  125. ALLOC(xref_info,xmem,ABBREV(max_refs),max_refs,0);
  126. xmem_end = xmem + max_refs - 1;
  127.  
  128. @
  129. @<Set init...@>=
  130.  
  131. name_dir->xref = (XREF_POINTER)(xref_ptr=xmem); 
  132. xref_switch = mod_xref_switch = defd_switch = index_short = NO;
  133. xmem->num = 0; // Cross-references to undefined modules.
  134.  
  135. @ A new cross-reference for an identifier is formed by calling |new_xref|,
  136. which discards duplicate entries and ignores non-underlined references to
  137. one-letter identifiers or reserved words.
  138.  
  139. If the user has sent the |no_xref| flag (the \.{-x} option of the command
  140. line), it is unnecessary to keep track of cross-references for identifers.
  141. If one were careful, one could probably make more changes around module~100
  142. (??) to avoid a lot of identifier looking up.
  143.  
  144. @<Part 1@>=@[
  145.  
  146. SRTN new_xref FCN((part0,p))
  147.     PART part0 C0("")@;
  148.     name_pointer p C1("")@;
  149. {
  150. xref_pointer q; // Pointer to previous cross-reference.
  151. sixteen_bits m, n; // New and previous cross-reference value.
  152.  
  153. if(index_flag == NO)
  154.     {
  155.     SET_TYPE(p,DEFINED_TYPE(p) | 0x80);
  156.     index_flag = BOOLEAN(!(language==LITERAL));
  157.     }
  158.  
  159. /* Do nothing if we're not supposed to cross-reference. Also do nothing if
  160. we're inside a \&{format} statement. This is a bit kludgy, but it works. */
  161. if (!index_flag || !(output_on || index_hidden) || in_format
  162.         || (unnamed_section && !xref_unnamed) )
  163.     return; /* The |output_on| flag    here prevents index entries for
  164.         modules skipped with~\.{-i}. */ 
  165.  
  166. index_flag = BOOLEAN(!(language==LITERAL));
  167.  
  168. /* Say where the identifier is defined (but not if it's a reserved word). */
  169. if(defd_switch && (part0 == DEFINITION 
  170.         || !(is_reserved(p) || is_intrinsic(p) || is_keyword(p)))) 
  171.     {
  172.     sixteen_bits mod_defined = p->defined_in(language);
  173.  
  174.     if(mod_defined && mod_defined != module_count)
  175.         {
  176.         err_print(W,"Identifier in %s was already explicitly \
  177. or implicitly marked via @@[ as defined in %s",
  178.             MOD_TRANS(module_count), MOD_TRANS(mod_defined));
  179.         mark_harmless;
  180.         }
  181.  
  182.     p->defined_in(language) = module_count;
  183.     defd_switch = NO;
  184.     }
  185.  
  186. if(defd_type != NEVER_DEFINED)
  187.     SET_TYPE(p,defd_type); // Used to be up in previous block.
  188.  
  189. defd_type = NEVER_DEFINED;
  190.  
  191. if ( xref_switch==NO 
  192.         && (is_reserved(p) || ((!index_short) && (length(p)==1))) )
  193.     return;
  194.  
  195. if(index_short)
  196.     index_short = NO;
  197.  
  198. if(no_xref) 
  199.     return; // The result of the \.{-x} flag.
  200.  
  201. m = module_count + xref_switch; 
  202. xref_switch = NO; 
  203. q = (xref_pointer)p->xref;
  204.  
  205. if(!(do_inside || all_includes || (quoted_includes && qtd_file)))
  206.     goto check_implicit; // Skip if reading an include file.
  207.  
  208. if (q != xmem)
  209.     {  /* There's already an entry. */
  210.     n = q->num;
  211.  
  212.     if (n==m || n==m+def_flag) 
  213.         goto check_implicit; 
  214.             // Discard duplicates within the same module.
  215.     else if (m==n+def_flag) 
  216.         {
  217.         q->num = m; /* Update the entry to be defined instead of
  218. just used. */
  219.         goto check_implicit;
  220.         }
  221.     }
  222.  
  223. /* There's no entry yet; make a new cross-reference. */
  224. append_xref(m);
  225.  
  226. /* Link in; highest module number is first. */
  227. xref_ptr->xlink=q; p->xref = (XREF_POINTER)xref_ptr;
  228.  
  229. check_implicit:
  230.   if(typd_switch) 
  231.     @<Execute an implicit \.{@@f}@>@;
  232. }
  233.  
  234. @ When the |typd_switch| is on, due to an~\.{@@`}, we execute an implicit
  235. format statement that formats~|p| as a reserved word.
  236. @<Execute an implicit...@>=
  237. {
  238. NAME_INFO rs_wd;
  239. name_pointer lhs = p, rhs = &rs_wd;
  240.  
  241. rhs->ilk = int_like;
  242. rhs->reserved_word = rhs->Language = BOOLEAN(language);
  243. rhs->intrinsic_word = rhs->keyword = NO;
  244.  
  245. @<Format the left-hand side@>@;
  246.  
  247. @#if 0
  248. /* Mark as defined in this module. */
  249. if(mark_defined.imp_reserved_name)
  250.     {
  251.     p->defined_in(language) = module_count;
  252.     SET_TYPE(p,IMPLICIT_RESERVED);
  253.     }
  254. @#endif
  255.  
  256. /* Make all previous entries register as defined, not just used. */
  257. for(q=(xref_pointer)p->xref; q>xmem; q = q->xlink)
  258.     if(q->num < def_flag) q->num += def_flag;
  259.  
  260. typd_switch = NO;
  261. }
  262.  
  263. @ The cross-reference lists for module names are slightly different.
  264. Suppose that a module name is defined in modules~$m_1$, \dots, $m_k$ and
  265. used in modules~$n_1$, \dots, $n_l$. Then its list will contain
  266. $m_1+|def_flag|$, $m_k+|def_flag|$, \dots, $m_2+|def_flag|$, $n_l$, \dots,
  267. $n_1$, in this order.  After Phase II, however, the order will be
  268. $m_1+|def_flag|$, \dots, $m_k+|def_flag|$, $n_1$, \dots, $n_l$.
  269.  
  270. @<Part 1@>=@[
  271.  
  272. SRTN new_mod_xref FCN((p))
  273.     name_pointer p C1("")@;
  274. {
  275.   xref_pointer q,r; /* pointers to previous cross-references */
  276.  
  277. @#if(0)
  278. if(!output_on) return; /* Don't bother with references if the module is
  279.             skipped with \.{-i}. */
  280. @#endif
  281.  
  282.   q = (xref_pointer)p->xref; r=xmem;
  283.  
  284.   if (q>xmem) 
  285.     {
  286. /* ``Used in module...'' Scan past all the definitions. */
  287.     if (mod_xref_switch==NO) 
  288.         while (q->num>=def_flag) 
  289.             {
  290.             r=q; q=q->xlink;
  291.             }
  292.     else /* Defining...*/
  293.         if (q->num>=def_flag) 
  294.             {
  295.             r=q; q=q->xlink;
  296.             }
  297.     }
  298.  
  299. /* Discard duplicate ``used in'' xref. */
  300. if(mod_xref_switch == NO && q->num == module_count) 
  301.     return;
  302.  
  303.   append_xref(module_count+mod_xref_switch);
  304.   xref_ptr->xlink=q; mod_xref_switch=NO;
  305.  
  306.   if (r==xmem) 
  307.     p->xref = (XREF_POINTER)xref_ptr;
  308.   else 
  309.     r->xlink=xref_ptr;
  310. }
  311.  
  312. @i tokens.hweb /* Declarations for |token| storage. */
  313.  
  314. @
  315. @<Alloc...@>=
  316.  
  317. ALLOC(Token,tok_mem,ABBREV(max_toks_w),max_toks,1);
  318. tok_mem++; /* In some unusual circumstances, there may be references to
  319.         |tok_mem[-1]|, so be sure it exists. */
  320. tok_m_end = tok_mem+max_toks-1; // End of |tok_mem|./
  321.  
  322. ALLOC(token_pointer,tok_start,ABBREV(max_texts),max_texts,0);
  323. tok_end = tok_start+max_texts-1; // End of |tok_start|.
  324.  
  325. @<Set init...@>=
  326.  
  327. @<Initialize |tok_ptr|, |tok_start|, and |text_ptr|@>@;
  328. mx_tok_ptr=tok_ptr; mx_text_ptr=text_ptr;
  329.  
  330. @
  331. @<Initialize |tok_ptr|...@>=
  332. {
  333. tok_ptr = tok_mem + 1;
  334. tok_start[0] = tok_start[1] = tok_ptr;
  335. text_ptr = tok_start + 1;
  336. }
  337.  
  338. @ The |names_match| function is called from |id_lookup| in \.{common.web}
  339. when deciding whether to put a name into the table.
  340.  
  341. @<Part 1@>=@[
  342.  
  343. boolean names_match FCN((p,first,l,t))
  344.     name_pointer p C0("Points to the proposed match.")@;
  345.     CONST ASCII HUGE *first C0("Position of first character of string.")@;
  346.     int l C0("Length of identifier.")@;
  347.     eight_bits t C1("Desired ilk.")@;
  348. {
  349.   if (length(p)!=l) return NO; /* Speedy return. */
  350.  
  351.   if ( (p->Language&(boolean)language) && (p->ilk!=t) && !(t==normal &&
  352. is_reserved(p))) 
  353.         return NO; 
  354.  
  355.   return (boolean)(!STRNCMP(first,p->byte_start,l));
  356. }
  357.  
  358. @ The following two functions are used in initializations; they are called
  359. from \.{common.web}.
  360.  
  361. @<Part 1@>=@[
  362.  
  363. SRTN ini_p FCN((p,t))
  364.     name_pointer p C0("")@;
  365.     eight_bits t C1("")@;
  366. {
  367. CONST ASCII HUGE *k;
  368.  
  369. p->ilk=t; p->xref = (XREF_POINTER)xmem;
  370.  
  371. /* Check if identifier is all upper-case. */
  372. p->info.upper_case = NO;
  373.  
  374. for(k = p->byte_start; k<byte_ptr; k++)
  375.     if(isAlpha(*k) && !isAupper(*k))
  376.         return;
  377.  
  378. p->info.upper_case = YES;
  379. }
  380.  
  381. SRTN ini_node FCN((node))
  382.     CONST name_pointer node C1("")@;
  383. {
  384. node->xref = (XREF_POINTER)xmem;
  385.  
  386. @<Initialize |mod_info| and |Language|@>@;
  387. }
  388.  
  389. @i ccodes.hweb /* Category codes for the reserved words. */
  390.  
  391. @* LEXICAL SCANNING.  Let us now consider the subroutines that read the
  392. \.{WEB} source file and break it into meaningful units. There are four such
  393. procedures: |skip_limbo| simply skips to the next `\.{@@\ }' or `\.{@@*}'
  394. that begins a module; |skip_TeX| passes over the \TeX\ text at the
  395. beginning of a module; |copy_comment| passes over the \TeX\ text in a \cee\
  396. comment; and |get_next|, which is the most interesting, gets the next token
  397. of a \cee\ text.  They all use the pointers |limit| and |loc| into the line
  398. of input currently being studied.
  399.  
  400. Control codes in \.{WEB}, which begin with~`\.{@@}', are converted into a
  401. numeric code designed to simplify \WEAVE's logic; for example, larger
  402. numbers are given to the control codes that denote more significant
  403. milestones, and the code of |new_module| should be the largest of all. Some
  404. of these numeric control codes take the place of ASCII control codes that
  405. will not otherwise appear in the output of the scanning routines.  
  406. @^ASCII code@>
  407.  
  408. The following table shows the assignments:
  409. $$\def\:{\char\count255\global\advance\count255 by 1}
  410. \def\Hrule{\noalign{\hrule}}\def\HHrule{\noalign{\hrule height2pt}}
  411. \def\Width{60pt}
  412. \count255='40
  413. \vbox{
  414. \hbox{\hbox to \Width{\it\hfill0\/\hfill}%
  415. \hbox to \Width{\it\hfill1\/\hfill}%
  416. \hbox to \Width{\it\hfill2\/\hfill}%
  417. \hbox to \Width{\it\hfill3\/\hfill}%
  418. \hbox to \Width{\it\hfill4\/\hfill}%
  419. \hbox to \Width{\it\hfill5\/\hfill}%
  420. \hbox to \Width{\it\hfill6\/\hfill}%
  421. \hbox to \Width{\it\hfill7\/\hfill}}
  422. \vskip 4pt
  423. \hrule
  424. \def\!{\vrule height 10.5pt depth 4.5pt}
  425. \halign{\hbox to 0pt{\hskip -24pt\WO{\~#}\hfill}&\!
  426. \hbox to \Width{\hfill$#$\hfill\!}&
  427. &\hbox to \Width{\hfill$#$\hfill\!}\cr
  428. 00&\\{ignore}&\MM &\\{verbatim}&\\{force\_line}&\WW    &**     &\CC    &\\{bell}\cr\Hrule
  429. 01&\dots  &\\{begin\_cmnt}&\\{lf} &\PP    &\\{ff} &\\{cr}
  430.     &\\{begin\_lang}       &\\{cmpd\_assgn}        \cr\Hrule
  431. 02&\GG    &\LS    &\LL    &\.{.DOT.}&;    &\SR    &\SlSl  &        \cr\Hrule
  432. 03&\\{stmt\_label}&\MG   &\WI    &\WL    &\NN    &\WG    &\WS    &\WV     \cr\HHrule
  433. 04&       &\WR    &       &\#     &       &\MOD   &\amp   &        \cr\Hrule
  434. 05&       &       &\ast   &+      &       &-      &       &/       \cr\Hrule
  435. 06&       &       &       &       &       &       &       &        \cr\Hrule
  436. 07&       &       &       &       &<      &=      &>      &?       \cr\Hrule
  437. 10&\Wcp   &\Wcm   &\Wcs   &\Wcv   &\Wcd   &\Wcx   &\Wca   &\Wco    \cr\Hrule
  438. 11&\Wcg   &\Wcl   &       &       &       &       &       &        \cr\Hrule
  439. 12&       &       &       &       &       &       &       &        \cr\Hrule
  440. 13&       &       &       &       &       &       &\^     &        \cr\Hrule
  441. 14&       &       &       &       &       &       &       &        \cr\Hrule
  442. 15&       &       &       &       &       &       &       &        \cr\Hrule
  443. 16&       &       &       &       &       &       &       &        \cr\Hrule
  444. 17&       &       &       &       &\OR    &\.{@@\$}&\.{@@\_},\TL&\\{param}\cr\HHrule
  445. 20&\.{L$l$}&\.{C} &\.{R}  &\.{N}  &\.{M}  &\.{X}  &       &        \cr\Hrule
  446. 21&\NP    &\NC    &\.{\#<}&\WPtr  &\CC    &       &       &
  447. \cr\Hrule
  448. 22&       &       &       &       &       &       &       &        \cr\Hrule
  449. 23&\\{constant}&\\{stringg}&\\{identifier}&\.{@@\^}&\.{@@9} &\.{@@.} &\.{@@t} &\.{@@'}  \cr\Hrule
  450. 24&\.{@@\&}&\.{@@,} &\.{@@\char'174}&\.{@@/} &\.{@@\#} &\.{@@~} &\.{@@;}& \cr\Hrule
  451. 25&\.{@@(} &\.{@@)} &\.{\ } &\\{copy\_mode}&\\{toggle\_output}&\.{@@e}&\.{@@:}&
  452. \cr\Hrule
  453. 26&       &       &\.{@@!} &       &       &\.{@@0} &\.{@@1} &\.{@@2}  \cr\Hrule
  454. 27&\.{@@f} &\.{@@\%}&       &       &\.{@@l} &\.{@@o} &\.{@@d} &\.{@@m}  \cr\Hrule
  455. 30&\.{@@\#ifdef}&\.{@@\#ifndef}&\.{@@\#if}&\.{@@\#else}&\.{@@\#elif}&\.{@@\#endif}
  456. &\.{@@\#pragma}       &\.{@@\#undef}\cr\Hrule
  457. 31&\.{@@a} &\.{@@<} &\.{@@\ }&       &       &       &       &        \cr\Hrule
  458. 32&       &       &       &       &       &       &       &        \cr\Hrule
  459. 33&       &       &       &       &       &       &       &        \cr\Hrule
  460. 34&       &       &       &       &       &       &       &
  461. \cr\Hrule
  462. 35&       &       &       &       &       &       &       &
  463. \cr\Hrule
  464. 36&       &       &       &       &       &       &       &
  465. \cr\Hrule
  466. 37&       &       &       &       &       &       &\\{begin\_cmnt0}&        \cr}
  467. \hrule width 480pt}$$
  468.  
  469.  
  470. @d ignore 0 // Control code of no interest to \WEAVE.
  471. @d verbatim OCTAL(2) // Extended |ASCII| alpha will not appear.
  472. @d force_line OCTAL(3) // Extended |ASCII| beta will not appear.
  473.  
  474. @d begin_comment0 HEX(FE) // Sent from |input_ln|.
  475. @d begin_comment1 HEX(FD)
  476. @d begin_comment OCTAL(11) // |ASCII| tab mark will not appear.
  477.  
  478. @d compound_assignment OCTAL(17) // Things like `\.{*=}'.
  479. @% @d param OCTAL(177) // |ASCII| delete will not appear.
  480.  
  481. /* Language codes. */
  482. @d L_switch OCTAL(200) // The generic language switch \.{@@L$l$}.
  483. @d begin_C OCTAL(201)
  484. @d begin_RATFOR OCTAL(202)
  485. @d begin_FORTRAN OCTAL(203)
  486. @d begin_LITERAL OCTAL(204)
  487. @d begin_TEX OCTAL(205)
  488.  
  489. @d begin_nuweb OCTAL(206) // Strictly speaking, not a language code.
  490.  
  491. /* More two-byte combinations that couldn't be fitted below printable
  492. |ASCII|. */
  493. @d dont_expand OCTAL(210) // Control code for `\.{\#!}'.
  494. @d auto_label OCTAL(211) // Control code for `\.{\#:}'.
  495. @d all_variable_args OCTAL(212) // Control code for `\.{\#.}'.
  496. @d macro_module_name OCTAL(213) // Control code for `\.{\#<\dots@@>}'.
  497. @d eq_gt OCTAL(214) // Control code for `\.{=>}'.
  498. @d colon_colon OCTAL(215) /* Control code for `\.{::}'. */
  499.  
  500. /* Control codes for \FWEB\ commands beginning with \.{@@}. */
  501.  
  502. /* The following two codes will be intercepted without confusion, because
  503. they're processed immediately after an \.{@@}, not returned from
  504. |next_control|. */
  505. @d switch_math_flag OCTAL(175)
  506. @d underline OCTAL(176)
  507.  
  508. @d xref_roman OCTAL(233) /* control code for `\.{@@\^}' */
  509. @d xref_wildcard OCTAL(234) /* control code for `\.{@@9}' */
  510. @d xref_typewriter OCTAL(235) /* control code for `\.{@@.}' */
  511. @d TeX_string OCTAL(236) /* control code for `\.{@@t}' */
  512. @d ascii_constant OCTAL(237) /* control code for `\.{@@'}' */
  513. @d join OCTAL(240) /* control code for `\.{@@\&}' */
  514. @d thin_space OCTAL(241) /* control code for `\.{@@,}' */
  515. @d math_break OCTAL(242) /* control code for `\.{@@\char'174}' */
  516. @d line_break OCTAL(243) /* control code for `\.{@@/}' */
  517.  
  518. @d big_line_break OCTAL(244) /* control code for `\.{@@\#}' */
  519. @d no_line_break OCTAL(245) /* control code for `\.{@@~}' */
  520. @d pseudo_semi OCTAL(246) /* control code for `\.{@@;}' */
  521. @d defd_at OCTAL(247) // Control code for `\.['.
  522.  
  523. @d begin_meta OCTAL(250) /* Control code for |"@@("|. */
  524. @d end_meta OCTAL(251) /* Control code for |"@@)"|. */
  525.  
  526. @d macro_space OCTAL(252) /* Space token during preprocessing. */
  527. @d copy_mode OCTAL(253) /* Are we copying comments? */
  528.  
  529. @d toggle_output OCTAL(254) // Turns on and off Weave's output.
  530. @d turn_output_on OCTAL(254) // Appended to the scraps for code.
  531. @d turn_output_off OCTAL(255)
  532. @d Turn_output_on OCTAL(256)
  533. @d Turn_output_off OCTAL(257)
  534.  
  535. /* 260 and 261 are elsewhere. */
  536.  
  537. @d compiler_directive OCTAL(262)  // No longer used.
  538. @d Compiler_Directive OCTAL(263) /* Control code for `\.{@@?}' */
  539. @d new_output_file OCTAL(264) // Control code for `\.{@@o}'.
  540.  
  541. @d implicit_reserved OCTAL(265) // Control code for `\.{@@]}'.
  542.  
  543. @d trace OCTAL(266) /* control code for `\.{@@0}', `\.{@@1}', and `\.{@@2}' */
  544.  
  545. @d invisible_cmnt OCTAL(271) /* Control code for `\.{@@\%}' */
  546.  
  547. @d pseudo_expr OCTAL(272) /* Control code for `\.{@@e}' */
  548. @d pseudo_colon OCTAL(273) /* Control code for `\.{@@:}' */
  549.  
  550. @d begin_bp OCTAL(274) // Control code for `\.{@@\lb}'.
  551. @d insert_bp OCTAL(275) // Control code for `\.{@@b}'.
  552.  
  553. @d no_index OCTAL(276) // Control code for `\.{@@-}'.
  554. @d yes_index OCTAL(277) // Control code for `\.{@@~}'.
  555.  
  556. @d no_mac_expand OCTAL(300) // Control code for `\.{@@!}'.
  557. @d protect_code OCTAL(301) // Control code for `\.{@@p}'.
  558. @d set_line_info OCTAL(302) // Control code for `\.{@@q}'.
  559.  
  560. /* Definition section begun by codes $\ge$~|formatt|. */
  561. @d formatt OCTAL(310) /* control code for `\.{@@f}' */
  562.  
  563. @d limbo_text OCTAL(313) /* Control code for `\.{@@l}' */
  564. @d op_def OCTAL(314) /* Control code for `\.{@@v}' */
  565. @d macro_def OCTAL(315) // Control code for `\.{@@w}'.
  566.  
  567. @d definition OCTAL(320) /* control code for `\.{@@d}' */
  568. @d undefinition OCTAL(321) // Control code for `\.{@@u}'.
  569. @d WEB_definition OCTAL(322) /* Control code for `\.{@@M}' */
  570.  
  571. /* --- Preprocessor commands --- */
  572. @d m_ifdef OCTAL(330)
  573. @d m_ifndef OCTAL(331)
  574. @d m_if OCTAL(332)
  575. @d m_else OCTAL(333)
  576. @d m_elif OCTAL(334)
  577. @d m_endif OCTAL(335)
  578. @d m_for OCTAL(336)
  579. @d m_endfor OCTAL(337)
  580. @d m_line OCTAL(340)
  581. @d m_undef OCTAL(341)
  582.  
  583. /* --- Module names --- */
  584. @d begin_code OCTAL(350) /* control code for `\.{@@a}' */
  585. @d module_name OCTAL(351) /* control code for `\.{@@<}' */
  586.  
  587. /* --- Beginning of new module --- */
  588. @d new_module OCTAL(352) /* control code for `\.{@@\ }' and `\.{@@*}' */
  589.  
  590.  
  591. @ Control codes are converted from ASCII to \WEAVE's internal
  592. representation by means of the table |ccode|.  Codes that are used only by
  593. \FTANGLE\ get the special code~|ignore| (see \.{typedefs.hweb}; these are
  594. just skipped.  Codes that are used by neither processor are initialized
  595. to~|'0xFF'|; that can be used to trigger an error message.
  596.  
  597. @<Global...@>=
  598.  
  599. IN_STYLE eight_bits ccode[128]; 
  600.     /* Meaning of an |ASCII| char following '\.{@@}'. */
  601.  
  602. @ The control codes are set up in \.{style.web}.
  603.  
  604. @m TANGLE_ONLY(d,c) INI_CCODE(d,USED_BY_OTHER)
  605. @m WEAVE_ONLY(d,c) INI_CCODE(d,c)
  606.  
  607. @<Set ini...@>=
  608.  
  609. zero_ccodes();  // See \.{style.web}.
  610. ccode[@'/'] = line_break; /* The commenting style is also fundamental, and
  611.     for convenience the |line_break| command is also inviolate. */
  612.  
  613. @<Set the changable codes@>@;
  614. prn_codes();
  615.  
  616. @ Here are the default values for the things that are allowed to be
  617. changed.   
  618. @<Set the changable...@>= 
  619. SAME_CCODE(" \t*",new_module); // Either space, tab, or asterisk.
  620.  
  621. SAME_CCODE("aA",begin_code);
  622. SAME_CCODE("<",module_name);
  623.  
  624. SAME_CCODE("dD",definition);
  625. SAME_CCODE("uU",undefinition);
  626. SAME_CCODE("mM",WEB_definition);
  627. SAME_CCODE("fF",formatt);
  628.  
  629. WEAVE_ONLY("\001",toggle_output); // This command is for internal use only!
  630.  
  631. SAME_CCODE("'\"",ascii_constant);
  632. REASSIGNABLE("=",verbatim);
  633. WEAVE_ONLY("\\",line_break);
  634.  
  635. REASSIGNABLE("tT",TeX_string);
  636.  
  637. SAME_CCODE("L",L_switch);
  638. SAME_CCODE("cC",begin_C);
  639. SAME_CCODE("rR",begin_RATFOR);
  640. SAME_CCODE("n",begin_FORTRAN);
  641. SAME_CCODE("N",begin_nuweb);
  642. SAME_CCODE("xX",begin_TEX);
  643.  
  644. SAME_CCODE("&",join);
  645. WEAVE_ONLY("_",underline);
  646. WEAVE_ONLY("[",defd_at);
  647. WEAVE_ONLY("`]",implicit_reserved);
  648.  
  649. SAME_CCODE("%",invisible_cmnt);
  650. SAME_CCODE("?",Compiler_Directive);
  651.  
  652. WEAVE_ONLY("$",switch_math_flag);
  653.  
  654. REASSIGNABLE("^",xref_roman);
  655. REASSIGNABLE(".",xref_typewriter);
  656. REASSIGNABLE("9",xref_wildcard);
  657.  
  658. {
  659. char temp[3];
  660.  
  661. sprintf(temp,";%c",XCHR(interior_semi));
  662. WEAVE_ONLY(temp,pseudo_semi);
  663. }
  664.  
  665. WEAVE_ONLY("e",pseudo_expr);
  666. WEAVE_ONLY(":",pseudo_colon);
  667.  
  668. SAME_CCODE("l",limbo_text);
  669. SAME_CCODE("vV",op_def);
  670. SAME_CCODE("wW",macro_def);
  671.  
  672. WEAVE_ONLY(",",thin_space);
  673. WEAVE_ONLY("|",math_break);
  674. SAME_CCODE("#",big_line_break);
  675. WEAVE_ONLY("~",no_line_break);
  676.  
  677. SAME_CCODE("(",begin_meta);
  678. SAME_CCODE(")",end_meta);
  679.  
  680. SAME_CCODE("oO",new_output_file);
  681.  
  682. SAME_CCODE("{",begin_bp);
  683. TANGLE_ONLY("}bB",insert_bp);
  684. SAME_CCODE("!",no_mac_expand);
  685. TANGLE_ONLY("q", set_line_info);
  686.  
  687. WEAVE_ONLY("-",no_index);
  688. WEAVE_ONLY("+",yes_index);
  689.  
  690. WEAVE_ONLY("p", protect_code);
  691.  
  692. @<Special control codes allowed only when debugging@>@;
  693. }
  694.  
  695. @ If \WEAVE\ is compiled with debugging commands, one can write~\.{@@2},
  696. \.{@@1}, and~\.{@@0} to turn tracing fully on, partly on, and off,
  697. respectively.
  698. @<Special control codes...@>=
  699.  
  700. #if(DEBUG)
  701.     WEAVE_ONLY("012",trace);
  702. #endif /* |DEBUG| */
  703.  
  704. @ At this point |loc|~is positioned after a language command like~\.{@@c},
  705. or on the~$l$ in~\.{@@L$l$}.
  706.  
  707. @f @<Cases to set |language| and |break|@> case
  708.  
  709. @<Cases to set |language| and |break|@>=
  710.  
  711.    @<Specific language cases@>:
  712.     loc--; /* Position to letter after \.{@@}. Falls
  713. through to general case |L_switch|. */
  714.  
  715.    case L_switch:
  716.     @<Set the |language| and maybe kill rest of line@>@;
  717.     break;
  718.  
  719.    case begin_nuweb:
  720.     nuweb_mode = !NUWEB_MODE;
  721.  
  722.     if(module_count == 0) 
  723.         global_params = params;
  724.     break;
  725.     
  726. @<Set the |language| and maybe kill...@>=
  727. {
  728. @<Set |language|@>@;
  729.  
  730. if(module_count == 0) 
  731.     global_params = params;
  732.  
  733. ini0_language();
  734. @<Kill rest of line; no |auto_semi|@>@;
  735. }
  736.  
  737. @ The |skip_limbo| routine is used on the first pass to skip through
  738. portions of the input that are not in any modules, i.e., that precede the
  739. first module. Language commands may be encountered at any time; these reset
  740. the current language from whatever was specified on the command line.  When
  741. the first module is found, the global language is set to the current
  742. language.
  743.  
  744. After this procedure has been called, the value of |input_has_ended| will
  745. tell whether or not a module has actually been found.
  746.  
  747. @<Part 1@>=@[
  748.  
  749. SRTN skip_limbo(VOID) 
  750. {
  751. WHILE() 
  752.     {
  753.         if (loc>limit && !get_line()) return;
  754.  
  755.         *(limit+1)=@'@@'; // Guard character.
  756.  
  757. /* Look for '@@', then skip two chars. */
  758.         while (*loc!=@'@@') loc++; 
  759.  
  760. /* |loc| now on the \.{@@}. */
  761.        if(loc++ <= limit)
  762.         switch(ccode[*loc++]) 
  763.             { /* Process any language change
  764. commands; skip any other @@~commands. */
  765.            @<Cases to set |language| and |break|@>@:@;
  766.  
  767.            case invisible_cmnt:
  768.             loc = limit + 1;
  769.             break;
  770.  
  771.            case new_module: 
  772.             return; // End of limbo section.
  773.             }
  774.     
  775. @#if(0) // Old code.
  776.         if (loc <=limit) if (ccode[*loc++]==new_module) return; 
  777. @#endif
  778.     }
  779. }
  780.  
  781. @ The |skip_TeX| routine is used on the first pass to skip through the
  782. \TeX\ code at the beginning of a module. It returns the next control code
  783. or~`\v' found in the input. A |new_module| is assumed to exist at the very
  784. end of the file.
  785.  
  786. @<Part 1@>=@[
  787.  
  788. eight_bits skip_TeX(VOID)
  789. {
  790. WHILE()
  791.     {
  792.     if (loc>limit && !get_line()) return new_module;
  793.  
  794.     *(limit+1)=@'@@'; /* Marker to curtail the scan. */
  795.  
  796.     while (*loc!=@'@@' && *loc!=@'|') loc++;
  797.  
  798.     if (*loc++ ==@'|') return @'|'; // Have hit beginning of code mode.
  799.  
  800.     if (loc<=limit) 
  801.         {
  802.         SET_CASE(*loc);
  803.         return ccode[*(loc++)];
  804.         }
  805.     }
  806.  
  807. DUMMY_RETURN(0);
  808. }
  809.  
  810. @* INPUTTING the NEXT TOKEN.
  811. As stated above, \.{WEAVE}'s most interesting lexical scanning routine is the
  812. |get_next| function that inputs the next token of \cee\ input. However,
  813. |get_next| is not especially complicated.
  814.  
  815. The result of |get_next| is either an ASCII code for some special
  816. character, or it is a special code representing a pair of characters (e.g.,
  817. `\.{!=}'), or it is the numeric value computed by the |ccode| table, or it
  818. is one of the following special codes:
  819.  
  820. \yskip\hang |identifier|: In this case the global variables |id_first| and
  821. |id_loc| will have been set to the beginning and ending-plus-one locations
  822. in the buffer, as required by the |id_lookup| routine.
  823.  
  824. \yskip\hang |string|: The string will have been copied into the array
  825. |mod_text|; |id_first| and |id_loc| are set as above (now they are
  826. pointers into |mod_text|).
  827.  
  828. \yskip\hang |constant|: The constant is copied into |mod_text|, with slight
  829. modifications; |id_first| and |id_loc| are set.
  830.  
  831. \yskip\noindent Furthermore, some of the control codes cause |get_next| to
  832. take additional actions:
  833.  
  834. \yskip\hang |xref_roman|, |xref_wildcard|, |xref_typewriter|, |TeX_string|,
  835. |verbatim|: The values of |id_first| and |id_loc| will have been set to the
  836. beginning and ending-plus-one locations in the buffer.
  837.  
  838. \yskip\hang |module_name|: In this case the global variable |cur_module| will
  839. point to the |byte_start| entry for the module name that has just been scanned.
  840.  
  841. \yskip\noindent If |get_next| sees `\.{@@\_}' it sets |xref_switch| to
  842. |def_flag| and goes on to the next token.
  843.  
  844. \yskip\noindent If |get_next| sees `\.{@@\$}' it sets |math_flag| to
  845. |!math_flag| and goes on to the next token.
  846.  
  847. @d constant OCTAL(230) /* \cee\ string or \.{WEB} precomputed string */
  848. @d stringg OCTAL(231) /* \cee\ string or \.{WEB} precomputed string */
  849. @d identifier OCTAL(232) /* \cee\ identifier or reserved word */
  850.  
  851. @<Global...@>=
  852.  
  853. EXTERN name_pointer cur_module; // Name of module just scanned.
  854. EXTERN int math_flag SET(NO);
  855. EXTERN boolean chk_end SET(YES); // Do we check for end of line?
  856. EXTERN boolean last_was_cmnt SET(NO); /* Helps with interchanging
  857.                     semicolons and comments. */
  858. EXTERN boolean lst_ampersand SET(NO); /* For continuations in
  859.         free-form syntax \Fortran-90. */
  860. EXTERN boolean eat_blank_lines SET(NO); // For Nuweb mode.
  861.  
  862. EXTERN ASCII c; // The current character for |get_next|.
  863.  
  864. @ As one might expect, |get_next| consists mostly of a big switch that
  865. branches to the various special cases that can arise.  This function has
  866. been broken into multiple function calls to |prs_TeX_code| and
  867. |prs_regular_code| in order to make it fit on personal computers.
  868.  
  869. @<Part 1@>=@[
  870.  
  871. eight_bits get_next(VOID) /* produces the next input token */
  872. {
  873. boolean terminate = NO;
  874. char terminator[2];
  875. GOTO_CODE pcode; // Return from the parsing functions.  0~means |continue|.
  876.  
  877. WHILE()
  878.     {
  879.     @<Check if we're at the id part of a preprocessor command@>;
  880.     @<Check if we're at the end of a preprocessor command@>;
  881.  
  882.     chk_end = YES;
  883.  
  884.     @<Get another line of input if necessary@>@;
  885.     @<Get next character; skip blanks and tabs@>@;
  886.  
  887. /* Handle an (effectively) empty line. (Don't move this statement upwards.) */
  888.      if(limit == cur_buffer || (at_beginning && loc > limit))  
  889.         return big_line_break; 
  890.  
  891.     switch(language)
  892.         {
  893.        case TEX:
  894.         if((pcode=prs_TeX_code()) == MORE_PARSE) 
  895.             break;
  896.         else if((int)pcode < 0) 
  897.             CONFUSION("prs_TEX_code","Negative pcode");
  898.         else 
  899.             goto found_something;
  900.  
  901.        default:
  902.         if((pcode=prs_regular_code(MORE_PARSE)) == MORE_PARSE) 
  903.             break;
  904.         else if((int)pcode < 0)
  905.             CONFUSION("prs_regular_code",
  906.                 "Negative pcode");
  907.         else 
  908.             goto found_something;
  909.         }
  910.     }
  911.  
  912. found_something:
  913.  /* We need the following stuff to handle the |INNER| parsing mode properly.
  914. (|at_beginning| doesn't correspond to physical beginning of line, so can't
  915. be reset by |get_line()|.) */
  916.     if(!preprocessing)
  917.         switch((eight_bits)pcode)
  918.             {
  919.            case begin_language:
  920.             break;
  921.  
  922.            default:
  923.             at_beginning = NO;
  924.             break;
  925.             }
  926.  
  927. return (eight_bits)pcode;
  928. }
  929.  
  930. @ Get another line of input if necessary. We raise the special flag
  931. |at_beginning| to help us with statement labels and preprocessor commands.
  932. Normally this flag is set when we get a new line.  However, it must also be
  933. set after we enter code mode by encountering vertical bars.
  934.  
  935. @<Get another line...@>=
  936.  
  937. if (loc>limit)
  938.     {
  939.     if(terminate)
  940.         {
  941.         terminator[0] = *limit; terminator[1] = *(limit+1);
  942.         }
  943.  
  944.     if(!get_line())
  945.         return(new_module);
  946.  
  947.     if(eat_blank_lines)
  948.         { /* Avoid empty stuff at end of module in Nuweb mode. */
  949.         @<Skip blank lines@>@;
  950.         eat_blank_lines = NO;
  951.         }
  952.  
  953.     if(parsing_mode == OUTER) 
  954.         at_beginning = YES; // Start of new line.
  955.  
  956.     if(terminate) 
  957.         {
  958.         *limit = terminator[0]; *(limit+1) = terminator[1];
  959.         terminate = NO;
  960.         }
  961.     }
  962. else if(parsing_mode == OUTER) at_beginning = NO;
  963.  
  964. @ In Nuweb mode, blank lines at the end of the module are significant,
  965. unless `\.{@@\%\%}' is used.  That turns on |eat_blank_lines|.
  966.  
  967. @<Skip blank lines@>=
  968. {
  969. while(loc >= limit)
  970.     if(!get_line())
  971.         {
  972.         eat_blank_lines = NO;
  973.         return(new_module);
  974.         }
  975. }
  976.  
  977. @ Here we obtain the next character, advancing~|loc| in the process.
  978. Depending on the situation, we also skip blanks and tabs.
  979.  
  980. @<Get next char...@>=
  981.  
  982. if(preprocessing) 
  983.     @<Compress string of blanks into one; if any found, return 
  984.     |macro_space|@>@;
  985. else
  986.     @<Skip white space at beginning of line@>@;
  987.  
  988. if(c==cont_char && loc==limit)
  989.     {
  990.     if(preprocessing || free_Fortran) loc--; /* IFFY */
  991.     else loc++;
  992.  
  993.     terminate = YES;
  994.     continue;
  995.     }
  996.  
  997. @
  998. @<Compress string of blanks...@>=
  999. {
  1000. do
  1001.     {
  1002.     if((c=*loc++) != @' ' || c != tab_mark) 
  1003.         break;
  1004.     }
  1005. while(loc < limit);
  1006.  
  1007. if(c==@' ' || c==tab_mark) 
  1008.     return macro_space;
  1009. }
  1010.  
  1011. @
  1012. @<Skip white space at beg...@>=
  1013. {
  1014. if(language==TEX) 
  1015.     c = *loc++;
  1016. else
  1017.     {
  1018.     ASCII HUGE *loc0 = loc; // Remember starting point for nuweb mode.
  1019.  
  1020.     do
  1021.         { /* Skip beginning white space. */
  1022.         c = *loc++;
  1023.         }
  1024.     while(loc<=limit && (c==@' ' || c==tab_mark) );
  1025.  
  1026.     if(nuweb_mode)
  1027.         {
  1028.         if(!(c == @'@@' && *loc == @'#'))
  1029.             { /* Go back to beginning. */
  1030.             loc = loc0;
  1031.             c = *loc++;
  1032.             if(phase == 1 && c == tab_mark)
  1033.                 c = @' ';
  1034.             }
  1035.         }
  1036.     }
  1037. }
  1038.  
  1039.  
  1040. @ \TeX\ syntax differs significantly from that of the other languages.
  1041. First of all, \TeX\ comments (beginning with~'\.\%') are always short. Next,
  1042. in phase~1, we must look at the text identifier by identifier in order to make
  1043. cross-references properly.  In phase~2, however, we can absorb whole
  1044. collections of identifiers, until a comment or control code comes along.
  1045.  
  1046. In order to deal with changing category codes, we translate letters through
  1047. the array~|TeX|, which contains the most up-to-date category codes.
  1048.  
  1049. @<Part 1@>=@[
  1050. GOTO_CODE prs_TeX_code(VOID)
  1051. {
  1052. GOTO_CODE icode; // Return code from |get_control_code|.
  1053.  
  1054. if(loc>limit) 
  1055.     return @';';
  1056.  
  1057. if (c==@'@@') 
  1058.     { // The next call takes care of a branch to |mistake|.
  1059.     if((icode=get_control_code()) == GOTO_MISTAKE) 
  1060.         return prs_regular_code(GOTO_MISTAKE);
  1061.     else 
  1062.         return icode;
  1063.     }
  1064. else if(TeX[c] == TeX_comment)
  1065.     {
  1066.     long_comment = YES; // Since we may concatenate lines.
  1067.     return begin_comment;
  1068.     }
  1069. else if(c == @'|' && parsing_mode == INNER) 
  1070.     return @'|';
  1071. else 
  1072.     if(phase==1)
  1073.         {
  1074.         if(TeX[c] == TeX_escape) 
  1075.             @<Get \TeX\ identifier@>@;
  1076.         else 
  1077.             return MORE_PARSE;
  1078.         }
  1079.     else 
  1080.         @<Get \TeX\ string@>@;
  1081.  
  1082. @% return MORE_PARSE; // This means to continue to top of |get_next|.
  1083. }
  1084.  
  1085. @ If the identifier doesn't begin with a letter, it's a single-character
  1086. macro such as~`\.{\\<}'.
  1087.  
  1088. @<Get \TeX\ identifier@>=
  1089. {
  1090. id_first = id_loc = mod_text + 1;
  1091.  
  1092. *id_loc++ = *(loc-1); // The beginning backslash.
  1093.  
  1094. if(TeX[*loc] != TeX_letter)
  1095.     { /* Single-character macro, such as~`\.{\\<}'. */
  1096.     if(*loc == @'@@')
  1097.         {
  1098.         if(*(loc+1) != @'@@') ERR_PRINT(W,"You should say `\\@@@@'");
  1099.         else loc++;
  1100.         }
  1101.     *id_loc++ = *loc++; // The single character.
  1102.     }
  1103. else while(TeX[*loc] == TeX_letter)
  1104.     { /* Scan over the macro name. */
  1105.     if(*loc == @'@@')
  1106.         {
  1107.         if(*(loc+1) != @'@@') ERR_PRINT(W,"You should say `@@@@'");
  1108.         else loc++;
  1109.         }
  1110.     *id_loc++ = *loc++;
  1111.     }
  1112.  
  1113. return identifier;
  1114. }
  1115.  
  1116. @ \TeX\ strings are everything on a single line, up to a comment or, if
  1117. we're inside vertical bars, up to a terminating bar.  It looks nicer if we
  1118. leave spaces alone instead of displaying them as~`\.{\ }'.
  1119.  
  1120. @d ordinary_space 01 /* Inserted after ctrl sequences, to avoid many
  1121.             visible spcs. */
  1122.  
  1123. @<Get \TeX\ string@>=
  1124. {
  1125. loc--;
  1126. id_first = id_loc = mod_text + 1;
  1127.  
  1128. while(loc < limit)
  1129.     {
  1130.     if(*loc == @'@@')
  1131.         if(*(loc+1)==@'@@') *id_loc++ = *loc++;
  1132.         else  break; // Scan ended by control code.
  1133.  
  1134.     if(TeX[*loc] == TeX_comment) break;
  1135.     if(*loc==@'|' && parsing_mode==INNER) break; // End of internal mode.
  1136.  
  1137.     if(TeX[*loc] == TeX_escape)
  1138.         {
  1139.         if(TeX[*(loc+1)] != TeX_letter)
  1140.             { // One-character control sequence.
  1141.             if(*(loc+1) == @'@@')
  1142.                 if(*(loc+2) != @'@@') 
  1143.                     ERR_PRINT(W,"You should say \\@@@@");
  1144.                 else *id_loc++ = *loc++;
  1145.  
  1146.             *id_loc++ = *loc++;
  1147.             }
  1148.         else 
  1149.             { // Ordinary control sequence.
  1150.             do 
  1151.                 *id_loc++ = *loc++;
  1152.             while (TeX[*loc] == TeX_letter);
  1153.  
  1154.             while (loc < limit)
  1155.                 {
  1156.                 if(TeX[*loc] != TeX_space) break;
  1157.  
  1158.                 *id_loc++ = ordinary_space;
  1159.                 loc++;
  1160.                 }
  1161.                 
  1162.             continue;
  1163.             }
  1164.         }
  1165.  
  1166.     *id_loc++ = *loc++;
  1167.     }
  1168.  
  1169. return stringg;
  1170. }
  1171.     
  1172. @ Parse everything but \TeX.  
  1173. @<Part 1@>=@[
  1174.  
  1175. GOTO_CODE prs_regular_code FCN((iswitch))
  1176.     GOTO_CODE iswitch C1("")@;
  1177. {
  1178. GOTO_CODE icode; // Return code from |get_control_code|.
  1179.  
  1180. switch(iswitch)
  1181.     {
  1182.    case GOTO_MISTAKE: goto mistake;
  1183.    case GOTO_GET_IDENTIFIER: goto get_identifier;
  1184.    default: break;
  1185.     }
  1186.  
  1187. /* --- ELLIPSIS: `\.{...}' --- */
  1188. if(c==@'.' && *loc==@'.' && *(loc+1)==@'.')
  1189.     {
  1190.     ++loc;
  1191.     compress(ellipsis);
  1192.     }
  1193.  
  1194. /* --- DOT CONSTANT: `\.{.FALSE.}' --- */
  1195. else if(FORTRAN_LIKE(language) && dot_constants &&
  1196.         (c == wt_style.dot_delimiter.begin) && !isDigit(*loc))
  1197.     @<Get a dot constant@>@;
  1198.  
  1199. /* --- CONSTANT: `\.{123}', `\.{.1}', or `\.{\\135}' --- */
  1200. else if (isDigit(c) || c==@'\\' || c==@'.') @<Get a constant@>@;
  1201.  
  1202. /* --- BOZ-CONSTANT --- */
  1203. else if (in_data && Fortran88 && (*loc==@'"' || *loc==@'\'') &&
  1204.     (c==@'B' || c==@'O' || c==@'Z') ) return get_string(*loc++,c);
  1205.  
  1206. /* --- IDENTIFIER --- */
  1207. else if (is_identifier(c)) @<Get an identifier@>@;
  1208.  
  1209. /* --- STRING: `\.{"abc"}', `\.{'\\n'}', `\.{<file\_name>}' --- */
  1210.  else if (c==@'\'' || c==@'"' 
  1211.     || (sharp_include_line && !in_comment &&
  1212.          (c==@'(' || (C_LIKE(language) && c==@'<') ) ))
  1213.             return get_string(c,'\0');
  1214.  
  1215. /* --- CONTROL CODE --- */
  1216. else if (c==@'@@') 
  1217.     if((icode=get_control_code()) == GOTO_MISTAKE) goto mistake;
  1218.     else return icode;
  1219.  
  1220. /* --- WHITE SPACE --- */
  1221. /* Blanks were skipped above. */
  1222. else if (c==@' ' || c==tab_mark)
  1223. @#if(0)
  1224.     if(preprocessing) /* What is this statement for? */
  1225.         {
  1226.         id_first = mod_text + 1;
  1227.         id_loc = id_first + 1;
  1228.         *id_first = c;
  1229.         return stringg;
  1230.         }
  1231.     else    /* JAK to here */
  1232. @#endif
  1233.     if(nuweb_mode)
  1234.         return c; @%(c==tab_mark ? bell : c);
  1235.     else
  1236.         return MORE_PARSE; // Ignore spaces and tabs; continue.
  1237.  
  1238. /* --- C PREPROCESSOR STATEMENT: `\.{\#include}' --- */
  1239. if (c==@'#' && at_beginning && C_LIKE(language)) 
  1240.     @<Raise preprocessor flag@>@;
  1241.   /* If |'#'| is first character in line, it's a C~preprocessor statement. */
  1242.  
  1243. /* --- END A |@r format| STATEMENT: `\.{format(\dots);}' --- */
  1244. else if (in_format && c==@';')
  1245.     { /* End a |@r format| statement. */
  1246.     in_format = NO;
  1247.     return end_format_stmt;
  1248.     }
  1249.  
  1250. /* --- TWO-SYMBOL OPERATOR --- */
  1251. mistake: @<Compress two-symbol operator@>@;
  1252. return (eight_bits)c;
  1253. }
  1254.  
  1255. @ For FORTRAN, we allow ``dot constants'', like ~\.{.true.}\ or~\.{.or.}.
  1256. This routine scans between the dots, then looks up the identifier in a
  1257. table to see if it's valid and to get its token translation. This procedure
  1258. has a tendency to run away if an unexpected dot finds its way into the
  1259. input (either because of a syntactical mistake, or because \Weave\ is
  1260. missing the relevant rule). Thus, we limit the search to no more than
  1261. |MAX_DOT_LENGTH == 31| characters, the maximum possible length of a dot
  1262. constant. 
  1263.  
  1264. @<Get a dot constant@>=
  1265. @{
  1266. ASCII HUGE *p0;
  1267. int n;
  1268. int dcode;
  1269. ASCII dot_end = wt_style.dot_delimiter.end;
  1270.  
  1271. @b
  1272. /* At this point, |loc| is positioned to the first position after the dot. */
  1273. for(p0=loc, n=0; n<MAX_DOT_LENGTH; n++,loc++)
  1274.     if(*loc == dot_end || !isAlpha(*loc)) break; /* Found end of dot
  1275. constant, or something not allowed. */ 
  1276.  
  1277. if(*loc != dot_end) /* Didn't find end. */
  1278.     {
  1279.     loc = p0; /* Reset position back to beginning. */
  1280.     goto mistake;
  1281.     }
  1282.  
  1283. if((dcode=dot_code(dots,uppercase(p0,n),loc,dot_const)) != 0) compress(dcode);
  1284. /* Search for match in table. */
  1285.  
  1286. /* Invalid dot constant. */
  1287. loc = p0; goto mistake;
  1288. }
  1289.  
  1290. @ Because preprocessor commands do not fit in with the rest of the syntax
  1291. of C, we have to deal with them separately.  One solution [Levy] is to enclose
  1292. such commands between special markers.  Thus, when a~'\.\#' is seen as the
  1293. first character of a line, |get_next| returns a special code
  1294. \\{left\_preproc} and raises a flag |preprocessing|.
  1295.  
  1296. (Unfortunately, Levy's solution didn't work in certain situations, and when
  1297. the preprocessor language was installed a different method was adopted.
  1298. Thus, parts of the code are asymmetrical. This should eventually be
  1299. improved, but it was considered more important to make it work at all.)
  1300.  
  1301. @d left_preproc OCTAL(260) // Begins a preprocessor command.
  1302. @d right_preproc OCTAL(261) // Ends a preprocessor command.
  1303.  
  1304. @<Raise prep...@>= 
  1305. @{
  1306. IN_COMMON ASCII HUGE *pinclude, HUGE *ppragma; 
  1307.     /* Strings for tokens |include| and |pragma|. */
  1308.  
  1309. @b
  1310. preprocessing = YES;
  1311. @<Check if next token is |include| or |pragma|@>;
  1312. return left_preproc;
  1313. }
  1314.  
  1315. @ An additional complication is the freakish use of~'\.<' and~'\.>' to delimit
  1316. a file name in lines that start with \&{\#include}.  We must treat this file
  1317. name as a string, and use the flag |sharp_include_line| to help.
  1318.  
  1319. Also, |#pragma|s can have arbitrary syntax, so we don't want to typeset it
  1320. as usual.  For those, we set |sharp_pragma_line|.  (Not yet used for anything.)
  1321.  
  1322. @<Check if next token is |include|...@>=
  1323. {
  1324. /* According to ANSI, white space may be skipped at beginning of line. */
  1325. while (*loc==@' ' || *loc==@'\t') 
  1326.     loc++;
  1327.  
  1328. if(STRNCMP(loc,pinclude,7)==0) 
  1329.     sharp_include_line = YES;
  1330. else if(STRNCMP(loc, ppragma, 7) == 0)
  1331.     sharp_pragma_line = YES;
  1332. }
  1333.  
  1334. @ Since the preprocessor has different reserved words than C~itself, we
  1335. include the preprocessor token with the identifier if it's first on a
  1336. preprocessor line.
  1337.  
  1338. @<Check if we're at the id...@>=
  1339.  
  1340. if(preprocessing && at_beginning) 
  1341.     {
  1342.     at_beginning = NO;
  1343.  
  1344. /* Preprocessor directives can have white space between the '\.\#' and the
  1345. name. */
  1346.     for( ; loc < limit; loc++)
  1347.         if(!(*loc==@' ' || *loc==tab_mark)) break;
  1348.  
  1349.     *(loc-1) = @'#'; /* Now we're positioned on an identifier beginning
  1350. with~|'#'|, with no intervening blanks. */
  1351.     return (eight_bits)prs_regular_code(GOTO_GET_IDENTIFIER);
  1352.     }
  1353.  
  1354. @ When we get to the end of a preprocessor line, we lower the flag and send
  1355. a code \\{right\_preproc}, unless the last character was the continuation
  1356. character'~\.\\'.
  1357.  
  1358. @<Check if we're at the end...@>=
  1359.  
  1360. chk_the_end:
  1361. if(chk_end)
  1362.  {
  1363. /* Continue to next line; also skip all lines that have continuation
  1364. character in column~1. */
  1365.   while (*loc==cont_char && loc==limit-1 && (preprocessing || free_Fortran))
  1366.     if (!get_line()) 
  1367.     return new_module; /* still in preprocessor mode */
  1368.  
  1369. /* Now we've gotten to the end of line, but it's not continued. */
  1370. if (loc>=limit)
  1371.     if(preprocessing) 
  1372.         {
  1373.         chk_end=preprocessing=sharp_include_line=sharp_pragma_line=NO;
  1374.         return right_preproc;
  1375.         }
  1376.     else if(Fortran88 
  1377.             && parsing_mode == OUTER 
  1378.             && auto_semi && limit > cur_buffer
  1379.             && !(limit[0] == @'@@' && limit[1] == @'m'))
  1380.         {
  1381.         loc = limit + 1;
  1382.         chk_end = NO;
  1383.         if(last_was_cmnt) 
  1384.             { // Comment has already been appended.
  1385.             last_was_cmnt = NO;
  1386.             if(lst_ampersand)
  1387.                 { // Deal with continuation before comment.
  1388.                 lst_ampersand = NO;
  1389.                 chk_end = YES;
  1390.                 if(!get_line())
  1391.                     {
  1392. ERR_PRINT(W,"Section ended in middle of Fortran-90 continuation");
  1393.                     return new_module;
  1394.                     }
  1395.                 APP_STR("\\indent");
  1396.                 goto chk_the_end;
  1397.                 }
  1398.             continue;
  1399.             }
  1400. @%        else return @'\n'; // or @';' ???  or nothing???
  1401.         }
  1402.  }
  1403.  
  1404. @ The following code assigns values to the combinations~\.{++}, \.{--},
  1405. \.{->}, \.{>=}, \.{<=}, \.{==}, \.{<<}, \.{>>}, \.{!=}, and~\.{\&\&}.  (For
  1406. FORTRAN, we also have~\.{//} and~\.{\^}.)  The compound assignment
  1407. operators in~C are indexed, all under the aegis of |compound_assignment|.
  1408.  
  1409. @d compress(c) if (loc++<=limit) return (eight_bits)c@;
  1410.  
  1411. @d COMPOUND(c,n) if(loc <= limit) {loc += n; assignment_token=c; 
  1412.         return (eight_bits)compound_assignment;}
  1413.  
  1414. @d CA_START OCTAL(100) /* The index into |op| is |CA_START + assignment_token|,
  1415. where |assignment_token| is one of the following. See |valid_op()| for
  1416. further details. */
  1417. @d plus_eq 0
  1418. @d minus_eq 01
  1419. @d star_eq 02
  1420. @d slash_eq 03
  1421. @d mod_eq 04
  1422. @d xor_eq 05
  1423. @d and_eq 06
  1424. @d or_eq 07
  1425. @d gt_gt_eq 010
  1426. @d lt_lt_eq 011
  1427. @d or_or_or 012
  1428.  
  1429. @<Glob...@>=
  1430.  
  1431. EXTERN eight_bits assignment_token; /* The particular one of the above
  1432.             compound assignment tokens. */
  1433.  
  1434. @
  1435. @<Compress two...@>=
  1436.  
  1437. switch(c) 
  1438.     {
  1439.   case (ASCII)begin_comment0:// Comment sent from FORTRAN or Ratfor |input_ln|.
  1440.     long_comment = YES;
  1441.     return begin_comment;
  1442.  
  1443.   case (ASCII)begin_comment1: // As above, but short comment.
  1444.     long_comment = NO;
  1445.     return begin_comment;
  1446.  
  1447.   case @'\\': 
  1448.     if(*loc==@'/' && !in_format && FORTRAN_LIKE(language)) 
  1449.         {
  1450.         compress(slash_slash); // `\.{\\/}' $\to$ `|@r \/|'.
  1451.         } 
  1452.     break;
  1453.  
  1454.   case @'/': 
  1455.     @<Cases for \.{\slashstar}, \.{//}, \.{/)}, and~\.{/=}@>@;
  1456.     break; 
  1457.  
  1458.   case @'(': 
  1459.     if(*loc == @'/' && !in_format) compress(left_array); 
  1460.     break;
  1461.  
  1462.   case @'+': 
  1463.     if (*loc==@'+') {compress(plus_plus); // `\.{++}' $\to$ `|++|'.
  1464.                 }
  1465.     else if(*loc==@'=') {COMPOUND(plus_eq,1); 
  1466.             // `\.{+=}' $\to$ `|+=|'. 
  1467.                 }
  1468.     break;
  1469.  
  1470.   case @'-': 
  1471.     if (*loc==@'-') {compress(minus_minus); // `\.{--}' $\to$ `|--|'.
  1472.         }
  1473.     else if (*loc==@'>') {compress(minus_gt); 
  1474.             // `\.{->}' $\to$ `|->|'. 
  1475.         } 
  1476.     else if(*loc==@'=') {COMPOUND(minus_eq,1); 
  1477.             // `\.{-=}' $\to$ `|-=|'.
  1478.         }
  1479.     break;
  1480.  
  1481.   case @'=': 
  1482.     if (*loc==@'=') {compress(eq_eq); // `\.{==}' $\to$ `|==|'.
  1483.         }
  1484.     else if(*loc==@'>') {compress(eq_gt); 
  1485.             // `\.{=>}' $\to$ `$\WPtr$'.
  1486.         } /* \FORTRAN-88's pointer assignment statement. */
  1487.     break;
  1488.  
  1489.   case @'>': 
  1490.     if (*loc==@'=') {compress(gt_eq); // `\.{>=}' $\to$ `|>=|'.
  1491.         }
  1492.     else if (*loc==@'>') 
  1493.         if(*(loc+1)==@'=') {COMPOUND(gt_gt_eq,2);
  1494.                 // `\.{>>=}' $\to$ `|>>=|'.
  1495.             }
  1496.         else {compress(gt_gt); // `\.{>>}' $\to$ `|>>|'.
  1497.             }
  1498.     break;
  1499.  
  1500.   case @'<': 
  1501.     if (*loc==@'=') {compress(lt_eq); // `\.{<=}' $\to$ `|<=|'.
  1502.         }
  1503.      else if (*loc==@'<') 
  1504.         if(*(loc+1)==@'=') 
  1505.             {COMPOUND(lt_lt_eq,2); 
  1506.                 // `\.{<<=}' $\to$ `|<<=|'. 
  1507.             }
  1508.         else {compress(lt_lt); // `\.{<<}' $\to$ `|<<|'.
  1509.             }
  1510.     else if(*loc==@'>') {compress(not_eq); 
  1511.             // `\.{<>}' $\to$ `|!=|'.
  1512.         } /* \FORTRAN-88 */
  1513.     break;
  1514.  
  1515.   case @'%': 
  1516.     if(*loc==@'=') {COMPOUND(mod_eq,1); // `\.{\%=}' $\to$ `|%=|'.
  1517.         }
  1518.     break;
  1519.  
  1520.   case @'&': 
  1521.     if (*loc==@'&') {compress(and_and); // `\.{\&\&}' $\to$ `|&&|'.
  1522.         }
  1523.     else if(*loc==@'=') 
  1524.         {
  1525.         COMPOUND(and_eq,1); // `\.{\&=}' $\to$ `|&=|'.
  1526.         }
  1527.     break;
  1528.  
  1529.   case @'|': 
  1530.     if (*loc==@'|') 
  1531.         {
  1532.         if(*(loc+1)==@'|')
  1533.             {
  1534.             COMPOUND(or_or_or,2); // `\.{\vb\vb\vb}' $\to$ `|||||'.
  1535.             }
  1536.         else compress(or_or); // `\.{\vb\vb}' $\to$ `||| |'.
  1537.         } 
  1538.     else if(*loc==@'=' && !FORTRAN_LIKE(language)) 
  1539.         {
  1540.         COMPOUND(or_eq,1); // `\.{\vertbar=}' $\to$ `||=|'. 
  1541.         }
  1542.     break;
  1543.  
  1544.   case @'!': 
  1545.     if(!in_format && (point_comments || *loc == @'!') )
  1546.         {
  1547.         if(*loc != @'!') loc--;
  1548.         long_comment = NO;
  1549.         compress(begin_comment); // \.{! Comment} or \.{!! Comment}.
  1550.         }
  1551.     else if (*loc==@'=') {compress(not_eq); // `\.{!=}' $\to$ `|!=|'.
  1552.         } 
  1553.     break;
  1554.  
  1555.   case @'*': 
  1556.     if(FORTRAN_LIKE(language) && (*loc == @'*') )
  1557.         {compress(star_star); // `\.{x**y}' $\to$ `|@r x**y|'.
  1558.         } /* Exponentiation. */
  1559.     else if(*loc==@'=') {COMPOUND(star_eq,1); // `\.{*=}' $\to$ `|*=|'.
  1560.         }
  1561.     break;
  1562.  
  1563.  case @'^': 
  1564.     if(*loc == @'^') {compress(star_star);}
  1565.     else if(FORTRAN_LIKE(language) && (loc < limit) )
  1566.          return star_star; // `\.{x\^y}' $\to$ `|@r x^y|'.
  1567.     else if(*loc==@'=') {COMPOUND(xor_eq,1); // `\.{\^=}' $\to$ `|^=|'.
  1568.         }
  1569.     break;
  1570.  
  1571.   case @':': 
  1572.     if(*loc==@':') compress(colon_colon);  // `\.{::}' $\to$ `|::|'.
  1573.     break;        
  1574.  
  1575.   case @'#': 
  1576.     @<Cases for \.{\#\#}, \.{\#!}, \.{\#:}, \.{\#.}, and~\.{\#<}@>@;
  1577.     break;
  1578.     }
  1579.  
  1580.  
  1581. @
  1582. @<Cases for \.{\slashstar}...@>=
  1583.  
  1584. if (*loc==@'*') 
  1585.     {
  1586.     long_comment = YES;
  1587.     compress(begin_comment); // \.{\slashstar\dots/starslash}
  1588.     }
  1589. else if(*loc == @'/')
  1590.     {
  1591.     if(C_LIKE(language) || language==TEX || (Cpp_comments &&
  1592. !in_format && FORTRAN_LIKE(language)))
  1593.         { /* Short comments are recognized in both~C and
  1594. \Cpp, and also in |TEX|. */
  1595.         long_comment = NO; /* \Cpp-style comment. */
  1596.         compress(begin_comment); // \.{//\dots}
  1597.         }
  1598.     else if(!in_format)
  1599.         {
  1600.         compress(slash_slash); /* Concatenation
  1601. operator~|@r \/|. Multiple slashes in |format| statements are just left
  1602. alone. */ 
  1603.         }
  1604.     }
  1605. else if(*loc == @')' && !in_format) 
  1606.     {compress(right_array); // `\.{/)}' $\to$ `$\SR$'.
  1607.     }
  1608. else if(*loc == @'=') 
  1609.     {COMPOUND(slash_eq,1); // `\.{(/}' $\to$ `$\LS$'.
  1610.     }
  1611.         
  1612. @
  1613. @<Cases for \.{\#\#}...@>=
  1614.  
  1615. switch(*loc)
  1616.     {
  1617.    case @'#':
  1618.     compress(paste); // `\.{\#\#}' $\to$ token `\.{\#\#}'.
  1619.     break;
  1620.  
  1621.    case @'!':
  1622.     compress(dont_expand);     // `\.{\#!}' $\to$ token `\.{\#!}'.
  1623.     break;
  1624.  
  1625.    case @':':
  1626.     compress(auto_label);     // `\.{\#:}' $\to$ token `\.{\#:}'.
  1627.     break;
  1628.  
  1629.    case @'.':
  1630.     compress(all_variable_args); // `\.{\#.}' $\to$ token `\.{\#.}'.
  1631.     break;
  1632.  
  1633.    case @'<':
  1634.     loc++;
  1635.     mac_mod_name = YES;
  1636.     @<Scan the module name and make |cur_module| point to it@>;  
  1637.     return macro_module_name;
  1638.  
  1639.    case @'\'':
  1640.    case @'"':
  1641.     if(phase == 1) loc++; // Skip over so string scanner doesn't complain.
  1642.     break;
  1643.     }
  1644.  
  1645. @ Different conventions are followed by \TeX\ and \cee\ to express octal
  1646. and hexadecimal numbers; it is reasonable to stick to each convention
  1647. withing its realm.  Thus the \cee\ part of a \.{WEB} file has octals
  1648. introduced by~\.0 and hexadecimals by~\.{0x}---e.g., \.{0377} or
  1649. \.{0xFF}---but \.{WEAVE} will print in italics or typewriter font,
  1650. respectively, and introduced by single or double quotes---e.g., |0377| or
  1651. |0xFF|.  \FWEB\ also adds binary constants, written as \.{0b10101} and
  1652. printed as |0b10101|.  In order to simplify the \TeX\ macro used to print
  1653. such constants, we replace some of the characters. (If you don't like the
  1654. way these constants look, you can easily change the macro; see
  1655. \.{fwebmac.tex}.) 
  1656.  
  1657. Notice that in this section and the next, |id_first| and |id_loc| are
  1658. pointers into the array |mod_text|, not into |cur_buffer|.
  1659.  
  1660. The next definitions correspond to the macros in \.{fwebmac.tex}.
  1661.  
  1662. @d BINARY_CODE @'&'     /* `\.{0b10101}' $\to$ `|0b10101|' */
  1663. @d OCTAL_CODE @'~'     /* `\.{0377}' $\to$ `|0377|' */
  1664. @d HEX_CODE @'`'     /* `\.{0xabc}' $\to$ `|0xabc|' */
  1665.  
  1666. @d CONSTANT_CODE @'#'    // Various kinds of constants.
  1667. @d FLOAT_CODE @'0'     // `\.{50000F}' $\to$ `|50000F|'.
  1668. @d LONG_CODE @'1'    /* `\.{50000L}' $\to$ `|50000L|' */
  1669. @d UNSIGNED_CODE @'2'    // `\.{50000U}' $\to$ `|50000U|'.
  1670. @d ULONG_CODE @'3'    // `\.{50000UL}' $\to$ `|50000UL|'.
  1671.  
  1672. @d EXP_CODE @'^'    /* `\.{(x+y)\^(a+b)}' $\to$ `|@r (x+y)^(a+b)|' */
  1673. @d HOLLERITH_CODE @'%'    /* `\.{5Hhello}' $\to$ `|@r 5Hhello|' */
  1674.  
  1675. @<Get a constant@>= 
  1676. @{
  1677. boolean decimal_point = NO;
  1678. ASCII prec_char;
  1679.  
  1680. @b
  1681. id_first = id_loc = mod_text + 1;
  1682.  
  1683. if (c==@'\\')
  1684.     { /* Probably octal---e.g., `\.{\\107}' */
  1685.     ASCII *loc0;
  1686.  
  1687.     if(*loc == @'/') goto mistake; // It's really `\.{\\/}'.
  1688.     *id_loc++ = OCTAL_CODE; // \.{WEBMAC} control code for octal.
  1689.     loc0 = loc;
  1690.     while (isOdigit(*loc)) *id_loc++ = *loc++;
  1691.     if(loc == loc0) return (eight_bits)c; // Not octal!
  1692.     }
  1693. else if (c==@'0') @<Get an octal, hex, or binary constant@>@;
  1694. else @<Get a decimal or Hollerith constant@>@;
  1695.  
  1696. @<Post-process constant@>@;
  1697.  
  1698. if(!decimal_point && at_beginning && 
  1699.     ((is_FORTRAN_(language) && !last_was_continued) ||
  1700.        (is_RATFOR_(language) && *loc == @':')))
  1701.         return stmt_label;
  1702.  
  1703. return constant;
  1704. }
  1705.  
  1706. @
  1707. @<Get an octal, hex...@>=
  1708. {
  1709.     if (*loc==@'x' || *loc==@'X') /* Hex---e.g., `\.{0xABC}' */
  1710.     {
  1711.     *id_loc++ = HEX_CODE; /* \.{WEBMAC} code for hex. */
  1712.     loc++;
  1713.         while (isXdigit(*loc)) *id_loc++ = *loc++;
  1714.     }
  1715.     else if(*loc==@'b' || *loc==@'B') /* Binary */
  1716.     {
  1717.     *id_loc++ = BINARY_CODE; /* \.{WEBMAC} code for binary. */
  1718.     loc++;
  1719.     while(isBdigit(*loc)) *id_loc++ = *loc++;
  1720.     }
  1721.     else if (isOdigit(*loc)) /* Octal---e.g., `\.{011}' */
  1722.      {
  1723.     *id_loc++ = OCTAL_CODE;
  1724.       while (isOdigit(*loc)) *id_loc++=*loc++;
  1725.     }
  1726.     else goto dec; /* decimal constant */
  1727. }
  1728.  
  1729. @ Decimal (\.{1.0e-5}) or \FORTRAN\ Hollerith constant (|@R 3Habc|).
  1730.  
  1731. @<Get a decimal...@>=
  1732. {
  1733.     if (c==@'.' && !isDigit(*loc)) goto mistake; /* Isn't a constant
  1734. like~`|.1|'. */
  1735.  
  1736. dec: 
  1737.     *id_loc++ = c;
  1738.     while (isDigit(*loc) || *loc==@'.') *id_loc++ = *loc++;
  1739. /* Optimistically, we'll include the decimal point with the constant.
  1740. However, in \Fortran\ we have to check for the possibility that it's an
  1741. integer followed by a dot constant. We do this immediately below. */
  1742.  
  1743.    decimal_point = BOOLEAN(*(loc-1) == @'.');
  1744.  
  1745.    if(FORTRAN_LIKE(language))
  1746.     if(decimal_point) /* Check for dot constant. */
  1747.         {
  1748.         if(is_dot()) /* It's an integer constant
  1749. followed by a dot constant. */
  1750.             {
  1751.             id_loc--;
  1752.             loc--;
  1753.             return constant; 
  1754.             }
  1755.         }
  1756.     else if(*loc == @'h' || *loc == @'H') @<Copy Hollerith constant@>;
  1757.  
  1758.    if(in_format) return constant;
  1759.  
  1760.     prec_char = *loc;
  1761.  
  1762.     if (prec_char==@'e' || prec_char==@'E' || (FORTRAN_LIKE(language) &&
  1763.     (prec_char==@'d' || prec_char==@'D' ||
  1764.     prec_char==@'q' || prec_char==@'Q')))
  1765.         @<Get the exponent field@>@;
  1766. }
  1767.  
  1768. @ Process the exponent part of a floating-point constant such as
  1769. \.{1.5e-10} |@e = 1.5e-10|.
  1770.  
  1771. @<Get the expon...@>=
  1772. {
  1773. *id_loc++ = EXP_CODE;    // Control character for WEB power of ten.
  1774. *id_loc++ = A_TO_UPPER(prec_char);
  1775.  
  1776. loc++; // Skip past the exponent character.
  1777.  
  1778. if (*loc==@'+' || *loc==@'-') *id_loc++ = *loc++;
  1779.  
  1780. while (isDigit(*loc)) *id_loc++ = *loc++;
  1781. }
  1782.  
  1783. @ Hollerith constants have the form \.{3Habc}.
  1784. @<Copy Hol...@>=
  1785. @{
  1786. int k,n;
  1787.  
  1788. @b
  1789. *id_loc = '\0'; /* Temporarily make a true terminated string. */
  1790. n = ATOI(id_first); /* Convert the string to an integer constant. */
  1791. *id_loc++ = HOLLERITH_CODE; /* Control character for WEB Hollerith macro. */
  1792. ++loc;    /* Skip the |'H'|. */
  1793.  
  1794. for(k=0; k<n; ++k) /* Copy the actual string. */
  1795.     *id_loc++ = *loc++;
  1796.  
  1797. return constant;
  1798. }
  1799.  
  1800. @ We don't yet handle correctly things like~\.{50UL}; it comes out like~|50UL|.
  1801.  
  1802. @<Post-process...@>=
  1803.  
  1804. if (C_LIKE(language))
  1805.     {
  1806.     switch(*loc)
  1807.         {
  1808.        case @'l':
  1809.        case @'L':
  1810.         *id_loc++ = CONSTANT_CODE;
  1811.         loc++;
  1812.         if(*loc == @'u' || *loc == @'U') 
  1813.             {
  1814.             *id_loc++ = ULONG_CODE;
  1815.             loc++;
  1816.             }
  1817.         else *id_loc++ = LONG_CODE;
  1818.         break;
  1819.  
  1820.        case @'u':
  1821.        case @'U':
  1822.         *id_loc++ = CONSTANT_CODE;
  1823.         loc++;
  1824.         if(*loc == @'l' || *loc == @'L') 
  1825.             {
  1826.             *id_loc++ = ULONG_CODE;
  1827.             loc++;
  1828.             }
  1829.         else *id_loc++ = UNSIGNED_CODE;
  1830.         break;
  1831.  
  1832.        case @'f':
  1833.        case @'F':
  1834.         *id_loc++ = CONSTANT_CODE;
  1835.         *id_loc++ = FLOAT_CODE;
  1836.         loc++;
  1837.         break;
  1838.         }
  1839.     }
  1840. else if(Fortran88) @<Absorb optional kind-param@>@;
  1841.  
  1842. @ In \Fortran-90, there can be optional kind parameters after a constant,
  1843. started off by an underscore. Example: |@r 50_4|. 
  1844. @<Absorb optional kind-param@>=
  1845. {
  1846. if(*loc == @'_')
  1847.     while(is_kind(*loc))
  1848.         *id_loc++ = *loc++;
  1849. }
  1850.  
  1851. @ Code strings and character constants, delimited by double and single
  1852. quotes, respectively, can contain newlines or instances of their own
  1853. delimiters if they are protected by a backslash (for~C) or if the delimiter
  1854. is repeated (for \FORTRAN).  We follow this convention, but do not allow
  1855. the string to be longer than |longest_name|.  Special codes are inserted
  1856. every |NBREAK| characters so that \TeX\ can break the strings.  (The count
  1857. is restarted after commas, which are also treated as discretionary breaks.)
  1858.  
  1859. @d discretionary_break OCTAL(177)
  1860. @d NBREAK 25 // \bf Put into style file?
  1861.  
  1862. @<Glob...@>=
  1863.  
  1864. EXTERN boolean insert_breaks SET(YES); /* No breaks inserted during limbo
  1865.             text processing. */
  1866.  
  1867. @ Here we absorb a string.  Examples:  \.{"abc"}, \.{'\\n'}, or
  1868. \.{<file\_name>}. 
  1869.  
  1870. @<Part 1@>=@[
  1871.  
  1872. eight_bits get_string FCN((c,boz))
  1873.     ASCII c C0("What started the string")@;
  1874.     ASCII boz C1("The boz character, or 0.")@;
  1875. {
  1876. ASCII delim = c; /* what started the string */
  1877. ASCII right_delim = c;
  1878. int level,kount;
  1879. boolean equal_delims;
  1880.  
  1881.   id_first = mod_text + 1;
  1882.   id_loc = mod_text;
  1883.  
  1884. /* ???? */
  1885.   if (delim==@'\'' && *(loc-2)==@'@@') {*++id_loc=@'@@'; *++id_loc=@'@@';}
  1886.   *++id_loc=delim;
  1887.  
  1888. @<Determine the right matching delimiter@>@;
  1889.  
  1890. kount = 0; /* How far since last discretionary line break command. */
  1891.  
  1892. WHILE()
  1893. { /* Scan for end of string. */
  1894.     if (loc>=limit) @<Check for continued string@>@;
  1895.  
  1896.     if ((c=*loc++)==delim) @<Handle left-hand delimiter@>@;
  1897.  
  1898.   if(c==right_delim)
  1899.     if(--level == 0)
  1900.         {
  1901.           if (++id_loc<=mod_end) *id_loc=c;
  1902.          break; /* Found end of string for unequal delims. */
  1903.         }
  1904.  
  1905. /* Handle a final backslash. */
  1906.     if ((c==cont_char) && 
  1907.          (C_LIKE(language) || (is_FORTRAN_(language) && free_form_input)))
  1908.     if (loc>=limit) continue;
  1909.       else if (++id_loc<=mod_end) 
  1910.         {
  1911.             *id_loc = c; c=*loc++;
  1912.             }
  1913.  
  1914. /* Store the character. */
  1915.     if (++id_loc<=mod_end) *id_loc=c;
  1916.  
  1917.     @<Insert discretionary line-break commands@>@;
  1918.   } /* End of \&{while}. */
  1919.  
  1920.   if (id_loc>=mod_end) 
  1921.     {
  1922.     SET_COLOR(error);
  1923.     printf("\n! String too long: ");
  1924. @.String too long@>
  1925.     ASCII_write(mod_text+1,25);
  1926.     printf("..."); mark_error;
  1927.       }
  1928.  
  1929.   id_loc++;
  1930.  
  1931. @<Check for boz constant@>@;
  1932.  
  1933. return stringg;
  1934. }
  1935.  
  1936. @
  1937. @<Determine the right...@>=
  1938. {
  1939. switch(delim)
  1940.     {
  1941.    case @'<':
  1942.     right_delim=@'>'; // for file names in |#include| lines.
  1943.     break;
  1944.  
  1945.    case @'(':
  1946.      right_delim = @')'; // For m4 \&{include} or related functions.
  1947.     sharp_include_line = NO;
  1948.     break;
  1949.  
  1950.    case @'[':
  1951.     right_delim = @']'; // For auto insertions in macro definitions.
  1952.     break;
  1953.     }
  1954.  
  1955. level = 1; // For searching for balanced delimiters.
  1956.  
  1957. equal_delims = BOOLEAN(right_delim==delim);
  1958. }
  1959.  
  1960. @
  1961. @<Check for continued string@>=
  1962. {
  1963.       if( (equal_delims || chk_ifelse) && *(limit-1)!=cont_char) 
  1964.         {
  1965.             err_print(W,"String %s with '%s%c' didn't end",
  1966.             BTRANS, delim==@'\'' ? "\\" : "", XCHR(delim)); 
  1967.             loc=limit; break;
  1968. @.String didn't end@>
  1969.             }
  1970.  
  1971.       if(!get_line())
  1972.         {
  1973.             err_print(W,"Input ended in middle of string beginning with \
  1974. '\\%c'",XCHR(delim)); 
  1975.             loc=cur_buffer;
  1976.         break; 
  1977. @.Input ended in middle of string@>
  1978.           }
  1979.     else
  1980.        {
  1981. /* Now the continuation of the string is in the buffer.  If appropriate,
  1982. skip over beginning white space and backslash. */
  1983.     if(bslash_continued_strings)
  1984.         {
  1985.         for(; loc < limit; loc++)
  1986.             if(*loc != @' ' && *loc != tab_mark) break;
  1987.  
  1988.         if(*loc == cont_char) loc++; /* Move past the backslash. */
  1989.         else err_print(W,"Inserted '\\%c' at beginning of continued \
  1990. string",XCHR(cont_char));
  1991.         }
  1992.         }
  1993.  }
  1994.  
  1995. @
  1996. @<Handle left-hand delim...@>=
  1997. {
  1998. level++;
  1999.  
  2000. if (++id_loc<=mod_end) *id_loc=c;
  2001.  
  2002. if(!equal_delims) continue;
  2003.  
  2004. if(FORTRAN_LIKE(language) && (*loc == delim) ) 
  2005.     ++loc; /* Copy over repeated delimiter. */
  2006. else  break;  /* Found end of string. */
  2007. }    
  2008.  
  2009. @ Insert discretionary line-break command  every |NBREAK|
  2010. characters. Since the string macro also inserts discretionary breaks after
  2011. commas, we reset the counter to~0 after a comma. As one annoyance, we don't
  2012. want to insert a break immediately after an~`\.{@@}', because the output
  2013. routines would otherwise get confused.
  2014. @<Insert discretionary line-break...@>=
  2015.  
  2016. if(insert_breaks)
  2017.     if(c == @',') kount = 0;
  2018.     else if(++kount >= NBREAK && c != @'@@' && ++id_loc<=mod_end)
  2019.             {
  2020.             kount = 0;
  2021.             *id_loc = discretionary_break;
  2022.             }
  2023.  
  2024. @ In \Fortran-90, we have \It{boz-constants}---binary, octal, or
  2025. hexadecimal constants that look like~`\.{B'011'}', `\.{O'077'}',
  2026. or~`\.{Z'FF'}'. (The single quotes may be replaced by double quotes.)
  2027. These constants may appear only in |@r data| statements.
  2028.  
  2029. @<Check for boz...@>=
  2030. {
  2031. if(FORTRAN_LIKE(language))
  2032.     if(boz)
  2033.         @<Handle boz constant@>@;
  2034.     else
  2035.         @<Handle VAX extensions of hex or octal constants@>@;
  2036. }
  2037.  
  2038. @ At this point we already know we're dealing with a boz constant.
  2039. @<Handle boz...@>=
  2040. {
  2041. switch(boz)
  2042.     {
  2043.     case @'B':
  2044.         *id_first = BINARY_CODE;
  2045.         break;
  2046.  
  2047.     case @'O':
  2048.         *id_first = OCTAL_CODE;
  2049.         break;
  2050.  
  2051.     case @'Z':
  2052.         *id_first = HEX_CODE;
  2053.         break;
  2054.     }
  2055.         
  2056. id_loc--;
  2057. return constant;
  2058. }
  2059.  
  2060. @ Handle the VAX extensions of hex or octal
  2061. constants---e.g., \.{'abc'X} or \.{'123'O}.
  2062. @<Handle VAX exten...@>=
  2063. if(*loc==@'X' || *loc==@'x')
  2064.     {
  2065.     *id_first = HEX_CODE;    /* Overwrite opening delimiter. */
  2066.     @<Finish VAX hex/octal constant.@>@;
  2067.     }
  2068. else if(*loc==@'O' || *loc==@'o')
  2069.     {
  2070.     *id_first = OCTAL_CODE; /* Octal */
  2071.     @<Finish VAX hex...@>@;
  2072.     }
  2073. }
  2074.  
  2075. @<Finish VAX hex...@>=
  2076.  
  2077.     loc++;    /* Skip the ending signifier. */
  2078.     id_loc--; /* Forget closing delimiter. */
  2079.     return constant;
  2080.  
  2081. @
  2082. @<Glob...@>=
  2083.  
  2084. EXTERN boolean doing_cdir SET(NO);
  2085.  
  2086. @ After an \.{@@}~sign has been scanned, the next character tells us
  2087. whether there is more work to do.  Note that lower- and upper-case control
  2088. codes are generally treated as variants of the same fundamental code; to
  2089. distinguish them, we set the |upper_case_code| flag.  When the code is in
  2090. upper case, it does not automatically issue an implicit~\.{@@[}, for example.
  2091.  
  2092. @<Part 1@>=@[
  2093. GOTO_CODE get_control_code(VOID)
  2094. {
  2095. eight_bits cc; /* The |ccode| value. */
  2096.  
  2097. @b
  2098. c = *loc++;
  2099. SET_CASE(c); // Set the |upper_case_code| flag.
  2100.  
  2101. /* Deflect a verbatim comment beginning with `\.{@@\slashstar}'. */
  2102. if( (c==@'/' && (*loc==@'*' || *loc==@'/')) || 
  2103.         c==(ASCII)begin_comment0 || c==(ASCII)begin_comment1)
  2104.     return GOTO_MISTAKE; 
  2105.  
  2106. switch(cc = ccode[c]) 
  2107.     {
  2108.    case no_index:
  2109.     index_flag = NO;
  2110.     return MORE_PARSE;
  2111.  
  2112.    case yes_index:
  2113.     INDEX_SHORT;
  2114.     return MORE_PARSE;
  2115.  
  2116.     case defd_at:
  2117.     if(mark_defined.generic_name)
  2118.         {
  2119.         defd_switch = YES; // `\.{@@[}'.
  2120.         defd_type = GENERIC_NAME;
  2121.         } //   \bf NOTE: Falls through.
  2122.  
  2123.     case underline: 
  2124.     xref_switch = def_flag; // `\.{@@\_}'
  2125.     return MORE_PARSE;
  2126.  
  2127.    case implicit_reserved:
  2128.     if(mark_defined.imp_reserved_name)
  2129.         {
  2130.         typd_switch = defd_switch = YES; // `\.{@@`}'.
  2131.         defd_type = IMPLICIT_RESERVED;
  2132.         xref_switch = def_flag;
  2133.         }
  2134.     return MORE_PARSE;
  2135.  
  2136.     case switch_math_flag: math_flag=!math_flag;  // `\.{@@\$}'
  2137.     return MORE_PARSE;
  2138.  
  2139. #ifdef DEBUG
  2140.     case trace: tracing=c-@'0'; // `\.{@@0}', `\.{@@1}', `\.{@@2}'
  2141.     return MORE_PARSE;
  2142. #endif /* |DEBUG| */
  2143.  
  2144. /* For language switches, we set the |language|, then
  2145. send back a single code |begin_language|. When we process this, we'll then
  2146. append another 8-bit code with the language number itself. */
  2147.  
  2148.    @<Specific language cases@>:
  2149.     loc--; // Falls through to general case below.
  2150.  
  2151.    case L_switch:
  2152.     {
  2153.     @<Set the |language|...@>@;
  2154.     return begin_language; // `\.{@@L$l$}'
  2155.     }
  2156.  
  2157.    case begin_nuweb:
  2158.     ERR_PRINT(W,"@@N ignored; must appear before beginning of code part");
  2159.     return MORE_PARSE;
  2160.  
  2161.     case xref_roman: case xref_wildcard: case xref_typewriter:
  2162.     case TeX_string: @<Scan to the next \.{@@>}@>@; /* `\.{@@\^\dots@@>}',
  2163. `\.{@@9\dots@@>}', `\.{@@.\dots@@>}', and `\.{@@t\dots@@>}'. */
  2164.  
  2165.     case module_name: 
  2166.     mac_mod_name = NO; // Used as a flag for macro processing.
  2167.     @<Scan the module name and make |cur_module| point to it@>@;
  2168.     return module_name; // `\.{@@<\dots@@>}'
  2169.  
  2170.     case new_output_file:
  2171.     @<Scan the output file name@>@;
  2172.     return cc;
  2173.  
  2174.     case invisible_cmnt:
  2175.     if(*loc == @'%')
  2176.         eat_blank_lines = YES;
  2177.     loc = limit + 1; // Skip the line.
  2178.     return MORE_PARSE; // `\.{@@\%}
  2179.  
  2180.     case compiler_directive:
  2181.     case Compiler_Directive:
  2182.     long_comment = NO;
  2183.     doing_cdir = YES;
  2184.     return begin_comment; // `\.{@@!}' or `\.{@@?}'
  2185.  
  2186.     case verbatim: @<Scan a verbatim string@>@; // `\.{@@=\dots@@>}'
  2187.  
  2188.     case ascii_constant: return get_string(c,'\0'); // `\.{@@'\dots'}'
  2189.  
  2190.     case big_line_break: // `\.{@@\#}'
  2191.     if(loc >= limit) return cc;
  2192.  
  2193.     @<Process possible pre...@>; // In \.{typedefs.web}.
  2194.     return cc;
  2195.  
  2196.     case begin_bp:
  2197.     return @'{'; // Ought to improve this, to mark the debugging locations.
  2198.  
  2199.     case USED_BY_NEITHER:
  2200.     if(phase==1) 
  2201.         err_print(W,"Invalid `@@%c' ignored",XCHR(c));
  2202.  
  2203.     return ignore;
  2204.  
  2205.     default: return cc;
  2206.     }
  2207. }
  2208.  
  2209. @ The occurrence of a module name sets |xref_switch| to zero, because the
  2210. module name might (for example) follow \&{int}.
  2211.  
  2212. @<Scan the module name...@>= 
  2213. @{
  2214. ASCII HUGE *k; // Pointer into |mod_text|.
  2215. static ASCII ell[] = @"...";
  2216. static ASCII bad_mod_name[] = @"!!! {\\it Incompatible} !!!";
  2217.  
  2218. @b
  2219. @<Put module name into |mod_text|@>@;
  2220.  
  2221. if (k-mod_text > 3 && STRNCMP(k-2,ell,3)==0)
  2222.     cur_module = prefix_lookup(mod_text+1,k-3); 
  2223. else cur_module = mod_lookup(mod_text+1,k);
  2224.  
  2225. if(!cur_module) 
  2226.       cur_module = mod_lookup(bad_mod_name,bad_mod_name+STRLEN(bad_mod_name)-1); 
  2227.  
  2228. if(cur_module)
  2229.     {
  2230. @#if 0
  2231.     language = (LANGUAGE)cur_module->Language;
  2232. @#endif
  2233.     params = cur_module->mod_info->params;// Restore state for this module.
  2234.     frz_params();
  2235.     }
  2236.  
  2237. xref_switch = NO; 
  2238.  
  2239. /* The actual return value can be either |module_name| or
  2240. |macro_module_name| and is put in explicitly right after the use of this
  2241. module in the code. */ 
  2242. }
  2243.  
  2244. @ Module names are placed into the |mod_text| array with consecutive
  2245. spaces, tabs, and carriage-returns replaced by single spaces. There will be
  2246. no spaces at the beginning or the end. (We set |mod_text[0]=' '| to
  2247. facilitate this, since the |mod_lookup| routine uses |mod_text[1]| as the
  2248. first character of the name.)
  2249.  
  2250. @<Set init...@>=
  2251.  
  2252. mod_text[0] = @' ';
  2253.  
  2254. @ Here we copy the text of the module name, stripping off white space from
  2255. the front and back.  Also, we convert any real semicolons into interior
  2256. semis.  This helps out with language switches between \Fortran\ and~C, for
  2257. example.  If the global language were~C, then a module name that should be
  2258. read in \Fortran\ will be first be absorbed in~C because the parser doesn't
  2259. know yet which language it will be.
  2260.  
  2261. @<Put module name...@>=
  2262. {
  2263. int mlevel = 1; // For nested module names.
  2264.  
  2265. k = mod_text;
  2266.  
  2267. WHILE()
  2268.     {
  2269.     if (loc>limit && !get_line())
  2270.         {
  2271.         ERR_PRINT(W,"Input ended in section name");
  2272. @.Input ended in section name@>
  2273.         loc=cur_buffer+1; break;
  2274.         }
  2275.  
  2276.       c = *loc;
  2277.       @<If end of name, |break|@>;
  2278.       loc++; 
  2279.  
  2280.     if (k<mod_end) k++;
  2281.  
  2282.     switch(c)
  2283.         {
  2284.        case @' ':
  2285.        case tab_mark:
  2286.         c=@' '; if (*(k-1)==@' ') k--; // Compress white space.
  2287.         break;
  2288.  
  2289.        case @';':
  2290.         c = interior_semi;
  2291.         break;
  2292.         }
  2293.  
  2294.     *k = c;
  2295.     }
  2296.  
  2297. if (k>=mod_end) 
  2298.     {
  2299.   SET_COLOR(warning);
  2300.   printf("\n! Section name too long: ");
  2301. @.Section name too long@>
  2302.   ASCII_write(mod_text+1,25);
  2303.   printf("..."); mark_harmless;
  2304.     }
  2305.  
  2306. if (*k==@' ' && k>mod_text) k--; // Trailing blanks.
  2307. }
  2308.  
  2309. @<If end of name,...@>=
  2310.  
  2311. if (c==@'@@') 
  2312.     {
  2313.     c = *(loc+1);
  2314.  
  2315.     if (c==@'>')
  2316.         {
  2317.         if(--mlevel == 0)
  2318.             {
  2319.             loc+=2; break;
  2320.             }
  2321.         }
  2322.     else if(c==@'<') mlevel++;
  2323.  
  2324.       if (ccode[c]==new_module) 
  2325.         {
  2326.         ERR_PRINT(W,"Section name didn't end"); break;
  2327. @.Section name didn't end@>
  2328.         }
  2329.  
  2330.       *(++k) = @'@@'; loc++; // Now |c==*loc| again.
  2331.     }
  2332.  
  2333. @ This fragment is used for skipping over control text, such as
  2334. `\.{@@t\dots@@>}'. 
  2335.  
  2336. @<Scan to the next...@>= 
  2337. {
  2338. cc = ccode[*(loc-1)]; /* Is this statement redundant? */
  2339. id_first=loc; *(limit+1)=@'@@';
  2340.  
  2341. while (*loc!=@'@@') loc++;
  2342.  
  2343. id_loc=loc;
  2344.  
  2345. if (loc++>limit) 
  2346.     {
  2347.     ERR_PRINT(W,"Control text didn't end"); loc=limit; return cc;
  2348. @.Control text didn't end@>
  2349.     }
  2350.  
  2351. if (*loc++!=@'>') ERR_PRINT(W,"Control codes are forbidden in control text");
  2352. @.Control codes are forbidden...@>
  2353.  
  2354. return cc;
  2355. }
  2356.  
  2357. @ At the present point in the program we have |*(loc-1)=verbatim|; we set
  2358. |id_first| to the beginning of the string itself, and |id_loc| to its
  2359. ending-plus-one location in the buffer.  We also set~|loc| to the position
  2360. just after the ending delimiter.
  2361.  
  2362. @<Scan a verbatim string@>= 
  2363. {
  2364. id_first=loc++; 
  2365.  
  2366. *(limit+1)=@'@@'; *(limit+2)=@'>';
  2367.  
  2368. while (*loc!=@'@@' || *(loc+1)!=@'>') loc++;
  2369.  
  2370. if (loc>=limit) ERR_PRINT(W,"Verbatim string didn't end");
  2371. @.Verbatim string didn't end@>
  2372.  
  2373. id_loc=loc; loc+=2;
  2374.  
  2375. return (verbatim);
  2376. }
  2377.  
  2378. @* PHASE ONE PROCESSING.
  2379. We now have accumulated enough subroutines to make it possible to carry out
  2380. \.{WEAVE}'s first pass over the source file. If everything works right,
  2381. both phase one and phase two of \.{WEAVE} will assign the same numbers to
  2382. modules, and these numbers will agree with what \.{TANGLE} does.
  2383.  
  2384. The global variable |next_control| often contains the most recent output of
  2385. |get_next|; in interesting cases, this will be the control code that ended
  2386. a module or part of a module.
  2387.  
  2388. @<Global...@>=
  2389.  
  2390. EXTERN eight_bits next_control; /* control code waiting to be acting upon */
  2391.  
  2392. @ The overall processing strategy in phase one has the following
  2393. straightforward outline.
  2394.  
  2395. @<Part 1@>=@[
  2396.  
  2397. SRTN phase1(VOID) 
  2398. {
  2399. LANGUAGE language0=language;
  2400.  
  2401. phase = 1; 
  2402. the_part = LIMBO;
  2403.  
  2404. rst_input(); 
  2405. reading(web_file_name,(boolean)(tex_file==stdout));
  2406. module_count = 0;
  2407. skip_limbo(); // Skip stuff before any module (but process language commands).
  2408. change_exists = NO;
  2409.  
  2410. /* Remember the language to put into force at the beginning of each module.
  2411.   |language| may have been set from the command line, by default (nothing on
  2412.   the command line), or by explicit~\.{@@c}, \.{@@r}, \.{@@n},
  2413. or~\.{@@L$l$} commands  during the limbo phase. */
  2414. chk_override(language0);
  2415. fin_language(); /* Make sure all flags are initialized properly. */
  2416. global_params = params;
  2417.  
  2418. while (!input_has_ended)
  2419.   @<Store cross-reference data for the current module@>;
  2420.  
  2421. chngd_module[module_count]=change_exists;
  2422.   /* the index changes if anything does */
  2423.  
  2424. @<Print error messages about unused or undefined module names@>;
  2425. }
  2426.  
  2427. @<Store cross-reference data...@>=
  2428. {
  2429. the_part = TEX_;
  2430.  
  2431.   if (++module_count==(sixteen_bits)max_modules) 
  2432.     OVERFLW("section numbers",ABBREV(max_modules)); 
  2433.  
  2434.   chngd_module[module_count]=NO; // It will become |YES| if any line changes.
  2435.  
  2436.     progress();
  2437.  
  2438. /* All modules start off in the global language. */
  2439. params = global_params;
  2440. frz_params();
  2441.  
  2442.   @<Store cross-references in the \TeX\ part of a module@>;
  2443.   @<Store cross-references in the definition part of a module@>;
  2444.   @<Store cross-references in the \cee\ part of a module@>;
  2445.  
  2446.   if(chngd_module[module_count]) 
  2447.     change_exists=YES;
  2448.  
  2449. typd_switch = defd_switch = NO; // Don't propagate beyond one module.
  2450. }
  2451.  
  2452. @ The |C_xref| subroutine stores references to identifiers in \cee\ text
  2453. material beginning with the current value of |next_control| and continuing
  2454. until |next_control| is~`\.\{' or~`\v', or until the next ``milestone'' is
  2455. passed (i.e., |next_control>=formatt|). If |next_control>=formatt| when
  2456. |C_xref| is called, nothing will happen; but if |next_control="|"| upon
  2457. entry, the procedure assumes that this is the~`\v' preceding \cee\ text
  2458. that is to be processed.
  2459.  
  2460. The program uses the fact that our internal code numbers satisfy the
  2461. relations |xref_roman=identifier+roman| and |xref_wildcard=identifier
  2462. +wildcard| and |xref_typewriter=identifier+typewriter| and |normal=0|.
  2463.  
  2464. @<Part 1@>=@[
  2465.  
  2466. SRTN C_xref FCN((part0,mode0))
  2467.     PART part0 C0("")@;
  2468.     PARSING_MODE mode0 C1("")@;
  2469. {
  2470. PARAMS outer_params;
  2471. PARSE_PARAMS parse_params0;
  2472. name_pointer p; /* a referenced name */
  2473.  
  2474. parsing_mode = mode0;
  2475.  
  2476. if(parsing_mode == INNER)
  2477.     {
  2478.     outer_params = params; /* Store whole structure. */
  2479.     parse_params0 = parse_params;
  2480.     }
  2481.  
  2482. if(language == LITERAL)
  2483.     next_control = begin_meta;
  2484.  
  2485. do_inside = YES;
  2486.  
  2487. while (next_control<formatt) 
  2488.     {
  2489.     switch(next_control)
  2490.         {
  2491.          case begin_language:
  2492. @<Handle a possible language switch in the middle of the module@>@;
  2493.         break;
  2494.  
  2495.        case toggle_output:
  2496.         @<Toggle output@>@;
  2497.         break;
  2498.  
  2499.        case begin_meta:
  2500.         @<Skip over meta-comment@>@;
  2501.         break;
  2502.  
  2503.        case identifier:
  2504.        case xref_roman:
  2505.        case xref_wildcard:
  2506.        case xref_typewriter:
  2507.         p=id_lookup(id_first,id_loc,
  2508.             (eight_bits)(next_control-identifier));
  2509.  
  2510.         new_xref(part0,p); 
  2511.  
  2512.         if(part0 == DEFINITION) 
  2513.             defd_switch = NO; /* Prevent the implicit~\.{@@[}
  2514. from propagating beyond the first identifier. */ 
  2515.  
  2516.         if(next_control==identifier && C_LIKE(language)
  2517.                 && parsing_mode == OUTER)
  2518.             {
  2519.             if(p->ilk == typedef_like)
  2520.                 @<Mark \&{typedef} variable@>@;
  2521.             else if(p->ilk == class_like)
  2522.                 @<Mark \&{class} variable@>@;
  2523.             }
  2524.         break;
  2525.  
  2526.        case stringg:
  2527.         if(sharp_include_line && phase == 1 && read_iformats 
  2528.                 && C_LIKE(language)) 
  2529.             get_iformats();
  2530.  
  2531.         break;
  2532.         }
  2533.  
  2534.     next_control=get_next();
  2535.  
  2536.     if ( next_control==@'|' || next_control==begin_comment) break;
  2537.     }
  2538.  
  2539. end_xref:
  2540.   if(parsing_mode==INNER)
  2541.     {
  2542.     params = outer_params;
  2543.     frz_params();
  2544.     parse_params = parse_params0;
  2545.     parsing_mode = OUTER;
  2546.     }
  2547. }
  2548.  
  2549. @<Glob...@>=
  2550.  
  2551. IN_COMMON outer_char wbprefix[MAX_FILE_NAME_LENGTH];
  2552. EXTERN boolean do_inside; // Cross-reference stuff inside a \&{typedef}?
  2553. EXTERN boolean qtd_file; // Is the include file quoted?
  2554.  
  2555. #ifndef L_tmpnam
  2556. #define L_tmpnam 25
  2557. #endif
  2558.  
  2559. EXTERN outer_char temp_in[L_tmpnam], temp_out[L_tmpnam];
  2560.     // Names of temporary files used in |get_iformats|.
  2561.  
  2562. @ To scan an include file for |typedef| and/or |@c++ class| statements, we
  2563. use two temporary files whose names are |temp_in| and |temp_out|.  These
  2564. are created once, the first time |get_iformats| is called (so we don't call
  2565. |tmpnam| possible many times).  The include command is written into
  2566. |temp_in|.  By means of issuing a |system| command, the C preprocessor
  2567. expands that command and writes its results to |temp_out|.  Then \FWEAVE\
  2568. parses that file, cross-referencing only the |typedef| and/or |@c++ class|
  2569. variables.
  2570.  
  2571. Presently, this only works for the \.{gcc} and \.{g++} compilers.
  2572.  
  2573. @<Part 1@>=@[
  2574.  
  2575. SRTN
  2576. get_iformats(VOID)
  2577. {
  2578. int n, new_depth;
  2579. outer_char file_name[256], temp[100];
  2580. FILE *ftemp_in;
  2581. PART part0 = CODE;
  2582.  
  2583. if(!temp_in[0])
  2584.     mktmp(temp_in, 
  2585.        language==C ? wt_style.output_ext.C_ : wt_style.output_ext.Cpp_);
  2586.  
  2587. if((ftemp_in = FOPEN(temp_in, "w")) == NULL)
  2588.     {
  2589.     printf("\n! Can't open temporary file `%s'", temp_in);
  2590.     mark_harmless;
  2591.     read_iformats = NO;
  2592.     return;
  2593.     }
  2594.  
  2595. if(!temp_out[0])
  2596.     mktmp(temp_out, (outer_char *)""); 
  2597.         /* We don't open the output file here, as \.{cpp} may not
  2598.             write into it if it's open. */
  2599.  
  2600. preprocessing = sharp_include_line = NO;
  2601.  
  2602. /* Copy include file name, include delimiters. */
  2603. STRNCPY(file_name, id_first, n=PTR_DIFF(int, id_loc, id_first));
  2604. file_name[n] = '\0';
  2605. to_outer((ASCII HUGE *)file_name);
  2606.  
  2607. qtd_file = BOOLEAN(file_name[0] == '"'); 
  2608.     // Is this file name quoted (i.e., look locally)?
  2609.  
  2610. /* Write the include file command to temporary file, so the preprocessor
  2611. can read it. */
  2612. fprintf(ftemp_in, "#include %s\n", file_name);
  2613. fclose(ftemp_in);
  2614.  
  2615. /* Create a command to run the preprocessor.  We tell the preprocessor to
  2616. look first in the |wbprefix| directory, then in the current directory.
  2617. (Note the use of the \.{-I.} command of \.{gcc}, which looks in the
  2618. directory current when the compiler was invoked.) */ 
  2619. sprintf((char *)temp, "\n%s -E -P -I%s -I. -o %s %s",
  2620.     language==C ? "gcc" : "g++",
  2621.     *wbprefix ? (char *)wbprefix : ".", 
  2622.     temp_out, temp_in);
  2623.  
  2624. if(!rmv_files)
  2625.     puts((char *)temp); 
  2626.         // Echo the |system| command that runs the preprocessor.
  2627.  
  2628. system((CONST char *)temp);
  2629.  
  2630. @<Deflect the input file to be \.{temp\_out}@>@;
  2631.  
  2632. if(new_depth != incl_depth || !get_line())
  2633.     goto restore;  // No file, or nothing in it.
  2634.  
  2635. do_inside = NO; 
  2636.     // This flag says to not xref stuff inside braces of \&{typedef}. 
  2637.  
  2638. next_control = get_next();
  2639.  
  2640. /* Parse the preprocessed include file until EOF is reached and the
  2641. |incl_depth| changes. */
  2642. while(new_depth == incl_depth)
  2643.     {
  2644.     name_pointer p;
  2645.  
  2646.     switch(next_control)
  2647.         {
  2648.        case identifier:
  2649.         p=id_lookup(id_first,id_loc,
  2650.             (eight_bits)(next_control-identifier));
  2651.  
  2652.         if(p->ilk == typedef_like)
  2653.             @<Mark \&{typedef} variable@>@;
  2654.         else if(p->ilk == class_like)
  2655.             @<Mark \&{class} variable@>@;
  2656.  
  2657.         break;
  2658.         }
  2659.  
  2660.     next_control=get_next();
  2661.     }
  2662.  
  2663. end_xref:
  2664. restore:
  2665.   preprocessing = sharp_include_line = YES;
  2666. }
  2667.  
  2668. @ The following commands are borrowed with slight modifications from
  2669. \.{common.web}. 
  2670.  
  2671. @<Deflect...@>=
  2672. {
  2673. if(++incl_depth >= (int)max_include_depth)
  2674.     {
  2675.     incl_depth--;
  2676.     err_print(C, "Too many nested includes; %d allowed.  \
  2677. Increase with `-yid'.", max_include_depth); 
  2678. @.Too many nested includes@>
  2679.     goto restore;
  2680.     }
  2681.  
  2682. { /* No change file name specified; obtain it from the last level. */
  2683. INPUT_PRMS *p_lower = &prms[incl_depth-1];
  2684. INPUT_PRMS0 *p0_lower = &p_lower->change;
  2685.  
  2686. STRCPY(change_file_name,p0_lower->File_name);
  2687. change_file = p0_lower->File;
  2688. change_params = p_lower->input_params;
  2689. }
  2690.  
  2691. STRCPY(cur_file_name, temp_out);
  2692. new_depth = incl_depth;
  2693.  
  2694. {
  2695. IN_COMMON INCL_PATHS incl;
  2696.  
  2697. if(ini_input_prms(CUR_FILE, incl.list, NO))
  2698.     {
  2699.     if(cur_prms.change->File != prms[incl_depth-1].change.File)
  2700.         {}
  2701.     else *cur_prms.change = prms[incl_depth-1].change;
  2702.         // Still using the old change file.
  2703.  
  2704.     cur_line = 0;
  2705.     prn_where = YES;
  2706. /* Instead of printing the names of the temporary files, we print the
  2707. include file name itself. */
  2708.     CLR_PRINTF(include_file,(" (%s", file_name));
  2709. /* Tell the terminal where we're reading from. */
  2710.     }
  2711. else 
  2712.     { /* Failed to open include file. */
  2713.         incl_depth--;
  2714.     }
  2715. }
  2716. }
  2717.  
  2718. @ The following is called from |wrap_up()| in \.{common.web}. 
  2719.  
  2720. @<Part 1@>=@[
  2721.  
  2722. SRTN
  2723. cls_files(VOID)
  2724. {
  2725. if(read_iformats && rmv_files)
  2726.     {
  2727.     remove((CONST char *)temp_in);
  2728.     remove((CONST char *)temp_out);
  2729.     }
  2730. }
  2731.  
  2732. @ Make a temporary file name, and append an extension.  We use |tempnam| if
  2733. possible, because it gives more control over the directory.  Otherwise, we
  2734. use the ANSI |tmpnam|.
  2735.  
  2736. @<Part 1@>=@[
  2737.  
  2738. outer_char *
  2739. mktmp FCN((file_name, ext))
  2740.     outer_char *file_name C0("")@;
  2741.     outer_char *ext C1("")@;
  2742. {
  2743. outer_char *buffer;
  2744.  
  2745. #if(HAVE_TEMPNAM)
  2746.     extern char *tempnam();
  2747.  
  2748.     if(!*wbprefix) 
  2749.         STRCPY(wbprefix,"./");
  2750.  
  2751.     buffer = (outer_char *)tempnam((char *)wbprefix, "FTMP"); 
  2752.     // Non-|ANSI|, but more control over directory.
  2753. #else
  2754.     buffer = (outer_char *)tmpnam(NULL); // |ANSI| routine.
  2755. #endif
  2756.  
  2757. STRCPY(file_name, buffer);
  2758.  
  2759. if(*ext)
  2760.     {
  2761.     STRCAT(file_name, ".");
  2762.     STRCAT(file_name, ext);
  2763.     }
  2764.  
  2765. return file_name;
  2766. }
  2767.  
  2768.  
  2769. @ When an include line of the form |#include <test.h>| is sensed in C or
  2770. \Cpp, we would like to open the related file \.{test.H} and process it for
  2771. format commands.   (Processing \.{test.h} would format and cross-reference
  2772. many variables that the user wouldn't care to know about.)  See ``Push
  2773. stack'' code in \.{common.web}.
  2774.  
  2775. @d change_params prms[incl_depth].input_params
  2776.  
  2777. @<Unused@>=
  2778.  
  2779. SRTN 
  2780. get_iformats(VOID)
  2781. {
  2782. outer_char temp[100], HUGE *period;
  2783. int n;
  2784. int new_depth;
  2785.  
  2786. preprocessing = sharp_include_line = NO;
  2787.  
  2788. STRNCPY(temp, id_first+1, n=PTR_DIFF(int, id_loc, id_first)-2);
  2789. temp[n] = '\0';
  2790. to_outer((ASCII HUGE *)temp);
  2791.  
  2792. if(!(period = (outer_char HUGE *)STRRCHR(temp, '.')))
  2793.     goto restore;
  2794.  
  2795. period[1] = '\0';
  2796. STRCAT(temp, w_style.misc.include_ext);
  2797.  
  2798. if(++incl_depth >= (int)max_include_depth)
  2799.     {
  2800.     incl_depth--;
  2801.     err_print(C, "Too many nested includes; %d allowed.  \
  2802. Increase with `-yid'.", max_include_depth); 
  2803. @.Too many nested includes@>
  2804.     goto restore;
  2805.     }
  2806.  
  2807.         { /* No change file name specified; obtain it from the
  2808. last level. */
  2809.         INPUT_PRMS *p_lower = &prms[incl_depth-1];
  2810.         INPUT_PRMS0 *p0_lower = &p_lower->change;
  2811.  
  2812.         STRCPY(change_file_name,p0_lower->File_name);
  2813.         change_file = p0_lower->File;
  2814.         change_params = p_lower->input_params;
  2815.         }
  2816.  
  2817. STRCPY(cur_file_name, temp);
  2818. new_depth = incl_depth;
  2819.  
  2820.     {
  2821.     IN_COMMON INCL_PATHS incl;
  2822.  
  2823.     if(ini_input_prms(CUR_FILE,incl.list,NO))
  2824.         {
  2825.         if(cur_prms.change->File != prms[incl_depth-1].change.File)
  2826.             {}
  2827.         else *cur_prms.change = prms[incl_depth-1].change;
  2828.             // Still using the old change file.
  2829.  
  2830.         cur_line = 0;
  2831.         prn_where = YES;
  2832.         CLR_PRINTF(include_file,(" (%s", (char *)cur_file_name)); 
  2833. /* Tell the terminal where we're reading from. */
  2834.         }
  2835.     else 
  2836.         { /* Failed to open include file. */
  2837.             incl_depth--;
  2838.         }
  2839.      }
  2840.  
  2841. if(new_depth != incl_depth || !get_line())
  2842.     goto restore;
  2843.  
  2844. next_control = get_next();
  2845.  
  2846. while(new_depth == incl_depth)
  2847.     {
  2848.     switch(next_control)
  2849.         {
  2850.        case formatt:
  2851.         pr_format(NO, NO);
  2852.         break;
  2853.  
  2854.        default:
  2855.         ERR_PRINT(W, "Invalid command in #include file");
  2856.         break;
  2857.         }
  2858.     }
  2859.  
  2860. restore:
  2861.   preprocessing = sharp_include_line = YES;
  2862. }
  2863.  
  2864. @
  2865. @<Skip over meta-comment@>=
  2866. {
  2867. WHILE()
  2868.     {
  2869.     if(!get_line()) 
  2870.         if(language == LITERAL)
  2871.             {
  2872.             next_control = new_module;
  2873.             goto done_meta;
  2874.             }
  2875.         else
  2876.             {
  2877.             ERR_PRINT(W,"Input ended during meta-comment");
  2878.             break;
  2879.             }
  2880.         
  2881.     if(*loc == @'@@')
  2882.         switch(*(loc+1))
  2883.             {
  2884.            case @')':
  2885.             get_line();
  2886.  
  2887.            case @'*':
  2888.            case @' ':
  2889.             next_control = new_module;
  2890.             goto done_meta;
  2891.  
  2892.            case @'<':
  2893.             next_control = module_name;
  2894.             goto done_meta;
  2895.             }
  2896.     }
  2897.  
  2898. done_meta:;
  2899. }
  2900.  
  2901. @ For the forward-referencing facility, we need to format the variable of a
  2902. \&{typedef} during phase~1.  We mark the first variable we come to that isn't
  2903. reserved and isn't enclosed by braces.  (We must format identifiers even if
  2904. they're inside braces.)
  2905. @<Mark \&{typedef} variable@>=
  2906. {
  2907. int brace_level = 0;
  2908. boolean typedefd_it = NO;
  2909.  
  2910. /* First, we scan over a possible |struct|. */
  2911. while((next_control=get_next()) == identifier)
  2912.     if((p=id_lookup(id_first,id_loc,0))->ilk != struct_like) 
  2913.         {
  2914.         new_xref(part0,p); // Structure name: ``|typedef struct s@;|''.
  2915.         next_control = get_next(); // Don't repeat the structure name.
  2916.         break;
  2917.         }
  2918.  
  2919. while(next_control <=module_name)
  2920.     {
  2921.     switch(next_control)
  2922.         {
  2923.        case @'{':
  2924.         brace_level++;
  2925.         break;
  2926.  
  2927.        case @'}':
  2928.         if(brace_level-- == 0) 
  2929.             {
  2930.             ERR_PRINT(W,"Extra '}' in typedef");
  2931.             goto done;
  2932.             }
  2933.         break;
  2934.  
  2935.        case identifier:
  2936.         p = id_lookup(id_first,id_loc,0);
  2937.  
  2938.         if(brace_level == 0 && !typedefd_it)
  2939.             {
  2940.             if(is_reserved(p))
  2941.                 break;
  2942.  
  2943.             defd_switch = BOOLEAN(mark_defined.typedef_name);
  2944.             defd_type = TYPEDEF_NAME;
  2945.             typd_switch = YES;
  2946.             INDEX_SHORT;
  2947.             new_xref(part0,p);
  2948.             }
  2949.         else if(do_inside)
  2950.             new_xref(part0,p);
  2951.  
  2952.         if(brace_level == 0 && !typedefd_it)
  2953.             typedefd_it = YES; /* Don't do any more (e.g., array
  2954. dimensions).  (But this means one can't yet do |BB| in |typedef int AA, BB@;|.) */
  2955.         break;
  2956.  
  2957.        case formatt:
  2958.        case limbo_text:
  2959.        case op_def:
  2960.        case macro_def:
  2961.        case definition:
  2962.        case undefinition:
  2963.        case WEB_definition:
  2964.        case begin_code:
  2965.        case new_output_file:
  2966.        case protect_code:
  2967.         ERR_PRINT(W,"You can't do that inside a typedef");
  2968.         break;
  2969.  
  2970.        case module_name:
  2971.         if(cur_module) new_mod_xref(cur_module);
  2972.         next_control = get_next();
  2973.         if(next_control == @'=')
  2974.             {
  2975.             ERR_PRINT(W,"'=' not allowed after @@<...@@> \
  2976. inside typedef; check typedef syntax.  Inserted ';'");
  2977.             next_control = @';';
  2978.             }
  2979.         continue;
  2980.  
  2981.        case @';':
  2982.         if(brace_level == 0) goto done; // End of |typedef|.
  2983.         break;
  2984.  
  2985.        case begin_comment:
  2986.         @<Handle a comment@>@;
  2987.         break;
  2988.         }
  2989.  
  2990.     next_control = get_next();
  2991.     }
  2992.  
  2993. done: 
  2994.   defd_switch = typd_switch = NO; // Just in case we screwed up.
  2995.  
  2996.   if(next_control == new_module)
  2997.     {
  2998.     ERR_PRINT(W,"Module ended during typedef");
  2999.     goto end_xref;
  3000.     }
  3001. }
  3002.  
  3003. @ Similarly, \&{class} variables should be formatted during phase~1.
  3004. @<Mark \&{class}...@>=
  3005. {
  3006. if((next_control=get_next()) == identifier)
  3007.     {
  3008.     p = id_lookup(id_first,id_loc,0);
  3009.  
  3010.     defd_switch = BOOLEAN(mark_defined.typedef_name);
  3011.     defd_type = TYPEDEF_NAME;
  3012.     typd_switch = YES;
  3013.     INDEX_SHORT;
  3014.  
  3015.     new_xref(part0,p);
  3016.     typd_switch = NO;
  3017.     }
  3018. }
  3019.  
  3020. @ The |language| has already been set inside |get_next()| when we get to here.
  3021.  
  3022. @<Handle a possible language switch...@>=
  3023.  
  3024. switch(language)
  3025.     {
  3026.     case NO_LANGUAGE:
  3027.         CONFUSION("handle possible language switch",
  3028.             "Language isn't defined");
  3029.  
  3030.     case FORTRAN:
  3031.     case FORTRAN_90:
  3032.     case RATFOR:
  3033.     case RATFOR_90:
  3034.         if(mode0 == OUTER && !free_form_input) 
  3035.             @<Set up column mode@>@;
  3036.         break;
  3037.  
  3038.     case TEX:
  3039.         if(mode0 == OUTER) @<Set up col...@>@;
  3040.         break;
  3041.  
  3042.     case C:
  3043.     case C_PLUS_PLUS:
  3044.     case LITERAL:
  3045.         column_mode = NO;
  3046.         break;
  3047.  
  3048.     case NUWEB_OFF:
  3049.     case NUWEB_ON:
  3050.         CONFUSION("handle possible language switch","Invalid langage");
  3051.     }
  3052.  
  3053.  
  3054. @ The |outr_xref| subroutine is like |C_xref| but it begins with
  3055. |next_control!='|'| and ends with |next_control>=formatt|. Thus, it handles
  3056. \cee\ text with embedded comments.
  3057.  
  3058. @<Part 1@>=@[
  3059.  
  3060. SRTN outr_xref FCN((part0)) /* extension of |C_xref| */
  3061.     PART part0 C1("")@;
  3062. {
  3063. while (next_control<formatt)
  3064.     if (next_control!=begin_comment) 
  3065.         C_xref(part0,OUTER);
  3066.     else 
  3067.         @<Handle a comment@>@;
  3068. }
  3069.  
  3070. @ Deal with a comment inside C~text.
  3071. @<Handle a comment@>=
  3072. {
  3073. int bal; // Brace level in comment.
  3074.  
  3075. bal = copy_comment(1); next_control = @'|';
  3076.  
  3077. doing_cdir = NO;
  3078.  
  3079. while (bal>0)
  3080.     { /* Inside comment. */
  3081.     in_comment = YES;
  3082.     C_xref(part0,INNER);
  3083.  
  3084.     if (next_control==@'|') 
  3085.         bal = copy_comment(bal);
  3086.     else 
  3087.         bal = 0; // An error message will occur in phase 2.
  3088.     }
  3089. }
  3090.  
  3091. @ In the \TeX\ part of a module, cross-reference entries are made only for
  3092. the identifiers in \cee\ texts enclosed in~\Cb, or for control texts
  3093. enclosed in \.{@@\^}$\,\ldots\,$\.{@@>} or \.{@@.}$\,\ldots\,$\.{@@>} or
  3094. \.{@@9}$\,\ldots\,$\.{@@>}.
  3095.  
  3096. @<Store cross-references in the \T...@>=
  3097. {
  3098. the_part = TEX_;
  3099.  
  3100. WHILE() 
  3101.     {
  3102.     switch (next_control=skip_TeX()) 
  3103.         {
  3104.        @<Specific language cases@>:
  3105.         loc--; // Falls through to general case below.
  3106.  
  3107.        case L_switch:
  3108.         {
  3109.         @<Set the |language|...@>;
  3110.         continue;
  3111.         }
  3112.  
  3113.        case begin_nuweb:
  3114.         nuweb_mode = !NUWEB_MODE;
  3115.         continue;
  3116.  
  3117.        case toggle_output: 
  3118.         @<Toggle output@>@; 
  3119.         continue;
  3120.  
  3121.        case underline: 
  3122.         xref_switch = def_flag; 
  3123.         continue;
  3124.  
  3125. #ifdef DEBUG
  3126.        case trace: tracing=next_control-@'0'; continue;
  3127. #endif /* |DEBUG| */
  3128.  
  3129.        case @'|': 
  3130.         while(next_control <= module_name)
  3131.             {
  3132.             C_xref(TEX_,INNER); 
  3133.             if(next_control == @'|' || next_control == new_module) 
  3134.                 break;
  3135.             next_control = get_next();
  3136.             if(next_control == @'|') break;
  3137.             }
  3138.  
  3139.         break;
  3140.  
  3141.        case xref_roman: case xref_wildcard: case xref_typewriter: 
  3142.        case macro_module_name: case module_name: 
  3143.         loc-=2; next_control=get_next(); // Scan to \.{@@>}.
  3144.  
  3145.         if( !(next_control==module_name || 
  3146.             next_control==macro_module_name) )
  3147.                   new_xref(TEX_,id_lookup(id_first,id_loc,
  3148.                 (eight_bits)(next_control-identifier)));  
  3149.         break;
  3150.  
  3151.         case invisible_cmnt:
  3152.         loc = limit + 1;
  3153.         break;
  3154.         }
  3155.  
  3156.     if (next_control>=formatt) 
  3157.         break;
  3158.     }
  3159. }
  3160.  
  3161. @ During the definition and \cee\ parts of a module, cross-references are
  3162. made for all identifiers except reserved words; however, the identifiers in
  3163. a format definition are referenced even if they are reserved. The \TeX\
  3164. code in comments is, of course, ignored, except for \cee\ portions enclosed
  3165. in~\Cb; the text of a module name is skipped entirely, even if it contains
  3166. \Cb~constructions.
  3167.  
  3168. The variables |lhs| and |rhs| point to the respective identifiers involved
  3169. in a format definition.
  3170.  
  3171. @<Global...@>=
  3172.  
  3173. EXTERN name_pointer lhs, rhs; /* pointers to |byte_start| for format
  3174.                 identifiers */ 
  3175.  
  3176. @ When we get to the following code we have |next_control>=formatt|.
  3177.  
  3178. @d KILL_XREFS(name) no_xref |= !defn_mask.name
  3179. @d INDEX_SHORT index_short = index_flag = YES // Implicit \.{@@~}.
  3180.  
  3181. @<Store cross-references in the d...@>=
  3182. {
  3183. boolean no_xref0 = no_xref;
  3184.  
  3185. the_part = DEFINITION;
  3186.  
  3187. while (next_control<begin_code) 
  3188.     { /* |formatt| or |definition| or |WEB_definition| or \.{@@\#...}
  3189. command. */ 
  3190.     switch(next_control)
  3191.         {
  3192.          case WEB_definition:
  3193.         if(mark_defined.WEB_macro && lower_case_code)
  3194.             defd_switch = YES; // Implied \.{@@[}.
  3195.  
  3196.         xref_switch = def_flag; /* Implied \.{@@\_} */
  3197.         defd_type = M_MACRO;
  3198.             
  3199.         KILL_XREFS(macros);
  3200.         INDEX_SHORT;
  3201.         break;
  3202.  
  3203.        case m_undef:
  3204.         KILL_XREFS(macros);
  3205.         INDEX_SHORT;
  3206.         break;
  3207.  
  3208.         case definition: 
  3209.         if(mark_defined.outer_macro && mark_defined.outer_macro)
  3210.             defd_switch = YES; // Implied \.{@@[}.
  3211.  
  3212.         xref_switch = def_flag; /* Implied \.{@@\_} */
  3213.         defd_type = D_MACRO;
  3214.  
  3215.         KILL_XREFS(outer_macros);
  3216.         INDEX_SHORT;
  3217.         break;
  3218.  
  3219.        case undefinition:
  3220.         KILL_XREFS(outer_macros);
  3221.         INDEX_SHORT;
  3222.         break;
  3223.  
  3224.        case m_ifdef:
  3225.        case m_ifndef:
  3226.         INDEX_SHORT;
  3227.         break;
  3228.         }
  3229.  
  3230.     switch(next_control)
  3231.         {
  3232.        case formatt:
  3233.         pr_format(YES, YES);
  3234.         break;
  3235.  
  3236.        case limbo_text:
  3237.         @<Absorb limbo text@>@;
  3238.         break;
  3239.  
  3240.        case op_def:
  3241.         @<Overload an operator@>@;
  3242.         break;
  3243.  
  3244.        case macro_def:
  3245.         @<Overload an identifier@>@;
  3246.         break;
  3247.  
  3248.        case invisible_cmnt:
  3249.         loc = limit + 1; // Skip the line.
  3250.  
  3251.        default:
  3252.         next_control=get_next();
  3253.         break;
  3254.         }
  3255.  
  3256.     outr_xref(DEFINITION);
  3257.     no_xref = no_xref0;
  3258.     }
  3259. }
  3260.  
  3261. @ The syntax of a format definition is ``\.{@@f\ new\_name\ old\_name}'' or
  3262. ``\.{@@f\ `\{\ 10}''.  Error messages for improper format definitions of
  3263. the first kind will be issued in phase two; for the second kind, in phase
  3264. one. For the first kind, our job in phase one is to define the |ilk| of a
  3265. properly formatted identifier, and to fool the |new_xref| routine into
  3266. thinking that the identifier on the right-hand side of the format
  3267. definition is not a reserved word.  For the second kind, we must actually
  3268. change the category code of a \TeX\ character, and that must be done in
  3269. phase one so future identifiers can be resolved properly.
  3270.  
  3271. @<Part 1@>=@[
  3272.  
  3273. SRTN 
  3274. pr_format FCN((xref_lhs, xref_rhs))
  3275.     boolean xref_lhs C0("")@;
  3276.     boolean xref_rhs C1("")@;
  3277. {
  3278. eight_bits last_control,rhs_ilk;
  3279. LANGUAGE saved_language = language;
  3280.  
  3281. if(upper_case_code)
  3282.     KILL_XREFS(Formats);
  3283. else
  3284.     KILL_XREFS(formats);
  3285.  
  3286. INDEX_SHORT;
  3287.  
  3288. if(language==TEX) 
  3289.     language = C;
  3290.  
  3291. last_control = next_control = get_next(); /* Identifier or module name to be
  3292.                 formatted, or |ASCII| character. */
  3293.  
  3294. if (next_control==identifier || next_control==module_name) 
  3295.     @<Process an identifier or module name@>@;
  3296. else if(next_control==@'`')
  3297.     @<Change a category code@>@;
  3298.  
  3299. if(saved_language==TEX)
  3300.     language = saved_language;
  3301. }
  3302.  
  3303. @ Here we deal with format commands of the form ``\.{@@f\ new\_name\
  3304. old\_name}''.
  3305.  
  3306. @<Process an identifier...@>=
  3307. {
  3308. if(next_control==identifier)
  3309.     {
  3310.     lhs=id_lookup(id_first, id_loc, normal); 
  3311.     lhs->ilk=normal; 
  3312.  
  3313.     if(xref_lhs)
  3314.         new_xref(DEFINITION,lhs);
  3315.     }
  3316. else 
  3317.     lhs = cur_module;
  3318.  
  3319. next_control=get_next();
  3320.  
  3321. if (next_control==identifier)  
  3322.     { /* Format the lhs like this one. */
  3323.      rhs=id_lookup(id_first, id_loc,normal);
  3324.  
  3325.     if(lhs != NULL)
  3326.         {
  3327.          if(last_control==identifier) 
  3328.             @<Format the left-hand side@>@;
  3329.         else 
  3330.             lhs->mod_ilk = rhs->ilk; 
  3331.                 // We're formatting a module name.
  3332.         }
  3333.  
  3334. /* Take care of the possibility that the rhs may not yet have been
  3335. encountered. */
  3336. if(xref_rhs)
  3337.     {
  3338.     rhs_ilk = rhs->ilk;
  3339.     rhs->ilk=normal; 
  3340.  
  3341.     new_xref(DEFINITION,rhs);
  3342.  
  3343.     rhs->ilk=rhs_ilk;
  3344.     }
  3345.  
  3346.     next_control=get_next();
  3347.     }
  3348. }
  3349.  
  3350. @ Set the appropriate format bit.
  3351. @<Format the left-hand side@>=
  3352. {
  3353. lhs->ilk = rhs->ilk; 
  3354.  
  3355. /* First turn off the old lhs bit (retaining all others), then add in the
  3356. new bit for the current language. */
  3357. #define RST_BIT(field) lhs->field = BOOLEAN(lhs->field & ~(boolean)language)\
  3358.      | (rhs->field & (boolean)language)
  3359.  
  3360. RST_BIT(reserved_word);
  3361. RST_BIT(Language);
  3362. RST_BIT(intrinsic_word);
  3363. RST_BIT(keyword);
  3364.  
  3365. #undef RST_BIT
  3366. }
  3367.  
  3368. @ Here we consider format commands of the form ``\.{@@f\ `\{\ 10}''.
  3369. |get_TeX|~leaves the (|outer_char|) constant string between
  3370. [|id_first|,|id_loc|). 
  3371. @<Change a category code@>=
  3372. {
  3373. if((next_control = get_TeX()) != constant)
  3374.   ERR_PRINT(W,"Invalid @@f command:  \
  3375. One of the representations `a, `\\a, or `^^M is required");
  3376. else
  3377.     {
  3378.     int c = TeX_char(); // Convert the |ASCII| code in |id_first|.
  3379.  
  3380.     next_control = get_next(); // Now expecting integer category code.
  3381.  
  3382.     if(next_control != constant) ERR_PRINT(W,"Invalid category code");
  3383.     else
  3384.         {
  3385.         TeX_CATEGORY cat;
  3386.  
  3387.         TERMINATE(id_loc,0);
  3388.         cat = (TeX_CATEGORY)ATOI(id_first); 
  3389.             // Numerical value of new cat code.
  3390.  
  3391.         if((int)cat < 0 || (int)cat > 15) 
  3392.             ERR_PRINT(W,"Category code must be between 0 and 15");
  3393.         else TeX[c] = cat; // Change the category code.
  3394.  
  3395.         next_control = get_next();
  3396.         }
  3397.     }
  3398. }
  3399.  
  3400. @ We require a special routine to obtain an |ASCII| character in \TeX's
  3401. representation after a~'\.`'.  On entry, |loc|~is positioned after
  3402. the~'\.`'.  The possible representations are~`\.{a}', `\.{\\a}',
  3403. or~`\.{\^\^M}'.
  3404.  
  3405. @<Part 1@>=@[
  3406.  
  3407. eight_bits get_TeX(VOID)
  3408. {
  3409. if(loc >= limit)
  3410.     {
  3411.     ERR_PRINT(W,"@@f line ends prematurely");
  3412.     return ignore;
  3413.     }
  3414.  
  3415. id_first = id_loc = mod_text + 1;
  3416.  
  3417. if(*loc == @'\\') *id_loc++ = *loc++;
  3418. else if(*loc == @'^' && *(loc+1) == @'^')
  3419.     { // \TeX's way of representing control characters.
  3420.     *id_loc++ = *loc++; @~ *id_loc++ = *loc++;
  3421.     }
  3422.  
  3423. if(*loc == @'@@')
  3424.     if(*(loc+1) == @'@@') loc++;
  3425.     else ERR_PRINT(W,"You should say `@@@@");
  3426.  
  3427. *id_loc++ = *loc++; // Position to next non-processed character.
  3428. *id_loc = '\0';
  3429.  
  3430. id_first = esc_buf(id_loc+1,mod_end,id_first,YES);
  3431. to_outer(id_first);
  3432.  
  3433. return constant;
  3434. }
  3435.  
  3436. @ Here we convert the constant obtained in the previous routine into an
  3437. |ASCII| character.
  3438. @<Part 1@>=@[
  3439.  
  3440. int TeX_char(VOID)
  3441. {
  3442. int c;
  3443.  
  3444. while(*id_first == @'\\') id_first++;
  3445.  
  3446. if(*id_first == @'^' && *(id_first+1) == @'^') 
  3447.     {
  3448.     c = *(id_first+2);
  3449.     if(c >= 64) c -= 64;
  3450.     else c += 64;
  3451.     }
  3452. else c = *id_first;
  3453.  
  3454. return c;
  3455. }
  3456.  
  3457. @ Limbo text commands have the form ``\.{@@l\ "abc\\ndef"}'', and must be
  3458. absorbed during phase one so they can be dumped out at the beginning of
  3459. phase two.
  3460.  
  3461. @<Absorb limbo text@>=
  3462. {
  3463. LANGUAGE language0 = language;
  3464.  
  3465. KILL_XREFS(limbo);
  3466.  
  3467. if(language==TEX)
  3468.     language = C; // In order to absorb strings properly.
  3469.  
  3470. insert_breaks = NO; // We want the string to be absorbed completely literally.
  3471.  
  3472. if((next_control = get_next()) != stringg)
  3473.     ERR_PRINT(W,"String must follow @@l");
  3474. else
  3475.     { // Begin by stripping off delimiting quotes.
  3476.     for(id_first++,id_loc--; id_first<id_loc; )
  3477.         {
  3478.         if(*id_first==@'@@')
  3479.             {
  3480.             if(*(id_first+1)==@'@@') 
  3481.                 id_first++;
  3482.             else 
  3483.               ERR_PRINT(W,"Double @@ should be used in strings");
  3484.             }
  3485.  
  3486. /* Deal with escape sequences. */
  3487.         if(*id_first == @'\\') 
  3488.             {
  3489.             id_first++; 
  3490. /* Splitting the following line before |HUGE| led to compiler problem with
  3491. VAX/VMS. */
  3492.             app_tok(esc_achar(
  3493. (CONST ASCII HUGE*HUGE*)&id_first))@;
  3494.             } 
  3495.         else 
  3496.             app_tok(*id_first++);
  3497.         }
  3498.  
  3499.     freeze_text; /* We'll know we've collected stuff because |text_ptr|
  3500. will be advanced. */
  3501.     }
  3502.  
  3503. insert_breaks = YES;
  3504.  
  3505. language = language0;
  3506. }
  3507.  
  3508. @ The syntax of an operator-overloading command is 
  3509. ``\.{@@v\ .IN.\ "\\in"\ +}''.
  3510.  
  3511. @<Overload an op...@>=
  3512. {
  3513. OPERATOR HUGE *p,HUGE *p1;
  3514.  
  3515. KILL_XREFS(v);
  3516.  
  3517. /* Look at the first field, which should be an operator or a dot-op. */
  3518. next_control = get_next();
  3519.  
  3520. if(next_control == identifier)
  3521.     ERR_PRINT(W,"For future compatibility, please use syntax `.NAME.' for \
  3522. overloading dot operators");
  3523.  
  3524. if(!(p=valid_op(next_control)))
  3525.     ERR_PRINT(W,"Operator after @@v is invalid");
  3526. else
  3527.     {
  3528.     if(get_next() != stringg)
  3529.         ERR_PRINT(W,"Second argument (replacement text) \
  3530. of @@v must be a quoted string");
  3531.     else
  3532.         {
  3533.         int k = language_num;
  3534.         OP_INFO HUGE *q = p->info + k;
  3535.         int n = PTR_DIFF(int, id_loc, id_first) - 2; /* Don't count the
  3536. string delimiters. */
  3537.         outer_char HUGE *s;
  3538.  
  3539.         if(q->defn) FREE_MEM(q->defn,"q->defn",STRLEN(q->defn)+1,
  3540.             outer_char);
  3541.         q->defn = GET_MEM("q->defn",n+1,outer_char);
  3542.  
  3543.         *(id_loc-1) = '\0'; // Kill off terminating quote.
  3544.  
  3545.         for(s=q->defn,id_first++; *id_first; s++)
  3546.             if(*id_first == @'\\')
  3547.                 {
  3548.                 id_first++; 
  3549.                 *s = XCHR(esc_achar((CONST ASCII HUGE
  3550. *HUGE*)&id_first));
  3551.                 } 
  3552.             else *s = XCHR(*id_first++);
  3553.  
  3554.         overloaded[k] = q->overloaded = YES;
  3555.  
  3556. /* There may be several representations with the same name. */
  3557.         for(p1=op; p1<op_ptr; p1++)
  3558.             {
  3559.             if(p1==p || !p1->op_name) continue;
  3560.  
  3561.             if(STRCMP(p1->op_name,p->op_name) == 0)
  3562.                 {
  3563.                 OP_INFO HUGE *q1 = p1->info + k;
  3564.  
  3565.                 if(q1->defn) FREE_MEM(q1->defn,"q1->defn",
  3566.                     STRLEN(q1->defn)+1,outer_char);
  3567.                 q1->defn = GET_MEM("q1->defn",n+1,outer_char);
  3568.                 STRCPY(q1->defn,q->defn);
  3569.                 q1->overloaded = YES;
  3570.                 }
  3571.             }
  3572.  
  3573. /* Get the new category and set it.  If the last construction isn't
  3574. recognized as a valid operator, the category is set to |expr|. */
  3575.         p = valid_op(next_control=get_next());
  3576.  
  3577.         q->cat = (p ? p->info[k].cat : (eight_bits)expr);
  3578.         }
  3579.     }
  3580. }
  3581.  
  3582. @ The syntax for overloading an identifier is ``\.{@@w\ \It{id}\
  3583. "\dots"}'', or the string replacement text can be replaced by~'\..', which
  3584. means just prepend a backslash to make it into a macro name.
  3585.  
  3586. @d QUICK_FORMAT @'.' // The shorthand for overloading like itself.
  3587.  
  3588. @<Overload an id...@>=
  3589. {
  3590. if((next_control=get_next()) != identifier)
  3591.     ERR_PRINT(W,"Identifier must follow @@w");
  3592. else
  3593.     {
  3594.     name_pointer p = id_lookup(id_first,id_loc,normal);
  3595.     int n,offset;
  3596.     WV_MACRO HUGE *w;
  3597.     ASCII HUGE *s;
  3598.     ASCII HUGE *id_first0, HUGE *id_loc0;
  3599.  
  3600. /* Index the identifier (but not defined).  Force short identifiers to be
  3601. indexed. */
  3602.     KILL_XREFS(w);
  3603.     INDEX_SHORT;
  3604.     new_xref(DEFINITION, p);
  3605.  
  3606. /* Remember the first identifier. */
  3607.     id_first0 = id_first;
  3608.     id_loc0 = id_loc;
  3609.  
  3610.     switch(next_control=get_next())
  3611.         {
  3612.        case @'\\':
  3613.         if((next_control = get_next()) != identifier)
  3614.             {
  3615.             ERR_PRINT(W,"Identifier must follow '\\'");
  3616.             break;
  3617.             }
  3618.  
  3619.         next_control = ignore; /* We don't want to put the
  3620. identifier into the index. */
  3621.         goto quick_code;
  3622.  
  3623.  
  3624.        case QUICK_FORMAT:
  3625.         id_first = id_first0;
  3626.         id_loc = id_loc0;
  3627.  
  3628.     quick_code:
  3629.         offset = 1;
  3630.         n = PTR_DIFF(int, id_loc, id_first) + 1;
  3631.         *id_loc = '\0';
  3632.         goto fmt_like_string;    
  3633.     
  3634.        case stringg:
  3635.         {
  3636.         offset = 0;
  3637.         n = PTR_DIFF(int, id_loc, id_first) - 2; // Don't count quotes.
  3638.         *(id_loc-1) = '\0';
  3639.         id_first++; // Skip over opening quote.
  3640.  
  3641.          fmt_like_string:
  3642.         p->wv_macro = w = GET_MEM("wv_macro",1,WV_MACRO);
  3643.         w->text = GET_MEM("w->text",n+1,outer_char);
  3644.         
  3645.         if(offset) *w->text = @'\\';
  3646.  
  3647.         for(s=w->text + offset; *id_first; s++)
  3648.             if(*id_first == @'\\')
  3649.                 {
  3650.                 id_first++;
  3651.                 *s = esc_achar((CONST ASCII HUGE
  3652. *HUGE*)&id_first);  
  3653.                 }
  3654.             else *s = *id_first++;
  3655.  
  3656.         w->len = PTR_DIFF(unsigned, s, w->text);
  3657.  
  3658.         w->cat = (eight_bits)(upper_case_code ? 0 : expr); // Temporary
  3659.         }
  3660.         break;
  3661.  
  3662.        default:
  3663.         ERR_PRINT(W,"Second argument (replacement text) \
  3664. of @@w must be either a quoted string or '.' or have the form \\name");
  3665.         break;    
  3666.         }
  3667.     }
  3668. }
  3669.  
  3670. @ Finally, when the \TeX\ and definition parts have been treated, we have
  3671. |next_control>=begin_code|.
  3672.  
  3673. @<Glob...@>=
  3674.  
  3675. EXTERN boolean unnamed_section SET(NO);
  3676.  
  3677. @
  3678. @<Store cross-references in the \cee...@>=
  3679. {
  3680. the_part = CODE;
  3681.  
  3682. if (next_control<=module_name) 
  3683. {  /* |begin_code| or |module_name| */
  3684. boolean beginning_module = YES;
  3685.  
  3686. if(next_control==begin_code)
  3687.     {
  3688.     boolean nuweb_mode0 = nuweb_mode;
  3689.  
  3690.     unnamed_section = YES;
  3691.  
  3692.     params = global_params;
  3693.     nuweb_mode = nuweb_mode0;
  3694.     frz_params();
  3695.  
  3696.     mod_xref_switch = NO;
  3697.  
  3698.     if(mark_defined.fcn_name && lower_case_code) 
  3699.         {
  3700.         defd_switch = YES; // Implicit \.{@@[}.
  3701.         defd_type = FUNCTION_NAME;
  3702.         }
  3703.     }
  3704. else 
  3705.     {
  3706.     unnamed_section = NO;
  3707.     mod_xref_switch = def_flag;
  3708.     }
  3709.  
  3710.  
  3711.   do 
  3712.     {
  3713.     if (next_control==module_name && cur_module) 
  3714.         new_mod_xref(cur_module);
  3715.  
  3716.     if(beginning_module)
  3717.     {
  3718.     if(mod_xref_switch) 
  3719.         next_control = get_next();
  3720.     else 
  3721.         next_control = @'='; // For |begin_code|.
  3722.  
  3723.     if(next_control==@'=')
  3724.          if( !nuweb_mode && ((FORTRAN_LIKE(language) && !free_form_input)
  3725.             || (language==TEX)) ) 
  3726.         @<Set up column mode@>@; 
  3727.  
  3728.     beginning_module = NO;
  3729.     }
  3730.    else next_control = get_next();
  3731.  
  3732.     outr_xref(CODE);
  3733.     } 
  3734. while (next_control<=module_name)
  3735.     ; // Hunt for new module.
  3736.  
  3737. column_mode = NO;    // Turn off the FORTRAN verbatim input mode.
  3738. unnamed_section = NO; // Don't deflect cross-references.
  3739. }
  3740. }
  3741.  
  3742. @ After phase one has looked at everything, we want to check that each
  3743. module name was both defined and used.  The variable |cur_xref| will point
  3744. to cross-references for the current module name of interest.
  3745.  
  3746. @<Global...@>=
  3747.  
  3748. EXTERN xref_pointer cur_xref; /* temporary cross-reference pointer */
  3749.  
  3750. @ The following recursive procedure
  3751. walks through the tree of module names and prints out anomalies.
  3752. @^recursion@>
  3753.  
  3754. @<Part 1@>=@[
  3755.  
  3756. SRTN mod_check FCN((p))
  3757.     name_pointer p C1("Print anomalies in subtree |p|.")@;
  3758. {
  3759.   if (p) 
  3760.     {
  3761.     mod_check(p->llink);
  3762.     cur_xref = (xref_pointer)p->xref;
  3763.  
  3764.     if (cur_xref->num <def_flag) 
  3765.         {
  3766.         SET_COLOR(warning);
  3767.             printf("\n! Never defined: <"); prn_id(p); putchar('>');
  3768.         mark_harmless; 
  3769. @.Never defined: <section name>@>
  3770.           }
  3771.  
  3772.     while (cur_xref->num >= def_flag) cur_xref = cur_xref->xlink;
  3773.  
  3774.     if (cur_xref==xmem) 
  3775.         {
  3776.         SET_COLOR(warning);
  3777.             printf("\n! Never used: <"); prn_id(p); putchar('>');
  3778.         mark_harmless; 
  3779. @.Never used: <section name>@>
  3780.           }
  3781.  
  3782.         mod_check(p->rlink);
  3783.     }
  3784. }
  3785.  
  3786. @ Start off at the top of the tree.
  3787. @<Print error messages about un...@>=
  3788.  
  3789. mod_check(root)
  3790.  
  3791. @* LOW-LEVEL OUTPUT ROUTINES.
  3792. The \TeX\ output is supposed to appear in lines at most |line_length|
  3793. characters long, so we place it into an output buffer. During the output
  3794. process, |out_line| will hold the current line number of the line about to
  3795. be output.
  3796.  
  3797. @d CHECK_OPEN // This is defined differently in \FTANGLE.
  3798.  
  3799. @<Global...@>=
  3800.  
  3801. EXTERN BUF_SIZE line_length;
  3802. EXTERN ASCII HUGE *out_buf; // Assembled characters.
  3803. EXTERN ASCII HUGE *out_end; // End of |out_buf|.
  3804.  
  3805. EXTERN ASCII HUGE *out_ptr; // Points to last character in |out_buf|.
  3806. EXTERN LINE_NUMBER out_line; // number of next line to be output.
  3807.  
  3808. @
  3809. @<Alloc...@>=
  3810.  
  3811. ALLOC(ASCII,out_buf,ABBREV(line_length),line_length,1); /* assembled
  3812.                             characters */ 
  3813. out_end = out_buf+line_length; /* end of |out_buf| */
  3814.  
  3815. @ The |flush_buffer| routine empties the buffer up to a given breakpoint,
  3816. and moves any remaining characters to the beginning of the next line.  If
  3817. the |per_cent| parameter is |YES|, a |'%'|~is appended to the line that is
  3818. being output; in this case the breakpoint~|b| should be strictly less than
  3819. |out_end|. If the |per_cent| parameter is |NO|, trailing blanks are
  3820. suppressed.  The characters emptied from the buffer form a new line of
  3821. output.
  3822.  
  3823. The same caveat that applies to |ASCII_write| applies to |c_line_write|. (??)
  3824.  
  3825. @d OUT_FILE tex_file
  3826. @d C_LINE_WRITE(n) 
  3827.     fflush(tex_file),FWRITE(out_buf+1,n,tex_file)
  3828. @d ASCII_LINE_WRITE(n) 
  3829.     fflush(tex_file),ASCII_file_write(tex_file,out_buf+1,(size_t)(n))@;
  3830. @d TEX_PUTXCHAR(c) PUTC(c) // Send an |outer_char| to the \.{TEX} file.
  3831. @d TEX_NEW_LINE PUTC('\n') // A newline to the \.{TEX} file.
  3832. @d TEX_PRINTF(s) fprintf(tex_file,s) // A string to the \.{TEX} file.
  3833.  
  3834. @<Part 1@>=@[
  3835.  
  3836. SRTN flush_buffer FCN((b,per_cent))
  3837.     ASCII HUGE *b C0("")@;
  3838.     boolean per_cent C1("Outputs from |out_buf+1| to |b|, \
  3839. where |b<=out_ptr|.")@;
  3840. {
  3841. ASCII HUGE *j; 
  3842. ASCII HUGE *out_start;
  3843.  
  3844. if(output_on)
  3845.     {
  3846.     out_start = out_buf + 1;
  3847.     j = b; // Pointer into |out_buffer|.
  3848.  
  3849. /* Remove trailing blanks. */
  3850.     if(!per_cent) 
  3851.         while (j>out_buf && *j==@' ') 
  3852.             j--;
  3853.  
  3854.     ASCII_LINE_WRITE(j-out_buf);
  3855.  
  3856.     if (per_cent) 
  3857.         TEX_PUTXCHAR('%');
  3858.  
  3859.     if(*b != @'\n')
  3860.         TEX_NEW_LINE; // Nuweb mode has explicit newlines.
  3861.  
  3862.     out_line++;
  3863.  
  3864.     if (b<out_ptr) 
  3865.         {
  3866.         if(*out_start == @'%') 
  3867.             out_start++;
  3868.  
  3869.         STRNCPY(out_start,b+1,PTR_DIFF(size_t,out_ptr,b));
  3870.         }
  3871.  
  3872.     out_ptr -= b - out_start + 1;
  3873.     }
  3874. else 
  3875.     out_ptr = out_buf;
  3876. }
  3877.  
  3878. @ When we are copying \TeX\ source material, we retain line breaks that
  3879. occur in the input, except that an empty line is not output when the \TeX\
  3880. source line was nonempty. For example, a line of the \TeX\ file that
  3881. contains only an index cross-reference entry will not be copied. The
  3882. |fin_line| routine is called just before |get_line| inputs a new line,
  3883. and just after a line break token has been emitted during the output of
  3884. translated \cee\ text.
  3885.  
  3886. @<Part 1@>=@[
  3887.  
  3888. SRTN fin_line(VOID) /* do this at the end of a line */
  3889. {
  3890. ASCII HUGE *k; // Pointer into |cur_buffer|.
  3891.  
  3892. if (out_ptr>out_buf) 
  3893.     flush_buffer(out_ptr,NO); // Something nontrivial in line.
  3894. else 
  3895.     {
  3896. /* Don't output an empty line when \TeX\ source line is nonempty. */
  3897.     for (k=cur_buffer; k<=limit; k++)
  3898.           if (*k!=@' ' && *k!=tab_mark) 
  3899.             return;
  3900.  
  3901.     flush_buffer(out_buf,NO); // Empty line.
  3902.     }
  3903. }
  3904.  
  3905. @ In particular, the |fin_line| procedure is called near the very
  3906. beginning of phase two. We initialize the output variables in a slightly
  3907. tricky way so that the first line of the output file will be `\.{\\input
  3908. fwebmac}'.  This is the default. However, occasionally, one may need to
  3909. load other macro packages before \.{fwebmac}. To prevent this first line to
  3910. be generated, use the command line option~``\.{-w}''.  To change the name
  3911. of the default, way ``\.{-wnew\_name}''---for example, ``\.{-wfmac.sty}''.
  3912.  
  3913. @<Set init...@>=
  3914. {
  3915. out_ptr = out_buf; out_line = 1; 
  3916.  
  3917. if(input_macros) 
  3918.     {
  3919.     TEX_PRINTF("\\input ");
  3920.     OUT_STR(*fwebmac ? fwebmac : w_style.misc.macros); /* The command
  3921. line overrides the style file. */
  3922.     }
  3923. }
  3924.  
  3925. @ When the `\.{@@I}'~command is used in conjunction with the command-line
  3926. option `\.{-i}', we process the incoming text, but don't write it out. We
  3927. need an output flag to tell us when output is allowed.
  3928.  
  3929. @<Glob...@>=
  3930.  
  3931. EXTERN boolean output_on SET(YES);
  3932.  
  3933. @ When we wish to append one character~|c| to the output buffer, we write
  3934. `|out(c)|'; this will cause the buffer to be emptied if it was already
  3935. full.  |c|~is assumed to be of type |ASCII|.  If we want to append more
  3936. than one character at once, we say |OUT_STR(s)|, where |s|~is a string
  3937. containing the characters, or |out_del_str(s,t)| (``output a delimited
  3938. string''), where~|s| and~|t| point to the same array of characters (stored
  3939. as 16-bit tokens); characters from~|s| to~|t-1|, inclusive, are output. The
  3940. |out_str| routine takes an |outer_char| string as an argument, since this
  3941. is typically used as a print statement from inside the code.
  3942.  
  3943. A line break will occur at a space or after a single-nonletter \TeX\
  3944. control sequence.
  3945.  
  3946. @d out(c) 
  3947.     {
  3948.     if(out_ptr >= out_end) 
  3949.         break_out(); 
  3950.     *(++out_ptr) = (ASCII)(c);
  3951.     }
  3952.  
  3953. @d OUT_STR(s) out_str(OC(s))
  3954.  
  3955. @<Part 1@>=@[
  3956.  
  3957. SRTN out_del_str FCN((s,t)) /* output |ASCII| characters from |s| to |t-1|.  */
  3958.     token_pointer s C0("")@;
  3959.     token_pointer t C1("")@;
  3960. {
  3961. if(!output_on) 
  3962.     return; // Skip output.
  3963.  
  3964. while (s<t) 
  3965.     out(*s++);
  3966. }
  3967.  
  3968. SRTN out_str FCN((s)) /* output characters from |s| to end of string */
  3969.     CONST outer_char HUGE *s C1("")@;
  3970. {
  3971. if(!output_on) 
  3972.     return; // Skip output.
  3973.  
  3974. while (*s) 
  3975.     out(XORD(*s++));
  3976. }
  3977.  
  3978. @ Here we write an |outer_char| file name. We have to watch out for special
  3979. characters. 
  3980. @<Part 1@>=@[
  3981.  
  3982. SRTN out_fname FCN((s))
  3983.     CONST outer_char HUGE *s C1("File name to be written.")@;
  3984. {
  3985. ASCII a;
  3986.  
  3987. while(*s)
  3988.     {
  3989.     a = XORD(*s++);
  3990.  
  3991.     switch(a)
  3992.         {
  3993.         @<Special string cases@>:
  3994.             out(@'\\');
  3995.             break;
  3996.         }
  3997.     out(a);
  3998.     }
  3999. }
  4000.  
  4001. @ The |break_out| routine is called just before the output buffer is about
  4002. to overflow. To make this routine a little faster, we initialize position~0
  4003. of the output buffer to~'\.\\'; this character isn't really output.
  4004.  
  4005. @<Set init...@>=
  4006.  
  4007. out_buf[0] = @'\\';
  4008.  
  4009. @ A long line is broken at a blank space or a newline (which may enter from
  4010. a limbo string), or just before a backslash that isn't preceded by another
  4011. backslash or a newline. In the latter case, a~|'%'| is output at the break.
  4012.  
  4013. @<Part 1@>=@[
  4014.  
  4015. SRTN break_out(VOID) /* finds a way to break the output line */
  4016. {
  4017. ASCII HUGE *k = out_ptr; /* pointer into |out_buf| */
  4018. boolean is_tex_comment = BOOLEAN(*(out_buf+1) == @'%');
  4019.  
  4020. if(nuweb_mode)
  4021. WHILE()
  4022.     {
  4023.     if(k==out_buf)
  4024.         @<Print warning message, break the line, and |return|@>; 
  4025.  
  4026.     if(*(k--) == @'\n')
  4027.         {
  4028.         flush_buffer(++k, NO);
  4029.         break;
  4030.         }
  4031.     }
  4032. else
  4033. WHILE()
  4034.     {
  4035.     if (k==out_buf) 
  4036.         @<Print warning message, break the line, and |return|@>; 
  4037.  
  4038.     if (*k==@' ')
  4039.         {
  4040.         flush_buffer(k,NO); 
  4041.         break;
  4042.         }
  4043.  
  4044.     if (*k==@'\n' && k[-1] != @'\n')
  4045.         {/* Get the per-cent sign before the newline. */
  4046.         *k = @'%';
  4047.         flush_buffer(k,NO); // Kill off the newline.
  4048.         break;
  4049.         }
  4050.  
  4051.     if (*(k--)==@'\\' && *k!=@'\\' && *k != @'\n') 
  4052.         { /* we've decreased |k| */
  4053.         flush_buffer(k,YES); 
  4054.         break;
  4055.         }
  4056.     }
  4057.  
  4058. if(is_tex_comment) 
  4059.     *(++out_ptr) = @'%';
  4060. }
  4061.  
  4062. @ We get to this module only in unusual cases that the entire output line
  4063. consists of a string of backslashes followed by a string of nonblank
  4064. non-backslashes. In such cases it is almost always safe to break the line
  4065. by putting a~|'%'| just before the last character.
  4066.  
  4067. @<Print warning message...@>=
  4068. {
  4069. SET_COLOR(warning);
  4070.   printf("\n! Line had to be broken (output l. %u):\n",out_line);
  4071. @.Line had to be broken@>
  4072.   ASCII_write(out_buf+1, out_ptr-out_buf-1);
  4073.   new_line; mark_harmless;
  4074.   flush_buffer(out_ptr-1,YES); return;
  4075. }
  4076.  
  4077. @ Here is a macro that outputs a module number in decimal notation.  The
  4078. number to be converted by |out_mod| is known to be less than |def_flag|, so
  4079. it cannot have more than five decimal digits.  If the module is changed, we
  4080. output~`\.{\\*}' just after the number.
  4081.  
  4082. @<Part 1@>=@[
  4083.  
  4084. SRTN out_mod FCN((n,encap))
  4085.     sixteen_bits n C0("Module number.")@;
  4086.     boolean encap C1("Encapsulate?")@;
  4087. {
  4088. char s[100];
  4089.  
  4090. if(encap)
  4091.     sprintf(s,"%s%s%u%s",
  4092.         (char *)w_style.indx.encap_prefix, 
  4093.         (char *)w_style.indx.encap_infix
  4094.         ,n
  4095.         , (char *)w_style.indx.encap_suffix); 
  4096. else
  4097.     sprintf(s,"%u",n);
  4098.  
  4099. OUT_STR(s);
  4100.  
  4101. if(chngd_module[n]) OUT_STR("\\*");
  4102. }
  4103.  
  4104. @ The |out_name| procedure is used to output an identifier or index entry,
  4105. enclosing it in braces. When we're outputting an identifier, we must escape
  4106. the various special characters that may sneak in. Index entries are treated
  4107. literally.
  4108.  
  4109. @d IDENTIFIER YES
  4110. @d INDEX_ENTRY NO
  4111.  
  4112. @<Part 1@>=@[
  4113.  
  4114. SRTN out_name FCN((is_id,p))
  4115.     boolean is_id C0("Flag to distinguish identifier/index entry.")@;
  4116.     name_pointer p C1("The name to be output.")@;
  4117. {
  4118. ASCII HUGE *k,  HUGE *k_end=(p+1)->byte_start; // Pointers into |byte_mem|.
  4119. boolean multi_char,non_TeX_macro;
  4120. sixteen_bits mod_defined;
  4121.  
  4122. if(!output_on) 
  4123.     return; // Skip output.
  4124.  
  4125. multi_char = BOOLEAN(k_end - p->byte_start > 1);
  4126.  
  4127. if(multi_char) 
  4128.     out(@'{');// Multiple-letter identifiers are enclosed in braces.
  4129.  
  4130. non_TeX_macro = BOOLEAN(is_id && *p->byte_start == @'\\' && language != TEX);
  4131.  
  4132. if(non_TeX_macro) 
  4133.     out(@'$'); /* \Cpp\ macros (such as those like \.{\\Wcp} that would
  4134.             arise from |@c++ operator +=()|) must be in math mode. */
  4135.  
  4136. for (k=p->byte_start; k<k_end; k++) 
  4137.     {
  4138.     if(is_id)
  4139.         switch(*k)
  4140.             { /* Escape the special characters in identifiers. */
  4141.            case @'\\':
  4142.            case @'{': case @'}': 
  4143. /* A non-\TeX\ identifier can result from the translation of an operator
  4144. name in \Cpp.  For that, we shouldn't escape the opening backslash.  We
  4145. also assume that any braces following that macro should be interpreted
  4146. literally. */
  4147.             if(non_TeX_macro) 
  4148.                 break; 
  4149.  
  4150.            @<Other string cases@>:
  4151.             out(@'\\');
  4152.             }
  4153.  
  4154.     out(*k);
  4155.     }
  4156.  
  4157. if(non_TeX_macro) 
  4158.     out(@'$');
  4159.  
  4160. if(multi_char) 
  4161.     out(@'}');
  4162.  
  4163. if(p->wv_macro)
  4164.     @<Output the overloaded translation@>@;
  4165.  
  4166. /* Should do all languages here. (Sorted!). */
  4167. if(subscript_fcns && (mod_defined = p->defined_in(language)))
  4168.     {
  4169.     char temp[100];
  4170.  
  4171.     if(output_protect)
  4172.         OUT_STR("\\protect");
  4173.  
  4174.     sprintf(temp,"\\WIN%d{%d}",DEFINED_TYPE(p),
  4175.         mod_defined==module_count ? 0 : mod_defined);
  4176.     OUT_STR(temp);
  4177.     }
  4178. }
  4179.  
  4180. @
  4181. @<Output the overlo...@>=
  4182. {
  4183. WV_MACRO HUGE *w = p->wv_macro;
  4184. ASCII HUGE *s = w->text;
  4185.  
  4186. OUT_STR("\\WTeX{");
  4187.  
  4188. while(*s)
  4189.     out(*s++);
  4190.  
  4191. out(@'}');
  4192. }
  4193.  
  4194. @ The following can occur in identifiers recognized by \FWEB.
  4195. @<Special identifier cases@>=
  4196.  
  4197. case @'_':
  4198. case @'$':
  4199. case @'%':
  4200. case @'#':
  4201. case @'\\':
  4202.     out(@'\\')@;
  4203.  
  4204. @* ROUTINES THAT COPY \TeX\ MATERIAL.  During phase two, we use the
  4205. subroutines |copy_limbo| and |copy_TeX| in place of the analogous
  4206. |skip_limbo| and |skip_TeX| that were used in phase one. The routine
  4207. |copy_comment| serves for both phases.
  4208.  
  4209. The |copy_limbo| routine, for example, begins by outputting two kinds of
  4210. \TeX\ code that it has constructed or collected.  First, it writes out
  4211. \TeX\ definitions for user-defined dot constants; second, it writes out any
  4212. limbo text that it collected during phase one.  Then it takes \TeX\
  4213. material that is not part of any module and transcribes it almost verbatim
  4214. to the output file.  No `\.{@@}'~signs should occur in such material except
  4215. in `\.{@@@@}'~pairs; such pairs are replaced by singletons.
  4216.  
  4217. @<Part 2@>=@[
  4218.  
  4219. SRTN copy_limbo(VOID)
  4220. {
  4221. ASCII c;
  4222.  
  4223. @<Output default definitions for user-defined dot constants@>@;
  4224. @<Output any limbo text definitions@>@;
  4225.  
  4226. OUT_STR("\n% --- Beginning of user's limbo section ---");
  4227. flush_buffer(out_ptr,NO);
  4228.  
  4229. WHILE()
  4230.     {
  4231.         if (loc>limit && (fin_line(), !get_line())) 
  4232.         break;
  4233.  
  4234.         *(limit+1)=@'@@';
  4235.  
  4236.         while (*loc!=@'@@') out(*(loc++)); // Copy verbatim to output.
  4237.  
  4238.         if (loc++<=limit) 
  4239.         {
  4240.           c=*loc++;     // Character after `\.{@@}'.
  4241.  
  4242.           if (ccode[c]==new_module) 
  4243.         break;
  4244.  
  4245.           if (c!=@'z' && c!=@'Z')
  4246.             switch(ccode[c])
  4247.                 {
  4248.                @<Cases to set |language| and |break|@>@:@;
  4249.  
  4250.             case toggle_output: 
  4251.                 out_skip();
  4252.                 break; 
  4253.  
  4254.             case invisible_cmnt:
  4255.                 loc = limit + 1; // Skip entire rest of line.
  4256.                 break;
  4257.  
  4258.             case @'@@':
  4259.                     out(@'@@'); // $\.{@@@@} \to \.{@@}$.
  4260.                 break;
  4261.  
  4262.             default:
  4263.                   ERR_PRINT(W,"Double @@ required\
  4264.  outside of sections"); 
  4265. @.Double \AT! required...@>
  4266.                  }
  4267.         }
  4268.     }
  4269.  
  4270. @<Output the end of limbo section@>@;
  4271. }
  4272.  
  4273. @ By the beginning of phase~2, we know about any user-defined operators in
  4274. \Fortran-90 via the \.{@@v}~command.  Here we output default (empty)
  4275. definitions of the associated 
  4276. macros.  The user can override these in his limbo section.
  4277.  
  4278. @<Output default def...@>=
  4279. {
  4280. int k;
  4281. OPERATOR *p;
  4282.  
  4283. /* An extra blank line after \.{\\input fwebmac.sty}. */
  4284. for(k=0; k<NUM_LANGUAGES; k++)
  4285.     if(overloaded[k])
  4286.         {
  4287.         flush_buffer(out_ptr,NO);
  4288.         break;
  4289.         }
  4290.  
  4291. for(k=0; k<NUM_LANGUAGES; k++)
  4292.     if(overloaded[k])
  4293.         {
  4294.         flush_buffer(out_ptr,NO);
  4295.  
  4296.            OUT_STR("% --- Overloaded operator definitions from @@v for '");
  4297.         OUT_STR(lang_codes[k]);
  4298.         OUT_STR("' ---");
  4299.         flush_buffer(out_ptr,NO);
  4300.  
  4301.         for(p=op; p<op_ptr; p++)
  4302.             {
  4303.             OP_INFO HUGE *q = p->info + k;
  4304.  
  4305.             if(q->overloaded)
  4306.                 @<Define to \TeX\ an overloaded operator@>@;
  4307.             }
  4308.  
  4309.         flush_buffer(out_ptr,NO);
  4310.         }
  4311. }
  4312.  
  4313. @ This fragment produces output of the form
  4314. ``\.{\\newbinop\{abc\}\{C\{def\}}''.  See \.{fwebmac.web} to learn how such
  4315. macros are defined.
  4316.  
  4317. @<Define to \TeX\ ...@>=
  4318. @{
  4319. #define TEMP_LEN 1000
  4320.  
  4321. outer_char temp[TEMP_LEN], outer_op_name[100];
  4322.  
  4323. OUT_STR("\\new");
  4324.  
  4325. switch(q->cat)
  4326.     {
  4327.     case unorbinop:
  4328.     case binop:
  4329.         OUT_STR("binop"); @~ break;
  4330.  
  4331.     case unop:
  4332.         OUT_STR("unop"); @~ break;
  4333.  
  4334.     default:
  4335.         OUT_STR("op"); @~ break;
  4336.     }
  4337.  
  4338. STRCPY(outer_op_name,p->op_name); @~ to_outer((ASCII *)outer_op_name);
  4339. SPRINTF(TEMP_LEN,temp,`"{%s}{%s}{%s} ",outer_op_name,lang_codes[k],q->defn`);
  4340. OUT_STR(temp);
  4341.  
  4342. #undef TEMP_LEN
  4343. }
  4344.  
  4345. @ Limbo text material is collected from all \.{@@l}~commands, then output
  4346. verbatim here, at the beginning of phase two.  We begin by writing out any
  4347. default material from the style file entry \.{limbo}.
  4348. @<Output any limbo text...@>=
  4349. {
  4350. text_pointer t = tok_start + 1;
  4351.  
  4352. /* Default material. */
  4353. if(*w_style.misc.limbo_begin)
  4354.     {
  4355.     flush_buffer(out_ptr,NO);
  4356.     OUT_STR("% --- Limbo text from style-file parameter `limbo.begin' ---");
  4357.     flush_buffer(out_ptr,NO);
  4358.     OUT_STR(w_style.misc.limbo_begin);
  4359.     flush_buffer(out_ptr,NO);
  4360.     }
  4361.  
  4362. /* If there were any \.{@@l}~commands, they were stored in phase~1; output
  4363. them now. */
  4364. if(text_ptr > t)
  4365.     {
  4366.     flush_buffer(out_ptr,NO);
  4367.     OUT_STR("% --- Limbo text from @@l ---"); // Header line.
  4368.     flush_buffer(out_ptr,NO);
  4369.     }
  4370.  
  4371. /* Actual text. */
  4372. for(; t<text_ptr; t++)
  4373.     {
  4374.     out_del_str(*t,*(t+1));
  4375.     flush_buffer(out_ptr,NO);
  4376.     }
  4377.  
  4378. @<Initialize |tok_ptr|...@>@;
  4379. }
  4380.  
  4381. @
  4382. @<Output the end of limbo...@>=
  4383. {
  4384. if(*w_style.misc.limbo_end)
  4385.     {
  4386.     flush_buffer(out_ptr,NO);
  4387.     OUT_STR("% --- Limbo text from style-file parameter `limbo.end' ---");
  4388.     flush_buffer(out_ptr,NO);
  4389.     OUT_STR(w_style.misc.limbo_end);
  4390.     flush_buffer(out_ptr,NO);
  4391.     }
  4392. }
  4393.  
  4394. @
  4395. @<Unused@>=
  4396.  
  4397. if(Fortran88)
  4398.     {
  4399.     DOTS *d;
  4400.  
  4401.     flush_buffer(out_ptr,NO);
  4402.  
  4403.     for(d=dots + PREDEFINED_DOTS; d->code; d++)
  4404.         if(d->code == dot_const) 
  4405.             fprintf(tex_file,"\\newdot{%s}{} ",d->symbol);
  4406.  
  4407.     if(d-dots > PREDEFINED_DOTS + 1) flush_buffer(out_ptr,NO);
  4408.     }
  4409.  
  4410. @ A fragment that toggles the output switch.  This is used in conjunction
  4411. with the \.{@@i}~command, which is translated into a |toggle_output|.
  4412.  
  4413. @<Glob...@>=
  4414.  
  4415. EXTERN boolean strt_off SET(NO), ending_off SET(NO);
  4416.  
  4417. @
  4418. @<Toggle output@>=
  4419. {
  4420. static int outer_include_depth;
  4421.  
  4422. if(output_on)
  4423.     {
  4424.     if(phase==2) 
  4425.         {
  4426.         flush_buffer(out_ptr,NO);
  4427.         }
  4428.     outer_include_depth = incl_depth;
  4429.     output_on = NO;
  4430.     }
  4431. else if(incl_depth <= outer_include_depth) 
  4432.     {
  4433.     output_on = YES;
  4434.     }
  4435. }
  4436.  
  4437. @ While appending code text, store the state of the output.
  4438. @
  4439. @<Store the output switch@>=
  4440. {
  4441. if(output_on) app(Turn_output_on);
  4442. else
  4443.     {    
  4444.     app(force); /* If we don't do this, output is turned off before the
  4445. contents of the last line are printed. */
  4446.     app(turn_output_off);
  4447.     }
  4448.  
  4449. app_scrap(ignore_scrap,no_math);
  4450. }
  4451.  
  4452. @ While appending code text, store the state of the output.
  4453. @
  4454. @<Store output switch and \.{\\Wskipped}@>=
  4455. {
  4456. if(output_on) app(Turn_output_on);
  4457. else
  4458.     {    
  4459.     app(force);
  4460.     app(Turn_output_off);
  4461.     }
  4462.  
  4463. app_scrap(ignore_scrap,no_math);
  4464. }
  4465.  
  4466. @ The |copy_TeX| routine processes the \TeX\ code at the beginning of a
  4467. module; for example, the words you are now reading were copied in this way.
  4468. It returns the next control code or~`\v' found in the input.  Lines that
  4469. consist of all spaces are made empty; spaces between the beginning of a
  4470. line and an \.{@@}~command are stripped away.  (Unlike the original design,
  4471. we leave tab marks in, since some users use those as active characters.)
  4472. This makes the test for empty lines in |fin_line| work.
  4473.  
  4474. @<Part 2@>=@[
  4475. eight_bits copy_TeX(VOID)
  4476. {
  4477. ASCII c; // Current character being copied.
  4478.  
  4479. WHILE()
  4480.     {
  4481.     if (loc>limit)
  4482.         {
  4483.         @<Delete run of spaces between beginning of line and
  4484. present position@>@;
  4485.         fin_line();
  4486.  
  4487.         if(!get_line()) 
  4488.             return new_module;
  4489.         }
  4490.  
  4491.     *(limit+1)=@'@@';
  4492.  
  4493. scan:
  4494.     while ((c=*(loc++))!=@'|' && c!=@'@@')
  4495.         {
  4496.         if(c==interior_semi) 
  4497.             c = @';';
  4498.          out(c); // Copy \TeX\ verbatim to output.
  4499.  
  4500. #if(0)
  4501.         if (out_ptr==out_buf+1 && (c==@' '
  4502.                  || c==tab_mark
  4503.             )) out_ptr--; 
  4504. #endif
  4505.         }
  4506.  
  4507.     if (c==@'|') 
  4508.         return @'|'; // Beginning of code mode.
  4509.  
  4510.     if (loc<=limit)
  4511.         { /* Found an \.{@@}. */
  4512.         eight_bits cc;
  4513.  
  4514.         if(*loc == @'@@')
  4515.             {
  4516.             out(@'@@');
  4517.             loc++;
  4518.             goto scan;
  4519.             }
  4520.  
  4521.         @<Delete run of spaces...@>@;
  4522.  
  4523.         SET_CASE(*loc);
  4524.  
  4525.         if( (cc = ccode[*(loc++)]) != big_line_break) 
  4526.             return cc;
  4527.  
  4528.         if(loc >= limit) 
  4529.             return cc;
  4530.  
  4531.         @<Process possible pre...@>; // An `\.{@@\#\dots}' command.
  4532.         return cc; // A |big_line_break| command.
  4533.         }
  4534.     }
  4535.  
  4536. DUMMY_RETURN(ignore);
  4537. }
  4538.  
  4539. @ If there are only spaces between the beginning of the output buffer and
  4540. the present position |out_ptr|, delete those spaces.
  4541. @<Delete run of spaces...@>=
  4542. {
  4543. ASCII HUGE *b;
  4544.  
  4545. for(b=out_buf+1; b<=out_ptr; b++)
  4546.     if(*b != @' ') 
  4547.         break;
  4548.  
  4549. if(b > out_ptr) 
  4550.     out_ptr = out_buf;
  4551. }
  4552.  
  4553. @ A flag lets us know when we're processing a comment.
  4554. @<Glob...@>=
  4555.  
  4556. EXTERN boolean in_comment;
  4557.  
  4558. @ The |copy_comment| function issues a warning if more braces are opened
  4559. than closed, and in the case of a more serious error it supplies enough
  4560. braces to keep \TeX\ from complaining about unbalanced braces. (Because of
  4561. a bug inherited from \CWEB, this doesn't work right if there is a
  4562. construction such as~`\.{\\\{}' in the comment.)  Instead of copying the
  4563. \TeX\ material into the output buffer, this function copies it into the
  4564. token memory.  The abbreviation |app_tok(t)| is used to append token~|t| to
  4565. the current token list, and it also makes sure that it is possible to
  4566. append at least one further token without overflow.
  4567.  
  4568. @d app_tok(c) {if (tok_ptr+2>tok_m_end)
  4569.             OVERFLW("tokens",ABBREV(max_toks_w)); 
  4570.         app(c);} 
  4571.  
  4572. @<Part 2@>=@[
  4573.  
  4574. int copy_comment FCN((bal)) /* copies \TeX\ code in comments */
  4575.     int bal C1("Brace balance.")@;
  4576. {
  4577. ASCII c; //* Current character being copied.
  4578. char terminator[2];
  4579. token_pointer tok_ptr0 = tok_ptr;
  4580.  
  4581. in_comment = YES;
  4582.  
  4583. terminator[0] = *limit; @~ terminator[1] = *(limit+1);
  4584.  
  4585. *limit = @' '; /* Space to implement continued line.  Short commands will
  4586.             be ended by this space. */
  4587.  
  4588. /* Especially when it comes to stars and asterisks, we need to know when
  4589. we're copying \TeX. Since this is actually going into token memory instead
  4590. of being transcribed directly to the output, we append the |copy_mode| flag
  4591. to help us know where we are. For this to work properly, one must return
  4592. only from the bottom of this function, because we append another
  4593. |copy_mode| at the bottom. */
  4594. if(phase == 2) 
  4595.     app_tok(copy_mode);
  4596.  
  4597. WHILE()
  4598.     {
  4599.     if(loc > limit) 
  4600.         @<Continue comment if necessary@>@;
  4601.  
  4602. // Get the next character.  Convert a run of tabs into one tab.
  4603.     if(language==TEX) 
  4604.         c = *loc++;
  4605.     else do 
  4606.         c = *(loc++);
  4607.     while(c == tab_mark);
  4608.  
  4609.         if (c==@'|') break; // Found beginning of code mode.
  4610.  
  4611.     if (c==@'*' && *loc==@'/' && long_comment) 
  4612.         {
  4613.         loc++; // Position after `\.{\starslash}'.
  4614.  
  4615.         @<Finish comment and |break|@>;
  4616.         }
  4617.  
  4618. /* It looks better in the \.{tex} file if tabs are replaced by spaces.
  4619. Presumably this won't harm anything else. */
  4620.         if (phase==2) 
  4621.         @<Append comment text@>@;
  4622.  
  4623.         @<Copy special things when |c=='@@', '\\', '{', '}'|@>; 
  4624.     }
  4625.  
  4626. if(phase == 2) 
  4627.     app_tok(copy_mode); // Negate the copying mode.
  4628.  
  4629. *limit = terminator[0]; @~ *(limit+1) = terminator[1];
  4630.  
  4631. if(!long_comment && *limit == @'@@' && loc > limit) 
  4632.     loc = limit;
  4633.  
  4634. in_comment = NO;
  4635. return bal;
  4636. }
  4637.  
  4638. @
  4639. @<Continue comment if nec...@>=
  4640. {
  4641. if(!(long_comment || language==TEX))
  4642.     { // End of short comment.
  4643.     if(auto_semi && *(tok_ptr-2) == @';' &&    *(tok_ptr-1) == @' ')
  4644.             tok_ptr -= 2;
  4645.  
  4646. /* Strip trailing spaces. */
  4647.     while(*(tok_ptr-1) == @' ') 
  4648.         tok_ptr--;
  4649.  
  4650. /* If the last space happened to be escaped, kill the escape. */
  4651.     if(*(tok_ptr-1) == @'\\' && *(tok_ptr-2) != @'\\') 
  4652.         tok_ptr--;
  4653.  
  4654. /* Kill the trailing end-of-comment. */
  4655.     if(*(tok_ptr-2)==@'*' && *(tok_ptr-1)==@'/') 
  4656.         tok_ptr -= 2;
  4657.  
  4658.     @<Finish comment and |break|@>@;
  4659.     }
  4660.  
  4661. if (!get_line())
  4662.     {
  4663.     if(language!=TEX)
  4664.        ERR_PRINT(W,"Input ended in mid-comment");
  4665. @.Input ended in mid-comment@>
  4666.         loc=cur_buffer+1; @<Clear |bal| and |break|@>;
  4667.     }
  4668.  
  4669. /* For \TeX, we concatenate adjacent lines that all begin with comment
  4670. characters. */
  4671. if(language==TEX)
  4672.     {
  4673.     if(loc==limit) @<Finish comment...@>@;
  4674.  
  4675.     for(;loc <= limit; loc++)
  4676.       if(*loc!=@' ' && *loc!=tab_mark) break;
  4677.  
  4678.     if(loc > limit) continue;
  4679.  
  4680.     if(TeX[*loc] == TeX_comment) loc++;
  4681.     else 
  4682.         { // Unskip the white space.
  4683.         loc = cur_buffer;
  4684.         @<Finish comment...@>@;
  4685.         }
  4686.     }                
  4687. }
  4688.  
  4689. @ During phase~2, we must actually append the text character by character.
  4690. That's essentially straightforward, but a few replacements are made.
  4691.  
  4692. @<Append comment text@>=
  4693. switch(c)
  4694.     {
  4695.    case tab_mark:
  4696.     if(language==TEX) 
  4697.         APP_STR("\\quad");
  4698.     else 
  4699.         app_tok(@' '); 
  4700.  
  4701.     break;
  4702.  
  4703.    case interior_semi:
  4704.     app_tok(@';'); 
  4705.     break;
  4706.  
  4707.    case @'%':
  4708.     if(language==TEX)
  4709.         app_tok(@'\\');
  4710.  
  4711.     app_tok(c);
  4712.     break;
  4713.  
  4714.    default:
  4715. /* Basically, we just append the present character here.  However, compiler
  4716. directives need to be escaped. */
  4717.     if(doing_cdir)
  4718.         switch(c)
  4719.             {
  4720.             @<Special string cases@>:
  4721.             app_tok(@'\\');
  4722.             }
  4723.  
  4724.     app_tok(c); 
  4725.     break;
  4726.     }
  4727.  
  4728. @ This fragment finishes off a comment, ensuring that braces are properly
  4729. balanced. 
  4730. @<Finish comment...@>=
  4731.  
  4732. if(bal==1) 
  4733.     {
  4734.     if (phase==2) 
  4735.         {
  4736.         if(language==TEX) @<Check for a null \TeX\ comment@>@;
  4737.         app_tok(@'}'); 
  4738.         }
  4739.     bal = 0;
  4740.     break;
  4741.     }
  4742. else 
  4743.     {
  4744.     ERR_PRINT(W,"Braces don't balance in comment");
  4745. @.Braces don't balance in comment@>
  4746.     @<Clear |bal| and |break|@>;
  4747.     }
  4748.  
  4749. @
  4750. @<Check for a null ...@>=
  4751. {
  4752. token_pointer t;
  4753.  
  4754. for(t=tok_ptr-1; t>tok_ptr0; t--)
  4755.     if(*t != @' ') break;
  4756.  
  4757. if(t == tok_ptr0 && *(t-4)==@'\\' && *(t-3)==@'W' && *(t-2)==@'C' &&
  4758.         *(t-1)==@'{')
  4759.     *(tok_ptr0-2) = @'x'; // Change \.{\\WC} to \.{\\Wx}.
  4760. }
  4761.  
  4762.  
  4763. @<Copy special things when |c=='@@'...@>=
  4764.  
  4765. if (c==@'@@') 
  4766.     {
  4767.       if (*(loc++)!=@'@@') 
  4768.         {
  4769.         ERR_PRINT(W,"Illegal use of @@ in comment");
  4770. @.Illegal use of \AT!...@>
  4771.         loc-=2; 
  4772.  
  4773.         if (phase==2) 
  4774.             tok_ptr--; 
  4775.         
  4776.         @<Clear |bal|...@>;
  4777.         }
  4778.     }
  4779. else if (c==@'\\' && *loc!=@'@@' && phase==2) 
  4780.     app_tok(*(loc++))@;
  4781. else if (c==@'{') 
  4782.     bal++;
  4783. else if (c==@'}') 
  4784.     bal--;
  4785.  
  4786. @ When the comment has terminated abruptly due to an error, we output
  4787. enough right braces to keep \TeX\ happy.
  4788.  
  4789. @<Clear |bal|...@>=
  4790.  
  4791. app_tok(@' '); /* this is done in case the previous character was~`\.\\' */
  4792.  
  4793. while (bal-- >0) app_tok(@'}');
  4794.  
  4795. bal = 0;
  4796. break;
  4797.  
  4798. @i scraps.hweb /* Declarations related to the scraps and productions. */
  4799.  
  4800. @
  4801. @<Alloc...@>=
  4802.  
  4803. ALLOC(scrap,scrp_info,ABBREV(max_scraps),max_scraps,0);
  4804. scrp_end=scrp_info+max_scraps -1; /* end of |scrp_info| */  
  4805.  
  4806. @<Set init...@>=
  4807.  
  4808. scrp_base=scrp_info+1;
  4809.  
  4810. mx_scr_ptr=scrp_ptr=scrp_info;
  4811.  
  4812. @* INITIALIZING the SCRAPS.  If we are going to use the powerful production
  4813. mechanism just developed, we must get the scraps set up in the first place,
  4814. given a \cee\ text. A table of the initial scraps corresponding to \cee\
  4815. tokens appeared above in the section on parsing; our goal now is to
  4816. implement that table. We shall do this by implementing a subroutine called
  4817. |C_parse| that is analogous to the |C_xref| routine used during phase one.
  4818.  
  4819. Like |C_xref|, the |C_parse| procedure starts with the current value of
  4820. |next_control| and it uses the operation |next_control=get_next()| repeatedly
  4821. to read \cee\ text until encountering the next~`\v' or comment, or until
  4822. |next_control>=formatt|. The scraps corresponding to what it reads are
  4823. appended into the |cat| and |trans| arrays, and |scrp_ptr| is advanced.
  4824.  
  4825. @<Glob...@>=
  4826.  
  4827. EXTERN boolean scanning_meta SET(NO);
  4828.  
  4829. @
  4830. @<Part 2@>=@[
  4831.  
  4832. SRTN C_parse FCN((mode0)) /* Creates scraps from \cee\ tokens */
  4833.     PARSING_MODE mode0 C1("")@;
  4834. {
  4835. name_pointer p; // Identifier designator.
  4836. LANGUAGE language0 = language; // Save the incoming language.
  4837. PARSE_PARAMS parse_params0;
  4838.  
  4839. parse_params0 = parse_params; // Save parsing state.
  4840.  
  4841. parsing_mode = mode0;
  4842.  
  4843.  
  4844. if(parsing_mode == INNER)
  4845.     { // Start fresh for parsing interior code.
  4846.     at_beginning = YES;
  4847.     preprocessing = NO;
  4848.     }
  4849.  
  4850. while (next_control<formatt) 
  4851.     {
  4852.     if(nuweb_mode && parsing_mode == INNER)
  4853.         @<Append a verbatim scrap@>@;
  4854.     else
  4855.         {
  4856.         @<Append the scrap appropriate to |next_control|@>;
  4857.         next_control = get_next();
  4858.         }
  4859.  
  4860.     if (next_control==@'|' || next_control==begin_comment) 
  4861.         break;
  4862.  
  4863.  
  4864.     if(next_control == begin_language && !ok_to_define 
  4865.             && parsing_mode == OUTER)
  4866.         return;
  4867.     }
  4868.  
  4869. /* If the language has changed, append stuff to restore it. */
  4870. if(language != language0)
  4871.     {
  4872.     app_tok(begin_language);
  4873.     app(lan_num(language0));
  4874.     app_scrap(ignore_scrap,no_math);
  4875.     }
  4876.  
  4877. if(parsing_mode == INNER)
  4878.     parse_params = parse_params0; // Restore incoming values.
  4879. }
  4880.  
  4881. @ This fragment is a simple kludge; it doesn't handle various cases
  4882. gracefully, such as `\.{||}'.
  4883.  
  4884. @<Append a verbatim s...@>=
  4885. {
  4886. while(loc < limit)
  4887.     {
  4888.     if(*loc == @'|')
  4889.         {
  4890.         next_control = *loc++;
  4891.         break;
  4892.         }
  4893.  
  4894.     app(*loc++);
  4895.     }
  4896.             
  4897. app_scrap(ignore_scrap, no_math);
  4898. }
  4899.  
  4900. @ The following macro is used to append a scrap whose tokens have just
  4901. been appended.  Note that mathness is stored in the form $4(\hbox{\it right
  4902. boundary}) + \hbox{\it left boundary}$.  Thus, noting that $5b = 4b + b$,
  4903. we see that the construction~$5b$ makes the left- and right-hand boundaries
  4904. equal. 
  4905.  
  4906. @d app_scrap(c,b)@/
  4907.     (++scrp_ptr)->cat = (eight_bits)(c); 
  4908.     scrp_ptr->trans = text_ptr;
  4909.     scrp_ptr->mathness = (eight_bits)(5*(b)); /* Make left and right
  4910.         boundaries equal. */  
  4911.     freeze_text@;
  4912.  
  4913. @<Part 2@>=@[
  4914.  
  4915. SRTN set_language FCN((language0))
  4916.     LANGUAGE language0 C1("")@;
  4917. {
  4918. char language_line[50];
  4919.  
  4920. language = language0;
  4921.  
  4922. app_tok(begin_language);
  4923. app(lan_num(language));
  4924.  
  4925. if(parsing_mode == OUTER)
  4926.     {
  4927.     sprintf(language_line,"\\LANGUAGE{%s}", 
  4928.         (char *)LANGUAGE_CODE(language));
  4929.     APP_STR(language_line);
  4930. @.\\LANGUAGE@>
  4931.     }
  4932.  
  4933. app_scrap(language_scrap,no_math);
  4934. }
  4935.  
  4936. @ Operator overloading.
  4937. @<Glob...@>=
  4938.  
  4939. EXTERN boolean overloaded[NUM_LANGUAGES];
  4940.  
  4941. EXTERN BUF_SIZE op_entries; /* Length for dynamic array. */
  4942. EXTERN OPERATOR HUGE *op, HUGE *op_end; /* Dynamic array of entries for
  4943.             operator overloading. */ 
  4944. EXTERN OPERATOR HUGE *op_ptr; /* Next open position in |OP|. */
  4945.  
  4946. @ Initializing operators is conveniently handled by macros. 
  4947.  
  4948. /* Initialize an ordinary operator such as~`\.+'. */
  4949. @d INIT_OP(op_code,op_name,lang,op_macro,cat) 
  4950.     init_op((eight_bits)(op_code),OC(op_name),(int)(lang),OC(op_macro),
  4951.         NO,cat,(CONST outer_char *)NULL)
  4952.  
  4953. /* Initialize a compound assignment operator such as~`\.{+=}'. */
  4954. @d INIT_CA(ca_index,op_name,lang,op_macro,cat)
  4955.     assignment_token = ca_index;
  4956.     INIT_OP(compound_assignment,OC(op_name),(int)(lang),OC(op_macro),cat)@;
  4957.  
  4958. /* Initialize a dot operator such as~`\.{.NE.}'. */
  4959. @d INIT_DOT(op_name,lang,op_macro,cat)
  4960.        init_op((eight_bits)identifier,OC(op_name),(int)(lang),OC(op_macro),
  4961.         NO,cat,(CONST outer_char *)NULL)
  4962.  
  4963. @d ALL_LANGUAGES ((int)C | (int)C_PLUS_PLUS | (int)FORTRAN | (int)FORTRAN_90 
  4964.     | (int)(RATFOR) | (int)(RATFOR_90) | (int)LITERAL)
  4965.  
  4966. @d ONLY_C_like ((int)C | (int)C_PLUS_PLUS)
  4967. @d ALL_BUT_C_like (~ONLY_C_like)
  4968. @d ALL_BUT_Cpp ((int)C | (int)FORTRAN | (int)FORTRAN_90 
  4969.     | (int)(RATFOR) | (int)(RATFOR_90) | (int)LITERAL)
  4970.  
  4971. @<Alloc...@>=
  4972. {
  4973. int l;
  4974.  
  4975. for(l=0; l<NUM_LANGUAGES; l++)
  4976.     overloaded[l] =NO;
  4977.  
  4978. ALLOC(OPERATOR,op,ABBREV(op_entries),op_entries,0);
  4979. op_end = op + op_entries;
  4980. op_ptr = op + 128; /* The first 128 are for direct indexing. */
  4981.  
  4982. @<Initialize ordinary operators@>;
  4983. @<Initialize compound assignment operators@>;
  4984. }
  4985.  
  4986. @
  4987. @<Initialize ordinary op...@>=
  4988.  
  4989.  INIT_OP(@'!',"NOT",ALL_LANGUAGES,"\\WR",unop); // `|!|'
  4990.  INIT_DOT("NOT",ALL_BUT_C_like,"\\WR",unop);
  4991. @.\\WR@> @..NOT.@>
  4992.  
  4993.  INIT_OP(@'%',"MOD",ALL_LANGUAGES,"\\MOD",binop); // `|%|'
  4994. @.\\MOD@>
  4995.  
  4996.  INIT_OP(@'&',"LAND",C,"\\amp",unorbinop);  /* `|&|'. */
  4997.  INIT_OP(@'&',"LAND",C_PLUS_PLUS,"\\amp",reference);
  4998. @.\\amp@>
  4999.  INIT_OP(@'&',"LAND",ALL_BUT_C_like,"\\AND",binop); // `|@r &|'
  5000. @.\\AND@>
  5001.  
  5002.  INIT_OP(@'*',"STAR",ALL_LANGUAGES,"\\ast",unorbinop); // `|*|'
  5003. @.\\ast@>
  5004.  INIT_OP(@'+',"PLUS",ALL_LANGUAGES,"+",unorbinop); // `|+|'
  5005.  INIT_OP(@'-',"MINUS",ALL_LANGUAGES,"-",unorbinop); // `|-|'
  5006.  INIT_OP(@'/',"SLASH",ALL_LANGUAGES,"/",binop); // `|/|'
  5007.  
  5008.  INIT_OP(@'<',"LT",ALL_BUT_Cpp,"<",binop); // `|<|'
  5009.  INIT_OP(@'<',"LT",C_PLUS_PLUS,"<",langle); // `|<|'
  5010.  INIT_DOT("LT",ALL_BUT_C_like,"<",binop);
  5011. @..LT.@>
  5012.  
  5013.  INIT_OP(@'=',"EQUALS",ALL_LANGUAGES,"=",binop); // `|=|'
  5014.  
  5015.  INIT_OP(@'>',"GT",ALL_BUT_Cpp,">",binop); // `|>|'
  5016.  INIT_OP(@'>',"GT",C_PLUS_PLUS,">",rangle); // `|>|'
  5017.  INIT_DOT("GT",ALL_BUT_C_like,">",binop);
  5018. @..GT.@>
  5019.  
  5020.  INIT_OP(@'?',"QUESTION",ONLY_C_like,"\\?",question); // `|?|'
  5021. @.\\?@>
  5022.  INIT_OP(@'^',"CARET",ALL_LANGUAGES,"\\^",binop); // `|x^y|'
  5023. @.\\\^@>
  5024.  
  5025.  INIT_OP(@'|',"OR",ALL_LANGUAGES,"\\OR",binop); // `$\OR$'
  5026. @.\\OR@>
  5027.  INIT_OP(@'~',"TILDE",ONLY_C_like,"\\TLD",unop);
  5028. @.\\TL@>
  5029.  
  5030.  INIT_OP(not_eq,"NE",ALL_LANGUAGES,"\\WI",binop);  /* `|!=|' */
  5031.  INIT_DOT("NE",ALL_BUT_C_like,"\\WI",binop);
  5032. @.\\WI@> @..NE.@>
  5033.  
  5034.  INIT_OP(lt_eq,"LE",ALL_LANGUAGES,"\\WL",binop);   /* `|<=|' */ 
  5035.  INIT_DOT("LE",ALL_BUT_C_like,"\\WL",binop);
  5036. @.\\WL@> @..LE.@>
  5037.  
  5038.  INIT_OP(gt_eq,"GE",ALL_LANGUAGES,"\\WG",binop);  /* `|>=|' */ 
  5039.  INIT_DOT("GE",ALL_BUT_C_like,"\\WG",binop);
  5040. @.\\WG@>
  5041.  
  5042.  INIT_OP(eq_eq,"EQ",ALL_LANGUAGES,"\\WS",binop);  /* `|==|' */
  5043.  INIT_DOT("EQ",ALL_BUT_C_like,"\\WS",binop);
  5044. @.\\WS@> @..EQ.@>
  5045.  
  5046.  INIT_OP(and_and,"AND",ALL_LANGUAGES,"\\WW",binop);  /* `|&&|' */ 
  5047.  INIT_DOT("AND",ALL_BUT_C_like,"\\WW",binop);
  5048. @.\\WW@> @..AND.@>
  5049.  
  5050.  INIT_OP(or_or,"OR",ALL_LANGUAGES,"\\WV",binop);  /* `||| |' */
  5051.  INIT_DOT("OR",ALL_BUT_C_like,"\\OR",binop);
  5052. @.\\WV@> @..OR.@>
  5053.  
  5054.  INIT_OP(plus_plus,"PP",ALL_LANGUAGES,"\\PP",unop); // `|++|'
  5055. @.\\PP@>
  5056.  INIT_OP(minus_minus,"MM",ALL_LANGUAGES,"\\MM",unop); // `|--|'
  5057. @.\\MM@>
  5058.  
  5059.  INIT_OP(minus_gt,"EQV",ONLY_C_like,"\\MG",binop);  /* `|->|' */
  5060. @.\\MG@>
  5061.  INIT_OP(minus_gt,"EQV",ALL_BUT_C_like,"\\EQV",binop);  /* `|@r .eqv.|' */
  5062.  INIT_DOT("EQV",ALL_BUT_C_like,"\\EQV",binop);
  5063. @.\\EQV@> @..EQV.@>
  5064.  
  5065.  INIT_OP(gt_gt, "RSHIFT",ONLY_C_like,"\\GG",binop); // `|>>|'
  5066. @.\\GG@>
  5067.  INIT_OP(lt_lt,"LSHIFT",ONLY_C_like,"\\LL",binop); // `|<<|'
  5068. @.\\LL@>
  5069.  INIT_OP(star_star,"EE",ALL_LANGUAGES,"\\EE",exp_op);  /* `\.{**}' */
  5070. @.\\EE@>
  5071.  INIT_OP(slash_slash,"SlSl",ALL_BUT_C_like,"\\SlSl",binop);  /* `|@r \/|' */
  5072. @.\\SlSl@>
  5073.  
  5074.  INIT_OP(ellipsis,"NEQV",ALL_BUT_C_like,"\\NEQV",binop); // `|@r .NEQV.|'
  5075.  INIT_DOT("NEQV",ALL_BUT_C_like,"\\NEQV",binop);
  5076.  INIT_DOT("XOR",ALL_BUT_C_like,"\\NEQV",binop);
  5077. @..NEQV.@> @..XOR.@>
  5078.  
  5079.  INIT_DOT("FALSE",ALL_BUT_C_like,"\\FALSE",expr); // `|@r .false.|'
  5080. @..FALSE.@>
  5081.  INIT_DOT("TRUE",ALL_BUT_C_like,"\\TRUE",expr)@; // `|@r .true.|'
  5082. @..TRUE.@>
  5083.  
  5084. @
  5085. @<Initialize compound...@>=
  5086.  
  5087.  INIT_CA(plus_eq,"Wcp",ALL_LANGUAGES,"\\Wcp",binop); // `|+=|'
  5088. @.\\Wcp@>
  5089.  INIT_CA(minus_eq,"Wcm",ALL_LANGUAGES,"\\Wcm",binop); // `|-=|'
  5090. @.\\Wcm@>
  5091.  INIT_CA(star_eq,"Wcs",ALL_LANGUAGES,"\\Wcs",binop); // `|*=|'
  5092. @.\\Wcs@>
  5093.  INIT_CA(slash_eq,"Wcv",ALL_LANGUAGES,"\\Wcv",binop); // `|/=|'
  5094. @.\\Wcv@>
  5095.  INIT_CA(mod_eq,"Wcd",ONLY_C_like,"\\Wcd",binop); // `|%=|'
  5096. @.\\Wcd@>
  5097.  INIT_CA(xor_eq,"Wcx",ONLY_C_like,"\\Wcx",binop); // `|^=|'
  5098. @.\\Wcx@>
  5099.  INIT_CA(and_eq,"Wca",ONLY_C_like,"\\Wca",binop); // `|&=|'
  5100. @.\\Wca@>
  5101.  INIT_CA(or_eq,"Wco",ONLY_C_like,"\\Wco",binop); // `||=|'
  5102. @.\\Wco@>
  5103.  INIT_CA(gt_gt_eq,"Wcg",ONLY_C_like,"\\Wcg",binop); // `|>>=|'
  5104. @.\\Wcg@>
  5105.  INIT_CA(lt_lt_eq,"Wcl",ONLY_C_like,"\\Wcl",binop)@; // `|<<=|'
  5106. @.\\Wcl@>
  5107.  
  5108. @ Initializing an operator involves several possibilities.  If the
  5109. operator's code is less than~128, the info is put directly into the
  5110. corresponding table position.  Otherwise, as for a new dot constant, we
  5111. search through the positions $>= 128$ and insert it at the first available
  5112. slot. 
  5113. @<Part 3@>=@[
  5114.  
  5115. SRTN init_op FCN((op_code,op_name,lang,op_macro,overload,cat,defn))
  5116.     eight_bits op_code C0("The operator")@;
  5117.     CONST outer_char op_name[] C0("Fortran-like name of the operator")@;
  5118.     int lang C0("Union of all allowable languages for this def")@;
  5119.     CONST outer_char op_macro[] C0("Default macro expansion")@;
  5120.     boolean overload C0("Do we overload?")@;
  5121.     eight_bits cat C0("Category code")@;
  5122.     CONST outer_char defn[] C1("Replacement text for overloaded macro")@;
  5123. {
  5124. OPERATOR HUGE *p;
  5125. int k,l;
  5126.  
  5127. /* The dot constants won't be in the table yet. Just put them there. */
  5128. if(op_code == identifier) p = op_ptr++; // Next free position for a dot op.
  5129. else if(!(p=valid_op(op_code)))
  5130.         {
  5131.         err_print(W,"Invalid op code %d",op_code);
  5132.         return;
  5133.         }
  5134.  
  5135. p->op_name = GET_MEM("op name",STRLEN(op_name)+1,ASCII);
  5136. STRCPY(p->op_name,op_name);
  5137. to_ASCII((outer_char *)p->op_name);
  5138.  
  5139. /* Access the languages by bit-shifting with~|l|. */
  5140. for(k=0,l=1; k<NUM_LANGUAGES; k++,l<<=1)
  5141.     if(lang & l)
  5142.         {
  5143.         OP_INFO HUGE *q = p->info + k;
  5144.  
  5145.         q->op_macro = op_macro;
  5146.         overloaded[k] |= (q->overloaded = overload);
  5147.         q->cat = cat;
  5148.         if(defn) q->defn = (outer_char HUGE *)defn;
  5149.         }
  5150. }
  5151.  
  5152. @ A storage variable.
  5153. @<Glob...@>=
  5154.  
  5155. EXTERN eight_bits last_control;
  5156.  
  5157. @ Here we translate |next_control| into text characters, which are stored
  5158. in memory.
  5159.  
  5160. @<Append the scrap appropriate to |next_control|@>=
  5161. {
  5162. room_for(6,4,4); // Is there enough room?  (Check and justify these numbers!!!)
  5163.  
  5164. if(next_control) lst_ampersand = NO;
  5165.  
  5166. switch (next_control) 
  5167.  
  5168.     {
  5169.   case macro_module_name: @<Append a module name@>@; break;
  5170.     
  5171.   case stmt_label: 
  5172.   case stringg: case constant: case verbatim: @<Append a string or constant@>;
  5173.     break;
  5174.  
  5175.   case begin_format_stmt: in_format = YES;
  5176.   case identifier: @<Append an identifier scrap@>; break;
  5177.   case TeX_string: @<Append a \TeX\ string scrap@>; break;
  5178.   case begin_language: @<Append scraps for |begin_language|@>; break;
  5179.  
  5180.   case new_output_file: @<Append the output file name@>@; break;
  5181.  
  5182.  
  5183.   case toggle_output:
  5184.     @<Toggle output@>@;
  5185.     @<Store output switch and \.{\\Wskipped}@>@;
  5186.     break; 
  5187.  
  5188.  
  5189.   case macro_space: app(@' '); app_scrap(space,maybe_math); break;
  5190.  
  5191.   @<Cases involving single ASCII characters@>@:@;
  5192.   @<Cases involving nonstandard ASCII characters@>@:@;
  5193.   @<Cases involving special \WEB\ commands@>@:@;
  5194.  
  5195.   default: app(next_control); app_scrap(ignore_scrap,maybe_math); break;
  5196.     }
  5197. }
  5198.  
  5199. @ Check against possible overflow.
  5200.  
  5201. @<Part 3@>=@[
  5202.  
  5203. SRTN room_for FCN((ntokens,ntexts,nscraps))
  5204.     int ntokens C0("")@;
  5205.     int ntexts C0("")@;
  5206.     int nscraps C1("")@;
  5207. {
  5208. if(tok_ptr+ntokens>tok_m_end)
  5209.     {
  5210.     if (tok_ptr>mx_tok_ptr) mx_tok_ptr=tok_ptr;
  5211.     OVERFLW("tokens",ABBREV(max_toks_w));
  5212.     }
  5213.  
  5214. if(text_ptr+ntexts>tok_end) 
  5215.     {
  5216.     if (text_ptr>mx_text_ptr) mx_text_ptr=text_ptr;
  5217.     OVERFLW("texts",ABBREV(max_texts));
  5218.     }
  5219.  
  5220. if (scrp_ptr+nscraps>scrp_end)
  5221.     {
  5222.     if (scrp_ptr>mx_scr_ptr) mx_scr_ptr=scrp_ptr;
  5223.     OVERFLW("scraps",ABBREV(max_scraps));
  5224.     }
  5225. }
  5226.  
  5227. @ Some nonstandard ASCII characters may have entered \.{WEAVE} by means of
  5228. standard ones. They are converted to \TeX\ control sequences so that it is
  5229. possible to keep \.{WEAVE} from stepping beyond standard ASCII.
  5230.  
  5231. @<Cases involving nonstandard...@>=
  5232.  
  5233. /* Overloaded operators can be defined dynamically in \FORTRAN-88. These
  5234. are generically labelled by |dot_const|. The |dot_code| routine fills the
  5235. structure |dot_op| with the macro name and category corresponding to the
  5236. operator. */
  5237. case dot_const: 
  5238.     next_control = identifier;
  5239.     id_first = dot_op.name + 1;
  5240.     id_loc = id_first + STRLEN(id_first);
  5241.     app_overload();
  5242.     break;
  5243.  
  5244. case eq_gt: APP_STR("\\WPtr"); /* `$\WPtr$' */ app_scrap(binop,yes_math);
  5245. break; 
  5246. @.\\WPtr@>
  5247.  
  5248. case ellipsis: 
  5249.     if(C_LIKE(language))
  5250.         {
  5251.         APP_STR("\\dots"); /* `|...|' */
  5252. @.\\dots@>
  5253.         app_scrap(int_like,maybe_math);
  5254.         }
  5255.     else app_overload();
  5256.  
  5257.     break;
  5258.  
  5259. case not_eq: 
  5260. case lt_eq: 
  5261. case gt_eq: 
  5262. case eq_eq: 
  5263. case and_and: 
  5264. case or_or: 
  5265. case plus_plus:
  5266. case minus_minus:
  5267. case minus_gt:
  5268. case gt_gt: 
  5269. case lt_lt:
  5270. case star_star: 
  5271. case slash_slash: 
  5272. case compound_assignment:
  5273.     app_overload(); @~ break;
  5274.  
  5275. case paste: APP_STR("\\NN"); /* `|##|' */ app_scrap(ignore_scrap,maybe_math);
  5276.             break;
  5277. @.\\NN@>
  5278.  
  5279. case dont_expand: APP_STR("\\NP"); /* `|#!|' */
  5280.         app_scrap(ignore_scrap,maybe_math); 
  5281.             break;
  5282. @.\\NP@>
  5283.  
  5284. case auto_label: APP_STR("\\NC"); /* `|#:|' */
  5285.         app_scrap(ignore_scrap,maybe_math); 
  5286.         break;
  5287. @.\\NC@>
  5288.  
  5289. case all_variable_args: 
  5290.     APP_STR("\\ND"); // `|#.|
  5291.     app_scrap(expr,maybe_math);
  5292.     break;
  5293. @.\\ND@>
  5294.  
  5295. case colon_colon: 
  5296.     if(C_LIKE(language))
  5297.         {
  5298. @.\\CC@>
  5299.         APP_STR("\\CC"); // `|a::b|'
  5300.         app_scrap(unop,yes_math);
  5301.         }
  5302.     else
  5303.         {
  5304.         APP_STR("\\CF"); // `|@r a::b|'
  5305. @.\\CF@>
  5306.         app_scrap(binop,yes_math);
  5307.         }
  5308.     break;
  5309.  
  5310. case left_array:
  5311.     APP_STR("\\LS"); // `|@r (/|'
  5312. @.\\LS@>
  5313.     app_scrap(lpar,yes_math);
  5314.     break;
  5315.  
  5316. case right_array:
  5317.     APP_STR("\\SR"); // `|@r /)|'
  5318. @.\\SR@>
  5319.     app_scrap(rpar,yes_math);
  5320.     break;
  5321.  
  5322. @
  5323. @<Cases involving special...@>=
  5324.  
  5325.   case force_line: APP_STR("\\]"); app_scrap(ignore_scrap,yes_math); break;
  5326.   case thin_space: APP_STR("\\,"); app_scrap(ignore_scrap,yes_math); break;
  5327.   case math_break: app(opt); @~ APP_STR("0");
  5328.             app_scrap(ignore_scrap,yes_math); break; 
  5329.   case line_break: app(force); app_scrap(ignore_scrap,no_math); break;
  5330.  
  5331.   case left_preproc: 
  5332.     app(force);
  5333.     if(parsing_mode==OUTER) APP_STR("\\4"); // Backspace for beauty.
  5334.     app_scrap(lproc,no_math); break;
  5335.  
  5336.   case right_preproc: 
  5337.     app(force); app_scrap(rproc,no_math); break;
  5338.  
  5339.   case no_mac_expand:
  5340.     APP_STR("\\WTLD"); app_scrap(expr,maybe_math); break;
  5341.  
  5342.   case begin_meta: 
  5343.     @<Process |begin_meta|@>@;
  5344.     break;
  5345.  
  5346.   case end_meta:
  5347.     if( !nuweb_mode && ((FORTRAN_LIKE(language) && !free_form_input) 
  5348.             || (language==TEX)) )  
  5349.         @<Set up column mode@>@;
  5350.  
  5351.     get_line();
  5352.     APP_STR(w_style.misc.meta.code.end); 
  5353.     app(force);
  5354.     app_scrap(ignore_scrap,no_math); 
  5355.     scanning_meta = NO;
  5356.     break;
  5357.  
  5358. @.\\WBM@>
  5359. @.\\WEM@>
  5360.  
  5361.   case big_line_break: app(big_force); app_scrap(ignore_scrap,no_math); break;
  5362.   case no_line_break: app(big_cancel); @~ APP_STR("\\ ");@~ app(big_cancel);
  5363.     app_scrap(ignore_scrap,no_math); break;
  5364.  
  5365.   case pseudo_expr: app_scrap(expr,maybe_math); @~ break;
  5366.   case pseudo_semi: app_scrap(semi,maybe_math); @~ break;
  5367.   case pseudo_colon: app_scrap(colon,maybe_math); @~ break;
  5368.  
  5369.   case join: APP_STR("\\WJ"); app_scrap(ignore_scrap,no_math); break;
  5370. @.\\WJ@>
  5371.  
  5372.   case protect_code:
  5373.       ERR_PRINT(W,"You can't do that in code text");
  5374. @.You can't do that...@>
  5375.     break;
  5376.  
  5377. @
  5378. @<Process |begin_meta|@>=
  5379. {
  5380. if(!nuweb_mode)
  5381.     app(force);
  5382.  
  5383. app(toggle_meta);
  5384. APP_STR(w_style.misc.meta.code.begin); 
  5385.  
  5386. column_mode = NO;
  5387. scanning_meta = YES;
  5388.  
  5389. WHILE()
  5390.     {
  5391.     if(loc >= limit) // !!!!!
  5392.         {
  5393.         app(@'\n');
  5394.         if(!get_line()) 
  5395.             break;
  5396.         }
  5397.  
  5398.     while(loc < limit) 
  5399.         {
  5400.         if(*loc == @'@@') 
  5401.             @<Check for end of meta-comment and |goto
  5402. done_meta@;| if necessary@>@; 
  5403.         app(*loc++);
  5404.         }
  5405.     }
  5406.  
  5407. done_meta:
  5408.     APP_STR(w_style.misc.meta.code.end); 
  5409.     app(toggle_meta);
  5410.  
  5411.     if(!nuweb_mode)
  5412.         app(force);
  5413.  
  5414.     app_scrap(ignore_scrap,no_math); 
  5415.     scanning_meta = NO;
  5416. }
  5417.  
  5418. @
  5419. @<Check for end of meta-comment...@>=
  5420. {
  5421. switch(ccode[*(loc+1)])
  5422.     {
  5423.    case @'@@':
  5424.     loc++;
  5425.     break;
  5426.  
  5427.    case end_meta:
  5428.     if( !nuweb_mode && ((FORTRAN_LIKE(language) && !free_form_input) 
  5429.             || (language==TEX)) )  
  5430.         @<Set up column mode@>@;
  5431.  
  5432.     get_line();
  5433.     goto done_meta;
  5434.  
  5435.    case invisible_cmnt:
  5436.     if(*(loc+2) == @'%')
  5437.         eat_blank_lines = YES;
  5438.  
  5439.     app(@'\n');
  5440.     get_line();
  5441.  
  5442.     if(eat_blank_lines)
  5443.         {
  5444.         eat_blank_lines = NO;
  5445.  
  5446.         while(loc >= limit)
  5447.             if(!get_line())
  5448.                 goto done_meta;
  5449.         }
  5450.  
  5451.     continue;
  5452.     
  5453.    case new_module:
  5454.     goto done_meta; // !!!!!
  5455.  
  5456.     case line_break: 
  5457.     if(loc[2] == @'*' || loc[2] == @'/')
  5458.         { /* Verbatim comment. */
  5459.         loc++;
  5460.         break;
  5461.         }
  5462.         
  5463. /* Falls through! */
  5464.  
  5465.     case thin_space: 
  5466.     case no_line_break: case join:
  5467.     case pseudo_semi: case pseudo_expr: case pseudo_colon:
  5468.     case compiler_directive: case Compiler_Directive:
  5469.     case no_index: case yes_index:
  5470.     case begin_bp: case insert_bp:
  5471.     loc += 2;
  5472.     continue;
  5473.  
  5474.    case big_line_break: 
  5475.     break; // To handle preprocessor statements easily.
  5476.  
  5477.    default:
  5478.     if(nuweb_mode)
  5479.         goto done_meta;  // !!!!!
  5480.  
  5481.       break;
  5482.     }
  5483. }
  5484.  
  5485. @
  5486. @<Cases involving single...@>=
  5487.  
  5488.   case @'\\':
  5489.     APP_STR("\\ttBS");
  5490.     app_scrap(ignore_scrap,no_math);
  5491.     break;
  5492.  
  5493.   case @'\n': 
  5494.     app(@' ');
  5495.     app_scrap(newline,maybe_math);
  5496.     break;
  5497.  
  5498.   case @'/': 
  5499.     if(in_format)
  5500.         {
  5501.         app(next_control);
  5502.         app_scrap(expr,no_math); /* ``|@r format(//e10.5/f5.2)|'' */
  5503.         }
  5504.     else if(in_data)
  5505.         {
  5506.         app(@'{'); @~ app(next_control); @~ app(@'}');
  5507.         app_scrap(slash_like,maybe_math);
  5508.         }
  5509.     else
  5510.         {
  5511.         app_overload(); /* ``|a/b|'' */
  5512.         }
  5513.     break;
  5514.  
  5515. case @'.': 
  5516.     app(next_control); app_scrap(binop,yes_math); break;
  5517.  
  5518.  case @'+':/* Handle \FORTRAN's |@r +1.0|; now also ANSI~C: ``|x = +2.5;|'' */ 
  5519.  case @'<': 
  5520.  case @'>': 
  5521.  case @'=': 
  5522.  case @'%':
  5523.  case @'!': 
  5524.  case @'~': 
  5525.  case @'-': 
  5526.  case @'*': 
  5527.  case @'|':
  5528.  case @'?':
  5529.  case @'^':
  5530.     app_overload(); @~ break;
  5531.  
  5532.  case @'&':
  5533.     lst_ampersand = YES;
  5534.     app_overload(); @~ break;
  5535.  
  5536.  case @'#': 
  5537.     switch(*loc)
  5538.         {
  5539.        case @'\'':
  5540.         APP_STR("\\Nq");
  5541.         loc++;
  5542.         break;
  5543.  
  5544.        case @'"':
  5545.         APP_STR("\\NQ");
  5546.         loc++;
  5547.         break;
  5548.  
  5549.        default:
  5550.         APP_STR("\\#");
  5551.         break;
  5552.         }
  5553.  
  5554.     app_scrap(expr,maybe_math); 
  5555.     break;
  5556.  
  5557.   case ignore: case xref_roman: case xref_wildcard:
  5558.   case xref_typewriter: break;
  5559.  
  5560.   case @'(': app(next_control); app_scrap(lpar,maybe_math); break;
  5561.   case @')': app(next_control); app_scrap(rpar,maybe_math); break;
  5562.  
  5563.   case @'[': app(next_control); app_scrap(lbracket,yes_math); break;
  5564.   case @']': app(next_control); app_scrap(rbracket,yes_math); break;
  5565.  
  5566.   case @'{': APP_STR("\\{"); app_scrap(lbrace,yes_math); break;
  5567.   case @'}': APP_STR("\\}"); app_scrap(rbrace,yes_math); break;
  5568.   case @',': app(@','); app_scrap(comma,maybe_math); break;
  5569.  
  5570.   case end_format_stmt: in_format = NO; /* Falls through to the next case,
  5571.         which appends the semi. */
  5572.   case interior_semi:
  5573.     in_data = NO;
  5574.     app(@';'); app_scrap(semi,maybe_math); break;
  5575.   case @';': 
  5576.     in_data = NO;
  5577.     if(!is_FORTRAN_(language) || prn_semis)
  5578.         app(@';');
  5579.      app_scrap(semi,maybe_math); break;
  5580.  
  5581.   case @':': app(@':'); app_scrap(colon,maybe_math);
  5582.      break;
  5583.   case @'`': 
  5584. @#if 0
  5585.     if(!ok_to_define)
  5586.         {
  5587.         APP_STR("\\LA"); app_scrap(expr,maybe_math);
  5588.         }
  5589.     else
  5590.         {
  5591.         q_protected = BOOLEAN(!q_protected);
  5592.         app(q_protected ? @'{' : @'}');
  5593.         app_scrap(expr,yes_math);
  5594.         }
  5595. @#endif
  5596.     APP_STR("\\LA"); app_scrap(expr,maybe_math);
  5597.     break;
  5598.  
  5599. @
  5600. @<Append scraps for |begin_language|@>=
  5601.  
  5602.     switch(language)
  5603.         {
  5604.       case NO_LANGUAGE:
  5605.         CONFUSION("append scraps for begin_language",
  5606.             "Language isn't defined");
  5607.  
  5608.       case C: 
  5609.       case C_PLUS_PLUS:
  5610.       case LITERAL:
  5611.         column_mode = NO; @~ break;
  5612.  
  5613.       case FORTRAN: 
  5614.       case FORTRAN_90:
  5615.       case RATFOR: 
  5616.       case RATFOR_90:
  5617.         if(mode0==OUTER && !free_form_input) @<Set up column mode@>@;
  5618.         break;
  5619.  
  5620.       case TEX:
  5621.         if(mode0==OUTER) @<Set up col...@>@;
  5622.         break;
  5623.  
  5624.        case NUWEB_OFF:
  5625.        case NUWEB_ON:
  5626.     CONFUSION("append scraps for begin_language","Invalid language");
  5627.          }
  5628.  
  5629.     set_language(language);
  5630.     break@;
  5631.  
  5632. @ The following function returns a pointer to an |OPERATOR| structure, or
  5633. |NULL| if there's something invalid about the operator.  Identifiers must
  5634. be searched for explicitly.  If an identifier isn't there, it's put into
  5635. the table.
  5636. @<Part 3@>=@[
  5637.  
  5638. OPERATOR HUGE *valid_op FCN((op_code))
  5639.     eight_bits op_code C1("")@;
  5640. {
  5641. int n = 0;
  5642. OPERATOR HUGE *p;
  5643.  
  5644. switch(op_code)
  5645.     {
  5646.    case @'/':
  5647.    case @'+':
  5648.    case @'<': 
  5649.    case @'>': 
  5650.    case @'=': 
  5651.    case @'%':
  5652.    case @'!': 
  5653.    case @'~': 
  5654.    case @'-': 
  5655.    case @'*': 
  5656.    case @'&':
  5657.    case @'|':
  5658.    case @'?':
  5659.    case @'^':
  5660.    case ellipsis:
  5661.    case not_eq: 
  5662.    case lt_eq: 
  5663.    case gt_eq: 
  5664.    case eq_eq: 
  5665.    case and_and: 
  5666.    case or_or: 
  5667.    case plus_plus:
  5668.    case minus_minus:
  5669.    case minus_gt:
  5670.    case gt_gt: 
  5671.    case lt_lt:
  5672.    case star_star: 
  5673.    case slash_slash: 
  5674.     p = op + op_code;
  5675.     if(p >= op + 128) CONFUSION("valid_op",
  5676.         "Operator out of range");
  5677.     return p;
  5678.  
  5679.    case compound_assignment:
  5680.     if(assignment_token==or_or_or)
  5681.         return op + @'|';
  5682.  
  5683.     p = op + CA_START + assignment_token;
  5684.     if(p >= op + 128) CONFUSION("valid_op",
  5685.         "Compound assignment operator out of range");
  5686.     return p;
  5687.  
  5688.    case dot_const:
  5689.     if(!FORTRAN_LIKE(language)) return NULL;
  5690.     id_first = dot_op.name + 1;
  5691.     id_loc = id_first + STRLEN(id_first);
  5692.  
  5693.    case identifier:
  5694.     if(!FORTRAN_LIKE(language)) return NULL; /* Can do names only in
  5695. \Fortran. */ 
  5696.     @<Add an operator to the table, if necessary, and |return p@;|@>@; 
  5697.     }
  5698.  
  5699. return NULL;
  5700. }        
  5701.  
  5702. @
  5703. @<Add an operator...@>=
  5704. {
  5705. ASCII id[255];
  5706.  
  5707. STRNCPY(id,id_first,n=PTR_DIFF(int,id_loc,id_first));
  5708. id[n] = '\0'; // Make into proper string.
  5709.  
  5710. for(p=op+128; p<op_ptr; p++)
  5711.     if(STRCMP(p->op_name,id) == 0) return p;
  5712.  
  5713. if(op_ptr >= op_end) OVERFLW("op table","op");
  5714.  
  5715. p->op_name = GET_MEM("op name",n+1,ASCII);
  5716. STRCPY(p->op_name,id);
  5717. op_ptr++;
  5718. return p;
  5719. }
  5720.  
  5721. @ The form in which operators are appended depends on whether they have
  5722. been overloaded with an \.{@@v}~command or not.  If they have not, they are
  5723. are appended as a straight macro name, such as the translation of
  5724. `\.{.FALSE.}' into `\.{\\FALSE}'.  If they have been overloaded, they are
  5725. appended instead as a construction such as `\.{\\Wop\{FALSE\}\{N\}}';
  5726. the output limbo section will then contain an automatically generated
  5727. definition such as `\.{\\newop\{FALSE\}\{N\}\{\\\{.FALSE.\}\}}'. This
  5728. defines the macro \.{\\\_FALSE\_N} to have the definition specified in the
  5729. \.{@@v}~command. 
  5730.  
  5731. @<Part 3@>=@[
  5732.  
  5733. SRTN app_overload(VOID)
  5734. {
  5735. int ln = language_num;
  5736. OPERATOR HUGE *p = valid_op(next_control);
  5737. OP_INFO HUGE *q = p->info + ln;
  5738. char temp[10];
  5739.  
  5740. if(overload_ops && q->overloaded)
  5741.     {
  5742.     switch(q->cat)
  5743.         {
  5744.         case unorbinop:
  5745.         case binop:
  5746.             APP_STR("\\Wb{"); @~ break;
  5747.  
  5748.         case unop:
  5749.             APP_STR("\\Wu{"); @~ break;
  5750.  
  5751.         default:
  5752.             APP_STR(" \\Wop{"); @~ break;
  5753.         }
  5754.  
  5755.     app_ASCII_str(p->op_name);
  5756.     sprintf(temp,"}{%s}",lang_codes[ln]);
  5757.     APP_STR(temp);
  5758.     }
  5759. else if(q->op_macro) 
  5760.     APP_STR(q->op_macro);
  5761. else
  5762.     {
  5763.        err_print(W,"Unidentifiable dot constant in language %s.  Missing @@v?",
  5764.         languages[ln]);
  5765.     APP_STR("\\Wunknown{");
  5766.     app(wt_style.dot_delimiter.begin);
  5767.     app_ASCII_str(p->op_name);
  5768.     app(wt_style.dot_delimiter.end);
  5769.     app(@'}');
  5770.     app_scrap(binop,yes_math);
  5771.     return;
  5772.     }
  5773.  
  5774. app_scrap(q->cat,yes_math);
  5775. }
  5776.  
  5777. @ The following code must use |app_tok| instead of |app| in order to
  5778. protect against overflow. Note that |tok_ptr+1<=max_toks| after |app_tok|
  5779. has been used, so another |app| is legitimate before testing again.
  5780.  
  5781. Many of the special characters in a string must be prefixed by '\.\\' so that
  5782. \TeX\ will print them properly.
  5783. @^special string characters@>
  5784.  
  5785. @<Append a string or...@>=
  5786.  
  5787. if(next_control == stmt_label && !isDigit(*id_first)) /* Identifier as
  5788.                 statement label. */
  5789.     {
  5790.     p = id_lookup(id_first,id_loc,normal);
  5791.     APP_FLAG(id,p,name_dir);
  5792.     app_scrap(label,no_math);
  5793.     }
  5794. else
  5795.     {
  5796.     if (next_control==constant || next_control==stmt_label) 
  5797.         APP_STR("\\WO{");
  5798. @.\\WO@>
  5799.     else if (next_control==stringg)
  5800.         @<Append commands for beginning of string@>@;
  5801. @.\\.@>
  5802.     else APP_STR("\\={");
  5803. @.\\=@>
  5804.  
  5805.     @<Append the basic string@>@;
  5806.  
  5807.     if(next_control==stmt_label) {app_scrap(label,no_math);}
  5808.     else {app_scrap(expr,yes_math);}
  5809.     }
  5810.  
  5811. @
  5812. @<Append commands for beginning of string@>=
  5813. {
  5814. APP_STR(pfmt->typewritr);
  5815. app_tok(@'{');
  5816. }
  5817.  
  5818. @ Here we append the string material within [|id_first|,|id_loc|).  This is
  5819. basically straightforward; however, commas are replaced by~`\.{\\1}' (which
  5820. will be treated as a comma followed by a discretionary break), the
  5821. |discretionary_break| code is replaced by~`\.{\\2}' (which will be treated
  5822. as a discretionary break), the |ordinary_space| code is replaced
  5823. by~`\.{\\2}' (which is treated as an ordinary space, not~`\.{\ }'), and the
  5824. |tab_mark| code (which will be present only in \TeX\ mode) is replaced
  5825. by~`\.{\\3}', which is defined in \.{fwebmac.web} to be several spaces.
  5826.  
  5827. @<Append the basic str...@>=
  5828. {
  5829. while (id_first<id_loc) 
  5830.     {
  5831.       switch (*id_first) 
  5832.         {
  5833.     case @',': *id_first = @'1'; app(@'\\'); break; 
  5834.  
  5835.     case ordinary_space:
  5836.         *id_first = @'2'; app(@'\\'); break;
  5837.  
  5838.     case tab_mark:
  5839.         *id_first = @'3'; app(@'\\'); break;
  5840.  
  5841.     case discretionary_break: *id_first = @'0'; // Falls through!
  5842.  
  5843.     @<Special string cases@>:
  5844.         app(@'\\'); break;
  5845.  
  5846.     case @'@@': if (*(id_first+1)==@'@@') id_first++;
  5847.           else ERR_PRINT(W,"Double @@ should be used in strings");
  5848. @.Double \AT! should be used...@>
  5849.           }
  5850.  
  5851.       app_tok(*id_first++);
  5852.     }
  5853.  
  5854. /* End the macro. */
  5855. app(@'}'); 
  5856. }
  5857.  
  5858. @ Here are the characters that are special to \TeX\ and therefore need to
  5859. be escaped within a string.
  5860.  
  5861. @f @<Special string cases@> default
  5862. @f @<Special \TeX\ cases@> default
  5863. @f @<Other string cases@> default
  5864.  
  5865. @<Special string cases@>=
  5866.  
  5867. @<Special \TeX\ cases@>:
  5868. @<Other string cases@>@: @;
  5869.  
  5870. @
  5871. @<Special \TeX\ cases@>=
  5872.  
  5873. case @'\\':case @'{': case @'}'@: @;
  5874.  
  5875. @
  5876. @<Other string cases@>=
  5877. case @' ':case @'#':case @'%':case @'$':case @'^':case @'`':
  5878. case @'~': case @'&': case @'_'@: @;
  5879.  
  5880. @ This fragment appends the text collected inside `\.{@@t\dots@@>}'.  That
  5881. text is placed inside an \.{\\hbox} and treated as an ordinary expression.
  5882.  
  5883. @<Append a \TeX\ string scrap@>=
  5884.  
  5885. APP_STR("\\hbox{"); while (id_first<id_loc) app_tok(*id_first++);
  5886. app(@'}'); app_scrap(expr,maybe_math);
  5887.  
  5888. @ Ordinary identifiers are just treated as expressions.
  5889.  
  5890. @<Append an identifier scrap@>=
  5891.  
  5892. p = id_lookup(id_first, id_loc,normal);
  5893.  
  5894. @#if 0
  5895. if (p->ilk==normal || !(p->reserved_word & (boolean)language) ) 
  5896.     {
  5897.     APP_FLAG(id,p,name_dir);
  5898.     app_scrap(expr,maybe_math); /* not a reserved word */
  5899.     }
  5900. else 
  5901.     {
  5902.     APP_FLAG(res,p,name_dir);
  5903.     app_scrap(p->ilk,maybe_math);
  5904.     }
  5905. @#endif
  5906.  
  5907. if(p->wv_macro)
  5908.     {
  5909.     WV_MACRO HUGE *w = p->wv_macro;
  5910.     ASCII HUGE *s = w->text;
  5911.  
  5912.     if(w->cat) 
  5913.         {
  5914.         APP_STR(pfmt->id);
  5915.         app(@'{');
  5916.         }
  5917.  
  5918.     while(*s)
  5919.         app_tok(*s++);
  5920.  
  5921.     if(w->cat) app(@'}');
  5922.     
  5923.     app_scrap(p->ilk ? p->ilk : expr, w->cat ? maybe_math : yes_math);
  5924.     }
  5925. else if (p->reserved_word & (boolean)language)
  5926.      {
  5927.     APP_FLAG(res,p,name_dir);
  5928.     app_scrap(p->ilk == normal ? expr : p->ilk,maybe_math);
  5929. /* See the inverse construction in \.{reserved}:|save_words|. */
  5930.     }
  5931. else
  5932.     {
  5933.     APP_FLAG(id,p,name_dir);
  5934.     app_scrap(expr,maybe_math); // Not a reserved word.
  5935.     }
  5936.  
  5937. @
  5938. @<Append the output file...@>=
  5939. {
  5940. APP_STR(upper_case_code ? "\\WOut{" : "\\Wout{");
  5941.     *id_loc = '\0';
  5942.     id_first = esc_buf(mod_text+1, mod_end, id_first, YES);
  5943.      was_opened(id_first, upper_case_code, ¶ms.OUTPUT_FILE_NAME, NULL);
  5944.     if(upper_case_code)
  5945.         was_opened(id_first, upper_case_code,
  5946.             &global_params.OUTPUT_FILE_NAME, NULL); 
  5947.     while(*id_first) 
  5948.         app_tok(*id_first++);
  5949. app(@'}');
  5950.  
  5951. @%if(nuweb_mode)
  5952.     app(force);
  5953.  
  5954. app_scrap(ignore_scrap,no_math);
  5955.  
  5956. if(nuweb_mode)
  5957.     { /* !!!!! */
  5958.     next_control = begin_meta;
  5959.     continue;
  5960.     }
  5961. }
  5962.  
  5963. @ When the~`\ttv' that introduces \cee\ text is sensed, a call on
  5964. |C_translate| will return a pointer to the \TeX\ translation of that text.
  5965. If scraps exist in |scrp_info|, they are unaffected by this translation
  5966. process.
  5967.  
  5968. @<Part 2@>=@[
  5969.  
  5970. text_pointer C_translate(VOID)
  5971. {
  5972. text_pointer p; // Points to the translation.
  5973. scrap_pointer save_base; // Holds original value of |scrp_base|.
  5974. PARAMS outer_params;
  5975. PARSE_PARAMS parse_params0;
  5976.  
  5977. outer_params = params;
  5978. parse_params0 = parse_params;
  5979.  
  5980. save_base = scrp_base; 
  5981. scrp_base = scrp_ptr+1; // Empty work space after last existing scrap.
  5982.  
  5983. /* We enclose code fragments with the \TeX\ macro~\.{\\WCD\{\dots\}}. */
  5984. if(output_protect)
  5985.     APP_STR("\\protect");
  5986.  
  5987. APP_STR("\\WCD{"); app_scrap(ignore_scrap,no_math);
  5988.  
  5989. if(nuweb_mode)
  5990.     {
  5991.     APP_STR("{\\tt ");
  5992.     app_scrap(ignore_scrap, no_math);
  5993.     }
  5994.  
  5995. while(next_control <= module_name)
  5996.     {
  5997.     C_parse(INNER); // Get the scraps together.
  5998.  
  5999.     if(next_control == @'|') 
  6000.         break;
  6001.  
  6002.     @<Emit the scrap for a module name if present@>;
  6003.  
  6004.     if(next_control == @'|') 
  6005.         break;
  6006.     }
  6007.  
  6008. app_tok(cancel); app_scrap(ignore_scrap,maybe_math);
  6009.     // Place a |cancel| token as a final ``comment''.
  6010.  
  6011. if(nuweb_mode)
  6012.     app(@'}');
  6013. #if 0
  6014. else
  6015.     app_scrap(semi, maybe_math); /* Append a pseudo-semicolon to try to
  6016.             force the code fragments to reduce to full statements. */
  6017. #endif
  6018.  
  6019. if(output_protect)
  6020.     {
  6021.     app(protect_code);
  6022.     app_scrap(ignore_scrap, no_math);
  6023.     }
  6024.  
  6025. app(@'}'); app_scrap(ignore_scrap,no_math);
  6026.  
  6027. if (next_control != @'|') 
  6028.     ERR_PRINT(W,"Missing '|' after code text");
  6029. @.Missing '|'...@>
  6030.  
  6031. p = translate(INNER); // Make the translation.
  6032.  
  6033. if (scrp_ptr>mx_scr_ptr) 
  6034.     mx_scr_ptr=scrp_ptr;
  6035.  
  6036. scrp_ptr = scrp_base-1; // Restore old |scrp_ptr|.
  6037. scrp_base = save_base; // Scrap the scraps.
  6038.  
  6039. params = outer_params;
  6040. frz_params();
  6041.  
  6042. parse_params = parse_params0;
  6043.  
  6044. return p;
  6045. }
  6046.  
  6047. @ The |outr_parse| routine is to |C_parse| as |outr_xref| is to |C_xref|:
  6048. it constructs a sequence of scraps for \cee\ text until
  6049. |next_control>=formatt|. Thus, it takes care of embedded comments.
  6050.  
  6051. @<Part 2@>=@[
  6052.  
  6053. SRTN outr_parse(VOID) /* makes scraps from \cee\ tokens and comments */
  6054. {
  6055.   int bal; // Brace level in comment.
  6056.   text_pointer p, q; // Partial comments.  |p|: Stuff before `\Cb'; |q|: `\Cb'.
  6057.  
  6058.   while (next_control<formatt)
  6059.     {
  6060.     if (next_control != begin_comment) 
  6061.     C_parse(OUTER);
  6062.     else 
  6063.     @<Append a comment or compiler directive@>@;
  6064.     }
  6065. }
  6066.  
  6067. @
  6068. @<Append a comment...@>=
  6069. { // Append a comment/compiler directive.
  6070. if(doing_cdir) 
  6071.     @<Begin a compiler directive@>@;
  6072. else 
  6073.     @<Append a regular comment@>@;
  6074.  
  6075. bal = copy_comment(1);  // Closing brace is inserted here.
  6076. next_control = ignore;
  6077.  
  6078. if(doing_cdir && bal > 0) 
  6079.     ERR_PRINT(W,"Can't have vertical bars in @@! compiler directives");
  6080.  
  6081. doing_cdir = NO;
  6082.  
  6083. /* Handle code mode inside comments. */
  6084. while (bal > 0) 
  6085.     {
  6086.     in_comment = YES;
  6087.     p=text_ptr; freeze_text; 
  6088.  
  6089.     q = C_translate();
  6090.              /* at this point we have |tok_ptr+7<=max_toks| */
  6091.     APP_FLAG(tok,p,tok_start); APP_FLAG(inner_tok,q,tok_start);
  6092.  
  6093.         if (next_control==@'|') 
  6094.         {
  6095.           bal = copy_comment(bal);
  6096.           next_control = ignore;
  6097.         }
  6098.         else 
  6099.         bal = 0; // An error has been reported.
  6100.     }
  6101.  
  6102.  app(force); app_scrap(ignore_scrap,no_math); /* the full comment
  6103.                     becomes a scrap */ 
  6104. }
  6105.  
  6106. @ Compiler directives are begun by the style-file text \.{cdir.start}.  For
  6107. example, `\.{@@!abc}' $\to$ `\.{\#pragma\ abc}'.
  6108.  
  6109. @<Begin a compiler dir...@>=
  6110. {
  6111. outer_char HUGE *s = t_style.cdir_start[language_num];
  6112. int n = 2*STRLEN(s) + 1; 
  6113.   /* The factor of~2 counts possible escapes, and the 1 takes care of |'\0'|. */
  6114. ASCII HUGE *temp = GET_MEM("temp_cdir",n,ASCII);
  6115. ASCII HUGE *start = GET_MEM("start_cdir",n,ASCII);
  6116.  
  6117. STRCPY(start,s);
  6118. to_ASCII((outer_char HUGE *)start);
  6119.  
  6120. room_for(9+n,3,1); /* Tokens: */
  6121.  
  6122. app(force);
  6123. APP_STR("\\WCDIR{");
  6124. esc_buf(temp,temp+n,start,YES); @~ APP_STR(to_outer(temp));
  6125. @.\\WCDIR@>
  6126. FREE_MEM(temp,"temp_cdir",n,ASCII);
  6127. FREE_MEM(start,"start_cdir",n,ASCII);
  6128. }
  6129.  
  6130. @
  6131. @<Append a regular comment@>=
  6132. {
  6133. room_for(8,3,1); /* Tokens:  `\.{;{ }\ { }\\{ }W{ }C\{{ }\}{ }\It{force}}'. */
  6134.  
  6135. if(Fortran88)
  6136.     {
  6137.     if(free_Fortran && lst_ampersand)
  6138.         {
  6139.         scrp_ptr--; // Kill off the \.{\&}.
  6140.         }
  6141.     else if(!at_beginning && auto_semi)
  6142.         {
  6143.         app(@';');
  6144.         }
  6145.     last_was_cmnt = YES;
  6146.     }
  6147.  
  6148. app(break_space); 
  6149. APP_STR(long_comment ? "\\WC{" : "\\Wc{"); // Long/short comment.
  6150. @.\\WC@> @.\\Wc@>
  6151. }
  6152.  
  6153. @* OUTPUT of TOKENS.  So far our programs have only built up multi-layered
  6154. token lists in \.{WEAVE}'s internal memory; we have to figure out how to
  6155. get them into the desired final form. The job of converting token lists to
  6156. characters in the \TeX\ output file is not difficult, although it is an
  6157. implicitly recursive process. Three main considerations had to be kept in
  6158. mind when this part of \.{WEAVE} was designed: (a)~There are two modes of
  6159. output, |outer| mode that translates tokens like |force| into line-breaking
  6160. control sequences, and |inner| mode, intended for code between~\Cb, that
  6161. ignores them except that blank 
  6162. spaces take the place of line breaks. (b)~The |cancel| instruction applies
  6163. to adjacent token or tokens that are output, and this cuts across levels of
  6164. recursion since `|cancel|' occurs at the beginning or end of a token list
  6165. on one level. (c)~The \TeX\ output file will be semi-readable if line
  6166. breaks are inserted after the result of tokens like |break_space| and
  6167. |force|.  (d)~The final line break should be suppressed, and there should
  6168. be no |force| token output immediately after `\.{\\WY\\WP}'.
  6169.  
  6170. @i output.hweb
  6171.  
  6172. @ The output process uses a stack to keep track of what is going on at
  6173. different ``levels'' as the token lists are being written out. Entries on
  6174. this stack have three parts:
  6175.  
  6176. \yskip\hang |end_field| is the |tok_mem| location where the token list of a
  6177. particular level will end;
  6178.  
  6179. \yskip\hang |tok_field| is the |tok_mem| location from which the next token
  6180. on a particular level will be read;
  6181.  
  6182. \yskip\hang |mode_field| is the current mode, either |inner| or |outer|.
  6183.  
  6184. \yskip\noindent The current values of these quantities are referred to
  6185. quite frequently, so they are stored in a separate place instead of in the
  6186. |stack| array. We call the current values |cur_end|, |cur_tok|, and
  6187. |cur_mode|.
  6188.  
  6189. The global variable |stck_ptr| tells how many levels of output are
  6190. currently in progress. The end of output occurs when an |end_translation|
  6191. token is found, so the stack is never empty except when we first begin the
  6192. output process.
  6193.  
  6194. @d inner 0 /* Value of |mode| for \cee\ texts within \TeX\ texts */
  6195. @d outer 1 /* Value of |mode| for \cee\ texts in modules */
  6196.  
  6197. @<Typed...@>=
  6198.  
  6199. typedef int mode;
  6200.  
  6201. typedef struct {
  6202.   token_pointer end_field; /* Ending location of token list */
  6203.   token_pointer tok_field; /* Present location within token list */
  6204.   boolean mode_field; /* Interpretation of control tokens */
  6205. } output_state;
  6206.  
  6207. typedef output_state HUGE *stack_pointer;
  6208.  
  6209. @d cur_end cur_state.end_field /* Current ending location in |tok_mem| */
  6210. @d cur_tok cur_state.tok_field /* Location of next output token in |tok_mem| */
  6211. @d cur_mode cur_state.mode_field /* Current mode of interpretation */
  6212. @d ini_stack stck_ptr=stack;cur_mode=outer@; /* Initialize the stack */
  6213.  
  6214. @<Global...@>=
  6215.  
  6216. EXTERN output_state cur_state; /* |cur_end|, |cur_tok|, |cur_mode| */
  6217.  
  6218. EXTERN BUF_SIZE stck_size;
  6219. EXTERN output_state HUGE *stack; /* Dynamic array of info for non-current
  6220.                     levels */ 
  6221. EXTERN stack_pointer stck_end; /* End of |stack| */
  6222.  
  6223. EXTERN stack_pointer stck_ptr; /* First unused location in the output
  6224.                 state stack */ 
  6225. EXTERN stack_pointer mx_stck_ptr; /* Largest value assumed by |stck_ptr| */
  6226.  
  6227. @
  6228. @<Alloc...@>=
  6229.  
  6230. ALLOC(output_state,stack,ABBREV(stck_size_w),stck_size,0);
  6231. stck_end=stack+stck_size-1; /* End of |stack| */
  6232.  
  6233. @<Set init...@>=
  6234.  
  6235. mx_stck_ptr=stack;
  6236.  
  6237. @ To insert token-list |p| into the output, the |push_level| subroutine is
  6238. called; it saves the old level of output and gets a new one going.  The
  6239. value of |cur_mode| is not changed.
  6240.  
  6241. @<Part 2@>=@[
  6242.  
  6243. SRTN push_level FCN((p)) /* Suspends the current level */
  6244.     text_pointer p C1("")@;
  6245. {
  6246.   if (stck_ptr==stck_end) OVERFLW("stack levels",ABBREV(stck_size_w));
  6247.  
  6248.   if (stck_ptr>stack) { /* save current state */
  6249.     stck_ptr->end_field=cur_end;
  6250.     stck_ptr->tok_field=cur_tok;
  6251.     stck_ptr->mode_field=cur_mode;
  6252.   }
  6253.  
  6254.   stck_ptr++;
  6255.  
  6256.   if (stck_ptr>mx_stck_ptr) mx_stck_ptr=stck_ptr;
  6257.  
  6258.   cur_tok=*p; cur_end=*(p+1);
  6259. }
  6260.  
  6261. @ Conversely, the |pop_level| routine restores the conditions that were in
  6262. force when the current level was begun. This subroutine will never be
  6263. called when |stck_ptr=1|.
  6264.  
  6265. @<Part 2@>=@[
  6266.  
  6267. SRTN pop_level(VOID)
  6268. {
  6269.   cur_end=(--stck_ptr)->end_field;
  6270.   cur_tok=stck_ptr->tok_field; cur_mode=stck_ptr->mode_field;
  6271. }
  6272.  
  6273. @ The |get_output| function returns the next byte of output that is not a
  6274. reference to a token list. It returns the values |identifier| or |res_word|
  6275. or |mod_name| if the next token is to be an identifier (typeset in
  6276. italics), a reserved word (typeset in boldface) or a module name (typeset
  6277. by a complex routine that might generate additional levels of output).  In
  6278. these cases |cur_name| points to the identifier or module name in question.
  6279.  
  6280. @<Global...@>=
  6281.  
  6282. EXTERN name_pointer cur_name;
  6283.  
  6284. @d res_word OCTAL(201) /* Returned by |get_output| for reserved words */
  6285. @d mod_name OCTAL(200) /* Returned by |get_output| for module names */
  6286.  
  6287. @<Part 2@>=@[
  6288.  eight_bits get_output(VOID) /* Returns the next token of output */
  6289. {
  6290.   sixteen_bits a; /* Current item read from |tok_mem| */
  6291.  
  6292.   restart: while (cur_tok==cur_end) pop_level(); /* Get back to unfinished
  6293.         level. */
  6294.  
  6295.   a=*(cur_tok++);
  6296.  
  6297.   if (a>=0400) 
  6298.     {
  6299.     cur_name=a % id_flag + name_dir;
  6300.  
  6301.     switch (a / id_flag) 
  6302.         {
  6303.       case 2: return res_word; /* |a==res_flag+cur_name| */
  6304.       case 3: return mod_name; /* |a==mod_flag+cur_name| */
  6305.       case 4: push_level(a % id_flag + tok_start); goto restart;
  6306.     /* |a==tok_flag+cur_name| */
  6307.       case 5: push_level(a % id_flag + tok_start); cur_mode=inner; 
  6308.         goto restart; 
  6309.       /* |a==inner_tok_flag+cur_name| */
  6310.       default: return identifier; /* |a==id_flag+cur_name| */
  6311.         }
  6312.       }
  6313.  
  6314. /* If we get here, it's a single-byte token. */
  6315. return (eight_bits)a;
  6316. }
  6317.  
  6318. @ The real work associated with token output is done by |make_output|.
  6319. This procedure appends an |end_translation| token to the current token
  6320. list, and then it repeatedly calls |get_output| and feeds characters to the
  6321. output buffer until reaching the |end_translation| sentinel. It is possible
  6322. for |make_output| to be called recursively, since a module name may include
  6323. embedded \cee\ text; however, the depth of recursion never exceeds one
  6324. level, since module names cannot be inside of module names.
  6325.  
  6326. A procedure called |output_C| does the scanning, translation, and output of
  6327. \cee\ text within `\Cb'~brackets, and this procedure uses |make_output| to
  6328. output the current token list. Thus, the recursive call of |make_output|
  6329. actually occurs when |make_output| calls |output_C| while outputting the
  6330. name of a module.
  6331. @^recursion@>
  6332.  
  6333. @<Part 2@>=@[
  6334.  
  6335. SRTN output_C(VOID) /* Outputs the current token list */
  6336. {
  6337.   token_pointer save_tok_ptr;
  6338.   text_pointer save_text_ptr;
  6339.   eight_bits save_next_control; /* Values to be restored */
  6340.   text_pointer p; /* Translation of the \cee\ text */
  6341.  
  6342.   save_tok_ptr=tok_ptr; save_text_ptr=text_ptr;
  6343.   save_next_control=next_control;
  6344.  
  6345.   next_control=ignore; p=C_translate();
  6346.   APP_FLAG(inner_tok,p,tok_start);
  6347.   scanning_meta = NO;
  6348.  
  6349.   make_output(); /* output the list */
  6350.  
  6351.   if (text_ptr>mx_text_ptr) mx_text_ptr=text_ptr;
  6352.   if (tok_ptr>mx_tok_ptr) mx_tok_ptr=tok_ptr;
  6353.  
  6354.   text_ptr=save_text_ptr; tok_ptr=save_tok_ptr; /* Forget the tokens */
  6355.   next_control=save_next_control; /* Restore |next_control| to original
  6356.         state */ 
  6357. }
  6358.  
  6359. @ Here is \.{WEAVE}'s major output handler.
  6360.  
  6361. @<Part 3@>=@[
  6362.  
  6363. SRTN make_output(VOID) /* outputs the equivalents of tokens */
  6364. {
  6365.   eight_bits a; // Current output byte.
  6366.   eight_bits b; // Next output byte.
  6367.   int c; // Count of |indent| and |outdent| tokens.
  6368.   boolean copying = NO; // Are we copying the \TeX\ part of a comment?
  6369.  
  6370.   app(end_translation); // Append a sentinel.
  6371.   freeze_text; push_level(text_ptr-1);
  6372.  
  6373. WHILE()
  6374.     {
  6375.     a = get_output();
  6376.  
  6377. reswitch: switch(a) 
  6378.         {
  6379.     case ignore: continue; // In case a null sneaks in.
  6380.  
  6381.     case begin_language:
  6382.         language = lan_enum(get_output()); /* The byte after
  6383. |begin_language| contains the language number. */
  6384.         continue;
  6385.  
  6386.     @<Cases for turning output on or off@>@:@;
  6387.       case end_translation: 
  6388.     return;
  6389.  
  6390.       case identifier: case res_word: 
  6391.     if(output_on) 
  6392.         @<Output an identifier@>@; 
  6393.     break;
  6394.  
  6395.       case mod_name: 
  6396.     if(output_on) 
  6397.         @<Output a module name@>@; @~ break;
  6398.  
  6399.       case math_bin: case math_rel: 
  6400.         @<Output a \.{\\math} operator@>; @~ break;
  6401.  
  6402.     case toggle_meta:
  6403.         scanning_meta = BOOLEAN(!scanning_meta);
  6404.         break;
  6405.  
  6406.       case cancel: 
  6407.         c=0; while ((a=get_output())>=indent && a<=big_force) 
  6408.             {
  6409.               if (a==indent) c++; if (a==outdent) c--;
  6410.                 }
  6411.             @<Output saved |indent| or |outdent| tokens@>;
  6412.             goto reswitch;
  6413.  
  6414.       case big_cancel: 
  6415.     c=0;
  6416.     while (((a=get_output())>=indent || a==@' ') && a<=big_force) 
  6417.             {
  6418.               if (a==indent) c++; if (a==outdent) c--;
  6419.                 }
  6420.         @<Output saved...@>;
  6421.         goto reswitch;
  6422.  
  6423.       case indent: case outdent: case opt: case backup: case break_space:
  6424.       case force: case big_force: 
  6425.     @<Output a control,
  6426.         look ahead in case of line breaks, possibly |goto reswitch@;|@>; break;
  6427.  
  6428.       case interior_semi:
  6429.         if(output_on) out(';');
  6430.         break;
  6431.  
  6432.       case @'*': 
  6433.     if(!(copying || nuweb_mode))
  6434.         {
  6435.         OUT_STR("\\ast "); // Special macro for asterisks in code mode.
  6436. @.\\ast@>
  6437.         break; 
  6438.         }
  6439. /* If |copying|, the asterisk case falls through to the default. */
  6440.  
  6441.       default: 
  6442.     if(output_on) 
  6443.         {
  6444.         out(a); // Otherwise |a| is an |ASCII| character.
  6445.  
  6446.         if(scanning_meta && a=='\n')
  6447.             flush_buffer(out_ptr, NO);
  6448.         }
  6449.     }
  6450.   }
  6451. }
  6452.  
  6453. @
  6454. @<Cases for turning output on...@>=
  6455.  
  6456. case protect_code:
  6457.     output_protect = BOOLEAN(!output_protect); @~ break;
  6458.  
  6459. case copy_mode:
  6460.     copying = BOOLEAN(!copying); @~ break;
  6461.  
  6462. case turn_output_off:
  6463. @%        OUT_STR("OFF"); // For debugging.
  6464.     output_on = NO;
  6465.     break;
  6466.  
  6467. case turn_output_on:
  6468. @%        OUT_STR("ON"); // For debugging.
  6469.     output_on = YES;
  6470.     break;
  6471.  
  6472. case Turn_output_off:
  6473.     skip_file();
  6474.     strt_off = YES;
  6475. @%        OUT_STR("OFF"); // For debugging.
  6476.     output_on = NO;
  6477.     break;
  6478.  
  6479. case Turn_output_on:
  6480.     strt_off = NO;
  6481. @%        OUT_STR("ON"); // For debugging.
  6482.     output_on = YES;
  6483.     break;
  6484.  
  6485.  
  6486. @
  6487. @<Part 3@>=@[
  6488. SRTN skip_file(VOID)
  6489. {
  6490. #define TEMP_LEN (MAX_FILE_NAME_LENGTH + 11)
  6491.  
  6492. outer_char temp[TEMP_LEN],temp1[TEMP_LEN];
  6493.  
  6494. esc_file_name(temp1,TEMP_LEN,prms[1].web.File_name);
  6495. SPRINTF(TEMP_LEN,temp,`"\\Wskipped{%s}",temp1`);
  6496. OUT_STR(temp);
  6497. fin_line();
  6498.  
  6499. #undef TEMP_LEN
  6500. }
  6501.  
  6502. @
  6503. @<Part 3@>=@[
  6504. SRTN out_skip(VOID)
  6505. {
  6506. @<Toggle output@>;
  6507. if(!output_on) 
  6508.     {
  6509.     output_on = YES;
  6510.     OUT_STR("\\WY\\WP");
  6511.     skip_file();
  6512.     output_on = NO;
  6513.     }
  6514. }
  6515.  
  6516.  
  6517. @<Output an identifier@>=
  6518. {
  6519. if(nuweb_mode)
  6520.     {
  6521.     ASCII HUGE *k;
  6522.  
  6523.     for(k=cur_name->byte_start; k<(cur_name+1)->byte_start; k++)
  6524.         {
  6525.         out(*k);
  6526.         }
  6527.     }
  6528. else
  6529.     @<Format and output an identifier@>@;
  6530. }
  6531.  
  6532.  
  6533. @ An identifier of length one does not have to be enclosed in braces, and
  6534. it looks slightly better if set in a math-italic font instead of a
  6535. (slightly narrower) text-italic font. Thus we output `\.{\\\char'174a}' but
  6536. `\.{\\]\{aa\}}'.
  6537.  
  6538. @d ALL_UC (all_uc && length(cur_name) > 1)
  6539.  
  6540.  
  6541. @<Format and output an id...@>=
  6542. {
  6543. boolean all_uc = cur_name->info.upper_case;
  6544.  
  6545. if(output_protect)
  6546.     OUT_STR("\\protect");
  6547.  
  6548. if (a==identifier)
  6549.   {
  6550.   if(is_intrinsic(cur_name)) 
  6551.     OUT_STR(pfmt->intrinsic); 
  6552.     /* Intrinsic function---e.g., |fopen|.  */
  6553. @.\\\AT!@>
  6554.   else if(is_keyword(cur_name)) 
  6555.     OUT_STR(ALL_UC ? pfmt->KEYWORD : pfmt->keyword); 
  6556.     /* Fortran keyword---e.g., |@r BLOCKSIZE|.  */
  6557. @.\\.@>
  6558.   else if (length(cur_name)==1) 
  6559.     OUT_STR(pfmt->short_id); 
  6560.     /* One-character identifier---e.g., |a|. */
  6561. @.\\|@>
  6562.   else 
  6563.     @<Output the appropriate identifier prefix@>@;
  6564.   }
  6565. else 
  6566.     OUT_STR(ALL_UC ? pfmt->RESERVED : pfmt->reserved); 
  6567.         /* Reserved word---e.g., |float|. */
  6568. @.\\\&@>
  6569.  
  6570. out_name(IDENTIFIER,cur_name);
  6571. }
  6572.  
  6573. @ Some people prefer macros to be formatted differently from ordinary
  6574. identifiers.
  6575. @<Output the appro...@>=
  6576. switch(DEFINED_TYPE(cur_name))
  6577.     {
  6578.     case D_MACRO:
  6579.     OUT_STR(ALL_UC ? pfmt->ID_OUTER : pfmt->id_outer); 
  6580.         // E.g., |NON_TEX_MACRO|.
  6581.     break;
  6582.  
  6583.     case M_MACRO:
  6584.     OUT_STR(ALL_UC ? pfmt->ID_INNER : pfmt->id_inner); // E.g., |_FWEAVE_|.
  6585.     break;
  6586.  
  6587.     default:
  6588.     OUT_STR(ALL_UC ? pfmt->ID: pfmt->id); 
  6589.         // Longer ordinary identifier---e.g., |out|.
  6590.     break;
  6591. @.\\\\@>
  6592.     }
  6593.  
  6594. @ Here |a|~will only be |math_bin| or |math_rel|.
  6595. @<Output a \....@>=
  6596.  
  6597. OUT_STR(a==math_bin ? "\\mathbin{" : "\\mathrel{");
  6598. @.\\mathbin@>
  6599. @.\\mathrel@>
  6600.  
  6601. @ The current mode does not affect the behavior of \.{WEAVE}'s output routine
  6602. except when we are outputting control tokens.
  6603.  
  6604. @<Output a control...@>=
  6605.  
  6606. if (a<break_space) 
  6607.     {
  6608.       if (cur_mode==outer) 
  6609.         {
  6610.         if(output_on)
  6611.             {
  6612.             out(@'\\'); @~ out(a-cancel+@'0'); /* As an example,
  6613. $|backup| = |0345| - |0341| + \.{'0'} = \.{'4'} \to \.{\\4}$. */
  6614.             }
  6615.         if (a==opt) 
  6616.         if(output_on) {out(get_output());} /* |opt| is followed by a
  6617. digit. */ 
  6618.         else get_output();
  6619.          }
  6620.       else if (a==opt) b=get_output(); // Ignore digit following |opt|.
  6621.       }
  6622. else @<Look ahead for strongest line break, |goto reswitch@;|@>; /* Here $a
  6623.     \in \{|break_space|,|force|,|big_force|\}$. */
  6624.  
  6625. @ If several of the tokens |break_space|, |force|, |big_force| occur in a
  6626. row, possibly mixed with blank spaces (which are ignored), the largest one
  6627. is used. A line break also occurs in the output file, except at the very
  6628. end of the translation. The very first line break is suppressed (i.e., a
  6629. line break that follows `\.{\\WY\\WP}').
  6630.  
  6631. @<Look ahead for st...@>= 
  6632. {
  6633. boolean save_mode; /* value of |cur_mode| before a sequence of breaks */
  6634.  
  6635.   b=a; save_mode=cur_mode; c=0;
  6636.  
  6637. WHILE()
  6638.     {
  6639.         a = get_output();
  6640.  
  6641.         if (a==cancel || a==big_cancel) 
  6642.         {
  6643.           @<Output saved |indent| or |outdent| tokens@>;
  6644.           goto reswitch; // |cancel| overrides everything.
  6645.             }
  6646.  
  6647.         if ((a!=@' ' && a<indent) || a==backup || a>big_force) 
  6648.         { // Time to output something.
  6649.           if (save_mode==outer) 
  6650.             {
  6651.             if (out_ptr>out_buf+5 && 
  6652.                 STRNCMP(out_ptr-5,"\\WY\\WP",6)==0)
  6653.                   goto reswitch;
  6654.                 @<Output saved |indent| or |outdent| tokens@>;
  6655.             if(output_on)
  6656.                if(strt_off)
  6657.                 {
  6658.                 if(STRNCMP(out_ptr-2,"\\WP",3)==0)
  6659.                       {
  6660.                       out_ptr = out_buf;
  6661.                       goto reswitch;
  6662.                       }
  6663.                 }
  6664.                else
  6665.                 {
  6666.                     out(@'\\'); @~ out(b-cancel+@'0');
  6667.                 }
  6668.                 if (a!=end_translation) fin_line();
  6669.               }
  6670.           else if (a!=end_translation && cur_mode==inner) 
  6671.         if(output_on) out(@' ');
  6672.  
  6673.           goto reswitch;
  6674.         }
  6675.  
  6676.         if (a==indent) c++;
  6677.         else if (a==outdent) c--;
  6678.         else 
  6679. /* Use only the largest. */
  6680.         if (a>b) b=a; /* if |a==' '| we have |a<b| */
  6681.         else if(a==opt) get_output(); /* Throw away digit after
  6682.                             |opt|. */ 
  6683.       }
  6684. }
  6685.  
  6686. @  While we're removing unwanted or duplicate tokens, we don't want to lose
  6687. track of the indent level.  So we count the |indent|s and |outdent|s, and
  6688. write out the net here.
  6689.  
  6690. @<Output saved...@>=
  6691.  
  6692.   for (;c>0;c--) OUT_STR("\\1");
  6693.  
  6694.   for (;c<0;c++) OUT_STR("\\2");
  6695.  
  6696. @ The remaining part of |make_output| is somewhat more complicated. When we
  6697. output a module name, we may need to enter the parsing and translation
  6698. routines, since the name may contain code embedded in \Cb\~constructions.
  6699. This code is placed at the end of the active input buffer and the
  6700. translation process uses the end of the active |tok_mem| area.
  6701.  
  6702. @<Output a module name@>= 
  6703. #if FCN_CALLS
  6704.     out_md_name();
  6705. #else
  6706.     @<Code to output a module name@>@;
  6707. #endif
  6708.  
  6709. @
  6710. @<Part 3@>=
  6711.  
  6712. #if FCN_CALLS
  6713. @[SRTN out_md_name(VOID)
  6714. {
  6715. @<Code to output a module name@>@;
  6716. }
  6717. #endif
  6718.  
  6719. @
  6720. @<Code to output a module name@>=
  6721. {
  6722. name_pointer cur_mod_name; /* name of module being output */
  6723.  
  6724.   OUT_STR("\\WX");
  6725. @.\\WX@>
  6726.   cur_xref = (xref_pointer)cur_name->xref;
  6727.  
  6728.  /* Output the module number, or zero if it was undefined */
  6729.   if (cur_xref->num>=def_flag) 
  6730.     {
  6731.         out_mod(cur_xref->num-def_flag,ENCAP);
  6732.  
  6733.         if (phase==3) 
  6734.         {
  6735.           cur_xref=cur_xref->xlink;
  6736.  
  6737.           while (cur_xref->num>=def_flag) 
  6738.             {
  6739.             OUT_STR(", ");
  6740.                 out_mod(cur_xref->num-def_flag,ENCAP);
  6741.              cur_xref=cur_xref->xlink;
  6742.               }
  6743.          }
  6744.     }
  6745.   else out(@'0');
  6746.  
  6747.     out(@':');  /* End the module number. */
  6748.     @<Output the text of the module name@>;
  6749.     OUT_STR("\\X ");  /* End the text. (Can't use a colon here, because
  6750. there may be colons in the text.) */
  6751.     OUT_STR(cur_xref->num >= def_flag ? 
  6752.     language_symbol((LANGUAGE)cur_mod_name->mod_info->language) :
  6753.         (CONST outer_char *)"");
  6754.     OUT_STR("\\X"); /* End the language marker. */
  6755. }
  6756.  
  6757. @ In most situations, we only want to output a language marker if we're in
  6758. a language different from the global language.
  6759.  
  6760. @d language_name_ptr(l) languages[lan_num(l)] /* Points to the full
  6761.                     language name. */
  6762. @d language_symbol(l) 
  6763.     (l!=global_language ? LANGUAGE_CODE(l) : (CONST outer_char *)"")
  6764.  
  6765. @<Output the text...@>=
  6766. {
  6767. ASCII HUGE *k,  HUGE *k_limit; /* indices into |byte_mem| */
  6768. ASCII HUGE *j; /* index into |cur_buffer| */
  6769. ASCII HUGE *save_loc, HUGE *save_limit; // |loc| and |limit| to be restored.
  6770. eight_bits b;
  6771.  
  6772. k=cur_name->byte_start; k_limit=(cur_name+1)->byte_start;
  6773. cur_mod_name=cur_name;
  6774.  
  6775. while (k<k_limit) 
  6776.     {
  6777.       b=*(k++);
  6778.  
  6779.       if (b==@'@@') @<Skip next character, give error if not `\.{@@}'@>;
  6780.  
  6781.       if (b!=@'|') out(b)@;
  6782.       else 
  6783.         {
  6784.         @<Copy the \cee\ text into the |cur_buffer| array@>;
  6785.         save_loc=loc; save_limit=limit; loc=limit+2; limit=j+1;
  6786.         *limit=@'|'; output_C();
  6787.         loc=save_loc; limit=save_limit;
  6788.           }
  6789.     }
  6790. }
  6791.  
  6792. @<Skip next char...@>=
  6793.  
  6794. if (*k++!=@'@@') 
  6795. {
  6796. SET_COLOR(error);
  6797.   printf("\n! Illegal control code in section name: <");
  6798. @.Illegal control code...@>
  6799.   prn_id(cur_mod_name); printf("> "); mark_error;
  6800. }
  6801.  
  6802. @ The \cee\ text enclosed in~\Cb\ should not contain `\vertbar'~characters,
  6803. except within strings. We put a~`\vertbar' at the front of the buffer, so
  6804. that an error message that displays the whole buffer will look a little bit
  6805. sensible.  The variable |delim| is zero outside of strings, otherwise it
  6806. equals the delimiter that began the string being copied.
  6807.  
  6808. @<Copy the \cee\ text into...@>=
  6809. {
  6810. ASCII delim; /* first and last character of string being copied */
  6811.  
  6812. j=limit+1; *j=@'|'; delim=0;
  6813.  
  6814. WHILE()
  6815.     {
  6816.       if (k>=k_limit) 
  6817.         {
  6818.         SET_COLOR(error);
  6819.             printf("\n! C text in section name didn't end: <");
  6820. @.C text...didn't end@>
  6821.             prn_id(cur_mod_name); printf("> "); mark_error; break;
  6822.           }
  6823.  
  6824.       b=*(k++);
  6825.  
  6826.       if (b==@'@@') @<Copy a control code into the buffer@>@;
  6827.       else 
  6828.         {
  6829.             if (b==@'\'' || b==@'"')
  6830.               if (delim==0) delim=b;
  6831.               else if ((eight_bits)delim == b) delim=0;
  6832.  
  6833.             if (b!=@'|' || delim!=0) 
  6834.             {
  6835.               if (j>cur_buffer+buf_size-2) OVERFLW("buffer","");
  6836.  
  6837.               *(++j)=b;
  6838.                 }
  6839.             else break;
  6840.           }
  6841.     }
  6842. }
  6843.  
  6844. @<Copy a control code into the buffer@>= 
  6845. {
  6846.   if (j>cur_buffer+buf_size-3) OVERFLW("buffer","");
  6847.  
  6848.   *(++j)=@'@@'; *(++j)=*(k++);
  6849. }
  6850.  
  6851. @* PHASE TWO PROCESSING.  We have assembled enough pieces of the puzzle in
  6852. order to be ready to specify the processing in \.{WEAVE}'s main pass over
  6853. the source file. Phase two is analogous to phase one, except that more work
  6854. is involved because we must actually output the \TeX\ material instead of
  6855. merely looking at the \.{WEB} specifications.
  6856.  
  6857. @<Part 2@>=@[
  6858.  
  6859. SRTN phase2(VOID) 
  6860. {
  6861. extern outer_char wbflnm0[];
  6862. IN_COMMON int num_ifiles;
  6863.  
  6864. phase = 2; // Prepare for second phase.
  6865. the_part = LIMBO;
  6866.  
  6867. params = global_params;
  6868. frz_params();
  6869.  
  6870. rst_input(); 
  6871. strt_off = ending_off = NO;
  6872. writing(YES,tex_fname); @~ if(tex_file==stdout) putchar('\n');
  6873.  
  6874. fin_line(); // Write out the ``\.{\\input\ fwebmac.sty}''.
  6875.  
  6876. @<Issue the \.{\\Wbegin} command that sets up the beginning of the document@>@;
  6877.  
  6878. module_count = 0; 
  6879. num_ifiles = 0;
  6880.  
  6881. copy_limbo();
  6882. flush_buffer(out_buf,NO); /* Insert a blank line---it looks nice. */ 
  6883.  
  6884. math_flag = NO;
  6885.  
  6886. while (!input_has_ended) 
  6887.     @<Translate the current module@>@;
  6888. }
  6889.  
  6890. @ After the macros have been read in, we are ready to
  6891. actually begin the document.  The command has the form
  6892. ``\.{\\Wbegin[\It{options}]\{\It{style}\}\{\It{TeXindent}\}\{\It{codeindent}\}
  6893. \{\It{contents}\}
  6894. \{\{\It{reserved}\}\{\It{short identifier}\}\{\It{identifier}\}
  6895. \{\It{UPPERCASE identifier}\}
  6896. \{\It{outer macro}\}\{\It{inner macro}\}
  6897. \{\It{intrinsic}\}\{\It{keyword}\}\{\It{typewriter}\}\{\It{modtrans}\}\}}.''  
  6898. The \It{options} and \It{style} field are used only by \LaTeX.
  6899. @<Issue the \.{\\Wbegin} command...@>=
  6900. {
  6901. #define TEMP_LEN (MAX_FILE_NAME_LENGTH + 100)
  6902. #define ARGS \
  6903.     w_style.misc.LaTeX.class.options, w_style.misc.LaTeX.package.options,@\ \
  6904.     w_style.misc.LaTeX.class.file, w_style.misc.LaTeX.package.file,@\ \
  6905.     w_style.misc.TeXindent,@\ \
  6906.     w_style.misc.codeindent,@\ \
  6907.     w_style.contents.tex,@\ \
  6908.     pfmt->reserved, pfmt->RESERVED,@\ \
  6909.         pfmt->short_id,@\ \
  6910.         pfmt->id, pfmt->ID,@\ \
  6911.         pfmt->id_outer, pfmt->ID_OUTER,@\ \
  6912.         pfmt->id_inner, pfmt->ID_INNER,@\ \
  6913.         pfmt->intrinsic,@\ \
  6914.         pfmt->keyword, pfmt->KEYWORD,@\ \
  6915.         pfmt->typewritr,@\ \
  6916.     w_style.indx.encap_prefix,@\ \
  6917.     w_style.misc.doc_preamble, w_style.misc.doc_postamble,@\ \
  6918.     w_style.indx.name
  6919.  
  6920. outer_char temp0[TEMP_LEN];
  6921. outer_char HUGE *temp1 = GET_MEM("temp1",TEMP_LEN,outer_char);
  6922.  
  6923. SPRINTF(TEMP_LEN,temp0,
  6924. `"\n\\Wbegin[%s;%s]{%s;%s} {%s} {%s} {%s}\n\
  6925. {{%s%s} {%s} {%s%s} {%s%s} {%s%s} {%s} {%s%s} {%s}}\n\
  6926. {%s} {%s;%s} {%s}",
  6927.     ARGS`);
  6928. OUT_STR(xpn_name(&temp1,TEMP_LEN,temp0,wbflnm0));
  6929. FREE(temp1);
  6930. fin_line();
  6931.  
  6932. #undef TEMP_LEN
  6933. #undef ARGS
  6934. }
  6935.  
  6936. @ The output file will contain the control sequence~\.{\\WY} between
  6937. non-null sections of a module, e.g., between the \TeX\ and definition parts
  6938. if both are nonempty. This puts a little white space between the parts when
  6939. they are printed. However, we don't want \.{\\WY} to occur between two
  6940. definitions within a single module. The variables |out_line| or |out_ptr|
  6941. will change if a section is non-null, so the following macros
  6942. `|save_position|' and `|emit_space_if_needed|' are able to handle the
  6943. situation:
  6944.  
  6945. @d save_position save_line=out_line; save_place=out_ptr@;
  6946. @d emit_space_if_needed if (save_line!=out_line || save_place!=out_ptr)
  6947.   {
  6948.   OUT_STR("\\WY");
  6949. @.\\WY@>
  6950.   yskipped = YES;
  6951.   }
  6952.  
  6953. @<Global...@>=
  6954.  
  6955. EXTERN LINE_NUMBER save_line; // Former value of |out_line|.
  6956. EXTERN ASCII HUGE *save_place; // Former value of |out_ptr|.
  6957. EXTERN boolean in_module SET(NO); // Between \.{\\WN} and \.{\\fi}?
  6958. EXTERN boolean yskipped SET(NO); // Did we skip between parts?
  6959.  
  6960. @<Translate the current module@>= 
  6961. {
  6962. the_part = TEX_;
  6963.  
  6964. /* Again, all modules start off in the global language. */
  6965. params = global_params;
  6966. frz_params();
  6967. scanning_meta = NO; // For safety.
  6968.  
  6969.   module_count++;
  6970.  
  6971.   @<Output the code for the beginning of a new module@>;
  6972.   save_position;
  6973.  
  6974.   trns_TeX();
  6975.   trns_defn();
  6976.   trns_code();
  6977.  
  6978.   @<Show cross-references to this module@>;
  6979.   @<Output the code for the end of a module@>;
  6980. }
  6981.  
  6982. @ Modules beginning with the \.{WEB} control sequence~`\.{@@\ }' start in the
  6983. output with the \TeX\ control sequence~`\.{\\WM}', followed by the module
  6984. number. Similarly, `\.{@@*}'~modules lead to the control sequence~`\.{\\WN}'.
  6985. If this is a changed module, we put~\.{*} just before the module number.
  6986.  
  6987. @<Output the code for the beginning...@>=
  6988. {
  6989. @<Output the include file name if necessary@>;
  6990.  
  6991. if(!in_module && output_on)
  6992.     {
  6993.     OUT_STR(*(loc-1) == @'*' ? "\\WN" : "\\WM");
  6994. @.\\WM@>
  6995. @.\\WN@>
  6996.     in_module = YES;
  6997.  
  6998.     out_mod(module_count,NO_ENCAP); OUT_STR(". ");
  6999.     }
  7000.  
  7001. progress(); // Progress report to terminal.
  7002. }
  7003.  
  7004. @ These variables remember the last and current name of the include file.
  7005. @<Glob...@>=
  7006.  
  7007. IN_COMMON outer_char last_include_file[],this_include_file[];
  7008.  
  7009. @<Output the include file name...@>=
  7010.  
  7011. if(STRCMP(last_include_file,this_include_file) != 0)
  7012.     {
  7013.     STRCPY(last_include_file,this_include_file);
  7014.     OUT_STR("\\WIF{"); @~ out_fname(this_include_file); @~
  7015.         OUT_STR("}"); 
  7016.     fin_line();
  7017.     }
  7018.  
  7019. @ In the \TeX\ part of a module, we simply copy the source text, except that
  7020. index entries are not copied and \cee\ text within \Cb\ is translated.
  7021.  
  7022. @<Part 2@>=@[
  7023.  
  7024. SRTN trns_TeX(VOID)
  7025. {
  7026. the_part = TEX_;
  7027. parsing_mode = OUTER;
  7028.  
  7029. do
  7030.     {
  7031.     next_control = copy_TeX();
  7032.  
  7033.     switch(next_control) 
  7034.         {
  7035.        @<Cases to set |language| and |break|@>@:@;
  7036.  
  7037.        case toggle_output: 
  7038.         out_skip();
  7039.         break;
  7040.  
  7041.         case @'|': ini_stack; output_C(); break;
  7042.  
  7043.         case math_break: 
  7044.         out(@'|'); // Literal vertical bar.
  7045.         break;
  7046.  
  7047.         case @'@@': 
  7048.         out(@'@@'); // Literal '\.{@@}'.
  7049.         break;
  7050.  
  7051.        case invisible_cmnt:  loc = limit + 1; break;
  7052.  
  7053.        case begin_meta:
  7054.         OUT_STR(w_style.misc.meta.TeX.begin); 
  7055.         break;
  7056.  
  7057.        case end_meta:
  7058.         OUT_STR(w_style.misc.meta.TeX.end); 
  7059.         break;
  7060.  
  7061.         case TeX_string: 
  7062.             case xref_roman: case xref_wildcard: case xref_typewriter:
  7063.         case macro_module_name: case module_name: 
  7064.         loc-=2; next_control=get_next(); /* skip to \.{@@>} */ 
  7065.  
  7066.       if (next_control==TeX_string)
  7067.         ERR_PRINT(W,"TeX string should be in code text only"); break;
  7068. @.TeX string should be...@>
  7069.  
  7070.     case thin_space: 
  7071.     case line_break: case big_line_break: case no_line_break: case join:
  7072.     case pseudo_semi: case pseudo_expr: case pseudo_colon:
  7073.     case compiler_directive: case Compiler_Directive:
  7074.     case no_index:
  7075.     case begin_bp: case insert_bp:
  7076.      ERR_PRINT(W,"You can't do that in TeX text"); break;
  7077. @.You can't do that...@>
  7078.  
  7079.    case protect_code:
  7080.     if(*loc != @'|')
  7081.         ERR_PRINT(W, "@@p should be immediately followed by '|'");
  7082.  
  7083.     output_protect = YES;
  7084.     break;
  7085.  
  7086.    case USED_BY_NEITHER:
  7087.     err_print(W, "Invalid `@@%c' ignored", XCHR(*(loc-1)));
  7088.     break;
  7089.         }
  7090.     } 
  7091. while (next_control<formatt);
  7092.  
  7093. output_protect = NO;
  7094. }
  7095.  
  7096. @ We need a flag to suppress phase~2 declarations of stuff recognized
  7097. during macro definitions.  Some other flags are useful too.
  7098. @<Glob...@>=
  7099.  
  7100. EXTERN boolean ok_to_define SET(YES);
  7101. EXTERN boolean q_protected SET(NO); // For protecting with quotes.
  7102. EXTERN boolean suppress_defn SET(NO); // For masking out formats, etc.
  7103. EXTERN boolean output_protect SET(NO); // For writing \.{\\protect}.
  7104.  
  7105. @ When we get to the following code we have |next_control>=formatt|, and
  7106. the token memory is in its initial empty state.
  7107.  
  7108. @d SUPPRESS(name) if(!defn_mask.name) suppress_defn = YES@;
  7109.  
  7110. @<Part 2@>=@[
  7111.  
  7112. SRTN trns_defn(VOID)
  7113. {
  7114. boolean overload_ops0 = overload_ops;
  7115.  
  7116. the_part = DEFINITION;
  7117. parsing_mode = OUTER;
  7118.  
  7119. if (next_control<begin_code) 
  7120.     { /* definition part non-empty */
  7121.     emit_space_if_needed; save_position;
  7122.     @<Store the output switch@>@;
  7123. @%    @<Append \.{\\WP}@>@;
  7124.     }
  7125.  
  7126. while (next_control<begin_code) 
  7127.     @<Translate a |definition|, |formatt|, etc.@>@;
  7128. }
  7129.  
  7130. @ Now deal with a |formatt|, |definition|, |undefinition|, |WEB_definition|,
  7131. |limbo_text|, |op_def|, |macro_def|,  or \.{@@\#...} command.
  7132.  
  7133. @<Translate a |definition|...@>=
  7134. {
  7135. eight_bits last_control = next_control;
  7136. boolean nuweb_mode0;
  7137.  
  7138. ini_stack;
  7139.  
  7140. switch(next_control)
  7141.     {
  7142.    case begin_comment:
  7143.    case invisible_cmnt:
  7144.     break;
  7145.  
  7146.    default:
  7147.     @<Store the output switch@>@;
  7148.     break;
  7149.     }
  7150.  
  7151. nuweb_mode0 = nuweb_mode;
  7152. nuweb_mode = NO;
  7153.  
  7154. switch(next_control)
  7155.     {
  7156.    case formatt:
  7157.     @<Start a format definition@>@;
  7158.     break;
  7159.  
  7160.    case limbo_text:
  7161.     @<Start a limbo text definition@>@;
  7162.     break;
  7163.  
  7164.    case op_def:
  7165.     @<Start an overloaded operator definition@>@;
  7166.     break;
  7167.  
  7168.    case macro_def:
  7169.     @<Start an overloaded identifier definition@>@;
  7170.     break;
  7171.  
  7172.    case begin_comment:
  7173.     doing_cdir = NO;
  7174.     break;
  7175.  
  7176.    case invisible_cmnt:
  7177.     loc = limit + 1; // Skip the line.
  7178. /* Skip any other extraneous material that doesn't belong in the definition
  7179. section. */ 
  7180.     while((next_control=get_next()) < formatt
  7181.         && next_control!=begin_comment);
  7182.     continue;
  7183.  
  7184.    default:
  7185.     @<Start a macro definition@>@;
  7186.     break;
  7187.     }
  7188.  
  7189. ok_to_define = NO;
  7190. nuweb_mode = nuweb_mode0;
  7191.  
  7192. outr_parse(); // Scan the definition or whatever.
  7193.  
  7194. if(auto_app_semi && last_control==WEB_definition) 
  7195.     {app_scrap(semi,maybe_math);}
  7196.  
  7197. overload_ops = overload_ops0;
  7198. fin_C(); // Finish up the definition or whatever.
  7199. ok_to_define = YES;
  7200. }
  7201.  
  7202. @ The switch into code mode is appended rather than just written directly
  7203. out in order to deal with the |output_on| status properly.
  7204. @<Append \.{\\WP}@>=
  7205. {
  7206. APP_STR("\\WP");
  7207. @.\\WP@>
  7208. }
  7209.  
  7210. @ The |fin_C| procedure outputs the translation of the current scraps,
  7211. preceded by the control sequence~`\.{\\WP}' and followed by the control
  7212. sequence~`\.{\\par}'. It also restores the token and scrap memories to
  7213. their initial empty state.
  7214.  
  7215. A |force| token is appended to the current scraps before translation takes
  7216. place, so that the translation will normally end with~\.{\\6} or~\.{\\7}
  7217. (the \TeX\ macros for |force| and |big_force|). This~\.{\\6} or~\.{\\7} is
  7218. replaced by the concluding \.{\\par} or by \.{\\WY\\par}.
  7219.  
  7220. @<Part 2@>=@[
  7221.  
  7222. SRTN fin_C(VOID) // Finishes a definition or a \cee\ part.
  7223. {
  7224. text_pointer p; // Translation of the scraps.
  7225. boolean current_output_state = output_on;
  7226.  
  7227. if(!suppress_defn)
  7228.     {
  7229. @%    output_on = YES;
  7230.     column_mode = NO;
  7231.  
  7232.     app_tok(force); // Last thing in the translation.
  7233.     app_scrap(ignore_scrap,no_math); 
  7234.         // The last stuff doesn't count for syntax.
  7235.  
  7236. /* We've accumulated all the stuff for one part.  Translate it, then print
  7237. it. */
  7238.     p = translate(OUTER);
  7239.  
  7240.     APP_FLAG(tok,p,tok_start);
  7241.     make_output(); // Output the list.
  7242.  
  7243.     if (out_ptr>out_buf+1)
  7244.         @<Tidy up the end of the part@>@;
  7245.  
  7246.     OUT_STR("\\par"); fin_line();
  7247.  
  7248. /* Accumulate statistics. */
  7249.     if (text_ptr>mx_text_ptr) 
  7250.         mx_text_ptr=text_ptr;
  7251.     if (tok_ptr>mx_tok_ptr) 
  7252.         mx_tok_ptr=tok_ptr;
  7253.     if (scrp_ptr>mx_scr_ptr) 
  7254.         mx_scr_ptr=scrp_ptr;
  7255.     }
  7256. else 
  7257.     suppress_defn = NO;
  7258.  
  7259. /* Forget the tokens and the scraps. */  
  7260. tok_ptr=tok_mem+1; text_ptr=tok_start+1; scrp_ptr=scrp_info;
  7261.  
  7262. #if(0)
  7263. if(strt_off) output_on = strt_off = ending_off = NO;
  7264. if(ending_off)
  7265.     {
  7266.     strt_off = ending_off = NO;
  7267.     output_on = YES;
  7268.     }
  7269. #endif
  7270.  
  7271. output_on = current_output_state;
  7272. }
  7273.  
  7274. @
  7275. @<Tidy up...@>=
  7276. {
  7277.         if (*(out_ptr-1)==@'\\')
  7278.             {
  7279. @.\\6@>
  7280. @.\\7@>
  7281. @.\\WY@>
  7282.             if (*out_ptr==@'6') 
  7283.                 out_ptr -= 2; // Throw away the \.{\\6}.
  7284.             else if (*out_ptr==@'7') 
  7285.                 {
  7286.                 out_ptr -= 2; // Throw away the \.{\\7}\dots
  7287.                 OUT_STR("\\WY"); 
  7288.                     // and replace it with \.{\\WY}.
  7289.                 }
  7290.             }
  7291. }
  7292.  
  7293. @ Here is a nucleus that writes out the appropriate macro for the
  7294. preprocessor command.
  7295.  
  7296. @d APP_TEMP(letter,arg) app_temp(OC(letter),OC(arg))
  7297.  
  7298. @<Part 2@>=@[
  7299.  
  7300. SRTN app_temp FCN((letter,arg))
  7301.     CONST outer_char letter[] C0("")@;
  7302.     CONST outer_char arg[] C1("")@;
  7303. {
  7304. char temp[50];
  7305.  
  7306. sprintf(temp,"\\W%s:%s:", (char *)letter, (char *)arg);
  7307. APP_STR(temp);
  7308. }
  7309.  
  7310. @ This nucleus appends stuff for the preprocessor commands, macro
  7311. definitions, formats, etc.
  7312.  
  7313. @<Part 2@>=@[
  7314.  
  7315. SRTN app_proc FCN((next_control))
  7316.     eight_bits next_control C1("")@;
  7317. {
  7318. if(the_part == DEFINITION) 
  7319.     {
  7320.     @<Append \.{\\WP}@>@;
  7321.  
  7322.     if(yskipped)
  7323.         {
  7324.         @<Append the scrap header for the definition part@>@;
  7325.         yskipped = NO;
  7326.         }
  7327.     }
  7328.  
  7329. switch(next_control)
  7330.     {
  7331.    case WEB_definition:  // ``\.{@@m}''
  7332.     APP_STR(upper_case_code ? "\\WMD" : "\\WMd"); @~ break;
  7333.  
  7334.    case undefinition: // ``\.{@@u}''
  7335.     APP_LANG("Ud"); @~ break;
  7336.     
  7337.    case definition:  // ``\.{@@d}''
  7338.     APP_LANG(upper_case_code ? "D" : "d"); @~ break; 
  7339.  
  7340.    case formatt: // ``\.{@@f}''
  7341.     APP_LANG(upper_case_code ? "F" : "f"); @~ break;
  7342.  
  7343.    case limbo_text: // ``\.{@@l}''
  7344.     APP_LANG("l"); @~ break;
  7345.  
  7346.    case op_def: // ``\.{@@v}''
  7347.     APP_LANG("v"); @~ break;
  7348.  
  7349.    case macro_def:  // `\.{@@w}'.
  7350.     APP_LANG(upper_case_code ? "WW" : "w"); @~ break;
  7351.  
  7352.    case m_ifdef:
  7353.     APP_TEMP("E","ifdef"); @~ break;
  7354.  
  7355.    case m_ifndef:
  7356.     APP_TEMP("E","ifndef"); @~ break;
  7357.  
  7358.    case m_line:
  7359.     APP_TEMP("E","line"); @~ break;
  7360.  
  7361.    case m_undef:
  7362.     APP_TEMP("E","undef"); @~ break;
  7363.  
  7364.    case m_if:
  7365.     APP_TEMP("E","if"); @~ break;
  7366.  
  7367.    case m_elif:
  7368.     APP_TEMP("E","elif"); @~ break;
  7369.  
  7370.    case m_else:
  7371.     APP_TEMP("E","else"); 
  7372.     app_scrap(ignore_scrap,no_math);
  7373.     break;
  7374.  
  7375.    case m_for:
  7376.     APP_TEMP("E","for"); @~ break;
  7377.  
  7378.    case m_endfor:
  7379.     APP_TEMP("E","endfor");
  7380.     app_scrap(ignore_scrap,no_math);
  7381.     break;
  7382.  
  7383.    case m_endif:
  7384.     APP_TEMP("E","endif");
  7385.     app_scrap(ignore_scrap,no_math);
  7386.     break;
  7387.     }
  7388. @.\\WD@>
  7389. @.\\WMD@>
  7390. @.\\WE@>
  7391. }
  7392.  
  7393. @ This function helps keep the code short.
  7394.  
  7395. @d APP_LANG(suffix) app_lang(OC(suffix))
  7396.  
  7397. @<Part 2@>=@[
  7398.  
  7399. SRTN app_lang FCN((suffix))
  7400.     CONST outer_char *suffix C1("")@;
  7401. {
  7402. APP_TEMP(suffix,(CONST outer_char *)(language_symbol(language)));
  7403. }
  7404.  
  7405. @ Macro definitions have the syntax `\.{@@m\ A\ b}' or `\.{@@m\ A(x)\ y}'.
  7406. Keeping in line with the conventions of the C and~\.{WEB} preprocessors
  7407. (and otherwise contrary to the rules of \.{WEB}) we distinguish here
  7408. between the case that `\.('~immediately follows an identifier and the case
  7409. that the two are separated by a space.  In the latter case, and if the
  7410. identifier is not followed by~`\.(' at all, the replacement text starts
  7411. immediately after the identifier.  In the former case, it starts after we
  7412. scan the matching~`\.)'.
  7413.  
  7414. @<Start a macro...@>= 
  7415. {
  7416. LANGUAGE saved_language = language;
  7417.  
  7418. if(next_control == definition)
  7419.     SUPPRESS(outer_macros);
  7420.  
  7421. if(next_control == WEB_definition)
  7422.     SUPPRESS(macros);
  7423.  
  7424. app_proc(next_control);
  7425.  
  7426. if(language==TEX) 
  7427.     language = C;
  7428.  
  7429. if( ((C_LIKE(language) || language==LITERAL) &&
  7430.         next_control<=WEB_definition) || 
  7431.         next_control==WEB_definition || 
  7432.         next_control==m_ifdef || 
  7433.         next_control==m_ifndef || next_control==m_undef)
  7434.     {
  7435.     if( (next_control=get_next())!=identifier && next_control != @'[')
  7436.         {
  7437.         ERR_PRINT(W,"Improper macro definition: \
  7438. expected identifier");
  7439. @.Improper macro definition@>
  7440.         }
  7441.     else 
  7442.         {
  7443.         if(next_control == @'[') 
  7444.             @<Format auto insertion@>@;
  7445.  
  7446.         app(@'$'); APP_ID;
  7447.  
  7448.         if (*loc==@'(') 
  7449.             @<Append argument of \WEB\ macro@>@;
  7450.          else 
  7451.             { /* Id not followed by parenthesis. */
  7452.             next_control = get_next();
  7453.             }
  7454.  
  7455.         app(@'$'); app(break_space);
  7456.         app_scrap(ignore_scrap,no_math); /* scrap won't take part in
  7457.                         the parsing */ 
  7458.         }
  7459.     }
  7460. else 
  7461.     next_control = get_next(); 
  7462.  
  7463. if(saved_language == TEX)
  7464.     language = saved_language;
  7465. }
  7466.  
  7467. @
  7468. @<Format auto insert...@>=
  7469. {
  7470. APP_STR("\\Wauto");
  7471. get_string(@'[','\0');
  7472. *id_loc = '\0';
  7473. app_ASCII_str(id_first);
  7474. next_control = get_next();
  7475. }
  7476.  
  7477. @
  7478. @<Append argument of \WEB\ macro@>=
  7479. {
  7480. reswitch: 
  7481.   next_control = get_next();
  7482. the_switch:
  7483.   switch(next_control)
  7484.     {
  7485.       case @'(': 
  7486.     app(next_control);
  7487.     next_control = get_next();
  7488.     if(next_control == @')')
  7489.         {
  7490.         b_app(@'\\'); @~ b_app(@','); // Extra thinspace for beauty.
  7491.         goto done_arg;
  7492.         }
  7493.     else goto the_switch;
  7494.  
  7495.       case @',': 
  7496.     app(next_control); goto reswitch;
  7497.  
  7498.       case identifier: 
  7499.     APP_ID;
  7500.     goto reswitch; 
  7501.  
  7502.       case ellipsis:
  7503.     APP_STR("\\dots");
  7504.     if( (next_control=get_next()) != @')')
  7505.         {
  7506.         ERR_PRINT(M,"Improper macro \
  7507. definition: expected ')' after ellipsis");
  7508.         break;
  7509.         }
  7510.  
  7511.       case @')': 
  7512.        done_arg:
  7513.     app(next_control); app(@'~');
  7514.     next_control=get_next(); break; 
  7515.  
  7516.       default: 
  7517.     ERR_PRINT(M,"Improper macro definition: \
  7518. unrecognized token in argument list"); 
  7519.     break;
  7520.     }
  7521. }
  7522.  
  7523. @ Here we append a format command, which has the two possible forms
  7524. ``\.{@@f\ a\ b}'' or ``\.{@@f\ `\{\ 11}''.
  7525.  
  7526. @<Start a format...@>= 
  7527. {
  7528. LANGUAGE saved_language = language;
  7529. scrap_pointer scrp_ptr0;
  7530.  
  7531. if(upper_case_code)
  7532.     {
  7533.     SUPPRESS(Formats);
  7534.     }
  7535. else
  7536.     {
  7537.     SUPPRESS(formats);
  7538.     }
  7539.  
  7540. /* Mark formats that are not in the global language. */
  7541. app_proc(next_control); // |formatt|.
  7542. scrp_ptr0 = scrp_ptr; // Save to help check valid format.
  7543. app_scrap(expr,maybe_math); /* this will produce `\&{format}'. The
  7544.     macro inserts a blank after \&{format}. */
  7545. @.\\WF@>
  7546.  
  7547. if(language==TEX) 
  7548.     language = C; // This kludge ought to be removed!
  7549.  
  7550. next_control=get_next(); /* First field: identifier, module name, or~'\.`'. */
  7551.  
  7552. if (next_control==identifier || next_control==module_name) 
  7553.     @<Format an identifier or module name@>@;
  7554. else if(next_control==@'`')
  7555.     @<Format a category code@>@;
  7556.  
  7557. if (scrp_ptr!=scrp_ptr0+3) 
  7558.     ERR_PRINT(W,"Improper format definition");
  7559. @.Improper format definition@>
  7560.  
  7561. /* The following doesn't work right if the format command is immediately
  7562. followed by a language-changing command. */
  7563. if(saved_language == TEX)
  7564.     language = saved_language;
  7565. }
  7566.  
  7567. @
  7568. @<Format an identifier or mod...@>=
  7569. {
  7570. if(next_control==identifier) 
  7571.     APP_ID;
  7572. else 
  7573.     APP_FLAG(mod,cur_module,name_dir);
  7574.  
  7575. APP_STR("\\ ");
  7576.  
  7577. next_control=get_next(); /* Second field: identifier. */
  7578.  
  7579. if (next_control==identifier) 
  7580.     {
  7581.     APP_ID;
  7582.     @<Finish appending format definition@>@;
  7583.     }
  7584. }
  7585.  
  7586. @
  7587. @<Finish appending format...@>=
  7588. {
  7589. app_scrap(expr,maybe_math); 
  7590. app_scrap(semi,maybe_math); // Pseudo-semi.
  7591.  
  7592. sharp_include_line = NO;
  7593.  
  7594. next_control=get_next();
  7595. }
  7596.  
  7597. @ Here we typeset a format command that changes a category code, such as
  7598. ``\.{@@f\ `a\ 10}''.
  7599.  
  7600. @<Format a cat...@>=
  7601. {
  7602. @<Append commands for beginning of string@>@;
  7603. app(@'`');
  7604. if( (next_control = get_TeX()) == constant)
  7605.     APP_STR((outer_char *)id_first);
  7606. app(@'}');
  7607.  
  7608. APP_STR("\\ ");
  7609.  
  7610. next_control = get_next(); // Integer category code.
  7611.  
  7612. if(next_control == constant)
  7613.     {
  7614.     APP_STR("\\WO{");
  7615.  
  7616.     while(id_first < id_loc)
  7617.         app_tok(*id_first++);
  7618.  
  7619.     app(@'}');
  7620.  
  7621.     @<Finish appending format...@>@;
  7622.     }
  7623. }
  7624.  
  7625. @ Here we append a limbo text definition of the form ``\.{@@l\ "text"}''.
  7626.  
  7627. @<Start a limbo...@>=
  7628. {
  7629. SUPPRESS(limbo);
  7630.  
  7631. app_proc(next_control);
  7632. app_scrap(expr,maybe_math);
  7633.  
  7634. /* First field: String. */
  7635. if((next_control = get_next()) != stringg)
  7636.     ERR_PRINT(W,"A string must follow @@l"); 
  7637. }
  7638.  
  7639. @ Here we append an operator-overload command, of the form ``\.{@@v\ .IN.\
  7640. "\\\\in"\ +}''.
  7641.  
  7642. @<Start an overloaded op...@>=
  7643. {
  7644. SUPPRESS(v);
  7645.  
  7646. overload_ops = NO;
  7647.  
  7648. app_proc(next_control);
  7649. app_scrap(expr,maybe_math);
  7650.  
  7651. /* First field: The operator to be overloaded. */
  7652. if(valid_op(next_control = get_next()))
  7653.     {
  7654.     @<Append an operator name@>@;
  7655.  
  7656.     app(@' '); @~ app_scrap(expr,no_math);
  7657.  
  7658.  /* Second field: Replacement text. */
  7659.     if((next_control = get_next()) == stringg)
  7660.         {
  7661.         @<Append commands for beginning of string@>@;
  7662.         @<Append the basic str...@>@;
  7663.         app_scrap(expr,yes_math);
  7664.  
  7665.     /* Third field: Cat of this operator. */
  7666.         if(valid_op(next_control=get_next()))
  7667.             {
  7668.             app(@' '); @~ app_scrap(expr,no_math);
  7669.  
  7670.             @<Append an operator...@>@;        
  7671.  
  7672.             next_control = get_next();
  7673.             }
  7674.         }
  7675.     }
  7676. }
  7677.  
  7678. @ The last field of an \.{@@v}~command can be either an operator like~`\.+'
  7679. or an identifier like~`\.{.IN.}'.
  7680.  
  7681. @<Append an operator...@>=
  7682. {
  7683. switch(next_control)
  7684.     {
  7685.    case identifier:
  7686.     ERR_PRINT(W,"For future compatibility, please use syntax .NAME. for \
  7687. overloading dot operators");
  7688.  
  7689.     APP_ID;
  7690.     break;
  7691.  
  7692.    case dot_const:
  7693.     @<Append commands for beginning of string@>@;
  7694.     app(wt_style.dot_delimiter.begin);
  7695.     app_ASCII_str(dot_op.name + 1);
  7696.     app(wt_style.dot_delimiter.end);
  7697.     app(@'}');
  7698.     break;
  7699.  
  7700.    default:
  7701.     app(@'{'); 
  7702.     app_overload();
  7703.     app(@'}');
  7704.     break;
  7705.     }
  7706.  
  7707. app_scrap(expr,yes_math);
  7708. }
  7709.  
  7710. @
  7711. @<Start an overloaded id...@>=
  7712. {
  7713. SUPPRESS(w);
  7714.  
  7715. app_proc(next_control);
  7716. app_scrap(expr,maybe_math);
  7717.  
  7718. /* First field:  The identifier to be overloaded. */
  7719. if((next_control = get_next()) == identifier)
  7720.     {
  7721.     ASCII HUGE *id_first0, HUGE *id_loc0;
  7722.  
  7723. /* Remember first identifier. */
  7724.     id_first0 = id_first;
  7725.     id_loc0 = id_loc;
  7726.  
  7727.     APP_ID;
  7728.  
  7729.     app(@' '); @~ app_scrap(expr,no_math);
  7730.  
  7731. /* Second field:  Replacement text. */
  7732.     switch(next_control = get_next())
  7733.         {
  7734.        case @'\\':
  7735.         if((next_control=get_next()) != identifier) break;
  7736.         goto quick_code1;
  7737.  
  7738.        case QUICK_FORMAT:
  7739.         id_first = id_first0;
  7740.         id_loc = id_loc0;
  7741.  
  7742.     quick_code1:
  7743.         @<Append commands for beginning of string@>@;
  7744.         APP_STR("\\\\");
  7745.         *id_loc = '\0'; // Make name into string.
  7746.         app_ASCII_str(id_first);
  7747.         app(@'}');
  7748.         app_scrap(expr,yes_math);
  7749.         next_control = get_next();
  7750.         break;
  7751.  
  7752.        case stringg:
  7753.         @<Append commands for beginning of string@>@;
  7754.         @<Append the basic str...@>@;
  7755.         app_scrap(expr,yes_math);
  7756.         next_control = get_next();
  7757.         break;
  7758.         }
  7759.     }
  7760. }
  7761.  
  7762. @ Finally, when the \TeX\ and definition parts have been treated, we have
  7763. |next_control>=begin_code|. We will make the global variable |this_module|
  7764. point to the current module name, if it has a name; otherwise, it will be
  7765. equal to |name_dir|.
  7766.  
  7767. @<Global...@>=
  7768.  
  7769. EXTERN name_pointer this_module; // The current module name, or zero.
  7770. EXTERN name_pointer the_module; /* The module we're working on; equal to
  7771.     |cur_module| at the beginning of the entire module. */
  7772.  
  7773. @<Part 2@>=@[
  7774.  
  7775. SRTN trns_code(VOID)
  7776. {
  7777. the_part = CODE;
  7778. this_module = name_dir;
  7779. parsing_mode = OUTER;
  7780.  
  7781. if (next_control<=module_name) 
  7782.     {
  7783. @%    emit_space_if_needed; 
  7784.     OUT_STR("\\WY");
  7785.     ini_stack;
  7786.     @<Store the output switch@>@;
  7787.     @<Append \.{\\WP}@>@;
  7788.  
  7789.     if (next_control==begin_code)
  7790.         { /* We've hit an \.{@@a}. */
  7791.         boolean nuweb_mode0 = nuweb_mode;
  7792.  
  7793.         unnamed_section = YES;
  7794.         params = global_params;// Unnamed module is in global language.
  7795.         nuweb_mode = nuweb_mode0;        
  7796.         frz_params();
  7797.         the_module = NULL;
  7798.         @<Maybe start column mode.@>@;
  7799.  
  7800.         @<Append the scrap header for code@>@; // !!!!!
  7801.         }
  7802.       else 
  7803.         { /* Named module. */
  7804.         unnamed_section = NO;
  7805.  
  7806.         if(cur_module != NULL) 
  7807.             {
  7808.             params = cur_module->mod_info->params;
  7809.                 // Restore state for this module.
  7810.             frz_params();
  7811.             this_module = cur_module;
  7812.             }
  7813.         the_module = cur_module;
  7814.         @<Check that |=| or |==| follows this module name, and
  7815.               emit the scraps to start the module definition@>;
  7816.         }
  7817.  
  7818. /* Now scan the whole module. */
  7819.       while  (next_control<=module_name) 
  7820.         {
  7821.         outr_parse();
  7822.         @<Emit the scrap for a module name if present@>;
  7823.         }
  7824.  
  7825.     @<Reset the language before translation@>@;
  7826.     fin_C();
  7827.     unnamed_section = NO;
  7828.     }
  7829. }
  7830.  
  7831. @
  7832. @<Append the scrap header for the definition part@>=
  7833. {
  7834. app_hdr("defs");
  7835. }
  7836.  
  7837. @
  7838. @<Append the scrap header for code@>=
  7839. {
  7840. app_hdr("code");
  7841. }
  7842.  
  7843. @ The scrap header needs the file name as argument to \.{\\Wunnamed}; it
  7844. must be escaped.  We use the |mod_text| buffer as a scratch area.
  7845.  
  7846. @<Part 2@>=@[
  7847.  
  7848. SRTN app_hdr FCN((section_part))
  7849.     CONST char *section_part C1("Either \"code\" or \"defs\"")@;
  7850. {
  7851. outer_char temp[1000], *temp_end = temp + 1000, *t_first, *t_loc;
  7852.  
  7853. t_first = temp;
  7854. STRCPY(t_first, params.OUT_FILE_NAME);
  7855. to_ASCII(t_first);
  7856. t_first = esc_buf((ASCII HUGE *)t_first+STRLEN(t_first)+1, 
  7857.     (ASCII HUGE *)temp_end, (CONST ASCII HUGE *)t_first, YES); 
  7858. to_outer((ASCII HUGE *)t_first);
  7859. t_loc = t_first + STRLEN(t_first) + 1;
  7860. sprintf((char *)t_loc, " \\Wunnamed{%s}{%s}%%\n", 
  7861.     section_part, (char *)t_first);
  7862. APP_STR(t_loc);
  7863. app_scrap(ignore_scrap,no_math);
  7864. }
  7865.  
  7866. @<Check that |=|...@>=
  7867. {
  7868. LANGUAGE saved_language = language;
  7869.  
  7870. if(language==TEX) 
  7871.     language = C;
  7872.  
  7873. /* Allow optional `\.{+=}'. */
  7874. do 
  7875.     next_control=get_next();
  7876. while (next_control==@'+');
  7877.  
  7878. language = saved_language;
  7879.  
  7880. switch(next_control)
  7881.     {
  7882.    case compound_assignment:
  7883.     if(assignment_token != plus_eq)
  7884.         {
  7885.         ERR_PRINT(W,"Invalid compound assignment after section \
  7886. name; please use one of `=', `==', or `+='");
  7887. @.Invalid compound assignment...@>
  7888.         break;
  7889.         }
  7890.  
  7891. /* The |plus_eq| falls through to the next case. */
  7892.  
  7893.    case @'=':
  7894.    case eq_eq:
  7895.     @<Maybe start column mode.@>@; // Positioned after `\.{@@<\dots@@>=}'.
  7896.     break;
  7897.  
  7898.    default:
  7899.     ERR_PRINT(W,"You need an = sign after the section name");
  7900. @.You need an = sign...@>
  7901.     break;
  7902.     }
  7903.  
  7904. #if(0)
  7905. if (out_ptr>out_buf+2 && STRNCMP(out_ptr-2,"\\WY",3)==0)
  7906. #endif
  7907.     {
  7908.     app(backup);     /* The module name will be flush left */
  7909.     app(backup);
  7910.     }
  7911. @.\\WY@>
  7912.  
  7913. APP_FLAG(mod,this_module,name_dir);
  7914. cur_xref = (xref_pointer)this_module->xref;
  7915. APP_STR("${}");
  7916.  
  7917. if(cur_xref->num != module_count+def_flag) 
  7918.     {
  7919.     APP_STR("\\PQ"); // Module name is multiply defined,
  7920. @.\\PQ@>
  7921.     this_module=name_dir; // so we won't give cross-reference info here.
  7922.     }
  7923. else 
  7924.     APP_STR("\\WSQ"); // Output the equivalence sign~`$\equiv$'.
  7925. @.\\WSQ@>
  7926.  
  7927. APP_STR("{}$");
  7928. app_misc(w_style.misc.named_preamble); // Optional stuff from style file.
  7929. app(force);  // This forces a line break unless `\.{@@~}' follows.
  7930. app_scrap(ignore_scrap,no_math);
  7931. }
  7932.  
  7933. @ Because the language may have changed in the middle of a module, we must
  7934. reset it before we perform the translation of the scraps that have just
  7935. been collected.
  7936.  
  7937. @<Reset the language...@>=
  7938. {
  7939. boolean nuweb_mode0 = nuweb_mode;
  7940.  
  7941. params = (the_module == NULL ? global_params : the_module->mod_info->params);
  7942. nuweb_mode = nuweb_mode0;
  7943. frz_params();
  7944. }
  7945.  
  7946. @ When we append miscellaneous stuff from the style file, we must be a bit
  7947. clever.  If the stuff contains something like~`\.{\\7}' and we just
  7948. appended it raw, it wouldn't be subject to the later output mechanism that
  7949. takes the maximum of adjacent |force| and |big_force| tokens.  Thus, we
  7950. will translate the macros~`\.{\\1}' to~`\.{\\8}' into their internal tokens
  7951. before appending them.  Other text in the miscellaneous string is just left
  7952. alone.
  7953.  
  7954. @<Part 2@>=@[
  7955.  
  7956. SRTN app_misc FCN((s))
  7957.     outer_char *s C1("")@;
  7958. {
  7959. outer_char *s0;
  7960.  
  7961. for(s0=s; *s; )
  7962.     if(*s++ == '\\')
  7963.         {
  7964.         if(isdigit(*s) && *s != '0' && *s != '8' && *s != '9')
  7965.             {
  7966.             *(s-1) = '\0'; // Terminate for |app_str|.
  7967.             APP_STR(s0);
  7968.  
  7969.             switch(*s)
  7970.                 {
  7971.                case '1': app(indent); @~ break;
  7972.                case '2': app(outdent); @~ break;
  7973.                case '3': app(opt); @~ break;
  7974.                case '4': app(backup); @~ break;
  7975.                case '5': app(break_space); @~ break;
  7976.                case '6': app(force); @~ break;
  7977.                case '7': app(big_force); @~ break;
  7978.                 }
  7979.             *(s-1) = '\\'; // Put it back for the next time.
  7980.             s0 = ++s; // Skip the digit.
  7981.             }
  7982.         }
  7983.  
  7984. APP_STR(s0);
  7985. }
  7986.  
  7987. @<Maybe start column mode.@>=
  7988. {
  7989. if(!nuweb_mode && ((FORTRAN_LIKE(language) && !free_form_input) 
  7990.         || (language==TEX)) ) 
  7991.     {
  7992.     @<Set up column mode@>@;
  7993.     next_control = ignore;
  7994.     }
  7995. else
  7996.     {
  7997.     @<Kill rest of line; no |auto_semi|@>@;
  7998.     next_control = (nuweb_mode ? begin_meta : get_next()); // !!!!!
  7999.     }
  8000. }
  8001.  
  8002. @
  8003. @<Kill rest of line; no...@>=
  8004.  
  8005. if(Fortran88 && auto_semi)
  8006.     {
  8007.     loc = limit + 1;
  8008.     chk_end = NO;
  8009.     }
  8010.  
  8011.  
  8012. @ When shifting into \FORTRAN\ mode, we skip any stuff on the same line as
  8013. the~\.{@@n}, because surely that text isn't in the appropriate columns.
  8014. @<Set up col...@>=
  8015. {
  8016. loc = limit + 1; // Skip rest of line.
  8017. chk_end = NO;
  8018. column_mode = YES;
  8019. }
  8020.  
  8021. @<Emit the scrap...@>=
  8022.  
  8023. if (next_control<module_name) 
  8024.     {
  8025.     switch(next_control)
  8026.         {
  8027.         case m_if: case m_ifdef: case m_ifndef: 
  8028.         case m_undef: case m_else: 
  8029.         case m_elif: case m_endif: 
  8030.         case m_for: case m_endfor:
  8031.         case m_line:
  8032.         case WEB_definition:
  8033.             pre_scrap(next_control);
  8034.             break;
  8035.  
  8036.         default:
  8037.               ERR_PRINT(W,"You can't do that in code text");
  8038. @.You can't do that...@>
  8039.             break;
  8040.         }
  8041.       next_control=get_next();
  8042.     }
  8043. else if (next_control==module_name) 
  8044.     {
  8045.     @<Append a module name@>@;
  8046.     next_control = (nuweb_mode ? begin_meta : get_next()); // !!!!!
  8047.     }
  8048.  
  8049. @ Tack on the representation of a module name.
  8050. @<Append a mod...@>=
  8051. {
  8052. if(cur_module) 
  8053.     APP_FLAG(mod,cur_module,name_dir);
  8054. app_scrap(cur_module != NULL ? cur_module->mod_ilk : expr,maybe_math); 
  8055. }
  8056.  
  8057. @ Build a preprocessor scrap.
  8058. @<Part 2@>=@[
  8059.  
  8060. SRTN pre_scrap FCN((last_control))
  8061.     eight_bits last_control C1("")@;
  8062. {
  8063. scrap_pointer save_base;
  8064. text_pointer p,q;
  8065. LANGUAGE saved_language = language;
  8066.  
  8067. app(force); 
  8068. app_proc(last_control);
  8069.  
  8070. switch(last_control)
  8071.     {
  8072.     case WEB_definition:
  8073.         @<Start a deferred macro definition@>;
  8074.         break;
  8075.     }
  8076.  
  8077. p = text_ptr; freeze_text;
  8078.  
  8079. save_base = scrp_base;
  8080. scrp_base = scrp_ptr + 1;
  8081.  
  8082. *limit = @'@@'; @~ *(limit+1) = @'m'; /* Stop the |outr_parse|. */
  8083. next_control = ignore;
  8084.  
  8085. if(language==TEX) language = C;
  8086.     outr_parse();
  8087. language = saved_language;
  8088.  
  8089. if(last_control==WEB_definition) {app_scrap(semi,maybe_math);}
  8090.  
  8091. q = translate(OUTER);
  8092. scrp_ptr = scrp_base - 1;
  8093. scrp_base = save_base;
  8094.  
  8095. APP_FLAG(tok,p,tok_start);
  8096. APP_FLAG(tok,q,tok_start);
  8097. APP_STR("\\WPs"); app(force); // Terminate preprocessor command.
  8098. app_scrap(ignore_scrap,no_math);
  8099. }
  8100.  
  8101. @
  8102. @<Start a deferred macro...@>=
  8103. {
  8104. if( (next_control=get_next())!=identifier)
  8105.            ERR_PRINT(M,"Improper deferred macro definition: \
  8106. expected identifier");
  8107. @.Improper macro definition@>
  8108. else 
  8109.     {
  8110.     app(@'$'); APP_ID;
  8111.  
  8112.     if (*loc==@'(')
  8113.         {
  8114.       reswitch: switch (next_control=get_next()) 
  8115.         {
  8116.           case @'(': case @',': 
  8117.             app(next_control); goto reswitch;
  8118.           case identifier: 
  8119.             APP_ID;
  8120.             goto reswitch; 
  8121.               case ellipsis:
  8122.                 APP_STR("\\dots");
  8123.                 if( (next_control=get_next()) != @')')
  8124.                     {
  8125.                     ERR_PRINT(M,"Improper deferred macro \
  8126. definition: expected ')' after ellipsis");
  8127.                     break;
  8128.                     }
  8129.           case @')': app(next_control); app(@' ');
  8130.             break; 
  8131.           default: ERR_PRINT(M,"Improper deferred macro definition: \
  8132. unrecognized token within argument list"); break;
  8133.          }
  8134.         }
  8135.  
  8136.     app(@'$'); app(break_space);
  8137.     app_scrap(ignore_scrap,no_math); /* scrap won't take part 
  8138.                     in the parsing */ 
  8139.     }
  8140. }
  8141.  
  8142. @ Cross references relating to a named module are given after the module ends.
  8143.  
  8144. @<Show cross...@>=
  8145.  
  8146. if (this_module>name_dir) 
  8147.     {
  8148.   @<Rearrange the list pointed to by |cur_xref|@>;
  8149.   footnote(def_flag); footnote(0);
  8150.     }
  8151.  
  8152. @ To rearrange the order of the linked list of cross-references, we need
  8153. four more variables that point to cross-reference entries.  We'll end up
  8154. with a list pointed to by |cur_xref|.
  8155.  
  8156. @<Global...@>=
  8157.  
  8158. EXTERN xref_pointer next_xref, this_xref, first_xref, mid_xref;
  8159.   /* Pointer variables for rearranging a list */
  8160.  
  8161. @ We want to rearrange the cross-reference list so that all the entries
  8162. with |def_flag| come first, in ascending order; then come all the other
  8163. entries, in ascending order.  There may be no entries in either one or both
  8164. of these categories.
  8165.  
  8166. @<Rearrange the list...@>=
  8167.  
  8168.   first_xref = (xref_pointer)this_module->xref;
  8169.   this_xref=first_xref->xlink; /* Bypass current module number */
  8170.  
  8171.   if (this_xref->num>def_flag) 
  8172.     {
  8173.         mid_xref=this_xref; cur_xref=0; /* This value doesn't matter */
  8174.  
  8175.       do 
  8176.         {
  8177.             next_xref=this_xref->xlink; this_xref->xlink=cur_xref;
  8178.             cur_xref=this_xref; this_xref=next_xref;
  8179.           } 
  8180.     while (this_xref->num>def_flag);
  8181.  
  8182.       first_xref->xlink=cur_xref;
  8183.     }
  8184. else mid_xref=xmem; /* First list null */
  8185.  
  8186. cur_xref=xmem;
  8187.  
  8188. while (this_xref!=xmem) 
  8189.     {
  8190.       next_xref=this_xref->xlink; this_xref->xlink=cur_xref;
  8191.       cur_xref=this_xref; this_xref=next_xref;
  8192.     }
  8193.  
  8194. if (mid_xref>xmem) mid_xref->xlink=cur_xref;
  8195. else first_xref->xlink=cur_xref;
  8196.  
  8197. cur_xref=first_xref->xlink;
  8198.  
  8199. @ The |footnote| procedure gives cross-reference information about multiply
  8200. defined module names (if the |flag| parameter is |def_flag|), or about the
  8201. uses of a module name (if the |flag| parameter is zero). It assumes that
  8202. |cur_xref| points to the first cross-reference entry of interest, and it
  8203. leaves |cur_xref| pointing to the first element not printed.  Typical
  8204. outputs: `\.{\\WA\ section 101.}'; `\.{\\WU\ sections 370 and 1009.}';
  8205. `\.{\\WA\ sections 8, 27\\*, and 64.}'.
  8206.  
  8207. @<Part 3@>=@[
  8208.  
  8209. SRTN footnote FCN((flag)) /* Outputs module cross-references */
  8210.     sixteen_bits flag C1("")@;
  8211. {
  8212.   xref_pointer q; /* Cross-reference pointer variable */
  8213.  
  8214.   if (cur_xref->num<=flag) return;
  8215.  
  8216.   fin_line(); OUT_STR("\\W");
  8217. @.\\WA@>
  8218. @.\\WU@>
  8219.  
  8220.   out( flag==0 ? @'U' : @'A');
  8221.  
  8222.   OUT_STR(" section");
  8223.   @<Output all the module numbers on the reference list |cur_xref|@>;
  8224.   out(@'.');
  8225.   fin_line();
  8226. }
  8227.  
  8228. @ The following code distinguishes three cases, according as the number of
  8229. cross-references is one, two, or more than two. Variable~|q| points to the
  8230. first cross-reference, and the last link is a zero.
  8231.  
  8232. @<Output all the module numbers...@>=
  8233.  
  8234. q=cur_xref; if (q->xlink->num>flag) out(@'s'); // Pluralize.
  8235. out(@'~');
  8236.  
  8237. WHILE()
  8238.     {
  8239.   out_mod(cur_xref->num-flag,ENCAP);
  8240.   cur_xref=cur_xref->xlink; /* Point to the next cross-reference to output */
  8241.  
  8242.   if (cur_xref->num<=flag) break;
  8243.  
  8244.   if (cur_xref->xlink->num>flag || cur_xref!=q->xlink) out(@',');
  8245.     /* Not the last of two */
  8246.  
  8247.   out(@' ');
  8248.  
  8249.   if (cur_xref->xlink->num<=flag) OUT_STR("and~"); /* the last */
  8250.     }
  8251.  
  8252. @<Output the code for the end of a module@>=
  8253. {
  8254. if(in_module && output_on)
  8255.     {
  8256.     outer_char temp[100];
  8257.  
  8258.     SPRINTF(100,temp,`"\\fi %% End of %s", MOD_TRANS(module_count)`);
  8259.     OUT_STR(temp); @~ fin_line();
  8260. @.\\fi@>
  8261.     mfree();
  8262.     in_module = NO;
  8263.  
  8264.     flush_buffer(out_buf,NO); // Insert a blank line for beauty.
  8265.     }
  8266. }
  8267.  
  8268. @* PHASE THREE PROCESSING.  We are nearly finished! \.{WEAVE}'s only
  8269. remaining task is to write out the index and module list, after sorting the
  8270. identifiers and index entries.  The index and module list are written into
  8271. separate files, by default \.{INDEX.tex} and \.{MODULES.tex}.
  8272.  
  8273. If the user has set the |no_xref| flag (the \.{-x} option on the command
  8274. line), just finish off the page, omitting the index, module name list, and
  8275. table of contents.  (Fix this up.)
  8276.  
  8277. @d NEW_TeX(file_name) 
  8278.     if(tex_file != stdout)
  8279.         {
  8280.         fclose(tex_file);
  8281.         if((tex_file=FOPEN(file_name,"w"))==NULL)
  8282.             FATAL(W, "! Can't open output file ",file_name);
  8283.         }
  8284.  
  8285. @<Part 3@>=@[
  8286.  
  8287. SRTN phase3(VOID) 
  8288. {
  8289. language = global_language;
  8290.  
  8291. if (no_xref && !prn_contents) 
  8292.     {
  8293.     fin_line();
  8294.     @<Finish off |phase3|@>@;
  8295.     }
  8296. else 
  8297.     { // Print cross-reference information.
  8298.     outer_char HUGE *temp_ndx,HUGE *temp_mds;
  8299.     IN_COMMON outer_char wbflnm0[];
  8300.  
  8301.     temp_ndx = GET_MEM("temp_ndx",MAX_FILE_NAME_LENGTH,outer_char);
  8302.     temp_mds = GET_MEM("temp_mds",MAX_FILE_NAME_LENGTH,outer_char);
  8303.  
  8304.     phase = 3; 
  8305.     nuweb_mode = NO; // Force full output of identifiers.
  8306.  
  8307.     if(prn_index)
  8308.         {
  8309.         OUT_STR("\\input "); 
  8310.         OUT_STR(xpn_name(&temp_ndx,MAX_FILE_NAME_LENGTH,
  8311.             w_style.indx.tex,wbflnm0));
  8312.         fin_line();
  8313.         }
  8314.  
  8315.     if(prn_modules)
  8316.         {
  8317.         OUT_STR("\\input "); 
  8318.         OUT_STR(xpn_name(&temp_mds,MAX_FILE_NAME_LENGTH,
  8319.             w_style.modules.tex,wbflnm0)); 
  8320.         fin_line(); 
  8321.  
  8322.         fin_line();
  8323.  
  8324.         @<Print the command line, etc.@>; 
  8325. @.\\Winfo@>
  8326.         }
  8327.  
  8328.     if(prn_contents)
  8329.         {
  8330.         outer_char temp[20];
  8331.  
  8332.         OUT_STR(w_style.contents.preamble); 
  8333.  
  8334.         SPRINTF(20, temp, `"{%i}", module_count`);
  8335.         OUT_STR(temp);
  8336.  
  8337.         OUT_STR(w_style.contents.postamble); 
  8338.         fin_line();
  8339. @.\\Wcon@>
  8340.         }
  8341.     else @<Finish off |phase3|@>@;
  8342.  
  8343.     if(prn_index) @<Output the index@>@;
  8344.     if(prn_modules) @<Output all the module names@>@;
  8345.  
  8346.     if(tex_file != stdout) fclose(tex_file);
  8347.     }
  8348.  
  8349. CLR_PRINTF(info,("\nDone."));
  8350. chk_complete(); /* Was all of the change file used? */
  8351. }
  8352.  
  8353. @
  8354. @<Finish off |phase3|@>=
  8355. {
  8356. OUT_STR("\\vfill\\FWEBend"); @~ fin_line();
  8357. }
  8358.  
  8359. @
  8360.  
  8361. @d N_CMD 1000
  8362.  
  8363. @<Print the command line...@>=
  8364. @{
  8365. outer_char HUGE *temp;
  8366.  
  8367. @b
  8368. temp = GET_MEM("temp",N_CMD,outer_char);
  8369.  
  8370. OUT_STR(w_style.modules.info);
  8371. OUT_STR(cmd_ln_buf); @~ fin_line();
  8372.  
  8373. /* Print a message identifying the global language. */
  8374. SPRINTF(N_CMD,temp,`" {%s}",language_name_ptr(global_language)`);
  8375. OUT_STR(temp); @~ fin_line();
  8376.  
  8377. FREE_MEM(temp,"temp",N_CMD,outer_char);
  8378. }
  8379.  
  8380.  
  8381. @ Here we escape an |ASCII| string into another buffer.  We return the
  8382. beginning of the output buffer.
  8383.  
  8384. @d TO_TEMP(val) if(temp < temp_end) *temp++ = val; 
  8385.         else OVERFLW("Esc_buf:temp","")@;
  8386.  
  8387. @<Part 3@>=@[
  8388.  
  8389. ASCII HUGE *esc_buf FCN((temp,temp_end,buf,all_cases))
  8390.     ASCII HUGE *temp C0("Put it into here.")@;
  8391.     CONST ASCII HUGE *temp_end C0("End of |temp|.")@;
  8392.     CONST ASCII HUGE *buf C0("Translate from here.")@;
  8393.     boolean all_cases C1("")@;
  8394. {
  8395. ASCII HUGE *temp0 = temp;
  8396.  
  8397. while(*buf != '\0')
  8398.     {
  8399.     switch(*buf)
  8400.         {
  8401.         @<Special \TeX\ cases@>:
  8402.             if(!all_cases) break;
  8403.  
  8404.         @<Other string cases@>:
  8405.             TO_TEMP(@'\\');
  8406.             break;
  8407.         }
  8408.  
  8409.     TO_TEMP(*buf++);
  8410.     }
  8411.  
  8412. TO_TEMP('\0');
  8413. return temp0; // Return the beginning of the output buffer.
  8414. }
  8415.  
  8416. @ Just before the index comes a list of all the changed modules, including
  8417. the index module itself.
  8418.  
  8419. @<Global...@>=
  8420.  
  8421. EXTERN sixteen_bits k_module; /* Runs through the modules */
  8422.  
  8423. @<Tell about changed modules@>= 
  8424.     {
  8425.   /* Remember that the index is already marked as changed */
  8426.       k_module=0;
  8427.  
  8428.       while (!chngd_module[++k_module]);
  8429.  
  8430.       OUT_STR("\\Wch ");
  8431. @.\\Wch@>
  8432.       out_mod(k_module,ENCAP);
  8433.  
  8434.       while (k_module < module_count)
  8435.         {
  8436.             while (!chngd_module[++k_module]); /* Skip over
  8437. unchanged modules. */
  8438.  
  8439.             OUT_STR(", "); out_mod(k_module,ENCAP);
  8440.           }
  8441.  
  8442.   out(@'.');
  8443. }
  8444.  
  8445. @ A left-to-right radix sorting method is used, since this makes it easy to
  8446. adjust the collating sequence and since the running time will be at worst
  8447. proportional to the total length of all entries in the index. We put the
  8448. identifiers into different lists based on their first characters.
  8449. (Uppercase letters are put into the same list as the corresponding
  8450. lowercase letters, since we want to have `$t<\\{TeX}<\&{to}$'.) The list
  8451. for character~|c| begins at location |bucket[c]| and continues through the
  8452. |blink| array.
  8453.  
  8454. @<Global...@>=
  8455.  
  8456. EXTERN name_pointer bucket[128]; // One for each standard |ASCII char|.
  8457. EXTERN name_pointer next_name; /* Successor of |cur_name| when sorting */
  8458. IN_COMMON hash_pointer h; /* Index into |hash| */
  8459.  
  8460. IN_COMMON BUF_SIZE max_names; /* number of identifiers, strings, module names;
  8461.   must be less than~10240 */
  8462. EXTERN name_pointer HUGE *blink; /* Links in the buckets */
  8463. EXTERN ASCII last_letter SET('\0'); /* Used for separating groups in the
  8464.                     index. */ 
  8465.  
  8466. @
  8467. @<Alloc...@>=
  8468.  
  8469. ALLOC(name_pointer,blink,ABBREV(max_names),max_names,0);
  8470.  
  8471. @ To begin the sorting, we go through all the hash lists and put each entry
  8472. having a nonempty cross-reference list into the proper bucket.
  8473.  
  8474. @<Do the first pass of sorting@>= 
  8475. @{
  8476. int c;
  8477.  
  8478. @b
  8479. for (c=0; c<=127; c++) bucket[c]=NULL;
  8480.  
  8481. for (h=hash; h<=hash_end; h++) 
  8482.     {
  8483.       next_name=*h;
  8484.  
  8485.       while (next_name) 
  8486.         {
  8487.             cur_name=next_name; next_name=cur_name->link;
  8488.  
  8489.             if ((xref_pointer)cur_name->xref != xmem) 
  8490.             {
  8491.                   c=(cur_name->byte_start)[0];
  8492.  
  8493.                 c = A_TO_LOWER(c);
  8494.  
  8495.                   blink[cur_name-name_dir]=bucket[c];
  8496.                 bucket[c]=cur_name; 
  8497.              }
  8498.         }
  8499.     }
  8500. }
  8501.  
  8502. @ During the sorting phase we shall use the |cat| and |trans| arrays from
  8503. \.{WEAVE}'s parsing algorithm and rename them |depth| and |head|. They now
  8504. represent a stack of identifier lists for all the index entries that have
  8505. not yet been output. The variable |sort_ptr| tells how many such lists are
  8506. present; the lists are output in reverse order (first |sort_ptr|, then
  8507. |sort_ptr-1|, etc.). The |j|th list starts at |head[j]|, and if the first
  8508. |k| characters of all entries on this list are known to be equal we have
  8509. |depth[j]=k|.
  8510.  
  8511. @<Rest of |trans_plus| union@>=
  8512.  
  8513. name_pointer Head;
  8514.  
  8515. @
  8516. @f sort_pointer scrap_pointer
  8517.  
  8518. @d depth cat /* reclaims memory that is no longer needed for parsing */
  8519. @d head trans_plus.Head /* ditto */
  8520. @d sort_pointer scrap_pointer /* ditto */
  8521. @d sort_ptr scrp_ptr /* ditto */
  8522. @d max_sorts max_scraps /* ditto */
  8523.  
  8524. @<Global...@>=
  8525.  
  8526. EXTERN eight_bits cur_depth; /* Depth of current buckets */
  8527. EXTERN ASCII HUGE *cur_byte; /* Index into |byte_mem| */
  8528. EXTERN sixteen_bits cur_val; /* Current cross-reference number */
  8529.  
  8530. EXTERN sort_pointer mx_sort_ptr; /* largest value of |sort_ptr| */
  8531.  
  8532. @<Set init...@>=
  8533.  
  8534. mx_sort_ptr=scrp_info;
  8535.  
  8536.  
  8537. @ The desired alphabetic order is specified by the |collate| array; namely,
  8538. |collate[0]==0 <collate[1]<@t$\cdots$@><collate[max_collate]|.  The collate
  8539. array can be set by the style file entry \.{collate}.
  8540.  
  8541. @<Global...@>=
  8542.  
  8543. EXTERN ASCII collate[128]; // collation order.
  8544. EXTERN int max_collate; // Last index in |collate|.  
  8545.  
  8546. @ We use the order $\hbox{null}<\.\ <\hbox{other characters}<\.\_<
  8547. \.A=\.a<\cdots<\.Z=\.z<\.0<\cdots<\.9.$
  8548.  
  8549. @<Set init...@>=
  8550.  
  8551. collate[0] = 0; 
  8552.  
  8553. @ Procedure |unbucket| goes through the buckets and adds nonempty lists to
  8554. the stack, using the collating sequence specified in the |collate| array.
  8555. The parameter to |unbucket| tells the current depth in the buckets.  Any
  8556. two sequences that agree in their first 255 character positions are
  8557. regarded as identical.
  8558.  
  8559. @d INFTY 255 // $\infty$ (approximately).
  8560.  
  8561. @<Part 3@>=@[
  8562.  
  8563. SRTN unbucket FCN((d)) /* Empties buckets having depth |d| */
  8564.     eight_bits d C1("")@;
  8565. {
  8566. int c;  /* Index into |bucket|. {\it Must be |int|.} */
  8567.  
  8568.   for (c=max_collate; c>= 0; c--) if (bucket[collate[c]]) {
  8569.     if (sort_ptr>=scrp_end) OVERFLW("sort levels",ABBREV(max_scraps));
  8570.  
  8571.     sort_ptr++;
  8572.  
  8573.     if (sort_ptr>mx_sort_ptr) mx_sort_ptr = sort_ptr;
  8574.  
  8575.    sort_ptr->depth = (eight_bits)(c==0 ? INFTY : d);
  8576.     sort_ptr->head = bucket[collate[c]]; 
  8577.     bucket[collate[c]] = NULL;
  8578.   }
  8579. }
  8580.  
  8581. @<Sort and output the index@>=
  8582.  
  8583. w_style.indx.collate = x__to_ASCII((outer_char *)w_style.indx.collate);
  8584. max_collate = STRLEN(w_style.indx.collate);
  8585. STRNCPY(collate+1,w_style.indx.collate,max_collate);
  8586.  
  8587. sort_ptr=scrp_info; unbucket(1);
  8588.  
  8589. while (sort_ptr>scrp_info) 
  8590.     {
  8591.       cur_depth=sort_ptr->depth;
  8592.  
  8593.       if (blink[sort_ptr->head-name_dir]==0 || cur_depth==INFTY)
  8594.             @<Output index entries for the list at |sort_ptr|@>@;
  8595.       else @<Split the list at |sort_ptr| into further lists@>;
  8596.     }
  8597.  
  8598. @<Split the list...@>= 
  8599. @{
  8600.   ASCII c;
  8601.  
  8602. @b
  8603.   next_name=sort_ptr->head;
  8604.  
  8605.   do 
  8606.     {
  8607.     cur_name=next_name; next_name=blink[cur_name-name_dir];
  8608.     cur_byte=cur_name->byte_start+cur_depth;
  8609.  
  8610.     if (cur_byte==(cur_name+1)->byte_start) c=0; /* hit end of the name */
  8611.     else 
  8612.     {
  8613.          c = *cur_byte;
  8614.     c = A_TO_LOWER(c);
  8615.      }
  8616.  
  8617.     blink[PTR_DIFF(size_t,cur_name,name_dir)]=bucket[c]; 
  8618.     bucket[c]=cur_name;
  8619.       } 
  8620. while (next_name);
  8621.  
  8622.   --sort_ptr; unbucket((eight_bits)(cur_depth+(eight_bits)1));
  8623. }
  8624.  
  8625. @<Output index...@>= 
  8626. {
  8627. cur_name = sort_ptr->head;
  8628.  
  8629. @<Separate the groups if necessary@>@;
  8630.  
  8631.   do 
  8632.     {
  8633.     if(cur_name->defined_type(language) < 0x80)
  8634.         { /* Write index entry for one identifier. */
  8635.         OUT_STR(w_style.indx.item_0);
  8636. @.\\:@>
  8637.         @<Output the name at |cur_name|@>;
  8638.         @<Output the cross-references at |cur_name|@>;
  8639.         }
  8640.  
  8641.     cur_name = blink[cur_name-name_dir];
  8642.     } 
  8643. while (cur_name);
  8644.  
  8645. --sort_ptr;
  8646. }
  8647.  
  8648. @ Here we insert an optional macro between the different groups.
  8649.  
  8650. @d NON_TEX_MACRO '\1'
  8651.  
  8652. @<Separate the groups...@>=
  8653. {
  8654. ASCII letter = *cur_name->byte_start; 
  8655.  
  8656. /* In some special cases in \Cpp, the identifier may be a \TeX\ macro
  8657. beginning with~'\.\\' at this point. We must then take special precautions.
  8658. In particular, we assign a non-null, non-printable value to |letter|. */
  8659. if(letter == @'\\' && cur_name->ilk==normal && language!=TEX) 
  8660.     letter = NON_TEX_MACRO; 
  8661. else letter = A_TO_LOWER(letter);
  8662.  
  8663. if(letter != last_letter)
  8664.     {
  8665.     if(last_letter)    OUT_STR(w_style.indx.group_skip); /* Separate groups,
  8666. but not for the very first one. */
  8667.  
  8668.     if(w_style.indx.lethead_flag && letter != NON_TEX_MACRO) 
  8669.         {
  8670.         OUT_STR(w_style.indx.lethead_prefix);
  8671.  
  8672.         switch(letter)
  8673.             {
  8674.             @<Special string cases@>: out(@'\\');
  8675.             }
  8676.         out((w_style.indx.lethead_flag > 0 ? A_TO_UPPER(letter) :
  8677. A_TO_LOWER(letter)));
  8678.  
  8679.         OUT_STR(w_style.indx.lethead_suffix);
  8680.         }
  8681.     }
  8682.  
  8683. last_letter = letter;
  8684. }
  8685.  
  8686. @<Output the name...@>=
  8687. @{
  8688. boolean output_type;
  8689. boolean all_uc = cur_name->info.upper_case;
  8690.  
  8691. @b
  8692. switch (cur_name->ilk) 
  8693.     {
  8694.   case normal: 
  8695.     output_type = IDENTIFIER;
  8696.  
  8697.     if(is_intrinsic(cur_name)) 
  8698.         OUT_STR(pfmt->intrinsic);
  8699.         // E.g., |sqrt|.
  8700.     else if(is_keyword(cur_name)) 
  8701.         OUT_STR(ALL_UC ? pfmt->KEYWORD : pfmt->keyword);
  8702.         // E.g., |@r BLOCKSIZE|.
  8703.     else 
  8704.         if(language==TEX) 
  8705.             OUT_STR(pfmt->typewritr); 
  8706.             // E.g., \.{\\hfill}.
  8707.         else if (length(cur_name)==1) 
  8708.             OUT_STR(pfmt->short_id); // E.g., |a|.
  8709.         else 
  8710.             @<Output the appropriate identifier prefix@>@;
  8711.      break;
  8712. @.\\\AT!@>
  8713. @.\\|@>
  8714. @.\\\\@>
  8715.   case roman: output_type = INDEX_ENTRY; @~ break;
  8716.   case wildcard: OUT_STR(pfmt->wildcrd); @~ output_type = INDEX_ENTRY; @~ break;
  8717. @.\\9@>
  8718.   case typewriter: OUT_STR(pfmt->typewritr); 
  8719.     output_type = INDEX_ENTRY; @~ break;
  8720. @.\\.@>
  8721.   default: 
  8722.     OUT_STR(ALL_UC ? pfmt->RESERVED : pfmt->reserved); 
  8723.     output_type = IDENTIFIER; @~ break; // E.g., |int|.
  8724. @.\\\&@>
  8725.     }
  8726.  
  8727. out_name(output_type,cur_name);
  8728. }
  8729.  
  8730. @ Section numbers that are to be underlined are enclosed in
  8731. `\.{\\[}$\,\ldots\,$\.]'.
  8732.  
  8733. @d ENCAP YES
  8734. @d NO_ENCAP NO
  8735.  
  8736. @<Output the cross-references...@>=
  8737.  
  8738. @<Invert the cross-reference list at |cur_name|, making |cur_xref| the head@>;
  8739.  
  8740. OUT_STR(w_style.indx.delim_0); /* Immediately after identifier. */
  8741.  
  8742. WHILE()
  8743.     {
  8744.     cur_val=cur_xref->num;
  8745.  
  8746.       if (cur_val<def_flag) out_mod(cur_val,ENCAP);
  8747.       else 
  8748.         {
  8749.         OUT_STR(w_style.indx.underline_prefix); 
  8750.         out_mod(cur_val-def_flag,ENCAP);
  8751.         OUT_STR(w_style.indx.underline_suffix);
  8752.         }
  8753. @.\\[@>
  8754.  
  8755. /* If the language of this module isn't the global language, mark it in the
  8756. |w_style|. */
  8757.     if((LANGUAGE)cur_xref->Language != global_language)
  8758.         {
  8759.         char temp[50];
  8760.  
  8761.         sprintf(temp,"%s%s%s",
  8762.             (char *)w_style.indx.language_prefix,
  8763.             (char *)language_symbol((LANGUAGE)cur_xref->Language),
  8764.             (char *)w_style.indx.language_suffix); 
  8765.         OUT_STR(temp);
  8766.         }
  8767.  
  8768.     cur_xref=cur_xref->xlink;
  8769.  
  8770.     if(cur_xref == xmem) break;
  8771.     OUT_STR(w_style.indx.delim_n); /* Between identifiers. */
  8772.     } 
  8773.  
  8774. out(@'.'); @~ fin_line();
  8775.  
  8776. @ List inversion is best thought of as popping elements off one stack and
  8777. pushing them onto another. In this case |cur_xref| will be the head of
  8778. the stack that we push things onto.
  8779.  
  8780. @<Invert the cross-reference list at |cur_name|, making |cur_xref| the head@>=
  8781.  
  8782. this_xref = (xref_pointer)cur_name->xref; cur_xref=xmem;
  8783.  
  8784. do 
  8785.     {
  8786.       next_xref=this_xref->xlink; this_xref->xlink=cur_xref;
  8787.       cur_xref=this_xref; this_xref=next_xref;
  8788.     } 
  8789. while (this_xref!=xmem);
  8790.  
  8791. @ The following recursive procedure walks through the tree of module names and
  8792. prints them.
  8793. @^recursion@>
  8794.  
  8795. @<Part 3@>=@[
  8796.  
  8797. SRTN mod_print FCN((p)) /* Print all module names in subtree |p|. */
  8798.     name_pointer p C1("")@;
  8799. {
  8800.   if (p) 
  8801.     {
  8802.     mod_print(p->llink); OUT_STR("\\:");
  8803. @.\\:@>
  8804.     tok_ptr=tok_mem+1; text_ptr=tok_start+1; scrp_ptr=scrp_info; ini_stack;
  8805.     APP_FLAG(mod,p,name_dir);
  8806.     make_output();
  8807.     footnote(0); /* |cur_xref| was set by |make_output| */
  8808.     fin_line();
  8809.  
  8810.     mod_print(p->rlink);
  8811.       }
  8812. }
  8813.  
  8814. @
  8815. @<Output the index@>=
  8816. {
  8817. writing(YES,temp_ndx);
  8818. if(tex_file == stdout) puts("");
  8819. NEW_TeX(temp_ndx);
  8820.  
  8821. if (change_exists) 
  8822.     {
  8823.     @<Tell about changed modules@>;
  8824.     fin_line(); 
  8825.     fin_line(); 
  8826.     }
  8827.  
  8828. OUT_STR(w_style.indx.preamble); @~ fin_line();
  8829. @.\\Winx@>
  8830.  
  8831. @<Do the first pass of sorting@>;
  8832. @<Sort and output the index@>;
  8833.  
  8834. OUT_STR(w_style.indx.postamble); @~ fin_line();
  8835. @.\\Wfin@>
  8836. }
  8837.  
  8838. @<Output all the module names@>=
  8839. {
  8840. writing(BOOLEAN(!prn_index),temp_mds);
  8841. NEW_TeX(temp_mds);
  8842.  
  8843. OUT_STR(w_style.modules.preamble); @~ fin_line();
  8844. @.\\Wmods@>
  8845.  
  8846. mod_print(root);
  8847.  
  8848. OUT_STR(w_style.modules.postamble); @~ fin_line();
  8849. }
  8850.  
  8851. @ Statistics are printed when the command-line option~\.{-s} is used.
  8852.  
  8853. @<Part 3@>=@[
  8854.  
  8855. SRTN see_wstatistics(VOID)
  8856. {
  8857. CLR_PRINTF(info,("\n\nMEMORY USAGE STATISTICS:\n"));
  8858.  
  8859. STAT0("names",sizeof(*name_ptr),
  8860.     SUB_PTRS(name_ptr,name_dir),max_names,UPPER(max_names),",");
  8861.  
  8862. STAT0("cross-references",sizeof(*xref_ptr),
  8863.     SUB_PTRS(xref_ptr,xmem),max_refs,UPPER(max_refs),",");
  8864.  
  8865. STAT0("bytes",sizeof(*byte_ptr),
  8866.     SUB_PTRS(byte_ptr,byte_mem),max_bytes,UPPER(max_bytes),";");
  8867.  
  8868. CLR_PRINTF(info,(" parsing required\n"));
  8869.  
  8870. STAT0("scraps",sizeof(*mx_scr_ptr),
  8871.     SUB_PTRS(mx_scr_ptr,scrp_base),max_scraps,UPPER(max_scraps),",");
  8872.  
  8873. STAT0("texts",sizeof(*mx_text_ptr),
  8874.     SUB_PTRS(mx_text_ptr,tok_start),max_texts,UPPER(max_texts),",");
  8875.  
  8876. STAT0("tokens",sizeof(*mx_tok_ptr),
  8877.     SUB_PTRS(mx_tok_ptr,tok_mem),max_toks,UPPER(max_toks_w),",");
  8878.  
  8879. STAT0("stack levels",sizeof(*mx_stck_ptr),
  8880.     SUB_PTRS(mx_stck_ptr,stack),stck_size,UPPER(stck_size_w),";");
  8881.  
  8882. CLR_PRINTF(info,(" sorting required"));
  8883.  
  8884. printf(" %lu level(s).\n",SUB_PTRS(mx_sort_ptr,scrp_info));
  8885.  
  8886. mem_avail(1); /* How much memory left at end of run? */
  8887. }
  8888.  
  8889. @ The following routines are invoked by \.{common.web}, but are  used only by
  8890. \.{TANGLE}. 
  8891. @<Part 3@>=@[
  8892.  
  8893. SRTN predefine_macros(VOID)
  8894. {}
  8895.  
  8896. SRTN open_out(VOID)
  8897. {}
  8898.  
  8899. boolean was_opened FCN((name,global_scope,pname,pptr))
  8900.     CONST outer_char HUGE *name C0("")@;
  8901.     boolean global_scope C0("")@;
  8902.     outer_char HUGE * HUGE *pname C0("")@;
  8903.     FILE **pptr C1("")@;
  8904. {
  8905. *pname = GET_MEM("*pname",STRLEN(name)+1,outer_char);
  8906. STRCPY(*pname,name);
  8907.  
  8908. return NO;
  8909. }
  8910.  
  8911. SRTN ini_tokens FCN((language0))
  8912.     LANGUAGE language0 C1("")@;
  8913. {}
  8914.  
  8915. @* STYLE FILE. The style file is common to \FWEAVE\ and \FTANGLE. See
  8916. \.{style.web}. 
  8917.  
  8918. @<Include...@>=
  8919.  
  8920. #include "map.h" // Relations between style file keywords and internal arrays.
  8921.  
  8922. @* INDEX.  If you have read and understood the code for Phase~III above,
  8923. you know what is in this index and how it got here. All modules in which an
  8924. identifier is used are listed with that identifier, except that reserved
  8925. words are indexed only when they appear in format definitions, and the
  8926. appearances of identifiers in module names are not indexed. Underlined
  8927. entries correspond to where the identifier was declared. Error messages,
  8928. control sequences put into the output, and a few other things like
  8929. ``recursion'' are indexed here too.
  8930.