type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; Label1: TLabel; procedure Button1Click(Sender: TObject); procedure FormShow(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure into_dop_from_trimmed; var fin,fout:textfile; str:string; begin assignfile(fin,Form1.edit1.Text+'(Trimmed).PAS'); reset(fin); assignfile(fout,'dop.txt'); rewrite(fout); while not Eof(fin) do begin readln(fin,str); writeln(fout,str); end; Closefile(fout); Closefile(fin); end;
function min(a,b:byte):byte; begin if a<=b then min:=a else min:=b; end;
(*После каждой точки с запятой перенос на новую строку*) procedure into_new_line; var fin,fout:textfile; str:string; position:byte; begin assignfile(fin,Form1.edit1.Text+'.PAS'); reset(fin); assignfile(fout,Form1.Edit1.Text+'(Trimmed).PAS'); rewrite(fout); while not Eof(fin) do begin readln(fin,str); repeat if pos(';',str)=0 then Position:=Length(str) else Position:=pos(';',str); writeln(fout,Copy(str,1,Position)); Delete(str,1,Position); while (0<Length(str))and(str[1]=' ') do Delete(str,1,1); until str=''; end; Closefile(fout); Closefile(fin); end;
(*Отступы перед каждой строкой*) procedure otstup; const Dlina_otstup=2; var fin,fout:textfile; str:string; i,kol_otstup:byte; (*Количество отступов*) begin into_dop_from_trimmed; kol_otstup:=0; assignfile(fin,'dop.txt'); reset(fin); assignfile(fout,Form1.Edit1.Text+'(Trimmed).PAS'); rewrite(fout); while not Eof(fin) do begin readln(fin,str); if (pos('end',str)<>0)then if kol_otstup>0 then dec(kol_otstup); for i:=1 to kol_otstup*Dlina_otstup do str:=' '+str; writeln(fout,str); if (pos('begin',str)<>0)or (pos('case',str)<>0)then inc(kol_otstup); end; Closefile(fout); Closefile(fin); Erase(fin); end;
procedure TForm1.Button1Click(Sender: TObject); begin into_new_line; otstup; halt; end;
procedure TForm1.FormShow(Sender: TObject); begin {edit1.SetFocus;} end;
end.
Сообщение отредактировано: sheka - 27.08.2009 19:28