|
@@ -1,32 +1,51 @@
|
|
|
|
+{
|
|
|
|
+ $Id$
|
|
|
|
+ This file is part of the Free Pascal run time library.
|
|
|
|
+ Copyright (c) 1997-2000 by the Free Pascal development team
|
|
|
|
+
|
|
|
|
+ See the file COPYING.FPC, included in this distribution,
|
|
|
|
+ for details about the copyright.
|
|
|
|
+
|
|
|
|
+ This program is distributed in the hope that it will be useful,
|
|
|
|
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
+
|
|
|
|
+ **********************************************************************}
|
|
|
|
+
|
|
|
|
+{****************************************************************************
|
|
|
|
+ A platform independent FExpand implementation
|
|
|
|
+****************************************************************************}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+function GetDirIO (DriveNr: byte; var Dir: OpenString): word;
|
|
|
|
+ [external name 'FPC_GETDIRIO'];
|
|
|
|
+
|
|
|
|
+(* GetDirIO is supposed to return the root of the given drive *)
|
|
|
|
+(* in case of an error for compatibility of FExpand with TP/BP. *)
|
|
|
|
+(* Dir must be specified as OpenString since System has $P+. *)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+function FExpand (const Path: PathStr): PathStr;
|
|
|
|
+
|
|
(* LFNSupport boolean constant, variable or function must be declared for all
|
|
(* LFNSupport boolean constant, variable or function must be declared for all
|
|
the platforms, at least locally in the Dos unit implementation part.
|
|
the platforms, at least locally in the Dos unit implementation part.
|
|
- In addition, FEXPAND_UNC, FEXPAND_DRIVES, FEXPAND_GETENV_PCHAR
|
|
|
|
- and FEXPAND_TILDE conditionals might be defined to specify FExpand
|
|
|
|
|
|
+ In addition, FPC_FEXPAND_UNC, FPC_FEXPAND_DRIVES, FPC_FEXPAND_GETENV_PCHAR
|
|
|
|
+ and FPC_FEXPAND_TILDE conditionals might be defined to specify FExpand
|
|
behaviour. Only forward slashes are supported if UNIX conditional
|
|
behaviour. Only forward slashes are supported if UNIX conditional
|
|
is defined, both forward and backslashes otherwise.
|
|
is defined, both forward and backslashes otherwise.
|
|
*)
|
|
*)
|
|
|
|
|
|
-(* TODO: GetDir replacement function should appear here to remove
|
|
|
|
- the incorrect setting of IOResult within FExpand.
|
|
|
|
-*)
|
|
|
|
-{
|
|
|
|
- function get_current_drive:byte;assembler;
|
|
|
|
- asm
|
|
|
|
- movb $0x19,%ah
|
|
|
|
- call syscall
|
|
|
|
- end;
|
|
|
|
-}
|
|
|
|
const
|
|
const
|
|
{$IFDEF UNIX}
|
|
{$IFDEF UNIX}
|
|
DirSep = '/';
|
|
DirSep = '/';
|
|
{$ELSE UNIX}
|
|
{$ELSE UNIX}
|
|
DirSep = '\';
|
|
DirSep = '\';
|
|
{$ENDIF UNIX}
|
|
{$ENDIF UNIX}
|
|
-{$IFDEF FEXPAND_DRIVES}
|
|
|
|
|
|
+{$IFDEF FPC_FEXPAND_DRIVES}
|
|
PathStart = 3;
|
|
PathStart = 3;
|
|
-{$ELSE FEXPAND_DRIVES}
|
|
|
|
|
|
+{$ELSE FPC_FEXPAND_DRIVES}
|
|
PathStart = 1;
|
|
PathStart = 1;
|
|
-{$ENDIF FEXPAND_DRIVES}
|
|
|
|
|
|
+{$ENDIF FPC_FEXPAND_DRIVES}
|
|
|
|
|
|
var S, Pa: PathStr;
|
|
var S, Pa: PathStr;
|
|
I, J: longint;
|
|
I, J: longint;
|
|
@@ -42,15 +61,16 @@ begin
|
|
if Pa [I] = '/' then
|
|
if Pa [I] = '/' then
|
|
Pa [I] := DirSep;
|
|
Pa [I] := DirSep;
|
|
{$ENDIF}
|
|
{$ENDIF}
|
|
-{$IFDEF FEXPAND_TILDE}
|
|
|
|
|
|
+{$IFDEF FPC_FEXPAND_TILDE}
|
|
{Replace ~/ with $HOME}
|
|
{Replace ~/ with $HOME}
|
|
- if (Length (Pa) > 1) and (Pa [1] ='~') and (Pa [2] = DirSep) then
|
|
|
|
|
|
+ if (Length (Pa) >= 1) and (Pa [1] ='~') and
|
|
|
|
+ ((Pa [2] = DirSep) or (Length (Pa) = 1)) then
|
|
begin
|
|
begin
|
|
- {$IFDEF FEXPAND_GETENV_PCHAR}
|
|
|
|
|
|
+ {$IFDEF FPC_FEXPAND_GETENV_PCHAR}
|
|
S := StrPas (GetEnv ('HOME'));
|
|
S := StrPas (GetEnv ('HOME'));
|
|
- {$ELSE FEXPAND_GETENV_PCHAR}
|
|
|
|
|
|
+ {$ELSE FPC_FEXPAND_GETENV_PCHAR}
|
|
S := GetEnv ('HOME');
|
|
S := GetEnv ('HOME');
|
|
- {$ENDIF FEXPAND_GETENV_PCHAR}
|
|
|
|
|
|
+ {$ENDIF FPC_FEXPAND_GETENV_PCHAR}
|
|
if (S = '') or (Length (S) = 1) and (S [1] = DirSep) then
|
|
if (S = '') or (Length (S) = 1) and (S [1] = DirSep) then
|
|
Delete (Pa, 1, 1)
|
|
Delete (Pa, 1, 1)
|
|
else
|
|
else
|
|
@@ -59,27 +79,15 @@ begin
|
|
else
|
|
else
|
|
Pa := S + Copy (Pa, 2, Pred (Length (Pa)));
|
|
Pa := S + Copy (Pa, 2, Pred (Length (Pa)));
|
|
end;
|
|
end;
|
|
-{$ENDIF FEXPAND_TILDE}
|
|
|
|
|
|
+{$ENDIF FPC_FEXPAND_TILDE}
|
|
if (Length (Pa) > 1) and (Pa [1] in ['A'..'Z', 'a'..'z']) and
|
|
if (Length (Pa) > 1) and (Pa [1] in ['A'..'Z', 'a'..'z']) and
|
|
(Pa [2] = ':') then
|
|
(Pa [2] = ':') then
|
|
begin
|
|
begin
|
|
-{$IFDEF FEXPAND_DRIVES}
|
|
|
|
|
|
+{$IFDEF FPC_FEXPAND_DRIVES}
|
|
{ Always uppercase driveletter }
|
|
{ Always uppercase driveletter }
|
|
if (Pa [1] in ['a'..'z']) then
|
|
if (Pa [1] in ['a'..'z']) then
|
|
Pa [1] := Chr (Ord (Pa [1]) and not ($20));
|
|
Pa [1] := Chr (Ord (Pa [1]) and not ($20));
|
|
- {We must get the right directory (should be changed to avoid
|
|
|
|
- touching IOResult)}
|
|
|
|
- {$IFOPT I+}
|
|
|
|
- {$DEFINE FEXPAND_WAS_I}
|
|
|
|
- {$I-}
|
|
|
|
- {$ENDIF}
|
|
|
|
- I := IOResult;
|
|
|
|
- GetDir (Ord (Pa [1]) - Ord ('A') + 1, S);
|
|
|
|
- I := IOResult;
|
|
|
|
- {$IFDEF FEXPAND_WAS_I}
|
|
|
|
- {$I+}
|
|
|
|
- {$UNDEF FEXPAND_WAS_I}
|
|
|
|
- {$ENDIF FEXPAND_WAS_I}
|
|
|
|
|
|
+ if GetDirIO (Ord (Pa [1]) - Ord ('A') + 1, S) = 0 then ;
|
|
case Length (Pa) of
|
|
case Length (Pa) of
|
|
2: Pa := S;
|
|
2: Pa := S;
|
|
else
|
|
else
|
|
@@ -96,35 +104,25 @@ begin
|
|
end;
|
|
end;
|
|
end
|
|
end
|
|
else
|
|
else
|
|
-{$ELSE FEXPAND_DRIVES}
|
|
|
|
|
|
+{$ELSE FPC_FEXPAND_DRIVES}
|
|
Delete (Path, 1, 2);
|
|
Delete (Path, 1, 2);
|
|
Delete (Pa, 1, 2);
|
|
Delete (Pa, 1, 2);
|
|
end;
|
|
end;
|
|
-{$ENDIF FEXPAND_DRIVES}
|
|
|
|
|
|
+{$ENDIF FPC_FEXPAND_DRIVES}
|
|
begin
|
|
begin
|
|
-{$IFOPT I+}
|
|
|
|
- {$DEFINE FEXPAND_WAS_I}
|
|
|
|
- {$I-}
|
|
|
|
-{$ENDIF}
|
|
|
|
- I := IOResult;
|
|
|
|
- GetDir (0, S);
|
|
|
|
- I := IOResult;
|
|
|
|
-{$IFDEF FEXPAND_WAS_I}
|
|
|
|
- {$I+}
|
|
|
|
- {$UNDEF FEXPAND_WAS_I}
|
|
|
|
-{$ENDIF FEXPAND_WAS_I}
|
|
|
|
-{$IFDEF FEXPAND_DRIVES}
|
|
|
|
|
|
+ if GetDirIO (0, S) = 0 then ;
|
|
|
|
+{$IFDEF FPC_FEXPAND_DRIVES}
|
|
if (Length (Pa) > 0) and (Pa [1] = DirSep) then
|
|
if (Length (Pa) > 0) and (Pa [1] = DirSep) then
|
|
begin
|
|
begin
|
|
- {$IFDEF FEXPAND_UNC}
|
|
|
|
|
|
+ {$IFDEF FPC_FEXPAND_UNC}
|
|
{ Do not touch Network drive names }
|
|
{ Do not touch Network drive names }
|
|
if not ((Length (Pa) > 1) and (Pa [2] = Pa [1])
|
|
if not ((Length (Pa) > 1) and (Pa [2] = Pa [1])
|
|
and LFNSupport) then
|
|
and LFNSupport) then
|
|
- {$ENDIF FEXPAND_UNC}
|
|
|
|
|
|
+ {$ENDIF FPC_FEXPAND_UNC}
|
|
Pa := S [1] + ':' + Pa
|
|
Pa := S [1] + ':' + Pa
|
|
end
|
|
end
|
|
else
|
|
else
|
|
-{$ENDIF FEXPAND_DRIVES}
|
|
|
|
|
|
+{$ENDIF FPC_FEXPAND_DRIVES}
|
|
(* We already have a slash if root is the curent directory. *)
|
|
(* We already have a slash if root is the curent directory. *)
|
|
if Length (S) = PathStart then
|
|
if Length (S) = PathStart then
|
|
Pa := S + Pa
|
|
Pa := S + Pa
|
|
@@ -151,9 +149,9 @@ begin
|
|
while (J > 0) and (Pa [J] <> DirSep) do
|
|
while (J > 0) and (Pa [J] <> DirSep) do
|
|
Dec (J);
|
|
Dec (J);
|
|
if (J = 0)
|
|
if (J = 0)
|
|
-{$IFDEF FEXPAND_UNC}
|
|
|
|
|
|
+{$IFDEF FPC_FEXPAND_UNC}
|
|
or (J = 1) and (I = 2)
|
|
or (J = 1) and (I = 2)
|
|
-{$ENDIF FEXPAND_UNC}
|
|
|
|
|
|
+{$ENDIF FPC_FEXPAND_UNC}
|
|
then
|
|
then
|
|
Delete (Pa, Succ (I), 3)
|
|
Delete (Pa, Succ (I), 3)
|
|
else
|
|
else
|
|
@@ -169,9 +167,9 @@ begin
|
|
while (J >= 1) and (Pa [J] <> DirSep) do
|
|
while (J >= 1) and (Pa [J] <> DirSep) do
|
|
Dec (J);
|
|
Dec (J);
|
|
if (J = 0)
|
|
if (J = 0)
|
|
-{$IFDEF FEXPAND_UNC}
|
|
|
|
|
|
+{$IFDEF FPC_FEXPAND_UNC}
|
|
or (J = 1) and (I = 2)
|
|
or (J = 1) and (I = 2)
|
|
-{$ENDIF FEXPAND_UNC}
|
|
|
|
|
|
+{$ENDIF FPC_FEXPAND_UNC}
|
|
then
|
|
then
|
|
Delete (Pa, Succ (I), 2)
|
|
Delete (Pa, Succ (I), 2)
|
|
else
|
|
else
|
|
@@ -180,14 +178,15 @@ begin
|
|
{Now remove also any reference to '\.' at the end of line}
|
|
{Now remove also any reference to '\.' at the end of line}
|
|
I := Pos (DirSep + '.', Pa);
|
|
I := Pos (DirSep + '.', Pa);
|
|
if (I <> 0) and (I = Pred (Length (Pa))) then
|
|
if (I <> 0) and (I = Pred (Length (Pa))) then
|
|
- if (I = PathStart)
|
|
|
|
-{$IFDEF FEXPAND_DRIVES}
|
|
|
|
- and (Pa [2] = ':')
|
|
|
|
-{$ENDIF FEXPAND_DRIVES}
|
|
|
|
-{$IFDEF FEXPAND_UNC}
|
|
|
|
- or (I = 2) and (Pa [1] = '\')
|
|
|
|
-{$ENDIF FEXPAND_UNC}
|
|
|
|
- then
|
|
|
|
|
|
+{$IFDEF FPC_FEXPAND_DRIVES}
|
|
|
|
+ if (I = 3) and (Pa [2] = ':')
|
|
|
|
+{$ELSE FPC_FEXPAND_DRIVES}
|
|
|
|
+ if (I = 1)
|
|
|
|
+{$ENDIF FPC_FEXPAND_DRIVES}
|
|
|
|
+{$IFDEF FPC_FEXPAND_UNC}
|
|
|
|
+ or (I = 2) and (Pa [1] = '\')
|
|
|
|
+{$ENDIF FPC_FEXPAND_UNC}
|
|
|
|
+ then
|
|
Dec (Pa [0])
|
|
Dec (Pa [0])
|
|
else
|
|
else
|
|
Delete (Pa, I, 2);
|
|
Delete (Pa, I, 2);
|
|
@@ -198,3 +197,11 @@ begin
|
|
Dec (Pa [0]);
|
|
Dec (Pa [0]);
|
|
FExpand := Pa;
|
|
FExpand := Pa;
|
|
end;
|
|
end;
|
|
|
|
+
|
|
|
|
+{
|
|
|
|
+ $Log$
|
|
|
|
+ Revision 1.2 2001-03-10 09:57:51 hajny
|
|
|
|
+ * FExpand without IOResult change, remaining direct asm removed
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|