Debian Codegraph @

addon/doxywizard/config_doxyw.l

raw
1 /******************************************************************************
2 *
3 * Copyright (C) 1997-2019 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 */
12
13 %option never-interactive
14 %option prefix="config_doxywYY"
15 %top{
16 #include <stdint.h>
17 }
18
19 %{
20
21 /*
22 * includes
23 */
24 #include "config.h"
25 #include "input.h"
26 #include "inputbool.h"
27 #include "inputstring.h"
28 #include "inputobsolete.h"
29 #include "config_msg.h"
30
31 #include <QString>
32 #include <QVariant>
33 #include <QStack>
34 #include <QByteArray>
35 #include <QFileInfo>
36 #include <QStringList>
37 #include <QRegularExpression>
38 #include <QTextStream>
39 #include <QMessageBox>
40
41 #define YY_NO_UNISTD_H 1
42
43 #define MAX_INCLUDE_DEPTH 10
44
45 #define USE_STATE2STRING 0
46
47 /* -----------------------------------------------------------------
48 *
49 * static variables
50 */
51
52 struct ConfigFileState
53 {
54 int lineNr;
55 FILE *file;
56 YY_BUFFER_STATE oldState;
57 YY_BUFFER_STATE newState;
58 QString fileName;
59 };
60
61 static const QHash<QString,Input*> *g_options=nullptr;
62 static FILE *g_file=nullptr;
63 static QString g_yyFileName;
64 static QString g_includeName;
65 static QVariant g_includePathList;
66 static QStack<ConfigFileState*> g_includeStack;
67 static int g_includeDepth=0;
68 static QVariant *g_arg=nullptr;
69 static Input *g_curOption=nullptr;
70 static QByteArray g_str;
71 static std::unique_ptr<TextCodecAdapter> g_codec = std::make_unique<TextCodecAdapter>("UTF-8");
72 static QString g_codecName = QString::fromLatin1("UTF-8");
73 static QString g_cmd;
74 static bool g_isEnum=false;
75
76 static const char *stateToString(int state);
77
78 /* -----------------------------------------------------------------
79 */
80 #undef YY_INPUT
81 #define YY_INPUT(buf,result,max_size) result=yyread(buf,max_size);
82
83 static int yyread(char *buf,int maxSize)
84 {
85 // no file included
86 if (g_includeStack.isEmpty())
87 {
88 return static_cast<int>(fread(buf,1,maxSize,g_file));
89 }
90 else
91 {
92 return static_cast<int>(fread(buf,1,maxSize,g_includeStack.top()->file));
93 }
94 }
95
96 static void substEnvVarsInStrList(QStringList &sl);
97 static void substEnvVarsInString(QString &s);
98
99 static void checkEncoding()
100 {
101 Input *option = g_options->value(QString::fromLatin1("DOXYFILE_ENCODING"));
102 if (option && option->value().toString()!=g_codecName)
103 {
104 auto newCodec = std::make_unique<TextCodecAdapter>(option->value().toString().toLatin1());
105 if (newCodec->isValid())
106 {
107 g_codec.swap(newCodec);
108 g_codecName = option->value().toString();
109 }
110 }
111 }
112
113 static QByteArray stripComment(const QByteArray &s)
114 {
115 // check if there is a comment at the end of the string
116 bool insideQuote=false;
117 int l = s.length();
118 for (int i=0;i<l;i++)
119 {
120 char c = s.at(i);
121 if (c=='\\') // skip over escaped characters
122 {
123 i++;
124 }
125 else if (c=='"') // toggle inside/outside quotation
126 {
127 insideQuote=!insideQuote;
128 }
129 else if (!insideQuote && c=='#') // found start of a comment
130 {
131 return s.left(i).trimmed();
132 }
133 }
134 return s;
135 }
136
137
138 static void processString()
139 {
140 // strip leading and trailing whitespace
141 QByteArray s = stripComment(g_str.trimmed());
142 int l = s.length();
143
144 // remove surrounding quotes if present (and not escaped)
145 if (l>=2 && s.at(0)=='"' && s.at(l-1)=='"' && // remove quotes
146 (s.at(l-2)!='\\' || (s.at(l-2)=='\\' && s.at(l-3)=='\\')))
147 {
148 s=s.mid(1,s.length()-2);
149 l=s.length();
150 }
151
152 // check for invalid and/or escaped quotes
153 bool warned=false;
154 QByteArray result;
155 for (int i=0;i<l;i++)
156 {
157 char c = s.at(i);
158 if (c=='\\') // escaped character
159 {
160 if (i<l-1 && s.at(i+1)=='"') // unescape the quote character
161 {
162 result+='"';
163 }
164 else // keep other escaped characters in escaped form
165 {
166 result+=c;
167 if (i<l-1)
168 {
169 result+=s.at(i+1);
170 }
171 }
172 i++; // skip over the escaped character
173 }
174 else if (c=='"') // unescaped quote
175 {
176 if (!warned)
177 {
178 std::string str = g_str.trimmed().data();
179 config_warn("Invalid value for '%s' tag at line %d, file %s: Value '%s' is not properly quoted\n",
180 qPrintable(g_cmd),yylineno-1,qPrintable(g_yyFileName),str.c_str());
181 }
182 warned=true;
183 }
184 else // normal character
185 {
186 result+=c;
187 }
188 }
189
190 // recode the string
191 if (g_isEnum)
192 {
193 InputString *cur = dynamic_cast<InputString *>(g_curOption);
194 *g_arg = cur->checkEnumVal(g_codec->decode(result));
195 }
196 else
197 {
198 *g_arg = QVariant(g_codec->decode(result));
199 }
200
201 // update encoding
202 checkEncoding();
203
204 //printf("Processed string '%s'\n",g_string->data());
205 }
206
207 static void processList()
208 {
209 bool allowCommaAsSeparator = g_cmd!=QString::fromLatin1("PREDEFINED");
210
211 const QByteArray s = stripComment(g_str.trimmed());
212 int l = s.length();
213
214 QByteArray elemStr;
215
216 // helper to push elemStr to the list and clear it
217 auto addElem = [&elemStr]()
218 {
219 if (!elemStr.isEmpty())
220 {
221 //printf("Processed list element '%s'\n",e.data());
222 *g_arg = QVariant(g_arg->toStringList() << g_codec->decode(elemStr));
223 elemStr="";
224 }
225 };
226
227 bool needsSeparator=false;
228 int insideQuote=false;
229 bool warned=false;
230 for (int i=0;i<l;i++)
231 {
232 char c = s.at(i);
233 if (!needsSeparator && c=='\\') // escaped character
234 {
235 if (i<l-1 && s.at(i+1)=='"') // unescape the quote character
236 {
237 elemStr+='"';
238 }
239 else if (insideQuote && i<l-2 && s.at(i+1)=='\\' && s.at(i+2)=='"') // escaped "\" at the end of a quoted section
240 {
241 elemStr+="\\";
242 }
243 else // keep other escaped characters in escaped form
244 {
245 elemStr+=c;
246 if (i<l-1)
247 {
248 elemStr+=s.at(i+1);
249 }
250 }
251 i++; // skip over the escaped character
252 }
253 else if (!needsSeparator && c=='"') // quote character
254 {
255 if (!insideQuote)
256 {
257 insideQuote=true;
258 }
259 else // this quote ends an element
260 {
261 insideQuote=false;
262 needsSeparator=true;
263 }
264 }
265 else if (!insideQuote && ((c==',' && allowCommaAsSeparator) || isspace(c))) // separator
266 {
267 needsSeparator=false;
268 addElem();
269 }
270 else // normal content character
271 {
272 if (needsSeparator)
273 {
274 if (!warned)
275 {
276 std::string str = g_str.trimmed().data();
277 config_warn("Invalid value for '%s' tag at line %d, file %s: Values in list '%s' are not properly space %sseparated\n",
278 qPrintable(g_cmd),yylineno-1,qPrintable(g_yyFileName),str.c_str(),allowCommaAsSeparator?"or comma ":"");
279 warned=true;
280 }
281 needsSeparator=false;
282 i--; // try the character again as part of a new element
283 addElem();
284 }
285 else
286 {
287 elemStr+=c;
288 }
289 }
290 }
291 // add last part
292 addElem();
293 if (insideQuote)
294 {
295 std::string str = g_str.trimmed().data();
296 config_warn("Invalid value for '%s' tag at line %d, file %s: Values in list '%s' are not properly quoted\n",
297 qPrintable(g_cmd),yylineno-1,qPrintable(g_yyFileName),str.c_str());
298 }
299 }
300
301
302 static FILE *tryPath(const QString &path,const QString &fileName)
303 {
304 QString absName=!path.isEmpty() ? path+QString::fromLatin1("/")+fileName : fileName;
305 QFileInfo fi(absName);
306 if (fi.exists() && fi.isFile())
307 {
308 FILE *f = fopen(absName.toLocal8Bit(),"r");
309 if (f==nullptr)
310 config_err("could not open file %s for reading\n",qPrintable(absName));
311 else
312 return f;
313 }
314 return nullptr;
315 }
316
317 static FILE *findFile(const QString &fileName)
318 {
319 if (QFileInfo(fileName).isAbsolute()) // absolute path
320 {
321 return tryPath(QString(), fileName);
322 }
323
324 // relative path, try with include paths in the list
325 QStringList sl = g_includePathList.toStringList();
326 substEnvVarsInStrList(sl);
327 foreach (QString s, sl)
328 {
329 FILE *f = tryPath(s,fileName);
330 if (f) return f;
331 }
332 // try cwd if g_includePathList fails
333 return tryPath(QString::fromLatin1("."),fileName);
334 }
335
336 static void readIncludeFile(const QString &incName)
337 {
338 if (g_includeDepth==MAX_INCLUDE_DEPTH)
339 {
340 config_err("maximum include depth (%d) reached, %s is not included.",
341 MAX_INCLUDE_DEPTH,qPrintable(incName));
342 }
343
344 QString inc = incName;
345 substEnvVarsInString(inc);
346 inc = inc.trimmed();
347 uint incLen = inc.length();
348 if (inc.at(0)==QChar::fromLatin1('"') &&
349 inc.at(incLen-1)==QChar::fromLatin1('"')) // strip quotes
350 {
351 inc=inc.mid(1,incLen-2);
352 }
353
354 FILE *f = findFile(inc);
355 if (f) // see if the include file can be found
356 {
357 // For debugging
358 #if SHOW_INCLUDES
359 for (i=0;i<includeStack.count();i++) msg(" ");
360 msg("@INCLUDE = %s: parsing...\n",qPrintable(inc));
361 #endif
362
363 // store the state of the old file
364 ConfigFileState *fs=new ConfigFileState;
365 fs->oldState=YY_CURRENT_BUFFER;
366 fs->fileName=g_yyFileName;
367 fs->file=f;
368 // push the state on the stack
369 g_includeStack.push(fs);
370 // set the scanner to the include file
371 yy_switch_to_buffer(yy_create_buffer(f, YY_BUF_SIZE));
372 fs->newState=YY_CURRENT_BUFFER;
373 g_yyFileName=inc;
374 g_includeDepth++;
375 }
376 else
377 {
378 config_err("@INCLUDE = %s: not found!\n",qPrintable(inc));
379 }
380 }
381
382 #if USE_STATE2STRING
383 static const char *stateToString(int state);
384 #endif
385
386 %}
387
388 %option nounput
389 %option noyywrap
390 %option yylineno
391
392 %x Start
393 %x SkipInvalid
394 %x GetString
395 %x GetStrList
396 %x Include
397
398 %%
399
400 <*>\0x0d
401
402 /*-------------- Comments ---------------*/
403
404 <Start>"#".*\n { /* Skip comment */ }
405
406 /*-------------- TAG start ---------------*/
407
408 <Start>[a-z_A-Z][a-z_A-Z0-9]*[ \t]*"=" {
409 g_cmd = g_codec->decode(yytext);
410 g_cmd=g_cmd.left(g_cmd.length()-1).trimmed();
411 g_curOption = g_options->value(g_cmd);
412 if (g_curOption==nullptr) // oops not known
413 {
414 config_warn("ignoring unsupported tag '%s' at line %d, file %s\n",
415 qPrintable(g_cmd),yylineno,qPrintable(g_yyFileName));
416 BEGIN(SkipInvalid);
417 }
418 else // known tag
419 {
420 g_arg = &g_curOption->value();
421 g_str = QByteArray();
422 g_isEnum = false;
423 switch(g_curOption->kind())
424 {
425 case Input::StrList:
426 *g_arg = QStringList();
427 BEGIN(GetStrList);
428 break;
429 case Input::String:
430 g_isEnum = dynamic_cast<InputString *>(g_curOption)->stringMode() == InputString::StringFixed;
431 BEGIN(GetString);
432 break;
433 case Input::Int:
434 BEGIN(GetString);
435 break;
436 case Input::Bool:
437 BEGIN(GetString);
438 break;
439 case Input::Obsolete:
440 {
441 config_warn("Tag '%s' at line %d of file %s has become obsolete.\n"
442 "To avoid this warning please update your configuration "
443 "file using \"doxygen -u\"\n", qPrintable(g_cmd),
444 yylineno,qPrintable(g_yyFileName));
445 InputObsolete *obsoleteOpt = dynamic_cast<InputObsolete*>(g_curOption);
446 if (obsoleteOpt)
447 {
448 if (obsoleteOpt->orgKind()==Input::StrList)
449 {
450 *g_arg = QStringList();
451 BEGIN(GetStrList);
452 }
453 else
454 {
455 BEGIN(GetString);
456 }
457 }
458 else
459 {
460 BEGIN(SkipInvalid);
461 }
462 }
463 break;
464 }
465 }
466 }
467 <Start>[a-z_A-Z][a-z_A-Z0-9]*[ \t]*"+=" {
468 g_cmd=g_codec->decode(yytext);
469 g_cmd=g_cmd.left(g_cmd.length()-2).trimmed();
470 g_curOption = g_options->value(g_cmd);
471 if (g_curOption==nullptr) // oops not known
472 {
473 config_warn("ignoring unsupported tag '%s' at line %d, file %s\n",
474 yytext,yylineno,qPrintable(g_yyFileName));
475 BEGIN(SkipInvalid);
476 }
477 else // known tag
478 {
479 switch(g_curOption->kind())
480 {
481 case Input::StrList:
482 g_arg = &g_curOption->value();
483 g_str=QByteArray();
484 BEGIN(GetStrList);
485 break;
486 case Input::String:
487 case Input::Int:
488 case Input::Bool:
489 config_warn("operator += not supported for '%s'. Ignoring line %d, file %s\n",
490 qPrintable(g_cmd),yylineno,qPrintable(g_yyFileName));
491 BEGIN(SkipInvalid);
492 break;
493 case Input::Obsolete:
494 {
495 config_warn("Tag '%s' at line %d of file %s has become obsolete.\n"
496 "To avoid this warning please update your configuration "
497 "file using \"doxygen -u\"\n",
498 qPrintable(g_cmd),yylineno,qPrintable(g_yyFileName));
499 InputObsolete *obsoleteOpt = dynamic_cast<InputObsolete*>(g_curOption);
500 if (obsoleteOpt && obsoleteOpt->orgKind()==Input::StrList)
501 {
502 g_arg = &g_curOption->value();
503 g_str=QByteArray();
504 BEGIN(GetStrList);
505 }
506 else
507 {
508 BEGIN(SkipInvalid);
509 }
510 }
511 break;
512 }
513 }
514 }
515
516 /*-------------- INCLUDE* ---------------*/
517
518 <Start>"@INCLUDE_PATH"[ \t]*"=" { BEGIN(GetStrList); g_arg=&g_includePathList; *g_arg = QStringList(); g_str=QByteArray(); }
519 /* include a config file */
520 <Start>"@INCLUDE"[ \t]*"=" { BEGIN(Include);}
521 <Include>([^ \"\t\r\n]+)|("\""[^\n\"]+"\"") {
522 readIncludeFile(g_codec->decode(yytext));
523 BEGIN(Start);
524 }
525 <<EOF>> {
526 //printf("End of include file\n");
527 //printf("Include stack depth=%d\n",g_includeStack.count());
528 if (g_includeStack.isEmpty())
529 {
530 //printf("Terminating scanner!\n");
531 yyterminate();
532 }
533 else
534 {
535 ConfigFileState *fs = g_includeStack.pop();
536 fclose(fs->file);
537 YY_BUFFER_STATE oldBuf = YY_CURRENT_BUFFER;
538 yy_switch_to_buffer( fs->oldState );
539 yy_delete_buffer( oldBuf );
540 g_yyFileName=fs->fileName;
541 delete fs;
542 g_includeDepth--;
543 }
544 }
545
546 <Start>[a-z_A-Z0-9]+ { config_warn("ignoring unknown tag '%s' at line %d, file %s\n",yytext,yylineno,qPrintable(g_yyFileName)); }
547
548 /*-------------- GetString ---------------*/
549
550 <GetString>\n { // end of string
551 processString();
552 BEGIN(Start);
553 }
554 <GetString>\\[ \r\t]*\n { // line continuation
555 g_str+=' ';
556 }
557 <GetString>"\\" { // escape character
558 g_str+=yytext;
559 }
560 <GetString>[^\n\\]+ { // string part without escape characters
561 g_str+=yytext;
562 }
563
564 /*-------------- GetStrList ---------------*/
565
566 <GetStrList>\n { // end of list
567 processList();
568 BEGIN(Start);
569 }
570 <GetStrList>\\[ \r\t]*\n { // line continuation
571 g_str+=' ';
572 }
573 <GetStrList>"\\" { // escape character
574 g_str+=yytext;
575 }
576 <GetStrList>[^\n\\]+ { // string part without escape characters
577 g_str+=yytext;
578 }
579
580 /*-------------- SkipInvalid ---------------*/
581
582 <SkipInvalid>\n { // end of skipped part
583 BEGIN(Start);
584 }
585 <SkipInvalid>\\[ \r\t]*\n { // line continuation
586 g_str+=' ';
587 }
588 <SkipInvalid>"\\" { // escape character
589 g_str+=yytext;
590 }
591 <SkipInvalid>[^\n\\]+ { // string part without escape characters
592 g_str+=yytext;
593 }
594
595 /*-------------- fall through -------------*/
596
597 <*>\\[ \r\t]*\n { }
598 <*>[ \r\t] { }
599 <*>\n
600 <*>. { config_warn("ignoring unknown character '%c' at line %d, file %s\n",yytext[0],yylineno,qPrintable(g_yyFileName)); }
601
602 %%
603
604 /*@ ----------------------------------------------------------------------------
605 */
606
607 static void substEnvVarsInString(QString &s)
608 {
609 static QRegularExpression re(QString::fromLatin1("\\$\\([a-z_A-Z0-9]+\\)"));
610 if (s.isEmpty()) return;
611 int p=0;
612 int i,l;
613 //printf("substEnvVarInString(%s) start\n",qPrintable(s));
614
615 QRegularExpressionMatch match;
616 while ((i=s.indexOf(re,p,&match))!=-1)
617 {
618 l = match.capturedLength();
619 //printf("Found environment var s.mid(%d,%d)='%s'\n",i+2,l-3,qPrintable(s.mid(i+2,l-3)));
620 QString env=g_codec->decode(getenv(s.mid(i+2,l-3).toLatin1()));
621 substEnvVarsInString(env); // recursively expand variables if needed.
622 s = s.left(i)+env+s.right(s.length()-i-l);
623 p=i+env.length(); // next time start at the end of the expanded string
624 }
625 s=s.trimmed(); // to strip the bogus space that was added when an argument
626 // has quotes
627 //printf("substEnvVarInString(%s) end\n",qPrintable(s));
628 }
629
630 static void substEnvVarsInStrList(QStringList &sl)
631 {
632 QStringList out;
633
634 foreach (QString result, sl)
635 {
636 // an argument with quotes will have an extra space at the end, so wasQuoted will be TRUE.
637 bool wasQuoted = (result.indexOf(QChar::fromLatin1(' '))!=-1) ||
638 (result.indexOf(QChar::fromLatin1('\t'))!=-1);
639 // here we strip the quote again
640 substEnvVarsInString(result);
641
642 //printf("Result %s was quoted=%d\n",qPrintable(result),wasQuoted);
643
644 if (!wasQuoted) /* as a result of the expansion, a single string
645 may have expanded into a list, which we'll
646 add to sl. If the original string already
647 contained multiple elements no further
648 splitting is done to allow quoted items with spaces! */
649 {
650 int l=result.length();
651 int i,p=0;
652 // skip spaces
653 // search for a "word"
654 for (i=0;i<l;i++)
655 {
656 QChar c;
657 // skip until start of new word
658 while (i<l && ((c=result.at(i))==QChar::fromLatin1(' ') || c==QChar::fromLatin1('\t'))) i++;
659 p=i; // p marks the start index of the word
660 // skip until end of a word
661 while (i<l && ((c=result.at(i))!=QChar::fromLatin1(' ') &&
662 c!=QChar::fromLatin1('\t') &&
663 c!=QChar::fromLatin1('"'))) i++;
664 if (i<l) // not at the end of the string
665 {
666 if (c==QChar::fromLatin1('"')) // word within quotes
667 {
668 p=i+1;
669 for (i++;i<l;i++)
670 {
671 c=result.at(i);
672 if (c==QChar::fromLatin1('"')) // end quote
673 {
674 out += result.mid(p,i-p);
675 p=i+1;
676 break;
677 }
678 else if (c==QChar::fromLatin1('\\')) // skip escaped stuff
679 {
680 i++;
681 }
682 }
683 }
684 else if (c==QChar::fromLatin1(' ') || c==QChar::fromLatin1('\t')) // separator
685 {
686 out += result.mid(p,i-p);
687 p=i+1;
688 }
689 }
690 }
691 if (p!=l) // add the leftover as a string
692 {
693 out += result.right(l-p);
694 }
695 }
696 else // just goto the next element in the list
697 {
698 out += result;
699 }
700 }
701 sl = out;
702 }
703
704 //--------------------------------------------------------------------------
705
706 static void upgradeConfig(const QHash<QString,Input*> &options)
707 {
708 auto it1 = options.find(QString::fromLatin1("CLASS_DIAGRAMS"));
709 auto it2 = options.find(QString::fromLatin1("HAVE_DOT"));
710 auto it3 = options.find(QString::fromLatin1("CLASS_GRAPH"));
711 if (it1!=options.end() && it2!=options.end() && it3!=options.end())
712 {
713 if ((*it1)->kind()==Input::Obsolete)
714 {
715 InputObsolete *optClassDiagram = dynamic_cast<InputObsolete*>(*it1);
716 InputBool *optHaveDot = dynamic_cast<InputBool*> (*it2);
717 InputString *optClassGraph = dynamic_cast<InputString*> (*it3);
718 if (optClassDiagram->orgKind()==Input::Bool)
719 {
720 const QVariant &v1 = optClassDiagram->value();
721 const QVariant &v2 = optHaveDot->value();
722 QVariant &v3 = optClassGraph->value();
723 bool isValid1=false,isValid2=false,isValid3=false;
724 bool classDiagrams = InputBool::convertToBool(v1,isValid1);
725 bool haveDot = InputBool::convertToBool(v2,isValid2);
726 bool classGraph = InputBool::convertToBool(v3,isValid3);
727 if (isValid1 && isValid2 && isValid3 && !classDiagrams && !haveDot && classGraph)
728 {
729 config_warn("Changing CLASS_GRAPH option to TEXT because obsolete option CLASS_DIAGRAM was found and set to NO.\n");
730 optClassGraph->setValue(QString::fromLatin1("TEXT"));
731 }
732 }
733 }
734 }
735 }
736
737 //--------------------------------------------------------------------------
738
739 bool parseConfig(
740 const QString &fileName,
741 const QHash<QString,Input *> &options
742 )
743 {
744 yylineno = 1;
745 config_open();
746 QHashIterator<QString, Input*> i(options);
747 g_file = fopen(fileName.toLocal8Bit(),"r");
748 if (g_file==nullptr) return false;
749
750 // reset all values
751 i.toFront();
752 while (i.hasNext())
753 {
754 i.next();
755 if (i.value())
756 {
757 i.value()->reset();
758 }
759 }
760
761 // parse config file
762 g_options = &options;
763 g_yyFileName = fileName;
764 g_includeStack.clear();
765 g_includeDepth = 0;
766 config_doxywYYrestart( config_doxywYYin );
767 BEGIN( Start );
768 config_doxywYYlex();
769
770 upgradeConfig(options);
771
772 // update the values in the UI
773 i.toFront();
774 while (i.hasNext())
775 {
776 i.next();
777 if (i.value())
778 {
779 //printf("Updating: %s\n",qPrintable(i.key()));
780 i.value()->update();
781 }
782 else
783 {
784 printf("Invalid option: %s\n",qPrintable(i.key()));
785 }
786 }
787 fclose(g_file);
788 config_finish();
789 return true;
790 }
791
792 void writeStringValue(QTextStream &t,TextCodecAdapter *codec,const QString &s,bool convert)
793 {
794 QChar c;
795 bool needsEscaping=false;
796 bool needsHashEscaping=false;
797 // convert the string back to it original encoding
798 codec->applyToStream(t);
799 const QChar *p=s.data();
800 if (!s.isEmpty() && !p->isNull())
801 {
802 if (*p != QChar::fromLatin1('"'))
803 {
804 while (!(c=*p++).isNull() && !needsEscaping)
805 {
806 needsEscaping = (c==QChar::fromLatin1(' ') ||
807 c==QChar::fromLatin1(',') ||
808 c==QChar::fromLatin1('\n') ||
809 c==QChar::fromLatin1('\t') ||
810 c==QChar::fromLatin1('\\') ||
811 c==QChar::fromLatin1('"'));
812 }
813 p=s.data();
814 while (!(c=*p++).isNull() && !needsHashEscaping)
815 {
816 needsHashEscaping = (c==QChar::fromLatin1('#'));
817 }
818 }
819 if (needsHashEscaping || needsEscaping)
820 {
821 t << "\"";
822 }
823 if (needsEscaping)
824 {
825 p=s.data();
826 while (!p->isNull())
827 {
828 if (*p ==QChar::fromLatin1(' ') &&
829 *(p+1)==QChar::fromLatin1('\0')) break; // skip inserted space at the end
830 if (*p ==QChar::fromLatin1('"')) t << "\\"; // escape quotes
831 if (*p ==QChar::fromLatin1('\\') && (p+1)->isNull()) t << "\\"; // escape last "\", for e.g c:\temp\ where "\" is part of the path
832 if (convert)
833 {
834 if (*p ==QChar::fromLatin1('<')) t << "&lt;";
835 else if (*p ==QChar::fromLatin1('>')) t << "&gt;";
836 else if (*p ==QChar::fromLatin1('&')) t << "&amp;";
837 else t << *p;
838 }
839 else
840 {
841 t << *p;
842 }
843 p++;
844 }
845 }
846 else
847 {
848 p=s.data();
849 while (!p->isNull())
850 {
851 if (convert)
852 {
853 if (*p ==QChar::fromLatin1('<')) t << "&lt;";
854 else if (*p ==QChar::fromLatin1('>')) t << "&gt;";
855 else if (*p ==QChar::fromLatin1('&')) t << "&amp;";
856 else t << *p;
857 }
858 else
859 {
860 t << *p;
861 }
862 p++;
863 }
864 }
865 if (needsHashEscaping || needsEscaping)
866 {
867 t << "\"";
868 }
869 }
870 }
871 #if USE_STATE2STRING
872 #include "config_doxyw.l.h"
873 #endif