📄 lpr.c
字号:
#ifndef lintstatic char *sccsid = "@(#)lpr.c 4.2 ULTRIX 9/11/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. * * * ************************************************************************//*************************************************************** * lpr -- off line print * * * * Allows access to multiple printers and printers on remote * * machines by using information from a printer data base. * ***************************************************************//* SCCS history beginning * *************************************************************** * -- Revision History -- * *************************************************************** * * 1.1 01/11/83 -- sccs * date and time created 83/11/01 20:58:05 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 02/10/86 -- root * Comments taken from: 1.4: * *** Working Pool Statistics ***: 1.4 86/07/08 17:19:16 hoffman 00001/00000/00646 * * Added pass-thru filter parameter xf * * *************************************************************** * * 1.5 08/01/88 -- maxwell * user interface rewritten using getopt(3c) - now checks for invalid options * and missing arguments. * Functionally unchanged * * * *************************************************************** * * 1.6 13/01/88 -- maxwell * added new lps40 options: -D -I -F -O -L -N -S -R -M * tightened up command line error testing * * * *************************************************************** * * 1.7 27/01/88 -- maxwell * Added multiple filter test * * * *************************************************************** * * 1.8 11/02/88 -- maxwell * * * *************************************************************** * * 1.9 05/05/88 -- maxwell * added table to map command line options to command file * * * *************************************************************** * * 1.10 06/05/88 -- thoms * Fixed PostScript parameter strings * Fixed message and number up command file letters to E and G * * *************************************************************** * * 1.11 13/05/88 -- maxwell * added code to spool layup file * made minor changes to order of control file entries * * *************************************************************** * * 1.12 16/05/88 -- maxwell * put arg strings for command line into separate module (argstrings.c) * allow -i0 (zero length indent) * * *************************************************************** * * 1.13 17/05/88 -- thoms * Put 'N' line in command file after data files (else lpq fouls up) * * *************************************************************** * * 1.14 31/05/88 -- maxwell * Minor changes to error messages * * *************************************************************** * * 1.15 21/07/88 -- maxwell * Changes as per code review: * Added more comments * Tidied up exit codes - added warn() routine to pass warning messages to stderr * replaced '?' switch in case with 'default' * made changes to keep lint happy * * *************************************************************** * * 1.16 21/07/88 -- thoms * Added copyright notice and modification history * * *************************************************************** * * 1.17 05/08/88 -- maxwell * changed n-up range to 0-100 * * *************************************************************** * * 1.18 21/07/88 -- maxwell * put back unique abbre code for data_types * * *************************************************************** * * 1.19 12/08/88 -- maxwell * search for layup files in LUPDIR if rel path name and not in current dir * * *************************************************************** * * 1.20 16/08/88 -- maxwell * rationalised handling of numerical args - added valid_num() * fixed syntax of -Z (e.g. -Z 4 now equals -Z4,) * corrected usage message for -Z * * **************************************************************** * * 1.21 10/11/88 -- thoms * Removed #include of a.out.h, lpr.c now includes exec.h instead * * **************************************************************** * 1.22 20/08/90 -- atkinson * Modifications to block symbolic link tricks. * Name symbolic links the same way as copies * * SCCS history end */#include <stdio.h>#include <sys/types.h>#include <sys/file.h>#include <sys/stat.h>#include <sys/exec.h>#include <pwd.h>#include <signal.h>#include <ctype.h>#include "lp.local.h"#include "argstrings.h"#define LUPDIR "/usr/lib/lpdfilters/"char *name; /* program name *//* global variables */static char *tfname; /* tmp copy of cf before linking */static char *cfname; /* daemon control files, linked from tf's */static char *dfname; /* data files */static struct stat statb; /* Used by test() and for symbolic links */static int tfd; /* control file descriptor */static int userid; /* user id */static char host[32]; /* host name */static int nact; /* number of jobs to act on */static char format = 'f'; /* format char for printing files (default plain text) */static int inchar; /* location to increment char in file names */static int ncopies = 1; /* # of copies to make */static char *title; /* pr'ing title */static char buf[BUFSIZ];static int MX; /* maximum number of blocks to copy */static int MC; /* maximum number of copies allowed */static int DU; /* daemon user-id */static char *SD; /* spool directory */static char *LO; /* lock file name */static short SC; /* suppress multiple copies *//* external functions */extern char *getenv();extern char *getwd();extern char *rindex();extern char *malloc();extern char *index();/* forward declarations */static char *linked();static void cleanup();static void chkprinter();static void mktemps();static char *itoa();int check_arg();static int valid_num();static void invalid_arg();static void usage();static void warn();static void fatal();static void nextname();/******************************************************************* * main * parse and validate command line, create control file in spool dir, * copy/symlink data file to spool dir and start print deamon *******************************************************************//*ARGSUSED*/main(argc, argv) int argc; char *argv[];{ static char *options = "cdfghi:lmnpqrstvw:xz:C:P:J:T:#:1:2:3:4:D:I:o:O:F:Z:X:S:M:N:L:K:"; extern struct passwd *getpwuid(); extern int getopt(); extern int optind; extern char *optarg; register char *arg, *cp; int num, i, opt, lifd; struct passwd *pw; struct stat stb; int mailflg = 0; /* send mail */ int qflag = 0; /* q job but don't exec daemon (undocumented option) */ int sflag = 0; /* symbolic link flag */ int hdr = 1; /* print header or not (default is yes) */ int rflag = 0; /* remove files upon completion */ int remove = 0; /* can user remove file */ char *data_type = NULL; /* name of data_type */ char *input_tray = NULL; /* name of input_tray */ char *output_tray = NULL; /* name of output_tray */ char *orientation = NULL; /* name of orientation */ char *page_size = NULL; /* name of page_size */ char *nsheets = NULL; /* num of sheets to print */ char *numberup = NULL; /* # for number_up */ char *layup = NULL; /* name of layup defn file */ char *sides = NULL; /* name of sides */ char *lower = NULL, /* range of sheets to print */ *upper = NULL; char *sheet_size = NULL; /* name of sheet_size */ char *message = NULL; /* name of message */ char *indent = NULL; /* amount to indent (default is 0) */ char *person = NULL; /* user name */ char *fonts[4]; /* troff font names */ char *width = NULL; /* width for printing */ char *length = NULL; /* length for printing */ char *class = host; /* class title on header page */ char *jobname = NULL; /* job name on header page */ char *printer = NULL; /* printer name */ if (signal(SIGHUP, SIG_IGN) != SIG_IGN) (void) signal(SIGHUP, cleanup); if (signal(SIGINT, SIG_IGN) != SIG_IGN) (void) signal(SIGINT, cleanup); if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) (void) signal(SIGQUIT, cleanup); if (signal(SIGTERM, SIG_IGN) != SIG_IGN) (void) signal(SIGTERM, cleanup); name = argv[0]; (void)gethostname(host, sizeof (host)); init_args(); /* parse options */ /* note numerical arguments are stored as strings so that only */ /* one card fn is required */ while ((opt = getopt(argc, argv, options)) != EOF ) { switch (opt) { /* deal with filters */ case 'c': /* print cifplot output */ case 'd': /* print tex output (dvi files) */ case 'g': /* print graph(1G) output */ case 'l': /* literal output */ case 'n': /* print ditroff output */ case 'p': /* print using ``pr'' */ case 't': /* print troff output (cat files) */ case 'v': /* print vplot output */ case 'x': /* print via pass-thru filter */ format = opt; break; case 'f': /* print FORTRAN output (f is used for text files) */ format = 'r'; break; case 'h': /* suppress header page */ hdr = 0; break; case 'i': /* indent output */ if (valid_num(optarg,1,-1) == 0) indent = optarg; else fatal("invalid argument %s - must be number > 0",optarg); break; case 'm': /* send mail when done */ mailflg++; break; case 'r': /* remove file when done */ rflag++; break; case 's': /* try to link files */ sflag++; break; case 'w': /* versatec page width */ if (valid_num(optarg,0,-1) == 0) width = optarg; else fatal("invalid argument %s - must be number > 0",optarg); break; case 'z': /* page length */ if (valid_num(optarg,0,-1) == 0) length=optarg; else fatal("invalid argument %s - must be number > 0",optarg); break; case 'C': /* classification spec */ hdr++; /* override header suppression */ class = optarg; break; case 'J': /* job name */ hdr++; /* override header suppression */ jobname = optarg; break; case 'P': /* specifiy printer name */ printer = optarg; chkprinter(printer); break; case 'T': /* pr's title line */ title = optarg; break; case '1': /* troff fonts */ case '2': case '3': case '4':
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -