home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / SPIDER / MASTER / COMMON.H next >
Encoding:
C/C++ Source or Header  |  1988-07-09  |  6.2 KB  |  147 lines

  1. @ Here's stuff from the file |'common.web'| that has to be included in
  2. |'tangle.web'| and |'weave.web'|.
  3.  
  4. General stuff:
  5.  
  6. @d tangle = 0
  7. @d weave = 1
  8.  
  9. @<Common code for \.{WEAVE} and \.{TANGLE}@>=
  10. typedef short boolean;
  11. typedef char unsigned eight_bits;
  12. extern boolean program; /* \.{WEAVE} or \.{TANGLE}? */
  13. extern int phase; /* which phase are we in? */
  14.  
  15. @ @<Include files@>=
  16. #include <stdio.h>
  17.  
  18. @ Code related to the character set:
  19. @d tab_mark = 011 /* ASCII code used as tab-skip */
  20. @d line_feed = 012 /* ASCII code thrown away at end of line */
  21. @d form_feed = 014 /* ASCII code used at end of page */
  22. @d carriage_return = 015 /* ASCII code used at end of line */
  23.  
  24. @<Common code...@>=
  25. typedef char ASCII; /* type of characters inside \.{WEB} */
  26. typedef char outer_char; /* type of characters outside \.{WEB} */
  27. extern ASCII xord[]; /* specifies conversion of input characters */
  28. extern outer_char xchr[]; /* specifies conversion of output characters */
  29. ASCII mod_text[longest_name+1]; /* name being sought for */
  30. ASCII *mod_text_end = mod_text+longest_name; /* end of |mod_text| */
  31. ASCII *id_first; /* where the current identifier begins in the buffer */
  32. ASCII *id_loc; /* just after the current identifier in the buffer */
  33.  
  34. @ Code related to input routines:
  35. Killed |buf_size|; already in weave and tangle.
  36.  
  37. @<Common code...@>=
  38. extern ASCII buffer[]; /* where each line of input goes */
  39. extern ASCII *buffer_end; /* end of |buffer| */
  40. extern ASCII *loc; /* points to the next character to be read from the buffer*/
  41. extern ASCII *limit; /* points to the last character in the buffer */
  42.  
  43. @ Code related to identifier and module name storage:
  44. Killed |max_bytes|, |max_names|, and |hash_size| --- all duplicated.
  45.  
  46. @d length(c) = ((c+1)->byte_start-(c)->byte_start) /* the length of a name */
  47. @d print_id(c) = ASCII_write((c)->byte_start,length((c)))
  48.   /* print identifier or module name */
  49. @d llink = link /* left link in binary search tree for module names */
  50. @d rlink = dummy.Rlink /* right link in binary search tree for module names */
  51. @d ilk = dummy.Ilk /* ilk in checking identifiers */
  52. @d root = name_dir->rlink /* the root of the binary search tree
  53.   for module names */
  54.  
  55. @<Common code...@>=
  56. typedef struct name_info {
  57.   ASCII *byte_start; /* beginning of the name in |byte_mem| */
  58.   struct name_info *link;
  59.   union {
  60.     struct name_info *Rlink; /* right link in binary search tree for module
  61.       names */  
  62.     eight_bits Ilk; /* used by identifiers in \.{WEAVE} (and for checking
  63.                             macros in \.{TANGLE}?) */
  64.   } dummy;
  65.   ASCII *equiv_or_xref; /* info corresponding to names */
  66. } name_info; /* contains information about an identifier or module name */
  67. typedef name_info *name_pointer; /* pointer into array of |name_info|s */
  68. typedef name_pointer *hash_pointer;
  69. extern ASCII byte_mem[]; /* characters of names */
  70. extern ASCII *byte_mem_end; /* end of |byte_mem| */
  71. extern name_info name_dir[]; /* information about names */
  72. extern name_pointer name_dir_end; /* end of |name_dir| */
  73. extern name_pointer name_ptr; /* first unused position in |byte_start| */
  74. extern ASCII *byte_ptr; /* first unused position in |byte_mem| */
  75. extern name_pointer hash[]; /* heads of hash lists */
  76. extern hash_pointer hash_end; /* end of |hash| */
  77. extern hash_pointer h; /* index into hash-head array */
  78. extern name_pointer id_lookup(); /* looks up a string in the identifier table */
  79. extern name_pointer mod_lookup(); /* finds module name */
  80. extern name_pointer prefix_lookup(); /* finds module name given a prefix */
  81.  
  82. @ Code related to error handling:
  83. @d spotless = 0 /* |history| value for normal jobs */
  84. @d harmless_message = 1 /* |history| value when non-serious info was printed */
  85. @d error_message = 2 /* |history| value when an error was noted */
  86. @d fatal_message = 3 /* |history| value when we had to stop prematurely */
  87. @d mark_harmless = {if (history==spotless) history=harmless_message;}
  88. @d mark_error = history=error_message
  89. @d confusion(s) = fatal("\n! This can't happen: ",s)
  90. @d fatal(s1,s2) = {
  91.   printf(s1); err_print(s2);
  92.   history=fatal_message; wrap_up();
  93. }
  94. @d overflow(s) = {
  95.   fatal("\n! Sorry, capacity exceeded: ",s);
  96. }
  97.  
  98. @<Common...@>=
  99. extern history; /* indicates how bad this run was */
  100.  
  101. @ Code related to file handling:
  102. @f line x /* make |line| an unreserved word */
  103. @d max_file_name_length = 60
  104. @d cur_file = file[include_depth] /* current file */
  105. @d cur_file_name = file_name[include_depth] /* current file name */
  106. @d web_file_name = file_name[0] /* main source file name */
  107. @d cur_line = line[include_depth] /* number of current line in current file */
  108.  
  109. @<Common code...@>=
  110. extern include_depth; /* current level of nesting */
  111. extern FILE *file[]; /* stack of non-change files */
  112. extern FILE *change_file; /* change file */
  113. extern char C_file_name[]; /* name of |C_file| */
  114. extern char tex_file_name[]; /* name of |tex_file| */
  115. extern char file_name[][max_file_name_length];
  116.   /* stack of non-change file names */
  117. extern char change_file_name[]; /* name of change file */
  118. extern line[]; /* number of current line in the stacked files */
  119. extern change_line; /* number of current line in change file */
  120. extern boolean input_has_ended; /* if there is no more input */
  121. extern boolean changing; /* if the current line is from |change_file| */
  122.  
  123. @ Code related to module numbers:
  124. @<Common code...@>=
  125. typedef unsigned short sixteen_bits;
  126. extern sixteen_bits module_count; /* the current module number */
  127. extern boolean changed_module[]; /* is the module changed? */
  128. extern boolean print_where; /* tells \.{TANGLE} to print line and file info */
  129.  
  130. @ Code related to command line arguments:
  131. @<Common code...@>=
  132. extern int argc; /* copy of |ac| parameter to |main| */
  133. extern char **argv; /* copy of |av| parameter to |main| */
  134. extern no_xref; /* should \.{WEAVE} print an index? */
  135.  
  136. @ Code relating to output:
  137. @d update_terminal = fflush(stdout) /* empty the terminal output buffer */
  138. @d new_line = putchar('\n') @d putxchar = putchar
  139. @d ASCII_write(a,b) = fflush(stdout), write(1,a,b) /* write on the standard output */
  140. @d line_write(c) = write(fileno(C_file),c) /* write on the C output file */
  141. @d C_printf(c,a) = fprintf(C_file,c,a)
  142. @d C_putc(c) = putc(c,C_file)
  143.  
  144. @<Common code...@>=
  145. FILE *C_file; /* where output of \.{TANGLE} goes */
  146. FILE *tex_file; /* where output of \.{WEAVE} goes */
  147.