home *** CD-ROM | disk | FTP | other *** search
- (* Utilities to deal with name/path strings
-
- vers1.01 10/21/85 add LastChar function
- vers1.00 08/22/85
- PL Glatz
- *)
-
-
- (* return last character from string *)
- FUNCTION LastChar(s : Str255) : CHAR ;
- BEGIN
- IF s > '' THEN
- LastChar := Copy(s, Length(s), 1)
- ELSE
- LastChar := ''
- END ; (* LastChar *)
-
-
- (* seperate name and path components from string:
- Possibilities: NamePathStr path name
- ----------- ---- ----
- [1] nnnn - nnnn
- [2] dr:nnnn dr+path of dr nnnn
- [3] dr:\nnnn dr\ nnnn
- [4] dr:\pppp\ dr:\pppp\ -
- [5] \pppp\ \pppp\ -
- [6] \pppp\nnnn\ \pppp\ nnnn
- [7] \nnnn \ nnnn
- [8] dr: dr+path of dr ---
-
- path will always be returned with a trailing '\'
- *)
-
- PROCEDURE SeperateNameFromPath(VAR NamePathStr : Str255 ; (* string containing path and name *)
- VAR name, (* returned name part here *)
- path : NameStr) ; (* returned path part here *)
- TYPE
- Possibility = (Empty,NameOnly,DriveAndName,DriveAndSlashAndName,
- DriveAndPath,PathOnly,PathAndName,SlashAndName,DriveOnly) ;
-
- VAR
- FoundPosition,
- SeperationPoint : INTEGER ;
- temp : NameStr ;
- DrivePart : STRING[2] ;
-
- (* Return name/path type *)
- FUNCTION DeterminePossibility(VAR str : Str255) : Possibility ;
- (* return TRUE if string s contains a slash *)
- FUNCTION HasSlash(VAR s : Str255) : BOOLEAN ;
- BEGIN
- FoundPosition := Pos('\',s) ;
- IF FoundPosition > 0 THEN
- HasSlash := TRUE ELSE HasSlash := FALSE
- END; (* Function HasSlash *)
-
- (* return # of slashes in string s *)
- FUNCTION SlashCount(VAR s : Str255) : INTEGER ;
- VAR
- j,
- count : INTEGER ;
- BEGIN
- count := 0 ;
- FOR j := 1 TO Length(s) DO
- IF s[j] = '\' THEN count := Succ(count) ;
- SlashCount := count
- END; (* Function SlashCount *)
-
- (* return TRUE if string s contains a colon in position 2 *)
- FUNCTION HasColon(VAR s : Str255) : BOOLEAN ;
- BEGIN
- FoundPosition := Pos(':',s) ;
- IF FoundPosition > 0 THEN
- HasColon := TRUE ELSE HasColon := FALSE
- END; (* Function HasColon *)
-
-
- BEGIN (* DeterminePossibility *)
- IF (str = '') THEN DeterminePossibility := Empty
- ELSE
- IF (NOT HasSlash(str)) AND (NOT HasColon(str)) THEN
- DeterminePossibility := NameOnly
- ELSE
- BEGIN
- IF HasColon(str) THEN
- BEGIN
- IF NOT HasSlash(str) THEN
- IF LastChar(str) = ':' THEN
- DeterminePossibility := DriveOnly
- ELSE
- DeterminePossibility := DriveAndName
- ELSE
- IF LastChar(str) = '\' THEN
- DeterminePossibility := DriveAndPath
- ELSE
- DeterminePossibility := DriveAndSlashAndName
- END
- ELSE
- IF LastChar(str) = '\' THEN
- DeterminePossibility := PathOnly
- ELSE
- IF SlashCount(str) > 1 THEN
- DeterminePossibility := PathAndName
- ELSE
- DeterminePossibility := SlashAndName
- END
- END; (* Function DeterminePossibility *)
-
- PROCEDURE DetermineSeperationPoint ;
- BEGIN
- SeperationPoint := Length(NamePathStr) ;
- WHILE (SeperationPoint > 0)
- AND (Copy(NamePathStr,SeperationPoint,1) <> '\') DO
- SeperationPoint := Pred(SeperationPoint)
- END; (* Procedure DetermineSeperationPoint *)
-
- PROCEDURE ExtractPathAndName ;
- VAR
- i : INTEGER ;
-
- BEGIN
- DetermineSeperationPoint ;
- FOR i := 1 TO SeperationPoint DO
- path := path + NamePathStr[i] ;
- i := Succ(i) ;
- WHILE i <= Length(NamePathStr) DO
- BEGIN
- name := name + NamePathStr[i] ;
- i := Succ(i)
- END
- END ; (* Procedure ExtractPathAndName *)
-
- PROCEDURE GetDriveAndName ;
- VAR
- i : INTEGER ;
-
- BEGIN
- GetDir(Ord(UpCase(NamePathStr[1]))-Ord('A')+1,path) ;
- i := Pos(':',NamePathStr) + 1 ;
- WHILE i <= Length(NamePathStr) DO
- BEGIN
- name := name + NamePathStr[i] ;
- i := Succ(i)
- END
- END ; (* Procedure GetDriveAndName *)
-
-
- BEGIN (* Procedure SeperateNameFromPath *)
- name := '' ;
- path := '' ;
- CASE DeterminePossibility(NamePathStr) OF
- NameOnly : name := NamePathStr ;
- DriveAndName : GetDriveAndName ;
- DriveAndSlashAndName : ExtractPathAndName ;
- DriveAndPath : path := NamePathStr ;
- PathOnly : path := NamePathStr ;
- PathAndName : ExtractPathAndName ;
- SlashAndName : ExtractPathAndName ;
- DriveOnly : path := NamePathStr ;
- ELSE END ; (* case *)
-
- IF path<> '' THEN
- BEGIN
- IF LastChar(path) <> '\' THEN path := path + '\'
- END
- END ; (* Procedure SeperateNameFromPath *)
-