home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / dec93 / dev / misc / cweb.lha / CWeb / ctangle-p.ch < prev    next >
Encoding:
Text File  |  1993-12-21  |  17.9 KB  |  557 lines

  1.                                 -*-Web-*-
  2. This file, CTANGLE-P.CH, is part of CWEB-p.
  3. It is a changefile for CTANGLE.W, Version 3.0.
  4.  
  5. Authors and Contributors:
  6. (H2B) Hans-Hermann Bode, Universität Osnabrück,
  7.   (hhbode@@dosuni1.rz.uni-osnabrueck.de or HHBODE@@DOSUNI1.BITNET).
  8.  
  9. (KG) Klaus Guntermann, TH Darmstadt,
  10.   (guntermann@@iti.informatik.th-darmstadt.de).
  11.  
  12. (AS) Andreas Scherer,
  13.   Abt-Wolf-Straße 17, 96215 Lichtenfels, Germany.
  14.  
  15. (CS) Carsten Steger, Universität München,
  16.   carsten.steger@informatik.tu-muenchen.de
  17.  
  18. Caveat utilitor:  Some of the source code introduced by this change file is
  19. made conditional to the use of specific compilers on specific systems.
  20. This applies to places marked with `#ifdef __TURBOC__' and `#ifdef _AMIGA'.
  21.  
  22. This program is distributed WITHOUT ANY WARRANTY, express or implied.
  23.  
  24. The following copyright notice extends to this changefile only, not to
  25. the masterfile CTANGLE.W.
  26.  
  27. Copyright (C) 1993 Andreas Scherer
  28. Copyright (C) 1991, 1993 Carsten Steger
  29. Copyright (C) 1991, 1992 Hans-Hermann Bode
  30.  
  31. Permission is granted to make and distribute verbatim copies of this
  32. document provided that the copyright notice and this permission notice
  33. are preserved on all copies.
  34.  
  35. Permission is granted to copy and distribute modified versions of this
  36. document under the conditions for verbatim copying, provided that the
  37. entire resulting derived work is distributed under the terms of a
  38. permission notice identical to this one.
  39.  
  40. Version history:
  41.  
  42. Version    Date        Author    Comment
  43. a1/t1    10 Oct 1991    H2B    First attempt for CTANGLE.W 2.0.
  44. p2    13 Feb 1992    H2B    Updated for CTANGLE.W 2.2, ANSI and Turbo
  45.                 changefiles merged together.
  46. p3    16 Apr 1992    H2B    Updated for CTANGLE.W 2.4.
  47. p4    21 Jun 1992    H2B    Nothing changed.
  48. p5    18 Jul 1992    H2B    Extensions for C++ implemented.
  49. p5a    24 Jul 1992    KG    adaptions for other ANSI C compiler
  50. p5b    28 Jul 1992    H2B    Remaining headers converted to ANSI style.
  51. p6    06 Sep 1992    H2B    Updated for CTANGLE.W 2.7, |dot_dot_dot|
  52.                 added, parsing of @@'\'' fixed (due to KG),
  53.                 @@<Copy an ASCII constant@@> extended,
  54.                 (nonfatal) confusion in processing short
  55.                 comments fixed.
  56. p6a     15 Mar 1993     AS      Re-changing some of the TC stuff to SAS/C
  57. p6b     27 Jul 1993     AS      new patch level in accordance with CWeave
  58. p6c    04 Sep 1993    AS    new patch level in accordance with Common
  59. p6d    09 Oct 1993    AS    Updated for CTANGLE.W 2.8. (This was p7)
  60. p7    13 Nov 1992    H2B    Converted to master change file, updated for
  61.                 ctangle.w 2.8. [Not released.]
  62. p7.5    29 Nov 1992    H2B    Updated for ctangle.w 2.9beta. [Not released.]
  63. p8    08 Dec 1992    H2B    Updated for ctangle.w 2.9++ (stuff went into
  64.                 the source file), ANSI bug in <Get a constant>
  65.                 fixed. [Not released.]
  66. p8a    10 Mar 1993    H2B    Restructured for public release.
  67.                 [Not released.]
  68. p8b    14 Apr 1993    H2B    Updated for ctangle.w 3.0beta. [Not released.]
  69. p8c    21 Jun 1993    H2B    Updated for final ctangle.w 3.0.
  70. p8d    25 Oct 1993    AS    Incorporated into Amiga version 2.8 [p7] and
  71.                 updated to version 3.0.
  72. ------------------------------------------------------------------------------
  73. @x l.1
  74. % This file is part of CWEB.
  75. % This program by Silvio Levy and Donald E. Knuth
  76. % is based on a program by Knuth.
  77. % It is distributed WITHOUT ANY WARRANTY, express or implied.
  78. % Version 3.0 --- June 1993
  79.  
  80. % Copyright (C) 1987,1990,1993 Silvio Levy and Donald E. Knuth
  81. @y
  82. % This file, CTANGLE.W, is part of CWEB-p.
  83. % This program by Silvio Levy and Donald E. Knuth
  84. % is based on a program by Knuth.
  85. % It is distributed WITHOUT ANY WARRANTY, express or implied.
  86. % Version 2.4 --- Don Knuth, April 1992
  87. % Version 2.4 [p5] --- Hans-Hermann Bode, July 1992
  88. % Version 2.4 [p5a] --- Klaus Guntermann, July 1992
  89. % Version 2.4 [p5b] --- Hans-Hermann Bode, July 1992
  90. % Version 2.7 --- Don Knuth, July 1992
  91. % Version 2.7 [p6] --- Hans-Hermann Bode, September 1992
  92. % Version 2.7 [p6a] --- Andreas Scherer, March 1993
  93. % Version 2.7 [p6b] --- Andreas Scherer, July 1993
  94. % Version 2.7 [p6c] --- Andreas Scherer, September 1993
  95. % Version 2.8 --- Don Knuth, September 1992
  96. % Version 2.8 [p7] --- Andreas Scherer, October 1993
  97. % Version 3.0 --- Don Knuth, June 1993
  98. % Version 3.0 [p8c] --- Hans-Hermann Bode, June 1993
  99. % Version 3.0 [p8d] --- Andreas Scherer, October 1993
  100.  
  101. % Copyright (C) 1987,1990,1993 Silvio Levy and Donald E. Knuth
  102. % Copyright (C) 1991,1992,1993 Hans-Hermann Bode
  103. % Copyright (C) 1993 Andreas Scherer
  104. @z
  105. ------------------------------------------------------------------------------
  106. @x l.25
  107. \def\title{CTANGLE (Version 3.0)}
  108. @y
  109. \def\title{CTANGLE (Version 3.0 [p8d])}
  110. @z
  111. ------------------------------------------------------------------------------
  112. @x l.29
  113.   \centerline{(Version 3.0)}
  114. @y
  115.   \centerline{(Version 3.0 [p8d])}
  116. @z
  117. ------------------------------------------------------------------------------
  118. @x l.33
  119. Copyright \copyright\ 1987, 1990, 1993 Silvio Levy and Donald E. Knuth
  120. @y
  121. Copyright \copyright\ 1987, 1990, 1993 Silvio Levy and Donald E. Knuth
  122. \smallskip\noindent
  123. Copyright \copyright\ 1991, 1992, 1993 Hans-Hermann Bode
  124. \smallskip\noindent
  125. Copyright \copyright\ 1993 Andreas Scherer
  126. @z
  127. ------------------------------------------------------------------------------
  128. Activate this, if only the changed modules should be printed.
  129. x l.46
  130. \let\maybe=\iftrue
  131. y
  132. \let\maybe=\iffalse
  133. z
  134. ------------------------------------------------------------------------------
  135. @x l.49
  136. This is the \.{CTANGLE} program by Silvio Levy and Donald E. Knuth,
  137. based on \.{TANGLE} by Knuth.
  138. @y
  139. This is the \.{CTANGLE} program by Silvio Levy and Donald E. Knuth,
  140. based on \.{TANGLE} by Knuth, with {\mc ANSI-C} conforming changes
  141. and {\mc TURBO}-\CPLUSPLUS/ implementation made by Hans-Hermann Bode.
  142. {\mc SAS/C~6.0} implementation made by Andreas Scherer.
  143. @z
  144. ------------------------------------------------------------------------------
  145. @x l.59
  146. @d banner "This is CTANGLE (Version 3.0)\n"
  147. @y
  148. @d banner "This is CTANGLE (Version 3.0 [p8d])\n"
  149. @z
  150. ------------------------------------------------------------------------------
  151. @x l.74
  152. @<Predecl...@>=
  153. extern int strlen(); /* length of string */
  154. extern int strcmp(); /* compare strings lexicographically */
  155. extern char* strcpy(); /* copy one string to another */
  156. extern int strncmp(); /* compare up to $n$ string characters */
  157. extern char* strncpy(); /* copy up to $n$ string characters */
  158. @y
  159. @<Include files@>=
  160. #include <string.h>
  161. @z
  162. ------------------------------------------------------------------------------
  163. @x l.89
  164. int main (ac, av)
  165. int ac;
  166. char **av;
  167. @y
  168. int main (int ac, char **av)
  169. @z
  170. ------------------------------------------------------------------------------
  171. Blow the fuck out of {\mc MULTIPLE SCLEROSIS};
  172. any decent system is capable of using the defaults.
  173. x l.103
  174. @ The following parameters were sufficient in the original \.{TANGLE} to
  175. handle \TEX/,
  176. so they should be sufficient for most applications of \.{CTANGLE}.
  177. y
  178. @ In the following, due to memory limitations of {\mc MS-DOS} systems, the
  179. value of |max_toks| is reduced to~$1\over2$ of its value in the original
  180. \.{CTANGLE}, the remaining parameters were sufficient in the original
  181. \.{CTANGLE} to handle \TEX/; nevertheless, even |max_toks| should be sufficient
  182. for most applications of \.{CTANGLE}.
  183. @^system dependencies@>
  184. z
  185. ------------------------------------------------------------------------------
  186. x l.111
  187. @d max_toks 270000 /* number of bytes in compressed \Cee\ code */
  188. y
  189. @d max_toks 135000 /* number of bytes in compressed \Cee\ code */
  190. z
  191. ------------------------------------------------------------------------------
  192. @x l.124
  193. @i common.h
  194. @y
  195. @i common-p.h
  196. @z
  197. ------------------------------------------------------------------------------
  198. @x l.151
  199.   eight_bits *tok_start; /* pointer into |tok_mem| */
  200. @y
  201.   eight_bits HUGE *tok_start; /* pointer into |tok_mem| */
  202. @z
  203. ------------------------------------------------------------------------------
  204. @x l.160
  205. eight_bits tok_mem[max_toks];
  206. eight_bits *tok_mem_end=tok_mem+max_toks-1;
  207. eight_bits *tok_ptr; /* first unused position in |tok_mem| */
  208. @y
  209. #ifdef __TURBOC__
  210. eight_bits HUGE *tok_mem;
  211. eight_bits HUGE *tok_mem_end;
  212. #else
  213. eight_bits tok_mem[max_toks];
  214. eight_bits *tok_mem_end=tok_mem+max_toks-1;
  215. #endif
  216. eight_bits HUGE *tok_ptr; /* first unused position in |tok_mem| */
  217. @z
  218. ------------------------------------------------------------------------------
  219. @x l.165
  220. text_info->tok_start=tok_ptr=tok_mem;
  221. @y
  222. #ifdef __TURBOC__
  223. tok_mem=allocsafe(max_toks,sizeof(*tok_mem));
  224. tok_mem_end=tok_mem+max_toks-1;
  225. #endif
  226. text_info->tok_start=tok_ptr=tok_mem;
  227. @z
  228. ------------------------------------------------------------------------------
  229. @x l.175
  230. name_dir->equiv=(char *)text_info; /* the undefined section has no replacement text */
  231. @y
  232. name_dir->equiv=(char HUGE *)text_info; /* the undefined section has no replacement text */
  233. @z
  234. ------------------------------------------------------------------------------
  235. According to COMMON, names_match has to be declared with 4 parameters.
  236. @x l.181
  237. int names_match(p,first,l)
  238. name_pointer p; /* points to the proposed match */
  239. char *first; /* position of first character of string */
  240. int l; /* length of identifier */
  241. @y
  242. int names_match(name_pointer p,char *first,int l,eight_bits dummy)
  243. /* |p|: points to the proposed match */
  244. /* |first|: position of first character of string */
  245. /* |l|: length of identifier */
  246. /* |dummy|: not used by \.{TANGLE} */
  247. @z
  248. ------------------------------------------------------------------------------
  249. @x l.187
  250.   return !strncmp(first,p->byte_start,l);
  251. @y
  252.   return( !strncmp(first,p->byte_start,l) );
  253. @z
  254. ------------------------------------------------------------------------------
  255. @x l.196
  256. void
  257. init_node(node)
  258. name_pointer node;
  259. @y
  260. void init_node(name_pointer node)
  261. @z
  262. ------------------------------------------------------------------------------
  263. @x l.200
  264.     node->equiv=(char *)text_info;
  265. @y
  266.     node->equiv=(char HUGE *)text_info;
  267. @z
  268. ------------------------------------------------------------------------------
  269. According to COMMON, init_p has to be declared with 2 parameters.
  270. @x l.202
  271. void
  272. init_p() {}
  273. @y
  274. void init_p(name_pointer dummy1,eight_bits dummy2)
  275. {}
  276. @z
  277. ------------------------------------------------------------------------------
  278. @x l.258
  279. void
  280. store_two_bytes(x)
  281. sixteen_bits x;
  282. @y
  283. static void store_two_bytes(sixteen_bits x)
  284. @z
  285. ------------------------------------------------------------------------------
  286. @x l.295
  287.   eight_bits *end_field; /* ending location of replacement text */
  288.   eight_bits *byte_field; /* present location within replacement text */
  289. @y
  290.   eight_bits HUGE *end_field; /* ending location of replacement text */
  291.   eight_bits HUGE *byte_field; /* present location within replacement text */
  292. @z
  293. ------------------------------------------------------------------------------
  294. @x l.334
  295. void
  296. push_level(p) /* suspends the current level */
  297. name_pointer p;
  298. @y
  299. static void push_level(name_pointer p) /* suspends the current level */
  300. @z
  301. ------------------------------------------------------------------------------
  302. @x l.353
  303. void
  304. pop_level(flag) /* do this when |cur_byte| reaches |cur_end| */
  305. int flag; /* |flag==0| means we are in |output_defs| */
  306. @y
  307. static void pop_level(int flag) /* do this when |cur_byte| reaches |cur_end| */
  308. @z
  309. ------------------------------------------------------------------------------
  310. @x l.389
  311. void
  312. get_output() /* sends next token to |out_char| */
  313. @y
  314. static void get_output(void) /* sends next token to |out_char| */
  315. @z
  316. ------------------------------------------------------------------------------
  317. @x l.423
  318.   if ((a+name_dir)->equiv!=(char *)text_info) push_level(a+name_dir);
  319. @y
  320.   if ((a+name_dir)->equiv!=(char HUGE *)text_info) push_level(a+name_dir);
  321. @z
  322. ------------------------------------------------------------------------------
  323. @x l.476
  324. void
  325. flush_buffer() /* writes one line to output file */
  326. @y
  327. static void flush_buffer(void) /* writes one line to output file */
  328. @z
  329. ------------------------------------------------------------------------------
  330. @x l.526
  331. @<Predecl...@>=
  332. void phase_two();
  333.  
  334. @ @c
  335. void
  336. phase_two () {
  337. @y
  338. @<Predecl...@>=
  339. static void phase_two();
  340.  
  341. @ @c
  342. static void phase_two (void) {
  343. @z
  344. ------------------------------------------------------------------------------
  345. @x l.595
  346. @ @<Predecl...@>=
  347. void output_defs();
  348.  
  349. @ @c
  350. void
  351. output_defs()
  352. @y
  353. @ @<Predecl...@>=
  354. static void output_defs(void);
  355.  
  356. @ @c
  357. static void output_defs(void)
  358. @z
  359. ------------------------------------------------------------------------------
  360. @x l.641
  361. @<Predecl...@>=
  362. void out_char();
  363.  
  364. @ @c
  365. void
  366. out_char(cur_char)
  367. eight_bits cur_char;
  368. {
  369.   char *j, *k; /* pointer into |byte_mem| */
  370. @y
  371. @<Predecl...@>=
  372. static void out_char(eight_bits);
  373.  
  374. @ @c
  375. static void out_char(eight_bits cur_char)
  376. {
  377.   char HUGE *j;
  378.   char HUGE *k; /* pointer into |byte_mem| */
  379. @z
  380. ------------------------------------------------------------------------------
  381. This part never came out right, so change it in a better fashion.
  382. @x l.655
  383.       @/@t\4@>@<Case of an identifier@>;
  384.       @/@t\4@>@<Case of a section number@>;
  385.       @/@t\4@>@<Cases like \.{!=}@>;
  386. @y
  387.       @#@<Case of an identifier@>;
  388.       @/@<Case of a section number@>;
  389.       @/@<Cases like \.{!=}@>;@#
  390. @z
  391. ------------------------------------------------------------------------------
  392. @x l.800
  393. eight_bits
  394. skip_ahead() /* skip to next control code */
  395. @y
  396. static eight_bits skip_ahead(void) /* skip to next control code */
  397. @z
  398. ------------------------------------------------------------------------------
  399. @x l.835
  400. int skip_comment(is_long_comment) /* skips over comments */
  401. boolean is_long_comment;
  402. @y
  403. static int skip_comment(boolean is_long_comment) /* skips over comments */
  404. @z
  405. ------------------------------------------------------------------------------
  406. @x l.885
  407. eight_bits
  408. get_next() /* produces the next input token */
  409. @y
  410. static eight_bits get_next(void) /* produces the next input token */
  411. @z
  412. ------------------------------------------------------------------------------
  413. @x l.1185
  414. void
  415. scan_repl(t) /* creates a replacement text */
  416. eight_bits t;
  417. @y
  418. static void scan_repl(eight_bits t) /* creates a replacement text */
  419. @z
  420. ------------------------------------------------------------------------------
  421. Some compilers complain about `missing space between macro name and its
  422. replacement list'.  ANSI C requires a space after the closing parenthesis
  423. of a parametric macro.
  424. @x l.1196
  425.       default: app_repl(a); /* store |a| in |tok_mem| */
  426. @y
  427.       case ')': app_repl(a); if(t==macro) app_repl(' '); break;
  428.       default: app_repl(a); /* store |a| in |tok_mem| */
  429. @z
  430. ------------------------------------------------------------------------------
  431. According to COMMON, a dummy third argument is supplied to id_lookup.
  432. @x l.1214
  433. {int a=id_lookup(id_first,id_loc)-name_dir; app_repl((a / 0400)+0200);
  434. @y
  435. {int a=id_lookup(id_first,id_loc,' ')-name_dir; app_repl((a / 0400)+0200);
  436. @z
  437. ------------------------------------------------------------------------------
  438. Again, according to COMMON, a dummy third argument is supplied to id_lookup.
  439. @x l.1218
  440. case identifier: a=id_lookup(id_first,id_loc)-name_dir;
  441. @y
  442. case identifier: a=id_lookup(id_first,id_loc,' ')-name_dir;
  443. @z
  444. ------------------------------------------------------------------------------
  445. @x l.1335
  446. void
  447. scan_section()
  448. @y
  449. static void scan_section(void)
  450. @z
  451. ------------------------------------------------------------------------------
  452. Once again, according to COMMON, a dummy third argument is supplied to
  453. id_lookup.
  454. @x l.386
  455.   app_repl(((a=id_lookup(id_first,id_loc)-name_dir) / 0400)+0200);
  456. @y
  457.   app_repl(((a=id_lookup(id_first,id_loc,' ')-name_dir) / 0400)+0200);
  458. @z
  459. ------------------------------------------------------------------------------
  460. @x l.1422
  461. else if (p->equiv==(char *)text_info) p->equiv=(char *)cur_text;
  462. @y
  463. else if (p->equiv==(char HUGE *)text_info) p->equiv=(char HUGE *)cur_text;
  464. @z
  465. ------------------------------------------------------------------------------
  466. @x l.1433
  467. @ @<Predec...@>=
  468. void phase_one();
  469.  
  470. @ @c
  471. void
  472. phase_one() {
  473. @y
  474. @ @<Predec...@>=
  475. static void phase_one(void);
  476.  
  477. @ @c
  478. static void phase_one(void) {
  479. @z
  480. ------------------------------------------------------------------------------
  481. @x l.1451
  482. @<Predecl...@>=
  483. void skip_limbo();
  484.  
  485. @ @c
  486. void
  487. skip_limbo()
  488. @y
  489. @<Predecl...@>=
  490. static void skip_limbo(void);
  491.  
  492. @ @c
  493. static void skip_limbo(void)
  494. @z
  495. ------------------------------------------------------------------------------
  496. @x l.1509
  497. @c
  498. void
  499. print_stats() {
  500.   printf("\nMemory usage statistics:\n");
  501.   printf("%ld names (out of %ld)\n",
  502.           (long)(name_ptr-name_dir),(long)max_names);
  503.   printf("%ld replacement texts (out of %ld)\n",
  504.           (long)(text_ptr-text_info),(long)max_texts);
  505.   printf("%ld bytes (out of %ld)\n",
  506.           (long)(byte_ptr-byte_mem),(long)max_bytes);
  507.   printf("%ld tokens (out of %ld)\n",
  508.           (long)(tok_ptr-tok_mem),(long)max_toks);
  509. }
  510. @y
  511. @c
  512. void
  513. print_stats(void) {
  514.   printf("\nMemory usage statistics:\n");
  515. #ifdef __TURBOC__
  516.   printf("%ld names (out of %ld)\n",name_ptr-name_dir,(long)max_names);
  517.   printf("%ld replacement texts (out of %ld)\n",text_ptr-text_info,(long)max_texts);
  518.   printf("%ld bytes (out of %ld)\n",byte_ptr-byte_mem,(long)max_bytes);
  519.   printf("%ld tokens (out of %ld)\n",tok_ptr-tok_mem,(long)max_toks);
  520. #else
  521.   printf("%ld names (out of %ld)\n",
  522.           (long)(name_ptr-name_dir),(long)max_names);
  523.   printf("%ld replacement texts (out of %ld)\n",
  524.           (long)(text_ptr-text_info),(long)max_texts);
  525.   printf("%ld bytes (out of %ld)\n",
  526.           (long)(byte_ptr-byte_mem),(long)max_bytes);
  527.   printf("%ld tokens (out of %ld)\n",
  528.           (long)(tok_ptr-tok_mem),(long)max_toks);
  529. #endif
  530. }
  531. @z
  532. ------------------------------------------------------------------------------
  533. @x l.1523
  534. @** Index.
  535. @y
  536. @* Function declarations.  Here are declarations---conforming to
  537. {\mc ANSI~C}---of all functions in this code, as far as they are
  538. not already in |"common-p.h"|.
  539.  
  540. @<Predecl...@>=
  541. static void store_two_bytes(sixteen_bits x);@/
  542. static void push_level(name_pointer p);@/
  543. static void pop_level(int);@/
  544. static void get_output(void);@/
  545. static void flush_buffer(void);@/
  546. static void phase_two(void);@/
  547. static eight_bits skip_ahead(void);@/
  548. static int skip_comment(boolean long_style);@/
  549. static eight_bits get_next(void);@/
  550. static void scan_repl(eight_bits t);@/
  551. static void scan_section(void);@/
  552. static void phase_one(void);@/
  553.  
  554. @** Index.
  555. @z
  556. ------------------------------------------------------------------------------
  557.