dcn@ihuxl.UUCP (Dave Newkirk) (11/12/83)
/* entab - replace blanks with tabs */ #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 ) entab( stdin ) ; else for( ; argc>0 ; argc--,argv++) if( (input=fopen(*argv,"r")) == NULL ) { fprintf(stderr, "entab: can't open %s\n", *argv) ; exit(1) ; } else { entab( input ) ; fclose( input ) ; } exit(0) ; } /* end main */ /* entab - replace blanks with tabs */ entab( in ) FILE *in ; { int c, i, nextcol, nb, nt, sqstring, dqstring ; nextcol = nb = nt = 0 ; sqstring = dqstring = FALSE ; while( (c=agetc(in)) != EOF ) { nextcol++ ; if( c==BLANK && !sqstring && !dqstring ) { nb++ ; if( nextcol % INTERVAL == 0 && nb > 1 ) { nt++ ; nb = 0 ; } } else if( c == NL ) { aputc( NL, stdout ) ; nextcol = nb = nt = 0 ; sqstring = dqstring = FALSE ; } else { for( i=1 ; i <= nt ; i++ ) aputc( TAB, stdout ) ; for( i=1 ; i <= nb ; i++ ) aputc( BLANK, stdout ) ; nb = nt = 0 ; aputc( c, stdout ) ; if( c == SQUOTE ) sqstring = 1 - sqstring ; else if( c == DQUOTE ) dqstring = 1 - dqstring ; } } /* end while */ } /* end entab */