NAME
DtSearchAndOpenFile - To locate and open a file.
SYNOPSIS
#include <Dt.h>
FILE *DtSearchAndOpenFile( char *Name, int DirSweepDepth, int CombLevelDepth, int ReplaceFilename, char SeparatorCharacter, int NofPatterns, ... )
DESCRIPTION
DtSearchAndOpenFile() tries to open the Name named file
by trying to access it through two path-combination
methods : standard directory-type sweep-search and
combining the supplied paths in all possible ways.
The sweep-search will descend only DirSweepDepth
number of levels, while the combination-type search
will try to combine maximum CombLevelDepth number
of elements. If the ReplaceFilename is set, the
extended valid path (including the filename) will be
copied back to Name. The SeparatorCharacter will
determine the separator character used to separate the
different paths within the supplied patterns if more
than one is set. This is the same method what is used in
UNIX environments such as the $PATH. The NofPatterns
indicates how may patterns are following. If 0, the
evaluation goes until a NULL pointer is reached.
The ... indicates the patterns which contain the
supplied paths.
EXAMPLE
DtSearcAndOpenFile("read.me",5,99,0,':',0,"/usr:$PATH:$HOME","wires:readmes:others",NULL)
This will search for the 'read.me' file the following directories, max.depth 5 :
- /usr
- $PATH
- $HOME
- wires
- readmes
- others
If the standard dir-sweep-search doesn't succeed, the
routine goes to search-phase #2 : it combines all the
above occuring patterns and try to open 'read.me' relative
to those : /usr/$PATH , /usr/$HOME , /usr/wires , /usr/readmes
/usr/others , $PATH/usr , $PATH/wires , $PATH/$HOME , ...
... others/readmes/wires/$HOME/$PATH/usr/
The following rules are being observed during the combination-
calculations to avoid excessive time-and-CPU usage :
- paths beginning with the slash '/' will not be used in the middle
- repeating never occurs (like $PATH/$PATH/$PATH...)
- double slashing '//' never occurs (pre-filtering)
- repeated patterns are filtered out (like "./" and "$PWD")
DIAGNOSTICS
DtSearchAndOpenFile() returns the file pointer on success
and NULL on failure.
FILES
Link with -lDtOMio