summaryrefslogtreecommitdiff
path: root/src/option.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-06-11 16:03:50 -0400
committerJohn Wiegley <johnw@newartisans.com>2010-06-11 17:02:25 -0400
commitdea2aed0b509734ec4e1cd163ac2a4f013000da2 (patch)
tree7908da76c67ae5172882306a319bf26df81b73b4 /src/option.h
parentd580079df892c30d023b3211d6c4611c17b11f8f (diff)
downloadfork-ledger-dea2aed0b509734ec4e1cd163ac2a4f013000da2.tar.gz
fork-ledger-dea2aed0b509734ec4e1cd163ac2a4f013000da2.tar.bz2
fork-ledger-dea2aed0b509734ec4e1cd163ac2a4f013000da2.zip
Untabified all source files
Diffstat (limited to 'src/option.h')
-rw-r--r--src/option.h108
1 files changed, 54 insertions, 54 deletions
diff --git a/src/option.h b/src/option.h
index f11497a4..91ff26f9 100644
--- a/src/option.h
+++ b/src/option.h
@@ -52,10 +52,10 @@ template <typename T>
class option_t
{
protected:
- const char * name;
+ const char * name;
string::size_type name_len;
- const char ch;
- bool handled;
+ const char ch;
+ bool handled;
optional<string> source;
option_t& operator=(const option_t&);
@@ -63,7 +63,7 @@ protected:
public:
T * parent;
value_t value;
- bool wants_arg;
+ bool wants_arg;
option_t(const char * _name, const char _ch = '\0')
: name(_name), name_len(std::strlen(name)), ch(_ch),
@@ -93,11 +93,11 @@ public:
out.width(24);
out << std::right << desc();
if (wants_arg) {
- out << " = ";
- value.print(out, 42);
+ out << " = ";
+ value.print(out, 42);
} else {
- out.width(45);
- out << ' ';
+ out.width(45);
+ out << ' ';
}
out << std::left << *source << std::endl;
}
@@ -108,10 +108,10 @@ public:
out << "--";
for (const char * p = name; *p; p++) {
if (*p == '_') {
- if (*(p + 1))
- out << '-';
+ if (*(p + 1))
+ out << '-';
} else {
- out << *p;
+ out << *p;
}
}
if (ch)
@@ -145,7 +145,7 @@ public:
on_with(whence, string_value(str));
}
virtual void on_with(const optional<string>& whence,
- const value_t& val) {
+ const value_t& val) {
handled = true;
value = val;
source = whence;
@@ -162,11 +162,11 @@ public:
virtual void handler(call_scope_t& args) {
if (wants_arg) {
if (args.size() < 2)
- throw_(std::runtime_error, _("No argument provided for %1") << desc());
+ throw_(std::runtime_error, _("No argument provided for %1") << desc());
else if (args.size() > 2)
- throw_(std::runtime_error, _("To many arguments provided for %1") << desc());
+ throw_(std::runtime_error, _("To many arguments provided for %1") << desc());
else if (! args[0].is_string())
- throw_(std::runtime_error, _("Context argument for %1 not a string") << desc());
+ throw_(std::runtime_error, _("Context argument for %1 not a string") << desc());
on_with(args[0].as_string(), args[1]);
}
else if (args.size() < 1) {
@@ -194,9 +194,9 @@ public:
}
else if (wants_arg) {
if (handled)
- return value;
+ return value;
else
- return NULL_VALUE;
+ return NULL_VALUE;
}
else {
return handled;
@@ -204,13 +204,13 @@ public:
}
};
-#define BEGIN(type, name) \
+#define BEGIN(type, name) \
struct name ## option_t : public option_t<type>
-#define CTOR(type, name) \
+#define CTOR(type, name) \
name ## option_t() : option_t<type>(#name)
-#define DECL1(type, name, vartype, var, value) \
- vartype var ; \
+#define DECL1(type, name, vartype, var, value) \
+ vartype var ; \
name ## option_t() : option_t<type>(#name), var(value)
#define DO() virtual void handler_thunk(call_scope_t&)
@@ -220,10 +220,10 @@ public:
#define COPY_OPT(name, other) name ## handler(other.name ## handler)
-#define MAKE_OPT_HANDLER(type, x) \
+#define MAKE_OPT_HANDLER(type, x) \
expr_t::op_t::wrap_functor(bind(&option_t<type>::handler_wrapper, x, _1))
-#define MAKE_OPT_FUNCTOR(type, x) \
+#define MAKE_OPT_FUNCTOR(type, x) \
expr_t::op_t::wrap_functor(bind(&option_t<type>::operator(), x, _1))
inline bool is_eq(const char * p, const char * n) {
@@ -236,57 +236,57 @@ inline bool is_eq(const char * p, const char * n) {
return *p == *n || (! *p && *n == '_' && ! *(n + 1));
}
-#define OPT(name) \
- if (is_eq(p, #name)) \
+#define OPT(name) \
+ if (is_eq(p, #name)) \
return ((name ## handler).parent = this, &(name ## handler))
-#define OPT_ALT(name, alt) \
- if (is_eq(p, #name) || is_eq(p, #alt)) \
+#define OPT_ALT(name, alt) \
+ if (is_eq(p, #name) || is_eq(p, #alt)) \
return ((name ## handler).parent = this, &(name ## handler))
-#define OPT_(name) \
- if (! *(p + 1) || \
- ((name ## handler).wants_arg && \
- *(p + 1) == '_' && ! *(p + 2)) || \
- is_eq(p, #name)) \
+#define OPT_(name) \
+ if (! *(p + 1) || \
+ ((name ## handler).wants_arg && \
+ *(p + 1) == '_' && ! *(p + 2)) || \
+ is_eq(p, #name)) \
return ((name ## handler).parent = this, &(name ## handler))
-#define OPT_CH(name) \
- if (! *(p + 1) || \
- ((name ## handler).wants_arg && \
- *(p + 1) == '_' && ! *(p + 2))) \
+#define OPT_CH(name) \
+ if (! *(p + 1) || \
+ ((name ## handler).wants_arg && \
+ *(p + 1) == '_' && ! *(p + 2))) \
return ((name ## handler).parent = this, &(name ## handler))
#define HANDLER(name) name ## handler
#define HANDLED(name) HANDLER(name)
-#define OPTION(type, name) \
- BEGIN(type, name) \
- { \
- CTOR(type, name) {} \
- } \
+#define OPTION(type, name) \
+ BEGIN(type, name) \
+ { \
+ CTOR(type, name) {} \
+ } \
END(name)
-#define OPTION_(type, name, body) \
- BEGIN(type, name) \
- { \
- CTOR(type, name) {} \
- body \
- } \
+#define OPTION_(type, name, body) \
+ BEGIN(type, name) \
+ { \
+ CTOR(type, name) {} \
+ body \
+ } \
END(name)
-#define OPTION__(type, name, body) \
- BEGIN(type, name) \
- { \
- body \
- } \
+#define OPTION__(type, name, body) \
+ BEGIN(type, name) \
+ { \
+ body \
+ } \
END(name)
bool process_option(const string& whence, const string& name, scope_t& scope,
- const char * arg, const string& varname);
+ const char * arg, const string& varname);
void process_environment(const char ** envp, const string& tag,
- scope_t& scope);
+ scope_t& scope);
strings_list process_arguments(strings_list args, scope_t& scope);