home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / fweb153.zip / fweb-1.53 / web / typedefs.hweb < prev    next >
Text File  |  1995-09-23  |  9KB  |  426 lines

  1.  
  2.  
  3. @I formats.hweb
  4.  
  5. @ The actual names of the processors.
  6.  
  7. @m TANGLE "FTANGLE"
  8. @m WEAVE "FWEAVE"
  9.  
  10.  
  11. @ Some compilers can't handle files as large as \.{ftangle} or \.{fweave}.
  12. Therefore, if the C~preprocessor macros |part| are defined from the
  13. compiler's command line to have the value~1, 2, or~3, the other parts of
  14. those files are commented out.
  15.  
  16. @<Possibly split into parts@>=
  17.  
  18. #ifndef part
  19.     #define part 0 /* Standard value, when the files aren't split. */
  20. #else
  21.     #if(part != 1 && part != 2 && part != 3)
  22.         #define part 1 /* Should issue error message here. */
  23.     #endif
  24. #endif /* |part| */
  25.  
  26.  
  27. @
  28. @F EXTERN extern
  29.  
  30. @f IN_TANGLE extern
  31. @f IN_COMMON extern
  32. @f IN_RATFOR extern
  33. @f IN_EVAL extern
  34. @f IN_MACS extern
  35. @f IN_PROD extern
  36. @f IN_STYLE extern
  37.  
  38.  
  39. @f SET $_EXPR
  40. @f CSET $_EXPR
  41.  
  42. @<Possibly split...@>=
  43.  
  44. #if(part == 0 || part == 1)
  45.     #define part1_or_extern
  46.     #define SET1(stuff) @e = stuff
  47.     #define TSET1(stuff) @e = stuff
  48. #else
  49.     #define part1_or_extern extern
  50.     #define SET1(stuff)
  51.     #define TSET1(stuff)
  52. #endif
  53.  
  54.  
  55. @ Here's a somewhat sophisticated use of \WEB\ macros.
  56. @f WHILE while
  57. @f ptr_equals $EXPR_
  58. @m OCTAL0(n) $ASCII(#'n) /* Single-quote the argument and send to
  59.                 \.{\$ASCII}. */
  60. @m OCTAL(n) (eight_bits)OCTAL0(\@&n) /* Make octal constant. */
  61. @m HEX(n) (eight_bits)OCTAL0(\@&x##n) /* Make hex constant. */
  62.  
  63.  
  64. @
  65. @m IS_NEXT(c0,keyword)
  66. {
  67. eight_bits c;
  68.  
  69. if((c=next_byte()) != c0)
  70.     {
  71.     didnt_expand(c0,c,#*keyword);
  72.     return;
  73.     }
  74. }
  75.  
  76. @m IS_NEXT_PAREN(keyword) IS_NEXT('(',keyword)
  77.  
  78.  
  79. @
  80. @<Specific language cases@>=
  81.  
  82. case begin_C:
  83. case begin_RATFOR:
  84. case begin_FORTRAN:
  85. case begin_LITERAL@: @;
  86.  
  87.  
  88.  
  89. @
  90. @f @<|ASCII| cases for |C|@> case
  91. @f @<|ASCII| cases for |RATFOR|@> case
  92. @f @<|ASCII| cases for |FORTRAN|@> case
  93. @f @<|ASCII| cases for |TEX|@> case
  94. @f @<|ASCII| cases for |LITERAL|@> case
  95. @<|ASCII| cases for |C|@>=
  96. case @'c': case @'C'@: @;
  97.  
  98. @ @<|ASCII| cases for |RATFOR|@>=
  99. case @'r': case @'R'@: @;
  100.  
  101. @ @<|ASCII| cases for |FORTRAN|@>=
  102. case @'n': case @'N'@: @;
  103.  
  104. @ @<|ASCII| cases for |TEX|@>=
  105. case @'x': case @'X'@: @;
  106.  
  107. @ @<|ASCII| cases for |LITERAL|@>=
  108. case @'v': case @'V'@: @;
  109.  
  110.  
  111.  
  112. @
  113. @f @<|outer_char| cases for |C|@> case
  114. @f @<|outer_char| cases for |RATFOR|@> case
  115. @f @<|outer_char| cases for |FORTRAN|@> case
  116. @f @<|outer_char| cases for |TEX|@> case
  117. @f @<|outer_char| cases for |LITERAL|@> case
  118. @<|outer_char| cases for |C|@>=
  119. case 'c': case 'C'@: @;
  120.  
  121. @ @<|outer_char| cases for |RATFOR|@>=
  122. case 'r': case 'R'@: @;
  123.  
  124. @ @<|outer_char| cases for |FORTRAN|@>=
  125. case 'n': case 'N'@: @;
  126.  
  127. @ @<|outer_char| cases for |TEX|@>=
  128. case 'x': case 'X'@: @;
  129.  
  130. @ @<|outer_char| cases for |LITERAL|@>=
  131. case 'v': case 'V'@: @;
  132.  
  133.  
  134.  
  135. @ Read the basic language letter and set the language.  We must check for
  136. dialects before we call |opt_args| because the first thing that does is
  137. to set the language based on the values of the dialect flags.
  138.  
  139. @<Set |language|@>=
  140. {
  141. ASCII l = *loc++; /* The basic language letter. */
  142.  
  143. switch(l)
  144.     {
  145.    @<|ASCII| cases for |C|@>:
  146.     Cpp = BOOLEAN(*loc == @'+');
  147.     break;
  148.  
  149.    @<|ASCII| cases for |RATFOR|@>:
  150.    @<|ASCII| cases for |FORTRAN|@>:
  151.     Fortran88 = BOOLEAN(*loc == @'9');
  152.     break;
  153.  
  154.    @<|ASCII| cases for |LITERAL|@>:
  155.    @<|ASCII| cases for |TEX|@>:
  156.     break;
  157.  
  158.    default:
  159.     err_print(C,"! Invalid language command `@@L%c' ignored",XCHR(l));
  160.     break;
  161.     }
  162.  
  163. opt_args(l); /* Set the language, and parse optional arguments after
  164.         language command. */
  165. }
  166.  
  167.  
  168. @
  169. @m UPPER(var) smin0(MAX_VAL(ABBREV(var))),ABBREV(var)
  170.  
  171.  
  172. @ A simple error message with no arguments is used frequently.  Error
  173. messages now carry an indication of their origin.
  174.  
  175. @m err_print(origin,msg,...)
  176.     err0_print(ERR_##origin,OC(msg),#0,#.)
  177. @m ERR_PRINT(origin,msg) err_print(origin,msg)
  178.  
  179. @m MACRO_ERR(msg,trail,...)
  180.     macro_err(OC(msg),trail,#.)
  181.  
  182.  
  183. @ FORTRAN uses constructions such as~|@r .true.| or~|@r .and.|, which we
  184. have to parse separately.
  185.  
  186. @m PREDEFINED_DOTS 14 /* \# of pre-initialized entries in the |dots| table. */
  187.  
  188.  
  189. @
  190. @f HUGE_FCN_PTR huge
  191. @<Initialize |mod_info| and |Language|@>=
  192. {
  193. /* We allocate |MOD_INFO| structures only for module names, not for
  194.     identifiers. */
  195. node->mod_info = GET_MEM("mod_info",1,MOD_INFO);
  196.  
  197. node->mod_info->Ilk = expr;
  198. node->mod_info->params = params; /* Freeze parameters at this point in time. */
  199.  
  200. node->Language = (boolean)language; /* Redundant. */
  201. }
  202.  
  203.  
  204. @ For initializing |ccodes|.
  205.  
  206. @m INI_CCODE(defaults,code)
  207.     ini_ccode((outer_char *)#code,(outer_char *)defaults,code)
  208.         /* We use the same keyword name as the \FWEB\ code. */
  209.  
  210. @m REASSIGNABLE(d,c) INI_CCODE(d,c) /* For stuff that must later be
  211. reassigned for     \FTANGLE. */
  212.  
  213. @m SAME_CCODE(d,c) INI_CCODE(d,c)
  214.  
  215.  
  216. @ Macros to guard against overflow during |sprintf| or |vprintf|. The function
  217. |nsprintf| is defined in \.{common.web} to handle non-ANSI return values from
  218. |sprintf|.
  219.  
  220. @m NSPRINTF(buf_name,fmt,...)
  221.     nsprintf(buf_name,OC(fmt),#0,#.)
  222. @m NVSPRINTF(buf_name,fmt,...)
  223.     nvsprintf(buf_name,OC(fmt),#0,#.)
  224.  
  225. @m SPRINTF(nmax,buf_name,args)
  226.     if(NSPRINTF(buf_name,args) >= (int)(nmax)) OVERFLW(#buf_name,"")@;
  227.  
  228. @m VSPRINTF(nmax,buf_name,args)
  229.     if(NVSPRINTF(buf_name,args) >= (int)(nmax)) OVERFLW(#buf_name,"")@;
  230.  
  231. @m vsprintf_(out,fmt,arg_ptr)
  232.     $P if(NUM_VA_ARGS == 1)
  233.         {
  234.         char *fmt0 = va_arg(arg_ptr,char *);
  235.  
  236.         va_arg(arg_ptr,int); /* Skip over~$n$. */
  237.         vsprintf((char *)out,fmt0,arg_ptr);
  238.         }
  239.     $P else
  240.         vsprintf(out,fmt,arg_ptr);
  241.     $P endif
  242.  
  243. @m vprintf_(fmt,arg_ptr)
  244.     $P if(NUM_VA_ARGS == 1)
  245.         {
  246.         char *fmt0 = va_arg(arg_ptr,char *);
  247.  
  248.         va_arg(arg_ptr,int);
  249.         vprintf(out,fmt0,arg_ptr);
  250.         }
  251.     $P else
  252.         vprintf(fmt,arg_ptr);
  253.     $P endif
  254.  
  255. @f VA_ARGS $_EXPR
  256. @f VA_DECL int
  257. @f VA_LIST int
  258.  
  259.  
  260. @ Abbreviations for buffer allocations.
  261.  
  262. @m ABBREV(name) V_##name
  263.  
  264. @m V_buf_size "bs"
  265. @m V_C_buf_size "cb"
  266. @m V_cmd_fsize "cf"
  267. @m V_cmd_size "cg"
  268. @m V_delta_dots "d"
  269. @m V_line_length "ll"
  270. @m V_longest_name "ln"
  271. @m V_max_bytes "b"
  272. @m V_dtexts_max "dx"
  273. @m V_max_dtoks "dt"
  274. @m V_max_expr_chars "lx"
  275. @m V_max_lbls "lb"
  276. @m V_max_margs "ma"
  277. @m V_max_ifiles "if"
  278. @m V_max_include_depth "id"
  279. @m V_max_modules "m"
  280. @m V_max_names "n"
  281. @m V_max_refs "r"
  282. @m V_max_scraps "s"
  283. @m V_max_texts "x"
  284. @m V_max_toks_t "tt"
  285. @m V_max_toks_w "tw"
  286. @m V_mbuf_size "mb"
  287. @m V_op_entries "op"
  288. @m V_num_files "nf"
  289. @m V_sbuf_len "sb"
  290. @m V_stck_size_t "kt"
  291. @m V_stck_size_w "kw"
  292. @m V_X_buf_size "xb"
  293.  
  294.  
  295. @
  296. @f X_FCN void
  297. @m RAT_ERROR(err_type,msg,n,...)
  298.     RAT_error(err_type,OC(msg),n,#.)
  299.  
  300.  
  301. @ For~C, getting an identifier is simple. For FORTRAN, we treat \&{format}
  302. statements much like C's preprocessor statement. However, there's no
  303. special character to start a \&{format} line; we have to actually check the
  304. identifier. Furthermore, it looks nicer if constructions such as \\{f6.2}
  305. are treated as one identifier, so when we're inside a \&{format} statement
  306. we allow the period to be an acceptable (internal) character for an
  307. identifier.
  308.  
  309. @<Get an identifier@>=
  310. {
  311. IN_COMMON ASCII HUGE *pformat, HUGE *pdata;
  312.  
  313. get_identifier:
  314.     @<Make |id_first| and |id_loc| point to the identifier@>@;
  315.  
  316. if(FORTRAN_LIKE(language))
  317.     {
  318.     if(web_strcmp(pformat,pformat+6,id_first,id_loc) == EQUAL)
  319.         { /* Raise special flag to say we're inside a |@r format|
  320. statement. */
  321.         in_format = YES;
  322.         return begin_format_stmt;
  323.         }
  324.     else if(program==weave)
  325.         {
  326.         if(web_strcmp(pdata,pdata+4,id_first,id_loc) == EQUAL)
  327.             { /* Inside a |@r data| statement. */
  328.             in_data = YES;
  329.             return identifier;
  330.             }
  331.         else if(at_beginning && *loc==':' &&
  332.                 !is_in(non_labels,id_first,id_loc))
  333.             return stmt_label;
  334.         }
  335.     }
  336.  
  337. if(is_include_like()) sharp_include_line = YES;
  338. return identifier;
  339. }
  340.  
  341.  
  342. @
  343. @<Make |id_first|...@>=
  344. {
  345. id_first = --loc;
  346.  
  347. /* Scan over subsequent elements of an identifier. */
  348. for(++loc; isAlpha(*loc) || isDigit(*loc)
  349.     || *loc==@'_' || *loc==@'$' || (in_format && *loc==@'.'); loc++)
  350.         ;
  351.  
  352. id_loc = loc;  /* End plus one of the identifier.*/
  353. }
  354.  
  355.  
  356. @ Here we obtain the file name after an \.{@@o}~command.
  357. @<Scan the output file name@>=
  358. {
  359. while(*loc == ' ' || *loc == tab_mark)
  360.     {
  361.     loc++;
  362.     if(loc > limit) return ignore;
  363.     }
  364.  
  365. id_first = loc;
  366. while(*loc != ' ' && *loc != tab_mark) loc++; /* Absorb file name. */
  367. id_loc = loc;
  368. if(*id_first == '"') id_first++;
  369. if(*(id_loc-1) == '"') id_loc--;
  370. if(id_loc - id_first >= MAX_FILE_NAME_LENGTH)
  371.     {
  372.     err_print(T,"Output file name too long; allowed only %d characters",
  373.         MAX_FILE_NAME_LENGTH - 1);
  374.     id_loc = id_first + MAX_FILE_NAME_LENGTH - 1;
  375.     }
  376. }
  377.  
  378.  
  379. @ The preprocessor commands are piggy-backed on the \.{@@\#} command. If
  380. there's text after that command, then we hunt through the above table.
  381. If we find a processor command, any subsequent white space is skipped.
  382. (This was added for nuweb mode, which otherwise takes each blank one at a
  383. time.)  Otherwise, it's a |big_line_break|.
  384.  
  385. @<Process possible preprocessor command@>=
  386. {
  387. boolean mcode;
  388.  
  389. *limit = ' '; /* Terminator for identifier search. */
  390. id_first = loc;
  391.  
  392. while(isAlpha(*loc)) loc++; /* Find end of identifier. */
  393.  
  394. if((mcode=is_mcmd(mcmds,id_first,loc)) != 0)
  395.     {
  396.     while(loc < limit && (*loc == @' ' || *loc == tab_mark))
  397.         loc++;
  398.  
  399.     return mcode;
  400.     }
  401.  
  402. loc = id_first; /* Failed to recognize preprocessor command. */
  403. }
  404.  
  405.  
  406. @
  407. @<Glob...@>=
  408.  
  409. /* The shorter length here is primarily to keep the stack under control.
  410. Now that |N_MSGBUF| is used  dynamically, maybe this statement isn't
  411. necessary. */
  412. #ifdef SMALL_MEMORY
  413.     #define N_MSGBUF 2000
  414. #else
  415.     #define N_MSGBUF 10000
  416. #endif
  417.  
  418.  
  419.  
  420. @
  421. @<Include...@>=
  422. #include "typedefs.h"
  423.  
  424.  
  425.  
  426.