jwg@duke.cs.duke.edu (Jeffrey William Gillette) (03/17/88)
[] Now that I have a LaserJet Series II, I need some excuse to justify its existence. LJP is a small program I wrote to dump out text files in 2 column lineprinter format. Since I haven't noticed a similar program on the net, I am posting LJP, in the hope that someone else might find it useful. LJP runs in PC8 character set, so it should handle all upper ASCII characters. Making "d" the first command line argument puts LJP in a "doubleprint" mode. LJP will print all odd pages, prompt the user to turn the paper stack over, and then print the even pages. LJP prints the even pages in descending order to handle the LJ II collating feature. Thus it is not necessary to shuffle or recollate the printout. ================================ CUT HERE ================================== /* LJP.C Jeffrey William Gillette Durham, NC LJP is a text print utility for the LaserJet Series II printer. It prints files, 2 columns to a landscape page, in the small lineprinter (16.6cpi) font. To reduce further the size of listings, the "d" command line switch can be used to print on both sides of the paper (odd pages first, then even pages). LJP uses the PC8 character set, so all IBM characters ought to print correctly. LJP also observes the LJ II collate sequence in the doubleprint mode, so it is not necessary to shuffle paper in a long print. In both these features, the LJ II differs from the original recepie LaserJet, so LJP will probably need some modifications to work with the earlier printer. Compile LJP with MSC (version 4 or 5). I have placed LJP in the public domain. Use it as you please. */ #include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.h> #define LINES_PER_PAGE 57 #define TRUE 1 #define FALSE !TRUE #define MAX_PAGES 1000 long PageBreak[MAX_PAGES]; int PagePtr = 0; int PageNumber = 0; char FileName[80]; main(argc,argv) int argc; char *argv[]; { long lDate; int DoubleFlag = TRUE; int argCount = 1; int i; FILE *fd; char buf[80], c; if ( !strcmp(argv[1],"d") ) { DoubleFlag = FALSE; argCount++; } /* Set up printer - requires Series II */ fprintf(stdprn,"%c&l1O%c(10U%c(s16.6h0T",27,27,27); fprintf(stdprn,"%c&l68p8D",27); /* Do for each file on command line */ for ( ; argCount < argc; argCount++ ) { /* First open the file */ if ( (fd = fopen(argv[argCount],"r")) == NULL ) { sprintf(buf,"Cannot open file %s ", argv[argCount] ); printf(buf); continue; } /* Copy to FileName */ strcpy(FileName,argv[argCount]); printf("\nPrinting file: %s - ",FileName); /* Do pages until done */ while ( !feof(fd) ) { printf("\b\b\b%3d",PageNumber+1); DoPage(fd,0,TRUE); DoPage(fd,1,TRUE); StampPage(TRUE); printf("\b\b\b%3d",PageNumber+1); PageBreak[PagePtr++] = ftell(fd); DoPage(fd,0,DoubleFlag); DoPage(fd,1,DoubleFlag); StampPage(DoubleFlag); } /* For DoubleFlag, turn paper over and do file again */ if ( !DoubleFlag ) { putchar(6); printf("\n\nFinished side 1, turn paper over for side 2.\n"); printf("Hit Enter key to continue "); do c = getche(); while ( c != '\r' && c != '\r' ); printf("\n\nPrinting file: %s - ",FileName); for ( i = PagePtr -1; i >= 0; i-- ) { PageNumber = 2 * i + 1; printf("\b\b\b%3d",PageNumber+1); if ( PageBreak[i] < 0 ) { fprintf(stdprn,"%c",12); continue; } fseek(fd,PageBreak[i],SEEK_SET); DoPage(fd,0,TRUE); DoPage(fd,1,TRUE); StampPage(TRUE); } } /* Done with file */ fclose(fd); } /* Re-initialize printer */ fprintf(stdprn,"%cE",27); exit(0); } int DoPage(fd,Side,Flag) FILE *fd; int Side, Flag; { int i; char buf[80]; /* Set left margin */ fprintf(stdprn,"%c&a%dL", 27, Side ? 92 : 8 ); fprintf(stdprn,"%c&a0r%dC",27, Side ? 92 : 8 ); for ( i = 0; !feof(fd), i < LINES_PER_PAGE; i++ ) { if ( !fgets(buf, sizeof(buf),fd) ) continue; if ( Flag ) fprintf(stdprn,"%s\r",buf); } return(TRUE); } int StampPage( Flag ) int Flag; { char buf[80],DateBuf[40],TimeBuf[40]; time_t TimePtr; PageNumber++; if ( Flag ) { fprintf(stdprn,"%c9%c&a59r8CFile: %s",27,27,FileName); TimePtr = time(NULL); sprintf(buf,"Page %-3d %8s %8s", PageNumber, _strdate(DateBuf), _strtime(TimeBuf) ); fprintf(stdprn,"%c&a134C%37s",27,buf); fprintf(stdprn,"%c",12); } return(TRUE); } /* That's all */ -- Jeffrey William Gillette uucp: jwg at duke.edu Duke University bitnet: DYBBUK at TUCCVM