home *** CD-ROM | disk | FTP | other *** search
- -*-Web-*-
- This file, COMMON-P.CH, is part of CWEB-p.
- It is a changefile for COMMON.H, Version 3.0.
-
- Authors and Contributors:
- (H2B) Hans-Hermann Bode, Universität Osnabrück,
- (hhbode@@dosuni1.rz.uni-osnabrueck.de or HHBODE@@DOSUNI1.BITNET).
-
- (KG) Klaus Guntermann, TH Darmstadt,
- (guntermann@@iti.informatik.th-darmstadt.de).
-
- (AS) Andreas Scherer,
- Abt-Wolf-Straße 17, 96215 Lichtenfels, Germany.
-
- (CS) Carsten Steger, Universität München,
- carsten.steger@informatik.tu-muenchen.de
-
- Caveat utilitor: Some of the source code introduced by this change file is
- made conditional to the use of specific compilers on specific systems.
- This applies to places marked with `#ifdef __TURBOC__' and `#ifdef _AMIGA'.
-
- This program is distributed WITHOUT ANY WARRANTY, express or implied.
-
- The following copyright notice extends to this changefile only, not to
- the masterfile COMMON.W.
-
- Copyright (C) 1993 Andreas Scherer
- Copyright (C) 1991, 1993 Carsten Steger
- Copyright (C) 1991, 1992, 1993 Hans-Hermann Bode
-
- Permission is granted to make and distribute verbatim copies of this
- document provided that the copyright notice and this permission notice
- are preserved on all copies.
-
- Permission is granted to copy and distribute modified versions of this
- document under the conditions for verbatim copying, provided that the
- entire resulting derived work is distributed under the terms of a
- permission notice identical to this one.
-
- Version history:
-
- Version Date Author Comment
- a1/t1 10 Oct 1991 H2B First attempt for COMMON.W 2.0.
- p2 13 Feb 1992 H2B Updated for COMMON.W 2.1, ANSI and Turbo
- changefiles merged together.
- p3 16 Apr 1992 H2B Updated for COMMON.W 2.2, change option for
- |@@i| completed.
- p4 22 Jun 1992 H2B Updated for COMMON.W 2.4, getting INCLUDEDIR
- from environment variable CWEBINCLUDE.
- p5 19 Jul 1992 H2B string.h included, usage message extended.
- p5a 24 Jul 1992 KG adaptions for other ANSI C compiler
- p5b 28 Jul 1992 H2B Remaining headers converted to ANSI style.
- p5c 30 Jul 1992 KG removed comments used after #endif
- p6 06 Sep 1992 H2B Updated for COMMON.W 2.7.
- p6a 15 Mar 1993 AS adaptions for SAS/C 6.0 compiler
- p6b 28 Jul 1993 AS path delimiters are `/' or `:' for AMIGA
- 31 Aug 1993 AS return codes extended to AMIGA values
- p6c 04 Sep 1993 AS path searching with CWEBINCLUDE
- p6d 09 Oct 1993 AS Updated for COMMON.W 2.8. (This was p7 for me)
- p7 06 Nov 1992 H2B Converted to master change file, updated for
- common.w 2.8. [Not released.]
- p7.5 29 Nov 1992 H2B Updated for common.w 2.9beta. [Not released.]
- p8 04 Dec 1992 H2B Updated for common.w 2.9++ (stuff went into
- the source file). [Not released.]
- p8a 10 Mar 1993 H2B Restructured for public release.
- [Not released.]
- p8b 15 Apr 1993 H2B Updated for common.w 3.0beta. [Not released.]
- p8c 21 Jun 1993 H2B Updated for final common.w 3.0.
- p8d 26 Oct 1993 AS Incorporated with Amiga version 2.8 [p7] and
- updated to version 3.0.
- ------------------------------------------------------------------------------
- @x l.1
- % This file is part of CWEB.
- % This program by Silvio Levy and Donald E. Knuth
- % is based on a program by Knuth.
- % It is distributed WITHOUT ANY WARRANTY, express or implied.
- % Version 3.0 --- June 1993
-
- % Copyright (C) 1987,1990,1993 Silvio Levy and Donald E. Knuth
- @y
- % This file, common.w, is part of CWEB-p.
- % This program by Silvio Levy and Donald E. Knuth
- % is based on a program by Knuth.
- % It is distributed WITHOUT ANY WARRANTY, express or implied.
- % Version 2.4 --- Don Knuth, June 1992
- % Version 2.4 [p5] --- Hans-Hermann Bode, July 1992
- % Version 2.4 [p5a] --- Klaus Guntermann, July 1992
- % Version 2.4 [p5b] --- Hans-Hermann Bode, July 1992
- % Version 2.4 [p5c] --- Klaus Guntermann, July 1992
- % Version 2.7 [p6] --- Hans-Hermann Bode, September 1992
- % Version 2.7 [p6a] --- Andreas Scherer, March 1993
- % Version 2.7 [p6b] --- Andreas Scherer, August 1993
- % Version 2.7 [p6c] --- Andreas Scherer, September 1993
- % Version 2.8 --- Don Knuth, June 1992
- % Version 2.8 [p7] --- Andreas Scherer, October 1993
- % Version 3.0 --- Don Knuth, June 1993
- % Version 3.0 [p8c] --- Hans-Hermann Bode, June 1993
- % Version 3.0 [p8d] --- Andreas Scherer, October 1993
-
- % Copyright (C) 1987,1990,1993 Silvio Levy and Donald E. Knuth
- % Copyright (C) 1991,1992,1993 Hans-Hermann Bode
- % Copyright (C) 1991,1993 Carsten Steger
- % Copyright (C) 1993 Andreas Scherer
- @z
- ------------------------------------------------------------------------------
- @x l.20
- \def\title{Common code for CTANGLE and CWEAVE (Version 3.0)}
- @y
- \def\title{Common code for CTANGLE and CWEAVE (Version 3.0 [p8d])}
- @z
- ------------------------------------------------------------------------------
- @x l.25
- \centerline{(Version 3.0)}
- @y
- \centerline{(Version 3.0 [p8d])}
- @z
- ------------------------------------------------------------------------------
- @x l.29
- Copyright \copyright\ 1987, 1990, 1993 Silvio Levy and Donald E. Knuth
- @y
- Copyright \copyright\ 1987, 1990, 1993 Silvio Levy and Donald E. Knuth
- \smallskip\noindent
- Copyright \copyright\ 1991, 1992, 1993 Hans-Hermann Bode
- \smallskip\noindent
- Copyright \copyright\ 1991, 1993 Carsten Steger
- \smallskip\noindent
- Copyright \copyright\ 1993 Andreas Scherer
- @z
- ------------------------------------------------------------------------------
- Activate this, if only the changed modules should be printed.
- x l.43
- \let\maybe=\iftrue
- y
- \let\maybe=\iffalse
- z
- ------------------------------------------------------------------------------
- @x l.58
- @<Include files@>@/
- @y
- @<Include files@>@/
- @<Macro definitions@>@/
- @z
- ------------------------------------------------------------------------------
- @x l.89
- void
- common_init()
- @y
- void common_init(void)
- @z
- ------------------------------------------------------------------------------
- Correct a type.
- @x l.108
- character set can type things like \.{\char'32} and \.{char'4} instead
- @y
- character set can type things like \.{\char'32} and \.{\char'4} instead
- @z
- ------------------------------------------------------------------------------
- @x l.169
- int input_ln(fp) /* copies a line into |buffer| or returns 0 */
- FILE *fp; /* what file to read from */
- @y
- static int input_ln(FILE *fp) /* copies a line into |buffer| or returns 0 */
- /* |fp|: what file to read from */
- @z
- ------------------------------------------------------------------------------
- AmigaDOS allows path names with up to 255 characters.
- @x l.203
- @d max_file_name_length 60
- @y
- @d max_file_name_length 256
- @z
- ------------------------------------------------------------------------------
- Correct a typo.
- @x l.225
- @ When |changing=0|, the next line of |change_file| is kept in
- @y
- @ When |changing==0|, the next line of |change_file| is kept in
- @z
- ------------------------------------------------------------------------------
- @x l.248
- void
- prime_the_change_buffer()
- @y
- static void prime_the_change_buffer(void)
- @z
- ------------------------------------------------------------------------------
- @x l.317
- void
- check_change() /* switches to |change_file| if the buffers match */
- @y
- static void check_change(void) /* switches to |change_file| if the buffers match */
- @z
- ------------------------------------------------------------------------------
- @x l.375
- void
- reset_input()
- @y
- void reset_input(void)
- @z
- ------------------------------------------------------------------------------
- @x l.423
- int get_line() /* inputs the next line */
- @y
- int get_line(void) /* inputs the next line */
- @z
- ------------------------------------------------------------------------------
- @x l.452
- @ When an \.{@@i} line is found in the |cur_file|, we must temporarily
- stop reading it and start reading from the named include file. The
- \.{@@i} line should give a complete file name with or without
- double quotes.
- If the environment variable \.{CWEBINPUTS} is set, or if the compiler flag
- of the same name was defined at compile time,
- \.{CWEB} will look for include files in the directory thus named, if
- it cannot find them in the current directory.
- (Colon-separated paths are not supported.)
- The remainder of the \.{@@i} line after the file name is ignored.
- @y
- @ When an \.{@@i} line is found in the |cur_file|, we must temporarily
- stop reading it and start reading from the named include file. The
- \.{@@i} line should give a complete file name with or without
- double quotes. The remainder of the \.{@@i} line after the file name
- is ignored. \.{CWEB} will look for include files in standard directories
- specified in the environment variable \.{CWEBINPUTS}. Multiple search paths
- can be specified by delimiting them with \.{PATH\_SEPARATOR}s. The given
- file is searched for in the current directory first. You also may include
- device names; these must have a \.{DEVICE\_SEPARATOR} as their rightmost
- character.
-
- @d PATH_SEPARATOR ','
- @d DIR_SEPARATOR '/'
- @d DEVICE_SEPARATOR ':'
- @z
- ------------------------------------------------------------------------------
- CWEB will perform a path search for `@i'nclude files along the environment
- variable CWEBINPUTS in case the given file can not be opened in the current
- directory or in the absolute path. The single paths are delimited by
- PATH_SEPARATORs.
- @x l.483
- kk=getenv("CWEBINPUTS");
- if (kk!=NULL) {
- if ((l=strlen(kk))>max_file_name_length-2) too_long();
- strcpy(temp_file_name,kk);
- }
- else {
- #ifdef CWEBINPUTS
- if ((l=strlen(CWEBINPUTS))>max_file_name_length-2) too_long();
- strcpy(temp_file_name,CWEBINPUTS);
- #else
- l=0;
- #endif /* |CWEBINPUTS| */
- }
- if (l>0) {
- if (k+l+2>=cur_file_name_end) too_long();
- @.Include file name ...@>
- for (; k>= cur_file_name; k--) *(k+l+1)=*k;
- strcpy(cur_file_name,temp_file_name);
- cur_file_name[l]='/'; /* \UNIX/ pathname separator */
- if ((cur_file=fopen(cur_file_name,"r"))!=NULL) {
- cur_line=0; print_where=1;
- goto restart; /* success */
- }
- }
- @y
- if(0==set_path(include_path,getenv("CWEBINPUTS"))) {
- include_depth--; goto restart; /* internal error */
- }
- path_prefix = include_path;
- while(path_prefix) {
- for(kk=temp_file_name, p=path_prefix, l=0;
- p && *p && *p!=PATH_SEPARATOR;
- *kk++ = *p++, l++);
- if(path_prefix && *path_prefix && *path_prefix!=PATH_SEPARATOR &&
- *--p!=DEVICE_SEPARATOR && *p!=DIR_SEPARATOR) {
- *kk++ = DIR_SEPARATOR; l++;
- }
- if(k+l+2>=cur_file_name_end) too_long(); /* emergency break */
- strcpy(kk,cur_file_name);
- if(cur_file = fopen(temp_file_name,"r")) {
- cur_line=0; print_where=1; goto restart; /* success */
- }
- if(next_path_prefix = strchr(path_prefix,PATH_SEPARATOR))
- path_prefix = next_path_prefix+1;
- else break; /* no more paths to search; no file found */
- }
- @z
- ------------------------------------------------------------------------------
- @x l.560
- void
- check_complete(){
- @y
- void check_complete(void){
- @z
- ------------------------------------------------------------------------------
- @x l.586
- char *byte_start; /* beginning of the name in |byte_mem| */
- @y
- char HUGE *byte_start; /* beginning of the name in |byte_mem| */
- @z
- ------------------------------------------------------------------------------
- @x l.589
- typedef name_info *name_pointer; /* pointer into array of |name_info|s */
- char byte_mem[max_bytes]; /* characters of names */
- char *byte_mem_end = byte_mem+max_bytes-1; /* end of |byte_mem| */
- name_info name_dir[max_names]; /* information about names */
- name_pointer name_dir_end = name_dir+max_names-1; /* end of |name_dir| */
- @y
- typedef name_info HUGE *name_pointer; /* pointer into array of |name_info|s */
- #ifdef __TURBOC__
- char HUGE *byte_mem; /* characters of names */
- char HUGE *byte_mem_end; /* end of |byte_mem| */
- name_info HUGE *name_dir; /* information about names */
- name_pointer name_dir_end; /* end of |name_dir| */
- #else
- char byte_mem[max_bytes]; /* characters of names */
- char *byte_mem_end = byte_mem+max_bytes-1; /* end of |byte_mem| */
- name_info name_dir[max_names]; /* information about names */
- name_pointer name_dir_end = name_dir+max_names-1; /* end of |name_dir| */
- #endif
- @z
- ------------------------------------------------------------------------------
- @x l.609
- char *byte_ptr; /* first unused position in |byte_mem| */
- @y
- char HUGE *byte_ptr; /* first unused position in |byte_mem| */
- @z
- ------------------------------------------------------------------------------
- @x l.612
- name_dir->byte_start=byte_ptr=byte_mem; /* position zero in both arrays */
- @y
- #ifdef __TURBOC__
- byte_mem=allocsafe(max_bytes,sizeof(*byte_mem));
- byte_mem_end=byte_mem+max_bytes-1;
- name_dir=allocsafe(max_names,sizeof(*name_dir));
- name_dir_end=name_dir+max_names-1;
- #endif
- name_dir->byte_start=byte_ptr=byte_mem; /* position zero in both arrays */
- @z
- ------------------------------------------------------------------------------
- @x l.622
- struct name_info *link;
- @y
- struct name_info HUGE *link;
- @z
- ------------------------------------------------------------------------------
- @x l.640
- @ @<Predec...@>=
- extern int names_match();
- @y
- @ @<Predec...@>=
- extern int names_match(name_pointer,char *,int,eight_bits);@/
- @z
- ------------------------------------------------------------------------------
- In the following, the parameter t must be of type char to be accordant with
- CWEAVE.
- @x l.652
- name_pointer
- id_lookup(first,last,t) /* looks up a string in the identifier table */
- char *first; /* first character of string */
- char *last; /* last character of string plus one */
- char t; /* the |ilk|; used by \.{CWEAVE} only */
- @y
- name_pointer id_lookup(char *first,char *last,char t)
- /* looks up a string in the identifier table */
- /* |first|: first character of string */
- /* |last|: last character of string plus one */
- /* |t|: the |ilk|; used by \.{CWEAVE} only */
- @z
- ------------------------------------------------------------------------------
- @x l.693
- @<Pred...@>=
- void init_p();
- @y
- @<Pred...@>=
- extern void init_p(name_pointer,eight_bits);@/
- @z
- ------------------------------------------------------------------------------
- @x l.722
- struct name_info *Rlink; /* right link in binary search tree for section
- @y
- struct name_info HUGE *Rlink; /* right link in binary search tree for section
- @z
- ------------------------------------------------------------------------------
- @x l.755
- void
- print_section_name(p)
- name_pointer p;
- @y
- void print_section_name(name_pointer p)
- @z
- ------------------------------------------------------------------------------
- @x l.759
- char *ss, *s = first_chunk(p);
- @y
- char HUGE *ss;
- char HUGE *s = first_chunk(p);
- @z
- ------------------------------------------------------------------------------
- @x l.774
- void
- sprint_section_name(dest,p)
- char*dest;
- name_pointer p;
- @y
- void sprint_section_name(char *dest,name_pointer p)
- @z
- ------------------------------------------------------------------------------
- @x l.779
- char *ss, *s = first_chunk(p);
- @y
- char HUGE *ss;
- char HUGE *s = first_chunk(p);
- @z
- ------------------------------------------------------------------------------
- @x l.795
- void
- print_prefix_name(p)
- name_pointer p;
- @y
- void print_prefix_name(name_pointer p)
- @z
- ------------------------------------------------------------------------------
- @x l.799
- char *s = first_chunk(p);
- @y
- char HUGE *s = first_chunk(p);
- @z
- ------------------------------------------------------------------------------
- @x l.816
- int web_strcmp(j,j_len,k,k_len) /* fuller comparison than |strcmp| */
- char *j, *k; /* beginning of first and second strings */
- int j_len, k_len; /* length of strings */
- {
- char *j1=j+j_len, *k1=k+k_len;
- @y
- static int web_strcmp(char HUGE *j, int j_len, char HUGE *k, int k_len)
- /* fuller comparison than |strcmp| */
- /* |j|: beginning of first string */
- /* |k|: beginning of second string */
- /* |j_len|: length of first string */
- /* |k_len|: length of second string */
- {
- char HUGE *j1=j+j_len;
- char HUGE *k1=k+k_len;
- @z
- ------------------------------------------------------------------------------
- @x l.842
- @<Prede...@>=
- extern void init_node();
- @y
- @<Prede...@>=
- extern void init_node(name_pointer);@/
- @z
- ------------------------------------------------------------------------------
- @x l.846
- name_pointer
- add_section_name(par,c,first,last,ispref) /* install a new node in the tree */
- name_pointer par; /* parent of new node */
- int c; /* right or left? */
- char *first; /* first character of section name */
- char *last; /* last character of section name, plus one */
- int ispref; /* are we adding a prefix or a full name? */
- @y
- name_pointer add_section_name(name_pointer par, int c,
- char *first, char *last, int ispref)
- /* install a new node in the tree */
- /* par: parent of new node */
- /* c: right or left? */
- /* first: first character of section name */
- /* last: last character of section name, plus one */
- /* ispref: are we adding a prefix or a full name? */
- @z
- ------------------------------------------------------------------------------
- @x l.855
- char *s=first_chunk(p);
- @y
- char HUGE *s=first_chunk(p);
- @z
- ------------------------------------------------------------------------------
- @x l.875
- void
- extend_section_name(p,first,last,ispref)
- name_pointer p; /* name to be extended */
- char *first; /* beginning of extension text */
- char *last; /* one beyond end of extension text */
- int ispref; /* are we adding a prefix or a full name? */
- @y
- void extend_section_name(name_pointer p,char *first,char *last,int ispref)
- /* p: name to be extended */
- /* first: beginning of extension text */
- /* last: one beyond end of extension text */
- /* ispref: are we adding a prefix or a full name? */
- @z
- ------------------------------------------------------------------------------
- @x l.882
- char *s;
- @y
- char HUGE *s;
- @z
- ------------------------------------------------------------------------------
- Correct a typo.
- @x l.898
- its doesn't match an existing one. The new name is the string
- @y
- it doesn't match an existing one. The new name is the string
- @z
- ------------------------------------------------------------------------------
- @x l.903
- name_pointer
- section_lookup(first,last,ispref) /* find or install section name in tree */
- char *first, *last; /* first and last characters of new name */
- int ispref; /* is the new name a prefix or a full name? */
- @y
- name_pointer section_lookup(char *first,char *last,int ispref)
- /* find or install section name in tree */
- /* first, last: first and last characters of new name */
- /* ispref: is the new name a prefix or a full name? */
- @z
- ------------------------------------------------------------------------------
- @x l.1007
- @<Predec...@>=
- int section_name_cmp();
- @y
- @<Predec...@>=
- static int section_name_cmp(char **,int,name_pointer);@/
- @z
- ------------------------------------------------------------------------------
- @x l.1011
- int section_name_cmp(pfirst,len,r)
- char **pfirst; /* pointer to beginning of comparison string */
- int len; /* length of string */
- name_pointer r; /* section name being compared */
- @y
- static int section_name_cmp(char **pfirst,int len,name_pointer r)
- /*pfirst: pointer to beginning of comparison string */
- /* len: length of string */
- /* r: section name being compared */
- @z
- ------------------------------------------------------------------------------
- @x l.1018
- char *ss, *s=first_chunk(r);
- @y
- char HUGE *ss;
- char HUGE *s=first_chunk(r);
- @z
- ------------------------------------------------------------------------------
- @x l.1053
- char *equiv_or_xref; /* info corresponding to names */
- @y
- char HUGE *equiv_or_xref; /* info corresponding to names */
- @z
- ------------------------------------------------------------------------------
- Correct a typo.
- @x l.1080
- if the string begins with |"|"|.
- @y
- if the string begins with |"!"|.
- @z
- ------------------------------------------------------------------------------
- @x l.1082
- @<Predecl...@>=
- void err_print();
- @y
- @<Predecl...@>=
- extern void err_print(char *);@/
- @z
- ------------------------------------------------------------------------------
- @x l.1087
- void
- err_print(s) /* prints `\..' and location of error message */
- char *s;
- @y
- void err_print(char *s) /* prints `\..' and location of error message */
- @z
- ------------------------------------------------------------------------------
- @x l.1130
- @<Prede...@>=
- int wrap_up();
- extern void print_stats();
- @y
- @<Prede...@>=
- int wrap_up(void);@/
- extern void print_stats(void);@/
- @z
- ------------------------------------------------------------------------------
- On the AMIGA it is very convenient to know a little bit more about the reasons
- why a program failed. There are four levels of return for this purpose.
- Let CWeb be so kind to use them, so ARexx scripts can be made better.
- @x l.1134
- @ Some implementations may wish to pass the |history| value to the
- operating system so that it can be used to govern whether or not other
- programs are started. Here, for instance, we pass the operating system
- a status of 0 if and only if only harmless messages were printed.
- @^system dependencies@>
-
- @c
- int wrap_up() {
- putchar('\n');
- if (show_stats)
- print_stats(); /* print statistics about memory usage */
- @<Print the job |history|@>;
- if (history > harmless_message) return(1);
- else return(0);
- }
- @y
- @ On multi-tasking systems like the Amiga it is very convenient to know
- a little bit more about the reasons why a program failed. The four levels
- of return indicated by the |history| value are very suitable for this
- purpose. Here, for instance, we pass the operating system a status of~0
- if and only if the run was a complete success. Any warning or error
- message will result in a higher return value, so ARexx scripts can be
- made sensitive to these conditions.
- @^system dependencies@>
-
- @d RETURN_OK 0 /* No problems, success */
- @d RETURN_WARN 5 /* A warning only */
- @d RETURN_ERROR 10 /* Something wrong */
- @d RETURN_FAIL 20 /* Complete or severe failure */
-
- @c
- int wrap_up(void) {
- putchar('\n');
- if (show_stats) print_stats(); /* print statistics about memory usage */
- @<Print the job |history|@>;
- switch(history) {
- case harmless_message: return(RETURN_WARN); break;
- case error_message: return(RETURN_ERROR); break;
- case fatal_message: return(RETURN_FAIL); break;
- default: return(RETURN_OK);
- }
- }
- @z
- ------------------------------------------------------------------------------
- @x l.1163
- @<Predec...@>=
- void fatal(), overflow();
- @y
- @<Predec...@>=
- extern void fatal(char *,char *);
- extern void overflow(char *);
- @z
- ------------------------------------------------------------------------------
- On the AMIGA there is a list of additional identifiers that have to be
- formatted correctly. Also for German programmers it is more convenient to
- write German program documentations. This changes by Andreas Scherer are
- based on ideas of Carsten Steger as of his `CWeb 2.0' port from ><> 551 and
- his `CWeb 2.8' port from the electronic nets. First we correct a typo.
- @x l.1199
- or flags to be turned on (beginning with |"+"|.
- The following globals are for communicating the user's desires to the rest
- of the program. The various file name variables contain strings with
- the names of those files. Most of the 128 flags are undefined but available
- for future extensions.
-
- @d show_banner flags['b'] /* should the banner line be printed? */
- @d show_progress flags['p'] /* should progress reports be printed? */
- @d show_stats flags['s'] /* should statistics be printed at end of run? */
- @d show_happiness flags['h'] /* should lack of errors be announced? */
- @y
- or flags to be turned on (beginning with |"+"|).
- The following globals are for communicating the user's desires to the rest
- of the program. The various file name variables contain strings with
- the names of those files. Most of the 256 flags are undefined but available
- for future extensions.
-
- @d show_banner flags['b'] /* should the banner line be printed? */
- @d show_progress flags['p'] /* should progress reports be printed? */
- @d show_stats flags['s'] /* should statistics be printed at end of run? */
- @d show_happiness flags['h'] /* should lack of errors be announced? */
- @d use_amiga_keywords flags['a'] /* should Amiga/SAS C keywords be used? */
- @d use_german_macros flags['g'] /* should the output be German? */
- @d indent_param_decl flags['i'] /* should formal parameter declarations be indented? */
- @z
- ----------------------------------------------------------------------
- @x l.1217
- boolean flags[128]; /* an option for each 7-bit code */
- @y
- boolean flags[256]; /* an option for each 8-bit code */
- @z
- ------------------------------------------------------------------------------
- @x l.1223
- @<Set the default options common to \.{CTANGLE} and \.{CWEAVE}@>=
- show_banner=show_happiness=show_progress=1;
- @y
- @<Set the default options common to \.{CTANGLE} and \.{CWEAVE}@>=
- show_banner=show_happiness=show_progress=1;
- #ifdef _AMIGA
- use_amiga_keywords=
- #endif
- use_german_macros=indent_param_decl=1;
- @z
- ----------------------------------------------------------------------
- @x l.1235
- An omitted change file argument means that |"/dev/null"| should be used,
- when no changes are desired.
- @y
- An omitted change file argument means that |"/dev/null"| or---on {\mc
- MS-DOS} systems---|"nul"| or---on {\mc AMIGA} systems---|"NIL:"| should be
- used, when no changes are desired.
- @z
- ------------------------------------------------------------------------------
- @x l.1241
- @<Pred...@>=
- void scan_args();
- @y
- @<Pred...@>=
- static void scan_args(void);@/
- @z
- ------------------------------------------------------------------------------
- @x l.1245
- void
- scan_args()
- @y
- static void scan_args(void)
- @z
- ------------------------------------------------------------------------------
- For consistency we include both AMIGA path delimiters; else there would be
- a difference in the output file name when compiling files from an other
- device, especially `RAM:'.
- @x l.1259
- while (*s) {
- if (*s=='.') dot_pos=s++;
- else if (*s=='/') dot_pos=NULL,name_pos=++s;
- else s++;
- }
- @y
- while (*s) {
- if (*s=='.') dot_pos=s++;
- #ifdef _AMIGA
- else if ((*s=='/') || (*s==':')) dot_pos=NULL,name_pos=++s;
- #else
- else if (*s=='/') dot_pos=NULL,name_pos=++s;
- #endif
- else s++;
- }
- @z
- ------------------------------------------------------------------------------
- @x l.1272
- if (!found_change) strcpy(change_file_name,"/dev/null");
- @y
- #if defined( __TURBOC__ )
- if (!found_change) strcpy(change_file_name,"nul");
- #elif defined( _AMIGA )
- if (!found_change) strcpy(change_file_name,"NIL:");
- #else
- if (!found_change) strcpy(change_file_name,"/dev/null");
- #endif
- @z
- ------------------------------------------------------------------------------
- @x l.1346
- fatal(
- "! Usage: ctangle [options] webfile[.w] [changefile[.ch] [outfile[.c]]]\n"
- ,"");
- @.Usage:@>
- else fatal(
- "! Usage: cweave [options] webfile[.w] [changefile[.ch] [outfile[.tex]]]\n"
- ,"");
- @y
- fatal(
- "! Usage: ctangle [options] webfile[.w] [changefile[.ch] [outfile[.c]]]\n"@|
- "Options are (+ turns on, - turns off, default in brackets):\n"@|
- "b print banner line [+]\n"@|
- "h print happy message [+]\n"@|
- "p give progress reports [+]\n"@|
- "s show statistics [-]\n"@|
- ,"");
- @.Usage:@>
- #ifdef _AMIGA
- else fatal(
- "! Usage: cweave [options] webfile[.w] [changefile[.ch] [outfile[.tex]]]\n"@|
- "Options are (+ turns on, - turns off, default in brackets):\n"@|
- "a use AMIGA specific keywords [+]\n"@|
- "b print banner line [+]\n"@|
- "f force line breaks [+]\n"@|
- "g use German macros as of gcwebmac.tex [+]\n"@|
- "h print happy message [+]\n"@|
- "i indent parameter declarations [+]\n"@|
- "p give progress reports [+]\n"@|
- "s show statistics [-]\n"@|
- "x include indexes and table of contents [+]\n"@|
- ,"");
- #else
- else fatal(
- "! Usage: cweave [options] webfile[.w] [changefile[.ch] [outfile[.tex]]]\n"@|
- "Options are (+ turns on, - turns off, default in brackets):\n"@|
- "b print banner line [+]\n"@|
- "f force line breaks [+]\n"@|
- "g use German macros as of gcwebmac.tex [+]\n"@|
- "h print happy message [+]\n"@|
- "i indent parameter declarations [+]\n"@|
- "p give progress reports [+]\n"@|
- "s show statistics [-]\n"@|
- "x include indexes and table of contents [+]\n"@|
- ,"");
- #endif
- @z
- ------------------------------------------------------------------------------
- @x l.1402 Will be declared in <string.h> below.
- @<Predecl...@>=
- extern int strlen(); /* length of string */
- extern int strcmp(); /* compare strings lexicographically */
- extern char* strcpy(); /* copy one string to another */
- extern int strncmp(); /* compare up to $n$ string characters */
- extern char* strncpy(); /* copy up to $n$ string characters */
-
- @** Index.
- @y
- @<Include...@>=
- #include <string.h>
-
- @* Path searching. On default, CTangle and CWeave are looking for include
- files along the path |CWEBINPUTS| given in this source file. By setting
- the environment variable of the same name to a different search path that
- suits your personal needs, you may override the default on startup. The
- following procdure copies the value of the environment variable (if any) to
- the variable |include_path| used for path searching.
-
- @c
- static boolean set_path(char *ptr,char *override)
- {
- if(override) {
- if(strlen(override) >= MAXPATHLENGTH) {
- err_print("! Include path too long"); return(0);
- @.Include path too long@>
- }
- else strcpy(ptr, override);
- }
- return(1);
- }
-
- @ The path search algorithm defined in section |@<Try to open...@>|
- needs a few extra variables. The search path given in the environment
- variable |CWEBINPUTS| must not be longer than |MAXPATHLENGTH|. If no
- string is given in this variable, the internal default |CWEBINPUTS| is
- used instead, which holds some sensible paths.
-
- @d MAXPATHLENGTH 4095
- @d CWEBINPUTS ",CWeb:,CWeb:include,CWeb:inputs"
-
- @<Other...@>=
- char include_path[MAXPATHLENGTH+1]=CWEBINPUTS;@/
- char *p, *path_prefix, *next_path_prefix;@/
-
- @* Memory allocation. Due to restrictions of most {\mc MS-DOS}-\CEE/ compilers,
- large arrays will be allocated dynamically rather than statically. In the {\mc
- TURBO}-\CEE/ implementation the |farcalloc| function provides a way to allocate
- more than 64~KByte of data. The |allocsafe| function tries to carry out an
- allocation of |nunits| blocks of size |unitsz| by calling |farcalloc| and takes
- a safe method, when this fails: the program will be aborted.
-
- To deal with such allocated data areas |huge| pointers will be used in this
- implementation.
-
- @f far int
- @f huge int
- @f HUGE int
-
- @<Pred...@>=
- extern void far *allocsafe(unsigned long,unsigned long);
- @^system dependencies@>
-
- @ @c
- #ifdef __TURBOC__
- void far *allocsafe (unsigned long nunits,unsigned long unitsz)
- {
- void far *p = farcalloc(nunits,unitsz);
- if (p==NULL) fatal("","! Memory allocation failure");
- @.Memory allocation failure@>
- return p;
- }
- #endif
- @^system dependencies@>
-
- @ @<Include...@>=
- #ifdef __TURBOC__
- #include <alloc.h> /* import |farcalloc| */
- #include <io.h> /* import |write| */
- #endif
- @^system dependencies@>
-
- @ @<Macro...@>=
- #ifdef __TURBOC__
- #define HUGE huge
- #else
- #define HUGE
- #endif
- @^system dependencies@>
-
- @* Function declarations. Here are declarations, conforming to {\mc ANSI~C}, of
- all functions in this code that appear in |"common.h"| and thus should
- agree with \.{CTANGLE} and \.{CWEAVE}.
-
- @<Other...@>=
- #ifdef _AMIGA /* I don't know, which form is correct */
- typedef unsigned char eight_bits;
- #else
- typedef char unsigned eight_bits;
- #endif
- void common_init(void);@/
- void reset_input(void);@/
- int get_line(void);@/
- void check_complete(void);@/
- name_pointer id_lookup(char *first,char *last,char t);@/
- void print_section_name(name_pointer);@/
- void sprint_section_name(char *,name_pointer);@/
- void print_prefix_name(name_pointer);@/
- name_pointer add_section_name(name_pointer par, int c,
- char *first, char *last, int ispref);@/
- void extend_section_name(name_pointer p,char *first,char *last,int ispref);@/
- name_pointer section_lookup(char *first,char *last,int ispref);
-
- @ The following functions are private to |"common.w"|.
-
- @<Other...@>=
- static int input_ln(FILE *fp);@/
- static void prime_the_change_buffer(void);@/
- static void check_change(void);@/
- static int web_strcmp(char HUGE *j, int j_len, char HUGE *k, int k_len);@/
- static boolean set_path(char *ptr, char *override);@/
-
- @ Finally, we include \.{stdlib.h} that contains the prototype for the
- |getenv| function used above and \.{string.h} for |strncmp|, |strncpy|,
- |strcpy|, and |strlen|.
-
- @<Include...@>=
- #include <stdlib.h>
-
- @** Index.
- @z
- ------------------------------------------------------------------------------
-