1 /******************************************************************************
3 * Copyright (C) 1997-2015 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.
12 %option never-interactive
13 %option prefix="configimplYY"
27 #include <qfileinfo.h>
29 #include <qtextstream.h>
34 #include "configimpl.h"
41 #include "configoptions.h"
44 #define YY_NO_UNISTD_H 1
46 static const char *warning_str = "warning: ";
47 static const char *error_str = "error: ";
49 void config_err(const char *fmt, ...)
53 vfprintf(stderr, (QCString(error_str) + fmt).data(), args);
56 void config_warn(const char *fmt, ...)
60 vfprintf(stderr, (QCString(warning_str) + fmt).data(), args);
64 static QCString configStringRecode(
66 const char *fromEncoding,
67 const char *toEncoding);
69 #define MAX_INCLUDE_DEPTH 10
70 #define YY_NEVER_INTERACTIVE 1
72 /* -----------------------------------------------------------------
74 static QCString convertToComment(const QCString &s, const QCString &u)
76 //printf("convertToComment(%s)=%s\n",s.data(),u.data());
80 QCString tmp=s.stripWhiteSpace();
81 const char *p=tmp.data();
100 if (!result.isEmpty()) result+='\n';
106 void ConfigOption::writeBoolValue(FTextStream &t,bool v)
109 if (v) t << "YES"; else t << "NO";
112 void ConfigOption::writeIntValue(FTextStream &t,int i)
117 void ConfigOption::writeStringValue(FTextStream &t,QCString &s)
120 bool needsEscaping=FALSE;
121 // convert the string back to it original encoding
122 QCString se = configStringRecode(s,"UTF-8",m_encoding);
123 const char *p=se.data();
127 while ((c=*p++)!=0 && !needsEscaping)
128 needsEscaping = (c==' ' || c=='\n' || c=='\t' || c=='"' || c=='#');
135 if (*p==' ' && *(p+1)=='\0') break; // skip inserted space at the end
136 if (*p=='"') t << "\\"; // escape quotes
148 void ConfigOption::writeStringList(FTextStream &t,QStrList &l)
150 const char *p = l.first();
158 writeStringValue(t,s);
160 if (p) t << " \\" << endl;
164 /* -----------------------------------------------------------------
167 ConfigImpl *ConfigImpl::m_instance = 0;
169 void ConfigInt::convertStrToVal()
171 if (!m_valueString.isEmpty())
174 int val = m_valueString.toInt(&ok);
175 if (!ok || val<m_minVal || val>m_maxVal)
177 config_warn("argument `%s' for option %s is not a valid number in the range [%d..%d]!\n"
178 "Using the default: %d!\n",m_valueString.data(),m_name.data(),m_minVal,m_maxVal,m_value);
187 void ConfigBool::convertStrToVal()
189 QCString val = m_valueString.stripWhiteSpace().lower();
192 if (val=="yes" || val=="true" || val=="1" || val=="all")
196 else if (val=="no" || val=="false" || val=="0" || val=="none")
202 config_warn("argument `%s' for option %s is not a valid boolean value\n"
203 "Using the default: %s!\n",m_valueString.data(),m_name.data(),m_value?"YES":"NO");
208 QCString &ConfigImpl::getString(const char *fileName,int num,const char *name) const
210 ConfigOption *opt = m_dict->find(name);
213 config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
216 else if (opt->kind()!=ConfigOption::O_String)
218 config_err("%s<%d>: Internal error: Requested option %s not of string type!\n",fileName,num,name);
221 return *((ConfigString *)opt)->valueRef();
224 QStrList &ConfigImpl::getList(const char *fileName,int num,const char *name) const
226 ConfigOption *opt = m_dict->find(name);
229 config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
232 else if (opt->kind()!=ConfigOption::O_List)
234 config_err("%s<%d>: Internal error: Requested option %s not of list type!\n",fileName,num,name);
237 return *((ConfigList *)opt)->valueRef();
240 QCString &ConfigImpl::getEnum(const char *fileName,int num,const char *name) const
242 ConfigOption *opt = m_dict->find(name);
245 config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
248 else if (opt->kind()!=ConfigOption::O_Enum)
250 config_err("%s<%d>: Internal error: Requested option %s not of enum type!\n",fileName,num,name);
253 return *((ConfigEnum *)opt)->valueRef();
256 int &ConfigImpl::getInt(const char *fileName,int num,const char *name) const
258 ConfigOption *opt = m_dict->find(name);
261 config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
264 else if (opt->kind()!=ConfigOption::O_Int)
266 config_err("%s<%d>: Internal error: Requested option %s not of integer type!\n",fileName,num,name);
269 return *((ConfigInt *)opt)->valueRef();
272 bool &ConfigImpl::getBool(const char *fileName,int num,const char *name) const
274 ConfigOption *opt = m_dict->find(name);
277 config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
280 else if (opt->kind()!=ConfigOption::O_Bool)
282 config_err("%s<%d>: Internal error: Requested option %s not of boolean type!\n",fileName,num,name);
285 return *((ConfigBool *)opt)->valueRef();
288 /* ------------------------------------------ */
290 void ConfigInfo::writeTemplate(FTextStream &t, bool sl,bool)
296 t << "#---------------------------------------------------------------------------\n";
297 t << "# " << m_doc << endl;
298 t << "#---------------------------------------------------------------------------\n";
301 void ConfigList::writeTemplate(FTextStream &t,bool sl,bool)
306 t << convertToComment(m_doc, m_userComment);
309 else if (!m_userComment.isEmpty())
311 t << convertToComment("", m_userComment);
313 t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) << "=";
314 writeStringList(t,m_value);
318 void ConfigEnum::writeTemplate(FTextStream &t,bool sl,bool)
323 t << convertToComment(m_doc, m_userComment);
326 else if (!m_userComment.isEmpty())
328 t << convertToComment("", m_userComment);
330 t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) << "=";
331 writeStringValue(t,m_value);
335 void ConfigString::writeTemplate(FTextStream &t,bool sl,bool)
340 t << convertToComment(m_doc, m_userComment);
343 else if (!m_userComment.isEmpty())
345 t << convertToComment("", m_userComment);
347 t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) << "=";
348 writeStringValue(t,m_value);
352 void ConfigInt::writeTemplate(FTextStream &t,bool sl,bool upd)
357 t << convertToComment(m_doc, m_userComment);
360 else if (!m_userComment.isEmpty())
362 t << convertToComment("", m_userComment);
364 t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) << "=";
365 if (upd && !m_valueString.isEmpty())
367 writeStringValue(t,m_valueString);
371 writeIntValue(t,m_value);
376 void ConfigBool::writeTemplate(FTextStream &t,bool sl,bool upd)
381 t << convertToComment(m_doc, m_userComment);
384 else if (!m_userComment.isEmpty())
386 t << convertToComment("", m_userComment);
388 t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) << "=";
389 if (upd && !m_valueString.isEmpty())
391 writeStringValue(t,m_valueString);
395 writeBoolValue(t,m_value);
400 void ConfigObsolete::writeTemplate(FTextStream &,bool,bool) {}
401 void ConfigDisabled::writeTemplate(FTextStream &,bool,bool) {}
403 /* -----------------------------------------------------------------
408 struct ConfigFileState
412 YY_BUFFER_STATE oldState;
413 YY_BUFFER_STATE newState;
417 static const char *inputString;
418 static int inputPosition;
420 static QCString yyFileName;
421 static QCString tmpString;
422 static QCString *s=0;
424 static QStrList *l=0;
425 static int lastState;
426 static QCString elemStr;
427 static QStrList includePathList;
428 static QStack<ConfigFileState> includeStack;
429 static int includeDepth;
430 static bool config_upd = FALSE;
431 static QCString encoding;
432 static ConfigImpl *config;
434 /* -----------------------------------------------------------------
437 #define YY_INPUT(buf,result,max_size) result=yyread(buf,max_size);
439 static int yyread(char *buf,int max_size)
442 if (includeStack.isEmpty())
445 if (inputString==0) return c;
446 while( c < max_size && inputString[inputPosition] )
448 *buf = inputString[inputPosition++] ;
455 //assert(includeStack.current()->newState==YY_CURRENT_BUFFER);
456 return (int)fread(buf,1,max_size,includeStack.current()->filePtr);
461 static QCString configStringRecode(
463 const char *fromEncoding,
464 const char *toEncoding)
466 QCString inputEncoding = fromEncoding;
467 QCString outputEncoding = toEncoding;
468 if (inputEncoding.isEmpty() || outputEncoding.isEmpty() || inputEncoding==outputEncoding) return str;
469 int inputSize=str.length();
470 int outputSize=inputSize*4+1;
471 QCString output(outputSize);
472 void *cd = portable_iconv_open(outputEncoding,inputEncoding);
473 if (cd==(void *)(-1))
475 fprintf(stderr,"Error: unsupported character conversion: '%s'->'%s'\n",
476 inputEncoding.data(),outputEncoding.data());
479 size_t iLeft=(size_t)inputSize;
480 size_t oLeft=(size_t)outputSize;
481 char *inputPtr = str.rawData();
482 char *outputPtr = output.rawData();
483 if (!portable_iconv(cd, &inputPtr, &iLeft, &outputPtr, &oLeft))
485 outputSize-=(int)oLeft;
486 output.resize(outputSize+1);
487 output.at(outputSize)='\0';
488 //printf("iconv: input size=%d output size=%d\n[%s]\n",size,newSize,srcBuf.data());
492 fprintf(stderr,"Error: failed to translate characters from %s to %s: %s\n",
493 inputEncoding.data(),outputEncoding.data(),strerror(errno));
496 portable_iconv_close(cd);
500 static void checkEncoding()
502 ConfigString *option = (ConfigString*)config->get("DOXYFILE_ENCODING");
503 encoding = *option->valueRef();
506 static FILE *tryPath(const char *path,const char *fileName)
508 QCString absName=(path ? (QCString)path+"/"+fileName : (QCString)fileName);
509 QFileInfo fi(absName);
510 if (fi.exists() && fi.isFile())
512 FILE *f=portable_fopen(absName,"r");
513 if (!f) config_err("could not open file %s for reading\n",absName.data());
519 static void substEnvVarsInStrList(QStrList &sl);
520 static void substEnvVarsInString(QCString &s);
522 static FILE *findFile(const char *fileName)
528 if (portable_isAbsolutePath(fileName))
530 return tryPath(NULL, fileName);
532 substEnvVarsInStrList(includePathList);
533 char *s=includePathList.first();
534 while (s) // try each of the include paths
536 FILE *f = tryPath(s,fileName);
538 s=includePathList.next();
540 // try cwd if includePathList fails
541 return tryPath(".",fileName);
544 static void readIncludeFile(const char *incName)
546 if (includeDepth==MAX_INCLUDE_DEPTH) {
547 config_err("maximum include depth (%d) reached, %s is not included. Aborting...\n",
548 MAX_INCLUDE_DEPTH,incName);
552 QCString inc = incName;
553 substEnvVarsInString(inc);
554 inc = inc.stripWhiteSpace();
555 uint incLen = inc.length();
556 if (incLen>0 && inc.at(0)=='"' && inc.at(incLen-1)=='"') // strip quotes
558 inc=inc.mid(1,incLen-2);
563 if ((f=findFile(inc))) // see if the include file can be found
567 for (i=0;i<includeStack.count();i++) msg(" ");
568 msg("@INCLUDE = %s: parsing...\n",inc.data());
571 // store the state of the old file
572 ConfigFileState *fs=new ConfigFileState;
573 fs->oldState=YY_CURRENT_BUFFER;
575 fs->fileName=yyFileName;
577 // push the state on the stack
578 includeStack.push(fs);
579 // set the scanner to the include file
580 yy_switch_to_buffer(yy_create_buffer(f, YY_BUF_SIZE));
581 fs->newState=YY_CURRENT_BUFFER;
587 config_err("@INCLUDE = %s: not found!\n",inc.data());
611 <PreStart>"##".*"\n" { config->appendStartComment(yytext);}
616 <Start,GetString,GetStrList,GetBool,SkipInvalid>"##".*"\n" { config->appendUserComment(yytext);}
617 <Start,GetString,GetStrList,GetBool,SkipInvalid>"#" { BEGIN(SkipComment); }
618 <Start>[a-z_A-Z][a-z_A-Z0-9]*[ \t]*"=" { QCString cmd=yytext;
619 cmd=cmd.left(cmd.length()-1).stripWhiteSpace();
620 ConfigOption *option = config->get(cmd);
621 if (option==0) // oops not known
623 config_warn("ignoring unsupported tag `%s' at line %d, file %s\n",
624 yytext,yyLineNr,yyFileName.data());
629 option->setUserComment(config->takeUserComment());
630 option->setEncoding(encoding);
631 switch(option->kind())
633 case ConfigOption::O_Info:
634 // shouldn't get here!
637 case ConfigOption::O_List:
638 l = ((ConfigList *)option)->valueRef();
643 case ConfigOption::O_Enum:
644 s = ((ConfigEnum *)option)->valueRef();
648 case ConfigOption::O_String:
649 s = ((ConfigString *)option)->valueRef();
653 case ConfigOption::O_Int:
654 s = ((ConfigInt *)option)->valueStringRef();
658 case ConfigOption::O_Bool:
659 s = ((ConfigBool *)option)->valueStringRef();
663 case ConfigOption::O_Obsolete:
666 config_warn("Tag `%s' at line %d of file `%s' has become obsolete.\n"
667 " This tag has been removed.\n", cmd.data(),yyLineNr,yyFileName.data());
671 config_warn("Tag `%s' at line %d of file `%s' has become obsolete.\n"
672 " To avoid this warning please remove this line from your configuration "
673 "file or upgrade it using \"doxygen -u\"\n", cmd.data(),yyLineNr,yyFileName.data());
677 case ConfigOption::O_Disabled:
680 config_warn("Tag `%s' at line %d of file `%s' belongs to an option that was not enabled at compile time.\n"
681 " This tag has been removed.\n", cmd.data(),yyLineNr,yyFileName.data());
685 config_warn("Tag `%s' at line %d of file `%s' belongs to an option that was not enabled at compile time.\n"
686 " To avoid this warning please remove this line from your configuration "
687 "file or upgrade it using \"doxygen -u\", or recompile doxygen with this feature enabled.\n", cmd.data(),yyLineNr,yyFileName.data());
694 <Start>[a-z_A-Z][a-z_A-Z0-9]*[ \t]*"+=" { QCString cmd=yytext;
695 cmd=cmd.left(cmd.length()-2).stripWhiteSpace();
696 ConfigOption *option = config->get(cmd);
697 if (option==0) // oops not known
699 config_warn("ignoring unsupported tag `%s' at line %d, file %s\n",
700 yytext,yyLineNr,yyFileName.data());
705 option->setUserComment(config->takeUserComment());
706 switch(option->kind())
708 case ConfigOption::O_Info:
709 // shouldn't get here!
712 case ConfigOption::O_List:
713 l = ((ConfigList *)option)->valueRef();
717 case ConfigOption::O_Enum:
718 case ConfigOption::O_String:
719 case ConfigOption::O_Int:
720 case ConfigOption::O_Bool:
721 config_warn("operator += not supported for `%s'. Ignoring line at line %d, file %s\n",
722 yytext,yyLineNr,yyFileName.data());
725 case ConfigOption::O_Obsolete:
726 config_warn("Tag `%s' at line %d of file %s has become obsolete.\n"
727 "To avoid this warning please update your configuration "
728 "file using \"doxygen -u\"\n", cmd.data(),yyLineNr,yyFileName.data());
731 case ConfigOption::O_Disabled:
732 config_warn("Tag `%s' at line %d of file %s belongs to an option that was not enabled at compile time.\n"
733 "To avoid this warning please remove this line from your configuration "
734 "file, upgrade it using \"doxygen -u\", or recompile doxygen with this feature enabled.\n", cmd.data(),yyLineNr,yyFileName.data());
740 <Start>"@INCLUDE_PATH"[ \t]*"=" { BEGIN(GetStrList); l=&includePathList; l->clear(); elemStr=""; }
741 /* include a config file */
742 <Start>"@INCLUDE"[ \t]*"=" { BEGIN(Include);}
743 <Include>([^ \"\t\r\n]+)|("\""[^\n\"]+"\"") {
744 readIncludeFile(configStringRecode(yytext,encoding,"UTF-8"));
748 //printf("End of include file\n");
749 //printf("Include stack depth=%d\n",g_includeStack.count());
750 if (includeStack.isEmpty())
752 //printf("Terminating scanner!\n");
757 ConfigFileState *fs=includeStack.pop();
759 YY_BUFFER_STATE oldBuf = YY_CURRENT_BUFFER;
760 yy_switch_to_buffer( fs->oldState );
761 yy_delete_buffer( oldBuf );
763 yyFileName=fs->fileName;
769 <Start>[a-z_A-Z0-9]+ { config_warn("ignoring unknown tag `%s' at line %d, file %s\n",yytext,yyLineNr,yyFileName.data()); }
770 <GetString,GetBool,SkipInvalid>\n { yyLineNr++; BEGIN(Start); }
773 if (!elemStr.isEmpty())
775 //printf("elemStr1=`%s'\n",elemStr.data());
781 if (!elemStr.isEmpty())
783 //printf("elemStr2=`%s'\n",elemStr.data());
788 <GetString>[^ \"\t\r\n]+ { (*s)+=configStringRecode(yytext,encoding,"UTF-8");
791 <GetString,GetStrList,SkipInvalid>"\"" { lastState=YY_START;
792 BEGIN(GetQuotedString);
795 <GetQuotedString>"\""|"\n" {
796 // we add a bogus space to signal that the string was quoted. This space will be stripped later on.
798 //printf("Quoted String = `%s'\n",tmpString.data());
799 if (lastState==GetString)
801 (*s)+=configStringRecode(tmpString,encoding,"UTF-8");
806 elemStr+=configStringRecode(tmpString,encoding,"UTF-8");
810 config_warn("Missing end quote (\") on line %d, file %s\n",yyLineNr,yyFileName.data());
815 <GetQuotedString>"\\\"" {
818 <GetQuotedString>. { tmpString+=*yytext; }
822 if (bs=="YES" || bs=="1")
824 else if (bs=="NO" || bs=="0")
829 config_warn("Invalid value `%s' for "
830 "boolean tag in line %d, file %s; use YES or NO\n",
831 bs.data(),yyLineNr,yyFileName.data());
834 <GetStrList>[^ \#\"\t\r\n]+ {
835 elemStr+=configStringRecode(yytext,encoding,"UTF-8");
837 <SkipComment>\n { yyLineNr++; BEGIN(Start); }
838 <SkipComment>\\[ \r\t]*\n { yyLineNr++; BEGIN(Start); }
839 <*>\\[ \r\t]*\n { yyLineNr++; }
841 <*>\n { yyLineNr++ ; }
845 /*@ ----------------------------------------------------------------------------
848 void ConfigImpl::writeTemplate(FTextStream &t,bool sl,bool upd)
850 /* print first lines of user comment that were at the beginning of the file, might have special meaning for editors */
853 t << takeStartComment() << endl;
855 t << "# Doxyfile " << versionString << endl << endl;
858 t << convertToComment(m_header,"");
860 QListIterator<ConfigOption> it = iterator();
861 ConfigOption *option;
862 for (;(option=it.current());++it)
864 option->writeTemplate(t,sl,upd);
866 /* print last lines of user comment that were at the end of the file */
870 t << takeUserComment();
874 void ConfigImpl::convertStrToVal()
876 QListIterator<ConfigOption> it = iterator();
877 ConfigOption *option;
878 for (;(option=it.current());++it)
880 option->convertStrToVal();
884 static void substEnvVarsInString(QCString &s)
886 static QRegExp re("\\$\\([a-z_A-Z0-9.-]+\\)");
887 static QRegExp re2("\\$\\([a-z_A-Z0-9.-]+\\([a-z_A-Z0-9.-]+\\)\\)"); // For e.g. PROGRAMFILES(X86)
888 if (s.isEmpty()) return;
891 //printf("substEnvVarInString(%s) start\n",s.data());
892 while ((i=re.match(s,p,&l))!=-1 || (i=re2.match(s,p,&l))!=-1)
894 //printf("Found environment var s.mid(%d,%d)=`%s'\n",i+2,l-3,s.mid(i+2,l-3).data());
895 QCString env=portable_getenv(s.mid(i+2,l-3));
896 substEnvVarsInString(env); // recursively expand variables if needed.
897 s = s.left(i)+env+s.right(s.length()-i-l);
898 p=i+env.length(); // next time start at the end of the expanded string
900 s=s.stripWhiteSpace(); // to strip the bogus space that was added when an argument
902 //printf("substEnvVarInString(%s) end\n",s.data());
905 static void substEnvVarsInStrList(QStrList &sl)
907 char *s = sl.first();
911 // an argument with quotes will have an extra space at the end, so wasQuoted will be TRUE.
912 bool wasQuoted = (result.find(' ')!=-1) || (result.find('\t')!=-1);
913 // here we strip the quote again
914 substEnvVarsInString(result);
916 //printf("Result %s was quoted=%d\n",result.data(),wasQuoted);
918 if (!wasQuoted) /* as a result of the expansion, a single string
919 may have expanded into a list, which we'll
920 add to sl. If the original string already
921 contained multiple elements no further
922 splitting is done to allow quoted items with spaces! */
924 int l=result.length();
927 // search for a "word"
931 // skip until start of new word
932 while (i<l && ((c=result.at(i))==' ' || c=='\t')) i++;
933 p=i; // p marks the start index of the word
934 // skip until end of a word
935 while (i<l && ((c=result.at(i))!=' ' && c!='\t' && c!='"')) i++;
936 if (i<l) // not at the end of the string
938 if (c=='"') // word within quotes
944 if (c=='"') // end quote
946 // replace the string in the list and go to the next item.
947 sl.insert(sl.at(),result.mid(p,i-p)); // insert new item before current item.
948 sl.next(); // current item is now the old item
952 else if (c=='\\') // skip escaped stuff
958 else if (c==' ' || c=='\t') // separator
960 // replace the string in the list and go to the next item.
961 sl.insert(sl.at(),result.mid(p,i-p)); // insert new item before current item.
962 sl.next(); // current item is now the old item
967 if (p!=l) // add the leftover as a string
969 // replace the string in the list and go to the next item.
970 sl.insert(sl.at(),result.right(l-p)); // insert new item before current item.
971 sl.next(); // current item is now the old item
974 else // just goto the next element in the list
976 sl.insert(sl.at(),result);
979 // remove the old unexpanded string from the list
981 sl.remove(); // current item index changes if the last element is removed.
982 if (sl.at()==i) // not last item
984 else // just removed last item
989 void ConfigString::substEnvVars()
991 substEnvVarsInString(m_value);
994 void ConfigList::substEnvVars()
996 substEnvVarsInStrList(m_value);
999 void ConfigBool::substEnvVars()
1001 substEnvVarsInString(m_valueString);
1004 void ConfigInt::substEnvVars()
1006 substEnvVarsInString(m_valueString);
1009 void ConfigEnum::substEnvVars()
1011 substEnvVarsInString(m_value);
1014 //---------------------------------------------
1016 void ConfigImpl::substituteEnvironmentVars()
1018 QListIterator<ConfigOption> it = iterator();
1019 ConfigOption *option;
1020 for (;(option=it.current());++it)
1022 option->substEnvVars();
1026 void ConfigImpl::init()
1028 QListIterator<ConfigOption> it = iterator();
1029 ConfigOption *option;
1030 for (;(option=it.current());++it)
1035 // sanity check if all depends relations are valid
1036 for (it.toFirst();(option=it.current());++it)
1038 QCString depName = option->dependsOn();
1039 if (!depName.isEmpty())
1041 ConfigOption * opt = ConfigImpl::instance()->get(depName);
1044 config_warn("Config option '%s' has invalid depends relation on unknown option '%s'\n",
1045 option->name().data(),depName.data());
1052 void ConfigImpl::create()
1054 if (m_initialized) return;
1055 m_initialized = TRUE;
1056 addConfigOptions(this);
1059 static QCString configFileToString(const char *name)
1061 if (name==0 || name[0]==0) return 0;
1064 bool fileOpened=FALSE;
1065 if (name[0]=='-' && name[1]==0) // read from stdin
1067 fileOpened=f.open(IO_ReadOnly,stdin);
1070 const int bSize=4096;
1071 QCString contents(bSize);
1074 while ((size=f.readBlock(contents.rawData()+totalSize,bSize))==bSize)
1077 contents.resize(totalSize+bSize);
1080 contents.resize(totalSize);
1081 contents.at(totalSize-2)='\n'; // to help the scanner
1082 contents.at(totalSize-1)='\0';
1086 else // read from file
1089 if (!fi.exists() || !fi.isFile())
1091 config_err("file `%s' not found\n",name);
1095 fileOpened=f.open(IO_ReadOnly);
1099 QCString contents(fsize+2);
1100 f.readBlock(contents.rawData(),fsize);
1102 if (fsize==0 || contents[fsize-1]=='\n')
1103 contents[fsize]='\0';
1105 contents[fsize]='\n'; // to help the scanner
1106 contents[fsize+1]='\0';
1112 config_err("cannot open file `%s' for reading\n",name);
1118 bool ConfigImpl::parseString(const char *fn,const char *str,bool update)
1120 config = ConfigImpl::instance();
1125 includeStack.setAutoDelete(TRUE);
1126 includeStack.clear();
1128 configimplYYrestart( configimplYYin );
1130 config_upd = update;
1137 bool ConfigImpl::parse(const char *fn,bool update)
1141 printlex(yy_flex_debug, TRUE, __FILE__, fn);
1142 retval = parseString(fn,configFileToString(fn), update);
1143 printlex(yy_flex_debug, FALSE, __FILE__, fn);
1147 //----------------------------------------------------------------------
1149 static void cleanUpPaths(QStrList &str)
1151 char *sfp = str.first();
1154 register char *p = sfp;
1160 if (c=='\\') *p='/';
1164 QCString path = sfp;
1165 if ((path.at(0)!='/' && (path.length()<=2 || path.at(1)!=':')) ||
1166 path.at(path.length()-1)!='/'
1170 if (fi.exists() && fi.isDir())
1173 QString p = fi.absFilePath();
1174 if (p.at(p.length()-1)!='/')
1177 if (str.at()==i) // did not remove last item
1178 str.insert(i,p.utf8());
1180 str.append(p.utf8());
1187 static void checkFileName(QCString &s,const char *optionName)
1189 QCString val = s.stripWhiteSpace().lower();
1190 if ((val=="yes" || val=="true" || val=="1" || val=="all") ||
1191 (val=="no" || val=="false" || val=="0" || val=="none"))
1193 err("file name expected for option %s, got %s instead. Ignoring...\n",optionName,s.data());
1194 s=""; // note the use of &s above: this will change the option value!
1202 ConfigImpl::instance()->init();
1205 void Config::checkAndCorrect()
1207 QCString &warnFormat = ConfigImpl_getString("WARN_FORMAT");
1208 if (warnFormat.stripWhiteSpace().isEmpty())
1210 warnFormat="$file:$line $text";
1214 if (warnFormat.find("$file")==-1)
1216 warn_uncond("warning format does not contain a $file tag!\n");
1219 if (warnFormat.find("$line")==-1)
1221 warn_uncond("warning format does not contain a $line tag!\n");
1223 if (warnFormat.find("$text")==-1)
1225 warn_uncond("warning format foes not contain a $text tag!\n");
1229 QCString &manExtension = ConfigImpl_getString("MAN_EXTENSION");
1231 // set default man page extension if non is given by the user
1232 if (manExtension.isEmpty())
1237 QCString &paperType = ConfigImpl_getEnum("PAPER_TYPE");
1238 paperType=paperType.lower().stripWhiteSpace();
1239 if (paperType.isEmpty() || paperType=="a4wide")
1243 if (paperType!="a4" && paperType!="letter" &&
1244 paperType!="legal" && paperType!="executive")
1246 err("Unknown page type specified\n");
1250 QCString &outputLanguage=ConfigImpl_getEnum("OUTPUT_LANGUAGE");
1251 outputLanguage=outputLanguage.stripWhiteSpace();
1252 if (outputLanguage.isEmpty())
1254 outputLanguage = "English";
1257 QCString &htmlFileExtension=ConfigImpl_getString("HTML_FILE_EXTENSION");
1258 htmlFileExtension=htmlFileExtension.stripWhiteSpace();
1259 if (htmlFileExtension.isEmpty())
1261 htmlFileExtension = ".html";
1264 // expand the relative stripFromPath values
1265 QStrList &stripFromPath = ConfigImpl_getList("STRIP_FROM_PATH");
1266 char *sfp = stripFromPath.first();
1267 if (sfp==0) // by default use the current path
1269 QString p = QDir::currentDirPath();
1270 if (p.at(p.length()-1)!='/')
1272 stripFromPath.append(p.utf8());
1276 cleanUpPaths(stripFromPath);
1279 // expand the relative stripFromPath values
1280 QStrList &stripFromIncPath = ConfigImpl_getList("STRIP_FROM_INC_PATH");
1281 cleanUpPaths(stripFromIncPath);
1283 // Test to see if HTML header is valid
1284 QCString &headerFile = ConfigImpl_getString("HTML_HEADER");
1285 if (!headerFile.isEmpty())
1287 QFileInfo fi(headerFile);
1290 err("tag HTML_HEADER: header file `%s' "
1291 "does not exist\n",headerFile.data());
1295 // Test to see if HTML footer is valid
1296 QCString &footerFile = ConfigImpl_getString("HTML_FOOTER");
1297 if (!footerFile.isEmpty())
1299 QFileInfo fi(footerFile);
1302 err("tag HTML_FOOTER: footer file `%s' "
1303 "does not exist\n",footerFile.data());
1308 // Test to see if MathJax code file is valid
1309 if (ConfigImpl_getBool("USE_MATHJAX"))
1311 QCString &MathJaxCodefile = ConfigImpl_getString("MATHJAX_CODEFILE");
1312 if (!MathJaxCodefile.isEmpty())
1314 QFileInfo fi(MathJaxCodefile);
1317 err("tag MATHJAX_CODEFILE file `%s' "
1318 "does not exist\n",MathJaxCodefile.data());
1322 QCString &path = ConfigImpl_getString("MATHJAX_RELPATH");
1323 if (!path.isEmpty() && path.at(path.length()-1)!='/')
1330 // Test to see if LaTeX header is valid
1331 QCString &latexHeaderFile = ConfigImpl_getString("LATEX_HEADER");
1332 if (!latexHeaderFile.isEmpty())
1334 QFileInfo fi(latexHeaderFile);
1337 err("tag LATEX_HEADER: header file `%s' "
1338 "does not exist\n",latexHeaderFile.data());
1342 // Test to see if LaTeX footer is valid
1343 QCString &latexFooterFile = ConfigImpl_getString("LATEX_FOOTER");
1344 if (!latexFooterFile.isEmpty())
1346 QFileInfo fi(latexFooterFile);
1349 err("tag LATEX_FOOTER: footer file `%s' "
1350 "does not exist\n",latexFooterFile.data());
1355 // check include path
1356 QStrList &includePath = ConfigImpl_getList("INCLUDE_PATH");
1357 char *s=includePath.first();
1361 if (!fi.exists()) warn_uncond("tag INCLUDE_PATH: include path `%s' "
1362 "does not exist\n",s);
1363 s=includePath.next();
1367 QStrList &aliasList = ConfigImpl_getList("ALIASES");
1368 s=aliasList.first();
1371 QRegExp re1("[a-z_A-Z][a-z_A-Z0-9]*[ \t]*="); // alias without argument
1372 QRegExp re2("[a-z_A-Z][a-z_A-Z0-9]*{[0-9]*}[ \t]*="); // alias with argument
1374 alias=alias.stripWhiteSpace();
1375 if (alias.find(re1)!=0 && alias.find(re2)!=0)
1377 err("Illegal alias format `%s'. Use \"name=value\" or \"name(n)=value\", where n is the number of arguments\n",
1383 // check if GENERATE_TREEVIEW and GENERATE_HTMLHELP are both enabled
1384 if (ConfigImpl_getBool("GENERATE_TREEVIEW") && ConfigImpl_getBool("GENERATE_HTMLHELP"))
1386 err("When enabling GENERATE_HTMLHELP the tree view (GENERATE_TREEVIEW) should be disabled. I'll do it for you.\n");
1387 ConfigImpl_getBool("GENERATE_TREEVIEW")=FALSE;
1389 if (ConfigImpl_getBool("SEARCHENGINE") && ConfigImpl_getBool("GENERATE_HTMLHELP"))
1391 err("When enabling GENERATE_HTMLHELP the search engine (SEARCHENGINE) should be disabled. I'll do it for you.\n");
1392 ConfigImpl_getBool("SEARCHENGINE")=FALSE;
1395 // check if SEPARATE_MEMBER_PAGES and INLINE_GROUPED_CLASSES are both enabled
1396 if (ConfigImpl_getBool("SEPARATE_MEMBER_PAGES") && ConfigImpl_getBool("INLINE_GROUPED_CLASSES"))
1398 err("When enabling INLINE_GROUPED_CLASSES the SEPARATE_MEMBER_PAGES option should be disabled. I'll do it for you.\n");
1399 ConfigImpl_getBool("SEPARATE_MEMBER_PAGES")=FALSE;
1402 // check dot image format
1403 QCString &dotImageFormat=ConfigImpl_getEnum("DOT_IMAGE_FORMAT");
1404 dotImageFormat=dotImageFormat.stripWhiteSpace();
1405 if (dotImageFormat.isEmpty())
1407 dotImageFormat = "png";
1409 //else if (dotImageFormat!="gif" && dotImageFormat!="png" && dotImageFormat!="jpg")
1411 // err("Invalid value for DOT_IMAGE_FORMAT: `%s'. Using the default.\n",dotImageFormat.data());
1412 // dotImageFormat = "png";
1415 QCString &dotFontName=ConfigImpl_getString("DOT_FONTNAME");
1416 if (dotFontName=="FreeSans" || dotFontName=="FreeSans.ttf")
1418 warn_uncond("doxygen no longer ships with the FreeSans font.\n"
1419 "You may want to clear or change DOT_FONTNAME.\n"
1420 "Otherwise you run the risk that the wrong font is being used for dot generated graphs.\n");
1425 QCString &dotPath = ConfigImpl_getString("DOT_PATH");
1426 if (!dotPath.isEmpty())
1428 QFileInfo fi(dotPath);
1429 if (fi.exists() && fi.isFile()) // user specified path + exec
1431 dotPath=fi.dirPath(TRUE).utf8()+"/";
1435 QFileInfo dp(dotPath+"/dot"+portable_commandExtension());
1436 if (!dp.exists() || !dp.isFile())
1438 warn_uncond("the dot tool could not be found at %s\n",dotPath.data());
1443 dotPath=dp.dirPath(TRUE).utf8()+"/";
1446 #if defined(_WIN32) // convert slashes
1447 uint i=0,l=dotPath.length();
1448 for (i=0;i<l;i++) if (dotPath.at(i)=='/') dotPath.at(i)='\\';
1451 else // make sure the string is empty but not null!
1456 // check mscgen path
1457 QCString &mscgenPath = ConfigImpl_getString("MSCGEN_PATH");
1458 if (!mscgenPath.isEmpty())
1460 QFileInfo dp(mscgenPath+"/mscgen"+portable_commandExtension());
1461 if (!dp.exists() || !dp.isFile())
1463 warn_uncond("the mscgen tool could not be found at %s\n",mscgenPath.data());
1468 mscgenPath=dp.dirPath(TRUE).utf8()+"/";
1469 #if defined(_WIN32) // convert slashes
1470 uint i=0,l=mscgenPath.length();
1471 for (i=0;i<l;i++) if (mscgenPath.at(i)=='/') mscgenPath.at(i)='\\';
1475 else // make sure the string is empty but not null!
1480 // check plantuml path
1481 QCString &plantumlJarPath = ConfigImpl_getString("PLANTUML_JAR_PATH");
1482 if (!plantumlJarPath.isEmpty())
1484 QFileInfo pu(plantumlJarPath);
1485 if (pu.exists() && pu.isDir()) // PLANTUML_JAR_PATH is directory
1487 QFileInfo jar(plantumlJarPath+portable_pathSeparator()+"plantuml.jar");
1488 if (jar.exists() && jar.isFile())
1490 plantumlJarPath = jar.dirPath(TRUE).utf8()+portable_pathSeparator();
1494 err("Jar file plantuml.jar not found at location "
1495 "specified via PLANTUML_JAR_PATH: '%s'\n",plantumlJarPath.data());
1499 else if (pu.exists() && pu.isFile() && plantumlJarPath.right(4)==".jar") // PLANTUML_JAR_PATH is file
1501 plantumlJarPath = pu.dirPath(TRUE).utf8()+portable_pathSeparator();
1505 err("path specified via PLANTUML_JAR_PATH does not exist or not a directory: %s\n",
1506 plantumlJarPath.data());
1512 QCString &diaPath = ConfigImpl_getString("DIA_PATH");
1513 if (!diaPath.isEmpty())
1515 QFileInfo dp(diaPath+"/dia"+portable_commandExtension());
1516 if (!dp.exists() || !dp.isFile())
1518 warn_uncond("dia could not be found at %s\n",diaPath.data());
1523 diaPath=dp.dirPath(TRUE).utf8()+"/";
1524 #if defined(_WIN32) // convert slashes
1525 uint i=0,l=diaPath.length();
1526 for (i=0;i<l;i++) if (diaPath.at(i)=='/') diaPath.at(i)='\\';
1530 else // make sure the string is empty but not null!
1536 QStrList &inputSources=ConfigImpl_getList("INPUT");
1537 if (inputSources.count()==0)
1539 // use current dir as the default
1540 inputSources.append(QDir::currentDirPath().utf8());
1544 s=inputSources.first();
1550 warn_uncond("tag INPUT: input source `%s' does not exist\n",s);
1552 s=inputSources.next();
1556 // add default file patterns if needed
1557 QStrList &filePatternList = ConfigImpl_getList("FILE_PATTERNS");
1558 if (filePatternList.isEmpty())
1560 ConfigOption * opt = ConfigImpl::instance()->get("FILE_PATTERNS");
1561 if (opt->kind()==ConfigOption::O_List)
1563 ((ConfigList*)opt)->init();
1567 // add default pattern if needed
1568 QStrList &examplePatternList = ConfigImpl_getList("EXAMPLE_PATTERNS");
1569 if (examplePatternList.isEmpty())
1571 examplePatternList.append("*");
1574 // if no output format is enabled, warn the user
1575 if (!ConfigImpl_getBool("GENERATE_HTML") &&
1576 !ConfigImpl_getBool("GENERATE_LATEX") &&
1577 !ConfigImpl_getBool("GENERATE_MAN") &&
1578 !ConfigImpl_getBool("GENERATE_RTF") &&
1579 !ConfigImpl_getBool("GENERATE_XML") &&
1580 !ConfigImpl_getBool("GENERATE_PERLMOD") &&
1581 !ConfigImpl_getBool("GENERATE_RTF") &&
1582 !ConfigImpl_getBool("GENERATE_DOCBOOK") &&
1583 !ConfigImpl_getBool("GENERATE_AUTOGEN_DEF") &&
1584 ConfigImpl_getString("GENERATE_TAGFILE").isEmpty()
1587 warn_uncond("No output formats selected! Set at least one of the main GENERATE_* options to YES.\n");
1590 // check HTMLHELP creation requirements
1591 if (!ConfigImpl_getBool("GENERATE_HTML") &&
1592 ConfigImpl_getBool("GENERATE_HTMLHELP"))
1594 warn_uncond("GENERATE_HTMLHELP=YES requires GENERATE_HTML=YES.\n");
1597 // check QHP creation requirements
1598 if (ConfigImpl_getBool("GENERATE_QHP"))
1600 if (ConfigImpl_getString("QHP_NAMESPACE").isEmpty())
1602 err("GENERATE_QHP=YES requires QHP_NAMESPACE to be set. Using 'org.doxygen.doc' as default!.\n");
1603 ConfigImpl_getString("QHP_NAMESPACE")="org.doxygen.doc";
1606 if (ConfigImpl_getString("QHP_VIRTUAL_FOLDER").isEmpty())
1608 err("GENERATE_QHP=YES requires QHP_VIRTUAL_FOLDER to be set. Using 'doc' as default!\n");
1609 ConfigImpl_getString("QHP_VIRTUAL_FOLDER")="doc";
1613 if (ConfigImpl_getBool("OPTIMIZE_OUTPUT_JAVA") && ConfigImpl_getBool("INLINE_INFO"))
1615 // don't show inline info for Java output, since Java has no inline
1617 ConfigImpl_getBool("INLINE_INFO")=FALSE;
1620 int &depth = ConfigImpl_getInt("MAX_DOT_GRAPH_DEPTH");
1626 int &hue = ConfigImpl_getInt("HTML_COLORSTYLE_HUE");
1636 int &sat = ConfigImpl_getInt("HTML_COLORSTYLE_SAT");
1645 int &gamma = ConfigImpl_getInt("HTML_COLORSTYLE_GAMMA");
1655 QCString mathJaxFormat = ConfigImpl_getEnum("MATHJAX_FORMAT");
1656 if (!mathJaxFormat.isEmpty() && mathJaxFormat!="HTML-CSS" &&
1657 mathJaxFormat!="NativeMML" && mathJaxFormat!="SVG")
1659 err("Unsupported value for MATHJAX_FORMAT: Should be one of HTML-CSS, NativeMML, or SVG\n");
1660 ConfigImpl_getEnum("MATHJAX_FORMAT")="HTML-CSS";
1663 // add default words if needed
1664 QStrList &annotationFromBrief = ConfigImpl_getList("ABBREVIATE_BRIEF");
1665 if (annotationFromBrief.isEmpty())
1667 annotationFromBrief.append("The $name class");
1668 annotationFromBrief.append("The $name widget");
1669 annotationFromBrief.append("The $name file");
1670 annotationFromBrief.append("is");
1671 annotationFromBrief.append("provides");
1672 annotationFromBrief.append("specifies");
1673 annotationFromBrief.append("contains");
1674 annotationFromBrief.append("represents");
1675 annotationFromBrief.append("a");
1676 annotationFromBrief.append("an");
1677 annotationFromBrief.append("the");
1680 // some default settings for vhdl
1681 if (ConfigImpl_getBool("OPTIMIZE_OUTPUT_VHDL") &&
1682 (ConfigImpl_getBool("INLINE_INHERITED_MEMB") ||
1683 ConfigImpl_getBool("INHERIT_DOCS") ||
1684 !ConfigImpl_getBool("HIDE_SCOPE_NAMES") ||
1685 !ConfigImpl_getBool("EXTRACT_PRIVATE") ||
1686 !ConfigImpl_getBool("EXTRACT_PACKAGE")
1690 bool b1 = ConfigImpl_getBool("INLINE_INHERITED_MEMB");
1691 bool b2 = ConfigImpl_getBool("INHERIT_DOCS");
1692 bool b3 = ConfigImpl_getBool("HIDE_SCOPE_NAMES");
1693 bool b4 = ConfigImpl_getBool("EXTRACT_PRIVATE");
1694 bool b5 = ConfigImpl_getBool("SKIP_FUNCTION_MACROS");
1695 bool b6 = ConfigImpl_getBool("EXTRACT_PACKAGE");
1696 const char *s1,*s2,*s3,*s4,*s5,*s6;
1697 if (b1) s1=" INLINE_INHERITED_MEMB = NO (was YES)\n"; else s1="";
1698 if (b2) s2=" INHERIT_DOCS = NO (was YES)\n"; else s2="";
1699 if (!b3) s3=" HIDE_SCOPE_NAMES = YES (was NO)\n"; else s3="";
1700 if (!b4) s4=" EXTRACT_PRIVATE = YES (was NO)\n"; else s4="";
1701 if (b5) s5=" ENABLE_PREPROCESSING = NO (was YES)\n"; else s5="";
1702 if (!b6) s6=" EXTRACT_PACKAGE = YES (was NO)\n"; else s6="";
1705 warn_uncond("enabling OPTIMIZE_OUTPUT_VHDL assumes the following settings:\n"
1706 "%s%s%s%s%s%s",s1,s2,s3,s4,s5,s6
1709 ConfigImpl_getBool("INLINE_INHERITED_MEMB") = FALSE;
1710 ConfigImpl_getBool("INHERIT_DOCS") = FALSE;
1711 ConfigImpl_getBool("HIDE_SCOPE_NAMES") = TRUE;
1712 ConfigImpl_getBool("EXTRACT_PRIVATE") = TRUE;
1713 ConfigImpl_getBool("ENABLE_PREPROCESSING") = FALSE;
1714 ConfigImpl_getBool("EXTRACT_PACKAGE") = TRUE;
1717 checkFileName(ConfigImpl_getString("GENERATE_TAGFILE"),"GENERATE_TAGFILE");
1719 #if 0 // TODO: this breaks test 25; SOURCEBROWSER = NO and SOURCE_TOOLTIPS = YES.
1720 // So this and other regressions should be analysed and fixed before this can be enabled
1721 // disable any boolean options that depend on disabled options
1722 QListIterator<ConfigOption> it = iterator();
1723 ConfigOption *option;
1724 for (it.toFirst();(option=it.current());++it)
1726 QCString depName = option->dependsOn(); // option has a dependency
1727 if (!depName.isEmpty())
1729 ConfigOption * dep = Config::instance()->get(depName);
1730 if (dep->kind()==ConfigOption::O_Bool &&
1731 ConfigImpl_getBool("depName")==FALSE) // dependent option is disabled
1733 if (option->kind()==ConfigOption::O_Bool)
1735 printf("disabling option %s\n",option->name().data());
1736 ConfigImpl_getBool("option->name("))=FALSE; // also disable this option
1743 ConfigValues::instance().init();
1747 void Config::writeTemplate(FTextStream &t,bool shortList,bool update)
1749 ConfigImpl::instance()->writeTemplate(t,shortList,update);
1752 bool Config::parse(const char *fileName,bool update)
1754 return ConfigImpl::instance()->parse(fileName,update);
1757 void Config::postProcess(bool clearHeaderAndFooter)
1759 ConfigImpl::instance()->substituteEnvironmentVars();
1760 ConfigImpl::instance()->convertStrToVal();
1762 // avoid bootstrapping issues when the config file already
1763 // refers to the files that we are supposed to parse.
1764 if (clearHeaderAndFooter)
1766 ConfigImpl_getString("HTML_HEADER")="";
1767 ConfigImpl_getString("HTML_FOOTER")="";
1768 ConfigImpl_getString("LATEX_HEADER")="";
1769 ConfigImpl_getString("LATEX_FOOTER")="";
1773 void Config::deinit()
1775 ConfigImpl::instance()->deleteInstance();