2 * Copyright (c) 1991 Keith Muller.
4 * The Regents of the University of California. All rights reserved.
6 * This code is derived from software contributed to Berkeley by
7 * Keith Muller of the University of California, San Diego.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * $FreeBSD: src/usr.bin/pr/pr.c,v 1.9.2.4 2002/04/15 17:16:57 jmallett Exp $
34 * $DragonFly: src/usr.bin/pr/pr.c,v 1.4 2008/10/16 01:52:32 swildner Exp $
36 * @(#) Copyright (c) 1993 The Regents of the University of California. All rights reserved.
37 * @(#)pr.c 8.2 (Berkeley) 4/16/94
40 #include <sys/types.h>
58 * pr: a printing and pagination filter. If multiple input files
59 * are specified, each is read, formatted, and written to standard
60 * output. By default, input is separated into 66-line pages, each
61 * with a header that includes the page number, date, time and the
64 * Complies with posix P1003.2/D11
70 static int pgnm
; /* starting page number */
71 static int clcnt
; /* number of columns */
72 static int colwd
; /* column data width - multiple columns */
73 static int across
; /* mult col flag; write across page */
74 static int dspace
; /* double space flag */
75 static char inchar
; /* expand input char */
76 static int ingap
; /* expand input gap */
77 static int pausefst
; /* Pause before first page */
78 static int pauseall
; /* Pause before each page */
79 static int formfeed
; /* use formfeed as trailer */
80 static char *header
; /* header name instead of file name */
81 static char ochar
; /* contract output char */
82 static int ogap
; /* contract output gap */
83 static int lines
; /* number of lines per page */
84 static int merge
; /* merge multiple files in output */
85 static char nmchar
; /* line numbering append char */
86 static int nmwd
; /* width of line number field */
87 static int offst
; /* number of page offset spaces */
88 static int nodiag
; /* do not report file open errors */
89 static char schar
; /* text column separation character */
90 static int sflag
; /* -s option for multiple columns */
91 static int nohead
; /* do not write head and trailer */
92 static int pgwd
; /* page width with multiple col output */
93 static char *timefrmt
; /* time conversion string */
98 static FILE *err
; /* error message file pointer */
99 static int addone
; /* page length is odd with double space */
100 static int errcnt
; /* error count on file processing */
101 static char digs
[] = "0123456789"; /* page number translation map */
104 main(int argc
, char **argv
)
108 if (signal(SIGINT
, SIG_IGN
) != SIG_IGN
)
109 (void)signal(SIGINT
, terminate
);
110 ret_val
= setup(argc
, argv
);
113 * select the output format based on options
116 ret_val
= mulfile(argc
, argv
);
118 ret_val
= onecol(argc
, argv
);
120 ret_val
= horzcol(argc
, argv
);
122 ret_val
= vertcol(argc
, argv
);
127 if (errcnt
|| ret_val
)
133 * Check if we should pause and write an alert character and wait for a
134 * carriage return on /dev/tty.
137 ttypause(int pagecnt
)
142 if ((pauseall
|| (pausefst
&& pagecnt
== 1)) &&
143 isatty(STDOUT_FILENO
)) {
144 if ((ttyfp
= fopen("/dev/tty", "r")) != NULL
) {
145 (void)putc('\a', stderr
);
146 while ((pch
= getc(ttyfp
)) != '\n' && pch
!= EOF
)
154 * onecol: print files with only one column of output.
155 * Line length is unlimited.
158 onecol(int argc
, char **argv
)
186 * allocate line buffer
188 if ((obuf
= malloc((unsigned)(LBUF
+ off
)*sizeof(char))) == NULL
) {
193 * allocate header buffer
195 if ((hbuf
= malloc((unsigned)(HDBUF
+ offst
)*sizeof(char))) == NULL
) {
200 ohbuf
= hbuf
+ offst
;
204 nbuf
[--num
] = nmchar
;
206 (void)memset(obuf
, (int)' ', offst
);
207 (void)memset(hbuf
, (int)' ', offst
);
213 while ((inf
= nxtfile(argc
, argv
, &fname
, ohbuf
, 0)) != NULL
) {
216 * skip to specified page
218 if (inskip(inf
, pgnm
, lines
))
240 while (linecnt
< lines
) {
244 if ((cnt
= inln(inf
,lbuf
,LBUF
,&cps
,0,&mor
)) < 0)
246 if (!linecnt
&& !nohead
&&
247 prhead(hbuf
, fname
, pagecnt
))
255 addnum(nbuf
, num
, ++lncnt
);
256 if (otln(obuf
,cnt
+off
, &ips
, &ops
, mor
))
258 } else if (otln(lbuf
, cnt
, &ips
, &ops
, mor
))
262 * if line bigger than buffer, get more
270 * whole line rcvd. reset tab proc. state
279 * fill to end of page
281 if (linecnt
&& prtail(lines
-linecnt
-lrgln
, lrgln
))
285 * On EOF go to next file
300 * vertcol: print files with more than one column of output down a page
303 vertcol(int argc
, char **argv
)
318 int mxlen
= pgwd
+ offst
+ 1;
319 int mclcnt
= clcnt
- 1;
336 * allocate page buffer
338 if ((buf
= malloc((unsigned)lines
*mxlen
*sizeof(char))) == NULL
) {
344 * allocate page header
346 if ((hbuf
= malloc((unsigned)(HDBUF
+ offst
)*sizeof(char))) == NULL
) {
350 ohbuf
= hbuf
+ offst
;
352 (void)memset(hbuf
, (int)' ', offst
);
355 * col pointers when no headers
359 (struct vcol
*)malloc((unsigned)mvc
*sizeof(struct vcol
))) == NULL
) {
365 * pointer into page where last data per line is located
367 if ((lstdat
= (char **)malloc((unsigned)lines
*sizeof(char *))) == NULL
){
373 * fast index lookups to locate start of lines
375 if ((indy
= (int *)malloc((unsigned)lines
*sizeof(int))) == NULL
) {
379 if ((lindy
= (int *)malloc((unsigned)lines
*sizeof(int))) == NULL
) {
390 * initialize buffer lookup indexes and offset area
392 for (j
= 0; j
< lines
; ++j
) {
393 lindy
[j
] = j
* mxlen
;
394 indy
[j
] = lindy
[j
] + offst
;
396 ptbf
= buf
+ lindy
[j
];
397 (void)memset(ptbf
, (int)' ', offst
);
400 ptbf
= buf
+ indy
[j
];
407 while ((inf
= nxtfile(argc
, argv
, &fname
, ohbuf
, 0)) != NULL
) {
410 * skip to requested page
412 if (inskip(inf
, pgnm
, lines
))
429 for (i
= 0; i
< clcnt
; ++i
) {
432 * if last column, do not pad
443 * is this first column
446 ptbf
= buf
+ indy
[j
];
456 addnum(ptbf
, nmwd
, ++lncnt
);
464 cnt
= inln(inf
,ptbf
,colwd
,&cps
,1,&mor
);
471 * pad all but last column on page
475 * pad to end of column
479 else if ((pln
= col
-cnt
) > 0) {
486 * remember last char in line
497 * when -t (no header) is specified the spec requires
498 * the min number of lines. The last page may not have
499 * balanced length columns. To fix this we must reorder
500 * the columns. This is a very slow technique so it is
501 * only used under limited conditions. Without -t, the
502 * balancing of text columns is unspecified. To NOT
503 * balance the last page, add the global variable
504 * nohead to the if statement below e.g.
506 * if ((cnt < 0) && nohead && cvc ......
511 * check to see if last page needs to be reordered
513 if ((cnt
< 0) && cvc
&& ((mvc
-cvc
) >= clcnt
)){
521 if (!nohead
&& prhead(hbuf
, fname
, pagecnt
))
523 for (i
= 0; i
< pln
; ++i
) {
526 if (offst
&& otln(buf
,offst
,&ips
,&ops
,1))
530 for (j
= 0; j
< clcnt
; ++j
) {
532 * determine column length
545 cnt
= vc
[tvc
].cnt
+ 1;
550 if (otln(vc
[tvc
].pt
, cnt
, &ips
,
560 if (otln(buf
, 0, &ips
, &ops
, 0))
566 if (prtail((lines
- pln
), 0))
569 * done with output, go to next file
575 * determine how many lines to output
585 if (pln
&& !nohead
&& prhead(hbuf
, fname
, pagecnt
))
591 for (i
= 0; i
< pln
; ++i
) {
592 ptbf
= buf
+ lindy
[i
];
593 if ((j
= lstdat
[i
] - ptbf
) <= offst
)
595 if (otln(ptbf
, j
, &ips
, &ops
, 0))
602 if (pln
&& prtail((lines
- pln
), 0))
606 * if EOF go to next file
621 * horzcol: print files with more than one column of output across a page
624 horzcol(int argc
, char *argv
[])
645 if ((buf
= malloc((unsigned)(pgwd
+offst
+1)*sizeof(char))) == NULL
) {
653 if ((hbuf
= malloc((unsigned)(HDBUF
+ offst
)*sizeof(char))) == NULL
) {
657 ohbuf
= hbuf
+ offst
;
659 (void)memset(buf
, (int)' ', offst
);
660 (void)memset(hbuf
, (int)' ', offst
);
666 while ((inf
= nxtfile(argc
, argv
, &fname
, ohbuf
, 0)) != NULL
) {
668 if (inskip(inf
, pgnm
, lines
))
684 for (i
= 0; i
< lines
; ++i
) {
694 * add number to column
696 addnum(ptbf
, nmwd
, ++lncnt
);
703 if ((cnt
= inln(inf
,ptbf
,colwd
,&cps
,1,
710 * if last line skip padding
716 * pad to end of column
720 else if ((pln
= col
- cnt
) > 0) {
721 (void)memset(ptbf
,(int)' ',pln
);
727 * determine line length
729 if ((j
= lstdat
- buf
) <= offst
)
732 prhead(hbuf
, fname
, pagecnt
))
737 if (otln(buf
, j
, &ips
, &ops
, 0))
744 if (i
&& prtail(lines
-i
, 0))
748 * if EOF go to next file
763 * mulfile: print files with more than one column of output and
764 * more than one file concurrently
767 mulfile(int argc
, char *argv
[])
791 * array of FILE *, one for each operand
793 if ((fbuf
= (FILE **)malloc((unsigned)clcnt
*sizeof(FILE *))) == NULL
) {
801 if ((hbuf
= malloc((unsigned)(HDBUF
+ offst
)*sizeof(char))) == NULL
) {
805 ohbuf
= hbuf
+ offst
;
808 * do not know how many columns yet. The number of operands provide an
809 * upper bound on the number of columns. We use the number of files
810 * we can open successfully to set the number of columns. The operation
811 * of the merge operation (-m) in relation to unsuccesful file opens
812 * is unspecified by posix.
816 if ((fbuf
[j
] = nxtfile(argc
, argv
, &fname
, ohbuf
, 1)) == NULL
)
818 if (pgnm
&& (inskip(fbuf
[j
], pgnm
, lines
)))
830 * calculate page boundries based on open file count
834 colwd
= (pgwd
- clcnt
- nmwd
)/clcnt
;
835 pgwd
= ((colwd
+ 1) * clcnt
) - nmwd
- 2;
837 colwd
= (pgwd
+ 1 - clcnt
)/clcnt
;
838 pgwd
= ((colwd
+ 1) * clcnt
) - 1;
842 "pr: page width too small for %d columns\n", clcnt
);
851 if ((buf
= malloc((unsigned)(pgwd
+offst
+1)*sizeof(char))) == NULL
) {
856 (void)memset(buf
, (int)' ', offst
);
857 (void)memset(hbuf
, (int)' ', offst
);
866 * continue to loop while any file still has data
874 for (i
= 0; i
< lines
; ++i
) {
879 * add line number to line
881 addnum(ptbf
, nmwd
, ++lncnt
);
891 for (j
= 0; j
< clcnt
; ++j
) {
892 if (fbuf
[j
] == NULL
) {
897 } else if ((cnt
= inln(fbuf
[j
], ptbf
, colwd
,
898 &cps
, 1, &mor
)) < 0) {
902 if (fbuf
[j
] != stdin
)
903 (void)fclose(fbuf
[j
]);
917 * if last ACTIVE column, done with line
923 * pad to end of column
927 } else if ((pln
= col
- cnt
) > 0) {
928 (void)memset(ptbf
, (int)' ', pln
);
934 * calculate data in line
936 if ((j
= lstdat
- buf
) <= offst
)
939 if (!i
&& !nohead
&& prhead(hbuf
, fname
, pagecnt
))
945 if (otln(buf
, j
, &ips
, &ops
, 0))
949 * if no more active files, done
960 if (i
&& prtail(lines
-i
, 0))
970 * inln(): input a line of data (unlimited length lines supported)
971 * Input is optionally expanded to spaces
976 * cps: column positon 1st char in buffer (large line support)
977 * trnc: throw away data more than lim up to \n
978 * mor: set if more data in line (not truncated)
981 inln(FILE *inf
, char *buf
, int lim
, int *cps
, int trnc
, int *mor
)
987 int chk
= (int)inchar
;
993 * expanding input option
995 while ((--lim
>= 0) && ((ch
= getc(inf
)) != EOF
)) {
997 * is this the input "tab" char
1001 * expand to number of spaces
1003 col
= (ptbuf
- buf
) + *cps
;
1004 col
= gap
- (col
% gap
);
1007 * if more than this line, push back
1009 if ((col
> lim
) && (ungetc(ch
, inf
) == EOF
))
1015 while ((--col
>= 0) && (--lim
>= 0))
1027 while ((--lim
>= 0) && ((ch
= getc(inf
)) != EOF
)) {
1043 * entire line processed
1051 * line was larger than limit
1055 * throw away rest of line
1057 while ((ch
= getc(inf
)) != EOF
) {
1065 * save column offset if not truncated
1075 * otln(): output a line of data. (Supports unlimited length lines)
1076 * output is optionally contracted to tabs
1078 * buf: output buffer with data
1079 * cnt: number of chars of valid data in buf
1080 * svips: buffer input column position (for large lines)
1081 * svops: buffer output column position (for large lines)
1082 * mor: output line not complete in this buf; more data to come.
1083 * 1 is more, 0 is complete, -1 is no \n's
1086 otln(char *buf
, int cnt
, int *svips
, int *svops
, int mor
)
1088 int ops
; /* last col output */
1089 int ips
; /* last col in buf examined */
1096 * contracting on output
1101 while (buf
< endbuf
) {
1103 * count number of spaces and ochar in buffer
1112 * simulate ochar processing
1114 if (*buf
== ochar
) {
1115 ips
+= gap
- (ips
% gap
);
1121 * got a non space char; contract out spaces
1125 * use as many ochar as will fit
1127 if ((tbps
= ops
+ gap
- (ops
% gap
)) > ips
)
1129 if (putchar(ochar
) == EOF
) {
1138 * finish off with spaces
1140 if (putchar(' ') == EOF
) {
1148 * output non space char
1150 if (putchar(*buf
++) == EOF
) {
1160 * if incomplete line, save position counts
1170 * use as many ochar as will fit
1172 if ((tbps
= ops
+ gap
- (ops
% gap
)) > ips
)
1174 if (putchar(ochar
) == EOF
) {
1182 * finish off with spaces
1184 if (putchar(' ') == EOF
) {
1194 * output is not contracted
1196 if (cnt
&& (fwrite(buf
, sizeof(char), cnt
, stdout
) <= 0)) {
1205 * process line end and double space as required
1207 if ((putchar('\n') == EOF
) || (dspace
&& (putchar('\n') == EOF
))) {
1215 * inskip(): skip over pgcnt pages with lncnt lines per page
1216 * file is closed at EOF (if not stdin).
1218 * inf FILE * to read from
1219 * pgcnt number of pages to skip
1220 * lncnt number of lines per page
1223 inskip(FILE *inf
, int pgcnt
, int lncnt
)
1228 while(--pgcnt
> 0) {
1230 while ((c
= getc(inf
)) != EOF
) {
1231 if ((c
== '\n') && (--cnt
== 0))
1244 * nxtfile: returns a FILE * to next file in arg list and sets the
1245 * time field for this file (or current date).
1247 * buf array to store proper date for the header.
1248 * dt if set skips the date processing (used with -m)
1251 nxtfile(int argc
, char **argv
, const char **fname
, char *buf
, int dt
)
1257 struct tm
*timeptr
= NULL
;
1258 struct stat statbuf
;
1259 static int twice
= -1;
1262 if (eoptind
>= argc
) {
1264 * no file listed; default, use standard input
1276 if (gettimeofday(&tv
, &tz
) < 0) {
1278 (void)fprintf(err
, "pr: cannot get time of day, %s\n",
1284 timeptr
= localtime(&tv_sec
);
1286 for (; eoptind
< argc
; ++eoptind
) {
1287 if (strcmp(argv
[eoptind
], "-") == 0) {
1289 * process a "-" for filename
1298 if (nohead
|| (dt
&& twice
))
1300 if (gettimeofday(&tv
, &tz
) < 0) {
1303 "pr: cannot get time of day, %s\n",
1308 timeptr
= localtime(&tv_sec
);
1311 * normal file processing
1313 if ((inf
= fopen(argv
[eoptind
], "r")) == NULL
) {
1317 (void)fprintf(err
, "pr: Cannot open %s, %s\n",
1318 argv
[eoptind
], strerror(errno
));
1326 *fname
= argv
[eoptind
];
1328 if (nohead
|| (dt
&& twice
))
1332 if (gettimeofday(&tv
, &tz
) < 0) {
1335 "pr: cannot get time of day, %s\n",
1340 timeptr
= localtime(&tv_sec
);
1342 if (fstat(fileno(inf
), &statbuf
) < 0) {
1346 "pr: Cannot stat %s, %s\n",
1347 argv
[eoptind
], strerror(errno
));
1350 timeptr
= localtime(&(statbuf
.st_mtime
));
1359 * set up time field used in header
1361 if (strftime(buf
, HDBUF
, timefrmt
, timeptr
) <= 0) {
1365 (void)fputs("pr: time conversion failed\n", err
);
1372 * addnum(): adds the line number to the column
1373 * Truncates from the front or pads with spaces as required.
1374 * Numbers are right justified.
1376 * buf buffer to store the number
1377 * wdth width of buffer to fill
1380 * NOTE: numbers occupy part of the column. The posix
1381 * spec does not specify if -i processing should or should not
1382 * occur on number padding. The spec does say it occupies
1383 * part of the column. The usage of addnum currently treats
1384 * numbers as part of the column so spaces may be replaced.
1387 addnum(char *buf
, int wdth
, int line
)
1389 char *pt
= buf
+ wdth
;
1392 *--pt
= digs
[line
% 10];
1394 } while (line
&& (pt
> buf
));
1397 * pad with space as required
1404 * prhead(): prints the top of page header
1406 * buf buffer with time field (and offset)
1407 * cnt number of chars in buf
1408 * fname fname field for header
1409 * pagcnt page number
1412 prhead(char *buf
, const char *fname
, int pagcnt
)
1417 if ((putchar('\n') == EOF
) || (putchar('\n') == EOF
)) {
1422 * posix is not clear if the header is subject to line length
1423 * restrictions. The specification for header line format
1424 * in the spec clearly does not limit length. No pr currently
1425 * restricts header length. However if we need to truncate in
1426 * a reasonable way, adjust the length of the printf by
1427 * changing HDFMT to allow a length max as an argument to printf.
1428 * buf (which contains the offset spaces and time field could
1431 * note only the offset (if any) is processed for tab expansion
1433 if (offst
&& otln(buf
, offst
, &ips
, &ops
, -1))
1435 (void)printf(HDFMT
,buf
+offst
, fname
, pagcnt
);
1440 * prtail(): pad page with empty lines (if required) and print page trailer
1443 * cnt number of lines of padding needed
1444 * incomp was a '\n' missing from last line output
1447 prtail(int cnt
, int incomp
)
1451 * only pad with no headers when incomplete last line
1454 ((dspace
&& (putchar('\n') == EOF
)) ||
1455 (putchar('\n') == EOF
))) {
1460 * but honor the formfeed request
1463 if (putchar('\f') == EOF
) {
1471 * if double space output two \n
1477 * if an odd number of lines per page, add an extra \n
1486 if ((incomp
&& (putchar('\n') == EOF
)) ||
1487 (putchar('\f') == EOF
)) {
1494 while (--cnt
>= 0) {
1495 if (putchar('\n') == EOF
) {
1504 * terminate(): when a SIGINT is recvd
1507 terminate(int which_sig __unused
)
1515 * flsh_errs(): output saved up diagnostic messages after all normal
1516 * processing has completed
1523 (void)fflush(stdout
);
1528 while (fgets(buf
, BUFSIZ
, err
) != NULL
)
1529 (void)fputs(buf
, stderr
);
1535 (void)fputs("pr: memory allocation failed\n", err
);
1541 (void)fprintf(err
, "pr: write failure, %s\n", strerror(errno
));
1548 "usage: pr [+page] [-col] [-adFfmprt] [-e[ch][gap]] [-h header]\n",
1551 " [-i[ch][gap]] [-l line] [-n[ch][width]] [-o offset]\n",err
);
1553 " [-L locale] [-s[ch]] [-w width] [-] [file ...]\n", err
);
1557 * setup: Validate command args, initialize and perform sanity
1561 setup(int argc
, char *argv
[])
1571 if (isatty(fileno(stdout
))) {
1573 * defer diagnostics until processing is done
1575 if ((err
= tmpfile()) == NULL
) {
1577 (void)fputs("Cannot defer diagnostic messages\n",stderr
);
1582 while ((c
= egetopt(argc
, argv
, "#adFfmrte?h:i?L:l:n?o:ps?w:")) != -1) {
1585 if ((pgnm
= atoi(eoptarg
)) < 1) {
1586 (void)fputs("pr: +page number must be 1 or more\n",
1592 if ((clcnt
= atoi(eoptarg
)) < 1) {
1593 (void)fputs("pr: -columns must be 1 or more\n", err
);
1607 if ((eoptarg
!= NULL
) && !isdigit((unsigned char)*eoptarg
))
1608 inchar
= *eoptarg
++;
1611 if ((eoptarg
!= NULL
) && isdigit((unsigned char)*eoptarg
)) {
1612 if ((ingap
= atoi(eoptarg
)) < 0) {
1614 "pr: -e gap must be 0 or more\n", err
);
1619 } else if ((eoptarg
!= NULL
) && (*eoptarg
!= '\0')) {
1621 "pr: invalid value for -e %s\n", eoptarg
);
1637 if ((eoptarg
!= NULL
) && !isdigit((unsigned char)*eoptarg
))
1641 if ((eoptarg
!= NULL
) && isdigit((unsigned char)*eoptarg
)) {
1642 if ((ogap
= atoi(eoptarg
)) < 0) {
1644 "pr: -i gap must be 0 or more\n", err
);
1649 } else if ((eoptarg
!= NULL
) && (*eoptarg
!= '\0')) {
1651 "pr: invalid value for -i %s\n", eoptarg
);
1660 if (!isdigit((unsigned char)*eoptarg
) || ((lines
=atoi(eoptarg
)) < 1)) {
1662 "pr: Number of lines must be 1 or more\n",err
);
1670 if ((eoptarg
!= NULL
) && !isdigit((unsigned char)*eoptarg
))
1671 nmchar
= *eoptarg
++;
1674 if ((eoptarg
!= NULL
) && isdigit((unsigned char)*eoptarg
)) {
1675 if ((nmwd
= atoi(eoptarg
)) < 1) {
1677 "pr: -n width must be 1 or more\n",err
);
1680 } else if ((eoptarg
!= NULL
) && (*eoptarg
!= '\0')) {
1682 "pr: invalid value for -n %s\n", eoptarg
);
1688 if (!isdigit((unsigned char)*eoptarg
) || ((offst
= atoi(eoptarg
))< 1)){
1689 (void)fputs("pr: -o offset must be 1 or more\n",
1702 if (eoptarg
== NULL
)
1706 if (*eoptarg
!= '\0') {
1708 "pr: invalid value for -s %s\n",
1719 if (!isdigit((unsigned char)*eoptarg
) || ((pgwd
= atoi(eoptarg
)) < 1)){
1721 "pr: -w width must be 1 or more \n",err
);
1732 * default and sanity checks
1736 if ((clcnt
= argc
- eoptind
) <= 1) {
1745 (void)fputs("pr: -a flag requires multiple columns\n",
1750 (void)fputs("pr: -m cannot be used with -a\n", err
);
1760 if (cflag
|| merge
) {
1773 "pr: -m cannot be used with multiple columns\n", err
);
1777 colwd
= (pgwd
+ 1 - (clcnt
* (nmwd
+ 2)))/clcnt
;
1778 pgwd
= ((colwd
+ nmwd
+ 2) * clcnt
) - 1;
1780 colwd
= (pgwd
+ 1 - clcnt
)/clcnt
;
1781 pgwd
= ((colwd
+ 1) * clcnt
) - 1;
1785 "pr: page width is too small for %d columns\n",clcnt
);
1793 * make sure long enough for headers. if not disable
1795 if (lines
<= HEADLEN
+ TAILLEN
)
1798 lines
-= HEADLEN
+ TAILLEN
;
1801 * adjust for double space on odd length pages
1813 (void) setlocale(LC_TIME
, (Lflag
!= NULL
) ? Lflag
: "");
1815 d_first
= (*nl_langinfo(D_MD_ORDER
) == 'd');
1816 timefrmt
= strdup(d_first
? TIMEFMTD
: TIMEFMTM
);