Skip to content

gmSCFileSystemClass

The service class FileSystem interacts with the operating system to form, decompose, and determine file names and attributes so that they conform the requirements of the hosting platform. In addition, it performs several low level file management operations such as searching for files and loading text files into internal text streams.

A full filename is viewed as consisting of three components:

ComponentDescription
pathnameContains the location within the file system of the file. If it is omitted the
the currently selected location is assumed.
localnamecontains the actual name of the file. This is the only component that cannot be
omitted.
extensioncontains a short extension that describes the type of the file. If it is omitted
then the context is often used to determine its value.


Prototype

int FileSystem_FileName(char* fileIdent,int nIdent,char* name,int iExt);

The FileSystem_FileName method extracts the local name from a full filename. In particular it locates the local name and copies it into the return parameter as a null-terminated string. If the include extension flag is nonzero, then the extension is included with the name. Its parameters are as follows:

ParameterDescription
fileIdentContains the file name to be parsed. It need be null-terminated only if its
length is not specified.
nIdentSpecifies the length of file name. If it is set to zero, then the length is
computed.
nameReceives the localname of the file possibly concatenated with its extension. It
is null-terminated.
iExtSpecifies whether the extension should be included in the returned name. If it is
nonzero, then the extension is included in the name.

This method returns the overall length of the local name.


Prototype

void* FileSystem_FindFiles(char* directory,char* extensions);

The FileSystem_FindFiles method searches the directory tree starting in a specified directory for all files that have some specified number of extensions. The full names of the local files are stored in a text stream whose handle is the return value of this method. Its parameters are as follows:

ParameterDescription
directoryContains the full name of the root directory for the search.
extensionsContains a comma-delimited string of the extensions to be searched for.

The method returns the handle of the local text stream which contains the full filenames. It can be NULL, if it could not be created. It can contain no entries, if no files were found or if the starting directory did not exist.


Prototype

int FileSystem_GetDirectory(char* buffer,char* string,int nString,int remove);

The FileSystem_GetDirectory method gets the full directory name from a path name by removing the local filename. In addition, it may remove additional subdirectory names. Its parameters are as follows:

ParameterDescription
bufferReceives the directory name extracted from the pathname in null-terminated form.
stringContains the full pathname of a file whose directory location is wanted. It need be
null-terminated only if nString set to zero.
nStringSpecifies the overall length of the pathname. If set to zero, then the length of the
pathname is computed.
removedSpecifies the number of subdirectory names to be removed from the back of the
directory name.

This method returns the length in characters of the returned directory name.


Prototype

int FileSystem_LoadFile(void* Storage,char* filename,int strip);

The FileSystem_LoadFile method loads the content of a text file into a text stream in storage. Optionally, leading and/or trailing whitespace is stripped. The file is closed after it has been read. Note that both ASCII and Unicode files can be read by this method. The Unicode is transparently converted to ASCII before loading the records into the text stream. Its parameters are as follows:

Parameter

Description

Storage

Specifies the handle for the storage area to contain the text buffer. If this handle is NULL, then the text buffer will be allocated to a memory based storage area. If the LoadFile_UseExisting entry flag is set then this parameter Specifies the handle of the text stream.

filename

Contains the full filename for the text file whose content is to be loaded.

strip

Specifies how records are to be modified and/or stored in the text stream. The bits this parameter are used as follows:

Entry

Description of use

LoadFile_StripTrailing

strip trailing whitespace

LoadFile_StripLeading

strip leading white space

LoadFile_ReplaceCR

replace embedded CR’s with newlines

LoadFile_NullTerminate

terminate stored records with null-byte

LoadFile_UseExisting

insert file into existing text stream


The method returns the root offset of the variable information stream that contains the records of the file if all goes well. If the file cannot be opened with readonly access, then a zero is returned.


Prototype

int FileSystem_MakeFullName(char* path,char* name,int nname,char* ext,char* fullname);

The FileSystem_MakeFullName method forms a full filename from its components. This method views a file as though it consisted of three concatenated components: path name, local name, and extension. This method constructs the full name in accordance with the conventions of the platform. It has the following parameters:

ParameterDescription
pathContains the path name to be used. It may be NULL, in which case a local filename
is constructed.
nameContains the local name of the file. It need not be null-terminated if the
nname parameter is not zero.
nnameSpecifies the number of characters in the beginning of the name parameter.
If it is zero, then the name string must be null-terminated and its entire
content is used.
extContains the extension to be used. If it is NULL then the filename contains no
extension.
fullnameReceives the full constructed name of the file in null-terminated form. If is up
to the user to ensure that it contains sufficient space.

The method returns the overall length of the filename as constructed.


Prototype

int FileSystem_MakeLocalName(char* FileName,char* LocalName,int LocalLength,CONST char* Extension,int XtnLength);

The FileSystem_MakeLocalName method creates a local filename by concatenating a local name with the local extension character and an extension. Note that the local name may already contain an extension. In that case that extension is replaced. Its parameters are:

ParameterDescription
FileNameReceives the constructed local filename in null-terminated form.
LocalNameContains the local name to be used. This name may already have an extension at
its back. This method does not check the front of this name therefore, it may
contain a path name as well.
LocalLengthspecifies length of local name. A value of zero means that LocalName is
null-terminated and its length is computed.
ExtensionContains the extension.
XtnLengthSpecifies the length of the extension. If it is zero then Extension is
assumed to be null-terminated.

The method returns the length of the constructed filename.


Prototype

int FileSystem_ParseFileName(char* FileName,int Length,int* LocalStart,int* XtnStart);

The FileSystem_ParseFileName method parses a filename into its components. It views a filename as though it consisted of three concatenated components: path name, local name, and extension. This method computes the relative position within the full name of the start of the local name and the start of the extension. Since the path name is always first, if the local name start is greater than zero, then the beginning of the filename contains a path name. Its parameters are as follows:

ParameterDescription
FileNameContains the filename to be parsed. It need be null-terminated only if
Length set to zero.
LengthSpecifies the overall length of the filename. If set to zero, then the length of
the filename is computed.
LocalStartreturns the offset of the start of the local name in the filename. A value of
zero indicates that the name contains no path name component.
XtnStartreturns the offset of the start of the extension in the filename. A value of
Length indicates that the name had no extension.

The method returns the overall length of the filename.


Prototype

int FileSystem_RelativePathName(char* parent,char* child,char* relative);

The FileSystem_RelativePathName method creates a relative pathname of a child file as referenced by a parent file, such as a code file being referenced by a project file. Its parameters are as follows:

ParameterDescription
parentContains the full pathname of the parent file.
childContains the full pathname of the child file.
relativeReceives the relative pathname required to reference the child file when in the
parent location.

The method returns the length of the relative name.