Solved

rearrange file

Posted on 1998-01-11
2
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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
Extract text from webbrowser 5 1,434
delphi 8 625
Client Data Set - Wide Memo 6 1,799
qrdesign delphi 5 pdf 5 475
A big percent of today’s marketing activity is performed through the online environment. The marketing strategies that have existed a decade ago no longer relate to what’s happening today. We’re currently facing a revolutionary era, called the digit…
Unified and professional email signatures help maintain a consistent company brand image to the outside world. This article shows how to create an email signature in Exchange Server 2010 using a transport rule and how to overcome native limitations …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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