source: cprs/branches/ScanSourceForConstants/Copy of SrcScannerU.pas@ 1239

Last change on this file since 1239 was 461, checked in by Kevin Toppenberg, 16 years ago

Initial upload of Multi-language support appt: ScanSourceForConstants

File size: 8.0 KB
Line 
1unit SrcScannerU;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls;
8
9const
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
14const
15 SIGNIF_LEN = 3;
16
17type
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
67var
68 MainForm: TMainForm;
69
70implementation
71
72{$R *.dfm}
73
74uses StrUtils,ShowConstsU;
75
76
77procedure TMainForm.OpenButtonClick(Sender: TObject);
78begin
79 dateStr := DateToStr(Date);
80 if OpenDialog1.Execute then begin
81 FileList.Assign(OpenDialog1.Files);
82 FileListIndex:=-1;
83 NextButtonClick(nil);
84 end;
85end;
86
87procedure TMainForm.NextButtonClick(Sender: TObject);
88var Result : integer;
89begin
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;
100end;
101
102
103procedure TMainForm.PrevButtonClick(Sender: TObject);
104var Result : integer;
105begin
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;
116end;
117
118function TMainForm.OpenInputFile(FName : string) : integer;
119var BakFName : string;
120begin
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;
134end;
135
136function TMainForm.CloseCurFiles : integer;
137begin
138 //check if should be saved.
139 Result := DoSave;
140 if Result <> mrCancel then begin
141 NewEdit.Lines.Clear;
142 end;
143end;
144
145procedure TMainForm.ProcessLines;
146var i,j : integer;
147 tempS,s : string;
148begin
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;
162end;
163
164function TMainForm.HasSignifStr(s: string) : boolean;
165var p1,p2 : integer;
166
167begin
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);
184end;
185
186
187procedure TMainForm.HandleStrLine(var s:string);
188var
189 origS, tempS,
190 constStr,constSName: string;
191 p1,p2:integer;
192begin
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;
218end;
219
220procedure TMainForm.SpeedButton1Click(Sender: TObject);
221begin
222 ConstantsOutputForm.Show;
223end;
224
225procedure TMainForm.SaveButtonClick(Sender: TObject);
226begin
227 DoSave;
228end;
229
230function TMainForm.DoSave : integer;
231begin
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;
243end;
244
245
246procedure TMainForm.FormCreate(Sender: TObject);
247begin
248 FileList := TStringList.Create;
249end;
250
251procedure TMainForm.FormDestroy(Sender: TObject);
252begin
253 FileList.Free;
254end;
255
256
257procedure TMainForm.BitBtn1Click(Sender: TObject);
258begin
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;
267end;
268
269end.
Note: See TracBrowser for help on using the repository browser.