bool ConfigParser::StrictMode = true;
std::stack<ConfigParser::CfgFile *> ConfigParser::CfgFiles;
ConfigParser::TokenType ConfigParser::LastTokenType = ConfigParser::SimpleToken;
-const char *ConfigParser::CfgLine = NULL;
-const char *ConfigParser::CfgPos = NULL;
+const char *ConfigParser::CfgLine = nullptr;
+const char *ConfigParser::CfgPos = nullptr;
std::queue<char *> ConfigParser::CfgLineTokens_;
bool ConfigParser::AllowMacros_ = false;
bool ConfigParser::ParseQuotedOrToEol_ = false;
return ConfigParser::NextToken();
static int fromFile = 0;
- static FILE *wordFile = NULL;
+ static FILE *wordFile = nullptr;
char *t;
static char buf[CONFIG_LINE_LIMIT];
ConfigParser::TokenType tokenType;
t = ConfigParser::NextElement(tokenType);
if (!t) {
- return NULL;
+ return nullptr;
} else if (*t == '\"' || *t == '\'') {
/* quote found, start reading from file */
debugs(3, 8,"Quoted token found : " << t);
*t = '\0';
- if ((wordFile = fopen(fn, "r")) == NULL) {
+ if ((wordFile = fopen(fn, "r")) == nullptr) {
debugs(3, DBG_CRITICAL, "ERROR: Can not open file " << fn << " for reading");
- return NULL;
+ return nullptr;
}
#if _SQUID_WINDOWS_
}
/* fromFile */
- if (fgets(buf, sizeof(buf), wordFile) == NULL) {
+ if (fgets(buf, sizeof(buf), wordFile) == nullptr) {
/* stop reading from file */
fclose(wordFile);
- wordFile = NULL;
+ wordFile = nullptr;
fromFile = 0;
- return NULL;
+ return nullptr;
} else {
char *t2, *t3;
t = buf;
char *
ConfigParser::UnQuote(const char *token, const char **next)
{
- const char *errorStr = NULL;
- const char *errorPos = NULL;
+ const char *errorStr = nullptr;
+ const char *errorPos = nullptr;
char quoteChar = *token;
assert(quoteChar == '"' || quoteChar == '\'');
LOCAL_ARRAY(char, UnQuoted, CONFIG_LINE_LIMIT);
ConfigParser::TokenParse(const char * &nextToken, ConfigParser::TokenType &type)
{
if (!nextToken || *nextToken == '\0')
- return NULL;
+ return nullptr;
type = ConfigParser::SimpleToken;
nextToken += strspn(nextToken, w_space);
if (*nextToken == '#')
- return NULL;
+ return nullptr;
if (ConfigParser::RecognizeQuotedValues && (*nextToken == '"' || *nextToken == '\'')) {
type = ConfigParser::QuotedToken;
} else
type = ConfigParser::SimpleToken;
- char *token = NULL;
+ char *token = nullptr;
if (nextToken - tokenStart) {
if (ConfigParser::StrictMode && type == ConfigParser::SimpleToken) {
bool tokenIsNumber = true;
char *
ConfigParser::NextToken()
{
- char *token = NULL;
+ char *token = nullptr;
do {
- while (token == NULL && !CfgFiles.empty()) {
+ while (token == nullptr && !CfgFiles.empty()) {
ConfigParser::CfgFile *wordfile = CfgFiles.top();
token = wordfile->parse(LastTokenType);
if (!token) {
if (LastTokenType != ConfigParser::QuotedToken) {
debugs(3, DBG_CRITICAL, "FATAL: Quoted filename missing: " << token);
self_destruct();
- return NULL;
+ return nullptr;
}
// The next token in current cfg file line must be a ")"
if (LastTokenType != ConfigParser::SimpleToken || strcmp(end, ")") != 0) {
debugs(3, DBG_CRITICAL, "FATAL: missing ')' after " << token << "(\"" << path << "\"");
self_destruct();
- return NULL;
+ return nullptr;
}
if (CfgFiles.size() > 16) {
debugs(3, DBG_CRITICAL, "FATAL: can't open %s for reading parameters: includes are nested too deeply (>16)!\n" << path);
self_destruct();
- return NULL;
+ return nullptr;
}
ConfigParser::CfgFile *wordfile = new ConfigParser::CfgFile();
debugs(3, DBG_CRITICAL, "FATAL: Error opening config file: " << token);
delete wordfile;
self_destruct();
- return NULL;
+ return nullptr;
}
CfgFiles.push(wordfile);
- token = NULL;
+ token = nullptr;
}
- } while (token == NULL && !CfgFiles.empty());
+ } while (token == nullptr && !CfgFiles.empty());
return token;
}
bool
ConfigParser::NextKvPair(char * &key, char * &value)
{
- key = value = NULL;
+ key = value = nullptr;
ParseKvPair_ = true;
KvPairState_ = ConfigParser::atParseKey;
- if ((key = NextToken()) != NULL) {
+ if ((key = NextToken()) != nullptr) {
KvPairState_ = ConfigParser::atParseValue;
value = NextQuotedToken();
}
bool
ConfigParser::CfgFile::startParse(char *path)
{
- assert(wordFile == NULL);
+ assert(wordFile == nullptr);
debugs(3, 3, "Parsing from " << path);
- if ((wordFile = fopen(path, "r")) == NULL) {
+ if ((wordFile = fopen(path, "r")) == nullptr) {
debugs(3, DBG_CRITICAL, "WARNING: file :" << path << " not found");
return false;
}
ConfigParser::CfgFile::getFileLine()
{
// Else get the next line
- if (fgets(parseBuffer, CONFIG_LINE_LIMIT, wordFile) == NULL) {
+ if (fgets(parseBuffer, CONFIG_LINE_LIMIT, wordFile) == nullptr) {
/* stop reading from file */
fclose(wordFile);
- wordFile = NULL;
+ wordFile = nullptr;
parseBuffer[0] = '\0';
return false;
}
ConfigParser::CfgFile::parse(ConfigParser::TokenType &type)
{
if (!wordFile)
- return NULL;
+ return nullptr;
if (!*parseBuffer)
- return NULL;
+ return nullptr;
char *token;
while (!(token = nextElement(type))) {
if (!getFileLine())
- return NULL;
+ return nullptr;
}
return token;
}