home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / games / volume2 / dungeon / part04 / lex.c < prev    next >
Text File  |  1987-09-01  |  2KB  |  79 lines

  1. #define FALSE    0
  2. #define TRUE    1
  3.  
  4. lex_(inbuf, inlnt, outbuf, op, vbflag, lprscon)
  5.     char inbuf[78];
  6.     int outbuf[40], *inlnt, *op, *vbflag;
  7.     int *lprscon;    /* added */
  8. {
  9.     /*
  10.      * lex - lexical analyzer, converted from fortran
  11.      *
  12.      * input: one line of ascii characters
  13.      * output: tokenized input, packed in radix-50 format
  14.      */
  15.  
  16.     char    j;
  17.     int    cp, i, k, prsptr;
  18.     static int    num601 = {601};
  19.  
  20.     for (i=0; i<40; i++)
  21.         outbuf[i] = 0;
  22.     *op = -1;
  23.     prsptr = *lprscon - 1;
  24.     /* printf("lex: inbuf=%s, inlnt=%d\n", inbuf, *inlnt); */
  25.  
  26. toknlp:
  27.     *op += 2;
  28.     cp = 0;
  29.     while ((*lprscon)++ <= *inlnt) {
  30.         j = inbuf[prsptr++];
  31.         /* printf("lex: chr=%c\n", j); */
  32.         if ((j == '.') || (j == ','))
  33.             break;
  34.         else if (j == ' ')
  35.             if (cp)        /* if (cp != 0) */
  36.                 goto toknlp;
  37.             else
  38.                 continue;   /* first token */
  39.         else if ((j >= 'A') && (j <= 'Z'))
  40.             j -= '@';
  41.         else if (((j >= '1') && (j <= '9')) || (j == '-'))
  42.             j -= 0x0c;    /* formfeed */
  43.         else {
  44.             if (*vbflag)
  45.                 rspeak_(&num601);
  46.             return(FALSE);
  47.         }
  48.  
  49.         if (cp >= 6)
  50.             /*
  51.              * ignore remainder of any token > 6 chars
  52.              */
  53.             continue;
  54.         /*
  55.          * pack three chars per word in radix-50 format
  56.          */
  57.         k = *op + (cp/3) - 1;
  58.         /* printf("*op=%d, cp=%d, k=%d\n", *op, cp, k); */
  59.         switch (cp%3) {
  60.             case 0:
  61.                 outbuf[k] += j * 1560;
  62.             case 1:
  63.                 outbuf[k] += j * 39;
  64.             case 2:
  65.                 outbuf[k] += j;
  66.         }
  67.         cp++;
  68.     }
  69.     if (*lprscon > *inlnt)
  70.         *lprscon = 1;
  71.     if (!cp)    /* if (cp == 0) */
  72.         if (*op == 1)
  73.             return(FALSE);   /* no valid tokens */
  74.         else {
  75.             *op -= 2;
  76.             return(TRUE);
  77.         };
  78. }
  79.