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

📄 posttek.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
📖 第 1 页 / 共 2 页
字号:
	case CR:		x = margin;		break;	case VT:		if ((y += charheight[tekfont]) >= TEKYMAX)		    y = 0;		break;	case HT:	case ' ':	default:		if ( characters++ == 0 )		    fprintf(fp_out, "%d %d (", cursor.x, cursor.y);		switch ( c )  {		    case '(':		    case ')':		    case '\\':			putc('\\', fp_out);		    default:			putc(c, fp_out);		}   /* End switch */		x += charwidth[tekfont];		move(x, y);		break;    }	/* End switch */    if (x >= TEKXMAX) {	x = margin;	y -= charheight[tekfont];    }	/* End if */    if (y < 0) {	y = TEKYMAX - charheight[tekfont];	x -= margin;	margin = (TEKXMAX/2) - margin;	if ((x += margin) > TEKXMAX)	    x -= margin;    }	/* End if */    if ( y != cursor.y || x != cursor.x )	text();    move(x, y);}   /* End of alpha *//*****************************************************************************/graph(){    int			c;		/* next character */    int			b;		/* for figuring out loy */    int			x, y;		/* next point in the vector */    static int		hix, hiy;	/* upper */    static int		lox, loy;	/* and lower part of the address */    static int		extra;		/* for extended addressing *//* * * Handles things when we're in GRAPH, POINT, or SPECIALPOINT mode. * */    if ((c = nextchar()) < 040) {	control(c);	return;    }	/* End if */    if ((c & 0140) == 040) {		/* new hiy */	hiy = c & 037;	do	    if (((c = nextchar()) < 040) && ((c = control(c)) == OUTMODED))		return;	while (c == 0);    }	/* End if */    if ((c & 0140) == 0140) {		/* new loy */	b = c & 037;	do	    if (((c = nextchar()) < 040) && ((c = control(c)) == OUTMODED))		return;	while (c == 0);	if ((c & 0140) == 0140) {	/* no, it was extra */	    extra = b;	    loy = c & 037;	    do		if (((c = nextchar()) < 040) && ((c = control(c)) == OUTMODED))		    return;	    while (c == 0);	} else loy = b;    }	/* End if */    if ((c & 0140) == 040) {		/* new hix */	hix = c & 037;	do	    if (((c = nextchar()) < 040) && ((c = control(c)) == OUTMODED))		return;	while (c == 0);    }	/* End if */    lox = c & 037;			/* this should be lox */    if (extra & 020)	margin = TEKXMAX/2;    x = (hix<<7) | (lox<<2) | (extra & 03);    y = (hiy<<7) | (loy<<2) | ((extra & 014)>>2);    if ( points > 100 )  {		/* don't put too much on the stack */	draw();	points = 1;    }	/* End if */    if ( points++ )	fprintf(fp_out, "%d %d\n", cursor.x - x, cursor.y - y);    move(x, y);				/* adjust the cursor */}   /* End of graph *//*****************************************************************************/point(){    int		c;			/* next input character *//* * * Special point mode permits gray scaling by varying the size of the stored * point, which is controlled by an intensity character that preceeds each point * address. * */    if ( dispmode == SPECIALPOINT )  {	if ( (c = nextchar()) < 040 || c > 0175 )	    return(control(c));	fprintf(fp_out, "%d %d i\n", intensity[c - ' '], c & 0100);    }	/* End if */    graph();    draw();}   /* End of point *//*****************************************************************************/incremental(){    int		c;			/* for the next few characters */    int		x, y;			/* cursor position when we're done *//* * * Handles incremental plot mode. It's entered after the RS control code and is * used to mark points relative to our current position. It's typically followed * by one or two bytes that set the pen state and are used to increment the * current position. * */    if ( (c = nextchar()) == OUTMODED )	return;    if ( (c < 040) && ((c = control(c)) <= 0) )	return;    x = cursor.x;			/* where we are right now */    y = cursor.y;    if ( c & 060 )	pen = ( c & 040 ) ? UP : DOWN;    if ( c & 04 ) y++;    if ( c & 010 ) y--;    if ( c & 01 ) x++;    if ( c & 02 ) x--;    move(x, y);    if ( pen == DOWN )  {	points = 1;	draw();    }	/* End if */}   /* End of incremental *//*****************************************************************************/gin(){/* * * All we really have to do for GIN mode is make sure it's properly ended. * */    control(nextchar());}   /* End of gin *//*****************************************************************************/control(c)    int		c;			/* check this control character */{/* * * Checks character c and does special things, like mode changes, that depend * not only on the character, but also on the current state. If the mode changed * becuase of c, OUTMODED is returned to the caller. In all other cases the * return value is c or 0, if c doesn't make sense in the current mode. * */    switch ( c )  {	case BEL:		return(0);	case BS:	case HT:	case VT:		return(dispmode == ALPHA ? c : 0);	case CR:		if ( dispmode != ALPHA )  {		    setmode(ALPHA);		    ungetc(c, fp_in);		    return(OUTMODED);		} else return(c);	case FS:		if ( (dispmode == ALPHA) || (dispmode == GRAPH) )  {		    setmode(POINT);		    return(OUTMODED);		}   /* End if */		return(0);	case GS:		if ( (dispmode == ALPHA) || (dispmode == GRAPH) )  {		    setmode(GRAPH);		    return(OUTMODED);		}   /* End if */		return(0);	case NL:		ungetc(CR, fp_in);		return(dispmode == ALPHA ? c : 0);	case RS:		if ( dispmode != GIN )  {		    setmode(INCREMENTAL);		    return(OUTMODED);		}   /* End if */		return(0);	case US:		if ( dispmode == ALPHA )		    return(0);		setmode(ALPHA);		return(OUTMODED);	case ESC:		return(esc());	case OUTMODED:		return(c);	default:		return(c < 040 ? 0 : c);    }	/* End switch */}   /* End of control *//*****************************************************************************/esc(){    int		c;			/* next input character */    int		ignore;			/* skip it if nonzero *//* * * Handles tektronix escape code. Called from control() whenever an ESC character * is found in the input file. * */    do  {	c = nextchar();	ignore = 0;	switch ( c )  {	    case CAN:		    return(0);	    case CR:		    ignore = 1;		    break;	    case ENQ:		    setmode(ALPHA);		    return(OUTMODED);	    case ETB:		    return(0);	    case FF:		    formfeed();		    setmode(ALPHA);		    return(OUTMODED);	    case FS:		    if ( (dispmode == INCREMENTAL) || ( dispmode == GIN) )			return(0);		    setmode(SPECIALPOINT);		    return(OUTMODED);	    case SI:	    case SO:		    return(0);	    case SUB:		    setmode(GIN);		    return(OUTMODED);	    case OUTMODED:		    return(OUTMODED);	    case '8':	    case '9':	    case ':':	    case ';':		    setfont(c - '8');		    return(0);	    default:		    if ( c == '?' && dispmode == GRAPH )			return(DEL);		    if ( (c<'`') || (c>'w') )			break;		    c -= '`';		    if ( (c & 010) != linetype )			fprintf(fp_out, "%d w\n", (linetype = (c & 010))/010);		    if ( ((c + 1) & 7) >= 6 )			break;		    if ( (c + 1) & 7 )			if ( (c & 7) != linestyle )  {			    linestyle = c & 7;			    setmode(dispmode);			    fprintf(fp_out, "%s l\n", styles[linestyle]);			}   /* End if */		    return(0);	}   /* End switch */    } while (ignore);    return(0);}   /* End of esc *//*****************************************************************************/move(x, y)    int		x, y;			/* move the cursor here */{/* * * Moves the cursor to the point (x, y). * */    cursor.x = x;    cursor.y = y;}   /* End of move *//*****************************************************************************/setmode(mode)    int		mode;			/* this should be the new mode */{/* * * Makes sure the current mode is properly ended and then sets dispmode to mode. * */    switch ( dispmode )  {	case ALPHA:		text();		break;	case GRAPH:		draw();		break;	case INCREMENTAL:		pen = UP;		break;    }	/* End switch */    dispmode = mode;}   /* End of setmode *//*****************************************************************************/home(){/* * * Makes sure the cursor is positioned at the upper left corner of the page. * */    margin = 0;    move(0, TEKYMAX);}   /* End of home *//*****************************************************************************/setfont(newfont)    int		newfont;		/* use this font next */{/* * * Generates the call to the procedure that's responsible for changing the * tektronix font (really just the size). * */    if ( newfont != tekfont )  {	setmode(dispmode);	fprintf(fp_out, "%d f\n", charwidth[newfont]);    }	/* End if */    tekfont = newfont;}   /* End of setfont *//*****************************************************************************/text(){/* * * Makes sure any text we've put on the stack is printed. * */    if ( dispmode == ALPHA && characters > 0 )	fprintf(fp_out, ") t\n");    characters = 0;}   /* End of text *//*****************************************************************************/draw(){/* * * Called whenever we need to draw a vector or plot a point. Nothing will be * done if points is 0 or if it's 1 and we're in GRAPH mode. * */    if ( points > 1 )			/* it's a vector */	fprintf(fp_out, "%d %d v\n", cursor.x, cursor.y);    else if ( points == 1 && dispmode != GRAPH )	fprintf(fp_out, "%d %d p\n", cursor.x, cursor.y);    points = 0;}   /* End of draw *//*****************************************************************************/formfeed(){/* * * Usually called when we've finished the last page and want to get ready for the * next one. Also used at the beginning and end of each input file, so we have to * be careful about exactly what's done. * */    setmode(dispmode);			/* end any outstanding text or graphics */    if ( fp_out == stdout )		/* count the last page */	printed++;    fprintf(fp_out, "cleartomark\n");    fprintf(fp_out, "showpage\n");    fprintf(fp_out, "saveobj restore\n");    fprintf(fp_out, "%s %d %d\n", ENDPAGE, page, printed);    if ( ungetc(getc(fp_in), fp_in) == EOF )	redirect(-1);    else redirect(++page);    fprintf(fp_out, "%s %d %d\n", PAGE, page, printed+1);    fprintf(fp_out, "/saveobj save def\n");    fprintf(fp_out, "mark\n");    writerequest(printed+1, fp_out);    fprintf(fp_out, "%d pagesetup\n", printed+1);    fprintf(fp_out, "%d f\n", charwidth[tekfont]);    fprintf(fp_out, "%s l\n", styles[linestyle]);    home();}   /* End of formfeed *//*****************************************************************************/nextchar(){    int		ch;			/* next input character *//* * * Reads the next character from the current input file and returns it to the * caller. When we're finished with the file dispmode is set to EXIT and OUTMODED * is returned to the caller. * */    if ( (ch = getc(fp_in)) == EOF )  {	setmode(EXIT);	ch = OUTMODED;    }	/* End if */    return(ch);}   /* End of nextchar *//*****************************************************************************/redirect(pg)    int		pg;			/* next page we're printing */{    static FILE	*fp_null = NULL;	/* if output is turned off *//* * * If we're not supposed to print page pg, fp_out will be directed to /dev/null, * otherwise output goes to stdout. * */    if ( pg >= 0 && in_olist(pg) == ON )	fp_out = stdout;    else if ( (fp_out = fp_null) == NULL )	fp_out = fp_null = fopen("/dev/null", "w");}   /* End of redirect *//*****************************************************************************/

⌨️ 快捷键说明

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