home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / CONTRIB / MBASE / MBASE50.TAR / mbase / src / parse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-10  |  1.8 KB  |  102 lines

  1. /*
  2.  * METALBASE 5.0
  3.  *
  4.  * Released October 1st, 1992 by Huan-Ti [ richid@owlnet.rice.edu ]
  5.  *                                       [ t-richj@microsoft.com ]
  6.  */
  7.  
  8. #define PARSE_C
  9. #include "mbase.h"
  10.  
  11. long  _lpos = 0L;
  12. int   quoted = 0;
  13.  
  14. int
  15. skip (f, s)  /* 0 means didn't skip the word, 1 means we did. */
  16. int   f;
  17. char    *s;
  18. {
  19.    int   i;
  20.    char  a;
  21.  
  22.    i = 0;
  23.    _lpos = lseek (f, 0L, 1);
  24.  
  25.    while (s[i] != 0)
  26.     {
  27.       if (read (f, &a, 1) != 1)  return -1;
  28.  
  29.       if (i != 0 || (i==0 && !iswhite(a)))
  30.        { if (s[i] != tolower(a))
  31.           { lseek (f, -1L -(long)i, 1);
  32.             break;
  33.           }
  34.          else
  35.             i++;
  36.        }
  37.     }
  38.  
  39.    return (s[i] == 0);
  40. }
  41.  
  42. char *
  43. getword (fle)
  44. int      fle;
  45. {
  46.    int          okay = 1, go = 0;
  47.    static char  buffer[256];
  48.    char        *ptr,   a;
  49.  
  50.    while (read (fle, &a, 1) == 1)
  51.       if (! iswhite (a))  break;
  52.    _lpos = lseek (fle, 0L, 1)-1L;
  53.  
  54.    quoted = 0;
  55.  
  56.    for (ptr = buffer; okay; okay = read (fle, &a, 1))
  57.     { if (go == 1 && !quoted && istoken (a))
  58.        { lseek (fle, -1L, 1);  /* Backup--we don't want the token yet */
  59.          break;
  60.        }
  61.       if (a == '\"')
  62.          if (quoted)  break;
  63.          else
  64.           { quoted = 1;
  65.             continue;
  66.           }
  67.  
  68.       if (quoted)  *ptr = a;
  69.       else
  70.          if (iswhite(a)) break;
  71.          else            *ptr = tolower(a);
  72.  
  73.       ptr++; go = 1;
  74.       if (! quoted && istoken (a))  break;
  75.     }
  76.    *ptr = 0;
  77.  
  78.    return buffer;
  79. }
  80.  
  81. void
  82. goeol (fle, str)
  83. int    fle;
  84. char       *str;
  85. {
  86.    char  a, *ptr;
  87.    char  f;
  88.  
  89.    _lpos = lseek (fle, 0L, 1);
  90.  
  91.    for (ptr = str; read (fle, &a, 1) == 1; )
  92.     { if (a == '\n' || a == '\r')  break;
  93.       if (ptr != NULL)  { *ptr = a; ptr++; }
  94.     }
  95.    if (ptr != NULL)  *ptr = 0;
  96.  
  97.    if (read (fle, &f, 1) == 1)
  98.       if ((f != '\n' && f != '\r') || f == a)
  99.          lseek (fle, -1L, 1);
  100. }
  101.  
  102.