home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / CPM3 / CPMMAKE.ARK / READER.C < prev    next >
C/C++ Source or Header  |  1986-08-31  |  3KB  |  156 lines

  1. /*
  2.  *    Read in makefile
  3.  */
  4.  
  5.  
  6. #include "c:stdio.h"
  7. #include "h.h"
  8.  
  9.  
  10. int            lineno;
  11.  
  12. int endoffile = FALSE;
  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, " on 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.     int            concatflag = 0;
  44.     int            size;
  45.  
  46.  
  47.     for (;;)
  48.     {
  49.         if (fgets(str+pos, LZ-pos, fd) == (char *)0) {
  50.             endoffile = TRUE;
  51.             return (TRUE);        /*  EOF  */
  52.             
  53.         }
  54.         if (index(str+pos,'\032') != (char *)0) {
  55.             endoffile = TRUE;
  56.             return(TRUE);
  57.         }
  58.  
  59.         /*
  60.          * Strip CP/M CR characters
  61.          */
  62.         if ((p=index(str+pos,'\015')) != (char *)0) {
  63.             do {
  64.                 *p = p[1];
  65.             } while (*(++p) != '\0');
  66.         }
  67.  
  68.         /*
  69.          * Shorten leading whitespace on line extensions.
  70.          */
  71.         if (concatflag != 0) {
  72.             for (p = str+pos ; iswhite(*p) ; p++ ) ;
  73.             size = p-str-pos-1;
  74.             if (size > 0) {
  75.                 p = str+pos+1;
  76.                 while ((*p = p[size]) != '\0') {
  77.                     p++;
  78.                 }
  79.             }
  80.         }
  81.  
  82.         strlower(str+pos); /* let's do everything inlower case */
  83.  
  84.         lineno++;
  85.  
  86.         if ((p = index(str+pos, '\n')) == (char *)0)
  87.             error("Line too long");
  88.  
  89.         /* 
  90.          * I want to actually join lines that are logically joined
  91.          * so that when link commands are generated for CP/M,
  92.          * a usable CCP command line will be generated.
  93.          */
  94.         if (p[-1] == '\\') {
  95.             *(--p) = '\0';
  96.             pos = p - str;
  97.             concatflag = 1;
  98.             continue;
  99.         }
  100.  
  101.         p = str;
  102.         while (((q = index(p, '#')) != (char *)0) &&
  103.             (p != q) && (q[-1] == '\\'))
  104.         {
  105.             char    *a;
  106.  
  107.             a = q - 1;    /*  Del \ chr; move rest back  */
  108.             p = q;
  109.             while (*a++ = *q++)
  110.                 ;
  111.         }
  112.         if (q != (char *)0)
  113.         {
  114.             q[0] = '\n';
  115.             q[1] = '\0';
  116.         }
  117.  
  118.         p = str;
  119.         while (isspace(*p))    /*  Checking for blank  */
  120.             p++;
  121.  
  122.         if (*p != '\0')
  123.             return FALSE;
  124.         pos = 0;
  125.     }
  126. }
  127.  
  128.  
  129. /*
  130.  *    Get a word from the current line, surounded by white space.
  131.  *    return a pointer to it. String returned has no white spaces
  132.  *    in it.
  133.  */
  134. char *
  135. gettok(ptr)
  136. char    **ptr;
  137. {
  138.     register char *        p;
  139.  
  140.  
  141.     while (isspace(**ptr))    /*  Skip spaces  */
  142.         (*ptr)++;
  143.  
  144.     if (**ptr == '\0')    /*  Nothing after spaces  */
  145.         return NULL;
  146.  
  147.     p = *ptr;        /*  word starts here  */
  148.  
  149.     while ((**ptr != '\0') && (!isspace(**ptr)))
  150.         (*ptr)++;    /*  Find end of word  */
  151.  
  152.     *(*ptr)++ = '\0';    /*  Terminate it  */
  153.  
  154.     return(p);
  155. }
  156.