home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / f2csrc.zip / f2csrc / src / lex.c < prev    next >
C/C++ Source or Header  |  1994-02-25  |  34KB  |  1,627 lines

  1. /****************************************************************
  2. Copyright 1990, 1992, 1993, 1994 by AT&T Bell Laboratories and Bellcore.
  3.  
  4. Permission to use, copy, modify, and distribute this software
  5. and its documentation for any purpose and without fee is hereby
  6. granted, provided that the above copyright notice appear in all
  7. copies and that both that the copyright notice and this
  8. permission notice and warranty disclaimer appear in supporting
  9. documentation, and that the names of AT&T Bell Laboratories or
  10. Bellcore or any of their entities not be used in advertising or
  11. publicity pertaining to distribution of the software without
  12. specific, written prior permission.
  13.  
  14. AT&T and Bellcore disclaim all warranties with regard to this
  15. software, including all implied warranties of merchantability
  16. and fitness.  In no event shall AT&T or Bellcore be liable for
  17. any special, indirect or consequential damages or any damages
  18. whatsoever resulting from loss of use, data or profits, whether
  19. in an action of contract, negligence or other tortious action,
  20. arising out of or in connection with the use or performance of
  21. this software.
  22. ****************************************************************/
  23.  
  24. #include "defs.h"
  25. #include "tokdefs.h"
  26. #include "p1defs.h"
  27.  
  28. #ifdef NO_EOF_CHAR_CHECK
  29. #undef EOF_CHAR
  30. #else
  31. #ifndef EOF_CHAR
  32. #define EOF_CHAR 26    /* ASCII control-Z */
  33. #endif
  34. #endif
  35.  
  36. #define BLANK    ' '
  37. #define MYQUOTE (2)
  38. #define SEOF 0
  39.  
  40. /* card types */
  41.  
  42. #define STEOF 1
  43. #define STINITIAL 2
  44. #define STCONTINUE 3
  45.  
  46. /* lex states */
  47.  
  48. #define NEWSTMT    1
  49. #define FIRSTTOKEN    2
  50. #define OTHERTOKEN    3
  51. #define RETEOS    4
  52.  
  53.  
  54. LOCAL int stkey;    /* Type of the current statement (DO, END, IF, etc) */
  55. extern char token[];    /* holds the actual token text */
  56. static int needwkey;
  57. ftnint yystno;
  58. flag intonly;
  59. extern int new_dcl;
  60. LOCAL long int stno;
  61. LOCAL long int nxtstno;    /* Statement label */
  62. LOCAL int parlev;    /* Parentheses level */
  63. LOCAL int parseen;
  64. LOCAL int expcom;
  65. LOCAL int expeql;
  66. LOCAL char *nextch;
  67. LOCAL char *lastch;
  68. LOCAL char *nextcd     = NULL;
  69. LOCAL char *endcd;
  70. LOCAL long prevlin;
  71. LOCAL long thislin;
  72. LOCAL int code;        /* Card type; INITIAL, CONTINUE or EOF */
  73. LOCAL int lexstate    = NEWSTMT;
  74. LOCAL char *sbuf;    /* Main buffer for Fortran source input. */
  75. LOCAL char *send;    /* Was = sbuf+20*66 with sbuf[1390]. */
  76. LOCAL int maxcont;
  77. LOCAL int nincl    = 0;    /* Current number of include files */
  78. LOCAL long firstline;
  79. LOCAL char *laststb, *stb0;
  80. extern int addftnsrc;
  81. static char **linestart;
  82. LOCAL int ncont;
  83. LOCAL char comstart[Table_size];
  84. #define USC (unsigned char *)
  85.  
  86. static char anum_buf[Table_size];
  87. #define isalnum_(x) anum_buf[x]
  88. #define isalpha_(x) (anum_buf[x] == 1)
  89.  
  90. #define COMMENT_BUF_STORE 4088
  91.  
  92. typedef struct comment_buf {
  93.     struct comment_buf *next;
  94.     char *last;
  95.     char buf[COMMENT_BUF_STORE];
  96.     } comment_buf;
  97. static comment_buf *cbfirst, *cbcur;
  98. static char *cbinit, *cbnext, *cblast;
  99. static void flush_comments Argdcl((void));
  100. extern flag use_bs;
  101.  
  102.  
  103. /* Comment buffering data
  104.  
  105.     Comments are kept in a list until the statement before them has
  106.    been parsed.  This list is implemented with the above comment_buf
  107.    structure and the pointers cbnext and cblast.
  108.  
  109.     The comments are stored with terminating NULL, and no other
  110.    intervening space.  The last few bytes of each block are likely to
  111.    remain unused.
  112. */
  113.  
  114. /* struct Inclfile   holds the state information for each include file */
  115. struct Inclfile
  116. {
  117.     struct Inclfile *inclnext;
  118.     FILEP inclfp;
  119.     char *inclname;
  120.     int incllno;
  121.     char *incllinp;
  122.     int incllen;
  123.     int inclcode;
  124.     ftnint inclstno;
  125. };
  126.  
  127. LOCAL struct Inclfile *inclp    =  NULL;
  128. struct Keylist {
  129.     char *keyname;
  130.     int keyval;
  131.     char notinf66;
  132. };
  133. struct Punctlist {
  134.     char punchar;
  135.     int punval;
  136. };
  137. struct Fmtlist {
  138.     char fmtchar;
  139.     int fmtval;
  140. };
  141. struct Dotlist {
  142.     char *dotname;
  143.     int dotval;
  144.     };
  145. LOCAL struct Keylist *keystart[26], *keyend[26];
  146.  
  147. /* KEYWORD AND SPECIAL CHARACTER TABLES
  148. */
  149.  
  150. static struct Punctlist puncts[ ] =
  151. {
  152.     '(', SLPAR,
  153.     ')', SRPAR,
  154.     '=', SEQUALS,
  155.     ',', SCOMMA,
  156.     '+', SPLUS,
  157.     '-', SMINUS,
  158.     '*', SSTAR,
  159.     '/', SSLASH,
  160.     '$', SCURRENCY,
  161.     ':', SCOLON,
  162.     '<', SLT,
  163.     '>', SGT,
  164.     0, 0 };
  165.  
  166. LOCAL struct Dotlist  dots[ ] =
  167. {
  168.     "and.", SAND,
  169.         "or.", SOR,
  170.         "not.", SNOT,
  171.         "true.", STRUE,
  172.         "false.", SFALSE,
  173.         "eq.", SEQ,
  174.         "ne.", SNE,
  175.         "lt.", SLT,
  176.         "le.", SLE,
  177.         "gt.", SGT,
  178.         "ge.", SGE,
  179.         "neqv.", SNEQV,
  180.         "eqv.", SEQV,
  181.         0, 0 };
  182.  
  183. LOCAL struct Keylist  keys[ ] =
  184. {
  185.     { "assign",  SASSIGN  },
  186.     { "automatic",  SAUTOMATIC, YES  },
  187.     { "backspace",  SBACKSPACE  },
  188.     { "blockdata",  SBLOCK  },
  189.     { "byte",    SBYTE    },
  190.     { "call",  SCALL  },
  191.     { "character",  SCHARACTER, YES  },
  192.     { "close",  SCLOSE, YES  },
  193.     { "common",  SCOMMON  },
  194.     { "complex",  SCOMPLEX  },
  195.     { "continue",  SCONTINUE  },
  196.     { "data",  SDATA  },
  197.     { "dimension",  SDIMENSION  },
  198.     { "doubleprecision",  SDOUBLE  },
  199.     { "doublecomplex", SDCOMPLEX, YES  },
  200.     { "elseif",  SELSEIF, YES  },
  201.     { "else",  SELSE, YES  },
  202.     { "endfile",  SENDFILE  },
  203.     { "endif",  SENDIF, YES  },
  204.     { "enddo", SENDDO, YES },
  205.     { "end",  SEND  },
  206.     { "entry",  SENTRY, YES  },
  207.     { "equivalence",  SEQUIV  },
  208.     { "external",  SEXTERNAL  },
  209.     { "format",  SFORMAT  },
  210.     { "function",  SFUNCTION  },
  211.     { "goto",  SGOTO  },
  212.     { "implicit",  SIMPLICIT, YES  },
  213.     { "include",  SINCLUDE, YES  },
  214.     { "inquire",  SINQUIRE, YES  },
  215.     { "intrinsic",  SINTRINSIC, YES  },
  216.     { "integer",  SINTEGER  },
  217.     { "logical",  SLOGICAL  },
  218.     { "namelist", SNAMELIST, YES },
  219.     { "none", SUNDEFINED, YES },
  220.     { "open",  SOPEN, YES  },
  221.     { "parameter",  SPARAM, YES  },
  222.     { "pause",  SPAUSE  },
  223.     { "print",  SPRINT  },
  224.     { "program",  SPROGRAM, YES  },
  225.     { "punch",  SPUNCH, YES  },
  226.     { "read",  SREAD  },
  227.     { "real",  SREAL  },
  228.     { "return",  SRETURN  },
  229.     { "rewind",  SREWIND  },
  230.     { "save",  SSAVE, YES  },
  231.     { "static",  SSTATIC, YES  },
  232.     { "stop",  SSTOP  },
  233.     { "subroutine",  SSUBROUTINE  },
  234.     { "then",  STHEN, YES  },
  235.     { "undefined", SUNDEFINED, YES  },
  236.     { "while", SWHILE, YES  },
  237.     { "write",  SWRITE  },
  238.     { 0, 0 }
  239. };
  240.  
  241. static void analyz Argdcl((void));
  242. static void crunch Argdcl((void));
  243. static int getcd Argdcl((char*, int));
  244. static int getcds Argdcl((void));
  245. static int getkwd Argdcl((void));
  246. static int gettok Argdcl((void));
  247. static void store_comment Argdcl((char*));
  248. LOCAL char *stbuf[3];
  249.  
  250.  int
  251. #ifdef KR_headers
  252. inilex(name)
  253.     char *name;
  254. #else
  255. inilex(char *name)
  256. #endif
  257. {
  258.     stbuf[0] = Alloc(3*P1_STMTBUFSIZE);
  259.     stbuf[1] = stbuf[0] + P1_STMTBUFSIZE;
  260.     stbuf[2] = stbuf[1] + P1_STMTBUFSIZE;
  261.     nincl = 0;
  262.     inclp = NULL;
  263.     doinclude(name);
  264.     lexstate = NEWSTMT;
  265.     return(NO);
  266. }
  267.  
  268.  
  269.  
  270. /* throw away the rest of the current line */
  271.  void
  272. flline(Void)
  273. {
  274.     lexstate = RETEOS;
  275. }
  276.  
  277.  
  278.  
  279.  char *
  280. #ifdef KR_headers
  281. lexline(n)
  282.     int *n;
  283. #else
  284. lexline(int *n)
  285. #endif
  286. {
  287.     *n = (lastch - nextch) + 1;
  288.     return(nextch);
  289. }
  290.  
  291.  
  292.  
  293.  
  294.  void
  295. #ifdef KR_headers
  296. doinclude(name)
  297.     char *name;
  298. #else
  299. doinclude(char *name)
  300. #endif
  301. {
  302.     FILEP fp;
  303.     struct Inclfile *t;
  304.     char *lastslash, *s, *s0, *temp;
  305.     int k;
  306.  
  307.     if(inclp)
  308.     {
  309.         inclp->incllno = thislin;
  310.         inclp->inclcode = code;
  311.         inclp->inclstno = nxtstno;
  312.         if(nextcd)
  313.             inclp->incllinp = copyn(inclp->incllen = endcd-nextcd , nextcd);
  314.         else
  315.             inclp->incllinp = 0;
  316.     }
  317.     nextcd = NULL;
  318.  
  319.     if(++nincl >= MAXINCLUDES)
  320.         Fatal("includes nested too deep");
  321.     if(name[0] == '\0')
  322.         fp = stdin;
  323.     else if(name[0] == '/' || inclp == NULL
  324. #ifdef MSDOS
  325.         || name[0] == '\\'
  326.         || name[1] == ':'
  327. #endif
  328.         )
  329.         fp = fopen(name, textread);
  330.     else {
  331.         lastslash = NULL;
  332.         s = s0 = inclp->inclname;
  333. #ifdef MSDOS
  334.         if (s[1] == ':')
  335.             lastslash = s + 1;
  336. #endif
  337.         for(; *s ; ++s)
  338.             if(*s == '/'
  339. #ifdef MSDOS
  340.             || *s == '\\'
  341. #endif
  342.             )
  343.                 lastslash = s;
  344.         if(lastslash) {
  345.             k = lastslash - s0 + 1;
  346.             temp = Alloc(k + strlen(name) + 1);
  347.             strncpy(temp, s0, k);
  348.             strcpy(temp+k, name);
  349.             name = temp;
  350.             }
  351.         fp = fopen(name, textread);
  352.         }
  353.     if (fp)
  354.     {
  355.         t = inclp;
  356.         inclp = ALLOC(Inclfile);
  357.         inclp->inclnext = t;
  358.         prevlin = thislin = 0;
  359.         infname = inclp->inclname = name;
  360.         infile = inclp->inclfp = fp;
  361.     }
  362.     else
  363.     {
  364.         fprintf(diagfile, "Cannot open file %s\n", name);
  365.         done(1);
  366.     }
  367. }
  368.  
  369.  
  370.  
  371.  
  372.  LOCAL int
  373. popinclude(Void)
  374. {
  375.     struct Inclfile *t;
  376.     register char *p;
  377.     register int k;
  378.  
  379.     if(infile != stdin)
  380.         clf(&infile, infname, 1);    /* Close the input file */
  381.     free(infname);
  382.  
  383.     --nincl;
  384.     t = inclp->inclnext;
  385.     free( (charptr) inclp);
  386.     inclp = t;
  387.     if(inclp == NULL) {
  388.         infname = 0;
  389.         return(NO);
  390.         }
  391.  
  392.     infile = inclp->inclfp;
  393.     infname = inclp->inclname;
  394.     prevlin = thislin = inclp->incllno;
  395.     code = inclp->inclcode;
  396.     stno = nxtstno = inclp->inclstno;
  397.     if(inclp->incllinp)
  398.     {
  399.         endcd = nextcd = sbuf;
  400.         k = inclp->incllen;
  401.         p = inclp->incllinp;
  402.         while(--k >= 0)
  403.             *endcd++ = *p++;
  404.         free( (charptr) (inclp->incllinp) );
  405.     }
  406.     else
  407.         nextcd = NULL;
  408.     return(YES);
  409. }
  410.  
  411.  
  412. static char *lastfile = "??", *lastfile0 = "?";
  413. static char fbuf[P1_FILENAME_MAX];
  414.  
  415.  void
  416. #ifdef KR_headers
  417. p1_line_number(line_number)
  418.     long line_number;
  419. #else
  420. p1_line_number(long line_number)
  421. #endif
  422. {
  423.     if (lastfile != lastfile0) {
  424.         p1puts(P1_FILENAME, fbuf);
  425.         lastfile0 = lastfile;
  426.         }
  427.     fprintf(pass1_file, "%d: %ld\n", P1_SET_LINE, line_number);
  428.     }
  429.  
  430.  static void
  431. putlineno(Void)
  432. {
  433.     static long lastline;
  434.     extern int gflag;
  435.     register char *s0, *s1;
  436.  
  437.     if (gflag) {
  438.         if (lastline)
  439.             p1_line_number(lastline);
  440.         lastline = firstline;
  441.         if (lastfile != infname)
  442.             if (lastfile = infname) {
  443.                 strncpy(fbuf, lastfile, sizeof(fbuf));
  444.                 fbuf[sizeof(fbuf)-1] = 0;
  445.                 }
  446.             else
  447.                 fbuf[0] = 0;
  448.         }
  449.     if (addftnsrc) {
  450.         if (laststb && *laststb) {
  451.             for(s1 = laststb; *s1; s1++) {
  452.                 for(s0 = s1; *s1 != '\n'; s1++)
  453.                     if (*s1 == '*' && s1[1] == '/')
  454.                         *s1 = '+';
  455.                 *s1 = 0;
  456.                 p1puts(P1_FORTRAN, s0);
  457.                 }
  458.             *laststb = 0;    /* prevent trouble after EOF */
  459.             }
  460.         laststb = stb0;
  461.         }
  462.     }
  463.  
  464.  int
  465. yylex(Void)
  466. {
  467.     static int  tokno;
  468.     int retval;
  469.  
  470.     switch(lexstate)
  471.     {
  472.     case NEWSTMT :    /* need a new statement */
  473.         retval = getcds();
  474.         putlineno();
  475.         if(retval == STEOF) {
  476.             retval = SEOF;
  477.             break;
  478.         } /* if getcds() == STEOF */
  479.         crunch();
  480.         tokno = 0;
  481.         lexstate = FIRSTTOKEN;
  482.         yystno = stno;
  483.         stno = nxtstno;
  484.         toklen = 0;
  485.         retval = SLABEL;
  486.         break;
  487.  
  488. first:
  489.     case FIRSTTOKEN :    /* first step on a statement */
  490.         analyz();
  491.         lexstate = OTHERTOKEN;
  492.         tokno = 1;
  493.         retval = stkey;
  494.         break;
  495.  
  496.     case OTHERTOKEN :    /* return next token */
  497.         if(nextch > lastch)
  498.             goto reteos;
  499.         ++tokno;
  500.         if( (stkey==SLOGIF || stkey==SELSEIF) && parlev==0 && tokno>3)
  501.             goto first;
  502.  
  503.         if(stkey==SASSIGN && tokno==3 && nextch<lastch &&
  504.             nextch[0]=='t' && nextch[1]=='o')
  505.         {
  506.             nextch+=2;
  507.             retval = STO;
  508.             break;
  509.         }
  510.         retval = gettok();
  511.         break;
  512.  
  513. reteos:
  514.     case RETEOS:
  515.         lexstate = NEWSTMT;
  516.         retval = SEOS;
  517.         break;
  518.     default:
  519.         fatali("impossible lexstate %d", lexstate);
  520.         break;
  521.     }
  522.  
  523.     if (retval == SEOF)
  524.         flush_comments ();
  525.  
  526.     return retval;
  527. }
  528.  
  529.  LOCAL void
  530. contmax(Void)
  531. {
  532.     lineno = thislin;
  533.     many("continuation lines", 'C', maxcontin);
  534.     }
  535.  
  536. /* Get Cards.
  537.  
  538.    Returns STEOF or STINITIAL, never STCONTINUE.  Any continuation cards get
  539. merged into one long card (hence the size of the buffer named   sbuf)   */
  540.  
  541.  LOCAL int
  542. getcds(Void)
  543. {
  544.     register char *p, *q;
  545.  
  546.     flush_comments ();
  547. top:
  548.     if(nextcd == NULL)
  549.     {
  550.         code = getcd( nextcd = sbuf, 1 );
  551.         stno = nxtstno;
  552.         prevlin = thislin;
  553.     }
  554.     if(code == STEOF)
  555.         if( popinclude() )
  556.             goto top;
  557.         else
  558.             return(STEOF);
  559.  
  560.     if(code == STCONTINUE)
  561.     {
  562.         lineno = thislin;
  563.         nextcd = NULL;
  564.         goto top;
  565.     }
  566.  
  567. /* Get rid of unused space at the head of the buffer */
  568.  
  569.     if(nextcd > sbuf)
  570.     {
  571.         q = nextcd;
  572.         p = sbuf;
  573.         while(q < endcd)
  574.             *p++ = *q++;
  575.         endcd = p;
  576.     }
  577.  
  578. /* Be aware that the input (i.e. the string at the address   nextcd)   is NOT
  579.    NULL-terminated */
  580.  
  581. /* This loop merges all continuations into one long statement, AND puts the next
  582.    card to be read at the end of the buffer (i.e. it stores the look-ahead card
  583.    when there's room) */
  584.  
  585.     ncont = 0;
  586.     for(;;) {
  587.         nextcd = endcd;
  588.         if (ncont >= maxcont || nextcd+66 > send)
  589.             contmax();
  590.         linestart[ncont++] = nextcd;
  591.         if ((code = getcd(nextcd,0)) != STCONTINUE)
  592.             break;
  593.         if (ncont == 20 && noextflag) {
  594.             lineno = thislin;
  595.             errext("more than 19 continuation lines");
  596.             }
  597.         }
  598.     nextch = sbuf;
  599.     lastch = nextcd - 1;
  600.  
  601.     lineno = prevlin;
  602.     prevlin = thislin;
  603.     return(STINITIAL);
  604. }
  605.  
  606.  static void
  607. #ifdef KR_headers
  608. bang(a, b, c, d, e)
  609.     char *a;
  610.     char *b;
  611.     char *c;
  612.     register char *d;
  613.     register char *e;
  614. #else
  615. bang(char *a, char *b, char *c, register char *d, register char *e)
  616. #endif
  617.         /* save ! comments */
  618. {
  619.     char buf[COMMENT_BUFFER_SIZE + 1];
  620.     register char *p, *pe;
  621.  
  622.     p = buf;
  623.     pe = buf + COMMENT_BUFFER_SIZE;
  624.     *pe = 0;
  625.     while(a < b)
  626.         if (!(*p++ = *a++))
  627.             p[-1] = 0;
  628.     if (b < c)
  629.         *p++ = '\t';
  630.     while(d < e) {
  631.         if (!(*p++ = *d++))
  632.             p[-1] = ' ';
  633.         if (p == pe) {
  634.             store_comment(buf);
  635.             p = buf;
  636.             }
  637.         }
  638.     if (p > buf) {
  639.         while(--p >= buf && *p == ' ');
  640.         p[1] = 0;
  641.         store_comment(buf);
  642.         }
  643.     }
  644.  
  645.  
  646. /* getcd - Get next input card
  647.  
  648.     This function reads the next input card from global file pointer   infile.
  649. It assumes that   b   points to currently empty storage somewhere in  sbuf  */
  650.  
  651.  LOCAL int
  652. #ifdef KR_headers
  653. getcd(b, nocont)
  654.     register char *b;
  655.     int nocont;
  656. #else
  657. getcd(register char *b, int nocont)
  658. #endif
  659. {
  660.     register int c;
  661.     register char *p, *bend;
  662.     int speclin;        /* Special line - true when the line is allowed
  663.                    to have more than 66 characters (e.g. the
  664.                    "&" shorthand for continuation, use of a "\t"
  665.                    to skip part of the label columns) */
  666.     static char a[6];    /* Statement label buffer */
  667.     static char *aend    = a+6;
  668.     static char *stb, *stbend;
  669.     static int nst;
  670.     char *atend, *endcd0;
  671.     extern int warn72;
  672.     char buf72[24];
  673.     int amp, i;
  674.     char storage[COMMENT_BUFFER_SIZE + 1];
  675.     char *pointer;
  676.     long L;
  677.  
  678. top:
  679.     endcd = b;
  680.     bend = b+66;
  681.     amp = speclin = NO;
  682.     atend = aend;
  683.  
  684. /* Handle the continuation shorthand of "&" in the first column, which stands
  685.    for "     x" */
  686.  
  687.     if( (c = getc(infile)) == '&')
  688.     {
  689.         a[0] = c;
  690.         a[1] = 0;
  691.         a[5] = 'x';
  692.         amp = speclin = YES;
  693.         bend = send;
  694.         p = aend;
  695.     }
  696.  
  697. /* Handle the Comment cards (a 'C', 'c', '*', or '!' in the first column). */
  698.  
  699.     else if(comstart[c & 0xfff])
  700.     {
  701.         if (feof (infile)
  702. #ifdef EOF_CHAR
  703.              || c == EOF_CHAR
  704. #endif
  705.                     )
  706.             return STEOF;
  707.  
  708.         if (c == '#') {
  709.             *endcd++ = c;
  710.             while((c = getc(infile)) != '\n')
  711.                 if (c == EOF)
  712.                     return STEOF;
  713.                 else if (endcd < bend)
  714.                     *endcd++ = c;
  715.             ++thislin;
  716.             *endcd = 0;
  717.             if (b[1] == ' ')
  718.                 p = b + 2;
  719.             else if (!strncmp(b,"#line ",6))
  720.                 p = b + 6;
  721.             else {
  722.  bad_cpp:
  723.                 errstr("Bad # line: \"%s\"", b);
  724.                 goto top;
  725.                 }
  726.             if (*p < '1' || *p > '9')
  727.                 goto bad_cpp;
  728.             L = *p - '1';    /* bias down 1 */
  729.             while((c = *++p) >= '0' && c <= '9')
  730.                 L = 10*L + c - '0';
  731.             if (c != ' ' || *++p != '"')
  732.                 goto bad_cpp;
  733.             bend = p;
  734.             while(*++p != '"')
  735.                 if (!*p)
  736.                     goto bad_cpp;
  737.             *p = 0;
  738.             i = p - bend++;
  739.             thislin = L;
  740.             if (!infname || strcmp(infname, bend)) {
  741.                 if (infname)
  742.                     free(infname);
  743.                 infname = Alloc(i);
  744.                 strcpy(infname, bend);
  745.                 if (inclp)
  746.                     inclp->inclname = infname;
  747.                 }
  748.             goto top;
  749.             }
  750.  
  751.         storage[COMMENT_BUFFER_SIZE] = c = '\0';
  752.         pointer = storage;
  753.         while( !feof (infile) && (*pointer++ = c = getc(infile)) != '\n') {
  754.  
  755. /* Handle obscure end of file conditions on many machines */
  756.  
  757.             if (feof (infile) && (c == '\377' || c == EOF)) {
  758.                 pointer--;
  759.                 break;
  760.             } /* if (feof (infile)) */
  761.  
  762.             if (c == '\0')
  763.                 *(pointer - 1) = ' ';
  764.  
  765.             if (pointer == &storage[COMMENT_BUFFER_SIZE]) {
  766.                 store_comment (storage);
  767.                 pointer = storage;
  768.             } /* if (pointer == BUFFER_SIZE) */
  769.         } /* while */
  770.  
  771.         if (pointer > storage) {
  772.             if (c == '\n')
  773.  
  774. /* Get rid of the newline */
  775.  
  776.             pointer[-1] = 0;
  777.             else
  778.             *pointer = 0;
  779.  
  780.             store_comment (storage);
  781.         } /* if */
  782.  
  783.         if (feof (infile))
  784.             if (c != '\n')    /* To allow the line index to
  785.                        increment correctly */
  786.             return STEOF;
  787.  
  788.         ++thislin;
  789.         goto top;
  790.     }
  791.  
  792.     else if(c != EOF)
  793.     {
  794.  
  795. /* Load buffer   a   with the statement label */
  796.  
  797.         /* a tab in columns 1-6 skips to column 7 */
  798.         ungetc(c, infile);
  799.         for(p=a; p<aend && (c=getc(infile)) != '\n' && c!=EOF; )
  800.             if(c == '\t')
  801.  
  802. /* The tab character translates into blank characters in the statement label */
  803.  
  804.             {
  805.                 atend = p;
  806.                 while(p < aend)
  807.                     *p++ = BLANK;
  808.                 speclin = YES;
  809.                 bend = send;
  810.             }
  811.             else
  812.                 *p++ = c;
  813.     }
  814.  
  815. /* By now we've read either a continuation character or the statement label
  816.    field */
  817.  
  818.     if(c == EOF)
  819.         return(STEOF);
  820.  
  821. /* The next 'if' block handles lines that have fewer than 7 characters */
  822.  
  823.     if(c == '\n')
  824.     {
  825.         while(p < aend)
  826.             *p++ = BLANK;
  827.  
  828. /* Blank out the buffer on lines which are not longer than 66 characters */
  829.  
  830.         endcd0 = endcd;
  831.         if( ! speclin )
  832.             while(endcd < bend)
  833.                 *endcd++ = BLANK;
  834.     }
  835.     else    {    /* read body of line */
  836.         if (warn72 & 2) {
  837.             speclin = YES;
  838.             bend = send;
  839.             }
  840.         while( endcd<bend && (c=getc(infile)) != '\n' && c!=EOF )
  841.             *endcd++ = c;
  842.         if(c == EOF)
  843.             return(STEOF);
  844.  
  845. /* Drop any extra characters on the input card; this usually means those after
  846.    column 72 */
  847.  
  848.         if(c != '\n')
  849.         {
  850.             i = 0;
  851.             while( (c=getc(infile)) != '\n' && c != EOF)
  852.                 if (i < 23)
  853.                     buf72[i++] = c;
  854.             if (warn72 && i && !speclin) {
  855.                 buf72[i] = 0;
  856.                 if (i >= 23)
  857.                     strcpy(buf72+20, "...");
  858.                 lineno = thislin + 1;
  859.                 errstr("text after column 72: %s", buf72);
  860.                 }
  861.             if(c == EOF)
  862.                 return(STEOF);
  863.         }
  864.  
  865.         endcd0 = endcd;
  866.         if( ! speclin )
  867.             while(endcd < bend)
  868.                 *endcd++ = BLANK;
  869.     }
  870.  
  871. /* The flow of control usually gets to this line (unless an earlier RETURN has
  872.    been taken) */
  873.  
  874.     ++thislin;
  875.  
  876.     /* Fortran 77 specifies that a 0 in column 6 */
  877.     /* does not signify continuation */
  878.  
  879.     if( !isspace(a[5]) && a[5]!='0') {
  880.         if (!amp)
  881.             for(p = a; p < aend;)
  882.                 if (*p++ == '!' && p != aend)
  883.                     goto initcheck;
  884.         if (addftnsrc && stb) {
  885.             if (stbend > stb + 7) { /* otherwise forget col 1-6 */
  886.                 /* kludge around funny p1gets behavior */
  887.                 *stb++ = '$';
  888.                 if (amp)
  889.                     *stb++ = '&';
  890.                 else
  891.                     for(p = a; p < atend;)
  892.                         *stb++ = *p++;
  893.                 }
  894.             if (endcd0 - b > stbend - stb) {
  895.                 if (stb > stbend)
  896.                     stb = stbend;
  897.                 endcd0 = b + (stbend - stb);
  898.                 }
  899.             for(p = b; p < endcd0;)
  900.                 *stb++ = *p++;
  901.             *stb++ = '\n';
  902.             *stb = 0;
  903.             }
  904.         if (nocont) {
  905.             lineno = thislin;
  906.             errstr("illegal continuation card (starts \"%.6s\")",a);
  907.             }
  908.         else if (!amp && strncmp(a,"     ",5)) {
  909.             lineno = thislin;
  910.             errstr("labeled continuation line (starts \"%.6s\")",a);
  911.             }
  912.         return(STCONTINUE);
  913.         }
  914. initcheck:
  915.     for(p=a; p<atend; ++p)
  916.         if( !isspace(*p) ) {
  917.             if (*p++ != '!')
  918.                 goto initline;
  919.             bang(p, atend, aend, b, endcd);
  920.             goto top;
  921.             }
  922.     for(p = b ; p<endcd ; ++p)
  923.         if( !isspace(*p) ) {
  924.             if (*p++ != '!')
  925.                 goto initline;
  926.             bang(a, a, a, p, endcd);
  927.             goto top;
  928.             }
  929.  
  930. /* Skip over blank cards by reading the next one right away */
  931.  
  932.     goto top;
  933.  
  934. initline:
  935.     if (addftnsrc) {
  936.         nst = (nst+1)%3;
  937.         if (!laststb && stb0)
  938.             laststb = stb0;
  939.         stb0 = stb = stbuf[nst];
  940.         *stb++ = '$';    /* kludge around funny p1gets behavior */
  941.         stbend = stb + sizeof(stbuf[0])-2;
  942.         for(p = a; p < atend;)
  943.             *stb++ = *p++;
  944.         if (atend < aend)
  945.             *stb++ = '\t';
  946.         for(p = b; p < endcd0;)
  947.             *stb++ = *p++;
  948.         *stb++ = '\n';
  949.         *stb = 0;
  950.         }
  951.  
  952. /* Set   nxtstno   equal to the integer value of the statement label */
  953.  
  954.     nxtstno = 0;
  955.     bend = a + 5;
  956.     for(p = a ; p < bend ; ++p)
  957.         if( !isspace(*p) )
  958.             if(isdigit(*p))
  959.                 nxtstno = 10*nxtstno + (*p - '0');
  960.             else if (*p == '!') {
  961.                 if (!addftnsrc)
  962.                     bang(p+1,atend,aend,b,endcd);
  963.                 endcd = b;
  964.                 break;
  965.                 }
  966.             else    {
  967.                 lineno = thislin;
  968.                 errstr(
  969.                 "nondigit in statement label field \"%.5s\"", a);
  970.                 nxtstno = 0;
  971.                 break;
  972.             }
  973.     firstline = thislin;
  974.     return(STINITIAL);
  975. }
  976.  
  977.  
  978. /* crunch -- deletes all space characters, folds the backslash chars and
  979.    Hollerith strings, quotes the Fortran strings */
  980.  
  981.  LOCAL void
  982. crunch(Void)
  983. {
  984.     register char *i, *j, *j0, *j1, *prvstr;
  985.     int k, ten, nh, nh0, quote;
  986.  
  987.     /* i is the next input character to be looked at
  988.        j is the next output character */
  989.  
  990.     new_dcl = needwkey = parlev = parseen = 0;
  991.     expcom = 0;    /* exposed ','s */
  992.     expeql = 0;    /* exposed equal signs */
  993.     j = sbuf;
  994.     prvstr = sbuf;
  995.     k = 0;
  996.     for(i=sbuf ; i<=lastch ; ++i)
  997.     {
  998.         if(isspace(*i) )
  999.             continue;
  1000.         if (*i == '!') {
  1001.             while(i >= linestart[k])
  1002.                 if (++k >= maxcont)
  1003.                     contmax();
  1004.             j0 = linestart[k];
  1005.             if (!addftnsrc)
  1006.                 bang(sbuf,sbuf,sbuf,i+1,j0);
  1007.             i = j0-1;
  1008.             continue;
  1009.             }
  1010.  
  1011. /* Keep everything in a quoted string */
  1012.  
  1013.         if(*i=='\'' ||  *i=='"')
  1014.         {
  1015.             int len = 0;
  1016.  
  1017.             quote = *i;
  1018.             *j = MYQUOTE; /* special marker */
  1019.             for(;;)
  1020.             {
  1021.                 if(++i > lastch)
  1022.                 {
  1023.                     err("unbalanced quotes; closing quote supplied");
  1024.                     if (j >= lastch)
  1025.                         j = lastch - 1;
  1026.                     break;
  1027.                 }
  1028.                 if(*i == quote)
  1029.                     if(i<lastch && i[1]==quote) ++i;
  1030.                     else break;
  1031.                 else if(*i=='\\' && i<lastch && use_bs) {
  1032.                     ++i;
  1033.                     *i = escapes[*(unsigned char *)i];
  1034.                     }
  1035.                 if (len < MAXTOKENLEN)
  1036.                     *++j = *i;
  1037.                 else if (len == MAXTOKENLEN)
  1038.                     erri
  1039.         ("String too long, truncating to %d chars", MAXTOKENLEN);
  1040.                 len++;
  1041.             } /* for (;;) */
  1042.  
  1043.             j[1] = MYQUOTE;
  1044.             j += 2;
  1045.             prvstr = j;
  1046.         }
  1047.         else if( (*i=='h' || *i=='H')  && j>prvstr)    /* test for Hollerith strings */
  1048.         {
  1049.             j0 = j - 1;
  1050.             if( ! isdigit(*j0)) goto copychar;
  1051.             nh = *j0 - '0';
  1052.             ten = 10;
  1053.             j1 = prvstr;
  1054.             if (j1+4 < j)
  1055.                 j1 = j-4;
  1056.             for(;;) {
  1057.                 if (j0-- <= j1)
  1058.                     goto copychar;
  1059.                 if( ! isdigit(*j0 ) ) break;
  1060.                 nh += ten * (*j0-'0');
  1061.                 ten*=10;
  1062.                 }
  1063.             /* a hollerith must be preceded by a punctuation mark.
  1064.    '*' is possible only as repetition factor in a data statement
  1065.    not, in particular, in character*2h
  1066. */
  1067.  
  1068.             if( !(*j0=='*'&&sbuf[0]=='d') && *j0!='/'
  1069.             && *j0!='(' && *j0!=',' && *j0!='=' && *j0!='.')
  1070.                 goto copychar;
  1071.             nh0 = nh;
  1072.             if(i+nh > lastch || nh > MAXTOKENLEN)
  1073.             {
  1074.                 erri("%dH too big", nh);
  1075.                 nh = lastch - i;
  1076.                 if (nh > MAXTOKENLEN)
  1077.                     nh = MAXTOKENLEN;
  1078.                 nh0 = -1;
  1079.             }
  1080.             j0[1] = MYQUOTE; /* special marker */
  1081.             j = j0 + 1;
  1082.             while(nh-- > 0)
  1083.             {
  1084.                 if (++i > lastch) {
  1085.  hol_overflow:
  1086.                     if (nh0 >= 0)
  1087.                       erri("escapes make %dH too big",
  1088.                         nh0);
  1089.                     break;
  1090.                     }
  1091.                 if(*i == '\\' && use_bs) {
  1092.                     if (++i > lastch)
  1093.                         goto hol_overflow;
  1094.                     *i = escapes[*(unsigned char *)i];
  1095.                     }
  1096.                 *++j = *i;
  1097.             }
  1098.             j[1] = MYQUOTE;
  1099.             j+=2;
  1100.             prvstr = j;
  1101.         }
  1102.         else    {
  1103.             if(*i == '(') parseen = ++parlev;
  1104.             else if(*i == ')') --parlev;
  1105.             else if(parlev == 0)
  1106.                 if(*i == '=') expeql = 1;
  1107.                 else if(*i == ',') expcom = 1;
  1108. copychar:        /*not a string or space -- copy, shifting case if necessary */
  1109.             if(shiftcase && isupper(*i))
  1110.                 *j++ = tolower(*i);
  1111.             else    *j++ = *i;
  1112.         }
  1113.     }
  1114.     lastch = j - 1;
  1115.     nextch = sbuf;
  1116. }
  1117.  
  1118.  LOCAL void
  1119. analyz(Void)
  1120. {
  1121.     register char *i;
  1122.  
  1123.     if(parlev != 0)
  1124.     {
  1125.         err("unbalanced parentheses, statement skipped");
  1126.         stkey = SUNKNOWN;
  1127.         lastch = sbuf - 1; /* prevent double error msg */
  1128.         return;
  1129.     }
  1130.     if(nextch+2<=lastch && nextch[0]=='i' && nextch[1]=='f' && nextch[2]=='(')
  1131.     {
  1132.         /* assignment or if statement -- look at character after balancing paren */
  1133.         parlev = 1;
  1134.         for(i=nextch+3 ; i<=lastch; ++i)
  1135.             if(*i == (MYQUOTE))
  1136.             {
  1137.                 while(*++i != MYQUOTE)
  1138.                     ;
  1139.             }
  1140.             else if(*i == '(')
  1141.                 ++parlev;
  1142.             else if(*i == ')')
  1143.             {
  1144.                 if(--parlev == 0)
  1145.                     break;
  1146.             }
  1147.         if(i >= lastch)
  1148.             stkey = SLOGIF;
  1149.         else if(i[1] == '=')
  1150.             stkey = SLET;
  1151.         else if( isdigit(i[1]) )
  1152.             stkey = SARITHIF;
  1153.         else    stkey = SLOGIF;
  1154.         if(stkey != SLET)
  1155.             nextch += 2;
  1156.     }
  1157.     else if(expeql) /* may be an assignment */
  1158.     {
  1159.         if(expcom && nextch<lastch &&
  1160.             nextch[0]=='d' && nextch[1]=='o')
  1161.         {
  1162.             stkey = SDO;
  1163.             nextch += 2;
  1164.         }
  1165.         else    stkey = SLET;
  1166.     }
  1167.     else if (parseen && nextch + 7 < lastch
  1168.             && nextch[2] != 'u' /* screen out "double..." early */
  1169.             && nextch[0] == 'd' && nextch[1] == 'o'
  1170.             && ((nextch[2] >= '0' && nextch[2] <= '9')
  1171.                 || nextch[2] == ','
  1172.                 || nextch[2] == 'w'))
  1173.         {
  1174.         stkey = SDO;
  1175.         nextch += 2;
  1176.         needwkey = 1;
  1177.         }
  1178.     /* otherwise search for keyword */
  1179.     else    {
  1180.         stkey = getkwd();
  1181.         if(stkey==SGOTO && lastch>=nextch)
  1182.             if(nextch[0]=='(')
  1183.                 stkey = SCOMPGOTO;
  1184.             else if(isalpha_(* USC nextch))
  1185.                 stkey = SASGOTO;
  1186.     }
  1187.     parlev = 0;
  1188. }
  1189.  
  1190.  
  1191.  
  1192.  LOCAL int
  1193. getkwd(Void)
  1194. {
  1195.     register char *i, *j;
  1196.     register struct Keylist *pk, *pend;
  1197.     int k;
  1198.  
  1199.     if(! isalpha_(* USC nextch) )
  1200.         return(SUNKNOWN);
  1201.     k = letter(nextch[0]);
  1202.     if(pk = keystart[k])
  1203.         for(pend = keyend[k] ; pk<=pend ; ++pk )
  1204.         {
  1205.             i = pk->keyname;
  1206.             j = nextch;
  1207.             while(*++i==*++j && *i!='\0')
  1208.                 ;
  1209.             if(*i=='\0' && j<=lastch+1)
  1210.             {
  1211.                 nextch = j;
  1212.                 if(no66flag && pk->notinf66)
  1213.                     errstr("Not a Fortran 66 keyword: %s",
  1214.                         pk->keyname);
  1215.                 return(pk->keyval);
  1216.             }
  1217.         }
  1218.     return(SUNKNOWN);
  1219. }
  1220.  
  1221.  void
  1222. initkey(Void)
  1223. {
  1224.     register struct Keylist *p;
  1225.     register int i,j;
  1226.     register char *s;
  1227.  
  1228.     for(i = 0 ; i<26 ; ++i)
  1229.         keystart[i] = NULL;
  1230.  
  1231.     for(p = keys ; p->keyname ; ++p) {
  1232.         j = letter(p->keyname[0]);
  1233.         if(keystart[j] == NULL)
  1234.             keystart[j] = p;
  1235.         keyend[j] = p;
  1236.         }
  1237.     i = (maxcontin + 2) * 66;
  1238.     sbuf = (char *)ckalloc(i + 70);
  1239.     send = sbuf + i;
  1240.     maxcont = maxcontin + 1;
  1241.     linestart = (char **)ckalloc(maxcont*sizeof(char*));
  1242.     comstart['c'] = comstart['C'] = comstart['*'] = comstart['!'] =
  1243.     comstart['#'] = 1;
  1244. #ifdef EOF_CHAR
  1245.     comstart[EOF_CHAR] = 1;
  1246. #endif
  1247.     s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
  1248.     while(i = *s++)
  1249.         anum_buf[i] = 1;
  1250.     s = "0123456789";
  1251.     while(i = *s++)
  1252.         anum_buf[i] = 2;
  1253.     }
  1254.  
  1255.  LOCAL int
  1256. #ifdef KR_headers
  1257. hexcheck(key)
  1258.     int key;
  1259. #else
  1260. hexcheck(int key)
  1261. #endif
  1262. {
  1263.     register int radix;
  1264.     register char *p;
  1265.     char *kind;
  1266.  
  1267.     switch(key) {
  1268.         case 'z':
  1269.         case 'Z':
  1270.         case 'x':
  1271.         case 'X':
  1272.             radix = 16;
  1273.             key = SHEXCON;
  1274.             kind = "hexadecimal";
  1275.             break;
  1276.         case 'o':
  1277.         case 'O':
  1278.             radix = 8;
  1279.             key = SOCTCON;
  1280.             kind = "octal";
  1281.             break;
  1282.         case 'b':
  1283.         case 'B':
  1284.             radix = 2;
  1285.             key = SBITCON;
  1286.             kind = "binary";
  1287.             break;
  1288.         default:
  1289.             err("bad bit identifier");
  1290.             return(SNAME);
  1291.         }
  1292.     for(p = token; *p; p++)
  1293.         if (hextoi(*p) >= radix) {
  1294.             errstr("invalid %s character", kind);
  1295.             break;
  1296.             }
  1297.     return key;
  1298.     }
  1299.  
  1300. /* gettok -- moves the right amount of text from   nextch   into the   token
  1301.    buffer.   token   initially contains garbage (leftovers from the prev token) */
  1302.  
  1303.  LOCAL int
  1304. gettok(Void)
  1305. {
  1306.     int havdot, havexp, havdbl;
  1307.     int radix, val;
  1308.     struct Punctlist *pp;
  1309.     struct Dotlist *pd;
  1310.     register int ch;
  1311.  
  1312.     char *i, *j, *n1, *p;
  1313.  
  1314.     ch = * USC nextch;
  1315.     if(ch == (MYQUOTE))
  1316.     {
  1317.         ++nextch;
  1318.         p = token;
  1319.         while(*nextch != MYQUOTE)
  1320.             *p++ = *nextch++;
  1321.         toklen = p - token;
  1322.         *p = 0;
  1323.         /* allow octal, binary, hex constants of the form 'abc'x (etc.) */
  1324.         if (++nextch <= lastch && isalpha_(val = * USC nextch)) {
  1325.             ++nextch;
  1326.             return hexcheck(val);
  1327.             }
  1328.         return (SHOLLERITH);
  1329.     }
  1330.  
  1331.     if(needkwd)
  1332.     {
  1333.         needkwd = 0;
  1334.         return( getkwd() );
  1335.     }
  1336.  
  1337.     for(pp=puncts; pp->punchar; ++pp)
  1338.         if(ch == pp->punchar) {
  1339.             val = pp->punval;
  1340.             if (++nextch <= lastch)
  1341.                 switch(ch) {
  1342.                 case '/':
  1343.                     if (*nextch == '/') {
  1344.                         nextch++;
  1345.                         val = SCONCAT;
  1346.                         }
  1347.                     else if (new_dcl && parlev == 0)
  1348.                         val = SSLASHD;
  1349.                     return val;
  1350.                 case '*':
  1351.                     if (*nextch == '*') {
  1352.                         nextch++;
  1353.                         return SPOWER;
  1354.                         }
  1355.                     break;
  1356.                 case '<':
  1357.                     if (*nextch == '=') {
  1358.                         nextch++;
  1359.                         val = SLE;
  1360.                         }
  1361.                     if (*nextch == '>') {
  1362.                         nextch++;
  1363.                         val = SNE;
  1364.                         }
  1365.                     goto extchk;
  1366.                 case '=':
  1367.                     if (*nextch == '=') {
  1368.                         nextch++;
  1369.                         val = SEQ;
  1370.                         goto extchk;
  1371.                         }
  1372.                     break;
  1373.                 case '>':
  1374.                     if (*nextch == '=') {
  1375.                         nextch++;
  1376.                         val = SGE;
  1377.                         }
  1378.  extchk:
  1379.                     NOEXT("Fortran 8x comparison operator");
  1380.                     return val;
  1381.                 }
  1382.             else if (ch == '/' && new_dcl && parlev == 0)
  1383.                 return SSLASHD;
  1384.             switch(val) {
  1385.                 case SLPAR:
  1386.                     ++parlev;
  1387.                     break;
  1388.                 case SRPAR:
  1389.                     --parlev;
  1390.                 }
  1391.             return(val);
  1392.             }
  1393.     if(ch == '.')
  1394.         if(nextch >= lastch) goto badchar;
  1395.         else if(isdigit(nextch[1])) goto numconst;
  1396.         else    {
  1397.             for(pd=dots ; (j=pd->dotname) ; ++pd)
  1398.             {
  1399.                 for(i=nextch+1 ; i<=lastch ; ++i)
  1400.                     if(*i != *j) break;
  1401.                     else if(*i != '.') ++j;
  1402.                     else    {
  1403.                         nextch = i+1;
  1404.                         return(pd->dotval);
  1405.                     }
  1406.             }
  1407.             goto badchar;
  1408.         }
  1409.     if( isalpha_(ch) )
  1410.     {
  1411.         p = token;
  1412.         *p++ = *nextch++;
  1413.         while(nextch<=lastch)
  1414.             if( isalnum_(* USC nextch) )
  1415.                 *p++ = *nextch++;
  1416.             else break;
  1417.         toklen = p - token;
  1418.         *p = 0;
  1419.         if (needwkey) {
  1420.             needwkey = 0;
  1421.             if (toklen == 5
  1422.                 && nextch <= lastch && *nextch == '(' /*)*/
  1423.                 && !strcmp(token,"while"))
  1424.             return(SWHILE);
  1425.             }
  1426.         if(inioctl && nextch<=lastch && *nextch=='=')
  1427.         {
  1428.             ++nextch;
  1429.             return(SNAMEEQ);
  1430.         }
  1431.         if(toklen>8 && eqn(8,token,"function")
  1432.         && isalpha_(* USC (token+8)) &&
  1433.             nextch<lastch && nextch[0]=='(' &&
  1434.             (nextch[1]==')' || isalpha_(* USC (nextch+1))) )
  1435.         {
  1436.             nextch -= (toklen - 8);
  1437.             return(SFUNCTION);
  1438.         }
  1439.  
  1440.         if(toklen > 50)
  1441.         {
  1442.             char buff[100];
  1443.             sprintf(buff, toklen >= 60
  1444.                 ? "name %.56s... too long, truncated to %.*s"
  1445.                 : "name %s too long, truncated to %.*s",
  1446.                 token, 50, token);
  1447.             err(buff);
  1448.             toklen = 50;
  1449.             token[50] = '\0';
  1450.         }
  1451.         if(toklen==1 && *nextch==MYQUOTE) {
  1452.             val = token[0];
  1453.             ++nextch;
  1454.             for(p = token ; *nextch!=MYQUOTE ; )
  1455.                 *p++ = *nextch++;
  1456.             ++nextch;
  1457.             toklen = p - token;
  1458.             *p = 0;
  1459.             return hexcheck(val);
  1460.         }
  1461.         return(SNAME);
  1462.     }
  1463.  
  1464.     if (isdigit(ch)) {
  1465.  
  1466.         /* Check for NAG's special hex constant */
  1467.  
  1468.         if (nextch[1] == '#' && nextch < lastch
  1469.         ||  nextch[2] == '#' && isdigit(nextch[1]
  1470.                      && lastch - nextch >= 2)) {
  1471.  
  1472.             radix = atoi (nextch);
  1473.             if (*++nextch != '#')
  1474.             nextch++;
  1475.             if (radix != 2 && radix != 8 && radix != 16) {
  1476.                 erri("invalid base %d for constant, defaulting to hex",
  1477.                 radix);
  1478.             radix = 16;
  1479.             } /* if */
  1480.             if (++nextch > lastch)
  1481.             goto badchar;
  1482.             for (p = token; hextoi(*nextch) < radix;) {
  1483.             *p++ = *nextch++;
  1484.             if (nextch > lastch)
  1485.                 break;
  1486.             }
  1487.             toklen = p - token;
  1488.             *p = 0;
  1489.             return (radix == 16) ? SHEXCON : ((radix == 8) ? SOCTCON :
  1490.                 SBITCON);
  1491.             }
  1492.         }
  1493.     else
  1494.         goto badchar;
  1495. numconst:
  1496.     havdot = NO;
  1497.     havexp = NO;
  1498.     havdbl = NO;
  1499.     for(n1 = nextch ; nextch<=lastch ; ++nextch)
  1500.     {
  1501.         if(*nextch == '.')
  1502.             if(havdot) break;
  1503.             else if(nextch+2<=lastch && isalpha_(* USC (nextch+1))
  1504.                 && isalpha_(* USC (nextch+2)))
  1505.                 break;
  1506.             else    havdot = YES;
  1507.         else if( !intonly && (*nextch=='d' || *nextch=='e') )
  1508.         {
  1509.             p = nextch;
  1510.             havexp = YES;
  1511.             if(*nextch == 'd')
  1512.                 havdbl = YES;
  1513.             if(nextch<lastch)
  1514.                 if(nextch[1]=='+' || nextch[1]=='-')
  1515.                     ++nextch;
  1516.             if( ! isdigit(*++nextch) )
  1517.             {
  1518.                 nextch = p;
  1519.                 havdbl = havexp = NO;
  1520.                 break;
  1521.             }
  1522.             for(++nextch ;
  1523.                 nextch<=lastch && isdigit(* USC nextch);
  1524.                 ++nextch);
  1525.             break;
  1526.         }
  1527.         else if( ! isdigit(* USC nextch) )
  1528.             break;
  1529.     }
  1530.     p = token;
  1531.     i = n1;
  1532.     while(i < nextch)
  1533.         *p++ = *i++;
  1534.     toklen = p - token;
  1535.     *p = 0;
  1536.     if(havdbl) return(SDCON);
  1537.     if(havdot || havexp) return(SRCON);
  1538.     return(SICON);
  1539. badchar:
  1540.     sbuf[0] = *nextch++;
  1541.     return(SUNKNOWN);
  1542. }
  1543.  
  1544. /* Comment buffering code */
  1545.  
  1546.  static void
  1547. #ifdef KR_headers
  1548. store_comment(str)
  1549.     char *str;
  1550. #else
  1551. store_comment(char *str)
  1552. #endif
  1553. {
  1554.     int len;
  1555.     comment_buf *ncb;
  1556.  
  1557.     if (nextcd == sbuf) {
  1558.         flush_comments();
  1559.         p1_comment(str);
  1560.         return;
  1561.         }
  1562.     len = strlen(str) + 1;
  1563.     if (cbnext + len > cblast) {
  1564.         if (!cbcur || !(ncb = cbcur->next)) {
  1565.             ncb = (comment_buf *) Alloc(sizeof(comment_buf));
  1566.             if (cbcur) {
  1567.                 cbcur->last = cbnext;
  1568.                 cbcur->next = ncb;
  1569.                 }
  1570.             else {
  1571.                 cbfirst = ncb;
  1572.                 cbinit = ncb->buf;
  1573.                 }
  1574.             ncb->next = 0;
  1575.             }
  1576.         cbcur = ncb;
  1577.         cbnext = ncb->buf;
  1578.         cblast = cbnext + COMMENT_BUF_STORE;
  1579.         }
  1580.     strcpy(cbnext, str);
  1581.     cbnext += len;
  1582.     }
  1583.  
  1584.  static void
  1585. flush_comments(Void)
  1586. {
  1587.     register char *s, *s1;
  1588.     register comment_buf *cb;
  1589.     if (cbnext == cbinit)
  1590.         return;
  1591.     cbcur->last = cbnext;
  1592.     for(cb = cbfirst;; cb = cb->next) {
  1593.         for(s = cb->buf; s < cb->last; s = s1) {
  1594.             /* compute s1 = new s value first, since */
  1595.             /* p1_comment may insert nulls into s */
  1596.             s1 = s + strlen(s) + 1;
  1597.             p1_comment(s);
  1598.             }
  1599.         if (cb == cbcur)
  1600.             break;
  1601.         }
  1602.     cbcur = cbfirst;
  1603.     cbnext = cbinit;
  1604.     cblast = cbnext + COMMENT_BUF_STORE;
  1605.     }
  1606.  
  1607.  void
  1608. unclassifiable(Void)
  1609. {
  1610.     register char *s, *se;
  1611.  
  1612.     s = sbuf;
  1613.     se = lastch;
  1614.     if (se < sbuf)
  1615.         return;
  1616.     lastch = s - 1;
  1617.     if (se - s > 10)
  1618.         se = s + 10;
  1619.     for(; s < se; s++)
  1620.         if (*s == MYQUOTE) {
  1621.             se = s;
  1622.             break;
  1623.             }
  1624.     *se = 0;
  1625.     errstr("unclassifiable statement (starts \"%s\")", sbuf);
  1626.     }
  1627.