home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pctchnqs / 1990 / number1 / tabexp.cpp < prev    next >
Text File  |  1990-02-15  |  751b  |  39 lines

  1. /* Listing 4. Code file for tabexp class */
  2.  
  3. #include "tabexp.hpp"
  4.  
  5. tabexp::tabexp(FILE *fp, int ts)
  6. /* The constructor for tabexp objects */
  7. {
  8.    init(fp, ts);
  9. }
  10.  
  11. void tabexp::init(FILE *fp, int ts)
  12. /* A method to initialize tabexp objects */
  13. {
  14.    f = fp;
  15.    col = 0; tabsize = ts; tabcnt = 0;
  16. }
  17.  
  18. int tabexp::get(void)
  19. /* A method that gets a character from the input */
  20. /* file, expanding tabs along the way            */
  21. {
  22.   int c;
  23.  
  24.   if (tabcnt) { /* currently expanding tab */
  25.      tabcnt--; col++;
  26.      c = ' ';
  27.   }
  28.   else c = fgetc(f);
  29.  
  30.   if (c == 0x09) { /* handle tabs */
  31.      tabcnt = tabsize - (col % tabsize);
  32.      return get();
  33.   }
  34.   else {
  35.     if (c == '\n') col = 0; else col++;
  36.   }
  37.   return c;
  38. }
  39.