1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE a_modes.inc}
20 // g_ExtractWadName C:\svr\shit.wad:\MAPS\MAP01 -> C:/svr/shit.wad
21 function g_ExtractWadName (resourceStr
: AnsiString): AnsiString;
23 // g_ExtractWadNameNoPath C:\svr\shit.wad:\MAPS\MAP01 -> shit.wad
24 function g_ExtractWadNameNoPath (resourceStr
: AnsiString): AnsiString;
26 // g_ExtractFilePath C:\svr\shit.wad:\MAPS\MAP01 -> :/MAPS
27 function g_ExtractFilePath (resourceStr
: AnsiString): AnsiString;
29 // g_ExtractFileName C:\svr\shit.wad:\MAPS\MAP01 -> MAP01
30 function g_ExtractFileName (resourceStr
: AnsiString): AnsiString; // without path
32 // g_ExtractFilePathName C:\svr\shit.wad:\MAPS\MAP01 -> MAPS/MAP01
33 function g_ExtractFilePathName (resourceStr
: AnsiString): AnsiString;
37 function normSlashes (s
: AnsiString): AnsiString;
41 for f
:= 1 to length(s
) do if s
[f
] = '\' then s
[f
] := '/';
45 function g_ExtractWadNameNoPath (resourceStr
: AnsiString): AnsiString;
49 for f
:= length(resourceStr
) downto 1 do
51 if resourceStr
[f
] = ':' then
53 result
:= normSlashes(Copy(resourceStr
, 1, f
-1));
55 while (c
> 0) and (result
[c
] <> '/') do Dec(c
);
56 if c
> 0 then result
:= Copy(result
, c
+1, length(result
));
63 function g_ExtractWadName (resourceStr
: AnsiString): AnsiString;
67 for f
:= length(resourceStr
) downto 1 do
69 if resourceStr
[f
] = ':' then
71 result
:= normSlashes(Copy(resourceStr
, 1, f
-1));
78 function g_ExtractFilePath (resourceStr
: AnsiString): AnsiString;
80 f
, lastSlash
: Integer;
84 for f
:= length(resourceStr
) downto 1 do
86 if (lastSlash
< 0) and (resourceStr
[f
] = '\') or (resourceStr
[f
] = '/') then lastSlash
:= f
;
87 if resourceStr
[f
] = ':' then
91 result
:= normSlashes(Copy(resourceStr
, f
, lastSlash
-f
));
92 while (length(result
) > 0) and (result
[1] = '/') do Delete(result
, 1, 1);
97 if lastSlash
> 0 then result
:= normSlashes(Copy(resourceStr
, 1, lastSlash
-1));
100 function g_ExtractFileName (resourceStr
: AnsiString): AnsiString; // without path
102 f
, lastSlash
: Integer;
106 for f
:= length(resourceStr
) downto 1 do
108 if (lastSlash
< 0) and (resourceStr
[f
] = '\') or (resourceStr
[f
] = '/') then lastSlash
:= f
;
109 if resourceStr
[f
] = ':' then
111 if lastSlash
> 0 then result
:= Copy(resourceStr
, lastSlash
+1, length(resourceStr
));
115 if lastSlash
> 0 then result
:= Copy(resourceStr
, lastSlash
+1, length(resourceStr
));
118 function g_ExtractFilePathName (resourceStr
: AnsiString): AnsiString;
123 for f
:= length(resourceStr
) downto 1 do
125 if resourceStr
[f
] = ':' then
127 result
:= normSlashes(Copy(resourceStr
, f
+1, length(resourceStr
)));
128 while (length(result
) > 0) and (result
[1] = '/') do Delete(result
, 1, 1);
132 result
:= normSlashes(resourceStr
);
133 while (length(result
) > 0) and (result
[1] = '/') do Delete(result
, 1, 1);