2013-08-14 09:41:55 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2014-11-13 18:54:28 +00:00
|
|
|
#include <ctype.h>
|
2013-08-14 09:41:55 +00:00
|
|
|
#include <stdio.h>
|
2014-11-13 17:29:30 +00:00
|
|
|
|
2013-08-14 09:41:55 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
static void dostrings(FILE *fp, const char *fname);
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2014-11-23 12:44:07 +00:00
|
|
|
eprintf("usage: %s [file ...]\n", argv0);
|
2013-08-14 09:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
FILE *fp;
|
2014-11-23 12:44:07 +00:00
|
|
|
int ret = 0;
|
2013-08-14 09:41:55 +00:00
|
|
|
|
|
|
|
ARGBEGIN {
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
2013-10-10 15:04:15 +00:00
|
|
|
if (argc == 0) {
|
2013-08-14 09:41:55 +00:00
|
|
|
dostrings(stdin, "<stdin>");
|
2013-10-10 15:04:15 +00:00
|
|
|
} else {
|
|
|
|
for (; argc > 0; argc--, argv++) {
|
2013-11-13 11:39:24 +00:00
|
|
|
if (!(fp = fopen(argv[0], "r"))) {
|
|
|
|
weprintf("fopen %s:", argv[0]);
|
2014-11-23 12:44:07 +00:00
|
|
|
ret = 1;
|
2013-11-13 11:39:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-10-10 15:04:15 +00:00
|
|
|
dostrings(fp, argv[0]);
|
|
|
|
fclose(fp);
|
|
|
|
}
|
2013-08-14 09:41:55 +00:00
|
|
|
}
|
2014-11-23 12:44:07 +00:00
|
|
|
return ret;
|
2013-08-14 09:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dostrings(FILE *fp, const char *fname)
|
|
|
|
{
|
|
|
|
unsigned char buf[BUFSIZ];
|
|
|
|
int c, i = 0;
|
|
|
|
off_t offset = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
offset++;
|
|
|
|
if (isprint(c = getc(fp)))
|
|
|
|
buf[i++] = c;
|
|
|
|
if ((!isprint(c) && i >= 6) || i == sizeof(buf) - 1) {
|
|
|
|
buf[i] = '\0';
|
|
|
|
printf("%8ld: %s\n", (long)offset - i - 1, buf);
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
} while (c != EOF);
|
|
|
|
if (ferror(fp))
|
|
|
|
eprintf("%s: read error:", fname);
|
|
|
|
}
|