Back to index

tetex-bin  3.0
common.h
Go to the documentation of this file.
00001 % This file is part of CWEB.
00002 % This program by Silvio Levy and Donald E. Knuth
00003 % is based on a program by Knuth.
00004 % It is distributed WITHOUT ANY WARRANTY, express or implied.
00005 % Version 3.0 --- June 1993 (works also with later versions)
00006 
00007 % Copyright (C) 1987,1990,1993 Silvio Levy and Donald E. Knuth
00008 
00009 % Permission is granted to make and distribute verbatim copies of this
00010 % document provided that the copyright notice and this permission notice
00011 % are preserved on all copies.
00012 
00013 % Permission is granted to copy and distribute modified versions of this
00014 % document under the conditions for verbatim copying, provided that the
00015 % entire resulting derived work is distributed under the terms of a
00016 % permission notice identical to this one.
00017 
00018 % Please send comments, suggestions, etc. to levy@@math.berkeley.edu.
00019 
00020 % The next few sections contain stuff from the file |"common.w"| that has
00021 % to be included in both |"ctangle.w"| and |"cweave.w"|. It appears in this
00022 % file |"common.h"|, which needs to be updated when |"common.w"| changes.
00023 
00024 First comes general stuff:
00025 
00026 @d ctangle 0
00027 @d cweave 1
00028 
00029 @<Common code for \.{CWEAVE} and \.{CTANGLE}@>=
00030 typedef short boolean;
00031 typedef char unsigned eight_bits;
00032 extern boolean program; /* \.{CWEAVE} or \.{CTANGLE}? */
00033 extern int phase; /* which phase are we in? */
00034 
00035 @ @<Include files@>=
00036 #include <stdio.h>
00037 
00038 @ Code related to the character set:
00039 @^ASCII code dependencies@>
00040 
00041 @d and_and 04 /* `\.{\&\&}'\,; corresponds to MIT's {\tentex\char'4} */
00042 @d lt_lt 020 /* `\.{<<}'\,;  corresponds to MIT's {\tentex\char'20} */
00043 @d gt_gt 021 /* `\.{>>}'\,;  corresponds to MIT's {\tentex\char'21} */
00044 @d plus_plus 013 /* `\.{++}'\,;  corresponds to MIT's {\tentex\char'13} */
00045 @d minus_minus 01 /* `\.{--}'\,;  corresponds to MIT's {\tentex\char'1} */
00046 @d minus_gt 031 /* `\.{->}'\,;  corresponds to MIT's {\tentex\char'31} */
00047 @d not_eq 032 /* `\.{!=}'\,;  corresponds to MIT's {\tentex\char'32} */
00048 @d lt_eq 034 /* `\.{<=}'\,;  corresponds to MIT's {\tentex\char'34} */
00049 @d gt_eq 035 /* `\.{>=}'\,;  corresponds to MIT's {\tentex\char'35} */
00050 @d eq_eq 036 /* `\.{==}'\,;  corresponds to MIT's {\tentex\char'36} */
00051 @d or_or 037 /* `\.{\v\v}'\,;  corresponds to MIT's {\tentex\char'37} */
00052 @d dot_dot_dot 016 /* `\.{...}'\,;  corresponds to MIT's {\tentex\char'16} */
00053 @d colon_colon 06 /* `\.{::}'\,;  corresponds to MIT's {\tentex\char'6} */
00054 @d period_ast 026 /* `\.{.*}'\,;  corresponds to MIT's {\tentex\char'26} */
00055 @d minus_gt_ast 027 /* `\.{->*}'\,;  corresponds to MIT's {\tentex\char'27} */
00056 
00057 @<Common code...@>=
00058 char section_text[longest_name+1]; /* name being sought for */
00059 char *section_text_end = section_text+longest_name; /* end of |section_text| */
00060 char *id_first; /* where the current identifier begins in the buffer */
00061 char *id_loc; /* just after the current identifier in the buffer */
00062 
00063 @ Code related to input routines:
00064 
00065 @d xisalpha(c) (isalpha(c)&&((eight_bits)c<0200))
00066 @d xisdigit(c) (isdigit(c)&&((eight_bits)c<0200))
00067 @d xisspace(c) (isspace(c)&&((eight_bits)c<0200))
00068 @d xislower(c) (islower(c)&&((eight_bits)c<0200))
00069 @d xisupper(c) (isupper(c)&&((eight_bits)c<0200))
00070 @d xisxdigit(c) (isxdigit(c)&&((eight_bits)c<0200))
00071 
00072 @<Common code...@>=
00073 extern char buffer[]; /* where each line of input goes */
00074 extern char *buffer_end; /* end of |buffer| */
00075 extern char *loc; /* points to the next character to be read from the buffer*/
00076 extern char *limit; /* points to the last character in the buffer */
00077 
00078 @ Code related to identifier and section name storage:
00079 @d length(c) (c+1)->byte_start-(c)->byte_start /* the length of a name */
00080 @d print_id(c) term_write((c)->byte_start,length((c))) /* print identifier */
00081 @d llink link /* left link in binary search tree for section names */
00082 @d rlink dummy.Rlink /* right link in binary search tree for section names */
00083 @d root name_dir->rlink /* the root of the binary search tree
00084   for section names */
00085 @d chunk_marker 0
00086 
00087 @<Common code...@>=
00088 typedef struct name_info {
00089   char *byte_start; /* beginning of the name in |byte_mem| */
00090   struct name_info *link;
00091   union {
00092     struct name_info *Rlink; /* right link in binary search tree for section
00093       names */
00094     char Ilk; /* used by identifiers in \.{CWEAVE} only */
00095   } dummy;
00096   char *equiv_or_xref; /* info corresponding to names */
00097 } name_info; /* contains information about an identifier or section name */
00098 typedef name_info *name_pointer; /* pointer into array of \&{name\_info}s */
00099 typedef name_pointer *hash_pointer;
00100 extern char byte_mem[]; /* characters of names */
00101 extern char *byte_mem_end; /* end of |byte_mem| */
00102 extern name_info name_dir[]; /* information about names */
00103 extern name_pointer name_dir_end; /* end of |name_dir| */
00104 extern name_pointer name_ptr; /* first unused position in |byte_start| */
00105 extern char *byte_ptr; /* first unused position in |byte_mem| */
00106 extern name_pointer hash[]; /* heads of hash lists */
00107 extern hash_pointer hash_end; /* end of |hash| */
00108 extern hash_pointer h; /* index into hash-head array */
00109 extern name_pointer id_lookup(); /* looks up a string in the identifier table */
00110 extern name_pointer section_lookup(); /* finds section name */
00111 extern void print_section_name(), sprint_section_name();
00112 
00113 @ Code related to error handling:
00114 @d spotless 0 /* |history| value for normal jobs */
00115 @d harmless_message 1 /* |history| value when non-serious info was printed */
00116 @d error_message 2 /* |history| value when an error was noted */
00117 @d fatal_message 3 /* |history| value when we had to stop prematurely */
00118 @d mark_harmless {if (history==spotless) history=harmless_message;}
00119 @d mark_error history=error_message
00120 @d confusion(s) fatal("! This can't happen: ",s)
00121 
00122 @<Common...@>=
00123 extern history; /* indicates how bad this run was */
00124 extern err_print(); /* print error message and context */
00125 extern wrap_up(); /* indicate |history| and exit */
00126 extern void fatal(); /* issue error message and die */
00127 extern void overflow(); /* succumb because a table has overflowed */
00128 
00129 @ Code related to file handling:
00130 @f line x /* make |line| an unreserved word */
00131 @d max_file_name_length 60
00132 @d cur_file file[include_depth] /* current file */
00133 @d cur_file_name file_name[include_depth] /* current file name */
00134 @d web_file_name file_name[0] /* main source file name */
00135 @d cur_line line[include_depth] /* number of current line in current file */
00136 
00137 @<Common code...@>=
00138 extern include_depth; /* current level of nesting */
00139 extern FILE *file[]; /* stack of non-change files */
00140 extern FILE *change_file; /* change file */
00141 extern char C_file_name[]; /* name of |C_file| */
00142 extern char tex_file_name[]; /* name of |tex_file| */
00143 extern char idx_file_name[]; /* name of |idx_file| */
00144 extern char scn_file_name[]; /* name of |scn_file| */
00145 extern char file_name[][max_file_name_length];
00146   /* stack of non-change file names */
00147 extern char change_file_name[]; /* name of change file */
00148 extern line[]; /* number of current line in the stacked files */
00149 extern change_line; /* number of current line in change file */
00150 extern boolean input_has_ended; /* if there is no more input */
00151 extern boolean changing; /* if the current line is from |change_file| */
00152 extern boolean web_file_open; /* if the web file is being read */
00153 extern reset_input(); /* initialize to read the web file and change file */
00154 extern get_line(); /* inputs the next line */
00155 extern check_complete(); /* checks that all changes were picked up */
00156 
00157 @ Code related to section numbers:
00158 @<Common code...@>=
00159 typedef unsigned short sixteen_bits;
00160 extern sixteen_bits section_count; /* the current section number */
00161 extern boolean changed_section[]; /* is the section changed? */
00162 extern boolean change_pending; /* is a decision about change still unclear? */
00163 extern boolean print_where; /* tells \.{CTANGLE} to print line and file info */
00164 
00165 @ Code related to command line arguments:
00166 @d show_banner flags['b'] /* should the banner line be printed? */
00167 @d show_progress flags['p'] /* should progress reports be printed? */
00168 @d show_happiness flags['h'] /* should lack of errors be announced? */
00169 
00170 @<Common code...@>=
00171 extern int argc; /* copy of |ac| parameter to |main| */
00172 extern char **argv; /* copy of |av| parameter to |main| */
00173 extern boolean flags[]; /* an option for each 7-bit code */
00174 
00175 @ Code relating to output:
00176 @d update_terminal fflush(stdout) /* empty the terminal output buffer */
00177 @d new_line putchar('\n') @d putxchar putchar
00178 @d term_write(a,b) fflush(stdout),fwrite(a,sizeof(char),b,stdout)
00179 @d C_printf(c,a) fprintf(C_file,c,a)
00180 @d C_putc(c) putc(c,C_file)
00181 
00182 @<Common code...@>=
00183 extern FILE *C_file; /* where output of \.{CTANGLE} goes */
00184 extern FILE *tex_file; /* where output of \.{CWEAVE} goes */
00185 extern FILE *idx_file; /* where index from \.{CWEAVE} goes */
00186 extern FILE *scn_file; /* where list of sections from \.{CWEAVE} goes */
00187 extern FILE *active_file; /* currently active file for \.{CWEAVE} output */
00188 
00189 @ The procedure that gets everything rolling:
00190 
00191 @<Common code...@>=
00192 extern void common_init();