home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / print / ascii2ps / nenscrib / print.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  1.8 KB  |  82 lines

  1.  
  2. /*
  3.  *   $Id: print.c,v 1.2 1992/10/02 01:02:32 craigs Exp $
  4.  *
  5.  *   This code was written by Craig Southeren whilst under contract
  6.  *   to Computer Sciences of Australia, Systems Engineering Division.
  7.  *   It has been kindly released by CSA into the public domain.
  8.  *
  9.  *   Neither CSA or me guarantee that this source code is fit for anything,
  10.  *   so use it at your peril. I don't even work for CSA any more, so
  11.  *   don't bother them about it. If you have any suggestions or comments
  12.  *   (or money, cheques, free trips =8^) !!!!! ) please contact me
  13.  *   care of geoffw@extro.ucc.oz.au
  14.  *
  15.  */
  16.  
  17. #include "machdep.h"
  18. #include "defs.h"
  19.  
  20. #include "print.h"
  21. #include "postscri.h"
  22. #include "main.h"
  23.  
  24. /********************************
  25.   defines
  26.  ********************************/
  27. #define    PAGEBREAK    ('L' - 0x40)
  28.  
  29.  
  30. /********************************
  31.   print_file
  32.  ********************************/
  33.  
  34. void print_file (input, output, filename, line_numbers)
  35.  
  36. FILE *input;
  37. FILE *output;
  38. char *filename;
  39. int  line_numbers;
  40.  
  41. {
  42.   char line[8192+1];
  43.   int touched = False;
  44.   char *p;
  45.   long line_num;
  46.   char *buffer;
  47.   int  bufflen;
  48.  
  49.   buffer  = line;
  50.   bufflen = 8192;
  51.  
  52.   if (line_numbers) {
  53.     buffer  += 8;
  54.     bufflen -= 8;
  55.     sprintf (line, "%7lu:", line_num = 1);
  56.   }
  57.  
  58.   StartDocument (output, filename);
  59.  
  60.   while (fgets (buffer, bufflen, input) != NULL) {
  61.  
  62.     /* remove the trailing newline from the line */
  63.     buffer [strlen(buffer)-1] = 0;
  64.  
  65.     /* if the line is a page break, then handle it */
  66.     for (p = buffer; *p == ' ' || *p == '\t'; p++)
  67.       ;
  68.     if (*p == PAGEBREAK) {
  69.       if (touched)
  70.         EndColumn (output);
  71.     } else {
  72.       WriteLine (output, line);
  73.       touched = True;
  74.       line_num++;
  75.     }
  76.     if (line_numbers)
  77.       sprintf (line, "%7lu:", line_num);
  78.   }
  79.  
  80.   EndDocument (output);
  81. }
  82.