]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/ConfigParser.cc
Maintenance: Removed most NULLs using modernize-use-nullptr (#1075)
[thirdparty/squid.git] / src / ConfigParser.cc
index bbc97ef581e6dd56a06193aa8f61a331c5c76d03..a2d51ab3b7ba670688e3d715c17b602230b97074 100644 (file)
@@ -21,8 +21,8 @@ bool ConfigParser::RecognizeQuotedValues = true;
 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;
@@ -67,7 +67,7 @@ ConfigParser::strtokFile()
         return ConfigParser::NextToken();
 
     static int fromFile = 0;
-    static FILE *wordFile = NULL;
+    static FILE *wordFile = nullptr;
 
     char *t;
     static char buf[CONFIG_LINE_LIMIT];
@@ -78,7 +78,7 @@ ConfigParser::strtokFile()
             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);
@@ -89,9 +89,9 @@ ConfigParser::strtokFile()
 
                 *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_
@@ -105,12 +105,12 @@ ConfigParser::strtokFile()
         }
 
         /* 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;
@@ -137,8 +137,8 @@ ConfigParser::strtokFile()
 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);
@@ -221,12 +221,12 @@ char *
 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;
@@ -279,7 +279,7 @@ ConfigParser::TokenParse(const char * &nextToken, ConfigParser::TokenType &type)
     } else
         type = ConfigParser::SimpleToken;
 
-    char *token = NULL;
+    char *token = nullptr;
     if (nextToken - tokenStart) {
         if (ConfigParser::StrictMode && type == ConfigParser::SimpleToken) {
             bool tokenIsNumber = true;
@@ -331,10 +331,10 @@ ConfigParser::NextElement(ConfigParser::TokenType &type)
 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) {
@@ -357,7 +357,7 @@ ConfigParser::NextToken()
             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 ")"
@@ -366,13 +366,13 @@ ConfigParser::NextToken()
             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();
@@ -380,12 +380,12 @@ ConfigParser::NextToken()
                 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;
 }
@@ -446,10 +446,10 @@ ConfigParser::optionalKvPair(char * &key, char * &value)
 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();
     }
@@ -594,9 +594,9 @@ ConfigParser::optionalAclList()
 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;
     }
@@ -613,10 +613,10 @@ bool
 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;
     }
@@ -630,15 +630,15 @@ char *
 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;
 }