home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1995 October / Simtel-MSDOS-Oct1995-CD1.iso / disc1 / printer / page.c < prev    next >
C/C++ Source or Header  |  1984-07-06  |  2KB  |  74 lines

  1.  
  2. #include <stdio.h>
  3.  
  4. #define pagelen 60
  5. #define tabsize 8
  6.  
  7. /* page: print out files, converting tabs to spaces and inserting a f.f. */
  8. /*       every 66 lines.  Submitted by Ron Kuper, Millar Elevator Ind., NYC */
  9.  
  10. main(argc,argv)
  11. int argc;
  12. char *argv[];
  13.  
  14.         int i, line;
  15.         FILE *infile, *fopen();
  16.         char inbuf[133], *retn, *fgets();
  17.  
  18.         if (argc==1)
  19.                 fputs("Usage: PAGE file1 file2 ...",stderr);
  20.                 exit(0);
  21.  
  22.  
  23.         for (i=1; i<argc; i++)
  24.                 infile = fopen (argv[i],"r");
  25.                 if (infile==NULL)
  26.                         fprintf(stderr,"page: skipping file ");
  27.                         fputs(argv[i],stderr);
  28.  
  29.                 else
  30.                         putc('\014',stdout);            /* send inital ff */
  31.                         line = 0;
  32.                         do
  33.                                 retn=fgets(inbuf,256,infile);
  34.                                 if (retn==NULL)
  35.                                         putc('\014',stdout);
  36.                                 else
  37.                                         outline(inbuf);
  38.                                 line++;
  39.                                 if (line==pagelen)
  40.                                         line = 0;
  41.                                         putc('\014',stdout);
  42.  
  43.                           while (retn!=NULL);
  44.                         fclose(infile);
  45.  
  46.  
  47.  
  48.  
  49. outline(txt)
  50. char *txt;
  51.         register int i,j,col;
  52.  
  53.         col = 0;
  54.         for (i=0; txt[i]!='\0'; i++)
  55.                 if (txt[i]!='\t')
  56.                         putc(txt[i],stdout);
  57.                         col++;
  58.  
  59.                 else
  60.                         j = col % tabsize;
  61.                         if (j!=tabsize)
  62.                                 j = tabsize - j;
  63.                         col += j;
  64.                          while (j>0)
  65.                                 putc(' ',stdout);
  66.                                 j--;
  67.  
  68.  
  69.  
  70.  
  71.  
  72. ------
  73.  
  74.