home *** CD-ROM | disk | FTP | other *** search
/ RBBS in a Box Volume 1 #3.1 / RBBSIABOX31.cdr / fasm / expand.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1986-03-21  |  2.1 KB  |  75 lines

  1. program texpand; { test program for EXPAND.INC     }
  2.                  { Requires TurboPascal v 3.x      }
  3.                  { must be compiled to COM to work }
  4.  
  5. {   Written as an example of a Pascal tab expansion procedure.  }
  6. {   This is a good example of how much "cleaner" you can do     }
  7. {   text manipulation in C than even an extended Pascal like    }
  8. {   Turbo. (see MPC.C for the counter-example)                  }
  9. {   Ray L. McVay; Arlington, TX; 21 Mar, 1986; CIS 75006,2563   }
  10. {   -for Kenneth Whitney                                        }
  11.  
  12. {$G512}
  13. {$P512}
  14. VAR
  15.     istr,
  16.     ostr    :STRING[255];
  17.     tabs,
  18.     x       :INTEGER;
  19.  
  20. {$i ..\lib\expand.inc}
  21. { start of include file EXPAND.INC}
  22. {------------------------------------------------------------------
  23.  expand the tabs in a string
  24.  input: instr  - the string containing tabs
  25.         outstr - the string to which the expanded line is put
  26.         tabcol - the (fixed) tab columns
  27.  This assumes Turbo Pascal type strings where the first byte is
  28.  the length of the string that follows.
  29. ------------------------------------------------------------------}
  30. TYPE
  31.     ASTRING = STRING[255];
  32.  
  33. {$v-}
  34.  
  35. PROCEDURE expand(VAR instr,outstr:ASTRING; tabcol :INTEGER);
  36. VAR
  37.     c, i :BYTE;
  38.  
  39.     BEGIN
  40.     c := 1;
  41.     FOR i := 1 TO integer(instr[0]) DO
  42.         BEGIN
  43.         IF instr[i] = chr(9) THEN
  44.             BEGIN
  45.             outstr[c] := chr($20);
  46.             c := c + 1;
  47.             WHILE ((c mod tabcol) <> 1) DO
  48.                 BEGIN
  49.                 outstr[c] := chr($20);
  50.                 c := c + 1;
  51.                 END;
  52.             END
  53.         ELSE
  54.             BEGIN
  55.             outstr[c] := instr[i];
  56.             c := c + 1;
  57.             END;
  58.         END;
  59.     outstr[0] := chr(c - 1);
  60.     END;
  61. { end of include file EXPAND.INC }
  62.  
  63. BEGIN
  64. IF paramcount = 1 THEN
  65.     val(paramstr(1), tabs, x)
  66. ELSE
  67.     tabs := 8;
  68. WHILE not eof DO
  69.     BEGIN
  70.     readln(istr);
  71.     expand(istr, ostr, tabs);
  72.     writeln(ostr);
  73.     END;
  74. END.
  75.