home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Add-Ons / MPW / MPW noweb 2.7 / src / c / columns.c next >
Encoding:
C/C++ Source or Header  |  1995-05-30  |  821 b   |  33 lines  |  [TEXT/MPS ]

  1. #line 19 "columns.nw"
  2. #include <stdio.h>
  3. #include "columns.h"
  4.  
  5. int tabsize = 8;
  6. #line 24 "columns.nw"
  7. int columnwidth (char *s) {             /* width of a string in columns */
  8.   return limitcolumn(s, 0);
  9. }
  10. #line 29 "columns.nw"
  11. int limitcolumn (char *s, int col) {
  12.     while (*s) {
  13.         col++;
  14.         if (*s=='\t' && tabsize > 0) while (col % tabsize != 0) col++;
  15.         s++;
  16.     }
  17.     return col;
  18. }
  19. #line 39 "columns.nw"
  20. void indent_for (int width, FILE *fp) { 
  21.                                 /* write whitespace [[width]] columns wide */
  22. /*fprintf(fp,"<%2d>",width); if (width>4) {fprintf(fp,"    "); width -= 4;}*/
  23.     if (tabsize > 1)
  24.         while (width >= tabsize) {
  25.             putc('\t', fp);
  26.             width -= tabsize;
  27.         }
  28.     while (width > 0) {
  29.         putc(' ', fp);
  30.         width--;
  31.     }
  32. }
  33.