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

Diff for /src/usr.bin/hexdump/parse.c between version 1.14 and 1.15

version 1.14, 2004/11/21 19:57:16 version 1.15, 2006/08/23 03:13:09
Line 53 
Line 53 
 void  void
 addfile(char *name)  addfile(char *name)
 {  {
         char *p;  
         FILE *fp;          FILE *fp;
         int ch;          size_t len;
         char buf[2048 + 1];          char *buf, *lbuf, *p;
   
         if ((fp = fopen(name, "r")) == NULL)          if ((fp = fopen(name, "r")) == NULL)
                 err(1, "fopen %s", name);                  err(1, "fopen %s", name);
         while (fgets(buf, sizeof(buf), fp)) {  
                 if (!(p = strchr(buf, '\n'))) {          lbuf = NULL;
                         warnx("line too long.");          while ((buf = fgetln(fp, &len))) {
                         while ((ch = getchar()) != '\n' && ch != EOF);                  if (buf[len - 1] == '\n')
                         continue;                          buf[len - 1] = '\0';
                   else {
                           /* EOF without EOL, copy and add the NUL */
                           if ((lbuf = malloc(len + 1)) == NULL)
                                   err(1, NULL);
                           memcpy(lbuf, buf, len);
                           lbuf[len] = '\0';
                           buf = lbuf;
                 }                  }
                 *p = '\0';  
                 for (p = buf; *p && isspace((unsigned char)*p); ++p);                  for (p = buf; *p && isspace((unsigned char)*p); ++p);
                 if (!*p || *p == '#')                  if (!*p || *p == '#')
                         continue;                          continue;
                 add(p);                  add(p);
         }          }
           free(lbuf);
         (void)fclose(fp);          (void)fclose(fp);
 }  }
   

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15