Add a --version option

And fix that --reservation was missing from the optstring.
This commit is contained in:
Přemysl Eric Janouch 2020-09-05 20:00:11 +02:00
parent 796a9640d3
commit 46fa50749f
Signed by: p
GPG Key ID: A0420B94F92B9493
2 changed files with 15 additions and 2 deletions

View File

@ -1,4 +1,11 @@
project('pdf-simple-sign', 'cpp', default_options : ['cpp_std=c++11']) project('pdf-simple-sign', 'cpp', default_options : ['cpp_std=c++11'],
version : '1.0')
conf = configuration_data()
conf.set('PROJECT_NAME', '"' + meson.project_name() + '"')
conf.set('PROJECT_VERSION', '"' + meson.project_version() + '"')
configure_file(output : 'config.h', configuration : conf)
cryptodep = dependency('libcrypto') cryptodep = dependency('libcrypto')
executable('pdf-simple-sign', 'pdf-simple-sign.cpp', executable('pdf-simple-sign', 'pdf-simple-sign.cpp',
install : true, install : true,

View File

@ -37,6 +37,8 @@
#include <openssl/x509v3.h> #include <openssl/x509v3.h>
#include <openssl/pkcs12.h> #include <openssl/pkcs12.h>
#include "config.h"
// ------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------
using uint = unsigned int; using uint = unsigned int;
@ -952,6 +954,7 @@ int main(int argc, char* argv[]) {
static struct option opts[] = { static struct option opts[] = {
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"reservation", required_argument, 0, 'r'}, {"reservation", required_argument, 0, 'r'},
{nullptr, 0, 0, 0}, {nullptr, 0, 0, 0},
}; };
@ -961,7 +964,7 @@ int main(int argc, char* argv[]) {
while (1) { while (1) {
int option_index = 0; int option_index = 0;
auto c = getopt_long(argc, const_cast<char* const*>(argv), auto c = getopt_long(argc, const_cast<char* const*>(argv),
"h", opts, &option_index); "hVr:", opts, &option_index);
if (c == -1) if (c == -1)
break; break;
@ -972,6 +975,9 @@ int main(int argc, char* argv[]) {
if (errno || *end || reservation <= 0 || reservation > USHRT_MAX) if (errno || *end || reservation <= 0 || reservation > USHRT_MAX)
die(1, "%s: must be a positive number", optarg); die(1, "%s: must be a positive number", optarg);
break; break;
case 'V':
die(0, "%s", PROJECT_NAME " " PROJECT_VERSION);
break;
case 'h': case 'h':
default: default:
usage(); usage();