home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / dev / c / cweb / ctangle.ch < prev    next >
Encoding:
Text File  |  1994-12-14  |  45.1 KB  |  1,366 lines

  1.                                 -*-Web-*-
  2. This file, CTANGLE.CH, is part of CWEB (Version 3.3 [patch level 11]).
  3. It is a changefile for CTANGLE.W, Version 3.3.
  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. (GG) Giuseppe Ghibò,
  10.   (ghibo@@galileo.polito.it).
  11.  
  12. (KG) Klaus Guntermann, TH Darmstadt,
  13.   (guntermann@@iti.informatik.th-darmstadt.de).
  14.  
  15. (AS) Andreas Scherer, RWTH Aachen,
  16.   (scherer@@genesis.informatik.rwth-aachen.de).
  17.  
  18. (CS) Carsten Steger, Universität München,
  19.   (carsten.steger@@informatik.tu-muenchen.de).
  20.  
  21. (TW) Tomas Willis,
  22.   (tomas@@cae.wisc.edu).
  23.  
  24. Caveat utilitor:  Some of the source code introduced by this change file is
  25. made conditional to the use of specific compilers on specific systems.
  26. This applies to places marked with `#ifdef __MSDOS__' and `#ifdef __TURBOC__',
  27. `#ifdef _AMIGA' and `#ifdef __SASC'.
  28.  
  29. Some of the changes made in this document are marked by one or more
  30. keywords to indicate that they are somehow related to each other:
  31.  
  32.      - None: These changes are necessary for the indentification
  33.        of this port.
  34.  
  35.      - ANSI: This distribution of CWEB 3.3 not only fully supports
  36.        the writing and documentation of ANSI-C programs, but has been
  37.        transformed into a set of ANSI-C programs (in fact C++ programs)
  38.        by adding function prototypes, standard header files, explicit
  39.        casts, and other features.
  40.  
  41.      - EXTENSIONS: New flags and their effects are introduced by such
  42.        changes.  There are no new CWEB commands (yet).
  43.  
  44.      - MEMORY ALLOCATION: All internal arrays are replaced by pointers
  45.        that address dynamically allocated memory blocks.  Although there
  46.        is no external configuration file or other possibility of changing
  47.        the dimensions at runtime, this effort has the positive effect that
  48.        all source modules can be compiled in the "NEAR" data segment, thus
  49.        making the programs "pure" and enabling them to be made "resident"
  50.        on the Amiga.
  51.  
  52.      - OUTPUT: All three programs of the CWEB system write into
  53.        temporary files first, then they check if there are any
  54.        differences between the current run and possible earlier runs
  55.        and their results, before activating the output "for real".
  56.  
  57.      - SYSTEM DEPENDENCIES: Should be clear.  These changes are caused
  58.        by porting CWEB to other systems than UNIX.  Care has been taken
  59.        to make these points safe on all machines.
  60.  
  61.      - TRANSLATION: For support of the "locale.library" mechanism of the
  62.        Commodore Amiga, all internal strings of characters have been
  63.        replaced by references to an external array in "cweb.h".  The
  64.        portable part of this produces the English default, but on the
  65.        Amiga system support for other languages is given by means of
  66.        "language catalogs".
  67.  
  68. This program is distributed WITHOUT ANY WARRANTY, express or implied.
  69.  
  70. The following copyright notice extends to this changefile only, not to
  71. the masterfile CTANGLE.W.
  72.  
  73. Copyright (C) 1993,1994 Andreas Scherer
  74. Copyright (C) 1991-1993 Hans-Hermann Bode
  75.  
  76. Permission is granted to make and distribute verbatim copies of this
  77. document provided that the copyright notice and this permission notice
  78. are preserved on all copies.
  79.  
  80. Permission is granted to copy and distribute modified versions of this
  81. document under the conditions for verbatim copying, provided that the
  82. entire resulting derived work is given a different name and distributed
  83. under the terms of a permission notice identical to this one.
  84.  
  85. Version history:
  86.  
  87. Version    Date        Author    Comment
  88. a1/t1    10 Oct 1991    H2B    First attempt for CTANGLE.W 2.0.
  89. p2    13 Feb 1992    H2B    Updated for CTANGLE.W 2.2, ANSI and Turbo
  90.                 changefiles merged together.
  91. p3    16 Apr 1992    H2B    Updated for CTANGLE.W 2.4.
  92. p4    21 Jun 1992    H2B    Nothing changed.
  93. p5    18 Jul 1992    H2B    Extensions for C++ implemented.
  94. p5a    24 Jul 1992    KG    adaptions for other ANSI C compiler
  95. p5b    28 Jul 1992    H2B    Remaining headers converted to ANSI style.
  96. p6    06 Sep 1992    H2B    Updated for CTANGLE.W 2.7, |dot_dot_dot|
  97.                 added, parsing of @@'\'' fixed (due to KG),
  98.                 @@<Copy an ASCII constant@@> extended,
  99.                 (nonfatal) confusion in processing short
  100.                 comments fixed.
  101. p6a     15 Mar 1993     AS      Re-changing some of the TC stuff to SAS/C
  102. p6b     27 Jul 1993     AS      new patch level in accordance with CWeave
  103. p6c    04 Sep 1993    AS    new patch level in accordance with Common
  104. p6d    09 Oct 1993    AS    Updated for CTANGLE.W 2.8. (This was p7)
  105. p7    13 Nov 1992    H2B    Converted to master change file, updated for
  106.                 CTANGLE.W 2.8. [Not released.]
  107. p7.5    29 Nov 1992    H2B    Updated for CTANGLE.W 2.9beta. [Not released.]
  108. p8    08 Dec 1992    H2B    Updated for CTANGLE.W 2.9++ (stuff went into
  109.                 the source file), ANSI bug in <Get a constant>
  110.                 fixed. [Not released.]
  111. p8a    10 Mar 1993    H2B    Restructured for public release.
  112.                 [Not released.]
  113. p8b    14 Apr 1993    H2B    Updated for CTANGLE.W 3.0beta. [Not released.]
  114. p8c    21 Jun 1993    H2B    Updated for final CTANGLE.W 3.0.
  115. p8d    25 Oct 1993    AS    Incorporated into Amiga version 2.8 [p7] and
  116.                 updated for version 3.0.
  117. p8e    04 Nov 1993    AS    New patch level in accordance with COMMON.
  118. p9    18 Nov 1993    AS    Updated for CTANGLE.W 3.1.
  119. p9a    30 Nov 1993    AS    Minor changes and corrections.
  120. p9b    06 Dec 1993    AS    Multilinguality implemented.
  121. p9c    18 Jan 1994    AS    Version information included.
  122. p9d    13 May 1994    AS    Dynamic memory allocation.
  123.     02 Jul 1994    AS    Portability version.
  124. p10    12 Aug 1994    AS    Updated for CTANGLE.W 3.2.
  125. p10a    24 Aug 1994    AS    New patch level.
  126.     26 Sep 1994    AS    Replace `calloc' by `malloc'.
  127. p10b    11 Oct 1994    AS    Write to check_file and compare results.
  128.     18 Oct 1994    AS    Some refinements for C++ compilation.
  129.     12 Nov 1994    AS    Use SEPARATORS instead of the multi-way
  130.                 selection for '/', ':', '\', etc.
  131.     13 Nov 1994    AS    Take care of opened system resources and
  132.                 temporary files in case of an user abort.
  133.     25 Nov 1994    AS    CWEB 3.2 [p10b] works with Boheyland 3.1.
  134.                 Reduce `max_toks' drastically.
  135. p11    03 Dec 1994    AS    Updated for CWEB 3.3.
  136. ------------------------------------------------------------------------------
  137. @x l.1
  138. % This file is part of CWEB.
  139. % This program by Silvio Levy and Donald E. Knuth
  140. % is based on a program by Knuth.
  141. % It is distributed WITHOUT ANY WARRANTY, express or implied.
  142. % Version 3.3 --- December 1994
  143.  
  144. % Copyright (C) 1987,1990,1993 Silvio Levy and Donald E. Knuth
  145. @y
  146. % This file, CTANGLE.W, is part of CWEB.
  147. % This program by Silvio Levy and Donald E. Knuth
  148. % is based on a program by Knuth.
  149. % It is distributed WITHOUT ANY WARRANTY, express or implied.
  150. % Version 2.4 --- Don Knuth, April 1992
  151. % Version 2.4 [p5] --- Hans-Hermann Bode, July 1992
  152. % Version 2.4 [p5a] --- Klaus Guntermann, July 1992
  153. % Version 2.4 [p5b] --- Hans-Hermann Bode, July 1992
  154. % Version 2.7 --- Don Knuth, July 1992
  155. % Version 2.7 [p6] --- Hans-Hermann Bode, September 1992
  156. % Version 2.7 [p6a] --- Andreas Scherer, March 1993
  157. % Version 2.7 [p6b] --- Andreas Scherer, July 1993
  158. % Version 2.7 [p6c] --- Andreas Scherer, September 1993
  159. % Version 2.8 --- Don Knuth, September 1992
  160. % Version 2.8 [p7] --- Andreas Scherer, October 1993
  161. % Version 3.0 --- Don Knuth, June 1993
  162. % Version 3.0 [p8c] --- Hans-Hermann Bode, June 1993
  163. % Version 3.0 [p8d] --- Andreas Scherer, October 1993
  164. % Version 3.0 [p8e] --- Andreas Scherer, November 1993
  165. % Version 3.1 --- Don Knuth, November 1993
  166. % Version 3.1 [p9] --- Andreas Scherer, November 1993
  167. % Version 3.1 [p9a] --- Andreas Scherer, November 1993
  168. % Version 3.1 [p9b] --- Andreas Scherer, December 1993
  169. % Version 3.1 [p9c] --- Andreas Scherer, January 1994
  170. % Version 3.1 [p9d] --- Andreas Scherer, July 1994
  171. % Version 3.2 --- Don Knuth, July 1994
  172. % Version 3.2 [p10] --- Andreas Scherer, August 1994
  173. % Version 3.2 [p10a] --- Andreas Scherer, September 1994
  174. % Version 3.2 [p10b] --- Andreas Scherer, October 1994
  175. % Version 3.3 --- Don Knuth, December 1994
  176. % Version 3.3 [p11] --- Andreas Scherer, December 1994
  177.  
  178. % Copyright (C) 1987,1990,1993 Silvio Levy and Donald E. Knuth
  179. % Copyright (C) 1991-1993 Hans-Hermann Bode
  180. % Copyright (C) 1993,1994 Andreas Scherer
  181. @z
  182. ------------------------------------------------------------------------------
  183. @x l.25
  184. \def\title{CTANGLE (Version 3.3)}
  185. @y
  186. \def\title{CTANGLE (Version 3.3 [p11])}
  187. @z
  188. ------------------------------------------------------------------------------
  189. @x l.29
  190.   \centerline{(Version 3.3)}
  191. @y
  192.   \centerline{(Version 3.3 [p11])}
  193. @z
  194. ------------------------------------------------------------------------------
  195. @x l.33
  196. Copyright \copyright\ 1987, 1990, 1993 Silvio Levy and Donald E. Knuth
  197. @y
  198. Copyright \copyright\ 1987, 1990, 1993 Silvio Levy and Donald E. Knuth
  199. \smallskip\noindent
  200. Copyright \copyright\ 1991--1993 Hans-Hermann Bode
  201. \smallskip\noindent
  202. Copyright \copyright\ 1993, 1994 Andreas Scherer
  203. @z
  204. ------------------------------------------------------------------------------
  205. Activate this, if only the changed modules should be printed.
  206. x l.46
  207. \let\maybe=\iftrue
  208. y
  209. \let\maybe=\iffalse
  210. z
  211. ------------------------------------------------------------------------------
  212. TRANSLATION
  213. @x l.59
  214. @d banner "This is CTANGLE (Version 3.3)\n"
  215. @y
  216. @d banner get_string(MSG_BANNER_CT1)
  217. @z
  218. ------------------------------------------------------------------------------
  219. ANSI
  220. @x l.69
  221. @ We predeclare several standard system functions here instead of including
  222. their system header files, because the names of the header files are not as
  223. standard as the names of the functions. (For example, some \CEE/ environments
  224. have \.{<string.h>} where others have \.{<strings.h>}.)
  225.  
  226. @<Predecl...@>=
  227. extern int strlen(); /* length of string */
  228. extern int strcmp(); /* compare strings lexicographically */
  229. extern char* strcpy(); /* copy one string to another */
  230. extern int strncmp(); /* compare up to $n$ string characters */
  231. extern char* strncpy(); /* copy up to $n$ string characters */
  232. @y
  233. @ For string handling we include the {\mc ANSI C} system header file instead
  234. of predeclaring the standard system functions |strlen|, |strcmp|, |strcpy|,
  235. |strncmp|, and |strncpy|.
  236. @^system dependencies@>
  237.  
  238. @<Include files@>=
  239. #include <string.h>
  240. @z
  241. ------------------------------------------------------------------------------
  242. ANSI
  243. @x l.89
  244. int main (ac, av)
  245. int ac;
  246. char **av;
  247. @y
  248. int main (int ac, char **av)
  249. @z
  250. ------------------------------------------------------------------------------
  251. MEMORY ALLOCATION
  252. @x l.95
  253.   @<Set initial values@>;
  254.   common_init();
  255. @y
  256.   common_init();
  257.   @<Set initial values@>;
  258. @z
  259. ==============================================================================
  260. The following changes will effect `common.h', so the line numbers refer
  261. to a different source file!
  262. ------------------------------------------------------------------------------
  263. SYSTEM DEPENDENCIES
  264. @x l.24
  265. First comes general stuff:
  266.  
  267. @y
  268. First comes general stuff.
  269. In {\mc TURBO} \CEE/, we use |huge| pointers instead of large arrays.
  270. @^system dependencies@>
  271.  
  272. @f far int
  273. @f huge int
  274. @f HUGE int
  275. @#
  276. @z
  277. ------------------------------------------------------------------------------
  278. SYSTEM DEPENDENCIES
  279. @x l.33
  280. extern int phase; /* which phase are we in? */
  281. @y
  282. extern int phase; /* which phase are we in? */
  283. @#
  284. #ifdef __TURBOC__
  285. #define HUGE huge
  286. #else
  287. #define HUGE
  288. #endif
  289. @^system dependencies@>
  290. @z
  291. ------------------------------------------------------------------------------
  292. SYSTEM DEPENDENCIES, TRANSLATION
  293. @x l.35
  294. @ @<Include files@>=
  295. #include <stdio.h>
  296. @y
  297. @ Version~2.1 of the {\mc AMIGA} operating system introduced localization
  298. of programs and applications by means of ``language catalogs'' that contain
  299. replacement strings for terminal texts produced by suitably prepared programs.
  300. The complete \.{CWEB} system has been modified to accommodate this great idea
  301. and so the \.{cweb.h} header file with the original English strings is
  302. included in this section.  Other systems than the {\mc AMIGA} will have to do
  303. the language conversion by different means, so a little bit of care is to be
  304. taken with what follows.
  305. @^system dependencies@>
  306.  
  307. @f type int /* \.{type} becomes the pseudotype \&{type} */
  308. @#
  309. @d alloc_object(object,size,@!type)
  310.    if(!(object = (type *)malloc((size)*sizeof(type))))
  311.       fatal("",get_string(MSG_FATAL_CO85));
  312.  
  313. @<Include files@>=
  314. #include <stdio.h>
  315. @#
  316. #ifdef __TURBOC__
  317. #include <io.h>
  318. #endif
  319. @#
  320. #ifndef _AMIGA /* non-{\mc AMIGA} systems don't know about \.{<exec/types.h>} */
  321. typedef long int LONG; /* excerpt from \.{<exec/types.h>} */
  322. typedef char * STRPTR; /* ditto, but \UNIX/ says it's signed. */
  323. #define EXEC_TYPES_H 1 /* don't include \.{<exec/types.h>} in \.{"cweb.h"} */
  324. #endif
  325. @#
  326. #ifdef STRINGARRAY
  327. #undef STRINGARRAY /* don't include the string array |AppStrings| again */
  328. #endif
  329. #define get_string(n) AppStrings[n].as_Str
  330. @#
  331. #include "cweb.h"
  332. @#
  333. struct AppString
  334. {
  335.    LONG   as_ID;
  336.    STRPTR as_Str;
  337. };
  338. @#
  339. extern struct AppString AppStrings[];
  340. @z
  341. ------------------------------------------------------------------------------
  342. MEMORY ALLOCATION
  343. @x l.58
  344. char section_text[longest_name+1]; /* name being sought for */
  345. char *section_text_end = section_text+longest_name; /* end of |section_text| */
  346. @y
  347. char *section_text; /* name being sought for */
  348. char *section_text_end; /* end of |section_text| */
  349. @z
  350. ------------------------------------------------------------------------------
  351. MEMORY ALLOCATION
  352. @x l.73
  353. extern char buffer[]; /* where each line of input goes */
  354. @y
  355. extern char *buffer; /* where each line of input goes */
  356. @z
  357. ------------------------------------------------------------------------------
  358. ANSI
  359. @x l.79
  360. @d length(c) (c+1)->byte_start-(c)->byte_start /* the length of a name */
  361. @y
  362. @d length(c) (size_t)((c+1)->byte_start-(c)->byte_start) /* the length of a name */
  363. @z
  364. ------------------------------------------------------------------------------
  365. SYSTEM DEPENDENCIES, MEMORY ALLOCATION
  366. @x l.88
  367. typedef struct name_info {
  368.   char *byte_start; /* beginning of the name in |byte_mem| */
  369.   struct name_info *link;
  370.   union {
  371.     struct name_info *Rlink; /* right link in binary search tree for section
  372.       names */
  373.     char Ilk; /* used by identifiers in \.{CWEAVE} only */
  374.   } dummy;
  375.   char *equiv_or_xref; /* info corresponding to names */
  376. } name_info; /* contains information about an identifier or section name */
  377. typedef name_info *name_pointer; /* pointer into array of \&{name\_info}s */
  378. typedef name_pointer *hash_pointer;
  379. extern char byte_mem[]; /* characters of names */
  380. extern char *byte_mem_end; /* end of |byte_mem| */
  381. extern name_info name_dir[]; /* information about names */
  382. extern name_pointer name_dir_end; /* end of |name_dir| */
  383. extern name_pointer name_ptr; /* first unused position in |byte_start| */
  384. extern char *byte_ptr; /* first unused position in |byte_mem| */
  385. @y
  386. typedef struct name_info {
  387.   char HUGE *byte_start; /* beginning of the name in |byte_mem| */
  388.   struct name_info HUGE *link;
  389.   union {
  390.     struct name_info HUGE *Rlink; /* right link in binary search tree for section
  391.       names */  
  392.     char Ilk; /* used by identifiers in \.{WEAVE} only */
  393.   } dummy;
  394.   void HUGE *equiv_or_xref; /* info corresponding to names */
  395. } name_info; /* contains information about an identifier or section name */
  396. typedef name_info HUGE *name_pointer; /* pointer into array of |name_info|s */
  397. typedef name_pointer *hash_pointer;
  398. extern name_pointer name_dir; /* information about names */
  399. extern name_pointer name_dir_end; /* end of |name_dir| */
  400. extern name_pointer name_ptr; /* first unused position in |byte_start| */
  401. extern char HUGE *byte_mem; /* characters of names */
  402. extern char HUGE *byte_mem_end; /* end of |byte_mem| */
  403. extern char HUGE *byte_ptr; /* first unused position in |byte_mem| */
  404. #ifdef __TURBOC__
  405. extern void far *allocsafe(unsigned long,unsigned long);
  406. #endif
  407. @^system dependencies@>
  408. @z
  409. ------------------------------------------------------------------------------
  410. MEMORY ALLOCATION
  411. @x l.106
  412. extern name_pointer hash[]; /* heads of hash lists */
  413. @y
  414. extern name_pointer *hash; /* heads of hash lists */
  415. @z
  416. ------------------------------------------------------------------------------
  417. ANSI
  418. @x l.109
  419. extern name_pointer id_lookup(); /* looks up a string in the identifier table */
  420. extern name_pointer section_lookup(); /* finds section name */
  421. extern void print_section_name(), sprint_section_name();
  422. @y
  423. extern int names_match(name_pointer,char *,int,eight_bits);@/
  424. extern name_pointer id_lookup(char *,char *,char);
  425.    /* looks up a string in the identifier table */
  426. extern name_pointer prefix_lookup(char *,char *); /* finds section name given a prefix */
  427. extern name_pointer section_lookup(char *,char *,int);@/
  428. extern void init_node(name_pointer);@/
  429. extern void init_p(name_pointer,eight_bits);@/
  430. extern void print_prefix_name(name_pointer);@/
  431. extern void print_section_name(name_pointer);@/
  432. extern void sprint_section_name(char *,name_pointer);@/
  433. @z
  434. ------------------------------------------------------------------------------
  435. ANSI, TRANSLATION
  436. @x l.117
  437. @d fatal_message 3 /* |history| value when we had to stop prematurely */
  438. @d mark_harmless {if (history==spotless) history=harmless_message;}
  439. @d mark_error history=error_message
  440. @d confusion(s) fatal("! This can't happen: ",s)
  441.  
  442. @<Common...@>=
  443. extern history; /* indicates how bad this run was */
  444. extern err_print(); /* print error message and context */
  445. extern wrap_up(); /* indicate |history| and exit */
  446. extern void fatal(); /* issue error message and die */
  447. extern void overflow(); /* succumb because a table has overflowed */
  448. @y
  449. @d fatal_message 3 /* |history| value when we had to stop prematurely */
  450. @d mark_harmless {if (history==spotless) history=harmless_message;}
  451. @d mark_error history=error_message
  452. @d confusion(s) fatal(get_string(MSG_FATAL_CO66),s)
  453.  
  454. @<Common...@>=
  455. extern history; /* indicates how bad this run was */
  456. extern int wrap_up(void); /* indicate |history| and exit */
  457. extern void err_print(char *); /* prints error message and context */
  458. extern void fatal(char *,char *); /* issue error message and die */
  459. extern void overflow(char *); /* succumb because a table has overflowed */
  460. @z
  461. ------------------------------------------------------------------------------
  462. SYSTEM DEPENDENCIES
  463. @x l.131
  464. @d max_file_name_length 60
  465. @y
  466. @d max_file_name_length 256
  467. @z
  468. ------------------------------------------------------------------------------
  469. MEMORY ALLOCATION, OUTPUT
  470. @x l.139
  471. extern FILE *file[]; /* stack of non-change files */
  472. extern FILE *change_file; /* change file */
  473. extern char C_file_name[]; /* name of |C_file| */
  474. extern char tex_file_name[]; /* name of |tex_file| */
  475. extern char idx_file_name[]; /* name of |idx_file| */
  476. extern char scn_file_name[]; /* name of |scn_file| */
  477. extern char file_name[][max_file_name_length];
  478.   /* stack of non-change file names */
  479. extern char change_file_name[]; /* name of change file */
  480. extern line[]; /* number of current line in the stacked files */
  481. @y
  482. extern FILE **file; /* stack of non-change files */
  483. extern FILE *change_file; /* change file */
  484. extern char *C_file_name; /* name of |C_file| */
  485. extern char *tex_file_name; /* name of |tex_file| */
  486. extern char *idx_file_name; /* name of |idx_file| */
  487. extern char *scn_file_name; /* name of |scn_file| */
  488. extern char *check_file_name; /* name of |check_file| */
  489. extern char **file_name; /* stack of non-change file names */
  490. extern char *change_file_name; /* name of change file */
  491. extern char *use_language; /* prefix to \.{cwebmac.tex} in \TEX/ output */
  492. extern int *line; /* number of current line in the stacked files */
  493. @z
  494. ------------------------------------------------------------------------------
  495. ANSI
  496. @x l.153
  497. extern reset_input(); /* initialize to read the web file and change file */
  498. extern get_line(); /* inputs the next line */
  499. extern check_complete(); /* checks that all changes were picked up */
  500. @y
  501. extern boolean get_line(void); /* inputs the next line */
  502. extern void check_complete(void); /* checks that all changes were picked up */
  503. extern void reset_input(void); /* initialize to read the web file and change file */
  504. @z
  505. ------------------------------------------------------------------------------
  506. MEMORY ALLOCATION
  507. @x l.161
  508. extern boolean changed_section[]; /* is the section changed? */
  509. @y
  510. extern boolean *changed_section; /* is the section changed? */
  511. @z
  512. ------------------------------------------------------------------------------
  513. EXTENSIONS
  514. @x l.165
  515. @ Code related to command line arguments:
  516. @d show_banner flags['b'] /* should the banner line be printed? */
  517. @d show_progress flags['p'] /* should progress reports be printed? */
  518. @d show_happiness flags['h'] /* should lack of errors be announced? */
  519. @y
  520. @ Code related to command line arguments:
  521. @d show_banner flags['b'] /* should the banner line be printed? */
  522. @d show_happiness flags['h'] /* should lack of errors be announced? */
  523. @d show_progress flags['p'] /* should progress reports be printed? */
  524. @d indent_param_decl flags['i'] /* should formal parameter declarations be indented? */
  525. @d send_error_messages flags['m'] /* should {\mc AREXX} communication be used? */
  526. @d order_decl_stmt flags['o'] /* should declarations and statements be separated? */
  527. @z
  528. ------------------------------------------------------------------------------
  529. @x l.173
  530. extern boolean flags[]; /* an option for each 7-bit code */
  531. @y
  532. extern boolean flags[]; /* an option for each 8-bit code */
  533. @z
  534. ------------------------------------------------------------------------------
  535. OUTPUT
  536. @x l.186
  537. extern FILE *scn_file; /* where list of sections from \.{CWEAVE} goes */
  538. @y
  539. extern FILE *scn_file; /* where list of sections from \.{CWEAVE} goes */
  540. extern FILE *check_file; /* temporary output file */
  541. @z
  542. ------------------------------------------------------------------------------
  543. ANSI
  544. @x l.192
  545. extern void common_init();
  546. @y
  547. extern void common_init(void);
  548. extern void print_stats(void);
  549. @z
  550. ==============================================================================
  551. SYSTEM DEPENDENCIES
  552. @x l.151
  553.   eight_bits *tok_start; /* pointer into |tok_mem| */
  554. @y
  555.   eight_bits HUGE *tok_start; /* pointer into |tok_mem| */
  556. @z
  557. ------------------------------------------------------------------------------
  558. MEMORY ALLOCATION
  559. @x l.157
  560. text text_info[max_texts];
  561. text_pointer text_info_end=text_info+max_texts-1;
  562. @y
  563. text_pointer text_info;
  564. text_pointer text_info_end;
  565. @z
  566. ------------------------------------------------------------------------------
  567. MEMORY ALLOCATION, SYSTEM DEPENDENCIES
  568. @x l.160
  569. eight_bits tok_mem[max_toks];
  570. eight_bits *tok_mem_end=tok_mem+max_toks-1;
  571. eight_bits *tok_ptr; /* first unused position in |tok_mem| */
  572. @y
  573. eight_bits HUGE *tok_mem;
  574. eight_bits HUGE *tok_mem_end;
  575. eight_bits HUGE *tok_ptr; /* first unused position in |tok_mem| */
  576. @z
  577. ------------------------------------------------------------------------------
  578. MEMORY ALLOCATION, SYSTEM DEPENDENCIES
  579. @x l.165
  580. text_info->tok_start=tok_ptr=tok_mem;
  581. @y
  582. alloc_object(section_text,longest_name+1,char);
  583. section_text_end = section_text + longest_name;
  584. alloc_object(text_info,max_texts,text);
  585. text_info_end = text_info + max_texts - 1;
  586. #ifdef __TURBOC__
  587. #undef max_toks
  588. #define max_toks 170000
  589. tok_mem=(eight_bits HUGE *)allocsafe(max_toks,sizeof(*tok_mem));
  590. #else
  591. alloc_object(tok_mem,max_toks,eight_bits);
  592. #endif
  593. tok_mem_end = tok_mem + max_toks - 1;
  594. text_info->tok_start=tok_ptr=tok_mem;
  595. alloc_object(stack,stack_size+1,output_state);
  596. stack_end = stack + stack_size;
  597. @^system dependencies@>
  598. @z
  599. ------------------------------------------------------------------------------
  600. SYSTEM DEPENDENCIES
  601. @x l.175
  602. name_dir->equiv=(char *)text_info; /* the undefined section has no replacement text */
  603. @y
  604. name_dir->equiv=(void HUGE *)text_info; /* the undefined section has no replacement text */
  605. @z
  606. ------------------------------------------------------------------------------
  607. ANSI
  608. @x l.181
  609. int names_match(p,first,l)
  610. name_pointer p; /* points to the proposed match */
  611. char *first; /* position of first character of string */
  612. int l; /* length of identifier */
  613. @y
  614. int names_match(@t\1\1@>
  615.   name_pointer p, /* points to the proposed match */
  616.   char *first, /* position of first character of string */
  617.   int l, /* length of identifier */
  618.   eight_bits dummy@t\2\2@>) /* not used by \.{TANGLE} */
  619. @z
  620. ------------------------------------------------------------------------------
  621. ANSI
  622. @x l.196
  623. void
  624. init_node(node)
  625. name_pointer node;
  626. @y
  627. void init_node(name_pointer node)
  628. @z
  629. ------------------------------------------------------------------------------
  630. SYSTEM DEPENDENCIES
  631. @x l.200
  632.     node->equiv=(char *)text_info;
  633. @y
  634.     node->equiv=(void HUGE *)text_info;
  635. @z
  636. ------------------------------------------------------------------------------
  637. ANSI
  638. @x l.202
  639. void
  640. init_p() {}
  641. @y
  642. void init_p(name_pointer dummy1,eight_bits dummy2)
  643. {}
  644. @z
  645. ------------------------------------------------------------------------------
  646. ANSI
  647. @x l.258
  648. void
  649. store_two_bytes(x)
  650. sixteen_bits x;
  651. @y
  652. static void store_two_bytes(sixteen_bits x)
  653. @z
  654. ------------------------------------------------------------------------------
  655. TRANSLATION
  656. @x l.262
  657.   if (tok_ptr+2>tok_mem_end) overflow("token");
  658. @y
  659.   if (tok_ptr+2>tok_mem_end) overflow(get_string(MSG_OVERFLOW_CT26));
  660. @z
  661. ------------------------------------------------------------------------------
  662. SYSTEM DEPENDENCIES
  663. @x l.295
  664.   eight_bits *end_field; /* ending location of replacement text */
  665.   eight_bits *byte_field; /* present location within replacement text */
  666. @y
  667.   eight_bits HUGE *end_field; /* ending location of replacement text */
  668.   eight_bits HUGE *byte_field; /* present location within replacement text */
  669. @z
  670. ------------------------------------------------------------------------------
  671. MEMORY ALLOCATION
  672. @x l.312
  673. output_state stack[stack_size+1]; /* info for non-current levels */
  674. stack_pointer stack_ptr; /* first unused location in the output state stack */
  675. stack_pointer stack_end=stack+stack_size; /* end of |stack| */
  676. @y
  677. stack_pointer stack; /* info for non-current levels */
  678. stack_pointer stack_end; /* end of |stack| */
  679. stack_pointer stack_ptr; /* first unused location in the output state stack */
  680. @z
  681. ------------------------------------------------------------------------------
  682. ANSI, TRANSLATION
  683. @x l.334
  684. void
  685. push_level(p) /* suspends the current level */
  686. name_pointer p;
  687. {
  688.   if (stack_ptr==stack_end) overflow("stack");
  689. @y
  690. static void push_level(name_pointer p) /* suspends the current level */
  691. {
  692.   if (stack_ptr==stack_end) overflow(get_string(MSG_OVERFLOW_CT30));
  693. @z
  694. ------------------------------------------------------------------------------
  695. ANSI
  696. @x l.353
  697. void
  698. pop_level(flag) /* do this when |cur_byte| reaches |cur_end| */
  699. int flag; /* |flag==0| means we are in |output_defs| */
  700. @y
  701. static void pop_level(int flag) /* do this when |cur_byte| reaches |cur_end| */
  702. @z
  703. ------------------------------------------------------------------------------
  704. ANSI
  705. @x l.389
  706. void
  707. get_output() /* sends next token to |out_char| */
  708. @y
  709. static void get_output(void) /* sends next token to |out_char| */
  710. @z
  711. ------------------------------------------------------------------------------
  712. SYSTEM DEPENDENCIES, TRANSLATION
  713. @x l.423
  714.   if ((a+name_dir)->equiv!=(char *)text_info) push_level(a+name_dir);
  715.   else if (a!=0) {
  716.     printf("\n! Not present: <");
  717. @y
  718.   if ((a+name_dir)->equiv!=(void HUGE *)text_info) push_level(a+name_dir);
  719.   else if (a!=0) {
  720.     printf(get_string(MSG_ERROR_CT34));
  721. @z
  722. ------------------------------------------------------------------------------
  723. ANSI
  724. @x l.476
  725. void
  726. flush_buffer() /* writes one line to output file */
  727. @y
  728. static void flush_buffer(void) /* writes one line to output file */
  729. @z
  730. ------------------------------------------------------------------------------
  731. MEMORY ALLOCATION
  732. @x l.497
  733. name_pointer output_files[max_files];
  734. name_pointer *cur_out_file, *end_output_files, *an_output_file;
  735. char cur_section_name_char; /* is it |'<'| or |'('| */
  736. char output_file_name[longest_name]; /* name of the file */
  737.  
  738. @ We make |end_output_files| point just beyond the end of
  739. |output_files|. The stack pointer
  740. |cur_out_file| starts out there. Every time we see a new file, we
  741. decrement |cur_out_file| and then write it in.
  742. @<Set initial...@>=
  743. cur_out_file=end_output_files=output_files+max_files;
  744. @y
  745. name_pointer *output_files;
  746. name_pointer *cur_out_file, *end_output_files, *an_output_file;
  747. char cur_section_name_char; /* is it |'<'| or |'('| */
  748. char *output_file_name; /* name of the file */
  749.  
  750. @ We make |end_output_files| point just beyond the end of
  751. |output_files|. The stack pointer
  752. |cur_out_file| starts out there. Every time we see a new file, we
  753. decrement |cur_out_file| and then write it in.
  754.  
  755. @<Set initial...@>=
  756. alloc_object(output_files,max_files,name_pointer);
  757. alloc_object(output_file_name,longest_name,char);
  758. cur_out_file=end_output_files=output_files+max_files;
  759. @z
  760. ------------------------------------------------------------------------------
  761. TRANSLATION
  762. @x l.519
  763.       overflow("output files");
  764. @y
  765.       overflow(get_string(MSG_OVERFLOW_CT40));
  766. @z
  767. ------------------------------------------------------------------------------
  768. ANSI
  769. @x l.527
  770. @<Predecl...@>=
  771. void phase_two();
  772.  
  773. @ @c
  774. void
  775. phase_two () {
  776. @y
  777. @<Predecl...@>=
  778. static void phase_two(void);
  779.  
  780. @ @c
  781. static void phase_two (void) {
  782. @z
  783. ------------------------------------------------------------------------------
  784. TRANSLATION
  785. @x l.538
  786.     printf("\n! No program text was specified."); mark_harmless;
  787. @y
  788.     printf(get_string(MSG_WARNING_CT42)); mark_harmless;
  789. @z
  790. ------------------------------------------------------------------------------
  791. TRANSLATION
  792. @x l.544
  793.         printf("\nWriting the output file (%s):",C_file_name);
  794. @y
  795.         printf(get_string(MSG_PROGRESS_CT42_1),C_file_name);
  796. @z
  797. ------------------------------------------------------------------------------
  798. TRANSLATION
  799. @x l.548
  800.         printf("\nWriting the output files:");
  801. @y
  802.         printf(get_string(MSG_PROGRESS_CT42_2));
  803. @z
  804. ------------------------------------------------------------------------------
  805. TRANSLATION
  806. @x l.558
  807.     if(show_happiness) printf("\nDone.");
  808. @y
  809.     if(show_happiness) printf(get_string(MSG_PROGRESS_CT42_3));
  810. @z
  811. ------------------------------------------------------------------------------
  812. TRANSLATION, OUTPUT
  813. @x l.566
  814. @<Write all the named output files@>=
  815. for (an_output_file=end_output_files; an_output_file>cur_out_file;) {
  816.     an_output_file--;
  817.     sprint_section_name(output_file_name,*an_output_file);
  818.     fclose(C_file);
  819.     C_file=fopen(output_file_name,"w");
  820.     if (C_file ==0) fatal("! Cannot open output file:",output_file_name);
  821. @.Cannot open output file@>
  822.     printf("\n(%s)",output_file_name); update_terminal;
  823.     cur_line=1;
  824.     stack_ptr=stack+1;
  825.     cur_name= (*an_output_file);
  826.     cur_repl= (text_pointer)cur_name->equiv;
  827.     cur_byte=cur_repl->tok_start;
  828.     cur_end=(cur_repl+1)->tok_start;
  829.     while (stack_ptr > stack) get_output();
  830.     flush_buffer();
  831. }
  832. @y
  833. @<Write all the named output files@>=
  834. fclose(C_file); C_file=NULL;
  835. @<Update the primary result when it has changed@>@;
  836. for (an_output_file=end_output_files; an_output_file>cur_out_file;) {
  837.     an_output_file--;
  838.     sprint_section_name(output_file_name,*an_output_file);
  839.     C_file=fopen(check_file_name,"w");
  840.     if (C_file ==0) fatal(get_string(MSG_FATAL_CO78),check_file_name);
  841. @.Cannot open output file@>
  842.     printf("\n(%s)",output_file_name); update_terminal;
  843.     cur_line=1;
  844.     stack_ptr=stack+1;
  845.     cur_name= (*an_output_file);
  846.     cur_repl= (text_pointer)cur_name->equiv;
  847.     cur_byte=cur_repl->tok_start;
  848.     cur_end=(cur_repl+1)->tok_start;
  849.     while (stack_ptr > stack) get_output();
  850.     flush_buffer(); fclose(C_file); C_file=NULL;
  851.     @<Update the secondary results when they have changed@>@;
  852. }
  853. check_file_name=NULL; /* We want to get rid of the temporary file */
  854. @z
  855. ------------------------------------------------------------------------------
  856. ANSI
  857. @x l.596
  858. @ @<Predecl...@>=
  859. void output_defs();
  860.  
  861. @ @c
  862. void
  863. output_defs()
  864. @y
  865. @ @<Predecl...@>=
  866. static void output_defs(void);
  867.  
  868. @ @c
  869. static void output_defs(void)
  870. @z
  871. ------------------------------------------------------------------------------
  872. TRANSLATION
  873. @x l.623
  874.           else if (a<050000) { confusion("macro defs have strange char");}
  875. @y
  876.           else if (a<050000) { confusion(get_string(MSG_CONFUSION_CT47));}
  877. @z
  878. ------------------------------------------------------------------------------
  879. ANSI, SYSTEM DEPENDENCIES
  880. @x l.642
  881. @<Predecl...@>=
  882. static void out_char();
  883.  
  884. @ @c
  885. static void
  886. out_char(cur_char)
  887. eight_bits cur_char;
  888. {
  889.   char *j, *k; /* pointer into |byte_mem| */
  890. @y
  891. @<Predecl...@>=
  892. static void out_char(eight_bits);
  893.  
  894. @ @c
  895. static void out_char(eight_bits cur_char)
  896. {
  897.   char HUGE *j;
  898.   char HUGE *k; /* pointer into |byte_mem| */
  899. @z
  900. ------------------------------------------------------------------------------
  901. MEMORY ALLOCATION
  902. @x l.701
  903. char translit[128][translit_length];
  904.  
  905. @ @<Set init...@>=
  906. {
  907.   int i;
  908.   for (i=0;i<128;i++) sprintf(translit[i],"X%02X",(unsigned)(128+i));
  909. }
  910. @y
  911. char **translit;
  912.  
  913. @ @<Set init...@>=
  914. {
  915.   int i;
  916.   alloc_object(translit,128,char *);
  917.   for(i=0; i<128; i++)
  918.     alloc_object(translit[i],translit_length,char);
  919.   for (i=0;i<128;i++)
  920.     sprintf(translit[i],"X%02X",(unsigned)(128+i));
  921. }
  922. @z
  923. ------------------------------------------------------------------------------
  924. MEMORY ALLOCATION
  925. @x l.777
  926. eight_bits ccode[256]; /* meaning of a char following \.{@@} */
  927.  
  928. @ @<Set ini...@>= {
  929.   int c; /* must be |int| so the |for| loop will end */
  930. @y
  931. eight_bits *ccode; /* meaning of a char following \.{@@} */
  932.  
  933. @ @<Set ini...@>= {
  934.   int c; /* must be |int| so the |for| loop will end */
  935.   alloc_object(ccode,256,eight_bits);
  936. @z
  937. ------------------------------------------------------------------------------
  938. ANSI
  939. @x l.801
  940. eight_bits
  941. skip_ahead() /* skip to next control code */
  942. @y
  943. static eight_bits skip_ahead(void) /* skip to next control code */
  944. @z
  945. ------------------------------------------------------------------------------
  946. ANSI
  947. @x l.836
  948. int skip_comment(is_long_comment) /* skips over comments */
  949. boolean is_long_comment;
  950. @y
  951. static int skip_comment(boolean is_long_comment) /* skips over comments */
  952. @z
  953. ------------------------------------------------------------------------------
  954. TRANSLATION
  955. @x l.845
  956.           err_print("! Input ended in mid-comment");
  957. @y
  958.           err_print(get_string(MSG_ERROR_CT60_1));
  959. @z
  960. ------------------------------------------------------------------------------
  961. TRANSLATION
  962. @x l.858
  963.         err_print("! Section name ended in mid-comment"); loc--;
  964. @y
  965.         err_print(get_string(MSG_ERROR_CT60_2)); loc--;
  966. @z
  967. ------------------------------------------------------------------------------
  968. ANSI
  969. @x l.887
  970. eight_bits
  971. get_next() /* produces the next input token */
  972. @y
  973. static eight_bits get_next(void) /* produces the next input token */
  974. @z
  975. ------------------------------------------------------------------------------
  976. TRANSLATION
  977. @x l.1005
  978.         err_print("! String didn't end"); loc=limit; break;
  979. @y
  980.         err_print(get_string(MSG_ERROR_CT67_1)); loc=limit; break;
  981. @z
  982. ------------------------------------------------------------------------------
  983. TRANSLATION
  984. @x l.1009
  985.         err_print("! Input ended in middle of string"); loc=buffer; break;
  986. @y
  987.         err_print(get_string(MSG_ERROR_CT67_2)); loc=buffer; break;
  988. @z
  989. ------------------------------------------------------------------------------
  990. TRANSLATION
  991. @x l.1027
  992.     printf("\n! String too long: ");
  993. @y
  994.     printf(get_string(MSG_ERROR_CT67_3));
  995. @z
  996. ------------------------------------------------------------------------------
  997. TRANSLATION
  998. @x l.1044
  999.     case translit_code: err_print("! Use @@l in limbo only"); continue;
  1000. @y
  1001.     case translit_code: err_print(get_string(MSG_ERROR_CT68_1)); continue;
  1002. @z
  1003. ------------------------------------------------------------------------------
  1004. TRANSLATION
  1005. @x l.1049
  1006.         err_print("! Double @@ should be used in control text");
  1007. @y
  1008.         err_print(get_string(MSG_ERROR_CT68_2));
  1009. @z
  1010. ------------------------------------------------------------------------------
  1011. TRANSLATION
  1012. @x l.1075
  1013.         err_print("! Double @@ should be used in ASCII constant");
  1014. @y
  1015.         err_print(get_string(MSG_ERROR_CT69));
  1016. @z
  1017. ------------------------------------------------------------------------------
  1018. TRANSLATION
  1019. @x l.1081
  1020.         err_print("! String didn't end"); loc=limit-1; break;
  1021. @y
  1022.         err_print(get_string(MSG_ERROR_CT67_1)); loc=limit-1; break;
  1023. @z
  1024. ------------------------------------------------------------------------------
  1025. TRANSLATION
  1026. @x l.1112
  1027.     err_print("! Input ended in section name");
  1028. @y
  1029.     err_print(get_string(MSG_ERROR_CT72_1));
  1030. @z
  1031. ------------------------------------------------------------------------------
  1032. TRANSLATION
  1033. @x l.1125
  1034.   printf("\n! Section name too long: ");
  1035. @y
  1036.   printf(get_string(MSG_ERROR_CT72_2));
  1037. @z
  1038. ------------------------------------------------------------------------------
  1039. TRANSLATION
  1040. @x l.1139
  1041.     err_print("! Section name didn't end"); break;
  1042. @y
  1043.     err_print(get_string(MSG_ERROR_CT73_1)); break;
  1044. @z
  1045. ------------------------------------------------------------------------------
  1046. TRANSLATION
  1047. @x l.1143
  1048.     err_print("! Nesting of section names not allowed"); break;
  1049. @y
  1050.     err_print(get_string(MSG_ERROR_CT73_2)); break;
  1051. @z
  1052. ------------------------------------------------------------------------------
  1053. TRANSLATION
  1054. @x l.1157
  1055.   if (loc>=limit) err_print("! Verbatim string didn't end");
  1056. @y
  1057.   if (loc>=limit) err_print(get_string(MSG_ERROR_CT74));
  1058. @z
  1059. ------------------------------------------------------------------------------
  1060. TRANSLATION
  1061. @x l.1183
  1062. @d app_repl(c)  {if (tok_ptr==tok_mem_end) overflow("token"); *tok_ptr++=c;}
  1063. @y
  1064. @d app_repl(c)
  1065.   {if (tok_ptr==tok_mem_end)
  1066.      overflow(get_string(MSG_OVERFLOW_CT26));
  1067.    *tok_ptr++=c;}
  1068. @z
  1069. ------------------------------------------------------------------------------
  1070. ANSI
  1071. @x l.1190
  1072. void
  1073. scan_repl(t) /* creates a replacement text */
  1074. eight_bits t;
  1075. @y
  1076. static void scan_repl(eight_bits t) /* creates a replacement text */
  1077. @z
  1078. ------------------------------------------------------------------------------
  1079. TRANSLATION
  1080. @x l.1207
  1081.   if (text_ptr>text_info_end) overflow("text");
  1082. @y
  1083.   if (text_ptr>text_info_end) overflow(get_string(MSG_OVERFLOW_CT76));
  1084. @z
  1085. ------------------------------------------------------------------------------
  1086. TRANSLATION
  1087. @x l.1248
  1088.     err_print("! @@d, @@f and @@c are ignored in C text"); continue;
  1089. @y
  1090.     err_print(get_string(MSG_ERROR_CT78)); continue;
  1091. @z
  1092. ------------------------------------------------------------------------------
  1093. TRANSLATION
  1094. @x l.1258
  1095.   if (*try_loc=='=') err_print ("! Missing `@@ ' before a named section");
  1096. @y
  1097.   if (*try_loc=='=') err_print (get_string(MSG_ERROR_CT79));
  1098. @z
  1099. ------------------------------------------------------------------------------
  1100. TRANSLATION
  1101. @x l.1269
  1102.       else err_print("! Double @@ should be used in string");
  1103. @y
  1104.       else err_print(get_string(MSG_ERROR_CT80));
  1105. @z
  1106. ------------------------------------------------------------------------------
  1107. TRANSLATION
  1108. @x l.1316
  1109.     default: err_print("! Unrecognized escape sequence");
  1110. @y
  1111.     default: err_print(get_string(MSG_ERROR_CT81));
  1112. @z
  1113. ------------------------------------------------------------------------------
  1114. ANSI
  1115. @x l.1343
  1116. void
  1117. scan_section()
  1118. @y
  1119. static void scan_section(void)
  1120. @z
  1121. ------------------------------------------------------------------------------
  1122. TRANSLATION
  1123. @x l.1391
  1124.     err_print("! Definition flushed, must start with identifier");
  1125. @y
  1126.     err_print(get_string(MSG_ERROR_CT85));
  1127. @z
  1128. ------------------------------------------------------------------------------
  1129. SYSTEM DEPENDENCIES
  1130. @x l.1431
  1131. else if (p->equiv==(char *)text_info) p->equiv=(char *)cur_text;
  1132. @y
  1133. else if (p->equiv==(void HUGE *)text_info) p->equiv=(void HUGE *)cur_text;
  1134. @z
  1135. ------------------------------------------------------------------------------
  1136. ANSI
  1137. @x l.1442
  1138. @ @<Predec...@>=
  1139. void phase_one();
  1140.  
  1141. @ @c
  1142. void
  1143. phase_one() {
  1144. @y
  1145. @ @<Predec...@>=
  1146. static void phase_one(void);
  1147.  
  1148. @ @c
  1149. static void phase_one(void) {
  1150. @z
  1151. ------------------------------------------------------------------------------
  1152. ANSI
  1153. @x l.1460
  1154. @<Predecl...@>=
  1155. void skip_limbo();
  1156.  
  1157. @ @c
  1158. void
  1159. skip_limbo()
  1160. @y
  1161. @<Predecl...@>=
  1162. static void skip_limbo(void);
  1163.  
  1164. @ @c
  1165. static void skip_limbo(void)
  1166. @z
  1167. ------------------------------------------------------------------------------
  1168. TRANSLATION
  1169. @x l.1481
  1170.             err_print("! Double @@ should be used in control text");
  1171. @y
  1172.             err_print(get_string(MSG_ERROR_CT68_2));
  1173. @z
  1174. ------------------------------------------------------------------------------
  1175. TRANSLATION
  1176. @x l.1485
  1177.         default: err_print("! Double @@ should be used in limbo");
  1178. @y
  1179.         default: err_print(get_string(MSG_ERROR_CT93));
  1180. @z
  1181. ------------------------------------------------------------------------------
  1182. TRANSLATION
  1183. @x l.1497
  1184.     err_print("! Improper hex number following @@l");
  1185. @y
  1186.     err_print(get_string(MSG_ERROR_CT94_1));
  1187. @z
  1188. ------------------------------------------------------------------------------
  1189. TRANSLATION
  1190. @x l.1507
  1191.       err_print("! Replacement string in @@l too long");
  1192. @y
  1193.       err_print(get_string(MSG_ERROR_CT94_2));
  1194. @z
  1195. ------------------------------------------------------------------------------
  1196. ANSI
  1197. @x l.1510
  1198.       strncpy(translit[i-0200],beg,loc-beg);
  1199. @y
  1200.       strncpy(translit[i-0200],beg,(size_t)(loc-beg));
  1201. @z
  1202. ------------------------------------------------------------------------------
  1203. ANSI, TRANSLATION
  1204. @x l.1515
  1205. @ Because on some systems the difference between two pointers is a |long|
  1206. but not an |int|, we use \.{\%ld} to print these quantities.
  1207.  
  1208. @c
  1209. void
  1210. print_stats() {
  1211.   printf("\nMemory usage statistics:\n");
  1212.   printf("%ld names (out of %ld)\n",
  1213.           (long)(name_ptr-name_dir),(long)max_names);
  1214.   printf("%ld replacement texts (out of %ld)\n",
  1215.           (long)(text_ptr-text_info),(long)max_texts);
  1216.   printf("%ld bytes (out of %ld)\n",
  1217.           (long)(byte_ptr-byte_mem),(long)max_bytes);
  1218.   printf("%ld tokens (out of %ld)\n",
  1219.           (long)(tok_ptr-tok_mem),(long)max_toks);
  1220. }
  1221. @y
  1222. @ {\mc ANSI C} declares the difference between two pointers to be of type
  1223. |ptrdiff_t| which equals |long| on (almost) all systems instead of |int|,
  1224. so we use \.{\%ld} to print these quantities and cast them to |long|
  1225. explicitly.
  1226.  
  1227. @c
  1228. void print_stats(void) {
  1229.   printf(get_string(MSG_STATS_CT95_1));
  1230.   printf(get_string(MSG_STATS_CT95_2),
  1231.           (long)(name_ptr-name_dir),(long)max_names);
  1232.   printf(get_string(MSG_STATS_CT95_3),
  1233.           (long)(text_ptr-text_info),(long)max_texts);
  1234.   printf(get_string(MSG_STATS_CT95_4),
  1235.           (long)(byte_ptr-byte_mem),(long)max_bytes);
  1236.   printf(get_string(MSG_STATS_CT95_5),
  1237.           (long)(tok_ptr-tok_mem),(long)max_toks);
  1238. }
  1239. @z
  1240. ------------------------------------------------------------------------------
  1241. ANSI, SYSTEM DEPENDENCIES, OUTPUT
  1242. @x l.1532
  1243. @** Index.
  1244. @y
  1245. @** Function declarations.  Here are declarations---conforming to
  1246. {\mc ANSI~C}---of all functions in this code, as far as they are
  1247. not already in |"common.h"|.  These are private to \.{CTANGLE}.
  1248.  
  1249. @<Predecl...@>=
  1250. static eight_bits get_next(void);@/
  1251. static eight_bits skip_ahead(void);@/
  1252. static int skip_comment(boolean);@/
  1253. static void flush_buffer(void);@/
  1254. static void get_output(void);@/
  1255. static void pop_level(int);@/
  1256. static void push_level(name_pointer);@/
  1257. static void scan_repl(eight_bits);@/
  1258. static void scan_section(void);@/
  1259. static void store_two_bytes(sixteen_bits);
  1260.  
  1261. @* Version information.  The {\mc AMIGA} operating system provides the
  1262. `version' command and good programs answer with some informations about
  1263. their creation date and their current version.
  1264. @^system dependencies@>
  1265.  
  1266. @<Glob...@>=
  1267. #ifdef __SASC
  1268. const char Version[] = "$VER: CTangle 3.3 [p11] ("__DATE__", "__TIME__")\n";
  1269. #endif
  1270.  
  1271. @* Output file update.  Most \CEE/ projects are controlled by a
  1272. \.{makefile} which automatically takes care of the temporal dependecies
  1273. between the different source modules.  It is suitable that \.{CWEB} doesn't
  1274. create new output for all existing files, when there are only changes to
  1275. some of them. Thus the \.{make} process will only recompile those modules
  1276. where necessary. The idea and basic implementation of this mechanism can
  1277. be found in the program \.{NUWEB} by Preston Briggs, to whom credit is due.
  1278.  
  1279. @d free_object(object)
  1280.    if(object) {
  1281.       free(object);
  1282.       object=NULL;
  1283.       }
  1284.  
  1285. @<Update the primary result...@>=
  1286. if(C_file=fopen(C_file_name,"r")) {
  1287.   char *x,*y;
  1288.   int x_size,y_size;
  1289.  
  1290.   if(!(check_file=fopen(check_file_name,"r")))
  1291.     fatal(get_string(MSG_FATAL_CO78),check_file_name);
  1292.  
  1293.   alloc_object(x,BUFSIZ,char);
  1294.   alloc_object(y,BUFSIZ,char);
  1295.  
  1296.   @<Compare the temporary output to the previous output@>@;
  1297.  
  1298.   fclose(C_file); C_file=NULL;
  1299.   fclose(check_file); check_file=NULL;
  1300.  
  1301.   @<Create the primary output depending on the comparison@>@;
  1302.  
  1303.   free_object(y);
  1304.   free_object(x);
  1305.   }
  1306. else
  1307.   rename(check_file_name,C_file_name); /* This was the first run */
  1308.  
  1309. @ We hope that this runs fast on most systems.
  1310.  
  1311. @<Compare the temp...@>=
  1312. do {
  1313.   x_size = fread(x,1,BUFSIZ,C_file);
  1314.   y_size = fread(y,1,BUFSIZ,check_file);
  1315.   } while((x_size == y_size) && !memcmp(x,y,x_size) &&
  1316.           !feof(C_file) && !feof(check_file));
  1317.  
  1318. @ Note the superfluous call to |remove| before |rename|.  We're using it to
  1319. get around a bug in some implementations of |rename|.
  1320.  
  1321. @<Create the primary output...@>=
  1322. if((x_size != y_size) || memcmp(x,y,x_size)) {
  1323.   remove(C_file_name);
  1324.   rename(check_file_name,C_file_name);
  1325.   }
  1326. else
  1327.   remove(check_file_name);
  1328.  
  1329. @ @<Update the secondary results...@>=
  1330. if(C_file=fopen(output_file_name,"r")) {
  1331.   char *x,*y;
  1332.   int x_size,y_size;
  1333.  
  1334.   if(!(check_file=fopen(check_file_name,"r")))
  1335.     fatal(get_string(MSG_FATAL_CO78),check_file_name);
  1336.  
  1337.   alloc_object(x,BUFSIZ,char);
  1338.   alloc_object(y,BUFSIZ,char);
  1339.  
  1340.   @<Compare the temp...@>@;
  1341.  
  1342.   fclose(C_file); C_file=NULL;
  1343.   fclose(check_file); check_file=NULL;
  1344.  
  1345.   @<Create the secondary output depending on the comparison@>@;
  1346.  
  1347.   free_object(y);
  1348.   free_object(x);
  1349.   }
  1350. else
  1351.   rename(check_file_name,output_file_name); /* This was the first run */
  1352.  
  1353. @ Again, we use a call to |remove| before |rename|.
  1354.  
  1355. @<Create the secondary output...@>=
  1356.   if((x_size != y_size) || memcmp(x,y,x_size)) {
  1357.     remove(output_file_name);
  1358.     rename(check_file_name,output_file_name);
  1359.     }
  1360.   else
  1361.     remove(check_file_name); /* The output remains untouched */
  1362.  
  1363. @** Index.
  1364. @z
  1365. ------------------------------------------------------------------------------
  1366.