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
39 static const char copyright[] =
40 "@(#) Copyright (c) 1993\n\
41 The Regents of the University of California. All rights reserved.\n";
46 static char sccsid[] = "@(#)pr.c 8.2 (Berkeley) 4/16/94";
50 #include <sys/cdefs.h>
51 __FBSDID("$FreeBSD$");
53 #include <sys/types.h>
71 * pr: a printing and pagination filter. If multiple input files
72 * are specified, each is read, formatted, and written to standard
73 * output. By default, input is separated into 66-line pages, each
74 * with a header that includes the page number, date, time and the
77 * Complies with posix P1003.2/D11
83 static int pgnm; /* starting page number */
84 static int clcnt; /* number of columns */
85 static int colwd; /* column data width - multiple columns */
86 static int across; /* mult col flag; write across page */
87 static int dspace; /* double space flag */
88 static char inchar; /* expand input char */
89 static int ingap; /* expand input gap */
90 static int pausefst; /* Pause before first page */
91 static int pauseall; /* Pause before each page */
92 static int formfeed; /* use formfeed as trailer */
93 static char *header; /* header name instead of file name */
94 static char ochar; /* contract output char */
95 static int ogap; /* contract output gap */
96 static int lines; /* number of lines per page */
97 static int merge; /* merge multiple files in output */
98 static char nmchar; /* line numbering append char */
99 static int nmwd; /* width of line number field */
100 static int offst; /* number of page offset spaces */
101 static int nodiag; /* do not report file open errors */
102 static char schar; /* text column separation character */
103 static int sflag; /* -s option for multiple columns */
104 static int nohead; /* do not write head and trailer */
105 static int pgwd; /* page width with multiple col output */
106 static char *timefrmt; /* time conversion string */
111 static FILE *err; /* error message file pointer */
112 static int addone; /* page length is odd with double space */
113 static int errcnt; /* error count on file processing */
114 static char digs[] = "0123456789"; /* page number translation map */
116 static char fnamedefault[] = FNAME;
119 main(int argc, char *argv[])
123 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
124 (void)signal(SIGINT, terminate);
125 ret_val = setup(argc, argv);
128 * select the output format based on options
131 ret_val = mulfile(argc, argv);
133 ret_val = onecol(argc, argv);
135 ret_val = horzcol(argc, argv);
137 ret_val = vertcol(argc, argv);
142 if (errcnt || ret_val)
148 * Check if we should pause and write an alert character and wait for a
149 * carriage return on /dev/tty.
152 ttypause(int pagecnt)
157 if ((pauseall || (pausefst && pagecnt == 1)) &&
158 isatty(STDOUT_FILENO)) {
159 if ((ttyfp = fopen("/dev/tty", "r")) != NULL) {
160 (void)putc('\a', stderr);
161 while ((pch = getc(ttyfp)) != '\n' && pch != EOF)
169 * onecol: print files with only one column of output.
170 * Line length is unlimited.
173 onecol(int argc, char *argv[])
201 * allocate line buffer
203 if ((obuf = malloc((unsigned)(LBUF + off)*sizeof(char))) == NULL) {
208 * allocate header buffer
210 if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) {
216 ohbuf = hbuf + offst;
220 nbuf[--num] = nmchar;
222 (void)memset(obuf, (int)' ', offst);
223 (void)memset(hbuf, (int)' ', offst);
229 while ((inf = nxtfile(argc, argv, &fname, ohbuf, 0)) != NULL) {
232 * skip to specified page
234 if (inskip(inf, pgnm, lines))
256 while (linecnt < lines) {
260 if ((cnt = inln(inf,lbuf,LBUF,&cps,0,&mor)) < 0)
262 if (!linecnt && !nohead &&
263 prhead(hbuf, fname, pagecnt))
271 addnum(nbuf, num, ++lncnt);
272 if (otln(obuf,cnt+off, &ips, &ops, mor))
274 } else if (otln(lbuf, cnt, &ips, &ops, mor))
278 * if line bigger than buffer, get more
286 * whole line rcvd. reset tab proc. state
295 * fill to end of page
297 if (linecnt && prtail(lines-linecnt-lrgln, lrgln))
301 * On EOF go to next file
322 * vertcol: print files with more than one column of output down a page
325 vertcol(int argc, char *argv[])
328 char **lstdat = NULL;
340 int mxlen = pgwd + offst + 1;
341 int mclcnt = clcnt - 1;
342 struct vcol *vc = NULL;
359 * allocate page buffer
361 if ((buf = malloc((unsigned)lines*mxlen*sizeof(char))) == NULL) {
367 * allocate page header
369 if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) {
373 ohbuf = hbuf + offst;
375 (void)memset(hbuf, (int)' ', offst);
378 * col pointers when no headers
382 (struct vcol *)malloc((unsigned)mvc*sizeof(struct vcol))) == NULL) {
388 * pointer into page where last data per line is located
390 if ((lstdat = (char **)malloc((unsigned)lines*sizeof(char *))) == NULL){
396 * fast index lookups to locate start of lines
398 if ((indy = (int *)malloc((unsigned)lines*sizeof(int))) == NULL) {
402 if ((lindy = (int *)malloc((unsigned)lines*sizeof(int))) == NULL) {
413 * initialize buffer lookup indexes and offset area
415 for (j = 0; j < lines; ++j) {
416 lindy[j] = j * mxlen;
417 indy[j] = lindy[j] + offst;
419 ptbf = buf + lindy[j];
420 (void)memset(ptbf, (int)' ', offst);
423 ptbf = buf + indy[j];
430 while ((inf = nxtfile(argc, argv, &fname, ohbuf, 0)) != NULL) {
433 * skip to requested page
435 if (inskip(inf, pgnm, lines))
452 for (i = 0; i < clcnt; ++i) {
455 * if last column, do not pad
466 * is this first column
469 ptbf = buf + indy[j];
479 addnum(ptbf, nmwd, ++lncnt);
487 cnt = inln(inf,ptbf,colwd,&cps,1,&mor);
494 * pad all but last column on page
498 * pad to end of column
502 else if ((pln = col-cnt) > 0) {
509 * remember last char in line
520 * when -t (no header) is specified the spec requires
521 * the min number of lines. The last page may not have
522 * balanced length columns. To fix this we must reorder
523 * the columns. This is a very slow technique so it is
524 * only used under limited conditions. Without -t, the
525 * balancing of text columns is unspecified. To NOT
526 * balance the last page, add the global variable
527 * nohead to the if statement below e.g.
529 * if ((cnt < 0) && nohead && cvc ......
534 * check to see if last page needs to be reordered
536 if ((cnt < 0) && cvc && ((mvc-cvc) >= clcnt)){
544 if (!nohead && prhead(hbuf, fname, pagecnt))
546 for (i = 0; i < pln; ++i) {
550 otln(buf,offst,&ips,&ops,1))
554 for (j = 0; j < clcnt; ++j) {
556 * determine column length
569 cnt = vc[tvc].cnt + 1;
574 if (otln(vc[tvc].pt, cnt, &ips,
584 if (otln(buf, 0, &ips, &ops, 0))
590 if (prtail((lines - pln), 0))
593 * done with output, go to next file
599 * determine how many lines to output
609 if (pln && !nohead && prhead(hbuf, fname, pagecnt))
615 for (i = 0; i < pln; ++i) {
616 ptbf = buf + lindy[i];
617 if ((j = lstdat[i] - ptbf) <= offst)
619 if (otln(ptbf, j, &ips, &ops, 0))
626 if (pln && prtail((lines - pln), 0))
630 * if EOF go to next file
653 * horzcol: print files with more than one column of output across a page
656 horzcol(int argc, char *argv[])
677 if ((buf = malloc((unsigned)(pgwd+offst+1)*sizeof(char))) == NULL) {
685 if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) {
690 ohbuf = hbuf + offst;
692 (void)memset(buf, (int)' ', offst);
693 (void)memset(hbuf, (int)' ', offst);
699 while ((inf = nxtfile(argc, argv, &fname, ohbuf, 0)) != NULL) {
701 if (inskip(inf, pgnm, lines))
717 for (i = 0; i < lines; ++i) {
727 * add number to column
729 addnum(ptbf, nmwd, ++lncnt);
736 if ((cnt = inln(inf,ptbf,colwd,&cps,1,
743 * if last line skip padding
749 * pad to end of column
753 else if ((pln = col - cnt) > 0) {
754 (void)memset(ptbf,(int)' ',pln);
760 * determine line length
762 if ((j = lstdat - buf) <= offst)
765 prhead(hbuf, fname, pagecnt))
770 if (otln(buf, j, &ips, &ops, 0))
777 if (i && prtail(lines-i, 0))
781 * if EOF go to next file
802 * mulfile: print files with more than one column of output and
803 * more than one file concurrently
806 mulfile(int argc, char *argv[])
831 * array of FILE *, one for each operand
833 if ((fbuf = (FILE **)malloc((unsigned)clcnt*sizeof(FILE *))) == NULL) {
841 if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) {
845 ohbuf = hbuf + offst;
848 * do not know how many columns yet. The number of operands provide an
849 * upper bound on the number of columns. We use the number of files
850 * we can open successfully to set the number of columns. The operation
851 * of the merge operation (-m) in relation to unsuccessful file opens
852 * is unspecified by posix.
856 if ((fbuf[j] = nxtfile(argc, argv, &fname, ohbuf, 1)) == NULL)
858 if (pgnm && (inskip(fbuf[j], pgnm, lines)))
870 * calculate page boundaries based on open file count
874 colwd = (pgwd - clcnt - nmwd)/clcnt;
875 pgwd = ((colwd + 1) * clcnt) - nmwd - 2;
877 colwd = (pgwd + 1 - clcnt)/clcnt;
878 pgwd = ((colwd + 1) * clcnt) - 1;
882 "pr: page width too small for %d columns\n", clcnt);
891 if ((buf = malloc((unsigned)(pgwd+offst+1)*sizeof(char))) == NULL) {
896 (void)memset(buf, (int)' ', offst);
897 (void)memset(hbuf, (int)' ', offst);
906 * continue to loop while any file still has data
914 for (i = 0; i < lines; ++i) {
919 * add line number to line
921 addnum(ptbf, nmwd, ++lncnt);
931 for (j = 0; j < clcnt; ++j) {
932 if (fbuf[j] == NULL) {
937 } else if ((cnt = inln(fbuf[j], ptbf, colwd,
938 &cps, 1, &mor)) < 0) {
942 if (fbuf[j] != stdin)
943 (void)fclose(fbuf[j]);
957 * if last ACTIVE column, done with line
963 * pad to end of column
967 } else if ((pln = col - cnt) > 0) {
968 (void)memset(ptbf, (int)' ', pln);
974 * calculate data in line
976 if ((j = lstdat - buf) <= offst)
979 if (!i && !nohead && prhead(hbuf, fname, pagecnt))
985 if (otln(buf, j, &ips, &ops, 0))
989 * if no more active files, done
1000 if (i && prtail(lines-i, 0))
1015 * inln(): input a line of data (unlimited length lines supported)
1016 * Input is optionally expanded to spaces
1020 * lim: buffer length
1021 * cps: column position 1st char in buffer (large line support)
1022 * trnc: throw away data more than lim up to \n
1023 * mor: set if more data in line (not truncated)
1026 inln(FILE *inf, char *buf, int lim, int *cps, int trnc, int *mor)
1032 int chk = (int)inchar;
1038 * expanding input option
1040 while ((--lim >= 0) && ((ch = getc(inf)) != EOF)) {
1042 * is this the input "tab" char
1046 * expand to number of spaces
1048 col = (ptbuf - buf) + *cps;
1049 col = gap - (col % gap);
1052 * if more than this line, push back
1054 if ((col > lim) && (ungetc(ch, inf) == EOF))
1060 while ((--col >= 0) && (--lim >= 0))
1072 while ((--lim >= 0) && ((ch = getc(inf)) != EOF)) {
1088 * entire line processed
1096 * line was larger than limit
1100 * throw away rest of line
1102 while ((ch = getc(inf)) != EOF) {
1110 * save column offset if not truncated
1120 * otln(): output a line of data. (Supports unlimited length lines)
1121 * output is optionally contracted to tabs
1123 * buf: output buffer with data
1124 * cnt: number of chars of valid data in buf
1125 * svips: buffer input column position (for large lines)
1126 * svops: buffer output column position (for large lines)
1127 * mor: output line not complete in this buf; more data to come.
1128 * 1 is more, 0 is complete, -1 is no \n's
1131 otln(char *buf, int cnt, int *svips, int *svops, int mor)
1133 int ops; /* last col output */
1134 int ips; /* last col in buf examined */
1141 * contracting on output
1146 while (buf < endbuf) {
1148 * count number of spaces and ochar in buffer
1157 * simulate ochar processing
1159 if (*buf == ochar) {
1160 ips += gap - (ips % gap);
1166 * got a non space char; contract out spaces
1168 while (ips - ops > 1) {
1170 * use as many ochar as will fit
1172 if ((tbps = ops + gap - (ops % gap)) > ips)
1174 if (putchar(ochar) == EOF) {
1183 * finish off with spaces
1185 if (putchar(' ') == EOF) {
1193 * output non space char
1195 if (putchar(*buf++) == EOF) {
1205 * if incomplete line, save position counts
1213 while (ips - ops > 1) {
1215 * use as many ochar as will fit
1217 if ((tbps = ops + gap - (ops % gap)) > ips)
1219 if (putchar(ochar) == EOF) {
1227 * finish off with spaces
1229 if (putchar(' ') == EOF) {
1239 * output is not contracted
1241 if (cnt && (fwrite(buf, sizeof(char), cnt, stdout) <= 0)) {
1250 * process line end and double space as required
1252 if ((putchar('\n') == EOF) || (dspace && (putchar('\n') == EOF))) {
1260 * inskip(): skip over pgcnt pages with lncnt lines per page
1261 * file is closed at EOF (if not stdin).
1263 * inf FILE * to read from
1264 * pgcnt number of pages to skip
1265 * lncnt number of lines per page
1268 inskip(FILE *inf, int pgcnt, int lncnt)
1273 while(--pgcnt > 0) {
1275 while ((c = getc(inf)) != EOF) {
1276 if ((c == '\n') && (--cnt == 0))
1289 * nxtfile: returns a FILE * to next file in arg list and sets the
1290 * time field for this file (or current date).
1292 * buf array to store proper date for the header.
1293 * dt if set skips the date processing (used with -m)
1296 nxtfile(int argc, char **argv, const char **fname, char *buf, int dt)
1300 struct tm *timeptr = NULL;
1301 struct stat statbuf;
1302 static int twice = -1;
1305 if (eoptind >= argc) {
1307 * no file listed; default, use standard input
1316 *fname = fnamedefault;
1319 if ((tv_sec = time(NULL)) == -1) {
1321 (void)fprintf(err, "pr: cannot get time of day, %s\n",
1326 timeptr = localtime(&tv_sec);
1328 for (; eoptind < argc; ++eoptind) {
1329 if (strcmp(argv[eoptind], "-") == 0) {
1331 * process a "-" for filename
1338 *fname = fnamedefault;
1340 if (nohead || (dt && twice))
1342 if ((tv_sec = time(NULL)) == -1) {
1345 "pr: cannot get time of day, %s\n",
1349 timeptr = localtime(&tv_sec);
1352 * normal file processing
1354 if ((inf = fopen(argv[eoptind], "r")) == NULL) {
1358 (void)fprintf(err, "pr: cannot open %s, %s\n",
1359 argv[eoptind], strerror(errno));
1365 *fname = fnamedefault;
1367 *fname = argv[eoptind];
1369 if (nohead || (dt && twice))
1373 if ((tv_sec = time(NULL)) == -1) {
1376 "pr: cannot get time of day, %s\n",
1381 timeptr = localtime(&tv_sec);
1383 if (fstat(fileno(inf), &statbuf) < 0) {
1387 "pr: cannot stat %s, %s\n",
1388 argv[eoptind], strerror(errno));
1391 timeptr = localtime(&(statbuf.st_mtime));
1400 * set up time field used in header
1402 if (strftime(buf, HDBUF, timefrmt, timeptr) <= 0) {
1406 (void)fputs("pr: time conversion failed\n", err);
1413 * addnum(): adds the line number to the column
1414 * Truncates from the front or pads with spaces as required.
1415 * Numbers are right justified.
1417 * buf buffer to store the number
1418 * wdth width of buffer to fill
1421 * NOTE: numbers occupy part of the column. The posix
1422 * spec does not specify if -i processing should or should not
1423 * occur on number padding. The spec does say it occupies
1424 * part of the column. The usage of addnum currently treats
1425 * numbers as part of the column so spaces may be replaced.
1428 addnum(char *buf, int wdth, int line)
1430 char *pt = buf + wdth;
1433 *--pt = digs[line % 10];
1435 } while (line && (pt > buf));
1438 * pad with space as required
1445 * prhead(): prints the top of page header
1447 * buf buffer with time field (and offset)
1448 * cnt number of chars in buf
1449 * fname fname field for header
1450 * pagcnt page number
1453 prhead(char *buf, const char *fname, int pagcnt)
1458 if ((putchar('\n') == EOF) || (putchar('\n') == EOF)) {
1463 * posix is not clear if the header is subject to line length
1464 * restrictions. The specification for header line format
1465 * in the spec clearly does not limit length. No pr currently
1466 * restricts header length. However if we need to truncate in
1467 * a reasonable way, adjust the length of the printf by
1468 * changing HDFMT to allow a length max as an argument to printf.
1469 * buf (which contains the offset spaces and time field could
1472 * note only the offset (if any) is processed for tab expansion
1474 if (offst && otln(buf, offst, &ips, &ops, -1))
1476 (void)printf(HDFMT,buf+offst, fname, pagcnt);
1481 * prtail(): pad page with empty lines (if required) and print page trailer
1484 * cnt number of lines of padding needed
1485 * incomp was a '\n' missing from last line output
1488 prtail(int cnt, int incomp)
1492 * only pad with no headers when incomplete last line
1495 ((dspace && (putchar('\n') == EOF)) ||
1496 (putchar('\n') == EOF))) {
1501 * but honor the formfeed request
1504 if (putchar('\f') == EOF) {
1512 * if double space output two \n
1518 * if an odd number of lines per page, add an extra \n
1527 if ((incomp && (putchar('\n') == EOF)) ||
1528 (putchar('\f') == EOF)) {
1535 while (--cnt >= 0) {
1536 if (putchar('\n') == EOF) {
1545 * terminate(): when a SIGINT is recvd
1548 terminate(int which_sig __unused)
1556 * flsh_errs(): output saved up diagnostic messages after all normal
1557 * processing has completed
1564 (void)fflush(stdout);
1569 while (fgets(buf, BUFSIZ, err) != NULL)
1570 (void)fputs(buf, stderr);
1576 (void)fputs("pr: memory allocation failed\n", err);
1582 (void)fprintf(err, "pr: write failure, %s\n", strerror(errno));
1589 "usage: pr [+page] [-col] [-adFfmprt] [-e[ch][gap]] [-h header]\n",
1592 " [-i[ch][gap]] [-l line] [-n[ch][width]] [-o offset]\n",err);
1594 " [-L locale] [-s[ch]] [-w width] [-] [file ...]\n", err);
1598 * setup: Validate command args, initialize and perform sanity
1602 setup(int argc, char *argv[])
1612 if (isatty(fileno(stdout))) {
1614 * defer diagnostics until processing is done
1616 if ((err = tmpfile()) == NULL) {
1618 (void)fputs("Cannot defer diagnostic messages\n",stderr);
1623 while ((c = egetopt(argc, argv, "#adFfmrte?h:i?L:l:n?o:ps?w:")) != -1) {
1626 if ((pgnm = atoi(eoptarg)) < 1) {
1627 (void)fputs("pr: +page number must be 1 or more\n",
1633 if ((clcnt = atoi(eoptarg)) < 1) {
1634 (void)fputs("pr: -columns must be 1 or more\n",err);
1648 if ((eoptarg != NULL) && !isdigit((unsigned char)*eoptarg))
1649 inchar = *eoptarg++;
1652 if ((eoptarg != NULL) && isdigit((unsigned char)*eoptarg)) {
1653 if ((ingap = atoi(eoptarg)) < 0) {
1655 "pr: -e gap must be 0 or more\n", err);
1660 } else if ((eoptarg != NULL) && (*eoptarg != '\0')) {
1662 "pr: invalid value for -e %s\n", eoptarg);
1678 if ((eoptarg != NULL) && !isdigit((unsigned char)*eoptarg))
1682 if ((eoptarg != NULL) && isdigit((unsigned char)*eoptarg)) {
1683 if ((ogap = atoi(eoptarg)) < 0) {
1685 "pr: -i gap must be 0 or more\n", err);
1690 } else if ((eoptarg != NULL) && (*eoptarg != '\0')) {
1692 "pr: invalid value for -i %s\n", eoptarg);
1701 if (!isdigit((unsigned char)*eoptarg) || ((lines=atoi(eoptarg)) < 1)) {
1703 "pr: number of lines must be 1 or more\n",err);
1711 if ((eoptarg != NULL) && !isdigit((unsigned char)*eoptarg))
1712 nmchar = *eoptarg++;
1715 if ((eoptarg != NULL) && isdigit((unsigned char)*eoptarg)) {
1716 if ((nmwd = atoi(eoptarg)) < 1) {
1718 "pr: -n width must be 1 or more\n",err);
1721 } else if ((eoptarg != NULL) && (*eoptarg != '\0')) {
1723 "pr: invalid value for -n %s\n", eoptarg);
1729 if (!isdigit((unsigned char)*eoptarg) || ((offst = atoi(eoptarg))< 1)){
1730 (void)fputs("pr: -o offset must be 1 or more\n",
1743 if (eoptarg == NULL)
1747 if (*eoptarg != '\0') {
1749 "pr: invalid value for -s %s\n",
1760 if ((eoptarg == NULL ) ||
1761 !isdigit((unsigned char)*eoptarg) ||
1762 ((pgwd = atoi(eoptarg)) < 1)){
1764 "pr: -w width must be 1 or more \n",err);
1775 * default and sanity checks
1779 if ((clcnt = argc - eoptind) <= 1) {
1788 (void)fputs("pr: -a flag requires multiple columns\n",
1793 (void)fputs("pr: -m cannot be used with -a\n", err);
1803 if (cflag || merge) {
1816 "pr: -m cannot be used with multiple columns\n", err);
1820 colwd = (pgwd + 1 - (clcnt * (nmwd + 2)))/clcnt;
1821 pgwd = ((colwd + nmwd + 2) * clcnt) - 1;
1823 colwd = (pgwd + 1 - clcnt)/clcnt;
1824 pgwd = ((colwd + 1) * clcnt) - 1;
1828 "pr: page width is too small for %d columns\n",clcnt);
1836 * make sure long enough for headers. if not disable
1838 if (lines <= HEADLEN + TAILLEN)
1841 lines -= HEADLEN + TAILLEN;
1844 * adjust for double space on odd length pages
1856 (void) setlocale(LC_TIME, (Lflag != NULL) ? Lflag : "");
1858 d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
1859 timefrmt = strdup(d_first ? TIMEFMTD : TIMEFMTM);