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

Diff for /src/usr.bin/sendbug/sendbug.c between version 1.53 and 1.54

version 1.53, 2008/01/03 03:19:36 version 1.54, 2008/01/04 00:50:09
Line 425 
Line 425 
 send_file(const char *file, int dst)  send_file(const char *file, int dst)
 {  {
         size_t len;          size_t len;
         char *buf;          char *buf, *lbuf;
         FILE *fp;          FILE *fp;
         int blank = 0, dmesg_line = 0;          int rval = -1, saved_errno;
   
         if ((fp = fopen(file, "r")) == NULL)          if ((fp = fopen(file, "r")) == NULL)
                 return (-1);                  return (-1);
           lbuf = NULL;
         while ((buf = fgetln(fp, &len))) {          while ((buf = fgetln(fp, &len))) {
                   if (buf[len - 1] == '\n')
                           buf[len - 1] = '\0';
                   else {
                           /* EOF without EOL, copy and add the NUL */
                           if ((lbuf = malloc(len + 1)) == NULL)
                                   goto end;
                           memcpy(lbuf, buf, len);
                           lbuf[len] = '\0';
                           buf = lbuf;
                   }
   
                 /* Skip lines starting with "SENDBUG". */                  /* Skip lines starting with "SENDBUG". */
                 if (len >= sizeof("SENDBUG") - 1 &&                  if (strncmp(buf, "SENDBUG", sizeof("SENDBUG") - 1) == 0)
                     memcmp(buf, "SENDBUG", sizeof("SENDBUG") - 1) == 0)  
                         continue;                          continue;
                 /* Are we done with the headers? */  
                 if (!blank && len == 1 && buf[0] == '\n')  
                         blank = 1;  
                 /* Have we reached the dmesg? */  
                 if (blank && !dmesg_line &&  
                     len >= sizeof(DMESG_START) - 1 &&  
                     memcmp(buf, DMESG_START, sizeof(DMESG_START) - 1) == 0)  
                         dmesg_line = 1;  
                 /* Skip comments between headers and dmesg. */  
                 while (len) {                  while (len) {
                         char *sp = NULL, *ep = NULL;                          char *sp = NULL, *ep = NULL;
                         size_t copylen;                          size_t copylen;
   
                         if (blank && !dmesg_line &&                          if ((sp = strchr(buf, '<')) != NULL) {
                             (sp = memchr(buf, '<', len)) != NULL)                                  size_t i;
                                 ep = memchr(sp, '>', len - (sp - buf + 1));  
                                   for (i = 0; i < sizeof(comment) / sizeof(*comment); ++i) {
                                           size_t commentlen = strlen(comment[i]);
   
                                           if (strncmp(sp, comment[i], commentlen) == 0) {
                                                   ep = sp + commentlen - 1;
                                                   break;
                                           }
                                   }
                           }
                         /* Length of string before comment. */                          /* Length of string before comment. */
                         if (ep)                          if (ep)
                                 copylen = sp - buf;                                  copylen = sp - buf;
                         else                          else
                                 copylen = len;                                  copylen = len;
                         if (atomicio(vwrite, dst, buf, copylen) != copylen) {                          if (atomicio(vwrite, dst, buf, copylen) != copylen ||
                                 int saved_errno = errno;                              atomicio(vwrite, dst, "\n", 1) != 1)
                                   goto end;
                                 fclose(fp);  
                                 errno = saved_errno;  
                                 return (-1);  
                         }  
                         if (!ep)                          if (!ep)
                                 break;                                  break;
                         /* Skip comment. */                          /* Skip comment. */
Line 471 
Line 478 
                         buf = ep + 1;                          buf = ep + 1;
                 }                  }
         }          }
           rval = 0;
    end:
           saved_errno = errno;
           free(lbuf);
         fclose(fp);          fclose(fp);
         return (0);          errno = saved_errno;
           return (rval);
 }  }
   
 /*  /*
Line 550 
Line 562 
 {  {
         fprintf(fp, "SENDBUG: -*- sendbug -*-\n");          fprintf(fp, "SENDBUG: -*- sendbug -*-\n");
         fprintf(fp, "SENDBUG: Lines starting with `SENDBUG' will"          fprintf(fp, "SENDBUG: Lines starting with `SENDBUG' will"
             " be removed automatically, as\n");              " be removed automatically.\n");
         fprintf(fp, "SENDBUG: will all comments (text enclosed in `<' and `>').\n");  
         fprintf(fp, "SENDBUG:\n");          fprintf(fp, "SENDBUG:\n");
         fprintf(fp, "SENDBUG: Choose from the following categories:\n");          fprintf(fp, "SENDBUG: Choose from the following categories:\n");
         fprintf(fp, "SENDBUG:\n");          fprintf(fp, "SENDBUG:\n");

Legend:
Removed from v.1.53  
changed lines
  Added in v.1.54