home *** CD-ROM | disk | FTP | other *** search
- program texpand; { test program for EXPAND.INC }
- { Requires TurboPascal v 3.x }
- { must be compiled to COM to work }
-
- { Written as an example of a Pascal tab expansion procedure. }
- { This is a good example of how much "cleaner" you can do }
- { text manipulation in C than even an extended Pascal like }
- { Turbo. (see MPC.C for the counter-example) }
- { Ray L. McVay; Arlington, TX; 21 Mar, 1986; CIS 75006,2563 }
- { -for Kenneth Whitney }
-
- {$G512}
- {$P512}
- VAR
- istr,
- ostr :STRING[255];
- tabs,
- x :INTEGER;
-
- {$i ..\lib\expand.inc}
- { start of include file EXPAND.INC}
- {------------------------------------------------------------------
- expand the tabs in a string
- input: instr - the string containing tabs
- outstr - the string to which the expanded line is put
- tabcol - the (fixed) tab columns
- This assumes Turbo Pascal type strings where the first byte is
- the length of the string that follows.
- ------------------------------------------------------------------}
- TYPE
- ASTRING = STRING[255];
-
- {$v-}
-
- PROCEDURE expand(VAR instr,outstr:ASTRING; tabcol :INTEGER);
- VAR
- c, i :BYTE;
-
- BEGIN
- c := 1;
- FOR i := 1 TO integer(instr[0]) DO
- BEGIN
- IF instr[i] = chr(9) THEN
- BEGIN
- outstr[c] := chr($20);
- c := c + 1;
- WHILE ((c mod tabcol) <> 1) DO
- BEGIN
- outstr[c] := chr($20);
- c := c + 1;
- END;
- END
- ELSE
- BEGIN
- outstr[c] := instr[i];
- c := c + 1;
- END;
- END;
- outstr[0] := chr(c - 1);
- END;
- { end of include file EXPAND.INC }
-
- BEGIN
- IF paramcount = 1 THEN
- val(paramstr(1), tabs, x)
- ELSE
- tabs := 8;
- WHILE not eof DO
- BEGIN
- readln(istr);
- expand(istr, ostr, tabs);
- writeln(ostr);
- END;
- END.
-