diff options
author | EliteTK <tomasz.kramkowski@gmail.com> | 2014-02-24 21:03:53 +0000 |
---|---|---|
committer | EliteTK <tomasz.kramkowski@gmail.com> | 2014-02-24 21:03:53 +0000 |
commit | be9d9aedb53e9b3211765f16bf4b90f5d31c1722 (patch) | |
tree | f9368e8a880abf9b9392d631da1e5a373c23dc7e /python-indent_swapper.c | |
parent | de4075f451a2d6e457dbf9dff714d166618c4495 (diff) | |
download | c-stuff-be9d9aedb53e9b3211765f16bf4b90f5d31c1722.tar.gz c-stuff-be9d9aedb53e9b3211765f16bf4b90f5d31c1722.tar.xz c-stuff-be9d9aedb53e9b3211765f16bf4b90f5d31c1722.zip |
Added all files
Diffstat (limited to 'python-indent_swapper.c')
-rw-r--r-- | python-indent_swapper.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/python-indent_swapper.c b/python-indent_swapper.c new file mode 100644 index 0000000..a39d450 --- /dev/null +++ b/python-indent_swapper.c @@ -0,0 +1,92 @@ +#include<stdio.h> +#include<stdlib.h> + +#define MAXFILE 1000 +#define MAXLINE 1000 + +int readline(char *line, int maxline); +int stripspace(char *line); + +int main(int argc, char *argv[]) { + + char line[MAXFILE][MAXLINE]; + int inspace, outspace, i, linecount, space; + + if (argc == 3) { +/* inspace = atoi(argv[1]); + outspace = atoi(argv[2]); */ + + inspace = 4; + outspace = 2; + + i = linecount = 0; + + while ( readline(line[i++], MAXLINE ) >= 0) + linecount++; + +/* for (i = 0; i < linecount; i++) { + space = stripspace(line[i]); + space = space - space % inspace; + space = space / inspace * outspace; + addspace(line[i], space); + } */ + + } else { + return 1; + } + + return 0; + +} + +int readline(char *string, int lim) { + + int c, i; + + i = 0; + while (--lim > 0 && (c=getchar()) != EOF && c != '\n') + string[i++] = c; + + if (c == '\n') + string[i++] = c; + + if (c == EOF) + i = -1; + + string[i] = '\0'; + return i; +} + +int stripspace(char *string) { + + int i, ii; + + i = ii = 0; + while (string[i] == ' ') + i++; + + while ( (string[ii++] = string[i++]) != '\0') + ; + + return i - ii; +} + +int addspace(char *string, int amount) { + + int i, ii; + + i = 0; + while ( string[i++] != '\0' ) + ; + + ii = i + amount; + + while (--i != -1) { + --ii; + + string [ii] = string [i]; + } + + while (--ii != -1) + string [ii] = ' '; +} |