From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/CONTRIB/SNIP/remtab.c | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 reference/C/CONTRIB/SNIP/remtab.c (limited to 'reference/C/CONTRIB/SNIP/remtab.c') diff --git a/reference/C/CONTRIB/SNIP/remtab.c b/reference/C/CONTRIB/SNIP/remtab.c new file mode 100755 index 0000000..d2822c7 --- /dev/null +++ b/reference/C/CONTRIB/SNIP/remtab.c @@ -0,0 +1,63 @@ +/* remtab.c 12-4-91 Robert Mashlan, Public Domain + modified 28 mar 93 by Bob Stout + + Filter for removing tabs. All tabs in the input will be replaced + with spaces. This filter takes one optional command line + parameter, which specifies the number spaces to replace for a tab. + If no size is specifies, it defaults to 8. + + example usage: + + remtab 6 < tabbed.c > untabbed.c + +*/ + +#include +#include + +#define BUFSIZE 4096 + + +int main(int argc, char **argv ) +{ + int tabsize = 8; + + if (argc > 1) /* look for command line parameter */ + { + if (0 == (tabsize = atoi(argv[1]))) + tabsize = 8; + } + + while (1) + { + char buf[BUFSIZE]; + int nr, i, j, pos = 0; + + nr = fread(buf, 1, sizeof(buf), stdin); + for (i = 0; i < nr; i++) + { + switch (buf[i]) + { + case '\t': /* replace tabs with spaces */ + for(j = pos % tabsize; j < tabsize; ++j) + { + putchar(' '); + ++pos; + } + break; + + case '\n': /* start a new line */ + pos = -1; /* this will become 0 when... */ + + /* ...we fall through to... */ + + default: + putchar(buf[i]);/* send character through unchanged */ + ++pos; + } + } + if (nr < sizeof(buf)) + break; + } + return 0; +} -- cgit v1.2.3-54-g00ecf