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

📄 postdmd.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
📖 第 1 页 / 共 2 页
字号:
 * * Handles things that must be done after the options are read but before the * input files are processed. * */    writerequest(0, stdout);		/* global requests eg. manual feed */    setencoding(fontencoding);		/* unnecessary */    fprintf(stdout, "setup\n");    if ( formsperpage > 1 )  {		/* followed by stuff for multiple pages */	if ( cat(formfile) == FALSE )	    error(FATAL, "can't read %s", formfile);	fprintf(stdout, "%d setupforms\n", formsperpage);    }	/* End if */    fprintf(stdout, "%s", ENDSETUP);}   /* End of setup *//*****************************************************************************/arguments(){    FILE	*fp;			/* next input file *//* * * Makes sure all the non-option command line arguments are processed. If we get * here and there aren't any arguments left, or if '-' is one of the input files * we'll process stdin. * */    if ( argc < 1 )	bitmap(stdin);    else  {				/* at least one argument is left */	while ( argc > 0 )  {	    if ( strcmp(*argv, "-") == 0 )		fp = stdin;	    else if ( (fp = fopen(*argv, "r")) == NULL )		error(FATAL, "can't open %s", *argv);	    bitmap(fp);	    if ( fp != stdin )		fclose(fp);	    argc--;	    argv++;	}   /* End while */    }   /* End else */}   /* End of arguments *//*****************************************************************************/done(){/* * * Finished with all the input files, so mark the end of the pages with a TRAILER * comment, make sure the last page prints, and add things like the PAGES comment * that can only be determined after all the input files have been read. * */    fprintf(stdout, "%s", TRAILER);    fprintf(stdout, "done\n");    fprintf(stdout, "%s 0 0 %d %d\n", BOUNDINGBOX, (bbox[0]*72+100)/100, (bbox[1]*72+100)/100);    fprintf(stdout, "%s %d\n", PAGES, printed);}   /* End of done *//*****************************************************************************/account(){/* * * Writes an accounting record to *fp_acct provided it's not NULL. Accounting is * requested using the -A or -J options. * */    if ( fp_acct != NULL )	fprintf(fp_acct, " print %d\n copies %d\n", printed, copies);}   /* End of account *//*****************************************************************************/bitmap(fp)    FILE	*fp;			/* next input file */{    int		count;			/* pattern repeats this many times */    long	total;			/* expect this many patterns *//* * * Reads all the bitmaps from the next input file, translates each one into * PostScript, and arranges to have one bitmap printed on each page. Multiple * bitmaps per input file work. * */    fp_in = fp;				/* everyone reads from this file */    while ( dimensions() == TRUE )  {	patcount = 0;	total = scanlines * patterns;	bbox[0] = MAX(bbox[0], patterns*16);	/* for BoundingBox comment */	bbox[1] = MAX(bbox[1], scanlines);	redirect(++page);	fprintf(fp_out, "%s %d %d\n", PAGE, page, printed+1);	fprintf(fp_out, "/saveobj save def\n");	writerequest(printed+1, fp_out);	fprintf(fp_out, "%s ", (v8format == TRUE && v8undo == FALSE) ? "true" : "false");	fprintf(fp_out, "%s ", (flip == TRUE) ? "true" : "false");	fprintf(fp_out, "%d %d bitmap\n", patterns * 16, scanlines);	while ( patcount != total && (count = getc(fp)) != EOF )  {	    addrast(count);	    patcount += (count & 0177);	    if ( patcount % patterns == 0 )		putrast();	}   /* End while */	if ( debug == ON )	    fprintf(stderr, "patterns = %d, scanlines = %d, patcount = %d\n", patterns, scanlines, patcount);	if ( total != patcount )	    error(FATAL, "bitmap format error");	if ( fp_out == stdout ) printed++;	fprintf(fp_out, "showpage\n");	fprintf(fp_out, "saveobj restore\n");	fprintf(fp_out, "%s %d %d\n", ENDPAGE, page, printed);    }	/* End while */}   /* End of bitmap *//*****************************************************************************/dimensions(){    int		ox, oy;			/* coordinates of the origin */    int		cx, cy;			/* and right corner of the bitmap */    int		i;			/* loop index *//* * * Determines the dimensions and type of the next bitmap. Eighth edition bitmaps * have a zero in the first 16 bits. If valid dimensions are read TRUE is returned * to the caller. Changed so the check of whether we're done (by testing scanlines * or patterns) comes before the malloc(). * */    if ( (scanlines = getint()) == 0 )  {	ox = getint();	oy = getint();	cx = getint();	cy = getint();	scanlines = cy - oy;	patterns = (cx - ox + 15) / 16;	v8format = TRUE;    } else patterns = getint();    if ( scanlines <= 0 || patterns <= 0 )	/* done - don't do the malloc() */	return(FALSE);    if ( raster != NULL ) free(raster);    if ( prevrast != NULL ) free(prevrast);    if ( (rptr = raster = (char *) malloc(patterns * 2)) == NULL )	error(FATAL, "no memory");    if ( (prevrast = (char *) malloc(patterns * 2)) == NULL )	error(FATAL, "no memory");    for ( i = 0; i < patterns * 2; i++ )	*(prevrast+i) = 0377;    eptr = rptr + patterns * 2;    return(TRUE);}   /* End of dimensions *//*****************************************************************************/addrast(count)    int		count;			/* repeat count for next pattern */{    int		size;			/* number of bytes in next pattern */    int		l, h;			/* high and low bytes */    int		i, j;			/* loop indices *//* * * Reads the input file and adds the appropriate number of bytes to the output * raster line. If count has bit 7 on, one 16 bit pattern is read and repeated * count & 0177 times. If bit 7 is off, count is the number of patterns read from * fp_in - each one repeated once. * */    if ( count & 0200 )  {	size = 1;	count &= 0177;    } else {	size = count;	count = 1;    }	/* End else */    for ( i = size; i > 0; i-- )  {	if ( (l = getc(fp_in)) == EOF || (h = getc(fp_in)) == EOF )	    return;	for ( j = count; j > 0; j-- )  {	    *rptr++ = l;	    *rptr++ = h;	}   /* End for */    }	/* End for */}   /* End of addrast *//*****************************************************************************/putrast(){    char	*p1, *p2;		/* starting and ending patterns */    int		n;			/* set to bytes per pattern */    int		i;			/* loop index *//* * * Takes the scanline that's been saved in *raster, encodes it according to the * value that's been assigned to bytespp, and writes the result to *fp_out. Each * line in the output bitmap is terminated by a 0 on a line by itself. * */    n = (bytespp <= 0) ? 2 * patterns : bytespp;    if ( v8format == TRUE && v8undo == TRUE )	for ( i = 0; i < patterns * 2; i++ )	    *(raster+i) = (*(prevrast+i) ^= *(raster+i));    for ( p1 = raster, p2 = raster + n; p1 < eptr; p1 = p2 )	if ( patncmp(p1, n) == TRUE )  {	    while ( patncmp(p2, n) == TRUE ) p2 += n;	    p2 += n;	    fprintf(fp_out, "%d ", n);	    for ( i = 0; i < n; i++, p1++ )		fprintf(fp_out, "%.2X", ((int) *p1) & 0377);	    fprintf(fp_out, " %d\n", (p2 - p1) / n);	} else {	    while ( p2 < eptr && patncmp(p2, n) == FALSE ) p2 += n;	    if ( p2 > eptr ) p2 = eptr;	    fprintf(fp_out, "%d ", p2 - p1);	    while ( p1 < p2 )		fprintf(fp_out, "%.2X", ((int) *p1++) & 0377);	    fprintf(fp_out, " 0\n");	}   /* End else */    fprintf(fp_out, "0\n");    rptr = raster;}   /* End of putrast *//*****************************************************************************/patncmp(p1, n)    char	*p1;			/* first patterns starts here */    int		n;			/* and extends this many bytes */{    char	*p2;			/* address of the second pattern *//* * * Compares the two n byte patterns *p1 and *(p1+n). FALSE is returned if they're * different or extend past the end of the current raster line. * */    p2 = p1 + n;    for ( ; n > 0; n--, p1++, p2++ )	if ( p2 >= eptr || *p1 != *p2 )	    return(FALSE);    return(TRUE);}   /* End of patncmp *//*****************************************************************************/getint(){    int		h, l;			/* high and low bytes *//* * * Reads the next two bytes from *fp_in and returns the resulting integer. * */    if ( (l = getc(fp_in)) == EOF || (h = getc(fp_in)) == EOF )	return(-1);    return((h & 0377) << 8 | (l & 0377));}   /* End of getint *//*****************************************************************************/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 + -