26 const char OPTIONS_SEPARATOR =
',';
54 return (first.name == second.name &&
55 first.value == second.value);
67 inline std::istream& read(std::istream& in)
69 return in >> this->value;
81 inline std::ostream& write(std::ostream& out)
const
83 return out << this->value;
132 return out << (this->value ?
"1" :
"0");
146 return parameter.read(in);
160 return parameter.write(out);
167 template<
class T = JNullType>
189 __terminate__(false),
199 virtual void terminate(
const int status)
201 __terminate__ =
true;
202 __exit_code__ = status;
232 gexit(__exit_code__);
250 struct JShellParser :
251 public JShellParser<>
253 typedef JShellParser<>::key_type key_type;
261 void evaluate()
const
263 for (
typename data_type::const_iterator i = this->data.begin(); i != this->data.end(); ++i) {
265 std::ostringstream os;
290 struct JEnvironment<
std::string> :
291 public JShellParser<std::string>
293 typedef JShellParser<std::string>::key_type key_type;
311 friend inline std::istream&
operator>>(std::istream& in, JEnvironment& environment)
322 if (!has_facet<JEquationFacet>(in.getloc())) {
323 in.imbue(locale(in.getloc(), facet.clone()));
326 if (in >> c >> key >> equation) {
328 if (c ==
'-' && !equation.
getKey().empty()) {
330 environment.data.push_back(parameter_type(equation.
getKey()));
332 parameter_type& parameter = environment.data.back();
338 istringstream is(equation.
getValue());
342 for (parameter_type buffer(parameter.name);
getline(is, buffer.value, OPTIONS_SEPARATOR); ) {
344 buffer.value =
trim(buffer.value);
346 possible_values.push_back(buffer);
349 environment[key] =
JPARSER::getOption(parameter, equation.
getKey(), possible_values.begin(), possible_values.end());
371 struct JEnvironment<bool> :
372 public JShellParser<bool>
374 typedef JShellParser<bool>::key_type key_type;
392 friend inline std::istream&
operator>>(std::istream& in, JEnvironment& environment)
403 if (!has_facet<JEquationFacet>(in.getloc())) {
404 in.imbue(locale(in.getloc(), facet.clone()));
407 if (in >> c >> key >> equation) {
409 if (c ==
'-' && !equation.
getKey().empty()) {
411 environment.data.push_back(parameter_type(equation.
getKey()));
413 parameter_type& parameter = environment.data.back();
445 int main(
int argc,
char **argv)
452 JEnvironment<bool> boolean;
453 JEnvironment<string> regular;
460 const JArgs options = zap(argc, argv);
462 JShellParser<> buffer;
464 buffer.join(
boolean);
465 buffer.join(regular);
472 catch(
const exception& error) {
473 return gexit(2, error.what());