From c409a3e0a2299fe32a8cf341de2eb3dbd90997c1 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sat, 26 Dec 2015 14:51:49 +0000 Subject: [PATCH] Make main dindexer show options used to build. --- cmake/Modules/WithMediaAutodetect.cmake | 7 ++++ src/common/commandline.cpp | 2 +- src/main/CMakeLists.txt | 9 +++++ src/main/builtin_feats.c | 50 +++++++++++++++++++++++++ src/main/builtin_feats.h | 23 ++++++++++++ src/main/main.c | 50 ++++++++++++++++++------- src/scan/CMakeLists.txt | 9 +---- 7 files changed, 127 insertions(+), 23 deletions(-) create mode 100644 cmake/Modules/WithMediaAutodetect.cmake create mode 100644 src/main/builtin_feats.c create mode 100644 src/main/builtin_feats.h diff --git a/cmake/Modules/WithMediaAutodetect.cmake b/cmake/Modules/WithMediaAutodetect.cmake new file mode 100644 index 0000000..4946222 --- /dev/null +++ b/cmake/Modules/WithMediaAutodetect.cmake @@ -0,0 +1,7 @@ +if (DINDEXER_WITH_MEDIA_AUTODETECT) + find_package(blkid) + if (NOT BLKID_FOUND) + message(STATUS "libblkid not found, media autodetection will be disabled") + set(DINDEXER_WITH_MEDIA_AUTODETECT OFF) + endif() +endif() diff --git a/src/common/commandline.cpp b/src/common/commandline.cpp index d28087c..4b81483 100644 --- a/src/common/commandline.cpp +++ b/src/common/commandline.cpp @@ -37,7 +37,7 @@ namespace dinlib { #if VERSION_BETA "b" #endif - ; + ; } //unnamed namespace po::options_description get_default_commandline() { diff --git a/src/main/CMakeLists.txt b/src/main/CMakeLists.txt index 502ee2a..766deba 100644 --- a/src/main/CMakeLists.txt +++ b/src/main/CMakeLists.txt @@ -1,8 +1,11 @@ project(${bare_name} C) +include(WithMediaAutodetect) + add_executable(${PROJECT_NAME} main.c findactions.c + builtin_feats.c ) target_include_directories(${PROJECT_NAME} @@ -12,3 +15,9 @@ target_include_directories(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME} PRIVATE ${bare_name}-inc ) + +if (DINDEXER_WITH_MEDIA_AUTODETECT) + target_compile_definitions(${PROJECT_NAME} + PRIVATE WITH_MEDIA_AUTODETECT + ) +endif() diff --git a/src/main/builtin_feats.c b/src/main/builtin_feats.c new file mode 100644 index 0000000..d648194 --- /dev/null +++ b/src/main/builtin_feats.c @@ -0,0 +1,50 @@ +/* Copyright 2015, Michele Santullo + * This file is part of "dindexer". + * + * "dindexer" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * "dindexer" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with "dindexer". If not, see . + */ + +#include +#include "dindexerConfig.h" + +void print_builtin_feats() { +#if VERSION_BETA + char beta_str[2] = "b"; +#else + char beta_str[1] = ""; +#endif + + printf("%s v %d.%d.%d%s\nRev %s\n", + PROGRAM_NAME, + VERSION_MAJOR, + VERSION_MINOR, + VERSION_PATCH, + beta_str, + VERSION_GIT + ); + + printf("CONFIG_FILE_PATH = \"%s\"\n", CONFIG_FILE_PATH); + printf("ACTIONS_SEARCH_PATH = \"%s\"\n", ACTIONS_SEARCH_PATH); + printf("ACTION_PREFIX = \"%s\"\n", ACTION_PREFIX); +#if defined(WITH_MEDIA_AUTODETECT) + printf("WITH_MEDIA_AUTODETECT = yes\n"); +#else + printf("WITH_MEDIA_AUTODETECT = no\n"); +#endif +#if defined(NDEBUG) + printf("NDEBUG = yes (Release build)\n"); +#else + printf("NDEBUG = no (Debug build)\n"); +#endif +} diff --git a/src/main/builtin_feats.h b/src/main/builtin_feats.h new file mode 100644 index 0000000..ccfb7a9 --- /dev/null +++ b/src/main/builtin_feats.h @@ -0,0 +1,23 @@ +/* Copyright 2015, Michele Santullo + * This file is part of "dindexer". + * + * "dindexer" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * "dindexer" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with "dindexer". If not, see . + */ + +#ifndef id17B851C76AD54C8B9A2098323FC83038 +#define id17B851C76AD54C8B9A2098323FC83038 + +void print_builtin_feats ( void ); + +#endif diff --git a/src/main/main.c b/src/main/main.c index 41740f5..6d499ee 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -23,10 +23,12 @@ #include "dindexerConfig.h" #include "findactions.h" #include "helpers/lengthof.h" +#include "builtin_feats.h" -static size_t foreach_avail_action ( int(*parFunc)(const char*, const char*), char** parList, size_t parCount, char* parPass ); -static int printf_stderr ( const char* parMsg, const char* parUnused ); -static int same_action ( const char* parAction1, const char* parAction2 ); +static size_t foreach_avail_action ( int(*parFunc)(const char*, const void*), char** parList, size_t parCount, const void* parPass ); +static int printf_stream ( const char* parMsg, const void* parStream ); +static int same_action ( const char* parAction1, const void* parAction2 ); +static void print_usage ( void ); int main (int parArgc, char* parArgv[]) { size_t z; @@ -36,6 +38,8 @@ int main (int parArgc, char* parArgv[]) { size_t action_path_length; size_t selected_action; char** argv; + FILE* streamout; + int retval; find_actions(&actions, &actions_count); if (0 == actions_count) { @@ -44,22 +48,33 @@ int main (int parArgc, char* parArgv[]) { } if (parArgc < 2 or strcmp("-h", parArgv[1]) == 0 or strcmp("--help", parArgv[1]) == 0) { - fprintf(stderr, "No action specified. Available actions are:\n"); - foreach_avail_action(&printf_stderr, actions, actions_count, NULL); - free_actions(actions, actions_count); if (parArgc < 2) { - return 2; + streamout = stderr; + fprintf(stderr, "No action specified. "); + retval = 2; } else { - return 0; + print_usage(); + printf("\n"); + streamout = stdout; + retval = 0; } + fprintf(streamout, "Available actions are:\n"); + foreach_avail_action(&printf_stream, actions, actions_count, streamout); + free_actions(actions, actions_count); + return retval; + } + else if (strcmp("--builtin", parArgv[1]) == 0) { + print_builtin_feats(); + free_actions(actions, actions_count); + return 0; } selected_action = foreach_avail_action(&same_action, actions, actions_count, parArgv[1]); if (actions_count == selected_action) { fprintf(stderr, "Unrecognized action \"%s\" - available actions are:\n", parArgv[1]); - foreach_avail_action(&printf_stderr, actions, actions_count, NULL); + foreach_avail_action(&printf_stream, actions, actions_count, stderr); free_actions(actions, actions_count); return 2; } @@ -96,7 +111,7 @@ int main (int parArgc, char* parArgv[]) { return 0; } -static size_t foreach_avail_action(int(*parFunc)(const char*, const char*), char** parList, size_t parCount, char* parPass) { +static size_t foreach_avail_action(int(*parFunc)(const char*, const void*), char** parList, size_t parCount, const void* parPass) { size_t z; const char* cmd_name_start; int stop; @@ -112,16 +127,23 @@ static size_t foreach_avail_action(int(*parFunc)(const char*, const char*), char return z; } -static int printf_stderr (const char* parMsg, const char* parUnused) { - fprintf(stderr, "\t%s\n", parMsg); +static int printf_stream (const char* parMsg, const void* parStream) { + FILE* stream = (FILE*)parStream; + fprintf(stream, "\t%s\n", parMsg); return 0; } -static int same_action (const char* parAction1, const char* parAction2) { - if (0 == strcmp(parAction1, parAction2)) { +static int same_action (const char* parAction1, const void* parAction2) { + const char* const action2 = (const char*)parAction2; + if (0 == strcmp(parAction1, action2)) { return 1; } else { return 0; } } + +static void print_usage() { + printf("--help - show this help\n"); + printf("--builtin - show build info\n"); +} diff --git a/src/scan/CMakeLists.txt b/src/scan/CMakeLists.txt index 6c6dc10..2392dcb 100644 --- a/src/scan/CMakeLists.txt +++ b/src/scan/CMakeLists.txt @@ -1,13 +1,6 @@ project(${bare_name}-scan CXX C) -if (DINDEXER_WITH_MEDIA_AUTODETECT) - find_package(blkid) - if (NOT BLKID_FOUND) - message(STATUS "libblkid not found, media autodetection will be disabled") - set(DINDEXER_WITH_MEDIA_AUTODETECT OFF) - endif() -endif() - +include(WithMediaAutodetect) find_package(Magic REQUIRED) add_executable(${PROJECT_NAME}