[BACK]Return to misc.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / m4

Diff for /src/usr.bin/m4/misc.c between version 1.6 and 1.7

version 1.6, 1997/12/10 20:24:17 version 1.7, 1999/09/06 13:10:49
Line 50 
Line 50 
 #include <unistd.h>  #include <unistd.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
   #include <stddef.h>
 #include <string.h>  #include <string.h>
   #include <err.h>
 #include "mdef.h"  #include "mdef.h"
 #include "stdd.h"  #include "stdd.h"
 #include "extern.h"  #include "extern.h"
Line 59 
Line 61 
 /*  /*
  * find the index of second str in the first str.   * find the index of second str in the first str.
  */   */
 int  ptrdiff_t
 indx(s1, s2)  indx(s1, s2)
 char *s1;  const char *s1;
 char *s2;  const char *s2;
 {  {
         register char *t;          char *r;
         register char *p;  
         register char *m;  
   
         for (p = s1; *p; p++) {          r = strstr(s1, s2);
                 for (t = p, m = s2; *m && *m == *t; m++, t++);          if (r)
                 if (!*m)                  return (r - s1);
                         return (p - s1);          else
         }                  return (-1);
         return (-1);  
 }  }
 /*  /*
  *  putback - push character back onto input   *  putback - push character back onto input
Line 85 
Line 84 
         if (bp < endpbb)          if (bp < endpbb)
                 *bp++ = c;                  *bp++ = c;
         else          else
                 oops("too many characters pushed back");                  errx(1, "too many characters pushed back");
 }  }
   
 /*  /*
Line 110 
Line 109 
                 if (zp < endpbb)                  if (zp < endpbb)
                         *zp++ = *es--;                          *zp++ = *es--;
         if ((bp = zp) == endpbb)          if ((bp = zp) == endpbb)
                 oops("too many characters pushed back");                  errx(1, "too many characters pushed back");
 }  }
   
 /*  /*
Line 142 
Line 141 
         if (ep < endest)          if (ep < endest)
                 *ep++ = c;                  *ep++ = c;
         else          else
                 oops("string space overflow");                  errx(1, "string space overflow");
 }  }
   
 /*  /*
Line 156 
Line 155 
         register FILE *dfil;          register FILE *dfil;
   
         if (active == outfile[n])          if (active == outfile[n])
                 oops("%s: diversion still active.", "undivert");                  errx(1, "undivert: diversion still active");
         (void) fclose(outfile[n]);          (void) fclose(outfile[n]);
         outfile[n] = NULL;          outfile[n] = NULL;
         m4temp[UNIQUE] = n + '0';          m4temp[UNIQUE] = n + '0';
         if ((dfil = fopen(m4temp, "r")) == NULL)          if ((dfil = fopen(m4temp, "r")) == NULL)
                 oops("%s: cannot undivert.", m4temp);                  err(1, "%s: cannot undivert", m4temp);
         else          else
                 while ((c = getc(dfil)) != EOF)                  while ((c = getc(dfil)) != EOF)
                         putc(c, active);                          putc(c, active);
Line 172 
Line 171 
 #else  #else
         if (unlink(m4temp) == -1)          if (unlink(m4temp) == -1)
 #endif  #endif
                 oops("%s: cannot unlink.", m4temp);                  err(1, "%s: cannot unlink", m4temp);
 }  }
   
 void  void
 onintr(signo)  onintr(signo)
         int signo;          int signo;
 {  {
         oops("interrupted.");          errx(1, "interrupted.");
 }  }
   
 /*  /*
Line 209 
Line 208 
         register char *p = malloc(n);          register char *p = malloc(n);
   
         if (p == NULL)          if (p == NULL)
                 oops("malloc: %s", strerror(errno));                  err(1, "malloc");
         return p;          return p;
 }  }
   
Line 219 
Line 218 
 {  {
         register char *p = strdup(s);          register char *p = strdup(s);
         if (p == NULL)          if (p == NULL)
                 oops("strdup: %s", strerror(errno));                  err(1, "strdup");
         return p;          return p;
 }  }
   
 char *  
 basename(s)  
 register char *s;  
 {  
         register char *p;  
         extern char *strrchr();  
   
         if ((p = strrchr(s, '/')) == NULL)  
                 return s;  
   
         return ++p;  
 }  
   
 void  void
 usage()  usage()
 {  {
Line 243 
Line 229 
         exit(1);          exit(1);
 }  }
   
 #ifdef __STDC__  
 #include <stdarg.h>  
 #else  
 #include <varargs.h>  
 #endif  
   
 void  
 #ifdef __STDC__  
 oops(const char *fmt, ...)  
 #else  
 oops(fmt, va_alist)  
         char *fmt;  
         va_dcl  
 #endif  
 {  
         va_list ap;  
 #ifdef __STDC__  
         va_start(ap, fmt);  
 #else  
         va_start(ap);  
 #endif  
         (void)fprintf(stderr, "%s: ", progname);  
         (void)vfprintf(stderr, fmt, ap);  
         va_end(ap);  
         (void)fprintf(stderr, "\n");  
         exit(1);  
         /* NOTREACHED */  
 }  

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7