
#ifdef TPLTER

CMD =
    Strings;

VERSION = "1.0";

DESCRIPTION = {{
	FILTER
	    Extracts Printable Strings from binary files;
	    each line one string.

	OPTIONS
	    MIN/N/K	- Minimum length of a found string (defaults to 6)
	    BANNER/S	- prepend each string with the filename
	    -7=ASCII/S	- only search for 7bit ascii characters

	OUTPUT
	    all readable strings of the input
}};

HISTORY = {{
	14-02-95 b_noll created
	16-02-95 b_noll created .data file
	17-02-95 b_noll added ASCII/S
	23-02-95 b_noll updated documentation
	26-02-95 b_noll added breakcheck
}};

TEMPLATE =
    "MIN/N/K,BANNER/S,-7=ASCII/S";

ARGS = {{
#define MAXMIN (MAXLINELEN / 2)
#define DEFMIN	 6

    ULONG  *min;
    ULONG   banner;
    ULONG   ascii;
}};

BODY = {{
    ULONG found  = 0;
    ULONG min	 = DEFMIN;
    int   c, mask;
    UBYTE buffer[MAXLINELEN + 1];

#define is_printable(c) ((mask > c) && ((c & 127) > 31) && (c != 127))

    if ((argv->min) && (*argv->min) && (*argv->min < MAXMIN))
	min = *argv->min;

    mask = argv->ascii ? 127 : 256;

    while ((c = FGetC(infile)) != EOF) {
	if (BREAKCHECK())
	    break;
	if (is_printable(c)) {

	    ++found;
	    if (found <= min) {

		buffer[found] = c;
		if (found == min) {
		    int i;
		    if (argv->banner)
			FPrintf (outfile, "%s: ", gvars->inname);

		    for (i = 1; i <= found; ++i)
			FPutC(outfile, buffer[i]);
		} /* if */
	    } else
		FPutC(outfile, c);
	} else {
	    if (found >= min)
		FPutC(outfile, '\n');
	    found = 0;
	} /* if */
    } /* while */
}};

#endif
