Advertisement
algorithmuscanorj

The plain text gardener utility

Dec 29th, 2012
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.50 KB | None | 0 0
  1.  
  2. (*
  3.  
  4. Author: R. J. Cano.
  5. Written on Sat Dec 29 2012, 02:09 VET.
  6.  
  7. THIS PROGRAM IS FREE SOFTWARE AND GOES WITHOUT ANY WARRANTY WHATSOEVER.
  8. RELEASED UNDER THE TERMS OF THE GNU GPLv3.0 LICENSE.
  9.  
  10. For details please see: http://www.gnu.org/licenses/gpl-3.0.txt
  11.  
  12. *)
  13.  
  14. program plainTextGardener;
  15.  
  16. const
  17.   TAB=#9;
  18.   WhiteSpace=#32;
  19.   delim=':';
  20.   definedFields=4;
  21.   fieldSize_offsets=6;
  22.   fieldSize_data=16;
  23.   interFieldSize=3;
  24.   fieldBound=2*(fieldSize_offsets+fieldSize_data)+(definedFields-1)*interFieldSize;
  25.  
  26. fieldSize : array [1..definedFields] of byte= (fieldSize_offsets, fieldSize_data, fieldSize_data, fieldSize_offsets);
  27.  
  28. var
  29.   f: text;
  30.   s: string;
  31.   i,j,k,l,t: byte;
  32.  
  33. begin
  34.   assign(f, paramstr(1));
  35.   reset(f);
  36.   while (not eof(f)) do begin
  37.       readln(f,s);
  38.       for t:= 1 to length(s) do begin (*Ignores the TABS*)
  39.     if (s[t]=TAB) then s[t]:= WhiteSpace;
  40.       end;
  41.       i:= 1; (* Current field *)
  42.       if (length(s) < fieldBound) then begin
  43.     j:=0; (* How many chars before delim *)
  44.     k:=0; (* Cursor *)
  45.     while ( (i <= definedFields) and (k<length(s)) ) do begin
  46.       k:= k + 1;
  47.       if ((s[k]=delim)) then begin
  48.         (* Also: It would work properly to subtract "j" directly from fieldBound *)
  49.         for l:= 1 to (fieldSize[i]-j) do write(' ');
  50.         for l:= 1 to interFieldSize do write(' ');
  51.         i:= i + 1;
  52.         j:=0;
  53.       end else begin
  54.         write(s[k]);
  55.         j:= j + 1;
  56.       end;
  57.     end;
  58.     writeln();
  59.       end else begin
  60.     writeln(s);
  61.       end;
  62.   end;
  63.   close(f);
  64. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement