home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / UTILS / CPRINT.C next >
Encoding:
C/C++ Source or Header  |  1990-05-24  |  4.0 KB  |  150 lines

  1. /*********************
  2.  *
  3.  *  cprint.c - pretty printer for C programs
  4.  *
  5.  *  Purpose:  This program is used to output C source files to a printer
  6.  *            or print file. It prints a page header with date,time and
  7.  *            copyright, as well as line numbers for each file.
  8.  *            The format is:
  9.  *
  10.  *                     cprint <-o outfile> file1...filen
  11.  *
  12.  *            where <-o outfile> is used to print to a file for spooling.
  13.  *
  14.  *  Blackstar C Function Library
  15.  *  (c) Copyright 1985 Sterling Castle Software
  16.  *
  17.  *******/
  18.                                                                                             
  19. #include <stdio.h>
  20. #include <process.h>
  21. #include "blackstr.h"
  22. #include "kb_head.h"
  23. #include "pr_head.h"
  24. #include "ut_head.h"
  25.  
  26. #define LPP 60
  27. #define ERROR -1
  28. #define PRINTER EPSONRX80
  29.  
  30. FILE     *fpp;        /* printer file pointer */
  31. char    *name;
  32. char    sdate[10],stime[8];
  33. int    toprinter,page,line;
  34. long    ut_timel(),ut_datel();
  35.  
  36. /********
  37.  *
  38.  *   pr_shdr(year,sdate,stime) - print header
  39.  *
  40.  **/
  41.  
  42. void pr_shdr(int year, char *sdate, char *stime)
  43. {
  44.     fputc('\f',fpp);
  45.     fprintf(fpp,"\tCopyright (c), 19%2d by Tymon,Inc.",year);
  46.     fprintf (fpp,"\t\t\t\t\t\t    ");
  47.     fprintf(fpp,"%s",pr_attr(DWIDE));        /* double width printing */
  48.     fprintf(fpp,"%s",pr_attr(BOLD));        /* and bold */
  49.     fprintf(fpp,"%12s\n",name);
  50.     fprintf(fpp,"%s",pr_attr(NODWIDE));
  51.     fprintf(fpp,"%s",pr_attr(NOBOLD));
  52.     fprintf(fpp,"\tDate: %8s",sdate);
  53.     fprintf(fpp,"  Time: %8s",stime);
  54.     fprintf (fpp,"\t\t\t\t\t\t\t\t\tPage: ");
  55.     fprintf(fpp,"%s",pr_attr(DWIDE));        /* double width printing */
  56.     fprintf(fpp,"%s",pr_attr(BOLD));        /* and bold */
  57.     fprintf(fpp,"%3d\n\n\r",page++);
  58.     fprintf(fpp,"%s",pr_attr(NODWIDE));
  59.     fprintf(fpp,"%s",pr_attr(NOBOLD));
  60. }
  61.  
  62.  
  63. /********
  64.  *
  65.  *   main() - pretty printer for C programs.
  66.  *
  67.  **/
  68.  
  69. void main(int argc, char *argv[])
  70. {
  71.     int     i,j,c,st,year;
  72.     long    cdate,ctime;    /* current date & time */
  73.     FILE    *fp,*prn;
  74.     char    *ofile;         /* output file name (if any)*/
  75.  
  76.     /************************
  77.      PARSE COMMAND LINE
  78.     ************************/
  79.     if (argc<2) {
  80.     printf("Usage: cprint <-o outfile> file1...filen\n\n");
  81.     printf("<-o outfile> is used to print to a file.\n");
  82.     exit(-1);
  83.     }
  84.     else {
  85.     if (*argv[1] != '-') {
  86.         ofile = "prn";      
  87.         st = 1;
  88.         fpp = stdprn;
  89.     } else {
  90.         ofile = argv[2];    /* output to a file */
  91.         st = 3;
  92.     }
  93.     }
  94.  
  95.     /*************************
  96.      GET DATE AND TIME
  97.     **************************/
  98.     cdate=ut_datel();                                                               /* get current day */
  99.     ctime=ut_timel();                                                               /* and current time */
  100.     if (cdate<840000) {
  101.     printf("\n\r System date not set -- Please set ");
  102.     exit(-1);
  103.     } else
  104.     ut_ldatestr(sdate,cdate);       /* date to string */
  105.     year = cdate/10000;
  106.     ut_ltimestr(stime,ctime);           /* time to string */
  107.  
  108.     /****************************
  109.      OPEN OUTPUT FOR PRINTING
  110.     ****************************/
  111.     pr_init(EPSONRX80);                     /* set printer type */
  112.     if((fpp = fopen(ofile,"w")) == 0) {     /* printer */
  113.     printf("ERROR opening %s \n\r", ofile);
  114.     exit(-1);
  115.     }
  116.     fprintf(fpp,"%s",pr_attr(CONDENS)); /* set columns to 132 on printer */
  117.     fprintf(fpp,"%s",pr_tabs());
  118.  
  119.     /**************************
  120.      PRINT EACH FILE
  121.     ***************************/
  122.     for (j=st ; j < argc ; j++) {
  123.     line = 1;
  124.     page = 1;
  125.     name = argv[j];
  126.     if ((fp = fopen(argv[j], "r")) == 0) {
  127.         printf ("error opening file -- %s\n",argv[j]);
  128.         break;
  129.     }
  130.     pr_shdr(year,sdate,stime);      /* print page header */
  131.     fprintf (fpp,"%6d  ",line);
  132.     while (( c = fgetc(fp)) != EOF) {
  133.         if(c != '\f')
  134.         fputc(c,fpp);
  135.         if (c == '\n') {
  136.         if ((line % LPP) == 0)
  137.             pr_shdr(year,sdate,stime); /*,toprinter); */
  138.         line++;
  139.         fprintf (fpp,"%6d  ",line);
  140.         }
  141.     }
  142.     fputc(CR,fpp);  /* clear buffer */
  143.     fclose (fp);
  144.     }
  145.     fputc('\f',fpp);
  146.     fclose(fpp);
  147. }
  148.  
  149.  
  150.