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

📄 opostdaisy.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
📖 第 1 页 / 共 2 页
字号:
    int		i;			/* loop index *//* * * Clears all horizontal and vertical tab stops. * */    for ( i = 0; i < ROWS; i++ )	htabstops[i] = OFF;    for ( i = 0; i < COLUMNS; i++ )	vtabstops[i] = OFF;}   /* End of cleartabs *//*****************************************************************************/formfeed(){/* * * Called whenever we've finished with 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 what's done. I've added a simple test before the showpage that * should eliminate the extra blank page that was put out at the end of many jobs, * but the PAGES comments may be wrong. * */    if ( fp_out == stdout )		/* count the last page */	printed++;    endline();				/* print the last line */    fprintf(fp_out, "cleartomark\n");    if ( feof(fp_in) == 0 || markedpage == TRUE )	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);    vgoto(topmargin);    hgoto(leftmargin);    markedpage = FALSE;}   /* End of formfeed *//*****************************************************************************/linefeed(){    int		line = 0;		/* current line - based on ovmi *//* * * Adjust our current vertical position. If we've passed the bottom of the page * or exceeded the number of lines per page, print it and go to the upper left * corner of the next page. This routine is also called from carriage() if crislf * is ON. * */    vmot(vmi);    if ( lfiscr == ON )	hgoto(leftmargin);    if ( linespp > 0 )			/* means something so see where we are */	line = vpos / ovmi + 1;    if ( vpos > bottommargin || line > linespp )	formfeed();}   /* End of linefeed *//*****************************************************************************/carriage(){/* * * Handles carriage return character. If crislf is ON we'll generate a line feed * every time we get a carriage return character. * */    if ( shadowprint == ON )		/* back to normal mode */	changefont(fontname);    advance = 1;    shadowprint = OFF;    hgoto(leftmargin);    if ( crislf == ON )	linefeed();}   /* End of carriage *//*****************************************************************************/htab(){    int		col;			/* 'column' we'll be at next */    int		i;			/* loop index *//* * * Tries to figure out where the next tab stop is. Wasn't positive about this * one, since hmi can change. I'll assume columns are determined by the original * value of hmi. That fixes them on the page, which seems to make more sense than * letting them float all over the place. * */    endline();    col = hpos/ohmi + 1;    for ( i = col; i < ROWS; i++ )	if ( htabstops[i] == ON )  {	    col = i;	    break;	}   /* End if */    hgoto(col * ohmi);    lastx = hpos;}   /* End of htab *//*****************************************************************************/vtab(){    int		line;			/* line we'll be at next */    int		i;			/* loop index *//* * * Looks for the next vertical tab stop in the vtabstops[] array and moves to that * line. If we don't find a tab we'll just move down one line - shouldn't happen. * */    endline();    line = vpos/ovmi + 1;    for ( i = line; i < COLUMNS; i++ )	if ( vtabstops[i] == ON )  {	    line = i;	    break;	}   /* End if */    vgoto(line * ovmi);}   /* End of vtab *//*****************************************************************************/backspace(){/* * * Moves backwards a distance equal to the current value of hmi, but don't go * past the left margin. * */    endline();    if ( hpos - leftmargin >= hmi )	hmot(-hmi);    else hgoto(leftmargin);		/* maybe just ignore the backspace?? */    lastx = hpos;}   /* End of backspace *//*****************************************************************************/escape(){    int		ch;			/* control character *//* * * Handles special codes that are expected to follow an escape character. The * initial escape character is followed by one or two bytes. * */    switch ( ch = getc(fp_in) ) {	case 'T':			/* top margin */		topmargin = vpos;		break;	case 'L':			/* bottom margin */		bottommargin = vpos;		break;	case 'C':			/* clear top and bottom margins */		bottommargin = BOTTOMMARGIN;		topmargin = TOPMARGIN;		break;	case '9':			/* left margin */		leftmargin = hpos;		break;	case '0':			/* right margin */		rightmargin = hpos;		break;	case '1':			/* set horizontal tab */		htabstops[hpos/ohmi] = ON;		break;	case '8':			/* clear horizontal tab at hpos */		htabstops[hpos/ohmi] = OFF;		break;	case '-':			/* set vertical tab */		vtabstops[vpos/ovmi] = ON;		break;	case '2':			/* clear all tabs */		cleartabs();		break;	case '\014':			/* set lines per page */		linespp = getc(fp_in);		break;	case '\037':			/* set hmi to next byte minus 1 */		hmi = HSCALE * (getc(fp_in) - 1);		break;	case 'S':			/* reset hmi to default */		hmi = ohmi;		break;	case '\011':			/* move to column given by next byte */		hgoto((getc(fp_in)-1) * ohmi);		break;	case '?':			/* do carriage return after line feed */		lfiscr = ON;		break;	case '!':			/* don't generate carriage return */		lfiscr = OFF;		break;	case '5':			/* forward print mode */		advance = 1;		break;	case '6':			/* backward print mode */		advance = -1;		break;	case '\036':			/* set vmi to next byte minus 1 */		vmi = VSCALE * (getc(fp_in) - 1);		break;	case '\013':			/* move to line given by next byte */		vgoto((getc(fp_in)-1) * ovmi);		break;	case 'U':			/* positive half line feed */		vmot(vmi/2);		break;	case 'D':			/* negative half line feed */		vmot(-vmi/2);		break;	case '\012':			/* negative line feed */		vmot(-vmi);		break;	case '\015':			/* clear all margins */		bottommargin = BOTTOMMARGIN;		topmargin = TOPMARGIN;		leftmargin = BOTTOMMARGIN;		rightmargin = RIGHTMARGIN;		break;	case 'E':			/* auto underscore - use italic font */		changefont("/Courier-Oblique");		break;	case 'R':			/* disable auto underscore */		changefont(fontname);		break;	case 'O':			/* bold/shadow printing */	case 'W':		changefont("/Courier-Bold");		shadowprint = ON;		break;	case '&':			/* disable bold printing */		changefont(fontname);		shadowprint = OFF;		break;	case '/':			/* ignored 2 byte escapes */	case '\\':	case '<':	case '>':	case '%':	case '=':	case '.':	case '4':	case 'A':	case 'B':	case 'M':	case 'N':	case 'P':	case 'Q':	case 'X':	case '\010':		break;	case ',':			/* ignored 3 byte escapes */	case '\016':	case '\021':		getc(fp_in);		break;	case '3':			/* graphics mode - should quit! */	case '7':	case 'G':	case 'V':	case 'Y':	case 'Z':		error(FATAL, "graphics mode is not implemented");		break;	default:		error(FATAL, "missing case for escape o%o\n", ch);		break;    }	/* End switch */}   /* End of escape *//*****************************************************************************/vmot(n)    int		n;			/* move this far vertically */{/* * * Move vertically n units from where we are. * */    vpos += n;}   /* End of vmot *//*****************************************************************************/vgoto(n)    int		n;			/* new vertical position */{/* * * Moves to absolute vertical position n. * */    vpos = n;}   /* End of vgoto *//*****************************************************************************/hmot(n)    int		n;			/* move this horizontally */{/* * * Moves horizontally n units from our current position. * */    hpos += n * advance;    if ( hpos < leftmargin )	hpos = leftmargin;}   /* End of hmot *//*****************************************************************************/hgoto(n)    int		n;			/* go to this horizontal position */{/* * * Moves to absolute horizontal position n. * */    hpos = n;}   /* End of hgoto *//*****************************************************************************/changefont(name)    char	*name;{/* * * Changes the current font. Used to get in and out of auto underscore and bold * printing. * */    endline();    fprintf(fp_out, "%s f\n", name);}   /* End of changefont *//*****************************************************************************/startline(){/* * * Called whenever we want to be certain we're ready to start pushing characters * into an open string on the stack. If stringcount is positive we've already * started, so there's nothing to do. The first string starts in column 1. * */    if ( stringcount < 1 )  {	putc('(', fp_out);	stringstart = lastx = hpos;	lasty = vpos;	lasthmi = hmi;	lastc = -1;	prevx = -1;	stringcount = 1;    }	/* End if */}   /* End of startline *//*****************************************************************************/endline(){/* * * Generates a call to the PostScript procedure that processes the text on the * the stack - provided stringcount is positive. * */    if ( stringcount > 0 )	fprintf(fp_out, ")%d %d %d t\n", stringstart, lasty, lasthmi);    stringcount = 0;}   /* End of endline *//*****************************************************************************/endstring(){/* * * Takes the string we've been working on and adds it to the output file. Called * when we need to adjust our horizontal position before starting a new string. * Also called from endline() when we're done with the current line. * */    if ( stringcount > 0 )  {	fprintf(fp_out, ")%d(", stringstart);	lastx = stringstart = hpos;	stringcount++;    }	/* End if */}   /* End of endstring *//*****************************************************************************/oput(ch)    int		ch;			/* next output character */{/* * * Responsible for adding all printing characters from the input file to the * open string on top of the stack. The only other characters that end up in * that string are the quotes required for special characters. Reverse printing * mode hasn't been tested but it should be close. hpos and lastx should disagree * each time (except after startline() does something), and that should force a * call to endstring() for every character. * */    if ( stringcount > 100 )		/* don't put too much on the stack */	endline();    if ( vpos != lasty )	endline();    if ( advance == -1 )		/* for reverse printing - move first */	hmot(hmi);    startline();    if ( lastc != ch || hpos != prevx )  {	if ( lastx != hpos )	    endstring();	if ( ch == '\\' || ch == '(' || ch == ')' )	    putc('\\', fp_out);	putc(ch, fp_out);	lastc = ch;	prevx = hpos;	lastx += lasthmi;    }	/* End if */    if ( advance != -1 )	hmot(hmi);    markedpage = TRUE;}   /* End of oput *//*****************************************************************************/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 + -