Solved

rearrange file

Posted on 1998-01-11
2
203 Views
Last Modified: 2010-04-16
After my last never ending question i have managed to suss out how to write the coding to find a file on a computer.
Now i have to write some coding which will re-write the messy coding of the program and put in the right amount of indentations after 'begins' and 'ends'.
my tutor has told us that we will not affect the amount of lines in the program we just have to take each line strip out any spaces at the begining of each line and then re-write it. But when we find a 'begin' we have to indent so many spaces and when we find an 'end' we have to go back the same amount of spaces so the program looks neat.
He reckons it involves an indentation variable which increments when the program finds a 'begin' and decrements when it finds an 'end' it also has another variable which is the amount of spaces to increment.(i think when the indent count goes up it is multiplied on the space amount so if there is a loop in a loop it doubles the spaces until it finds an 'end'). I think each line is stored in a string and the ASCI end of line code is used.
Any help you can give me will be much appreciated and save me from being put in an asylum.
Cheers
Scarhand.
0
Comment
Question by:Scarhand
  • 2
2 Comments
 
LVL 1

Accepted Solution

by:
FuzzyLogic earned 200 total points
ID: 1217096
Here some code for you.

The procedure I wrote gets the Source filename, the Target filename and the tab size.
It then fixes the lines as you asked.
However, it will ignore the 'var', 'const', 'type' etc keywords, so that the varibles after 'var' won't be shifted.
If you want, I can fix this too, but then the procedure will be more compicated.

Hoping this will solve your problem.
Fuzzy
0
 
LVL 1

Expert Comment

by:FuzzyLogic
ID: 1217097
function UpStr(S:string):string;
  var
    a:byte;
  begin;
    for a:=1 to length(S) do S[a]:=UpCase(S[a]);
    UpStr:=S;
  end;

procedure Format(SourceName,TargetName:string; size:byte);
  var
    Source,Target:text;
    Line,LineUp,Spaces:string;
    len:byte absolute Line;    { shortcut }
    a:byte;
    tabs:byte;
  begin;
    FillChar(Spaces,byte(' '),255);
    tabs:=0;
    assign(Source,SourceName);
    reset(Source);
    assign(Target,TargetName);
    rewrite(Target);

    while not(eof(Source)) do begin;
      readln(Source,Line);                 { #9 is Tab }
      while (len>0) and ((Line[1]=' ') or (Line[1]=#9)) do delete(Line,1,1);
      LineUp:=UpStr(Line);
      if pos('END',LineUp)=1 then if (tabs>0) then dec(tabs);
      Spaces[0]:=char(tabs*size);   { String of leading spaces }
      Line:=Spaces+Line;
      if pos('BEGIN',LineUp)=1 then inc(tabs);
      writeln(Target,Line);
    end;

    close(Source);
    close(Target);

  end;

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get all files and directory recursively that using Unicode character in Delphi 8 1,922
Neural Networks with Delphi 3 1,608
Embarcadero Interbase 9 767
loading dll from external path 1 250
Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question