version 1.27, 2018/07/31 02:55:57 |
version 1.28, 2021/11/01 23:20:35 |
|
|
#include <wchar.h> |
#include <wchar.h> |
#include <wctype.h> |
#include <wctype.h> |
|
|
#define MAXLINELEN (8 * 1024) |
|
|
|
int cflag, dflag, iflag, uflag; |
int cflag, dflag, iflag, uflag; |
int numchars, numfields, repeats; |
int numchars, numfields, repeats; |
|
|
|
|
int |
int |
main(int argc, char *argv[]) |
main(int argc, char *argv[]) |
{ |
{ |
char *t1, *t2; |
char *prevline, *t1, *t2, *thisline; |
FILE *ifp = NULL, *ofp = NULL; |
FILE *ifp = NULL, *ofp = NULL; |
|
size_t prevsize, thissize, tmpsize; |
int ch; |
int ch; |
char *prevline, *thisline; |
|
|
|
setlocale(LC_CTYPE, ""); |
setlocale(LC_CTYPE, ""); |
|
|
|
|
if (pledge("stdio", NULL) == -1) |
if (pledge("stdio", NULL) == -1) |
err(1, "pledge"); |
err(1, "pledge"); |
|
|
prevline = malloc(MAXLINELEN); |
prevsize = 0; |
thisline = malloc(MAXLINELEN); |
prevline = NULL; |
if (prevline == NULL || thisline == NULL) |
if (getline(&prevline, &prevsize, ifp) == -1) { |
err(1, "malloc"); |
free(prevline); |
|
if (ferror(ifp)) |
if (fgets(prevline, MAXLINELEN, ifp) == NULL) |
err(1, "getline"); |
exit(0); |
exit(0); |
|
} |
while (fgets(thisline, MAXLINELEN, ifp)) { |
|
|
thissize = 0; |
|
thisline = NULL; |
|
while (getline(&thisline, &thissize, ifp) != -1) { |
/* If requested get the chosen fields + character offsets. */ |
/* If requested get the chosen fields + character offsets. */ |
if (numfields || numchars) { |
if (numfields || numchars) { |
t1 = skip(thisline); |
t1 = skip(thisline); |
|
|
t1 = prevline; |
t1 = prevline; |
prevline = thisline; |
prevline = thisline; |
thisline = t1; |
thisline = t1; |
|
tmpsize = prevsize; |
|
prevsize = thissize; |
|
thissize = tmpsize; |
repeats = 0; |
repeats = 0; |
} else |
} else |
++repeats; |
++repeats; |
} |
} |
|
free(thisline); |
|
if (ferror(ifp)) |
|
err(1, "getline"); |
|
|
show(ofp, prevline); |
show(ofp, prevline); |
|
free(prevline); |
|
|
exit(0); |
exit(0); |
} |
} |
|
|