home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / apple2 / 41 < prev    next >
Encoding:
Text File  |  1990-12-02  |  2.3 KB  |  127 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: v001SRC019:  entab -- Replace Blanks With Tabs
  5. Message-ID: <Dec.1.17.02.18.1990.24980@yoko.rutgers.edu>
  6. Date: 1 Dec 90 22:02:19 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 116
  9. Approved: jac@paul.rutgers.edu
  10.  
  11.  
  12. Submitted-by: NONE
  13. Posting-number: Volume 1, Source:19
  14. Archive-name: util/entab
  15. Architecture: ANY_2
  16. Version-number: 1.00
  17.  
  18. This C utility replaces all spaces in a file with tabs.
  19.  
  20. Enjoy.
  21.  
  22.  
  23. =entab.c
  24. -/*
  25. - *
  26. - * entab.c
  27. - *
  28. - * Replace blanks in a file with tabs.   File is modified.
  29. - *
  30. - * Usage:
  31. - *    entab [file_1] [file_2] [file_3] [...]
  32. - *
  33. - *    If file is not specified, entab reads from standard in and
  34. - *    writes to standard out.
  35. - *
  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. -        entab( stdin ) ;
  66. -
  67. -    else
  68. -        for( ; argc>0 ; argc--,argv++)
  69. -            if( (input=fopen(*argv,"r")) == NULL ) {
  70. -                fprintf(stderr, "entab: can't open %s\n", *argv) ;
  71. -                exit(1) ;
  72. -            }
  73. -            else {
  74. -                entab( input ) ;
  75. -                fclose( input ) ;
  76. -            }
  77. -
  78. -    exit(0) ;
  79. -
  80. -} /* end main */
  81. -
  82. -/* entab - replace blanks with tabs */
  83. -
  84. -entab( in )
  85. -FILE *in ;
  86. -{
  87. -    int c, i, nextcol, nb, nt, sqstring, dqstring ;
  88. -
  89. -
  90. -    nextcol = nb = nt = 0 ;
  91. -    sqstring = dqstring = FALSE ;
  92. -
  93. -    while( (c=agetc(in)) != EOF ) {
  94. -
  95. -        nextcol++ ;
  96. -        if( c==BLANK && !sqstring && !dqstring ) {
  97. -            nb++ ;
  98. -            if( nextcol % INTERVAL == 0 && nb > 1 ) {
  99. -                nt++ ;
  100. -                nb = 0 ;
  101. -            }
  102. -        }
  103. -        else if( c == NL ) {
  104. -            aputc( NL, stdout ) ;
  105. -            nextcol = nb = nt = 0 ;
  106. -            sqstring = dqstring = FALSE ;
  107. -        }
  108. -        else {
  109. -            for( i=1 ; i <= nt ; i++ )
  110. -                aputc( TAB, stdout ) ;
  111. -            for( i=1 ; i <= nb ; i++ )
  112. -                aputc( BLANK, stdout ) ;
  113. -            nb = nt = 0 ;
  114. -            aputc( c, stdout ) ;
  115. -            if( c == SQUOTE )
  116. -                sqstring = 1 - sqstring ;
  117. -            else if( c == DQUOTE )
  118. -                dqstring = 1 - dqstring ;
  119. -        }
  120. -
  121. -    } /* end while */
  122. -
  123. -} /* end entab */
  124. -
  125. -
  126. + END OF ARCHIVE
  127.