Printing Empty Files

2001-10-19
2001-10-19
  • Elizabeth Barham

    Hi!

    I like to print out manuals and other things on both sides of the paper. I print a whole bunch, perhaps 20, on one side, and then I put that in the paper bin and do the other side.

    I've been using Ghostscript with a Epson Stylus Color 740 printer and some of the files turned out to have no content. lpr just skipped over them and so it kind of messed up the plan.

    So, I updated lpr to have a '-b' (don't suppress blank pages / print blanks) which doesn't error out when the file is empty - it just makes a temporary file with a formfeed carriage-return in it and keeps going.

    So, I'm asking that this feature be considered by the developers for possible inclusion in a future release.

    Sincerely,
    Elizabeth

     
    • Elizabeth Barham

      --- lpr.c.orig  Fri Oct 19 15:14:53 2001
      +++ lpr.c       Fri Oct 19 15:33:00 2001
      @@ -101,6 +101,8 @@

      extern char *fenv[];          /* Extra filter options */

      +int     prtempty;               /* print empty file flag */
      +
      uid_t  euid,uid;
      gid_t  egid,gid;

      @@ -112,6 +114,7 @@
      static void card(char c, char *p2);
      static char *linked(char *file);
      static void copy(int f, char *n);
      +static void copy_buf(char* c, long l, char *n);
      static int test(char *file);

      int
      @@ -283,6 +286,10 @@
                              indent = arg[2] ? atoi(&arg[2]) : 8;
                              break;

      +               case 'b':           /* print empty files as blank pages */
      +                 prtempty++;
      +                 break;
      +
                      case '#':               /* n copies */
                              if (isdigit(arg[2])) {
                                      i = atoi(&arg[2]);
      @@ -379,6 +386,12 @@
                      if ((f = test(arg = *++argv)) < 0)
                              continue;       /* file unreasonable */

      +               if(f == 2) { /* Empty File : -b specified */
      +                 snprintf(buf, sizeof(buf), "%s\n", DEFFF);
      +                 copy_buf(buf, strlen(buf), arg);
      +                 continue;
      +               }
      +
                      if (sflag && (cp = linked(arg)) != NULL) {
                              (void) snprintf(buf, sizeof(buf), "%ld %ld",
                                         (long) statb.st_dev, (long) statb.st_ino);
      @@ -488,6 +501,34 @@
      }

      /*
      +  copys buffer c of length l with filename of n
      +  (similar to copy above)
      +*/
      +
      +static void
      +copy_buf(c, l, n)
      +     char *c;
      +     long l;
      +     char n[];
      +{
      +  register int fd, i;
      +
      +  if(format == 'p')
      +    card('T', title ? title : n);
      +  for(i = 0; i < ncopies; i++)
      +    card(format, &dfname[inchar-2]);
      +  card('U', &dfname[inchar-2]);
      +  card('N', n);
      +  fd = nfile(dfname);
      +  if(write(fd, c, l) == -1) {
      +    printf("%s: %s: temp file write error\n", name, n);
      +  }
      +  (void) close(fd);
      +  nact++;
      +}
      +
      +
      +/*
        * Try and link the file to dfname. Return a pointer to the full
        * path name if successful.
        */
      @@ -643,10 +684,14 @@
                      return(-1);
              }
              if (statb.st_size == 0) {
      -               printf("%s: %s is an empty file\n", name, file);
      -               close(fd);
      -               return(-1);
      -       }
      +         if(!prtempty) {
      +           printf("%s: %s is an empty file\n", name, file);
      +           close(fd);
      +           return(-1);
      +         } else {
      +           return(2);
      +         }
      +       }
              (void) close(fd);
              return rflag;
      }

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks