📄 printjob.c
字号:
#ifndef lintstatic char *sccsid = "@(#)printjob.c 4.3 ULTRIX 11/15/90";#endif/************************************************************************ * * * Copyright (c) 1988 by * * Digital Equipment Corporation, Maynard, MA * * All rights reserved. * * * * This software is furnished under a license and may be used and * * copied only in accordance with the terms of such license and * * with the inclusion of the above copyright notice. This * * software or any other copies thereof may not be provided or * * otherwise made available to any other person. No title to and * * ownership of the software is hereby transferred. * * * * This software is derived from software received from the * * University of California, Berkeley, and from Bell * * Laboratories. Use, duplication, or disclosure is subject to * * restrictions under license agreements with University of * * California and with AT&T. * * * * The information in this software is subject to change without * * notice and should not be construed as a commitment by Digital * * Equipment Corporation. * * * * Digital assumes no responsibility for the use or reliability * * of its software on equipment which is not supplied by Digital. * * * ************************************************************************//* * printjob.c -- print jobs in the queue. * * Description: * This file contains the main loop of the job print action * and is called from lpd.c * * The code is a complete rewrite of the code in the * original Berkeley printjob.c * * As much code as possible has been modularised and * moved elsewhere, in particular to filter.* connection.* * dcl.* and to print_utils.c * * NOTE: the lock file is used to pass information to lpq and lprm. * it does not need to be removed because file locks are dynamic. *//* * Modification History: * * 13-Nov-90 - Adrian Thoms (thoms@wessex) * Corrected use of LPS_SEPARATE module to separate files of job * * 04-Oct-90 - Adrian Thoms (thoms@wessex) * Added new defaulting scheme for orientation * Added new %x escape for passing a string of flags to filters * Straightened out recent modification history * * 11-jan-90 -- thoms * Fixed hostname buffer lengths * * 16/08/89 -- Giles Atkinson * Monitor flag page and Postscript prologue as well as file printing. * * 2/08/89 -- Giles Atkinson * Add "4.0" as option for the `uv' printcap capability (same as `psv1.0') * and support for the progress monitor. *//* SCCS history beginning * THIS SECTION IS NOW OBSOLETE, add history above * *************************************************************** * -- Revision History -- * *************************************************************** * * 1.1 01/11/83 -- sccs * date and time created 83/11/01 20:58:56 by sccs * * *************************************************************** * * 1.2 11/12/84 -- root * added Ultrix id keywords - lp * * * *************************************************************** * * 1.3 11/12/84 -- root * merged into library - lp * several additions by williams of: * add of ditroff filter call * fix sticky spooler control file param * add PP print replacement filter * add -z option for regulating page length * * * *************************************************************** * * 1.4 28/06/85 -- root * Comments taken from: /usr/src/usr.lib/lpr/SCCS/s.printjob.c: * 1.4 85/06/24 08:47:56 williams 4 3 00011/00001/01154 * added initialization file creation code and option on printcap to invoke * the init code. * * * * *************************************************************** * * 1.5 25/11/85 -- root * Comments taken from: /usr/src/usr.lib/lpr/SCCS/s.printjob.c: * 1.5 85/11/13 16:20:23 williams 5 4 00001/00001/01164 * added modes to init file open call * * * * *************************************************************** * * 1.6 17/07/86 -- root * Comments taken from: 1.7: * *** Working Pool Statistics ***: 1.7 86/06/24 15:05:14 logcher 00000/00006/01357 * * Removed three #ifdefs that were used in the testing process * * * * * *************************************************************** * * 1.7 17/07/86 -- root * Comments taken from: 1.8: * *** Working Pool Statistics ***: 1.8 86/07/01 13:48:39 logcher 00021/00018/01339 * * Added logic to make system calls, safe systems calls by setting IFS and PATH. * * * * * *************************************************************** * * 1.8 17/07/86 -- root * Comments taken from: 1.9: * *** Working Pool Statistics ***: 1.9 86/07/02 17:41:26 hoffman 00013/00000/01360 * * added LAT 5.1 host-initiated connect * * * * * *************************************************************** * * 1.9 02/10/86 -- root * Comments taken from: 1.10: * *** Working Pool Statistics ***: 1.10 86/07/08 17:20:06 hoffman 00006/00000/01373 * * Added pass-thru parameter xf * * * * * * * *************************************************************** * * 1.10 30/10/86 -- pnh * ADded pgetstr() initialization for TS, OP, OS attributes for Lat printer supp. * * * *************************************************************** * * 1.11 10/03/88 -- root * Brand new filter argument collection and despatch code. * * * *************************************************************** * * 1.12 22/03/88 -- thoms * DCL support added (using dcl output filter) * * * *************************************************************** * * 1.13 30/03/88 -- thoms * Basic PostScript job building and execution working * * * *************************************************************** * * 1.14 25/04/88 -- thoms * Lpd restructured, based on printer_type and connection_type switches. * * * *************************************************************** * * 1.15 29/04/88 -- thoms * Minor fixes, start and exit debug messages, onquit fix * * * *************************************************************** * * 1.16 03/05/88 -- thoms * Fixed and stable minimal PS functionality. * * * *************************************************************** * * 1.17 06/05/88 -- thoms * Added the fancy PostScript support features we had all been waiting for: * Q defaults in printcap * Inserting the appropriate PostScript modules as per command params. * * * *************************************************************** * * 1.18 12/05/88 -- thoms * Added layup file, and datatype code, hooked in ansi xlator * * * *************************************************************** * * 1.19 16/05/88 -- thoms * Fixed set output tray to occur before banner page. * * * *************************************************************** * * 1.20 17/05/88 -- thoms * Passes job id to banner page and makes available to filters. * * * *************************************************************** * * 1.21 20/05/88 -- thoms * Moved some utils to print_utils.c * Complete rewrite of printjob() to improved structure and * comprehensibility! * * * *************************************************************** * * 1.22 02/06/88 -- thoms * Simplified xlator code to allow any -D<datatype> * 3.0 is now the default behaviour * 2.6: removed if_pipe_to_of feature * * * *************************************************************** * * 1.23 19/07/88 -- thoms * Added copyright notice and modification history * Changed naming to conform to code review * * *************************************************************** * * 1.24 21/07/88 -- thoms * Check output filter exit status for ct_network connection type * so as to enable correct abort/retry behaviour. * Added exponential backoff in retry loop. * * *************************************************************** * * 1.25 28/07/88 -- thoms * Add code to deal with the stderr info from lpscomm * (output filter for pt_lps_v3). * This involves the parasite filter lpserrof and adds the * following functionality: * Supply of pre-loaded resource table to translators * Accounting * Message mail back to user * * *************************************************************** * * 1.26 29/07/88 -- thoms * Made Dl capability compulsory for PostScript printers * * *************************************************************** * * 1.27 29/07/88 -- thoms * Added cleanup on job abort * * *************************************************************** * * 1.28 01/09/88 -- thoms * Added SIGPIPE catcher to cope with output filter problems * Pass debug level to lpserrof * Fixed open pipe fd to lpserrof bug * Correct input_tray/sheetsize interaction bug * No longer include errorhandler module * * *************************************************************** * * 1.29 07/09/88 -- thoms * Made retry on SIGPIPE strict: retry on exit status 1 only * * *************************************************************** * * 1.30 09/09/88 -- thoms * Fixed argument passing to lpserrof: -J now switches on -Mk mailing * * **************************************************************** * * 1.31 16/10/88 -- thoms * Hacked out redundant code relating to LPS_v2 * Added TCP Printserver support * Added -p title fix as per 3.0 lpd * * **************************************************************** * * 1.32 21/10/88 -- thoms * Time stamp key log messages, improve status messages * * **************************************************************** * * 1.33 09/11/88 -- thoms * Fixed hanging problem:- switched SIGCHILD to SIG_DEF * * **************************************************************** * * 1.34 09/11/88 -- thoms * Fixed LPS_SETOUTPUTTRAY bug (was conditional on flagpage) * Now supply LPS_JOBJOG module for offset stacking * * **************************************************************** * SCCS history end */#include "lp.h"/**************** Table for new features enable ****************/enum enable_flag_code { e_IF_pipe_OF, e_printcap_escapes, e_CT_capability,};/* Flags to selectively enable new daemon features * these are turned on according to the features_enable_tab */static short enable_IF_pipe_OF; /* if 1: IF pipes into OF */static short enable_printcap_escapes; /* if 1; allow printcap escapes */static short enable_CT_capability; /* if 1 expect CT capability */static short features_enable_tab[][ULTRIX_upb] = {/* Ultrix V 3.0 psv1.0 4.0 *//* -------------------------------- */ { 0, 0, 0 }, /* IF_pipe_OF enabled */ { 0, 1, 1 }, /* printcap_escapes enabled */ { 0, 1, 1 }, /* CT_capability expected */};/****************************************************************//* * enumeration for state of queue as set in lock file mode bits */enum q_state_e { q_enabled, q_disabled, q_rebuild,};/**************** related extern functions (not in headers) ****************/extern enum job_status_e startdqs(/* char *printer */);extern enum job_status_e sendit(/* char *command_file */); /* sendjob.c */extern void sendmail(/* char *user, *fromhost, *jobname; * enum job_status_e job_status */); /* print_utils.c */extern char *lpd_time(); /* print_utils.c */extern int strlookup(/* char **strtab; char *str */); /* pcap_choices.c */extern void strtabprint(/* FILE *fp; char **strtab */); /* pcap_choices.c */extern void mon_setup(/* FCP */); /* monitor.c */extern void start_mon(/* int */), stop_mon(); /* monitor.c *//**************** Declarations of local functions ****************/static int onintr();static int onquit();static int onsigpipe();static void final_cleanup(/* CXP cxp; int sig_num */);static void init_features();static void set_connection_type();static void set_printer_type();static void process_the_queue(/* CXP cxp */);static int process_a_job(/* CXP cxp; char *command_file */);static enum job_status_e try_the_job(/* CXP cxp; char *command_file */);static enum job_status_e printit(/* char *command_file */);static void add_ps_module(/* DJP djp; va_dcl */ );static void cleanup_job(/* char *command_file */);static void job_init();/**************** Miscellaneous variables (ugh!!) ****************/static int pid; /* pid of lpd process */long pidoff; /* offset past pid in lock file */static int lfd; /* lock file descriptor */static int tof; /* true if at top of form */char ininame[32]; /* initialization file name */static int inid; /* initialization file descriptor */static char format_ncpy[] = "%.*s";static short cf_W_or_Z_found; /* user specified width or length */static short cf_O_found; /* user specified orientation *//**************** Behaviour switch variables ****************/static enum printer_type_e printer_type; /* type of printer */static enum connection_type_e connection_type;/* type of output connection *//**************** Job building functions ****************/static void get_resources(/* register FCP xlator, err_fcp; */);static void non_PS_prolog(/* DJP djp */);static void LPS_prolog(/* DJP djp */);static void non_PS_epilog(/* DJP djp */);static void LN03R_epilog(/* DJP djp */);static void LPS_epilog(/* DJP djp */);static enum job_status_e LPS_add_file(/* DJP djp; int format char *file */);static enum job_status_e non_PS_add_file(/* DJP djp; int format char *file */);/* check enum printer_type_e against order of this table *//***************************************************************** Switch tables to select behaviour for different printers****************************************************************/static job_build_sw job_build_sw_per_printer[] = { /* Printer type */ /*--------------*/ { non_PS_prolog, non_PS_epilog, non_PS_add_file }, /* :- pt_non_PS */ { LPS_prolog, LN03R_epilog, LPS_add_file }, /* :- pt_LN03R */ { LPS_prolog, LPS_epilog, LPS_add_file }, /* :- pt_LPS */};/* * In order to handle the standard error output from the lpscomm * network filter we have to do run an extra filter which * reads standard error from the output filter * The following table is used by open_output_filter() to select * the appropriate function according to enum printer_type_e */static void open_of();static void open_of_and_errorof();/* * RESOURCE TABLE CODE */static void (*open_output_filter_sw[])() = { /* Printer type */ /*--------------*/ open_of, /* :- pt_non_PS */ open_of, /* :- pt_LN03R */ open_of_and_errorof, /* :- pt_LPS */};/***************************************************************** Parameters set per job****************************************************************/#define TITLE_LEN 79#define PARAM_LEN 31#define CLASS_LEN 31#define DATATYPE_LEN 63#define LAYUP_FILE_LEN 127static char title[TITLE_LEN+1]; /* ``pr'' title */static char fromhost[HOSTNAME_LEN+1]; /* user's host machine */static char logname[PARAM_LEN+1]; /* user's login name */static char jobname[PARAM_LEN+1]; /* job or file name */static char job_id[PARAM_LEN+1]; /* job id number */static char class[CLASS_LEN+1]; /* job class */static char width[10]; /* page width in characters */static char length[10]; /* page length in lines */static char pxwidth[10]; /* page width in pixels */static char pxlength[10]; /* page length in pixels */static char indent[10]; /* indentation size in characters *//* These are new for psv1.0 */static char username[PARAM_LEN+1];static char datatype[DATATYPE_LEN+1]; /* D */static char input_tray[PARAM_LEN+1]; /* < */static char output_tray[PARAM_LEN+1]; /* > */static char orientation[PARAM_LEN+1]; /* O */static char pagesize[PARAM_LEN+1]; /* F */static char sheetsize[PARAM_LEN+1]; /* S */static char message[PARAM_LEN+1]; /* E */static char sheetcount[PARAM_LEN+1]; /* X */static char lower_pglim[PARAM_LEN+1]; /* A */static char upper_pglim[PARAM_LEN+1]; /* B */static char number_up[PARAM_LEN+1]; /* G */static char layup_file[LAYUP_FILE_LEN+1]; /* z */static char sides[PARAM_LEN+1]; /* K */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -