home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / make_1 / !make_c_reader < prev    next >
Encoding:
Text File  |  1992-12-07  |  1.5 KB  |  100 lines

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