home *** CD-ROM | disk | FTP | other *** search
/ Dream 57 / Amiga_Dream_57.iso / Amiga / Programmation / c / Docs / cwebbin-p13.lha / cwebbin-p13 / cweav-p13.ch < prev    next >
Encoding:
Text File  |  1995-09-20  |  37.8 KB  |  1,641 lines

  1. @x
  2. \def\title{CWEAVE (Version 3.4)}
  3. @y
  4. \def\title{CWEAVE (Version 3.4 [p13])}
  5. @z
  6.  
  7. @x
  8.   \centerline{(Version 3.4)}
  9. @y
  10.   \centerline{(Version 3.4 [p13])}
  11. @z
  12.  
  13. @x
  14. @d banner "This is CWEAVE (Version 3.4)\n"
  15. @y
  16. @d banner get_string(MSG_BANNER_CW1)
  17. @z
  18.  
  19. @x
  20. @ We predeclare several standard system functions here instead of including
  21. their system header files, because the names of the header files are not as
  22. standard as the names of the functions. (For example, some \CEE/ environments
  23. have \.{<string.h>} where others have \.{<strings.h>}.)
  24.  
  25. @<Predecl...@>=
  26. extern int strlen(); /* length of string */
  27. extern int strcmp(); /* compare strings lexicographically */
  28. extern char* strcpy(); /* copy one string to another */
  29. extern int strncmp(); /* compare up to $n$ string characters */
  30. extern char* strncpy(); /* copy up to $n$ string characters */
  31. @y
  32. @ For string handling we include the {\mc ANSI C} system header file instead
  33. of predeclaring the standard system functions |strlen|, |strcmp|, |strcpy|,
  34. |strncmp|, and |strncpy|.
  35. @^system dependencies@>
  36.  
  37. @<Include files@>=
  38. #include <string.h>
  39. @z
  40.  
  41. @x
  42. int main (ac, av)
  43. int ac; /* argument count */
  44. char **av; /* argument values */
  45. @y
  46. int main (int ac, char **av)
  47. /* argument count and argument values */
  48. @z
  49.  
  50. @x
  51. @i common.h
  52. @y
  53. @i comm-p13.h
  54. @z
  55.  
  56. @x
  57. typedef struct xref_info {
  58.   sixteen_bits num; /* section number plus zero or |def_flag| */
  59.   struct xref_info *xlink; /* pointer to the previous cross-reference */
  60. } xref_info;
  61. typedef xref_info *xref_pointer;
  62. @y
  63. typedef struct xref_info {
  64.   sixteen_bits num; /* section number plus zero or |def_flag| */
  65.   struct xref_info HUGE *xlink; /* pointer to the previous cross-reference */
  66. } xref_info;
  67. typedef xref_info HUGE *xref_pointer;
  68. @z
  69.  
  70. @x
  71. xref_info xmem[max_refs]; /* contains cross-reference information */
  72. xref_pointer xmem_end = xmem+max_refs-1;
  73. @y
  74. xref_pointer xmem; /* contains cross-reference information */
  75. xref_pointer xmem_end;
  76. @z
  77.  
  78. @x
  79. xref_ptr=xmem; name_dir->xref=(char*)xmem; xref_switch=0; section_xref_switch=0;
  80. @y
  81. alloc_object(section_text,longest_name+1,char);
  82. section_text_end = section_text + longest_name;
  83. #ifdef __TURBOC__
  84. xmem=(xref_pointer)allocsafe(max_refs,sizeof(*xmem));
  85. #else
  86. alloc_object(xmem,max_refs,xref_info);
  87. #endif
  88. xmem_end = xmem + max_refs - 1;
  89. xref_ptr=xmem; name_dir->xref=(void HUGE*)xmem;
  90. xref_switch=0; section_xref_switch=0;
  91. @z
  92.  
  93. @x
  94. @d append_xref(c) if (xref_ptr==xmem_end) overflow("cross-reference");
  95. @y
  96. @d append_xref(c) if (xref_ptr==xmem_end) overflow(get_string(MSG_OVERFLOW_CW21));
  97. @z
  98.  
  99. @x
  100. void
  101. new_xref(p)
  102. name_pointer p;
  103. @y
  104. static void new_xref(name_pointer p)
  105. @z
  106.  
  107. @x
  108.   append_xref(m); xref_ptr->xlink=q; p->xref=(char*)xref_ptr;
  109. @y
  110.   append_xref(m); xref_ptr->xlink=q; p->xref=(void HUGE*)xref_ptr;
  111. @z
  112.  
  113. @x
  114. void
  115. new_section_xref(p)
  116. name_pointer p;
  117. @y
  118. static void new_section_xref(name_pointer p)
  119. @z
  120.  
  121. @x
  122.   if (r==xmem) p->xref=(char*)xref_ptr;
  123. @y
  124.   if (r==xmem) p->xref=(void HUGE*)xref_ptr;
  125. @z
  126.  
  127. @x
  128. void
  129. set_file_flag(p)
  130. name_pointer p;
  131. @y
  132. static void set_file_flag(name_pointer p)
  133. @z
  134.  
  135. @x
  136.   p->xref = (char *)xref_ptr;
  137. @y
  138.   p->xref = (void HUGE*)xref_ptr;
  139. @z
  140.  
  141. @x
  142. typedef token *token_pointer;
  143. typedef token_pointer *text_pointer;
  144. @y
  145. typedef token HUGE *token_pointer;
  146. typedef token_pointer HUGE *text_pointer;
  147. @z
  148.  
  149. @x
  150. token tok_mem[max_toks]; /* tokens */
  151. token_pointer tok_mem_end = tok_mem+max_toks-1; /* end of |tok_mem| */
  152. token_pointer tok_start[max_texts]; /* directory into |tok_mem| */
  153. token_pointer tok_ptr; /* first unused position in |tok_mem| */
  154. text_pointer text_ptr; /* first unused position in |tok_start| */
  155. text_pointer tok_start_end = tok_start+max_texts-1; /* end of |tok_start| */
  156. @y
  157. token_pointer tok_mem; /* tokens */
  158. token_pointer tok_mem_end; /* end of |tok_mem| */
  159. token_pointer tok_ptr; /* first unused position in |tok_mem| */
  160. text_pointer tok_start; /* directory into |tok_mem| */
  161. text_pointer tok_start_end; /* end of |tok_start| */
  162. text_pointer text_ptr; /* first unused position in |tok_start| */
  163. @z
  164.  
  165. @x
  166. tok_ptr=tok_mem+1; text_ptr=tok_start+1; tok_start[0]=tok_mem+1;
  167. @y
  168. #ifdef __TURBOC__
  169. tok_mem=(token_pointer)allocsafe(max_toks,sizeof(*tok_mem));
  170. #else
  171. alloc_object(tok_mem,max_toks,token);
  172. #endif
  173. @^system dependencies@>
  174. tok_mem_end = tok_mem + max_toks - 1;
  175. alloc_object(tok_start,max_texts,token_pointer);
  176. tok_start_end = tok_start + max_texts - 1;
  177. tok_ptr=tok_mem+1; text_ptr=tok_start+1; tok_start[0]=tok_mem+1;
  178. @z
  179.  
  180. @x
  181. int names_match(p,first,l,t)
  182. name_pointer p; /* points to the proposed match */
  183. char *first; /* position of first character of string */
  184. int l; /* length of identifier */
  185. eight_bits t; /* desired ilk */
  186. @y
  187. int names_match(@t\1\1@>
  188.   name_pointer p, /* points to the proposed match */
  189.   char *first, /* position of first character of string */
  190.   int l, /* length of identifier */
  191.   eight_bits t@t\2\2@>) /* desired |ilk| */
  192. @z
  193.  
  194. @x
  195. void
  196. init_p(p,t)
  197. name_pointer p;
  198. eight_bits t;
  199. @y
  200. void init_p(name_pointer p,eight_bits t)
  201. @z
  202.  
  203. @x
  204.   p->ilk=t; p->xref=(char*)xmem;
  205. @y
  206.   p->ilk=t; p->xref=(void HUGE*)xmem;
  207. @z
  208.  
  209. @x
  210. void
  211. init_node(p)
  212. name_pointer p;
  213. @y
  214. void init_node(name_pointer p)
  215. @z
  216.  
  217. @x
  218.   p->xref=(char*)xmem;
  219. @y
  220.   p->xref=(void HUGE*)xmem;
  221. @z
  222.  
  223. @x
  224. eight_bits ccode[256]; /* meaning of a char following \.{@@} */
  225.  
  226. @ @<Set ini...@>=
  227. {int c; for (c=0; c<256; c++) ccode[c]=0;}
  228. @y
  229. eight_bits *ccode; /* meaning of a char following \.{@@} */
  230.  
  231. @ @<Set ini...@>=
  232. {int c;
  233. alloc_object(ccode,256,eight_bits);
  234. for (c=0; c<256; c++) ccode[c]=0;}
  235. @z
  236.  
  237. @x
  238. void   skip_limbo();
  239. @y
  240. static void skip_limbo(void);
  241. @z
  242.  
  243. @x
  244. void
  245. skip_limbo() {
  246. @y
  247. static void skip_limbo(void) {
  248. @z
  249.  
  250. @x
  251. unsigned
  252. skip_TeX() /* skip past pure \TEX/ code */
  253. @y
  254. static unsigned skip_TeX(void) /* skip past pure \TEX/ code */
  255. @z
  256.  
  257. @x
  258. #include <stdlib.h> /* definition of |exit| */
  259. @y
  260. #include <stddef.h> /* type definition of |ptrdiff_t| */
  261. #include <stdlib.h> /* definition of |exit| */
  262. @z
  263.  
  264. @x
  265. eight_bits get_next();
  266. @y
  267. static eight_bits get_next(void);
  268. @z
  269.  
  270. @x
  271. eight_bits
  272. get_next() /* produces the next input token */
  273. {@+eight_bits c; /* the current character */
  274. @y
  275. static eight_bits get_next(void) /* produces the next input token */
  276. {
  277.   eight_bits c; /* the current character */
  278. @z
  279.  
  280. @x
  281.         err_print("! String didn't end"); loc=limit; break;
  282. @y
  283.         err_print(get_string(MSG_ERROR_CT67_1)); loc=limit; break;
  284. @z
  285.  
  286. @x
  287.         err_print("! Input ended in middle of string"); loc=buffer; break;
  288. @y
  289.         err_print(get_string(MSG_ERROR_CT67_2)); loc=buffer; break;
  290. @z
  291.  
  292. @x
  293.     printf("\n! String too long: ");
  294. @y
  295.     printf(get_string(MSG_ERROR_CT67_3));
  296. @z
  297.  
  298. @x
  299.     case translit_code: err_print("! Use @@l in limbo only"); continue;
  300. @y
  301.     case translit_code: err_print(get_string(MSG_ERROR_CT68_1)); continue;
  302. @z
  303.  
  304. @x
  305.     err_print("! Input ended in section name");
  306. @y
  307.     err_print(get_string(MSG_ERROR_CT72_1));
  308. @z
  309.  
  310. @x
  311.   printf("\n! Section name too long: ");
  312. @y
  313.   printf(get_string(MSG_ERROR_CT72_2));
  314. @z
  315.  
  316. @x
  317.     err_print("! Section name didn't end"); break;
  318. @y
  319.     err_print(get_string(MSG_ERROR_CT73_1)); break;
  320. @z
  321.  
  322. @x
  323.     err_print("! Control codes are forbidden in section name"); break;
  324. @y
  325.     err_print(get_string(MSG_ERROR_CW54)); break;
  326. @z
  327.  
  328. @x
  329. void skip_restricted();
  330. @y
  331. void skip_restricted(void);
  332. @z
  333.  
  334. @x
  335. void
  336. skip_restricted()
  337. @y
  338. void skip_restricted(void)
  339. @z
  340.  
  341. @x
  342.     err_print("! Control text didn't end"); loc=limit;
  343. @y
  344.     err_print(get_string(MSG_ERROR_CW56_1)); loc=limit;
  345. @z
  346.  
  347. @x
  348.       err_print("! Control codes are forbidden in control text");
  349. @y
  350.       err_print(get_string(MSG_ERROR_CW56_2));
  351. @z
  352.  
  353. @x
  354.   if (loc>=limit) err_print("! Verbatim string didn't end");
  355. @y
  356.   if (loc>=limit) err_print(get_string(MSG_ERROR_CT74));
  357. @z
  358.  
  359. @x
  360. void phase_one();
  361. @y
  362. static void phase_one(void);
  363. @z
  364.  
  365. @x
  366. void
  367. phase_one() {
  368. @y
  369. static void phase_one(void) {
  370. @z
  371.  
  372. @x
  373.   if (++section_count==max_sections) overflow("section number");
  374. @y
  375.   if (++section_count==max_sections) overflow(get_string(MSG_OVERFLOW_CW61));
  376. @z
  377.  
  378. @x
  379. void C_xref();
  380. @y
  381. static void C_xref(eight_bits);
  382. @z
  383.  
  384. @x
  385. void
  386. C_xref( spec_ctrl ) /* makes cross-references for \CEE/ identifiers */
  387.   eight_bits spec_ctrl;
  388. @y
  389. static void C_xref( eight_bits spec_ctrl )
  390.    /* makes cross-references for \CEE/ identifiers */
  391. @z
  392.  
  393. @x
  394. void outer_xref();
  395. @y
  396. static void outer_xref(void);
  397. @z
  398.  
  399. @x
  400. void
  401. outer_xref() /* extension of |C_xref| */
  402. @y
  403. static void outer_xref(void) /* extension of |C_xref| */
  404. @z
  405.  
  406. @x
  407.     case translit_code: err_print("! Use @@l in limbo only"); continue;
  408. @y
  409.     case translit_code: err_print(get_string(MSG_ERROR_CT68_1)); continue;
  410. @z
  411.  
  412. @x
  413.             else lhs->xref=(char*)q->xlink;
  414. @y
  415.             else lhs->xref=(void HUGE*)q->xlink;
  416. @z
  417.  
  418. @x
  419.     err_print("! Missing left identifier of @@s");
  420. @y
  421.     err_print(get_string(MSG_ERROR_CW71_1));
  422. @z
  423.  
  424. @x
  425.       err_print("! Missing right identifier of @@s");
  426. @y
  427.       err_print(get_string(MSG_ERROR_CW71_2));
  428. @z
  429.  
  430. @x
  431. void section_check();
  432. @y
  433. static void section_check(name_pointer);
  434. @z
  435.  
  436. @x
  437. void
  438. section_check(p)
  439. name_pointer p; /* print anomalies in subtree |p| */
  440. @y
  441. static void section_check(name_pointer p)
  442.    /* print anomalies in subtree |p| */
  443. @z
  444.  
  445. @x
  446.       printf("\n! Never defined: <"); print_section_name(p); putchar('>'); mark_harmless;
  447. @y
  448.       printf(get_string(MSG_WARNING_CW75_1));
  449.       print_section_name(p); putchar('>'); mark_harmless;
  450. @z
  451.  
  452. @x
  453.       printf("\n! Never used: <"); print_section_name(p); putchar('>'); mark_harmless;
  454. @y
  455.       printf(get_string(MSG_WARNING_CW75_2));
  456.       print_section_name(p); putchar('>'); mark_harmless;
  457. @z
  458.  
  459. @x
  460. char out_buf[line_length+1]; /* assembled characters */
  461. char *out_ptr; /* just after last character in |out_buf| */
  462. char *out_buf_end = out_buf+line_length; /* end of |out_buf| */
  463. @y
  464. char *out_buf; /* assembled characters */
  465. char *out_buf_end; /* end of |out_buf| */
  466. char *out_ptr; /* just after last character in |out_buf| */
  467. @z
  468.  
  469. @x
  470. void
  471. flush_buffer(b,per_cent,carryover)
  472. char *b;  /* outputs from |out_buf+1| to |b|,where |b<=out_ptr| */
  473. boolean per_cent,carryover;
  474. @y
  475. static void flush_buffer(char *b,boolean per_cent,boolean carryover)
  476.    /* outputs from |out_buf+1| to |b|, where |b<=out_ptr| */
  477. @z
  478.  
  479. @x
  480.   if (b<out_ptr) strncpy(out_buf+1,b+1,out_ptr-b);
  481. @y
  482.   if (b<out_ptr) strncpy(out_buf+1,b+1,(size_t)(out_ptr-b));
  483. @z
  484.  
  485. @x
  486. void
  487. finish_line() /* do this at the end of a line */
  488. @y
  489. static void finish_line(void) /* do this at the end of a line */
  490. @z
  491.  
  492. @x
  493. @ In particular, the |finish_line| procedure is called near the very
  494. beginning of phase two. We initialize the output variables in a slightly
  495. tricky way so that the first line of the output file will be
  496. `\.{\\input cwebmac}'.
  497.  
  498. @<Set init...@>=
  499. out_ptr=out_buf+1; out_line=1; active_file=tex_file;
  500. *out_ptr='c'; tex_printf("\\input cwebma");
  501. @y
  502. @ In particular, the |finish_line| procedure is called near the very
  503. beginning of phase two. We initialize the output variables in a slightly
  504. tricky way so that the first line of the output file will be dependent of
  505. the user language set by the `\.{+l}' option and its argument.  If you call
  506. \.{CWEAVE} with `\.{+lX}' (or `\.{-lX} as well), where `\.X' is the
  507. (possibly empty) string of characters to the right of~`\.l', `\.X'~will be
  508. prepended to `\.{cwebmac.tex}', e.g., if you call \.{CWEAVE} with
  509. `\.{+ldeutsch}', you will receive the line `\.{\\input deutschcwebmac}'.
  510.  
  511. @<Set init...@>=
  512. alloc_object(out_buf,line_length+1,char);
  513. out_buf_end = out_buf + line_length;
  514. out_ptr=out_buf+1; out_line=1; active_file=tex_file; *out_ptr='c';
  515. tex_printf("\\input ");
  516. fprintf(active_file,"%s",use_language);
  517. tex_printf("cwebma");
  518. @z
  519.  
  520. @x
  521. void
  522. out_str(s) /* output characters from |s| to end of string */
  523. char *s;
  524. @y
  525. static void out_str(char*s) /* output characters from |s| to end of string */
  526. @z
  527.  
  528. @x
  529. void break_out();
  530. @y
  531. static void break_out(void);
  532. @z
  533.  
  534. @x
  535. void
  536. break_out() /* finds a way to break the output line */
  537. @y
  538. static void break_out(void) /* finds a way to break the output line */
  539. @z
  540.  
  541. @x
  542.   printf("\n! Line had to be broken (output l. %d):\n",out_line);
  543. @y
  544.   printf(get_string(MSG_WARNING_CW85),out_line);
  545. @z
  546.  
  547. @x
  548. void
  549. out_section(n)
  550. sixteen_bits n;
  551. @y
  552. static void out_section(sixteen_bits n)
  553. @z
  554.  
  555. @x
  556. void
  557. out_name(p)
  558. name_pointer p;
  559. @y
  560. void out_name(name_pointer p)
  561. @z
  562.  
  563. @x
  564.   char *k, *k_end=(p+1)->byte_start; /* pointers into |byte_mem| */
  565. @y
  566.   char HUGE *k;
  567.   char HUGE *k_end=(p+1)->byte_start; /* pointers into |byte_mem| */
  568. @z
  569.  
  570. @x
  571. void
  572. copy_limbo()
  573. @y
  574. static void copy_limbo(void)
  575. @z
  576.  
  577. @x
  578.         default: err_print("! Double @@ should be used in limbo");
  579. @y
  580.         default: err_print(get_string(MSG_ERROR_CT93));
  581. @z
  582.  
  583. @x
  584. eight_bits
  585. copy_TeX()
  586. @y
  587. static eight_bits copy_TeX(void)
  588. @z
  589.  
  590. @x
  591. @d app_tok(c) {if (tok_ptr+2>tok_mem_end) overflow("token"); *(tok_ptr++)=c;}
  592. @y
  593. @d app_tok(c) {if (tok_ptr+2>tok_mem_end)
  594.     overflow(get_string(MSG_OVERFLOW_CT26));
  595.   *(tok_ptr++)=c;}
  596. @z
  597.  
  598. @x
  599. int copy_comment();
  600. @y
  601. static int copy_comment(boolean,int);
  602. @z
  603.  
  604. @x
  605. int copy_comment(is_long_comment,bal) /* copies \TEX/ code in comments */
  606. boolean is_long_comment; /* is this a traditional \CEE/ comment? */
  607. int bal; /* brace balance */
  608. @y
  609. static copy_comment(@t\1\1@> /* copies \TeX\ code in comments */
  610.   boolean is_long_comment, /* is this a traditional \CEE/ comment? */
  611.   int bal@t\2\2@>) /* brace balance */
  612. @z
  613.  
  614. @x
  615.           err_print("! Input ended in mid-comment");
  616. @y
  617.           err_print(get_string(MSG_ERROR_CT60_1));
  618. @z
  619.  
  620. @x
  621.         if (bal>1) err_print("! Missing } in comment");
  622. @y
  623.         if (bal>1) err_print(get_string(MSG_ERROR_CW92_1));
  624. @z
  625.  
  626. @x
  627.       else {err_print("! Extra } in comment");
  628. @y
  629.       else {err_print(get_string(MSG_ERROR_CW92_2));
  630. @z
  631.  
  632. @x
  633.   if (bal>1) err_print("! Missing } in comment");
  634. @y
  635.   if (bal>1) err_print(get_string(MSG_ERROR_CW92_1));
  636. @z
  637.  
  638. @x
  639.     err_print("! Illegal use of @@ in comment");
  640. @y
  641.     err_print(get_string(MSG_ERROR_CW94));
  642. @z
  643.  
  644. @x
  645. char cat_name[256][12];
  646. eight_bits cat_index;
  647.  
  648. @ @<Set in...@>=
  649. @y
  650. char **cat_name;
  651. eight_bits cat_index;
  652.  
  653. @ @<Set in...@>=
  654. alloc_object(cat_name,256,char *);
  655. for(cat_index=0; cat_index<255; cat_index++)
  656.   alloc_object(cat_name[cat_index],12,char);
  657. @z
  658.  
  659. @x
  660. void
  661. print_cat(c) /* symbolic printout of a category */
  662. eight_bits c;
  663. @y
  664. static void print_cat(eight_bits c) /* symbolic printout of a category */
  665. @z
  666.  
  667. @x
  668. scrap scrap_info[max_scraps]; /* memory array for scraps */
  669. scrap_pointer scrap_info_end=scrap_info+max_scraps -1; /* end of |scrap_info| */
  670. @y
  671. scrap_pointer scrap_info; /* memory array for scraps */
  672. scrap_pointer scrap_info_end; /* end of |scrap_info| */
  673. @z
  674.  
  675. @x
  676. scrap_base=scrap_info+1;
  677. max_scr_ptr=scrap_ptr=scrap_info;
  678. @y
  679. alloc_object(scrap_info,max_scraps,scrap);
  680. scrap_info_end = scrap_info + max_scraps - 1;
  681. scrap_base=scrap_info+1;
  682. max_scr_ptr=scrap_ptr=scrap_info;
  683. @z
  684.  
  685. @x
  686. void
  687. print_text(p) /* prints a token list for debugging; not used in |main| */
  688. text_pointer p;
  689. @y
  690. static void print_text(text_pointer p)
  691.    /* prints a token list for debugging; not used in |main| */
  692. @z
  693.  
  694. @x
  695. @d app(a) *(tok_ptr++)=a
  696. @d app1(a) *(tok_ptr++)=tok_flag+(int)((a)->trans-tok_start)
  697. @y
  698. @d app(a) *(tok_ptr++)=(token)(a)
  699. @d app1(a) *(tok_ptr++)=(token)(tok_flag+(int)((a)->trans-tok_start))
  700. @z
  701.  
  702. @x
  703. void
  704. app_str(s)
  705. char *s;
  706. @y
  707. static void app_str(char *s)
  708. @z
  709.  
  710. @x
  711. void
  712. big_app(a)
  713. token a;
  714. @y
  715. static void big_app(token a)
  716. @z
  717.  
  718. @x
  719. void
  720. big_app1(a)
  721. scrap_pointer a;
  722. @y
  723. static void big_app1(scrap_pointer a)
  724. @z
  725.  
  726. @x
  727. token_pointer
  728. find_first_ident(p)
  729. text_pointer p;
  730. @y
  731. static token_pointer find_first_ident(text_pointer p)
  732. @z
  733.  
  734. @x
  735. void
  736. make_reserved(p) /* make the first identifier in |p->trans| like |int| */
  737. scrap_pointer p;
  738. @y
  739. static void make_reserved(scrap_pointer p)
  740. /* make the first identifier in |p->trans| like |int| */
  741. @z
  742.  
  743. @x
  744.   (name_dir+(sixteen_bits)(tok_value%id_flag))->ilk=raw_int;
  745. @y
  746.   (name_dir+(ptrdiff_t)(tok_value%id_flag))->ilk=raw_int;
  747. @z
  748.  
  749. @x
  750. void
  751. make_underlined(p)
  752. /* underline the entry for the first identifier in |p->trans| */
  753. scrap_pointer p;
  754. @y
  755. static void make_underlined(scrap_pointer p)
  756. /* underline the entry for the first identifier in |p->trans| */
  757. @z
  758.  
  759. @x
  760. void  underline_xref();
  761. @y
  762. static void underline_xref(name_pointer);
  763. @z
  764.  
  765. @x
  766. void
  767. underline_xref(p)
  768. name_pointer p;
  769. @y
  770. static void underline_xref(name_pointer p)
  771. @z
  772.  
  773. @x
  774.   p->xref=(char*)xref_ptr;
  775. @y
  776.   p->xref=(void HUGE*)xref_ptr;
  777. @z
  778.  
  779. @x
  780. @<Cases for |exp|@>=
  781. if (cat1==lbrace || cat1==int_like || cat1==decl) {
  782.   make_underlined(pp); big_app1(pp); big_app(indent); app(indent);
  783.   reduce(pp,1,fn_decl,0,1);
  784. }
  785. @y
  786. @<Cases for |exp|@>=
  787. if(cat1==lbrace || cat1==int_like || cat1==decl) {
  788.   make_underlined(pp); big_app1(pp);
  789.   if (indent_param_decl) {
  790.     big_app(indent); app(indent);
  791.   }
  792.   reduce(pp,1,fn_decl,0,1);
  793. }
  794. @z
  795.  
  796. @x
  797. @ @<Cases for |decl_head|@>=
  798. if (cat1==comma) {
  799.   big_app2(pp); big_app(' '); reduce(pp,2,decl_head,-1,33);
  800. }
  801. else if (cat1==unorbinop) {
  802.   big_app1(pp); big_app('{'); big_app1(pp+1); big_app('}');
  803.   reduce(pp,2,decl_head,-1,34);
  804. }
  805. else if (cat1==exp && cat2!=lpar && cat2!=exp) {
  806.   make_underlined(pp+1); squash(pp,2,decl_head,-1,35);
  807. }
  808. else if ((cat1==binop||cat1==colon) && cat2==exp && (cat3==comma ||
  809.     cat3==semi || cat3==rpar))
  810.   squash(pp,3,decl_head,-1,36);
  811. else if (cat1==cast) squash(pp,2,decl_head,-1,37);
  812. else if (cat1==lbrace || (cat1==int_like&&cat2!=colcol) || cat1==decl) {
  813.   big_app1(pp); big_app(indent); app(indent); reduce(pp,1,fn_decl,0,38);
  814. }
  815. else if (cat1==semi) squash(pp,2,decl,-1,39);
  816. @y
  817. @ @<Cases for |decl_head|@>=
  818. if (cat1==comma) {
  819.   big_app2(pp); big_app(' '); reduce(pp,2,decl_head,-1,33);
  820. }
  821. else if (cat1==unorbinop) {
  822.   big_app1(pp); big_app('{'); big_app1(pp+1); big_app('}');
  823.   reduce(pp,2,decl_head,-1,34);
  824. }
  825. else if (cat1==exp && cat2!=lpar && cat2!=exp) {
  826.   make_underlined(pp+1); squash(pp,2,decl_head,-1,35);
  827. }
  828. else if ((cat1==binop||cat1==colon) && cat2==exp && (cat3==comma ||
  829.     cat3==semi || cat3==rpar))
  830.   squash(pp,3,decl_head,-1,36);
  831. else if (cat1==cast) squash(pp,2,decl_head,-1,37);
  832. else if (cat1==lbrace || (cat1==int_like&&cat2!=colcol) || cat1==decl) {
  833.   big_app1(pp);
  834.   if (indent_param_decl) {
  835.     big_app(indent); app(indent);
  836.   }
  837.   reduce(pp,1,fn_decl,0,38);
  838. }
  839. else if (cat1==semi) squash(pp,2,decl,-1,39);
  840. @z
  841.  
  842. @x
  843. else if (cat1==stmt || cat1==function) {
  844.   big_app1(pp); big_app(big_force);
  845.   big_app1(pp+1); reduce(pp,2,cat1,-1,41);
  846. }
  847. @y
  848. else if (cat1==stmt || cat1==function) {
  849.   big_app1(pp);
  850.   if(order_decl_stmt) big_app(big_force);
  851.   else big_app(force);
  852.   big_app1(pp+1); reduce(pp,2,cat1,-1,41);
  853. }
  854. @z
  855.  
  856. @x
  857. @ @<Cases for |fn_decl|@>=
  858. if (cat1==decl) {
  859.   big_app1(pp); big_app(force); big_app1(pp+1); reduce(pp,2,fn_decl,0,51);
  860. }
  861. else if (cat1==stmt) {
  862.   big_app1(pp); app(outdent); app(outdent); big_app(force);
  863.   big_app1(pp+1); reduce(pp,2,function,-1,52);
  864. }
  865. @y
  866. @ @<Cases for |fn_decl|@>=
  867. if (cat1==decl) {
  868.   big_app1(pp); big_app(force); big_app1(pp+1); reduce(pp,2,fn_decl,0,51);
  869. }
  870. else if (cat1==stmt) {
  871.   big_app1(pp);
  872.   if (indent_param_decl) {
  873.     app(outdent); app(outdent);
  874.   }
  875.   big_app(force);
  876.   big_app1(pp+1); reduce(pp,2,function,-1,52);
  877. }
  878. @z
  879.  
  880. @x
  881. void
  882. reduce(j,k,c,d,n)
  883. scrap_pointer j;
  884. eight_bits c;
  885. short k, d, n;
  886. @y
  887. static void reduce(scrap_pointer j, short k, eight_bits c, short d, short n)
  888. @z
  889.  
  890. @x
  891. @ @<Change |pp| to $\max...@>=
  892. @y
  893. @ @<Change |pp| to $\max...@>=
  894. #ifdef __TURBOC__
  895. if (d<0 && pp+d>pp) pp=scrap_base; /* segmented architecture caused wrap */
  896. else
  897. #endif
  898. @z
  899.  
  900. @x
  901. void
  902. squash(j,k,c,d,n)
  903. scrap_pointer j;
  904. eight_bits c;
  905. short k, d, n;
  906. @y
  907. static void squash(scrap_pointer j, short k, eight_bits c, short d, short n)
  908. @z
  909.  
  910. @x
  911.     overflow("token");
  912. @y
  913.     overflow(get_string(MSG_OVERFLOW_CT30));
  914. @z
  915.  
  916. @x
  917.     overflow("text");
  918. @y
  919.     overflow(get_string(MSG_OVERFLOW_CT76));
  920. @z
  921.  
  922. @x
  923. text_pointer
  924. translate() /* converts a sequence of scraps */
  925. @y
  926. static text_pointer translate(void) /* converts a sequence of scraps */
  927. @z
  928.  
  929. @x
  930.     if (tok_ptr+6>tok_mem_end) overflow("token");
  931. @y
  932.     if (tok_ptr+6>tok_mem_end) overflow(get_string(MSG_OVERFLOW_CT26));
  933. @z
  934.  
  935. @x
  936.   printf("\nIrreducible scrap sequence in section %d:",section_count);
  937. @y
  938.   printf(get_string(MSG_WARNING_CW171),section_count);
  939. @z
  940.  
  941. @x
  942.   printf("\nTracing after l. %d:\n",cur_line); mark_harmless;
  943. @y
  944.   printf(get_string(MSG_WARNING_CW172),cur_line); mark_harmless;
  945. @z
  946.  
  947. @x
  948. void
  949. C_parse(spec_ctrl) /* creates scraps from \CEE/ tokens */
  950.   eight_bits spec_ctrl;
  951. @y
  952. static void C_parse(eight_bits spec_ctrl)
  953.   /* creates scraps from \CEE/ tokens */
  954. @z
  955.  
  956. @x
  957.   overflow("scrap/token/text");
  958. @y
  959.   overflow(get_string(MSG_OVERFLOW_CW176));
  960. @z
  961.  
  962. @x
  963.         else err_print("! Double @@ should be used in strings");
  964. @y
  965.         else err_print(get_string(MSG_ERROR_CT80));
  966. @z
  967.  
  968. @x
  969. void app_cur_id();
  970. @y
  971. void app_cur_id(boolean);
  972. @z
  973.  
  974. @x
  975. void
  976. app_cur_id(scrapping)
  977. boolean scrapping; /* are we making this into a scrap? */
  978. @y
  979. void app_cur_id(boolean scrapping) /* are we making this into a scrap? */
  980. @z
  981.  
  982. @x
  983. text_pointer
  984. C_translate()
  985. @y
  986. static text_pointer C_translate(void)
  987. @z
  988.  
  989. @x
  990.   if (next_control!='|') err_print("! Missing '|' after C text");
  991. @y
  992.   if (next_control!='|') err_print(get_string(MSG_ERROR_CW182));
  993. @z
  994.  
  995. @x
  996. void
  997. outer_parse() /* makes scraps from \CEE/ tokens and comments */
  998. @y
  999. static void outer_parse(void) /* makes scraps from \CEE/ tokens and comments */
  1000. @z
  1001.  
  1002. @x
  1003. output_state stack[stack_size]; /* info for non-current levels */
  1004. stack_pointer stack_ptr; /* first unused location in the output state stack */
  1005. stack_pointer stack_end=stack+stack_size-1; /* end of |stack| */
  1006. @y
  1007. stack_pointer stack; /* info for non-current levels */
  1008. stack_pointer stack_end; /* end of |stack| */
  1009. stack_pointer stack_ptr; /* first unused location in the output state stack */
  1010. @z
  1011.  
  1012. @x
  1013. max_stack_ptr=stack;
  1014. @y
  1015. alloc_object(stack,stack_size,output_state);
  1016. stack_end = stack + stack_size - 1;
  1017. max_stack_ptr=stack;
  1018. @z
  1019.  
  1020. @x
  1021. void
  1022. push_level(p) /* suspends the current level */
  1023. text_pointer p;
  1024. @y
  1025. static void push_level(text_pointer p) /* suspends the current level */
  1026. @z
  1027.  
  1028. @x
  1029.   if (stack_ptr==stack_end) overflow("stack");
  1030. @y
  1031.   if (stack_ptr==stack_end) overflow(get_string(MSG_OVERFLOW_CT30));
  1032. @z
  1033.  
  1034. @x
  1035. void
  1036. pop_level()
  1037. @y
  1038. static void pop_level(void)
  1039. @z
  1040.  
  1041. @x
  1042. eight_bits
  1043. get_output() /* returns the next token of output */
  1044. @y
  1045. static eight_bits get_output(void) /* returns the next token of output */
  1046. @z
  1047.  
  1048. @x
  1049.   return(a);
  1050. @y
  1051.   return((eight_bits)a);
  1052. @z
  1053.  
  1054. @x
  1055. void
  1056. output_C() /* outputs the current token list */
  1057. @y
  1058. static void output_C(void) /* outputs the current token list */
  1059. @z
  1060.  
  1061. @x
  1062. void make_output();
  1063. @y
  1064. static void make_output(void);
  1065. @z
  1066.  
  1067. @x
  1068. void
  1069. make_output() /* outputs the equivalents of tokens */
  1070. @y
  1071. static void make_output(void) /* outputs the equivalents of tokens */
  1072. @z
  1073.  
  1074. @x
  1075.   char *k, *k_limit; /* indices into |scratch| */
  1076. @y
  1077.   char HUGE *k;
  1078.   char HUGE *k_limit; /* indices into |scratch| */
  1079. @z
  1080.  
  1081. @x
  1082.     for (p=cur_name->byte_start;p<(cur_name+1)->byte_start;p++)
  1083.       out(isxalpha(*p)? 'x':*p);
  1084. @y
  1085. #ifdef __TURBOC__
  1086.     for (k=cur_name->byte_start;k<(cur_name+1)->byte_start;k++)
  1087.       out(isxalpha(*k)? 'x':*k);
  1088. #else
  1089.     for (p=cur_name->byte_start;p<(cur_name+1)->byte_start;p++)
  1090.       out(isxalpha(*p)? 'x':*p);
  1091. #endif
  1092. @^system dependencies@>
  1093. @z
  1094.  
  1095. @x
  1096.     for (p=cur_name->byte_start;p<(cur_name+1)->byte_start;p++)
  1097.       if (xislower(*p)) { /* not entirely uppercase */
  1098. @y
  1099. #ifdef __TURBOC__
  1100.     for (k=cur_name->byte_start;k<(cur_name+1)->byte_start;k++)
  1101.       if (xislower(*k)) { /* not entirely uppercase */
  1102. #else
  1103.     for (p=cur_name->byte_start;p<(cur_name+1)->byte_start;p++)
  1104.       if (xislower(*p)) { /* not entirely uppercase */
  1105. #endif
  1106. @^system dependencies@>
  1107. @z
  1108.  
  1109. @x
  1110.   printf("\n! Illegal control code in section name: <");
  1111. @y
  1112.   printf(get_string(MSG_ERROR_CW201));
  1113. @z
  1114.  
  1115. @x
  1116.     printf("\n! C text in section name didn't end: <");
  1117. @y
  1118.     printf(get_string(MSG_ERROR_CW202));
  1119. @z
  1120.  
  1121. @x
  1122.       if (j>buffer+long_buf_size-3) overflow("buffer");
  1123. @y
  1124.       if (j>buffer+long_buf_size-3) overflow(get_string(MSG_OVERFLOW_CW202));
  1125. @z
  1126.  
  1127. @x
  1128.   if (j>buffer+long_buf_size-4) overflow("buffer");
  1129. @y
  1130.   if (j>buffer+long_buf_size-4) overflow(get_string(MSG_OVERFLOW_CW202));
  1131. @z
  1132.  
  1133. @x
  1134. void phase_two();
  1135. @y
  1136. static void phase_two(void);
  1137. @z
  1138.  
  1139. @x
  1140. void
  1141. phase_two() {
  1142. @y
  1143. static void phase_two(void) {
  1144. @z
  1145.  
  1146. @x
  1147. reset_input(); if (show_progress) printf("\nWriting the output file...");
  1148. @y
  1149. reset_input(); if (show_progress) printf(get_string(MSG_PROGRESS_CW204));
  1150. @z
  1151.  
  1152. @x
  1153.         err_print("! TeX string should be in C text only"); break;
  1154. @y
  1155.         err_print(get_string(MSG_ERROR_CW209_1)); break;
  1156. @z
  1157.  
  1158. @x
  1159.         err_print("! You can't do that in TeX text"); break;
  1160. @y
  1161.         err_print(get_string(MSG_ERROR_CW209_2)); break;
  1162. @z
  1163.  
  1164. @x
  1165. void finish_C();
  1166. @y
  1167. static void finish_C(boolean);
  1168. @z
  1169.  
  1170. @x
  1171. void
  1172. finish_C(visible) /* finishes a definition or a \CEE/ part */
  1173.   boolean visible; /* nonzero if we should produce \TEX/ output */
  1174. @y
  1175. static void finish_C(@t\1\1@> /* finishes a definition or a \Cee\ part */
  1176.   boolean visible@t\2\2@>) /* nonzero if we should produce \TeX\ output */
  1177. @z
  1178.  
  1179. @x
  1180.     err_print("! Improper macro definition");
  1181. @y
  1182.     err_print(get_string(MSG_ERROR_CW213));
  1183. @z
  1184.  
  1185. @x
  1186.       default: err_print("! Improper macro definition"); break;
  1187. @y
  1188.       default: err_print(get_string(MSG_ERROR_CW213)); break;
  1189. @z
  1190.  
  1191. @x
  1192.   if (scrap_ptr!=scrap_info+2) err_print("! Improper format definition");
  1193. @y
  1194.   if (scrap_ptr!=scrap_info+2) err_print(get_string(MSG_ERROR_CW214));
  1195. @z
  1196.  
  1197. @x
  1198.   err_print("! You need an = sign after the section name");
  1199. @y
  1200.   err_print(get_string(MSG_ERROR_CW217));
  1201. @z
  1202.  
  1203. @x
  1204.   err_print("! You can't do that in C text");
  1205. @y
  1206.   err_print(get_string(MSG_ERROR_CW218));
  1207. @z
  1208.  
  1209. @x
  1210. void footnote();
  1211. @y
  1212. static void footnote(sixteen_bits);
  1213. @z
  1214.  
  1215. @x
  1216. void
  1217. footnote(flag) /* outputs section cross-references */
  1218. sixteen_bits flag;
  1219. @y
  1220. static void footnote(sixteen_bits flag) /* outputs section cross-references */
  1221. @z
  1222.  
  1223. @x
  1224. void phase_three();
  1225. @y
  1226. static void phase_three(void);
  1227. @z
  1228.  
  1229. @x
  1230. void
  1231. phase_three() {
  1232. @y
  1233. static void phase_three(void) {
  1234. @z
  1235.  
  1236. @x
  1237. if (no_xref) {
  1238.   finish_line();
  1239.   out_str("\\end");
  1240. @.\\end@>
  1241.   finish_line();
  1242. }
  1243. else {
  1244.   phase=3; if (show_progress) printf("\nWriting the index...");
  1245. @.Writing the index...@>
  1246.   finish_line();
  1247.   if ((idx_file=fopen(idx_file_name,"w"))==NULL)
  1248.     fatal("! Cannot open index file ",idx_file_name);
  1249. @.Cannot open index file@>
  1250.   if (change_exists) {
  1251.     @<Tell about changed sections@>; finish_line(); finish_line();
  1252.   }
  1253.   out_str("\\inx"); finish_line();
  1254. @.\\inx@>
  1255.   active_file=idx_file; /* change active file to the index file */
  1256.   @<Do the first pass of sorting@>;
  1257.   @<Sort and output the index@>;
  1258.   finish_line(); fclose(active_file); /* finished with |idx_file| */
  1259.   active_file=tex_file; /* switch back to |tex_file| for a tic */
  1260.   out_str("\\fin"); finish_line();
  1261. @.\\fin@>
  1262.   if ((scn_file=fopen(scn_file_name,"w"))==NULL)
  1263.     fatal("! Cannot open section file ",scn_file_name);
  1264. @.Cannot open section file@>
  1265.   active_file=scn_file; /* change active file to section listing file */
  1266.   @<Output all the section names@>;
  1267.   finish_line(); fclose(active_file); /* finished with |scn_file| */
  1268.   active_file=tex_file;
  1269.   if (group_found) out_str("\\con");@+else out_str("\\end");
  1270. @.\\con@>
  1271. @.\\end@>
  1272.   finish_line();
  1273.   fclose(active_file);
  1274. }
  1275. if (show_happiness) printf("\nDone.");
  1276. @y
  1277. if (no_xref) {
  1278.   finish_line();
  1279.   out_str("\\end");
  1280. @.\\end@>
  1281.   active_file=tex_file;
  1282. }
  1283. else {
  1284.   phase=3;
  1285.   if (show_progress) {
  1286.     printf(get_string(MSG_PROGRESS_CW225)); fflush(stdout);
  1287.   }
  1288. @.Writing the index...@>
  1289.   finish_line();
  1290.   if ((idx_file=fopen(idx_file_name,"w"))==NULL)
  1291.     fatal(get_string(MSG_FATAL_CW225_1),idx_file_name);
  1292. @.Cannot open index file@>
  1293.   if (change_exists) {
  1294.     @<Tell about changed sections@>; finish_line(); finish_line();
  1295.   }
  1296.   out_str("\\inx"); finish_line();
  1297. @.\\inx@>
  1298.   active_file=idx_file; /* change active file to the index file */
  1299.   @<Do the first pass of sorting@>;
  1300.   @<Sort and output the index@>;
  1301.   finish_line(); fclose(active_file); /* finished with |idx_file| */
  1302.   active_file=tex_file; /* switch back to |tex_file| for a tic */
  1303.   out_str("\\fin"); finish_line();
  1304. @.\\fin@>
  1305.   if ((scn_file=fopen(scn_file_name,"w"))==NULL)
  1306.     fatal(get_string(MSG_FATAL_CW225_2),scn_file_name);
  1307. @.Cannot open section file@>
  1308.   active_file=scn_file; /* change active file to section listing file */
  1309.   @<Output all the section names@>;
  1310.   finish_line(); fclose(active_file); /* finished with |scn_file| */
  1311.   active_file=tex_file;
  1312.   if (group_found) out_str("\\con");@+else out_str("\\end");
  1313. @.\\con@>
  1314. @.\\end@>
  1315. }
  1316. finish_line(); fclose(active_file); active_file=NULL;
  1317. @<Update the result when it has changed@>@;
  1318. if (show_happiness) printf(get_string(MSG_PROGRESS_CT42_3));
  1319. @z
  1320.  
  1321. @x
  1322. name_pointer bucket[256];
  1323. name_pointer next_name; /* successor of |cur_name| when sorting */
  1324. name_pointer blink[max_names]; /* links in the buckets */
  1325. @y
  1326. name_pointer *bucket;
  1327. name_pointer next_name; /* successor of |cur_name| when sorting */
  1328. name_pointer *blink; /* links in the buckets */
  1329. @z
  1330.  
  1331. @x
  1332.     if (cur_name->xref!=(char*)xmem) {
  1333. @y
  1334.     if (cur_name->xref!=(void HUGE*)xmem) {
  1335. @z
  1336.  
  1337. @x
  1338. char *cur_byte; /* index into |byte_mem| */
  1339. @y
  1340. char HUGE *cur_byte; /* index into |byte_mem| */
  1341. @z
  1342.  
  1343. @x
  1344. max_sort_ptr=scrap_info;
  1345. @y
  1346. alloc_object(bucket,256,name_pointer);
  1347. alloc_object(blink,max_names,name_pointer);
  1348. max_sort_ptr=scrap_info;
  1349. @z
  1350.  
  1351. @x
  1352. eight_bits collate[102+128]; /* collation order */
  1353. @y
  1354. eight_bits *collate; /* collation order */
  1355. @z
  1356.  
  1357. @x
  1358. collate[0]=0;
  1359. strcpy(collate+1," \1\2\3\4\5\6\7\10\11\12\13\14\15\16\17");
  1360. /* 16 characters + 1 = 17 */
  1361. strcpy(collate+17,"\20\21\22\23\24\25\26\27\30\31\32\33\34\35\36\37");
  1362. /* 16 characters + 17 = 33 */
  1363. strcpy(collate+33,"!\42#$%&'()*+,-./:;<=>?@@[\\]^`{|}~_");
  1364. /* 32 characters + 33 = 65 */
  1365. strcpy(collate+65,"abcdefghijklmnopqrstuvwxyz0123456789");
  1366. /* (26 + 10) characters + 65 = 101 */
  1367. strcpy(collate+101,"\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217");
  1368. /* 16 characters + 101 = 117 */
  1369. strcpy(collate+117,"\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237");
  1370. /* 16 characters + 117 = 133 */
  1371. strcpy(collate+133,"\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257");
  1372. /* 16 characters + 133 = 149 */
  1373. strcpy(collate+149,"\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277");
  1374. /* 16 characters + 149 = 165 */
  1375. strcpy(collate+165,"\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317");
  1376. /* 16 characters + 165 = 181 */
  1377. strcpy(collate+181,"\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337");
  1378. /* 16 characters + 181 = 197 */
  1379. strcpy(collate+197,"\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357");
  1380. /* 16 characters + 197 = 213 */
  1381. strcpy(collate+213,"\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377");
  1382. /* 16 characters + 213 = 229 */
  1383. @y
  1384. alloc_object(collate,102+128,eight_bits);
  1385. collate[0]=0;
  1386. strcpy((char *)collate+1,
  1387.   " \1\2\3\4\5\6\7\10\11\12\13\14\15\16\17");
  1388. /* 16 characters + 1 = 17 */
  1389. strcpy((char *)collate+17,
  1390.   "\20\21\22\23\24\25\26\27\30\31\32\33\34\35\36\37");
  1391. /* 16 characters + 17 = 33 */
  1392. strcpy((char *)collate+33,
  1393.   "!\42#$%&'()*+,-./:;<=>?@@[\\]^`{|}~_");
  1394. /* 32 characters + 33 = 65 */
  1395. strcpy((char *)collate+65,
  1396.   "abcdefghijklmnopqrstuvwxyz0123456789");
  1397. /* (26 + 10) characters + 65 = 101 */
  1398. strcpy((char *)collate+101,
  1399.   "\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217");
  1400. /* 16 characters + 101 = 117 */
  1401. strcpy((char *)collate+117,
  1402.   "\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237");
  1403. /* 16 characters + 117 = 133 */
  1404. strcpy((char *)collate+133,
  1405.   "\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257");
  1406. /* 16 characters + 133 = 149 */
  1407. strcpy((char *)collate+149,
  1408.   "\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277");
  1409. /* 16 characters + 149 = 165 */
  1410. strcpy((char *)collate+165,
  1411.   "\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317");
  1412. /* 16 characters + 165 = 181 */
  1413. strcpy((char *)collate+181,
  1414.   "\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337");
  1415. /* 16 characters + 181 = 197 */
  1416. strcpy((char *)collate+197,
  1417.   "\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357");
  1418. /* 16 characters + 197 = 213 */
  1419. strcpy((char *)collate+213,
  1420.   "\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377");
  1421. /* 16 characters + 213 = 229 */
  1422. @z
  1423.  
  1424. @x
  1425. void  unbucket();
  1426. @y
  1427. static void unbucket(eight_bits);
  1428. @z
  1429.  
  1430. @x
  1431. void
  1432. unbucket(d) /* empties buckets having depth |d| */
  1433. eight_bits d;
  1434. @y
  1435. static void unbucket(eight_bits d) /* empties buckets having depth |d| */
  1436. @z
  1437.  
  1438. @x
  1439.     if (sort_ptr>=scrap_info_end) overflow("sorting");
  1440. @y
  1441.     if (sort_ptr>=scrap_info_end) overflow(get_string(MSG_OVERFLOW_CW237));
  1442. @z
  1443.  
  1444. @x
  1445.     else {char *j;
  1446. @y
  1447.     else {char HUGE *j;
  1448. @z
  1449.  
  1450. @x
  1451.   case custom: case quoted: {char *j; out_str("$\\");
  1452. @y
  1453.   case custom: case quoted: {char HUGE *j; out_str("$\\");
  1454. @z
  1455.  
  1456. @x
  1457. void section_print();
  1458. @y
  1459. static void section_print(name_pointer);
  1460. @z
  1461.  
  1462. @x
  1463. void
  1464. section_print(p) /* print all section names in subtree |p| */
  1465. name_pointer p;
  1466. @y
  1467. static void section_print(name_pointer p) /* print all section names in subtree |p| */
  1468. @z
  1469.  
  1470. @x
  1471. @ Because on some systems the difference between two pointers is a |long|
  1472. rather than an |int|, we use \.{\%ld} to print these quantities.
  1473.  
  1474. @c
  1475. void
  1476. print_stats() {
  1477. @y
  1478. @ {\mc ANSI C} declares the difference between two pointers to be of type
  1479. |ptrdiff_t| which equals |long| on (almost) all systems instead of |int|,
  1480. so we use \.{\%ld} to print these quantities and cast them to |long|
  1481. explicitly.
  1482.  
  1483. @c
  1484. void print_stats(void) {
  1485. @z
  1486.  
  1487. @x
  1488.   printf("\nMemory usage statistics:\n");
  1489. @.Memory usage statistics:@>
  1490.   printf("%ld names (out of %ld)\n",
  1491.             (long)(name_ptr-name_dir),(long)max_names);
  1492.   printf("%ld cross-references (out of %ld)\n",
  1493.             (long)(xref_ptr-xmem),(long)max_refs);
  1494.   printf("%ld bytes (out of %ld)\n",
  1495.             (long)(byte_ptr-byte_mem),(long)max_bytes);
  1496.   printf("Parsing:\n");
  1497.   printf("%ld scraps (out of %ld)\n",
  1498.             (long)(max_scr_ptr-scrap_info),(long)max_scraps);
  1499.   printf("%ld texts (out of %ld)\n",
  1500.             (long)(max_text_ptr-tok_start),(long)max_texts);
  1501.   printf("%ld tokens (out of %ld)\n",
  1502.             (long)(max_tok_ptr-tok_mem),(long)max_toks);
  1503.   printf("%ld levels (out of %ld)\n",
  1504.             (long)(max_stack_ptr-stack),(long)stack_size);
  1505.   printf("Sorting:\n");
  1506.   printf("%ld levels (out of %ld)\n",
  1507.             (long)(max_sort_ptr-scrap_info),(long)max_scraps);
  1508. }
  1509. @y
  1510.   printf(get_string(MSG_STATS_CT95_1));
  1511. @.Memory usage statistics:@>
  1512.   printf(get_string(MSG_STATS_CT95_2),
  1513.             (long)(name_ptr-name_dir),(long)max_names);
  1514.   printf(get_string(MSG_STATS_CW248_1),
  1515.             (long)(xref_ptr-xmem),(long)max_refs);
  1516.   printf(get_string(MSG_STATS_CT95_4),
  1517.             (long)(byte_ptr-byte_mem),(long)max_bytes);
  1518.   printf(get_string(MSG_STATS_CW248_2));
  1519.   printf(get_string(MSG_STATS_CW248_3),
  1520.             (long)(max_scr_ptr-scrap_info),(long)max_scraps);
  1521.   printf(get_string(MSG_STATS_CW248_4),
  1522.             (long)(max_text_ptr-tok_start),(long)max_texts);
  1523.   printf(get_string(MSG_STATS_CT95_5),
  1524.             (long)(max_tok_ptr-tok_mem),(long)max_toks);
  1525.   printf(get_string(MSG_STATS_CW248_5),
  1526.             (long)(max_stack_ptr-stack),(long)stack_size);
  1527.   printf(get_string(MSG_STATS_CW248_6));
  1528.   printf(get_string(MSG_STATS_CW248_5),
  1529.             (long)(max_sort_ptr-scrap_info),(long)max_scraps);
  1530. }
  1531. @z
  1532.  
  1533. @x
  1534. @** Index.
  1535. @y
  1536. @** Version information.  The {\mc AMIGA} operating system provides the
  1537. `version' command and good programs answer with some informations about
  1538. their creation date and their current version.  This might be useful for
  1539. other operating systems as well.
  1540.  
  1541. @<Glob...@>=
  1542. const char Version[] = "$VER: CWeave 3.4 [p13] ("__DATE__", "__TIME__")\n";
  1543.  
  1544. @** Function declarations.  Here are declarations---conforming to
  1545. {\mc ANSI~C}---of all functions in this code, as far as they are
  1546. not already in |"common.h"|.  These are private to \.{CWEAVE}.
  1547.  
  1548. @<Predecl...@>=
  1549. static eight_bits copy_TeX(void);@/
  1550. static eight_bits get_output(void);@/
  1551. static text_pointer C_translate(void);@/
  1552. static text_pointer translate(void);@/
  1553. static token_pointer find_first_ident(text_pointer);@/
  1554. static unsigned skip_TeX(void);@/
  1555. static void app_str(char *);@/
  1556. static void big_app(token);@/
  1557. static void big_app1(scrap_pointer);@/
  1558. static void copy_limbo(void);@/
  1559. static void C_parse(eight_bits);@/
  1560. static void finish_line(void);@/
  1561. static void flush_buffer(char *,boolean,boolean);@/
  1562. static void make_reserved(scrap_pointer);@/
  1563. static void make_underlined(scrap_pointer);@/
  1564. static void new_section_xref(name_pointer);@/
  1565. static void new_xref(name_pointer);@/
  1566. static void outer_parse(void);@/
  1567. static void output_C(void);@/
  1568. static void out_name(name_pointer);@/
  1569. static void out_section(sixteen_bits);@/
  1570. static void out_str(char *);@/
  1571. static void pop_level(void);@/
  1572. static void print_cat(eight_bits);@/
  1573. static void print_text(text_pointer p);@/
  1574. static void push_level(text_pointer);@/
  1575. static void reduce(scrap_pointer,short,eight_bits,short,short);@/
  1576. static void set_file_flag(name_pointer);@/
  1577. static void skip_limbo(void);@/
  1578. static void squash(scrap_pointer,short,eight_bits,short,short);@/
  1579. #ifdef DEAD_CODE
  1580. static void out_str_del(char *,char *);@/
  1581. #endif
  1582.  
  1583. @** Output file update.  Most \CEE/ projects are controlled by a
  1584. \.{makefile} which automatically takes care of the temporal dependecies
  1585. between the different source modules.  It is suitable that \.{CWEB} doesn't
  1586. create new output for all existing files, when there are only changes to
  1587. some of them.  Thus the \.{make} process will only recompile those modules
  1588. where necessary. The idea and basic implementation of this mechanism can
  1589. be found in the program \.{NUWEB} by Preston Briggs, to whom credit is due.
  1590.  
  1591. @<Update the result...@>=
  1592. if((tex_file=fopen(tex_file_name,"r"))!=NULL) {
  1593.   char *x,*y;
  1594.   int x_size,y_size,comparison;
  1595.  
  1596.   if((check_file=fopen(check_file_name,"r"))==NULL)
  1597.     fatal(get_string(MSG_FATAL_CO78),check_file_name);
  1598.  
  1599.   alloc_object(x,BUFSIZ,char);
  1600.   alloc_object(y,BUFSIZ,char);
  1601.  
  1602.   @<Compare the temporary output to the previous output@>@;
  1603.  
  1604.   fclose(tex_file); tex_file=NULL;
  1605.   fclose(check_file); check_file=NULL;
  1606.  
  1607.   @<Take appropriate action depending on the comparison@>@;
  1608.  
  1609.   free_object(y);
  1610.   free_object(x);
  1611.   }
  1612. else
  1613.   rename(check_file_name,tex_file_name); /* This was the first run */
  1614.  
  1615. check_file_name=NULL; /* We want to get rid of the temporary file */
  1616.  
  1617. @ We hope that this runs fast on most systems.
  1618.  
  1619. @<Compare the temp...@>=
  1620. do {
  1621.   x_size = fread(x,1,BUFSIZ,tex_file);
  1622.   y_size = fread(y,1,BUFSIZ,check_file);
  1623.   comparison = (x_size == y_size); /* Do not merge these statements! */
  1624.   if(comparison) comparison = !memcmp(x,y,x_size);
  1625.   } while(comparison && !feof(tex_file) && !feof(check_file));
  1626.  
  1627. @ Note the superfluous call to |remove| before |rename|.  We're using it to
  1628. get around a bug in some implementations of |rename|.
  1629.  
  1630. @<Take appropriate action...@>=
  1631. if(comparison)
  1632.   remove(check_file_name); /* The output remains untouched */
  1633. else {
  1634.   remove(tex_file_name);
  1635.   rename(check_file_name,tex_file_name);
  1636.   }
  1637.  
  1638. @** Index.
  1639. @z
  1640.  
  1641.