
#ifdef TPLTER

CMD =
    Expand;

VERSION = "1.0";

DESCRIPTION = {{
	FILTER
	    Expands Strings from input(files) to output;
	    (converts tabs to spaces)

	OPTIONS
	    -T=TABWIDTH/N/A - specify the tabsize (defaults to 8)

	OUTPUT
	    input w/o any tabulators
}};

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

TEMPLATE =
    "-T=TABWIDTH/N/K";

ARGS = {{
    ULONG *tabs;
#define DEFTABS      8
#define MAXTABS     32
}};

USERDATA = {{ UBYTE buffer[MAXLINELEN]; UBYTE obuffer[MAXLINELEN]; }};

// ---- using dynamic buffers increases executable size >112 byte
//USERDATA = {{ STRPTR buffer; STRPTR obuffer; }};
//BUFFERS  = {	buffer; obuffer; };


BODY = {{
    int tabwidth = 8;
    if (argv->tabs && *argv->tabs < MAXTABS)
	tabwidth = *argv->tabs;

    while (FGets(infile, userdata->buffer, MAXLINELEN)) {
	if (BREAKCHECK())
	    break;
	detab (userdata->buffer, userdata->obuffer, MAXLINELEN, tabwidth);
	FPuts(outfile, userdata->obuffer);
    } /* while */
}};

APPEND = {{
static __inline int detab (char * ibuf, char * obuf, int maxlen, int bsize)
{
    short i, j;

    -- maxlen;
    for (i = j = 0; ibuf[i] && j < maxlen; ++i) {
	if (ibuf[i] == 9) {
	    do {
		obuf[j++] = ' ';
	    } while ((j % bsize) && j < maxlen);
	} else {
	    obuf[j++] = ibuf[i];
	} /* if */
    } /* for */
    //if    (j && obuf[j-1] == '\n')
    //	  --j;
    //while (j && obuf[j-1] == ' ')
    //	  --j;
    obuf[j] = 0;

    return (j);
} /* detab */
}};

#endif
