/* untab4.c Howard L. Dyckman November 29, 1990 Public Domain This program reads any text file and prints out the file with all tabs converted to spaces, where tabstop = 4. This is useful if you like to code with tabstop = 4 but your printer is set to 8. (To set up the vi text editor for tabstop = 4 put the following line in your .login file: setenv EXINIT 'se ts=4' .) */ #include main (argc, argv) int argc; char *argv[]; { int i; char c; int f; int r; if (argc == 1) f = 0; /* stdin */ else if (argc != 2) { fprintf (stderr, "Usage: untab4 file\n"); exit(1); }; if (argc == 2) { if ((f = open(argv[1], 0)) == -1) { perror (argv[1]); exit(1); }; }; for (i = 0; ; ) { i = i % 4; r = read (f, &c, 1); if (r == 0) exit (0); if (c == '\t') { do { fprintf (stdout, " "); i++; } while ((i = i % 4) != 0); } else { i++; fprintf (stdout, "%c", c); if (c == '\n') i = 0; } } } /* NAME = untab4 OFILES = untab4.o CFILES = untab4.c CFLAGS = -g LDFLAGS = -lm $(NAME): $(OFILES) cc $(CFLAGS) $(OFILES) -o $(NAME) $(LDFLAGS) */