1 /******************************************************************************
3 * Copyright (C) 1997-2014 by Dimitri van Heesch.
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
25 #include <qfileinfo.h>
27 #include <qtextstream.h>
39 #include "configoptions.h"
41 #undef Config_getString
49 // use in-class definitions
50 #define Config_getString(val) getString(__FILE__,__LINE__,val)
51 #define Config_getInt(val) getInt(__FILE__,__LINE__,val)
52 #define Config_getList(val) getList(__FILE__,__LINE__,val)
53 #define Config_getEnum(val) getEnum(__FILE__,__LINE__,val)
54 #define Config_getBool(val) getBool(__FILE__,__LINE__,val)
56 void config_err(const char *fmt, ...)
60 vfprintf(stderr, fmt, args);
63 void config_warn(const char *fmt, ...)
67 vfprintf(stderr, fmt, args);
71 static QCString configStringRecode(
73 const char *fromEncoding,
74 const char *toEncoding);
76 #define MAX_INCLUDE_DEPTH 10
77 #define YY_NEVER_INTERACTIVE 1
79 /* -----------------------------------------------------------------
81 static QCString convertToComment(const QCString &s, const QCString &u)
83 //printf("convertToComment(%s)=%s\n",s.data(),u.data());
87 QCString tmp=s.stripWhiteSpace();
107 if (!result.isEmpty()) result+='\n';
113 void ConfigOption::writeBoolValue(FTextStream &t,bool v)
116 if (v) t << "YES"; else t << "NO";
119 void ConfigOption::writeIntValue(FTextStream &t,int i)
124 void ConfigOption::writeStringValue(FTextStream &t,QCString &s)
127 bool needsEscaping=FALSE;
128 // convert the string back to it original encoding
129 QCString se = configStringRecode(s,"UTF-8",m_encoding);
130 const char *p=se.data();
134 while ((c=*p++)!=0 && !needsEscaping)
135 needsEscaping = (c==' ' || c=='\n' || c=='\t' || c=='"' || c=='#');
142 if (*p==' ' && *(p+1)=='\0') break; // skip inserted space at the end
143 if (*p=='"') t << "\\"; // escape quotes
155 void ConfigOption::writeStringList(FTextStream &t,QStrList &l)
157 const char *p = l.first();
165 writeStringValue(t,s);
167 if (p) t << " \\" << endl;
171 /* -----------------------------------------------------------------
174 Config *Config::m_instance = 0;
176 void ConfigInt::convertStrToVal()
178 if (!m_valueString.isEmpty())
181 int val = m_valueString.toInt(&ok);
182 if (!ok || val<m_minVal || val>m_maxVal)
184 config_warn("Warning: argument `%s' for option %s is not a valid number in the range [%d..%d]!\n"
185 "Using the default: %d!\n",m_valueString.data(),m_name.data(),m_minVal,m_maxVal,m_value);
194 void ConfigBool::convertStrToVal()
196 QCString val = m_valueString.stripWhiteSpace().lower();
199 if (val=="yes" || val=="true" || val=="1" || val=="all")
203 else if (val=="no" || val=="false" || val=="0" || val=="none")
209 config_warn("Warning: argument `%s' for option %s is not a valid boolean value\n"
210 "Using the default: %s!\n",m_valueString.data(),m_name.data(),m_value?"YES":"NO");
215 QCString &Config::getString(const char *fileName,int num,const char *name) const
217 ConfigOption *opt = m_dict->find(name);
220 config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
223 else if (opt->kind()!=ConfigOption::O_String)
225 config_err("%s<%d>: Internal error: Requested option %s not of string type!\n",fileName,num,name);
228 return *((ConfigString *)opt)->valueRef();
231 QStrList &Config::getList(const char *fileName,int num,const char *name) const
233 ConfigOption *opt = m_dict->find(name);
236 config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
239 else if (opt->kind()!=ConfigOption::O_List)
241 config_err("%d<%d>: Internal error: Requested option %s not of list type!\n",fileName,num,name);
244 return *((ConfigList *)opt)->valueRef();
247 QCString &Config::getEnum(const char *fileName,int num,const char *name) const
249 ConfigOption *opt = m_dict->find(name);
252 config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
255 else if (opt->kind()!=ConfigOption::O_Enum)
257 config_err("%s<%d>: Internal error: Requested option %s not of enum type!\n",fileName,num,name);
260 return *((ConfigEnum *)opt)->valueRef();
263 int &Config::getInt(const char *fileName,int num,const char *name) const
265 ConfigOption *opt = m_dict->find(name);
268 config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
271 else if (opt->kind()!=ConfigOption::O_Int)
273 config_err("%s<%d>: Internal error: Requested option %s not of integer type!\n",fileName,num,name);
276 return *((ConfigInt *)opt)->valueRef();
279 bool &Config::getBool(const char *fileName,int num,const char *name) const
281 ConfigOption *opt = m_dict->find(name);
284 config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
287 else if (opt->kind()!=ConfigOption::O_Bool)
289 config_err("%s<%d>: Internal error: Requested option %s not of boolean type!\n",fileName,num,name);
292 return *((ConfigBool *)opt)->valueRef();
295 /* ------------------------------------------ */
297 void ConfigInfo::writeTemplate(FTextStream &t, bool sl,bool)
303 t << "#---------------------------------------------------------------------------\n";
304 t << "# " << m_doc << endl;
305 t << "#---------------------------------------------------------------------------\n";
308 void ConfigList::writeTemplate(FTextStream &t,bool sl,bool)
313 t << convertToComment(m_doc, m_userComment);
316 else if (!m_userComment.isEmpty())
318 t << convertToComment("", m_userComment);
320 t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) << "=";
321 writeStringList(t,m_value);
325 void ConfigEnum::writeTemplate(FTextStream &t,bool sl,bool)
330 t << convertToComment(m_doc, m_userComment);
333 else if (!m_userComment.isEmpty())
335 t << convertToComment("", m_userComment);
337 t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) << "=";
338 writeStringValue(t,m_value);
342 void ConfigString::writeTemplate(FTextStream &t,bool sl,bool)
347 t << convertToComment(m_doc, m_userComment);
350 else if (!m_userComment.isEmpty())
352 t << convertToComment("", m_userComment);
354 t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) << "=";
355 writeStringValue(t,m_value);
359 void ConfigInt::writeTemplate(FTextStream &t,bool sl,bool upd)
364 t << convertToComment(m_doc, m_userComment);
367 else if (!m_userComment.isEmpty())
369 t << convertToComment("", m_userComment);
371 t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) << "=";
372 if (upd && !m_valueString.isEmpty())
374 writeStringValue(t,m_valueString);
378 writeIntValue(t,m_value);
383 void ConfigBool::writeTemplate(FTextStream &t,bool sl,bool upd)
388 t << convertToComment(m_doc, m_userComment);
391 else if (!m_userComment.isEmpty())
393 t << convertToComment("", m_userComment);
395 t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) << "=";
396 if (upd && !m_valueString.isEmpty())
398 writeStringValue(t,m_valueString);
402 writeBoolValue(t,m_value);
407 void ConfigObsolete::writeTemplate(FTextStream &,bool,bool) {}
408 void ConfigDisabled::writeTemplate(FTextStream &,bool,bool) {}
410 /* -----------------------------------------------------------------
415 struct ConfigFileState
419 YY_BUFFER_STATE oldState;
420 YY_BUFFER_STATE newState;
424 static const char *inputString;
425 static int inputPosition;
427 static QCString yyFileName;
428 static QCString tmpString;
429 static QCString *s=0;
431 static QStrList *l=0;
432 static int lastState;
433 static QCString elemStr;
434 static QCString includeName;
435 static QStrList includePathList;
436 static QStack<ConfigFileState> includeStack;
437 static int includeDepth;
438 static bool config_upd = FALSE;
440 static QCString tabSizeString;
441 static QCString maxInitLinesString;
442 static QCString colsInAlphaIndexString;
443 static QCString enumValuesPerLineString;
444 static QCString treeViewWidthString;
445 static QCString maxDotGraphWidthString;
446 static QCString maxDotGraphHeightString;
447 static QCString encoding;
449 static Config *config;
451 /* -----------------------------------------------------------------
454 #define YY_INPUT(buf,result,max_size) result=yyread(buf,max_size);
456 static int yyread(char *buf,int max_size)
459 if (includeStack.isEmpty())
462 if (inputString==0) return c;
463 while( c < max_size && inputString[inputPosition] )
465 *buf = inputString[inputPosition++] ;
472 //assert(includeStack.current()->newState==YY_CURRENT_BUFFER);
473 return (int)fread(buf,1,max_size,includeStack.current()->filePtr);
478 static QCString configStringRecode(
480 const char *fromEncoding,
481 const char *toEncoding)
483 QCString inputEncoding = fromEncoding;
484 QCString outputEncoding = toEncoding;
485 if (inputEncoding.isEmpty() || outputEncoding.isEmpty() || inputEncoding==outputEncoding) return str;
486 int inputSize=str.length();
487 int outputSize=inputSize*4+1;
488 QCString output(outputSize);
489 void *cd = portable_iconv_open(outputEncoding,inputEncoding);
490 if (cd==(void *)(-1))
492 fprintf(stderr,"Error: unsupported character conversion: '%s'->'%s'\n",
493 inputEncoding.data(),outputEncoding.data());
496 size_t iLeft=(size_t)inputSize;
497 size_t oLeft=(size_t)outputSize;
498 char *inputPtr = str.data();
499 char *outputPtr = output.data();
500 if (!portable_iconv(cd, &inputPtr, &iLeft, &outputPtr, &oLeft))
502 outputSize-=(int)oLeft;
503 output.resize(outputSize+1);
504 output.at(outputSize)='\0';
505 //printf("iconv: input size=%d output size=%d\n[%s]\n",size,newSize,srcBuf.data());
509 fprintf(stderr,"Error: failed to translate characters from %s to %s: %s\n",
510 inputEncoding.data(),outputEncoding.data(),strerror(errno));
513 portable_iconv_close(cd);
517 static void checkEncoding()
519 ConfigString *option = (ConfigString*)config->get("DOXYFILE_ENCODING");
520 encoding = *option->valueRef();
523 static FILE *tryPath(const char *path,const char *fileName)
525 QCString absName=(path ? (QCString)path+"/"+fileName : (QCString)fileName);
526 QFileInfo fi(absName);
527 if (fi.exists() && fi.isFile())
529 FILE *f=portable_fopen(absName,"r");
530 if (!f) config_err("Error: could not open file %s for reading\n",absName.data());
536 static void substEnvVarsInStrList(QStrList &sl);
537 static void substEnvVarsInString(QCString &s);
539 static FILE *findFile(const char *fileName)
545 if (portable_isAbsolutePath(fileName))
547 return tryPath(NULL, fileName);
549 substEnvVarsInStrList(includePathList);
550 char *s=includePathList.first();
551 while (s) // try each of the include paths
553 FILE *f = tryPath(s,fileName);
555 s=includePathList.next();
557 // try cwd if includePathList fails
558 return tryPath(".",fileName);
561 static void readIncludeFile(const char *incName)
563 if (includeDepth==MAX_INCLUDE_DEPTH) {
564 config_err("Error: maximum include depth (%d) reached, %s is not included. Aborting...\n",
565 MAX_INCLUDE_DEPTH,incName);
569 QCString inc = incName;
570 substEnvVarsInString(inc);
571 inc = inc.stripWhiteSpace();
572 uint incLen = inc.length();
573 if (incLen>0 && inc.at(0)=='"' && inc.at(incLen-1)=='"') // strip quotes
575 inc=inc.mid(1,incLen-2);
580 if ((f=findFile(inc))) // see if the include file can be found
584 for (i=0;i<includeStack.count();i++) msg(" ");
585 msg("@INCLUDE = %s: parsing...\n",inc.data());
588 // store the state of the old file
589 ConfigFileState *fs=new ConfigFileState;
590 fs->oldState=YY_CURRENT_BUFFER;
592 fs->fileName=yyFileName;
594 // push the state on the stack
595 includeStack.push(fs);
596 // set the scanner to the include file
597 yy_switch_to_buffer(yy_create_buffer(f, YY_BUF_SIZE));
598 fs->newState=YY_CURRENT_BUFFER;
604 config_err("Error: @INCLUDE = %s: not found!\n",inc.data());
628 <Start,GetString,GetStrList,GetBool,SkipInvalid>"##".*"\n" { config->appendUserComment(yytext);}
629 <Start,GetString,GetStrList,GetBool,SkipInvalid>"#" { BEGIN(SkipComment); }
630 <Start>[a-z_A-Z][a-z_A-Z0-9]*[ \t]*"=" { QCString cmd=yytext;
631 cmd=cmd.left(cmd.length()-1).stripWhiteSpace();
632 ConfigOption *option = config->get(cmd);
633 if (option==0) // oops not known
635 config_err("Warning: ignoring unsupported tag `%s' at line %d, file %s\n",
636 yytext,yyLineNr,yyFileName.data());
641 option->setUserComment(config->takeUserComment());
642 option->setEncoding(encoding);
643 switch(option->kind())
645 case ConfigOption::O_Info:
646 // shouldn't get here!
649 case ConfigOption::O_List:
650 l = ((ConfigList *)option)->valueRef();
655 case ConfigOption::O_Enum:
656 s = ((ConfigEnum *)option)->valueRef();
660 case ConfigOption::O_String:
661 s = ((ConfigString *)option)->valueRef();
665 case ConfigOption::O_Int:
666 s = ((ConfigInt *)option)->valueStringRef();
670 case ConfigOption::O_Bool:
671 s = ((ConfigBool *)option)->valueStringRef();
675 case ConfigOption::O_Obsolete:
678 config_err("Warning: Tag `%s' at line %d of file `%s' has become obsolete.\n"
679 " This tag has been removed.\n", cmd.data(),yyLineNr,yyFileName.data());
683 config_err("Warning: Tag `%s' at line %d of file `%s' has become obsolete.\n"
684 " To avoid this warning please remove this line from your configuration "
685 "file or upgrade it using \"doxygen -u\"\n", cmd.data(),yyLineNr,yyFileName.data());
689 case ConfigOption::O_Disabled:
692 config_err("Warning: Tag `%s' at line %d of file `%s' belongs to an option that was not enabled at compile time.\n"
693 " This tag has been removed.\n", cmd.data(),yyLineNr,yyFileName.data());
697 config_err("Warning: Tag `%s' at line %d of file `%s' belongs to an option that was not enabled at compile time.\n"
698 " To avoid this warning please remove this line from your configuration "
699 "file or upgrade it using \"doxygen -u\", or recompile doxygen with this feature enabled.\n", cmd.data(),yyLineNr,yyFileName.data());
706 <Start>[a-z_A-Z][a-z_A-Z0-9]*[ \t]*"+=" { QCString cmd=yytext;
707 cmd=cmd.left(cmd.length()-2).stripWhiteSpace();
708 ConfigOption *option = config->get(cmd);
709 if (option==0) // oops not known
711 config_err("Warning: ignoring unsupported tag `%s' at line %d, file %s\n",
712 yytext,yyLineNr,yyFileName.data());
717 option->setUserComment(config->takeUserComment());
718 switch(option->kind())
720 case ConfigOption::O_Info:
721 // shouldn't get here!
724 case ConfigOption::O_List:
725 l = ((ConfigList *)option)->valueRef();
729 case ConfigOption::O_Enum:
730 case ConfigOption::O_String:
731 case ConfigOption::O_Int:
732 case ConfigOption::O_Bool:
733 config_err("Warning: operator += not supported for `%s'. Ignoring line at line %d, file %s\n",
734 yytext,yyLineNr,yyFileName.data());
737 case ConfigOption::O_Obsolete:
738 config_err("Warning: Tag `%s' at line %d of file %s has become obsolete.\n"
739 "To avoid this warning please update your configuration "
740 "file using \"doxygen -u\"\n", cmd.data(),yyLineNr,yyFileName.data());
743 case ConfigOption::O_Disabled:
744 config_err("Warning: Tag `%s' at line %d of file %s belongs to an option that was not enabled at compile time.\n"
745 "To avoid this warning please remove this line from your configuration "
746 "file, upgrade it using \"doxygen -u\", or recompile doxygen with this feature enabled.\n", cmd.data(),yyLineNr,yyFileName.data());
752 <Start>"@INCLUDE_PATH"[ \t]*"=" { BEGIN(GetStrList); l=&includePathList; l->clear(); elemStr=""; }
753 /* include a config file */
754 <Start>"@INCLUDE"[ \t]*"=" { BEGIN(Include);}
755 <Include>([^ \"\t\r\n]+)|("\""[^\n\"]+"\"") {
756 readIncludeFile(configStringRecode(yytext,encoding,"UTF-8"));
760 //printf("End of include file\n");
761 //printf("Include stack depth=%d\n",g_includeStack.count());
762 if (includeStack.isEmpty())
764 //printf("Terminating scanner!\n");
769 ConfigFileState *fs=includeStack.pop();
771 YY_BUFFER_STATE oldBuf = YY_CURRENT_BUFFER;
772 yy_switch_to_buffer( fs->oldState );
773 yy_delete_buffer( oldBuf );
775 yyFileName=fs->fileName;
781 <Start>[a-z_A-Z0-9]+ { config_err("Warning: ignoring unknown tag `%s' at line %d, file %s\n",yytext,yyLineNr,yyFileName.data()); }
782 <GetString,GetBool,SkipInvalid>\n { yyLineNr++; BEGIN(Start); }
785 if (!elemStr.isEmpty())
787 //printf("elemStr1=`%s'\n",elemStr.data());
793 if (!elemStr.isEmpty())
795 //printf("elemStr2=`%s'\n",elemStr.data());
800 <GetString>[^ \"\t\r\n]+ { (*s)+=configStringRecode(yytext,encoding,"UTF-8");
803 <GetString,GetStrList,SkipInvalid>"\"" { lastState=YY_START;
804 BEGIN(GetQuotedString);
807 <GetQuotedString>"\""|"\n" {
808 // we add a bogus space to signal that the string was quoted. This space will be stripped later on.
810 //printf("Quoted String = `%s'\n",tmpString.data());
811 if (lastState==GetString)
813 (*s)+=configStringRecode(tmpString,encoding,"UTF-8");
818 elemStr+=configStringRecode(tmpString,encoding,"UTF-8");
822 config_err("Warning: Missing end quote (\") on line %d, file %s\n",yyLineNr,yyFileName.data());
827 <GetQuotedString>"\\\"" {
830 <GetQuotedString>. { tmpString+=*yytext; }
834 if (bs=="YES" || bs=="1")
836 else if (bs=="NO" || bs=="0")
841 config_warn("Warning: Invalid value `%s' for "
842 "boolean tag in line %d, file %s; use YES or NO\n",
843 bs.data(),yyLineNr,yyFileName.data());
846 <GetStrList>[^ \#\"\t\r\n]+ {
847 elemStr+=configStringRecode(yytext,encoding,"UTF-8");
849 <SkipComment>\n { yyLineNr++; BEGIN(Start); }
850 <SkipComment>\\[ \r\t]*\n { yyLineNr++; BEGIN(Start); }
851 <*>\\[ \r\t]*\n { yyLineNr++; }
853 <*>\n { yyLineNr++ ; }
857 /*@ ----------------------------------------------------------------------------
860 void Config::writeTemplate(FTextStream &t,bool sl,bool upd)
862 t << "# Doxyfile " << versionString << endl << endl;
865 t << convertToComment(m_header,"");
867 QListIterator<ConfigOption> it = iterator();
868 ConfigOption *option;
869 for (;(option=it.current());++it)
871 option->writeTemplate(t,sl,upd);
873 /* print last lines of user comment that were at the end of the file */
877 t << takeUserComment();
881 void Config::convertStrToVal()
883 QListIterator<ConfigOption> it = iterator();
884 ConfigOption *option;
885 for (;(option=it.current());++it)
887 option->convertStrToVal();
891 static void substEnvVarsInString(QCString &s)
893 static QRegExp re("\\$\\([a-z_A-Z0-9.-]+\\)");
894 static QRegExp re2("\\$\\([a-z_A-Z0-9.-]+\\([a-z_A-Z0-9.-]+\\)\\)"); // For e.g. PROGRAMFILES(X86)
895 if (s.isEmpty()) return;
898 //printf("substEnvVarInString(%s) start\n",s.data());
899 while ((i=re.match(s,p,&l))!=-1 || (i=re2.match(s,p,&l))!=-1)
901 //printf("Found environment var s.mid(%d,%d)=`%s'\n",i+2,l-3,s.mid(i+2,l-3).data());
902 QCString env=portable_getenv(s.mid(i+2,l-3));
903 substEnvVarsInString(env); // recursively expand variables if needed.
904 s = s.left(i)+env+s.right(s.length()-i-l);
905 p=i+env.length(); // next time start at the end of the expanded string
907 s=s.stripWhiteSpace(); // to strip the bogus space that was added when an argument
909 //printf("substEnvVarInString(%s) end\n",s.data());
912 static void substEnvVarsInStrList(QStrList &sl)
914 char *s = sl.first();
918 // an argument with quotes will have an extra space at the end, so wasQuoted will be TRUE.
919 bool wasQuoted = (result.find(' ')!=-1) || (result.find('\t')!=-1);
920 // here we strip the quote again
921 substEnvVarsInString(result);
923 //printf("Result %s was quoted=%d\n",result.data(),wasQuoted);
925 if (!wasQuoted) /* as a result of the expansion, a single string
926 may have expanded into a list, which we'll
927 add to sl. If the original string already
928 contained multiple elements no further
929 splitting is done to allow quoted items with spaces! */
931 int l=result.length();
934 // search for a "word"
938 // skip until start of new word
939 while (i<l && ((c=result.at(i))==' ' || c=='\t')) i++;
940 p=i; // p marks the start index of the word
941 // skip until end of a word
942 while (i<l && ((c=result.at(i))!=' ' && c!='\t' && c!='"')) i++;
943 if (i<l) // not at the end of the string
945 if (c=='"') // word within quotes
951 if (c=='"') // end quote
953 // replace the string in the list and go to the next item.
954 sl.insert(sl.at(),result.mid(p,i-p)); // insert new item before current item.
955 sl.next(); // current item is now the old item
959 else if (c=='\\') // skip escaped stuff
965 else if (c==' ' || c=='\t') // separator
967 // replace the string in the list and go to the next item.
968 sl.insert(sl.at(),result.mid(p,i-p)); // insert new item before current item.
969 sl.next(); // current item is now the old item
974 if (p!=l) // add the leftover as a string
976 // replace the string in the list and go to the next item.
977 sl.insert(sl.at(),result.right(l-p)); // insert new item before current item.
978 sl.next(); // current item is now the old item
981 else // just goto the next element in the list
983 sl.insert(sl.at(),result);
986 // remove the old unexpanded string from the list
988 sl.remove(); // current item index changes if the last element is removed.
989 if (sl.at()==i) // not last item
991 else // just removed last item
996 void ConfigString::substEnvVars()
998 substEnvVarsInString(m_value);
1001 void ConfigList::substEnvVars()
1003 substEnvVarsInStrList(m_value);
1006 void ConfigBool::substEnvVars()
1008 substEnvVarsInString(m_valueString);
1011 void ConfigInt::substEnvVars()
1013 substEnvVarsInString(m_valueString);
1016 void ConfigEnum::substEnvVars()
1018 substEnvVarsInString(m_value);
1021 void Config::substituteEnvironmentVars()
1023 QListIterator<ConfigOption> it = iterator();
1024 ConfigOption *option;
1025 for (;(option=it.current());++it)
1027 option->substEnvVars();
1031 static void cleanUpPaths(QStrList &str)
1033 char *sfp = str.first();
1036 register char *p = sfp;
1042 if (c=='\\') *p='/';
1046 QCString path = sfp;
1047 if ((path.at(0)!='/' && (path.length()<=2 || path.at(1)!=':')) ||
1048 path.at(path.length()-1)!='/'
1052 if (fi.exists() && fi.isDir())
1056 if (str.at()==i) // did not remove last item
1057 str.insert(i,fi.absFilePath().utf8()+"/");
1059 str.append(fi.absFilePath().utf8()+"/");
1066 void Config::checkFileName(const char *optionName)
1068 QCString &s = Config_getString(optionName);
1069 QCString val = s.stripWhiteSpace().lower();
1070 if ((val=="yes" || val=="true" || val=="1" || val=="all") ||
1071 (val=="no" || val=="false" || val=="0" || val=="none"))
1073 config_err("Error: file name expected for option %s, got %s instead. Ignoring...\n",optionName,s.data());
1074 s=""; // note tihe use of &s above: this will change the option value!
1078 void Config::check()
1080 //if (!projectName.isEmpty())
1082 // projectName[0]=toupper(projectName[0]);
1085 QCString &warnFormat = Config_getString("WARN_FORMAT");
1086 if (warnFormat.stripWhiteSpace().isEmpty())
1088 warnFormat="$file:$line $text";
1092 if (warnFormat.find("$file")==-1)
1094 config_err("Warning: warning format does not contain a $file tag!\n");
1096 if (warnFormat.find("$line")==-1)
1098 config_err("Warning: warning format does not contain a $line tag!\n");
1100 if (warnFormat.find("$text")==-1)
1102 config_err("Warning: warning format foes not contain a $text tag!\n");
1106 QCString &manExtension = Config_getString("MAN_EXTENSION");
1108 // set default man page extension if non is given by the user
1109 if (manExtension.isEmpty())
1114 QCString &paperType = Config_getEnum("PAPER_TYPE");
1115 paperType=paperType.lower().stripWhiteSpace();
1116 if (paperType.isEmpty())
1120 if (paperType!="a4" && paperType!="a4wide" && paperType!="letter" &&
1121 paperType!="legal" && paperType!="executive")
1123 config_err("Error: Unknown page type specified\n");
1126 QCString &outputLanguage=Config_getEnum("OUTPUT_LANGUAGE");
1127 outputLanguage=outputLanguage.stripWhiteSpace();
1128 if (outputLanguage.isEmpty())
1130 outputLanguage = "English";
1133 QCString &htmlFileExtension=Config_getString("HTML_FILE_EXTENSION");
1134 htmlFileExtension=htmlFileExtension.stripWhiteSpace();
1135 if (htmlFileExtension.isEmpty())
1137 htmlFileExtension = ".html";
1140 // expand the relative stripFromPath values
1141 QStrList &stripFromPath = Config_getList("STRIP_FROM_PATH");
1142 char *sfp = stripFromPath.first();
1143 if (sfp==0) // by default use the current path
1145 stripFromPath.append(QDir::currentDirPath().utf8()+"/");
1149 cleanUpPaths(stripFromPath);
1152 // expand the relative stripFromPath values
1153 QStrList &stripFromIncPath = Config_getList("STRIP_FROM_INC_PATH");
1154 cleanUpPaths(stripFromIncPath);
1156 // Test to see if HTML header is valid
1157 QCString &headerFile = Config_getString("HTML_HEADER");
1158 if (!headerFile.isEmpty())
1160 QFileInfo fi(headerFile);
1163 config_err("Error: tag HTML_HEADER: header file `%s' "
1164 "does not exist\n",headerFile.data());
1168 // Test to see if HTML footer is valid
1169 QCString &footerFile = Config_getString("HTML_FOOTER");
1170 if (!footerFile.isEmpty())
1172 QFileInfo fi(footerFile);
1175 config_err("Error: tag HTML_FOOTER: footer file `%s' "
1176 "does not exist\n",footerFile.data());
1180 // Test to see if MathJax code file is valid
1181 if (Config_getBool("USE_MATHJAX"))
1183 QCString &MathJaxCodefile = Config_getString("MATHJAX_CODEFILE");
1184 if (!MathJaxCodefile.isEmpty())
1186 QFileInfo fi(MathJaxCodefile);
1189 config_err("Error: tag MATHJAX_CODEFILE file `%s' "
1190 "does not exist\n",MathJaxCodefile.data());
1195 // Test to see if LaTeX header is valid
1196 QCString &latexHeaderFile = Config_getString("LATEX_HEADER");
1197 if (!latexHeaderFile.isEmpty())
1199 QFileInfo fi(latexHeaderFile);
1202 config_err("Error: tag LATEX_HEADER: header file `%s' "
1203 "does not exist\n",latexHeaderFile.data());
1207 // check include path
1208 QStrList &includePath = Config_getList("INCLUDE_PATH");
1209 char *s=includePath.first();
1213 if (!fi.exists()) config_err("Warning: tag INCLUDE_PATH: include path `%s' "
1214 "does not exist\n",s);
1215 s=includePath.next();
1219 QStrList &aliasList = Config_getList("ALIASES");
1220 s=aliasList.first();
1223 QRegExp re1("[a-z_A-Z][a-z_A-Z0-9]*[ \t]*="); // alias without argument
1224 QRegExp re2("[a-z_A-Z][a-z_A-Z0-9]*{[0-9]*}[ \t]*="); // alias with argument
1226 alias=alias.stripWhiteSpace();
1227 if (alias.find(re1)!=0 && alias.find(re2)!=0)
1229 config_err("Error: Illegal alias format `%s'. Use \"name=value\" or \"name(n)=value\", where n is the number of arguments\n",
1235 // check if GENERATE_TREEVIEW and GENERATE_HTMLHELP are both enabled
1236 if (Config_getBool("GENERATE_TREEVIEW") && Config_getBool("GENERATE_HTMLHELP"))
1238 config_err("Error: When enabling GENERATE_HTMLHELP the tree view (GENERATE_TREEVIEW) should be disabled. I'll do it for you.\n");
1239 Config_getBool("GENERATE_TREEVIEW")=FALSE;
1241 if (Config_getBool("SEARCHENGINE") && Config_getBool("GENERATE_HTMLHELP"))
1243 config_err("Error: When enabling GENERATE_HTMLHELP the search engine (SEARCHENGINE) should be disabled. I'll do it for you.\n");
1244 Config_getBool("SEARCHENGINE")=FALSE;
1247 // check if SEPARATE_MEMBER_PAGES and INLINE_GROUPED_CLASSES are both enabled
1248 if (Config_getBool("SEPARATE_MEMBER_PAGES") && Config_getBool("INLINE_GROUPED_CLASSES"))
1250 config_err("Error: When enabling INLINE_GROUPED_CLASSES the SEPARATE_MEMBER_PAGES option should be disabled. I'll do it for you.\n");
1251 Config_getBool("SEPARATE_MEMBER_PAGES")=FALSE;
1254 // check dot image format
1255 QCString &dotImageFormat=Config_getEnum("DOT_IMAGE_FORMAT");
1256 dotImageFormat=dotImageFormat.stripWhiteSpace();
1257 if (dotImageFormat.isEmpty())
1259 dotImageFormat = "png";
1261 //else if (dotImageFormat!="gif" && dotImageFormat!="png" && dotImageFormat!="jpg")
1263 // config_err("Invalid value for DOT_IMAGE_FORMAT: `%s'. Using the default.\n",dotImageFormat.data());
1264 // dotImageFormat = "png";
1267 QCString &dotFontName=Config_getString("DOT_FONTNAME");
1268 if (dotFontName=="FreeSans" || dotFontName=="FreeSans.ttf")
1270 config_err("Warning: doxygen no longer ships with the FreeSans font.\n"
1271 "You may want to clear or change DOT_FONTNAME.\n"
1272 "Otherwise you run the risk that the wrong font is being used for dot generated graphs.\n");
1277 QCString &dotPath = Config_getString("DOT_PATH");
1278 if (!dotPath.isEmpty())
1280 QFileInfo fi(dotPath);
1281 if (fi.exists() && fi.isFile()) // user specified path + exec
1283 dotPath=fi.dirPath(TRUE).utf8()+"/";
1287 QFileInfo dp(dotPath+"/dot"+portable_commandExtension());
1288 if (!dp.exists() || !dp.isFile())
1290 config_err("Warning: the dot tool could not be found at %s\n",dotPath.data());
1295 dotPath=dp.dirPath(TRUE).utf8()+"/";
1298 #if defined(_WIN32) // convert slashes
1299 uint i=0,l=dotPath.length();
1300 for (i=0;i<l;i++) if (dotPath.at(i)=='/') dotPath.at(i)='\\';
1303 else // make sure the string is empty but not null!
1308 // check mscgen path
1309 QCString &mscgenPath = Config_getString("MSCGEN_PATH");
1310 if (!mscgenPath.isEmpty())
1312 QFileInfo dp(mscgenPath+"/mscgen"+portable_commandExtension());
1313 if (!dp.exists() || !dp.isFile())
1315 config_err("Warning: the mscgen tool could not be found at %s\n",mscgenPath.data());
1320 mscgenPath=dp.dirPath(TRUE).utf8()+"/";
1321 #if defined(_WIN32) // convert slashes
1322 uint i=0,l=mscgenPath.length();
1323 for (i=0;i<l;i++) if (mscgenPath.at(i)=='/') mscgenPath.at(i)='\\';
1327 else // make sure the string is empty but not null!
1333 QCString &diaPath = Config_getString("DIA_PATH");
1334 if (!diaPath.isEmpty())
1336 QFileInfo dp(diaPath+"/dia"+portable_commandExtension());
1337 if (!dp.exists() || !dp.isFile())
1339 config_err("Warning: dia could not be found at %s\n",diaPath.data());
1344 diaPath=dp.dirPath(TRUE).utf8()+"/";
1345 #if defined(_WIN32) // convert slashes
1346 uint i=0,l=diaPath.length();
1347 for (i=0;i<l;i++) if (diaPath.at(i)=='/') diaPath.at(i)='\\';
1351 else // make sure the string is empty but not null!
1357 QStrList &inputSources=Config_getList("INPUT");
1358 if (inputSources.count()==0)
1360 // use current dir as the default
1361 inputSources.append(QDir::currentDirPath().utf8());
1365 s=inputSources.first();
1371 config_err("Warning: tag INPUT: input source `%s' does not exist\n",s);
1373 s=inputSources.next();
1377 // add default pattern if needed
1378 QStrList &filePatternList = Config_getList("FILE_PATTERNS");
1379 if (filePatternList.isEmpty())
1381 filePatternList.append("*.c");
1382 filePatternList.append("*.cc");
1383 filePatternList.append("*.cxx");
1384 filePatternList.append("*.cpp");
1385 filePatternList.append("*.c++");
1386 //filePatternList.append("*.d");
1387 filePatternList.append("*.java");
1388 filePatternList.append("*.ii");
1389 filePatternList.append("*.ixx");
1390 filePatternList.append("*.ipp");
1391 filePatternList.append("*.i++");
1392 filePatternList.append("*.inl");
1393 filePatternList.append("*.h");
1394 filePatternList.append("*.hh");
1395 filePatternList.append("*.hxx");
1396 filePatternList.append("*.hpp");
1397 filePatternList.append("*.h++");
1398 filePatternList.append("*.idl");
1399 filePatternList.append("*.odl");
1400 filePatternList.append("*.cs");
1401 filePatternList.append("*.php");
1402 filePatternList.append("*.php3");
1403 filePatternList.append("*.inc");
1404 filePatternList.append("*.m");
1405 filePatternList.append("*.mm");
1406 filePatternList.append("*.dox");
1407 filePatternList.append("*.py");
1408 filePatternList.append("*.f90");
1409 filePatternList.append("*.f");
1410 filePatternList.append("*.for");
1411 filePatternList.append("*.vhd");
1412 filePatternList.append("*.vhdl");
1413 filePatternList.append("*.tcl");
1414 filePatternList.append("*.md");
1415 filePatternList.append("*.markdown");
1416 if (portable_fileSystemIsCaseSensitive())
1418 // unix => case sensitive match => also include useful uppercase versions
1419 filePatternList.append("*.C");
1420 filePatternList.append("*.CC");
1421 filePatternList.append("*.C++");
1422 filePatternList.append("*.II");
1423 filePatternList.append("*.I++");
1424 filePatternList.append("*.H");
1425 filePatternList.append("*.HH");
1426 filePatternList.append("*.H++");
1427 filePatternList.append("*.CS");
1428 filePatternList.append("*.PHP");
1429 filePatternList.append("*.PHP3");
1430 filePatternList.append("*.M");
1431 filePatternList.append("*.MM");
1432 filePatternList.append("*.PY");
1433 filePatternList.append("*.F90");
1434 filePatternList.append("*.F");
1435 filePatternList.append("*.VHD");
1436 filePatternList.append("*.VHDL");
1437 filePatternList.append("*.TCL");
1438 filePatternList.append("*.MD");
1439 filePatternList.append("*.MARKDOWN");
1443 // add default pattern if needed
1444 QStrList &examplePatternList = Config_getList("EXAMPLE_PATTERNS");
1445 if (examplePatternList.isEmpty())
1447 examplePatternList.append("*");
1450 // if no output format is enabled, warn the user
1451 if (!Config_getBool("GENERATE_HTML") &&
1452 !Config_getBool("GENERATE_LATEX") &&
1453 !Config_getBool("GENERATE_MAN") &&
1454 !Config_getBool("GENERATE_RTF") &&
1455 !Config_getBool("GENERATE_XML") &&
1456 !Config_getBool("GENERATE_PERLMOD") &&
1457 !Config_getBool("GENERATE_RTF") &&
1458 !Config_getBool("GENERATE_AUTOGEN_DEF") &&
1459 Config_getString("GENERATE_TAGFILE").isEmpty()
1462 config_err("Warning: No output formats selected! Set at least one of the main GENERATE_* options to YES.\n");
1465 // check HTMLHELP creation requirements
1466 if (!Config_getBool("GENERATE_HTML") &&
1467 Config_getBool("GENERATE_HTMLHELP"))
1469 config_err("Warning: GENERATE_HTMLHELP=YES requires GENERATE_HTML=YES.\n");
1472 // check QHP creation requirements
1473 if (Config_getBool("GENERATE_QHP"))
1475 if (Config_getString("QHP_NAMESPACE").isEmpty())
1477 config_err("Error: GENERATE_QHP=YES requires QHP_NAMESPACE to be set. Using 'org.doxygen.doc' as default!.\n");
1478 Config_getString("QHP_NAMESPACE")="org.doxygen.doc";
1481 if (Config_getString("QHP_VIRTUAL_FOLDER").isEmpty())
1483 config_err("Error: GENERATE_QHP=YES requires QHP_VIRTUAL_FOLDER to be set. Using 'doc' as default!\n");
1484 Config_getString("QHP_VIRTUAL_FOLDER")="doc";
1488 if (Config_getBool("OPTIMIZE_OUTPUT_JAVA") && Config_getBool("INLINE_INFO"))
1490 // don't show inline info for Java output, since Java has no inline
1492 Config_getBool("INLINE_INFO")=FALSE;
1495 int &depth = Config_getInt("MAX_DOT_GRAPH_DEPTH");
1501 int &hue = Config_getInt("HTML_COLORSTYLE_HUE");
1511 int &sat = Config_getInt("HTML_COLORSTYLE_SAT");
1520 int &gamma = Config_getInt("HTML_COLORSTYLE_GAMMA");
1530 QCString mathJaxFormat = Config_getEnum("MATHJAX_FORMAT");
1531 if (!mathJaxFormat.isEmpty() && mathJaxFormat!="HTML-CSS" &&
1532 mathJaxFormat!="NativeMML" && mathJaxFormat!="SVG")
1534 config_err("Error: Unsupported value for MATHJAX_FORMAT: Should be one of HTML-CSS, NativeMML, or SVG\n");
1535 Config_getEnum("MATHJAX_FORMAT")="HTML-CSS";
1538 // add default words if needed
1539 QStrList &annotationFromBrief = Config_getList("ABBREVIATE_BRIEF");
1540 if (annotationFromBrief.isEmpty())
1542 annotationFromBrief.append("The $name class");
1543 annotationFromBrief.append("The $name widget");
1544 annotationFromBrief.append("The $name file");
1545 annotationFromBrief.append("is");
1546 annotationFromBrief.append("provides");
1547 annotationFromBrief.append("specifies");
1548 annotationFromBrief.append("contains");
1549 annotationFromBrief.append("represents");
1550 annotationFromBrief.append("a");
1551 annotationFromBrief.append("an");
1552 annotationFromBrief.append("the");
1555 // some default settings for vhdl
1556 if (Config_getBool("OPTIMIZE_OUTPUT_VHDL") &&
1557 (Config_getBool("INLINE_INHERITED_MEMB") ||
1558 Config_getBool("INHERIT_DOCS") ||
1559 !Config_getBool("HIDE_SCOPE_NAMES") ||
1560 !Config_getBool("EXTRACT_PRIVATE") ||
1561 !Config_getBool("EXTRACT_PACKAGE")
1565 bool b1 = Config_getBool("INLINE_INHERITED_MEMB");
1566 bool b2 = Config_getBool("INHERIT_DOCS");
1567 bool b3 = Config_getBool("HIDE_SCOPE_NAMES");
1568 bool b4 = Config_getBool("EXTRACT_PRIVATE");
1569 bool b5 = Config_getBool("SKIP_FUNCTION_MACROS");
1570 bool b6 = Config_getBool("EXTRACT_PACKAGE");
1571 const char *s1,*s2,*s3,*s4,*s5,*s6;
1572 if (b1) s1=" INLINE_INHERITED_MEMB = NO (was YES)\n"; else s1="";
1573 if (b2) s2=" INHERIT_DOCS = NO (was YES)\n"; else s2="";
1574 if (!b3) s3=" HIDE_SCOPE_NAMES = YES (was NO)\n"; else s3="";
1575 if (!b4) s4=" EXTRACT_PRIVATE = YES (was NO)\n"; else s4="";
1576 if (b5) s5=" ENABLE_PREPROCESSING = NO (was YES)\n"; else s5="";
1577 if (!b6) s6=" EXTRACT_PACKAGE = YES (was NO)\n"; else s6="";
1580 config_err("Warning: enabling OPTIMIZE_OUTPUT_VHDL assumes the following settings:\n"
1581 "%s%s%s%s%s%s",s1,s2,s3,s4,s5,s6
1584 Config_getBool("INLINE_INHERITED_MEMB") = FALSE;
1585 Config_getBool("INHERIT_DOCS") = FALSE;
1586 Config_getBool("HIDE_SCOPE_NAMES") = TRUE;
1587 Config_getBool("EXTRACT_PRIVATE") = TRUE;
1588 Config_getBool("ENABLE_PREPROCESSING") = FALSE;
1589 Config_getBool("EXTRACT_PACKAGE") = TRUE;
1592 checkFileName("GENERATE_TAGFILE");
1594 #if 0 // TODO: this breaks test 25; SOURCEBROWSER = NO and SOURCE_TOOLTIPS = YES.
1595 // So this and other regressions should be analysed and fixed before this can be enabled
1596 // disable any boolean options that depend on disabled options
1597 QListIterator<ConfigOption> it = iterator();
1598 ConfigOption *option;
1599 for (it.toFirst();(option=it.current());++it)
1601 QCString depName = option->dependsOn(); // option has a dependency
1602 if (!depName.isEmpty())
1604 ConfigOption * dep = Config::instance()->get(depName);
1605 if (dep->kind()==ConfigOption::O_Bool &&
1606 Config_getBool(depName)==FALSE) // dependent option is disabled
1608 if (option->kind()==ConfigOption::O_Bool)
1610 printf("disabling option %s\n",option->name().data());
1611 Config_getBool(option->name())=FALSE; // also disable this option
1621 QListIterator<ConfigOption> it = iterator();
1622 ConfigOption *option;
1623 for (;(option=it.current());++it)
1628 // sanity check if all depends relations are valid
1629 for (it.toFirst();(option=it.current());++it)
1631 QCString depName = option->dependsOn();
1632 if (!depName.isEmpty())
1634 ConfigOption * opt = Config::instance()->get(depName);
1637 config_err("Warning: Config option '%s' has invalid depends relation on unknown option '%s'\n",
1638 option->name().data(),depName.data());
1645 void Config::create()
1647 if (m_initialized) return;
1648 m_initialized = TRUE;
1649 addConfigOptions(this);
1652 static QCString configFileToString(const char *name)
1654 if (name==0 || name[0]==0) return 0;
1657 bool fileOpened=FALSE;
1658 if (name[0]=='-' && name[1]==0) // read from stdin
1660 fileOpened=f.open(IO_ReadOnly,stdin);
1663 const int bSize=4096;
1664 QCString contents(bSize);
1667 while ((size=f.readBlock(contents.data()+totalSize,bSize))==bSize)
1670 contents.resize(totalSize+bSize);
1673 contents.resize(totalSize);
1674 contents.at(totalSize-2)='\n'; // to help the scanner
1675 contents.at(totalSize-1)='\0';
1679 else // read from file
1682 if (!fi.exists() || !fi.isFile())
1684 config_err("Error: file `%s' not found\n",name);
1688 fileOpened=f.open(IO_ReadOnly);
1692 QCString contents(fsize+2);
1693 f.readBlock(contents.data(),fsize);
1695 if (fsize==0 || contents[fsize-1]=='\n')
1696 contents[fsize]='\0';
1698 contents[fsize]='\n'; // to help the scanner
1699 contents[fsize+1]='\0';
1705 config_err("Error: cannot open file `%s' for reading\n",name);
1710 bool Config::parseString(const char *fn,const char *str,bool update)
1712 config = Config::instance();
1717 includeStack.setAutoDelete(TRUE);
1718 includeStack.clear();
1720 configYYrestart( configYYin );
1722 config_upd = update;
1729 bool Config::parse(const char *fn,bool update)
1733 printlex(yy_flex_debug, TRUE, __FILE__, fn);
1734 retval = parseString(fn,configFileToString(fn), update);
1735 printlex(yy_flex_debug, FALSE, __FILE__, fn);
1739 extern "C" { // some bogus code to keep the compiler happy
1740 //int configYYwrap() { return 1 ; }