home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume8 / se / part06 / se_h / detab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-01-25  |  1.4 KB  |  64 lines

  1. #ifndef lint
  2. static char RCSid[] = "$Header: detab.c,v 1.1 86/05/06 14:04:37 arnold Locked $";
  3. #endif
  4.  
  5. /*
  6.  * $Log:    detab.c,v $
  7.  * Revision 1.1  86/05/06  14:04:37  arnold
  8.  * Initial revision
  9.  * 
  10.  * 
  11.  */
  12.  
  13. /* Detab - convert tabs to appropriate number of spaces */
  14.  
  15. /* transcribed from Kernighan and Plaguer (Software Tools) */
  16. /* fixed up by Arnold Robbins */
  17.  
  18. #include <stdio.h>
  19.  
  20. #define MAXLINE         132
  21.  
  22. #define repeat          do
  23. #define until(x)        while(!(x))
  24.  
  25. #define tabpos(col, tabs)       ( (col > MAXLINE) ? 1 : tabs[col - 1])
  26.  
  27. main()
  28. {
  29.         int c, i, tabs[MAXLINE], col = 1;
  30.  
  31.         settabs(tabs);
  32.  
  33.         while ((c = getchar()) != EOF)
  34.                 switch(c) {
  35.                 case '\t':
  36.                         repeat
  37.                         {
  38.                                 putchar(' ');
  39.                                 col++;
  40.                         } until(tabpos(col, tabs));
  41.                         break;
  42.  
  43.                 case '\n':
  44.                         putchar('\n');
  45.                         col = 1;
  46.                         break;
  47.  
  48.                 default:
  49.                         putchar(c);
  50.                         col++;
  51.                         break;
  52.                 }
  53. }
  54.  
  55. settabs(tabs)
  56. int tabs[];
  57. {
  58.         int i;
  59.  
  60.         for(i = 1; i <= MAXLINE; i++)
  61.                 tabs[i - 1] = ((i % 8) == 1);
  62.                 /* result is either 1 or 0 */
  63. }
  64.