Changeset 448


Ignore:
Timestamp:
May 19, 2022, 10:48:39 PM (7 months ago)
Author:
chronos
Message:
  • Modified: Extended source processing to replace identifiers with first capital letter.
Location:
tools/Prepare DPI
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • tools/Prepare DPI/UFormMain.lfm

    r302 r448  
    99  DesignTimePPI = 144
    1010  OnActivate = FormActivate
    11   LCLVersion = '2.0.12.0'
     11  OnCreate = FormCreate
     12  LCLVersion = '2.2.0.4'
    1213  object EditSrcDir: TEdit
    1314    Left = 159
    14     Height = 42
     15    Height = 43
    1516    Top = 17
    1617    Width = 497
    1718    TabOrder = 0
    18     Text = '/home/chronos/Projekty/C-evo/trunk'
     19    Text = '../../trunk'
    1920  end
    2021  object Label1: TLabel
    2122    Left = 17
    22     Height = 24
     23    Height = 26
    2324    Top = 25
    2425    Width = 91
    2526    Caption = 'Source dir:'
    26     ParentColor = False
    2727  end
    2828  object Label2: TLabel
    2929    Left = 16
    30     Height = 24
     30    Height = 26
    3131    Top = 72
    3232    Width = 130
    3333    Caption = 'Destination dir:'
    34     ParentColor = False
    3534  end
    3635  object EditDstDir: TEdit
    3736    Left = 159
    38     Height = 42
     37    Height = 43
    3938    Top = 64
    4039    Width = 496
    4140    TabOrder = 1
    42     Text = '/home/chronos/Projekty/C-evo/branches/highdpi_new'
     41    Text = '../../branches/highdpi_new'
    4342  end
    4443  object ButtonProcess: TButton
  • tools/Prepare DPI/UFormMain.pas

    r407 r448  
    2121    procedure ButtonProcessClick(Sender: TObject);
    2222    procedure FormActivate(Sender: TObject);
     23    procedure FormCreate(Sender: TObject);
    2324  private
    2425    Initialized: Boolean;
     26    FirstCapitalLetter: Boolean;
     27    UseDpi: Boolean;
    2528    procedure FormatCodePas(FileName: string);
    2629    procedure FormatCodeLfm(FileName: string);
    2730    function IsAlpha(C: Char): Boolean;
     31    function IsNumeric(C: Char): Boolean;
     32    function IsAlphaNumeric(C: Char): Boolean;
    2833    function ReplaceText(Text: string; FromText, ToText: string): string;
    2934    function ReplaceIdent(Text: string; FromText, ToText: string): string;
     
    4045    'ImageList', 'SpinEdit', 'PageControl', 'CheckBox', 'RadioButton',
    4146    'Memo', 'ComboBox', 'CustomDrawGrid');
     47  Idents: array[0..44] of string = ('True', 'False', 'Boolean', 'Integer', 'Inc',
     48    'Dec', 'Exit', 'Break', 'Result', 'Single', 'Assert', 'Move', 'Byte', 'Word',
     49    'Extended', 'PChar', 'SizeOf', 'Last', 'Pointer', 'Code', 'Test', 'Line',
     50    'Pos', 'Copy', 'Offscreen', 'Brush', 'FillChar', 'ShortInt', 'Cardinal',
     51    'Green', 'Red', 'Blue', 'Include', 'Canvas', 'Double', 'FillRect',
     52    'Length', 'Delete', 'IntToStr', 'Min', 'Max', 'Color', 'Me', 'Supervising',
     53    'Idle');
     54
    4255
    4356implementation
     
    87100end;
    88101
     102function TFormMain.IsNumeric(C: Char): Boolean;
     103begin
     104  Result := C in ['0'..'9'];
     105end;
     106
     107function TFormMain.IsAlphaNumeric(C: Char): Boolean;
     108begin
     109  Result := IsAlpha(C) or IsNumeric(C);
     110end;
     111
    89112procedure TFormMain.FormActivate(Sender: TObject);
    90113begin
     
    92115    Initialized := True;
    93116  end;
     117end;
     118
     119procedure TFormMain.FormCreate(Sender: TObject);
     120begin
     121  UseDpi := True;
     122  FirstCapitalLetter := False;
    94123end;
    95124
     
    133162  Lines: TStringList;
    134163  I, J: Integer;
     164  C: Char;
    135165  Line: string;
    136166  Differences: Integer;
     
    138168begin
    139169  Lines := TStringList.Create;
     170  Lines.LineBreak := #13#10;
    140171  try
    141172    Lines.LoadFromFile(FileName);
     
    143174    for I := 0 to Lines.Count - 1 do begin
    144175      Line := Lines[I];
    145       for J := 0 to Length(TypeNames) - 1 do
    146         Line := ReplaceIdent(Line, 'T' + TypeNames[J], 'TDpi' + TypeNames[J]);
    147       Line := ReplaceIdent(Line, 'Screen', 'DpiScreen');
    148       Line := ReplaceIdent(Line, 'Mouse', 'DpiMouse');
    149       Line := ReplaceIdent(Line, 'Application', 'DpiApplication');
    150       Line := StringReplace(Line, 'BitBlt(', 'DpiBitBlt(', [rfReplaceAll]);
    151       Line := StringReplace(Line, 'BitBltCanvas(', 'DpiBitCanvas(', [rfReplaceAll]);
    152       Line := StringReplace(Line, 'GetSystemMetrics(', 'DpiGetSystemMetrics(', [rfReplaceAll]);
    153       Line := StringReplace(Line, 'CreateRectRgn(', 'DpiCreateRectRgn(', [rfReplaceAll]);
    154       Line := StringReplace(Line, 'ScrollDC(', 'DpiScrollDC(', [rfReplaceAll]);
    155       if Lines[I] <> Line then Inc(Differences);
     176
     177      if FirstCapitalLetter then begin
     178        for J := 0 to Length(Idents) - 1 do
     179          Line := ReplaceIdent(Line, LowerCase(Idents[J]), Idents[J]);
     180        for C := 'A' to 'Z' do
     181          Line := ReplaceIdent(Line, LowerCase(C), C);
     182      end;
     183
     184      if UseDpi then begin
     185        for J := 0 to Length(TypeNames) - 1 do
     186          Line := ReplaceIdent(Line, 'T' + TypeNames[J], 'TDpi' + TypeNames[J]);
     187        Line := ReplaceIdent(Line, 'Screen', 'DpiScreen');
     188        Line := ReplaceIdent(Line, 'Mouse', 'DpiMouse');
     189        Line := ReplaceIdent(Line, 'Application', 'DpiApplication');
     190        Line := StringReplace(Line, 'BitBlt(', 'DpiBitBlt(', [rfReplaceAll]);
     191        Line := StringReplace(Line, 'BitBltCanvas(', 'DpiBitCanvas(', [rfReplaceAll]);
     192        Line := StringReplace(Line, 'GetSystemMetrics(', 'DpiGetSystemMetrics(', [rfReplaceAll]);
     193        Line := StringReplace(Line, 'CreateRectRgn(', 'DpiCreateRectRgn(', [rfReplaceAll]);
     194        Line := StringReplace(Line, 'ScrollDC(', 'DpiScrollDC(', [rfReplaceAll]);
     195        if Lines[I] <> Line then Inc(Differences);
     196      end;
    156197      Lines[I] := Line;
    157198    end;
     
    159200    // Add UDpiControls to uses clause
    160201    if Differences > 0 then begin
    161       UsesSection := False;
    162       for I := 0 to Lines.Count - 1 do begin
    163         if UsesSection then begin
    164           Lines[I] := '  UDpiControls, ' + TrimLeft(Lines[I]);
    165           Break;
     202      if UseDpi then begin
     203        UsesSection := False;
     204        for I := 0 to Lines.Count - 1 do begin
     205          if UsesSection then begin
     206            Lines[I] := '  UDpiControls, ' + TrimLeft(Lines[I]);
     207            Break;
     208          end;
     209          if Lines[I] = 'uses' then UsesSection := True;
    166210        end;
    167         if Lines[I] = 'uses' then UsesSection := True;
    168211      end;
    169212    end;
     
    207250function TFormMain.ReplaceIdent(Text: string; FromText, ToText: string): string;
    208251type
    209   TState = (stNone, stIdent);
     252  TState = (stNone, stIdent, stCommentBlock, stLineComment, stString);
    210253var
    211254  I: Integer;
     
    218261  IdentStart := 0;
    219262  while I <= Length(Text) do begin
     263    // Do not update line comment area
     264    if (I < Length(Text)) and (Copy(Text, I, 2) = '//') then begin
     265      State := stLineComment;
     266      Break;
     267    end;
     268
    220269    if State = stNone then begin
     270      if Text[I] = '{' then begin
     271        State := stCommentBlock;
     272      end else
     273      if Text[I] = '''' then begin
     274        State := stString;
     275      end else
    221276      if IsAlpha(Text[I]) then begin
    222277        State := stIdent;
     
    226281    end else
    227282    if State = stIdent then begin
    228       if IsAlpha(Text[I]) then begin
     283      if IsAlphaNumeric(Text[I]) then begin
    229284        Ident := Ident + Text[I];
    230285      end else begin
     
    233288        end;
    234289        State := stNone;
    235       end;
     290        Continue;
     291      end;
     292    end else
     293    if State = stString then begin
     294      if Text[I] = '''' then begin
     295        State := stNone;
     296      end;
     297    end else
     298    if State = stCommentBlock then begin
     299      if Text[I] = '}' then State := stNone;
    236300    end;
    237301    Inc(I);
    238302  end;
     303
     304  // Replace last ident terminated by line ending
     305  if (State = stIdent) and (Ident = FromText) then begin
     306    Text := Copy(Text, 1, IdentStart - 1) + ToText + Copy(Text, I, MaxInt);
     307  end;
    239308  Result := Text;
    240309end;
    241310
    242 
    243311end.
    244312
  • tools/Prepare DPI/project1.lpi

    r302 r448  
    22<CONFIG>
    33  <ProjectOptions>
    4     <Version Value="11"/>
     4    <Version Value="12"/>
    55    <General>
     6      <Flags>
     7        <CompatibilityMode Value="True"/>
     8      </Flags>
    69      <SessionStorage Value="InProjectDir"/>
    7       <MainUnit Value="0"/>
    810      <Title Value="project1"/>
    911      <Scaled Value="True"/>
     
    2426    <RunParams>
    2527      <FormatVersion Value="2"/>
    26       <Modes Count="0"/>
    2728    </RunParams>
    2829    <RequiredPackages Count="1">
Note: See TracChangeset for help on using the changeset viewer.