home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / fweb153.zip / fweb-1.53 / web / style.web < prev    next >
Text File  |  1995-09-23  |  35KB  |  1,612 lines

  1. @z --- style.web ---
  2.  
  3. FWEB version 1.53 (September 23, 1995)
  4.  
  5. Based on version 0.5 of S. Levy's CWEB [copyright (C) 1987 Princeton University]
  6.  
  7. @x-----------------------------------------------------------------------------
  8.  
  9.  
  10. \Title{STYLE.WEB} % Reading the style file for FWEAVE and FTANGLE.
  11.  
  12. @c
  13. @* INTRODUCTION.
  14. Here we read a style file. Style files are used to customize the output of
  15. \FWEAVE---for example, to adjust the appearance of the index.  The default
  16. style file is called \.{fweb.sty} in the directory set by the environment
  17. variable \.{FWEB\_STYLE\_DIR}, or in the directory of the \WEB\ source.
  18. The name can be changed with the \.{-z}~option: ``\.{-znew\_name}''.
  19.  
  20. Unlike the rest of the \FWEB\ processors, the style file does not
  21. automatically convert its input into |ASCII|.  That's because most of its
  22. fields are never manipulated internally, but are just written to the output
  23. file.  This may or may not have been a good design decision.
  24.  
  25. Associations between vocabulary words and internal \FWEB\ fields are made
  26. in \.{map.web}.
  27.  
  28. \It{We should discuss the detailed scheme here.}
  29.  
  30. @m _STYLE_
  31. @d _STYLE_h
  32.  
  33. @A 
  34. @<Include files@>@;
  35. @<Typedef declarations@>@;
  36. @<Global variables@>@;
  37.  
  38. @I typedefs.hweb
  39.  
  40. @
  41. @<Include...@>=
  42. #include "map.h"
  43.  
  44.  
  45. @d CMNT_CHAR '%' // The comment character in the style file.
  46.  
  47. @I mem.hweb
  48.  
  49. @ We need a few miscellaneous declarations.
  50. @<Glob...@>=
  51.  
  52. outer_char HUGE *sprm_buf,HUGE *sprm_ptr,HUGE *sprm_end; // For \.{-p} option.
  53. outer_char HUGE *sprm_ptr0; // Marks beginning of command-line \.{-p} options.
  54.  
  55. boolean from_sprm;
  56. static BUF_SIZE sbuf_len; // Length of line buffer.
  57. static outer_char HUGE *stemp, HUGE *stemp_end,HUGE *tloc; /* Temporary
  58.     hold for the argument, and position in it. */ 
  59. static outer_char cur_char; /* Current character after possible escape
  60.                 translation. */
  61. extern ASCII xord[];
  62. extern outer_char xchr[];
  63.  
  64. @* PROCESSING ARGUMENTS. We begin with a routine that converts the
  65. character representation of an escaped character to the proper byte.  Note
  66. that the escapes \.{'\\\\'}, \.{'\\''}, \.{'\\"'}, and~\.{'\\?'} can be
  67. handled as part of the |default|.  This routine also handles octal and hex
  68. escapes of the form~\.{\\123} or~\.{\\xFF}.  The function takes the address
  69. of a pointer to the first character; when it exits, that pointer has been
  70. updated to the next non-translated character.  We provide separate
  71. functions for escaping |outer_char|s and |ASCII|s.
  72.  
  73. @d isodigit(c) (isdigit(c) && (c)!='8' && (c)!='9')
  74.     // An |outer_char| octal digit?
  75.  
  76. @a
  77. outer_char esc_char FCN((ppc))
  78.     CONST outer_char HUGE * HUGE *ppc C1("")@;
  79. {
  80. int k;
  81. unsigned n;
  82. CONST outer_char HUGE *pc = *ppc; // Pointer to first character after~'\.\\'.
  83.  
  84. if(isodigit(*pc))
  85.     @<Process octal constant@>@;
  86. else if(*pc == 'x' && isxdigit(*(pc+1)))
  87.     @<Process hex constant@>@;
  88. else 
  89.     { /* Handle ordinary escaped character. */
  90.     switch(*pc)
  91.         {
  92.           case 'a': n = '\007'; @+ break;
  93.        case 'b': n = '\b'; @+ break;
  94.        case 'f': n = '\f'; @+ break;
  95.        case 'n': n = '\n'; @+ break;
  96.        case 'r': n = '\r'; @+ break;
  97.        case 't': n = '\t'; @+ break;
  98.        case 'v': n = '\v'; @+ break;
  99.        default: 
  100.         n = (unsigned)(*pc); // Unknowns, like '\.{\\m}' $\to$~'\.m'.
  101.         break;
  102.         }
  103.     pc++;
  104.     }
  105.  
  106. *ppc = pc;
  107. return (outer_char)n;
  108. }
  109.  
  110. @ Octal constants have the form \.{\\123}.
  111. @<Process octal constant@>=
  112. {
  113. n = ctoi(*pc++);
  114. for(k=0; k<2; k++)
  115.     {
  116.     if(!isodigit(*pc)) break;
  117.     n = 8*n + ctoi(*pc++);
  118.     }
  119. }
  120.  
  121. @ Hex constants have the form \.{\\xFF}.
  122. @<Process hex constant@>=
  123. {
  124. pc++; // Position after \.{'x'}.
  125. n = ctoi(*pc++);
  126. if(isxdigit(*pc)) n = 16*n + ctoi(*pc++);
  127. }
  128.  
  129. @ The corresponding function for |ASCII|.
  130.  
  131. @a
  132. ASCII esc_achar FCN((ppc))
  133.     CONST ASCII HUGE * HUGE *ppc C1("")@;
  134. {
  135. int k;
  136. unsigned n;
  137. CONST ASCII HUGE *pc = *ppc; // Pointer to first character after~'\.\\'.
  138.  
  139. if(isOdigit(*pc))
  140.     @<Process Octal constant@>@;
  141. else if(*pc == @'x' && isXdigit(*(pc+1)))
  142.     @<Process Hex constant@>@;
  143. else 
  144.     {
  145.     switch(*pc)
  146.         {
  147.           case @'a': n = @'\007'; @+ break;
  148.        case @'b': n = @'\b'; @+ break;
  149.        case @'f': n = @'\f'; @+ break;
  150.        case @'n': n = @'\n'; @+ break;
  151.        case @'r': n = @'\r'; @+ break;
  152.        case @'t': n = @'\t'; @+ break;
  153.        case @'v': n = @'\v'; @+ break;
  154.        default: n = *pc; @+ break; // Unknowns, like '\.{\\m}' $\to$~'\.m'.
  155.         }
  156.  
  157. #if(DEBUG_XCHR)
  158.     n = XCHR(n);
  159. #endif
  160.     pc++;
  161.     }
  162.  
  163. *ppc = pc; // Advance the pointer to point beyond the end of the constant.
  164.  
  165. #if(DEBUG_XCHR)
  166.     n = xord[n];
  167. #endif
  168.  
  169. return (ASCII)n; // Return the value.
  170. }
  171.  
  172. @ Octal constants have the form \.{\\123}.  The following is for |ASCII|.
  173. @<Process Octal constant@>=
  174. {
  175. n = Ctoi(*pc++);
  176. for(k=0; k<2; k++)
  177.     {
  178.     if(!isOdigit(*pc)) break;
  179.     n = 8*n + Ctoi(*pc++);
  180.     }
  181. }
  182.  
  183. @ Hex constants have the form \.{\\xFF}.  The following is for |ASCII|.
  184. @<Process Hex constant@>=
  185. {
  186. pc++; // Position after \.{'x'}.
  187. n = Ctoi(*pc++);
  188. if(isXdigit(*pc)) n = 16*n + Ctoi(*pc++);
  189. }
  190.  
  191. @ Translate a hex |outer_char| into integer.
  192.  
  193. @m XC(cin,cout) case cin: return 0x##cout@;
  194.  
  195. @d Ctoi(c) ctoi(XCHR(c)) // For |ASCII|.
  196.  
  197. @a
  198. int ctoi FCN((c))
  199.     outer_char c C1("")@;
  200. {
  201. switch(c)
  202.     {
  203.    XC('0',0); XC('1',1); XC('2',2); XC('3',3); XC('4',4); XC('5',5);
  204.    XC('6',6); XC('7',7); XC('8',8); XC('9',9); 
  205.    XC('a',a); @+ XC('A',A);
  206.    XC('b',b); @+ XC('B',B);
  207.    XC('c',c); @+ XC('C',C);
  208.    XC('d',d); @+ XC('D',D);
  209.    XC('e',e); @+ XC('E',E);
  210.    XC('f',f); @+ XC('F',F);
  211.    default: return 0;
  212.     }
  213. }
  214.  
  215. @ Search for a keyword.  Returns address of the relevant |S_MAP| entry.
  216. @a
  217. S_MAP HUGE *find_sty FCN((m,keyword))
  218.     S_MAP HUGE *m C0("Array of map variables")@;
  219.     CONST outer_char HUGE *keyword C1("Search for this keyword")@;
  220. {
  221. for(; *(m->keyword); m++)
  222.     if(STRCMP(keyword,m->keyword) == 0) return m;
  223.  
  224. return NULL;
  225. }
  226.  
  227. @ Read one line from style file. 
  228. @a
  229. boolean sty_line(VOID)
  230. {
  231. typedef enum {FROM_INI, FROM_LOCAL, FROM_CMD_LINE} STYLE_MODE;
  232.  
  233. static STYLE_MODE mode = FROM_INI;
  234.  
  235. from_sprm = BOOLEAN(mode == FROM_INI || mode == FROM_CMD_LINE);
  236.  
  237. switch(mode)
  238.     {
  239.    case FROM_INI:
  240.     if(!sty0_line(sprm_ptr0))
  241.         mode++;
  242.     else
  243.         return YES;
  244.  
  245.    case FROM_LOCAL:
  246.     if(!sty0_line(NULL))
  247.         mode++;
  248.     else
  249.         return YES;
  250.  
  251.    case FROM_CMD_LINE:
  252.     return sty0_line(sprm_end);
  253.     }
  254.  
  255. return YES; // Dummy.
  256. }
  257.  
  258. boolean sty0_line FCN((last_sprm))
  259.     outer_char HUGE *last_sprm C1("")@;
  260. {
  261. int c; /* Single character read from style file. |int| rather than |char|
  262.         because that's what |getc| returns. */
  263.  
  264. sloc = slimit = sbuf; // Position to beginning of line.
  265.  
  266. if(last_sprm)
  267.     { /* Read from the \.{-p} buffer. */
  268.     if(sprm_ptr >= last_sprm) 
  269.         { /* Nothing more in the \.{-p} buffer. */
  270.         s_line = 0;
  271.         return NO;
  272.         }
  273.     else
  274.         { /* Copy line from \.{-p} buffer. */
  275.         int n;
  276.         outer_char HUGE *p;
  277.  
  278.         if((p=(outer_char HUGE *)STRCHR(sprm_ptr,'\n')) == NULL)
  279.             {
  280.             err_print(S,"Trouble in sty_line");
  281.             return NO;
  282.             }
  283.         else n = PTR_DIFF(int, p, sprm_ptr);
  284.     
  285.         STRNCPY(sloc,sprm_ptr,n);
  286.         sprm_ptr += n + 1;
  287.         slimit += n;
  288.         s_line++;
  289.         }
  290.     }
  291. else
  292.     { /* Read from the local style file. */
  293.     if(!sty_file) 
  294.         @<Attempt to open style file@>@;
  295.  
  296.     @<Move characters from style file; |return NO| if end-of-file@>@;
  297.     }
  298.  
  299. return YES;
  300. }
  301.  
  302. @
  303. @<Attempt to open...@>=
  304. {
  305. outer_char full_sty_name[MAX_FILE_NAME_LENGTH];
  306.  
  307. /* If there's no style file, do nothing. */
  308. if(!*sty_file_name) return NO;
  309.  
  310. if(warn_if_absent) 
  311.     {
  312.     STRCPY(full_sty_name,sty_file_name);
  313.     add_prefix(full_sty_name);
  314.     }
  315. else mk_fname(full_sty_name,MAX_FILE_NAME_LENGTH,
  316.                 OC(ENV_FWEB_STY),NO,sty_file_name);
  317.  
  318. if((sty_file = fopen((char *)full_sty_name,"r")) == NULL)
  319.     {
  320.     if(warn_if_absent) 
  321.         {
  322.         err_print(C,"Can't open style file \"%s\"",
  323.             full_sty_name);
  324.         }
  325.     return NO;
  326.     }
  327.  
  328. reading(full_sty_name,YES);
  329. }
  330.  
  331. @
  332. @<Move characters from style...@>=
  333. {
  334. if(feof(sty_file)) 
  335.     return NO;
  336.  
  337. s_line++;
  338.  
  339. while((c = getc(sty_file)) != EOF && c != '\n')
  340.     {
  341.     if(slimit == sbuf_end)
  342.         {
  343.         err_print(S,"Input line too long; max is %lu characters",
  344.             sbuf_len);
  345.         ungetc(c,sty_file);
  346.         break;
  347.         }
  348.  
  349.     *slimit++ = (outer_char)c; // Put character into buffer.
  350.     }
  351. }
  352.  
  353. @ Extract the next argument from the style file.  Keywords begin with an
  354. alphabetic character or an underscore.
  355. @a
  356. STY_TYPE next_sty(VOID)
  357. {
  358. outer_char c; /* Single character from the buffer. */
  359.  
  360. WHILE()
  361.     {
  362. /* If we get to the end of the line or recognize a comment, read the next
  363. line. */
  364.     if(sloc == slimit || (c= *sloc++) == CMNT_CHAR) 
  365.         {
  366.         if(!sty_line()) return S_DONE; // Get more.
  367.         continue;
  368.         }
  369.  
  370.     if(isalpha(c) || c=='_') @<Style keyword@>@;
  371.     else if(isdigit(c) || c=='-' || c=='+') @<Style number@>@;
  372.     else if(c == '"') @<Style string@>@;
  373.     else if(c == '\'') @<Style character@>@;
  374.     else if(c==' ' || c=='\t' || c=='=') continue;
  375.     else 
  376.         {
  377.         err_print(S,"Invalid style-file field; \
  378. skipping remainder of file");
  379.         longjmp(top_of_style,1);
  380.         }
  381.     }
  382.  
  383. DUMMY_RETURN(S_DONE);
  384. }
  385.  
  386. @ Read a keyword into the buffer |stemp|.  Keywords consists of
  387. alphanumeric characters, underscores, or periods.  However, the periods are
  388. made equivalent to underscore so one can things such as ``\.{color.red}''
  389. instead of ``\.{color\_red}''.
  390.  
  391. @m S_RETURN(t) *tloc = '\0'; return S_##t@; /* Terminate |stemp|, and
  392.                     return the appropriate type. */
  393.  
  394. @<Style keyword@>=
  395. {
  396. sloc--;
  397. tloc = stemp;
  398. while(isalpha(*sloc) || isdigit(*sloc) || *sloc=='_' || *sloc=='.')
  399.     {
  400.     cur_char = *sloc++;
  401.     @<Copy and translate style character@>@; 
  402.     }
  403.  
  404. S_RETURN(KEYWORD);
  405. }
  406.  
  407. @ Move one character into |stemp|.
  408. @<Copy and translate style char...@>=
  409. {
  410. if(tloc < stemp_end) 
  411.     *tloc++ = (outer_char)CHOICE(cur_char=='.', '_', cur_char);
  412. else
  413.     {
  414.     err_print(S,"Buffer overflow");
  415.     break;
  416.     }
  417. }
  418.  
  419. @
  420. @<Copy style character@>=
  421. {
  422. if(tloc < stemp_end) *tloc++ = cur_char;
  423. else
  424.     {
  425.     err_print(S,"Buffer overflow");
  426.     break;
  427.     }
  428. }
  429.  
  430. @ Process a string argument (bracketed by double quotes).  We must allow
  431. for escapes, such as ``\.{\\123}''.
  432. @<Style string@>=
  433. {
  434. tloc = stemp; /* Start of buffer. */
  435.  
  436. while(*sloc != '"')
  437.     {
  438.     if(*sloc == '\\')
  439.         if(++sloc == slimit)
  440.             {
  441.             sty_line(); // String is continued.
  442.             continue;
  443.             }
  444.         else cur_char = esc_char(&sloc);
  445.     else cur_char = *sloc++;
  446.  
  447.     @<Copy sty...@>@;
  448.     }
  449.  
  450. sloc++; // Skip over terminating quote.
  451.  
  452. S_RETURN(STRING);
  453. }
  454.  
  455. @ Process a numerical argument.
  456. @<Style number@>=
  457. {
  458. sloc--;
  459. tloc = stemp;
  460. if(*sloc=='+' || *sloc=='-') {cur_char = *sloc++; @<Copy sty...@>@;}
  461.  
  462. while(isdigit(*sloc)) {cur_char = *sloc++; @<Copy sty...@>@;}
  463.  
  464. /* We allow the possibility of long integers. */
  465. if(*sloc == 'l' || *sloc == 'L')
  466.     {
  467.     sloc++; // Skip over '\.L'.
  468.     S_RETURN(LONG);
  469.     }
  470.  
  471. S_RETURN(INT);
  472. }
  473.  
  474. @ Process a character argument such as~'\.c' or~'\.{\\n}'.
  475. @<Style character@>=
  476. {
  477. tloc = stemp;
  478.  
  479. /* If the character is escaped, turn the next character into the actual
  480. byte. */
  481. if(*sloc == '\\') {sloc++; cur_char = esc_char(&sloc);}
  482. else cur_char = *sloc++;
  483.  
  484. @<Copy sty...@>@;
  485. sloc++; // Skip over closing quote.
  486.  
  487. S_RETURN(CHAR);
  488. }
  489.  
  490. @* READING the STYLE FILE.
  491. The style file is both opened and closed in this module.
  492.  
  493. @f jmp_buf int
  494.  
  495. @<Glob...@>=
  496.  
  497. static CONST outer_char *sty_file_name;
  498. static boolean warn_if_absent;
  499. static FILE *sty_file;
  500. static S_MAP HUGE *map_array = fweb_map; /* Points to the common map
  501.     array for both \FWEAVE\ and \FTANGLE. */
  502. jmp_buf top_of_style; // Environment for the |setjmp|--|longjmp|.
  503.  
  504. @ It's read line by line into a buffer. The length of that buffer can be
  505. set by dynamic memory allocation with option~\.{-ysb}.
  506.  
  507. @d ENV_FWEB_STY "FWEB_STYLE_DIR" /* Environment variable that defines
  508.         directory of style file.  */
  509.  
  510. @a
  511. SRTN read_sty FCN((sty_file_name0,warn_if_absent0))
  512.     CONST outer_char sty_file_name0[] C0("")@;
  513.     boolean warn_if_absent0 C1("")@;
  514. {
  515. sty_file_name = sty_file_name0;
  516. warn_if_absent = warn_if_absent0;
  517.  
  518. @<Modify defaults based on option settings@>@;
  519.  
  520. @<Allocate buffers for the style file@>@;
  521.  
  522. if(setjmp(top_of_style) != 0) goto done_sty;
  523.  
  524. /* Read the first line of style file. If the file's empty, do nothing. */
  525. if(!sty_line()) goto done_sty;
  526.  
  527. /* Parse the file. */
  528. WHILE()
  529.     switch(next_sty())
  530.         {
  531.         case S_CMNT: break;
  532.  
  533.         case S_KEYWORD:
  534.             @<Process style keyword@>@;
  535.             break;
  536.  
  537.         default:
  538.             err_print(S,"Was expecting keyword or comment here; \
  539. skipping remainder of file"); // Falls through to |case S_DONE@:|.
  540.  
  541.         case S_DONE:
  542.          done_sty:
  543.             if(sty_file) fclose(sty_file);
  544.             if(sprm_buf) FREE(sprm_buf);
  545.             FREE_MEM(stemp,"stemp",sbuf_len,outer_char);
  546.             FREE_MEM(sbuf,ABBREV(sbuf_len),sbuf_len,outer_char);
  547.             return;
  548.         }
  549. }
  550.  
  551. @ In a few cases, the proper defaults depend on command-line options; for
  552. example, which processor will be used to process \FWEAVE's output.
  553. @<Modify defaults...@>=
  554. {
  555. IN_COMMON outer_char HUGE *style_args;
  556.  
  557. if(TeX_processor == LaTeX_p)
  558.     {
  559.     W_META HUGE *m = &w_style.misc.meta;
  560.     INDEX HUGE *i = &w_style.indx;
  561.  
  562.     pfmt->id = pfmt->id_outer = pfmt->id_inner = OC("\\>");
  563.     pfmt->ID = pfmt->ID_OUTER = pfmt->ID_INNER = OC("\\WUC");
  564.     pfmt->RESERVED = OC("\\WRS");
  565.  
  566.     m->TeX.begin = OC("\\begin{verbatim}");
  567.     m->TeX.end = OC("\\end{verbatim}");    
  568.     m->code.begin = OC("\\WBM ");
  569.     m->code.end = OC("\\WEM ");
  570.  
  571.     i->encap_prefix = OC("\\M");
  572.     i->encap_infix = OC("{");
  573.     i->encap_suffix = OC("}");
  574.     }
  575.  
  576. if(prn_style_defaults) 
  577.     see_style(style_args, YES);
  578. }
  579.  
  580. @ We temporarily allocate buffers for working with the style file.
  581. @<Allocate buffers...@>=
  582. {
  583. ALLOC(outer_char,sbuf,ABBREV(sbuf_len),sbuf_len,0);
  584. sbuf_end = sbuf + sbuf_len;
  585.  
  586. stemp = GET_MEM("stemp",sbuf_len,outer_char);
  587. stemp_end = stemp + sbuf_len;
  588.  
  589. /* Reset the \.{-p} buffer. */
  590. sprm_end = sprm_ptr; // Actual end of material in buffer.
  591. sprm_ptr = sprm_buf; // Start at beginning.
  592. }
  593.  
  594. @ At the very beginning, initializations must be finished.
  595. @a
  596. SRTN ini_style(VOID)
  597. {
  598. ini_colors(NO_COLOR);
  599.  
  600. @<Finish initializing mappings@>@;
  601. }
  602.  
  603. @ We've recognized a keyword. Now deal with its arguments.  First, the
  604. argument is copied into the appropriate field.  Then, if an initialization
  605. routine has been defined, that routine is run on the argument.  The
  606. argument might be checked for validity, or it might be changed into
  607. something else.
  608. @<Process style key...@>=
  609. {
  610. S_MAP HUGE *ps; // Returned from |find_sty|.
  611. STY_TYPE type;
  612.  
  613. /* Is it a valid keyword? */
  614. if((ps = find_sty(map_array,stemp)) == NULL)
  615.     {
  616.     err_print(S,"Invalid style-file keyword; skipping remainder of line");
  617.     sty_line();
  618.     break;
  619.     }
  620.  
  621. /* Get the next argument. Is its type correct? */
  622. type = ps->type & ~S_MODIFIED;
  623.  
  624. if(type != next_sty())
  625.     {
  626.     err_print(S,"Argument of keyword \"%s\" has wrong type; \
  627. conversion attempted",ps->keyword);
  628.     }
  629.  
  630. switch(type)
  631.     {
  632.     case S_INT:
  633.     case S_LONG:
  634.     case S_STRING:
  635.     case S_CHAR:
  636.     break;
  637.  
  638.     default:
  639.         err_print(S,"Was expecting integer, double-quoted string, \
  640. or single-quoted character here; argument not processed");
  641.         goto processed;
  642.     }
  643.  
  644. /* Store the argument, check for validity, or process the result in some
  645. way. */
  646. if(ps->init) 
  647.     (*ps->init)(ps); 
  648. else 
  649.     CONFUSION("style keyword","NULL ini fcn");
  650.  
  651. /* Flag it as modified. */
  652. ps->type |= S_MODIFIED;
  653.  
  654. processed:;
  655. }
  656.  
  657.     
  658. @ Initialize a string.  (No error checking.)
  659. @a
  660. SRTN set_str FCN((ps))
  661.     S_MAP HUGE *ps C1("")@;
  662. {
  663. a_str(ps->ptr,(CONST outer_char HUGE *)stemp);
  664. }
  665.  
  666. @ Here we add a string to an already-existing (non-NULL) one, placing a
  667. newline in between.  If the original string is null, we just initialize it
  668. as usual.
  669.  
  670. @a
  671. SRTN add_str FCN((ps))
  672.     S_MAP HUGE *ps C1("")@;
  673. {
  674. outer_char HUGE *pa = *(outer_char HUGE **)ps->ptr, HUGE *pb;
  675.  
  676. if(*pa)
  677.     {
  678.     pb = GET_MEM("add_str",STRLEN(pa) + STRLEN(stemp) + 2,outer_char);
  679.     STRCPY(pb,pa);
  680.     STRCAT(pb,"\n");
  681.     STRCAT(pb,stemp);
  682.     *(outer_char HUGE **)ps->ptr = pb;
  683.     }
  684. else set_str(ps);
  685. }
  686.  
  687. @ Initialize an integer.  (No error checking.)
  688. @a
  689. SRTN set_int FCN((ps))
  690.     S_MAP HUGE *ps C1("")@;
  691. {
  692. *((int *)ps->ptr) = ATOI(stemp);
  693. }
  694.  
  695. @ Similarly, initialize a long.  (No error checking.)
  696. @a
  697. SRTN set_long FCN((ps))
  698.     S_MAP HUGE *ps C1("")@;
  699. {
  700. *((long *)ps->ptr) = ATOL(stemp);
  701. }
  702.  
  703. @ Initialize a character (no error checking).
  704. @a
  705. SRTN set_char FCN((ps))
  706.     S_MAP HUGE *ps C1("")@;
  707. {
  708. *((outer_char *)ps->ptr) = *stemp;
  709. }
  710.  
  711. @
  712. @<Typedef...@>=
  713.  
  714. typedef struct
  715.     {
  716.     CONST char *name;
  717.     COLOR value;
  718.     } CLR_MATCH;
  719.  
  720. CLR_MATCH clr_match[] = {
  721.     {"blue",BLUE},
  722.     {"default",NORMAL},
  723.     {"green",GREEN},
  724.     {"normal",NORMAL},
  725.     {"orange",ORANGE},
  726.     {"red",RED},
  727.     {"yellow",YELLOW},
  728.     {"",NORMAL}
  729.     };
  730.  
  731. @* VALIDITY CHECKS. 
  732. We begin with an initialization routine for color.  It replaces strings like
  733. \.{"red"} by enumerated values like~|RED|.
  734. @a
  735. SRTN ini_aclr FCN((ps))
  736.     S_MAP HUGE *ps C1("")@;
  737. {
  738. CLR_MATCH HUGE *c;
  739.  
  740. set_str(ps);
  741.  
  742. for(c=clr_match; STRCMP(c->name,"") != 0; c++)
  743.     if(STRCMP(c->name,*(outer_char HUGE **)ps->ptr) == 0)
  744.         {
  745.         *(COLOR *)ps->ptr = c->value;
  746.         return;
  747.         }
  748.  
  749. CLR_PRINTF(warning,("! Color name \"%s\" is invalid; \
  750. replaced by \"default\"\n",(char *)ps->ptr));
  751. mark_harmless;
  752.  
  753. *(COLOR *)ps->ptr = NORMAL;
  754. }
  755.  
  756. @ Initialization routine for \.{color.mode}.
  757. @a
  758. SRTN ini_clr FCN((ps))
  759.     S_MAP HUGE *ps C1("")@;
  760. {
  761. set_int(ps);
  762. ini_colors((COLOR_MODE)(*(int *)ps->ptr));
  763. }
  764.  
  765. @ Initialization routines for file name extension are create via a \WEB\
  766. macro. 
  767.  
  768. @m EXT_LINK(file,dflt) link0(&wt_style.input_ext.file,OC(dflt),ext_set)
  769.  
  770. @m INI_EXT(file) 
  771.     SRTN ini_##file FCN((ps))
  772.         CONST S_MAP HUGE *ps C1("")@;
  773.     {
  774.     EXT_LINK(file,(outer_char *)ps->ptr);
  775.     }
  776.  
  777. @<Unused@>=
  778. /* Actual functions are being created here. */
  779. INI_EXT(web)@;
  780. INI_EXT(change)@;
  781. INI_EXT(hweb)@;
  782. INI_EXT(hchange)@;
  783.  
  784. @
  785. @a
  786. SRTN ini_ext FCN((ps))
  787.     S_MAP HUGE *ps C1("")@;
  788. {
  789. set_str(ps);
  790. ext_set((CONST outer_char HUGE **)ps->ptr);
  791. }
  792.  
  793. @ Convert the delimiters for dot constants to |ASCII|.
  794. @a
  795. SRTN ini_dot FCN((ps))
  796.     S_MAP HUGE *ps C1("")@;
  797. {
  798. set_char(ps);
  799. *(ASCII *)ps->ptr = XORD(*(outer_char *)ps->ptr);
  800. }
  801.  
  802. @
  803. @a
  804. SRTN ini_cchar FCN((ps))
  805.     S_MAP HUGE *ps C1("")@;
  806. {
  807. outer_char c;
  808.  
  809. set_char(ps);
  810. c = *(outer_char *)ps->ptr;
  811.  
  812. if(!(c && isprint(c) && c != ' ' && c != '0'))
  813.     {
  814.     *(outer_char *)ps->ptr = CCHAR;
  815.     err_print(S,"Invalid continuation character '%c'; '%c' assumed",
  816.         c,CCHAR);
  817.     }
  818. }
  819.  
  820. @ Here we check the validity of the line length for Fortran's output.
  821.  
  822. @a
  823. SRTN ini_output_line_length FCN((ps))
  824.     S_MAP HUGE *ps C1("")@;
  825. {
  826. int output_line_length;
  827.  
  828. set_int(ps);
  829. output_line_length = *(int *)ps->ptr;
  830.  
  831. if(output_line_length < MIN_OUTPUT_LINE_LENGTH ||
  832.         output_line_length > MAX_OUTPUT_LINE_LENGTH)
  833.     {
  834.     *(int *)ps->ptr = STANDARD_OUTPUT_LINE_LENGTH;
  835.     err_print(S,"Invalid line length; %d assumed",
  836.         STANDARD_OUTPUT_LINE_LENGTH);
  837.     }
  838. }
  839.  
  840. @<Unused@>=
  841. SRTN ini_cdir FCN((ps))
  842.     CONST S_MAP HUGE *ps C1("")@;
  843. {
  844. outer_char *temp;
  845. int n;
  846.  
  847. temp = GET_MEM("temp_cdir",
  848.     (n=2*STRLEN(*((outer_char HUGE **)ps->ptr)))+1,outer_char); 
  849. esc_buf(temp,temp+n,*((CONST outer_char HUGE **)ps->ptr),stemp,YES);
  850. }
  851.  
  852. @* INITIALIZING CONTROL CODES.
  853. The control code mapping can be overridden from the style file, although
  854. this is not recommended except in unusual circumstances.
  855.  
  856. @d ignore 0
  857.  
  858. @<Glob...@>=
  859.  
  860. eight_bits ccode[128]; // Meaning of a character following '\.{@@}'.
  861. CONST outer_char *cname[128]; // Associated names of control codes.
  862. CONST ASCII HUGE *at_codes;
  863.  
  864. @ Here we initialize |ccode| with values that aren't allowed to be changed
  865. by the style file.  The flag |USED_BY_NEITHER| is written into everything
  866. first; if such a control code is encountered during the scan of either
  867. processor, an error message will be issued.
  868.  
  869. @a
  870. SRTN zero_ccodes(VOID)
  871. @{
  872. int c; // Must be |int|, not |eight_bits|, so the |for| loop will end.
  873.  
  874. @b
  875. /* Start out by initializing the array to a special flag. */
  876.  for (c=0; c<=127; c++) 
  877.     {
  878.     ccode[c] = USED_BY_NEITHER;
  879.     cname[c] = OC("?");
  880.     }
  881.  
  882. @<Initialize unchangable codes@>@;
  883. }
  884.  
  885. @ The following several codes aren't allowed to be changed.
  886. @<Initialize unchangable...@>=
  887. {
  888. ccode[@'@@']=@'@@'; /* `quoted' at sign. This is so fundamental that it
  889.             isn't allowed to be changed by the style file. */
  890.  
  891. ccode[@'{'] = @'{'; /* Since this is related to the C or \Ratfor\ languages,
  892.             it shouldn't be changed. */
  893. ccode[@'}'] = @'}'; // As above.
  894.  
  895. ccode[@'>'] = ignore; /* This is historical, and probably dangerous.  But
  896.             it can't be |USED_BY_NEITHER|! */
  897. }
  898.  
  899. @ The next routine is used by \FWEAVE\ or \FTANGLE\ to initialize the
  900. control code table. Say, for example,
  901. ``\.{INI\_CCODE("Aa",begin\_code)}.  If at any point a |ccode|
  902. entry has already been filled in, that means we \It{must} use the default
  903. value. Thus, if the style file has attempted to override that value,
  904. we complain---and abort after we've checked all the initializations.
  905. @a
  906. SRTN ini_ccode FCN((keyword,defaults,code))
  907.     CONST outer_char *keyword C0("The desired keyword.")@;
  908.     CONST outer_char *defaults C0("String of default characters.")@;
  909.     eight_bits code C1("Assign this \FWEB\ universal code")@;
  910. {
  911. CONST outer_char *pc; /* Pointer to the default characters to initialize. */
  912. CONST S_MAP HUGE *m; /* Points to map entry for requested keyword. */
  913. boolean bad_code = NO;
  914. eight_bits cval;
  915. boolean override; /* Are the default values overridden by the style file? */
  916. IN_COMMON outer_char style_file_name[];
  917. ASCII a; // Position in |ccode|.
  918.  
  919. /* Search for the keyword in the map array. */
  920. if( (m=find_sty(map_array,keyword)) == NULL)
  921.     override = NO; // The keyword isn't even in the table.
  922. else
  923. /* If the style file has set some values for this keyword, and the default
  924.   values for this code are non-zero, then use the values from the style file.
  925.   Otherwise, use the defaults. */
  926.     override = BOOLEAN(*(outer_char **)m->ptr != NULL); 
  927.         // The style file is overriding.
  928.  
  929. pc = (override && code) ? *(outer_char **)m->ptr : defaults;
  930.  
  931. /* If we're not ignoring this code completely, assign it to the relevant
  932. values. */
  933. if(code != USED_BY_NEITHER)
  934.    while(*pc)
  935.     {
  936.     if(override && ((cval = ccode[XORD(*pc)]) != USED_BY_NEITHER) )
  937.         {
  938.         printf("! ccode['%c'] already filled with \"%s\"; \
  939. not filled with \"%s\" = \"%s\".\n",
  940.             *pc, (char *)ccode_name(cval), (char *)keyword,
  941.             (char *)ccode_name(code));
  942.         bad_code = YES;
  943.         }
  944.  
  945.     a = XORD(*pc++);
  946.     ccode[a] = code;
  947.     cname[a] = keyword;
  948.     }
  949.  
  950. if(bad_code) 
  951.     FATAL(S, "!! Invalid control code mapping; check the style file ",
  952.         style_file_name);
  953. }
  954.  
  955. @ For \FTANGLE, after all the |ccode|s have been assigned, a few of them
  956. must be reinterpreted. For example, by default the codes ``\.{\^.9tT}'' are
  957. all interpreted as |control_text|.
  958. @a
  959. SRTN reassign FCN((old_code,new_code))
  960.     eight_bits old_code C0("")@;
  961.     eight_bits new_code C1("")@;
  962. {
  963. int c;
  964.  
  965. for(c=0; c<128; c++)
  966.     if(ccode[c] == old_code) 
  967.         ccode[c] = new_code;
  968. }
  969.  
  970. @ The following array is used for sorting the control-code keywords.
  971. @<Glob...@>=
  972.  
  973. static CC_BUF HUGE *cc_buf;
  974.  
  975. @ Here we print out the control code mappings in resonse to \.{-@@}.  They
  976. are printed twice, first alphabetized by the control code, next by the
  977. keyword.  These are printed out side by side.
  978.  
  979. @a
  980. SRTN prn_codes(VOID)
  981. {
  982. IN_COMMON boolean found_web;
  983. int HUGE *cc_indices;
  984. boolean prn_all = NO;
  985.  
  986. int k;
  987. int n = 0; // Number of codes to print.
  988.  
  989. if(!at_codes) 
  990.     return;
  991.  
  992. puts("Control-code assignments \
  993. ([S,D,C]==`Begins [section,definition,code])':");
  994.  
  995. cc_buf = GET_MEM("cc_buf", 128, CC_BUF);
  996. cc_indices = GET_MEM("cc_indices", 128, int);
  997.  
  998. if(*at_codes && at_codes[0] == @'*' && at_codes[1] == @'*')
  999.     prn_all = YES;
  1000.  
  1001. if(*at_codes && !prn_all)
  1002.     { /* A specific list was given on command line. */
  1003.     CONST ASCII *p;
  1004.  
  1005.     for(p=at_codes; *p; p++)
  1006.         prn0_code(*p, cc_buf, &n);
  1007.     }
  1008. else
  1009.     { /* Do all of them. */
  1010.     ASCII a;
  1011.  
  1012.     for(a=0; a<128; a++)
  1013.         {
  1014.         if(ccode[a] == USED_BY_NEITHER && !prn_all)
  1015.             continue;
  1016.  
  1017.         prn0_code(a, cc_buf, &n);
  1018.         }
  1019.     }
  1020.  
  1021. FREE_MEM(at_codes, "at_codes", 200, ASCII);
  1022.  
  1023. for(k=0; k<n; k++)
  1024.     cc_indices[k] = k;
  1025.  
  1026. QSORT(cc_indices, n, sizeof(int), cc_cmp);
  1027.  
  1028. for(k=0; k<n; k++)
  1029.     STRCPY(cc_buf[k][1], cc_buf[cc_indices[k]][0]);
  1030.  
  1031. for(k=0; k<n; k++)
  1032.     printf("%-40s%-40s\n", cc_buf[k][0], cc_buf[k][1]);
  1033.  
  1034. FREE_MEM(cc_buf, "cc_buf", 128, CC_BUF);
  1035. FREE_MEM(cc_indices, "cc_indices", 128, int);
  1036.  
  1037. if(!found_web) 
  1038.     wrap_up();
  1039. }
  1040.  
  1041. @ We alphabetize on the keywords, which follow the `\.{---}'.
  1042.  
  1043. @a
  1044. int cc_cmp FCN((k0, k1))
  1045.     CONST VOID *pk0 C0("")@;
  1046.     CONST VOID *pk1 C1("")@;
  1047. {
  1048. char *s0, *s1;
  1049.  
  1050. s0 = strrchr(cc_buf[*(int *)pk0][0], '-');
  1051. s1 = strrchr(cc_buf[*(int *)pk1][0], '-');
  1052.  
  1053. return STRCMP(s0, s1);
  1054. }
  1055.  
  1056. @ Print out one control code.
  1057. @a
  1058. SRTN prn0_code FCN((a, cc_buf, pk))
  1059.     ASCII a C0("")@;
  1060.     CC_BUF HUGE *cc_buf C0("")@;
  1061.     int *pk C1("")@;
  1062. {    
  1063. ASCII new_module, begin_code, formatt;
  1064. ASCII cc = ccode[a];
  1065. outer_char c;
  1066. int n;
  1067. outer_char *letter;
  1068.  
  1069. /* The following assumes that these particular codes never change.  This
  1070. was easier than including the header files. */
  1071. new_module = ccode[@'*'];
  1072. begin_code = ccode[@'a'];
  1073. formatt = ccode[@'f'];
  1074.  
  1075. c = XCHR(a);
  1076.  
  1077. if(cc == USED_BY_NEITHER)
  1078.     letter = OC("   ");
  1079. else if(cc >= new_module)
  1080.     letter = OC("[S]");
  1081. else if(cc >= begin_code)
  1082.     letter = OC("[C]");
  1083. else if(cc >= formatt)
  1084.     letter = OC("[D]");
  1085. else
  1086.     letter = OC("   ");
  1087.  
  1088. n = NSPRINTF((outer_char *)&cc_buf[*pk][0][0], 
  1089. isprint(c) ? "  %s @@%c" : " %s@@'0x%02x'", 
  1090.         isprint(c) ? letter : OC(""), c);
  1091.  
  1092. switch(c)
  1093.     {
  1094.    case '/':
  1095.     cname[c] = OC("(verbatim comment)");
  1096.     break;
  1097.  
  1098.    case '>':
  1099.     cname[c] = OC("(end of module name)");
  1100.     break;
  1101.  
  1102.    case '@@':
  1103.     cname[c] = OC("(literal '@@')");
  1104.     break;
  1105.     }
  1106.  
  1107. sprintf(&cc_buf[*pk][0][n], " --- %s", (char *)cname[c]);
  1108. (*pk)++; // Increment array index.
  1109. }
  1110.  
  1111. @* COLOR.
  1112.  
  1113. @d SET_ACOLOR(field,clr) wt_style.color.field.value = clr
  1114.  
  1115. @<Glob...@>=
  1116. static outer_char HUGE *termcap; // Name of termcap file.
  1117. static outer_char HUGE *tcap_buffer; // Allocated dynamically.
  1118.  
  1119. @  Colors are initialized to default values, then overridden for several
  1120. built-in palettes.
  1121. @a
  1122. SRTN ini_colors FCN((color_mode))
  1123.     COLOR_MODE color_mode C1("")@;
  1124. {
  1125. @<Set default colors@>@; // Attach colors to fields.
  1126.  
  1127. if(!(termcap=get_termcap())) wt_style.color_mode = color_mode = NO_COLOR;
  1128.  
  1129. @<Make default links between bilevel mode and colors@>@;
  1130.  
  1131. switch(color_mode)
  1132.     {
  1133.    case NO_COLOR:
  1134.     break;
  1135.  
  1136.    case BILEVEL:
  1137.     CLR_LINK(YELLOW,md);
  1138.     CLR_LINK(GREEN,md);
  1139.     CLR_LINK(RED,mdmr);
  1140.     break;
  1141.  
  1142.    case TRUE_COLOR:
  1143.     CLR_LINK(YELLOW,md);
  1144.     CLR_LINK(GREEN,us);
  1145.     CLR_LINK(BLUE,md);
  1146.     CLR_LINK(ORANGE,md);
  1147.     CLR_LINK(RED,mdmr);
  1148.     break;
  1149.     }
  1150. }
  1151.  
  1152. @ Get control sequence for a color.  This is an ini routine for
  1153. \.{color.red} etc.
  1154. @a
  1155. SRTN ini_bilevel FCN((ps))
  1156.     S_MAP HUGE *ps C1("")@;
  1157. {
  1158. set_str(ps);
  1159.  
  1160. if(termcap==NULL) return;
  1161.  
  1162. termset(ps->ptr);
  1163. }
  1164.  
  1165. @ Default color assignments to the various FWEB fields. Change these in the
  1166. style file by saying ``\.{color.error = "red"}''.
  1167. @<Set default colors@>=
  1168. {
  1169. SET_ACOLOR(ordinary,NORMAL);
  1170. SET_ACOLOR(program_name,YELLOW);
  1171. SET_ACOLOR(info,GREEN);
  1172. SET_ACOLOR(warning,ORANGE);
  1173. SET_ACOLOR(error,RED);
  1174. SET_ACOLOR(fatal,RED);
  1175. SET_ACOLOR(module_num,ORANGE);
  1176. SET_ACOLOR(line_num,ORANGE);
  1177. SET_ACOLOR(in_file,YELLOW);
  1178. SET_ACOLOR(include_file,BLUE);
  1179. SET_ACOLOR(out_file,YELLOW);
  1180. SET_ACOLOR(timing,ORANGE);
  1181. }
  1182.  
  1183. @ Associate a color with a control sequence.
  1184.  
  1185. @m CLR_LINK(CLR,id) link0(&wt_style.color._##CLR,OC(#id),termset)
  1186.  
  1187. @<Make default links...@>=
  1188.  
  1189. CLR_LINK(NORMAL,me);
  1190. CLR_LINK(YELLOW,md);
  1191. CLR_LINK(GREEN,me);
  1192. CLR_LINK(ORANGE,me);
  1193. CLR_LINK(RED,mdmr);
  1194. CLR_LINK(BLUE,me);
  1195.  
  1196. @
  1197. @a
  1198. SRTN link0 FCN((pp,id,fcn))
  1199.     outer_char HUGE **pp C0("")@;
  1200.     CONST outer_char HUGE *id C0("")@;
  1201.     SRTN (HUGE_FCN_PTR *fcn)PROTO((CONST outer_char HUGE **)) C1("")@;
  1202. {
  1203. a_str(pp,id); // Allocate space, and store abbreviation string.
  1204. (*fcn)((CONST outer_char HUGE **)pp); /* Replace that string by actual escape
  1205.                     sequences. */
  1206. }
  1207.  
  1208. @ Similarly, initialize extensions.
  1209.  
  1210. @<Finish initializing mappings@>=
  1211. {
  1212. EXT_LINK(web,"web");
  1213. EXT_LINK(change,"ch");
  1214. EXT_LINK(hweb,"hweb");
  1215. EXT_LINK(hchange,"hch");
  1216. }
  1217.  
  1218. @ Allocate and store an abbreviation string.
  1219. @a
  1220. SRTN a_str FCN((pp,id))
  1221.     outer_char HUGE **pp C0("")@;
  1222.     CONST outer_char HUGE *id C1("")@;
  1223. {
  1224. @% if(*pp) FREE(*pp); // It's VERY destructive to free memory here!
  1225. *((outer_char HUGE * *)pp) = GET_MEM("map_string",STRLEN(id)+1,outer_char); 
  1226. STRCPY(*((outer_char HUGE * *)pp),id);
  1227. }
  1228.  
  1229. @ Open and read the termcap file.
  1230.  
  1231. @d ENV_TERM "TERM" // Unix environment variable for terminal type.
  1232.  
  1233. @a
  1234. outer_char *get_termcap(VOID)
  1235. {
  1236. #if !HAVE_GETENV
  1237.     return NULL;
  1238. #else
  1239. if((termcap = GETENV(ENV_TERM)) == NULL) return NULL;
  1240.  
  1241. tcap_buffer = GET_MEM("tcap_buffer",1024,outer_char);
  1242.  
  1243. switch(tgetent(tcap_buffer,termcap))
  1244.     {
  1245.    case -1:
  1246.     printf("! Can't open termcap file \"%s\"\n", (char *)termcap);
  1247.  
  1248.    case 0:
  1249.     return NULL;
  1250.     }
  1251.  
  1252. return termcap;
  1253. #endif // |HAVE_GETENV|
  1254. }
  1255.  
  1256. @ On entry, takes as argument a pointer to a string of blank-separated
  1257. abbreviations.  On exit, the pointer is changed to point to a |SEQUENCES|
  1258. structure that contains the actual escape sequences.
  1259.  
  1260. @d NUM_TEMP_PTRS 20
  1261.  
  1262. @a
  1263. SRTN termset FCN((pid))
  1264.     CONST outer_char HUGE **pid C1("")@;
  1265. {
  1266. outer_char value_buf[500], *area = value_buf; // For |tgetstr|.
  1267. outer_char *s;
  1268. CONST outer_char HUGE *t;
  1269. outer_char id[3];
  1270. int k,n;
  1271. SEQUENCES HUGE *ps = GET_MEM("termcap struct",1,SEQUENCES);
  1272. outer_char *string[NUM_TEMP_PTRS];
  1273.  
  1274. if(!termcap) return;
  1275.  
  1276. for(t=*pid,n=0; *t; t+=2)
  1277.     {
  1278.     if(n == NUM_TEMP_PTRS) break;
  1279.     while(*t==' ') t++;
  1280.  
  1281. /* Put the abbreviation for escape sequence into |id|. */
  1282.     STRNCPY(id,t,2);
  1283.     TERMINATE(id,2);
  1284.  
  1285. /* Get the actual escape sequence from termcap file. */
  1286.     if((s=tgetstr(id,&area)) == NULL)
  1287.         printf("! Termcap entry \"%s\" not found \
  1288. for terminal type \"%s\".\n", (char *)id, (char *)termcap);
  1289.     else string[n++] = s;
  1290.     }
  1291.  
  1292. @<Allocate and initialize memory for the strings@>@;
  1293. }
  1294.  
  1295. @
  1296. @<Allocate and initialize memory for the strings@>=
  1297. {
  1298. ps->n = (short)n;
  1299. ps->string = GET_MEM("termcap strings",n,outer_char *);
  1300.  
  1301. for(k=0; k<n; k++)
  1302.     {
  1303.     ps->string[k] = GET_MEM("termcap string",
  1304.         STRLEN(string[k])+1,outer_char);
  1305.     STRCPY(ps->string[k],string[k]);
  1306.     }
  1307.  
  1308. FREE((void *)(*pid));
  1309. *pid = (CONST outer_char HUGE *)ps;
  1310. }
  1311.  
  1312. @ A similar routine processes a blank-delimited list of extensions.
  1313. @a
  1314. SRTN ext_set FCN((pid))
  1315.     CONST outer_char HUGE **pid C1("")@;
  1316. {
  1317. outer_char id[1000],*p,*p0;
  1318. CONST outer_char HUGE *t;
  1319. outer_char *string[NUM_TEMP_PTRS];
  1320. int k,n;
  1321. SEQUENCES HUGE *ps = GET_MEM("termcap struct",1,SEQUENCES);
  1322.  
  1323. t = *pid; // Beginning of blank-separated list.
  1324. n = 0; // Number of fields found.
  1325. p = id; // Start of storage area
  1326.  
  1327. while(*t)
  1328.     {
  1329.     if(n == NUM_TEMP_PTRS) break;
  1330.     while(*t == ' ') t++; // Skip initial white space.
  1331.     
  1332.     p0 = p;
  1333.     while(*t != ' ' && *t) *p++ = *t++;
  1334.     TERMINATE(p,0);
  1335.     p++;
  1336.     string[n++] = p0; // Remember where string is.
  1337.     }
  1338.  
  1339. @<Allocate and init...@>@;
  1340. }
  1341.  
  1342. @ Used by |tputs|, which is an output routine used to send one character.
  1343. We need this intermediate function |put_out| because |putchar| is a macro
  1344. on some systems.
  1345. @a
  1346. int put_out FCN((c))
  1347.     int c C1("")@;
  1348. {
  1349. return putchar(c);
  1350. }
  1351.  
  1352. @ Output the control sequences corresponding to a color.  This needs to be
  1353. generalized for~X.
  1354.  
  1355. @m SEND(CLR) tput((SEQUENCES *)wt_style.color._##CLR)
  1356.  
  1357. @m CLR_CASE(CLR) 
  1358.     case CLR:
  1359.        SEND(CLR);
  1360.        break@;
  1361.  
  1362. @a
  1363. SRTN set_color FCN((clr))
  1364.     COLOR clr C1("")@;
  1365. {
  1366. color0.last = color0.present; // Save the incoming color, for later restore.
  1367.  
  1368. if(wt_style.color_mode != NO_COLOR)
  1369.   switch(clr)
  1370.     {
  1371.     CLR_CASE(NORMAL);
  1372.     CLR_CASE(GREEN);
  1373.     CLR_CASE(RED);
  1374.     CLR_CASE(BLUE);
  1375.     CLR_CASE(ORANGE);
  1376.     CLR_CASE(YELLOW);
  1377.  
  1378.    default:
  1379.     SEND(NORMAL);
  1380.     break;
  1381.     }
  1382.  
  1383. color0.present = clr;
  1384. }
  1385.  
  1386. @ Send each abbreviation in turn.
  1387. @a
  1388. SRTN tput FCN((ps))
  1389.     SEQUENCES *ps C1("")@;
  1390. {
  1391. int k;
  1392.  
  1393. for(k=0; k<ps->n; k++)
  1394.     tputs(ps->string[k],1,put_out);
  1395. }
  1396.  
  1397. @ Print to terminal in particular color.  (This routine is independent of
  1398. the particular color mechanism.) \It{Check the variable arguments; they're
  1399. not right for Sun-CC yet.}
  1400. @<Unused@>=
  1401.  
  1402. SRTN clr_printf FCN(VA_ALIST((clr,fmt VA_ARGS)))
  1403.     VA_DCL(
  1404.     COLOR clr C0("")@;
  1405.     outer_char *fmt C2("")@;)@;
  1406. {
  1407. VA_LIST(arg_ptr)@;
  1408.  
  1409. set_color(clr); // Remembers previous color in |color0.last|.
  1410.  
  1411. VA_START(arg_ptr,fmt);
  1412. vprintf_(fmt,arg_ptr);
  1413. va_end(arg_ptr);
  1414.  
  1415. set_color(color0.last); // Restore color.
  1416. }
  1417.  
  1418. @* PRINTING OUT VALUES.
  1419. @<Unused@>=
  1420. boolean out_map FCN((name))
  1421.     outer_char *name C1("")@;
  1422. {
  1423. outer_char *p;
  1424. outer_char key_name[100];
  1425. S_MAP *m;
  1426.  
  1427. STRCPY(key_name,name);
  1428. for(p=key_name; *p; p++)
  1429.     if(*p == '.') *p = '_';
  1430.  
  1431. for(m=fweb_map; *m->keyword; m++)
  1432.     if(STRCMP(m->keyword,key_name) == 0)
  1433.         {
  1434.         for(p=key_name; *p; p++)
  1435.             if(*p == '_') *p = '.';
  1436.  
  1437.         printf("%s = ",key_name);
  1438.         switch(m->type)
  1439.             {
  1440.            case S_STRING:
  1441.             if(*(int *)m->ptr < (int)HIGHEST_COLOR)
  1442.                 printf("%s\n",clr_name[*(int *)m->ptr]);
  1443.             else printf("\"%s\"\n",*(char * *)m->ptr);
  1444.             break;
  1445.  
  1446.            case S_CHAR:
  1447.             printf("'%c'\n",*(char *)m->ptr);
  1448.             break;
  1449.  
  1450.            case S_INT:
  1451.             printf("%d\n",*(int *)m->ptr);
  1452.             break;
  1453.  
  1454.            case S_LONG:
  1455.             printf("%ld\n",*(long *)m->ptr);
  1456.             break;
  1457.  
  1458.            default:
  1459.             printf("INVALID TYPE\n");
  1460.             break;
  1461.             }
  1462.  
  1463.         return YES;
  1464.         }
  1465.  
  1466. return NO;
  1467. }
  1468.  
  1469. @ Query the style-file parameters; from \.{-Z}~option.
  1470. @a
  1471. SRTN see_style FCN((pa,see_all))
  1472.     CONST outer_char HUGE *pa C0("")@;
  1473.     boolean see_all C1("")@;
  1474. {
  1475. S_MAP HUGE **s0,HUGE **s,HUGE **s1,HUGE *m;
  1476.  
  1477. s0 = GET_MEM("s0",sizeof(fweb_map)/sizeof(S_MAP),S_MAP HUGE *);
  1478.  
  1479. /* Fill an array of pointers. */
  1480. for(s=s0,m=fweb_map; *(m->keyword); s++,m++)
  1481.     *s = m;
  1482.  
  1483. /* Sort the array. */
  1484. QSORT(s0,s-s0,sizeof(S_MAP HUGE *),cmpr_s_map);
  1485.  
  1486. /* Print out the values. */
  1487. printf("%s style-file parameters%s%s%s%s:\n",
  1488.     see_all ? "Default" : "Modified",
  1489.     *pa ? " beginning with \"" : "", (char *)pa, *pa ? "\"" : "",
  1490.     see_all ? "\n (null or empty values for colors and \
  1491. @@ command codes are misleading)" : "");
  1492.  
  1493. if(*pa)
  1494.     { /* Convert \.{'.'} to \.{'\_'}. */
  1495.     outer_char HUGE *p;
  1496.  
  1497.     for(p=(outer_char HUGE *)pa; *p; p++)
  1498.         if(*p == '.')
  1499.             *p = '_';
  1500.     }
  1501.  
  1502. for(s1=s0; s1<s; s1++)
  1503.     see_map(*s1,pa,see_all);
  1504.  
  1505. FREE_MEM(s0,"s0",sizeof(fweb_map)/sizeof(S_MAP),S_MAP);
  1506. }
  1507.  
  1508. @
  1509. @a
  1510. int cmpr_s_map FCN((s0,s1))
  1511.     S_MAP HUGE **s0 C0("")@;
  1512.     S_MAP HUGE **s1 C1("")@;
  1513. {
  1514. return STRCMP((*s0)->keyword,(*s1)->keyword);
  1515. }
  1516.  
  1517. @ Print out an individual style-file parameter.
  1518. @a
  1519. SRTN see_map FCN((s,pa,see_all))
  1520.     S_MAP HUGE *s C0("")@;
  1521.     CONST outer_char HUGE *pa C0("")@;
  1522.     boolean see_all C1("")@;
  1523. {
  1524. if(*pa && STRNCMP(pa,s->keyword,STRLEN(pa)) != 0) return;
  1525.  
  1526. if(see_all) 
  1527.     printf(" ");
  1528. else
  1529.     { /* Handled modified parameters. */
  1530.     if(s->type & S_MODIFIED) 
  1531.         {
  1532.         printf("*");
  1533.         s->type &= ~S_MODIFIED;
  1534.         }
  1535.  
  1536.     else return;
  1537.     }
  1538.  
  1539. printf(" %s = ", (char *)s->keyword);
  1540.  
  1541. switch(s->type)
  1542.     {
  1543.    case S_STRING:
  1544.     see_str(*((outer_char **)s->ptr));
  1545.     break;
  1546.  
  1547.    case S_CHAR:
  1548.     printf("'%c'\n",*(outer_char *)s->ptr);
  1549.     break;
  1550.  
  1551.    case S_INT:
  1552.     printf("%d\n",*(int *)s->ptr);
  1553.     break;
  1554.  
  1555.    case S_LONG:
  1556.     printf("%ld\n",*(long *)s->ptr);
  1557.     break;
  1558.  
  1559.    default:
  1560.     break;
  1561.     }
  1562. }
  1563.  
  1564. @
  1565. @a
  1566. SRTN see_str FCN((s))
  1567.     CONST outer_char HUGE *s C1("")@;
  1568. {
  1569. outer_char c;
  1570.  
  1571. if(s==NULL) 
  1572.     {
  1573.     printf("NULL\n");
  1574.     return;
  1575.     }
  1576. else if(s < (outer_char HUGE *)100) 
  1577.     { /* Horrible kludge to handle stupid color processing. */
  1578.     printf("\n");
  1579.     return;
  1580.     }
  1581.  
  1582. printf("\"");
  1583.  
  1584. while((c = *s++))
  1585.   print_it:
  1586.     if(c=='\\') printf("\\\\");
  1587.     else if(isprint(c)) printf("%c",c);
  1588.     else 
  1589.         {
  1590.         printf("\\");
  1591.         switch(c)
  1592.             {
  1593.            case '\a': c = 'a'; goto print_it;
  1594.            case '\b': c = 'b'; goto print_it;
  1595.            case '\f': c = 'f'; goto print_it;
  1596.            case '\n': c = 'n'; goto print_it;
  1597.            case '\r': c = 'r'; goto print_it;
  1598.            case '\t': c = 't'; goto print_it;
  1599.            case '\v': c = 'v'; goto print_it;
  1600.            default:
  1601.             printf("%o",c);
  1602.             break;
  1603.             }
  1604.         }
  1605.  
  1606. printf("\"\n");
  1607. }
  1608.  
  1609. @* INDEX.
  1610.