📄 config.cpp
字号:
/* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. */#define REJECT reject_used_but_not_detected#define yymore() yymore_used_but_not_detected#define YY_MORE_ADJ 0#define YY_RESTORE_YY_MORE_OFFSETchar *yytext;#line 1 "config.l"#define INITIAL 0/****************************************************************************** * * $Id: config_templ.l,v 1.8 2001/01/01 10:15:16 root Exp $ * * Copyright (C) 1997-2001 by Dimitri van Heesch. * * 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. * */#line 16 "config.l"/* * includes */#include <stdio.h>#include <stdlib.h>//#include <iostream.h>#include <assert.h>#include <ctype.h>#include <stdarg.h>#include <qfileinfo.h>#include <qdir.h>#include <qtextstream.h>#include <qregexp.h>#include <qstack.h> #include "config.h"#include "version.h"#undef Config_getString#undef Config_getInt#undef Config_getList#undef Config_getEnum#undef Config_getBool// 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) void config_err(const char *fmt, ...){ va_list args; va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args); }void config_warn(const char *fmt, ...){ va_list args; va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args);}#define MAX_INCLUDE_DEPTH 10#define YY_NEVER_INTERACTIVE 1#define YY_NO_UNPUT/* ----------------------------------------------------------------- */QCString ConfigOption::convertToComment(const QCString &s){ QCString result; if (s.isEmpty()) return result; else { result+="# "; QCString tmp=s.stripWhiteSpace(); char *p=tmp.data(); char c; while ((c=*p++)) { if (c=='\n') result+="\n# "; else result+=c; } result+='\n'; } return result;}void ConfigOption::writeBoolValue(QTextStream &t,bool v){ if (v) t << "YES"; else t << "NO";}void ConfigOption::writeIntValue(QTextStream &t,int i){ t << i;}void ConfigOption::writeStringValue(QTextStream &t,QCString &s){ const char *p=s.data(); char c; bool hasBlanks=FALSE; if (p) { while ((c=*p++)!=0 && !hasBlanks) hasBlanks = (c==' ' || c=='\n' || c=='\t'); if (hasBlanks) t << "\"" << s << "\""; else t << s; }}void ConfigOption::writeStringList(QTextStream &t,QStrList &l){ const char *p = l.first(); bool first=TRUE; while (p) { char c; const char *s=p; bool hasBlanks=FALSE; while ((c=*p++)!=0 && !hasBlanks) hasBlanks = (c==' ' || c=='\n' || c=='\t'); if (!first) t << " "; first=FALSE; if (hasBlanks) t << "\"" << s << "\""; else t << s; p = l.next(); if (p) t << " \\" << endl; }}/* ----------------------------------------------------------------- */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) { config_warn("Warning: argument `%s' for option %s is not a valid number in the range [%d..%d]!\n" "Using the default: %d!\n",m_valueString.data(),m_name.data(),m_minVal,m_maxVal,m_value); } m_value=val; }}void ConfigBool::convertStrToVal(){ QCString val = m_valueString.stripWhiteSpace().lower(); if (!val.isEmpty()) { if (val=="yes" || val=="true" || val=="1") { m_value=TRUE; } else if (val=="no" || val=="false" || val=="0") { m_value=FALSE; } else { config_warn("Warning: argument `%s' for option %s is not a valid boolean value\n" "Using the default: %s!\n",m_valueString.data(),m_name.data(),m_value?"YES":"NO"); } }}QCString &Config::getString(const char *fileName,int num,const char *name) const{ ConfigOption *opt = m_dict->find(name); if (opt==0) { config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name); exit(1); } else if (opt->kind()!=ConfigOption::O_String) { config_err("%s<%d>: Internal error: Requested option %s not of string type!\n",fileName,num,name); exit(1); } return *((ConfigString *)opt)->valueRef();}QStrList &Config::getList(const char *fileName,int num,const char *name) const{ ConfigOption *opt = m_dict->find(name); if (opt==0) { config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name); exit(1); } else if (opt->kind()!=ConfigOption::O_List) { config_err("%d<%d>: Internal error: Requested option %s not of list type!\n",fileName,num,name); exit(1); } return *((ConfigList *)opt)->valueRef();}QCString &Config::getEnum(const char *fileName,int num,const char *name) const{ ConfigOption *opt = m_dict->find(name); if (opt==0) { config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name); exit(1); } else if (opt->kind()!=ConfigOption::O_Enum) { config_err("%s<%d>: Internal error: Requested option %s not of enum type!\n",fileName,num,name); exit(1); } return *((ConfigEnum *)opt)->valueRef();}int &Config::getInt(const char *fileName,int num,const char *name) const{ ConfigOption *opt = m_dict->find(name); if (opt==0) { config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name); exit(1); } else if (opt->kind()!=ConfigOption::O_Int) { config_err("%s<%d>: Internal error: Requested option %s not of integer type!\n",fileName,num,name); exit(1); } return *((ConfigInt *)opt)->valueRef();}bool &Config::getBool(const char *fileName,int num,const char *name) const{ ConfigOption *opt = m_dict->find(name); if (opt==0) { config_err("%s<%d>: Internal error: Requested unknown option %s!\n",fileName,num,name); exit(1); } else if (opt->kind()!=ConfigOption::O_Bool) { config_err("%s<%d>: Internal error: Requested option %s not of integer type!\n",fileName,num,name); exit(1); } return *((ConfigBool *)opt)->valueRef();}/* ----------------------------------------------------------------- * * static variables */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;static QCString tabSizeString;static QCString maxInitLinesString;static QCString colsInAlphaIndexString;static QCString enumValuesPerLineString;static QCString treeViewWidthString;static QCString maxDotGraphWidthString;static QCString maxDotGraphHeightString;static Config *config;/* ----------------------------------------------------------------- */#undef YY_INPUT#define YY_INPUT(buf,result,max_size) result=yyread(buf,max_size);static int yyread(char *buf,int max_size){ // no file included if (includeStack.isEmpty()) { int c=0; while( c < max_size && inputString[inputPosition] ) { *buf = inputString[inputPosition++] ; c++; buf++; } return c; } else { //assert(includeStack.current()->newState==YY_CURRENT_BUFFER); return fread(buf,1,max_size,includeStack.current()->filePtr); }}static FILE *tryPath(const char *path,const char *fileName){ QCString absName=(QCString)path+"/"+fileName; QFileInfo fi(absName); if (fi.exists() && fi.isFile()) { FILE *f=fopen(absName,"r"); if (!f) config_err("Error: could not open file %s for reading\n",absName.data()); return f; } return 0;}static void substEnvVarsInStrList(QStrList &sl);static void substEnvVarsInString(QCString &s);static FILE *findFile(const char *fileName){ substEnvVarsInStrList(includePathList); 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) { config_err("Error: maximum include depth (%d) reached, %s is not included. Aborting...\n", MAX_INCLUDE_DEPTH,incName); exit(1); } QCString inc = incName; substEnvVarsInString(inc); inc = inc.stripWhiteSpace(); uint incLen = inc.length(); if (inc.at(0)=='"' && inc.at(incLen-1)=='"') // strip quotes { inc=inc.mid(1,incLen-2); } FILE *f; //printf("Searching for `%s'\n",incFileName.data()); 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 { config_err("Error: @INCLUDE = %s: not found!\n",inc.data()); exit(1); }}#define Start 1#define SkipComment 2#define SkipInvalid 3#define GetString 4#define GetBool 5#define GetStrList 6#define GetQuotedString 7#define GetEnvVar 8#define Include 9/* Macros after this point can all be overridden by user definitions in * section 1. */#ifndef YY_SKIP_YYWRAP#ifdef __cplusplusextern "C" int yywrap YY_PROTO(( void ));#elseextern int yywrap YY_PROTO(( void ));#endif#endif#ifndef YY_NO_UNPUTstatic void yyunput YY_PROTO(( int c, char *buf_ptr ));#endif#ifndef yytext_ptrstatic void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int ));#endif#ifdef YY_NEED_STRLENstatic int yy_flex_strlen YY_PROTO(( yyconst char * ));#endif#ifndef YY_NO_INPUT#ifdef __cplusplusstatic int yyinput YY_PROTO(( void ));#elsestatic int input YY_PROTO(( void ));#endif#endif#if YY_STACK_USEDstatic int yy_start_stack_ptr = 0;static int yy_start_stack_depth = 0;static int *yy_start_stack = 0;#ifndef YY_NO_PUSH_STATEstatic void yy_push_state YY_PROTO(( int new_state ));#endif#ifndef YY_NO_POP_STATEstatic void yy_pop_state YY_PROTO(( void ));#endif#ifndef YY_NO_TOP_STATEstatic int yy_top_state YY_PROTO(( void ));#endif#else#define YY_NO_PUSH_STATE 1#define YY_NO_POP_STATE 1#define YY_NO_TOP_STATE 1#endif#ifdef YY_MALLOC_DECLYY_MALLOC_DECL#else#if __STDC__#ifndef __cplusplus#include <stdlib.h>#endif#else/* Just try to get by without declaring the routines. This will fail * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int) * or sizeof(void*) != sizeof(int). */#endif#endif/* Amount of stuff to slurp up with each read. */#ifndef YY_READ_BUF_SIZE#define YY_READ_BUF_SIZE 8192#endif/* Copy whatever the last rule matched to the standard output. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -