home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************
- * PSD (PostScript Display)
- * Copyright 1986, 1987, 1988 MARTECH Consulting Group
- * 3457 Iris Court
- * Boulder, CO 80302
- * (303) 447-0832
- * Distributed free for non-commercial use only.
- *
- * Creates a Postscript file from one or more ASCII input files.
- * Prints in 10 pt. Courier (default) or 8 pt. Times-Bold in either
- * Portrait (default) or Landscape mode.
- * (8 pt. allows a wide report to print in Portrait mode on
- * 8.5 inch paper; Courier evenly spaces all characters to keep
- * columns aligned.)
- * Courier 10 pt. is used because the LaserWriter has it permanently in ROM.
- * With Times-Bold actual print widths vary with character content.
- * Tests with numeric characters produced the following widths
- * on 8.5x11 paper:
- * Times-Bold, 8 pt.; Portrait: 139
- * Times-Bold, 8 pt.; Landscape: 188
- * Courier, 10 pt.; Portrait: 93
- * Courier, 10 pt.; Landscape: 125
- * On 14 inch paper the landscape widths would be about 232 characters
- * for Times-Bold and 154 characters for Courier.
- *
- * This program assumes that input line length does not exceed print width.
- * A PostScript printer will simply truncate anything that doesn't fit.
- *
- * Normally, prints 56 lines per page in Portrait mode
- * or 40 lines per page in Landscape mode (can be changed).
- * Strips all unprintable characters.
- * Tabs are interpreted as five spaces.
- * Formfeed creates a new page, but will not create
- * a blank page.
- *
- * Sample call: psd inputfile inputfile ...
- *
- * With parameters: psd/T/L/F/C/N/nn inputfile ...
- * where:
- * /T indicates Times-Bold,
- * /L indicates Landscape mode,
- * /C is provided for users of Microsoft C;
- * the .LST files are 61 lines per page and contain
- * formfeeds.
- * /F instructs the program to ignore any formfeeds encountered.
- * /N specifies no page numbering; default is to page number.
- *
- * /nn specifies the number of lines per page, e.g. 55,
- * over-riding the defaults. To format under control of
- * formfeeds, specify a number longer than the longest page.
- * No error checking is done and the program assumes all
- * of the lines will fit on each page. In portrait mode,
- * only 60 lines fit, unless you specify the /C option,
- * which changes the default top margin from 1.0 to .5 inches
- * but assumes portrait mode.
- *
- * Parameters may be specified in any sequence; with
- * or without an intervening / (slash), e.g.
- * PSD/L35fn testfile is the same as
- * PSD/L/35/f/n testfile
- * Any other characters are ignored.
- *
- * The PSD environment variable is used to specify the default output.
- * It can be a printer address or a file. Usually it will be the address
- * of a port that is under control of SPOOL, e.g. PSD=LPT1.
- * If output is sent to a file that already exists, the output
- * will be appended.
- *
- *
- ***************************************************************************/
-
- /* NOTE: adapted from LWP, which also provided direct async support, XON/XOFF
- control, etc. The OS/2 SPOOL and MODE provide all of this. However,
- SPOOL does not seem to pass through the EOD from the end-of-the file, so
- some PostScript printers may continue expecting input until they time out.
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdlib.h>
- #include <signal.h>
- #include <time.h>
-
- extern int main(int argc,char * *argv);
- extern int newpage(void );
- extern int openline(int k);
- extern int pagenum(void );
- extern int instruct(void );
-
- #define xputs(s) fputs(s,fp2)
- #define xputc(c) fputc(c,fp2)
-
- /* external variables */
- FILE *fp1,*fp2;
- char timestring[25]="\0";
- int pageno=1,page=0;
- char *infile;
-
- main (argc,argv) /* main starts here */
- int argc;
- char *argv[];
-
- { /* define some variables */
- int ch,k=0;
- int j=1,formfeed=1;
- int lines=55,i=0;
- char *size="10";
- char *s;
- char *font="Courier ";
- char *start="36 720 translate \n";
- char *environ;
- long ltime;
- struct tm *newtime;
-
- /*********** start executing here ***********/
-
- time (<ime); /* set date, time string for page numbering */
- newtime=localtime(<ime);
- strncpy(timestring,asctime(newtime),24);
-
- if (argc < 2) /* check for existence of parm list */
- {
- instruct();
- exit(0);
- }
- environ=getenv("PSD");
- if (environ == NULL)
- {
- environ=getenv("LWP"); /* for compatibility with previous version */
- if (environ == NULL)
- {
- printf("Environment variable PSD not found. Aborting.\n");
- exit(1);
- }
- }
-
- if (strpbrk(argv[j],"/") != NULL) /* Is first parm a modifier? */
- {
- if (strpbrk(argv[j],"Tt")!=NULL) /* Does it contain a 'T' */
- {
- strcpy(font,"Times-Bold"); /* Yes, font is Times-Bold */
- strcpy(size," 8");
- }
- if (strpbrk(argv[j],"Ll")!=NULL) /* Does it contain an 'L' */
- { /* Yes, mode is Landscape */
- lines=39;
- strcpy(start,"540 756 translate -90 rotate\n");
- }
- if (strpbrk(argv[j],"Cc")!=NULL) /* Does it contain a 'C' */
- { /* C.LST file, use 61 lines */
- lines=61;
- strcpy(start,"36 756 translate \n");
- }
- if (strpbrk(argv[j],"Ff")!=NULL) /* F:ignore formfeeds? */
- formfeed=0;
- if (strpbrk(argv[j],"Nn")!=NULL) /* N:don't page number */
- pageno=0;
- s=strpbrk(argv[j],"0123456789"); /* ##:lines per page */
- if (s!=NULL)
- lines=atoi(s); /* note:no error checking! */
- ++j;
- }
-
- /* loop through specified input files */
- while (strlen(argv[j]) > 0)
- {
-
- if ((fp1=fopen(argv[j],"r"))==NULL)
- {printf("Unable to open input %s\n",argv[j++]); continue;}
- else
- infile=argv[j]; /* input file name */
- while (i<strlen(infile)) /* make it uppercase for printing */
- {
- infile[i]=toupper(infile[i]);
- ++i;
- }
- i=0; /* reset i to use again */
-
- if ((fp2=fopen(environ,"a"))==NULL)
- {printf("Unable to open output %s\n",environ);exit(1);}
-
- /* set up PostScript definitions, etc. */
-
- xputs("/ss{0 yline moveto show\n"); /* define show line */
- xputs("/yline yline 12 sub def}def\n"); /* define line spacing */
- xputs("/"); /* define font and size */
- xputs(font);
- xputs(" findfont ");
- xputs(size);
- xputs(" scalefont setfont\n");
- xputs("/yline 0 def\n");
- xputs(start); /* move to top of page */
- xputs("0 0 moveto\n");
- xputs("/savename save def\n"); /* save status */
-
- /* start processing input characters */
-
- while ((ch=fgetc(fp1))!=EOF)
- {
- switch(ch)
- {
- case'\n': /* end-of-line */
- {
- if (k) /* if line open, close it */
- {xputs(")ss\n");k=0;}
- else
- xputs("()ss\n"); /* put blank line */
- if(++i>lines) /* if endpage, show it */
- {
- newpage();
- i=0;
- }
- break;
- }
- case'\050': /* left paren */
- k=openline(k);
- xputs("\\(");
- break;
- case'\051': /* right paren */
- k=openline(k);
- xputs("\\)");
- break;
- case'\t': /* tab */
- k=openline(k);
- xputs(" "); /* five spaces */
- break;
- case'\\': /* back slash */
- k=openline(k);
- xputs("\\\\");
- break;
- case'\014': /* formfeed */
- if (k) /* close open line */
- {xputs(")ss\n");k=0;++i;}
- if (i && formfeed)
- { /* if page open, print it */
- newpage();
- i=0;
- }
- break;
- default: /* all other characters */
- if (isprint(ch)) /* is it printable? */
- /* may want to delete above test to let some special characters through */
- {
- k=openline(k); /* open a line if necessary */
- xputc(ch); /* put the char */
- }
- break;
- }
- }
-
- /* EOF: close up any open lines, pages */
- if (k) /* if line open, close it */
- {xputs(")ss\n");++i;}
- if (i) /* if page open, print it */
- {
- pagenum();
- xputs("showpage\n"); /* and clean up everything on printer */
- }
- else xputs("savename restore\n"); /* otherwise, restore printer */
-
- xputs("\004"); /* end-of-file for insurance */
-
- fclose(fp1); /* clean up and go home */
- fclose(fp2);
-
-
- printf("File: %s %u pages on %s\n",argv[j],page,environ);
- j++;
- page=0;
- }
-
- return(0);
- }
-
- /**************** FUNCTION DEFINITIONS ************************************/
-
- int newpage() /* close page and print it */
- {
- pagenum(); /* add page numbering */
- xputs("copypage erasepage\n");
- xputs("savename restore\n/savename save def\n");
- return(0);
- }
-
- int openline(k) /* if line not open, open it */
- int k;
- {
- if (!k)
- (xputs("("));
- return(1);
- }
-
- int pagenum()
- {
- char pageline[80];
- ++page;
- if (pageno)
- xputs("-90 rotate 200 -15 moveto\n");
- sprintf(pageline,"(%s, Page %u, %s)show\n",infile,page,timestring);
- xputs(pageline);
- return(0);
- }
-
- int instruct()
- {
- printf(" Sample call: PSD inputfile inputfile ...\n");
- printf(" With parameters: PSD/T/L/F/C/N/nn inputfile ...\n");
- printf(" (wildcards are supported for file names)\n");
- printf(" where:\n");
- printf(" /T indicates Times-Bold 8 pt.; default is Courier 10 pt.\n");
- printf(" /L indicates Landscape mode; default is Portrait.,\n");
- printf(" /C is provided for users of Microsoft C;\n");
- printf(" the .LST files are 61 lines per page and contain\n");
- printf(" formfeeds. It also reduces the top margin to 1/2 inch.\n");
- printf(" /F instructs the program to ignore any formfeeds encountered.\n");
- printf(" /N specifies no page numbering; default is to page number.\n");
- printf(" /nn specifies the number of lines per page, e.g. 55,\n");
- printf(" over-riding the defaults of 40 (Landscape) and 56 (Portrait).\n");
- printf(" To format under control of formfeeds in the text,\n");
- printf(" specify a number longer than the longest page.\n");
- printf(" Parameters may be specified in any sequence; with\n");
- printf(" or without an intervening / (slash). Other characters are ignored.\n");
- printf(" The environment variable PSD= must specify the \n");
- printf(" output device or file, usually a port controlled by SPOOL,\n");
- printf(" e.g. PSD=LPT1.\n");
- return(0);
- }
- /************************* END OF PROGRAM LWP *********************************/
-