From b007be7c1671661f31f056b7b7b5f480279ddbd6 Mon Sep 17 00:00:00 2001 From: albert-github Date: Mon, 25 Nov 2019 11:28:45 +0100 Subject: Checking of right usage of configuration list items In case of a configuration list item has an equal sign in it ('=') some extra restriction are imposed / made more understandable. --- src/configimpl.l | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/doxygen.cpp | 21 +++++-- src/pre.l | 5 +- 3 files changed, 203 insertions(+), 9 deletions(-) diff --git a/src/configimpl.l b/src/configimpl.l index 0cc5c88..351337e 100644 --- a/src/configimpl.l +++ b/src/configimpl.l @@ -1484,23 +1484,203 @@ void Config::checkAndCorrect() s=includePath.next(); } - // check aliases + // check EXTENSION_MAPPING + QStrList &extmapList = Config_getList(EXTENSION_MAPPING); + s=extmapList.first(); + while (s) + { + QCString extmap=s; + extmap=extmap.stripWhiteSpace(); + int i_equals=extmap.find('='); + if (i_equals==-1) + { + err("Illegal EXTENSION_MAPPING format '%s', no equal sign specified use 'ext=language'\n",extmap.data()); + } + else + { + QCString ext = extmap.left(i_equals); + QCString lang = extmap.mid(i_equals+1); + if (ext.isEmpty()) + { + err("Illegal EXTENSION_MAPPING format '%s', no extension to replace specified use 'ext=language'\n",extmap.data()); + } + else if (lang.isEmpty()) + { + err("Illegal EXTENSION_MAPPING format '%s', no replacement language specified use 'ext=language'\n",extmap.data()); + } + } + s=extmapList.next(); + } + + // check PREDEFINED + if (Config_getBool(ENABLE_PREPROCESSING)) + { + QStrList &predefList = Config_getList(PREDEFINED); + s=predefList.first(); + while (s) + { + QCString predef=s; + predef=predef.stripWhiteSpace(); + int i_equals=predef.find('='); + int i_obrace=predef.find('('); + if ((i_obrace==0) || (i_equals==0) || (i_equals==1 && predef.at(i_equals-1)==':')) + { + err("Illegal PREDEFINED format '%s', no define name specified\n",predef.data()); + } + s=predefList.next(); + } + } + + // check ALIASES QStrList &aliasList = Config_getList(ALIASES); s=aliasList.first(); while (s) { QRegExp re1("[a-z_A-Z][a-z_A-Z0-9]*[ \t]*="); // alias without argument - QRegExp re2("[a-z_A-Z][a-z_A-Z0-9]*{[0-9]*}[ \t]*="); // alias with argument + QRegExp re2("[a-z_A-Z][a-z_A-Z0-9]*{[0-9]+}[ \t]*="); // alias with argument QCString alias=s; alias=alias.stripWhiteSpace(); if (alias.find(re1)!=0 && alias.find(re2)!=0) { - err("Illegal alias format '%s'. Use \"name=value\" or \"name{n}=value\", where n is the number of arguments\n", + err("Illegal ALIASES format '%s'. Use \"name=value\" or \"name{n}=value\", where n is the number of arguments\n", alias.data()); } s=aliasList.next(); } + // check FILTER_PATTERNS + QStrList& filterList = Config_getList(FILTER_PATTERNS); + s=filterList.first(); + while (s) + { + QCString filter=s; + filter=filter.stripWhiteSpace(); + int i=filter.find('='); + if (i==-1) + { + err("Illegal FILTER_PATTERNS format, no equal sign specified in '%s'\n",filter.data()); + } + else + { + QCString myName=filter.left(i).stripWhiteSpace(); + QCString myValue=filter.right(filter.length()-i-1).stripWhiteSpace(); + if (myName.isEmpty()) + { + err("Illegal FILTER_PATTERNS format '%s', no name specified\n",filter.data()); + } + else if (myValue.isEmpty()) + { + err("Illegal FILTER_PATTERNS format '%s', no filter specified\n",filter.data()); + } + } + s=filterList.next(); + } + + // check FILTER_SOURCE_PATTERNS + QStrList& filterSrcList = Config_getList(FILTER_SOURCE_PATTERNS); + s=filterSrcList.first(); + while (s) + { + QCString filterSrc=s; + filterSrc=filterSrc.stripWhiteSpace(); + int i=filterSrc.find('='); + if (i==-1) + { + err("Illegal FILTER_SOURCE_PATTERNS format, no name specified in '%s'\n",filterSrc.data()); + } + else + { + QCString myName=filterSrc.left(i).stripWhiteSpace(); + if (myName.isEmpty()) + { + err("Illegal FILTER_SOURCE_PATTERNS format '%s', no name specified\n",filterSrc.data()); + } + } + s=filterSrcList.next(); + } + + // check TAGFILES + QStrList& tagfilesList = Config_getList(TAGFILES); + s=tagfilesList.first(); + while (s) + { + QCString tagfiles=s; + tagfiles=tagfiles.stripWhiteSpace(); + int i=tagfiles.find('='); + if (i!=-1) + { + QCString myName=tagfiles.left(i).stripWhiteSpace(); + QCString myValue=tagfiles.right(tagfiles.length()-i-1).stripWhiteSpace(); + if (myName.isEmpty()) + { + err("Illegal TAGFILES format '%s', no name specified\n",tagfiles.data()); + } + else if (myValue.isEmpty()) + { + err("Illegal TAGFILES format '%s', no tagfiles specified\n",tagfiles.data()); + } + } + s=tagfilesList.next(); + } + + // check EXTRA_SEARCH_MAPPINGS + if (Config_getBool(SEARCHENGINE) && Config_getBool(GENERATE_HTML)) + { + QStrList& searchList = Config_getList(EXTRA_SEARCH_MAPPINGS); + s=searchList.first(); + while (s) + { + QCString search=s; + search=search.stripWhiteSpace(); + int i=search.find('='); + if (i==-1) + { + err("Illegal EXTRA_SEARCH_MAPPINGS format, no equal sign specified in '%s'\n",search.data()); + } + else + { + QCString myName=search.left(i).stripWhiteSpace(); + QCString myValue=search.right(search.length()-i-1).stripWhiteSpace(); + if (myName.isEmpty()) + { + err("Illegal EXTRA_SEARCH_MAPPINGS format '%s', no tagname specified\n",search.data()); + } + else if (myValue.isEmpty()) + { + err("Illegal EXTRA_SEARCH_MAPPINGS format '%s', no location specified\n",search.data()); + } + } + s=searchList.next(); + } + } + + // check TCL_SUBST + QStrList tclsubstList = Config_getList(TCL_SUBST); + s=tclsubstList.first(); + while (s) + { + QCString tclsubst=s; + int i=tclsubst.find('='); + if (i==-1) + { + err("Illegal TCL_SUBST format, no equal sign specified in '%s'\n",tclsubst.data()); + } + else + { + QCString myName=tclsubst.left(i).stripWhiteSpace(); + QCString myValue=tclsubst.right(tclsubst.length()-i-1).stripWhiteSpace(); + if (myName.isEmpty()) + { + err("Illegal TCL_SUBST format '%s', no name to replace specified\n",tclsubst.data()); + } + else if (myValue.isEmpty()) + { + err("Illegal TCL_SUBST format '%s', no replacement value specified\n",tclsubst.data()); + } + } + s = tclsubstList.next(); + } + // check if GENERATE_TREEVIEW and GENERATE_HTMLHELP are both enabled if (Config_getBool(GENERATE_TREEVIEW) && Config_getBool(GENERATE_HTMLHELP)) { diff --git a/src/doxygen.cpp b/src/doxygen.cpp index d4d55e7..3b37567 100644 --- a/src/doxygen.cpp +++ b/src/doxygen.cpp @@ -9209,6 +9209,7 @@ static void readTagFile(const std::unique_ptr &root,const char *tl) { fileName = tagLine.left(eqPos).stripWhiteSpace(); destName = tagLine.right(tagLine.length()-eqPos-1).stripWhiteSpace(); + if (fileName.isEmpty() || destName.isEmpty()) return; QFileInfo fi(fileName); Doxygen::tagDestinationDict.insert(fi.absFilePath().utf8(),new QCString(destName)); //printf("insert tagDestination %s->%s\n",fi.fileName().data(),destName.data()); @@ -10689,11 +10690,22 @@ void adjustConfiguration() while (mapping) { QCString mapStr = mapping; - int i; - if ((i=mapStr.find('='))!=-1) + int i=mapStr.find('='); + if (i==-1) + { + mapping = extMaps.next(); + continue; + } + else { - QCString ext=mapStr.left(i).stripWhiteSpace().lower(); - QCString language=mapStr.mid(i+1).stripWhiteSpace().lower(); + QCString ext = mapStr.left(i).stripWhiteSpace().lower(); + QCString language = mapStr.mid(i+1).stripWhiteSpace().lower(); + if (ext.isEmpty() || language.isEmpty()) + { + mapping = extMaps.next(); + continue; + } + if (!updateLanguageMapping(ext,language)) { err("Failed to map file extension '%s' to unsupported language '%s'.\n" @@ -10709,7 +10721,6 @@ void adjustConfiguration() mapping = extMaps.next(); } - // add predefined macro name to a dictionary QStrList &expandAsDefinedList =Config_getList(EXPAND_AS_DEFINED); s=expandAsDefinedList.first(); diff --git a/src/pre.l b/src/pre.l index abc9df9..9d27e6f 100644 --- a/src/pre.l +++ b/src/pre.l @@ -3250,7 +3250,10 @@ void Preprocessor::processFile(const char *fileName,BufStr &input,BufStr &output int i_cbrace=ds.find(')'); bool nonRecursive = i_equals>0 && ds.at(i_equals-1)==':'; - if (i_obrace==0) continue; // no define name + if ((i_obrace==0) || (i_equals==0) || (i_equals==1 && ds.at(i_equals-1)==':')) + { + continue; // no define name + } if (i_obrace Date: Sat, 21 Dec 2019 12:22:36 +0100 Subject: Reduced code duplication --- src/configimpl.l | 185 +++++++++++-------------------------------------------- 1 file changed, 37 insertions(+), 148 deletions(-) diff --git a/src/configimpl.l b/src/configimpl.l index 754d06a..a05293f 100644 --- a/src/configimpl.l +++ b/src/configimpl.l @@ -1321,6 +1321,38 @@ void Config::init() ConfigImpl::instance()->init(); } +static void checkList(QStrList &list,const char *name, bool equalRequired,bool valueRequired) +{ + const char *s=list.first(); + while (s) + { + QCString item=s; + item=item.stripWhiteSpace(); + int i=item.find('='); + if (i==-1 && equalRequired) + { + err("Illegal format for option %s, no equal sign ('=') specified for item '%s'\n",name,item.data()); + } + if (i!=-1) + { + QCString myName=item.left(i).stripWhiteSpace(); + if (myName.isEmpty()) + { + err("Illegal format for option %s, no name specified for item '%s'\n",name,item.data()); + } + else if (valueRequired) + { + QCString myValue=item.right(item.length()-i-1).stripWhiteSpace(); + if (myValue.isEmpty()) + { + err("Illegal format for option %s, no value specified for item '%s'\n",name,item.data()); + } + } + } + s=list.next(); + } +} + void Config::checkAndCorrect() { ConfigValues::instance().init(); @@ -1484,34 +1516,6 @@ void Config::checkAndCorrect() s=includePath.next(); } - // check EXTENSION_MAPPING - QStrList &extmapList = Config_getList(EXTENSION_MAPPING); - s=extmapList.first(); - while (s) - { - QCString extmap=s; - extmap=extmap.stripWhiteSpace(); - int i_equals=extmap.find('='); - if (i_equals==-1) - { - err("Illegal EXTENSION_MAPPING format '%s', no equal sign specified use 'ext=language'\n",extmap.data()); - } - else - { - QCString ext = extmap.left(i_equals); - QCString lang = extmap.mid(i_equals+1); - if (ext.isEmpty()) - { - err("Illegal EXTENSION_MAPPING format '%s', no extension to replace specified use 'ext=language'\n",extmap.data()); - } - else if (lang.isEmpty()) - { - err("Illegal EXTENSION_MAPPING format '%s', no replacement language specified use 'ext=language'\n",extmap.data()); - } - } - s=extmapList.next(); - } - // check PREDEFINED if (Config_getBool(ENABLE_PREPROCESSING)) { @@ -1549,137 +1553,22 @@ void Config::checkAndCorrect() } // check FILTER_PATTERNS - QStrList& filterList = Config_getList(FILTER_PATTERNS); - s=filterList.first(); - while (s) - { - QCString filter=s; - filter=filter.stripWhiteSpace(); - int i=filter.find('='); - if (i==-1) - { - err("Illegal FILTER_PATTERNS format, no equal sign specified in '%s'\n",filter.data()); - } - else - { - QCString myName=filter.left(i).stripWhiteSpace(); - QCString myValue=filter.right(filter.length()-i-1).stripWhiteSpace(); - if (myName.isEmpty()) - { - err("Illegal FILTER_PATTERNS format '%s', no name specified\n",filter.data()); - } - else if (myValue.isEmpty()) - { - err("Illegal FILTER_PATTERNS format '%s', no filter specified\n",filter.data()); - } - } - s=filterList.next(); - } + checkList(Config_getList(FILTER_PATTERNS),"FILTER_PATTERNS",TRUE,TRUE); // check FILTER_SOURCE_PATTERNS - QStrList& filterSrcList = Config_getList(FILTER_SOURCE_PATTERNS); - s=filterSrcList.first(); - while (s) - { - QCString filterSrc=s; - filterSrc=filterSrc.stripWhiteSpace(); - int i=filterSrc.find('='); - if (i==-1) - { - err("Illegal FILTER_SOURCE_PATTERNS format, no name specified in '%s'\n",filterSrc.data()); - } - else - { - QCString myName=filterSrc.left(i).stripWhiteSpace(); - if (myName.isEmpty()) - { - err("Illegal FILTER_SOURCE_PATTERNS format '%s', no name specified\n",filterSrc.data()); - } - } - s=filterSrcList.next(); - } + checkList(Config_getList(FILTER_SOURCE_PATTERNS),"FILTER_SOURCE_PATTERNS",FALSE,FALSE); // check TAGFILES - QStrList& tagfilesList = Config_getList(TAGFILES); - s=tagfilesList.first(); - while (s) - { - QCString tagfiles=s; - tagfiles=tagfiles.stripWhiteSpace(); - int i=tagfiles.find('='); - if (i!=-1) - { - QCString myName=tagfiles.left(i).stripWhiteSpace(); - QCString myValue=tagfiles.right(tagfiles.length()-i-1).stripWhiteSpace(); - if (myName.isEmpty()) - { - err("Illegal TAGFILES format '%s', no name specified\n",tagfiles.data()); - } - else if (myValue.isEmpty()) - { - err("Illegal TAGFILES format '%s', no tagfiles specified\n",tagfiles.data()); - } - } - s=tagfilesList.next(); - } + checkList(Config_getList(TAGFILES),"TAGFILES",FALSE,TRUE); // check EXTRA_SEARCH_MAPPINGS if (Config_getBool(SEARCHENGINE) && Config_getBool(GENERATE_HTML)) { - QStrList& searchList = Config_getList(EXTRA_SEARCH_MAPPINGS); - s=searchList.first(); - while (s) - { - QCString search=s; - search=search.stripWhiteSpace(); - int i=search.find('='); - if (i==-1) - { - err("Illegal EXTRA_SEARCH_MAPPINGS format, no equal sign specified in '%s'\n",search.data()); - } - else - { - QCString myName=search.left(i).stripWhiteSpace(); - QCString myValue=search.right(search.length()-i-1).stripWhiteSpace(); - if (myName.isEmpty()) - { - err("Illegal EXTRA_SEARCH_MAPPINGS format '%s', no tagname specified\n",search.data()); - } - else if (myValue.isEmpty()) - { - err("Illegal EXTRA_SEARCH_MAPPINGS format '%s', no location specified\n",search.data()); - } - } - s=searchList.next(); - } + checkList(Config_getList(EXTRA_SEARCH_MAPPINGS),"EXTRA_SEARCH_MAPPING",TRUE,TRUE); } // check TCL_SUBST - QStrList tclsubstList = Config_getList(TCL_SUBST); - s=tclsubstList.first(); - while (s) - { - QCString tclsubst=s; - int i=tclsubst.find('='); - if (i==-1) - { - err("Illegal TCL_SUBST format, no equal sign specified in '%s'\n",tclsubst.data()); - } - else - { - QCString myName=tclsubst.left(i).stripWhiteSpace(); - QCString myValue=tclsubst.right(tclsubst.length()-i-1).stripWhiteSpace(); - if (myName.isEmpty()) - { - err("Illegal TCL_SUBST format '%s', no name to replace specified\n",tclsubst.data()); - } - else if (myValue.isEmpty()) - { - err("Illegal TCL_SUBST format '%s', no replacement value specified\n",tclsubst.data()); - } - } - s = tclsubstList.next(); - } + checkList(Config_getList(TCL_SUBST),"TCL_SUBST",TRUE,TRUE); // check if GENERATE_TREEVIEW and GENERATE_HTMLHELP are both enabled if (Config_getBool(GENERATE_TREEVIEW) && Config_getBool(GENERATE_HTMLHELP)) -- cgit v0.12