allow to use absolute file paths
This commit is contained in:
@ -461,8 +461,7 @@ drvInit()
|
||||
#endif
|
||||
if (!path)
|
||||
fprintf(stderr,
|
||||
"drvStreamInit: Warning! STREAM_PROTOCOL_PATH not set. "
|
||||
"Defaults to \"%s\"\n", StreamProtocolParser::path);
|
||||
"drvStreamInit: Warning! STREAM_PROTOCOL_PATH not set.\n");
|
||||
else
|
||||
StreamProtocolParser::path = path;
|
||||
debug("StreamProtocolParser::path = %s\n",
|
||||
|
@ -53,7 +53,7 @@ class StreamProtocolParser::Protocol::Variable
|
||||
// StreamProtocolParser
|
||||
|
||||
StreamProtocolParser* StreamProtocolParser::parsers = NULL;
|
||||
const char* StreamProtocolParser::path = ".";
|
||||
const char* StreamProtocolParser::path = NULL;
|
||||
static const char* specialChars = " ,;{}=()$'\"+-*/";
|
||||
|
||||
// Client destructor
|
||||
@ -157,12 +157,27 @@ this after protocol arguments have been replaced.
|
||||
StreamProtocolParser* StreamProtocolParser::
|
||||
readFile(const char* filename)
|
||||
{
|
||||
FILE* file;
|
||||
FILE* file = NULL;
|
||||
StreamProtocolParser* parser;
|
||||
const char *p;
|
||||
size_t n;
|
||||
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
|
||||
for (p = path; *p; p += n)
|
||||
{
|
||||
@ -191,24 +206,22 @@ readFile(const char* filename)
|
||||
// try to read the file
|
||||
debug("StreamProtocolParser::readFile: try '%s'\n", dir());
|
||||
file = fopen(dir(), "r");
|
||||
if (file)
|
||||
{
|
||||
// file found; create a parser to read it
|
||||
if (file) {
|
||||
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);
|
||||
fclose(file);
|
||||
if (!parser->valid) return NULL;
|
||||
// printf(
|
||||
// "/---------------------------------------------------------------------\\\n");
|
||||
// parser->report();
|
||||
// printf(
|
||||
// "\\---------------------------------------------------------------------/\n");
|
||||
return parser;
|
||||
}
|
||||
}
|
||||
error("Can't find readable file '%s' in '%s'\n", filename, path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
STEP 2: Compile protocols to executable format
|
||||
|
Reference in New Issue
Block a user