we look for strings.c, it is broken, this strings.c will make us go.

This commit is contained in:
cinap_lenrek 2014-05-30 04:05:18 +02:00
parent 5246416621
commit 17d0dea87c
2 changed files with 46 additions and 51 deletions

View file

@ -24,12 +24,10 @@ Printable characters are taken to be
.SM ASCII
characters from blank through tilde (hexadecimal 20 through 7E), inclusive,
and
all other characters from value 00A0 to FFFF.
all other characters above A0.
Strings reports
the decimal offset within the file at which the string starts and the text
of the string. If the string is longer than 70 runes the line is
terminated by three dots and the printing is resumed on the next
line with the offset of the continuation line.
of the string.
.SH SOURCE
.B /sys/src/cmd/strings.c
.SH SEE ALSO

View file

@ -2,16 +2,14 @@
#include <libc.h>
#include <bio.h>
Biobuf *fin;
Biobuf fin;
Biobuf fout;
#define MINSPAN 6 /* Min characters in string (default) */
#define BUFSIZE 70
void stringit(char *);
void stringit(int);
int isprint(Rune);
static int minspan = MINSPAN;
int minspan = 6; /* Min characters in string (default) */
Rune *span;
static void
usage(void)
@ -23,75 +21,74 @@ usage(void)
void
main(int argc, char **argv)
{
int i;
int i, fd;
ARGBEGIN{
case 'm':
minspan = atoi(EARGF(usage()));
if(minspan <= 0)
usage();
break;
default:
usage();
break;
}ARGEND
span = malloc(sizeof(Rune)*(minspan+1));
if(span == nil)
sysfatal("out of memory");
Binit(&fout, 1, OWRITE);
if(argc < 1) {
stringit("/fd/0");
stringit(0);
exits(0);
}
for(i = 0; i < argc; i++) {
if(argc > 2)
print("%s:\n", argv[i]);
stringit(argv[i]);
if(argc > 1){
Bprint(&fout, "%s:\n", argv[i]);
Bflush(&fout);
}
if((fd = open(argv[i], OREAD)) < 0){
perror("open");
continue;
}
stringit(fd);
close(fd);
}
exits(0);
}
void
stringit(char *str)
stringit(int fd)
{
long posn, start;
int cnt = 0;
Rune *sp;
long c;
Rune buf[BUFSIZE];
if ((fin = Bopen(str, OREAD)) == 0) {
perror("open");
return;
}
start = 0;
posn = Boffset(fin);
while((c = Bgetrune(fin)) >= 0) {
Binit(&fin, fd, OREAD);
sp = span;
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;
if(sp == nil){
Bputrune(&fout, c);
continue;
}
*sp++ = c;
if((sp-span) < minspan)
continue;
*sp = 0;
Bprint(&fout, "%8lld: %S", Boffset(&fin)-minspan, span);
sp = nil;
} else {
if(cnt >= minspan) {
buf[cnt] = 0;
Bprint(&fout, "%8ld: %S\n", start, buf);
}
start = 0;
cnt = 0;
}
posn = Boffset(fin);
if(sp == nil)
Bputrune(&fout, '\n');
sp = span;
}
}
if(cnt >= minspan){
buf[cnt] = 0;
Bprint(&fout, "%8ld: %S\n", start, buf);
}
Bterm(fin);
if(sp == nil)
Bputrune(&fout, '\n');
Bterm(&fin);
}
int