/* replaces strings of blanks with the minimum number of tabs and * blanks to achieve the same spacing */ #include #include #define TABSPC 8 #define MAXSTOPS 1000 char stops[MAXSTOPS] = "\0"; int sti = 0; int count = 0; void getargs(int argc, char *argv[]) { int i, j, flag = 0; for (i = 0; i < MAXSTOPS; i++) { if (--argc > 0) { if (*(++argv)[0] == '-') { stops[0] = atoi(++argv[0]); if (stops[0] == 0) { printf("you motherFUCKER!\n"); exit(1); } flag = 1; } else if (*argv[0] == '+') { if (flag == 0) { printf("don't FUCK with me!\n"); exit(1); } j = atoi(++argv[0]); if (j == 0) { printf("SLUT!\n"); exit(1); } while (i < MAXSTOPS) stops[i++] = j; return; } else if ((stops[i] = atoi(argv[0])) == 0) { printf("hey you BITCH\n"); exit(1); } } else { stops[i] = TABSPC; } } } void up(int i) { int j; if ((count+=i) >= stops[sti]) { j = count - stops[sti]; sti++; count = j; } } void clear(void) { count = 0; sti = 0; } int main(int argc, char *argv[]) { int c, blanks, i, j; getargs(argc, argv); while((c=getchar()) != EOF) { if (c == ' ') { blanks = 0; while(c == ' ') { blanks++; c = getchar(); } while (blanks > stops[sti] - count) { putchar('\t'); blanks -= (stops[sti] - count); up(stops[sti] - count); } while (blanks > 0) { putchar(' '); blanks--; up(1); } } if (c == '\n') { putchar(c); clear(); } else if (c != EOF) { putchar(c); if (c == '\t') up(stops[sti]-count); else { up(1); } } } return 0; }