home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / apple2 / 42 < prev    next >
Encoding:
Text File  |  1990-12-02  |  2.2 KB  |  121 lines

  1. Path: wuarchive!uwm.edu!rutgers!aramis.rutgers.edu!paul.rutgers.edu!yoko.rutgers.edu!jac
  2. From: jac@yoko.rutgers.edu (Jonathan A. Chandross)
  3. Newsgroups: comp.sources.apple2
  4. Subject: v001SRC020:  detab -- Replace Tabs With Spaces
  5. Message-ID: <Dec.1.17.04.04.1990.25024@yoko.rutgers.edu>
  6. Date: 1 Dec 90 22:04:05 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 110
  9. Approved: jac@paul.rutgers.edu
  10.  
  11.  
  12. Submitted-by: NONE
  13. Posting-number: Volume 1, Source:20
  14. Archive-name: util/detab
  15. Architecture: ANY_2
  16. Version-number: 1.00
  17.  
  18. This is the companion utility to entab.  It converts all tabs
  19. in a file into spaces.
  20.  
  21. Enjoy.
  22.  
  23. =detab.c
  24. -
  25. -/*
  26. - *
  27. - * detab.c
  28. - *
  29. - * Replace tabs in a file with blanks.   File is modified.
  30. - *
  31. - * Usage:
  32. - *    detab [file_1] [file_2] [file_3] [...]
  33. - *
  34. - *    If file is not specified, detab reads from standard in and
  35. - *    writes to standard out.
  36. - *
  37. - * Contributed Anonymously.  Written: November 1983
  38. - *
  39. - * Version 1.00
  40. - *
  41. - */
  42. -
  43. -#include "stdio.h"
  44. -
  45. -#define TRUE  1
  46. -#define FALSE 0
  47. -#define BLANK ' '
  48. -#define TAB   '\t'
  49. -#define NL    '\n'
  50. -
  51. -#define INTERVAL 4
  52. -#define SQUOTE 0x27
  53. -#define DQUOTE 0x22
  54. -
  55. -main(argc, argv)
  56. -int argc ;
  57. -char *argv[] ;
  58. -{
  59. -    FILE *input ;
  60. -
  61. -
  62. -    argc-- ; argv++ ;
  63. -
  64. -    if( argc == 0 )
  65. -        detab( stdin ) ;
  66. -
  67. -    else
  68. -        for( ; argc>0 ; argc--,argv++)
  69. -            if( (input=fopen(*argv,"r")) == NULL ) {
  70. -                fprintf(stderr, "detab: can't open %s\n", *argv) ;
  71. -                exit(1) ;
  72. -            }
  73. -            else {
  74. -                detab( input ) ;
  75. -                fclose( input ) ;
  76. -            }
  77. -
  78. -    exit(0) ;
  79. -
  80. -} /* end main */
  81. -
  82. -/* detab - replace tabs with blanks */
  83. -
  84. -detab( in )
  85. -FILE *in ;
  86. -{
  87. -    int c, i, col, tabover, sqstring, dqstring ;
  88. -
  89. -
  90. -    col = 0 ;
  91. -    sqstring = dqstring = FALSE ;
  92. -
  93. -    while( (c=agetc(in)) != EOF ) {
  94. -
  95. -        if( c==TAB && !sqstring && !dqstring ) {
  96. -            tabover = INTERVAL - (col % INTERVAL) ;
  97. -            for( i=1 ; i <= tabover ; i++ )
  98. -                aputc( BLANK, stdout ) ;
  99. -            col += tabover ;
  100. -        }
  101. -        else if( c == NL ) {
  102. -            aputc( NL, stdout ) ;
  103. -            col = 0 ;
  104. -            sqstring = dqstring = FALSE ;
  105. -        }
  106. -        else {
  107. -            aputc( c, stdout ) ;
  108. -            col++ ;
  109. -            if( c == SQUOTE )
  110. -                sqstring = 1 - sqstring ;
  111. -            else if( c == DQUOTE )
  112. -                dqstring = 1 - dqstring ;
  113. -        }
  114. -
  115. -    } /* end while */
  116. -
  117. -} /* end detab */
  118. -
  119. -
  120. + END OF ARCHIVE
  121.