home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / sozobon / scsrc20 / make / reader.c < prev    next >
C/C++ Source or Header  |  1988-10-13  |  3KB  |  132 lines

  1. /***************************************************************\
  2. *                                *
  3. *  PDMAKE, Atari ST version                    *
  4. *                                *
  5. *  Adapted from mod.sources Vol 7 Issue 71, 1986-12-03.        *
  6. *                                *
  7. *  This port makes extensive use of the original net.sources    *
  8. *  port by Jwahar Bammi.                    *
  9. *                                *
  10. *      Ton van Overbeek                        *
  11. *      Email: TPC862@ESTEC.BITNET                *
  12. *             TPC862%ESTEC.BITNET@WISCVM.WISC.EDU    (ARPA)    *
  13. *             ...!mcvax!tpc862%estec.bitnet   (UUCP Europe)    *
  14. *             ...!ucbvax!tpc862%estec.bitnet  (UUCP U.S.A.)    *
  15. *             71450,3537  (CompuServe)                *
  16. *                                *
  17. \***************************************************************/
  18.  
  19. /*
  20.  *    Read in makefile
  21.  */
  22.  
  23.  
  24. #include <stdio.h>
  25. #include <ctype.h>
  26. #include "h.h"
  27.  
  28.  
  29. int    lineno;
  30.  
  31.  
  32. /*
  33.  *    Syntax error handler.  Print message, with line number, and exits.
  34.  */
  35. void
  36. error(msg, a1, a2, a3)
  37. char    *msg;
  38. {
  39.     fprintf(stderr, "%s: ", myname);
  40.     fprintf(stderr, msg, a1, a2, a3);
  41.     if (lineno)
  42.         fprintf(stderr, " near line %d", lineno);
  43.     fputc('\n', stderr);
  44.     exit(1);
  45. }
  46.  
  47.  
  48. /*
  49.  *    Read a line into the supplied string of length LZ.  Remove
  50.  *    comments, ignore blank lines. Deal with quoted (\) #, and
  51.  *    quoted newlines.  If EOF return TRUE.
  52.  */
  53. bool
  54. getline(str, fd)
  55. char    *str;
  56. FILE    *fd;
  57. {
  58.     register char    *p;
  59.     char    *q;
  60.     int    pos = 0;
  61.  
  62.  
  63.     for (; ; ) {
  64.         fgets(str + pos, LZ - pos, fd);
  65.         if (feof(fd))
  66.             return TRUE;                /*  EOF  */
  67.  
  68.         lineno++;
  69.  
  70.         if ((p = strchr(str + pos, '\n')) == (char *)0)
  71.             error("Line too long");
  72.  
  73.         if (p[-1] == '\\') {
  74.             p[-1] = '\n';
  75.             pos = p - str;
  76.             continue;
  77.         }
  78.  
  79.         p = str;
  80.         while (((q = strchr(p, '#')) != (char *)0) && 
  81.             (p != q) && (q[-1] == '\\')) {
  82.             char    *a;
  83.  
  84.             a = q - 1;    /*  Del \ chr; move rest back  */
  85.             p = q;
  86.             while (*a++ = *q++)
  87.                 ;
  88.         }
  89.         if (q != (char *)0) {
  90.             q[0] = '\n';
  91.             q[1] = '\0';
  92.         }
  93.  
  94.         p = str;
  95.         while (isspace(*p))        /*  Checking for blank  */
  96.             p++;
  97.  
  98.         if (*p != '\0')
  99.             return FALSE;
  100.         pos = 0;
  101.     }
  102. }
  103.  
  104.  
  105. /*
  106.  *    Get a word from the current line, surounded by white space.
  107.  *    Return a pointer to it. String returned has no white spaces
  108.  *    in it.
  109.  */
  110. char    *
  111. gettok(ptr)
  112. char    **ptr;
  113. {
  114.     register char    *p;
  115.  
  116.  
  117.     while (isspace(**ptr))        /*  Skip spaces  */
  118.         (*ptr)++;
  119.  
  120.     if (**ptr == '\0')            /*  Nothing after spaces  */
  121.         return NULL;
  122.  
  123.     p = *ptr;                /*  Word starts here  */
  124.  
  125.     while ((**ptr != '\0') && (!isspace(**ptr)))
  126.         (*ptr)++;            /*  Find end of word  */
  127.  
  128.     *(*ptr)++ = '\0';            /*  Terminate it  */
  129.  
  130.     return(p);
  131. }
  132.