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

📄 lcg01of.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef lintstatic char *sccsid = "@(#)lcg01of.c	4.2      ULTRIX 	10/16/90";#endif/************************************************************************ *									* *			Copyright (c) 1987,1990 by			* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any	other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or	reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************//* * lcg01of.c * * Modification history * *  24-Sep-90 - Adrian Thoms (thoms@wessex) *	Removed determinefile() and associated functions and definitions *	to use library guesser module * *  23-Nov-88 - Dave Gray (gray) *     Fixed bad pointer reference in strncmp * * LCG01(formerly LCP01) Color Printing System filter * *  9-Sep-87 - Ricky Palmer (rsp) * *	Added some additional comments. * *  3-Mar-87 - Ricky Palmer (rsp) * *	Created original file and filter program contents. *	This filter supports all normal text output as well *	as color sixels for output of sixel graphics. * */#include <stdio.h>#include <signal.h>#include <errno.h>#include <syslog.h>#include <ctype.h>#include <a.out.h>#include <imghdr.h>#include <strings.h>#include <sys/ioctl.h>#include "guesser.h"#define MAXWIDTH		80		/* width char. count	*/#define MAXLENGTH		66		/* length char. count	*/#define MAXLWIDTH		132		/* max. landscape width */#define MAXP_PIX_WIDTH		585		/* portrait pixel width */#define MAXP_PIX_HEIGHT		770		/* portrait pix. height */#define MAXL_PIX_WIDTH		1540		/* landscape p. width	*/#define MAXL_PIX_HEIGHT		1170		/* landscape p. length	*/#define MAXCOPIES		1		/* default # of copies	*/#define ITS			77#define LCG_LOADFILE		"/usr/lib/lpdfilters/lcg01sw.dat" /* load file	*/#define SOFF			'\077'		/* sixel element offset */#define MAX(a,b)		(a < b ? b : a) /* useful macros	*/#define MAXIMUM(a,b,c)		(MAX(MAX(a,b),c))#define MIN(a,b)		(a > b ? b : a)#define MINIMUM(a,b,c)		(MIN(MIN(a,b),c))FILE	*input = stdin, *output = stdout;	/* input and output	*/char	lpin[80];				/* lp device tmp input	*/int	width = MAXWIDTH;			/* default line length	*/int	length = MAXLENGTH;			/* page length		*/int	indent;					/* indentation length	*/int	npages = MAXCOPIES;			/* number of copies	*/int	literal;				/* print control chars. */int	error;					/* error return status	*/char	*name;					/* user's login name	*/char	*host;					/* user's machine name	*/char	*acctfile;				/* accounting info. file*/int	kindofile = EMPTY_FILE;			/* initial kind of file */int	tmppagecount = 0, tmplinecount = 0;	/* tmp counters		*/char	*imgptr; 				/* image data pointers	*/short	*cmpptr;				/* color map pointer	*/struct	imghdr im;				/* image file header	*/char	*malloc();				/* malloc pointer	*/unsigned  size;					/* the usual		*/void		free(), exit(), bcopy(), syslog();unsigned	sleep();/* The general strategy here is to process the command line arguments,   open the syslog file for log information, determine the input   stream "file type", call the filter code, and then optionally   process accounting information upon completion. Informational   and failure conditions are logged to syslog.*/main(argc, argv)	int argc;	char *argv[];{	register char *cp;	register int i;	while (--argc) {		if (*(cp = *++argv) == '-') {			switch (cp[1]) {			case 'n':		/* collect login name	*/				argc--;				name = *++argv;				break;			case 'h':		/* collect host name	*/				argc--;				host = *++argv;				break;			case 'w':		/* collect page width	*/				if ((i = atoi(&cp[2])) > 0 && i <= MAXWIDTH)					width = i;				break;			case 'l':		/* collect page length	*/				length = atoi(&cp[2]);				break;			case 'i':		/* collect indent	*/				indent = atoi(&cp[2]);				break;			case 'c':		/* print control chars	*/				literal++;				break;			}		} else			acctfile = cp;	}	openlog("lcg01of",LOG_PID);	kindofile = determinefile(fileno(input));	error = lcg01of();	if(error) {		syslog(LOG_INFO,"Failed to output data");		exit(2);	}	if (name && acctfile && access(acctfile, 02) >= 0 &&	    freopen(acctfile, "a", output) != NULL) {		printf("%7.2f\t%s:%s\n", (float)npages, host, name);	}	exit(0);}/* Here is where all the real output work begins. The printer is   issued a "warm reset" to clear any faulty conditions.  We sleep   for five seconds to allow for stability and then switch to the   appropriate code for the determined file type stream.  The LCG01   has to also download its program if necessary and it does so if   the response code (lpin='c') is correct.  This filter code has the   peculiarity that it must "communicate" with the printer bi-directionally   for the above stated reason. The download (if necessary) and bi-directional   communications path are established before the warm reset.*/lcg01of(){	register int i = 0;	register FILE *dload;	register int counter = 0;	register short *tmpptr;	int	ch;	short sr,sg,sb;	int lpinc = 0, retrycnt = 0;tryitagain:	fprintf(output,"\033[c");	fflush(output);	sleep(5);	ioctl(fileno(output),FIONREAD,(char *)&lpinc);	lpinc = read(fileno(output),lpin,lpinc);	if(lpinc == 0) {		retrycnt++;		if(retrycnt > 5)			return(1);		if(retrycnt <= 5) {			sleep(40);			goto tryitagain;		}	}/* top: */	if(lpin[5] == 'c') {		if((dload=(fopen(LCG_LOADFILE,"r")))==NULL) {			syslog(LOG_INFO,"Unable to open %s",LCG_LOADFILE);			return(1);		}		while((ch = getc(dload)) != EOF) {			if(ch == '\033') {				write(fileno(output),(char *)&ch,1);				sleep(1);				while((ch = getc(dload)) != EOF &&				      ch != '\012' ) {					write(fileno(output),(char *)&ch,1);					sleep(1);				}				if(ch == '\012') {					write(fileno(output),(char *)&ch,1);					sleep(5);					continue;				} else {					break;				}			}			write(fileno(output), (char *)&ch,1);		}		fclose(dload);		syslog(LOG_INFO,"%s downloaded into LCG01",LCG_LOADFILE);	}	fprintf(output,"\033[5n");	fflush(output);	sleep(5);	ioctl(fileno(output),FIONREAD, (char *)&lpinc);	lpinc = read(fileno(output),lpin,lpinc);	if(lpinc != 0) {		switch(lpin[3]) {		case '2':			switch(lpin[4]) {			case '0':				syslog(LOG_INFO,"Printer is functional");				break;			case '1':				syslog(LOG_INFO,"Printer hardware error");				return(1);				break;			case '2':				syslog(LOG_INFO,"Printer communications I/O error");				return(1);				break;			case '3':				syslog(LOG_INFO,"Printer input buffer overflow");				return(1);				break;			case '4':				syslog(LOG_INFO,"Printer deselected");				return(1);				break;			case '7':				syslog(LOG_INFO,"Printer out of ink or paper");				return(1);				break;			case '8':				syslog(LOG_INFO,"Printer program load failure");				return(1);				break;			default:				break;			}			break;		case '4':			switch(lpin[4]) {			case '2':				syslog(LOG_INFO,"Printer font load failure");				return(1);				break;			case '4':				syslog(LOG_INFO,"Printer font memory exceeded");				return(1);				break;			default:				break;			}			break;		case '1':			switch(lpin[4]) {			case '0':				switch(lpin[5]) {				case '4':					syslog(LOG_INFO,"Printer has too many fonts");					return(1);					break;				default:					break;				}				break;			default:				break;			}			break;		default:			break;		}	}	fprintf(output, "\033c");	sleep(5);	counter = 0;	switch(kindofile) {		case EMPTY_FILE:			break;		case EXECUTABLE_FILE:		case ARCHIVE_FILE:		case DATA_FILE:		case CAT_FILE:		case POSTSCRIPT_FILE:			syslog(LOG_INFO,"Unprintable data");			return(1);			break;		case XIMAGE_FILE:			error = readXimghdr();			if(error) {				syslog(LOG_INFO,"Failed to use image header");				return(1);			}			error = readXimgcmp();			if(error) {				syslog(LOG_INFO,"Failed to use image colormap");				return(1);			}			if(im.format != ITS) {				/* do RGB to HLS conversion */				tmpptr=cmpptr;				for(i=0;i!=256;i++) {					sr = *tmpptr;					sg = *(tmpptr+1);					sb = *(tmpptr+2);					rgbtohls((unsigned short)sr, (unsigned short)sg, (unsigned short)sb, tmpptr,(tmpptr+1),(tmpptr+2));					tmpptr+=3;				}			}

⌨️ 快捷键说明

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