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 int pgnm; /* starting page number */
84 int clcnt; /* number of columns */
85 int colwd; /* column data width - multiple columns */
86 int across; /* mult col flag; write across page */
87 int dspace; /* double space flag */
88 char inchar; /* expand input char */
89 int ingap; /* expand input gap */
90 int pausefst; /* Pause before first page */
91 int pauseall; /* Pause before each page */
92 int formfeed; /* use formfeed as trailer */
93 char *header; /* header name instead of file name */
94 char ochar; /* contract output char */
95 int ogap; /* contract output gap */
96 int lines; /* number of lines per page */
97 int merge; /* merge multiple files in output */
98 char nmchar; /* line numbering append char */
99 int nmwd; /* width of line number field */
100 int offst; /* number of page offset spaces */
101 int nodiag; /* do not report file open errors */
102 char schar; /* text column separation character */
103 int sflag; /* -s option for multiple columns */
104 int nohead; /* do not write head and trailer */
105 int pgwd; /* page width with multiple col output */
106 const char *timefrmt; /* time conversion string */
111 FILE *err; /* error message file pointer */
112 int addone; /* page length is odd with double space */
113 int errcnt; /* error count on file processing */
114 char digs[] = "0123456789"; /* page number translation map */
116 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);
141 if (errcnt || ret_val)
147 * Check if we should pause and write an alert character and wait for a
148 * carriage return on /dev/tty.
151 ttypause(int pagecnt)
156 if ((pauseall || (pausefst && pagecnt == 1)) &&
157 isatty(STDOUT_FILENO)) {
158 if ((ttyfp = fopen("/dev/tty", "r")) != NULL) {
159 (void)putc('\a', stderr);
160 while ((pch = getc(ttyfp)) != '\n' && pch != EOF)
168 * onecol: print files with only one column of output.
169 * Line length is unlimited.
172 onecol(int argc, char *argv[])
200 * allocate line buffer
202 if ((obuf = malloc((unsigned)(LBUF + off)*sizeof(char))) == NULL) {
207 * allocate header buffer
209 if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) {
214 ohbuf = hbuf + offst;
218 nbuf[--num] = nmchar;
220 (void)memset(obuf, (int)' ', offst);
221 (void)memset(hbuf, (int)' ', offst);
227 while ((inf = nxtfile(argc, argv, &fname, ohbuf, 0)) != NULL) {
230 * skip to specified page
232 if (inskip(inf, pgnm, lines))
254 while (linecnt < lines) {
258 if ((cnt = inln(inf,lbuf,LBUF,&cps,0,&mor)) < 0)
260 if (!linecnt && !nohead &&
261 prhead(hbuf, fname, pagecnt))
269 addnum(nbuf, num, ++lncnt);
270 if (otln(obuf,cnt+off, &ips, &ops, mor))
272 } else if (otln(lbuf, cnt, &ips, &ops, mor))
276 * if line bigger than buffer, get more
284 * whole line rcvd. reset tab proc. state
293 * fill to end of page
295 if (linecnt && prtail(lines-linecnt-lrgln, lrgln))
299 * On EOF go to next file
314 * vertcol: print files with more than one column of output down a page
317 vertcol(int argc, char *argv[])
332 int mxlen = pgwd + offst + 1;
333 int mclcnt = clcnt - 1;
350 * allocate page buffer
352 if ((buf = malloc((unsigned)lines*mxlen*sizeof(char))) == NULL) {
358 * allocate page header
360 if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) {
364 ohbuf = hbuf + offst;
366 (void)memset(hbuf, (int)' ', offst);
369 * col pointers when no headers
373 (struct vcol *)malloc((unsigned)mvc*sizeof(struct vcol))) == NULL) {
379 * pointer into page where last data per line is located
381 if ((lstdat = (char **)malloc((unsigned)lines*sizeof(char *))) == NULL){
387 * fast index lookups to locate start of lines
389 if ((indy = (int *)malloc((unsigned)lines*sizeof(int))) == NULL) {
393 if ((lindy = (int *)malloc((unsigned)lines*sizeof(int))) == NULL) {
404 * initialize buffer lookup indexes and offset area
406 for (j = 0; j < lines; ++j) {
407 lindy[j] = j * mxlen;
408 indy[j] = lindy[j] + offst;
410 ptbf = buf + lindy[j];
411 (void)memset(ptbf, (int)' ', offst);
414 ptbf = buf + indy[j];
421 while ((inf = nxtfile(argc, argv, &fname, ohbuf, 0)) != NULL) {
424 * skip to requested page
426 if (inskip(inf, pgnm, lines))
443 for (i = 0; i < clcnt; ++i) {
446 * if last column, do not pad
457 * is this first column
460 ptbf = buf + indy[j];
470 addnum(ptbf, nmwd, ++lncnt);
478 cnt = inln(inf,ptbf,colwd,&cps,1,&mor);
485 * pad all but last column on page
489 * pad to end of column
493 else if ((pln = col-cnt) > 0) {
500 * remember last char in line
511 * when -t (no header) is specified the spec requires
512 * the min number of lines. The last page may not have
513 * balanced length columns. To fix this we must reorder
514 * the columns. This is a very slow technique so it is
515 * only used under limited conditions. Without -t, the
516 * balancing of text columns is unspecified. To NOT
517 * balance the last page, add the global variable
518 * nohead to the if statement below e.g.
520 * if ((cnt < 0) && nohead && cvc ......
525 * check to see if last page needs to be reordered
527 if ((cnt < 0) && cvc && ((mvc-cvc) >= clcnt)){
535 if (!nohead && prhead(hbuf, fname, pagecnt))
537 for (i = 0; i < pln; ++i) {
540 if (offst&& otln(buf,offst,&ips,&ops,1))
544 for (j = 0; j < clcnt; ++j) {
546 * determine column length
559 cnt = vc[tvc].cnt + 1;
564 if (otln(vc[tvc].pt, cnt, &ips,
574 if (otln(buf, 0, &ips, &ops, 0))
580 if (prtail((lines - pln), 0))
583 * done with output, go to next file
589 * determine how many lines to output
599 if (pln && !nohead && prhead(hbuf, fname, pagecnt))
605 for (i = 0; i < pln; ++i) {
606 ptbf = buf + lindy[i];
607 if ((j = lstdat[i] - ptbf) <= offst)
609 if (otln(ptbf, j, &ips, &ops, 0))
616 if (pln && prtail((lines - pln), 0))
620 * if EOF go to next file
635 * horzcol: print files with more than one column of output across a page
638 horzcol(int argc, char *argv[])
659 if ((buf = malloc((unsigned)(pgwd+offst+1)*sizeof(char))) == NULL) {
667 if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) {
671 ohbuf = hbuf + offst;
673 (void)memset(buf, (int)' ', offst);
674 (void)memset(hbuf, (int)' ', offst);
680 while ((inf = nxtfile(argc, argv, &fname, ohbuf, 0)) != NULL) {
682 if (inskip(inf, pgnm, lines))
698 for (i = 0; i < lines; ++i) {
708 * add number to column
710 addnum(ptbf, nmwd, ++lncnt);
717 if ((cnt = inln(inf,ptbf,colwd,&cps,1,
724 * if last line skip padding
730 * pad to end of column
734 else if ((pln = col - cnt) > 0) {
735 (void)memset(ptbf,(int)' ',pln);
741 * determine line length
743 if ((j = lstdat - buf) <= offst)
746 prhead(hbuf, fname, pagecnt))
751 if (otln(buf, j, &ips, &ops, 0))
758 if (i && prtail(lines-i, 0))
762 * if EOF go to next file
777 * mulfile: print files with more than one column of output and
778 * more than one file concurrently
781 mulfile(int argc, char *argv[])
805 * array of FILE *, one for each operand
807 if ((fbuf = (FILE **)malloc((unsigned)clcnt*sizeof(FILE *))) == NULL) {
815 if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) {
819 ohbuf = hbuf + offst;
822 * do not know how many columns yet. The number of operands provide an
823 * upper bound on the number of columns. We use the number of files
824 * we can open successfully to set the number of columns. The operation
825 * of the merge operation (-m) in relation to unsuccesful file opens
826 * is unspecified by posix.
830 if ((fbuf[j] = nxtfile(argc, argv, &fname, ohbuf, 1)) == NULL)
832 if (pgnm && (inskip(fbuf[j], pgnm, lines)))
844 * calculate page boundries based on open file count
848 colwd = (pgwd - clcnt - nmwd)/clcnt;
849 pgwd = ((colwd + 1) * clcnt) - nmwd - 2;
851 colwd = (pgwd + 1 - clcnt)/clcnt;
852 pgwd = ((colwd + 1) * clcnt) - 1;
856 "pr: page width too small for %d columns\n", clcnt);
865 if ((buf = malloc((unsigned)(pgwd+offst+1)*sizeof(char))) == NULL) {
870 (void)memset(buf, (int)' ', offst);
871 (void)memset(hbuf, (int)' ', offst);
880 * continue to loop while any file still has data
888 for (i = 0; i < lines; ++i) {
893 * add line number to line
895 addnum(ptbf, nmwd, ++lncnt);
905 for (j = 0; j < clcnt; ++j) {
906 if (fbuf[j] == NULL) {
911 } else if ((cnt = inln(fbuf[j], ptbf, colwd,
912 &cps, 1, &mor)) < 0) {
916 if (fbuf[j] != stdin)
917 (void)fclose(fbuf[j]);
931 * if last ACTIVE column, done with line
937 * pad to end of column
941 } else if ((pln = col - cnt) > 0) {
942 (void)memset(ptbf, (int)' ', pln);
948 * calculate data in line
950 if ((j = lstdat - buf) <= offst)
953 if (!i && !nohead && prhead(hbuf, fname, pagecnt))
959 if (otln(buf, j, &ips, &ops, 0))
963 * if no more active files, done
974 if (i && prtail(lines-i, 0))
984 * inln(): input a line of data (unlimited length lines supported)
985 * Input is optionally expanded to spaces
990 * cps: column positon 1st char in buffer (large line support)
991 * trnc: throw away data more than lim up to \n
992 * mor: set if more data in line (not truncated)
995 inln(FILE *inf, char *buf, int lim, int *cps, int trnc, int *mor)
1001 int chk = (int)inchar;
1007 * expanding input option
1009 while ((--lim >= 0) && ((ch = getc(inf)) != EOF)) {
1011 * is this the input "tab" char
1015 * expand to number of spaces
1017 col = (ptbuf - buf) + *cps;
1018 col = gap - (col % gap);
1021 * if more than this line, push back
1023 if ((col > lim) && (ungetc(ch, inf) == EOF))
1029 while ((--col >= 0) && (--lim >= 0))
1041 while ((--lim >= 0) && ((ch = getc(inf)) != EOF)) {
1057 * entire line processed
1065 * line was larger than limit
1069 * throw away rest of line
1071 while ((ch = getc(inf)) != EOF) {
1079 * save column offset if not truncated
1089 * otln(): output a line of data. (Supports unlimited length lines)
1090 * output is optionally contracted to tabs
1092 * buf: output buffer with data
1093 * cnt: number of chars of valid data in buf
1094 * svips: buffer input column position (for large lines)
1095 * svops: buffer output column position (for large lines)
1096 * mor: output line not complete in this buf; more data to come.
1097 * 1 is more, 0 is complete, -1 is no \n's
1100 otln(char *buf, int cnt, int *svips, int *svops, int mor)
1102 int ops; /* last col output */
1103 int ips; /* last col in buf examined */
1110 * contracting on output
1115 while (buf < endbuf) {
1117 * count number of spaces and ochar in buffer
1126 * simulate ochar processing
1128 if (*buf == ochar) {
1129 ips += gap - (ips % gap);
1135 * got a non space char; contract out spaces
1137 while (ips - ops > 1) {
1139 * use as many ochar as will fit
1141 if ((tbps = ops + gap - (ops % gap)) > ips)
1143 if (putchar(ochar) == EOF) {
1152 * finish off with spaces
1154 if (putchar(' ') == EOF) {
1162 * output non space char
1164 if (putchar(*buf++) == EOF) {
1174 * if incomplete line, save position counts
1182 while (ips - ops > 1) {
1184 * use as many ochar as will fit
1186 if ((tbps = ops + gap - (ops % gap)) > ips)
1188 if (putchar(ochar) == EOF) {
1196 * finish off with spaces
1198 if (putchar(' ') == EOF) {
1208 * output is not contracted
1210 if (cnt && (fwrite(buf, sizeof(char), cnt, stdout) <= 0)) {
1219 * process line end and double space as required
1221 if ((putchar('\n') == EOF) || (dspace && (putchar('\n') == EOF))) {
1229 * inskip(): skip over pgcnt pages with lncnt lines per page
1230 * file is closed at EOF (if not stdin).
1232 * inf FILE * to read from
1233 * pgcnt number of pages to skip
1234 * lncnt number of lines per page
1237 inskip(FILE *inf, int pgcnt, int lncnt)
1242 while(--pgcnt > 0) {
1244 while ((c = getc(inf)) != EOF) {
1245 if ((c == '\n') && (--cnt == 0))
1258 * nxtfile: returns a FILE * to next file in arg list and sets the
1259 * time field for this file (or current date).
1261 * buf array to store proper date for the header.
1262 * dt if set skips the date processing (used with -m)
1265 nxtfile(int argc, char **argv, const char **fname, char *buf, int dt)
1271 struct tm *timeptr = NULL;
1272 struct stat statbuf;
1273 static int twice = -1;
1276 if (eoptind >= argc) {
1278 * no file listed; default, use standard input
1287 *fname = fnamedefault;
1290 if (gettimeofday(&tv, &tz) < 0) {
1292 (void)fprintf(err, "pr: cannot get time of day, %s\n",
1298 timeptr = localtime(&tv_sec);
1300 for (; eoptind < argc; ++eoptind) {
1301 if (strcmp(argv[eoptind], "-") == 0) {
1303 * process a "-" for filename
1310 *fname = fnamedefault;
1312 if (nohead || (dt && twice))
1314 if (gettimeofday(&tv, &tz) < 0) {
1317 "pr: cannot get time of day, %s\n",
1322 timeptr = localtime(&tv_sec);
1325 * normal file processing
1327 if ((inf = fopen(argv[eoptind], "r")) == NULL) {
1331 (void)fprintf(err, "pr: cannot open %s, %s\n",
1332 argv[eoptind], strerror(errno));
1338 *fname = fnamedefault;
1340 *fname = argv[eoptind];
1342 if (nohead || (dt && twice))
1346 if (gettimeofday(&tv, &tz) < 0) {
1349 "pr: cannot get time of day, %s\n",
1354 timeptr = localtime(&tv_sec);
1356 if (fstat(fileno(inf), &statbuf) < 0) {
1360 "pr: cannot stat %s, %s\n",
1361 argv[eoptind], strerror(errno));
1364 timeptr = localtime(&(statbuf.st_mtime));
1373 * set up time field used in header
1375 if (strftime(buf, HDBUF, timefrmt, timeptr) <= 0) {
1379 (void)fputs("pr: time conversion failed\n", err);
1386 * addnum(): adds the line number to the column
1387 * Truncates from the front or pads with spaces as required.
1388 * Numbers are right justified.
1390 * buf buffer to store the number
1391 * wdth width of buffer to fill
1394 * NOTE: numbers occupy part of the column. The posix
1395 * spec does not specify if -i processing should or should not
1396 * occur on number padding. The spec does say it occupies
1397 * part of the column. The usage of addnum currently treats
1398 * numbers as part of the column so spaces may be replaced.
1401 addnum(char *buf, int wdth, int line)
1403 char *pt = buf + wdth;
1406 *--pt = digs[line % 10];
1408 } while (line && (pt > buf));
1411 * pad with space as required
1418 * prhead(): prints the top of page header
1420 * buf buffer with time field (and offset)
1421 * cnt number of chars in buf
1422 * fname fname field for header
1423 * pagcnt page number
1426 prhead(char *buf, const char *fname, int pagcnt)
1431 if ((putchar('\n') == EOF) || (putchar('\n') == EOF)) {
1436 * posix is not clear if the header is subject to line length
1437 * restrictions. The specification for header line format
1438 * in the spec clearly does not limit length. No pr currently
1439 * restricts header length. However if we need to truncate in
1440 * a reasonable way, adjust the length of the printf by
1441 * changing HDFMT to allow a length max as an argument to printf.
1442 * buf (which contains the offset spaces and time field could
1445 * note only the offset (if any) is processed for tab expansion
1447 if (offst && otln(buf, offst, &ips, &ops, -1))
1449 (void)printf(HDFMT,buf+offst, fname, pagcnt);
1454 * prtail(): pad page with empty lines (if required) and print page trailer
1457 * cnt number of lines of padding needed
1458 * incomp was a '\n' missing from last line output
1461 prtail(int cnt, int incomp)
1465 * only pad with no headers when incomplete last line
1468 ((dspace && (putchar('\n') == EOF)) ||
1469 (putchar('\n') == EOF))) {
1474 * but honor the formfeed request
1477 if (putchar('\f') == EOF) {
1485 * if double space output two \n
1491 * if an odd number of lines per page, add an extra \n
1500 if ((incomp && (putchar('\n') == EOF)) ||
1501 (putchar('\f') == EOF)) {
1508 while (--cnt >= 0) {
1509 if (putchar('\n') == EOF) {
1518 * terminate(): when a SIGINT is recvd
1521 terminate(int which_sig __unused)
1529 * flsh_errs(): output saved up diagnostic messages after all normal
1530 * processing has completed
1537 (void)fflush(stdout);
1542 while (fgets(buf, BUFSIZ, err) != NULL)
1543 (void)fputs(buf, stderr);
1549 (void)fputs("pr: memory allocation failed\n", err);
1555 (void)fprintf(err, "pr: write failure, %s\n", strerror(errno));
1562 "usage: pr [+page] [-col] [-adFfmprt] [-e[ch][gap]] [-h header]\n",
1565 " [-i[ch][gap]] [-l line] [-n[ch][width]] [-o offset]\n",err);
1567 " [-L locale] [-s[ch]] [-w width] [-] [file ...]\n", err);
1571 * setup: Validate command args, initialize and perform sanity
1575 setup(int argc, char *argv[])
1585 if (isatty(fileno(stdout))) {
1587 * defer diagnostics until processing is done
1589 if ((err = tmpfile()) == NULL) {
1591 (void)fputs("Cannot defer diagnostic messages\n",stderr);
1596 while ((c = egetopt(argc, argv, "#adFfmrte?h:i?L:l:n?o:ps?w:")) != -1) {
1599 if ((pgnm = atoi(eoptarg)) < 1) {
1600 (void)fputs("pr: +page number must be 1 or more\n",
1606 if ((clcnt = atoi(eoptarg)) < 1) {
1607 (void)fputs("pr: -columns must be 1 or more\n",err);
1621 if ((eoptarg != NULL) && !isdigit((unsigned char)*eoptarg))
1622 inchar = *eoptarg++;
1625 if ((eoptarg != NULL) && isdigit((unsigned char)*eoptarg)) {
1626 if ((ingap = atoi(eoptarg)) < 0) {
1628 "pr: -e gap must be 0 or more\n", err);
1633 } else if ((eoptarg != NULL) && (*eoptarg != '\0')) {
1635 "pr: invalid value for -e %s\n", eoptarg);
1651 if ((eoptarg != NULL) && !isdigit((unsigned char)*eoptarg))
1655 if ((eoptarg != NULL) && isdigit((unsigned char)*eoptarg)) {
1656 if ((ogap = atoi(eoptarg)) < 0) {
1658 "pr: -i gap must be 0 or more\n", err);
1663 } else if ((eoptarg != NULL) && (*eoptarg != '\0')) {
1665 "pr: invalid value for -i %s\n", eoptarg);
1674 if (!isdigit((unsigned char)*eoptarg) || ((lines=atoi(eoptarg)) < 1)) {
1676 "pr: number of lines must be 1 or more\n",err);
1684 if ((eoptarg != NULL) && !isdigit((unsigned char)*eoptarg))
1685 nmchar = *eoptarg++;
1688 if ((eoptarg != NULL) && isdigit((unsigned char)*eoptarg)) {
1689 if ((nmwd = atoi(eoptarg)) < 1) {
1691 "pr: -n width must be 1 or more\n",err);
1694 } else if ((eoptarg != NULL) && (*eoptarg != '\0')) {
1696 "pr: invalid value for -n %s\n", eoptarg);
1702 if (!isdigit((unsigned char)*eoptarg) || ((offst = atoi(eoptarg))< 1)){
1703 (void)fputs("pr: -o offset must be 1 or more\n",
1716 if (eoptarg == NULL)
1720 if (*eoptarg != '\0') {
1722 "pr: invalid value for -s %s\n",
1733 if (!isdigit((unsigned char)*eoptarg) || ((pgwd = atoi(eoptarg)) < 1)){
1735 "pr: -w width must be 1 or more \n",err);
1746 * default and sanity checks
1750 if ((clcnt = argc - eoptind) <= 1) {
1759 (void)fputs("pr: -a flag requires multiple columns\n",
1764 (void)fputs("pr: -m cannot be used with -a\n", err);
1774 if (cflag || merge) {
1787 "pr: -m cannot be used with multiple columns\n", err);
1791 colwd = (pgwd + 1 - (clcnt * (nmwd + 2)))/clcnt;
1792 pgwd = ((colwd + nmwd + 2) * clcnt) - 1;
1794 colwd = (pgwd + 1 - clcnt)/clcnt;
1795 pgwd = ((colwd + 1) * clcnt) - 1;
1799 "pr: page width is too small for %d columns\n",clcnt);
1807 * make sure long enough for headers. if not disable
1809 if (lines <= HEADLEN + TAILLEN)
1812 lines -= HEADLEN + TAILLEN;
1815 * adjust for double space on odd length pages
1827 (void) setlocale(LC_TIME, (Lflag != NULL) ? Lflag : "");
1829 d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
1830 timefrmt = strdup(d_first ? TIMEFMTD : TIMEFMTM);