home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
-
- cprint.c -- pretty printer for C programs
-
- Synopsis: This program is used to output C source files to a printer
- or print file. It prints a page header with date,time and copyright,
- as well as line numbers for each file. The format is:
-
- cprint <-o outfile> file1...filen
-
- where <-o outfile> is used to print to a file for spooling.
-
-
- Rev Date by Reason
- ----- -------- --- ------------------------------------
- 0001 04/16/84 jlk Fixed tab for HT on printer
- 0002 01/06/85 jlk Modified for IBM pc
- 0003 04/08/86 jlk Updated for v3.0 compilers
- 0004 05/01/87 jlk added comments, other printers
-
- ************************************************************************/
-
- #include "stdio.h"
- #include "blackstr.h"
- #include "kb_head.h"
- #include "pr_head.h"
- #include "ut_head.h"
-
- #define LPP 60
- #define ERROR -1
- #define PRINTER EPSONRX80
-
- FILE *fpp; /* printer file pointer */
- char *name;
- char sdate[10],stime[8];
- int toprinter,page,line;
- long ut_timel(),ut_datel();
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int i,j,c,st,year;
- long cdate,ctime; /* current date & time */
- FILE *fp,*prn;
- char *ofile; /* output file name (if any)*/
- /************************
- PARSE COMMAND LINE
- ************************/
- if (argc<2)
- {
- printf("Input filename required for numbered print");
- exit();
- } else {
- if (*argv[1] != '-')
- {
- ofile = "prn"; /* output to standard printer */
- st = 1;
- fpp = stdprn;
- } else {
- ofile = argv[2]; /* output to a file */
- st = 3;
- }
- }
- /*************************
- GET DATE AND TIME
- **************************/
- cdate=ut_datel(); /* get current day */
- ctime=ut_timel(); /* and current time */
- if (cdate<840000)
- {
- printf("\n\r System date not set -- Please set ");
- exit();
- } else ut_ldatestr(sdate,cdate); /* date to string */
- year = cdate/10000;
- ut_ltimestr(stime,ctime); /* time to string */
- /****************************
- OPEN OUTPUT FOR PRINTING
- ****************************/
- pr_init(EPSONRX80); /*set printer type */
- if(!(fpp = fopen(ofile,"w"))) /* printer */
- {
- printf("ERROR opening %s \n\r",ofile);
- exit();
- }
- fprintf(fpp,"%s",pr_attr(CONDENS)); /* set columns to 132 on printer */
- fprintf(fpp,"%s",pr_tabs());
- /**************************
- PRINT EACH FILE
- ***************************/
- for (j=st ; j < argc ; j++)
- {
- line = 1;
- page = 1;
- name = argv[j];
- if (!(fp = fopen(argv[j], "r")))
- {
- printf ("error opening file -- %s\n",argv[j]);
- break;
- }
- pr_shdr(year,sdate,stime); /* print page header */
- fprintf (fpp,"%6d ",line);
- while (( c = fgetc(fp)) != EOF)
- {
- if(c != '\f')
- fputc(c,fpp);
- if (c == '\n')
- {
- if ((line % LPP) == 0)
- pr_shdr(year,sdate,stime,toprinter);
- line++;
- fprintf (fpp,"%6d ",line);
- }
- }
- fputc(CR,fpp); /* clear buffer */
- fclose (fp);
- }
- fputc('\f',fpp);
- fclose(fpp);
- exit();
- }
- /***************************
- pr_shdr(year,sdate,stime) print header
- ***************************/
- pr_shdr(year,sdate,stime)
- int year;
- char *sdate,*stime;
- {
- fputc('\f',fpp);
- fprintf(fpp,"\tCopyright (c), 19%2d by Tymon,Inc.",year);
- fprintf (fpp,"\t\t\t\t\t\t ");
- fprintf(fpp,"%s",pr_attr(DWIDE));/* double width printing */
- fprintf(fpp,"%s",pr_attr(BOLD)); /* and bold */
- fprintf(fpp,"%12s\n",name);
- fprintf(fpp,"%s",pr_attr(NODWIDE));
- fprintf(fpp,"%s",pr_attr(NOBOLD));
- fprintf(fpp,"\tDate: %8s",sdate);
- fprintf(fpp," Time: %8s",stime);
- fprintf (fpp,"\t\t\t\t\t\t\t\t\tPage: ");
- fprintf(fpp,"%s",pr_attr(DWIDE));/* double width printing */
- fprintf(fpp,"%s",pr_attr(BOLD)); /* and bold */
- fprintf(fpp,"%3d\n\n\r",page++);
- fprintf(fpp,"%s",pr_attr(NODWIDE));
- fprintf(fpp,"%s",pr_attr(NOBOLD));
- return;
- }
-