Commit | Line | Data |
---|---|---|
d6dde5a3 RK |
1 | /* |
2 | * This file is part of DisOrder | |
3 | * Copyright (C) 2007 Richard Kettlewell | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program; if not, write to the Free Software | |
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
18 | * USA | |
19 | */ | |
20 | ||
21 | #include <config.h> | |
22 | #include "types.h" | |
23 | ||
24 | #include <locale.h> | |
25 | #include <stdio.h> | |
26 | #include <errno.h> | |
27 | #include <pcre.h> | |
28 | #include <getopt.h> | |
29 | ||
30 | #include "defs.h" | |
31 | #include "mem.h" | |
32 | #include "log.h" | |
33 | #include "syscalls.h" | |
34 | #include "configuration.h" | |
35 | #include "trackdb.h" | |
36 | ||
37 | static const struct option options[] = { | |
38 | { "help", no_argument, 0, 'h' }, | |
39 | { "version", no_argument, 0, 'V' }, | |
40 | { "config", required_argument, 0, 'c' }, | |
41 | { "debug", no_argument, 0, 'd' }, | |
42 | { "no-debug", no_argument, 0, 'D' }, | |
43 | { 0, 0, 0, 0 } | |
44 | }; | |
45 | ||
46 | /* display usage message and terminate */ | |
47 | static void help(void) { | |
48 | xprintf("Usage:\n" | |
49 | " disorder-stats [OPTIONS]\n" | |
50 | "Options:\n" | |
51 | " --help, -h Display usage message\n" | |
52 | " --version, -V Display version number\n" | |
53 | " --config PATH, -c PATH Set configuration file\n" | |
54 | " --[no-]debug, -d Turn on (off) debugging\n" | |
55 | "\n" | |
56 | "Generate DisOrder database statistics.\n"); | |
57 | xfclose(stdout); | |
58 | exit(0); | |
59 | } | |
60 | ||
61 | /* display version number and terminate */ | |
62 | static void version(void) { | |
63 | xprintf("disorder-stats version %s\n", disorder_version_string); | |
64 | xfclose(stdout); | |
65 | exit(0); | |
66 | } | |
67 | ||
68 | int main(int argc, char **argv) { | |
69 | int n; | |
70 | char **stats; | |
71 | ||
72 | set_progname(argv); | |
73 | mem_init(); | |
74 | if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); | |
75 | while((n = getopt_long(argc, argv, "hVc:dD", options, 0)) >= 0) { | |
76 | switch(n) { | |
77 | case 'h': help(); | |
78 | case 'V': version(); | |
79 | case 'c': configfile = optarg; break; | |
80 | case 'd': debugging = 1; break; | |
81 | case 'D': debugging = 0; break; | |
82 | default: fatal(0, "invalid option"); | |
83 | } | |
84 | } | |
85 | if(config_read(0)) | |
86 | fatal(0, "cannot read configuration"); | |
87 | trackdb_init(0); | |
88 | trackdb_open(); | |
89 | stats = trackdb_stats(0); | |
90 | while(*stats) | |
91 | xprintf("%s\n", *stats++); | |
92 | xfclose(stdout); | |
93 | return 0; | |
94 | } | |
95 | ||
96 | ||
97 | /* | |
98 | Local Variables: | |
99 | c-basic-offset:2 | |
100 | comment-column:40 | |
101 | fill-column:79 | |
102 | indent-tabs-mode:nil | |
103 | End: | |
104 | */ |