The Display Path
The access to files is greatly simplified by the display path mechanism. If the path name provided in a call to the functions that open and read files is relative, the function searches for the file name in the directories specified in the display path.
The member functions of IlvDisplay can be used to check and manipulate the display path, as well as to check whether a file name exists in any of the directories specified in the display path.
For details on the display path mechanism, see:
Setting the Display Path
The display path is a string that contains multiple directory path names, separated by the regular system path separator (‘:’ under UNIX, and ‘;’ for DOS).
Initially (when the IlvDisplay instance is created), the display path is set to the concatenation of three distinct elements as follows (using UNIX notation for path):
<.:user path:system path:>
*The first section contains only the current directory (noted ‘.’).
*The second section, user path, is composed of the contents of the display resource path followed by the contents of the environment variable ILVPATH.
*The third section, system path, contains subdirectories of IlvHome.
In short, the IlvPath initial value is (assuming ILVHOME is defined):
.:<path resource>:$ILVPATH:$ILVHOME/data:$ILVHOME/data/icon:$ILVHOME
data/images
The Path Resource
*On X Window, the path resource will be, for example:
AppName*path: /usr/local/views/ilv
*On Microsoft Windows, the path resource can be in the VIEWS.INI or application-dependent file .INI:
[AppName]
path=C:\USER\DATA\ILV
The ILVPATH Environment Variable
The ILVPATH environment variable can be set by the user before the application is launched.
*With UNIX, this setting can be defined by the lines:
$ ILVPATH=/usr/home/user/ilvimages:/usr/home/user/ilvpanels
$ export ILVPATH
*In a Microsoft Windows command prompt window, this setting could be:
C:\> SET ILVPATH=C:\USER\DATA\ILV;C:\USER\DATA\IMAGES
Querying or Modifying the Display Path
The class IlvDisplay provides member functions to manipulate the display path. These are getPath, setPath, appendToPath, and prependToPath.
These methods allow the user to get, set, and modify the user path (that is, the second section of the display path). The structure of the display path remains the same, that is:
<.:user path:system path.>
The method findInPath is used to:
*Check whether a file is in the display path.
*Get its absolute path name.
Example: Add a Directory to the Display Path
The following example shows how to add a directory to the display path and check whether a file is in the display path.
IlvDisplay* display = new IlvDisplay("AppName",
"DisplayName",
argc,
argv);
if (display->isBad()) {
delete display;
IlvFatalError("Could not create display");
IlvExit(-1);
}
 
const char* dirName = "./localDirectory/subDirectory";
const char* fileName = "foo.txt";
display->prependToPath(dirName);
// Now, if a file such as
// "./localDirectory/subDirectory/foo.txt"
// or
// ".\localDirectory\subDirectory\foo.txt"
// exists, we should be able to find it.
const char* filePath = display->findInPath(fileName);
if (filePath)
IlvPrint("File %s found at %s", fileName, filePath);
else
IlvWarning("File %s not found", fileName);
Published date: 05/24/2022
Last modified date: 02/24/2022