From b320b14cdfee48a90a732304d6398eb388b1c975 Mon Sep 17 00:00:00 2001 From: albert-github Date: Sat, 19 Dec 2020 18:42:18 +0100 Subject: Usage of version and help in addons More consequent and consistent usage of help and version in addons. --- addon/doxmlparser/examples/metrics/CMakeLists.txt | 2 ++ addon/doxmlparser/examples/metrics/main.cpp | 21 +++++++++-- addon/doxmlparser/test/CMakeLists.txt | 2 ++ addon/doxmlparser/test/main.cpp | 21 +++++++++-- addon/doxyapp/doxyapp.cpp | 19 +++++++++- addon/doxyparse/doxyparse.cpp | 24 +++++++++---- addon/doxysearch/CMakeLists.txt | 11 +++--- addon/doxysearch/doxyindexer.cpp | 13 +++++-- addon/doxysearch/doxysearch.cpp | 44 ++++++++++++++++++----- 9 files changed, 130 insertions(+), 27 deletions(-) diff --git a/addon/doxmlparser/examples/metrics/CMakeLists.txt b/addon/doxmlparser/examples/metrics/CMakeLists.txt index 255ae0e..7e99a08 100644 --- a/addon/doxmlparser/examples/metrics/CMakeLists.txt +++ b/addon/doxmlparser/examples/metrics/CMakeLists.txt @@ -1,6 +1,7 @@ include_directories( ../../include + ${PROJECT_SOURCE_DIR}/libversion ) add_executable(doxmlparser_metrics @@ -10,6 +11,7 @@ main.cpp target_link_libraries(doxmlparser_metrics doxmlparser + doxygen_version qtools ${COVERAGE_LINKER_FLAGS} ) diff --git a/addon/doxmlparser/examples/metrics/main.cpp b/addon/doxmlparser/examples/metrics/main.cpp index 1328abe..9e301b1 100644 --- a/addon/doxmlparser/examples/metrics/main.cpp +++ b/addon/doxmlparser/examples/metrics/main.cpp @@ -22,6 +22,7 @@ #include #include #include +#include "version.h" bool isDocumented(IDocRoot *brief,IDocRoot *detailed) { @@ -49,9 +50,25 @@ bool isDocumented(IDocRoot *brief,IDocRoot *detailed) int main(int argc,char **argv) { - if (argc!=2) + int locArgc = argc; + + if (locArgc == 2) + { + if (!strcmp(argv[1],"--help")) + { + printf("Usage: %s xml_dir\n",argv[0]); + exit(0); + } + else if (!strcmp(argv[1],"--version")) + { + printf("%s version: %s\n",argv[0],getFullVersion()); + exit(0); + } + } + + if (locArgc!=2) { - printf("Usage: %s xml_output_dir\n",argv[0]); + printf("Usage: %s xml_dir\n",argv[0]); exit(1); } diff --git a/addon/doxmlparser/test/CMakeLists.txt b/addon/doxmlparser/test/CMakeLists.txt index 7cdeda6..4caef57 100644 --- a/addon/doxmlparser/test/CMakeLists.txt +++ b/addon/doxmlparser/test/CMakeLists.txt @@ -1,6 +1,7 @@ include_directories( ../include + ${PROJECT_SOURCE_DIR}/libversion ${PROJECT_SOURCE_DIR}/qtools ) @@ -11,6 +12,7 @@ main.cpp target_link_libraries(doxmlparser_test doxmlparser + doxygen_version qtools ${COVERAGE_LINKER_FLAGS} ) diff --git a/addon/doxmlparser/test/main.cpp b/addon/doxmlparser/test/main.cpp index 0d1f95e..35fd700 100644 --- a/addon/doxmlparser/test/main.cpp +++ b/addon/doxmlparser/test/main.cpp @@ -17,6 +17,7 @@ #include #include #include +#include "version.h" /*! Dumps the contents of a hyperlinked text fragment as plain text to the * output. @@ -577,9 +578,25 @@ void DumpParamList(IParamIterator *pli,int indent) int main(int argc,char **argv) { - if (argc!=2) + int locArgc = argc; + + if (locArgc == 2) + { + if (!strcmp(argv[1],"--help")) + { + printf("Usage: %s xml_dir\n",argv[0]); + exit(0); + } + else if (!strcmp(argv[1],"--version")) + { + printf("%s version: %s\n",argv[0],getFullVersion()); + exit(0); + } + } + + if (locArgc!=2) { - printf("Usage: %s xmldir\n",argv[0]); + printf("Usage: %s xml_dir\n",argv[0]); exit(1); } diff --git a/addon/doxyapp/doxyapp.cpp b/addon/doxyapp/doxyapp.cpp index 3ec8fb2..2ee6566 100644 --- a/addon/doxyapp/doxyapp.cpp +++ b/addon/doxyapp/doxyapp.cpp @@ -38,6 +38,7 @@ #include "classlist.h" #include "config.h" #include "filename.h" +#include "version.h" class XRefDummyCodeGenerator : public CodeOutputInterface { @@ -225,7 +226,23 @@ int main(int argc,char **argv) { char cmd[256]; - if (argc<2) + int locArgc = argc; + + if (locArgc == 2) + { + if (!strcmp(argv[1],"--help")) + { + printf("Usage: %s [source_file | source_dir]\n",argv[0]); + exit(0); + } + else if (!strcmp(argv[1],"--version")) + { + printf("%s version: %s\n",argv[0],getFullVersion()); + exit(0); + } + } + + if (locArgc!=2) { printf("Usage: %s [source_file | source_dir]\n",argv[0]); exit(1); diff --git a/addon/doxyparse/doxyparse.cpp b/addon/doxyparse/doxyparse.cpp index 4235bf3..9a99549 100644 --- a/addon/doxyparse/doxyparse.cpp +++ b/addon/doxyparse/doxyparse.cpp @@ -431,15 +431,27 @@ static void listSymbols() { } int main(int argc,char **argv) { - if (argc < 2) { + int locArgc = argc; + + if (locArgc == 2) + { + if (!strcmp(argv[1],"--help")) + { + printf("Usage: %s [source_file | source_dir]\n",argv[0]); + exit(0); + } + else if (!strcmp(argv[1],"--version")) + { + printf("%s version: %s\n",argv[0],getFullVersion()); + exit(0); + } + } + + if (locArgc!=2) + { printf("Usage: %s [source_file | source_dir]\n",argv[0]); exit(1); } - if (qstrcmp(&argv[1][2], "version") == 0) { - QCString versionString = getDoxygenVersion(); - printf("%s\n", versionString.data()); - exit(0); - } // initialize data structures initDoxygen(); diff --git a/addon/doxysearch/CMakeLists.txt b/addon/doxysearch/CMakeLists.txt index 459d17a..d0c8724 100644 --- a/addon/doxysearch/CMakeLists.txt +++ b/addon/doxysearch/CMakeLists.txt @@ -6,8 +6,9 @@ if (WIN32) endif() include_directories( - ${PROJECT_SOURCE_DIR}/qtools - ${XAPIAN_INCLUDE_DIR} + ${PROJECT_SOURCE_DIR}/libversion + ${PROJECT_SOURCE_DIR}/qtools + ${XAPIAN_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS} ) add_executable(doxyindexer @@ -16,8 +17,9 @@ add_executable(doxyindexer target_link_libraries(doxyindexer ${XAPIAN_LIBRARIES} ${ZLIB_LIBRARIES} - ${WIN_EXTRA_LIBS} + ${WIN_EXTRA_LIBS} ${COVERAGE_LINKER_FLAGS} + doxygen_version qtools ) @@ -25,9 +27,10 @@ add_executable(doxysearch.cgi doxysearch.cpp ) target_link_libraries(doxysearch.cgi + doxygen_version ${XAPIAN_LIBRARIES} ${ZLIB_LIBRARIES} - ${WIN_EXTRA_LIBS} + ${WIN_EXTRA_LIBS} ) install(TARGETS doxyindexer doxysearch.cgi DESTINATION bin) diff --git a/addon/doxysearch/doxyindexer.cpp b/addon/doxysearch/doxyindexer.cpp index cd31b3d..ae4e046 100644 --- a/addon/doxysearch/doxyindexer.cpp +++ b/addon/doxysearch/doxyindexer.cpp @@ -30,6 +30,8 @@ // Xapian include #include +#include "version.h" + #define MAX_TERM_LENGTH 245 #if defined(_WIN32) && !defined(__CYGWIN__) @@ -303,10 +305,10 @@ class XMLErrorHandler : public QXmlErrorHandler QString errorMsg; }; -static void usage(const char *name) +static void usage(const char *name, int exitVal = 1) { std::cerr << "Usage: " << name << " [-o output_dir] searchdata.xml [searchdata2.xml ...]" << std::endl; - exit(1); + exit(exitVal); } /** main function to index data */ @@ -340,7 +342,12 @@ int main(int argc,const char **argv) } else if (std::string(argv[i])=="-h" || std::string(argv[i])=="--help") { - usage(argv[0]); + usage(argv[0],0); + } + else if (std::string(argv[i])=="-v" || std::string(argv[i])=="--version") + { + std::cerr << argv[0] << " version: " << getFullVersion() << std::endl; + exit(0); } } 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 +#include "version.h" + #ifdef _WIN32 #include #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 parts = split(queryString,'&'); std::string searchFor,callback; -- cgit v0.12