config.l 47.1 KB
Newer Older
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1 2
/******************************************************************************
 *
Dimitri van Heesch's avatar
Dimitri van Heesch committed
3
 * Copyright (C) 1997-2013 by Dimitri van Heesch.
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby 
 * granted. No representations are made about the suitability of this software 
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
 */

%{

/*
 *	includes
 */
#include <stdio.h>
19
#include <stdlib.h>
Dimitri van Heesch's avatar
Dimitri van Heesch committed
20 21
#include <assert.h>
#include <ctype.h>
22
#include <stdarg.h>
23
#include <errno.h>
Dimitri van Heesch's avatar
Dimitri van Heesch committed
24

25
#include <qfileinfo.h>
Dimitri van Heesch's avatar
Dimitri van Heesch committed
26
#include <qdir.h>
27
#include <qtextstream.h>
28
#include <qregexp.h>
29
#include <qstack.h>
Dimitri van Heesch's avatar
Dimitri van Heesch committed
30
#include <qglobal.h>
Dimitri van Heesch's avatar
Dimitri van Heesch committed
31 32
  
#include "config.h"
33
#include "version.h"
34
#include "portable.h"
35
#include "util.h"
36

37
#include "lang_cfg.h"
38
#include "configoptions.h"
39

40 41 42 43 44 45
#undef Config_getString
#undef Config_getInt
#undef Config_getList
#undef Config_getEnum
#undef Config_getBool

46 47
#define YY_NO_INPUT 1

48 49 50 51 52 53
// use in-class definitions
#define Config_getString(val)  getString(__FILE__,__LINE__,val)
#define Config_getInt(val)     getInt(__FILE__,__LINE__,val)
#define Config_getList(val)    getList(__FILE__,__LINE__,val)
#define Config_getEnum(val)    getEnum(__FILE__,__LINE__,val)
#define Config_getBool(val)    getBool(__FILE__,__LINE__,val)
54
  
55
void config_err(const char *fmt, ...)
56 57 58 59 60 61
{
  va_list args;
  va_start(args, fmt);
  vfprintf(stderr, fmt, args);
  va_end(args); 
}
62
void config_warn(const char *fmt, ...)
63 64 65 66 67 68
{
  va_list args;
  va_start(args, fmt);
  vfprintf(stderr, fmt, args);
  va_end(args);
}
Dimitri van Heesch's avatar
Dimitri van Heesch committed
69

70 71 72 73 74
static QCString configStringRecode(
    const QCString &str,
    const char *fromEncoding,
    const char *toEncoding);

75
#define MAX_INCLUDE_DEPTH 10
Dimitri van Heesch's avatar
Dimitri van Heesch committed
76
#define YY_NEVER_INTERACTIVE 1
77

Dimitri van Heesch's avatar
Dimitri van Heesch committed
78 79
/* -----------------------------------------------------------------
 */
80
QCString ConfigOption::convertToComment(const QCString &s, const QCString &u)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
81
{
82
  //printf("convertToComment(%s)=%s\n",s.data(),u.data());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
83
  QCString result;
84
  if (!s.isEmpty())
Dimitri van Heesch's avatar
Dimitri van Heesch committed
85 86 87 88
  {
    QCString tmp=s.stripWhiteSpace();
    char *p=tmp.data();
    char c;
89 90 91
    result+="#";
    if (*p && *p!='\n')
      result+=" ";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
92 93
    while ((c=*p++))
    {
94 95 96 97 98 99
      if (c=='\n')
      {
        result+="\n#";
        if (*p && *p!='\n')
          result+=" ";
      }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
100 101 102 103
      else result+=c;
    }
    result+='\n';
  }
104 105 106 107 108
  if (!u.isEmpty())
  {
    if (!result.isEmpty()) result+='\n';
    result+= u;
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
109 110 111
  return result;
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
112
void ConfigOption::writeBoolValue(FTextStream &t,bool v)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
113
{
114
  t << " ";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
115 116 117
  if (v) t << "YES"; else t << "NO";
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
118
void ConfigOption::writeIntValue(FTextStream &t,int i)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
119
{
120
  t << " " << i;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
121 122
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
123
void ConfigOption::writeStringValue(FTextStream &t,QCString &s)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
124 125
{
  char c;
126
  bool needsEscaping=FALSE;
127 128 129
  // convert the string back to it original encoding
  QCString se = configStringRecode(s,"UTF-8",m_encoding);
  const char *p=se.data();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
130 131
  if (p)
  {
132
    t << " ";
133
    while ((c=*p++)!=0 && !needsEscaping) 
134
      needsEscaping = (c==' ' || c=='\n' || c=='\t' || c=='"' || c=='#');
135 136 137
    if (needsEscaping)
    { 
      t << "\"";
138
      p=se.data();
139 140
      while (*p)
      {
141
	if (*p==' ' && *(p+1)=='\0') break; // skip inserted space at the end
142 143 144 145 146
	if (*p=='"') t << "\\"; // escape quotes
	t << *p++;
      }
      t << "\"";
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
147
    else
148
    {
149
      t << se;
150
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
151 152 153
  }
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
154
void ConfigOption::writeStringList(FTextStream &t,QStrList &l)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
155 156 157 158 159
{
  const char *p = l.first();
  bool first=TRUE;
  while (p)
  {
160
    QCString s=p;
161 162
    if (!first)
      t << "                        ";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
163
    first=FALSE;
164
    writeStringValue(t,s);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
165 166 167 168 169 170 171 172
    p = l.next();
    if (p) t << " \\" << endl;
  }
}

/* -----------------------------------------------------------------
 */

173 174 175 176 177 178 179 180 181 182
Config *Config::m_instance = 0;

void ConfigInt::convertStrToVal() 
{
  if (!m_valueString.isEmpty())
  {
    bool ok;
    int val = m_valueString.toInt(&ok);
    if (!ok || val<m_minVal || val>m_maxVal)
    {
183
      config_warn("Warning: argument `%s' for option %s is not a valid number in the range [%d..%d]!\n"
Dimitri van Heesch's avatar
Dimitri van Heesch committed
184
                "Using the default: %d!\n",m_valueString.data(),m_name.data(),m_minVal,m_maxVal,m_value);
185
    }
186 187 188 189
    else
    {
      m_value=val;
    }
190 191 192
  }
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
193 194 195 196 197
void ConfigBool::convertStrToVal()
{
  QCString val = m_valueString.stripWhiteSpace().lower();
  if (!val.isEmpty())
  {
198
    if (val=="yes" || val=="true" || val=="1" || val=="all") 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
199 200 201
    {
      m_value=TRUE;
    }
202
    else if (val=="no" || val=="false" || val=="0" || val=="none")
Dimitri van Heesch's avatar
Dimitri van Heesch committed
203 204 205 206 207
    {
      m_value=FALSE;
    }
    else
    {
208
      config_warn("Warning: argument `%s' for option %s is not a valid boolean value\n"
Dimitri van Heesch's avatar
Dimitri van Heesch committed
209 210 211 212 213
                "Using the default: %s!\n",m_valueString.data(),m_name.data(),m_value?"YES":"NO");
    }
  }
}

214
QCString &Config::getString(const char *fileName,int num,const char *name) const
215 216 217 218
{
  ConfigOption *opt = m_dict->find(name);
  if (opt==0) 
  {
219
    config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
220 221 222 223
    exit(1);
  }
  else if (opt->kind()!=ConfigOption::O_String)
  {
224
    config_err("%s<%d>: Internal error: Requested option %s not of string type!\n",fileName,num,name);
225 226 227 228 229
    exit(1);
  }
  return *((ConfigString *)opt)->valueRef();
}

230
QStrList &Config::getList(const char *fileName,int num,const char *name) const
231 232 233 234
{
  ConfigOption *opt = m_dict->find(name);
  if (opt==0) 
  {
235
    config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
236 237 238 239
    exit(1);
  }
  else if (opt->kind()!=ConfigOption::O_List)
  {
240
    config_err("%d<%d>: Internal error: Requested option %s not of list type!\n",fileName,num,name);
241 242 243 244 245
    exit(1);
  }
  return *((ConfigList *)opt)->valueRef();
}

246
QCString &Config::getEnum(const char *fileName,int num,const char *name) const
247 248 249 250
{
  ConfigOption *opt = m_dict->find(name);
  if (opt==0) 
  {
251
    config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
252 253 254 255
    exit(1);
  }
  else if (opt->kind()!=ConfigOption::O_Enum)
  {
256
    config_err("%s<%d>: Internal error: Requested option %s not of enum type!\n",fileName,num,name);
257 258 259 260 261
    exit(1);
  }
  return *((ConfigEnum *)opt)->valueRef();
}

262
int &Config::getInt(const char *fileName,int num,const char *name) const
263 264 265 266
{
  ConfigOption *opt = m_dict->find(name);
  if (opt==0) 
  {
267
    config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
268 269 270 271
    exit(1);
  }
  else if (opt->kind()!=ConfigOption::O_Int)
  {
272
    config_err("%s<%d>: Internal error: Requested option %s not of integer type!\n",fileName,num,name);
273 274 275 276 277
    exit(1);
  }
  return *((ConfigInt *)opt)->valueRef();
}

278
bool &Config::getBool(const char *fileName,int num,const char *name) const
279 280 281 282
{
  ConfigOption *opt = m_dict->find(name);
  if (opt==0) 
  {
283
    config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name);
284 285 286 287
    exit(1);
  }
  else if (opt->kind()!=ConfigOption::O_Bool)
  {
288
    config_err("%s<%d>: Internal error: Requested option %s not of integer type!\n",fileName,num,name);
289 290 291 292
    exit(1);
  }
  return *((ConfigBool *)opt)->valueRef();
}
Dimitri van Heesch's avatar
Dimitri van Heesch committed
293

294 295 296
/* -----------------------------------------------------------------
 */

Dimitri van Heesch's avatar
Dimitri van Heesch committed
297
void ConfigInt::writeXML(FTextStream& t)
298 299 300 301 302 303
{
  t << "    <option type='int' "
       "id='" << convertToXML(name()) << "' "
       "docs='\n" << convertToXML(docs()) << "' "
       "minval='" << m_minVal << "' "
       "maxval='" << m_maxVal << "' "
304 305 306
       "defval='" << m_defValue << "'";
  if (!m_dependency.isEmpty()) t << " depends='" << m_dependency << "'";
  t << "/>" << endl;
307 308
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
309
void ConfigBool::writeXML(FTextStream& t)
310 311 312 313
{
  t << "    <option type='bool' "
       "id='" << convertToXML(name()) << "' "
       "docs='\n" << convertToXML(docs()) << "' "
314 315 316
       "defval='" << m_defValue << "'";
  if (!m_dependency.isEmpty()) t << " depends='" << m_dependency << "'";
  t << "/>" << endl;
317 318
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
319
void ConfigString::writeXML(FTextStream& t)
320 321 322 323 324 325 326 327 328 329 330 331
{
  QString format;
  switch (m_widgetType)
  {
    case String: format="string"; break;
    case File:   format="file";   break;
    case Dir:    format="dir";    break;
  }
  t << "    <option type='string' "
       "id='" << convertToXML(name()) << "' "
       "format='" << format << "' "
       "docs='\n" << convertToXML(docs()) << "' "
332 333 334
       "defval='" << convertToXML(m_defValue) << "'";
  if (!m_dependency.isEmpty()) t << " depends='" << m_dependency << "'";
  t << "/>" << endl;
335 336
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
337
void ConfigEnum::writeXML(FTextStream &t)
338 339 340 341
{
  t << "    <option type='enum' "
       "id='" << convertToXML(name()) << "' "
       "defval='" << convertToXML(m_defValue) << "' "
342 343 344
       "docs='\n" << convertToXML(docs()) << "'";
  if (!m_dependency.isEmpty()) t << " depends='" << m_dependency << "'";
  t << ">" << endl;
345 346 347 348 349 350 351 352 353 354 355

  char *enumVal = m_valueRange.first();
  while (enumVal)
  {
    t << "      <value name='" << convertToXML(enumVal) << "'/>" << endl;
    enumVal = m_valueRange.next();
  }

  t << "    </option>" << endl;
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
356
void ConfigList::writeXML(FTextStream &t)
357 358 359 360 361 362 363 364 365 366 367 368
{
  QString format;
  switch (m_widgetType)
  {
    case String:     format="string";  break;
    case File:       format="file";    break;
    case Dir:        format="dir";     break;
    case FileAndDir: format="filedir"; break;
  }
  t << "    <option type='list' "
       "id='" << convertToXML(name()) << "' "
       "format='" << format << "' "
369 370 371
       "docs='\n" << convertToXML(docs()) << "'";
  if (!m_dependency.isEmpty()) t << " depends='" << m_dependency << "'";
  t << ">" << endl;
372 373 374 375 376 377 378 379 380 381
  char *enumVal = m_value.first();
  while (enumVal)
  {
    t << "      <value name='" << convertToXML(enumVal) << "'/>" << endl;
    enumVal = m_value.next();
  }

  t << "    </option>" << endl;
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
382
void ConfigObsolete::writeXML(FTextStream &t)
383 384
{
  t << "    <option type='obsolete' "
385
       "id='" << convertToXML(name()) << "'/>" << endl;
386 387
}

388 389 390 391 392 393
void ConfigDisabled::writeXML(FTextStream &t)
{
  t << "    <option type='disabled' "
       "id='" << convertToXML(name()) << "'/>" << endl;
}

394

Dimitri van Heesch's avatar
Dimitri van Heesch committed
395 396 397 398
/* -----------------------------------------------------------------
 *
 *	static variables
 */
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423

struct ConfigFileState
{
  int lineNr;
  FILE *filePtr;
  YY_BUFFER_STATE oldState;
  YY_BUFFER_STATE newState;
  QCString fileName;
};  

static const char       *inputString;
static int	         inputPosition;
static int               yyLineNr;
static QCString          yyFileName;
static QCString          tmpString;
static QCString         *s=0;
static bool             *b=0;
static QStrList         *l=0;
static int               lastState;
static QCString          elemStr;
static QCString          includeName;
static QStrList          includePathList;
static QStack<ConfigFileState> includeStack;  
static int               includeDepth;

424
static QCString     tabSizeString;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
425
static QCString     maxInitLinesString;
426
static QCString     colsInAlphaIndexString;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
427
static QCString     enumValuesPerLineString;
428
static QCString     treeViewWidthString;
429 430
static QCString     maxDotGraphWidthString;
static QCString     maxDotGraphHeightString;
431
static QCString     encoding;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
432

433 434
static Config      *config;

Dimitri van Heesch's avatar
Dimitri van Heesch committed
435 436 437 438 439 440 441
/* -----------------------------------------------------------------
 */
#undef	YY_INPUT
#define	YY_INPUT(buf,result,max_size) result=yyread(buf,max_size);

static int yyread(char *buf,int max_size)
{
442 443 444 445
    // no file included
    if (includeStack.isEmpty()) 
    {
        int c=0;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
446
	if (inputString==0) return c;
447 448 449 450 451 452 453 454
	while( c < max_size && inputString[inputPosition] )
	{
	      *buf = inputString[inputPosition++] ;
	      c++; buf++;
  	}
	return c;
    } 
    else 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
455
    {
456
        //assert(includeStack.current()->newState==YY_CURRENT_BUFFER);
457
	return (int)fread(buf,1,max_size,includeStack.current()->filePtr);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
458 459 460
    }
}

461

462 463 464 465 466 467 468 469 470
static QCString configStringRecode(
    const QCString &str,
    const char *fromEncoding,
    const char *toEncoding)
{
  QCString inputEncoding = fromEncoding;
  QCString outputEncoding = toEncoding;
  if (inputEncoding.isEmpty() || outputEncoding.isEmpty() || inputEncoding==outputEncoding) return str;
  int inputSize=str.length();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
471
  int outputSize=inputSize*4+1;
472 473 474 475
  QCString output(outputSize);
  void *cd = portable_iconv_open(outputEncoding,inputEncoding);
  if (cd==(void *)(-1)) 
  {
476
    fprintf(stderr,"Error: unsupported character conversion: '%s'->'%s'\n",
477 478 479
        inputEncoding.data(),outputEncoding.data());
    exit(1);
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
480 481
  size_t iLeft=(size_t)inputSize;
  size_t oLeft=(size_t)outputSize;
482 483
  char *inputPtr  = str.data();
  char *outputPtr = output.data();
484 485
  if (!portable_iconv(cd, &inputPtr, &iLeft, &outputPtr, &oLeft))
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
486
    outputSize-=(int)oLeft;
487
    output.resize(outputSize+1);
488
    output.at(outputSize)='\0';
489 490 491 492
    //printf("iconv: input size=%d output size=%d\n[%s]\n",size,newSize,srcBuf.data());
  }
  else
  {
493
    fprintf(stderr,"Error: failed to translate characters from %s to %s: %s\n",
494 495 496 497 498 499 500 501 502 503 504 505 506
        inputEncoding.data(),outputEncoding.data(),strerror(errno));
    exit(1);
  }
  portable_iconv_close(cd);
  return output;
}

static void checkEncoding()
{
  ConfigString *option = (ConfigString*)config->get("DOXYFILE_ENCODING");
  encoding = *option->valueRef();
}

507 508
static FILE *tryPath(const char *path,const char *fileName)
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
509
  QCString absName=(path ? (QCString)path+"/"+fileName : (QCString)fileName);
510 511 512
  QFileInfo fi(absName);
  if (fi.exists() && fi.isFile())
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
513
    FILE *f=portable_fopen(absName,"r");
514
    if (!f) config_err("Error: could not open file %s for reading\n",absName.data());
515 516 517 518 519
    return f;
  }
  return 0;
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
520 521 522
static void substEnvVarsInStrList(QStrList &sl);
static void substEnvVarsInString(QCString &s);

523 524
static FILE *findFile(const char *fileName)
{
525 526 527 528 529 530
  if (fileName==0)
  {
    return 0;
  }
  if (portable_isAbsolutePath(fileName))
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
531
    return tryPath(NULL, fileName);
532
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
533
  substEnvVarsInStrList(includePathList);
534 535 536 537 538 539 540 541 542 543 544 545 546 547
  char *s=includePathList.first();
  while (s) // try each of the include paths
  {
    FILE *f = tryPath(s,fileName);
    if (f) return f;
    s=includePathList.next();
  } 
  // try cwd if includePathList fails
  return tryPath(".",fileName);
}

static void readIncludeFile(const char *incName)
{
  if (includeDepth==MAX_INCLUDE_DEPTH) {
548
    config_err("Error: maximum include depth (%d) reached, %s is not included. Aborting...\n",
549 550 551 552 553
	MAX_INCLUDE_DEPTH,incName);
    exit(1);
  } 

  QCString inc = incName;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
554
  substEnvVarsInString(inc);
555 556
  inc = inc.stripWhiteSpace();
  uint incLen = inc.length();
557
  if (incLen>0 && inc.at(0)=='"' && inc.at(incLen-1)=='"') // strip quotes
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
  {
    inc=inc.mid(1,incLen-2);
  }

  FILE *f;

  if ((f=findFile(inc))) // see if the include file can be found
  {
    // For debugging
#if SHOW_INCLUDES
    for (i=0;i<includeStack.count();i++) msg("  ");
    msg("@INCLUDE = %s: parsing...\n",inc.data());
#endif

    // store the state of the old file 
    ConfigFileState *fs=new ConfigFileState;
    fs->oldState=YY_CURRENT_BUFFER;
    fs->lineNr=yyLineNr;
    fs->fileName=yyFileName;
    fs->filePtr=f;
    // push the state on the stack
    includeStack.push(fs);
    // set the scanner to the include file
    yy_switch_to_buffer(yy_create_buffer(f, YY_BUF_SIZE));
    fs->newState=YY_CURRENT_BUFFER;
    yyFileName=inc;
    includeDepth++;
  } 
  else
  {
588
    config_err("Error: @INCLUDE = %s: not found!\n",inc.data());
589 590 591 592 593
    exit(1);
  }
}


Dimitri van Heesch's avatar
Dimitri van Heesch committed
594 595
%}

596
%option nounput
597 598
%option noyywrap

Dimitri van Heesch's avatar
Dimitri van Heesch committed
599 600
%x      Start
%x	SkipComment
601
%x      SkipInvalid
Dimitri van Heesch's avatar
Dimitri van Heesch committed
602 603 604 605 606
%x      GetString
%x      GetBool
%x      GetStrList
%x      GetQuotedString
%x      GetEnvVar
607
%x      Include
Dimitri van Heesch's avatar
Dimitri van Heesch committed
608 609 610 611

%%

<*>\0x0d
612 613
<Start,GetString,GetStrList,GetBool,SkipInvalid>"##".*"\n" { config->appendUserComment(yytext);}
<Start,GetString,GetStrList,GetBool,SkipInvalid>"#"	   { BEGIN(SkipComment); }
614 615 616 617 618
<Start>[a-z_A-Z][a-z_A-Z0-9]*[ \t]*"="	 { QCString cmd=yytext;
                                           cmd=cmd.left(cmd.length()-1).stripWhiteSpace(); 
					   ConfigOption *option = config->get(cmd);
					   if (option==0) // oops not known
					   {
619
					     config_err("Warning: ignoring unsupported tag `%s' at line %d, file %s\n",
620 621 622 623 624
						 yytext,yyLineNr,yyFileName.data()); 
					     BEGIN(SkipInvalid);
					   }
					   else // known tag
					   {
625
                                             option->setUserComment(config->takeUserComment());
626
					     option->setEncoding(encoding);
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
					     switch(option->kind())
					     {
					       case ConfigOption::O_Info:
						 // shouldn't get here!
					         BEGIN(SkipInvalid);
						 break;
					       case ConfigOption::O_List:
						 l = ((ConfigList *)option)->valueRef();
					         l->clear();
						 elemStr="";
					         BEGIN(GetStrList);
					         break;
					       case ConfigOption::O_Enum:
						 s = ((ConfigEnum *)option)->valueRef();
					         s->resize(0);
					         BEGIN(GetString);
					         break;
					       case ConfigOption::O_String:
						 s = ((ConfigString *)option)->valueRef();
					         s->resize(0);
					         BEGIN(GetString);
					         break;
					       case ConfigOption::O_Int:
						 s = ((ConfigInt *)option)->valueStringRef();
					         s->resize(0);
					         BEGIN(GetString);
					         break;
					       case ConfigOption::O_Bool:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
655
						 s = ((ConfigBool *)option)->valueStringRef();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
656
					         s->resize(0);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
657
					         BEGIN(GetString);
658
						 break;
659
					       case ConfigOption::O_Obsolete:
660
					         config_err("Warning: Tag `%s' at line %d of file %s has become obsolete.\n"
661 662
						            "To avoid this warning please remove this line from your configuration "
							    "file or upgrade it using \"doxygen -u\"\n", cmd.data(),yyLineNr,yyFileName.data()); 
663 664
					         BEGIN(SkipInvalid);
						 break;
665 666 667 668 669 670
					       case ConfigOption::O_Disabled:
					         config_err("Warning: Tag `%s' at line %d of file %s belongs to an option that was not enabled at compile time.\n"
						            "To avoid this warning please remove this line from your configuration "
							    "file, upgrade it using \"doxygen -u\", or recompile doxygen with this feature enabled.\n", cmd.data(),yyLineNr,yyFileName.data()); 
					         BEGIN(SkipInvalid);
						 break;
671 672
					     }
					   }
673 674 675 676 677 678
					}
<Start>[a-z_A-Z][a-z_A-Z0-9]*[ \t]*"+="	{ QCString cmd=yytext;
                                          cmd=cmd.left(cmd.length()-2).stripWhiteSpace(); 
					  ConfigOption *option = config->get(cmd);
					  if (option==0) // oops not known
					  {
679
					    config_err("Warning: ignoring unsupported tag `%s' at line %d, file %s\n",
680 681 682 683 684
						yytext,yyLineNr,yyFileName.data()); 
					    BEGIN(SkipInvalid);
					  }
					  else // known tag
					  {
685
                                            option->setUserComment(config->takeUserComment());
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
					    switch(option->kind())
					    {
					      case ConfigOption::O_Info:
					        // shouldn't get here!
					        BEGIN(SkipInvalid);
						break;
					      case ConfigOption::O_List:
					        l = ((ConfigList *)option)->valueRef();
						elemStr="";
					        BEGIN(GetStrList);
					        break;
					      case ConfigOption::O_Enum:
					      case ConfigOption::O_String:
					      case ConfigOption::O_Int:
					      case ConfigOption::O_Bool:
701
					        config_err("Warning: operator += not supported for `%s'. Ignoring line at line %d, file %s\n",
702 703 704
						    yytext,yyLineNr,yyFileName.data()); 
					        BEGIN(SkipInvalid);
						break;
705
					       case ConfigOption::O_Obsolete:
706
					         config_err("Warning: Tag `%s' at line %d of file %s has become obsolete.\n"
707 708 709 710
						            "To avoid this warning please update your configuration "
							    "file using \"doxygen -u\"\n", cmd.data(),yyLineNr,yyFileName.data()); 
					         BEGIN(SkipInvalid);
						 break;
711 712 713 714 715 716
					       case ConfigOption::O_Disabled:
					         config_err("Warning: Tag `%s' at line %d of file %s belongs to an option that was not enabled at compile time.\n"
						            "To avoid this warning please remove this line from your configuration "
							    "file, upgrade it using \"doxygen -u\", or recompile doxygen with this feature enabled.\n", cmd.data(),yyLineNr,yyFileName.data()); 
					         BEGIN(SkipInvalid);
						 break;
717 718 719
					     }
					   }
					}
720 721 722 723
<Start>"@INCLUDE_PATH"[ \t]*"=" 	{ BEGIN(GetStrList); l=&includePathList; l->clear(); elemStr=""; }
  /* include a config file */
<Start>"@INCLUDE"[ \t]*"="     		{ BEGIN(Include);}
<Include>([^ \"\t\r\n]+)|("\""[^\n\"]+"\"") { 
724
  					  readIncludeFile(configStringRecode(yytext,encoding,"UTF-8")); 
725 726 727 728 729 730 731 732 733 734 735 736 737
  					  BEGIN(Start);
					}
<<EOF>>					{
                                          //printf("End of include file\n");
					  //printf("Include stack depth=%d\n",g_includeStack.count());
                                          if (includeStack.isEmpty())
					  {
					    //printf("Terminating scanner!\n");
					    yyterminate();
					  }
					  else
					  {
					    ConfigFileState *fs=includeStack.pop();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
738
					    fclose(fs->filePtr);
739 740 741 742 743 744 745 746 747 748
					    YY_BUFFER_STATE oldBuf = YY_CURRENT_BUFFER;
					    yy_switch_to_buffer( fs->oldState );
					    yy_delete_buffer( oldBuf );
					    yyLineNr=fs->lineNr;
					    yyFileName=fs->fileName;
					    delete fs; fs=0;
                                            includeDepth--;
					  }
  					}

749
<Start>[a-z_A-Z0-9]+			{ config_err("Warning: ignoring unknown tag `%s' at line %d, file %s\n",yytext,yyLineNr,yyFileName.data()); }
750
<GetString,GetBool,SkipInvalid>\n	{ yyLineNr++; BEGIN(Start); }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
751 752
<GetStrList>\n				{ 
  					  yyLineNr++; 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
753
					  if (!elemStr.isEmpty())
Dimitri van Heesch's avatar
Dimitri van Heesch committed
754 755 756 757 758 759 760
					  {
					    //printf("elemStr1=`%s'\n",elemStr.data());
					    l->append(elemStr);
					  }
					  BEGIN(Start); 
					}
<GetStrList>[ \t]+			{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
761
  				          if (!elemStr.isEmpty())
Dimitri van Heesch's avatar
Dimitri van Heesch committed
762 763 764 765 766 767
					  {
					    //printf("elemStr2=`%s'\n",elemStr.data());
  					    l->append(elemStr);
					  }
					  elemStr.resize(0);
  					}
768 769 770
<GetString>[^ \"\t\r\n]+		{ (*s)+=configStringRecode(yytext,encoding,"UTF-8"); 
                                          checkEncoding();
                                        }
771
<GetString,GetStrList,SkipInvalid>"\""	{ lastState=YY_START;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
772 773 774 775
  					  BEGIN(GetQuotedString); 
                                          tmpString.resize(0); 
					}
<GetQuotedString>"\""|"\n" 		{ 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
776 777
                                          // we add a bogus space to signal that the string was quoted. This space will be stripped later on.
                                          tmpString+=" ";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
778 779
  					  //printf("Quoted String = `%s'\n",tmpString.data());
  					  if (lastState==GetString)
780 781 782 783
					  {
					    (*s)+=configStringRecode(tmpString,encoding,"UTF-8");
                                            checkEncoding();
					  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
784
					  else
785 786 787
					  {
					    elemStr+=configStringRecode(tmpString,encoding,"UTF-8");
					  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
788 789
					  if (*yytext=='\n')
					  {
790
					    config_err("Warning: Missing end quote (\") on line %d, file %s\n",yyLineNr,yyFileName.data());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
791 792 793 794 795 796 797 798 799
					    yyLineNr++;
					  }
					  BEGIN(lastState);
  					}
<GetQuotedString>"\\\""			{
  					  tmpString+='"';
  					}
<GetQuotedString>.			{ tmpString+=*yytext; }
<GetBool>[a-zA-Z]+			{ 
800
  					  QCString bs=yytext; 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
801
  					  bs=bs.upper();
802
  					  if (bs=="YES" || bs=="1")
Dimitri van Heesch's avatar
Dimitri van Heesch committed
803
					    *b=TRUE;
804
					  else if (bs=="NO" || bs=="0")
Dimitri van Heesch's avatar
Dimitri van Heesch committed
805 806 807 808
					    *b=FALSE;
					  else 
					  {
					    *b=FALSE; 
809
					    config_warn("Warning: Invalid value `%s' for "
810 811
						 "boolean tag in line %d, file %s; use YES or NO\n",
						 bs.data(),yyLineNr,yyFileName.data());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
812 813
					  }
					}
814
<GetStrList>[^ \#\"\t\r\n]+		{
815
  					  elemStr+=configStringRecode(yytext,encoding,"UTF-8");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
816 817 818 819 820 821 822 823 824 825 826 827
  					}
<SkipComment>\n				{ yyLineNr++; BEGIN(Start); }
<SkipComment>\\[ \r\t]*\n		{ yyLineNr++; BEGIN(Start); }
<*>\\[ \r\t]*\n				{ yyLineNr++; }
<*>.					
<*>\n					{ yyLineNr++ ; }

%%

/*@ ----------------------------------------------------------------------------
 */

Dimitri van Heesch's avatar
Dimitri van Heesch committed
828
void Config::writeTemplate(FTextStream &t,bool sl,bool upd)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
829
{
830
  t << "# Doxyfile " << versionString << endl << endl;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
831 832
  if (!sl)
  {
833
    t << "# This file describes the settings to be used by the documentation system\n";
834
    t << "# doxygen (www.doxygen.org) for a project.\n";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
835
    t << "#\n";
836 837
    t << "# All text after a double hash (##) is considered a comment and is placed\n";
    t << "# in front of the TAG it is preceding .\n";
838
    t << "# All text after a hash (#) is considered a comment and will be ignored.\n";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
839 840
    t << "# The format is:\n";
    t << "#       TAG = value [value, ...]\n";
841 842
    t << "# For lists items can also be appended using:\n";
    t << "#       TAG += value [value, ...]\n";
843
    t << "# Values that contain spaces should be placed between quotes (\" \").\n";
844
  }
845 846
  ConfigOption *option = m_options->first();
  while (option)
847
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
848
    option->writeTemplate(t,sl,upd);
849
    option = m_options->next();
850
  }
851 852 853 854 855 856
  /* print last lines of user comment that were at the end of the file */
  if (m_userComment)
  {
    t << "\n";
    t << m_userComment;
  }
857 858
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
859
void Config::writeXML(FTextStream &t)
860 861 862
{
  t << "<doxygenconfig>" << endl;
  bool first=TRUE;
863
  ConfigOption *option = m_options->first();
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878
  while (option)
  {
    if (option->kind()==ConfigOption::O_Info)
    {
      if (!first) t << "  </group>" << endl;
      t << "  <group name='" << option->name() << "' "
	   "docs='"        << option->docs() << "'>" << endl;
      first=FALSE;
    }
    else
    {
      option->writeXML(t);
    }
    option = m_options->next();
  }
879 880 881 882 883 884
  option = m_obsolete->first();
  while (option)
  {
    option->writeXML(t);
    option = m_obsolete->next();
  }
885 886 887 888
  if (!first) t << "  </group>" << endl;
  t << "</doxygenconfig>" << endl;
}

889 890 891 892
void Config::convertStrToVal()
{
  ConfigOption *option = m_options->first();
  while (option)
893
  {
894 895
    option->convertStrToVal();
    option = m_options->next();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
896
  }
897 898 899 900
}

static void substEnvVarsInString(QCString &s)
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
901 902
  static QRegExp re("\\$\\([a-z_A-Z0-9.-]+\\)");
  static QRegExp re2("\\$\\([a-z_A-Z0-9.-]+\\([a-z_A-Z0-9.-]+\\)\\)"); // For e.g. PROGRAMFILES(X86)
903 904 905 906
  if (s.isEmpty()) return;
  int p=0;
  int i,l;
  //printf("substEnvVarInString(%s) start\n",s.data());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
907
  while ((i=re.match(s,p,&l))!=-1 || (i=re2.match(s,p,&l))!=-1)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
908
  {
909
    //printf("Found environment var s.mid(%d,%d)=`%s'\n",i+2,l-3,s.mid(i+2,l-3).data());
910
    QCString env=portable_getenv(s.mid(i+2,l-3));
911 912 913
    substEnvVarsInString(env); // recursively expand variables if needed.
    s = s.left(i)+env+s.right(s.length()-i-l);
    p=i+env.length(); // next time start at the end of the expanded string
Dimitri van Heesch's avatar
Dimitri van Heesch committed
914
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
915 916
  s=s.stripWhiteSpace(); // to strip the bogus space that was added when an argument
                         // has quotes
917 918 919 920 921 922 923
  //printf("substEnvVarInString(%s) end\n",s.data());
}

static void substEnvVarsInStrList(QStrList &sl)
{
  char *s = sl.first();
  while (s)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
924
  {
925
    QCString result(s);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
926
    // an argument with quotes will have an extra space at the end, so wasQuoted will be TRUE.
927
    bool wasQuoted = (result.find(' ')!=-1) || (result.find('\t')!=-1);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
928
    // here we strip the quote again
929 930
    substEnvVarsInString(result);

931 932
    //printf("Result %s was quoted=%d\n",result.data(),wasQuoted);

933 934
    if (!wasQuoted) /* as a result of the expansion, a single string
		       may have expanded into a list, which we'll
935
		       add to sl. If the original string already 
936 937 938 939 940 941 942 943 944
		       contained multiple elements no further 
		       splitting is done to allow quoted items with spaces! */
    {
      int l=result.length();
      int i,p=0;
      // skip spaces
      // search for a "word"
      for (i=0;i<l;i++)
      {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
945
	char c=0;
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990
	// skip until start of new word
	while (i<l && ((c=result.at(i))==' ' || c=='\t')) i++; 
	p=i; // p marks the start index of the word
	// skip until end of a word
	while (i<l && ((c=result.at(i))!=' ' && c!='\t' && c!='"')) i++;
	if (i<l) // not at the end of the string
	{
	  if (c=='"') // word within quotes
	  {
	    p=i+1;
	    for (i++;i<l;i++)
	    {
	      c=result.at(i);
	      if (c=='"') // end quote
	      {
		// replace the string in the list and go to the next item.
		sl.insert(sl.at(),result.mid(p,i-p)); // insert new item before current item.
		sl.next();                 // current item is now the old item
		p=i+1;
		break; 
	      }
	      else if (c=='\\') // skip escaped stuff
	      {
		i++;
	      }
	    }
	  }
	  else if (c==' ' || c=='\t') // separator
	  {
	    // replace the string in the list and go to the next item.
	    sl.insert(sl.at(),result.mid(p,i-p)); // insert new item before current item.
	    sl.next();                 // current item is now the old item
	    p=i+1;
	  }
	}
      }
      if (p!=l) // add the leftover as a string
      {
	// replace the string in the list and go to the next item.
	sl.insert(sl.at(),result.right(l-p)); // insert new item before current item.
	sl.next();                 // current item is now the old item
      }
    }
    else // just goto the next element in the list
    {
991 992
      sl.insert(sl.at(),result);
      sl.next();
993
    }
994 995 996 997 998 999 1000
    // remove the old unexpanded string from the list
    int i=sl.at();
    sl.remove(); // current item index changes if the last element is removed.
    if (sl.at()==i)     // not last item
	s = sl.current();
    else                // just removed last item
	s = 0;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1001
  }
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
}

void ConfigString::substEnvVars()
{
  substEnvVarsInString(m_value);
}

void ConfigList::substEnvVars()
{
  substEnvVarsInStrList(m_value);
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
void ConfigBool::substEnvVars()
{
  substEnvVarsInString(m_valueString);
}

void ConfigInt::substEnvVars()
{
  substEnvVarsInString(m_valueString);
}

void ConfigEnum::substEnvVars()
{
  substEnvVarsInString(m_value);
}
1028 1029 1030 1031 1032

void Config::substituteEnvironmentVars()
{
  ConfigOption *option = m_options->first();
  while (option)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1033
  {
1034 1035
    option->substEnvVars();
    option = m_options->next();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1036
  }
1037 1038
}

1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
static void cleanUpPaths(QStrList &str)
{
  char *sfp = str.first();
  while (sfp)
  {
    register char *p = sfp;
    if (p)
    {
      char c;
      while ((c=*p))
      {
	if (c=='\\') *p='/';
	p++;
      }
    }
    QCString path = sfp;
    if ((path.at(0)!='/' && (path.length()<=2 || path.at(1)!=':')) ||
	path.at(path.length()-1)!='/'
       )
    {
      QFileInfo fi(path);
      if (fi.exists() && fi.isDir())
      {
	int i = str.at();
	str.remove();
	if (str.at()==i) // did not remove last item
1065
	  str.insert(i,fi.absFilePath().utf8()+"/");
1066
	else
1067
	  str.append(fi.absFilePath().utf8()+"/");
1068 1069 1070 1071 1072 1073
      }
    }
    sfp = str.next();
  }
}

1074
void Config::check()
1075 1076 1077 1078 1079 1080
{
  //if (!projectName.isEmpty())
  //{
  //  projectName[0]=toupper(projectName[0]);
  //}

1081
  QCString &warnFormat = Config_getString("WARN_FORMAT");
1082
  if (warnFormat.stripWhiteSpace().isEmpty())
1083
  {
1084
    warnFormat="$file:$line $text";
1085 1086 1087
  }
  else
  {
1088
    if (warnFormat.find("$file")==-1)
1089
    {
1090
      config_err("Warning: warning format does not contain a $file tag!\n");
1091
    }
1092
    if (warnFormat.find("$line")==-1)
1093
    {
1094
      config_err("Warning: warning format does not contain a $line tag!\n");
1095
    }
1096
    if (warnFormat.find("$text")==-1)
1097
    {
1098
      config_err("Warning: warning format foes not contain a $text tag!\n");
1099 1100
    }
  }
1101

1102
  QCString &manExtension = Config_getString("MAN_EXTENSION");
1103
  
1104
  // set default man page extension if non is given by the user
1105
  if (manExtension.isEmpty())
1106
  {
1107
    manExtension=".3";
1108 1109
  }
  
1110
  QCString &paperType = Config_getEnum("PAPER_TYPE");
1111 1112
  paperType=paperType.lower().stripWhiteSpace(); 
  if (paperType.isEmpty())
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1113
  {
1114
    paperType = "a4";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1115
  }
1116 1117
  if (paperType!="a4" && paperType!="a4wide" && paperType!="letter" && 
      paperType!="legal" && paperType!="executive")
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1118
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1119
    config_err("Error: Unknown page type specified\n");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1120 1121
  }
  
1122
  QCString &outputLanguage=Config_getEnum("OUTPUT_LANGUAGE");
1123 1124
  outputLanguage=outputLanguage.stripWhiteSpace();
  if (outputLanguage.isEmpty())
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1125
  {
1126
    outputLanguage = "English";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1127
  }
1128 1129 1130 1131 1132 1133 1134

  QCString &htmlFileExtension=Config_getString("HTML_FILE_EXTENSION");
  htmlFileExtension=htmlFileExtension.stripWhiteSpace();
  if (htmlFileExtension.isEmpty())
  {
    htmlFileExtension = ".html";
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1135
  
1136
  // expand the relative stripFromPath values
1137
  QStrList &stripFromPath = Config_getList("STRIP_FROM_PATH");
1138
  char *sfp = stripFromPath.first();
1139
  if (sfp==0) // by default use the current path
1140
  {
1141
    stripFromPath.append(QDir::currentDirPath().utf8()+"/");
1142 1143 1144
  }
  else
  {
1145
    cleanUpPaths(stripFromPath);
1146
  }
1147 1148 1149 1150

  // expand the relative stripFromPath values
  QStrList &stripFromIncPath = Config_getList("STRIP_FROM_INC_PATH");
  cleanUpPaths(stripFromIncPath);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1151 1152
  
  // Test to see if HTML header is valid
1153
  QCString &headerFile = Config_getString("HTML_HEADER");
1154
  if (!headerFile.isEmpty())
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1155
  {
1156
    QFileInfo fi(headerFile);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1157 1158
    if (!fi.exists())
    {
1159
      config_err("Error: tag HTML_HEADER: header file `%s' "
1160
	  "does not exist\n",headerFile.data());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1161 1162 1163 1164
      exit(1);
    }
  }
  // Test to see if HTML footer is valid
1165
  QCString &footerFile = Config_getString("HTML_FOOTER");
1166
  if (!footerFile.isEmpty())
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1167
  {
1168
    QFileInfo fi(footerFile);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1169 1170
    if (!fi.exists())
    {
1171
      config_err("Error: tag HTML_FOOTER: footer file `%s' "
1172
	  "does not exist\n",footerFile.data());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1173 1174 1175
      exit(1);
    }
  }
1176 1177 1178 1179 1180 1181 1182 1183 1184
  // Test to see if MathJax code file is valid
  if (Config_getBool("USE_MATHJAX"))
  {
    QCString &MathJaxCodefile = Config_getString("MATHJAX_CODEFILE");
    if (!MathJaxCodefile.isEmpty())
    {
      QFileInfo fi(MathJaxCodefile);
      if (!fi.exists())
      {
1185
        config_err("Error: tag MATHJAX_CODEFILE file `%s' "
1186 1187 1188 1189 1190
	    "does not exist\n",MathJaxCodefile.data());
        exit(1);
      }
    }
  }
1191
  // Test to see if LaTeX header is valid
1192
  QCString &latexHeaderFile = Config_getString("LATEX_HEADER");
1193
  if (!latexHeaderFile.isEmpty())
1194
  {
1195
    QFileInfo fi(latexHeaderFile);
1196 1197
    if (!fi.exists())
    {
1198
      config_err("Error: tag LATEX_HEADER: header file `%s' "
1199
	  "does not exist\n",latexHeaderFile.data());
1200 1201 1202
      exit(1);
    }
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1203
  // check include path
1204
  QStrList &includePath = Config_getList("INCLUDE_PATH");
1205
  char *s=includePath.first();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1206 1207 1208
  while (s)
  {
    QFileInfo fi(s);
1209
    if (!fi.exists()) config_err("Warning: tag INCLUDE_PATH: include path `%s' "
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1210
	                  "does not exist\n",s);
1211
    s=includePath.next();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1212
  }
1213 1214

  // check aliases
1215
  QStrList &aliasList = Config_getList("ALIASES");
1216
  s=aliasList.first();
1217 1218
  while (s)
  {
1219 1220
    QRegExp re1("[a-z_A-Z][a-z_A-Z0-9]*[ \t]*=");         // alias without argument
    QRegExp re2("[a-z_A-Z][a-z_A-Z0-9]*{[0-9]*}[ \t]*="); // alias with argument
1221 1222
    QCString alias=s;
    alias=alias.stripWhiteSpace();
1223
    if (alias.find(re1)!=0 && alias.find(re2)!=0)
1224
    {
1225
      config_err("Error: Illegal alias format `%s'. Use \"name=value\" or \"name(n)=value\", where n is the number of arguments\n",
1226
	  alias.data());
1227
    }
1228
    s=aliasList.next();
1229
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1230

1231 1232 1233
  // check if GENERATE_TREEVIEW and GENERATE_HTMLHELP are both enabled
  if (Config_getBool("GENERATE_TREEVIEW") && Config_getBool("GENERATE_HTMLHELP"))
  {
1234
    config_err("Error: When enabling GENERATE_HTMLHELP the tree view (GENERATE_TREEVIEW) should be disabled. I'll do it for you.\n");
1235 1236 1237 1238
    Config_getBool("GENERATE_TREEVIEW")=FALSE;
  }
  if (Config_getBool("SEARCHENGINE") && Config_getBool("GENERATE_HTMLHELP"))
  {
1239
    config_err("Error: When enabling GENERATE_HTMLHELP the search engine (SEARCHENGINE) should be disabled. I'll do it for you.\n");
1240 1241
    Config_getBool("SEARCHENGINE")=FALSE;
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1242 1243 1244 1245

  // check if SEPARATE_MEMBER_PAGES and INLINE_GROUPED_CLASSES are both enabled
  if (Config_getBool("SEPARATE_MEMBER_PAGES") && Config_getBool("INLINE_GROUPED_CLASSES"))
  {
1246
    config_err("Error: When enabling INLINE_GROUPED_CLASSES the SEPARATE_MEMBER_PAGES option should be disabled. I'll do it for you.\n");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1247 1248
    Config_getBool("SEPARATE_MEMBER_PAGES")=FALSE;
  }
1249
    
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1250 1251 1252 1253 1254
  // check dot image format
  QCString &dotImageFormat=Config_getEnum("DOT_IMAGE_FORMAT");
  dotImageFormat=dotImageFormat.stripWhiteSpace();
  if (dotImageFormat.isEmpty())
  {
1255
    dotImageFormat = "png";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1256
  }
1257 1258 1259 1260 1261
  //else if (dotImageFormat!="gif" && dotImageFormat!="png" && dotImageFormat!="jpg")
  //{
  //  config_err("Invalid value for DOT_IMAGE_FORMAT: `%s'. Using the default.\n",dotImageFormat.data());
  //  dotImageFormat = "png";
  //}
1262 1263 1264 1265 1266

  QCString &dotFontName=Config_getString("DOT_FONTNAME");
  if (dotFontName=="FreeSans" || dotFontName=="FreeSans.ttf")
  {
    config_err("Warning: doxygen no longer ships with the FreeSans font.\n"
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1267 1268
               "You may want to clear or change DOT_FONTPATH.\n"
               "Otherwise you run the risk that the wrong font is being used for dot generated graphs.\n");
1269
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1270
  
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1271 1272
  
  // check dot path
1273
  QCString &dotPath = Config_getString("DOT_PATH");
1274
  if (!dotPath.isEmpty())
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1275
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1276 1277
    QFileInfo fi(dotPath);
    if (fi.exists() && fi.isFile()) // user specified path + exec
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1278
    {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1279
      dotPath=fi.dirPath(TRUE).utf8()+"/";
1280 1281 1282
    }
    else
    {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1283 1284 1285
      QFileInfo dp(dotPath+"/dot"+portable_commandExtension());
      if (!dp.exists() || !dp.isFile())
      {
1286
	config_err("Warning: the dot tool could not be found at %s\n",dotPath.data());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1287 1288 1289 1290
	dotPath="";
      }
      else
      {
1291
	dotPath=dp.dirPath(TRUE).utf8()+"/";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1292 1293
      }
    }
1294
#if defined(_WIN32) // convert slashes
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1295 1296
    uint i=0,l=dotPath.length();
    for (i=0;i<l;i++) if (dotPath.at(i)=='/') dotPath.at(i)='\\';
1297
#endif
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1298 1299 1300
  }
  else // make sure the string is empty but not null!
  {
1301
    dotPath="";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1302
  }
1303 1304 1305 1306 1307 1308 1309 1310

  // check mscgen path
  QCString &mscgenPath = Config_getString("MSCGEN_PATH");
  if (!mscgenPath.isEmpty())
  {
    QFileInfo dp(mscgenPath+"/mscgen"+portable_commandExtension());
    if (!dp.exists() || !dp.isFile())
    {
1311
      config_err("Warning: the mscgen tool could not be found at %s\n",mscgenPath.data());
1312 1313 1314 1315
      mscgenPath="";
    }
    else
    {
1316
      mscgenPath=dp.dirPath(TRUE).utf8()+"/";
1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
#if defined(_WIN32) // convert slashes
      uint i=0,l=mscgenPath.length();
      for (i=0;i<l;i++) if (mscgenPath.at(i)=='/') mscgenPath.at(i)='\\';
#endif
    }
  }
  else // make sure the string is empty but not null!
  {
    mscgenPath="";
  }

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1328
  
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1329
  // check input
1330
  QStrList &inputSources=Config_getList("INPUT");
1331
  if (inputSources.count()==0)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1332
  {
1333
    // use current dir as the default
1334
    inputSources.append(QDir::currentDirPath().utf8());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1335 1336 1337
  }
  else
  {
1338
    s=inputSources.first();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1339 1340 1341 1342 1343
    while (s)
    {
      QFileInfo fi(s);
      if (!fi.exists())
      {
1344
	config_err("Warning: tag INPUT: input source `%s' does not exist\n",s);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1345
      }
1346
      s=inputSources.next();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1347 1348
    }
  }
1349

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1350
  // add default pattern if needed
1351
  QStrList &filePatternList = Config_getList("FILE_PATTERNS");
1352
  if (filePatternList.isEmpty())
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1353
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1354 1355 1356 1357 1358
    filePatternList.append("*.c");
    filePatternList.append("*.cc"); 
    filePatternList.append("*.cxx");
    filePatternList.append("*.cpp");
    filePatternList.append("*.c++");
1359
    //filePatternList.append("*.d");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371
    filePatternList.append("*.java");
    filePatternList.append("*.ii");
    filePatternList.append("*.ixx");
    filePatternList.append("*.ipp");
    filePatternList.append("*.i++");
    filePatternList.append("*.inl");
    filePatternList.append("*.h");
    filePatternList.append("*.hh");
    filePatternList.append("*.hxx");
    filePatternList.append("*.hpp");
    filePatternList.append("*.h++");
    filePatternList.append("*.idl");
1372
    filePatternList.append("*.odl");
1373
    filePatternList.append("*.cs");
1374 1375 1376
    filePatternList.append("*.php");
    filePatternList.append("*.php3");
    filePatternList.append("*.inc");
1377 1378
    filePatternList.append("*.m");
    filePatternList.append("*.mm");
1379
    filePatternList.append("*.dox");
1380
    filePatternList.append("*.py");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1381
    filePatternList.append("*.f90");
1382
    filePatternList.append("*.f");
1383
    filePatternList.append("*.for");
1384 1385
    filePatternList.append("*.vhd");
    filePatternList.append("*.vhdl");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1386
    filePatternList.append("*.tcl");
1387 1388
    filePatternList.append("*.md");
    filePatternList.append("*.markdown");
1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405
    if (portable_fileSystemIsCaseSensitive())
    {
      // unix => case sensitive match => also include useful uppercase versions
      filePatternList.append("*.C");
      filePatternList.append("*.CC"); 
      filePatternList.append("*.C++");
      filePatternList.append("*.II");
      filePatternList.append("*.I++");
      filePatternList.append("*.H");
      filePatternList.append("*.HH");
      filePatternList.append("*.H++");
      filePatternList.append("*.CS");
      filePatternList.append("*.PHP");
      filePatternList.append("*.PHP3");
      filePatternList.append("*.M");
      filePatternList.append("*.MM");
      filePatternList.append("*.PY");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1406
      filePatternList.append("*.F90");
1407
      filePatternList.append("*.F");
1408 1409
      filePatternList.append("*.VHD");
      filePatternList.append("*.VHDL");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1410
      filePatternList.append("*.TCL");
1411 1412
      filePatternList.append("*.MD");
      filePatternList.append("*.MARKDOWN");
1413
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1414
  }
1415 1416

  // add default pattern if needed
1417
  QStrList &examplePatternList = Config_getList("EXAMPLE_PATTERNS");
1418
  if (examplePatternList.isEmpty())
1419
  {
1420
    examplePatternList.append("*");
1421 1422
  }

1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434
  // if no output format is enabled, warn the user
  if (!Config_getBool("GENERATE_HTML")    && 
      !Config_getBool("GENERATE_LATEX")   &&
      !Config_getBool("GENERATE_MAN")     && 
      !Config_getBool("GENERATE_RTF")     &&
      !Config_getBool("GENERATE_XML")     &&
      !Config_getBool("GENERATE_PERLMOD") &&
      !Config_getBool("GENERATE_RTF")     &&
      !Config_getBool("GENERATE_AUTOGEN_DEF") &&
      Config_getString("GENERATE_TAGFILE").isEmpty()
     )
  {
1435
    config_err("Warning: No output formats selected! Set at least one of the main GENERATE_* options to YES.\n");
1436 1437
  }

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1438
  // check HTMLHELP creation requirements
1439 1440 1441
  if (!Config_getBool("GENERATE_HTML") && 
      Config_getBool("GENERATE_HTMLHELP"))
  {
1442
    config_err("Warning: GENERATE_HTMLHELP=YES requires GENERATE_HTML=YES.\n");
1443 1444
  }

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1445 1446 1447 1448 1449
  // check QHP creation requirements
  if (Config_getBool("GENERATE_QHP"))
  {
    if (Config_getString("QHP_NAMESPACE").isEmpty())
    {
1450
      config_err("Error: GENERATE_QHP=YES requires QHP_NAMESPACE to be set. Using 'org.doxygen.doc' as default!.\n");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1451
      Config_getString("QHP_NAMESPACE")="org.doxygen.doc";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1452 1453 1454 1455
    }

    if (Config_getString("QHP_VIRTUAL_FOLDER").isEmpty())
    {
1456
      config_err("Error: GENERATE_QHP=YES requires QHP_VIRTUAL_FOLDER to be set. Using 'doc' as default!\n");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1457
      Config_getString("QHP_VIRTUAL_FOLDER")="doc";
1458
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1459 1460
  }

1461 1462 1463 1464 1465 1466
  if (Config_getBool("OPTIMIZE_OUTPUT_JAVA") && Config_getBool("INLINE_INFO"))
  {
    // don't show inline info for Java output, since Java has no inline 
    // concept.
    Config_getBool("INLINE_INFO")=FALSE;
  }
1467

1468 1469
  int &depth = Config_getInt("MAX_DOT_GRAPH_DEPTH");
  if (depth==0)
1470
  {
1471
    depth=1000;
1472
  }
1473

1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502
  int &hue = Config_getInt("HTML_COLORSTYLE_HUE");
  if (hue<0)
  {
    hue=0;
  }
  else if (hue>=360)
  {
    hue=hue%360;
  }

  int &sat = Config_getInt("HTML_COLORSTYLE_SAT");
  if (sat<0)
  {
    sat=0;
  }
  else if (sat>255)
  {
    sat=255;
  }
  int &gamma = Config_getInt("HTML_COLORSTYLE_GAMMA");
  if (gamma<40)
  {
    gamma=40;
  }
  else if (gamma>240)
  {
    gamma=240;
  }

1503 1504 1505 1506
  QCString mathJaxFormat = Config_getEnum("MATHJAX_FORMAT");
  if (!mathJaxFormat.isEmpty() && mathJaxFormat!="HTML-CSS" &&
       mathJaxFormat!="NativeMML" && mathJaxFormat!="SVG")
  {
1507
    config_err("Error: Unsupported value for MATHJAX_FORMAT: Should be one of HTML-CSS, NativeMML, or SVG\n");
1508 1509
    Config_getEnum("MATHJAX_FORMAT")="HTML-CSS";
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1510

1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526
  // add default words if needed
  QStrList &annotationFromBrief = Config_getList("ABBREVIATE_BRIEF");
  if (annotationFromBrief.isEmpty())
  {
    annotationFromBrief.append("The $name class");
    annotationFromBrief.append("The $name widget");
    annotationFromBrief.append("The $name file");
    annotationFromBrief.append("is");
    annotationFromBrief.append("provides");
    annotationFromBrief.append("specifies");
    annotationFromBrief.append("contains");
    annotationFromBrief.append("represents");
    annotationFromBrief.append("a");
    annotationFromBrief.append("an");
    annotationFromBrief.append("the");
  }
1527

1528 1529 1530 1531 1532
  // some default settings for vhdl
  if (Config_getBool("OPTIMIZE_OUTPUT_VHDL") && 
      (Config_getBool("INLINE_INHERITED_MEMB") || 
       Config_getBool("INHERIT_DOCS") || 
       !Config_getBool("HIDE_SCOPE_NAMES") ||
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1533 1534
       !Config_getBool("EXTRACT_PRIVATE") ||
       !Config_getBool("EXTRACT_PACKAGE")
1535 1536 1537 1538 1539 1540 1541
      )
     )
  {
    bool b1 = Config_getBool("INLINE_INHERITED_MEMB");
    bool b2 = Config_getBool("INHERIT_DOCS");
    bool b3 = Config_getBool("HIDE_SCOPE_NAMES");
    bool b4 = Config_getBool("EXTRACT_PRIVATE");
1542
    bool b5 = Config_getBool("SKIP_FUNCTION_MACROS");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1543 1544
    bool b6 = Config_getBool("EXTRACT_PACKAGE");
    const char *s1,*s2,*s3,*s4,*s5,*s6;
1545
    if (b1)  s1="  INLINE_INHERITED_MEMB  = NO (was YES)\n"; else s1="";
1546 1547 1548
    if (b2)  s2="  INHERIT_DOCS           = NO (was YES)\n"; else s2="";
    if (!b3) s3="  HIDE_SCOPE_NAMES       = YES (was NO)\n"; else s3="";
    if (!b4) s4="  EXTRACT_PRIVATE        = YES (was NO)\n"; else s4="";
1549
    if (b5)  s5="  ENABLE_PREPROCESSING   = NO (was YES)\n"; else s5="";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1550 1551
    if (!b6) s6="  EXTRACT_PACKAGE        = YES (was NO)\n"; else s6="";

1552

1553
    config_err("Warning: enabling OPTIMIZE_OUTPUT_VHDL assumes the following settings:\n"
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1554
	       "%s%s%s%s%s%s",s1,s2,s3,s4,s5,s6
1555 1556 1557 1558 1559 1560
	      );

    Config_getBool("INLINE_INHERITED_MEMB") = FALSE;
    Config_getBool("INHERIT_DOCS")          = FALSE;
    Config_getBool("HIDE_SCOPE_NAMES")      = TRUE;
    Config_getBool("EXTRACT_PRIVATE")       = TRUE;
1561
    Config_getBool("ENABLE_PREPROCESSING")  = FALSE;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1562
    Config_getBool("EXTRACT_PACKAGE")       = TRUE;
1563
  }                               
1564

1565 1566 1567 1568 1569 1570 1571 1572 1573 1574
}

void Config::init()
{
  ConfigOption *option = m_options->first();
  while (option)
  {
    option->init();
    option = m_options->next();
  }
1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585

  // sanity check if all depends relations are valid
  option = m_options->first();
  while (option)
  {
    QCString depName = option->dependsOn();
    if (!depName.isEmpty())
    {
      ConfigOption * opt = Config::instance()->get(depName);
      if (opt==0)
      {
1586
        config_err("Warning: Config option '%s' has invalid depends relation on unknown option '%s'\n",
1587 1588 1589 1590 1591 1592
            option->name().data(),depName.data());
        exit(1);
      }
    }
    option = m_options->next();
  }
1593 1594 1595 1596 1597 1598
}

void Config::create()
{
  if (m_initialized) return; 
  m_initialized = TRUE;
1599
  addConfigOptions(this);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1600 1601
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1602
static QCString configFileToString(const char *name)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1603
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1604 1605 1606 1607 1608
  if (name==0 || name[0]==0) return 0;
  QFile f;

  bool fileOpened=FALSE;
  if (name[0]=='-' && name[1]==0) // read from stdin
1609
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627
    fileOpened=f.open(IO_ReadOnly,stdin);
    if (fileOpened)
    {
      const int bSize=4096;
      QCString contents(bSize);
      int totalSize=0;
      int size;
      while ((size=f.readBlock(contents.data()+totalSize,bSize))==bSize)
      {
        totalSize+=bSize;
        contents.resize(totalSize+bSize); 
      }
      totalSize+=size+2;
      contents.resize(totalSize);
      contents.at(totalSize-2)='\n'; // to help the scanner
      contents.at(totalSize-1)='\0';
      return contents;
    }
1628
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1629
  else // read from file
1630
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1631 1632 1633
    QFileInfo fi(name);
    if (!fi.exists() || !fi.isFile())
    {
1634
      config_err("Error: file `%s' not found\n",name);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1635 1636
      return "";
    }
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651
    f.setName(name);
    fileOpened=f.open(IO_ReadOnly);
    if (fileOpened)
    {
      int fsize=f.size();
      QCString contents(fsize+2);
      f.readBlock(contents.data(),fsize);
      f.close();
      if (fsize==0 || contents[fsize-1]=='\n') 
	contents[fsize]='\0';
      else
	contents[fsize]='\n'; // to help the scanner
      contents[fsize+1]='\0';
      return contents;
    }
1652
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1653
  if (!fileOpened)  
1654
  {
1655
    config_err("Error: cannot open file `%s' for reading\n",name);
1656
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1657 1658
  return "";
}
1659

1660
bool Config::parseString(const char *fn,const char *str)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1661
{
1662
  config = Config::instance();
1663
  inputString   = str;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1664
  inputPosition = 0;
1665
  yyFileName    = fn;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1666
  yyLineNr      = 1;
1667 1668 1669
  includeStack.setAutoDelete(TRUE);
  includeStack.clear();
  includeDepth  = 0;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1670 1671 1672
  configYYrestart( configYYin );
  BEGIN( Start );
  configYYlex();
1673 1674
  inputString = 0;
  return TRUE;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1675 1676
}

1677 1678
bool Config::parse(const char *fn)
{
1679
  encoding = "UTF-8";
1680 1681 1682
  return parseString(fn,configFileToString(fn)); 
}

1683 1684 1685
extern "C" { // some bogus code to keep the compiler happy
  //int  configYYwrap() { return 1 ; }
}