pr.c (98408) | pr.c (98552) |
---|---|
1/*- 2 * Copyright (c) 1991 Keith Muller. 3 * Copyright (c) 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Keith Muller of the University of California, San Diego. 8 * --- 19 unchanged lines hidden (view full) --- 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 35 * SUCH DAMAGE. | 1/*- 2 * Copyright (c) 1991 Keith Muller. 3 * Copyright (c) 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Keith Muller of the University of California, San Diego. 8 * --- 19 unchanged lines hidden (view full) --- 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 35 * SUCH DAMAGE. |
36 * 37 * $FreeBSD: head/usr.bin/pr/pr.c 98408 2002-06-19 01:45:03Z tjr $ | |
38 */ 39 40#ifndef lint | 36 */ 37 38#ifndef lint |
41static char copyright[] = | 39static const char copyright[] = |
42"@(#) Copyright (c) 1993\n\ 43 The Regents of the University of California. All rights reserved.\n"; 44#endif /* not lint */ 45 | 40"@(#) Copyright (c) 1993\n\ 41 The Regents of the University of California. All rights reserved.\n"; 42#endif /* not lint */ 43 |
44#if 0 |
|
46#ifndef lint 47static char sccsid[] = "@(#)pr.c 8.2 (Berkeley) 4/16/94"; 48#endif /* not lint */ | 45#ifndef lint 46static char sccsid[] = "@(#)pr.c 8.2 (Berkeley) 4/16/94"; 47#endif /* not lint */ |
48#endif |
|
49 | 49 |
50#include <sys/cdefs.h> 51__FBSDID("$FreeBSD: head/usr.bin/pr/pr.c 98552 2002-06-21 10:14:57Z markm $"); 52 |
|
50#include <sys/types.h> 51#include <sys/time.h> 52#include <sys/stat.h> 53 54#include <ctype.h> 55#include <errno.h> 56#include <langinfo.h> 57#include <locale.h> --- 47 unchanged lines hidden (view full) --- 105/* 106 * misc globals 107 */ 108FILE *err; /* error message file pointer */ 109int addone; /* page length is odd with double space */ 110int errcnt; /* error count on file processing */ 111char digs[] = "0123456789"; /* page number translation map */ 112 | 53#include <sys/types.h> 54#include <sys/time.h> 55#include <sys/stat.h> 56 57#include <ctype.h> 58#include <errno.h> 59#include <langinfo.h> 60#include <locale.h> --- 47 unchanged lines hidden (view full) --- 108/* 109 * misc globals 110 */ 111FILE *err; /* error message file pointer */ 112int addone; /* page length is odd with double space */ 113int errcnt; /* error count on file processing */ 114char digs[] = "0123456789"; /* page number translation map */ 115 |
116char fnamedefault[] = FNAME; 117 |
|
113int | 118int |
114main(argc, argv) 115 int argc; 116 char *argv[]; | 119main(int argc, char *argv[]) |
117{ 118 int ret_val; 119 120 if (signal(SIGINT, SIG_IGN) != SIG_IGN) 121 (void)signal(SIGINT, terminate); 122 ret_val = setup(argc, argv); 123 if (!ret_val) { 124 /* --- 14 unchanged lines hidden (view full) --- 139 exit(1); 140 return(0); 141} 142 143/* 144 * Check if we should pause and write an alert character and wait for a 145 * carriage return on /dev/tty. 146 */ | 120{ 121 int ret_val; 122 123 if (signal(SIGINT, SIG_IGN) != SIG_IGN) 124 (void)signal(SIGINT, terminate); 125 ret_val = setup(argc, argv); 126 if (!ret_val) { 127 /* --- 14 unchanged lines hidden (view full) --- 142 exit(1); 143 return(0); 144} 145 146/* 147 * Check if we should pause and write an alert character and wait for a 148 * carriage return on /dev/tty. 149 */ |
147void 148ttypause(pagecnt) 149 int pagecnt; | 150static void 151ttypause(int pagecnt) |
150{ 151 int pch; 152 FILE *ttyfp; 153 154 if ((pauseall || (pausefst && pagecnt == 1)) && 155 isatty(STDOUT_FILENO)) { 156 if ((ttyfp = fopen("/dev/tty", "r")) != NULL) { 157 (void)putc('\a', stderr); --- 4 unchanged lines hidden (view full) --- 162 } 163} 164 165/* 166 * onecol: print files with only one column of output. 167 * Line length is unlimited. 168 */ 169int | 152{ 153 int pch; 154 FILE *ttyfp; 155 156 if ((pauseall || (pausefst && pagecnt == 1)) && 157 isatty(STDOUT_FILENO)) { 158 if ((ttyfp = fopen("/dev/tty", "r")) != NULL) { 159 (void)putc('\a', stderr); --- 4 unchanged lines hidden (view full) --- 164 } 165} 166 167/* 168 * onecol: print files with only one column of output. 169 * Line length is unlimited. 170 */ 171int |
170onecol(argc, argv) 171 int argc; 172 char *argv[]; | 172onecol(int argc, char *argv[]) |
173{ | 173{ |
174 register int cnt = -1; 175 register int off; 176 register int lrgln; 177 register int linecnt; 178 register int num; | 174 int cnt = -1; 175 int off; 176 int lrgln; 177 int linecnt; 178 int num; |
179 int lncnt; 180 int pagecnt; 181 int ips; 182 int ops; 183 int cps; 184 char *obuf; 185 char *lbuf; 186 char *nbuf; --- 122 unchanged lines hidden (view full) --- 309 return(1); 310 return(0); 311} 312 313/* 314 * vertcol: print files with more than one column of output down a page 315 */ 316int | 179 int lncnt; 180 int pagecnt; 181 int ips; 182 int ops; 183 int cps; 184 char *obuf; 185 char *lbuf; 186 char *nbuf; --- 122 unchanged lines hidden (view full) --- 309 return(1); 310 return(0); 311} 312 313/* 314 * vertcol: print files with more than one column of output down a page 315 */ 316int |
317vertcol(argc, argv) 318 int argc; 319 char *argv[]; | 317vertcol(int argc, char *argv[]) |
320{ | 318{ |
321 register char *ptbf; 322 register char **lstdat; 323 register int i; 324 register int j; 325 register int cnt = -1; 326 register int pln; 327 register int *indy; | 319 char *ptbf; 320 char **lstdat; 321 int i; 322 int j; 323 int cnt = -1; 324 int pln; 325 int *indy; |
328 int cvc; 329 int *lindy; 330 int lncnt; 331 int stp; 332 int pagecnt; 333 int col = colwd + 1; 334 int mxlen = pgwd + offst + 1; 335 int mclcnt = clcnt - 1; --- 296 unchanged lines hidden (view full) --- 632 return(1); 633 return(0); 634} 635 636/* 637 * horzcol: print files with more than one column of output across a page 638 */ 639int | 326 int cvc; 327 int *lindy; 328 int lncnt; 329 int stp; 330 int pagecnt; 331 int col = colwd + 1; 332 int mxlen = pgwd + offst + 1; 333 int mclcnt = clcnt - 1; --- 296 unchanged lines hidden (view full) --- 630 return(1); 631 return(0); 632} 633 634/* 635 * horzcol: print files with more than one column of output across a page 636 */ 637int |
640horzcol(argc, argv) 641 int argc; 642 char *argv[]; | 638horzcol(int argc, char *argv[]) |
643{ | 639{ |
644 register char *ptbf; 645 register int pln; 646 register int cnt = -1; 647 register char *lstdat; 648 register int col = colwd + 1; 649 register int j; 650 register int i; | 640 char *ptbf; 641 int pln; 642 int cnt = -1; 643 char *lstdat; 644 int col = colwd + 1; 645 int j; 646 int i; |
651 int lncnt; 652 int pagecnt; 653 char *buf; 654 char *hbuf; 655 char *ohbuf; 656 char *fname; 657 FILE *inf; 658 int ips = 0; --- 118 unchanged lines hidden (view full) --- 777 return(0); 778} 779 780/* 781 * mulfile: print files with more than one column of output and 782 * more than one file concurrently 783 */ 784int | 647 int lncnt; 648 int pagecnt; 649 char *buf; 650 char *hbuf; 651 char *ohbuf; 652 char *fname; 653 FILE *inf; 654 int ips = 0; --- 118 unchanged lines hidden (view full) --- 773 return(0); 774} 775 776/* 777 * mulfile: print files with more than one column of output and 778 * more than one file concurrently 779 */ 780int |
785mulfile(argc, argv) 786 int argc; 787 char *argv[]; | 781mulfile(int argc, char *argv[]) |
788{ | 782{ |
789 register char *ptbf; 790 register int j; 791 register int pln; 792 register int cnt; 793 register char *lstdat; 794 register int i; | 783 char *ptbf; 784 int j; 785 int pln; 786 int cnt; 787 char *lstdat; 788 int i; |
795 FILE **fbuf; 796 int actf; 797 int lncnt; 798 int col; 799 int pagecnt; 800 int fproc; 801 char *buf; 802 char *hbuf; --- 190 unchanged lines hidden (view full) --- 993 * inf: file 994 * buf: buffer 995 * lim: buffer length 996 * cps: column positon 1st char in buffer (large line support) 997 * trnc: throw away data more than lim up to \n 998 * mor: set if more data in line (not truncated) 999 */ 1000int | 789 FILE **fbuf; 790 int actf; 791 int lncnt; 792 int col; 793 int pagecnt; 794 int fproc; 795 char *buf; 796 char *hbuf; --- 190 unchanged lines hidden (view full) --- 987 * inf: file 988 * buf: buffer 989 * lim: buffer length 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) 993 */ 994int |
1001inln(inf, buf, lim, cps, trnc, mor) 1002 FILE *inf; 1003 char *buf; 1004 register int lim; 1005 int *cps; 1006 int trnc; 1007 int *mor; | 995inln(FILE *inf, char *buf, int lim, int *cps, int trnc, int *mor) |
1008{ | 996{ |
1009 register int col; 1010 register int gap = ingap; 1011 register int ch = EOF; 1012 register char *ptbuf; 1013 register int chk = (int)inchar; | 997 int col; 998 int gap = ingap; 999 int ch = EOF; 1000 char *ptbuf; 1001 int chk = (int)inchar; |
1014 1015 ptbuf = buf; 1016 1017 if (gap) { 1018 /* 1019 * expanding input option 1020 */ 1021 while ((--lim >= 0) && ((ch = getc(inf)) != EOF)) { --- 82 unchanged lines hidden (view full) --- 1104 * buf: output buffer with data 1105 * cnt: number of chars of valid data in buf 1106 * svips: buffer input column position (for large lines) 1107 * svops: buffer output column position (for large lines) 1108 * mor: output line not complete in this buf; more data to come. 1109 * 1 is more, 0 is complete, -1 is no \n's 1110 */ 1111int | 1002 1003 ptbuf = buf; 1004 1005 if (gap) { 1006 /* 1007 * expanding input option 1008 */ 1009 while ((--lim >= 0) && ((ch = getc(inf)) != EOF)) { --- 82 unchanged lines hidden (view full) --- 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 1098 */ 1099int |
1112otln(buf, cnt, svips, svops, mor) 1113 register char *buf; 1114 int cnt; 1115 int *svops; 1116 int *svips; 1117 int mor; | 1100otln(char *buf, int cnt, int *svips, int *svops, int mor) |
1118{ | 1101{ |
1119 register int ops; /* last col output */ 1120 register int ips; /* last col in buf examined */ 1121 register int gap = ogap; 1122 register int tbps; 1123 register char *endbuf; | 1102 int ops; /* last col output */ 1103 int ips; /* last col in buf examined */ 1104 int gap = ogap; 1105 int tbps; 1106 char *endbuf; |
1124 1125 if (ogap) { 1126 /* 1127 * contracting on output 1128 */ 1129 endbuf = buf + cnt; 1130 ops = *svops; 1131 ips = *svips; --- 114 unchanged lines hidden (view full) --- 1246 * inskip(): skip over pgcnt pages with lncnt lines per page 1247 * file is closed at EOF (if not stdin). 1248 * 1249 * inf FILE * to read from 1250 * pgcnt number of pages to skip 1251 * lncnt number of lines per page 1252 */ 1253int | 1107 1108 if (ogap) { 1109 /* 1110 * contracting on output 1111 */ 1112 endbuf = buf + cnt; 1113 ops = *svops; 1114 ips = *svips; --- 114 unchanged lines hidden (view full) --- 1229 * inskip(): skip over pgcnt pages with lncnt lines per page 1230 * file is closed at EOF (if not stdin). 1231 * 1232 * inf FILE * to read from 1233 * pgcnt number of pages to skip 1234 * lncnt number of lines per page 1235 */ 1236int |
1254inskip(inf, pgcnt, lncnt) 1255 FILE *inf; 1256 register int pgcnt; 1257 register int lncnt; | 1237inskip(FILE *inf, int pgcnt, int lncnt) |
1258{ | 1238{ |
1259 register int c; 1260 register int cnt; | 1239 int c; 1240 int cnt; |
1261 1262 while(--pgcnt > 0) { 1263 cnt = lncnt; 1264 while ((c = getc(inf)) != EOF) { 1265 if ((c == '\n') && (--cnt == 0)) 1266 break; 1267 } 1268 if (c == EOF) { --- 8 unchanged lines hidden (view full) --- 1277/* 1278 * nxtfile: returns a FILE * to next file in arg list and sets the 1279 * time field for this file (or current date). 1280 * 1281 * buf array to store proper date for the header. 1282 * dt if set skips the date processing (used with -m) 1283 */ 1284FILE * | 1241 1242 while(--pgcnt > 0) { 1243 cnt = lncnt; 1244 while ((c = getc(inf)) != EOF) { 1245 if ((c == '\n') && (--cnt == 0)) 1246 break; 1247 } 1248 if (c == EOF) { --- 8 unchanged lines hidden (view full) --- 1257/* 1258 * nxtfile: returns a FILE * to next file in arg list and sets the 1259 * time field for this file (or current date). 1260 * 1261 * buf array to store proper date for the header. 1262 * dt if set skips the date processing (used with -m) 1263 */ 1264FILE * |
1285nxtfile(argc, argv, fname, buf, dt) 1286 int argc; 1287 char **argv; 1288 char **fname; 1289 char *buf; 1290 int dt; | 1265nxtfile(int argc, char *argv[], char **fname, char *buf, int dt) |
1291{ 1292 FILE *inf = NULL; 1293 struct timeval tv; 1294 time_t tv_sec; 1295 struct timezone tz; 1296 struct tm *timeptr = NULL; 1297 struct stat statbuf; 1298 static int twice = -1; --- 5 unchanged lines hidden (view full) --- 1304 */ 1305 if (twice) 1306 return(NULL); 1307 clearerr(stdin); 1308 inf = stdin; 1309 if (header != NULL) 1310 *fname = header; 1311 else | 1266{ 1267 FILE *inf = NULL; 1268 struct timeval tv; 1269 time_t tv_sec; 1270 struct timezone tz; 1271 struct tm *timeptr = NULL; 1272 struct stat statbuf; 1273 static int twice = -1; --- 5 unchanged lines hidden (view full) --- 1279 */ 1280 if (twice) 1281 return(NULL); 1282 clearerr(stdin); 1283 inf = stdin; 1284 if (header != NULL) 1285 *fname = header; 1286 else |
1312 *fname = FNAME; | 1287 *fname = fnamedefault; |
1313 if (nohead) 1314 return(inf); 1315 if (gettimeofday(&tv, &tz) < 0) { 1316 ++errcnt; 1317 (void)fprintf(err, "pr: cannot get time of day, %s\n", 1318 strerror(errno)); 1319 eoptind = argc - 1; 1320 return(NULL); --- 6 unchanged lines hidden (view full) --- 1327 /* 1328 * process a "-" for filename 1329 */ 1330 clearerr(stdin); 1331 inf = stdin; 1332 if (header != NULL) 1333 *fname = header; 1334 else | 1288 if (nohead) 1289 return(inf); 1290 if (gettimeofday(&tv, &tz) < 0) { 1291 ++errcnt; 1292 (void)fprintf(err, "pr: cannot get time of day, %s\n", 1293 strerror(errno)); 1294 eoptind = argc - 1; 1295 return(NULL); --- 6 unchanged lines hidden (view full) --- 1302 /* 1303 * process a "-" for filename 1304 */ 1305 clearerr(stdin); 1306 inf = stdin; 1307 if (header != NULL) 1308 *fname = header; 1309 else |
1335 *fname = FNAME; | 1310 *fname = fnamedefault; |
1336 ++eoptind; 1337 if (nohead || (dt && twice)) 1338 return(inf); 1339 if (gettimeofday(&tv, &tz) < 0) { 1340 ++errcnt; 1341 (void)fprintf(err, 1342 "pr: cannot get time of day, %s\n", 1343 strerror(errno)); --- 11 unchanged lines hidden (view full) --- 1355 continue; 1356 (void)fprintf(err, "pr: Cannot open %s, %s\n", 1357 argv[eoptind], strerror(errno)); 1358 continue; 1359 } 1360 if (header != NULL) 1361 *fname = header; 1362 else if (dt) | 1311 ++eoptind; 1312 if (nohead || (dt && twice)) 1313 return(inf); 1314 if (gettimeofday(&tv, &tz) < 0) { 1315 ++errcnt; 1316 (void)fprintf(err, 1317 "pr: cannot get time of day, %s\n", 1318 strerror(errno)); --- 11 unchanged lines hidden (view full) --- 1330 continue; 1331 (void)fprintf(err, "pr: Cannot open %s, %s\n", 1332 argv[eoptind], strerror(errno)); 1333 continue; 1334 } 1335 if (header != NULL) 1336 *fname = header; 1337 else if (dt) |
1363 *fname = FNAME; | 1338 *fname = fnamedefault; |
1364 else 1365 *fname = argv[eoptind]; 1366 ++eoptind; 1367 if (nohead || (dt && twice)) 1368 return(inf); 1369 1370 if (dt) { 1371 if (gettimeofday(&tv, &tz) < 0) { --- 46 unchanged lines hidden (view full) --- 1418 * 1419 * NOTE: numbers occupy part of the column. The posix 1420 * spec does not specify if -i processing should or should not 1421 * occur on number padding. The spec does say it occupies 1422 * part of the column. The usage of addnum currently treats 1423 * numbers as part of the column so spaces may be replaced. 1424 */ 1425void | 1339 else 1340 *fname = argv[eoptind]; 1341 ++eoptind; 1342 if (nohead || (dt && twice)) 1343 return(inf); 1344 1345 if (dt) { 1346 if (gettimeofday(&tv, &tz) < 0) { --- 46 unchanged lines hidden (view full) --- 1393 * 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. 1399 */ 1400void |
1426addnum(buf, wdth, line) 1427 register char *buf; 1428 register int wdth; 1429 register int line; | 1401addnum(char *buf, int wdth, int line) |
1430{ | 1402{ |
1431 register char *pt = buf + wdth; | 1403 char *pt = buf + wdth; |
1432 1433 do { 1434 *--pt = digs[line % 10]; 1435 line /= 10; 1436 } while (line && (pt > buf)); 1437 1438 /* 1439 * pad with space as required --- 6 unchanged lines hidden (view full) --- 1446 * prhead(): prints the top of page header 1447 * 1448 * buf buffer with time field (and offset) 1449 * cnt number of chars in buf 1450 * fname fname field for header 1451 * pagcnt page number 1452 */ 1453int | 1404 1405 do { 1406 *--pt = digs[line % 10]; 1407 line /= 10; 1408 } while (line && (pt > buf)); 1409 1410 /* 1411 * pad with space as required --- 6 unchanged lines hidden (view full) --- 1418 * prhead(): prints the top of page header 1419 * 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 1424 */ 1425int |
1454prhead(buf, fname, pagcnt) 1455 char *buf; 1456 char *fname; 1457 int pagcnt; | 1426prhead(char *buf, char *fname, int pagcnt) |
1458{ 1459 int ips = 0; 1460 int ops = 0; 1461 1462 if ((putchar('\n') == EOF) || (putchar('\n') == EOF)) { 1463 pfail(); 1464 return(1); 1465 } --- 18 unchanged lines hidden (view full) --- 1484/* 1485 * prtail(): pad page with empty lines (if required) and print page trailer 1486 * if requested 1487 * 1488 * cnt number of lines of padding needed 1489 * incomp was a '\n' missing from last line output 1490 */ 1491int | 1427{ 1428 int ips = 0; 1429 int ops = 0; 1430 1431 if ((putchar('\n') == EOF) || (putchar('\n') == EOF)) { 1432 pfail(); 1433 return(1); 1434 } --- 18 unchanged lines hidden (view full) --- 1453/* 1454 * prtail(): pad page with empty lines (if required) and print page trailer 1455 * if requested 1456 * 1457 * cnt number of lines of padding needed 1458 * incomp was a '\n' missing from last line output 1459 */ 1460int |
1492prtail(cnt, incomp) 1493 register int cnt; 1494 int incomp; | 1461prtail(int cnt, int incomp) |
1495{ 1496 if (nohead) { 1497 /* 1498 * only pad with no headers when incomplete last line 1499 */ 1500 if (incomp && 1501 ((dspace && (putchar('\n') == EOF)) || 1502 (putchar('\n') == EOF))) { --- 43 unchanged lines hidden (view full) --- 1546 } 1547 return(0); 1548} 1549 1550/* 1551 * terminate(): when a SIGINT is recvd 1552 */ 1553void | 1462{ 1463 if (nohead) { 1464 /* 1465 * only pad with no headers when incomplete last line 1466 */ 1467 if (incomp && 1468 ((dspace && (putchar('\n') == EOF)) || 1469 (putchar('\n') == EOF))) { --- 43 unchanged lines hidden (view full) --- 1513 } 1514 return(0); 1515} 1516 1517/* 1518 * terminate(): when a SIGINT is recvd 1519 */ 1520void |
1554terminate(which_sig) 1555 int which_sig; | 1521terminate(int which_sig __unused) |
1556{ 1557 flsh_errs(); 1558 exit(1); 1559} 1560 1561 1562/* 1563 * flsh_errs(): output saved up diagnostic messages after all normal 1564 * processing has completed 1565 */ 1566void | 1522{ 1523 flsh_errs(); 1524 exit(1); 1525} 1526 1527 1528/* 1529 * flsh_errs(): output saved up diagnostic messages after all normal 1530 * processing has completed 1531 */ 1532void |
1567flsh_errs() | 1533flsh_errs(void) |
1568{ 1569 char buf[BUFSIZ]; 1570 1571 (void)fflush(stdout); 1572 (void)fflush(err); 1573 if (err == stderr) 1574 return; 1575 rewind(err); 1576 while (fgets(buf, BUFSIZ, err) != NULL) 1577 (void)fputs(buf, stderr); 1578} 1579 1580void | 1534{ 1535 char buf[BUFSIZ]; 1536 1537 (void)fflush(stdout); 1538 (void)fflush(err); 1539 if (err == stderr) 1540 return; 1541 rewind(err); 1542 while (fgets(buf, BUFSIZ, err) != NULL) 1543 (void)fputs(buf, stderr); 1544} 1545 1546void |
1581mfail() | 1547mfail(void) |
1582{ 1583 (void)fputs("pr: memory allocation failed\n", err); 1584} 1585 1586void | 1548{ 1549 (void)fputs("pr: memory allocation failed\n", err); 1550} 1551 1552void |
1587pfail() | 1553pfail(void) |
1588{ 1589 (void)fprintf(err, "pr: write failure, %s\n", strerror(errno)); 1590} 1591 1592void | 1554{ 1555 (void)fprintf(err, "pr: write failure, %s\n", strerror(errno)); 1556} 1557 1558void |
1593usage() | 1559usage(void) |
1594{ 1595 (void)fputs( 1596 "usage: pr [+page] [-col] [-adFfmprt] [-e[ch][gap]] [-h header]\n", 1597 err); 1598 (void)fputs( 1599 " [-i[ch][gap]] [-l line] [-n[ch][width]] [-o offset]\n",err); 1600 (void)fputs( 1601 " [-L locale] [-s[ch]] [-w width] [-] [file ...]\n", err); 1602} 1603 1604/* 1605 * setup: Validate command args, initialize and perform sanity 1606 * checks on options 1607 */ 1608int | 1560{ 1561 (void)fputs( 1562 "usage: pr [+page] [-col] [-adFfmprt] [-e[ch][gap]] [-h header]\n", 1563 err); 1564 (void)fputs( 1565 " [-i[ch][gap]] [-l line] [-n[ch][width]] [-o offset]\n",err); 1566 (void)fputs( 1567 " [-L locale] [-s[ch]] [-w width] [-] [file ...]\n", err); 1568} 1569 1570/* 1571 * setup: Validate command args, initialize and perform sanity 1572 * checks on options 1573 */ 1574int |
1609setup(argc, argv) 1610 register int argc; 1611 register char **argv; | 1575setup(int argc, char *argv[]) |
1612{ | 1576{ |
1613 register int c; | 1577 int c; |
1614 int d_first; 1615 int eflag = 0; 1616 int iflag = 0; 1617 int wflag = 0; 1618 int cflag = 0; 1619 char *Lflag = NULL; 1620 1621 if (isatty(fileno(stdout))) { --- 236 unchanged lines hidden (view full) --- 1858 ++addone; 1859 lines /= 2; 1860 } 1861 } 1862 1863 (void) setlocale(LC_TIME, (Lflag != NULL) ? Lflag : ""); 1864 1865 d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); | 1578 int d_first; 1579 int eflag = 0; 1580 int iflag = 0; 1581 int wflag = 0; 1582 int cflag = 0; 1583 char *Lflag = NULL; 1584 1585 if (isatty(fileno(stdout))) { --- 236 unchanged lines hidden (view full) --- 1822 ++addone; 1823 lines /= 2; 1824 } 1825 } 1826 1827 (void) setlocale(LC_TIME, (Lflag != NULL) ? Lflag : ""); 1828 1829 d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); |
1866 timefrmt = d_first ? TIMEFMTD : TIMEFMTM; | 1830 timefrmt = strdup(d_first ? TIMEFMTD : TIMEFMTM); |
1867 1868 return(0); 1869} | 1831 1832 return(0); 1833} |