#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <libdivecomputer/context.h>
#include <libdivecomputer/descriptor.h>
#include <libdivecomputer/version.h>
#include "dctool.h"
static int
dctool_version_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t *descriptor)
{
unsigned int help = 0;
int opt = 0;
const char *optstring = "h";
#ifdef HAVE_GETOPT_LONG
struct option options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0 }
};
while ((opt = getopt_long (argc, argv, optstring, options, NULL)) != -1) {
#else
while ((opt = getopt (argc, argv, optstring)) != -1) {
#endif
switch (opt) {
case 'h':
help = 1;
break;
default:
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
if (help) {
dctool_command_showhelp (&dctool_version);
return EXIT_SUCCESS;
}
printf ("libdivecomputer version %s\n", dc_version (NULL));
return EXIT_SUCCESS;
}
const dctool_command_t dctool_version = {
dctool_version_run,
DCTOOL_CONFIG_NONE,
"version",
"Show version information",
"Usage:\n"
" dctool version [options]\n"
"\n"
"Options:\n"
#ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n"
#else
" -h Show help message\n"
#endif
};