@@ -117,6 +117,8 @@ class MainStream : public ConfigFile::Stream
117117class TextStream : public ConfigFile ::Stream
118118{
119119public:
120+ inline static constexpr const char * STREAM_NAME = " Passed text" ;
121+
120122 explicit TextStream (const char * configText)
121123 : s(configText), l(0 )
122124 {
@@ -275,7 +277,7 @@ ConfigFile::Stream::~Stream()
275277 * Parse line, taking quotes into account
276278 */
277279
278- ConfigFile::LineType ConfigFile::parseLine (const char * fileName, const String& inputPar, Parameter& par)
280+ ConfigFile::LineType ConfigFile::parseLine (const StreamName fileName, const String& inputPar, Parameter& par)
279281{
280282 int inString = 0 ;
281283 String::size_type valStart = 0 ;
@@ -449,7 +451,7 @@ void ConfigFile::adjustMacroReplacePositions(const String& value, const String&
449451 to += getDirSeparatorLength (value, to);
450452}
451453
452- bool ConfigFile::macroParse (String& value, const char * fileName) const
454+ bool ConfigFile::macroParse (String& value, const StreamName fileName) const
453455{
454456 String::size_type pos = 0 ;
455457 String::size_type subFrom;
@@ -506,7 +508,7 @@ bool ConfigFile::macroParse(String& value, const char* fileName) const
506508 * Find macro value
507509 */
508510
509- bool ConfigFile::translate (const char * fileName, const String& from, String& to) const
511+ bool ConfigFile::translate (const StreamName fileName, const String& from, String& to) const
510512{
511513 if (from == " root" )
512514 {
@@ -518,19 +520,20 @@ bool ConfigFile::translate(const char* fileName, const String& from, String& to)
518520 }
519521 else if (from == " this" )
520522 {
521- if (!fileName)
523+ if (!fileName. has_value () )
522524 {
523525 return false ;
524526 }
525527
526- PathName tempPath (fileName);
528+ const char * fileNameData = fileName.value_or (" " );
529+ PathName tempPath (fileNameData);
527530
528531#ifdef UNIX
529532 if (PathUtils::isSymLink (tempPath))
530533 {
531534 // If $(this) is a symlink, expand it.
532535 TEXT temp[MAXPATHLEN ];
533- const int n = readlink (fileName , temp, sizeof (temp));
536+ const int n = readlink (fileNameData , temp, sizeof (temp));
534537
535538 if (n != -1 )
536539 {
@@ -539,7 +542,7 @@ bool ConfigFile::translate(const char* fileName, const String& from, String& to)
539542 if (PathUtils::isRelative (tempPath))
540543 {
541544 PathName parent;
542- PathUtils::splitLastComponent (parent, tempPath, fileName );
545+ PathUtils::splitLastComponent (parent, tempPath, fileNameData );
543546 PathUtils::concatPath (tempPath, parent, temp);
544547 }
545548 }
@@ -640,9 +643,9 @@ const ConfigFile::Parameter* ConfigFile::findParameter(const KeyType& name, cons
640643 * Take into an account fault line
641644 */
642645
643- void ConfigFile::badLine (const char * fileName, const String& line)
646+ void ConfigFile::badLine (const StreamName fileName, const String& line)
644647{
645- (Arg::Gds (isc_conf_line) << ( fileName ? fileName : " Passed text " ) << line).raise ();
648+ (Arg::Gds (isc_conf_line) << fileName. value_or (TextStream:: STREAM_NAME ) << line).raise ();
646649}
647650
648651/* *****************************************************************************
@@ -655,7 +658,7 @@ void ConfigFile::parse(Stream* stream)
655658 String inputLine;
656659 Parameter* previous = NULL ;
657660 unsigned int line;
658- const char * streamName = stream->getFileName ();
661+ const StreamName streamName = stream->getFileName ();
659662
660663 parameters.setSortMode (FB_ARRAY_SORT_MANUAL );
661664
@@ -756,24 +759,26 @@ void ConfigFile::parse(Stream* stream)
756759 * Parse include operator
757760 */
758761
759- void ConfigFile::include (const char * currentFileName, const PathName& parPath)
762+ void ConfigFile::include (const StreamName currentFileName, const PathName& parPath)
760763{
764+ const auto fileNameForError = currentFileName.value_or (TextStream::STREAM_NAME );
765+
761766#ifdef DEBUG_INCLUDES
762767 fprintf (stderr, " include into %s file(s) %s\n " , currentFileName, parPath.c_str ());
763768#endif
764769 // We should better limit include depth
765770 AutoSetRestore<unsigned > depth (&includeLimit, includeLimit + 1 );
766771 if (includeLimit > INCLUDE_LIMIT )
767772 {
768- (Arg::Gds (isc_conf_include) << currentFileName << parPath << Arg::Gds (isc_include_depth)).raise ();
773+ (Arg::Gds (isc_conf_include) << fileNameForError << parPath << Arg::Gds (isc_include_depth)).raise ();
769774 }
770775
771776 // for relative paths first of all prepend with current path (i.e. path of current conf file)
772777 PathName path;
773778 if (PathUtils::isRelative (parPath))
774779 {
775780 PathName dummy;
776- PathUtils::splitLastComponent (path, dummy, currentFileName);
781+ PathUtils::splitLastComponent (path, dummy, currentFileName. value_or ( " " ) );
777782 }
778783 PathUtils::concatPath (path, path, parPath);
779784
@@ -796,12 +801,12 @@ void ConfigFile::include(const char* currentFileName, const PathName& parPath)
796801 }
797802
798803 // analyze components for wildcards
799- if (!wildCards (currentFileName, pathPrefix, components))
804+ if (!wildCards (pathPrefix, components))
800805 {
801806 // no matches found - check for presence of wild symbols in path
802807 if (!hadWildCards)
803808 {
804- (Arg::Gds (isc_conf_include) << currentFileName << parPath << Arg::Gds (isc_include_miss)).raise ();
809+ (Arg::Gds (isc_conf_include) << fileNameForError << parPath << Arg::Gds (isc_include_miss)).raise ();
805810 }
806811 }
807812}
@@ -814,7 +819,7 @@ void ConfigFile::include(const char* currentFileName, const PathName& parPath)
814819 * - returns true if some match was found
815820 */
816821
817- bool ConfigFile::wildCards (const char * currentFileName, const PathName& pathPrefix, FilesArray& components)
822+ bool ConfigFile::wildCards (const PathName& pathPrefix, FilesArray& components)
818823{
819824 // Any change in directory can cause config change
820825 PathName prefix (pathPrefix);
@@ -855,7 +860,7 @@ bool ConfigFile::wildCards(const char* currentFileName, const PathName& pathPref
855860
856861 if (mustBeDir) // should be directory
857862 {
858- found = wildCards (currentFileName, name, components) || found;
863+ found = wildCards (name, components) || found;
859864 }
860865 else
861866 {
@@ -962,4 +967,3 @@ bool ConfigFile::Parameter::asBoolean() const
962967 value.equalsNoCase (" yes" ) ||
963968 value.equalsNoCase (" y" );
964969}
965-
0 commit comments