📄 printjob.c
字号:
/****************************************************************/static voidnon_PS_prolog(djp) register DJP djp;{ /* This is for old style banner page*/ if (!SF && !tof) { dj_start_module(djp, je_outstr, 0); dj_add_arg(djp, FF); /* Output Form Feed */ dj_end_module(djp); } if (*username) { dj_start_module(djp, je_banner, 0); dj_add_args_l(djp, username, jobname, class, 0); dj_end_module(djp); if (!SF) { dj_start_module(djp, je_outstr, 0); dj_add_arg(djp, FF); /* Output Form Feed */ dj_end_module(djp); } } tof = 1;}/* * LPS_prolog -- Generate prolog for V2.0 or V3.0 Postscript job */static voidLPS_prolog(djp)register DJP djp;{ int sheet_size_defaulted = 0; char name_tmp[(2 * PARAM_LEN) + 2]; extern int pc_orientation_found; /* print_utils.c */ get_resources(djp); djp->dj_flags |= ((cf_W_or_Z_found || cf_O_found) ? (!cf_O_found ? DJ_WIDTH_WINS : 0) : (!pc_orientation_found) ? DJ_WIDTH_WINS : 0); if (*output_tray) add_ps_module(djp, "LPS_SETOUTPUTTRAY", output_tray, 0); add_ps_module(djp, "LPS_JOBJOG", 0); if (*username) { sprintf(name_tmp, "%s@%s", logname, fromhost); add_ps_module (djp, "LPS_FLAGPAGE", "", /* VMesS version number*/ lpd_time(), "", /* node name */ printer, /* queue name */ "","","","","","","","","", jobname, /* job name */ job_id, /* job id number */ name_tmp, /* source of job (user@host) */ "", /* note: */ "JOB", /* type of page */ "", /* is it a burst page? */ 0); } add_ps_module(djp, "LPS_LOADDICT", 0); /* * Parameter related stuff gets put in between here * and LPS_SETCONTEXT. */ if (!(*number_up || *layup_file)) { if (pc_number_up) sprintf(number_up, format_ncpy, PARAM_LEN, pc_number_up); if (pc_layup_file) sprintf(layup_file, format_ncpy, PARAM_LEN, pc_layup_file); } if (!(*number_up) && *layup_file) strcpy(number_up, "1"); if (*number_up && atoi(number_up) != 0) { add_ps_module(djp, "LPS_SETNUMBERUP", number_up, 0); djp->dj_flags |= DJ_HAVE_SETNUMBERUP; } if (*sides) add_ps_module(djp, "LPS_SETSIDES", sides, 0); if (*output_tray) add_ps_module(djp, "LPS_SETOUTPUTTRAY", output_tray, 0); if (*orientation) add_ps_module(djp, "LPS_SETPAGEORIENTATION", orientation, 0); if (!(*sheetsize || *pagesize || *input_tray)) { if (pc_sheetsize) sprintf(sheetsize, format_ncpy, PARAM_LEN, pc_sheetsize); if (pc_pagesize) sprintf(pagesize, format_ncpy, PARAM_LEN, pc_pagesize); if (pc_input_tray) sprintf(input_tray, format_ncpy, PARAM_LEN, pc_input_tray); } /* If neither sheet size or page size is set * then use the fall-back sheet size, pc_sheetstd */ if (!(*pagesize || *sheetsize)) { sprintf(sheetsize, format_ncpy, PARAM_LEN, pc_sheetstd); sheet_size_defaulted = 1; } /* * Either pagesize or sheetsize must be set by this point. * If either is not set it defaults to the other. */ if (!*pagesize) { strcpy(pagesize, sheetsize); } else if (!*sheetsize) { strcpy(sheetsize, pagesize); } if (*input_tray) add_ps_module(djp, "LPS_SETINPUTTRAY", input_tray, 0); add_ps_module(djp, "LPS_SETPAGESIZE", pagesize, 0); add_ps_module(djp, "LPS_SETSHEETSIZE", ((sheet_size_defaulted) ? "defaulted" : "not-defaulted"), sheetsize, 0); if (*sheetcount) add_ps_module(djp, "LPS_SETSHEETCOUNT", sheetcount, 0); if (*lower_pglim || *upper_pglim) add_ps_module(djp, "LPS_SETPAGELIMIT", (*lower_pglim) ? lower_pglim : "1", (*upper_pglim) ? upper_pglim : "1000000", 0); if (*layup_file && LPS_add_file(djp, 'z', layup_file) != js_ok) { log("Sorry don't know about layup yet"); } add_ps_module(djp, "LPS_SETCONTEXT", 0); /* now we're ready for first file */}static enum job_status_enon_PS_add_file(djp, format, file) register DJP djp; int format; char *file;{ FCP xlator = new_fc(); int bfc_code = build_filter_chain(format, xlator); if (bfc_code == BFC_ERR) { return js_failed; } mon_setup(xlator); /* This enables the progess monitor */ if (!SF && !tof){ dj_start_module(djp, je_outstr, 0); dj_add_arg(djp, FF); /* Output Form Feed */ dj_end_module(djp); tof = 1; } if (xlator->fc_nf == 0) tof = 0; /* no filter, not at tof */ dj_start_module(djp, ((bfc_code == BFC_BYPASS) ? je_bypass : je_print), (opaque_method)xlator); dj_add_arg(djp, file); dj_end_module(djp); return js_ok;}static voidget_resources(djp)register DJP djp;{ int fd; FILE *res_fp = NULL; char buf[322]; /* Guaranteed maximum res. size */ FCP err_fcp, res_fcp; if (djp->dj_cxp->cx_output_filter && (err_fcp = djp->dj_cxp->cx_output_filter->fc_next)) { fd = err_fcp->fc_fds[1]; } else { return; } res_fcp = djp->dj_resources = new_fc(); if (fd < 0 || (res_fp = fdopen(fd, "r")) == NULL) { dlog(0, "Can't get resource info"); return; } while (fgets(buf, 322, res_fp)) { register char *newline; dlog(0, "Resource report: %s", buf); if (!(newline = strchr(buf, '\n'))) break; *newline = '\0'; fc_add_args_l(res_fcp, "-R", buf, 0); } fclose(res_fp); err_fcp->fc_fds[1] = FC_FD_CLOSED; fc_end_filter(res_fcp);}/* * LPS_add_file -- add a file translation module to job description * * Description: * If the filter to be used is a translator according to * the datatype parameter then xlator_call script is invoked. * Information about preloaded resources is appended to the * argument list. */static enum job_status_eLPS_add_file(djp, format, file)register DJP djp;int format;char *file;{ FCP xl_tmp = new_fc(); FCP xlator = new_fc(); int bfc_code; sprintf(xlator_call_flags, "-%s%s", (djp->dj_flags & DJ_AFTER_FIRST_FILE) ? "h" : "", (djp->dj_flags & DJ_WIDTH_WINS) ? "w" : ""); bfc_code = build_filter_chain(format, xlator); mon_setup(xlator); /* This enables the progess monitor */ if (bfc_code == BFC_ERR) { return js_failed; } else if (bfc_code == BFC_USE_OUTPUT_FILTER) { /* * For PostScript jobs: BFC_USE_OUTPUT_FILTER is interpreted * to mean use the data_type translator via xlator_call */ struct escapes escapes; if (djp->dj_flags & DJ_AFTER_FIRST_FILE) { add_ps_module(djp, "LPS_SEPARATE", 0); } es_init(&escapes, printcap_escapes); /* * This builds xlator_call calling * sequence. * Main difference from v2 is that we * have to append the Resource info * hence the extra copy of the arguments */ build_filter(xl_tmp, &escapes, pc_xlator, es_xflags, es_datatype, es_pagesize, es_orientation, es_width, es_length, es_indent, 0); fc_add_args_v(xlator, xl_tmp->fc_argv[0]); fc_delete(xl_tmp, 1); if (djp->dj_resources) fc_add_args_v(xlator, djp->dj_resources->fc_argv[0]); fc_end_filter(xlator); es_delete(&escapes); } dj_start_module(djp, je_print, (opaque_method)xlator); dj_add_arg(djp, file); dj_end_module(djp); return js_ok;}static voidnon_PS_epilog(djp)register DJP djp;{ return; /* Thats it until we do trailers */}static voidLN03R_epilog(djp)register DJP djp;{ if (djp->dj_flags & DJ_HAVE_SETNUMBERUP) add_ps_module(djp, "LPS_FLUSHPAGES", 0); add_ps_module(djp, "LPS_EOJ", 0); dj_start_module(djp, je_outstr, 0); dj_add_arg(djp, "\004"); /* Output ^D */ dj_end_module(djp);}static voidLPS_epilog(djp)register DJP djp;{ if (djp->dj_flags & DJ_HAVE_SETNUMBERUP) add_ps_module(djp, "LPS_FLUSHPAGES", 0); add_ps_module(djp, "LPS_EOJ", 0);}/****************************************************************//* * Cleanup child processes when a signal is caught. */static intonintr(){ longjmp(env, SIGINT);}static intonquit(){ longjmp(env, SIGQUIT);}static intonsigpipe(){ longjmp(sigpipe_env, SIGPIPE);}/****************************************************************/static voidfinal_cleanup(cxp, sig_num)register CXP cxp;int sig_num;{ /* SIG_IGN needed else next line is suicide under Posix (clever huh?)*/ if (sig_num != 0) { signal(SIGINT, SIG_IGN); kill(0, SIGINT); } cx_close(cxp); cx_delete(cxp, 0); switch (sig_num) { case 0: dlog(0, "%s: daemon %d exit", lpd_time(), pid); break; case SIGQUIT: dlog(0, "%s: daemon %d dumped core due to SIGQUIT", lpd_time(), pid); kill(pid, SIGIOT); break; default: dlog(0, "%s: daemon %d killed by signal %d", lpd_time(), pid, sig_num); break; }}/****************************************************************/static voidinit_features(){ int uv_code; uv_code = strlookup(UV_choices, UV); if (uv_code < 0) { uv_code = (int)ULTRIX_base; log("Ultrix version %s unrecognised, use one of:"); strtabprint(stderr, UV_choices); exit(1); } else { dlog(0, "Ultrix version for daemon enhancements: %s", UV_choices[uv_code]); } enable_IF_pipe_OF = features_enable_tab[(int)e_IF_pipe_OF][uv_code]; enable_printcap_escapes = features_enable_tab[(int)e_printcap_escapes][uv_code]; enable_CT_capability = features_enable_tab[(int)e_CT_capability][uv_code];}static void set_connection_type(){ int ct_code; /* Find out what sort of beast we are */ if (enable_CT_capability) { /* Good, we know what we are connected to */ ct_code = strlookup(CT_choices, CT); if (ct_code < 0) { log("Unknown connection type, use one of\n"); strtabprint(stderr, CT_choices); exit(1); } connection_type = (enum connection_type_e)ct_code; } else { /* Never mind, have to guess instead! */ if (TS && *TS) connection_type = con_lat; else if (*LP && !RM) { if (LP[0] == '@') connection_type = con_tcp; else connection_type = con_dev; } else if (RM && !*LP) connection_type = con_remote; else { log("impossible lp and rm combination in printcap"); exit(1); } }}static void set_printer_type(){ int ps_code; ps_code = strlookup(PS_choices, PS); if (ps_code < 0) { log("Unknown printer type, use one of\n"); strtabprint(stderr, PS_choices); exit(1); } printer_type = (enum printer_type_e)ps_code;}static char *reset_to_null_list[] = { fromhost, logname, jobname, class, username, datatype, input_tray, output_tray, orientation, pagesize, sheetsize, message, sheetcount, lower_pglim, upper_pglim, number_up, layup_file, sides, 0};/* * job_init -- initialise all strings with scope of current job only */static void job_init(){ register char **p; for (p = reset_to_null_list; *p; p++) **p = '\0'; sprintf(width, "-w%d", PW); sprintf(length, "-l%d", PL); sprintf(pxwidth, "-x%d", PX); sprintf(pxlength, "-y%d", PY); strcpy(indent, "-i0"); /* indentation size in characters */ strcpy(title, " "); /* title string */ if (pc_datatype) sprintf(datatype, format_ncpy, DATATYPE_LEN, pc_datatype); if (pc_output_tray) sprintf(output_tray, format_ncpy, PARAM_LEN, pc_output_tray); if (pc_orientation) sprintf(orientation, format_ncpy, PARAM_LEN, pc_orientation); /* * input_tray, sheetsize and pagesize have a complex default * mechanism and are not set up here */ if (pc_message) sprintf(message, format_ncpy, PARAM_LEN, pc_message); if (pc_upper_pglim) sprintf(upper_pglim, format_ncpy, PARAM_LEN, pc_upper_pglim); /* * number_up and layup_file interact and hence the * defaults are not set up here */ if (!*sides && pc_sides) { sprintf(sides, format_ncpy, PARAM_LEN, pc_sides); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -