⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 epr.c

📁 EPSON 打印机的列表功能 C 语言源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/************************************************************************

  File:		epr.c
  Function:	Permits listing of files on Epson printer with control
		over format of listing and printer attributes.
  Version:	1.10-A
  Author:	Robert Sjoberg (SJOBRG@MIT-OZ)
  Implementation notes:
    Originally written to be compiled using Computer Innovations C86
    compiler running under IBM PC-DOS.  Requires external functions
    in "timestmp.c"; should run under CP/M without modification,
    provided compiler and C library has support for stdin, stdout, and
    stderr output (Aztec C certainly does).
    Code written applies to Epson FX-80 printer.
  Revision History:
    V1.00 (09/24/83) - original program.
    V1.01 - put in h= option.
    V1.02 - added new dash options, fixed the way initialization done.
    V1.03 - added -p option to allow change of sheet-fed paper.
    V1.04 - added code to turn off autoskip on paper perforation;
	modified to use timestmp external function.
    V1.05 (11/28/83) - fixed bug in optfile routine and added o= option.
    V1.06 (01/08/84) - Fixed line overflow problem, introduced b= option.
    V1.07 (01/27/84) - Added -1 option, changed -t option to -h and so
	that it only suppresses the header, not top margin.
    V1.08 (05/23/84) - Modified for Unix V7.
    V1.09 (06/27/84) - Added -d switch, modified -s to simply suppress
	printer control codes.  Added "UPMODE" hack.  Sigh.
    V1.10 (07/16/84) - Removed -d switch (it is redundant with o=),
	added c= keyword to select character set.

    11 Dec 85  Craig Milo Rogers at USC/ISI (Rogers@USC-ISIB.ARPA)
	Added another debugging line.

	Converting to Lattice C (ver. 2.12).

	Changed "c" and "firstc" from "char" to "int" in getline() --
	EOF tests weren't working!  Same for "term" in main() and
	"c" in optfile().

	Tabs weren't working when international characters were
	enabled, uparrow mode didn't work -- I recoded the whole
	section.

	I added code to allow Epson escape sequences to be specified
	in the user's header.  Should be redone more cleanly, though.

	The table of printer widths didn't specify the full 137 chars
	possible in condensed (ie, compressed) mode.  It didn't tell
	about enlarged compressed pitch, either.  I rewrote it.

	The program didn't allow specification of the full set of Epson
	FX-80 print modes.  I rewrote the code involved.

	I added code to allow the header print modes to be assigned the
	same way as the modes for the body.  However, I didn't give
	the header a seperate columns-per-line value.

	I changed the default left margin to be 0 (this isn't completely
	arbitrary, my measurements of the margin didn't agree with
	what the program claimed it was doing.

  NOTICE	This program is furnished to the public domain.  It may
  ------	not be sold or otherwise commercially distributed for
		profit, in its original form or in any derivational form.
		It may be copied and distributed freely, without charge
		to recipients. If you see fit to improve this program,
		you are welcome to do so PROVIDED you clearly indicate
		the changes in the Revision History above, you include
		your name and handle (network or U.S. Mail address is
		sufficient), and you provide an original copy of this
		program to anyone who receives the modified copy.

************************************************************************/

/* Select host operating system by defining appropriate symbol.
 * The default is PCDOS for PC-DOS or MS-DOS or CP/M.  The alternative
 * is UNIX for UNIX V7 (also works for newer UNIX).
 */

#ifndef UNIX
#ifndef PCDOS
#define PCDOS
#endif
#endif

/* Format of include file names may be changed at different sites */
#include <stdio.h>
#include "timestmp.h"

#ifdef UNIX
#include <ctype.h>
#endif

#ifndef EOS
#define EOS '\0'	/* end of string character */
#endif

/* Define the name of the device attached to printer */

#ifdef UNIX
#define Epson "/dev/tty01"	/* name of printer device */
#define UPMODE 2		/* Unix will not output certain control
				 * codes unless in RAW mode, but then it
				 * doesn't like XON/XOFF protocol.  This
				 * gets around some (temporary) problems
				 * the author is having.  It should not
				 * affect use of epr. */
#endif

#ifdef PCDOS
#define Epson "PRN:"		/* name of printer device */
#define UPMODE 0
#endif

/* CP/M converts its command line to upper case, so use the following
 * to convert critical characters to lower case, for both CP/M and
 * PC-DOS/MS-DOS implementations.
 */
#define casecvt(x) if (isupper(x)) x = tolower(x)

/* Debugging information (lots of it) is available by defining the
 * symbol "Dbug".  All diagnostic output is written to stderr.
 */
/*
#define Dbug 1
 */

#ifdef Dbug
#define DBG(form) form
FILE	*dfp = stderr;
#else
#define DBG(form)
#endif

/* Convenience definitions */
#define BS '\b' /* Ascii 010 */
#define HT '\t' /* Ascii 011 */
#define LF '\n' /* Ascii 012 */
#define FF '\f' /* Ascii 014 */
#define CR '\r' /* Ascii 015 */
#define ESC '\033'
#define SP ' '
#define DEL '\177'
#define LL  0276	/* used to indicate long line on input */
#define EOH 0277	/* marks end of page header sequence */

/* Dash Option Variables */
char	altset = 0;	/* -a, 1 if use alternate character set */
char	cchar = 0;	/* -c, 1 if print control chars as ^X */
char	ffeed = 0;	/* -f, 1 if use form feed to end page */
char	nohead = 0;	/* -h, 1 if header should be suppressed */
char	intl = 0;	/* -i, 1 if allow international chars */
char	trunc = 0;	/* -o, 1 if truncate long lines */
char	pagpaus = 0;	/* -p, 1 if special start-of-page pause */
char	nopcc = 0;	/* -s, 1 if suppress printer control codes */
char	nopage1 = 0;	/* -1, 1 if suppress heading on page 1 */
char	space8 = 0;	/* -8, 1 if use 8 lines/inch */

/* Output Control and Printer Modes (currently only Epson) */
FILE	*ofp;		/* output file pointer */
char	outfile[50]=Epson; /* name of output file (o= option) */
short	pmode = 0;	/* mode byte for p= option */
short	qmode = 0;	/* mode byte for q= option */

#define F_t 010000		/* top (ie, superscript) */
#define F_s  04000		/* subscript */
#define F_p  02000		/* proportional */
#define F_u  01000		/* underlined */
#define F_i   0400		/* italic */
#define F_e    040		/* expanded */
#define F_d    020		/* double strike */
#define F_b    010		/* bold (ie, emphasized) */
#define F_c     04		/* compressed */
#define F_l     01		/* elite */

short	cmode = 0;	/* intl character set (defaults to U.S.A.) */
char *cntries[] = {	/* table of country mnemonics */
  "us","fr","ge","uk","de","sw","it","sp","ja",NULL
};

/* Input control */
char	**nextf = NULL;		/* list of input file names */
short	nfiles;			/* number of files to process */

/* Page formatting */
short	topmar = -1;		/* top margin, in lines */
short	leftmar = -1;		/* left margin, in chars */
short	cpl = -1;		/* chars per line */
short	lpp = -1;		/* number of lines per page before FF */
short	phycpl;			/* number of physical chars per line */
short	phylpp;			/* number of physical lines per page */
short	tabspaces = 8;		/* tabs expand into this many spaces */
short	headpf = 0;		/* flags order of pagen, filename */
short	hlines;			/* number of lines in header */
char	header[80] =		/* holds header string */
    "%d %t  %f Page %p\\n\\n";	/* default header */
char	hformat[130];		/* actual header format string */
char	textline[256];		/* holds input text line */
struct timedata timeinfo;	/* holds time and date info */


Abort (msg, param)
    char *msg;
    int param;
/*
 * Prints out an error message with optional parameter, then exits
 * with non-zero exit code.
 */
{
    fprintf(stderr,"epr: ");
    fprintf(stderr,msg,param);
    fprintf("\n");
    exit (1);
}


/* The main sequence following handles input file specs and reading
 * in characters.  Makes line-by-line output.
 * If no file names are specified in the command, then input is
 * from standard input.
 */

main (argc,argv)
    int		argc;
    char	**argv;
{
    FILE	*ifp;		/* fp for input file */
    char	*filename;	/* input filename */
    int		pagen;		/* page number */
    int		lines;		/* lines processed per page */
    int		c, l, n, endfile;
    int		term;		/* line terminator */
    char	*tl;

    DBG(fprintf(dfp,"About to parse command line.\n");)
    pcl (argc, argv);		/* parse command line options */

    DBG(fprintf(dfp,"About to initialize.\n");)
    initialize ();

    /* For debugging */
#ifdef Dbug
    fprintf (dfp,"Output is to %s\n",
	(outfile[0] ? outfile : "stdout"));
    fprintf (dfp,"altset %d, cchar %d, pagpaus %d, ffeed %d\n",
	altset,cchar,pagpaus,ffeed);
    fprintf (dfp,"intl %d, trunc %d, nohead %d, space8 %d\n",
	intl,trunc,nohead,space8);
    fprintf (dfp,"pmode %04o, qmode %04o, headpf %d, nopcc %d, nopage1 %d\n",
	pmode,qmode,headpf,nopcc,nopage1);
    fprintf (dfp,"topmar %d, leftmar %d, cpl %d, lpp %d\n",
	topmar,leftmar,cpl,lpp);
    fprintf (dfp,"header [%s]\n",header);
    fprintf (dfp,"hlines %d, hformat [%s]\n",hlines,hformat);
    fprintf (dfp,"nfiles %d",nfiles);
    for (n = 0; n < nfiles; n++) fprintf (dfp,", %s",nextf[n]);
    fprintf (dfp,"\n");
#endif

    if (nfiles == 0) {		/* input from stdin */
	ifp = stdin;
    }
    do {			/* repeat for each file */
	if (ifp != stdin) {
	    filename = *nextf++;
	    nfiles--;
	    DBG( fprintf (dfp,"Opening %s ...\n",filename); )
	    ifp = fopen (filename, "r");
	    if (ifp == NULL) {
		fprintf (stderr,"Couldn't open %s -- skipping\n",filename);
		continue;
	    }
	}
	else {
	    filename = "stdin";
/*	    DBG( fprintf (dfp,"Using stdin ...\n"); )		*/
	}
	endfile = 0;
	term = 0;
	for (pagen = 1; ; pagen++) {	/* repeat for each page */
	    /* Pause at start of each page, if requested */
	    if (pagpaus) {
		printf ("Set up printer and type CR...");
		while (getchar() != LF);
	    }
	    /* Output any top margin and header */
	    lines = 0;
	    if (n = topmar) {		/* write top margin */
		sendpcc(pmode);		/* Send body printer modes. */
		lines += n;
		while (n--) putc (LF,ofp);
	    }
	    if (!(nohead || (pagen == 1 && nopage1))) {
		sendpcc(qmode);		/* Send header printer modes. */
		lines += outhead (pagen, filename);
	    }
	    sendpcc(pmode);		/* Send body printer modes. */

	    while (lines < lpp) {
		if (term != LL && term != CR) {
		    /* Not continuation of long line or overprint */
		    if ((term = getline (ifp, textline)) == EOF) {
			endfile++; break;
		    }
		    if (term == FF) break;		/* end of page */
		    /*
		     * Routine putline writes a full line of text to
		     * output and returns the line-terminating char.
		     * A CR means the line is being overprinted; a LF
		     * means true end-of-line; a FF means a lone FF seen;
		     * and LL means long line (wrapped).
		     */
		    tl = textline;
/*		    DBG(showtl(tl);)		*/
		}
		term = putline (&tl, 0);
		if (term == CR) putc(term,ofp);	/* overprint */
		else {
		    putc(LF,ofp);		/* end of line */
		    lines++;
		}
	    }
	    /* Write any trailing blank lines */
	    if (ffeed) putc(FF,ofp);
	    else while (lines++ < phylpp) putc(LF,ofp);

	    if (endfile) break;
	}
	if (ifp != stdin) fclose (ifp);
    } while (nfiles > 0);

    DBG(fprintf(dfp,"Closing output file\n");)
    fflush (ofp);
    if (ofp != stdout) fclose (ofp);	/* close output file */
}

char htext[120];		/* holds formatted header text */

outhead (pagen, filename)
    int pagen;
    char *filename;
/*
 * Print the header using the given page number and filename.
 */
{
    int c, lines;
    char *tl;

    /* There are two forms for the header format string.  In one, the
     * page number comes before the file name (or just the page number
     * is used), and in the other the file name comes before the page
     * number (or just the file name is used).
     */
    if (headpf) sprintf (htext, hformat, pagen, filename);
    else sprintf (htext, hformat, filename, pagen);
    tl = htext;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -