replaced custom extension stripping routine by sysutils version

This commit is contained in:
Basile Burg 2014-12-07 07:59:28 +01:00
parent 460db35033
commit 3c62646055
5 changed files with 55 additions and 36 deletions

View File

@ -6,10 +6,9 @@ import std.getopt;
/*
pass:
--a=<CAF> --b=<CAP> --c=<CFF> --d=<CFP> --e=<CI> --f=<CFP> --g=<CPP> --h=<CPR> --i=<CPN> --j=<CPFS>
"--a=<CAF>" "--b=<CAP>" "--c=<CFF>" "--d=<CFP>" "--e=<CI>" "--f=<CPF>" "--g=<CPP>" "--h=<CPR>" "--i=<CPN>" "--j=<CPO>" "--k=<CPFS>"
as parameters in "Run, Compile and Run file..."
<CPFS>: only the first item is displayed but the symbol is expanded as expected.
*/
void main(string args[])
@ -27,7 +26,8 @@ void main(string args[])
'g' : "CurrentProjectPath.....: ",
'h' : "CurrentProjectRoot.....: ",
'i' : "CurrentProjectName.....: ",
'j' : "CurrentProjectFiles....: "
'j' : "CurrentProjectOutput...: ",
'k' : "CurrentProjectFiles....: "
];
string expanded;

View File

@ -16,6 +16,7 @@ const
exeExt = {$IFDEF WINDOWS} '.exe' {$ELSE} '' {$ENDIF};
objExt = {$IFDEF WINDOWS} '.obj' {$ELSE} '.o' {$ENDIF};
libExt = {$IFDEF WINDOWS} '.lib' {$ELSE} '.a' {$ENDIF};
dynExt = {$IFDEF WINDOWS} '.dll' {$ENDIF} {$IFDEF LINUX}'.so'{$ENDIF} {$IFDEF DARWIN}'.dylib'{$ENDIF};
var
dExtList: TStringList;
@ -127,6 +128,11 @@ type
*)
function patchPlateformExt(const aFilename: string): string;
(**
* Returns aFilename without its extension.
*)
function stripFileExt(const aFilename: string): string;
(**
* Ok/Cancel modal dialog
*)
@ -451,11 +457,9 @@ begin
result := aPath;
{$IFDEF MSWINDOWS}
result := patchProc(result, '/');
result := patchProc(result, ':');
{$ENDIF}
{$IFDEF LINUX}
{$IFDEF UNIX}
result := patchProc(result, '\');
result := patchProc(result, ':');
{$ENDIF}
end;
@ -471,45 +475,50 @@ begin
end;
end;
function stripFileExt(const aFilename: string): string;
begin
if Pos('.', aFilename) > 1 then
exit(ChangeFileExt(aFilename, ''))
else
exit(aFilename);
end;
function patchPlateformExt(const aFilename: string): string;
var
ext, newext: string;
begin
if aFilename = '' then exit(aFilename);
//
ext := extractFileExt(aFilename);
newext := '';
result := aFilename[1..length(aFilename)-length(ext)];
{$IFDEF MSWINDOWS}
case ext of
'.so': newext := '.dll';
'.so': newext := '.dll';
'.dylib': newext := '.dll';
'.a': newext := '.lib';
'.o': newext := '.obj';
else newext := ext;
'.a': newext := '.lib';
'.o': newext := '.obj';
else newext := ext;
end;
{$ENDIF}
{$IFDEF LINUX}
case ext of
'.dll': newext := '.so';
'.dll': newext := '.so';
'.dylib': newext := '.so';
'.lib': newext := '.a';
'.obj': newext := '.o';
'.exe': newext := '';
else newext := ext;
'.lib': newext := '.a';
'.obj': newext := '.o';
'.exe': newext := '';
else newext := ext;
end;
{$ENDIF}
{$IFDEF MACOS}
{$IFDEF DARWIN}
case ext of
'.dll': newext := '.dylib';
'.so': newext := '.dylib';
'.lib': newext := '.a';
'.obj': newext := '.o';
'.exe': newext := '';
else newext := ext;
else newext := ext;
end;
{$ENDIF}
result += newext;
result := ChangeFileExt(aFilename, newext);
end;
function dlgOkCancel(const aMsg: string): TModalResult;

View File

@ -1325,7 +1325,7 @@ begin
if fileExists(editor.fileName) then editor.save
else editor.saveToFile(editor.tempFilename);
fname := editor.fileName[1..length(editor.fileName) - length(extractFileExt(editor.fileName))];
fname := stripFileExt(editor.fileName);
if fRunnableSw = '' then
fRunnableSw := '-vcolumns'#13'-w'#13'-wi';
@ -1344,7 +1344,7 @@ begin
if (dmdProc.ExitStatus = 0) then
begin
subjLmFromString(fLogMessager, shortenPath(editor.fileName,25)
subjLmFromString(fLogMessager, shortenPath(editor.fileName, 25)
+ ' successfully compiled', editor, amcEdit, amkInf);
fRunProc.CurrentDirectory := extractFilePath(fRunProc.Executable);
@ -1535,7 +1535,7 @@ begin
begin
itm := TMenuItem.Create(self);
itm.Caption := extractFileName(lst.Strings[i]);
itm.Caption := itm.Caption[1..length(itm.Caption) - length(extractFileExt(itm.Caption))];
itm.Caption := stripFileExt(itm.Caption);
itm.OnClick := @layoutMnuItemClick;
itm.ImageIndex := 32;
mnuLayout.Add(itm);

View File

@ -448,14 +448,27 @@ end;
procedure TCEProject.updateOutFilename;
begin
fOutputFilename := currentConfiguration.pathsOptions.outputFilename;
fOutputFilename := symbolExpander.get(fOutputFilename);
fOutputFilename := getAbsoluteFilename(fOutputFilename);
if not fileExists(fOutputFilename) then if Sources.Count > 0 then
begin
// field is specified
if fOutputFilename <> '' then begin
fOutputFilename := symbolExpander.get(fOutputFilename);
fOutputFilename := getAbsoluteFilename(fOutputFilename);
end
// try to guess
else if Sources.Count > 0 then
begin
fOutputFilename := extractFilename(Sources.Strings[0]);
fOutputFilename := fOutputFilename[1..length(fOutputFilename) - length(extractFileExt(fOutputFilename))];
fOutputFilename := extractFilePath(fileName) + DirectorySeparator + fOutputFilename + exeExt;
fOutputFilename := stripFileExt(fOutputFilename);
if FileExists(fileName) then
fOutputFilename := extractFilePath(fileName) + fOutputFilename
else
fOutputFilename := GetTempDir(false) + fOutputFilename;
end;
// force extension
case currentConfiguration.outputOptions.binaryKind of
executable: fOutputFilename := ChangeFileExt(fOutputFilename, exeExt);
staticlib: fOutputFilename := ChangeFileExt(fOutputFilename, libExt);
sharedlib: fOutputFilename := ChangeFileExt(fOutputFilename, dynExt);
obj: fOutputFilename := ChangeFileExt(fOutputFilename, objExt);
end;
//
fCanBeRun := false;

View File

@ -113,7 +113,6 @@ procedure TCESymbolExpander.updateSymbols;
var
hasProj: boolean;
hasDoc: boolean;
extLen: Integer;
i: Integer;
const
na = '``';
@ -148,11 +147,10 @@ begin
if fileExists(fProj.fileName) then begin
fSymbols[CPF] := fProj.fileName;
fSymbols[CPP] := ExtractFilePath(fProj.fileName);
fSymbols[CPR] := fProj.RootFolder;
fSymbols[CPN] := extractFileName(fProj.fileName);
fSymbols[CPR] := fProj.getAbsoluteFilename(fProj.RootFolder);
fSymbols[CPN] := stripFileExt(extractFileName(fProj.fileName));
fSymbols[CPO] := fProj.outputFilename;
extLen := length(ExtractFileExt(fSymbols[CPN]));
fSymbols[CPN] := fSymbols[CPN][1..length(fSymbols[CPN])-extLen];
if fSymbols[CPR] = '' then fSymbols[CPR] := fSymbols[CPP];
end else begin
fSymbols[CPF] := na;
fSymbols[CPP] := na;
@ -174,7 +172,6 @@ begin
fSymbols[CPP] := na;
fSymbols[CPR] := na;
fSymbols[CPN] := na;
fSymbols[CPN] := na;
fSymbols[CPO] := na;
fSymbols[CPFS]:= na;
end;