home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / se / part7 / se_h / detab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  1.2 KB  |  52 lines

  1. /* Detab - convert tabs to appropriate number of spaces */
  2.  
  3. /* transcribed from Kernighan and Plaguer (Software Tools) */
  4. /* fixed up by Arnold Robbins */
  5.  
  6. #include <stdio.h>
  7.  
  8. #define MAXLINE         132
  9.  
  10. #define repeat          do
  11. #define until(x)        while(!(x))
  12.  
  13. #define tabpos(col, tabs)       ( (col > MAXLINE) ? 1 : tabs[col - 1])
  14.  
  15. main()
  16. {
  17.         int c, i, tabs[MAXLINE], col = 1;
  18.  
  19.         settabs(tabs);
  20.  
  21.         while ((c = getchar()) != EOF)
  22.                 switch(c) {
  23.                 case '\t':
  24.                         repeat
  25.                         {
  26.                                 putchar(' ');
  27.                                 col++;
  28.                         } until(tabpos(col, tabs));
  29.                         break;
  30.  
  31.                 case '\n':
  32.                         putchar('\n');
  33.                         col = 1;
  34.                         break;
  35.  
  36.                 default:
  37.                         putchar(c);
  38.                         col++;
  39.                         break;
  40.                 }
  41. }
  42.  
  43. settabs(tabs)
  44. int tabs[];
  45. {
  46.         int i;
  47.  
  48.         for(i = 1; i <= MAXLINE; i++)
  49.                 tabs[i - 1] = ((i % 8) == 1);
  50.                 /* result is either 1 or 0 */
  51. }
  52.