[461] | 1 | unit SrcScannerU;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
| 5 | uses
|
---|
| 6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
| 7 | Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls;
|
---|
| 8 |
|
---|
| 9 | const
|
---|
| 10 | //bill = 'This is a test' + ' some more ' + ' even more'; <-- original line. //kt 7/7/2007
|
---|
| 11 | bill = DKLangConstW('SrcScannerU_This_is_a_test') + DKLangConstW('SrcScannerU__some_more_') + DKLangConstW('SrcScannerU__even_more'); //kt added 7/7/2007
|
---|
| 12 | sue = '';
|
---|
| 13 |
|
---|
| 14 | const
|
---|
| 15 | SIGNIF_LEN = 3;
|
---|
| 16 |
|
---|
| 17 | type
|
---|
| 18 | TMainForm = class(TForm)
|
---|
| 19 | Panel1: TPanel;
|
---|
| 20 | Splitter1: TSplitter;
|
---|
| 21 | Panel2: TPanel;
|
---|
| 22 | Panel4: TPanel;
|
---|
| 23 | Panel5: TPanel;
|
---|
| 24 | Panel3: TPanel;
|
---|
| 25 | Panel6: TPanel;
|
---|
| 26 | SaveButton: TBitBtn;
|
---|
| 27 | OpenButton: TBitBtn;
|
---|
| 28 | NextButton: TBitBtn;
|
---|
| 29 | PrevButton: TBitBtn;
|
---|
| 30 | OpenDialog1: TOpenDialog;
|
---|
| 31 | Label1: TLabel;
|
---|
| 32 | Label2: TLabel;
|
---|
| 33 | SaveAsButton: TBitBtn;
|
---|
| 34 | SaveDialog1: TSaveDialog;
|
---|
| 35 | FileNameLabel: TLabel;
|
---|
| 36 | ChangesLabel: TLabel;
|
---|
| 37 | ConstantsButton: TBitBtn;
|
---|
| 38 | BitBtn1: TBitBtn;
|
---|
| 39 | OrigEdit: TMemo;
|
---|
| 40 | NewEdit: TMemo;
|
---|
| 41 | procedure OpenButtonClick(Sender: TObject);
|
---|
| 42 | procedure SpeedButton1Click(Sender: TObject);
|
---|
| 43 | procedure SaveButtonClick(Sender: TObject);
|
---|
| 44 | procedure FormCreate(Sender: TObject);
|
---|
| 45 | procedure FormDestroy(Sender: TObject);
|
---|
| 46 | procedure NextButtonClick(Sender: TObject);
|
---|
| 47 | procedure PrevButtonClick(Sender: TObject);
|
---|
| 48 | procedure BitBtn1Click(Sender: TObject);
|
---|
| 49 | private
|
---|
| 50 | { Private declarations }
|
---|
| 51 | FileModuleName : string;
|
---|
| 52 | FName : string;
|
---|
| 53 | dateStr : string;
|
---|
| 54 | FileList: TStringList;
|
---|
| 55 | FileListIndex :integer;
|
---|
| 56 | NewEditText : AnsiString;
|
---|
| 57 | function OpenInputFile(FName : string) : integer;
|
---|
| 58 | function CloseCurFiles : integer;
|
---|
| 59 | procedure ProcessLines;
|
---|
| 60 | function HasSignifStr(s: string) : boolean;
|
---|
| 61 | procedure HandleStrLine(var s:string);
|
---|
| 62 | function DoSave : integer;
|
---|
| 63 | public
|
---|
| 64 | { Public declarations }
|
---|
| 65 | end;
|
---|
| 66 |
|
---|
| 67 | var
|
---|
| 68 | MainForm: TMainForm;
|
---|
| 69 |
|
---|
| 70 | implementation
|
---|
| 71 |
|
---|
| 72 | {$R *.dfm}
|
---|
| 73 |
|
---|
| 74 | uses StrUtils,ShowConstsU;
|
---|
| 75 |
|
---|
| 76 |
|
---|
| 77 | procedure TMainForm.OpenButtonClick(Sender: TObject);
|
---|
| 78 | begin
|
---|
| 79 | dateStr := DateToStr(Date);
|
---|
| 80 | if OpenDialog1.Execute then begin
|
---|
| 81 | FileList.Assign(OpenDialog1.Files);
|
---|
| 82 | FileListIndex:=-1;
|
---|
| 83 | NextButtonClick(nil);
|
---|
| 84 | end;
|
---|
| 85 | end;
|
---|
| 86 |
|
---|
| 87 | procedure TMainForm.NextButtonClick(Sender: TObject);
|
---|
| 88 | var Result : integer;
|
---|
| 89 | begin
|
---|
| 90 | FileListIndex:=FileListIndex+1;
|
---|
| 91 | if FileListIndex<FileList.Count then begin
|
---|
| 92 | FName := FileList.Strings[FileListIndex];
|
---|
| 93 | Result := OpenInputFile(FName);
|
---|
| 94 | if Result = mrCancel then FileListIndex:=FileListIndex-1;
|
---|
| 95 | end else begin
|
---|
| 96 | FileListIndex:=FileListIndex-1;
|
---|
| 97 | // MessageDlg('No "Next" file to select.', mtError, [mbOK], 0); <-- original line. //kt 7/7/2007
|
---|
| 98 | MessageDlg(DKLangConstW('SrcScannerU_No_"Next"_file_to_select.'), mtError, [mbOK], 0); //kt added 7/7/2007
|
---|
| 99 | end;
|
---|
| 100 | end;
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 | procedure TMainForm.PrevButtonClick(Sender: TObject);
|
---|
| 104 | var Result : integer;
|
---|
| 105 | begin
|
---|
| 106 | FileListIndex:=FileListIndex-1;
|
---|
| 107 | if FileListIndex>-1 then begin
|
---|
| 108 | FName := FileList.Strings[FileListIndex];
|
---|
| 109 | Result := OpenInputFile(FName);
|
---|
| 110 | if Result = mrCancel then FileListIndex:=FileListIndex+1;
|
---|
| 111 | end else begin
|
---|
| 112 | FileListIndex:=FileListIndex+1;
|
---|
| 113 | // MessageDlg('No "Previous" file to select.', mtError, [mbOK], 0); <-- original line. //kt 7/7/2007
|
---|
| 114 | MessageDlg(DKLangConstW('SrcScannerU_No_"Previous"_file_to_select.'), mtError, [mbOK], 0); //kt added 7/7/2007
|
---|
| 115 | end;
|
---|
| 116 | end;
|
---|
| 117 |
|
---|
| 118 | function TMainForm.OpenInputFile(FName : string) : integer;
|
---|
| 119 | var BakFName : string;
|
---|
| 120 | begin
|
---|
| 121 | Result := CloseCurFiles;
|
---|
| 122 | if result <> mrCancel then begin
|
---|
| 123 | FileNameLabel.Caption:= ExtractFileName(FName);
|
---|
| 124 | // FileModuleName := AnsiReplaceStr(FileNameLabel.Caption, '.pas', ''); <-- original line. //kt 7/7/2007
|
---|
| 125 | FileModuleName := AnsiReplaceStr(FileNameLabel.Caption, DKLangConstW('SrcScannerU_.pas'), ''); //kt added 7/7/2007
|
---|
| 126 | FileModuleName := AnsiReplaceStr(FileModuleName, ' ', '_');
|
---|
| 127 |
|
---|
| 128 | OrigEdit.Lines.LoadFromFile(FName); //does a clear first
|
---|
| 129 | // BakFName:=FName + '.bak'; <-- original line. //kt 7/7/2007
|
---|
| 130 | BakFName:=FName + DKLangConstW('SrcScannerU_.bak'); //kt added 7/7/2007
|
---|
| 131 | OrigEdit.Lines.SaveToFile(BakFName); //make an immediate copy
|
---|
| 132 | ProcessLines;
|
---|
| 133 | end;
|
---|
| 134 | end;
|
---|
| 135 |
|
---|
| 136 | function TMainForm.CloseCurFiles : integer;
|
---|
| 137 | begin
|
---|
| 138 | //check if should be saved.
|
---|
| 139 | Result := DoSave;
|
---|
| 140 | if Result <> mrCancel then begin
|
---|
| 141 | NewEdit.Lines.Clear;
|
---|
| 142 | end;
|
---|
| 143 | end;
|
---|
| 144 |
|
---|
| 145 | procedure TMainForm.ProcessLines;
|
---|
| 146 | var i,j : integer;
|
---|
| 147 | tempS,s : string;
|
---|
| 148 | begin
|
---|
| 149 | for i:=0 to OrigEdit.Lines.Count-1 do begin
|
---|
| 150 | s := OrigEdit.Lines.Strings[i];
|
---|
| 151 | if HasSignifStr(s) then begin
|
---|
| 152 | tempS := s;
|
---|
| 153 | HandleStrLine(s);
|
---|
| 154 | if tempS<>s then begin
|
---|
| 155 | for j:=1 to 2 do if MidStr(tempS,1,1)=' ' then tempS:=MidStr(tempS,2,999);
|
---|
| 156 | tempS := '//'+tempS+ ' <-- original line. //kt '+ dateStr;
|
---|
| 157 | NewEdit.Lines.Add(tempS);
|
---|
| 158 | end
|
---|
| 159 | end;
|
---|
| 160 | NewEdit.Lines.Add(s);
|
---|
| 161 | end;
|
---|
| 162 | end;
|
---|
| 163 |
|
---|
| 164 | function TMainForm.HasSignifStr(s: string) : boolean;
|
---|
| 165 | var p1,p2 : integer;
|
---|
| 166 |
|
---|
| 167 | begin
|
---|
| 168 | Result := false;
|
---|
| 169 | s := AnsiReplaceStr(s, '''''', '');
|
---|
| 170 | //screen for "//" style comments
|
---|
| 171 | if Pos('//',s)>0 then begin
|
---|
| 172 | p1 := Pos('//',s);
|
---|
| 173 | s := MidStr(s,1,p1-1);
|
---|
| 174 | end;
|
---|
| 175 | p1 := 0;
|
---|
| 176 | repeat
|
---|
| 177 | p1 := PosEx('''',s,p1+1);
|
---|
| 178 | if (p1>0) and ((midstr(s,p1,2)<>'\"')) then begin
|
---|
| 179 | p2 := PosEx('''',s,p1+1);
|
---|
| 180 | if (p2-p1-1)>=SIGNIF_LEN then Result:= true;
|
---|
| 181 | p1:=p2;
|
---|
| 182 | end;
|
---|
| 183 | until (p1=0) or (Result=true);
|
---|
| 184 | end;
|
---|
| 185 |
|
---|
| 186 |
|
---|
| 187 | procedure TMainForm.HandleStrLine(var s:string);
|
---|
| 188 | var
|
---|
| 189 | origS, tempS,
|
---|
| 190 | constStr,constSName: string;
|
---|
| 191 | p1,p2:integer;
|
---|
| 192 | begin
|
---|
| 193 | origS:=s;
|
---|
| 194 | while AnsiReplaceStr(s, '''''', '') <> s do begin
|
---|
| 195 | s := AnsiReplaceStr(s, '''''', '\"'); // convert '' --> \"
|
---|
| 196 | end;
|
---|
| 197 |
|
---|
| 198 | p1 := 0;
|
---|
| 199 | repeat
|
---|
| 200 | p1 := PosEx('''',s,p1+1);
|
---|
| 201 | if (p1>0) and ((midstr(s,p1,2)<>'\"')) then begin
|
---|
| 202 | p2 := PosEx('''',s,p1+1);
|
---|
| 203 | if (p2-p1-1)>=SIGNIF_LEN then begin
|
---|
| 204 | constStr := AnsiMidStr(s, p1+1, (p2-p1-1));
|
---|
| 205 | //create dkLang constant name
|
---|
| 206 | constSName := FileModuleName+'_'+AnsiReplaceStr(constStr, ' ', '_');
|
---|
| 207 | ConstantsOutputForm.AddConst(constSName,constStr);
|
---|
| 208 | // tempS := AnsiMidStr(s, 1, p1-1)+ 'DKLangConstW(''' + constSName + ''')'; <-- original line. //kt 7/7/2007
|
---|
| 209 | tempS := AnsiMidStr(s, 1, p1-1)+ DKLangConstW('SrcScannerU_DKLangConstW(''') + constSName + ''')'; //kt added 7/7/2007
|
---|
| 210 | s := tempS + AnsiMidStr(s, p2+1, 999);
|
---|
| 211 | p1 := length(tempS)+1;
|
---|
| 212 | end else p1:=p2+1
|
---|
| 213 | end;
|
---|
| 214 | until (p1=0);
|
---|
| 215 |
|
---|
| 216 | s := AnsiReplaceStr(s, '\"', ''''''); // convert '\"' --> ''
|
---|
| 217 | s := s+ ' //kt added ' +dateStr;
|
---|
| 218 | end;
|
---|
| 219 |
|
---|
| 220 | procedure TMainForm.SpeedButton1Click(Sender: TObject);
|
---|
| 221 | begin
|
---|
| 222 | ConstantsOutputForm.Show;
|
---|
| 223 | end;
|
---|
| 224 |
|
---|
| 225 | procedure TMainForm.SaveButtonClick(Sender: TObject);
|
---|
| 226 | begin
|
---|
| 227 | DoSave;
|
---|
| 228 | end;
|
---|
| 229 |
|
---|
| 230 | function TMainForm.DoSave : integer;
|
---|
| 231 | begin
|
---|
| 232 | Result := mrYes;
|
---|
| 233 | if (NewEdit.Lines.Count>0) and (NewEdit.Lines.Text<>NewEditText) then begin
|
---|
| 234 | // Result := MessageDlg('Overwrite existing source code?',mtConfirmation, [mbYes, mbNo, mbCancel],0); <-- original line. //kt 7/7/2007
|
---|
| 235 | Result := MessageDlg(DKLangConstW('SrcScannerU_Overwrite_existing_source_code?'),mtConfirmation, [mbYes, mbNo, mbCancel],0); //kt added 7/7/2007
|
---|
| 236 | if Result = mrYes then begin
|
---|
| 237 | NewEdit.Lines.SaveToFile(FName);
|
---|
| 238 | NewEditText:=NewEdit.Lines.Text;
|
---|
| 239 | end;
|
---|
| 240 | end else begin
|
---|
| 241 | //MessageDlg('Nothing to save!', mtInformation, [mbOK], 0);
|
---|
| 242 | end;
|
---|
| 243 | end;
|
---|
| 244 |
|
---|
| 245 |
|
---|
| 246 | procedure TMainForm.FormCreate(Sender: TObject);
|
---|
| 247 | begin
|
---|
| 248 | FileList := TStringList.Create;
|
---|
| 249 | end;
|
---|
| 250 |
|
---|
| 251 | procedure TMainForm.FormDestroy(Sender: TObject);
|
---|
| 252 | begin
|
---|
| 253 | FileList.Free;
|
---|
| 254 | end;
|
---|
| 255 |
|
---|
| 256 |
|
---|
| 257 | procedure TMainForm.BitBtn1Click(Sender: TObject);
|
---|
| 258 | begin
|
---|
| 259 | if ConstantsOutputForm.NeedsSave then begin
|
---|
| 260 | // if MessageDlg('Save Gathered Constants List (Important)?', <-- original line. //kt 7/7/2007
|
---|
| 261 | if MessageDlg(DKLangConstW('SrcScannerU_Save_Gathered_Constants_List_(Important)?'), //kt added 7/7/2007
|
---|
| 262 | mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
|
---|
| 263 | ConstantsOutputForm.SaveButtonClick(nil);
|
---|
| 264 | end;
|
---|
| 265 | end;
|
---|
| 266 | Application.Terminate;
|
---|
| 267 | end;
|
---|
| 268 |
|
---|
| 269 | end.
|
---|