summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-01-23 14:39:19 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-01-23 14:39:19 +0200
commit8027e319831f02538fe431b5870d90c0267b3b78 (patch)
tree3ffb2c9f47b188cc361febffb7a24f45cec5321b
parent0267ede2d356abdef7b3e9af19d4725605a58947 (diff)
Allow the options file search function to ignore the file
-rw-r--r--cli/runtime-header.cxx10
-rw-r--r--cli/runtime-source.cxx18
-rw-r--r--doc/guide/index.xhtml10
3 files changed, 28 insertions, 10 deletions
diff --git a/cli/runtime-header.cxx b/cli/runtime-header.cxx
index 41c56c9..a1cf114 100644
--- a/cli/runtime-header.cxx
+++ b/cli/runtime-header.cxx
@@ -278,9 +278,13 @@ generate_runtime_header (context& ctx)
<< endl
<< "struct option_info"
<< "{"
- << " const char* option;"
- << " std::string (*search_func) (const char*, void* arg);"
- << " void* arg;"
+ << "// If search_func is not NULL, it is called, with the arg" << endl
+ << "// value as the second argument, to locate the options file." << endl
+ << "// If it returns an empty string, then the file is ignored." << endl
+ << "//" << endl
+ << "const char* option;"
+ << "std::string (*search_func) (const char*, void* arg);"
+ << "void* arg;"
<< "};"
<< "argv_file_scanner (int& argc," << endl
<< "char** argv," << endl
diff --git a/cli/runtime-source.cxx b/cli/runtime-source.cxx
index 4c6b2a2..7f87d1f 100644
--- a/cli/runtime-source.cxx
+++ b/cli/runtime-source.cxx
@@ -264,8 +264,13 @@ generate_runtime_source (context& ctx)
<< "if (!base::more ())" << endl
<< "throw missing_value (oi->option);"
<< endl
- << "if (oi->search_func != 0)" << endl
- << "load (oi->search_func (base::next (), oi->arg));"
+ << "if (oi->search_func != 0)"
+ << "{"
+ << "std::string f (oi->search_func (base::next (), oi->arg));"
+ << endl
+ << "if (!f.empty ())" << endl
+ << "load (f);"
+ << "}"
<< "else" << endl
<< "load (base::next ());"
<< endl
@@ -420,8 +425,13 @@ generate_runtime_source (context& ctx)
<< "if (s2.empty ())" << endl
<< "throw missing_value (oi->option);"
<< endl
- << "if (oi->search_func != 0)" << endl
- << "load (oi->search_func (s2.c_str (), oi->arg));"
+ << "if (oi->search_func != 0)"
+ << "{"
+ << "std::string f (oi->search_func (s2.c_str (), oi->arg));"
+ << endl
+ << "if (!f.empty ())" << endl
+ << "load (f);"
+ << "}"
<< "else" << endl
<< "load (s2);"
<< "}"
diff --git a/doc/guide/index.xhtml b/doc/guide/index.xhtml
index bc215e3..638b65b 100644
--- a/doc/guide/index.xhtml
+++ b/doc/guide/index.xhtml
@@ -743,9 +743,13 @@ namespace cli
struct option_info
{
- const char* option;
- std::string (*search_func) (const char*, void* arg);
- void* arg;
+ // If search_func is not NULL, it is called, with the arg
+ // value as the second argument, to locate the options file.
+ // If it returns an empty string, then the file is ignored.
+ //
+ const char* option;
+ std::string (*search_func) (const char*, void* arg);
+ void* arg;
};
argv_file_scanner (int&amp; argc,