Add support for pr's locale

This commit is contained in:
Andrey A. Chernov 1999-11-30 16:15:22 +00:00
parent 4bf9895e55
commit d3d56c3d4c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=53956
4 changed files with 46 additions and 11 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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 ,

View File

@ -65,6 +65,7 @@ static const char rcsid[] =
#include <fcntl.h>
#include <a.out.h>
#include <err.h>
#include <locale.h>
#include <signal.h>
#include <syslog.h>
#include <pwd.h>
@ -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);
}