Add command line help/verbose options to gui too.
Refactor code to reduce code duplication across the two programs.
This commit is contained in:
parent
f86032d2b4
commit
5d5cba5e3f
10 changed files with 186 additions and 34 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
build
|
build
|
||||||
tags
|
tags
|
||||||
|
compile_commands.json
|
||||||
|
|
20
meson.build
20
meson.build
|
@ -9,7 +9,25 @@ if get_option('buildtype').startswith('debug')
|
||||||
is_debug_build = 1
|
is_debug_build = 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
cxxopts_incl = include_directories('subprojects/cxxopts/include')
|
cpp = meson.get_compiler('cpp')
|
||||||
|
|
||||||
|
conf = configuration_data()
|
||||||
|
version_arr = meson.project_version().split('.')
|
||||||
|
conf.set('PROJECT_NAME', meson.project_name())
|
||||||
|
conf.set('PROJECT_VERSION_MAJOR', version_arr[0])
|
||||||
|
conf.set('PROJECT_VERSION_MINOR', version_arr[1])
|
||||||
|
conf.set('PROJECT_VERSION_PATCH', version_arr[2])
|
||||||
|
conf.set('COMPILER_NAME', cpp.get_id())
|
||||||
|
conf.set('COMPILER_VERSION', cpp.version())
|
||||||
|
conf.set('COPYRIGHT_YEAR', '2020')
|
||||||
|
project_config_file = configure_file(
|
||||||
|
input: 'src/config.h.in',
|
||||||
|
output: 'config.h',
|
||||||
|
configuration: conf
|
||||||
|
)
|
||||||
|
app_config_model = files('src/app_config.h.in')
|
||||||
|
|
||||||
|
cxxopts_incl = include_directories('subprojects/cxxopts/include', '.')
|
||||||
|
|
||||||
memcard_proj = subproject('memcard')
|
memcard_proj = subproject('memcard')
|
||||||
memcard_dep = memcard_proj.get_variable('memcard_dep')
|
memcard_dep = memcard_proj.get_variable('memcard_dep')
|
||||||
|
|
|
@ -17,9 +17,5 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define PROJECT_NAME "@PROJECT_NAME@"
|
#define APP_NAME "@APP_NAME@"
|
||||||
#define PROJECT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
|
#define APP_SHORT_DESC "@APP_SHORT_DESC@"
|
||||||
#define PROJECT_VERSION_MINOR @PROJECT_VERSION_MINOR@
|
|
||||||
#define PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH@
|
|
||||||
#define COMPILER_NAME "@COMPILER_NAME@"
|
|
||||||
#define COMPILER_VERSION "@COMPILER_VERSION@"
|
|
|
@ -17,27 +17,18 @@
|
||||||
|
|
||||||
#include "memcard.hpp"
|
#include "memcard.hpp"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "app_config.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cxxopts.hpp>
|
#include <cxxopts.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#if !defined(STRINGIZE)
|
|
||||||
# define STRINGIZE_IMPL(s) #s
|
|
||||||
# define STRINGIZE(s) STRINGIZE_IMPL(s)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr const char* project_ver() {
|
|
||||||
return STRINGIZE(PROJECT_VERSION_MAJOR) "."
|
|
||||||
STRINGIZE(PROJECT_VERSION_MINOR) "."
|
|
||||||
STRINGIZE(PROJECT_VERSION_PATCH);
|
|
||||||
}
|
|
||||||
} //unnamed namespace
|
} //unnamed namespace
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
cxxopts::Options options(PROJECT_NAME, "PSX memory card inspector");
|
cxxopts::Options options(APP_NAME, APP_SHORT_DESC);
|
||||||
options.add_options()
|
options.add_options()
|
||||||
("h,help", "Show this help and quit")
|
("h,help", "Show this help and quit")
|
||||||
("version", "Print version info")
|
("version", "Print version info")
|
||||||
|
@ -61,7 +52,7 @@ int main(int argc, char* argv[]) {
|
||||||
std::cout << PROJECT_NAME << " v" << project_ver()
|
std::cout << PROJECT_NAME << " v" << project_ver()
|
||||||
<< " built with " COMPILER_NAME " " COMPILER_VERSION
|
<< " built with " COMPILER_NAME " " COMPILER_VERSION
|
||||||
<< '\n';
|
<< '\n';
|
||||||
std::cout << "Copyright (C) 2020 Michele Santullo\n";
|
std::cout << "Copyright (C) " COPYRIGHT_YEAR " Michele Santullo\n";
|
||||||
std::cout << "This is free software; see the source for copying conditions. There is NO\n";
|
std::cout << "This is free software; see the source for copying conditions. There is NO\n";
|
||||||
std::cout << "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." << std::endl;
|
std::cout << "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." << std::endl;
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,17 @@
|
||||||
cpp = meson.get_compiler('cpp')
|
app_name = meson.project_name()
|
||||||
|
|
||||||
conf = configuration_data()
|
conf = configuration_data()
|
||||||
version_arr = meson.project_version().split('.')
|
conf.set('APP_NAME', app_name)
|
||||||
conf.set('PROJECT_NAME', meson.project_name())
|
conf.set('APP_SHORT_DESC', 'PSX memory card inspector')
|
||||||
conf.set('PROJECT_VERSION_MAJOR', version_arr[0])
|
|
||||||
conf.set('PROJECT_VERSION_MINOR', version_arr[1])
|
|
||||||
conf.set('PROJECT_VERSION_PATCH', version_arr[2])
|
|
||||||
conf.set('COMPILER_NAME', cpp.get_id())
|
|
||||||
conf.set('COMPILER_VERSION', cpp.version())
|
|
||||||
config_file = configure_file(
|
config_file = configure_file(
|
||||||
input: 'config.h.in',
|
input: app_config_model,
|
||||||
output: 'config.h',
|
output: 'app_config.h',
|
||||||
configuration: conf
|
configuration: conf
|
||||||
)
|
)
|
||||||
|
|
||||||
executable(meson.project_name(),
|
executable(app_name,
|
||||||
'main.cpp',
|
'main.cpp',
|
||||||
'memcard.cpp',
|
'memcard.cpp',
|
||||||
|
project_config_file,
|
||||||
config_file,
|
config_file,
|
||||||
dependencies: [
|
dependencies: [
|
||||||
memcard_dep
|
memcard_dep
|
||||||
|
|
47
src/config.h.in
Normal file
47
src/config.h.in
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/* Copyright 2020, Michele Santullo
|
||||||
|
* This file is part of memoserv.
|
||||||
|
*
|
||||||
|
* Memoserv 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.
|
||||||
|
*
|
||||||
|
* Memoserv 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 Memoserv. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define PROJECT_NAME "@PROJECT_NAME@"
|
||||||
|
#define PROJECT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
|
||||||
|
#define PROJECT_VERSION_MINOR @PROJECT_VERSION_MINOR@
|
||||||
|
#define PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH@
|
||||||
|
#define COMPILER_NAME "@COMPILER_NAME@"
|
||||||
|
#define COMPILER_VERSION "@COMPILER_VERSION@"
|
||||||
|
#define COPYRIGHT_YEAR "@COPYRIGHT_YEAR@"
|
||||||
|
|
||||||
|
#if !defined(STRINGIZE)
|
||||||
|
# define STRINGIZE_IMPL(s) #s
|
||||||
|
# define STRINGIZE(s) STRINGIZE_IMPL(s)
|
||||||
|
# define CONFIG_UNDEF_STRINGIZE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
constexpr
|
||||||
|
#endif
|
||||||
|
inline const char* project_ver() {
|
||||||
|
return STRINGIZE(PROJECT_VERSION_MAJOR) "."
|
||||||
|
STRINGIZE(PROJECT_VERSION_MINOR) "."
|
||||||
|
STRINGIZE(PROJECT_VERSION_PATCH);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(CONFIG_UNDEF_STRINGIZE)
|
||||||
|
# undef CONFIG_UNDEF_STRINGIZE
|
||||||
|
# undef STRINGIZE_IMPL
|
||||||
|
# undef STRINGIZE
|
||||||
|
#endif
|
57
src/gui/command_line.cpp
Normal file
57
src/gui/command_line.cpp
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/* Copyright 2020, Michele Santullo
|
||||||
|
* This file is part of memoserv.
|
||||||
|
*
|
||||||
|
* Memoserv 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.
|
||||||
|
*
|
||||||
|
* Memoserv 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 Memoserv. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "command_line.hpp"
|
||||||
|
#include "config.h"
|
||||||
|
#include "app_config.h"
|
||||||
|
#include <cxxopts.hpp>
|
||||||
|
|
||||||
|
namespace mc {
|
||||||
|
CommandLineResult::CommandLineResult() :
|
||||||
|
should_quit(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandLineResult parse_command_line (int argc, char* argv[]) {
|
||||||
|
cxxopts::Options options(APP_NAME, APP_SHORT_DESC);
|
||||||
|
options.add_options()
|
||||||
|
("h,help", "Show this help and quit")
|
||||||
|
("version", "Print version info")
|
||||||
|
;
|
||||||
|
auto command = options.parse(argc, argv);
|
||||||
|
CommandLineResult retval;
|
||||||
|
|
||||||
|
if (command.count("help")) {
|
||||||
|
std::cout << options.help() << std::endl;
|
||||||
|
retval.should_quit = true;
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.count("version")) {
|
||||||
|
std::cout << PROJECT_NAME << " v" << project_ver()
|
||||||
|
<< " built with " COMPILER_NAME " " COMPILER_VERSION
|
||||||
|
<< '\n';
|
||||||
|
std::cout << "Copyright (C) " COPYRIGHT_YEAR " Michele Santullo\n";
|
||||||
|
std::cout << "This is free software; see the source for copying conditions. There is NO\n";
|
||||||
|
std::cout << "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." << std::endl;
|
||||||
|
retval.should_quit = true;
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
} //namespace mc
|
28
src/gui/command_line.hpp
Normal file
28
src/gui/command_line.hpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/* Copyright 2020, Michele Santullo
|
||||||
|
* This file is part of memoserv.
|
||||||
|
*
|
||||||
|
* Memoserv 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.
|
||||||
|
*
|
||||||
|
* Memoserv 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 Memoserv. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace mc {
|
||||||
|
struct CommandLineResult {
|
||||||
|
CommandLineResult();
|
||||||
|
|
||||||
|
bool should_quit;
|
||||||
|
};
|
||||||
|
|
||||||
|
CommandLineResult parse_command_line (int argc, char* argv[]);
|
||||||
|
} //namespace mc
|
|
@ -19,6 +19,7 @@
|
||||||
#include "widget/block_grid.hpp"
|
#include "widget/block_grid.hpp"
|
||||||
#include "make_nana_animation.hpp"
|
#include "make_nana_animation.hpp"
|
||||||
#include "memcard/make_memory_card.hpp"
|
#include "memcard/make_memory_card.hpp"
|
||||||
|
#include "command_line.hpp"
|
||||||
#include <nana/gui.hpp>
|
#include <nana/gui.hpp>
|
||||||
#include <nana/gui/widgets/label.hpp>
|
#include <nana/gui/widgets/label.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -32,8 +33,13 @@ namespace {
|
||||||
const constexpr int g_def_icon_fps = 3;
|
const constexpr int g_def_icon_fps = 3;
|
||||||
} //unnamed namespace
|
} //unnamed namespace
|
||||||
|
|
||||||
int main() {
|
int main(int argc, char* argv[]) {
|
||||||
using mc::psx::MemoryCard;
|
using mc::psx::MemoryCard;
|
||||||
|
|
||||||
|
auto command = mc::parse_command_line(argc, argv);
|
||||||
|
if (command.should_quit)
|
||||||
|
return 0;
|
||||||
|
|
||||||
nana::form frm;
|
nana::form frm;
|
||||||
|
|
||||||
const MemoryCard mc1(mc::psx::make_memory_card("/home/michele/dev/code/cpp/memoserv/epsxe000_xa2.mcr"));
|
const MemoryCard mc1(mc::psx::make_memory_card("/home/michele/dev/code/cpp/memoserv/epsxe000_xa2.mcr"));
|
||||||
|
|
|
@ -19,11 +19,24 @@ libfontconfig_dep = dependency('fontconfig')
|
||||||
libthread_dep = dependency('threads')
|
libthread_dep = dependency('threads')
|
||||||
fslib_dep = cpp.find_library('stdc++fs', required: false)
|
fslib_dep = cpp.find_library('stdc++fs', required: false)
|
||||||
|
|
||||||
executable(meson.project_name() + 'gui',
|
app_name = meson.project_name() + 'gui'
|
||||||
|
conf = configuration_data()
|
||||||
|
conf.set('APP_NAME', app_name)
|
||||||
|
conf.set('APP_SHORT_DESC', 'PSX memory card inspector')
|
||||||
|
config_file = configure_file(
|
||||||
|
input: app_config_model,
|
||||||
|
output: 'app_config.h',
|
||||||
|
configuration: conf
|
||||||
|
)
|
||||||
|
|
||||||
|
executable(app_name,
|
||||||
'main.cpp',
|
'main.cpp',
|
||||||
'widget/block_grid.cpp',
|
'widget/block_grid.cpp',
|
||||||
'make_nana_animation.cpp',
|
'make_nana_animation.cpp',
|
||||||
'animation_with_size.cpp',
|
'animation_with_size.cpp',
|
||||||
|
'command_line.cpp',
|
||||||
|
config_file,
|
||||||
|
project_config_file,
|
||||||
dependencies: [
|
dependencies: [
|
||||||
nana_dep,
|
nana_dep,
|
||||||
x11_dep,
|
x11_dep,
|
||||||
|
@ -36,5 +49,5 @@ executable(meson.project_name() + 'gui',
|
||||||
fslib_dep,
|
fslib_dep,
|
||||||
],
|
],
|
||||||
install: true,
|
install: true,
|
||||||
include_directories: nana_incl_search,
|
include_directories: [nana_incl_search, cxxopts_incl]
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue