chiark / gitweb /
Switch to GPL v3
[disorder] / server / stats.c
1 /*
2  * This file is part of DisOrder
3  * Copyright (C) 2007, 2008 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 3 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,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU 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, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include "disorder-server.h"
20
21 static const struct option options[] = {
22   { "help", no_argument, 0, 'h' },
23   { "version", no_argument, 0, 'V' },
24   { "config", required_argument, 0, 'c' },
25   { "debug", no_argument, 0, 'd' },
26   { "no-debug", no_argument, 0, 'D' },
27   { "syslog", no_argument, 0, 's' },
28   { "no-syslog", no_argument, 0, 'S' },
29   { 0, 0, 0, 0 }
30 };
31
32 /* display usage message and terminate */
33 static void help(void) {
34   xprintf("Usage:\n"
35           "  disorder-stats [OPTIONS]\n"
36           "Options:\n"
37           "  --help, -h               Display usage message\n"
38           "  --version, -V            Display version number\n"
39           "  --config PATH, -c PATH   Set configuration file\n"
40           "  --[no-]debug, -d         Turn on (off) debugging\n"
41           "  --[no-]syslog            Force logging\n"
42           "\n"
43           "Generate DisOrder database statistics.\n");
44   xfclose(stdout);
45   exit(0);
46 }
47
48 int main(int argc, char **argv) {
49   int n, logsyslog = !isatty(2);
50   char **stats;
51
52   set_progname(argv);
53   mem_init();
54   if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale");
55   while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) {
56     switch(n) {
57     case 'h': help();
58     case 'V': version("disorder-stats");
59     case 'c': configfile = optarg; break;
60     case 'd': debugging = 1; break;
61     case 'D': debugging = 0; break;
62     case 'S': logsyslog = 0; break;
63     case 's': logsyslog = 1; break;
64     default: fatal(0, "invalid option");
65     }
66   }
67   if(logsyslog) {
68     openlog(progname, LOG_PID, LOG_DAEMON);
69     log_default = &log_syslog;
70   }
71   if(config_read(0))
72     fatal(0, "cannot read configuration");
73   trackdb_init(TRACKDB_NO_RECOVER);
74   trackdb_open(TRACKDB_NO_UPGRADE);
75   stats = trackdb_stats(0);
76   while(*stats)
77     xprintf("%s\n", *stats++);
78   xfclose(stdout);
79   return 0;
80 }
81
82
83 /*
84 Local Variables:
85 c-basic-offset:2
86 comment-column:40
87 fill-column:79
88 indent-tabs-mode:nil
89 End:
90 */