|
1 /****************************************************************************** |
|
2 * |
|
3 * |
|
4 * |
|
5 * Copyright (C) 1997-2008 by Dimitri van Heesch. |
|
6 * |
|
7 * Permission to use, copy, modify, and distribute this software and its |
|
8 * documentation under the terms of the GNU General Public License is hereby |
|
9 * granted. No representations are made about the suitability of this software |
|
10 * for any purpose. It is provided "as is" without express or implied warranty. |
|
11 * See the GNU General Public License for more details. |
|
12 * |
|
13 */ |
|
14 |
|
15 %{ |
|
16 |
|
17 /* |
|
18 * includes |
|
19 */ |
|
20 #include <stdio.h> |
|
21 #include <stdlib.h> |
|
22 #include <assert.h> |
|
23 #include <ctype.h> |
|
24 #include <stdarg.h> |
|
25 #include <errno.h> |
|
26 |
|
27 #include <qfileinfo.h> |
|
28 #include <qdir.h> |
|
29 #include <qtextstream.h> |
|
30 #include <qregexp.h> |
|
31 #include <qstack.h> |
|
32 #include <qglobal.h> |
|
33 |
|
34 #include "config.h" |
|
35 #include "version.h" |
|
36 #include "portable.h" |
|
37 #include "util.h" |
|
38 |
|
39 #include "lang_cfg.h" |
|
40 #include "configoptions.h" |
|
41 |
|
42 #undef Config_getString |
|
43 #undef Config_getInt |
|
44 #undef Config_getList |
|
45 #undef Config_getEnum |
|
46 #undef Config_getBool |
|
47 |
|
48 // use in-class definitions |
|
49 #define Config_getString(val) getString(__FILE__,__LINE__,val) |
|
50 #define Config_getInt(val) getInt(__FILE__,__LINE__,val) |
|
51 #define Config_getList(val) getList(__FILE__,__LINE__,val) |
|
52 #define Config_getEnum(val) getEnum(__FILE__,__LINE__,val) |
|
53 #define Config_getBool(val) getBool(__FILE__,__LINE__,val) |
|
54 |
|
55 void config_err(const char *fmt, ...) |
|
56 { |
|
57 va_list args; |
|
58 va_start(args, fmt); |
|
59 vfprintf(stderr, fmt, args); |
|
60 va_end(args); |
|
61 } |
|
62 void config_warn(const char *fmt, ...) |
|
63 { |
|
64 va_list args; |
|
65 va_start(args, fmt); |
|
66 vfprintf(stderr, fmt, args); |
|
67 va_end(args); |
|
68 } |
|
69 |
|
70 static QCString configStringRecode( |
|
71 const QCString &str, |
|
72 const char *fromEncoding, |
|
73 const char *toEncoding); |
|
74 |
|
75 #define MAX_INCLUDE_DEPTH 10 |
|
76 #define YY_NEVER_INTERACTIVE 1 |
|
77 |
|
78 /* ----------------------------------------------------------------- |
|
79 */ |
|
80 QCString ConfigOption::convertToComment(const QCString &s) |
|
81 { |
|
82 QCString result; |
|
83 if (s.isEmpty()) return result; |
|
84 else |
|
85 { |
|
86 QCString tmp=s.stripWhiteSpace(); |
|
87 char *p=tmp.data(); |
|
88 char c; |
|
89 result+="#"; |
|
90 if (*p && *p!='\n') |
|
91 result+=" "; |
|
92 while ((c=*p++)) |
|
93 { |
|
94 if (c=='\n') |
|
95 { |
|
96 result+="\n#"; |
|
97 if (*p && *p!='\n') |
|
98 result+=" "; |
|
99 } |
|
100 else result+=c; |
|
101 } |
|
102 result+='\n'; |
|
103 } |
|
104 return result; |
|
105 } |
|
106 |
|
107 void ConfigOption::writeBoolValue(QTextStream &t,bool v) |
|
108 { |
|
109 t << " "; |
|
110 if (v) t << "YES"; else t << "NO"; |
|
111 } |
|
112 |
|
113 void ConfigOption::writeIntValue(QTextStream &t,int i) |
|
114 { |
|
115 t << " " << i; |
|
116 } |
|
117 |
|
118 void ConfigOption::writeStringValue(QTextStream &t,QCString &s) |
|
119 { |
|
120 char c; |
|
121 bool needsEscaping=FALSE; |
|
122 // convert the string back to it original encoding |
|
123 QCString se = configStringRecode(s,"UTF-8",m_encoding); |
|
124 const char *p=se.data(); |
|
125 if (p) |
|
126 { |
|
127 t << " "; |
|
128 while ((c=*p++)!=0 && !needsEscaping) |
|
129 needsEscaping = (c==' ' || c=='\n' || c=='\t' || c=='"' || c=='#'); |
|
130 if (needsEscaping) |
|
131 { |
|
132 t << "\""; |
|
133 p=se.data(); |
|
134 while (*p) |
|
135 { |
|
136 if (*p==' ' && *(p+1)=='\0') break; // skip inserted space at the end |
|
137 if (*p=='"') t << "\\"; // escape quotes |
|
138 t << *p++; |
|
139 } |
|
140 t << "\""; |
|
141 } |
|
142 else |
|
143 { |
|
144 t << se; |
|
145 } |
|
146 } |
|
147 } |
|
148 |
|
149 void ConfigOption::writeStringList(QTextStream &t,QStrList &l) |
|
150 { |
|
151 const char *p = l.first(); |
|
152 bool first=TRUE; |
|
153 while (p) |
|
154 { |
|
155 QCString s=p; |
|
156 if (!first) |
|
157 t << " "; |
|
158 first=FALSE; |
|
159 writeStringValue(t,s); |
|
160 p = l.next(); |
|
161 if (p) t << " \\" << endl; |
|
162 } |
|
163 } |
|
164 |
|
165 /* ----------------------------------------------------------------- |
|
166 */ |
|
167 |
|
168 Config *Config::m_instance = 0; |
|
169 |
|
170 void ConfigInt::convertStrToVal() |
|
171 { |
|
172 if (!m_valueString.isEmpty()) |
|
173 { |
|
174 bool ok; |
|
175 int val = m_valueString.toInt(&ok); |
|
176 if (!ok || val<m_minVal || val>m_maxVal) |
|
177 { |
|
178 config_warn("Warning: argument `%s' for option %s is not a valid number in the range [%d..%d]!\n" |
|
179 "Using the default: %d!\n",m_valueString.data(),m_name.data(),m_minVal,m_maxVal,m_value); |
|
180 } |
|
181 m_value=val; |
|
182 } |
|
183 } |
|
184 |
|
185 void ConfigBool::convertStrToVal() |
|
186 { |
|
187 QCString val = m_valueString.stripWhiteSpace().lower(); |
|
188 if (!val.isEmpty()) |
|
189 { |
|
190 if (val=="yes" || val=="true" || val=="1" || val=="all") |
|
191 { |
|
192 m_value=TRUE; |
|
193 } |
|
194 else if (val=="no" || val=="false" || val=="0" || val=="none") |
|
195 { |
|
196 m_value=FALSE; |
|
197 } |
|
198 else |
|
199 { |
|
200 config_warn("Warning: argument `%s' for option %s is not a valid boolean value\n" |
|
201 "Using the default: %s!\n",m_valueString.data(),m_name.data(),m_value?"YES":"NO"); |
|
202 } |
|
203 } |
|
204 } |
|
205 |
|
206 QCString &Config::getString(const char *fileName,int num,const char *name) const |
|
207 { |
|
208 ConfigOption *opt = m_dict->find(name); |
|
209 if (opt==0) |
|
210 { |
|
211 config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name); |
|
212 exit(1); |
|
213 } |
|
214 else if (opt->kind()!=ConfigOption::O_String) |
|
215 { |
|
216 config_err("%s<%d>: Internal error: Requested option %s not of string type!\n",fileName,num,name); |
|
217 exit(1); |
|
218 } |
|
219 return *((ConfigString *)opt)->valueRef(); |
|
220 } |
|
221 |
|
222 QStrList &Config::getList(const char *fileName,int num,const char *name) const |
|
223 { |
|
224 ConfigOption *opt = m_dict->find(name); |
|
225 if (opt==0) |
|
226 { |
|
227 config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name); |
|
228 exit(1); |
|
229 } |
|
230 else if (opt->kind()!=ConfigOption::O_List) |
|
231 { |
|
232 config_err("%d<%d>: Internal error: Requested option %s not of list type!\n",fileName,num,name); |
|
233 exit(1); |
|
234 } |
|
235 return *((ConfigList *)opt)->valueRef(); |
|
236 } |
|
237 |
|
238 QCString &Config::getEnum(const char *fileName,int num,const char *name) const |
|
239 { |
|
240 ConfigOption *opt = m_dict->find(name); |
|
241 if (opt==0) |
|
242 { |
|
243 config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name); |
|
244 exit(1); |
|
245 } |
|
246 else if (opt->kind()!=ConfigOption::O_Enum) |
|
247 { |
|
248 config_err("%s<%d>: Internal error: Requested option %s not of enum type!\n",fileName,num,name); |
|
249 exit(1); |
|
250 } |
|
251 return *((ConfigEnum *)opt)->valueRef(); |
|
252 } |
|
253 |
|
254 int &Config::getInt(const char *fileName,int num,const char *name) const |
|
255 { |
|
256 ConfigOption *opt = m_dict->find(name); |
|
257 if (opt==0) |
|
258 { |
|
259 config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name); |
|
260 exit(1); |
|
261 } |
|
262 else if (opt->kind()!=ConfigOption::O_Int) |
|
263 { |
|
264 config_err("%s<%d>: Internal error: Requested option %s not of integer type!\n",fileName,num,name); |
|
265 exit(1); |
|
266 } |
|
267 return *((ConfigInt *)opt)->valueRef(); |
|
268 } |
|
269 |
|
270 bool &Config::getBool(const char *fileName,int num,const char *name) const |
|
271 { |
|
272 ConfigOption *opt = m_dict->find(name); |
|
273 if (opt==0) |
|
274 { |
|
275 config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name); |
|
276 exit(1); |
|
277 } |
|
278 else if (opt->kind()!=ConfigOption::O_Bool) |
|
279 { |
|
280 config_err("%s<%d>: Internal error: Requested option %s not of integer type!\n",fileName,num,name); |
|
281 exit(1); |
|
282 } |
|
283 return *((ConfigBool *)opt)->valueRef(); |
|
284 } |
|
285 |
|
286 /* ----------------------------------------------------------------- |
|
287 */ |
|
288 |
|
289 void ConfigInt::writeXML(QTextStream& t) |
|
290 { |
|
291 t << " <option type='int' " |
|
292 "id='" << convertToXML(name()) << "' " |
|
293 "docs='\n" << convertToXML(docs()) << "' " |
|
294 "minval='" << m_minVal << "' " |
|
295 "maxval='" << m_maxVal << "' " |
|
296 "defval='" << m_defValue << "'"; |
|
297 if (!m_dependency.isEmpty()) t << " depends='" << m_dependency << "'"; |
|
298 t << "/>" << endl; |
|
299 } |
|
300 |
|
301 void ConfigBool::writeXML(QTextStream& t) |
|
302 { |
|
303 t << " <option type='bool' " |
|
304 "id='" << convertToXML(name()) << "' " |
|
305 "docs='\n" << convertToXML(docs()) << "' " |
|
306 "defval='" << m_defValue << "'"; |
|
307 if (!m_dependency.isEmpty()) t << " depends='" << m_dependency << "'"; |
|
308 t << "/>" << endl; |
|
309 } |
|
310 |
|
311 void ConfigString::writeXML(QTextStream& t) |
|
312 { |
|
313 QString format; |
|
314 switch (m_widgetType) |
|
315 { |
|
316 case String: format="string"; break; |
|
317 case File: format="file"; break; |
|
318 case Dir: format="dir"; break; |
|
319 } |
|
320 t << " <option type='string' " |
|
321 "id='" << convertToXML(name()) << "' " |
|
322 "format='" << format << "' " |
|
323 "docs='\n" << convertToXML(docs()) << "' " |
|
324 "defval='" << convertToXML(m_defValue) << "'"; |
|
325 if (!m_dependency.isEmpty()) t << " depends='" << m_dependency << "'"; |
|
326 t << "/>" << endl; |
|
327 } |
|
328 |
|
329 void ConfigEnum::writeXML(QTextStream &t) |
|
330 { |
|
331 t << " <option type='enum' " |
|
332 "id='" << convertToXML(name()) << "' " |
|
333 "defval='" << convertToXML(m_defValue) << "' " |
|
334 "docs='\n" << convertToXML(docs()) << "'"; |
|
335 if (!m_dependency.isEmpty()) t << " depends='" << m_dependency << "'"; |
|
336 t << ">" << endl; |
|
337 |
|
338 char *enumVal = m_valueRange.first(); |
|
339 while (enumVal) |
|
340 { |
|
341 t << " <value name='" << convertToXML(enumVal) << "'/>" << endl; |
|
342 enumVal = m_valueRange.next(); |
|
343 } |
|
344 |
|
345 t << " </option>" << endl; |
|
346 } |
|
347 |
|
348 void ConfigList::writeXML(QTextStream &t) |
|
349 { |
|
350 QString format; |
|
351 switch (m_widgetType) |
|
352 { |
|
353 case String: format="string"; break; |
|
354 case File: format="file"; break; |
|
355 case Dir: format="dir"; break; |
|
356 case FileAndDir: format="filedir"; break; |
|
357 } |
|
358 t << " <option type='list' " |
|
359 "id='" << convertToXML(name()) << "' " |
|
360 "format='" << format << "' " |
|
361 "docs='\n" << convertToXML(docs()) << "'"; |
|
362 if (!m_dependency.isEmpty()) t << " depends='" << m_dependency << "'"; |
|
363 t << ">" << endl; |
|
364 char *enumVal = m_value.first(); |
|
365 while (enumVal) |
|
366 { |
|
367 t << " <value name='" << convertToXML(enumVal) << "'/>" << endl; |
|
368 enumVal = m_value.next(); |
|
369 } |
|
370 |
|
371 t << " </option>" << endl; |
|
372 } |
|
373 |
|
374 void ConfigObsolete::writeXML(QTextStream &t) |
|
375 { |
|
376 t << " <option type='obsolete' " |
|
377 "id='" << convertToXML(name()) << "'/>" << endl; |
|
378 } |
|
379 |
|
380 |
|
381 /* ----------------------------------------------------------------- |
|
382 * |
|
383 * static variables |
|
384 */ |
|
385 |
|
386 struct ConfigFileState |
|
387 { |
|
388 int lineNr; |
|
389 FILE *filePtr; |
|
390 YY_BUFFER_STATE oldState; |
|
391 YY_BUFFER_STATE newState; |
|
392 QCString fileName; |
|
393 }; |
|
394 |
|
395 static const char *inputString; |
|
396 static int inputPosition; |
|
397 static int yyLineNr; |
|
398 static QCString yyFileName; |
|
399 static QCString tmpString; |
|
400 static QCString *s=0; |
|
401 static bool *b=0; |
|
402 static QStrList *l=0; |
|
403 static int lastState; |
|
404 static QCString elemStr; |
|
405 static QCString includeName; |
|
406 static QStrList includePathList; |
|
407 static QStack<ConfigFileState> includeStack; |
|
408 static int includeDepth; |
|
409 |
|
410 static QCString tabSizeString; |
|
411 static QCString maxInitLinesString; |
|
412 static QCString colsInAlphaIndexString; |
|
413 static QCString enumValuesPerLineString; |
|
414 static QCString treeViewWidthString; |
|
415 static QCString maxDotGraphWidthString; |
|
416 static QCString maxDotGraphHeightString; |
|
417 static QCString encoding; |
|
418 |
|
419 static Config *config; |
|
420 |
|
421 /* ----------------------------------------------------------------- |
|
422 */ |
|
423 #undef YY_INPUT |
|
424 #define YY_INPUT(buf,result,max_size) result=yyread(buf,max_size); |
|
425 |
|
426 static int yyread(char *buf,int max_size) |
|
427 { |
|
428 // no file included |
|
429 if (includeStack.isEmpty()) |
|
430 { |
|
431 int c=0; |
|
432 if (inputString==0) return c; |
|
433 while( c < max_size && inputString[inputPosition] ) |
|
434 { |
|
435 *buf = inputString[inputPosition++] ; |
|
436 c++; buf++; |
|
437 } |
|
438 return c; |
|
439 } |
|
440 else |
|
441 { |
|
442 //assert(includeStack.current()->newState==YY_CURRENT_BUFFER); |
|
443 return (int)fread(buf,1,max_size,includeStack.current()->filePtr); |
|
444 } |
|
445 } |
|
446 |
|
447 |
|
448 static QCString configStringRecode( |
|
449 const QCString &str, |
|
450 const char *fromEncoding, |
|
451 const char *toEncoding) |
|
452 { |
|
453 QCString inputEncoding = fromEncoding; |
|
454 QCString outputEncoding = toEncoding; |
|
455 if (inputEncoding.isEmpty() || outputEncoding.isEmpty() || inputEncoding==outputEncoding) return str; |
|
456 int inputSize=str.length(); |
|
457 size_t outputSize=inputSize*4+1; |
|
458 QCString output(outputSize); |
|
459 void *cd = portable_iconv_open(outputEncoding,inputEncoding); |
|
460 if (cd==(void *)(-1)) |
|
461 { |
|
462 fprintf(stderr,"Error: unsupported character conversion: '%s'->'%s'\n", |
|
463 inputEncoding.data(),outputEncoding.data()); |
|
464 exit(1); |
|
465 } |
|
466 size_t iLeft=inputSize; |
|
467 size_t oLeft=outputSize; |
|
468 const char *inputPtr = str.data(); |
|
469 char *outputPtr = output.data(); |
|
470 if (!portable_iconv(cd, &inputPtr, &iLeft, &outputPtr, &oLeft)) |
|
471 { |
|
472 outputSize-=oLeft; |
|
473 output.resize(outputSize+1); |
|
474 output.at(outputSize)='\0'; |
|
475 //printf("iconv: input size=%d output size=%d\n[%s]\n",size,newSize,srcBuf.data()); |
|
476 } |
|
477 else |
|
478 { |
|
479 fprintf(stderr,"Error: failed to translate characters from %s to %s: %s\n", |
|
480 inputEncoding.data(),outputEncoding.data(),strerror(errno)); |
|
481 exit(1); |
|
482 } |
|
483 portable_iconv_close(cd); |
|
484 return output; |
|
485 } |
|
486 |
|
487 static void checkEncoding() |
|
488 { |
|
489 ConfigString *option = (ConfigString*)config->get("DOXYFILE_ENCODING"); |
|
490 encoding = *option->valueRef(); |
|
491 } |
|
492 |
|
493 static FILE *tryPath(const char *path,const char *fileName) |
|
494 { |
|
495 QCString absName=(path ? (QCString)path+"/"+fileName : (QCString)fileName); |
|
496 QFileInfo fi(absName); |
|
497 if (fi.exists() && fi.isFile()) |
|
498 { |
|
499 FILE *f=fopen(absName,"r"); |
|
500 if (!f) config_err("Error: could not open file %s for reading\n",absName.data()); |
|
501 return f; |
|
502 } |
|
503 return 0; |
|
504 } |
|
505 |
|
506 static void substEnvVarsInStrList(QStrList &sl); |
|
507 static void substEnvVarsInString(QCString &s); |
|
508 |
|
509 static bool isAbsolute(const char * fileName) |
|
510 { |
|
511 # ifdef _WIN32 |
|
512 if (isalpha (fileName [0]) && fileName[1] == ':') |
|
513 fileName += 2; |
|
514 # endif |
|
515 char const fst = fileName [0]; |
|
516 if (fst == '/') { |
|
517 return true; |
|
518 } |
|
519 # ifdef _WIN32 |
|
520 if (fst == '\\') |
|
521 return true; |
|
522 # endif |
|
523 return false; |
|
524 } |
|
525 |
|
526 static FILE *findFile(const char *fileName) |
|
527 { |
|
528 if(isAbsolute(fileName)) |
|
529 return tryPath(NULL, fileName); |
|
530 substEnvVarsInStrList(includePathList); |
|
531 char *s=includePathList.first(); |
|
532 while (s) // try each of the include paths |
|
533 { |
|
534 FILE *f = tryPath(s,fileName); |
|
535 if (f) return f; |
|
536 s=includePathList.next(); |
|
537 } |
|
538 // try cwd if includePathList fails |
|
539 return tryPath(".",fileName); |
|
540 } |
|
541 |
|
542 static void readIncludeFile(const char *incName) |
|
543 { |
|
544 if (includeDepth==MAX_INCLUDE_DEPTH) { |
|
545 config_err("Error: maximum include depth (%d) reached, %s is not included. Aborting...\n", |
|
546 MAX_INCLUDE_DEPTH,incName); |
|
547 exit(1); |
|
548 } |
|
549 |
|
550 QCString inc = incName; |
|
551 substEnvVarsInString(inc); |
|
552 inc = inc.stripWhiteSpace(); |
|
553 uint incLen = inc.length(); |
|
554 if (inc.at(0)=='"' && inc.at(incLen-1)=='"') // strip quotes |
|
555 { |
|
556 inc=inc.mid(1,incLen-2); |
|
557 } |
|
558 |
|
559 FILE *f; |
|
560 |
|
561 if ((f=findFile(inc))) // see if the include file can be found |
|
562 { |
|
563 // For debugging |
|
564 #if SHOW_INCLUDES |
|
565 for (i=0;i<includeStack.count();i++) msg(" "); |
|
566 msg("@INCLUDE = %s: parsing...\n",inc.data()); |
|
567 #endif |
|
568 |
|
569 // store the state of the old file |
|
570 ConfigFileState *fs=new ConfigFileState; |
|
571 fs->oldState=YY_CURRENT_BUFFER; |
|
572 fs->lineNr=yyLineNr; |
|
573 fs->fileName=yyFileName; |
|
574 fs->filePtr=f; |
|
575 // push the state on the stack |
|
576 includeStack.push(fs); |
|
577 // set the scanner to the include file |
|
578 yy_switch_to_buffer(yy_create_buffer(f, YY_BUF_SIZE)); |
|
579 fs->newState=YY_CURRENT_BUFFER; |
|
580 yyFileName=inc; |
|
581 includeDepth++; |
|
582 } |
|
583 else |
|
584 { |
|
585 config_err("Error: @INCLUDE = %s: not found!\n",inc.data()); |
|
586 exit(1); |
|
587 } |
|
588 } |
|
589 |
|
590 |
|
591 %} |
|
592 |
|
593 %option nounput |
|
594 %option noyywrap |
|
595 |
|
596 %x Start |
|
597 %x SkipComment |
|
598 %x SkipInvalid |
|
599 %x GetString |
|
600 %x GetBool |
|
601 %x GetStrList |
|
602 %x GetQuotedString |
|
603 %x GetEnvVar |
|
604 %x Include |
|
605 |
|
606 %% |
|
607 |
|
608 <*>\0x0d |
|
609 <Start,GetString,GetStrList,GetBool,SkipInvalid>"#" { BEGIN(SkipComment); } |
|
610 <Start>[a-z_A-Z][a-z_A-Z0-9]*[ \t]*"=" { QCString cmd=yytext; |
|
611 cmd=cmd.left(cmd.length()-1).stripWhiteSpace(); |
|
612 ConfigOption *option = config->get(cmd); |
|
613 if (option==0) // oops not known |
|
614 { |
|
615 config_err("Warning: ignoring unsupported tag `%s' at line %d, file %s\n", |
|
616 yytext,yyLineNr,yyFileName.data()); |
|
617 BEGIN(SkipInvalid); |
|
618 } |
|
619 else // known tag |
|
620 { |
|
621 option->setEncoding(encoding); |
|
622 switch(option->kind()) |
|
623 { |
|
624 case ConfigOption::O_Info: |
|
625 // shouldn't get here! |
|
626 BEGIN(SkipInvalid); |
|
627 break; |
|
628 case ConfigOption::O_List: |
|
629 l = ((ConfigList *)option)->valueRef(); |
|
630 l->clear(); |
|
631 elemStr=""; |
|
632 BEGIN(GetStrList); |
|
633 break; |
|
634 case ConfigOption::O_Enum: |
|
635 s = ((ConfigEnum *)option)->valueRef(); |
|
636 s->resize(0); |
|
637 BEGIN(GetString); |
|
638 break; |
|
639 case ConfigOption::O_String: |
|
640 s = ((ConfigString *)option)->valueRef(); |
|
641 s->resize(0); |
|
642 BEGIN(GetString); |
|
643 break; |
|
644 case ConfigOption::O_Int: |
|
645 s = ((ConfigInt *)option)->valueStringRef(); |
|
646 s->resize(0); |
|
647 BEGIN(GetString); |
|
648 break; |
|
649 case ConfigOption::O_Bool: |
|
650 s = ((ConfigBool *)option)->valueStringRef(); |
|
651 s->resize(0); |
|
652 BEGIN(GetString); |
|
653 break; |
|
654 case ConfigOption::O_Obsolete: |
|
655 config_err("Warning: Tag `%s' at line %d of file %s has become obsolete.\n" |
|
656 "To avoid this warning please update your configuration " |
|
657 "file using \"doxygen -u\"\n", cmd.data(),yyLineNr,yyFileName.data()); |
|
658 BEGIN(SkipInvalid); |
|
659 break; |
|
660 } |
|
661 } |
|
662 } |
|
663 <Start>[a-z_A-Z][a-z_A-Z0-9]*[ \t]*"+=" { QCString cmd=yytext; |
|
664 cmd=cmd.left(cmd.length()-2).stripWhiteSpace(); |
|
665 ConfigOption *option = config->get(cmd); |
|
666 if (option==0) // oops not known |
|
667 { |
|
668 config_err("Warning: ignoring unsupported tag `%s' at line %d, file %s\n", |
|
669 yytext,yyLineNr,yyFileName.data()); |
|
670 BEGIN(SkipInvalid); |
|
671 } |
|
672 else // known tag |
|
673 { |
|
674 switch(option->kind()) |
|
675 { |
|
676 case ConfigOption::O_Info: |
|
677 // shouldn't get here! |
|
678 BEGIN(SkipInvalid); |
|
679 break; |
|
680 case ConfigOption::O_List: |
|
681 l = ((ConfigList *)option)->valueRef(); |
|
682 elemStr=""; |
|
683 BEGIN(GetStrList); |
|
684 break; |
|
685 case ConfigOption::O_Enum: |
|
686 case ConfigOption::O_String: |
|
687 case ConfigOption::O_Int: |
|
688 case ConfigOption::O_Bool: |
|
689 config_err("Warning: operator += not supported for `%s'. Ignoring line at line %d, file %s\n", |
|
690 yytext,yyLineNr,yyFileName.data()); |
|
691 BEGIN(SkipInvalid); |
|
692 break; |
|
693 case ConfigOption::O_Obsolete: |
|
694 config_err("Warning: Tag `%s' at line %d of file %s has become obsolete.\n" |
|
695 "To avoid this warning please update your configuration " |
|
696 "file using \"doxygen -u\"\n", cmd.data(),yyLineNr,yyFileName.data()); |
|
697 BEGIN(SkipInvalid); |
|
698 break; |
|
699 } |
|
700 } |
|
701 } |
|
702 <Start>"@INCLUDE_PATH"[ \t]*"=" { BEGIN(GetStrList); l=&includePathList; l->clear(); elemStr=""; } |
|
703 /* include a config file */ |
|
704 <Start>"@INCLUDE"[ \t]*"=" { BEGIN(Include);} |
|
705 <Include>([^ \"\t\r\n]+)|("\""[^\n\"]+"\"") { |
|
706 readIncludeFile(configStringRecode(yytext,encoding,"UTF-8")); |
|
707 BEGIN(Start); |
|
708 } |
|
709 <<EOF>> { |
|
710 //printf("End of include file\n"); |
|
711 //printf("Include stack depth=%d\n",g_includeStack.count()); |
|
712 if (includeStack.isEmpty()) |
|
713 { |
|
714 //printf("Terminating scanner!\n"); |
|
715 yyterminate(); |
|
716 } |
|
717 else |
|
718 { |
|
719 ConfigFileState *fs=includeStack.pop(); |
|
720 fclose(fs->filePtr); |
|
721 YY_BUFFER_STATE oldBuf = YY_CURRENT_BUFFER; |
|
722 yy_switch_to_buffer( fs->oldState ); |
|
723 yy_delete_buffer( oldBuf ); |
|
724 yyLineNr=fs->lineNr; |
|
725 yyFileName=fs->fileName; |
|
726 delete fs; fs=0; |
|
727 includeDepth--; |
|
728 } |
|
729 } |
|
730 |
|
731 <Start>[a-z_A-Z0-9]+ { config_err("Warning: ignoring unknown tag `%s' at line %d, file %s\n",yytext,yyLineNr,yyFileName.data()); } |
|
732 <GetString,GetBool,SkipInvalid>\n { yyLineNr++; BEGIN(Start); } |
|
733 <GetStrList>\n { |
|
734 yyLineNr++; |
|
735 if (!elemStr.isEmpty()) |
|
736 { |
|
737 //printf("elemStr1=`%s'\n",elemStr.data()); |
|
738 l->append(elemStr); |
|
739 } |
|
740 BEGIN(Start); |
|
741 } |
|
742 <GetStrList>[ \t]+ { |
|
743 if (!elemStr.isEmpty()) |
|
744 { |
|
745 //printf("elemStr2=`%s'\n",elemStr.data()); |
|
746 l->append(elemStr); |
|
747 } |
|
748 elemStr.resize(0); |
|
749 } |
|
750 <GetString>[^ \"\t\r\n]+ { (*s)+=configStringRecode(yytext,encoding,"UTF-8"); |
|
751 checkEncoding(); |
|
752 } |
|
753 <GetString,GetStrList,SkipInvalid>"\"" { lastState=YY_START; |
|
754 BEGIN(GetQuotedString); |
|
755 tmpString.resize(0); |
|
756 } |
|
757 <GetQuotedString>"\""|"\n" { |
|
758 // we add a bogus space to signal that the string was quoted. This space will be stripped later on. |
|
759 tmpString+=" "; |
|
760 //printf("Quoted String = `%s'\n",tmpString.data()); |
|
761 if (lastState==GetString) |
|
762 { |
|
763 (*s)+=configStringRecode(tmpString,encoding,"UTF-8"); |
|
764 checkEncoding(); |
|
765 } |
|
766 else |
|
767 { |
|
768 elemStr+=configStringRecode(tmpString,encoding,"UTF-8"); |
|
769 } |
|
770 if (*yytext=='\n') |
|
771 { |
|
772 config_err("Warning: Missing end quote (\") on line %d, file %s\n",yyLineNr,yyFileName.data()); |
|
773 yyLineNr++; |
|
774 } |
|
775 BEGIN(lastState); |
|
776 } |
|
777 <GetQuotedString>"\\\"" { |
|
778 tmpString+='"'; |
|
779 } |
|
780 <GetQuotedString>. { tmpString+=*yytext; } |
|
781 <GetBool>[a-zA-Z]+ { |
|
782 QCString bs=yytext; |
|
783 bs=bs.upper(); |
|
784 if (bs=="YES" || bs=="1") |
|
785 *b=TRUE; |
|
786 else if (bs=="NO" || bs=="0") |
|
787 *b=FALSE; |
|
788 else |
|
789 { |
|
790 *b=FALSE; |
|
791 config_warn("Warning: Invalid value `%s' for " |
|
792 "boolean tag in line %d, file %s; use YES or NO\n", |
|
793 bs.data(),yyLineNr,yyFileName.data()); |
|
794 } |
|
795 } |
|
796 <GetStrList>[^ \#\"\t\r\n]+ { |
|
797 elemStr+=configStringRecode(yytext,encoding,"UTF-8"); |
|
798 } |
|
799 <SkipComment>\n { yyLineNr++; BEGIN(Start); } |
|
800 <SkipComment>\\[ \r\t]*\n { yyLineNr++; BEGIN(Start); } |
|
801 <*>\\[ \r\t]*\n { yyLineNr++; } |
|
802 <*>. |
|
803 <*>\n { yyLineNr++ ; } |
|
804 |
|
805 %% |
|
806 |
|
807 /*@ ---------------------------------------------------------------------------- |
|
808 */ |
|
809 |
|
810 void Config::writeTemplate(QTextStream &t,bool sl,bool upd) |
|
811 { |
|
812 t << "# Doxyfile " << versionString << endl << endl; |
|
813 if (!sl) |
|
814 { |
|
815 t << "# This file describes the settings to be used by the documentation system\n"; |
|
816 t << "# doxygen (www.doxygen.org) for a project\n"; |
|
817 t << "#\n"; |
|
818 t << "# All text after a hash (#) is considered a comment and will be ignored\n"; |
|
819 t << "# The format is:\n"; |
|
820 t << "# TAG = value [value, ...]\n"; |
|
821 t << "# For lists items can also be appended using:\n"; |
|
822 t << "# TAG += value [value, ...]\n"; |
|
823 t << "# Values that contain spaces should be placed between quotes (\" \")\n"; |
|
824 } |
|
825 ConfigOption *option = m_options->first(); |
|
826 while (option) |
|
827 { |
|
828 option->writeTemplate(t,sl,upd); |
|
829 option = m_options->next(); |
|
830 } |
|
831 } |
|
832 |
|
833 void Config::writeXML(QTextStream &t) |
|
834 { |
|
835 t << "<doxygenconfig>" << endl; |
|
836 bool first=TRUE; |
|
837 ConfigOption *option = m_options->first(); |
|
838 while (option) |
|
839 { |
|
840 if (option->kind()==ConfigOption::O_Info) |
|
841 { |
|
842 if (!first) t << " </group>" << endl; |
|
843 t << " <group name='" << option->name() << "' " |
|
844 "docs='" << option->docs() << "'>" << endl; |
|
845 first=FALSE; |
|
846 } |
|
847 else |
|
848 { |
|
849 option->writeXML(t); |
|
850 } |
|
851 option = m_options->next(); |
|
852 } |
|
853 option = m_obsolete->first(); |
|
854 while (option) |
|
855 { |
|
856 option->writeXML(t); |
|
857 option = m_obsolete->next(); |
|
858 } |
|
859 if (!first) t << " </group>" << endl; |
|
860 t << "</doxygenconfig>" << endl; |
|
861 } |
|
862 |
|
863 void Config::convertStrToVal() |
|
864 { |
|
865 ConfigOption *option = m_options->first(); |
|
866 while (option) |
|
867 { |
|
868 option->convertStrToVal(); |
|
869 option = m_options->next(); |
|
870 } |
|
871 } |
|
872 |
|
873 static void substEnvVarsInString(QCString &s) |
|
874 { |
|
875 static QRegExp re("\\$\\([a-z_A-Z0-9]+\\)"); |
|
876 if (s.isEmpty()) return; |
|
877 int p=0; |
|
878 int i,l; |
|
879 //printf("substEnvVarInString(%s) start\n",s.data()); |
|
880 while ((i=re.match(s,p,&l))!=-1) |
|
881 { |
|
882 //printf("Found environment var s.mid(%d,%d)=`%s'\n",i+2,l-3,s.mid(i+2,l-3).data()); |
|
883 QCString env=portable_getenv(s.mid(i+2,l-3)); |
|
884 substEnvVarsInString(env); // recursively expand variables if needed. |
|
885 s = s.left(i)+env+s.right(s.length()-i-l); |
|
886 p=i+env.length(); // next time start at the end of the expanded string |
|
887 } |
|
888 s=s.stripWhiteSpace(); // to strip the bogus space that was added when an argument |
|
889 // has quotes |
|
890 //printf("substEnvVarInString(%s) end\n",s.data()); |
|
891 } |
|
892 |
|
893 static void substEnvVarsInStrList(QStrList &sl) |
|
894 { |
|
895 char *s = sl.first(); |
|
896 while (s) |
|
897 { |
|
898 QCString result(s); |
|
899 // an argument with quotes will have an extra space at the end, so wasQuoted will be TRUE. |
|
900 bool wasQuoted = (result.find(' ')!=-1) || (result.find('\t')!=-1); |
|
901 // here we strip the quote again |
|
902 substEnvVarsInString(result); |
|
903 |
|
904 //printf("Result %s was quoted=%d\n",result.data(),wasQuoted); |
|
905 |
|
906 if (!wasQuoted) /* as a result of the expansion, a single string |
|
907 may have expanded into a list, which we'll |
|
908 add to sl. If the orginal string already |
|
909 contained multiple elements no further |
|
910 splitting is done to allow quoted items with spaces! */ |
|
911 { |
|
912 int l=result.length(); |
|
913 int i,p=0; |
|
914 // skip spaces |
|
915 // search for a "word" |
|
916 for (i=0;i<l;i++) |
|
917 { |
|
918 char c=0; |
|
919 // skip until start of new word |
|
920 while (i<l && ((c=result.at(i))==' ' || c=='\t')) i++; |
|
921 p=i; // p marks the start index of the word |
|
922 // skip until end of a word |
|
923 while (i<l && ((c=result.at(i))!=' ' && c!='\t' && c!='"')) i++; |
|
924 if (i<l) // not at the end of the string |
|
925 { |
|
926 if (c=='"') // word within quotes |
|
927 { |
|
928 p=i+1; |
|
929 for (i++;i<l;i++) |
|
930 { |
|
931 c=result.at(i); |
|
932 if (c=='"') // end quote |
|
933 { |
|
934 // replace the string in the list and go to the next item. |
|
935 sl.insert(sl.at(),result.mid(p,i-p)); // insert new item before current item. |
|
936 sl.next(); // current item is now the old item |
|
937 p=i+1; |
|
938 break; |
|
939 } |
|
940 else if (c=='\\') // skip escaped stuff |
|
941 { |
|
942 i++; |
|
943 } |
|
944 } |
|
945 } |
|
946 else if (c==' ' || c=='\t') // separator |
|
947 { |
|
948 // replace the string in the list and go to the next item. |
|
949 sl.insert(sl.at(),result.mid(p,i-p)); // insert new item before current item. |
|
950 sl.next(); // current item is now the old item |
|
951 p=i+1; |
|
952 } |
|
953 } |
|
954 } |
|
955 if (p!=l) // add the leftover as a string |
|
956 { |
|
957 // replace the string in the list and go to the next item. |
|
958 sl.insert(sl.at(),result.right(l-p)); // insert new item before current item. |
|
959 sl.next(); // current item is now the old item |
|
960 } |
|
961 } |
|
962 else // just goto the next element in the list |
|
963 { |
|
964 sl.insert(sl.at(),result); |
|
965 sl.next(); |
|
966 } |
|
967 // remove the old unexpanded string from the list |
|
968 int i=sl.at(); |
|
969 sl.remove(); // current item index changes if the last element is removed. |
|
970 if (sl.at()==i) // not last item |
|
971 s = sl.current(); |
|
972 else // just removed last item |
|
973 s = 0; |
|
974 } |
|
975 } |
|
976 |
|
977 void ConfigString::substEnvVars() |
|
978 { |
|
979 substEnvVarsInString(m_value); |
|
980 } |
|
981 |
|
982 void ConfigList::substEnvVars() |
|
983 { |
|
984 substEnvVarsInStrList(m_value); |
|
985 } |
|
986 |
|
987 void ConfigBool::substEnvVars() |
|
988 { |
|
989 substEnvVarsInString(m_valueString); |
|
990 } |
|
991 |
|
992 void ConfigInt::substEnvVars() |
|
993 { |
|
994 substEnvVarsInString(m_valueString); |
|
995 } |
|
996 |
|
997 void ConfigEnum::substEnvVars() |
|
998 { |
|
999 substEnvVarsInString(m_value); |
|
1000 } |
|
1001 |
|
1002 void Config::substituteEnvironmentVars() |
|
1003 { |
|
1004 ConfigOption *option = m_options->first(); |
|
1005 while (option) |
|
1006 { |
|
1007 option->substEnvVars(); |
|
1008 option = m_options->next(); |
|
1009 } |
|
1010 } |
|
1011 |
|
1012 static void cleanUpPaths(QStrList &str) |
|
1013 { |
|
1014 char *sfp = str.first(); |
|
1015 while (sfp) |
|
1016 { |
|
1017 register char *p = sfp; |
|
1018 if (p) |
|
1019 { |
|
1020 char c; |
|
1021 while ((c=*p)) |
|
1022 { |
|
1023 if (c=='\\') *p='/'; |
|
1024 p++; |
|
1025 } |
|
1026 } |
|
1027 QCString path = sfp; |
|
1028 if ((path.at(0)!='/' && (path.length()<=2 || path.at(1)!=':')) || |
|
1029 path.at(path.length()-1)!='/' |
|
1030 ) |
|
1031 { |
|
1032 QFileInfo fi(path); |
|
1033 if (fi.exists() && fi.isDir()) |
|
1034 { |
|
1035 int i = str.at(); |
|
1036 str.remove(); |
|
1037 if (str.at()==i) // did not remove last item |
|
1038 str.insert(i,fi.absFilePath()+"/"); |
|
1039 else |
|
1040 str.append(fi.absFilePath()+"/"); |
|
1041 } |
|
1042 } |
|
1043 sfp = str.next(); |
|
1044 } |
|
1045 } |
|
1046 |
|
1047 void Config::check() |
|
1048 { |
|
1049 //if (!projectName.isEmpty()) |
|
1050 //{ |
|
1051 // projectName[0]=toupper(projectName[0]); |
|
1052 //} |
|
1053 |
|
1054 QCString &warnFormat = Config_getString("WARN_FORMAT"); |
|
1055 if (warnFormat.stripWhiteSpace().isEmpty()) |
|
1056 { |
|
1057 warnFormat="$file:$line $text"; |
|
1058 } |
|
1059 else |
|
1060 { |
|
1061 if (warnFormat.find("$file")==-1) |
|
1062 { |
|
1063 config_err("Warning: warning format does not contain a $file tag!\n"); |
|
1064 } |
|
1065 if (warnFormat.find("$line")==-1) |
|
1066 { |
|
1067 config_err("Warning: warning format does not contain a $line tag!\n"); |
|
1068 } |
|
1069 if (warnFormat.find("$text")==-1) |
|
1070 { |
|
1071 config_err("Warning: warning format foes not contain a $text tag!\n"); |
|
1072 } |
|
1073 } |
|
1074 |
|
1075 QCString &manExtension = Config_getString("MAN_EXTENSION"); |
|
1076 |
|
1077 // set default man page extension if non is given by the user |
|
1078 if (manExtension.isEmpty()) |
|
1079 { |
|
1080 manExtension=".3"; |
|
1081 } |
|
1082 |
|
1083 QCString &paperType = Config_getEnum("PAPER_TYPE"); |
|
1084 paperType=paperType.lower().stripWhiteSpace(); |
|
1085 if (paperType.isEmpty()) |
|
1086 { |
|
1087 paperType = "a4wide"; |
|
1088 } |
|
1089 if (paperType!="a4" && paperType!="a4wide" && paperType!="letter" && |
|
1090 paperType!="legal" && paperType!="executive") |
|
1091 { |
|
1092 config_err("Error: Unknown page type specified"); |
|
1093 } |
|
1094 |
|
1095 QCString &outputLanguage=Config_getEnum("OUTPUT_LANGUAGE"); |
|
1096 outputLanguage=outputLanguage.stripWhiteSpace(); |
|
1097 if (outputLanguage.isEmpty()) |
|
1098 { |
|
1099 outputLanguage = "English"; |
|
1100 } |
|
1101 |
|
1102 QCString &htmlFileExtension=Config_getString("HTML_FILE_EXTENSION"); |
|
1103 htmlFileExtension=htmlFileExtension.stripWhiteSpace(); |
|
1104 if (htmlFileExtension.isEmpty()) |
|
1105 { |
|
1106 htmlFileExtension = ".html"; |
|
1107 } |
|
1108 |
|
1109 // expand the relative stripFromPath values |
|
1110 QStrList &stripFromPath = Config_getList("STRIP_FROM_PATH"); |
|
1111 char *sfp = stripFromPath.first(); |
|
1112 if (sfp==0) // by default use the current path |
|
1113 { |
|
1114 stripFromPath.append(QDir::currentDirPath()+"/"); |
|
1115 } |
|
1116 else |
|
1117 { |
|
1118 cleanUpPaths(stripFromPath); |
|
1119 } |
|
1120 |
|
1121 // expand the relative stripFromPath values |
|
1122 QStrList &stripFromIncPath = Config_getList("STRIP_FROM_INC_PATH"); |
|
1123 cleanUpPaths(stripFromIncPath); |
|
1124 |
|
1125 // Test to see if HTML header is valid |
|
1126 QCString &headerFile = Config_getString("HTML_HEADER"); |
|
1127 if (!headerFile.isEmpty()) |
|
1128 { |
|
1129 QFileInfo fi(headerFile); |
|
1130 if (!fi.exists()) |
|
1131 { |
|
1132 config_err("Error: tag HTML_HEADER: header file `%s' " |
|
1133 "does not exist\n",headerFile.data()); |
|
1134 exit(1); |
|
1135 } |
|
1136 } |
|
1137 // Test to see if HTML footer is valid |
|
1138 QCString &footerFile = Config_getString("HTML_FOOTER"); |
|
1139 if (!footerFile.isEmpty()) |
|
1140 { |
|
1141 QFileInfo fi(footerFile); |
|
1142 if (!fi.exists()) |
|
1143 { |
|
1144 config_err("Error: tag HTML_FOOTER: footer file `%s' " |
|
1145 "does not exist\n",footerFile.data()); |
|
1146 exit(1); |
|
1147 } |
|
1148 } |
|
1149 // Test to see if LaTeX header is valid |
|
1150 QCString &latexHeaderFile = Config_getString("LATEX_HEADER"); |
|
1151 if (!latexHeaderFile.isEmpty()) |
|
1152 { |
|
1153 QFileInfo fi(latexHeaderFile); |
|
1154 if (!fi.exists()) |
|
1155 { |
|
1156 config_err("Error: tag LATEX_HEADER: header file `%s' " |
|
1157 "does not exist\n",latexHeaderFile.data()); |
|
1158 exit(1); |
|
1159 } |
|
1160 } |
|
1161 // check include path |
|
1162 QStrList &includePath = Config_getList("INCLUDE_PATH"); |
|
1163 char *s=includePath.first(); |
|
1164 while (s) |
|
1165 { |
|
1166 QFileInfo fi(s); |
|
1167 if (!fi.exists()) config_err("Warning: tag INCLUDE_PATH: include path `%s' " |
|
1168 "does not exist\n",s); |
|
1169 s=includePath.next(); |
|
1170 } |
|
1171 |
|
1172 // check aliases |
|
1173 QStrList &aliasList = Config_getList("ALIASES"); |
|
1174 s=aliasList.first(); |
|
1175 while (s) |
|
1176 { |
|
1177 QRegExp re1("[a-z_A-Z][a-z_A-Z0-9]*[ \t]*="); // alias without argument |
|
1178 QRegExp re2("[a-z_A-Z][a-z_A-Z0-9]*{[0-9]*}[ \t]*="); // alias with argument |
|
1179 QCString alias=s; |
|
1180 alias=alias.stripWhiteSpace(); |
|
1181 if (alias.find(re1)!=0 && alias.find(re2)!=0) |
|
1182 { |
|
1183 config_err("Illegal alias format `%s'. Use \"name=value\" or \"name(n)=value\", where n is the number of arguments\n", |
|
1184 alias.data()); |
|
1185 } |
|
1186 s=aliasList.next(); |
|
1187 } |
|
1188 |
|
1189 // check dot image format |
|
1190 QCString &dotImageFormat=Config_getEnum("DOT_IMAGE_FORMAT"); |
|
1191 dotImageFormat=dotImageFormat.stripWhiteSpace(); |
|
1192 if (dotImageFormat.isEmpty()) |
|
1193 { |
|
1194 dotImageFormat = "png"; |
|
1195 } |
|
1196 else if (dotImageFormat!="gif" && dotImageFormat!="png" && dotImageFormat!="jpg") |
|
1197 { |
|
1198 config_err("Invalid value for DOT_IMAGE_FORMAT: `%s'. Using the default.\n",dotImageFormat.data()); |
|
1199 dotImageFormat = "png"; |
|
1200 } |
|
1201 |
|
1202 |
|
1203 // check dot path |
|
1204 QCString &dotPath = Config_getString("DOT_PATH"); |
|
1205 if (!dotPath.isEmpty()) |
|
1206 { |
|
1207 QFileInfo dp(dotPath+"/dot"+portable_commandExtension()); |
|
1208 if (!dp.exists() || !dp.isFile()) |
|
1209 { |
|
1210 config_err("Warning: the dot tool could not be found at %s\n",dotPath.data()); |
|
1211 dotPath=""; |
|
1212 } |
|
1213 else |
|
1214 { |
|
1215 dotPath=dp.dirPath(TRUE)+"/"; |
|
1216 #if defined(_WIN32) // convert slashes |
|
1217 uint i=0,l=dotPath.length(); |
|
1218 for (i=0;i<l;i++) if (dotPath.at(i)=='/') dotPath.at(i)='\\'; |
|
1219 #endif |
|
1220 } |
|
1221 } |
|
1222 else // make sure the string is empty but not null! |
|
1223 { |
|
1224 dotPath=""; |
|
1225 } |
|
1226 |
|
1227 // check mscgen path |
|
1228 QCString &mscgenPath = Config_getString("MSCGEN_PATH"); |
|
1229 if (!mscgenPath.isEmpty()) |
|
1230 { |
|
1231 QFileInfo dp(mscgenPath+"/mscgen"+portable_commandExtension()); |
|
1232 if (!dp.exists() || !dp.isFile()) |
|
1233 { |
|
1234 config_err("Warning: the mscgen tool could not be found at %s\n",mscgenPath.data()); |
|
1235 mscgenPath=""; |
|
1236 } |
|
1237 else |
|
1238 { |
|
1239 mscgenPath=dp.dirPath(TRUE)+"/"; |
|
1240 #if defined(_WIN32) // convert slashes |
|
1241 uint i=0,l=mscgenPath.length(); |
|
1242 for (i=0;i<l;i++) if (mscgenPath.at(i)=='/') mscgenPath.at(i)='\\'; |
|
1243 #endif |
|
1244 } |
|
1245 } |
|
1246 else // make sure the string is empty but not null! |
|
1247 { |
|
1248 mscgenPath=""; |
|
1249 } |
|
1250 |
|
1251 |
|
1252 // check input |
|
1253 QStrList &inputSources=Config_getList("INPUT"); |
|
1254 if (inputSources.count()==0) |
|
1255 { |
|
1256 // use current dir as the default |
|
1257 inputSources.append(QDir::currentDirPath()); |
|
1258 } |
|
1259 else |
|
1260 { |
|
1261 s=inputSources.first(); |
|
1262 while (s) |
|
1263 { |
|
1264 QFileInfo fi(s); |
|
1265 if (!fi.exists()) |
|
1266 { |
|
1267 config_err("Warning: tag INPUT: input source `%s' does not exist\n",s); |
|
1268 } |
|
1269 s=inputSources.next(); |
|
1270 } |
|
1271 } |
|
1272 |
|
1273 // add default pattern if needed |
|
1274 QStrList &filePatternList = Config_getList("FILE_PATTERNS"); |
|
1275 if (filePatternList.isEmpty()) |
|
1276 { |
|
1277 filePatternList.append("*.c"); |
|
1278 filePatternList.append("*.cc"); |
|
1279 filePatternList.append("*.cxx"); |
|
1280 filePatternList.append("*.cpp"); |
|
1281 filePatternList.append("*.c++"); |
|
1282 filePatternList.append("*.d"); |
|
1283 filePatternList.append("*.java"); |
|
1284 filePatternList.append("*.ii"); |
|
1285 filePatternList.append("*.ixx"); |
|
1286 filePatternList.append("*.ipp"); |
|
1287 filePatternList.append("*.i++"); |
|
1288 filePatternList.append("*.inl"); |
|
1289 filePatternList.append("*.h"); |
|
1290 filePatternList.append("*.hh"); |
|
1291 filePatternList.append("*.hxx"); |
|
1292 filePatternList.append("*.hpp"); |
|
1293 filePatternList.append("*.h++"); |
|
1294 filePatternList.append("*.idl"); |
|
1295 filePatternList.append("*.odl"); |
|
1296 filePatternList.append("*.cs"); |
|
1297 filePatternList.append("*.php"); |
|
1298 filePatternList.append("*.php3"); |
|
1299 filePatternList.append("*.inc"); |
|
1300 filePatternList.append("*.m"); |
|
1301 filePatternList.append("*.mm"); |
|
1302 filePatternList.append("*.dox"); |
|
1303 filePatternList.append("*.py"); |
|
1304 filePatternList.append("*.f90"); |
|
1305 filePatternList.append("*.f"); |
|
1306 filePatternList.append("*.vhd"); |
|
1307 filePatternList.append("*.vhdl"); |
|
1308 if (portable_fileSystemIsCaseSensitive()) |
|
1309 { |
|
1310 // unix => case sensitive match => also include useful uppercase versions |
|
1311 filePatternList.append("*.C"); |
|
1312 filePatternList.append("*.CC"); |
|
1313 filePatternList.append("*.C++"); |
|
1314 filePatternList.append("*.II"); |
|
1315 filePatternList.append("*.I++"); |
|
1316 filePatternList.append("*.H"); |
|
1317 filePatternList.append("*.HH"); |
|
1318 filePatternList.append("*.H++"); |
|
1319 filePatternList.append("*.CS"); |
|
1320 filePatternList.append("*.PHP"); |
|
1321 filePatternList.append("*.PHP3"); |
|
1322 filePatternList.append("*.M"); |
|
1323 filePatternList.append("*.MM"); |
|
1324 filePatternList.append("*.PY"); |
|
1325 filePatternList.append("*.F90"); |
|
1326 filePatternList.append("*.F"); |
|
1327 filePatternList.append("*.VHD"); |
|
1328 filePatternList.append("*.VHDL"); |
|
1329 } |
|
1330 } |
|
1331 |
|
1332 // add default pattern if needed |
|
1333 QStrList &examplePatternList = Config_getList("EXAMPLE_PATTERNS"); |
|
1334 if (examplePatternList.isEmpty()) |
|
1335 { |
|
1336 examplePatternList.append("*"); |
|
1337 } |
|
1338 |
|
1339 // if no output format is enabled, warn the user |
|
1340 if (!Config_getBool("GENERATE_HTML") && |
|
1341 !Config_getBool("GENERATE_LATEX") && |
|
1342 !Config_getBool("GENERATE_MAN") && |
|
1343 !Config_getBool("GENERATE_RTF") && |
|
1344 !Config_getBool("GENERATE_XML") && |
|
1345 !Config_getBool("GENERATE_XML_DITA") && |
|
1346 !Config_getBool("GENERATE_PERLMOD") && |
|
1347 !Config_getBool("GENERATE_RTF") && |
|
1348 !Config_getBool("GENERATE_AUTOGEN_DEF") && |
|
1349 Config_getString("GENERATE_TAGFILE").isEmpty() |
|
1350 ) |
|
1351 { |
|
1352 config_err("Warning: No output formats selected! Set at least one of the main GENERATE_* options to YES.\n"); |
|
1353 } |
|
1354 |
|
1355 // check HTMLHELP creation requirements |
|
1356 if (!Config_getBool("GENERATE_HTML") && |
|
1357 Config_getBool("GENERATE_HTMLHELP")) |
|
1358 { |
|
1359 config_err("Warning: GENERATE_HTMLHELP=YES requires GENERATE_HTML=YES.\n"); |
|
1360 } |
|
1361 |
|
1362 // check QHP creation requirements |
|
1363 if (Config_getBool("GENERATE_QHP")) |
|
1364 { |
|
1365 bool qhp=TRUE; |
|
1366 if (!Config_getBool("GENERATE_HTML")) |
|
1367 { |
|
1368 config_err("Error: GENERATE_QHP=YES requires GENERATE_HTML=YES. Disabling QHP output.\n"); |
|
1369 qhp=FALSE; |
|
1370 } |
|
1371 |
|
1372 if (Config_getString("QHP_NAMESPACE").isEmpty()) |
|
1373 { |
|
1374 config_err("Error: GENERATE_QHP=YES requires QHP_NAMESPACE to be set. Disabling QHP output.\n"); |
|
1375 qhp=FALSE; |
|
1376 } |
|
1377 |
|
1378 if (Config_getString("QHP_VIRTUAL_FOLDER").isEmpty()) |
|
1379 { |
|
1380 config_err("Error: GENERATE_QHP=YES requires QHP_VIRTUAL_FOLDER to be set. Disabling QHP output.\n"); |
|
1381 qhp=FALSE; |
|
1382 } |
|
1383 |
|
1384 Config_getBool("GENERATE_QHP")=qhp; |
|
1385 } |
|
1386 |
|
1387 if (Config_getBool("OPTIMIZE_OUTPUT_JAVA") && Config_getBool("INLINE_INFO")) |
|
1388 { |
|
1389 // don't show inline info for Java output, since Java has no inline |
|
1390 // concept. |
|
1391 Config_getBool("INLINE_INFO")=FALSE; |
|
1392 } |
|
1393 |
|
1394 int &depth = Config_getInt("MAX_DOT_GRAPH_DEPTH"); |
|
1395 if (depth==0) |
|
1396 { |
|
1397 depth=1000; |
|
1398 } |
|
1399 |
|
1400 |
|
1401 // add default words if needed |
|
1402 QStrList &annotationFromBrief = Config_getList("ABBREVIATE_BRIEF"); |
|
1403 if (annotationFromBrief.isEmpty()) |
|
1404 { |
|
1405 annotationFromBrief.append("The $name class"); |
|
1406 annotationFromBrief.append("The $name widget"); |
|
1407 annotationFromBrief.append("The $name file"); |
|
1408 annotationFromBrief.append("is"); |
|
1409 annotationFromBrief.append("provides"); |
|
1410 annotationFromBrief.append("specifies"); |
|
1411 annotationFromBrief.append("contains"); |
|
1412 annotationFromBrief.append("represents"); |
|
1413 annotationFromBrief.append("a"); |
|
1414 annotationFromBrief.append("an"); |
|
1415 annotationFromBrief.append("the"); |
|
1416 } |
|
1417 |
|
1418 // some default settings for vhdl |
|
1419 if (Config_getBool("OPTIMIZE_OUTPUT_VHDL") && |
|
1420 (Config_getBool("INLINE_INHERITED_MEMB") || |
|
1421 Config_getBool("INHERIT_DOCS") || |
|
1422 !Config_getBool("HIDE_SCOPE_NAMES") || |
|
1423 !Config_getBool("EXTRACT_PRIVATE") |
|
1424 ) |
|
1425 ) |
|
1426 { |
|
1427 bool b1 = Config_getBool("INLINE_INHERITED_MEMB"); |
|
1428 bool b2 = Config_getBool("INHERIT_DOCS"); |
|
1429 bool b3 = Config_getBool("HIDE_SCOPE_NAMES"); |
|
1430 bool b4 = Config_getBool("EXTRACT_PRIVATE"); |
|
1431 const char *s1,*s2,*s3,*s4; |
|
1432 if (b1) s1=" INLINDE_INHERITED_MEMB = NO (was YES)\n"; else s1=""; |
|
1433 if (b2) s2=" INHERIT_DOCS = NO (was YES)\n"; else s2=""; |
|
1434 if (!b3) s3=" HIDE_SCOPE_NAMES = YES (was NO)\n"; else s3=""; |
|
1435 if (!b4) s4=" EXTRACT_PRIVATE = YES (was NO)\n"; else s4=""; |
|
1436 |
|
1437 config_err("Warning: enabling OPTIMIZE_OUTPUT_VHDL assumes the following settings:\n" |
|
1438 "%s%s%s%s",s1,s2,s3,s4 |
|
1439 ); |
|
1440 |
|
1441 Config_getBool("INLINE_INHERITED_MEMB") = FALSE; |
|
1442 Config_getBool("INHERIT_DOCS") = FALSE; |
|
1443 Config_getBool("HIDE_SCOPE_NAMES") = TRUE; |
|
1444 Config_getBool("EXTRACT_PRIVATE") = TRUE; |
|
1445 } |
|
1446 |
|
1447 } |
|
1448 |
|
1449 void Config::init() |
|
1450 { |
|
1451 ConfigOption *option = m_options->first(); |
|
1452 while (option) |
|
1453 { |
|
1454 option->init(); |
|
1455 option = m_options->next(); |
|
1456 } |
|
1457 } |
|
1458 |
|
1459 void Config::create() |
|
1460 { |
|
1461 if (m_initialized) return; |
|
1462 m_initialized = TRUE; |
|
1463 addConfigOptions(this); |
|
1464 } |
|
1465 |
|
1466 static QCString configFileToString(const char *name) |
|
1467 { |
|
1468 if (name==0 || name[0]==0) return 0; |
|
1469 QFile f; |
|
1470 |
|
1471 bool fileOpened=FALSE; |
|
1472 if (name[0]=='-' && name[1]==0) // read from stdin |
|
1473 { |
|
1474 fileOpened=f.open(IO_ReadOnly,stdin); |
|
1475 if (fileOpened) |
|
1476 { |
|
1477 const int bSize=4096; |
|
1478 QCString contents(bSize); |
|
1479 int totalSize=0; |
|
1480 int size; |
|
1481 while ((size=f.readBlock(contents.data()+totalSize,bSize))==bSize) |
|
1482 { |
|
1483 totalSize+=bSize; |
|
1484 contents.resize(totalSize+bSize); |
|
1485 } |
|
1486 totalSize+=size+2; |
|
1487 contents.resize(totalSize); |
|
1488 contents.at(totalSize-2)='\n'; // to help the scanner |
|
1489 contents.at(totalSize-1)='\0'; |
|
1490 return contents; |
|
1491 } |
|
1492 } |
|
1493 else // read from file |
|
1494 { |
|
1495 QFileInfo fi(name); |
|
1496 if (!fi.exists() || !fi.isFile()) |
|
1497 { |
|
1498 config_err("Error: file `%s' not found\n",name); |
|
1499 return ""; |
|
1500 } |
|
1501 f.setName(name); |
|
1502 fileOpened=f.open(IO_ReadOnly); |
|
1503 if (fileOpened) |
|
1504 { |
|
1505 int fsize=f.size(); |
|
1506 QCString contents(fsize+2); |
|
1507 f.readBlock(contents.data(),fsize); |
|
1508 f.close(); |
|
1509 if (fsize==0 || contents[fsize-1]=='\n') |
|
1510 contents[fsize]='\0'; |
|
1511 else |
|
1512 contents[fsize]='\n'; // to help the scanner |
|
1513 contents[fsize+1]='\0'; |
|
1514 return contents; |
|
1515 } |
|
1516 } |
|
1517 if (!fileOpened) |
|
1518 { |
|
1519 config_err("Error: cannot open file `%s' for reading\n",name); |
|
1520 } |
|
1521 return ""; |
|
1522 } |
|
1523 |
|
1524 bool Config::parseString(const char *fn,const char *str) |
|
1525 { |
|
1526 config = Config::instance(); |
|
1527 inputString = str; |
|
1528 inputPosition = 0; |
|
1529 yyFileName = fn; |
|
1530 yyLineNr = 1; |
|
1531 includeStack.setAutoDelete(TRUE); |
|
1532 includeStack.clear(); |
|
1533 includeDepth = 0; |
|
1534 configYYrestart( configYYin ); |
|
1535 BEGIN( Start ); |
|
1536 configYYlex(); |
|
1537 inputString = 0; |
|
1538 return TRUE; |
|
1539 } |
|
1540 |
|
1541 bool Config::parse(const char *fn) |
|
1542 { |
|
1543 encoding = "UTF-8"; |
|
1544 return parseString(fn,configFileToString(fn)); |
|
1545 } |
|
1546 |
|
1547 extern "C" { // some bogus code to keep the compiler happy |
|
1548 //int configYYwrap() { return 1 ; } |
|
1549 } |