diff options
author | lloyd <[email protected]> | 2014-02-13 19:02:20 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-02-13 19:02:20 +0000 |
commit | cba6b70f5eccb941b2189ca7ef92d9a6510720f0 (patch) | |
tree | 6b1ed973f4844b21610e68a969e26fd2feadbba5 /src/cmd/main.cpp | |
parent | 241499ab648e27961f83c7c9724360657d8cf93b (diff) |
Add config and version subcommands
Diffstat (limited to 'src/cmd/main.cpp')
-rw-r--r-- | src/cmd/main.cpp | 113 |
1 files changed, 78 insertions, 35 deletions
diff --git a/src/cmd/main.cpp b/src/cmd/main.cpp index 37db57f68..f16db2027 100644 --- a/src/cmd/main.cpp +++ b/src/cmd/main.cpp @@ -1,13 +1,9 @@ /* -* (C) 2009 Jack Lloyd +* (C) 2009,2014 Jack Lloyd * * Distributed under the terms of the Botan license */ -/* - * Test Driver for Botan - */ - #include <vector> #include <string> @@ -20,7 +16,6 @@ #include <botan/init.h> #include <botan/version.h> -#include <botan/auto_rng.h> #include <botan/cpuid.h> #if defined(BOTAN_HAS_HTTP_UTIL) @@ -36,13 +31,79 @@ namespace { int help(int , char* argv[]) { std::cout << "Usage: " << argv[0] << " [subcommand]\n"; - std::cout << "version speed cpuid bcrypt x509 factor tls_client tls_server asn1 base64 hash self_sig ...\n"; + std::cout << "version config speed cpuid bcrypt x509 factor tls_client tls_server asn1 base64 hash self_sig ...\n"; return 1; } -int config_main(int , char* argv[]) +int config_main(int argc, char* argv[]) { - return 1; + if(argc != 2) + { + std::cout << "Usage: " << argv[0] << " <what>\n" + << " prefix: Print include params\n" + << " cflags: Print include params\n" + << " ldflags: Print linker params\n" + << " libs: Print libraries\n"; + return 1; + } + + const std::string arg = argv[1]; + + if(arg == "prefix") + std::cout << BOTAN_INSTALL_PREFIX << "\n"; + + else if(arg == "cflags") + std::cout << "-I" << BOTAN_INSTALL_PREFIX << "/" << BOTAN_INSTALL_HEADER_DIR << "\n"; + + else if(arg == "ldflags") + std::cout << "-L" << BOTAN_INSTALL_PREFIX << "/" << BOTAN_INSTALL_LIB_DIR << "\n"; + + else if(arg == "libs") + std::cout << "-lbotan-" << version_major() << "." << version_minor() + << " " << BOTAN_LIB_LINK << "\n"; + + else + { + std::cerr << "Unknown option " << arg << " to botan-config\n"; + return 1; + } + + return 0; + } + +int version_main(int argc, char* argv[]) + { + if(BOTAN_VERSION_MAJOR != version_major() || + BOTAN_VERSION_MINOR != version_minor() || + BOTAN_VERSION_PATCH != version_patch()) + { + std::cerr << "Warning: linked version (" + << version_major() << '.' + << version_minor() << '.' + << version_patch() + << ") does not match version built against (" + << BOTAN_VERSION_MAJOR << '.' + << BOTAN_VERSION_MINOR << '.' + << BOTAN_VERSION_PATCH << ")\n"; + } + + if(argc == 1) + { + std::cout << Botan::version_major() << "." + << Botan::version_minor() << "." + << Botan::version_patch() << "\n"; + } + else if(argc == 2 && std::string(argv[1]) == "--full") + { + std::cout << Botan::version_string() << "\n"; + } + else + { + std::cout << "Usage: " << argv[0] << " [--full]\n"; + return 1; + } + + return 0; } } @@ -67,31 +128,11 @@ int main(int argc, char* argv[]) if(cmd == "help") return help(argc, argv); - if(cmd == "config") - { + if(cmd == "config" && argc > 1) return config_main(argc - 1, argv + 1); - } - if(cmd == "version") - { - std::cout << Botan::version_string() << "\n"; - - if(BOTAN_VERSION_MAJOR != version_major() || - BOTAN_VERSION_MINOR != version_minor() || - BOTAN_VERSION_PATCH != version_patch()) - { - std::cout << "Warning: linked version (" - << version_major() << '.' - << version_minor() << '.' - << version_patch() - << ") does not match version built against (" - << BOTAN_VERSION_MAJOR << '.' - << BOTAN_VERSION_MINOR << '.' - << BOTAN_VERSION_PATCH << ")\n"; - } - - return 0; - } + if(cmd == "version" && argc > 1) + return version_main(argc - 1, argv + 1); if(cmd == "cpuid") { @@ -114,25 +155,27 @@ int main(int argc, char* argv[]) CALL_APP(base64); CALL_APP(bcrypt); CALL_APP(bzip); + CALL_APP(dsa_sign); + CALL_APP(dsa_verify); CALL_APP(factor); CALL_APP(fpe); CALL_APP(hash); CALL_APP(keygen); - CALL_APP(dsa_sign); - CALL_APP(dsa_verify); CALL_APP(read_ssh); + CALL_APP(speed); + #if defined(BOTAN_HAS_TLS) CALL_APP(tls_client); CALL_APP(tls_server); CALL_APP(tls_server_asio); #endif + #if defined(BOTAN_HAS_X509_CERTIFICATES) CALL_APP(ca); CALL_APP(pkcs10); CALL_APP(self_sig); CALL_APP(x509); #endif - CALL_APP(speed); std::cout << "Unknown command " << cmd << "\n"; return help(argc, argv); |