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

📄 printjob.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 4 页
字号:
		build_filter(fcp, &escapes, PP ? PP : PR,			     width, length, "-h", title, 0);		if (IF) {			build_filter(fcp, &escapes, IF,				     width, length, indent,				     "-n", logname, "-h", fromhost, AF, 0);			if (enable_IF_pipe_OF) retcode = BFC_USE_OUTPUT_FILTER;		} else {			retcode = BFC_USE_OUTPUT_FILTER;		}		break;	    case 'f':		/* print plain text using IF */		if (IF) {			build_filter(fcp, &escapes, IF,				     width, length, indent,				     "-n", logname, "-h", fromhost, AF, 0);			if (enable_IF_pipe_OF) {				retcode = BFC_USE_OUTPUT_FILTER;			}		} else {			retcode = BFC_USE_OUTPUT_FILTER;		}		break;	    case 'l':		/* like 'f', pass Ctrl chars */		if (IF) {			build_filter(fcp, &escapes, IF,				     "-c", width, length, indent,				     "-n", logname, "-h", fromhost, AF, 0);			if (enable_IF_pipe_OF) {				retcode = BFC_USE_OUTPUT_FILTER;			}		} else {			retcode = BFC_USE_OUTPUT_FILTER;		}		break;	    case 'r':		/* print fortran text file */		build_filter(fcp, &escapes, RF,			     width, length,			     "-n", logname, "-h", fromhost, AF, 0);		break;	    case 'n':		/* print ditroff output */		build_filter(fcp, &escapes, NF,			     "-c", width, length, indent,			     "-n", logname, "-h", fromhost, AF, 0);		break;	    case 't':		/* print troff output */	    case 'd':		/* print tex output */		(void) unlink(".railmag");		if ((fd = creat(".railmag", FILMOD)) < 0) {			log("cannot create .railmag");			(void) unlink(".railmag");		} else {			for (i=0; i < 4; i++) {				if (fonts[i][0] != '/')				    (void) write(fd, vfpre, strlen(vfpre));				(void) write(fd, fonts[i], strlen(fonts[i]));				(void) write(fd, "\n", 1);			}			(void) close(fd);		}		build_filter(fcp, &escapes, (format == 't') ? TF : DF,			     pxwidth, pxlength,			     "-n", logname, "-h", fromhost, AF, 0);		break;	    case 'c':		/* print cifplot output */		build_filter(fcp, &escapes, CF,			     pxwidth, pxlength,			     "-n", logname, "-h", fromhost, AF, 0);		break;	    case 'g':		/* print plot(1G) output */		build_filter(fcp, &escapes, GF,			     pxwidth, pxlength,			     "-n", logname, "-h", fromhost, AF, 0);		break;	    case 'v':		/* print raster output */		build_filter(fcp, &escapes, VF,			     pxwidth, pxlength,			     "-n", logname, "-h", fromhost, AF, 0);		break;	    case 'x':		/* print via pass-thru filter */		build_filter(fcp, &escapes, XF, 0);		break;	    case 'z':		build_filter(fcp, &escapes, pc_layup, 0);		break;	    default:		log("illegal format character '%c'", format);		retcode = BFC_ERR;		break;	}	es_delete(&escapes);	return retcode;}/* * open_output_filter -- if OF is specified in printcap open it */voidopen_output_filter(cxp)register CXP cxp;{	(*open_output_filter_sw[(int)printer_type])(cxp);}/* * open_of -- if OF is specified in printcap open it */static voidopen_of(cxp)register CXP cxp;{	if (OF) {		struct escapes escapes;	/* escapes */		cxp->cx_output_filter = new_fc();		es_init(&escapes, printcap_escapes);		build_filter(cxp->cx_output_filter, &escapes, OF,			     width, length, 0);		es_delete(&escapes);		fc_plumb_and_run(cxp->cx_output_filter, DOABORT,				 FC_MAKEPIPE, cxp->cx_pr_fd, 2);		cxp->cx_out_fd = cxp->cx_output_filter->fc_fds[FC_STDIN];	} else {		cxp->cx_out_fd = cxp->cx_pr_fd;	}}/* * open_of_and_errorof -- if OF is specified in printcap open it * * Description: *	Also opens up the lpserrof filter. *	This filter processes the stderr output of the lpscomm *	filter and processes it accordingly. *	The plumbing of lpscomm and lpserrof are as follows: * *	---------------------------------------------------------------- *	lpscomm: *	fds:	0	...	pipe A from lpd *		1	...	closed *		2	...	pipe B to lpserrof * *	---------------------------------------------------------------- *	lpserrof: *	fds:	0	...	pipe B from lpscomm *		1	...	pipe C to lpd *		2	...	copy of lpd fd 2 (to log file) * *	---------------------------------------------------------------- */static voidopen_of_and_errorof(cxp)register CXP cxp;{	register FCP err_fcp;	struct escapes escapes;	/* escapes */	char debug_level[8];	cxp->cx_output_filter = new_fc();	err_fcp = cxp->cx_output_filter->fc_next = new_fc();	es_init(&escapes, printcap_escapes);	build_filter(cxp->cx_output_filter, &escapes, OF,		     width, length, 0);	es_delete(&escapes);	sprintf(debug_level, "%d", DB);	fc_add_args_l(err_fcp, "lpserrof",		      "-d", debug_level,		      "-U", logname,		      "-H", fromhost,		      "-P", printer,		      0);	if (!strcmp(message, "keep")) {		fc_add_args_l(err_fcp,			      "-J", job_id,			      0);	}	if (AF) fc_add_args_l(err_fcp,			      "-A", AF,			      0);	fc_end_filter(err_fcp);	fc_plumb_and_run(err_fcp, DOABORT,			 FC_MAKEPIPE, FC_MAKEPIPE, 2);		fc_plumb_and_run(cxp->cx_output_filter, DOABORT,			 FC_MAKEPIPE,			 cxp->cx_pr_fd,			 err_fcp->fc_fds[FC_STDIN]);	/*	 * lpd doesn't want to write to lpserrof so we	 * must close spare pipe end	 */	(void) close(err_fcp->fc_fds[FC_STDIN]);	cxp->cx_out_fd = cxp->cx_output_filter->fc_fds[FC_STDIN];}static enum job_status_eprintit(cxp, command_file)register CXP cxp;register char *command_file;		/* name of command file */{	FILE *cfp;		/* control file */	register int command;	register char *line_param = &line[1];	struct dcl_job job;	/* build job description here */	enum job_status_e job_status = js_ok;	int first_file_found=0;	/* flag for first file to print */	/*	 * tof usage:	 *	While we are building the job tof is diddled to	 *	indicate the state the printer WILL be in when	 *	the job is actually printed.	 *	When we return from printit(), reality has caught up	 */	sprintf(job_id, "%d", atoi(command_file+3)); /* used by PS flagpage */	if ((cfp = fopen(command_file, "r")) == NULL) {		log("open failure (%d) of control file %s", errno, command_file);		return(js_failed); /* used to return ok */	}	/*  # format of command file produced by lpr #	 *	 *  H	<host> host name on banner page	 *  P	<user> user's login name	 *  J	<job> job name on banner page	 *  C	<class> class name on banner page	 *  L	<user> literal user name on banner page	 *  I	<num> amount to indent output for f and l filters	 *  M	<user> mail user on completion	 *  1	<font> R font file for troff, ditroff and TeX	 *  2	<font> I font file for troff, ditroff and TeX	 *  3	<font> B font file for troff, ditroff and TeX	 *  4	<font> S font file for troff, ditroff and TeX	 *  W	<num> width used by pr filter	 *  Z	<num> length used by pr filter	 * *D	<data_type> (ansi | regis | tek4014 | postscript)	 * *<	<input_tray> (top | middle | bottom)	 * *>	<output_tray> (top | side | face-up)	 * *O	<orientation> (portrait | landscape)	 * *F	<page_size> (a | a3 | a4 | a5 | b | b4 | b5 | ex | leg	 *		| c4 | c5 | dl | 10x13 | 9x12 | bus)	 * *S	<sheet_size> (a | a3 | a4 | a5 | b | b4 | b5 | ex | leg	 *		| c4 | c5 | dl | 10x13 | 9x12 | bus)	 * *E	<message> (print | keep | p+k | ign)	 * *X	<num> [1,10000] sheet count	 * *A	<num> [1,10000] lower page limit	 * *B	<num> [1,10000] upper page limit	 * *G	<num> [1,100] number up	 * *z	<filename> layup definition file	 * *K	<sides> (1 | 2 | tumble | one_sided_duplex	 *		| one_sided_tumble | two_sided_simplex)	 *  T	<title> header for pr filter	 *  f	<file name> text file	 *  p	<file name> text file for pr filter	 *  l	<file name> text file with control chars	 *  t	<file name> troff file	 *  n	<file name> ditroff file	 *  d	<file name> TeX file	 *  g	<file name> plot file	 *  v	<file name> raster file	 *  c	<file name> cifplot file	 *  r	<file name> FORTRAN file	 *  x	<file name> file for transparent filter	 *  U	<file name> unlink file after printing/spooling	 *  N	<name> name of first file (used by lpq)	 * 	 */	dj_init(&job, cxp,		&job_build_sw_per_printer[(int)printer_type]);	while (getline(cfp))	    switch(command = line[0]) {		case 'H':		    sprintf(fromhost, format_ncpy, PARAM_LEN, line_param);		    if (class[0] == '\0')			sprintf(class, format_ncpy, CLASS_LEN, line_param);		    continue;		case 'P':		    sprintf(logname, format_ncpy, PARAM_LEN, line_param);		    if (RS) {	/* restricted */			    if (getpwnam(logname) == (struct passwd *)0) {				    job_status = js_restricted;				    goto xpass2;			    }		    }		    continue;		case 'J':		    /* at least 1 char */		    sprintf(jobname, "%1.*s", PARAM_LEN, line_param);		    continue;		case 'C':		    if (*line_param != '\0')			sprintf(class, format_ncpy, CLASS_LEN, line_param);		    else if (class[0] == '\0')			gethostname(class, sizeof (class));		    continue;		case 'T':	/* header title for pr */		    /* set to " " if title is null string */		    sprintf(title, "%1.*s", TITLE_LEN, line_param);		    continue;		case '1':	/* troff fonts */		case '2':		case '3':		case '4':		    if (*line_param != '\0')			strcpy(fonts[command-'1'], line_param);		    continue;		case 'Z':	/* page length */		    strcpy(length+2, line_param);		    cf_W_or_Z_found = 1;		    continue;		case 'W':	/* page width */		    strcpy(width+2, line_param);		    cf_W_or_Z_found = 1;		    continue;		case 'I':	/* indent amount */		    strcpy(indent+2, line_param);		    continue;		    /* Here are the new ones for PostScript printers */		case 'L':		    if (!SH)			sprintf(username, format_ncpy, PARAM_LEN, line_param);		    continue;		case 'D':		    sprintf(datatype, format_ncpy, DATATYPE_LEN, line_param);		    continue;		case '<':		    sprintf(input_tray, format_ncpy, PARAM_LEN, line_param);		    continue;		case '>':		    sprintf(output_tray, format_ncpy, PARAM_LEN, line_param);		    continue;		case 'O':		    sprintf(orientation, format_ncpy, PARAM_LEN, line_param);		    cf_O_found = 1;		    continue;		case 'F':		    sprintf(pagesize, format_ncpy, PARAM_LEN, line_param);		    continue;		case 'S':		    sprintf(sheetsize, format_ncpy, PARAM_LEN, line_param);		    continue;		case 'E':		    sprintf(message, format_ncpy, PARAM_LEN, line_param);		    continue;		case 'X':		    sprintf(sheetcount, format_ncpy, PARAM_LEN, line_param);		    continue;		case 'A':		    sprintf(lower_pglim, format_ncpy, PARAM_LEN, line_param);		    continue;		case 'B':		    sprintf(upper_pglim, format_ncpy, PARAM_LEN, line_param);		    continue;		case 'G':		    sprintf(number_up, format_ncpy, PARAM_LEN, line_param);		    continue;		case 'z':		    sprintf(layup_file, format_ncpy,			    LAYUP_FILE_LEN, line_param);		    continue;		case 'K':		    sprintf(sides, format_ncpy, PARAM_LEN, line_param);		    continue;		default:	/* [a-z] => some file to print */		    if (command >= 'a' && command <= 'z') {			    if (first_file_found == 0) {				    first_file_found++;				    /*				     * This cx_open is needed for				     * network filters				     * Done here so that				     * LPS prolog can access				     * Resource table.				     * Start monitoring here because the				     * prologue can hang the job.				     */				    (void)cx_open(cxp);				    if (connection_type == con_network)				    	start_mon((int)con_network);				    dj_prolog(&job);			    }			    job_status = dj_add_file(&job, command, line_param);			    job.dj_flags |= DJ_AFTER_FIRST_FILE;			    if (job_status != js_ok) {				    goto xpass2;			    }		    } else {			    log("Undefined command letter %c", command);		    }		    continue;		case 'N':	/* used by lpq only */		case 'U':	/* handled on pass 2 */		case 'M':	/* handled on pass 2 */		    continue;	    }	dj_epilog(&job);	/*         * Start monitoring job progress if not network connection.	 * Start the job!	 * If we are a network printer, then we	 * close the output connection here for each job.	 */	if (connection_type == con_network) {		enum job_status_e xlator_status;		int cx_ret_code;		xlator_status = dj_exec(&job);		cx_ret_code = cx_close(cxp);		job_status = ((cx_ret_code == 0) ? js_ok :			      (cx_ret_code > 0) ? js_retry : js_failed);		/*		 * If the output filter aborts, we are more		 * interested in its status than in the		 * status of the xlator which may have failed		 * due to an uncaught SIGPIPE		 * as a consequence of writing on its output pipe		 * after the output filter has closed it		 */		if (job_status == js_ok) job_status = xlator_status;	} else {		start_mon((int)cxp->cx_type);		job_status = dj_exec(&job);	}	stop_mon();		/* Probably already stopped! */	dj_delete(&job, 0);    xpass2:	switch(job_status) {	    default:		cf_pass2(cfp, job_status);		(void) unlink(command_file);		(void) fclose(cfp);		break;	    case js_retry:		tof = 0;		(void) fclose(cfp);		break;	}	return(job_status);}/*VARARGS1*/static voidadd_ps_module(djp, va_alist)     register DJP djp;     va_dcl{	va_list args;	va_start(args);  	dj_start_module(djp, je_archive, 0);  	dj_add_args_va(djp, args);  	dj_end_module(djp);	va_end(args);}

⌨️ 快捷键说明

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