mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-08-07 13:29:49 +00:00
Make main dindexer show options used to build.
This commit is contained in:
parent
05979e24a2
commit
c409a3e0a2
7 changed files with 127 additions and 23 deletions
7
cmake/Modules/WithMediaAutodetect.cmake
Normal file
7
cmake/Modules/WithMediaAutodetect.cmake
Normal file
|
@ -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()
|
|
@ -37,7 +37,7 @@ namespace dinlib {
|
||||||
#if VERSION_BETA
|
#if VERSION_BETA
|
||||||
"b"
|
"b"
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
} //unnamed namespace
|
} //unnamed namespace
|
||||||
|
|
||||||
po::options_description get_default_commandline() {
|
po::options_description get_default_commandline() {
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
project(${bare_name} C)
|
project(${bare_name} C)
|
||||||
|
|
||||||
|
include(WithMediaAutodetect)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME}
|
||||||
main.c
|
main.c
|
||||||
findactions.c
|
findactions.c
|
||||||
|
builtin_feats.c
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME}
|
target_include_directories(${PROJECT_NAME}
|
||||||
|
@ -12,3 +15,9 @@ target_include_directories(${PROJECT_NAME}
|
||||||
target_link_libraries(${PROJECT_NAME}
|
target_link_libraries(${PROJECT_NAME}
|
||||||
PRIVATE ${bare_name}-inc
|
PRIVATE ${bare_name}-inc
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (DINDEXER_WITH_MEDIA_AUTODETECT)
|
||||||
|
target_compile_definitions(${PROJECT_NAME}
|
||||||
|
PRIVATE WITH_MEDIA_AUTODETECT
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
50
src/main/builtin_feats.c
Normal file
50
src/main/builtin_feats.c
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#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
|
||||||
|
}
|
23
src/main/builtin_feats.h
Normal file
23
src/main/builtin_feats.h
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef id17B851C76AD54C8B9A2098323FC83038
|
||||||
|
#define id17B851C76AD54C8B9A2098323FC83038
|
||||||
|
|
||||||
|
void print_builtin_feats ( void );
|
||||||
|
|
||||||
|
#endif
|
|
@ -23,10 +23,12 @@
|
||||||
#include "dindexerConfig.h"
|
#include "dindexerConfig.h"
|
||||||
#include "findactions.h"
|
#include "findactions.h"
|
||||||
#include "helpers/lengthof.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 size_t foreach_avail_action ( int(*parFunc)(const char*, const void*), char** parList, size_t parCount, const void* parPass );
|
||||||
static int printf_stderr ( const char* parMsg, const char* parUnused );
|
static int printf_stream ( const char* parMsg, const void* parStream );
|
||||||
static int same_action ( const char* parAction1, const char* parAction2 );
|
static int same_action ( const char* parAction1, const void* parAction2 );
|
||||||
|
static void print_usage ( void );
|
||||||
|
|
||||||
int main (int parArgc, char* parArgv[]) {
|
int main (int parArgc, char* parArgv[]) {
|
||||||
size_t z;
|
size_t z;
|
||||||
|
@ -36,6 +38,8 @@ int main (int parArgc, char* parArgv[]) {
|
||||||
size_t action_path_length;
|
size_t action_path_length;
|
||||||
size_t selected_action;
|
size_t selected_action;
|
||||||
char** argv;
|
char** argv;
|
||||||
|
FILE* streamout;
|
||||||
|
int retval;
|
||||||
|
|
||||||
find_actions(&actions, &actions_count);
|
find_actions(&actions, &actions_count);
|
||||||
if (0 == 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) {
|
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) {
|
if (parArgc < 2) {
|
||||||
return 2;
|
streamout = stderr;
|
||||||
|
fprintf(stderr, "No action specified. ");
|
||||||
|
retval = 2;
|
||||||
}
|
}
|
||||||
else {
|
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]);
|
selected_action = foreach_avail_action(&same_action, actions, actions_count, parArgv[1]);
|
||||||
|
|
||||||
if (actions_count == selected_action) {
|
if (actions_count == selected_action) {
|
||||||
fprintf(stderr, "Unrecognized action \"%s\" - available actions are:\n", parArgv[1]);
|
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);
|
free_actions(actions, actions_count);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
@ -96,7 +111,7 @@ int main (int parArgc, char* parArgv[]) {
|
||||||
return 0;
|
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;
|
size_t z;
|
||||||
const char* cmd_name_start;
|
const char* cmd_name_start;
|
||||||
int stop;
|
int stop;
|
||||||
|
@ -112,16 +127,23 @@ static size_t foreach_avail_action(int(*parFunc)(const char*, const char*), char
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int printf_stderr (const char* parMsg, const char* parUnused) {
|
static int printf_stream (const char* parMsg, const void* parStream) {
|
||||||
fprintf(stderr, "\t%s\n", parMsg);
|
FILE* stream = (FILE*)parStream;
|
||||||
|
fprintf(stream, "\t%s\n", parMsg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int same_action (const char* parAction1, const char* parAction2) {
|
static int same_action (const char* parAction1, const void* parAction2) {
|
||||||
if (0 == strcmp(parAction1, parAction2)) {
|
const char* const action2 = (const char*)parAction2;
|
||||||
|
if (0 == strcmp(parAction1, action2)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void print_usage() {
|
||||||
|
printf("--help - show this help\n");
|
||||||
|
printf("--builtin - show build info\n");
|
||||||
|
}
|
||||||
|
|
|
@ -1,13 +1,6 @@
|
||||||
project(${bare_name}-scan CXX C)
|
project(${bare_name}-scan CXX C)
|
||||||
|
|
||||||
if (DINDEXER_WITH_MEDIA_AUTODETECT)
|
include(WithMediaAutodetect)
|
||||||
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()
|
|
||||||
|
|
||||||
find_package(Magic REQUIRED)
|
find_package(Magic REQUIRED)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue