diff options
author | Michael Hunteman <michael@huntm.net> | 2023-07-04 17:03:53 -0500 |
---|---|---|
committer | Michael Hunteman <michael@huntm.net> | 2023-07-06 17:23:45 -0500 |
commit | bfce8f0d0d828209ec0bec71371ee94a7ad62d3e (patch) | |
tree | bdf49ca788ca1ca030d5b1cccfd0c9dffeb3f69f /one/tab.c |
Initial commit
Diffstat (limited to 'one/tab.c')
-rw-r--r-- | one/tab.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/one/tab.c b/one/tab.c new file mode 100644 index 0000000..f9c6dc5 --- /dev/null +++ b/one/tab.c @@ -0,0 +1,59 @@ +#include <stdio.h> + +/* XXX: dependent on file size */ +#define MAX 1024 + +void detab() +{ + char detab[MAX]; + + int c, i; + i = 0; + while (i < MAX && (c = getchar()) != EOF) { + if (c == '\t') { + for (int t = 0; t < 8; ++t) { + detab[i + t] = ' '; + } + i += 8; + } else { + detab[i++] = c; + } + } + detab[i] = '\0'; + printf("%s", detab); +} + +void entab() +{ + char entab[MAX]; + + int c, i, s; + i = s = 0; + while (i < MAX && (c = getchar()) != EOF) { + if (c == ' ') { + ++s; + } else { + while (s > 0) { + if (s >= 8) { + entab[i++] = '\t'; + s -= 8; + } else { + entab[i++] = ' '; + --s; + } + } + entab[i++] = c; + } + } + + entab[i] = '\0'; + printf("%s", entab); +} + +int +main() +{ + detab(); + /* entab(); */ + return 0; +} |