chiark / gitweb /
"make distcheck" now passes
[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 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 "disorder-server.h"
22
23 static const struct option options[] = {
24   { "help", no_argument, 0, 'h' },
25   { "version", no_argument, 0, 'V' },
26   { "config", required_argument, 0, 'c' },
27   { "debug", no_argument, 0, 'd' },
28   { "no-debug", no_argument, 0, 'D' },
29   { "syslog", no_argument, 0, 's' },
30   { "no-syslog", no_argument, 0, 'S' },
31   { 0, 0, 0, 0 }
32 };
33
34 /* display usage message and terminate */
35 static void help(void) {
36   xprintf("Usage:\n"
37           "  disorder-stats [OPTIONS]\n"
38           "Options:\n"
39           "  --help, -h               Display usage message\n"
40           "  --version, -V            Display version number\n"
41           "  --config PATH, -c PATH   Set configuration file\n"
42           "  --[no-]debug, -d         Turn on (off) debugging\n"
43           "  --[no-]syslog            Force logging\n"
44           "\n"
45           "Generate DisOrder database statistics.\n");
46   xfclose(stdout);
47   exit(0);
48 }
49
50 int main(int argc, char **argv) {
51   int n, logsyslog = !isatty(2);
52   char **stats;
53
54   set_progname(argv);
55   mem_init();
56   if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale");
57   while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) {
58     switch(n) {
59     case 'h': help();
60     case 'V': version("disorder-stats");
61     case 'c': configfile = optarg; break;
62     case 'd': debugging = 1; break;
63     case 'D': debugging = 0; break;
64     case 'S': logsyslog = 0; break;
65     case 's': logsyslog = 1; break;
66     default: fatal(0, "invalid option");
67     }
68   }
69   if(logsyslog) {
70     openlog(progname, LOG_PID, LOG_DAEMON);
71     log_default = &log_syslog;
72   }
73   if(config_read(0))
74     fatal(0, "cannot read configuration");
75   trackdb_init(TRACKDB_NO_RECOVER);
76   trackdb_open(TRACKDB_NO_UPGRADE);
77   stats = trackdb_stats(0);
78   while(*stats)
79     xprintf("%s\n", *stats++);
80   xfclose(stdout);
81   return 0;
82 }
83
84
85 /*
86 Local Variables:
87 c-basic-offset:2
88 comment-column:40
89 fill-column:79
90 indent-tabs-mode:nil
91 End:
92 */