home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 342a.lha / make / reader.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-10  |  2.1 KB  |  116 lines

  1. /*
  2.  *    Read in makefile
  3.  */
  4.  
  5.  
  6. #include <stdio.h>
  7. #include <ctype.h>
  8. #include "h.h"
  9.  
  10.  
  11. int        lineno;
  12.  
  13.  
  14. /*
  15.  *    Syntax error handler.  Print message, with line number, and exits.
  16.  */
  17. void
  18. error(msg, a1, a2, a3)
  19.     char       *msg;
  20. {
  21.     fprintf(stderr, "%s: ", myname);
  22.     fprintf(stderr, msg, a1, a2, a3);
  23.     if (lineno)
  24.     fprintf(stderr, " near line %d", lineno);
  25.     fputc('\n', stderr);
  26.     exit(1);
  27. }
  28.  
  29.  
  30. /*
  31.  *    Read a line into the supplied string of length LZ.  Remove
  32.  *    comments, ignore blank lines. Deal with quoted (\) #, and
  33.  *    quoted newlines.  If EOF return TRUE.
  34.  */
  35. bool
  36. getline(str, fd)
  37.     char       *str;
  38.     FILE       *fd;
  39. {
  40.     register char  *p;
  41.     register char  *q;        /*OIS*0.80*/
  42.     int         pos = 0;
  43.  
  44.  
  45.     for (;;) {
  46.     if (fgets(str + pos, LZ - pos, fd) == (char *) 0)
  47.         return TRUE;    /* EOF    */
  48.  
  49.     lineno++;
  50.  
  51.     if ((p = index(str + pos, '\n')) == (char *) 0)
  52.         error("Line too long");
  53.  
  54.     if (p[-1] == '\\') {
  55.         register char space; /*OIS*0.80*/
  56.         /* p[-1] = '\n';  */ /*OIS*0.80*/
  57.         /* Skip the leading spaces of the next line */
  58.         while (space = getc(fd), space == ' ' || space == '\t');
  59.         p[-1] = space;
  60.         if (space != '\n') {
  61.         pos = p - str;
  62.         continue;   /* read next line */
  63.         }
  64.     }
  65.     p = str;
  66.     while (((q = index(p, '#')) != (char *) 0) &&
  67.            (p != q) && (q[-1] == '\\')) {
  68.         char       *a;
  69.  
  70.         a = q - 1;        /* Del \ chr; move rest back  */
  71.         p = q;
  72.         while (*a++ = *q++);
  73.     }
  74.     if (q != (char *) 0) {
  75.         q[0] = '\n';
  76.         q[1] = '\0';
  77.     }
  78.     p = str;
  79.     while (isspace(*p))    /* Checking for blank line */
  80.         p++;
  81.  
  82.     if (*p != '\0')
  83.         return FALSE;
  84.     pos = 0;
  85.     }
  86. }
  87.  
  88.  
  89. /*
  90.  *    Get a word from the current line, surounded by white space.
  91.  *    return a pointer to it. String returned has no white spaces
  92.  *    in it.
  93.  */
  94. char           *
  95. gettok(ptr)
  96.     register char  **ptr;    /*OIS*0.80*/
  97. {
  98.     register char  *p;
  99.  
  100.  
  101.     while (isspace(**ptr))    /* Skip spaces    */
  102.     (*ptr)++;
  103.  
  104.     if (**ptr == '\0')          /* Nothing after spaces  */
  105.     return NULL;
  106.  
  107.     p = *ptr;            /* word starts here  */
  108.  
  109.     while ((**ptr != '\0') && (!isspace(**ptr)))
  110.     (*ptr)++;        /* Find end of word  */
  111.  
  112.     *(*ptr)++ = '\0';           /* Terminate it  */
  113.  
  114.     return (p);
  115. }
  116.