version 1.32, 2022/01/01 17:44:18 |
version 1.33, 2022/01/01 18:20:52 |
|
|
|
|
#include <ctype.h> |
#include <ctype.h> |
#include <err.h> |
#include <err.h> |
#include <errno.h> |
|
#include <limits.h> |
#include <limits.h> |
#include <locale.h> |
#include <locale.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
#include <strings.h> |
#include <unistd.h> |
#include <unistd.h> |
#include <wchar.h> |
#include <wchar.h> |
#include <wctype.h> |
#include <wctype.h> |
|
|
int |
int |
main(int argc, char *argv[]) |
main(int argc, char *argv[]) |
{ |
{ |
|
const char *errstr; |
char *p, *prevline, *t, *thisline, *tmp; |
char *p, *prevline, *t, *thisline, *tmp; |
size_t prevsize, thissize, tmpsize; |
size_t prevsize, thissize, tmpsize; |
ssize_t len; |
ssize_t len; |
|
|
|
|
obsolete(argv); |
obsolete(argv); |
while ((ch = getopt(argc, argv, "cdf:is:u")) != -1) { |
while ((ch = getopt(argc, argv, "cdf:is:u")) != -1) { |
const char *errstr; |
|
|
|
switch (ch) { |
switch (ch) { |
case 'c': |
case 'c': |
cflag = 1; |
cflag = 1; |
|
|
case 'f': |
case 'f': |
numfields = strtonum(optarg, 0, LLONG_MAX, &errstr); |
numfields = strtonum(optarg, 0, LLONG_MAX, &errstr); |
if (errstr) |
if (errstr) |
errx(1, "field skip value is %s: %s", |
errx(1, "fields is %s: %s", errstr, optarg); |
errstr, optarg); |
|
break; |
break; |
case 'i': |
case 'i': |
iflag = 1; |
iflag = 1; |
|
|
case 's': |
case 's': |
numchars = strtonum(optarg, 0, LLONG_MAX, &errstr); |
numchars = strtonum(optarg, 0, LLONG_MAX, &errstr); |
if (errstr) |
if (errstr) |
errx(1, |
errx(1, "chars is %s: %s", errstr, optarg); |
"character skip value is %s: %s", |
|
errstr, optarg); |
|
break; |
break; |
case 'u': |
case 'u': |
uflag = 1; |
uflag = 1; |
|
|
usage(); |
usage(); |
} |
} |
} |
} |
|
|
argc -= optind; |
argc -= optind; |
argv += optind; |
argv += optind; |
|
|
|
|
free(prevline); |
free(prevline); |
if (ferror(stdin)) |
if (ferror(stdin)) |
err(1, "getline"); |
err(1, "getline"); |
exit(0); |
return 0; |
} |
} |
if (prevline[len - 1] == '\n') |
if (prevline[len - 1] == '\n') |
prevline[len - 1] = '\0'; |
prevline[len - 1] = '\0'; |
|
|
show(prevline); |
show(prevline); |
free(prevline); |
free(prevline); |
|
|
exit(0); |
return 0; |
} |
} |
|
|
/* |
/* |
|
|
__dead void |
__dead void |
usage(void) |
usage(void) |
{ |
{ |
extern char *__progname; |
fprintf(stderr, |
|
|
(void)fprintf(stderr, |
|
"usage: %s [-ci] [-d | -u] [-f fields] [-s chars] [input_file [output_file]]\n", |
"usage: %s [-ci] [-d | -u] [-f fields] [-s chars] [input_file [output_file]]\n", |
__progname); |
getprogname()); |
exit(1); |
exit(1); |
} |
} |