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

📄 decuniversal_of.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 2 页
字号:
			}			break;		case la75:			/* Now LA75 has only one mode...so go for that */			if ( im.spbxnm > MAXP_PIX_WIDTH )			    im.spbxnm =  MAXP_PIX_WIDTH;			if ( im.spbynm > MAXP_PIX_HEIGHT ){				tmppagecount = im.spbynm/MAXP_PIX_HEIGHT;				tmplinecount = MAXP_PIX_HEIGHT;			}			break;		}		fprintf(output, fip->fi_sixel_intro);		error = dosixel();		if(error) {			syslog(LOG_INFO,"Failed to 'sixelize' data");			fprintf(output, "\033\\");			fprintf(output, "\033c");			sleep(5);			fprintf(output, "\014");			fflush(output);			return(1);		}		break;	case TEXT_FILE:	case CTEXT_FILE:	case ATEXT_FILE:	case RTEXT_FILE:	case FTEXT_FILE:	default:		memset(buf, ' ', (size_t) sizeof(buf));		done = 0;		escflg = 0;	/* is escape/control sequence in progress? */		globi = 0;		while (!done) {			col = indent;			esclen = 0;			maxrep = -1;			linedone = 0;			while (!linedone) {				ch = globi < in ? filestorage[globi++] : getc(input);				if (((escflg==0)&&(ch==ESC))||escflg)				    eschdl(output,ch); /* deal with escape character */				else 				    if ( literal && iscntrl(ch) &&					(ch != '\n') && (ch != EOF)) {					    cp = &buf[0][col]; /* Since literal mode..everything is the								  first row itself.*/					    maxrep = 0;					    if (is_7bit_cntrl(ch)){						    if (ch == 0177){							    *cp++ = '^';							    *cp   = '?';							    col ++;						    } else{ /* It is < 040 */							    *cp++ = '^';							    *cp   = ch + '@';							    col ++;						    }					    } else{ /* It is 8bit cntrl */						    if ((unsigned char)ch < 0240){							    *cp++ = 'M';							    *cp++ = '-';							    ch   &= 0177;							    *cp   = ch + '@';							    col  += 2;						    } else {							    *cp++ = 'M';							    *cp++ = '-';							    *cp   = '?';							    col  += 2;						    }					    }					    if ( col > maxcol[0] )						maxcol[0] = col;					    col++; /* col points to next blank entry in buf */				    }				    else { /* regular characters */					    switch (ch) {					    case EOF:						    linedone = done = 1;						    ch = '\n';						    break;  					    case '\f': /* new page on form feed */						    lineno = length;					    case '\n': /* new line */						    if (maxrep < 0)							maxrep = 0;						    linedone = 1;						    break;  					    case '\b': /* backspace */						    if (--col < indent)							col = indent;						    break;  					    case '\r': /* carriage return */						    col = indent;						    break;  					    case '\t': /* tab */						    col = ((col - indent) | 07) + indent + 1;						    break;  					    case '\031': /* end media */						    /*						     * lpd needs to use a different filter to						     * print data so stop what we are doing and						     * wait for lpd to restart us.						     */						    ch = globi < in ? filestorage[globi++] : getc(input);						    if (ch == '\1') {							    fflush(output);							    kill(getpid(), SIGSTOP);							    break;						    } else {							    if(globi <= in) {								    globi--;							    } else {								    ungetc(ch, input);							    }							    ch = '\031';						    }  					    default: /* everything else */						    addtobuf(ch);						    break;					    } /* end switch */				    } /* end else */			}	/* end while not linedone */			/* print out lines */			for (i = 0; i <= maxrep; i++) {				switch(which_filter) {				case la75:					if (i == 0) {						break;					} else {						/* drop through */					}				case ln03:				case lg31:				case lg02:				default:					putc('\r', output);				}				for (cp = buf[i], limit = cp+maxcol[i]; cp <= limit;) {					putc(*cp, output);					*cp++ = ' ';				}				if (i == maxrep)				    putc(ch, output);				if (++lineno >= length) {					npages++;					lineno = 0;					if (length < 66)					    putc('\f',output); /* FF for length < 66 */				}				maxcol[i] = -1;			}		}		if (lineno) {	/* be sure to end on a page boundary */			putc('\f',output);			npages++;		}  		fprintf(output,"\033c"); /* reset printer defaults */		fflush(output);	/* make sure reset goes out */		sleep(6);	/* some printers eat lines during reset so wait */		break;	}	return(0);}/****************************************************************** Prints a file already formatted with ansi control sequences.   **  The lf and cr options on the lg02 should be disabled. Fixes   **  a problem in lg02 when printing block characters in landscape **  mode. This procedure sends file directly to printer, however, **  it adds a carraige return character for linefeed character    **  seen.                                                         *******************************************************************/print_ansi_file (){	int     done;	register char ch;		globi = 0;	done = 0;	while (!done) {		ch = globi < in ? filestorage[globi++] : getc(input);		switch (ch) {			case EOF: 				done = 1;				break;			case '\n':                   /* new line */				putc('\r',output);   /* insert CR character */				putc(ch, output);				break;			default:				putc(ch, output);				break;		}	}	fprintf(output,"\033\143");  /* reset printer defaults - "escape c" */	fflush(output);		     /* make sure reset goes out            */	sleep(2);		     /* make sure the reset sets            */}					/****************************************************************  Adds the character specified to buffer - if it will fit on line*****************************************************************/addtobuf (ch)register char      ch;{	register char  *cp;        int  i;        if ((col >= (width + esclen) || iscntrl(ch)) && ch != ESC){		col++;		return(0);        }        cp = &buf[0][col];        for (i = 0; i < MAXREP; i++) {		if (i > maxrep)		    maxrep = i;		if (*cp == ' ') {			*cp = ch;			if (col > maxcol[i])			    maxcol[i] = col;			break;		}		cp += BUFWIDTH;        }        col++;        return(1);}/****************************************************************//*								*//*	eschdl - escape sequence handler			*//*								*//*	This routine intercepts escape sequences for the purpose*//*	of pass through.					*//*								*//****************************************************************/eschdl(o,c)int c;FILE  *o;{	if(escflg==0)	    {			/* set escflg=1 => ready to receive 2nd seqchar*/		    escflg=1;	    }	else	switch(escflg)	    {	    case 1:		/* second character of escseq		*/		    switch(c)			{			case E_NINE: /* added to buffer - hopefully in the correct place */				addtobuf (ESC);				addtobuf (PLD);				esclen += 2;				escflg = 0;				break;			case E_EIGHT: /* added to buffer - hopefully in the correct place */				addtobuf (ESC);				addtobuf (PLU);				esclen += 2;				escflg = 0;				break;			case E_SEVEN: /* added to buffer - hopefully in the correct place */				addtobuf (ESC);				addtobuf (FLU);				esclen += 2;				escflg = 0;				break;			case UCP:				escflg=2; /*ctrl str pass thru mode=8 */				lstchr=c;				putc(ESC,o);				putc(c,o);				break;			default:				escflg=3; /* set seq pass thru mode*/				putc(ESC,o);				putc(c,o);				break;			}		    break;	    case 2:		/* ctrl string pass through mode	*/		    if((lstchr==ESC) && (c==BSLH))			{				escflg=0;				lstchr=0;			}		    else lstchr=c; /* save it for next pass */		    putc(c,o);		    break;	    case 3:		    if(escend(c))			escflg=0; /* turn off esc handler if at end  */		    putc(c,o);		    break;	    }	return(0);}/*  * If the file stream is of the XIMAGE_FILE type this routine is called * from filter().  The routine creates a sixel output stream to send * the printer based on the input data from an image file. Currently, * only a frame buffer image of raw red, green, blue points or a * GPX workstation "savimg"  image are valid data streams.  Sixel * output is initialized and then the processing begins. * The current design of the algorithm dithers the data to a 3 x 3 matrix * of points using the structure sixmap. */dosixel(){	register int i;	int xcnt,ycnt,n = 1,iindex,ij=0;	unsigned char	*srcptr;	unsigned char	*nxtptr;	unsigned short sl;	unsigned int	temp;	struct sixmap *Sixmap;	struct sixmap *Sixmap_offset;	char *base_band,*pb;	int base_band_length = 0;	int count = 1;	char lastc = 0;	register char *cp;	srcptr=(unsigned char *)imgptr;	ycnt=im.spbynm;	if(im.format != ITS)	    nxtptr=srcptr+im.spbxnm * n;	else	    nxtptr=srcptr+(im.spbxnm * n * 3);	pb = base_band = (char *)malloc((unsigned) 6 * im.spbxnm);	Sixmap = base_sixmap;	Sixmap_offset = offset_sixmap;	while((ycnt/n) * n) {		xcnt=im.spbxnm;		base_band_length = 0;		base_band = pb;		while(xcnt>0) {			if(MAXL_PIX_WIDTH - xcnt < 0) {				if(im.format != ITS)				    srcptr+=n;				else				    srcptr+=n*3;				xcnt-=n;				continue;			}			if(im.format != ITS) {				sl = *(cmpptr + 3*(*srcptr));			} else {				/* need to convert to YIQ */				temp= *srcptr++ * .30;				temp+= *srcptr++ * .59;				temp+= *srcptr * .11;				temp=(255-temp);				sl = (unsigned short)temp;			}			iindex = (sl * 9) / 255;			for(i=0;i<3;i++) {				*(base_band+i) = SOFF;			}			if(!ij) {				*base_band++ = Sixmap[iindex].s0;				*base_band++ = Sixmap[iindex].s1;				*base_band++ = Sixmap[iindex].s2;			} else {				*base_band++ = Sixmap_offset[iindex].s0;				*base_band++ = Sixmap_offset[iindex].s1;				*base_band++ = Sixmap_offset[iindex].s2;			}			base_band_length+=3;			srcptr+=n;			xcnt-=n;		}		if(!ij) {			cp = pb;			lastc = *cp++;			for(i=0;i < base_band_length;i++) {				if(*cp != lastc) {					if(count >= 4)					    fprintf(output,"!%d%c",count,lastc);					else					    while(count--)putc(lastc,output);					count = 1;					lastc = *cp;				} else count++;				cp++;			}			fprintf(output,"$");			count = 1;			ij++;		} else {			cp = pb;			lastc = *cp++;			for(i=0;i < base_band_length;i++) {				if(*cp != lastc) {					if(count >= 4)					    fprintf(output,"!%d%c",count,lastc);					else					    while(count--)						putc(lastc,output);					count = 1;					lastc = *cp;				} else				    count++;				cp++;			}			count = 1;			ij = 0;			fprintf(output,"-");		}		srcptr=nxtptr;		if(im.format != ITS)		    nxtptr=srcptr+im.spbxnm * n;		else		    nxtptr=srcptr+(im.spbxnm * n * 3);		ycnt-= n;			if(tmppagecount) {			tmplinecount--;			if(tmplinecount == 0) {				fprintf(output,"+");				tmppagecount--;				if(im.spbxnm >= MAXL_PIX_WIDTH) {					if(im.spbynm > MAXL_PIX_WIDTH) {						tmplinecount = MAXP_PIX_WIDTH;					}				}				if(im.spbxnm <= MAXP_PIX_WIDTH) {					if(im.spbynm > MAXP_PIX_HEIGHT) {						tmplinecount = MAXP_PIX_HEIGHT;					}				}			}		}	}	fprintf(output,"+");	fprintf(output,"\033\\");	return(0);}readXimghdr(){	register int tmp;	size=HEDLEN*512;	bcopy(filestorage+globi, (char *)&im, (int)size);	globi = globi + size;	if(im.imgflg != IMGFLG)		return(1);	if(im.format != QDSS || im.spbgnm != 1) {		if(im.format != ITS)			return(1);	}	if(im.format == ITS) {		tmp = im.spbxnm;		im.spbxnm = im.spbynm;		im.spbynm = tmp;		im.spblen = im.spblen * 3;	}	return(0);}readXimgcmp(){	if(im.format == ITS)		return(0);	size=im.cmplen*512;	if(size==0)		return(1);	if((cmpptr=(short *) malloc(size))==NULL)		return(1);	bcopy(filestorage+globi, (char *)cmpptr, (int)size);	globi = globi + size;	return(0);}readXimgdat(){	size=im.spblen*512;	if((imgptr=(char *) malloc(size))==NULL)		return(1);	bcopy(&filestorage[globi],imgptr,in-globi);	fread(imgptr+(in-globi), (char)size-(in-globi), 1, input);	return(0);}

⌨️ 快捷键说明

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