reader.c

Go to the documentation of this file.
00001 /*************************************************************************
00002  *
00003  *  m a k e :   r e a d e r . c
00004  *
00005  *  Read in makefile
00006  *========================================================================
00007  * Edition history
00008  *
00009  *  #    Date                         Comments                       By
00010  * --- -------- ---------------------------------------------------- ---
00011  *   1    ??                                                         ??
00012  *   2 23.08.89 cast to NULL added                                   RAL
00013  *   3 30.08.89 indention changed                                    PSH,RAL
00014  *   4 03.09.89 fixed LZ eliminated                                  RAL
00015  * ------------ Version 2.0 released ------------------------------- RAL
00016  *
00017  *************************************************************************/
00018 
00019 #include "h.h"
00020 
00021 
00022 /*
00023  *      Syntax error handler.  Print message, with line number, and exits.
00024  */
00025 void error(msg, a1)
00026 char *msg;
00027 char *a1;
00028 {
00029   fprintf(stderr, "%s: ", myname);
00030   fprintf(stderr, msg, a1);
00031   if (lineno)  fprintf(stderr, " in %s near line %d", makefile, lineno);
00032   fputc('\n', stderr);
00033   exit(1);
00034 }
00035 
00036 
00037 /*
00038  *      Read a line into the supplied string.  Remove
00039  *      comments, ignore blank lines. Deal with quoted (\) #, and
00040  *      quoted newlines.  If EOF return TRUE.
00041  *
00042  *      The comment handling code has been changed to leave comments and
00043  *      backslashes alone in shell commands (lines starting with a tab).
00044  *      This is not what POSIX wants, but what all makes do.  (KJB)
00045  */
00046 bool getline(strs, fd)
00047 struct str *strs;
00048 FILE *fd;
00049 {
00050   register char *p;
00051   char          *q;
00052   int            c;
00053 
00054   for (;;) {
00055         strs->pos = 0;
00056         for (;;) {
00057                 do {
00058                         if (strs->pos >= strs->len)
00059                                 strrealloc(strs);
00060                         if ((c = getc(fd)) == EOF)
00061                                 return TRUE;            /* EOF */
00062                         (*strs->ptr)[strs->pos++] = c;
00063                 } while (c != '\n');
00064 
00065                 lineno++;
00066 
00067                 if (strs->pos >= 2 && (*strs->ptr)[strs->pos - 2] == '\\') {
00068                         (*strs->ptr)[strs->pos - 2] = '\n';
00069                         strs->pos--;
00070                 } else {
00071                         break;
00072                 }
00073         }
00074 
00075         if (strs->pos >= strs->len)
00076                 strrealloc(strs);
00077         (*strs->ptr)[strs->pos] = '\0';
00078 
00079         p = q =  *strs->ptr;
00080         while (isspace(*q)) q++;
00081         if (*p != '\t' || *q == '#') {
00082                 while (((q = strchr(p, '#')) != (char *)0) &&
00083                     (p != q) && (q[-1] == '\\'))
00084                 {
00085                         char    *a;
00086 
00087                         a = q - 1;      /*  Del \ chr; move rest back  */
00088                         p = q;
00089                         while (*a++ = *q++)
00090                                 ;
00091                 }
00092                 if (q != (char *)0)
00093                         {
00094                         q[0] = '\n';
00095                         q[1] = '\0';
00096                 }
00097         }
00098 
00099         p = *strs->ptr;
00100         while (isspace(*p))     /*  Checking for blank  */
00101                 p++;
00102 
00103         if (*p != '\0')
00104                 return FALSE;
00105   }
00106 }
00107 
00108 
00109 /*
00110  *      Get a word from the current line, surounded by white space.
00111  *      return a pointer to it. String returned has no white spaces
00112  *      in it.
00113  */
00114 char  *gettok(ptr)
00115 register char **ptr;
00116 {
00117   register char *p;
00118 
00119 
00120   while (isspace(**ptr))        /*  Skip spaces  */
00121         (*ptr)++;
00122 
00123   if (**ptr == '\0')    /*  Nothing after spaces  */
00124         return ((char *)NULL);
00125 
00126   p = *ptr;             /*  word starts here  */
00127 
00128   while ((**ptr != '\0') && (!isspace(**ptr)))
00129         (*ptr)++;       /*  Find end of word  */
00130 
00131   *(*ptr)++ = '\0';     /*  Terminate it  */
00132 
00133   return(p);
00134 }

Generated on Fri Apr 14 22:56:45 2006 for minix by  doxygen 1.4.6