home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d07xx / d0797.lha / A2ps / a2ps.c < prev    next >
C/C++ Source or Header  |  1993-01-10  |  19KB  |  745 lines

  1. /************************************************************************/
  2. /*                                    */
  3. /* Description: Ascii to PostScript printer program.            */
  4. /* File: imag:/users/local/a2ps/a2ps.c                    */
  5. /* Created: Mon Nov 28 15:22:15 1988 by miguel@imag (Miguel Santana)    */
  6. /* Version: 2.0                                */
  7. /*                                    */
  8. /* Edit history:                            */
  9. /* 1) Derived of shell program written by evan@csli (Evan Kirshenbaum).    */
  10. /*    Written in C for improve speed execution and portability. Many    */
  11. /*    improvements have been added.                    */
  12. /* Fixes by Oscar Nierstrasz @ cui.uucp:                */
  13. /* 2) Fixed incorrect handling of stdin (removed error if no file names)*/
  14. /* 3) Added start_page variable to eliminate blank pages printed for    */
  15. /*    files that are exactly multiples of 132 lines (e.g., man pages)    */
  16. /* Modified by miguel@imag:                        */
  17. /* 4) Added new options at installation : sheet format (height/width in    */
  18. /*    inches), page format (number of columns per line and of lines per    */
  19. /*    page).                                */
  20. /* Modified by miguel@imag:                        */
  21. /* 5) Added new option to print n copies of a same document.        */
  22. /* 6) Cut long filenames if don't fit in the page header.        */
  23. /* Modified by Tim Clark (T.Clark@warwick.ac.uk):            */
  24. /* 7) Two additional modes of printing (portrait and wide format modes)    */
  25. /* 8) Fixed to cope with filenames which contain a character which must    */
  26. /*    be escaped in a PostScript string.                */
  27. /* Modified by miguel@imag.fr to                    */
  28. /* 9) Add new option to suppress heading printing.            */
  29. /* 10) Add new option to suppress page surrounding border printing.    */
  30. /* 11) Add new option to change font size. Number of lines and columns    */
  31. /*     are now automatically adjusted, depending on font size and    */
  32. /*     printing mode used.                        */
  33. /* 12) Minor changes (best layout, usage message, etc).            */
  34. /*                                    */
  35. /************************************************************************/
  36.  
  37. /*
  38.  * Copyright (c) 1988, Miguel Santana, miguel@imag.imag.fr
  39.  *
  40.  * Permission is granted to copy and distribute this file in modified
  41.  * or unmodified form, for noncommercial use, provided (a) this copyright
  42.  * notice is preserved, (b) no attempt is made to restrict redistribution
  43.  * of this file, and (c) this file is not distributed as part of any
  44.  * collection whose redistribution is restricted by a compilation copyright.
  45. */
  46.  
  47.  
  48. #include <stdio.h>
  49. #include <ctype.h>
  50. #include <stdarg.h>
  51. #ifdef ANSIC
  52. #include <sys/types.h>
  53. #include <time.h>
  54. #else
  55. #ifdef BSD
  56. #include <sys/time.h>
  57. #else
  58. #ifdef SYSV
  59. #include <sys/types.h>
  60. #include <sys/timeb.h>
  61. #include <time.h>
  62. #else
  63. #ifdef AMIGA
  64. #include <exec/types.h>
  65. #include <time.h>
  66. #endif
  67. #endif
  68. #endif
  69. #endif
  70.  
  71. #ifndef    HEADER_PS
  72. #define    HEADER_PS    "./header.ps"
  73. #endif
  74.  
  75. #ifndef WIDTH
  76. #define    WIDTH    8.27
  77. #endif
  78.  
  79. #ifndef HEIGHT
  80. #define    HEIGHT    11.64
  81. #endif
  82.  
  83. #ifndef MARGIN
  84. #define    MARGIN    1.2
  85. #endif
  86.  
  87. #ifndef DIR_SEP
  88. #define    DIR_SEP    '/'
  89. #endif
  90.  
  91. #define    PORTRAIT_HEADER        0.29
  92. #define    LANDSCAPE_HEADER    0.22
  93. #define    PIXELS_INCH        72
  94. #define MAXFILENAME        20
  95. #define    FALSE            0
  96. #define    TRUE            1
  97.  
  98. int fold_line();
  99. void print_file();
  100. char cut_line();
  101. int printchar();
  102. void skip_page();
  103.  
  104.  
  105. int column = 0;            /* Column number (in current line) */
  106. int line = 0;            /* Line number (in current page) */
  107. int line_number = 0;        /* Source line number */
  108. int first_page;            /* First page for a file */
  109. int nonprinting_chars, chars;    /* Number of nonprinting and total chars */
  110. int prefix_width;        /* Width in characters for line prefix */
  111. int pages = 0;            /* Number of logical pages printed */
  112. int sheets = 0;            /* Number of physical pages printed */
  113. int linesperpage;        /* Lines per page */
  114. int columnsperline;        /* Characters per output line */
  115.  
  116. double font_size = 0.0;        /* Size of a char for body font */
  117. int numbering = TRUE;        /* Line numbering option */
  118. int folding = TRUE;        /* Line folding option */
  119. int restart = TRUE;        /* Restart page number at each file option */
  120. int only_printable = FALSE;    /* Replace non printable char by space option */
  121. int interpret = TRUE;        /* Interpret TAB, FF and BS chars option */
  122. int print_binaries = FALSE;    /* Force printing for binary files */ 
  123. int copies_number = 1;        /* Number of copies to print */
  124. int landscape = TRUE;        /* Otherwise portrait format sheets */
  125. int wide_pages = FALSE;         /* TRUE implies landscape, not twinpage */
  126. int twinpage = TRUE;        /* 2 pages per sheet if true, 1 otherwise */
  127. int no_border = FALSE;        /* TRUE if user don't want the border */
  128. int no_header = FALSE;        /* TRUE if user don't want the header */
  129. int column_width = 8;            /* default column tab width (8) */
  130.  
  131. main(argc, argv)
  132. int argc;
  133. char *argv[];
  134. {
  135.    register int narg;
  136.    register char *arg;
  137.    double char_width, header_size;
  138.    double page_height, page_width;
  139.    int i;
  140.    extern double atof();
  141.  
  142.    /* Option processing */
  143.    arg = argv[narg = 1];
  144.    while (narg < argc && arg[0] == '-')
  145.    {
  146.       switch (arg[1])
  147.       {
  148.       case '?':                    /* help */
  149.      goto usage;
  150.       case '#':                    /* n copies */
  151.      copies_number = 0;
  152.      arg += 2;
  153.      while (*arg != 0 && isdigit(*arg))
  154.         copies_number = copies_number*10 + (*arg++ - '0');
  155.      if (*arg != 0 || copies_number <= 0)
  156.         goto usage;
  157.      break;
  158.       case 'b':                    /* print binary files */
  159.      if (arg[2] != 0)
  160.         goto usage;
  161.      print_binaries = TRUE;
  162.      break;
  163.       case 'f':                    /* change font size */
  164.      if (arg[2] == 0) {
  165.         folding = TRUE;
  166.         break;
  167.      }
  168.      if ((font_size = atof(&arg[2])) == 0.0) {
  169.         fprintf(stderr, "Wrong value for option -s\n");
  170.         exit(1);
  171.      }
  172.      break;
  173.       case 'h':                    /* help */
  174.      goto usage;
  175.       case 'i':                    /* interpret control chars */
  176.      if (arg[2] != 0)
  177.         goto usage;
  178.      interpret = TRUE;
  179.      break;
  180.       case 'n':                    /* number file lines */
  181.      if (arg[2] == 0)
  182.      {
  183.         numbering = TRUE;
  184.         break;
  185.      }
  186.      if (arg[3] != 0)
  187.         goto usage;
  188.      switch (arg[2])
  189.      {
  190.      case 'b':                /* don't print binaries */
  191.         print_binaries = FALSE;
  192.         break;
  193.      case 'f':                /* cut lines too long */
  194.         folding = FALSE;
  195.         break;
  196.      case 'h':                /* don't print header */
  197.         no_header = TRUE;
  198.         break;
  199.      case 'i':                /* don't interpret ctrl chars */
  200.         interpret = FALSE;
  201.         break;
  202.      case 'n':                /* don't number lines */
  203.         numbering = FALSE;
  204.         break;
  205.      case 'p':                /* landscape format */
  206.         landscape = TRUE;
  207.         break;
  208.      case 'r':                /* don't restart sheet number */
  209.         restart = FALSE;
  210.         break;
  211.      case 's':                /* no surrounding border */
  212.         no_border = TRUE;
  213.         break;
  214.      case 'v':                /* only printable chars */
  215.         only_printable = TRUE;
  216.         break;
  217.      case 'w':                /* twin pages */
  218.         wide_pages = FALSE;
  219.         break;
  220.      default:
  221.         goto usage;
  222.      }
  223.      break;
  224.       case 'p':                    /* portrait format */
  225.      if (arg[2] != 0)
  226.         goto usage;
  227.      if (wide_pages) {
  228.         fprintf(stderr, "a2ps: options -p and -w are incompatible\n");
  229.         exit(1);
  230.      }
  231.      landscape = FALSE;
  232.      break;
  233.       case 'r':                    /* restart sheet number */
  234.      if (arg[2] != 0)
  235.         goto usage;
  236.      restart = TRUE;
  237.      break;
  238.       case 't':                    /* set tab size */
  239.      if (arg[2] == 0 || (column_width = atoi(arg+2)) <= 0)
  240.         goto usage;
  241.      break;
  242.       case 'v':                    /* print control chars */
  243.      if (arg[2] != 0)
  244.         goto usage;
  245.      only_printable = FALSE;
  246.      break;
  247.       case 'w':                    /* wide format */
  248.      if (arg[2] != 0)
  249.         goto usage;
  250.      if (!landscape) {
  251.         fprintf(stderr, "a2ps: options -p and -w are incompatible\n");
  252.         exit(1);
  253.      }
  254.      wide_pages = TRUE;
  255.      break;
  256.       default:
  257.       usage:
  258.      fprintf(stderr,"Usage: %s [options] [f1 f2 ... fn]\n", argv[0]);
  259.      fprintf(stderr,"options = -#num\t(number of copies to print)\n");
  260.      fprintf(stderr,"          -?\t(print this information)\n");
  261.      fprintf(stderr,"          -f\t(fold lines too large)\n");
  262.      fprintf(stderr,"          -fnum\t(font size, num is a float number)\n");
  263.      fprintf(stderr,"          -h\t(print this information)\n");
  264.      fprintf(stderr,"          -i\t(interpret tab, bs and ff chars)\n");
  265.      fprintf(stderr,"          -n\t(number line files)\n");
  266.      fprintf(stderr,"          -p\t(print in portrait mode)\n");
  267.      fprintf(stderr,"          -r\t(restart page number after each file)\n");
  268.      fprintf(stderr,"          -tn\t(set tab size to n)\n");
  269.      fprintf(stderr,"          -v\t(show non-printing chars in a clear form)\n");
  270.      fprintf(stderr,"          -w\t(print in wide format)\n");
  271.      fprintf(stderr,"          -nb\t(don't force printing binary files)\n");
  272.      fprintf(stderr,"          -nf\t(don't fold lines)\n");
  273.      fprintf(stderr,"          -nh\t(don't print the header)\n");
  274.      fprintf(stderr,"          -ni\t(don't interpret special chars)\n");
  275.      fprintf(stderr,"          -nn\t(don't number output lines)\n");
  276.      fprintf(stderr,"          -np\t(don't print in portrait format)\n");
  277.      fprintf(stderr,"          -nr\t(don't restart page number)\n");
  278.      fprintf(stderr,"          -ns\t(don't print surrounding borders)\n");
  279.      fprintf(stderr,"          -nv\t(replace non-printing chars by space)\n");
  280.      fprintf(stderr,"          -nw\t(don't print in wide format)\n");
  281.      exit(1);
  282.       }
  283.       arg = argv[++narg];
  284.    }
  285.    if (arg != 0 && strcmp(arg, "?") == 0)
  286.       goto usage;
  287.  
  288.    twinpage = landscape && !wide_pages;
  289.    if (font_size == 0.0)
  290.       font_size = landscape ? 6.8 : 9.0;
  291.    page_height = (HEIGHT - MARGIN) * PIXELS_INCH;
  292.    page_width = (WIDTH - MARGIN) * PIXELS_INCH;
  293.    char_width = 0.6 * font_size;
  294.    if (landscape) {
  295.       header_size = no_header ? 0.0 : LANDSCAPE_HEADER * PIXELS_INCH;
  296.       linesperpage = ((page_width - header_size) / font_size) - 1;
  297.       if (wide_pages)
  298.      columnsperline = (page_height / char_width) - 1;
  299.       else
  300.      columnsperline = ((page_height / 2) / char_width) - 1;
  301.    }
  302.    else {
  303.       header_size = no_header ? 0.0 : PORTRAIT_HEADER * PIXELS_INCH;
  304.       linesperpage = ((page_height - header_size) / font_size) - 1;
  305.       columnsperline = (page_width / char_width) - 1;
  306.    }
  307.    if (linesperpage <= 0 || columnsperline <= 0) {
  308.       fprintf(stderr, "Font %g too big !!\n", font_size);
  309.       exit(1);
  310.    }
  311.  
  312.    /* Header printing (postcript prolog) */
  313.    print_header();
  314.  
  315.    /* Print files designated or standard input */
  316.    prefix_width = numbering ? 6 : 1;
  317.    if (narg >= argc)
  318.       print_file("stdin");
  319.    else
  320.    {
  321.       while (narg < argc)
  322.       {
  323.      if (freopen(arg, "r", stdin) == 0)
  324.      {
  325.         fprintf(stderr, "Error opening %s\n", arg);
  326.         printf("\n%%%%Trailer\ncleanup\ndocsave restore end\n");
  327.         exit(1);
  328.      }
  329.      print_file(arg);
  330.      arg = argv[++narg];
  331.       }
  332.    }
  333.  
  334.    printf("\n%%%%Trailer\ncleanup\ndocsave restore end\n");
  335. }
  336.  
  337. void print_file(name)
  338. char *name;
  339. {
  340.    register int c;
  341.    int start_line, continue_exit;
  342.    int char_width;
  343.    int start_page;
  344.    char new_name[MAXFILENAME+1];
  345.    char *p;
  346.  
  347.    /*
  348.     * Boolean to indicates that previous char is \n (or interpreted \f)
  349.     * and a new page would be started, if more text follows
  350.     */
  351.    start_page = FALSE;
  352.  
  353.    /*
  354.     * Printing binary files is not very useful. We stop printing
  355.     * if we detect one of these files. Our heuristic to detect them:
  356.     * if 50% characters of first page are non-printing characters,
  357.     * the file is a binary file.
  358.     * Option -b force binary files impression.
  359.     */
  360.    first_page = TRUE;
  361.    nonprinting_chars = chars = 0;
  362.  
  363.    /*
  364.     * Preprocessing (before printing):
  365.     * - TABs expansion (see interpret option)
  366.     * - FF and BS interpretation
  367.     * - replace non printable characters by a space or a char sequence
  368.     *   like:
  369.     *     ^X for ascii codes < 0x20 (X = [@, A, B, ...])
  370.     *     ^? for del char
  371.     *     M-c for ascii codes > 0x3f
  372.     * - prefix parents and backslash ['(', ')', '\'] by backslash
  373.     *   (escape character in postcript)
  374.     */
  375.    column = 0;
  376.    line = line_number = 0;
  377.    start_line = TRUE;
  378.  
  379.    if (strlen(name) > MAXFILENAME) {
  380.       cut_filename(name, new_name);
  381.       name = new_name;
  382.    }
  383.    putchar('(');
  384.    for (p = name; *p != 0;)
  385.       printchar(*p++);
  386.    printf(") newfile\n");
  387.  
  388.    if (restart)
  389.       printf("/sheet 1 def\n");
  390.  
  391.    pages = 0;
  392.    skip_page();
  393.  
  394.    c = getchar();
  395.    while (c != EOF)
  396.    {
  397.       /* Form feed */
  398.       if (c == '\f' && interpret)
  399.       {
  400.      /* Close current line */
  401.      if (!start_line)
  402.      {
  403.         printf(") s\n");
  404.         start_line = TRUE;
  405.      }
  406.      /* start a new page ? */
  407.      if (start_page)
  408.         skip_page();
  409.      /* Close current page and begin another */
  410.      printf("endpage\n") ;
  411.      start_page = TRUE;
  412.      /* Verification for binary files */
  413.      if (first_page && is_binaryfile(name))
  414.         return;
  415.      line = 0;
  416.      if ((c = getchar()) == EOF)
  417.         break;
  418.       }
  419.  
  420.       /* Start a new line? */
  421.       if (start_line)
  422.       {
  423.      if (start_page)
  424.      {     /* only if there is something to print! */
  425.         skip_page();
  426.         start_page = FALSE ;
  427.      }
  428.      if (numbering)
  429.         printf("(%-5d ", ++line_number);
  430.      else
  431.         printf("( ");
  432.      start_line = FALSE;
  433.       }
  434.  
  435.       /* Interpret each character */
  436.       switch (c)
  437.       {
  438.       case '\b':
  439.      if (!interpret)
  440.         goto print;
  441.      if (column)
  442.         column--;
  443.      putchar(c);
  444.      break;
  445.       case '\n':
  446.      column = 0;
  447.      start_line = TRUE;
  448.      printf(") s\n");
  449.      if (++line >= linesperpage)
  450.      {
  451.         printf("endpage\n");
  452.         start_page = TRUE ;
  453.         if (first_page && is_binaryfile(name))
  454.            return;
  455.         line = 0;
  456.      }
  457.      break;
  458.       case '\t':
  459.      if (interpret)
  460.      {
  461.         continue_exit = FALSE;
  462.         do
  463.         {
  464.            if (++column + prefix_width > columnsperline)
  465.           if (folding)
  466.           {
  467.              if (fold_line(name) == FALSE)
  468.             return;
  469.           }
  470.           else
  471.           {
  472.              c = cut_line();
  473.              continue_exit = TRUE;
  474.              break;
  475.           }
  476.            putchar(' ');
  477.         } while (column % column_width);
  478.         if (continue_exit)
  479.            continue;
  480.         break;
  481.         }
  482.       default:
  483.       print:
  484.      if (only_printable)
  485.         char_width = 1;
  486.      else
  487.      {
  488.         char_width = c > 0177 ? 2 : 0;
  489.         char_width += c < ' ' || c == 0177 ? 2 : 1;
  490.      }
  491.      if (prefix_width + (column += char_width) > columnsperline)
  492.         if (folding)
  493.         {
  494.            if (fold_line(name) == FALSE)
  495.           return;
  496.         }
  497.         else
  498.         {
  499.            c = cut_line();
  500.            continue;
  501.         }
  502.      nonprinting_chars += printchar(c);
  503.      chars++;
  504.      break;
  505.       }
  506.       c = getchar();
  507.    }
  508.  
  509.    if (!start_line)
  510.       printf(") s\n");
  511.    if (!start_page)
  512.       printf("endpage\n");
  513. }
  514.  
  515. /*
  516.  * Cut long filenames.
  517.  */
  518. int cut_filename(old_name, new_name)
  519. char *old_name, *new_name;
  520. {
  521.    register char *p;
  522.    register int i;
  523.  
  524.    p = old_name + (strlen(old_name)-1);
  525.    while (p >= old_name && *p != DIR_SEP) p--;
  526.  
  527.    for (i = 0, p++; *p != 0 && i < MAXFILENAME; i++)
  528.       *new_name++ = *p++;
  529.    *new_name = 0;
  530. }
  531.  
  532. /*
  533.  * Fold a line too long.
  534.  */
  535. int fold_line(name)
  536. char *name;
  537. {
  538.    column = 0;
  539.    printf(") s\n");
  540.    if (++line >= linesperpage)
  541.    {
  542.       printf("endpage\n");
  543.       skip_page();
  544.       if (first_page && is_binaryfile(name))
  545.      return FALSE;
  546.       line = 0;
  547.    }
  548.    if (numbering)
  549.       printf("(      ");
  550.    else
  551.       printf("( ");
  552.  
  553.    return TRUE;
  554. }
  555.  
  556. /*
  557.  * Cut a textline too long to the size of a page line.
  558.  */
  559. char cut_line()
  560. {
  561.    char c;
  562.  
  563.    while ((c = getchar()) != EOF && c != '\n' && c != '\f');
  564.    return c;
  565. }
  566.  
  567. /*
  568.  * Print a char in a form accept by postscript printers.
  569.  */
  570. int printchar(c)
  571. unsigned char c;
  572. {
  573.    if (c >= ' ' && c < 0177)
  574.    {
  575.       if (c == '(' || c == ')' || c == '\\')
  576.          putchar('\\');
  577.       putchar(c);
  578.       return 0;
  579.    }
  580.  
  581.    if (only_printable)
  582.    {
  583.       putchar(' ');
  584.       return 1;
  585.    }
  586.  
  587.    if (c > 0177)
  588.    {
  589.       printf("M-");
  590.       c &= 0177;
  591.    }
  592.    if (c < ' ')
  593.    {
  594.       putchar('^');
  595.       if ((c = c + '@') == '(' || c == ')' || c == '\\')
  596.      putchar('\\');
  597.       putchar(c);
  598.    }
  599.    else if (c == 0177)
  600.       printf("^?");
  601.    else
  602.       putchar(c);
  603.  
  604.    return 1;
  605. }
  606.  
  607. /*
  608.  * Begins a new physical page.
  609.  */
  610. void skip_page()
  611. {
  612.    pages++;
  613.    if (twinpage == FALSE || (pages & 0x1))
  614.    {
  615.       sheets++;
  616.       printf("%%%%Page: %d %d\n", sheets, sheets);
  617.    }
  618.    printf("startpage\n");
  619. }
  620.  
  621. /*
  622.  * Test if we have a binary file.
  623.  */
  624. is_binaryfile(name)
  625. char *name;
  626. {
  627.    first_page = FALSE;
  628.    if (!print_binaries && (nonprinting_chars*100 / chars) >= 75)
  629.    {
  630.       fprintf(stderr, "%s is a binary file: printing aborted\n", name);
  631.       return TRUE;
  632.    }
  633.    return FALSE;
  634. }
  635.  
  636. print_header()
  637. {
  638.    register int c;
  639.    FILE *f;
  640.    char *string;
  641. #ifdef ANSIC
  642.    time_t date;
  643. #else
  644. #ifdef AMIGA
  645.    time_t date;
  646. #else
  647. #ifdef BSD
  648.    struct timeval date;
  649.    struct tm *p;
  650. #else
  651. #ifdef SYSV
  652.     struct timeb date;
  653. #endif
  654. #endif
  655. #endif
  656. #endif
  657.  
  658.    if ((f = fopen(HEADER_PS, "r")) == NULL)
  659.    {
  660.       fprintf(stderr, "Postcript header missing\n");
  661.       exit(1);
  662.    }
  663.  
  664.    /* Initialize some postcript variables */
  665.    printf("%%! a2ps 3.0\n\n");
  666.    printf("/$a2psdict 100 dict def\n");
  667.    printf("$a2psdict begin\n");
  668.    printf("%% Initialize page description variables.\n");
  669.    printf("/inch {72 mul} bind def\n");
  670.    printf("/landscape %s def\n", landscape ? "true" : "false");
  671.    printf("/twinpage %s def\n", twinpage ? "true" : "false");
  672.    printf("/sheetheight %g inch def\n", HEIGHT);
  673.    printf("/sheetwidth %g inch def\n", WIDTH);
  674.    printf("/margin %g inch def\n", MARGIN);
  675.    printf("/noborder %s def\n", no_border ? "true" : "false");
  676.    if (no_header) {
  677.       printf("/noheader true def\n");
  678.       printf("/headersize 0.0 def\n");
  679.    }
  680.    else {
  681.       printf("/noheader false def\n");
  682.       printf("/headersize %g inch def\n",
  683.          landscape ? LANDSCAPE_HEADER : PORTRAIT_HEADER);
  684.    }
  685.    printf("/bodyfontsize %g def\n", font_size);
  686.    printf("/lines %d def\n", linesperpage);
  687.    printf("/columns %d def\n", columnsperline);
  688.  
  689.    /* Retrieve date and hour */
  690. #ifdef ANSIC
  691.    if (time(&date) == -1)
  692.    {
  693.       fprintf(stderr, "Error calculing time\n");
  694.       exit(1);
  695.    }
  696.    string = ctime(&date);
  697.  
  698.    /* and print them */
  699.    printf("/date (%.6s %.4s %.8s) def\n", string+4, string+20, string+11);
  700. #else
  701. #ifdef AMIGA
  702.    if (time(&date) == -1)
  703.    {
  704.       fprintf(stderr, "Error calculing time\n");
  705.       exit(1);
  706.    }
  707.    string = ctime(&date);
  708.  
  709.    /* and print them */
  710.    printf("/date (%.6s %.4s %.8s) def\n", string+4, string+20, string+11);
  711. #else
  712. #ifdef BSD
  713.    (void) gettimeofday(&date, (struct timezone *)0);
  714.    p = localtime(&date.tv_sec);
  715.    string = asctime(p);
  716.  
  717.    /* and print them */
  718.    printf("/date (%.6s %.4s %.8s) def\n", string+4, string+20, string+11);
  719. #else
  720. #ifdef SYSV
  721.    (void)ftime(&date);
  722.    string = ctime(&date.time);
  723.    printf("/date (%.6s %.4s %.8s) def\n", string+4, string+20, string+11);
  724. #endif
  725. #endif
  726. #endif
  727. #endif
  728.  
  729.    /* Header file printing */
  730.    while ((c = getc(f)) != EOF)
  731.       putchar(c);
  732.  
  733.  
  734.    /* Close prolog */
  735.    printf("%%%%EndProlog\n\n");
  736.  
  737.    /* Ask for printing n copies */
  738.    if (copies_number > 1)
  739.       printf("/#copies %d def\n", copies_number);
  740.  
  741.    /* Go on */
  742.    printf("/docsave save def\n");
  743.    printf("startdoc\n");
  744. }
  745.