# HG changeset patch # User sheepluva # Date 1463513530 -7200 # Node ID 7654e23579347dc520afac1ebea9b2647db18423 # Parent bb6503b9847e3615fdf4bfba8dbcb33da0824625 implement ExtraftFileDir and ExtractFileName in uUtils diff -r bb6503b9847e -r 7654e2357934 hedgewars/pas2cRedo.pas --- a/hedgewars/pas2cRedo.pas Mon May 16 00:15:32 2016 +0200 +++ b/hedgewars/pas2cRedo.pas Tue May 17 21:32:10 2016 +0200 @@ -84,8 +84,6 @@ min, max:function:integer; assign, rewrite, rewrite_2, reset, reset_2, flush, BlockWrite, BlockRead, close : procedure; FileExists, DirectoryExists, eof : function : boolean; - ExtractFileDir : function : string; - ExtractFileName : function : string; ParamCount : function : integer; ParamStr : function : string; diff -r bb6503b9847e -r 7654e2357934 hedgewars/uLand.pas --- a/hedgewars/uLand.pas Mon May 16 00:15:32 2016 +0200 +++ b/hedgewars/uLand.pas Tue May 17 21:32:10 2016 +0200 @@ -30,7 +30,7 @@ procedure GenPreviewAlpha(out Preview: TPreviewAlpha); implementation -uses uConsole, uStore, uRandom, uLandObjects, uIO, uLandTexture, SysUtils, +uses uConsole, uStore, uRandom, uLandObjects, uIO, uLandTexture, uVariables, uUtils, uCommands, adler32, uDebug, uLandPainted, uTextures, uLandGenMaze, uPhysFSLayer, uScript, uLandGenPerlin, uLandGenTemplateBased, uLandUtils, uRenderUtils; diff -r bb6503b9847e -r 7654e2357934 hedgewars/uPhysFSLayer.pas --- a/hedgewars/uPhysFSLayer.pas Mon May 16 00:15:32 2016 +0200 +++ b/hedgewars/uPhysFSLayer.pas Tue May 17 21:32:10 2016 +0200 @@ -40,7 +40,7 @@ procedure hedgewarsMountPackage(filename: PChar); cdecl; external PhyslayerLibName; implementation -uses uConsts, uUtils, uVariables{$IFNDEF PAS2C}, sysutils{$ELSE}, physfs{$ENDIF}; +uses uConsts, uUtils, uVariables{$IFDEF PAS2C}, physfs{$ENDIF}; function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl; external PhyslayerLibName; function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external PhyslayerLibName; diff -r bb6503b9847e -r 7654e2357934 hedgewars/uUtils.pas --- a/hedgewars/uUtils.pas Mon May 16 00:15:32 2016 +0200 +++ b/hedgewars/uUtils.pas Tue May 17 21:32:10 2016 +0200 @@ -30,6 +30,9 @@ procedure SplitByChar(var a, b: shortstring; c: char); procedure SplitByCharA(var a, b: ansistring; c: char); +function ExtractFileDir(s: shortstring) : shortstring; +function ExtractFileName(s: shortstring) : shortstring; + function EnumToStr(const en : TGearType) : shortstring; overload; function EnumToStr(const en : TVisualGearType) : shortstring; overload; function EnumToStr(const en : TSound) : shortstring; overload; @@ -150,6 +153,61 @@ end; +function GetLastSlashPos(var s: shortString) : integer; +var lslash: integer; + c: char; +begin + +// find last slash +lslash:= Length(s); +while lslash >= 1 do + begin + c:= s[lslash]; + if (c = #47) or (c = #92) then + break; + dec(lslash); end; + +GetLastSlashPos:= lslash; +end; + +function ExtractFileDir(s: shortstring) : shortstring; +var lslash: byte; +begin + +if Length(s) = 0 then + exit(s); + +lslash:= GetLastSlashPos(s); + +if lslash <= 1 then + exit(''); + +s[0]:= char(lslash - 1); + +ExtractFileDir:= s; +end; + +function ExtractFileName(s: shortstring) : shortstring; +var lslash, len: byte; +begin + +len:= Length(s); + +if len = 0 then + exit(s); + +lslash:= GetLastSlashPos(s); + +if lslash < 1 then + exit(s); + +if lslash = len then + exit(''); + +len:= len - lslash; +ExtractFilename:= copy(s, lslash + 1, len); +end; + procedure SplitBySpace(var a,b: shortstring); begin SplitByChar(a,b,' ');