QString Parser::compileUsage(QString progName, bool useFlags) { QStringList usage; usage << "Usage: " << progName; QString optPrefix, flagPrefix; d_ptr->getPrefix(optPrefix, flagPrefix); // options for (QListIterator<ParameterDefinition *> it(d_ptr->m_options); it.hasNext();) { ParameterDefinition *param = it.next(); bool required = isRequired(param); if (!required) usage << " ["; if (!param->flags.isEmpty() && useFlags) usage << flagPrefix << param->flags[0]; else usage << optPrefix << param->name; if (param->type == DefinitionType::Option) usage << ((d_ptr->m_argStyle == ArgumentStyle::Equals) ? "=" : " ") << param->meta; if (!required) usage << "]"; } // arguments for (QListIterator<ParameterDefinition *> it(d_ptr->m_positionals); it.hasNext();) { ParameterDefinition *param = it.next(); usage << " "; bool required = isRequired(param); usage << (required ? "<" : "[") << param->meta << (required ? ">" : "]"); } return usage.join(""); }
bool ExtArgText::isValid() { bool valid = true; if ( isRequired() && value().length() == 0 ) valid = false; /* validation should only be checked if there is a value. if the argument * must be present (isRequired) the check above will handle that */ if ( valid && _argument->regexp != NULL && value().length() > 0) { QString regexp = QString().fromUtf8(_argument->regexp); if ( regexp.length() > 0 ) { QRegExp expr(regexp); if ( ! expr.isValid() || expr.indexIn(value(), 0) == -1 ) valid = false; } } QString lblInvalidColor = ColorUtils::fromColorT(prefs.gui_text_invalid).name(); QString txtStyle("QLineEdit { background-color: %1; } "); textBox->setStyleSheet( txtStyle.arg(valid ? QString("") : lblInvalidColor) ); return valid; }
inline void QtXorArg::check() const { if( isRequired() && !isDefined() ) throw QtArgNotDefinedMandatoryArgumentEx( QString::fromLatin1( "Not defined mandatory argument: %1" ) .arg( m_name ) ); QString definedArgumentName; foreach( QtArgIface * arg, m_args ) { arg->check(); if( arg->isDefined() && !definedArgumentName.isEmpty() ) throw QtArgXORMaskNotObservedEx( QString::fromLatin1( "Defined more than one argument under XOR mask." " First defined argument: %1. Second defined argument: %2." ) .arg( definedArgumentName ) .arg( arg->names().size() ? arg->names().front() : arg->flags().front() ) ); if( arg->isDefined() ) definedArgumentName = ( arg->names().size() ? arg->names().front() : arg->flags().front() ); }
string const LaTeXFeatures::getColorOptions() const { ostringstream colors; // Handling the color packages separately is needed to be able to load them // before babel when hyperref is loaded with the colorlinks option // for more info see Bufferparams.cpp // [x]color.sty if (mustProvide("color") || mustProvide("xcolor")) { string const package = (mustProvide("xcolor") ? "xcolor" : "color"); if (params_.graphicsDriver == "default" || params_.graphicsDriver == "none") colors << "\\usepackage{" << package << "}\n"; else colors << "\\usepackage[" << params_.graphicsDriver << "]{" << package << "}\n"; } // pdfcolmk must be loaded after color if (mustProvide("pdfcolmk")) colors << "\\usepackage{pdfcolmk}\n"; // the following 3 color commands must be set after color // is loaded and before pdfpages, therefore add the command // here define the set color if (mustProvide("pagecolor")) { colors << "\\definecolor{page_backgroundcolor}{rgb}{"; colors << outputLaTeXColor(params_.backgroundcolor) << "}\n"; // set the page color colors << "\\pagecolor{page_backgroundcolor}\n"; } if (mustProvide("fontcolor")) { colors << "\\definecolor{document_fontcolor}{rgb}{"; colors << outputLaTeXColor(params_.fontcolor) << "}\n"; // set the color colors << "\\color{document_fontcolor}\n"; } if (mustProvide("lyxgreyedout")) { colors << "\\definecolor{note_fontcolor}{rgb}{"; colors << outputLaTeXColor(params_.notefontcolor) << "}\n"; // the color will be set together with the definition of // the lyxgreyedout environment (see lyxgreyedout_def) } // color for shaded boxes if (isRequired("framed") && mustProvide("color")) { colors << "\\definecolor{shadecolor}{rgb}{"; colors << outputLaTeXColor(params_.boxbgcolor) << "}\n"; // this color is automatically used by the LaTeX-package "framed" } return colors.str(); }
bool PhiAnalysis::isRequiredAfter(const std::string &name, CFGBlock* block) { // If there are multiple successors, then none of them are allowed // to require any phi nodes if (block->successors.size() != 1) return false; // Fall back to the other method: return isRequired(name, block->successors[0]); }
bool ExtcapArgument::isValid() { /* Unrequired arguments are always valid, except if validity checks fail, * which must be checked in an derived class, not here */ if ( ! isRequired() ) return true; return value().length() > 0; }
void AbstractOptionStorage::finish() { GMX_RELEASE_ASSERT(!bInSet_, "finishSet() not called"); processAll(); if (isRequired() && !(isSet() || hasFlag(efOption_ExplicitDefaultValue))) { GMX_THROW(InvalidInputError("Option is required, but not set")); } }
bool ExtArgTimestamp::isValid() { bool valid = true; if ( value().length() == 0 && isRequired() ) valid = false; return valid; }
bool PhiAnalysis::isRequiredAfter(int vreg, CFGBlock* block) { assert(vreg >= 0); // If there are multiple successors, then none of them are allowed // to require any phi nodes if (block->successors.size() != 1) return false; // Fall back to the other method: return isRequired(vreg, block->successors[0]); }
bool ExtArgSelector::isValid() { bool valid = true; if ( value().length() == 0 && isRequired() ) valid = false; QString lblInvalidColor = ColorUtils::fromColorT(prefs.gui_text_invalid).name(); QString cmbBoxStyle("QComboBox { background-color: %1; } "); boxSelection->setStyleSheet( cmbBoxStyle.arg(valid ? QString("") : lblInvalidColor) ); return valid; }
FileNameOptionStorage::FileNameOptionStorage(const FileNameOption &settings) : MyBase(settings), info_(this), filetype_(settings.filetype_), bRead_(settings.bRead_), bWrite_(settings.bWrite_), bLibrary_(settings.bLibrary_) { if (settings.defaultBasename_ != NULL) { if (isRequired()) { setDefaultValue(completeFileName(settings.defaultBasename_, filetype_, false)); } else { setDefaultValueIfSet(completeFileName(settings.defaultBasename_, filetype_, false)); } } }
QWidget * ExtcapArgument::createLabel(QWidget * parent) { if ( _argument == 0 || _argument->display == 0 ) return 0; QString lblInvalidColor = ColorUtils::fromColorT(prefs.gui_text_invalid).name(); QString text = QString().fromUtf8(_argument->display); _label = new QLabel(text, parent); _label->setProperty("isRequired", QString(isRequired() ? "true" : "false")); _label->setStyleSheet ( label_style.arg(QString("")) ); if ( _argument->tooltip != 0 ) _label->setToolTip(QString().fromUtf8(_argument->tooltip)); return _label; }
bool ExtArgRadio::isValid() { bool valid = true; int idx = 0; if ( isRequired() ) { if ( selectorGroup == 0 || callStrings == 0 ) valid = false; else { idx = selectorGroup->checkedId(); if ( idx == -1 || callStrings->length() <= idx ) valid = false; } } /* If nothing is selected, but a selection is required, the only thing that * can be marked is the label */ QString lblInvalidColor = ColorUtils::fromColorT(prefs.gui_text_invalid).name(); _label->setStyleSheet ( label_style.arg(valid ? QString("") : lblInvalidColor) ); return valid; }
ISchemaElementInstance::SharedPtrTyp SchemaMap::newInstance() const { return ISchemaElementInstance::SharedPtrTyp(new Instance(*this, isRequired())); }
BOOL COcsNotifyUserApp::parseCommandLine() { CString csTimeOut; // /DEBUG if (isRequired( m_lpCmdLine, _T( "debug"))) m_pLogger->setLogLevel( LOG_PRIORITY_DEBUG); // Notification type if (isRequired( m_lpCmdLine, _T( "preinstall"))) { // Show preinstall dialog box /PREINSTALL m_uNotifcation = NOTIFY_TYPE_PREINSTALL; } else if (isRequired( m_lpCmdLine, _T( "asktag"))) { // Show askTag dialog box /ASKTAG m_uNotifcation = NOTIFY_TYPE_ASKTAG; // Ensure /FILE is provided if (isRequired( m_lpCmdLine, _T( "file"))) m_csFile = getParamValue( m_lpCmdLine, _T( "file")); else return FALSE; } else if (isRequired( m_lpCmdLine, _T( "postinstall"))) { // Show postinstall dialog box /POSTINSTALL m_uNotifcation = NOTIFY_TYPE_POSTINSTALL; } else { // Show default messagebox /MSGBOX m_uNotifcation = NOTIFY_TYPE_MSGBOX; } // /MSG=message (mandatory) if (isRequired( m_lpCmdLine, _T( "msg"))) m_csMessage = getParamValue( m_lpCmdLine, _T( "msg")); else return FALSE; // /NOCANCEL if (isRequired( m_lpCmdLine, _T( "nocancel"))) m_bCancel = FALSE; else m_bCancel = TRUE; // /DELAY if (isRequired( m_lpCmdLine, _T( "delay"))) m_bDelay = TRUE; else m_bDelay = FALSE; // /REBOOT if (isRequired( m_lpCmdLine, _T( "reboot"))) m_bReboot = TRUE; else m_bReboot = FALSE; // /TIMEOUT[=seconds] if (isRequired( m_lpCmdLine, _T( "timeout"))) csTimeOut = getParamValue( m_lpCmdLine, _T( "timeout")); else csTimeOut.Empty(); if (csTimeOut.IsEmpty()) m_uTimeOut = 0; else m_uTimeOut = _ttol( csTimeOut); return TRUE; }
bool LaTeXFeatures::mustProvide(string const & name) const { return isRequired(name) && !params_.documentClass().provides(name); }
string const LaTeXFeatures::getPackages() const { ostringstream packages; DocumentClass const & tclass = params_.documentClass(); // FIXME: currently, we can only load packages and macros known // to LyX. // However, with the Require tag of layouts/custom insets, // also inknown packages can be requested. They are silently // swallowed now. We should change this eventually. // // These are all the 'simple' includes. i.e // packages which we just \usepackage{package} // for (int i = 0; i < nb_simplefeatures; ++i) { if (mustProvide(simplefeatures[i])) packages << "\\usepackage{" << simplefeatures[i] << "}\n"; } // // The rest of these packages are somewhat more complicated // than those above. // // esint is preferred for esintoramsmath if ((mustProvide("amsmath") && params_.use_amsmath != BufferParams::package_off) || (mustProvide("esintoramsmath") && params_.use_esint == BufferParams::package_off && params_.use_amsmath != BufferParams::package_off)) { packages << "\\usepackage{amsmath}\n"; } else { // amsbsy and amstext are already provided by amsmath if (mustProvide("amsbsy")) packages << "\\usepackage{amsbsy}\n"; if (mustProvide("amstext")) packages << "\\usepackage{amstext}\n"; } // wasysym is a simple feature, but it must be after amsmath if both // are used // wasysym redefines some integrals (e.g. iint) from amsmath. That // leads to inconsistent integrals. We only load this package if // the document does not contain integrals (then isRequired("esint") // is false) or if esint is used, since esint redefines all relevant // integral symbols from wasysym and amsmath. // See http://www.lyx.org/trac/ticket/1942 if (mustProvide("wasysym") && (params_.use_esint != BufferParams::package_off || !isRequired("esint"))) packages << "\\usepackage{wasysym}\n"; // accents must be loaded after amsmath if (mustProvide("accents")) packages << "\\usepackage{accents}\n"; // mathdots must be loaded after amsmath if (mustProvide("mathdots")) packages << "\\usepackage{mathdots}\n"; // yhmath must be loaded after amsmath if (mustProvide("yhmath")) packages << "\\usepackage{yhmath}\n"; // [x]color and pdfcolmk are handled in getColorOptions() above // makeidx.sty if (isRequired("makeidx") || isRequired("splitidx")) { if (!tclass.provides("makeidx") && !isRequired("splitidx")) packages << "\\usepackage{makeidx}\n"; if (!tclass.provides("splitidx") && isRequired("splitidx")) packages << "\\usepackage{splitidx}\n"; packages << "\\makeindex\n"; } // graphicx.sty if (mustProvide("graphicx") && params_.graphicsDriver != "none") { if (params_.graphicsDriver == "default") packages << "\\usepackage{graphicx}\n"; else packages << "\\usepackage[" << params_.graphicsDriver << "]{graphicx}\n"; } // lyxskak.sty --- newer chess support based on skak.sty if (mustProvide("chess")) packages << "\\usepackage[ps,mover]{lyxskak}\n"; // setspace.sty if (mustProvide("setspace") && !tclass.provides("SetSpace")) packages << "\\usepackage{setspace}\n"; // amssymb.sty if (mustProvide("amssymb") || params_.use_amsmath == BufferParams::package_on) packages << "\\usepackage{amssymb}\n"; // esint must be after amsmath and wasysym, since it will redeclare // inconsistent integral symbols if ((mustProvide("esint") || mustProvide("esintoramsmath")) && params_.use_esint != BufferParams::package_off) packages << "\\usepackage{esint}\n"; // natbib.sty // Some classes load natbib themselves, but still allow (or even require) // plain numeric citations (ReVTeX is such a case, see bug 5182). // This special case is indicated by the "natbib-internal" key. if (mustProvide("natbib") && !tclass.provides("natbib-internal")) { packages << "\\usepackage["; if (params_.citeEngine() == ENGINE_NATBIB_NUMERICAL) packages << "numbers"; else packages << "authoryear"; packages << "]{natbib}\n"; } // jurabib -- we need version 0.6 at least. if (mustProvide("jurabib")) packages << "\\usepackage{jurabib}[2004/01/25]\n"; // xargs -- we need version 1.09 at least if (mustProvide("xargs")) packages << "\\usepackage{xargs}[2008/03/08]\n"; // bibtopic -- the dot provides the aux file naming which // LyX can detect. if (mustProvide("bibtopic")) packages << "\\usepackage[dot]{bibtopic}\n"; if (mustProvide("xy")) packages << "\\usepackage[all]{xy}\n"; if (mustProvide("ulem")) packages << "\\PassOptionsToPackage{normalem}{ulem}\n" "\\usepackage{ulem}\n"; if (mustProvide("mhchem") && params_.use_mhchem != BufferParams::package_off) packages << "\\PassOptionsToPackage{version=3}{mhchem}\n" "\\usepackage{mhchem}\n"; if (mustProvide("nomencl")) { // Make it work with the new and old version of the package, // but don't use the compatibility option since it is // incompatible to other packages. packages << "\\usepackage{nomencl}\n" "% the following is useful when we have the old nomencl.sty package\n" "\\providecommand{\\printnomenclature}{\\printglossary}\n" "\\providecommand{\\makenomenclature}{\\makeglossary}\n" "\\makenomenclature\n"; } return packages.str(); }
docstring const LaTeXFeatures::getMacros() const { odocstringstream macros; if (!preamble_snippets_.empty()) { macros << '\n'; macros << from_utf8(getPreambleSnippets()); } if (mustProvide("papersize")) { if (runparams_.flavor == OutputParams::LATEX) macros << papersizedvi_def << '\n'; else macros << papersizepdf_def << '\n'; } if (mustProvide("LyX")) macros << lyx_def << '\n'; if (mustProvide("lyxline")) macros << lyxline_def << '\n'; if (mustProvide("noun")) macros << noun_def << '\n'; if (mustProvide("lyxarrow")) macros << lyxarrow_def << '\n'; if (mustProvide("textgreek")) { // Avoid a LaTeX error if times fonts are used and the grtimes // package is installed but actual fonts are not (bug 6469). if (params_.fontsRoman == "times") macros << subst(textgreek_def, from_ascii("\\greektext #1"), from_ascii("%\n \\IfFileExists" "{grtm10.tfm}{}{\\fontfamily" "{cmr}}\\greektext #1")) << '\n'; else macros << textgreek_def << '\n'; } if (mustProvide("textcyr")) macros << textcyr_def << '\n'; if (mustProvide("lyxmathsym")) macros << lyxmathsym_def << '\n'; if (mustProvide("cedilla")) macros << cedilla_def << '\n'; if (mustProvide("subring")) macros << subring_def << '\n'; if (mustProvide("subdot")) macros << subdot_def << '\n'; if (mustProvide("subhat")) macros << subhat_def << '\n'; if (mustProvide("subtilde")) macros << subtilde_def << '\n'; if (mustProvide("dacute")) macros << dacute_def << '\n'; if (mustProvide("tipasymb")) macros << tipasymb_def << '\n'; if (mustProvide("dgrave")) macros << dgrave_def << '\n'; if (mustProvide("rcap")) macros << rcap_def << '\n'; if (mustProvide("ogonek")) macros << ogonek_def << '\n'; // quotes. if (mustProvide("quotesinglbase")) macros << quotesinglbase_def << '\n'; if (mustProvide("quotedblbase")) macros << quotedblbase_def << '\n'; if (mustProvide("guilsinglleft")) macros << guilsinglleft_def << '\n'; if (mustProvide("guilsinglright")) macros << guilsinglright_def << '\n'; if (mustProvide("guillemotleft")) macros << guillemotleft_def << '\n'; if (mustProvide("guillemotright")) macros << guillemotright_def << '\n'; // Math mode if (mustProvide("binom") && !isRequired("amsmath")) macros << binom_def << '\n'; if (mustProvide("mathcircumflex")) macros << mathcircumflex_def << '\n'; // other if (mustProvide("ParagraphLeftIndent")) macros << paragraphleftindent_def; if (mustProvide("NeedLyXFootnoteCode")) macros << floatingfootnote_def; // some problems with tex->html converters if (mustProvide("NeedTabularnewline")) macros << tabularnewline_def; // greyed-out environment (note inset) // the color is specified in the routine // getColorOptions() to avoid LaTeX-package clashes if (mustProvide("lyxgreyedout")) macros << lyxgreyedout_def; if (mustProvide("lyxdot")) macros << lyxdot_def << '\n'; // floats getFloatDefinitions(macros); // change tracking if (mustProvide("ct-dvipost")) macros << changetracking_dvipost_def; if (mustProvide("ct-xcolor-ulem")) { int const prec = macros.precision(2); RGBColor cadd = rgbFromHexName(lcolor.getX11Name(Color_addedtext)); macros << "\\providecolor{lyxadded}{rgb}{" << cadd.r / 255.0 << ',' << cadd.g / 255.0 << ',' << cadd.b / 255.0 << "}\n"; RGBColor cdel = rgbFromHexName(lcolor.getX11Name(Color_deletedtext)); macros << "\\providecolor{lyxdeleted}{rgb}{" << cdel.r / 255.0 << ',' << cdel.g / 255.0 << ',' << cdel.b / 255.0 << "}\n"; macros.precision(prec); if (isRequired("hyperref")) macros << changetracking_xcolor_ulem_hyperref_def; else macros << changetracking_xcolor_ulem_def; } if (mustProvide("ct-none")) macros << changetracking_none_def; return macros.str(); }
inline bool RadioButtonGroup::isValid() const { return !isRequired() || m_checkedButton; }
// Parsing QHash<QString, QVariant> ParserPrivate::parse(QStringList argv) { QHash<QString, QVariant> map; QStringListIterator it(argv); QString programName = it.next(); QString optionPrefix; QString flagPrefix; QListIterator<ParameterDefinition *> positionals(m_positionals); QStringList expecting; getPrefix(optionPrefix, flagPrefix); while (it.hasNext()) { QString arg = it.next(); if (!expecting.isEmpty()) // we were expecting an argument { QString name = expecting.first(); if (map.contains(name)) throw ParsingError( QString("Option %2%1 was given multiple times").arg(name, optionPrefix)); map[name] = QVariant(arg); expecting.removeFirst(); continue; } if (arg.startsWith(optionPrefix)) // we have an option { // qDebug("Found option %s", qPrintable(arg)); QString name = arg.mid(optionPrefix.length()); QString equals; if ((m_argStyle == ArgumentStyle::Equals || m_argStyle == ArgumentStyle::SpaceAndEquals) && name.contains("=")) { int i = name.indexOf("="); equals = name.mid(i + 1); name = name.left(i); } if (m_longLookup.contains(name)) { ParameterDefinition *param = m_longLookup[name]; if (map.contains(param->name)) throw ParsingError(QString("Option %2%1 was given multiple times") .arg(param->name, optionPrefix)); if (param->type == DefinitionType::Switch) map[param->name] = !param->defaultValue.toBool(); else // if (param->type == DefinitionType::Option) { if (m_argStyle == ArgumentStyle::Space) expecting.append(param->name); else if (!equals.isNull()) map[param->name] = equals; else if (m_argStyle == ArgumentStyle::SpaceAndEquals) expecting.append(param->name); else throw ParsingError(QString("Option %2%1 reqires an argument.") .arg(name, optionPrefix)); } continue; } // We need to fall through if the prefixes match if (optionPrefix != flagPrefix) throw ParsingError(QString("Unknown Option %2%1").arg(name, optionPrefix)); } if (arg.startsWith(flagPrefix)) // we have (a) flag(s) { // qDebug("Found flags %s", qPrintable(arg)); QString flags = arg.mid(flagPrefix.length()); QString equals; if ((m_argStyle == ArgumentStyle::Equals || m_argStyle == ArgumentStyle::SpaceAndEquals) && flags.contains("=")) { int i = flags.indexOf("="); equals = flags.mid(i + 1); flags = flags.left(i); } for (int i = 0; i < flags.length(); i++) { QChar flag = flags.at(i); if (!m_flagLookup.contains(flag)) throw ParsingError(QString("Unknown flag %2%1").arg(flag, flagPrefix)); ParameterDefinition *param = m_flagLookup[flag]; if (map.contains(param->name)) throw ParsingError(QString("Option %2%1 was given multiple times") .arg(param->name, optionPrefix)); if (param->type == DefinitionType::Switch) map[param->name] = !param->defaultValue.toBool(); else // if (param->type == DefinitionType::Option) { if (m_argStyle == ArgumentStyle::Space) expecting.append(param->name); else if (!equals.isNull()) if (i == flags.length() - 1) map[param->name] = equals; else throw ParsingError(QString("Flag %4%2 of Argument-requiring Option " "%1 not last flag in %4%3") .arg(param->name, flag, flags, flagPrefix)); else if (m_argStyle == ArgumentStyle::SpaceAndEquals) expecting.append(param->name); else throw ParsingError(QString("Option %1 reqires an argument. (flag %3%2)") .arg(param->name, flag, flagPrefix)); } } continue; } // must be a positional argument if (!positionals.hasNext()) throw ParsingError(QString("Too many positional arguments: '%1'").arg(arg)); ParameterDefinition *param = positionals.next(); map[param->name] = arg; } // check if we're missing something if (!expecting.isEmpty()) throw ParsingError(QString("Was still expecting arguments for %2%1").arg( expecting.join(QString(", ") + optionPrefix), optionPrefix)); // fill out gaps for (QListIterator<ParameterDefinition *> it(m_definitions); it.hasNext();) { ParameterDefinition *param = it.next(); if (!map.contains(param->name)) { if (isRequired(param)) throw ParsingError( QStringLiteral("Missing mandatory argument '%1'").arg(param->name)); else map[param->name] = param->defaultValue; } } return map; }