pr.c (151701) | pr.c (204358) |
---|---|
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 * --- 34 unchanged lines hidden (view full) --- 43 44#if 0 45#ifndef lint 46static char sccsid[] = "@(#)pr.c 8.2 (Berkeley) 4/16/94"; 47#endif /* not lint */ 48#endif 49 50#include <sys/cdefs.h> | 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 * --- 34 unchanged lines hidden (view full) --- 43 44#if 0 45#ifndef lint 46static char sccsid[] = "@(#)pr.c 8.2 (Berkeley) 4/16/94"; 47#endif /* not lint */ 48#endif 49 50#include <sys/cdefs.h> |
51__FBSDID("$FreeBSD: head/usr.bin/pr/pr.c 151701 2005-10-26 17:37:54Z jhb $"); | 51__FBSDID("$FreeBSD: head/usr.bin/pr/pr.c 204358 2010-02-26 13:47:51Z ed $"); |
52 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> --- 1200 unchanged lines hidden (view full) --- 1260 * 1261 * buf array to store proper date for the header. 1262 * dt if set skips the date processing (used with -m) 1263 */ 1264FILE * 1265nxtfile(int argc, char **argv, const char **fname, char *buf, int dt) 1266{ 1267 FILE *inf = NULL; | 52 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> --- 1200 unchanged lines hidden (view full) --- 1260 * 1261 * buf array to store proper date for the header. 1262 * dt if set skips the date processing (used with -m) 1263 */ 1264FILE * 1265nxtfile(int argc, char **argv, const char **fname, char *buf, int dt) 1266{ 1267 FILE *inf = NULL; |
1268 struct timeval tv; | |
1269 time_t tv_sec; | 1268 time_t tv_sec; |
1270 struct timezone tz; | |
1271 struct tm *timeptr = NULL; 1272 struct stat statbuf; 1273 static int twice = -1; 1274 1275 ++twice; 1276 if (eoptind >= argc) { 1277 /* 1278 * no file listed; default, use standard input 1279 */ 1280 if (twice) 1281 return(NULL); 1282 clearerr(stdin); 1283 inf = stdin; 1284 if (header != NULL) 1285 *fname = header; 1286 else 1287 *fname = fnamedefault; 1288 if (nohead) 1289 return(inf); | 1269 struct tm *timeptr = NULL; 1270 struct stat statbuf; 1271 static int twice = -1; 1272 1273 ++twice; 1274 if (eoptind >= argc) { 1275 /* 1276 * no file listed; default, use standard input 1277 */ 1278 if (twice) 1279 return(NULL); 1280 clearerr(stdin); 1281 inf = stdin; 1282 if (header != NULL) 1283 *fname = header; 1284 else 1285 *fname = fnamedefault; 1286 if (nohead) 1287 return(inf); |
1290 if (gettimeofday(&tv, &tz) < 0) { | 1288 if ((tv_sec = time(NULL)) == -1) { |
1291 ++errcnt; 1292 (void)fprintf(err, "pr: cannot get time of day, %s\n", 1293 strerror(errno)); 1294 eoptind = argc - 1; 1295 return(NULL); 1296 } | 1289 ++errcnt; 1290 (void)fprintf(err, "pr: cannot get time of day, %s\n", 1291 strerror(errno)); 1292 eoptind = argc - 1; 1293 return(NULL); 1294 } |
1297 tv_sec = tv.tv_sec; | |
1298 timeptr = localtime(&tv_sec); 1299 } 1300 for (; eoptind < argc; ++eoptind) { 1301 if (strcmp(argv[eoptind], "-") == 0) { 1302 /* 1303 * process a "-" for filename 1304 */ 1305 clearerr(stdin); 1306 inf = stdin; 1307 if (header != NULL) 1308 *fname = header; 1309 else 1310 *fname = fnamedefault; 1311 ++eoptind; 1312 if (nohead || (dt && twice)) 1313 return(inf); | 1295 timeptr = localtime(&tv_sec); 1296 } 1297 for (; eoptind < argc; ++eoptind) { 1298 if (strcmp(argv[eoptind], "-") == 0) { 1299 /* 1300 * process a "-" for filename 1301 */ 1302 clearerr(stdin); 1303 inf = stdin; 1304 if (header != NULL) 1305 *fname = header; 1306 else 1307 *fname = fnamedefault; 1308 ++eoptind; 1309 if (nohead || (dt && twice)) 1310 return(inf); |
1314 if (gettimeofday(&tv, &tz) < 0) { | 1311 if ((tv_sec = time(NULL)) == -1) { |
1315 ++errcnt; 1316 (void)fprintf(err, 1317 "pr: cannot get time of day, %s\n", 1318 strerror(errno)); 1319 return(NULL); 1320 } | 1312 ++errcnt; 1313 (void)fprintf(err, 1314 "pr: cannot get time of day, %s\n", 1315 strerror(errno)); 1316 return(NULL); 1317 } |
1321 tv_sec = tv.tv_sec; | |
1322 timeptr = localtime(&tv_sec); 1323 } else { 1324 /* 1325 * normal file processing 1326 */ 1327 if ((inf = fopen(argv[eoptind], "r")) == NULL) { 1328 ++errcnt; 1329 if (nodiag) --- 8 unchanged lines hidden (view full) --- 1338 *fname = fnamedefault; 1339 else 1340 *fname = argv[eoptind]; 1341 ++eoptind; 1342 if (nohead || (dt && twice)) 1343 return(inf); 1344 1345 if (dt) { | 1318 timeptr = localtime(&tv_sec); 1319 } else { 1320 /* 1321 * normal file processing 1322 */ 1323 if ((inf = fopen(argv[eoptind], "r")) == NULL) { 1324 ++errcnt; 1325 if (nodiag) --- 8 unchanged lines hidden (view full) --- 1334 *fname = fnamedefault; 1335 else 1336 *fname = argv[eoptind]; 1337 ++eoptind; 1338 if (nohead || (dt && twice)) 1339 return(inf); 1340 1341 if (dt) { |
1346 if (gettimeofday(&tv, &tz) < 0) { | 1342 if ((tv_sec = time(NULL)) == -1) { |
1347 ++errcnt; 1348 (void)fprintf(err, 1349 "pr: cannot get time of day, %s\n", 1350 strerror(errno)); 1351 return(NULL); 1352 } | 1343 ++errcnt; 1344 (void)fprintf(err, 1345 "pr: cannot get time of day, %s\n", 1346 strerror(errno)); 1347 return(NULL); 1348 } |
1353 tv_sec = tv.tv_sec; | |
1354 timeptr = localtime(&tv_sec); 1355 } else { 1356 if (fstat(fileno(inf), &statbuf) < 0) { 1357 ++errcnt; 1358 (void)fclose(inf); 1359 (void)fprintf(err, 1360 "pr: cannot stat %s, %s\n", 1361 argv[eoptind], strerror(errno)); --- 472 unchanged lines hidden --- | 1349 timeptr = localtime(&tv_sec); 1350 } else { 1351 if (fstat(fileno(inf), &statbuf) < 0) { 1352 ++errcnt; 1353 (void)fclose(inf); 1354 (void)fprintf(err, 1355 "pr: cannot stat %s, %s\n", 1356 argv[eoptind], strerror(errno)); --- 472 unchanged lines hidden --- |