Путь: Toys/POSIX, команды версии: Ver.4 Ver.9 strings Комментарии в файле strings.c :
Исходный текст в файле strings.c #define FOR_strings #include "toys.h" GLOBALS( long n; char *t; ) static void do_strings(int fd, char *filename) { int nread, i, wlen = TT.n, count = 0; off_t offset = 0; char *string = 0, pattern[8]; if (TT.t) if (!(string = strchr("oxd", *TT.t))) error_exit("-t needs oxd"); sprintf(pattern, "%%7ll%c ", string ? *string : 'd'); // input buffer can wrap before we have enough data to output, so // copy start of string to temporary buffer until enough to output string = xzalloc(wlen+1); for (i = nread = 0; ;i++) { if (i >= nread) { nread = read(fd, toybuf, sizeof(toybuf)); i = 0; if (nread < 0) perror_msg_raw(filename); if (nread < 1) { if (count) goto flush; break; } } offset++; if ((toybuf[i]>=32 && toybuf[i]<=126) || toybuf[i]=='\t') { if (count == wlen) fputc(toybuf[i], stdout); else { string[count++] = toybuf[i]; if (count == wlen) { if (FLAG(f)) printf("%s: ", filename); if (FLAG(o) || FLAG(t)) printf(pattern, (long long)(offset - wlen)); printf("%s", string); } } continue; } flush: // End of previous string if (count == wlen) xputc('\n'); count = 0; } xclose(fd); free(string); } void strings_main(void) { loopfiles(toys.optargs, do_strings); } |