Imported Upstream version 1.10
[platform/upstream/gdbm.git] / tests / gtver.c
1 /* This file is part of GDBM test suite.
2    Copyright (C) 2011 Free Software Foundation, Inc.
3
4    GDBM is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8
9    GDBM is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with GDBM. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include "autoconf.h"
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include "gdbm.h"
22 #include "progname.h"
23
24 #define major_number(lib) ((lib) ? gdbm_version_number[0] : GDBM_VERSION_MAJOR)
25 #define minor_number(lib) ((lib) ? gdbm_version_number[1] : GDBM_VERSION_MINOR)
26 #define patch_number(lib) ((lib) ? gdbm_version_number[2] : GDBM_VERSION_PATCH)
27
28 int
29 main (int argc, char **argv)
30 {
31   const char *progname = canonical_progname (argv[0]);
32   int library = 0;
33
34   if (argc == 1)
35     {
36       printf ("%s\n", gdbm_version);
37       exit (0);
38     }
39   
40   while (--argc)
41     {
42       char *arg = *++argv;
43
44       if (strcmp (arg, "-help") == 0)
45         {
46           printf ("usage: %s [-string] [-lib] [-header] [-major] [-minor] [-patch] [-full]\n", progname);
47           exit (0);
48         }
49       else if (strcmp (arg, "-string") == 0)
50         printf ("%s\n", gdbm_version);
51       else if (strcmp (arg, "-lib") == 0)
52         library = 1;
53       else if (strcmp (arg, "-header") == 0)
54         library = 0;
55       else if (strcmp (arg, "-major") == 0)
56         printf ("%d\n", major_number (library));
57       else if (strcmp (arg, "-minor") == 0)
58         printf ("%d\n", minor_number (library));
59       else if (strcmp (arg, "-patch") == 0)
60         printf ("%d\n", patch_number (library));
61       else if (strcmp (arg, "-full") == 0)
62         printf ("%d.%d.%d\n",
63                 major_number (library),
64                 minor_number (library),
65                 patch_number (library));
66       else
67         {
68           fprintf (stderr, "%s: unknown option %s\n",
69                    progname, arg);
70           exit (1);
71         }
72     }
73   exit (0);
74 }