allow to use absolute file paths
This commit is contained in:
@ -461,8 +461,7 @@ drvInit()
|
|||||||
#endif
|
#endif
|
||||||
if (!path)
|
if (!path)
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"drvStreamInit: Warning! STREAM_PROTOCOL_PATH not set. "
|
"drvStreamInit: Warning! STREAM_PROTOCOL_PATH not set.\n");
|
||||||
"Defaults to \"%s\"\n", StreamProtocolParser::path);
|
|
||||||
else
|
else
|
||||||
StreamProtocolParser::path = path;
|
StreamProtocolParser::path = path;
|
||||||
debug("StreamProtocolParser::path = %s\n",
|
debug("StreamProtocolParser::path = %s\n",
|
||||||
|
@ -53,7 +53,7 @@ class StreamProtocolParser::Protocol::Variable
|
|||||||
// StreamProtocolParser
|
// StreamProtocolParser
|
||||||
|
|
||||||
StreamProtocolParser* StreamProtocolParser::parsers = NULL;
|
StreamProtocolParser* StreamProtocolParser::parsers = NULL;
|
||||||
const char* StreamProtocolParser::path = ".";
|
const char* StreamProtocolParser::path = NULL;
|
||||||
static const char* specialChars = " ,;{}=()$'\"+-*/";
|
static const char* specialChars = " ,;{}=()$'\"+-*/";
|
||||||
|
|
||||||
// Client destructor
|
// Client destructor
|
||||||
@ -157,12 +157,27 @@ this after protocol arguments have been replaced.
|
|||||||
StreamProtocolParser* StreamProtocolParser::
|
StreamProtocolParser* StreamProtocolParser::
|
||||||
readFile(const char* filename)
|
readFile(const char* filename)
|
||||||
{
|
{
|
||||||
FILE* file;
|
FILE* file = NULL;
|
||||||
StreamProtocolParser* parser;
|
StreamProtocolParser* parser;
|
||||||
const char *p;
|
const char *p;
|
||||||
size_t n;
|
size_t n;
|
||||||
StreamBuffer dir;
|
StreamBuffer dir;
|
||||||
|
|
||||||
|
// no path or absolute file name
|
||||||
|
if (!path || filename[0] == '/'
|
||||||
|
#ifdef _WIN32
|
||||||
|
|| filename[0] == '\\' || (isalpha(filename[0]) && filename[1] == ':')
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
|
// absolute file name
|
||||||
|
file = fopen(filename, "r");
|
||||||
|
if (file) {
|
||||||
|
debug("StreamProtocolParser::readFile: found '%s'\n", filename);
|
||||||
|
} else {
|
||||||
|
error("Can't find readable file '%s'\n", filename);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
// look for filename in every dir in search path
|
// look for filename in every dir in search path
|
||||||
for (p = path; *p; p += n)
|
for (p = path; *p; p += n)
|
||||||
{
|
{
|
||||||
@ -191,23 +206,21 @@ readFile(const char* filename)
|
|||||||
// try to read the file
|
// try to read the file
|
||||||
debug("StreamProtocolParser::readFile: try '%s'\n", dir());
|
debug("StreamProtocolParser::readFile: try '%s'\n", dir());
|
||||||
file = fopen(dir(), "r");
|
file = fopen(dir(), "r");
|
||||||
if (file)
|
if (file) {
|
||||||
{
|
|
||||||
// file found; create a parser to read it
|
|
||||||
debug("StreamProtocolParser::readFile: found '%s'\n", dir());
|
debug("StreamProtocolParser::readFile: found '%s'\n", dir());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!file) {
|
||||||
|
error("Can't find readable file '%s' in '%s'\n", filename, path);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// file found; create a parser to read it
|
||||||
parser = new StreamProtocolParser(file, filename);
|
parser = new StreamProtocolParser(file, filename);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
if (!parser->valid) return NULL;
|
if (!parser->valid) return NULL;
|
||||||
// printf(
|
|
||||||
// "/---------------------------------------------------------------------\\\n");
|
|
||||||
// parser->report();
|
|
||||||
// printf(
|
|
||||||
// "\\---------------------------------------------------------------------/\n");
|
|
||||||
return parser;
|
return parser;
|
||||||
}
|
|
||||||
}
|
|
||||||
error("Can't find readable file '%s' in '%s'\n", filename, path);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user