diff options
author | rsc <devnull@localhost> | 2003-11-23 18:04:47 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2003-11-23 18:04:47 +0000 |
commit | bc7cb1a15a67c859c8c71c4b52bb35fe9425a63d (patch) | |
tree | 8ca0fe4e2418e6aa18dc74a236c577a719f6c6ed /src/cmd/strings.c | |
parent | f08fdedcee12c06e3ce9ac9bec363915978e8289 (diff) | |
download | plan9port-bc7cb1a15a67c859c8c71c4b52bb35fe9425a63d.tar.gz plan9port-bc7cb1a15a67c859c8c71c4b52bb35fe9425a63d.tar.bz2 plan9port-bc7cb1a15a67c859c8c71c4b52bb35fe9425a63d.zip |
new utilities.
the .C files compile but are renamed to avoid building automatically.
Diffstat (limited to 'src/cmd/strings.c')
-rw-r--r-- | src/cmd/strings.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/cmd/strings.c b/src/cmd/strings.c new file mode 100644 index 00000000..dbf57ff8 --- /dev/null +++ b/src/cmd/strings.c @@ -0,0 +1,88 @@ +#include <u.h> +#include <libc.h> +#include <bio.h> + +Biobuf *fin; +Biobuf fout; + +#define MINSPAN 6 /* Min characters in string */ + +#define BUFSIZE 70 + +void stringit(char *); +int isprint(Rune); + +void +main(int argc, char **argv) +{ + int i; + + Binit(&fout, 1, OWRITE); + if(argc < 2) { + stringit("/fd/0"); + exits(0); + } + + for(i = 1; i < argc; i++) { + if(argc > 2) + print("%s:\n", argv[i]); + + stringit(argv[i]); + } + + exits(0); +} + +void +stringit(char *str) +{ + long posn, start; + int cnt = 0; + long c; + + Rune buf[BUFSIZE]; + + if ((fin = Bopen(str, OREAD)) == 0) { + perror("open"); + return; + } + + start = 0; + posn = Boffset(fin); + while((c = Bgetrune(fin)) >= 0) { + if(isprint(c)) { + if(start == 0) + start = posn; + buf[cnt++] = c; + if(cnt == BUFSIZE-1) { + buf[cnt] = 0; + Bprint(&fout, "%8ld: %S ...\n", start, buf); + start = 0; + cnt = 0; + } + } else { + if(cnt >= MINSPAN) { + buf[cnt] = 0; + Bprint(&fout, "%8ld: %S\n", start, buf); + } + start = 0; + cnt = 0; + } + posn = Boffset(fin); + } + + if(cnt >= MINSPAN){ + buf[cnt] = 0; + Bprint(&fout, "%8ld: %S\n", start, buf); + } + Bterm(fin); +} + +int +isprint(Rune r) +{ + if ((r >= ' ' && r <0x7f) || r > 0xA0) + return 1; + else + return 0; +} |