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. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * $FreeBSD: src/usr.bin/pr/pr.c,v 1.9.2.4 2002/04/15 17:16:57 jmallett Exp $
38 * $DragonFly: src/usr.bin/pr/pr.c,v 1.3 2003/10/04 20:36:50 hmp Exp $
40 * @(#) Copyright (c) 1993 The Regents of the University of California. All rights reserved.
41 * @(#)pr.c 8.2 (Berkeley) 4/16/94
44 #include <sys/types.h>
62 * pr: a printing and pagination filter. If multiple input files
63 * are specified, each is read, formatted, and written to standard
64 * output. By default, input is separated into 66-line pages, each
65 * with a header that includes the page number, date, time and the
68 * Complies with posix P1003.2/D11
74 int pgnm; /* starting page number */
75 int clcnt; /* number of columns */
76 int colwd; /* column data width - multiple columns */
77 int across; /* mult col flag; write across page */
78 int dspace; /* double space flag */
79 char inchar; /* expand input char */
80 int ingap; /* expand input gap */
81 int pausefst; /* Pause before first page */
82 int pauseall; /* Pause before each page */
83 int formfeed; /* use formfeed as trailer */
84 char *header; /* header name instead of file name */
85 char ochar; /* contract output char */
86 int ogap; /* contract output gap */
87 int lines; /* number of lines per page */
88 int merge; /* merge multiple files in output */
89 char nmchar; /* line numbering append char */
90 int nmwd; /* width of line number field */
91 int offst; /* number of page offset spaces */
92 int nodiag; /* do not report file open errors */
93 char schar; /* text column separation character */
94 int sflag; /* -s option for multiple columns */
95 int nohead; /* do not write head and trailer */
96 int pgwd; /* page width with multiple col output */
97 char *timefrmt; /* time conversion string */
102 FILE *err; /* error message file pointer */
103 int addone; /* page length is odd with double space */
104 int errcnt; /* error count on file processing */
105 char digs[] = "0123456789"; /* page number translation map */
108 main(int argc, char **argv)
112 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
113 (void)signal(SIGINT, terminate);
114 ret_val = setup(argc, argv);
117 * select the output format based on options
120 ret_val = mulfile(argc, argv);
122 ret_val = onecol(argc, argv);
124 ret_val = horzcol(argc, argv);
126 ret_val = vertcol(argc, argv);
130 if (errcnt || ret_val)
136 * Check if we should pause and write an alert character and wait for a
137 * carriage return on /dev/tty.
140 ttypause(int pagecnt)
145 if ((pauseall || (pausefst && pagecnt == 1)) &&
146 isatty(STDOUT_FILENO)) {
147 if ((ttyfp = fopen("/dev/tty", "r")) != NULL) {
148 (void)putc('\a', stderr);
149 while ((pch = getc(ttyfp)) != '\n' && pch != EOF)
157 * onecol: print files with only one column of output.
158 * Line length is unlimited.
161 onecol(int argc, char **argv)
163 register int cnt = -1;
166 register int linecnt;
189 * allocate line buffer
191 if ((obuf = malloc((unsigned)(LBUF + off)*sizeof(char))) == NULL) {
196 * allocate header buffer
198 if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) {
203 ohbuf = hbuf + offst;
207 nbuf[--num] = nmchar;
209 (void)memset(obuf, (int)' ', offst);
210 (void)memset(hbuf, (int)' ', offst);
216 while ((inf = nxtfile(argc, argv, &fname, ohbuf, 0)) != NULL) {
219 * skip to specified page
221 if (inskip(inf, pgnm, lines))
243 while (linecnt < lines) {
247 if ((cnt = inln(inf,lbuf,LBUF,&cps,0,&mor)) < 0)
249 if (!linecnt && !nohead &&
250 prhead(hbuf, fname, pagecnt))
258 addnum(nbuf, num, ++lncnt);
259 if (otln(obuf,cnt+off, &ips, &ops, mor))
261 } else if (otln(lbuf, cnt, &ips, &ops, mor))
265 * if line bigger than buffer, get more
273 * whole line rcvd. reset tab proc. state
282 * fill to end of page
284 if (linecnt && prtail(lines-linecnt-lrgln, lrgln))
288 * On EOF go to next file
303 * vertcol: print files with more than one column of output down a page
306 vertcol(int argc, char **argv)
309 register char **lstdat;
312 register int cnt = -1;
321 int mxlen = pgwd + offst + 1;
322 int mclcnt = clcnt - 1;
339 * allocate page buffer
341 if ((buf = malloc((unsigned)lines*mxlen*sizeof(char))) == NULL) {
347 * allocate page header
349 if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) {
353 ohbuf = hbuf + offst;
355 (void)memset(hbuf, (int)' ', offst);
358 * col pointers when no headers
362 (struct vcol *)malloc((unsigned)mvc*sizeof(struct vcol))) == NULL) {
368 * pointer into page where last data per line is located
370 if ((lstdat = (char **)malloc((unsigned)lines*sizeof(char *))) == NULL){
376 * fast index lookups to locate start of lines
378 if ((indy = (int *)malloc((unsigned)lines*sizeof(int))) == NULL) {
382 if ((lindy = (int *)malloc((unsigned)lines*sizeof(int))) == NULL) {
393 * initialize buffer lookup indexes and offset area
395 for (j = 0; j < lines; ++j) {
396 lindy[j] = j * mxlen;
397 indy[j] = lindy[j] + offst;
399 ptbf = buf + lindy[j];
400 (void)memset(ptbf, (int)' ', offst);
403 ptbf = buf + indy[j];
410 while ((inf = nxtfile(argc, argv, &fname, ohbuf, 0)) != NULL) {
413 * skip to requested page
415 if (inskip(inf, pgnm, lines))
432 for (i = 0; i < clcnt; ++i) {
435 * if last column, do not pad
446 * is this first column
449 ptbf = buf + indy[j];
459 addnum(ptbf, nmwd, ++lncnt);
467 cnt = inln(inf,ptbf,colwd,&cps,1,&mor);
474 * pad all but last column on page
478 * pad to end of column
482 else if ((pln = col-cnt) > 0) {
489 * remember last char in line
500 * when -t (no header) is specified the spec requires
501 * the min number of lines. The last page may not have
502 * balanced length columns. To fix this we must reorder
503 * the columns. This is a very slow technique so it is
504 * only used under limited conditions. Without -t, the
505 * balancing of text columns is unspecified. To NOT
506 * balance the last page, add the global variable
507 * nohead to the if statement below e.g.
509 * if ((cnt < 0) && nohead && cvc ......
514 * check to see if last page needs to be reordered
516 if ((cnt < 0) && cvc && ((mvc-cvc) >= clcnt)){
524 if (!nohead && prhead(hbuf, fname, pagecnt))
526 for (i = 0; i < pln; ++i) {
529 if (offst&& otln(buf,offst,&ips,&ops,1))
533 for (j = 0; j < clcnt; ++j) {
535 * determine column length
548 cnt = vc[tvc].cnt + 1;
553 if (otln(vc[tvc].pt, cnt, &ips,
563 if (otln(buf, 0, &ips, &ops, 0))
569 if (prtail((lines - pln), 0))
572 * done with output, go to next file
578 * determine how many lines to output
588 if (pln && !nohead && prhead(hbuf, fname, pagecnt))
594 for (i = 0; i < pln; ++i) {
595 ptbf = buf + lindy[i];
596 if ((j = lstdat[i] - ptbf) <= offst)
598 if (otln(ptbf, j, &ips, &ops, 0))
605 if (pln && prtail((lines - pln), 0))
609 * if EOF go to next file
624 * horzcol: print files with more than one column of output across a page
627 horzcol(int argc, char **argv)
631 register int cnt = -1;
632 register char *lstdat;
633 register int col = colwd + 1;
648 if ((buf = malloc((unsigned)(pgwd+offst+1)*sizeof(char))) == NULL) {
656 if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) {
660 ohbuf = hbuf + offst;
662 (void)memset(buf, (int)' ', offst);
663 (void)memset(hbuf, (int)' ', offst);
669 while ((inf = nxtfile(argc, argv, &fname, ohbuf, 0)) != NULL) {
671 if (inskip(inf, pgnm, lines))
687 for (i = 0; i < lines; ++i) {
697 * add number to column
699 addnum(ptbf, nmwd, ++lncnt);
706 if ((cnt = inln(inf,ptbf,colwd,&cps,1,
713 * if last line skip padding
719 * pad to end of column
723 else if ((pln = col - cnt) > 0) {
724 (void)memset(ptbf,(int)' ',pln);
730 * determine line length
732 if ((j = lstdat - buf) <= offst)
735 prhead(hbuf, fname, pagecnt))
740 if (otln(buf, j, &ips, &ops, 0))
747 if (i && prtail(lines-i, 0))
751 * if EOF go to next file
766 * mulfile: print files with more than one column of output and
767 * more than one file concurrently
770 mulfile(int argc, char **argv)
776 register char *lstdat;
794 * array of FILE *, one for each operand
796 if ((fbuf = (FILE **)malloc((unsigned)clcnt*sizeof(FILE *))) == NULL) {
804 if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) {
808 ohbuf = hbuf + offst;
811 * do not know how many columns yet. The number of operands provide an
812 * upper bound on the number of columns. We use the number of files
813 * we can open successfully to set the number of columns. The operation
814 * of the merge operation (-m) in relation to unsuccesful file opens
815 * is unspecified by posix.
819 if ((fbuf[j] = nxtfile(argc, argv, &fname, ohbuf, 1)) == NULL)
821 if (pgnm && (inskip(fbuf[j], pgnm, lines)))
833 * calculate page boundries based on open file count
837 colwd = (pgwd - clcnt - nmwd)/clcnt;
838 pgwd = ((colwd + 1) * clcnt) - nmwd - 2;
840 colwd = (pgwd + 1 - clcnt)/clcnt;
841 pgwd = ((colwd + 1) * clcnt) - 1;
845 "pr: page width too small for %d columns\n", clcnt);
854 if ((buf = malloc((unsigned)(pgwd+offst+1)*sizeof(char))) == NULL) {
859 (void)memset(buf, (int)' ', offst);
860 (void)memset(hbuf, (int)' ', offst);
869 * continue to loop while any file still has data
877 for (i = 0; i < lines; ++i) {
882 * add line number to line
884 addnum(ptbf, nmwd, ++lncnt);
894 for (j = 0; j < clcnt; ++j) {
895 if (fbuf[j] == NULL) {
900 } else if ((cnt = inln(fbuf[j], ptbf, colwd,
901 &cps, 1, &mor)) < 0) {
905 if (fbuf[j] != stdin)
906 (void)fclose(fbuf[j]);
920 * if last ACTIVE column, done with line
926 * pad to end of column
930 } else if ((pln = col - cnt) > 0) {
931 (void)memset(ptbf, (int)' ', pln);
937 * calculate data in line
939 if ((j = lstdat - buf) <= offst)
942 if (!i && !nohead && prhead(hbuf, fname, pagecnt))
948 if (otln(buf, j, &ips, &ops, 0))
952 * if no more active files, done
963 if (i && prtail(lines-i, 0))
973 * inln(): input a line of data (unlimited length lines supported)
974 * Input is optionally expanded to spaces
979 * cps: column positon 1st char in buffer (large line support)
980 * trnc: throw away data more than lim up to \n
981 * mor: set if more data in line (not truncated)
984 inln(FILE *inf, char *buf, register int lim, int *cps, int trnc, int *mor)
987 register int gap = ingap;
988 register int ch = EOF;
989 register char *ptbuf;
990 register int chk = (int)inchar;
996 * expanding input option
998 while ((--lim >= 0) && ((ch = getc(inf)) != EOF)) {
1000 * is this the input "tab" char
1004 * expand to number of spaces
1006 col = (ptbuf - buf) + *cps;
1007 col = gap - (col % gap);
1010 * if more than this line, push back
1012 if ((col > lim) && (ungetc(ch, inf) == EOF))
1018 while ((--col >= 0) && (--lim >= 0))
1030 while ((--lim >= 0) && ((ch = getc(inf)) != EOF)) {
1046 * entire line processed
1054 * line was larger than limit
1058 * throw away rest of line
1060 while ((ch = getc(inf)) != EOF) {
1068 * save column offset if not truncated
1078 * otln(): output a line of data. (Supports unlimited length lines)
1079 * output is optionally contracted to tabs
1081 * buf: output buffer with data
1082 * cnt: number of chars of valid data in buf
1083 * svips: buffer input column position (for large lines)
1084 * svops: buffer output column position (for large lines)
1085 * mor: output line not complete in this buf; more data to come.
1086 * 1 is more, 0 is complete, -1 is no \n's
1089 otln(register char *buf, int cnt, int *svips, int *svops, int mor)
1091 register int ops; /* last col output */
1092 register int ips; /* last col in buf examined */
1093 register int gap = ogap;
1095 register char *endbuf;
1099 * contracting on output
1104 while (buf < endbuf) {
1106 * count number of spaces and ochar in buffer
1115 * simulate ochar processing
1117 if (*buf == ochar) {
1118 ips += gap - (ips % gap);
1124 * got a non space char; contract out spaces
1128 * use as many ochar as will fit
1130 if ((tbps = ops + gap - (ops % gap)) > ips)
1132 if (putchar(ochar) == EOF) {
1141 * finish off with spaces
1143 if (putchar(' ') == EOF) {
1151 * output non space char
1153 if (putchar(*buf++) == EOF) {
1163 * if incomplete line, save position counts
1173 * use as many ochar as will fit
1175 if ((tbps = ops + gap - (ops % gap)) > ips)
1177 if (putchar(ochar) == EOF) {
1185 * finish off with spaces
1187 if (putchar(' ') == EOF) {
1197 * output is not contracted
1199 if (cnt && (fwrite(buf, sizeof(char), cnt, stdout) <= 0)) {
1208 * process line end and double space as required
1210 if ((putchar('\n') == EOF) || (dspace && (putchar('\n') == EOF))) {
1218 * inskip(): skip over pgcnt pages with lncnt lines per page
1219 * file is closed at EOF (if not stdin).
1221 * inf FILE * to read from
1222 * pgcnt number of pages to skip
1223 * lncnt number of lines per page
1226 inskip(FILE *inf, register int pgcnt, register int lncnt)
1231 while(--pgcnt > 0) {
1233 while ((c = getc(inf)) != EOF) {
1234 if ((c == '\n') && (--cnt == 0))
1247 * nxtfile: returns a FILE * to next file in arg list and sets the
1248 * time field for this file (or current date).
1250 * buf array to store proper date for the header.
1251 * dt if set skips the date processing (used with -m)
1254 nxtfile(int argc, char **argv, char **fname, char *buf, int dt)
1260 struct tm *timeptr = NULL;
1261 struct stat statbuf;
1262 static int twice = -1;
1265 if (eoptind >= argc) {
1267 * no file listed; default, use standard input
1279 if (gettimeofday(&tv, &tz) < 0) {
1281 (void)fprintf(err, "pr: cannot get time of day, %s\n",
1287 timeptr = localtime(&tv_sec);
1289 for (; eoptind < argc; ++eoptind) {
1290 if (strcmp(argv[eoptind], "-") == 0) {
1292 * process a "-" for filename
1301 if (nohead || (dt && twice))
1303 if (gettimeofday(&tv, &tz) < 0) {
1306 "pr: cannot get time of day, %s\n",
1311 timeptr = localtime(&tv_sec);
1314 * normal file processing
1316 if ((inf = fopen(argv[eoptind], "r")) == NULL) {
1320 (void)fprintf(err, "pr: Cannot open %s, %s\n",
1321 argv[eoptind], strerror(errno));
1329 *fname = argv[eoptind];
1331 if (nohead || (dt && twice))
1335 if (gettimeofday(&tv, &tz) < 0) {
1338 "pr: cannot get time of day, %s\n",
1343 timeptr = localtime(&tv_sec);
1345 if (fstat(fileno(inf), &statbuf) < 0) {
1349 "pr: Cannot stat %s, %s\n",
1350 argv[eoptind], strerror(errno));
1353 timeptr = localtime(&(statbuf.st_mtime));
1362 * set up time field used in header
1364 if (strftime(buf, HDBUF, timefrmt, timeptr) <= 0) {
1368 (void)fputs("pr: time conversion failed\n", err);
1375 * addnum(): adds the line number to the column
1376 * Truncates from the front or pads with spaces as required.
1377 * Numbers are right justified.
1379 * buf buffer to store the number
1380 * wdth width of buffer to fill
1383 * NOTE: numbers occupy part of the column. The posix
1384 * spec does not specify if -i processing should or should not
1385 * occur on number padding. The spec does say it occupies
1386 * part of the column. The usage of addnum currently treats
1387 * numbers as part of the column so spaces may be replaced.
1390 addnum(register char *buf, register int wdth, register int line)
1392 register char *pt = buf + wdth;
1395 *--pt = digs[line % 10];
1397 } while (line && (pt > buf));
1400 * pad with space as required
1407 * prhead(): prints the top of page header
1409 * buf buffer with time field (and offset)
1410 * cnt number of chars in buf
1411 * fname fname field for header
1412 * pagcnt page number
1415 prhead(char *buf, char *fname, int pagcnt)
1420 if ((putchar('\n') == EOF) || (putchar('\n') == EOF)) {
1425 * posix is not clear if the header is subject to line length
1426 * restrictions. The specification for header line format
1427 * in the spec clearly does not limit length. No pr currently
1428 * restricts header length. However if we need to truncate in
1429 * an reasonable way, adjust the length of the printf by
1430 * changing HDFMT to allow a length max as an arguement printf.
1431 * buf (which contains the offset spaces and time field could
1434 * note only the offset (if any) is processed for tab expansion
1436 if (offst && otln(buf, offst, &ips, &ops, -1))
1438 (void)printf(HDFMT,buf+offst, fname, pagcnt);
1443 * prtail(): pad page with empty lines (if required) and print page trailer
1446 * cnt number of lines of padding needed
1447 * incomp was a '\n' missing from last line output
1450 prtail(register int cnt, int incomp)
1454 * only pad with no headers when incomplete last line
1457 ((dspace && (putchar('\n') == EOF)) ||
1458 (putchar('\n') == EOF))) {
1463 * but honor the formfeed request
1466 if (putchar('\f') == EOF) {
1474 * if double space output two \n
1480 * if an odd number of lines per page, add an extra \n
1489 if ((incomp && (putchar('\n') == EOF)) ||
1490 (putchar('\f') == EOF)) {
1497 while (--cnt >= 0) {
1498 if (putchar('\n') == EOF) {
1507 * terminate(): when a SIGINT is recvd
1510 terminate(int which_sig)
1518 * flsh_errs(): output saved up diagnostic messages after all normal
1519 * processing has completed
1526 (void)fflush(stdout);
1531 while (fgets(buf, BUFSIZ, err) != NULL)
1532 (void)fputs(buf, stderr);
1538 (void)fputs("pr: memory allocation failed\n", err);
1544 (void)fprintf(err, "pr: write failure, %s\n", strerror(errno));
1551 "usage: pr [+page] [-col] [-adFfmprt] [-e[ch][gap]] [-h header]\n",
1554 " [-i[ch][gap]] [-l line] [-n[ch][width]] [-o offset]\n",err);
1556 " [-L locale] [-s[ch]] [-w width] [-] [file ...]\n", err);
1560 * setup: Validate command args, initialize and perform sanity
1564 setup(register int argc, register char **argv)
1574 if (isatty(fileno(stdout))) {
1576 * defer diagnostics until processing is done
1578 if ((err = tmpfile()) == NULL) {
1580 (void)fputs("Cannot defer diagnostic messages\n",stderr);
1585 while ((c = egetopt(argc, argv, "#adFfmrte?h:i?L:l:n?o:ps?w:")) != -1) {
1588 if ((pgnm = atoi(eoptarg)) < 1) {
1589 (void)fputs("pr: +page number must be 1 or more\n",
1595 if ((clcnt = atoi(eoptarg)) < 1) {
1596 (void)fputs("pr: -columns must be 1 or more\n",err);
1610 if ((eoptarg != NULL) && !isdigit((unsigned char)*eoptarg))
1611 inchar = *eoptarg++;
1614 if ((eoptarg != NULL) && isdigit((unsigned char)*eoptarg)) {
1615 if ((ingap = atoi(eoptarg)) < 0) {
1617 "pr: -e gap must be 0 or more\n", err);
1622 } else if ((eoptarg != NULL) && (*eoptarg != '\0')) {
1624 "pr: invalid value for -e %s\n", eoptarg);
1640 if ((eoptarg != NULL) && !isdigit((unsigned char)*eoptarg))
1644 if ((eoptarg != NULL) && isdigit((unsigned char)*eoptarg)) {
1645 if ((ogap = atoi(eoptarg)) < 0) {
1647 "pr: -i gap must be 0 or more\n", err);
1652 } else if ((eoptarg != NULL) && (*eoptarg != '\0')) {
1654 "pr: invalid value for -i %s\n", eoptarg);
1663 if (!isdigit((unsigned char)*eoptarg) || ((lines=atoi(eoptarg)) < 1)) {
1665 "pr: Number of lines must be 1 or more\n",err);
1673 if ((eoptarg != NULL) && !isdigit((unsigned char)*eoptarg))
1674 nmchar = *eoptarg++;
1677 if ((eoptarg != NULL) && isdigit((unsigned char)*eoptarg)) {
1678 if ((nmwd = atoi(eoptarg)) < 1) {
1680 "pr: -n width must be 1 or more\n",err);
1683 } else if ((eoptarg != NULL) && (*eoptarg != '\0')) {
1685 "pr: invalid value for -n %s\n", eoptarg);
1691 if (!isdigit((unsigned char)*eoptarg) || ((offst = atoi(eoptarg))< 1)){
1692 (void)fputs("pr: -o offset must be 1 or more\n",
1705 if (eoptarg == NULL)
1709 if (*eoptarg != '\0') {
1711 "pr: invalid value for -s %s\n",
1722 if (!isdigit((unsigned char)*eoptarg) || ((pgwd = atoi(eoptarg)) < 1)){
1724 "pr: -w width must be 1 or more \n",err);
1735 * default and sanity checks
1739 if ((clcnt = argc - eoptind) <= 1) {
1748 (void)fputs("pr: -a flag requires multiple columns\n",
1753 (void)fputs("pr: -m cannot be used with -a\n", err);
1763 if (cflag || merge) {
1776 "pr: -m cannot be used with multiple columns\n", err);
1780 colwd = (pgwd + 1 - (clcnt * (nmwd + 2)))/clcnt;
1781 pgwd = ((colwd + nmwd + 2) * clcnt) - 1;
1783 colwd = (pgwd + 1 - clcnt)/clcnt;
1784 pgwd = ((colwd + 1) * clcnt) - 1;
1788 "pr: page width is too small for %d columns\n",clcnt);
1796 * make sure long enough for headers. if not disable
1798 if (lines <= HEADLEN + TAILLEN)
1801 lines -= HEADLEN + TAILLEN;
1804 * adjust for double space on odd length pages
1816 (void) setlocale(LC_TIME, (Lflag != NULL) ? Lflag : "");
1818 d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
1819 timefrmt = d_first ? TIMEFMTD : TIMEFMTM;