- Timestamp:
- Nov 27, 2021, 11:14:09 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:ignore
set to
lib
DirtyCppToPascal
DirtyCppToPascal.res
DirtyCppToPascal.lps
-
Property svn:ignore
set to
-
trunk/UFormMain.lfm
r2 r3 16 16 Anchors = [akTop, akLeft, akRight] 17 17 TabOrder = 0 18 Text = '/home/chronos/Projekty/DirtyCppToPascal/ CapitalAI'18 Text = '/home/chronos/Projekty/DirtyCppToPascal/trunk/CapitalAI' 19 19 end 20 20 object ButtonBrowse: TButton -
trunk/UFormMain.pas
r2 r3 36 36 function SpaceAround(Text, What: string; Left: Boolean = True; Right: Boolean = True): string; 37 37 function Replace(Text: string; OldPattern, NewPattern: string): string; 38 function ReplaceIdent(Text: string; OldPattern, NewPattern: string): string; 38 39 function ReplaceFunction(Text: string; ReturnType: string): string; 39 40 function ReplaceVariable(Text: string; VarType: string): string; … … 182 183 Files := TStringList.Create; 183 184 SearchFiles(Files, DirSrc, nil, nil); 185 186 for I := 0 to Files.Count - 1 do begin 187 MemoLog.Lines.Add(Files[I]); 188 FileNameSrc := Files[I]; 189 if DirectoryExists(FileNameSrc) then continue; 190 if FileExists(FileNameSrc) then begin 191 FileNameDst := DirDst + Copy(FileNameSrc, Length(DirSrc) + 1, MaxInt); 192 ForceDirectories(ExtractFileDir(FileNameDst)); 193 FileExt := ExtractFileExt(FileNameSrc); 194 if FileExt = '.cpp' then begin 195 FileNameDst := ExtractFileNameWithoutExt(FileNameDst) + '.pas'; 196 DeleteFile(FileNameDst); 197 end; 198 end; 199 end; 200 184 201 for I := 0 to Files.Count - 1 do begin 185 202 MemoLog.Lines.Add(Files[I]); … … 269 286 end; 270 287 288 function TFormMain.ReplaceIdent(Text: string; OldPattern, NewPattern: string 289 ): string; 290 var 291 I: Integer; 292 TextBefore: string; 293 TextAfter: string; 294 begin 295 Result := ''; 296 while True do begin 297 I := Pos(OldPattern, Text); 298 if I > 0 then begin 299 TextBefore := Copy(Text, 1, I - 1); 300 TextAfter := Copy(Text, I + Length(OldPattern), Length(Text)); 301 if ((Length(TextBefore) >= 1) and IsAlphaNumeric(TextBefore[Length(TextBefore)]) or 302 ((Length(Result) >= 1) and IsAlphaNumeric(Result[Length(Result)]) and 303 (Copy(Result, Length(Result) - Length(NewPattern) + 1, Length(NewPattern)) <> NewPattern)) or 304 ((Length(TextAfter) >= 1) and IsAlphaNumeric(TextAfter[1]))) 305 then begin 306 Result := Result + TextBefore + OldPattern; 307 Delete(Text, 1, Length(TextBefore) + Length(OldPattern)); 308 Continue; 309 end; 310 Result := Result + TextBefore + NewPattern; 311 Delete(Text, 1, Length(TextBefore) + Length(OldPattern)); 312 end else Break; 313 end; 314 Result := Result + Text; 315 end; 316 271 317 function TFormMain.ReplaceFunction(Text: string; ReturnType: string): string; 272 318 var … … 421 467 Line: string; 422 468 const 423 Types: array[0..8] of string = ('Integer', 'Boolean', 'Cardinal', 'Byte', 424 'ShortInt', 425 'Advances', 'TNewGameData', 'TServerCall', 'TClientCall'); 469 Types: array[0..11] of string = ('Integer', 'Boolean', 'Cardinal', 'Byte', 470 'ShortInt', 'Pointer', 471 'Advances', 'TNewGameData', 'TServerCall', 'TClientCall', 'MyEVOArea', 472 'TileFunction'); 426 473 PascalKeywords: array[0..1] of string = ('object', 'type'); 427 474 begin … … 443 490 Line := ReplaceSpecialSymbol(Line, '::', '.'); 444 491 Line := Replace(Line, 'switch', 'case'); 445 Line := Replace(Line, 'int', 'Integer'); 446 Line := Replace(Line, 'bool', 'Boolean'); 447 Line := Replace(Line, 'unsigned long', 'Cardinal'); 448 Line := Replace(Line, 'unsigned short', 'ShortInt'); 449 Line := Replace(Line, 'unsigned char', 'Byte'); 450 Line := Replace(Line, 'unsigned Integer', 'Cardinal'); 492 Line := Replace(Line, 'unsigned long ', 'Cardinal '); 493 Line := Replace(Line, 'unsigned short ', 'Byte '); 494 Line := Replace(Line, 'unsigned char ', 'Byte '); 495 Line := Replace(Line, 'unsigned int ', 'Cardinal '); 496 Line := Replace(Line, 'int ', 'Integer '); 497 Line := Replace(Line, 'short ', 'ShortInt '); 498 Line := Replace(Line, 'long ', 'Integer '); 499 Line := Replace(Line, 'bool ', 'Boolean '); 451 500 Line := Replace(Line, 'void *', 'Pointer '); 452 Line := Replace(Line, 'std.ofstream', 'TStream'); 501 Line := Replace(Line, 'std.ofstream ', 'TStream '); 502 Line := Replace(Line, 'std.ostream ', 'TStream '); 453 503 Line := ReplaceOperator(Line, '+=', ':=', '+'); 454 504 Line := ReplaceOperator(Line, '-=', ':=', '-'); … … 473 523 Line := Replace(Line, 'const ', ''); 474 524 Line := Replace(Line, ' const', ''); 525 Line := Replace(Line, 'mutable ', ''); 475 526 for J := 0 to Length(Types) - 1 do 476 527 Line := ReplaceFunction(Line, Types[J]); … … 482 533 Line := Replace(Line, '()', ''); 483 534 for J := 0 to Length(PascalKeywords) - 1 do 484 Line := Replace (Line, PascalKeywords[J], 'K' + PascalKeywords[J]);535 Line := ReplaceIdent(Line, PascalKeywords[J], 'K' + PascalKeywords[J]); 485 536 //Line := SpaceAround(Line, ':='); 486 537 //Line := SpaceAround(Line, '+');
Note:
See TracChangeset
for help on using the changeset viewer.