Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1exp 11/4/83; site ihuxl.UUCP Path: utzoo!linus!decvax!harpo!floyd!clyde!ihnp4!ihuxl!dcn From: dcn@ihuxl.UUCP (Dave Newkirk) Newsgroups: net.sources Subject: Aztec C source - entab.c Message-ID: <732@ihuxl.UUCP> Date: Fri, 11-Nov-83 17:46:34 EST Article-I.D.: ihuxl.732 Posted: Fri Nov 11 17:46:34 1983 Date-Received: Sun, 13-Nov-83 08:10:05 EST Organization: AT&T Bell Labs, Naperville, Il Lines: 78 /* 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 */