version 1.21, 2016/03/20 17:14:51 |
version 1.22, 2021/10/10 15:57:25 |
|
|
int |
int |
main(int argc, char *argv[]) |
main(int argc, char *argv[]) |
{ |
{ |
|
const char *errstr; |
FILE *fp; |
FILE *fp; |
long cnt; |
long cnt; |
int ch, firsttime; |
int ch, firsttime; |
long linecnt = 10; |
long linecnt = 10; |
char *p = NULL; |
|
int status = 0; |
int status = 0; |
|
|
if (pledge("stdio rpath", NULL) == -1) |
if (pledge("stdio rpath", NULL) == -1) |
|
|
/* handle obsolete -number syntax */ |
/* handle obsolete -number syntax */ |
if (argc > 1 && argv[1][0] == '-' && |
if (argc > 1 && argv[1][0] == '-' && |
isdigit((unsigned char)argv[1][1])) { |
isdigit((unsigned char)argv[1][1])) { |
p = argv[1] + 1; |
linecnt = strtonum(argv[1] + 1, 1, LONG_MAX, &errstr); |
|
if (errstr != NULL) |
|
errx(1, "count is %s: %s", errstr, argv[1] + 1); |
argc--; |
argc--; |
argv++; |
argv++; |
} |
} |
|
|
while ((ch = getopt(argc, argv, "n:")) != -1) { |
while ((ch = getopt(argc, argv, "n:")) != -1) { |
switch (ch) { |
switch (ch) { |
case 'n': |
case 'n': |
p = optarg; |
linecnt = strtonum(optarg, 1, LONG_MAX, &errstr); |
|
if (errstr != NULL) |
|
errx(1, "count is %s: %s", errstr, optarg); |
break; |
break; |
default: |
default: |
usage(); |
usage(); |
} |
} |
} |
} |
argc -= optind, argv += optind; |
argc -= optind, argv += optind; |
|
|
if (p) { |
|
const char *errstr; |
|
|
|
linecnt = strtonum(p, 1, LONG_MAX, &errstr); |
|
if (errstr) |
|
errx(1, "line count %s: %s", errstr, p); |
|
} |
|
|
|
for (firsttime = 1; ; firsttime = 0) { |
for (firsttime = 1; ; firsttime = 0) { |
if (!*argv) { |
if (!*argv) { |