home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / tools / make / make_pd / reader.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-01-10  |  1.9 KB  |  117 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.     char *            q;
  42.     int            pos = 0;
  43.  
  44.  
  45.     for (;;)
  46.     {
  47.         if (fgets(str+pos, LZ-pos, fd) == (char *)0)
  48.             return TRUE;        /*  EOF  */
  49.  
  50.         lineno++;
  51.  
  52.         if ((p = index(str+pos, '\n')) == (char *)0)
  53.             error("Line too long");
  54.  
  55.         if (p[-1] == '\\')
  56.         {
  57.             p[-1] = '\n';
  58.             pos = p - str;
  59.             continue;
  60.         }
  61.  
  62.         p = str;
  63.         while (((q = index(p, '#')) != (char *)0) &&
  64.             (p != q) && (q[-1] == '\\'))
  65.         {
  66.             char    *a;
  67.  
  68.             a = q - 1;    /*  Del \ chr; move rest back  */
  69.             p = q;
  70.             while (*a++ = *q++)
  71.                 ;
  72.         }
  73.         if (q != (char *)0)
  74.         {
  75.             q[0] = '\n';
  76.             q[1] = '\0';
  77.         }
  78.  
  79.         p = str;
  80.         while (isspace(*p))    /*  Checking for blank  */
  81.             p++;
  82.  
  83.         if (*p != '\0')
  84.             return FALSE;
  85.         pos = 0;
  86.     }
  87. }
  88.  
  89.  
  90. /*
  91.  *    Get a word from the current line, surounded by white space.
  92.  *    return a pointer to it. String returned has no white spaces
  93.  *    in it.
  94.  */
  95. char *
  96. gettok(ptr)
  97. char    **ptr;
  98. {
  99.     register char *        p;
  100.  
  101.  
  102.     while (isspace(**ptr))    /*  Skip spaces  */
  103.         (*ptr)++;
  104.  
  105.     if (**ptr == '\0')    /*  Nothing after spaces  */
  106.         return NULL;
  107.  
  108.     p = *ptr;        /*  word starts here  */
  109.  
  110.     while ((**ptr != '\0') && (!isspace(**ptr)))
  111.         (*ptr)++;    /*  Find end of word  */
  112.  
  113.     *(*ptr)++ = '\0';    /*  Terminate it  */
  114.  
  115.     return(p);
  116. }
  117.