home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / compiler / small_c / cb / sources / etb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1985-08-11  |  1.1 KB  |  51 lines

  1. /*
  2. ** etb.c -- replace blanks with tabs and blanks
  3. **
  4. ** Copyright 1982 J. E. Hendrix.  All rights reserved.
  5. */
  6. #include <stdio.h>
  7. #include "tools.h"
  8. #define NOCCARGC
  9. #define MAXLIN1 (MAXLINE+1)
  10. main(argc, argv) int argc, *argv; {
  11.   char c, tabs[MAXLIN1];
  12.   int col, newcol;
  13.   auxbuf(stdin, 4096);
  14.   if(settab(tabs, argc, argv)==ERR) {
  15.     fputs("usage: ETB [#]... [+#]\n", stderr);
  16.     abort(7);
  17.     }
  18.   col=1;
  19.   while(YES) {
  20.     poll(YES);
  21.     newcol=col;
  22.     while((c=getchar())==' ') {
  23.       ++newcol;
  24.       if(tabpos(newcol, tabs)==YES) {
  25.         cout('\t', stdout);
  26.         col=newcol;
  27.         }
  28.       }
  29.     if(c=='\t') {
  30.       while(tabpos(newcol, tabs)==NO) ++newcol;
  31.       cout('\t', stdout);
  32.       col=newcol;
  33.       continue;
  34.       }
  35.     while(col<newcol) {
  36.       cout(' ', stdout);
  37.       ++col;
  38.       }
  39.     if(c==EOF) break;
  40.     cout(c, stdout);
  41.     if(c=='\n') col=1;
  42.     else if(c=='\b') --col; /* ok if it goes neg */
  43.     else ++col;
  44.     }
  45.   fclose(stdout);
  46.   }
  47. #include "settab.c"
  48. #include "tabpos.c"
  49. #include "out.c"
  50.  
  51.