strings: Rename len
to min
This commit is contained in:
parent
5377a9c3d1
commit
7ef4038fb5
20
strings.c
20
strings.c
@ -10,33 +10,33 @@
|
|||||||
static char *format = "";
|
static char *format = "";
|
||||||
|
|
||||||
static void
|
static void
|
||||||
strings(FILE *fp, const char *fname, size_t len)
|
strings(FILE *fp, const char *fname, size_t min)
|
||||||
{
|
{
|
||||||
Rune r, *rbuf;
|
Rune r, *rbuf;
|
||||||
size_t i, bread;
|
size_t i, bread;
|
||||||
off_t off;
|
off_t off;
|
||||||
|
|
||||||
rbuf = ereallocarray(NULL, len, sizeof(*rbuf));
|
rbuf = ereallocarray(NULL, min, sizeof(*rbuf));
|
||||||
|
|
||||||
for (off = 0, i = 0; (bread = efgetrune(&r, fp, fname)); ) {
|
for (off = 0, i = 0; (bread = efgetrune(&r, fp, fname)); ) {
|
||||||
off += bread;
|
off += bread;
|
||||||
if (r == Runeerror)
|
if (r == Runeerror)
|
||||||
continue;
|
continue;
|
||||||
if (!isprintrune(r)) {
|
if (!isprintrune(r)) {
|
||||||
if (i == len)
|
if (i == min)
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
i = 0;
|
i = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (i == len) {
|
if (i == min) {
|
||||||
efputrune(&r, stdout, "<stdout>");
|
efputrune(&r, stdout, "<stdout>");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
rbuf[i++] = r;
|
rbuf[i++] = r;
|
||||||
if (i < len)
|
if (i < min)
|
||||||
continue;
|
continue;
|
||||||
printf(format, (long)off - i);
|
printf(format, (long)off - i);
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < min; i++)
|
||||||
efputrune(rbuf + i, stdout, "<stdout>");
|
efputrune(rbuf + i, stdout, "<stdout>");
|
||||||
}
|
}
|
||||||
free(rbuf);
|
free(rbuf);
|
||||||
@ -52,7 +52,7 @@ int
|
|||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
size_t len = 4;
|
size_t min = 4;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
char f;
|
char f;
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ main(int argc, char *argv[])
|
|||||||
case 'a':
|
case 'a':
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
len = estrtonum(EARGF(usage()), 1, LLONG_MAX);
|
min = estrtonum(EARGF(usage()), 1, LLONG_MAX);
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
format = estrdup("%8l#: ");
|
format = estrdup("%8l#: ");
|
||||||
@ -75,7 +75,7 @@ main(int argc, char *argv[])
|
|||||||
} ARGEND
|
} ARGEND
|
||||||
|
|
||||||
if (!argc) {
|
if (!argc) {
|
||||||
strings(stdin, "<stdin>", len);
|
strings(stdin, "<stdin>", min);
|
||||||
} else {
|
} else {
|
||||||
for (; *argv; argc--, argv++) {
|
for (; *argv; argc--, argv++) {
|
||||||
if (!strcmp(*argv, "-")) {
|
if (!strcmp(*argv, "-")) {
|
||||||
@ -86,7 +86,7 @@ main(int argc, char *argv[])
|
|||||||
ret = 1;
|
ret = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
strings(fp, *argv, len);
|
strings(fp, *argv, min);
|
||||||
if (fp != stdin && fshut(fp, *argv))
|
if (fp != stdin && fshut(fp, *argv))
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user