using std::ostream;
using std::string;
using std::exception;
+using lyx::support::bformat;
using lyx::support::trim;
using lyx::support::isStrInt;
using lyx::support::prefixIs;
ALL, // accept all
TRUEFALSE, // accept 'true' or 'false'
INTEGER, // accept an integer
- LENGTH, // accept an latex length
+ LENGTH, // accept a latex length
ONEOF, // accept one of a few values
SUBSETOF, // accept a string composed of given characters
};
char const * name;
/// default value
char const * value;
- // for option with value "true", "false",
+ // for option with value "true", "false",
// if onoff is true,
// "true": option
// "false":
// "false": option=false
bool onoff;
/// validator type
- param_type type;
// ALL:
// TRUEFALSE:
// INTEGER:
// SUBSETOF
// info is a string from which par is composed of
// (e.g. floatplacement can be one or more of tbph)
+ param_type type;
+ /// parameter info, meaning depending on parameter type
char const * info;
- //
+ /// a help message that is displayed in the gui
char const * hint;
};
+
+/// languages and language/dialect combinations
char const * allowed_languages =
- "no language\nBAP\nACSL\nAda\nALGOL\nC\nC++\nCaml\nClean\nCobol\n"
- "Comal 80\ncsh\nDelphi\nEiffel\nElan\nEuphoria\nFortran\nHaskell\n"
- "HTML\nIDL\nJava\nLisp\nLogo\nmake\nMathematica\nMatlab\nMercury\n"
- "Miranda\nML\nModula-2\nOberon-2\nOCL\nPascal\nPerl\nPHP\nPL/I\nPOV\n"
- "Python\nProlog\nR\nS\nSAS\nSHELXL\nSimula\ntcl\nSQL\nTeX\nVBScript\n"
- "VHDL\nXML";
-
-char const * style_hint = "Use \\footnotessize, \\small, \\itshape, \\ttfamily or something like that";
-char const * frame_hint = "none, leftline, topline, bottomline, lines, single, shadowbox or subset of trblTRBL";
-char const * frameround_hint = "The foru letters (t or f) attached to top right, bottom right, bottom left and top left corner.";
-char const * color_hint = "Enter something like \\color{white}";
+ "no language\nABAP\n[R/2 4.3]ABAP\n[R/2 5.0]ABAP\n[R/3 3.1]ABAP\n"
+ "[R/3 4.6C]ABAP\n[R/3 6.10]ABAP\nACSL\nAda\n[2005]Ada\n[83]Ada\n"
+ "[95]Ada\nALGOL\n[60]ALGOL\n[68]ALGOL\nAssembler\n"
+ "[Motorola68k]Assembler\n[x86masm]Assembler\nAwk\n[gnu]Awk\n[POSIX]Awk\n"
+ "bash\nBasic\n[Visual]Basic\nC\n[ANSI]C\n[Handel]C\n[Objective]C\n"
+ "[Sharp]C\nC++\n[ANSI]C++\n[GNU]C++\n[ISO]C++\n[Visual]C++\nCaml\n"
+ "[light]Caml\n[Objective]Caml\nClean\nCobol\n[1974]Cobol\n[1985]Cobol\n"
+ "[ibm]Cobol\nComal 80\ncommand.com\n[WinXP]command.com\nComsol\ncsh\n"
+ "Delphi\nEiffel\nElan\nEuphoria\nFortran\n[77]Fortran\n[90]Fortran\n"
+ "[95]Fortran\nGCL\nGnuplot\nHaskell\nHTML\nIDL\n[CORBA]IDL\ninform\n"
+ "Java\n[AspectJ]Java\nJVMIS\nksh\nLingo\nLisp\n[Auto]Lisp\nLogo\n"
+ "make\n[gnu]make\nMathematica\n[1.0]Mathematica\n[3.0]Mathematica\n"
+ "[5.2]Mathematica\nMatlab\nMercury\nMetaPost\nMiranda\nMizar\nML\n"
+ "Modula-2\nMuPAD\nNASTRAN\nOberon-2\nOCL\n[decorative]OCL\n[OMG]OCL\n"
+ "Octave\nOz\nPascal\n[Borland6]Pascal\n[Standard]Pascal\n[XSC]Pascal\n"
+ "Perl\nPHP\nPL/I\nPlasm\nPostScript\nPOV\nProlog\nPromela\nPSTricks\n"
+ "Python\nR\nReduce\nRexx\nRSL\nRuby\nS\n[PLUS]S\nSAS\nScilab\nsh\n"
+ "SHELXL\nSimula\n[67]Simula\n[CII]Simula\n[DEC]Simula\n[IBM]Simula\n"
+ "SPARQL\nSQL\ntcl\n[tk]tcl\nTeX\n[AlLaTeX]TeX\n[common]TeX\n[LaTeX]TeX\n"
+ "[plain]TeX\n[primitive]TeX\nVBScript\nVerilog\nVHDL\n[AMS]VHDL\nVRML\n"
+ "[97]VRML\nXML\nXSLT";
+
+char const * style_hint = N_("Use \\footnotesize, \\small, \\itshape, \\ttfamily or something like that");
+char const * frame_hint = N_("none, leftline, topline, bottomline, lines, single, shadowbox or subset of trblTRBL");
+char const * frameround_hint =
+ N_("Enter four letters (either t = round or f = square) for top right, bottom right, bottom left and top left corner.");
+char const * color_hint = N_("Enter something like \\color{white}");
/// options copied from page 26 of listings manual
// FIXME: add default parameters ... (which is not used now)
{ "firstline", "", false, INTEGER, "", "" },
{ "lastline", "", false, INTEGER, "", "" },
{ "showlines", "", false, TRUEFALSE, "", "" },
- { "emptylines", "", false, ALL, "", "Expect a number with an optional * before it" },
+ { "emptylines", "", false, ALL, "", N_("Expect a number with an optional * before it") },
{ "gobble", "", false, INTEGER, "", "" },
{ "style", "", false, ALL, "", "" },
{ "language", "", false, ONEOF, allowed_languages, "" },
{ "numberstyle", "", false, ALL, "", style_hint },
{ "numbersep", "", false, LENGTH, "", "" },
{ "numberblanklines", "", false, ALL, "", "" },
- { "firstnumber", "", false, ALL, "", "auto, last or a number" },
+ { "firstnumber", "", false, ALL, "", N_("auto, last or a number") },
{ "name", "", false, ALL, "", "" },
{ "thelstnumber", "", false, ALL, "", "" },
{ "title", "", false, ALL, "", "" },
// this option is not handled in the parameter box
- { "caption", "", false, ALL, "", "This parameter should not be entered here. "
- "Please use caption editbox (Include dialog) or insert->caption (listings inset)" },
+ { "caption", "", false, ALL, "", N_("This parameter should not be entered here. "
+ "Please use caption editbox (Include dialog) or insert->caption (listings inset)") },
// this option is not handled in the parameter box
- { "label", "", false, ALL, "", "This parameter should not be entered here."
- "Please use label editbox (Include dialog) or insert->caption (listings inset)"},
+ { "label", "", false, ALL, "", N_("This parameter should not be entered here. "
+ "Please use label editbox (Include dialog) or insert->caption (listings inset)") },
{ "nolol", "", false, TRUEFALSE, "", "" },
{ "captionpos", "", false, SUBSETOF, "tb", "" },
{ "abovecaptionskip", "", false, LENGTH, "", "" },
: name(n), info(0)
{
if (name.empty())
- throw invalidParam("Invalid (empty) listings param name.");
+ throw invalidParam(_("Invalid (empty) listings param name."));
else if (name == "?") {
string pars;
size_t idx = 0;
pars += listings_param_table[idx].name;
++idx;
}
- throw invalidParam("Available listings parameters are " + pars);
+ throw invalidParam(bformat(
+ _("Available listings parameters are %1$s"), from_utf8(pars)));
}
// locate name in parameter table
size_t idx = 0;
string matching_names;
for (size_t i = 0; i < idx; ++i) {
string n(listings_param_table[i].name);
- if (n.size() >= name.size() && n.substr(0, name.size()) == name) {
+ if (prefixIs(n, name)) {
if (matching_names.empty())
matching_names += n;
else
}
}
if (matching_names.empty())
- throw invalidParam("Unknown listings param name: " + name);
+ throw invalidParam(bformat(_("Unknown listings param name: %1$s"),
+ from_utf8(name)));
else
- throw invalidParam("Parameters starting with '" + name +
- "': " + matching_names);
+ throw invalidParam(bformat(_("Parameters starting with '%1$s': %2$s"),
+ from_utf8(name), from_utf8(matching_names)));
}
void parValidator::validate(std::string const & par) const
{
+ bool unclosed = false;
+ string par2 = par;
+ // braces are allowed
+ if (prefixIs(par, "{") && suffixIs(par, "}"))
+ par2 = par.substr(1, par.size() - 2);
+ else if (prefixIs(par, "{")) {
+ par2 = par.substr(1);
+ unclosed = true;
+ }
+
+
switch (info->type) {
case ALL:
- if (par.empty() && !info->onoff) {
+ if (par2.empty() && !info->onoff) {
if (info->hint != "")
- throw invalidParam(info->hint);
+ throw invalidParam(from_utf8(info->hint));
else
- throw invalidParam("An value is expected");
+ throw invalidParam(_("A value is expected"));
}
+ if (unclosed)
+ throw invalidParam(_("Unbalanced braces!"));
return;
case TRUEFALSE: {
- if (par.empty() && !info->onoff) {
+ if (par2.empty() && !info->onoff) {
if (info->hint != "")
- throw invalidParam(info->hint);
+ throw invalidParam(from_utf8(info->hint));
else
- throw invalidParam("Please specify true or false");
+ throw invalidParam(_("Please specify true or false"));
}
- if (par != "true" && par != "false")
- throw invalidParam("Only true or false is allowed for parameter" + name);
+ if (par2 != "true" && par2 != "false")
+ throw invalidParam(bformat(_("Only true or false is allowed for parameter %1$s"),
+ from_utf8(name)));
+ if (unclosed)
+ throw invalidParam(_("Unbalanced braces!"));
return;
}
case INTEGER: {
- if (!isStrInt(par)) {
+ if (!isStrInt(par2)) {
if (info->hint != "")
- throw invalidParam(info->hint);
+ throw invalidParam(from_utf8(info->hint));
else
- throw invalidParam("Please specify an integer value");
+ throw invalidParam(_("Please specify an integer value"));
}
- if (convert<int>(par) == 0 && par[0] != '0')
- throw invalidParam("An integer is expected for parameter " + name);
+ if (convert<int>(par2) == 0 && par2[0] != '0')
+ throw invalidParam(bformat(_("An integer is expected for parameter %1$s"),
+ from_utf8(name)));
+ if (unclosed)
+ throw invalidParam(_("Unbalanced braces!"));
return;
}
case LENGTH: {
- if (par.empty() && !info->onoff) {
+ if (par2.empty() && !info->onoff) {
if (info->hint != "")
- throw invalidParam(info->hint);
+ throw invalidParam(from_utf8(info->hint));
else
- throw invalidParam("Please specify a latex length expression");
+ throw invalidParam(_("Please specify a latex length expression"));
}
- if (!isValidLength(par))
- throw invalidParam("Invalid latex length expression for parameter " + name);
+ if (!isValidLength(par2))
+ throw invalidParam(bformat(_("Invalid latex length expression for parameter %1$s"),
+ from_utf8(name)));
+ if (unclosed)
+ throw invalidParam(_("Unbalanced braces!"));
return;
}
case ONEOF: {
- if (par.empty() && !info->onoff) {
+ if (par2.empty() && !info->onoff) {
if (info->hint != "")
- throw invalidParam(info->hint);
+ throw invalidParam(from_utf8(info->hint));
else
- throw invalidParam("Please specify one of " + string(info->info));
+ throw invalidParam(bformat(_("Please specify one of %1$s"),
+ from_utf8(string(info->info))));
}
// break value to allowed strings
vector<string> lists;
lists.push_back(v);
// good, find the string
- if (std::find(lists.begin(), lists.end(), par) != lists.end())
+ if (std::find(lists.begin(), lists.end(), par2) != lists.end()) {
+ if (unclosed)
+ throw invalidParam(_("Unbalanced braces!"));
return;
+ }
// otherwise, produce a meaningful error message.
string matching_names;
for (vector<string>::iterator it = lists.begin();
it != lists.end(); ++it) {
- if (it->size() >= par.size() && it->substr(0, par.size()) == par) {
+ if (it->size() >= par2.size() && it->substr(0, par2.size()) == par2) {
if (matching_names.empty())
matching_names += *it;
else
}
}
if (matching_names.empty())
- throw invalidParam("Try one of " + string(info->info));
+ throw invalidParam(bformat(_("Try one of %1$s"),
+ from_utf8(string(info->info))));
else
- throw invalidParam("I guess you mean " + matching_names);
+ throw invalidParam(bformat(_("I guess you mean %1$s"),
+ from_utf8(matching_names)));
return;
}
case SUBSETOF: {
- if (par.empty() && !info->onoff) {
+ if (par2.empty() && !info->onoff) {
if (info->hint != "")
- throw invalidParam(info->hint);
+ throw invalidParam(from_utf8(info->hint));
else
- throw invalidParam("Please specify one or more of " + string(info->info));
+ throw invalidParam(bformat(_("Please specify one or more of '%1$s'"),
+ from_utf8(string(info->info))));
}
- for (size_t i = 0; i < par.size(); ++i)
- if (string(info->info).find(par[i], 0) == string::npos)
- throw invalidParam("Parameter " + name +
- " should be composed of one or more of " + info->info);
+ for (size_t i = 0; i < par2.size(); ++i)
+ if (string(info->info).find(par2[i], 0) == string::npos)
+ throw invalidParam(
+ bformat(_("Parameter %1$s should be composed of one or more of %2$s"),
+ from_utf8(name), from_utf8(info->info)));
+ if (unclosed)
+ throw invalidParam(_("Unbalanced braces!"));
return;
}
}
if (key.empty())
return;
// exception may be thown.
- parValidator(key.c_str()).validate(value);
+ parValidator(key).validate(value);
// duplicate parameters!
if (find(keys_.begin(), keys_.end(), key) != keys_.end())
- throw invalidParam("Parameter " + key + " has already been defined");
+ throw invalidParam(bformat(_("Parameter %1$s has already been defined"),
+ from_utf8(key)));
else
keys_.push_back(key);
if (!params_.empty())
}
+bool InsetListingsParams::isFloat() const
+{
+ return find(keys_.begin(), keys_.end(), "float") != keys_.end();
+}
+
+
string InsetListingsParams::getParamValue(string const & param) const
{
// is this parameter defined?