dcn@ihuxl.UUCP (Dave Newkirk) (11/12/83)
/* detab - replace tabs with blanks */ #include "stdio.h" #define INTERVAL 4 #define SQUOTE 0x27 #define DQUOTE 0x22 main(argc, argv) int argc ; char *argv[] ; { FILE *input ; argc-- ; argv++ ; if( argc == 0 ) detab( stdin ) ; else for( ; argc>0 ; argc--,argv++) if( (input=fopen(*argv,"r")) == NULL ) { fprintf(stderr, "detab: can't open %s\n", *argv) ; exit(1) ; } else { detab( input ) ; fclose( input ) ; } exit(0) ; } /* end main */ /* detab - replace tabs with blanks */ detab( in ) FILE *in ; { int c, i, col, tabover, sqstring, dqstring ; col = 0 ; sqstring = dqstring = FALSE ; while( (c=agetc(in)) != EOF ) { if( c==TAB && !sqstring && !dqstring ) { tabover = INTERVAL - (col % INTERVAL) ; for( i=1 ; i <= tabover ; i++ ) aputc( BLANK, stdout ) ; col += tabover ; } else if( c == NL ) { aputc( NL, stdout ) ; col = 0 ; sqstring = dqstring = FALSE ; } else { aputc( c, stdout ) ; col++ ; if( c == SQUOTE ) sqstring = 1 - sqstring ; else if( c == DQUOTE ) dqstring = 1 - dqstring ; } } /* end while */ } /* end detab */