{ ********************************************************************* $Id$ Copyright (C) 1997, 1998 Gertjan Schouten This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ********************************************************************* System Utilities For Free Pascal } {$IFDEF VIRTUALPASCAL} {$J+} {$ENDIF} function ChangeFileExt(const FileName, Extension: string): string; var i: longint; begin I := Length(FileName); while (I > 0) and not(FileName[I] in ['/', '.', '\', ':']) do Dec(I); if (I = 0) or (FileName[I] <> '.') then I := Length(FileName)+1; Result := Copy(FileName, 1, I - 1) + Extension; end; function ExtractFilePath(const FileName: string): string; var i: longint; begin i := Length(FileName); while (i > 0) and not (FileName[i] in ['/', '\', ':']) do Dec(i); If I>0 then Result := Copy(FileName, 1, i) else Result:=''; end; function ExtractFileDir(const FileName: string): string; var i: longint; begin I := Length(FileName); while (I > 0) and not (FileName[I] in ['/', '\', ':']) do Dec(I); if (I > 1) and (FileName[I] in ['\', '/']) and not (FileName[I - 1] in ['/', '\', ':']) then Dec(I); Result := Copy(FileName, 1, I); end; function ExtractFileDrive(const FileName: string): string; var i: longint; begin if (Length(FileName) >= 3) and (FileName[2] = ':') then result := Copy(FileName, 1, 2) else if (Length(FileName) >= 2) and (FileName[1] in ['/', '\']) and (FileName[2] in ['/', '\']) then begin i := 2; While (i < Length(Filename)) do begin if Filename[i + 1] in ['/', '\'] then break; inc(i); end ; Result := Copy(FileName, 1, i); end else Result := ''; end; function ExtractFileName(const FileName: string): string; var i: longint; begin I := Length(FileName); while (I > 0) and not (FileName[I] in ['/', '\', ':']) do Dec(I); Result := Copy(FileName, I + 1, 255); end; function ExtractFileExt(const FileName: string): string; var i: longint; begin I := Length(FileName); while (I > 0) and not (FileName[I] in ['.', '/', '\', ':']) do Dec(I); if (I > 0) and (FileName[I] = '.') then Result := Copy(FileName, I, 255) else Result := ''; end; function ExpandFileName (Const FileName : string): String; Var S : String; Begin S:=FileName; {$IFNDEF VIRTUALPASCAL} DoDirSeparators(S); {$ENDIF} {$ifdef HasUnix} Result:=fexpand(S); {$else} Result:=Dos.Fexpand(S); {$endif} end; function ExpandUNCFileName (Const FileName : string): String; begin Result:=ExpandFileName (FileName); //!! Here should follow code to replace the drive: part with UNC... end; Const MaxDirs = 129; function ExtractRelativepath (Const BaseName,DestName : String): String; Var Source, Dest : String; Sc,Dc,I,J : Longint; SD,DD : Array[1..MaxDirs] of PChar; Const OneLevelBack = '..'+PathDelim; begin If Uppercase(ExtractFileDrive(BaseName))<>Uppercase(ExtractFileDrive(DestName)) Then begin Result:=DestName; exit; end; Source:=ExtractFilePath(BaseName); Dest:=ExtractFilePath(DestName); SC:=GetDirs (Source,SD); DC:=GetDirs (Dest,DD); I:=1; While (I-1 then inc(Result); end; function IncludeTrailingPathDelimiter(Const Path : String) : String; Var l : Integer; begin Result:=Path; l:=Length(Result); If (L=0) or (Result[l]<>PathDelim) then Result:=Result+PathDelim; end; function IncludeTrailingBackslash(Const Path : String) : String; begin Result:=IncludeTrailingPathDelimiter(Path); end; function ExcludeTrailingBackslash(Const Path: string): string; begin Result:=ExcludeTrailingPathDelimiter(Path); end; function ExcludeTrailingPathDelimiter(Const Path: string): string; Var L : Integer; begin L:=Length(Path); If (L>0) and (Path[L]=PathDelim) then Dec(L); Result:=Copy(Path,1,L); end; function IsPathDelimiter(Const Path: string; Index: Integer): Boolean; begin Result:=(Index>0) and (Index<=Length(Path)) and (Path[Index]=PathDelim); end; Function GetFileHandle(var f : File):Longint; begin result:=filerec(f).handle; end; Function GetFileHandle(var f : Text):Longint; begin result:=textrec(f).handle; end; { $Log$ Revision 1.4 2004-10-30 20:49:32 marco * Removed a "unix." prefix Revision 1.3 2004/05/01 11:56:25 marco * fileno -> getfilehandle Revision 1.2 2004/05/01 11:04:34 marco * fileno Revision 1.1 2003/10/06 21:01:06 peter * moved classes unit to rtl Revision 1.10 2003/09/06 21:52:24 marco * commited. Revision 1.9 2003/01/10 21:02:13 marco * hasunix fix for beos Revision 1.8 2002/10/22 21:57:54 michael + Added some missing path functions Revision 1.7 2002/10/12 15:34:09 michael + Fixed changefileexit for long (>255) filenames Revision 1.6 2002/09/07 16:01:22 peter * old logs removed and tabs fixed }