home *** CD-ROM | disk | FTP | other *** search
- Path: wuarchive!uwm.edu!rutgers!aramis.rutgers.edu!paul.rutgers.edu!yoko.rutgers.edu!jac
- From: jac@yoko.rutgers.edu (Jonathan A. Chandross)
- Newsgroups: comp.sources.apple2
- Subject: v001SRC020: detab -- Replace Tabs With Spaces
- Message-ID: <Dec.1.17.04.04.1990.25024@yoko.rutgers.edu>
- Date: 1 Dec 90 22:04:05 GMT
- Organization: Rutgers Univ., New Brunswick, N.J.
- Lines: 110
- Approved: jac@paul.rutgers.edu
-
-
- Submitted-by: NONE
- Posting-number: Volume 1, Source:20
- Archive-name: util/detab
- Architecture: ANY_2
- Version-number: 1.00
-
- This is the companion utility to entab. It converts all tabs
- in a file into spaces.
-
- Enjoy.
-
- =detab.c
- -
- -/*
- - *
- - * detab.c
- - *
- - * Replace tabs in a file with blanks. File is modified.
- - *
- - * Usage:
- - * detab [file_1] [file_2] [file_3] [...]
- - *
- - * If file is not specified, detab reads from standard in and
- - * writes to standard out.
- - *
- - * Contributed Anonymously. Written: November 1983
- - *
- - * Version 1.00
- - *
- - */
- -
- -#include "stdio.h"
- -
- -#define TRUE 1
- -#define FALSE 0
- -#define BLANK ' '
- -#define TAB '\t'
- -#define NL '\n'
- -
- -#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 */
- -
- -
- + END OF ARCHIVE
-