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

📄 lg31of.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef lintstatic	char	*sccsid = "@(#)lg31of.c	4.1	(ULTRIX)	7/2/90";#endif lint/************************************************************************ *									* *			Copyright (c) 1988 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.	* *									* ************************************************************************//* * lg31of.c	 * * Modification history * * LG31 LINE PRINTER FILTER * * 23-Nov-88 - Dave Gray (gray) * *      Fixed bad pointer reference in strncmp * * The LG31 filter is a modified version of the ln03of filter. They are * basically the same. * *	5-May-88 Pradeep Chetal (chetal) *	 - made 8-bit clean * */#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>#define MAXWIDTH		132		/* maximum char. width	*/#define BUFWIDTH		182		/* 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 HOW_MUCH_TO_CHECK	4096		/* input buffer amount	*/#define EMPTY_FILE		0		/* 0-10,77 file types	*/#define EXECUTABLE_FILE		1#define ARCHIVE_FILE		2#define DATA_FILE		3#define TEXT_FILE		4#define CTEXT_FILE		5#define ATEXT_FILE		6#define RTEXT_FILE		7#define FTEXT_FILE		8#define CAT_FILE		9#define XIMAGE_FILE		10#define ITS			77#define SOFF			'\077'		/* sixel element offset */#define ESC	  '\033'	/* escape sequence introducer */#define BSLH	  '\134'	/* back slash */#define UCP	  '\120'	/* upper case P */#define PLD	  '\113'	/* upper case K = lg31of partial line down */#define PLU	  '\114'	/* upper case L = lg31of partial line up */#define FLU	  '\115'	/* upper case M = lg31of 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'))#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)))/* 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	filestorage[HOW_MUCH_TO_CHECK];		/* first chunk of pipe	*/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	globi = 0, in = 0;			/* global i and in vars.*/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		*/int	escflg =  0;	       /* escape sequence flag, 1 = in progress */int	lstchr;					/* last character	*/int	rotated = 0;				/* image rotated	*/char *setlocale();                              /* Intl. function 	*/char	*fort[] =  { "function","subroutine","common",		  "dimension","block","integer",		  "real","data","double",0 };char	*asc[] =   { "chmk","mov","tst","clr","jmp",0 };char	*c[] =	   { "int","char","float","double",		  "struct","extern",0 };char	*as[] =    { "globl","byte","align","text",		  "data","comm",0 };/* 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 }};void		exit(), bcopy(), syslog();unsigned	sleep();/* 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;	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;	/***************	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 '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("lg31of",LOG_PID);	kindofile = determinefile();	error = lg31of();	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);}/* The general strategy here is to "sniff" the incoming data to   determine how to process output characters to the printer. Not   all possible data streams are reflected here but a wide enough   variety is covered to handle printing of just about all kinds   of data streams.  This code is derived originally from the "file"   command code and modified to reflect its current usage.  Note   that currently only the first HOW_MUCH_TO_CHECK bytes are   used so that if multiple files are concatenated together and   then sent through the filter the first file will determine   how the filter will act.*/determinefile(){	register int j = 0, nl = 0;	register char ch, *chptr;	in = read(fileno(input), &filestorage[0], HOW_MUCH_TO_CHECK);	if((chptr = index(&filestorage[0],'\014')) != NULL)		globi = chptr + 1 - &filestorage[0];	if(in == 0 && globi == 0){		return(EMPTY_FILE);	}	switch(*(int *)&filestorage[globi]) {	case 0413:	case 0410:	case 0411:	case 0407:		return(EXECUTABLE_FILE);		break;	case 0177555:	case 0177545:	case 070707:	case 027456:		return(ARCHIVE_FILE);		break;	case 04553207:		return(XIMAGE_FILE);		break;	default:		break;	}	if((strncmp(filestorage+globi, "!<arch>\n__.SYMDEF", 17) == 0) ||	   (strncmp(filestorage+globi, "!<arch>\n", 8) == 0)) {		return(ARCHIVE_FILE);	}	if(ccom() == 0)		goto notc;	while(filestorage[globi] == '#'){		j = globi;		while(filestorage[globi++] != '\n'){			if(globi - j > 255){				return(DATA_FILE);			}			if(globi >= in)				goto notc;		}		if(ccom() == 0)			goto notc;	}check:	if(lookup(c) == 1){		while((ch = filestorage[globi++]) != ';' &&		      ch != '{')			if(globi >= in)				goto notc;		return(CTEXT_FILE);	}	nl = 0;	while(filestorage[globi] != '('){		if(filestorage[globi] <= 0)			goto notas;		if(filestorage[globi] == ';'){			globi++;			goto check;		}		if(filestorage[globi++] == '\n')			if(nl++ > 6)				goto notc;		if(globi >= in)			goto notc;	}	while(filestorage[globi] != ')'){		if(filestorage[globi++] == '\n')			if(nl++ > 6)				goto notc;		if(globi >= in)			goto notc;	}	while(filestorage[globi] != '{'){		if(filestorage[globi++] == '\n')			if(nl++ > 6)				goto notc;		if(globi >= in)			goto notc;	}	return(CTEXT_FILE);notc:	globi = 0;	while(filestorage[globi] == 'c' || filestorage[globi] == '#'){		while(filestorage[globi++] != '\n')			if(globi >= in)				goto notfort;	}	if(lookup(fort) == 1){		return(FTEXT_FILE);	}notfort:	globi=0;	if(ascom() == 0)		goto notas;	j = globi-1;	if(filestorage[globi] == '.'){		globi++;		if(lookup(as) == 1){			return(ATEXT_FILE);		}		else if(filestorage[j] == '\n' &&			isalpha(filestorage[j+2])){			return(RTEXT_FILE);		}	}	while(lookup(asc) == 0){		if(ascom() == 0)			goto notas;		while(filestorage[globi] != '\n' && filestorage[globi++] != ':')			if(globi >= in)				goto notas;		while(filestorage[globi] == '\n' || filestorage[globi] == ' ' ||		      filestorage[globi] == '\t')			if(globi++ >= in)				goto notas;		j = globi-1;		if(filestorage[globi] == '.'){			globi++;			if(lookup(as) == 1){				return(ATEXT_FILE);			}			else if(filestorage[j] == '\n' &&				isalpha(filestorage[j+2])){				return(RTEXT_FILE);			}		}	}	return(ATEXT_FILE);notas:	for(globi=0; globi < in; globi++)if(filestorage[globi]&0200){		if ((unsigned)filestorage[0]==(unsigned)'\100' && 		    (unsigned)filestorage[1]==(unsigned)'\357') {			return(CAT_FILE);		}	}	return(TEXT_FILE);}lookup(tab)register char *tab[];{	register char r;	register int k,j,l;	while(filestorage[globi] == ' ' || filestorage[globi] == '\t' ||	      filestorage[globi] == '\n')globi++;	for(j=0; tab[j] != 0; j++){		l=0;		for(k=globi; ((r=tab[j][l++]) == filestorage[k] &&		    r != '\0');k++);		if(r == '\0')			if(filestorage[k] == ' ' || filestorage[k] == '\n' ||			   filestorage[k] == '\t' || filestorage[k] == '{' ||			   filestorage[k] == '/'){				globi=k;				return(1);			}	}	return(0);}ccom(){	register char cc;	while((cc = filestorage[globi]) == ' ' || cc == '\t' ||	      cc == '\n')		if(globi++ >= in)			return(0);	if(filestorage[globi] == '/' && filestorage[globi+1] == '*'){		globi += 2;		while(filestorage[globi] != '*' || filestorage[globi+1] != '/'){			if(filestorage[globi] == '\\')				globi += 2;			else				globi++;			if(globi >= in)				return(0);		}		if((globi += 2) >= in)			return(0);	}	if(filestorage[globi] == '\n')		 if(ccom() == 0)			return(0);	return(1);}ascom(){	while(filestorage[globi] == '/') {		globi++;		while(filestorage[globi++] != '\n')			if(globi >= in)				return(0);		while(filestorage[globi] == '\n')			if(globi++ >= in)				return(0);	}	return(1);}/* Here is where all the real output work begins. We switch   to the appropriate code for the determined file type stream.*/lg31of(){	register int i = 0;	register char  *cp;	register int ch;	register short *tmpptr, *tmp;	unsigned int temp;	int done, linedone;	char *limit;	switch(kindofile) {		case EMPTY_FILE:			break;		case EXECUTABLE_FILE:		case ARCHIVE_FILE:		case DATA_FILE:		case CAT_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) {

⌨️ 快捷键说明

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