diff options
author | albert-github <albert.tests@gmail.com> | 2020-12-19 17:42:18 (GMT) |
---|---|---|
committer | albert-github <albert.tests@gmail.com> | 2020-12-19 17:42:18 (GMT) |
commit | b320b14cdfee48a90a732304d6398eb388b1c975 (patch) | |
tree | 39c1e152ef11f0885cae4193da40ebc64981fec7 /addon/doxysearch/doxysearch.cpp | |
parent | 77a37d141d3603c0089bc4a231c9381c1bb7d707 (diff) | |
download | Doxygen-b320b14cdfee48a90a732304d6398eb388b1c975.zip Doxygen-b320b14cdfee48a90a732304d6398eb388b1c975.tar.gz Doxygen-b320b14cdfee48a90a732304d6398eb388b1c975.tar.bz2 |
Usage of version and help in addons
More consequent and consistent usage of help and version in addons.
Diffstat (limited to 'addon/doxysearch/doxysearch.cpp')
-rw-r--r-- | addon/doxysearch/doxysearch.cpp | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/addon/doxysearch/doxysearch.cpp b/addon/doxysearch/doxysearch.cpp index 4c4dc72..26517bd 100644 --- a/addon/doxysearch/doxysearch.cpp +++ b/addon/doxysearch/doxysearch.cpp @@ -27,6 +27,8 @@ // Xapian includes #include <xapian.h> +#include "version.h" + #ifdef _WIN32 #include <windows.h> #else @@ -306,31 +308,55 @@ static void showError(const std::string &callback,const std::string &error) exit(0); } +static void usage(const char *name, int exitVal = 1) +{ + std::cerr << "Usage: " << name << "[query_string]" << std::endl; + std::cerr << " " << "alternatively the query string can be given by the environment variable QUERY_STRING" << std::endl; + exit(exitVal); +} + /** Main routine */ int main(int argc,char **argv) { // process inputs that were passed to us via QUERY_STRING - std::cout << "Content-Type:application/javascript;charset=utf-8\r\n\n"; std::string callback; try { - // get input parameters - const char *queryEnv = getenv("QUERY_STRING"); std::string queryString; - if (queryEnv) + if (argc == 1) { - queryString = queryEnv; + const char *queryEnv = getenv("QUERY_STRING"); + if (queryEnv) + { + queryString = queryEnv; + } + else + { + usage(argv[0]); + } } - else if (argc>=2) + else if (argc == 2) { - queryString = argv[1]; + if (std::string(argv[1])=="-h" || std::string(argv[1])=="--help") + { + usage(argv[0],0); + } + else if (std::string(argv[1])=="-v" || std::string(argv[1])=="--version") + { + std::cerr << argv[0] << " version: " << getFullVersion() << std::endl; + exit(0); + } + else + { + queryString = argv[1]; + } } else { - std::cout << "No input!\n"; - exit(1); + usage(argv[0]); } + std::cout << "Content-Type:application/javascript;charset=utf-8\r\n\n"; // parse query string std::vector<std::string> parts = split(queryString,'&'); std::string searchFor,callback; |