From d3d56c3d4cf0cbdd4a446a6ac1f18d95190e3890 Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Tue, 30 Nov 1999 16:15:22 +0000 Subject: [PATCH] Add support for pr's locale --- usr.sbin/lpr/lpd/lpd.8 | 3 +++ usr.sbin/lpr/lpd/printjob.c | 30 +++++++++++++++++++++--------- usr.sbin/lpr/lpr/lpr.1 | 6 ++++++ usr.sbin/lpr/lpr/lpr.c | 18 ++++++++++++++++-- 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/usr.sbin/lpr/lpd/lpd.8 b/usr.sbin/lpr/lpd/lpd.8 index 5f3403061fa8..cde575f53926 100644 --- a/usr.sbin/lpr/lpd/lpd.8 +++ b/usr.sbin/lpr/lpd/lpd.8 @@ -190,6 +190,9 @@ File name. The name of the file which is being printed, or a blank for the standard input (when .Xr lpr is invoked in a pipeline). +.It Z +Locale. String to be used as the locale for +.Xr pr 1 . .El .Pp If a file cannot be opened, a message will be logged via diff --git a/usr.sbin/lpr/lpd/printjob.c b/usr.sbin/lpr/lpd/printjob.c index 37cc960f0238..a3e3f28b40a7 100644 --- a/usr.sbin/lpr/lpd/printjob.c +++ b/usr.sbin/lpr/lpd/printjob.c @@ -103,6 +103,7 @@ static int pfd; /* prstatic inter file descriptor */ static int pid; /* pid of lpd process */ static int prchild; /* id of pr process */ static char title[80]; /* ``pr'' title */ +static char locale[80]; /* ``pr'' locale */ static char class[32]; /* classification field */ static char fromhost[32]; /* user's host machine */ @@ -388,6 +389,7 @@ printit(pp, file) * U -- "unlink" name of file to remove * (after we print it. (Pass 2 only)). * M -- "mail" to user when done printing + * Z -- "locale" for pr * * getline reads a line and expands tabs to blanks */ @@ -477,6 +479,11 @@ printit(pp, file) indent[2+sizeof(indent) - 3] = '\0'; continue; + case 'Z': /* locale for pr */ + strncpy(locale, line+1, sizeof(locale) - 1); + locale[sizeof(locale) - 1] = '\0'; + continue; + default: /* some file to print */ switch (i = print(pp, line[0], line+1)) { case ERROR: @@ -546,7 +553,7 @@ print(pp, format, file) int format; char *file; { - register int n; + register int n, i; register char *prog; int fi, fo; FILE *fp; @@ -584,13 +591,16 @@ print(pp, format, file) case 'p': /* print file using 'pr' */ if (pp->filters[LPF_INPUT] == NULL) { /* use output filter */ prog = _PATH_PR; - av[0] = "pr"; - av[1] = width; - av[2] = length; - av[3] = "-h"; - av[4] = *title ? title : " "; - av[5] = "-F"; - av[6] = 0; + i = 0; + av[i++] = "pr"; + av[i++] = width; + av[i++] = length; + av[i++] = "-h"; + av[i++] = *title ? title : " "; + av[i++] = "-L"; + av[i++] = *locale ? locale : "C"; + av[i++] = "-F"; + av[i] = 0; fo = ofd; goto start; } @@ -601,7 +611,9 @@ print(pp, format, file) closelog(); closeallfds(3); execl(_PATH_PR, "pr", width, length, - "-h", *title ? title : " ", "-F", 0); + "-h", *title ? title : " ", + "-L", *locale ? locale : "C", + "-F", 0); syslog(LOG_ERR, "cannot execl %s", _PATH_PR); exit(2); } diff --git a/usr.sbin/lpr/lpr/lpr.1 b/usr.sbin/lpr/lpr/lpr.1 index 62950427574c..396fa2d624f6 100644 --- a/usr.sbin/lpr/lpr/lpr.1 +++ b/usr.sbin/lpr/lpr/lpr.1 @@ -44,6 +44,7 @@ .Op Fl \&# Ns Ar num .Op Fl C Ar class .Op Fl J Ar job +.Op Fl L Ar locale .Op Fl T Ar title .Op Fl U Ar user .Op Fl i Ar numcols @@ -173,6 +174,11 @@ and the file foo.c to be printed. .It Fl J Ar job Job name to print on the burst page. Normally, the first file's name is used. +.It Fl L Ar locale +Use +.Ar locale +specified as argument instead of one found in environment. +Use "C" to reset locale to default. .It Fl T Ar title Title name for .Xr pr 1 , diff --git a/usr.sbin/lpr/lpr/lpr.c b/usr.sbin/lpr/lpr/lpr.c index 9a19606678f4..6a1a099603bc 100644 --- a/usr.sbin/lpr/lpr/lpr.c +++ b/usr.sbin/lpr/lpr/lpr.c @@ -65,6 +65,7 @@ static const char rcsid[] = #include #include #include +#include #include #include #include @@ -98,6 +99,7 @@ static int sflag; /* symbolic link flag */ static int tfd; /* control file descriptor */ static char *tfname; /* tmp copy of cf before linking */ static char *title; /* pr'ing title */ +static char *locale; /* pr'ing locale */ static int userid; /* user id */ static char *Uflag; /* user name specified with -U flag */ static char *width; /* width for versatec printing */ @@ -152,7 +154,7 @@ main(argc, argv) errs = 0; while ((c = getopt(argc, argv, - ":#:1:2:3:4:C:J:P:T:U:cdfghi:lnmprstvw:")) != -1) + ":#:1:2:3:4:C:J:L:P:T:U:cdfghi:lnmprstvw:")) != -1) switch (c) { case '#': /* n copies */ i = strtol(optarg, &p, 10); @@ -183,6 +185,10 @@ main(argc, argv) printer = optarg; break; + case 'L': /* pr's locale */ + locale = optarg; + break; + case 'T': /* pr's title line */ title = optarg; break; @@ -336,6 +342,14 @@ main(argc, argv) card('1'+i, fonts[i]); if (width != NULL) card('W', width); + if (format == 'p') { + char *s; + + if (locale) + card('Z', locale); + else if ((s = setlocale(LC_TIME, "")) != NULL) + card('Z', s); + } /* * Read the files and spool them. @@ -722,7 +736,7 @@ usage() { fprintf(stderr, "%s\n%s\n", "usage: lpr [-Pprinter] [-#num] [-C class] [-J job] [-T title] [-U user]", -"[-i[numcols]] [-1234 font] [-wnum] [-cdfghlnmprstv] [name ...]"); +"[-i[numcols]] [-1234 font] [-L locale] [-wnum] [-cdfghlnmprstv] [name ...]"); exit(1); }