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

Diff for /src/usr.bin/fsplit/Attic/fsplit.c between version 1.5 and 1.6

version 1.5, 1999/12/06 00:34:26 version 1.6, 2000/01/30 02:28:37
Line 51 
Line 51 
 #include <stdio.h>  #include <stdio.h>
 #include <unistd.h>  #include <unistd.h>
 #include <string.h>  #include <string.h>
   #include <stdlib.h>
 #include <sys/types.h>  #include <sys/types.h>
 #include <sys/stat.h>  #include <sys/stat.h>
   #include <sys/fcntl.h>
 #include <err.h>  #include <err.h>
   
 void badparms __P(());  void badparms __P(());
Line 96 
Line 98 
   
 #define TRUE 1  #define TRUE 1
 #define FALSE 0  #define FALSE 0
 int     extr = FALSE, extrknt = -1, extrfnd[100];  int     extr = FALSE, extrknt = -1;
 char    extrbuf[1000], *extrnames[100];  int maxextrknt;
   
   int *extrfnd;
   char **extrnames;
 struct stat sbuf;  struct stat sbuf;
   
 #define trim(p) while (*p == ' ' || *p == '\t') p++  #define trim(p) while (*p == ' ' || *p == '\t') p++
Line 111 
Line 116 
         register char *ptr;          register char *ptr;
         int     nflag,          /* 1 if got name of subprog., 0 otherwise */          int     nflag,          /* 1 if got name of subprog., 0 otherwise */
                 retval, i;                  retval, i;
         char    name[20], *extrptr = extrbuf;          /* must be as large as max(sizeof(x), sizeof(mainp), sizeof(blockp)) */
           char    name[20];
   
           maxextrknt = 100;
           extrnames = malloc(sizeof(char *) * maxextrknt);
           if (extrnames == NULL)
                   errx(1, "out of memory");
         /* scan -e options */          /* scan -e options */
         while (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e') {          while (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e') {
                 extr = TRUE;                  extr = TRUE;
Line 125 
Line 135 
                         ptr = argv[1];                          ptr = argv[1];
                 }                  }
                 extrknt = extrknt + 1;                  extrknt = extrknt + 1;
                 extrnames[extrknt] = extrptr;                  if (extrknt >= maxextrknt) {
                 extrfnd[extrknt] = FALSE;                          extrnames = realloc(extrnames,
                 while (*ptr)                              sizeof(char *) * maxextrknt);
                         *extrptr++ = *ptr++;                          if (extrnames == NULL)
                 *extrptr++ = 0;                                  errx(1, "too many -e arguments");
                   }
                   if ((extrnames[extrknt] = strdup(ptr)) == NULL)
                           errx(1, "out of memory");
                 argc--;                  argc--;
                 argv++;                  argv++;
         }          }
   
           extrfnd = calloc(extrknt+1, sizeof(int));
           if (extrfnd == NULL)
                   errx(1, "out of memory");
   
         if (argc > 2)          if (argc > 2)
                 badparms();                  badparms();
         else          else
                 if (argc == 2) {                  if (argc == 2) {
                         if ((ifp = fopen(argv[1], "r")) == NULL)                          if ((ifp = fopen(argv[1], "r")) == NULL)
                                 err(1, argv[1]);                                  err(1, "%s", argv[1]);
                 } else                  } else
                         ifp = stdin;                          ifp = stdin;
         for (;;) {          for (;;) {
                   int fd;
   
                 /* look for a temp file that doesn't correspond to an existing                  /* look for a temp file that doesn't correspond to an existing
                  * file */                   * file */
                 get_name(x, 3);                  get_name(x, 3);
                 ofp = fopen(x, "w");  
                   fd = open(x, O_CREAT|O_EXCL|O_RDWR, 0666);
                   if (fd == -1)
                           err(1, x);
                   ofp = fdopen(fd, "w");
                   if (ofp == NULL) {
                           close(fd);
                           unlink(x);
                           err(1, x);
                   }
                 nflag = 0;                  nflag = 0;
                 rv = 0;                  rv = 0;
                 while (getline() > 0) {                  while (getline() > 0) {
Line 196 
Line 224 
 void  void
 badparms()  badparms()
 {  {
         err(1, "usage:  fsplit [-e efile] ... [file]");          fprintf(stderr, "usage:  fsplit [-e efile] ... [file]\n");
           exit(1);
 }  }
   
 int  int
Line 204 
Line 233 
         char   *name;          char   *name;
 {  {
         int     i;          int     i;
         char    fname[50], *fptr = fname;          size_t  n;
   
         if (!extr)          if (!extr)
                 return (1);                  return (1);
         while (*name)  
                 *fptr++ = *name++;          n = strlen(name);
         *--fptr = 0;          if (n < 2)
         *--fptr = 0;                  return (0);
   
         for (i = 0; i <= extrknt; i++)          for (i = 0; i <= extrknt; i++)
                 if (strcmp(fname, extrnames[i]) == 0) {                  if (strncmp(name, extrnames[i], n - 2) == 0 &&
                   extrnames[i][n-2] == '\0') {
                         extrfnd[i] = TRUE;                          extrfnd[i] = TRUE;
                         return (1);                          return (1);
                 }                  }
Line 312 
Line 343 
         /* copy to buffer and converting to lower case */          /* copy to buffer and converting to lower case */
         p = ptr;          p = ptr;
         while (*p && p <= &buf[71]) {          while (*p && p <= &buf[71]) {
                 *iptr = isupper(*p) ? tolower(*p) : *p;                  *iptr = tolower(*p);
                 iptr++;                  iptr++;
                 p++;                  p++;
         }          }

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