Changeset 16 for trunk/UMainForm.pas


Ignore:
Timestamp:
Feb 11, 2012, 7:12:30 PM (12 years ago)
Author:
chronos
Message:
  • Added: Function for formating source using text indentation according loop nesting.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UMainForm.pas

    r15 r16  
    77uses
    88  Classes, SysUtils, FileUtil, SynEdit, Forms, Controls, Graphics, Dialogs,
    9   Menus, ActnList, StdCtrls, ComCtrls, UBrainFuck, UCoolTranslator,
     9  Menus, ActnList, StdCtrls, ComCtrls, UBrainFuck, UCoolTranslator, StrUtils,
    1010  SpecializedList;
    1111
     
    1717    ACompile: TAction;
    1818    AAbout: TAction;
    19     ABreakpointSet: TAction;
    20     ABreakpointUnset: TAction;
     19    ABreakpointToggle: TAction;
     20    AFormatSource: TAction;
    2121    AOptions: TAction;
    2222    AInterpretterStepOut: TAction;
     
    5555    MenuItem20: TMenuItem;
    5656    MenuItem22: TMenuItem;
     57    MenuItem23: TMenuItem;
     58    MenuItem24: TMenuItem;
     59    MenuItem25: TMenuItem;
    5760    MenuItem40: TMenuItem;
    5861    MenuItem21: TMenuItem;
     
    6568    MenuItem9: TMenuItem;
    6669    OpenDialog1: TOpenDialog;
     70    PopupMenuSource: TPopupMenu;
    6771    SaveDialog1: TSaveDialog;
    6872    StatusBar1: TStatusBar;
     
    7781    ToolButton7: TToolButton;
    7882    ToolButton8: TToolButton;
     83    ToolButton9: TToolButton;
     84    procedure ABreakpointToggleExecute(Sender: TObject);
    7985    procedure ACompileExecute(Sender: TObject);
    8086    procedure AExitExecute(Sender: TObject);
     87    procedure AFormatSourceExecute(Sender: TObject);
    8188    procedure AOptionsExecute(Sender: TObject);
    8289    procedure AProgramPauseExecute(Sender: TObject);
     
    230237end;
    231238
     239procedure TMainForm.AFormatSourceExecute(Sender: TObject);
     240var
     241  Source: string;
     242  NewSource: string;
     243  Indent: Integer;
     244  I: Integer;
     245const
     246  IndentText = '  ';
     247begin
     248  Source := MemoSource.Text;
     249  NewSource := '';
     250  Indent := 0;
     251  for I := 1 to Length(Source) do begin
     252    if Source[I] = '[' then begin
     253      NewSource := NewSource + LineEnding + DupeString(IndentText, Indent) + Source[I] + LineEnding ;
     254      Inc(Indent);
     255      NewSource := NewSource + DupeString(IndentText, Indent);
     256    end
     257    else if Source[I] = ']' then begin
     258      Dec(Indent);
     259      NewSource := NewSource + LineEnding + DupeString(IndentText, Indent) + Source[I] + LineEnding + DupeString(IndentText, Indent);
     260    end
     261    else if Ord(Source[I]) > $20 then
     262      NewSource := NewSource + Source[I];
     263  end;
     264  MemoSource.Text := NewSource;
     265end;
     266
    232267procedure TMainForm.AOptionsExecute(Sender: TObject);
    233268begin
     
    245280  CompiledForm.MemoCompiled.Text := BrainFuckCompiler.Output;
    246281  CompiledForm.Show;
     282end;
     283
     284procedure TMainForm.ABreakpointToggleExecute(Sender: TObject);
     285begin
     286  //BreakPoints.Add();
    247287end;
    248288
Note: See TracChangeset for help on using the changeset viewer.