/****************************************************************************** * * Copyright (C) 1997-2012 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. * */ %{ /* * includes */ #include #include #include #include #include #include #include #include #include #include #include #include #include "config.h" #include "version.h" #include "portable.h" #include "util.h" #include "lang_cfg.h" #include "configoptions.h" #undef Config_getString #undef Config_getInt #undef Config_getList #undef Config_getEnum #undef Config_getBool #define YY_NO_INPUT 1 // 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); } static QCString configStringRecode( const QCString &str, const char *fromEncoding, const char *toEncoding); #define MAX_INCLUDE_DEPTH 10 #define YY_NEVER_INTERACTIVE 1 /* ----------------------------------------------------------------- */ QCString ConfigOption::convertToComment(const QCString &s) { QCString result; if (s.isEmpty()) return result; else { QCString tmp=s.stripWhiteSpace(); char *p=tmp.data(); char c; result+="#"; if (*p && *p!='\n') result+=" "; while ((c=*p++)) { if (c=='\n') { result+="\n#"; if (*p && *p!='\n') result+=" "; } else result+=c; } result+='\n'; } return result; } void ConfigOption::writeBoolValue(FTextStream &t,bool v) { t << " "; if (v) t << "YES"; else t << "NO"; } void ConfigOption::writeIntValue(FTextStream &t,int i) { t << " " << i; } void ConfigOption::writeStringValue(FTextStream &t,QCString &s) { char c; bool needsEscaping=FALSE; // convert the string back to it original encoding QCString se = configStringRecode(s,"UTF-8",m_encoding); const char *p=se.data(); if (p) { t << " "; while ((c=*p++)!=0 && !needsEscaping) needsEscaping = (c==' ' || c=='\n' || c=='\t' || c=='"' || c=='#'); if (needsEscaping) { t << "\""; p=se.data(); while (*p) { if (*p==' ' && *(p+1)=='\0') break; // skip inserted space at the end if (*p=='"') t << "\\"; // escape quotes t << *p++; } t << "\""; } else { t << se; } } } void ConfigOption::writeStringList(FTextStream &t,QStrList &l) { const char *p = l.first(); bool first=TRUE; while (p) { QCString s=p; if (!first) t << " "; first=FALSE; writeStringValue(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 || valm_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" || val=="all") { m_value=TRUE; } else if (val=="no" || val=="false" || val=="0" || val=="none") { 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(); } /* ----------------------------------------------------------------- */ void ConfigInt::writeXML(FTextStream& t) { t << " " << endl; } void ConfigList::writeXML(FTextStream &t) { 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 << " " << endl; } void ConfigObsolete::writeXML(FTextStream &t) { t << "