home *** CD-ROM | disk | FTP | other *** search
- /*****
- *
- * Environ.prg
- *
- * Sample procedures and user-defined functions for controlling a
- * Clipper program
- *
- * Copyright, Nantucket Corporation, 1990
- * Apr 19, 1990
- *
- * NOTE: compile with /n/w/a/m
- *
- */
-
-
- #include "Set.ch"
-
-
- /***
- * FilePath( <cFile> ) --> cFilePath
- * Extract the full path name from a filename
- *
- */
- FUNCTION FilePath( cFile )
- LOCAL nPos, cFilePath
- IF (nPos := RAT("\", cFile)) != 0
- cFilePath := SUBSTR(cFile, 1, nPos)
- ELSE
- cFilePath := ""
- ENDIF
- RETURN cFilePath
-
-
-
- /***
- * FileBase( <cFile> ) --> cFileBase
- * Extract the eight letter base name from a filename
- *
- */
- FUNCTION FileBase( cFile )
- LOCAL nPos, cFileBase
-
- DO CASE
- CASE (nPos := RAT("\", cFile)) != 0
- // Strip full path name
- cFileBase := SUBSTR(cFile, nPos + 1)
- CASE (nPos := AT(":", cFile)) != 0
- // Strip drive letter
- cFileBase := SUBSTR(cFile, nPos + 1)
- OTHERWISE
- cFileBase := cFile
- ENDCASE
-
- // Strip file extension, if any
- IF (nPos := AT(".", cFileBase)) != 0
- cFileBase := SUBSTR(cFileBase, 1, nPos - 1)
- ENDIF
-
- RETURN cFileBase
-
-
-
- /***
- * FileExt( <cFile> ) --> cFileExt
- * Extract the three letter extension from a filename
- *
- */
- FUNCTION FileExt( cFile )
- LOCAL nPos, cFileExt
-
- IF (nPos := RAT(".", cFile)) != 0
- cFileExt := SUBSTR(cFile, nPos + 1)
- ELSE
- cFileExt := ""
- ENDIF
-
- RETURN cFileExt
-
-
-
- /***
- * FileDrive( <cFile> ) --> cFileDrive
- * Extract the drive designator from a fully qualified filename
- *
- */
- FUNCTION FileDrive( cFile )
- LOCAL nPos, cFileDrive := ""
-
- IF (nPos := AT(":", cFile)) != 0
- cFileDrive := SUBSTR(cFile, 1, nPos - 1)
- ENDIF
-
- RETURN cFileDrive
-
-
- /***
- * FullPath( <cFile>, <lClipPath> ) --> cFullPath
- * Returns the full path of cFile; similar to the FoxPro FULLPATH() function
- */
- FUNCTION FullPath( cFile, lDosPath )
- LOCAL cDefault, cPath
-
- cDefault := SET(_SET_DEFAULT)
- cDefault += IF( RIGHT(RTRIM(cDefault), 1) != "\", "\", "") + cFile
-
- IF FILE( cDefault )
- cPath := cDefault
- ELSE
- IF lDosPath = NIL .OR. !lDosPath
- cPath := GetPath( cFile, SET(_SET_PATH) )
- ELSE
- cPath := GetPath( cFile, GETENV( "PATH" ) )
- ENDIF
- ENDIF
- RETURN IF( cPath = NIL, cDefault, cPath )
-
-
-
- /***
- * GetPath( <cFile>, <cPathSpec> ) --> cPath
- * Returns the location of a file if found in cPathSpec; otherwise returns NIL
- *
- * NOTE: calls ListAsArray(), defined in String.prg
- */
- FUNCTION GetPath( cFile, cPathSpec )
- LOCAL aPathList, bFilePath, cPath, nPos
-
- bFilePath := { |cPath| FILE( cPath + ;
- IF( RIGHT(RTRIM(cPath), 1) != "\", "\", "") + cFile ) }
-
- aPathList := ListAsArray( STRTRAN(cPathSpec, ",", ";"), ";" )
-
- IF (nPos := ASCAN( aPathList, bFilePath )) != 0
- RETURN aPathList[ nPos ]
- ELSE
- RETURN NIL
- ENDIF
-
-
-
- /***
- * SetAll( [<aNewSets>] ) --> aCurrentSets
- * Using an array of settings, change all global SETs and return their
- * original settings in an array. If no argument is passed, simply
- * return current settings.
- *
- */
- FUNCTION SetAll( aNewSets )
- LOCAL aCurrentSets[_SET_COUNT], n
- IF ( aNewSets != NIL ) // Set new and return current
- FOR n := 1 TO _SET_COUNT
- aCurrentSets[n] := SET(n, aNewSets[n])
- NEXT
- ELSE // Just return current
- FOR n := 1 TO _SET_COUNT
- aCurrentSets[n] := SET(n)
- NEXT
- ENDIF
- RETURN (aCurrentSets)
-