home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cweb28.zip / common.h < prev    next >
C/C++ Source or Header  |  1992-10-01  |  8KB  |  177 lines

  1. % This file is part of CWEB.
  2. % This program by Silvio Levy and Donald E. Knuth 
  3. % is based on a program by Knuth.
  4. % It is distributed WITHOUT ANY WARRANTY, express or implied.
  5. % Version 2.8 -- September 1992
  6.  
  7. % Copyright (C) 1987,1990,1991,1992 Silvio Levy and Donald E. Knuth
  8.  
  9. % Permission is granted to make and distribute verbatim copies of this
  10. % document provided that the copyright notice and this permission notice
  11. % are preserved on all copies.
  12.  
  13. % Permission is granted to copy and distribute modified versions of this
  14. % document under the conditions for verbatim copying, provided that the
  15. % entire resulting derived work is distributed under the terms of a
  16. % permission notice identical to this one.
  17.  
  18. % Please send comments, suggestions, etc. to levy@@math.berkeley.edu.
  19.  
  20. % The next few sections contain stuff from the file |"common.w"| that has
  21. % to be included in both |"tangle.w"| and |"weave.w"|. It appears in this
  22. % file |"common.h"|, which needs to be updated when |"common.w"| changes.
  23.  
  24. First comes general stuff:
  25.  
  26. @d tangle 0
  27. @d weave 1
  28.  
  29. @<Common code for \.{WEAVE} and \.{TANGLE}@>=
  30. typedef short boolean;
  31. typedef char unsigned eight_bits;
  32. extern boolean program; /* \.{WEAVE} or \.{TANGLE}? */
  33. extern int phase; /* which phase are we in? */
  34.  
  35. @ @<Include files@>=
  36. #include <stdio.h>
  37.  
  38. @ Code related to the character set:
  39. @^ASCII code dependencies@>
  40.  
  41. @d and_and 04 /* `\.{\&\&}'; this corresponds to MIT's {\tentex\char'4} */
  42. @d lt_lt 020 /* `\.{<<}';  this corresponds to MIT's {\tentex\char'20} */
  43. @d gt_gt 021 /* `\.{>>}';  this corresponds to MIT's {\tentex\char'21} */
  44. @d plus_plus 013 /* `\.{++}';  this corresponds to MIT's {\tentex\char'13} */
  45. @d minus_minus 01 /* `\.{--}';  this corresponds to MIT's {\tentex\char'1} */
  46. @d minus_gt 031 /* `\.{->}';  this corresponds to MIT's {\tentex\char'31} */
  47. @d not_eq 032 /* `\.{!=}';  this corresponds to MIT's {\tentex\char'32} */
  48. @d lt_eq 034 /* `\.{<=}';  this corresponds to MIT's {\tentex\char'34} */
  49. @d gt_eq 035 /* `\.{>=}';  this corresponds to MIT's {\tentex\char'35} */
  50. @d eq_eq 036 /* `\.{==}';  this corresponds to MIT's {\tentex\char'36} */
  51. @d or_or 037 /* `\.{\v\v}';  this corresponds to MIT's {\tentex\char'37} */
  52.  
  53. @<Common code...@>=
  54. char section_text[longest_name+1]; /* name being sought for */
  55. char *section_text_end = section_text+longest_name; /* end of |section_text| */
  56. char *id_first; /* where the current identifier begins in the buffer */
  57. char *id_loc; /* just after the current identifier in the buffer */
  58.  
  59. @ Code related to input routines:
  60.  
  61. @<Common code...@>=
  62. extern char buffer[]; /* where each line of input goes */
  63. extern char *buffer_end; /* end of |buffer| */
  64. extern char *loc; /* points to the next character to be read from the buffer*/
  65. extern char *limit; /* points to the last character in the buffer */
  66.  
  67. @ Code related to identifier and section name storage:
  68. @d length(c) (c+1)->byte_start-(c)->byte_start /* the length of a name */
  69. @d print_id(c) term_write((c)->byte_start,length((c))) /* print identifier */
  70. @d llink link /* left link in binary search tree for section names */
  71. @d rlink dummy.Rlink /* right link in binary search tree for section names */
  72. @d root name_dir->rlink /* the root of the binary search tree
  73.   for section names */
  74. @d chunk_marker 0
  75.  
  76. @<Common code...@>=
  77. typedef struct name_info {
  78.   char *byte_start; /* beginning of the name in |byte_mem| */
  79.   struct name_info *link;
  80.   union {
  81.     struct name_info *Rlink; /* right link in binary search tree for section
  82.       names */  
  83.     char Ilk; /* used by identifiers in \.{WEAVE} only */
  84.   } dummy;
  85.   char *equiv_or_xref; /* info corresponding to names */
  86. } name_info; /* contains information about an identifier or section name */
  87. typedef name_info *name_pointer; /* pointer into array of |name_info|s */
  88. typedef name_pointer *hash_pointer;
  89. extern char byte_mem[]; /* characters of names */
  90. extern char *byte_mem_end; /* end of |byte_mem| */
  91. extern name_info name_dir[]; /* information about names */
  92. extern name_pointer name_dir_end; /* end of |name_dir| */
  93. extern name_pointer name_ptr; /* first unused position in |byte_start| */
  94. extern char *byte_ptr; /* first unused position in |byte_mem| */
  95. extern name_pointer hash[]; /* heads of hash lists */
  96. extern hash_pointer hash_end; /* end of |hash| */
  97. extern hash_pointer h; /* index into hash-head array */
  98. extern name_pointer id_lookup(); /* looks up a string in the identifier table */
  99. extern name_pointer section_lookup(); /* finds section name */
  100. extern name_pointer prefix_lookup(); /* finds section name given a prefix */
  101.  
  102. @ Code related to error handling:
  103. @d spotless 0 /* |history| value for normal jobs */
  104. @d harmless_message 1 /* |history| value when non-serious info was printed */
  105. @d error_message 2 /* |history| value when an error was noted */
  106. @d fatal_message 3 /* |history| value when we had to stop prematurely */
  107. @d mark_harmless {if (history==spotless) history=harmless_message;}
  108. @d mark_error history=error_message
  109. @d confusion(s) fatal("! This can't happen: ",s)
  110. @d fatal(s,t) {
  111.   printf(s); err_print(t);
  112.   history=fatal_message; wrap_up();
  113. }
  114. @d overflow(t) {
  115.   printf("\n! Sorry, %s capacity exceeded",t); fatal("","");
  116. }
  117.  
  118. @<Common...@>=
  119. extern history; /* indicates how bad this run was */
  120. extern err_print(); /* prints error message and context */
  121. extern wrap_up(); /* indicate |history| and exit */
  122.  
  123. @ Code related to file handling:
  124. @f line x /* make |line| an unreserved word */
  125. @d max_file_name_length 60
  126. @d cur_file file[include_depth] /* current file */
  127. @d cur_file_name file_name[include_depth] /* current file name */
  128. @d web_file_name file_name[0] /* main source file name */
  129. @d cur_line line[include_depth] /* number of current line in current file */
  130.  
  131. @<Common code...@>=
  132. extern include_depth; /* current level of nesting */
  133. extern FILE *file[]; /* stack of non-change files */
  134. extern FILE *change_file; /* change file */
  135. extern char C_file_name[]; /* name of |C_file| */
  136. extern char tex_file_name[]; /* name of |tex_file| */
  137. extern char file_name[][max_file_name_length];
  138.   /* stack of non-change file names */
  139. extern char change_file_name[]; /* name of change file */
  140. extern line[]; /* number of current line in the stacked files */
  141. extern change_line; /* number of current line in change file */
  142. extern boolean input_has_ended; /* if there is no more input */
  143. extern boolean changing; /* if the current line is from |change_file| */
  144. extern boolean web_file_open; /* if the web file is being read */
  145. extern reset_input(); /* initialize to read the web file and change file */
  146. extern get_line(); /* inputs the next line */
  147. extern check_complete(); /* checks that all changes were picked up */
  148.  
  149. @ Code related to section numbers:
  150. @<Common code...@>=
  151. typedef unsigned short sixteen_bits;
  152. extern sixteen_bits section_count; /* the current section number */
  153. extern boolean changed_section[]; /* is the section changed? */
  154. extern boolean change_pending; /* is a decision about change still unclear? */
  155. extern boolean print_where; /* tells \.{TANGLE} to print line and file info */
  156.  
  157. @ Code related to command line arguments:
  158. @d show_banner flags['b'] /* should the banner line be printed? */
  159. @d show_progress flags['p'] /* should progress reports be printed? */
  160. @d show_happiness flags['h'] /* should lack of errors be announced? */
  161.  
  162. @<Common code...@>=
  163. extern int argc; /* copy of |ac| parameter to |main| */
  164. extern char **argv; /* copy of |av| parameter to |main| */
  165. extern boolean flags[]; /* an option for each 7-bit code */
  166.  
  167. @ Code relating to output:
  168. @d update_terminal fflush(stdout) /* empty the terminal output buffer */
  169. @d new_line putchar('\n') @d putxchar putchar
  170. @d term_write(a,b) fflush(stdout), write(1,a,b) /* write on the standard output */
  171. @d C_printf(c,a) fprintf(C_file,c,a)
  172. @d C_putc(c) putc(c,C_file)
  173.  
  174. @<Common code...@>=
  175. extern FILE *C_file; /* where output of \.{TANGLE} goes */
  176. extern FILE *tex_file; /* where output of \.{WEAVE} goes */
  177.