From 7c02e3bda0ce6a1c94ebce7b25e56aa2f6b69242 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Wed, 3 Aug 2011 17:36:45 +0000 Subject: New file. --- tests/gtver.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 tests/gtver.c (limited to 'tests') diff --git a/tests/gtver.c b/tests/gtver.c new file mode 100644 index 0000000..0865666 --- /dev/null +++ b/tests/gtver.c @@ -0,0 +1,88 @@ +/* This file is part of GDBM test suite. + Copyright (C) 2011 Free Software Foundation, Inc. + + GDBM 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 2, or (at your option) + any later version. + + GDBM 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 GDBM. If not, see . +*/ +#include "autoconf.h" +#include +#include +#include +#include "gdbm.h" + +const char * +canonical_progname (const char *str) +{ + const char *p; + + p = strrchr (str, '/'); + if (p) + p++; + else + p = str; + if (strncmp (p, "lt-", 3) == 0) + p += 3; + return p; +} + +#define major_number(lib) ((lib) ? gdbm_version_number[0] : GDBM_VERSION_MAJOR) +#define minor_number(lib) ((lib) ? gdbm_version_number[1] : GDBM_VERSION_MINOR) +#define patch_number(lib) ((lib) ? gdbm_version_number[2] : GDBM_VERSION_PATCH) + +int +main (int argc, char **argv) +{ + const char *progname = canonical_progname (argv[0]); + int library = 0; + + if (argc == 1) + { + printf ("%s\n", gdbm_version); + exit (0); + } + + while (--argc) + { + char *arg = *++argv; + + if (strcmp (arg, "-help") == 0) + { + printf ("usage: %s [-string] [-lib] [-header] [-major] [-minor] [-patch] [-full]\n", progname); + exit (0); + } + else if (strcmp (arg, "-string") == 0) + printf ("%s\n", gdbm_version); + else if (strcmp (arg, "-lib") == 0) + library = 1; + else if (strcmp (arg, "-header") == 0) + library = 0; + else if (strcmp (arg, "-major") == 0) + printf ("%d\n", major_number (library)); + else if (strcmp (arg, "-minor") == 0) + printf ("%d\n", minor_number (library)); + else if (strcmp (arg, "-patch") == 0) + printf ("%d\n", patch_number (library)); + else if (strcmp (arg, "-full") == 0) + printf ("%d.%d.%d\n", + major_number (library), + minor_number (library), + patch_number (library)); + else + { + fprintf (stderr, "%s: unknown option %s\n", + progname, arg); + exit (1); + } + } + exit (0); +} -- cgit v1.2.1