/* notab.c Replace any Tab characters in the standard input with blanks. Default behaviour is to ensure that text after a Tab is aligned at an 8-character boundary and that at least one space replaces the Tab. If a command-line argument is encountered, it is treated as a number to replace "8" in the above description. That is, text can be aligned at 7-character boundaries with notab 7 outputfile Author: Graham Freeman Copyright: Graham Freeman, March 1994. This program may not be used for commercial purposes in its present or modified form without the consent of the author. It may be freely transmitted provided this authorship and copyright notice is retained unmodified. */ #include void fatal_error(void); int main( int argc, char *argv[] ) { int ch; int count = 0; int bound = 8; int i, j; FILE *output = stdout; FILE *input = stdin; for (i=1; i') { char *mode = "w"; j = 1; if (argv[i][j] == '>') { mode = "a"; ++j; } if (strlen(&argv[i][j]) == 0) { ++i; j = 0; } if ( (output = fopen(&argv[i][j], mode)) == NULL) { fprintf(stderr, "notab: unable to open output file %s\n", &argv[i][j]); fatal_error(); exit(1); } } else if (sscanf(argv[i],"%d",&bound) < 1 || bound <= 0) fatal_error(); } while ((ch = fgetc(input)) != EOF) { if (ch == '\n') { fputc(ch,output); count = 0; } else if (ch == '\t') { int i,k; k = count % bound; for ( i=k; i < bound; ++i) fputc(' ',output); count += bound - k; } else { fputc(ch,output); ++count; } } } void fatal_error() { fprintf(stderr, "You should run either\n" " notab outputfile\n" "for Tabs to be replaced with blanks so that following\n" "text is aligned at 8-character boundaries,\n" "or\n" " notab 6 outputfile\n" "where a number such as 6 indicates that\n" "Tabs are to be aligned at 6-character boundaries.\n"); exit(1); }