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

📄 decuniversal_of.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef lintstatic char *sccsid = "@(#)decuniversal_of.c	4.1      ULTRIX 	10/16/90";#endif/************************************************************************ *									* *			Copyright (c) 1987, 1988 and 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.			* *									* *   This software is  derived	from  software	received  from	the	* *   University    of	California,   Berkeley,   and	from   Bell	* *   Laboratories.  Use, duplication, or disclosure is	subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   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.	* *									* ************************************************************************//* * File:	ln03_lg31_lg02_la75.c * Author:	Adrian Thoms (thoms@wessex) * Description: *	This is the print filter for the following printers: *	LN03, LG31, LG02 and LA75 * *	This file was created by merging the code in lg31of.c, lg02of.c *	and la75.c back into ln03of.c from which they appear to have been *	derived. * *	File type guessing has been removed and is now performed by a *	library module. * * Modification history: * *  26-sep-90 - Adrian Thoms *	No longer prints PostScript(TM) files * *  25-sep-90 - Adrian Thoms *	Merged in fix to literal handling of EOF from la75.c * *  25-sep-90 - Adrian Thoms *	Merged in la75 functionality from la75.c * *  25-sep-90 - Adrian Thoms (thoms@wessex) *	Merged in lg02 functionality from lg02of.c * *  25-sep-90 - Adrian Thoms (thoms@wessex) *	Increased MAXWIDTH and BUFWIDTH to answer QAR #04155 * *  25-sep-90 - Adrian Thoms (thoms@wessex) *	Merged in lg31 functionality from lg31of.c * *  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 * * *	5-May-88 Pradeep Chetal (chetal) *	 - made 8-bit clean * *  23-Jan-88  David Gray (gray) * *      Modified the escape handler to embed Nroff escape sequences *      in the buffer to allow appropriate actions to take place, ie., *      super and subscripting. * *  7-Dec-87   Pradeep Chetal (chetal) * * 	Added code to handle literal option and some optimizations. * *  9-Sep-87 - Ricky Palmer (rsp) * *	Added some additional comments. * * 21-Aug-87 - David Gray (gray) * *	To determine file type the first 4096 characters of the file *	are buffered in "filestorage". When the file is actually printed *	an attempt was made to access the 4097 element which resulted in an *	extra character being inserted into the final output. This has been *	corrected. The correction made was to change the test *		  globi <= in	  to	globi < in *	in function ln03of(). * * * 25-Apr-87 - Ricky Palmer (rsp) * *	Berkeley ln03 filter code put into source maintenance format. * *	Letter Quality Printers filter for ln03 looking like lqp * *	filter which reads the output of nroff and converts lines *	with ^H's to overwritten lines.  Thus this works like 'ul' *	but is much better: it can handle more than 2 overwrites *	and it is written with some style. *	modified by kls to use register references instead of arrays *	to try to gain a little speed. * *	Passes through escape and control sequences. * *	Sends control chars to change to landscape mode for pages wider *	than 80 columns.  Also changes font and pitch for this case in *	order to get 66 lines per page in landscape mode. * *	Special logic for nroff ESC9 (partial line feed): this is *	converted to ln03 sequence for partial line feed.  Eventually *	this kluge should be replaced by an output package for nroff *	which knows about ln03 output. * * 25-Apr-87 - Ricky Palmer (rsp) * *	Added code to original Berkeley filter based on *	LCG01 and LJ250 filters. This filter supports *	normal text output as well as 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 <locale.h>#include "guesser.h"struct filter_info;		/* forward declaration *//* * Functions in this file */static struct filter_info *set_which_filter();		/* Determine which printer we are driving */static intfilter();			/* Process the data */#define MAXWIDTH		220		/* maximum char. width	*/#define BUFWIDTH		300		/* maximum buf.  width	*/#define MAXREP			10		/* buffer depth		*/#define DEFWIDTH		80		/* width char. count	*/#define DEFHEIGHT		66		/* length char. count	*/#define MAXP_PIX_WIDTH		800		/* portrait pixel width */#define MAXP_PIX_HEIGHT		1040		/* portrait pix. height */#define MAXL_PIX_WIDTH		1040		/* landscape p. width	*/#define MAXL_PIX_HEIGHT		800		/* landscape p. length	*/#define MAXCOPIES		1		/* default # of copies	*/#define ITS			77#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))#define ESC	  '\033'	/* escape sequence introducer */#define BSLH	  '\134'	/* back slash */#define UCP	  '\120'	/* upper case P */#define PLD	  '\113'	/* upper case K = ANSI partial line down */#define PLU	  '\114'	/* upper case L = ANSI partial line up */#define FLU	  '\115'	/* upper case M = ANSI full line up */#define E_NINE	  '\071'	/* 9: nroff ESC9 = partial line down */#define E_EIGHT   '\070'	/* 8: nroff ESC8 = partial line up */#define E_SEVEN   '\067'	/* 7: nroff ESC7 = full line up */#define escend(x) ((x!='\120')&&(x!='\133')&&(x>='\100')&&(x<='\176'))/* Added a few macros for 8bit support */#define is_7bit_cntrl(ch)	((unsigned char)ch < 040 || (unsigned char)ch == 0177)FILE	*input = stdin, *output = stdout;	/* input and output	*/char	buf[MAXREP][BUFWIDTH];			/* buffer for output	*/int	maxcol[MAXREP] = {-1};			/* maximum columns	*/int	lineno;					/* line number		*/int	width = DEFWIDTH;			/* default line length	*/int	length = DEFHEIGHT;			/* page length		*/int	indent;					/* indentation length	*/int	npages = MAXCOPIES;			/* number of copies	*/int	literal;				/* print control chars. */int	error;					/* error return status	*/int     esclen;                                 /* num escape chars     */int     maxrep;                                 /* current depth in buf */int     col;                                    /* column position      */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	*/char *setlocale();				/* Intl. function       */unsigned  size;					/* the usual		*/int	escflg =  0;	       /* escape sequence flag, 1 = in progress */int	lstchr;					/* last character	*/int	rotated = 0;				/* image rotated	*/void		exit(), bcopy(), syslog();unsigned	sleep();/* sixmap is the dither pattern used to create sixel output bytes */struct sixmap {	char s0, s1, s2;} base_sixmap[] = {	{ 0+SOFF, 0+SOFF, 0+SOFF },	{ 4+SOFF, 0+SOFF, 0+SOFF },	{ 4+SOFF, 0+SOFF, 1+SOFF },	{ 4+SOFF, 4+SOFF, 1+SOFF },	{ 6+SOFF, 4+SOFF, 1+SOFF },	{ 6+SOFF, 6+SOFF, 1+SOFF },	{ 6+SOFF, 6+SOFF, 6+SOFF },	{ 7+SOFF, 6+SOFF, 6+SOFF },	{ 7+SOFF, 6+SOFF, 7+SOFF },	{ 7+SOFF, 7+SOFF, 7+SOFF }};struct sixmap offset_sixmap[] = {	{  0+SOFF,  0+SOFF,  0+SOFF },	{ 32+SOFF,  0+SOFF,  0+SOFF },	{ 32+SOFF,  0+SOFF,  8+SOFF },	{ 32+SOFF, 32+SOFF,  8+SOFF },	{ 48+SOFF, 32+SOFF,  8+SOFF },	{ 48+SOFF, 48+SOFF,  8+SOFF },	{ 48+SOFF, 48+SOFF, 48+SOFF },	{ 56+SOFF, 48+SOFF, 48+SOFF },	{ 56+SOFF, 48+SOFF, 56+SOFF },	{ 56+SOFF, 56+SOFF, 56+SOFF }};/* * In order to merge the functionality of the ln03, lg31 and lg02 filters * we need a table of structure to contain the difference information. * we index into this with an enum. * * We pass the known names by which the filter can be called from the * via pre-processor definitions */static enum which_filter_e {		/* Enumerate different printers supported */	ln03,	lg31,	lg02,	la75    } which_filter;static struct filter_info {		/* Printer specific info */	char *fi_name;	char *fi_sixel_intro;} filter_info[] = {	{ LN03OF, "\033P9;0;1q\"1;1-"},	{ LG31OF, "\033P9;0;10q\"1;1-"},	{ LG02OF, "\033P9;0;0q\"1;1-"},	{ LA75OF, "\033P9;;5;q\"1;1-"},	{ NULL }};static char *name;		/* Name program called with */static struct filter_info *set_which_filter(arg0)	char *arg0;{	register struct filter_info *fip;	if ((name=strrchr(arg0, '/')) == NULL) {		name = arg0;	} else {			name++;	}	for (fip=filter_info; fip->fi_name != NULL; fip++) {		if (!strcmp(fip->fi_name, name)) {			which_filter =			    (enum which_filter_e) (fip - filter_info);			return(fip);		}	}	fprintf(stderr, "%s: Must be called one of following:\n\t", name);	for (fip=filter_info; fip->fi_name != NULL; fip++) {		fprintf(stderr, " %s", fip->fi_name);	}	putc('\n', stderr);	exit(2);	/* not reached */	return NULL;}/* The general strategy here is to reset the printer to initial state,   sleep for five seconds for stability, 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 int i;	register char *cp;	register struct filter_info *fip;	fip = set_which_filter(argv[0]);	/* 	 * The general strategy here is to reset the printer to initial state,   	 * sleep for five seconds for stability, process the command line arguments,   	 * determine the input stream "file type", call the filter code, and then 	 * optionally process accounting information.	 */	setlocale(LC_CTYPE, "ENG_GB.MCS");	fprintf(output, "\033c");		/* reset to initial state */	sleep(5);	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(name, LOG_PID);	switch(which_filter) {	case ln03:		if (width > 80) { /* switch to landscape mode */			fprintf(output,"\033[15m"); /* change font */			fprintf(output,"\033[7 J"); /* A4 page format */			fprintf(output,"\033[66t"); /* 66 lines/page */			fprintf(output,"\033[8 L"); /* vp = 12 lines/30mm */		}		break;	case lg31:	case lg02:		break;	case la75:		if ( width > 80 ) /* change HOR pitch to 16.5 cpi */		    fprintf(output,"\033[4w");		break;	default:		break;	}	kindofile = determinefile(fileno(input));	error = filter();	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. We switch   to the appropriate code for the determined file type stream.*/static intfilter(){	register int i = 0;	register char *cp;	register int ch;	register short *tmpptr, *tmp;	unsigned int temp;	int done, linedone;	char *limit;	register struct filter_info *fip= &filter_info[(int)which_filter];	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 ANSI_FILE:		print_ansi_file();		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 YIQ conversion */			tmpptr=cmpptr;			for(i=0;i!=256;i++) {				tmp=tmpptr;				temp= *tmpptr * .30;				tmpptr++;				temp+= *tmpptr * .59;				tmpptr++;				temp+= *tmpptr * .11;				tmpptr++;				*tmp=(255-temp);			}		}		error = readXimgdat();		if(error) {			syslog(LOG_INFO,"Failed to use image data");			return(1);		}		switch(which_filter) {		case ln03:		case lg31:		case lg02:		default:			if(im.spbxnm > MAXP_PIX_WIDTH) {				fprintf(output,"\033[11h\033[7 I");				fprintf(output,"\033[?21 J");				fprintf(output,"\033[?52l");				fprintf(output,"\033[1;3150s");				rotated++;				if(im.spbxnm > MAXL_PIX_WIDTH) {					im.spbxnm = MAXL_PIX_WIDTH;				}				if(im.spbynm > MAXL_PIX_WIDTH) {					tmppagecount = im.spbynm/MAXP_PIX_WIDTH;					tmplinecount = MAXP_PIX_WIDTH;				}			} else { /* im.spbxnm <= MAXP_PIX_WIDTH */				fprintf(output,"\033[11h\033[7 I");				fprintf(output,"\033[?20 J");				fprintf(output,"\033[?52l");				fprintf(output,"\033[1;2400s");				if(im.spbynm > MAXP_PIX_HEIGHT) {					tmppagecount = im.spbynm/MAXP_PIX_HEIGHT;					tmplinecount = MAXP_PIX_HEIGHT;				}

⌨️ 快捷键说明

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