1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
unit runxgettext;
(**************************************************************)
(* *)
(* (C) Copyright by Lars B. Dybdahl *)
(* E-mail: Lars@dybdahl.dk, phone +45 70201241 *)
(* You may distribute and modify this file as you wish *)
(* for free *)
(* *)
(* See http://dybdahl.dk/dxgettext/ for more information *)
(* *)
(**************************************************************)
// This unit handles running the xgettext.exe program to extract C/C++
// texts from C++ Builder projects
interface
uses
Classes;
type
TRunXGettext=
class
FileList:TStringList;
OutputDir:string;
constructor create;
destructor Destroy; override;
procedure Execute;
end;
implementation
uses
Dialogs, SysUtils, ConsoleAppHandler, Windows;
{ TRunXGettext }
constructor TRunXGettext.create;
begin
FileList:=TStringList.Create;
end;
destructor TRunXGettext.Destroy;
begin
FreeAndNil (FileList);
inherited;
end;
function shellescape (s:string):string;
var
i:integer;
begin
Result:='';
for i:=1 to length(s) do begin
if s[i]='"' then
Result:=Result+'\"'
else
if s[i]='\' then
Result:=Result+'\\'
else
Result:=Result+s[i];
end;
end;
procedure TRunXGettext.Execute;
var
AppOutput:TStringList;
cmdline:string;
appout:string;
filelistname:string;
tf:TextFile;
i:integer;
temppath:string;
begin
SetLength (temppath, 1000);
i:=GetTempPath(1000,PChar(temppath));
if i=0 then begin
filelistname:='c:\filelist.txt';
// This is extremely rare, and absolutely an Operating system error, and therefore doesn't need translation.
ShowMessage (Format('Please check your temp path settings - they are incorrect. Using "%s" instead.',[filelistname]));
end else begin
SetLength (temppath,i);
SetLength (filelistname, MAX_PATH);
i:=GetTempFileName(PChar(temppath),'ggd',0,PChar(filelistname));
if i=0 then begin
filelistname:='c:\filelist.txt';
// This is extremely rare, and absolutely an Operating system error, and therefore doesn't need translation.
ShowMessage (Format('Please check your temp path settings - they are incorrect. Using "%s" instead.',[filelistname]));
end else
SetLength (filelistname, strlen(PChar(filelistname)));
end;
AssignFile (tf,filelistname);
Rewrite (tf);
for i:=0 to FileList.Count-1 do begin
Writeln (tf,FileList.Strings[i]);
end;
CloseFile (tf);
AppOutput:=TStringList.Create;
try
cmdline:='xgettext --keyword=_ -n --files-from="'+shellescape(filelistname)+'" -j -p "'+shellescape(OutputDir)+'" -d default 2>&1';
cmdline:='-c "'+shellescape(cmdline)+'"';
ExecConsoleApp ('bash.exe',cmdline,AppOutput,nil);
appout:=trim(AppOutput.text);
if appout<>'' then
MessageDlg (appout,mtInformation,[mbOK],0);
finally
FreeAndNil (AppOutput);
end;
SysUtils.DeleteFile (filelistname);
end;
end.
|