133bc111fc1c6b4f61192b4543fdb38d5c31512f
[platform/upstream/doxygen.git] / src / config.l
1 /******************************************************************************
2  *
3  * Copyright (C) 1997-2014 by Dimitri van Heesch.
4  *
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.
10  *
11  */
12
13 %{
14
15 /*
16  *      includes
17  */
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <assert.h>
21 #include <ctype.h>
22 #include <stdarg.h>
23 #include <errno.h>
24
25 #include <qfileinfo.h>
26 #include <qdir.h>
27 #include <qtextstream.h>
28 #include <qregexp.h>
29 #include <qstack.h>
30 #include <qglobal.h>
31   
32 #include "config.h"
33 #include "version.h"
34 #include "portable.h"
35 #include "util.h"
36 #include "message.h"
37
38 #include "lang_cfg.h"
39 #include "configoptions.h"
40
41 #undef Config_getString
42 #undef Config_getInt
43 #undef Config_getList
44 #undef Config_getEnum
45 #undef Config_getBool
46
47 #define YY_NO_INPUT 1
48
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)
55   
56 void config_err(const char *fmt, ...)
57 {
58   va_list args;
59   va_start(args, fmt);
60   vfprintf(stderr, fmt, args);
61   va_end(args); 
62 }
63 void config_warn(const char *fmt, ...)
64 {
65   va_list args;
66   va_start(args, fmt);
67   vfprintf(stderr, fmt, args);
68   va_end(args);
69 }
70
71 static QCString configStringRecode(
72     const QCString &str,
73     const char *fromEncoding,
74     const char *toEncoding);
75
76 #define MAX_INCLUDE_DEPTH 10
77 #define YY_NEVER_INTERACTIVE 1
78
79 /* -----------------------------------------------------------------
80  */
81 static QCString convertToComment(const QCString &s, const QCString &u)
82 {
83   //printf("convertToComment(%s)=%s\n",s.data(),u.data());
84   QCString result;
85   if (!s.isEmpty())
86   {
87     QCString tmp=s.stripWhiteSpace();
88     char *p=tmp.data();
89     char c;
90     result+="#";
91     if (*p && *p!='\n')
92       result+=" ";
93     while ((c=*p++))
94     {
95       if (c=='\n')
96       {
97         result+="\n#";
98         if (*p && *p!='\n')
99           result+=" ";
100       }
101       else result+=c;
102     }
103     result+='\n';
104   }
105   if (!u.isEmpty())
106   {
107     if (!result.isEmpty()) result+='\n';
108     result+= u;
109   }
110   return result;
111 }
112
113 void ConfigOption::writeBoolValue(FTextStream &t,bool v)
114 {
115   t << " ";
116   if (v) t << "YES"; else t << "NO";
117 }
118
119 void ConfigOption::writeIntValue(FTextStream &t,int i)
120 {
121   t << " " << i;
122 }
123
124 void ConfigOption::writeStringValue(FTextStream &t,QCString &s)
125 {
126   char c;
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();
131   if (p)
132   {
133     t << " ";
134     while ((c=*p++)!=0 && !needsEscaping) 
135       needsEscaping = (c==' ' || c=='\n' || c=='\t' || c=='"' || c=='#');
136     if (needsEscaping)
137     { 
138       t << "\"";
139       p=se.data();
140       while (*p)
141       {
142         if (*p==' ' && *(p+1)=='\0') break; // skip inserted space at the end
143         if (*p=='"') t << "\\"; // escape quotes
144         t << *p++;
145       }
146       t << "\"";
147     }
148     else
149     {
150       t << se;
151     }
152   }
153 }
154
155 void ConfigOption::writeStringList(FTextStream &t,QStrList &l)
156 {
157   const char *p = l.first();
158   bool first=TRUE;
159   while (p)
160   {
161     QCString s=p;
162     if (!first)
163       t << "                        ";
164     first=FALSE;
165     writeStringValue(t,s);
166     p = l.next();
167     if (p) t << " \\" << endl;
168   }
169 }
170
171 /* -----------------------------------------------------------------
172  */
173
174 Config *Config::m_instance = 0;
175
176 void ConfigInt::convertStrToVal() 
177 {
178   if (!m_valueString.isEmpty())
179   {
180     bool ok;
181     int val = m_valueString.toInt(&ok);
182     if (!ok || val<m_minVal || val>m_maxVal)
183     {
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);
186     }
187     else
188     {
189       m_value=val;
190     }
191   }
192 }
193
194 void ConfigBool::convertStrToVal()
195 {
196   QCString val = m_valueString.stripWhiteSpace().lower();
197   if (!val.isEmpty())
198   {
199     if (val=="yes" || val=="true" || val=="1" || val=="all") 
200     {
201       m_value=TRUE;
202     }
203     else if (val=="no" || val=="false" || val=="0" || val=="none")
204     {
205       m_value=FALSE;
206     }
207     else
208     {
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");
211     }
212   }
213 }
214
215 QCString &Config::getString(const char *fileName,int num,const char *name) const
216 {
217   ConfigOption *opt = m_dict->find(name);
218   if (opt==0) 
219   {
220     config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
221     exit(1);
222   }
223   else if (opt->kind()!=ConfigOption::O_String)
224   {
225     config_err("%s<%d>: Internal error: Requested option %s not of string type!\n",fileName,num,name);
226     exit(1);
227   }
228   return *((ConfigString *)opt)->valueRef();
229 }
230
231 QStrList &Config::getList(const char *fileName,int num,const char *name) const
232 {
233   ConfigOption *opt = m_dict->find(name);
234   if (opt==0) 
235   {
236     config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
237     exit(1);
238   }
239   else if (opt->kind()!=ConfigOption::O_List)
240   {
241     config_err("%d<%d>: Internal error: Requested option %s not of list type!\n",fileName,num,name);
242     exit(1);
243   }
244   return *((ConfigList *)opt)->valueRef();
245 }
246
247 QCString &Config::getEnum(const char *fileName,int num,const char *name) const
248 {
249   ConfigOption *opt = m_dict->find(name);
250   if (opt==0) 
251   {
252     config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
253     exit(1);
254   }
255   else if (opt->kind()!=ConfigOption::O_Enum)
256   {
257     config_err("%s<%d>: Internal error: Requested option %s not of enum type!\n",fileName,num,name);
258     exit(1);
259   }
260   return *((ConfigEnum *)opt)->valueRef();
261 }
262
263 int &Config::getInt(const char *fileName,int num,const char *name) const
264 {
265   ConfigOption *opt = m_dict->find(name);
266   if (opt==0) 
267   {
268     config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
269     exit(1);
270   }
271   else if (opt->kind()!=ConfigOption::O_Int)
272   {
273     config_err("%s<%d>: Internal error: Requested option %s not of integer type!\n",fileName,num,name);
274     exit(1);
275   }
276   return *((ConfigInt *)opt)->valueRef();
277 }
278
279 bool &Config::getBool(const char *fileName,int num,const char *name) const
280 {
281   ConfigOption *opt = m_dict->find(name);
282   if (opt==0) 
283   {
284     config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
285     exit(1);
286   }
287   else if (opt->kind()!=ConfigOption::O_Bool)
288   {
289     config_err("%s<%d>: Internal error: Requested option %s not of boolean type!\n",fileName,num,name);
290     exit(1);
291   }
292   return *((ConfigBool *)opt)->valueRef();
293 }
294
295 /* ------------------------------------------ */
296
297 void ConfigInfo::writeTemplate(FTextStream &t, bool sl,bool)
298 {
299   if (!sl)
300   {
301     t << "\n";
302   }
303   t << "#---------------------------------------------------------------------------\n";
304   t << "# " << m_doc << endl;
305   t << "#---------------------------------------------------------------------------\n";
306 }
307
308 void ConfigList::writeTemplate(FTextStream &t,bool sl,bool)
309 {
310   if (!sl)
311   {
312     t << endl;
313     t << convertToComment(m_doc, m_userComment);
314     t << endl;
315   }
316   else if (!m_userComment.isEmpty())
317   {
318     t << convertToComment("", m_userComment);
319   }
320   t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) << "=";
321   writeStringList(t,m_value);
322   t << "\n";
323 }
324
325 void ConfigEnum::writeTemplate(FTextStream &t,bool sl,bool)
326 {
327   if (!sl)
328   {
329     t << endl;
330     t << convertToComment(m_doc, m_userComment);
331     t << endl;
332   }
333   else if (!m_userComment.isEmpty())
334   {
335     t << convertToComment("", m_userComment);
336   }
337   t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) << "=";
338   writeStringValue(t,m_value);
339   t << "\n";
340 }
341
342 void ConfigString::writeTemplate(FTextStream &t,bool sl,bool)
343 {
344   if (!sl)
345   {
346     t << endl;
347     t << convertToComment(m_doc, m_userComment);
348     t << endl;
349   }
350   else if (!m_userComment.isEmpty())
351   {
352     t << convertToComment("", m_userComment);
353   }
354   t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) << "=";
355   writeStringValue(t,m_value);
356   t << "\n";
357 }
358
359 void ConfigInt::writeTemplate(FTextStream &t,bool sl,bool upd)
360 {
361   if (!sl)
362   {
363     t << endl;
364     t << convertToComment(m_doc, m_userComment);
365     t << endl;
366   }
367   else if (!m_userComment.isEmpty())
368   {
369     t << convertToComment("", m_userComment);
370   }
371   t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) << "=";
372   if (upd && !m_valueString.isEmpty())
373   {
374     writeStringValue(t,m_valueString);
375   }
376   else
377   {
378     writeIntValue(t,m_value);
379   }
380   t << "\n";
381 }
382
383 void ConfigBool::writeTemplate(FTextStream &t,bool sl,bool upd)
384 {
385   if (!sl)
386   {
387     t << endl;
388     t << convertToComment(m_doc, m_userComment);
389     t << endl;
390   }
391   else if (!m_userComment.isEmpty())
392   {
393     t << convertToComment("", m_userComment);
394   }
395   t << m_name << m_spaces.left(MAX_OPTION_LENGTH-m_name.length()) << "=";
396   if (upd && !m_valueString.isEmpty())
397   {
398     writeStringValue(t,m_valueString);
399   }
400   else
401   {
402     writeBoolValue(t,m_value);
403   }
404   t << "\n";
405 }
406
407 void ConfigObsolete::writeTemplate(FTextStream &,bool,bool) {}
408 void ConfigDisabled::writeTemplate(FTextStream &,bool,bool) {}
409
410 /* -----------------------------------------------------------------
411  *
412  *      static variables
413  */
414
415 struct ConfigFileState
416 {
417   int lineNr;
418   FILE *filePtr;
419   YY_BUFFER_STATE oldState;
420   YY_BUFFER_STATE newState;
421   QCString fileName;
422 };  
423
424 static const char       *inputString;
425 static int               inputPosition;
426 static int               yyLineNr;
427 static QCString          yyFileName;
428 static QCString          tmpString;
429 static QCString         *s=0;
430 static bool             *b=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;
439
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;
448
449 static Config      *config;
450
451 /* -----------------------------------------------------------------
452  */
453 #undef  YY_INPUT
454 #define YY_INPUT(buf,result,max_size) result=yyread(buf,max_size);
455
456 static int yyread(char *buf,int max_size)
457 {
458     // no file included
459     if (includeStack.isEmpty()) 
460     {
461         int c=0;
462         if (inputString==0) return c;
463         while( c < max_size && inputString[inputPosition] )
464         {
465               *buf = inputString[inputPosition++] ;
466               c++; buf++;
467         }
468         return c;
469     } 
470     else 
471     {
472         //assert(includeStack.current()->newState==YY_CURRENT_BUFFER);
473         return (int)fread(buf,1,max_size,includeStack.current()->filePtr);
474     }
475 }
476
477
478 static QCString configStringRecode(
479     const QCString &str,
480     const char *fromEncoding,
481     const char *toEncoding)
482 {
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)) 
491   {
492     fprintf(stderr,"Error: unsupported character conversion: '%s'->'%s'\n",
493         inputEncoding.data(),outputEncoding.data());
494     exit(1);
495   }
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))
501   {
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());
506   }
507   else
508   {
509     fprintf(stderr,"Error: failed to translate characters from %s to %s: %s\n",
510         inputEncoding.data(),outputEncoding.data(),strerror(errno));
511     exit(1);
512   }
513   portable_iconv_close(cd);
514   return output;
515 }
516
517 static void checkEncoding()
518 {
519   ConfigString *option = (ConfigString*)config->get("DOXYFILE_ENCODING");
520   encoding = *option->valueRef();
521 }
522
523 static FILE *tryPath(const char *path,const char *fileName)
524 {
525   QCString absName=(path ? (QCString)path+"/"+fileName : (QCString)fileName);
526   QFileInfo fi(absName);
527   if (fi.exists() && fi.isFile())
528   {
529     FILE *f=portable_fopen(absName,"r");
530     if (!f) config_err("Error: could not open file %s for reading\n",absName.data());
531     return f;
532   }
533   return 0;
534 }
535
536 static void substEnvVarsInStrList(QStrList &sl);
537 static void substEnvVarsInString(QCString &s);
538
539 static FILE *findFile(const char *fileName)
540 {
541   if (fileName==0)
542   {
543     return 0;
544   }
545   if (portable_isAbsolutePath(fileName))
546   {
547     return tryPath(NULL, fileName);
548   }
549   substEnvVarsInStrList(includePathList);
550   char *s=includePathList.first();
551   while (s) // try each of the include paths
552   {
553     FILE *f = tryPath(s,fileName);
554     if (f) return f;
555     s=includePathList.next();
556   } 
557   // try cwd if includePathList fails
558   return tryPath(".",fileName);
559 }
560
561 static void readIncludeFile(const char *incName)
562 {
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);
566     exit(1);
567   } 
568
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
574   {
575     inc=inc.mid(1,incLen-2);
576   }
577
578   FILE *f;
579
580   if ((f=findFile(inc))) // see if the include file can be found
581   {
582     // For debugging
583 #if SHOW_INCLUDES
584     for (i=0;i<includeStack.count();i++) msg("  ");
585     msg("@INCLUDE = %s: parsing...\n",inc.data());
586 #endif
587
588     // store the state of the old file 
589     ConfigFileState *fs=new ConfigFileState;
590     fs->oldState=YY_CURRENT_BUFFER;
591     fs->lineNr=yyLineNr;
592     fs->fileName=yyFileName;
593     fs->filePtr=f;
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;
599     yyFileName=inc;
600     includeDepth++;
601   } 
602   else
603   {
604     config_err("Error: @INCLUDE = %s: not found!\n",inc.data());
605     exit(1);
606   }
607 }
608
609
610 %}
611
612 %option nounput
613 %option noyywrap
614
615 %x      Start
616 %x      SkipComment
617 %x      SkipInvalid
618 %x      GetString
619 %x      GetBool
620 %x      GetStrList
621 %x      GetQuotedString
622 %x      GetEnvVar
623 %x      Include
624
625 %%
626
627 <*>\0x0d
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
634                                            {
635                                              config_err("Warning: ignoring unsupported tag `%s' at line %d, file %s\n",
636                                                  yytext,yyLineNr,yyFileName.data()); 
637                                              BEGIN(SkipInvalid);
638                                            }
639                                            else // known tag
640                                            {
641                                              option->setUserComment(config->takeUserComment());
642                                              option->setEncoding(encoding);
643                                              switch(option->kind())
644                                              {
645                                                case ConfigOption::O_Info:
646                                                  // shouldn't get here!
647                                                  BEGIN(SkipInvalid);
648                                                  break;
649                                                case ConfigOption::O_List:
650                                                  l = ((ConfigList *)option)->valueRef();
651                                                  l->clear();
652                                                  elemStr="";
653                                                  BEGIN(GetStrList);
654                                                  break;
655                                                case ConfigOption::O_Enum:
656                                                  s = ((ConfigEnum *)option)->valueRef();
657                                                  s->resize(0);
658                                                  BEGIN(GetString);
659                                                  break;
660                                                case ConfigOption::O_String:
661                                                  s = ((ConfigString *)option)->valueRef();
662                                                  s->resize(0);
663                                                  BEGIN(GetString);
664                                                  break;
665                                                case ConfigOption::O_Int:
666                                                  s = ((ConfigInt *)option)->valueStringRef();
667                                                  s->resize(0);
668                                                  BEGIN(GetString);
669                                                  break;
670                                                case ConfigOption::O_Bool:
671                                                  s = ((ConfigBool *)option)->valueStringRef();
672                                                  s->resize(0);
673                                                  BEGIN(GetString);
674                                                  break;
675                                                case ConfigOption::O_Obsolete:
676                                                  if (config_upd)
677                                                  {
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());
680                                                  }
681                                                  else
682                                                  {
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()); 
686                                                  }
687                                                  BEGIN(SkipInvalid);
688                                                  break;
689                                                case ConfigOption::O_Disabled:
690                                                  if (config_upd)
691                                                  {
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());
694                                                  }
695                                                  else
696                                                  {
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()); 
700                                                  }
701                                                  BEGIN(SkipInvalid);
702                                                  break;
703                                              }
704                                            }
705                                         }
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
710                                           {
711                                             config_err("Warning: ignoring unsupported tag `%s' at line %d, file %s\n",
712                                                 yytext,yyLineNr,yyFileName.data()); 
713                                             BEGIN(SkipInvalid);
714                                           }
715                                           else // known tag
716                                           {
717                                             option->setUserComment(config->takeUserComment());
718                                             switch(option->kind())
719                                             {
720                                               case ConfigOption::O_Info:
721                                                 // shouldn't get here!
722                                                 BEGIN(SkipInvalid);
723                                                 break;
724                                               case ConfigOption::O_List:
725                                                 l = ((ConfigList *)option)->valueRef();
726                                                 elemStr="";
727                                                 BEGIN(GetStrList);
728                                                 break;
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()); 
735                                                 BEGIN(SkipInvalid);
736                                                 break;
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()); 
741                                                  BEGIN(SkipInvalid);
742                                                  break;
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()); 
747                                                  BEGIN(SkipInvalid);
748                                                  break;
749                                              }
750                                            }
751                                         }
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")); 
757                                           BEGIN(Start);
758                                         }
759 <<EOF>>                                 {
760                                           //printf("End of include file\n");
761                                           //printf("Include stack depth=%d\n",g_includeStack.count());
762                                           if (includeStack.isEmpty())
763                                           {
764                                             //printf("Terminating scanner!\n");
765                                             yyterminate();
766                                           }
767                                           else
768                                           {
769                                             ConfigFileState *fs=includeStack.pop();
770                                             fclose(fs->filePtr);
771                                             YY_BUFFER_STATE oldBuf = YY_CURRENT_BUFFER;
772                                             yy_switch_to_buffer( fs->oldState );
773                                             yy_delete_buffer( oldBuf );
774                                             yyLineNr=fs->lineNr;
775                                             yyFileName=fs->fileName;
776                                             delete fs; fs=0;
777                                             includeDepth--;
778                                           }
779                                         }
780
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); }
783 <GetStrList>\n                          { 
784                                           yyLineNr++; 
785                                           if (!elemStr.isEmpty())
786                                           {
787                                             //printf("elemStr1=`%s'\n",elemStr.data());
788                                             l->append(elemStr);
789                                           }
790                                           BEGIN(Start); 
791                                         }
792 <GetStrList>[ \t]+                      {
793                                           if (!elemStr.isEmpty())
794                                           {
795                                             //printf("elemStr2=`%s'\n",elemStr.data());
796                                             l->append(elemStr);
797                                           }
798                                           elemStr.resize(0);
799                                         }
800 <GetString>[^ \"\t\r\n]+                { (*s)+=configStringRecode(yytext,encoding,"UTF-8"); 
801                                           checkEncoding();
802                                         }
803 <GetString,GetStrList,SkipInvalid>"\""  { lastState=YY_START;
804                                           BEGIN(GetQuotedString); 
805                                           tmpString.resize(0); 
806                                         }
807 <GetQuotedString>"\""|"\n"              { 
808                                           // we add a bogus space to signal that the string was quoted. This space will be stripped later on.
809                                           tmpString+=" ";
810                                           //printf("Quoted String = `%s'\n",tmpString.data());
811                                           if (lastState==GetString)
812                                           {
813                                             (*s)+=configStringRecode(tmpString,encoding,"UTF-8");
814                                             checkEncoding();
815                                           }
816                                           else
817                                           {
818                                             elemStr+=configStringRecode(tmpString,encoding,"UTF-8");
819                                           }
820                                           if (*yytext=='\n')
821                                           {
822                                             config_err("Warning: Missing end quote (\") on line %d, file %s\n",yyLineNr,yyFileName.data());
823                                             yyLineNr++;
824                                           }
825                                           BEGIN(lastState);
826                                         }
827 <GetQuotedString>"\\\""                 {
828                                           tmpString+='"';
829                                         }
830 <GetQuotedString>.                      { tmpString+=*yytext; }
831 <GetBool>[a-zA-Z]+                      { 
832                                           QCString bs=yytext; 
833                                           bs=bs.upper();
834                                           if (bs=="YES" || bs=="1")
835                                             *b=TRUE;
836                                           else if (bs=="NO" || bs=="0")
837                                             *b=FALSE;
838                                           else 
839                                           {
840                                             *b=FALSE; 
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());
844                                           }
845                                         }
846 <GetStrList>[^ \#\"\t\r\n]+             {
847                                           elemStr+=configStringRecode(yytext,encoding,"UTF-8");
848                                         }
849 <SkipComment>\n                         { yyLineNr++; BEGIN(Start); }
850 <SkipComment>\\[ \r\t]*\n               { yyLineNr++; BEGIN(Start); }
851 <*>\\[ \r\t]*\n                         { yyLineNr++; }
852 <*>.                                    
853 <*>\n                                   { yyLineNr++ ; }
854
855 %%
856
857 /*@ ----------------------------------------------------------------------------
858  */
859
860 void Config::writeTemplate(FTextStream &t,bool sl,bool upd)
861 {
862   t << "# Doxyfile " << versionString << endl << endl;
863   if (!sl)
864   {
865     t << convertToComment(m_header,"");
866   }
867   QListIterator<ConfigOption> it = iterator();
868   ConfigOption *option;
869   for (;(option=it.current());++it)
870   {
871     option->writeTemplate(t,sl,upd);
872   }
873   /* print last lines of user comment that were at the end of the file */
874   if (m_userComment)
875   {
876     t << "\n";
877     t << takeUserComment();
878   }
879 }
880
881 void Config::convertStrToVal()
882 {
883   QListIterator<ConfigOption> it = iterator();
884   ConfigOption *option;
885   for (;(option=it.current());++it)
886   {
887     option->convertStrToVal();
888   }
889 }
890
891 static void substEnvVarsInString(QCString &s)
892 {
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;
896   int p=0;
897   int i,l;
898   //printf("substEnvVarInString(%s) start\n",s.data());
899   while ((i=re.match(s,p,&l))!=-1 || (i=re2.match(s,p,&l))!=-1)
900   {
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
906   }
907   s=s.stripWhiteSpace(); // to strip the bogus space that was added when an argument
908                          // has quotes
909   //printf("substEnvVarInString(%s) end\n",s.data());
910 }
911
912 static void substEnvVarsInStrList(QStrList &sl)
913 {
914   char *s = sl.first();
915   while (s)
916   {
917     QCString result(s);
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);
922
923     //printf("Result %s was quoted=%d\n",result.data(),wasQuoted);
924
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! */
930     {
931       int l=result.length();
932       int i,p=0;
933       // skip spaces
934       // search for a "word"
935       for (i=0;i<l;i++)
936       {
937         char c=0;
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
944         {
945           if (c=='"') // word within quotes
946           {
947             p=i+1;
948             for (i++;i<l;i++)
949             {
950               c=result.at(i);
951               if (c=='"') // end quote
952               {
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
956                 p=i+1;
957                 break; 
958               }
959               else if (c=='\\') // skip escaped stuff
960               {
961                 i++;
962               }
963             }
964           }
965           else if (c==' ' || c=='\t') // separator
966           {
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
970             p=i+1;
971           }
972         }
973       }
974       if (p!=l) // add the leftover as a string
975       {
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
979       }
980     }
981     else // just goto the next element in the list
982     {
983       sl.insert(sl.at(),result);
984       sl.next();
985     }
986     // remove the old unexpanded string from the list
987     int i=sl.at();
988     sl.remove(); // current item index changes if the last element is removed.
989     if (sl.at()==i)     // not last item
990         s = sl.current();
991     else                // just removed last item
992         s = 0;
993   }
994 }
995
996 void ConfigString::substEnvVars()
997 {
998   substEnvVarsInString(m_value);
999 }
1000
1001 void ConfigList::substEnvVars()
1002 {
1003   substEnvVarsInStrList(m_value);
1004 }
1005
1006 void ConfigBool::substEnvVars()
1007 {
1008   substEnvVarsInString(m_valueString);
1009 }
1010
1011 void ConfigInt::substEnvVars()
1012 {
1013   substEnvVarsInString(m_valueString);
1014 }
1015
1016 void ConfigEnum::substEnvVars()
1017 {
1018   substEnvVarsInString(m_value);
1019 }
1020
1021 void Config::substituteEnvironmentVars()
1022 {
1023   QListIterator<ConfigOption> it = iterator();
1024   ConfigOption *option;
1025   for (;(option=it.current());++it)
1026   {
1027     option->substEnvVars();
1028   }
1029 }
1030
1031 static void cleanUpPaths(QStrList &str)
1032 {
1033   char *sfp = str.first();
1034   while (sfp)
1035   {
1036     register char *p = sfp;
1037     if (p)
1038     {
1039       char c;
1040       while ((c=*p))
1041       {
1042         if (c=='\\') *p='/';
1043         p++;
1044       }
1045     }
1046     QCString path = sfp;
1047     if ((path.at(0)!='/' && (path.length()<=2 || path.at(1)!=':')) ||
1048         path.at(path.length()-1)!='/'
1049        )
1050     {
1051       QFileInfo fi(path);
1052       if (fi.exists() && fi.isDir())
1053       {
1054         int i = str.at();
1055         str.remove();
1056         if (str.at()==i) // did not remove last item
1057           str.insert(i,fi.absFilePath().utf8()+"/");
1058         else
1059           str.append(fi.absFilePath().utf8()+"/");
1060       }
1061     }
1062     sfp = str.next();
1063   }
1064 }
1065
1066 void Config::checkFileName(const char *optionName)
1067 {
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")) 
1072   {
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!
1075   }
1076 }
1077
1078 void Config::check()
1079 {
1080   //if (!projectName.isEmpty())
1081   //{
1082   //  projectName[0]=toupper(projectName[0]);
1083   //}
1084
1085   QCString &warnFormat = Config_getString("WARN_FORMAT");
1086   if (warnFormat.stripWhiteSpace().isEmpty())
1087   {
1088     warnFormat="$file:$line $text";
1089   }
1090   else
1091   {
1092     if (warnFormat.find("$file")==-1)
1093     {
1094       config_err("Warning: warning format does not contain a $file tag!\n");
1095     }
1096     if (warnFormat.find("$line")==-1)
1097     {
1098       config_err("Warning: warning format does not contain a $line tag!\n");
1099     }
1100     if (warnFormat.find("$text")==-1)
1101     {
1102       config_err("Warning: warning format foes not contain a $text tag!\n");
1103     }
1104   }
1105
1106   QCString &manExtension = Config_getString("MAN_EXTENSION");
1107   
1108   // set default man page extension if non is given by the user
1109   if (manExtension.isEmpty())
1110   {
1111     manExtension=".3";
1112   }
1113   
1114   QCString &paperType = Config_getEnum("PAPER_TYPE");
1115   paperType=paperType.lower().stripWhiteSpace(); 
1116   if (paperType.isEmpty())
1117   {
1118     paperType = "a4";
1119   }
1120   if (paperType!="a4" && paperType!="a4wide" && paperType!="letter" && 
1121       paperType!="legal" && paperType!="executive")
1122   {
1123     config_err("Error: Unknown page type specified\n");
1124   }
1125   
1126   QCString &outputLanguage=Config_getEnum("OUTPUT_LANGUAGE");
1127   outputLanguage=outputLanguage.stripWhiteSpace();
1128   if (outputLanguage.isEmpty())
1129   {
1130     outputLanguage = "English";
1131   }
1132
1133   QCString &htmlFileExtension=Config_getString("HTML_FILE_EXTENSION");
1134   htmlFileExtension=htmlFileExtension.stripWhiteSpace();
1135   if (htmlFileExtension.isEmpty())
1136   {
1137     htmlFileExtension = ".html";
1138   }
1139   
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
1144   {
1145     stripFromPath.append(QDir::currentDirPath().utf8()+"/");
1146   }
1147   else
1148   {
1149     cleanUpPaths(stripFromPath);
1150   }
1151
1152   // expand the relative stripFromPath values
1153   QStrList &stripFromIncPath = Config_getList("STRIP_FROM_INC_PATH");
1154   cleanUpPaths(stripFromIncPath);
1155   
1156   // Test to see if HTML header is valid
1157   QCString &headerFile = Config_getString("HTML_HEADER");
1158   if (!headerFile.isEmpty())
1159   {
1160     QFileInfo fi(headerFile);
1161     if (!fi.exists())
1162     {
1163       config_err("Error: tag HTML_HEADER: header file `%s' "
1164           "does not exist\n",headerFile.data());
1165       exit(1);
1166     }
1167   }
1168   // Test to see if HTML footer is valid
1169   QCString &footerFile = Config_getString("HTML_FOOTER");
1170   if (!footerFile.isEmpty())
1171   {
1172     QFileInfo fi(footerFile);
1173     if (!fi.exists())
1174     {
1175       config_err("Error: tag HTML_FOOTER: footer file `%s' "
1176           "does not exist\n",footerFile.data());
1177       exit(1);
1178     }
1179   }
1180   // Test to see if MathJax code file is valid
1181   if (Config_getBool("USE_MATHJAX"))
1182   {
1183     QCString &MathJaxCodefile = Config_getString("MATHJAX_CODEFILE");
1184     if (!MathJaxCodefile.isEmpty())
1185     {
1186       QFileInfo fi(MathJaxCodefile);
1187       if (!fi.exists())
1188       {
1189         config_err("Error: tag MATHJAX_CODEFILE file `%s' "
1190             "does not exist\n",MathJaxCodefile.data());
1191         exit(1);
1192       }
1193     }
1194   }
1195   // Test to see if LaTeX header is valid
1196   QCString &latexHeaderFile = Config_getString("LATEX_HEADER");
1197   if (!latexHeaderFile.isEmpty())
1198   {
1199     QFileInfo fi(latexHeaderFile);
1200     if (!fi.exists())
1201     {
1202       config_err("Error: tag LATEX_HEADER: header file `%s' "
1203           "does not exist\n",latexHeaderFile.data());
1204       exit(1);
1205     }
1206   }
1207   // check include path
1208   QStrList &includePath = Config_getList("INCLUDE_PATH");
1209   char *s=includePath.first();
1210   while (s)
1211   {
1212     QFileInfo fi(s);
1213     if (!fi.exists()) config_err("Warning: tag INCLUDE_PATH: include path `%s' "
1214                           "does not exist\n",s);
1215     s=includePath.next();
1216   }
1217
1218   // check aliases
1219   QStrList &aliasList = Config_getList("ALIASES");
1220   s=aliasList.first();
1221   while (s)
1222   {
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
1225     QCString alias=s;
1226     alias=alias.stripWhiteSpace();
1227     if (alias.find(re1)!=0 && alias.find(re2)!=0)
1228     {
1229       config_err("Error: Illegal alias format `%s'. Use \"name=value\" or \"name(n)=value\", where n is the number of arguments\n",
1230           alias.data());
1231     }
1232     s=aliasList.next();
1233   }
1234
1235   // check if GENERATE_TREEVIEW and GENERATE_HTMLHELP are both enabled
1236   if (Config_getBool("GENERATE_TREEVIEW") && Config_getBool("GENERATE_HTMLHELP"))
1237   {
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;
1240   }
1241   if (Config_getBool("SEARCHENGINE") && Config_getBool("GENERATE_HTMLHELP"))
1242   {
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;
1245   }
1246
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"))
1249   {
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;
1252   }
1253     
1254   // check dot image format
1255   QCString &dotImageFormat=Config_getEnum("DOT_IMAGE_FORMAT");
1256   dotImageFormat=dotImageFormat.stripWhiteSpace();
1257   if (dotImageFormat.isEmpty())
1258   {
1259     dotImageFormat = "png";
1260   }
1261   //else if (dotImageFormat!="gif" && dotImageFormat!="png" && dotImageFormat!="jpg")
1262   //{
1263   //  config_err("Invalid value for DOT_IMAGE_FORMAT: `%s'. Using the default.\n",dotImageFormat.data());
1264   //  dotImageFormat = "png";
1265   //}
1266
1267   QCString &dotFontName=Config_getString("DOT_FONTNAME");
1268   if (dotFontName=="FreeSans" || dotFontName=="FreeSans.ttf")
1269   {
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");
1273   }
1274   
1275   
1276   // check dot path
1277   QCString &dotPath = Config_getString("DOT_PATH");
1278   if (!dotPath.isEmpty())
1279   {
1280     QFileInfo fi(dotPath);
1281     if (fi.exists() && fi.isFile()) // user specified path + exec
1282     {
1283       dotPath=fi.dirPath(TRUE).utf8()+"/";
1284     }
1285     else
1286     {
1287       QFileInfo dp(dotPath+"/dot"+portable_commandExtension());
1288       if (!dp.exists() || !dp.isFile())
1289       {
1290         config_err("Warning: the dot tool could not be found at %s\n",dotPath.data());
1291         dotPath="";
1292       }
1293       else
1294       {
1295         dotPath=dp.dirPath(TRUE).utf8()+"/";
1296       }
1297     }
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)='\\';
1301 #endif
1302   }
1303   else // make sure the string is empty but not null!
1304   {
1305     dotPath="";
1306   }
1307
1308   // check mscgen path
1309   QCString &mscgenPath = Config_getString("MSCGEN_PATH");
1310   if (!mscgenPath.isEmpty())
1311   {
1312     QFileInfo dp(mscgenPath+"/mscgen"+portable_commandExtension());
1313     if (!dp.exists() || !dp.isFile())
1314     {
1315       config_err("Warning: the mscgen tool could not be found at %s\n",mscgenPath.data());
1316       mscgenPath="";
1317     }
1318     else
1319     {
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)='\\';
1324 #endif
1325     }
1326   }
1327   else // make sure the string is empty but not null!
1328   {
1329     mscgenPath="";
1330   }
1331
1332   // check dia path
1333   QCString &diaPath = Config_getString("DIA_PATH");
1334   if (!diaPath.isEmpty())
1335   {
1336     QFileInfo dp(diaPath+"/dia"+portable_commandExtension());
1337     if (!dp.exists() || !dp.isFile())
1338     {
1339       config_err("Warning: dia could not be found at %s\n",diaPath.data());
1340       diaPath="";
1341     }
1342     else
1343     {
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)='\\';
1348 #endif
1349     }
1350   }
1351   else // make sure the string is empty but not null!
1352   {
1353     diaPath="";
1354   }
1355
1356   // check input
1357   QStrList &inputSources=Config_getList("INPUT");
1358   if (inputSources.count()==0)
1359   {
1360     // use current dir as the default
1361     inputSources.append(QDir::currentDirPath().utf8());
1362   }
1363   else
1364   {
1365     s=inputSources.first();
1366     while (s)
1367     {
1368       QFileInfo fi(s);
1369       if (!fi.exists())
1370       {
1371         config_err("Warning: tag INPUT: input source `%s' does not exist\n",s);
1372       }
1373       s=inputSources.next();
1374     }
1375   }
1376
1377   // add default pattern if needed
1378   QStrList &filePatternList = Config_getList("FILE_PATTERNS");
1379   if (filePatternList.isEmpty())
1380   {
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())
1417     {
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");
1440     }
1441   }
1442
1443   // add default pattern if needed
1444   QStrList &examplePatternList = Config_getList("EXAMPLE_PATTERNS");
1445   if (examplePatternList.isEmpty())
1446   {
1447     examplePatternList.append("*");
1448   }
1449
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()
1460      )
1461   {
1462     config_err("Warning: No output formats selected! Set at least one of the main GENERATE_* options to YES.\n");
1463   }
1464
1465   // check HTMLHELP creation requirements
1466   if (!Config_getBool("GENERATE_HTML") && 
1467       Config_getBool("GENERATE_HTMLHELP"))
1468   {
1469     config_err("Warning: GENERATE_HTMLHELP=YES requires GENERATE_HTML=YES.\n");
1470   }
1471
1472   // check QHP creation requirements
1473   if (Config_getBool("GENERATE_QHP"))
1474   {
1475     if (Config_getString("QHP_NAMESPACE").isEmpty())
1476     {
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";
1479     }
1480
1481     if (Config_getString("QHP_VIRTUAL_FOLDER").isEmpty())
1482     {
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";
1485     }
1486   }
1487
1488   if (Config_getBool("OPTIMIZE_OUTPUT_JAVA") && Config_getBool("INLINE_INFO"))
1489   {
1490     // don't show inline info for Java output, since Java has no inline 
1491     // concept.
1492     Config_getBool("INLINE_INFO")=FALSE;
1493   }
1494
1495   int &depth = Config_getInt("MAX_DOT_GRAPH_DEPTH");
1496   if (depth==0)
1497   {
1498     depth=1000;
1499   }
1500
1501   int &hue = Config_getInt("HTML_COLORSTYLE_HUE");
1502   if (hue<0)
1503   {
1504     hue=0;
1505   }
1506   else if (hue>=360)
1507   {
1508     hue=hue%360;
1509   }
1510
1511   int &sat = Config_getInt("HTML_COLORSTYLE_SAT");
1512   if (sat<0)
1513   {
1514     sat=0;
1515   }
1516   else if (sat>255)
1517   {
1518     sat=255;
1519   }
1520   int &gamma = Config_getInt("HTML_COLORSTYLE_GAMMA");
1521   if (gamma<40)
1522   {
1523     gamma=40;
1524   }
1525   else if (gamma>240)
1526   {
1527     gamma=240;
1528   }
1529
1530   QCString mathJaxFormat = Config_getEnum("MATHJAX_FORMAT");
1531   if (!mathJaxFormat.isEmpty() && mathJaxFormat!="HTML-CSS" &&
1532        mathJaxFormat!="NativeMML" && mathJaxFormat!="SVG")
1533   {
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";
1536   }
1537
1538   // add default words if needed
1539   QStrList &annotationFromBrief = Config_getList("ABBREVIATE_BRIEF");
1540   if (annotationFromBrief.isEmpty())
1541   {
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");
1553   }
1554
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")
1562       )
1563      )
1564   {
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="";
1578
1579
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
1582               );
1583
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;
1590   }                               
1591
1592   checkFileName("GENERATE_TAGFILE");
1593
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)
1600   {
1601     QCString depName = option->dependsOn(); // option has a dependency
1602     if (!depName.isEmpty())
1603     {
1604       ConfigOption * dep = Config::instance()->get(depName);
1605       if (dep->kind()==ConfigOption::O_Bool &&
1606           Config_getBool(depName)==FALSE) // dependent option is disabled
1607       {
1608         if (option->kind()==ConfigOption::O_Bool)
1609         {
1610           printf("disabling option %s\n",option->name().data());
1611           Config_getBool(option->name())=FALSE; // also disable this option
1612         }
1613       }
1614     }
1615   }
1616 #endif
1617 }
1618
1619 void Config::init()
1620 {
1621   QListIterator<ConfigOption> it = iterator();
1622   ConfigOption *option;
1623   for (;(option=it.current());++it)
1624   {
1625     option->init();
1626   }
1627
1628   // sanity check if all depends relations are valid
1629   for (it.toFirst();(option=it.current());++it)
1630   {
1631     QCString depName = option->dependsOn();
1632     if (!depName.isEmpty())
1633     {
1634       ConfigOption * opt = Config::instance()->get(depName);
1635       if (opt==0)
1636       {
1637         config_err("Warning: Config option '%s' has invalid depends relation on unknown option '%s'\n",
1638             option->name().data(),depName.data());
1639         exit(1);
1640       }
1641     }
1642   }
1643 }
1644
1645 void Config::create()
1646 {
1647   if (m_initialized) return; 
1648   m_initialized = TRUE;
1649   addConfigOptions(this);
1650 }
1651
1652 static QCString configFileToString(const char *name)
1653 {
1654   if (name==0 || name[0]==0) return 0;
1655   QFile f;
1656
1657   bool fileOpened=FALSE;
1658   if (name[0]=='-' && name[1]==0) // read from stdin
1659   {
1660     fileOpened=f.open(IO_ReadOnly,stdin);
1661     if (fileOpened)
1662     {
1663       const int bSize=4096;
1664       QCString contents(bSize);
1665       int totalSize=0;
1666       int size;
1667       while ((size=f.readBlock(contents.data()+totalSize,bSize))==bSize)
1668       {
1669         totalSize+=bSize;
1670         contents.resize(totalSize+bSize); 
1671       }
1672       totalSize+=size+2;
1673       contents.resize(totalSize);
1674       contents.at(totalSize-2)='\n'; // to help the scanner
1675       contents.at(totalSize-1)='\0';
1676       return contents;
1677     }
1678   }
1679   else // read from file
1680   {
1681     QFileInfo fi(name);
1682     if (!fi.exists() || !fi.isFile())
1683     {
1684       config_err("Error: file `%s' not found\n",name);
1685       return "";
1686     }
1687     f.setName(name);
1688     fileOpened=f.open(IO_ReadOnly);
1689     if (fileOpened)
1690     {
1691       int fsize=f.size();
1692       QCString contents(fsize+2);
1693       f.readBlock(contents.data(),fsize);
1694       f.close();
1695       if (fsize==0 || contents[fsize-1]=='\n') 
1696         contents[fsize]='\0';
1697       else
1698         contents[fsize]='\n'; // to help the scanner
1699       contents[fsize+1]='\0';
1700       return contents;
1701     }
1702   }
1703   if (!fileOpened)  
1704   {
1705     config_err("Error: cannot open file `%s' for reading\n",name);
1706   }
1707   return "";
1708 }
1709
1710 bool Config::parseString(const char *fn,const char *str,bool update)
1711 {
1712   config = Config::instance();
1713   inputString   = str;
1714   inputPosition = 0;
1715   yyFileName    = fn;
1716   yyLineNr      = 1;
1717   includeStack.setAutoDelete(TRUE);
1718   includeStack.clear();
1719   includeDepth  = 0;
1720   configYYrestart( configYYin );
1721   BEGIN( Start );
1722   config_upd = update;
1723   configYYlex();
1724   config_upd = FALSE;
1725   inputString = 0;
1726   return TRUE;
1727 }
1728
1729 bool Config::parse(const char *fn,bool update)
1730 {
1731   int retval;
1732   encoding = "UTF-8";
1733   printlex(yy_flex_debug, TRUE, __FILE__, fn);
1734   retval =  parseString(fn,configFileToString(fn), update); 
1735   printlex(yy_flex_debug, FALSE, __FILE__, fn);
1736   return retval;
1737 }
1738
1739 extern "C" { // some bogus code to keep the compiler happy
1740   //int  configYYwrap() { return 1 ; }
1741 }