[BACK]Return to main.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/main.c between version 1.256 and 1.257

version 1.256, 2015/11/07 14:22:29 version 1.257, 2015/11/07 17:58:55
Line 774  passthrough(const char *file, int fd, int synopsis_onl
Line 774  passthrough(const char *file, int fd, int synopsis_onl
   
         FILE            *stream;          FILE            *stream;
         const char      *syscall;          const char      *syscall;
         char            *line;          char            *line, *cp;
         size_t           len, off;          size_t           linesz;
         ssize_t          nw;  
         int              print;          int              print;
   
         fflush(stdout);          line = NULL;
           linesz = 0;
   
         if ((stream = fdopen(fd, "r")) == NULL) {          if ((stream = fdopen(fd, "r")) == NULL) {
                 close(fd);                  close(fd);
Line 788  passthrough(const char *file, int fd, int synopsis_onl
Line 788  passthrough(const char *file, int fd, int synopsis_onl
         }          }
   
         print = 0;          print = 0;
         while ((line = fgetln(stream, &len)) != NULL) {          while (getline(&line, &linesz, stream) != -1) {
                   cp = line;
                 if (synopsis_only) {                  if (synopsis_only) {
                         if (print) {                          if (print) {
                                 if ( ! isspace((unsigned char)*line))                                  if ( ! isspace((unsigned char)*cp))
                                         goto done;                                          goto done;
                                 while (len &&                                  while (isspace((unsigned char)*cp))
                                     isspace((unsigned char)*line)) {                                          cp++;
                                         line++;  
                                         len--;  
                                 }  
                         } else {                          } else {
                                 if ((len == sizeof(synb) &&                                  if (strcmp(cp, synb) == 0 ||
                                      ! strncmp(line, synb, len - 1)) ||                                      strcmp(cp, synr) == 0)
                                     (len == sizeof(synr) &&  
                                      ! strncmp(line, synr, len - 1)))  
                                         print = 1;                                          print = 1;
                                 continue;                                  continue;
                         }                          }
                 }                  }
                 for (off = 0; off < len; off += nw)                  if (fputs(cp, stdout)) {
                         if ((nw = write(STDOUT_FILENO, line + off,                          fclose(stream);
                             len - off)) == -1 || nw == 0) {                          syscall = "fputs";
                                 fclose(stream);                          goto fail;
                                 syscall = "write";                  }
                                 goto fail;  
                         }  
         }          }
   
         if (ferror(stream)) {          if (ferror(stream)) {
                 fclose(stream);                  fclose(stream);
                 syscall = "fgetln";                  syscall = "getline";
                 goto fail;                  goto fail;
         }          }
   
 done:  done:
           free(line);
         fclose(stream);          fclose(stream);
         return;          return;
   
 fail:  fail:
           free(line);
         warn("%s: SYSERR: %s", file, syscall);          warn("%s: SYSERR: %s", file, syscall);
         if (rc < MANDOCLEVEL_SYSERR)          if (rc < MANDOCLEVEL_SYSERR)
                 rc = MANDOCLEVEL_SYSERR;                  rc = MANDOCLEVEL_SYSERR;

Legend:
Removed from v.1.256  
changed lines
  Added in v.1.257

CVSweb