home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * cprint.c - pretty printer for C programs
- *
- * Purpose: 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.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985 Sterling Castle Software
- *
- *******/
-
- #include <stdio.h>
- #include <process.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();
-
- /********
- *
- * pr_shdr(year,sdate,stime) - print header
- *
- **/
-
- void pr_shdr(int year, char *sdate, char *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));
- }
-
-
- /********
- *
- * main() - pretty printer for C programs.
- *
- **/
-
- void main(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("Usage: cprint <-o outfile> file1...filen\n\n");
- printf("<-o outfile> is used to print to a file.\n");
- exit(-1);
- }
- else {
- if (*argv[1] != '-') {
- ofile = "prn";
- 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(-1);
- } 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")) == 0) { /* printer */
- printf("ERROR opening %s \n\r", ofile);
- exit(-1);
- }
- 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")) == 0) {
- 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);
- }
-
-
-