home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
ddjmag
/
ddj8605.arc
/
LETTERS.MAY
< prev
next >
Wrap
Text File
|
1986-05-31
|
4KB
|
171 lines
/**
**
** LJ.C -- A printing utility for the HP LaserJet
**
** This program prints a series of files on the LaserJet
** printer. The files are printed in a ``landscape'' font at
** 17 characters to the inch. To take advantage of this
** density, two ``pages'' of information from the file are
** printed on each piece of paper (left and right halves).
**
** Usage is: LJ file1 file2 file3 ...
**
** Where file# is a valid MS-DOS filename, included on the
** command line. This program is compatible with Lattice C
** on the IBM PC and the HP Touchscreen computers.
**
** Joe Barnhart original version May 5, 1985
** Ray Duncan date and time stamping May 22, 1985
** Joe Barnhart revised date stamping June 6, 1985
** Ray Moon modified for CI86 December 13, 1985
** & revised EOF test
**
**/
#define CI86 1 /* Remove this #define => Lattice C version */
#ifdef CI86
#include <stdio.h>
#else
#include <h\stdio.h>
#endif
#define MAXLINE 56 /* maximum lines per page */
#define Page `/f' /* for compilers without `/f' */
#define TAB 8 /* width of one tab stop */
#ifdef CI86
typedef struct {
unsigned short ax,bx,cx,dx,si,di,ds,es;
} REGSET;
#else
typedef struct {
int ax, bx, cx, dx, si, di;
} REGSET;
#endif
main(argc, argv)
int argc;
char *argv[];
{
int filenum;
FILE *fp, *prn, *fopen();
if( (prn = fopen(``PRN:'', ``w'') ) == NULL )
printf(``Error opening printer as file.\n'');
else {
/* initialize the LaserJet for landscape printing */
fprintf(prn, ``\033E\033&l1o\033(s17H\033&l8d6E'' );
for(filenum=1; filenum < argc; filenum++) {
fp = fopen(argv[filenum], ``r'');
if (fp == NULL)
printf(``file %s doesn't exist.\n'', argv [filenum])
else {
printf(``Now printing %s\n'', argv[filenum]);
printfile(fp, prn, argv[filenum]);
fclose(fp);
}
}
fprintf(prn, ``\015\033E''); /* clear LaserJet */
}
}
printfile(fp,prn,filename)
FILE *fp,*prn;
char *filename;
{
int pagenum = 1;
while( !feof(fp)) {
fprintf(prn, ``\033&a0r85m5L\015''); /* set left half */
printpage(fp,prn); /* print page */
if( !feof(fp)) { /*if more .. */
fprintf(prn, ``\033&a0r171m91L''); /*set right half */
printpage(fp,prn); /* print another */
}
stamp(prn, filename, pagenum++); /* title */
fputc(PAGE, prn); /* kick paper */
}
}
printpage(fp,prn)
FILE *fp, *prn;
{
int c,line,col;
line = col = 0;
while(line < MAXLINE)
switch(c = fgetc(fp)) {
case `\n': /* newline found */
col = 0; /* zero column */
line++; /* adv line cnt */
fputc(`\n',prn);
break;
case `\t`: /* TAB found */
do
fputc(`\040',prn);
while ((++col % TAB) != 0);
break;
case PAGE: /* page break or */
case EOF: /* EOF found */
line = MAXLINE; /* force terminate */
break;
default: /* no special case */
fputc(c,prn); /* print character */
col++;
break;
}
}
stamp(prn, filename,pagenum)
FILE *prn;
char *filename;
int pagenum;
{
char datestr[10], timestr[10];
fprintf(prn, ``\033&a5l171M''); /* widen margins */
fprintf(prn, ``\015\033&a58R''); /* move to row 58 */
fprintf(prn, ``File: %-113s'', filename);
fprintf(prn, ``Page %-3d'', pagenum);
timestamp(timestr);
datestamp(datestr);
fprintf(prn, `` %s %s'', datestr, timestr);
}
datestamp(datestr)
char *datestr;
{
REGSET regs;
int month, day, year;
regs.ax = 0x2a00;
#ifdef CI86
sysint21(®s,®s);
#else
int86(0x21,®s,®s);
#endif
month = (regs.dx >> 8) & 255;
day = regs.dx & 255;
year = regs.cx - 1900;
sprintf(datestr, ``%02d/%02d/%02d'', month, day, year);
}
timestamp(timestr)
char *timestr;
{
REGSET regs;
int hours,mins;
regs.ax = 0x2c00;
#ifdef CI86
sysint21(®s,®s);
#else
int86(0x21,®s,®s);
#endif
hours = (regs.cx >> 8) & 255;
mins = regs.cx & 255;
sprintf(timestr, ``%02d:%02d'', hours, mins);
}
[EOF]