summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-07-27 17:28:27 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-07-27 17:28:27 +0200
commit8c1e0035404050376350d5e9b9242f5d39a6b53e (patch)
tree1aa609d156a4e0c131caf40c2d070d20b304bdbf /cli
parentdca38b27afc25d329fd7a7241095b40e2a1ecae2 (diff)
Add support for direct file loading with argv_file_scanner
Diffstat (limited to 'cli')
-rw-r--r--cli/options.cxx3
-rw-r--r--cli/options.hxx9
-rw-r--r--cli/options.ixx29
-rw-r--r--cli/runtime-header.cxx11
-rw-r--r--cli/runtime-inline.cxx33
-rw-r--r--cli/runtime-source.cxx3
6 files changed, 86 insertions, 2 deletions
diff --git a/cli/options.cxx b/cli/options.cxx
index 2e69cc9..7edc7f2 100644
--- a/cli/options.cxx
+++ b/cli/options.cxx
@@ -213,6 +213,8 @@ namespace cli
// argv_file_scanner
//
+ int argv_file_scanner::zero_argc_ = 0;
+
bool argv_file_scanner::
more ()
{
@@ -459,7 +461,6 @@ namespace cli
using namespace std;
const char* o (s.next ());
-
if (s.more ())
{
string v (s.next ());
diff --git a/cli/options.hxx b/cli/options.hxx
index 9f5124f..a865148 100644
--- a/cli/options.hxx
+++ b/cli/options.hxx
@@ -296,6 +296,9 @@ namespace cli
const std::string& option,
bool erase = false);
+ argv_file_scanner (const std::string& file,
+ const std::string& option);
+
struct option_info
{
// If search_func is not NULL, it is called, with the arg
@@ -320,6 +323,10 @@ namespace cli
std::size_t options_count,
bool erase = false);
+ argv_file_scanner (const std::string& file,
+ const option_info* options = 0,
+ std::size_t options_count = 0);
+
virtual bool
more ();
@@ -354,6 +361,8 @@ namespace cli
std::size_t i_;
bool skip_;
+
+ static int zero_argc_;
};
template <typename X>
diff --git a/cli/options.ixx b/cli/options.ixx
index ba5fff2..2b63fa8 100644
--- a/cli/options.ixx
+++ b/cli/options.ixx
@@ -194,6 +194,22 @@ namespace cli
}
inline argv_file_scanner::
+ argv_file_scanner (const std::string& file,
+ const std::string& option)
+ : argv_scanner (0, zero_argc_, 0),
+ option_ (option),
+ options_ (&option_info_),
+ options_count_ (1),
+ i_ (1),
+ skip_ (false)
+ {
+ option_info_.option = option_.c_str ();
+ option_info_.search_func = 0;
+
+ load (file);
+ }
+
+ inline argv_file_scanner::
argv_file_scanner (int& argc,
char** argv,
const option_info* options,
@@ -221,6 +237,19 @@ namespace cli
skip_ (false)
{
}
+
+ inline argv_file_scanner::
+ argv_file_scanner (const std::string& file,
+ const option_info* options,
+ std::size_t options_count)
+ : argv_scanner (0, zero_argc_, 0),
+ options_ (options),
+ options_count_ (options_count),
+ i_ (1),
+ skip_ (false)
+ {
+ load (file);
+ }
}
// options
diff --git a/cli/runtime-header.cxx b/cli/runtime-header.cxx
index 9d200bc..2b01071 100644
--- a/cli/runtime-header.cxx
+++ b/cli/runtime-header.cxx
@@ -415,6 +415,9 @@ generate_runtime_header (context& ctx)
<< "const std::string& option," << endl
<< "bool erase = false);"
<< endl
+ << "argv_file_scanner (const std::string& file," << endl
+ << "const std::string& option);"
+ << endl
<< "struct option_info"
<< "{"
<< "// If search_func is not NULL, it is called, with the arg" << endl
@@ -438,6 +441,10 @@ generate_runtime_header (context& ctx)
<< "std::size_t options_count," << endl
<< "bool erase = false);"
<< endl
+ << "argv_file_scanner (const std::string& file," << endl
+ << "const option_info* options = 0," << endl
+ << "std::size_t options_count = 0);"
+ << endl
<< "virtual bool" << endl
<< "more ();"
<< endl
@@ -475,7 +482,9 @@ generate_runtime_header (context& ctx)
os << endl
<< "bool skip_;";
- os << "};";
+ os << endl
+ << "static int zero_argc_;"
+ << "};";
}
// group_scanner
diff --git a/cli/runtime-inline.cxx b/cli/runtime-inline.cxx
index 18c5889..3a62db8 100644
--- a/cli/runtime-inline.cxx
+++ b/cli/runtime-inline.cxx
@@ -324,6 +324,24 @@ generate_runtime_inline (context& ctx)
<< "}";
os << inl << "argv_file_scanner::" << endl
+ << "argv_file_scanner (const std::string& file," << endl
+ << "const std::string& option)" << endl
+ << ": argv_scanner (0, zero_argc_, 0)," << endl
+ << " option_ (option)," << endl
+ << " options_ (&option_info_)," << endl
+ << " options_count_ (1)," << endl
+ << " i_ (1)";
+ if (sep)
+ os << "," << endl
+ << " skip_ (false)";
+ os << "{"
+ << "option_info_.option = option_.c_str ();"
+ << "option_info_.search_func = 0;"
+ << endl
+ << "load (file);"
+ << "}";
+
+ os << inl << "argv_file_scanner::" << endl
<< "argv_file_scanner (int& argc," << endl
<< "char** argv," << endl
<< "const option_info* options," << endl
@@ -355,6 +373,21 @@ generate_runtime_inline (context& ctx)
<< " skip_ (false)";
os << "{"
<< "}";
+
+ os << inl << "argv_file_scanner::" << endl
+ << "argv_file_scanner (const std::string& file," << endl
+ << "const option_info* options," << endl
+ << "std::size_t options_count)" << endl
+ << ": argv_scanner (0, zero_argc_, 0)," << endl
+ << " options_ (options)," << endl
+ << " options_count_ (options_count)," << endl
+ << " i_ (1)";
+ if (sep)
+ os << "," << endl
+ << " skip_ (false)";
+ os << "{"
+ << "load (file);"
+ << "}";
}
// group_scanner
diff --git a/cli/runtime-source.cxx b/cli/runtime-source.cxx
index 54a085f..dab695c 100644
--- a/cli/runtime-source.cxx
+++ b/cli/runtime-source.cxx
@@ -365,6 +365,9 @@ generate_runtime_source (context& ctx, bool complete)
os << "// argv_file_scanner" << endl
<< "//" << endl
+ << "int argv_file_scanner::zero_argc_ = 0;"
+ << endl
+
<< "bool argv_file_scanner::" << endl
<< "more ()"
<< "{"