chiark / gitweb /
disorder-choose rejects tracks in queue/recent list
[disorder] / server / stats.c
CommitLineData
d6dde5a3
RK
1/*
2 * This file is part of DisOrder
5aff007d 3 * Copyright (C) 2007, 2008 Richard Kettlewell
d6dde5a3
RK
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>
0ca6d097 29#include <syslog.h>
95daf696 30#include <unistd.h>
d6dde5a3
RK
31
32#include "defs.h"
33#include "mem.h"
34#include "log.h"
35#include "syscalls.h"
36#include "configuration.h"
5df73aeb 37#include "rights.h"
d6dde5a3 38#include "trackdb.h"
811263fd 39#include "version.h"
d6dde5a3
RK
40
41static const struct option options[] = {
42 { "help", no_argument, 0, 'h' },
43 { "version", no_argument, 0, 'V' },
44 { "config", required_argument, 0, 'c' },
45 { "debug", no_argument, 0, 'd' },
46 { "no-debug", no_argument, 0, 'D' },
0ca6d097
RK
47 { "syslog", no_argument, 0, 's' },
48 { "no-syslog", no_argument, 0, 'S' },
d6dde5a3
RK
49 { 0, 0, 0, 0 }
50};
51
52/* display usage message and terminate */
53static void help(void) {
54 xprintf("Usage:\n"
55 " disorder-stats [OPTIONS]\n"
56 "Options:\n"
57 " --help, -h Display usage message\n"
58 " --version, -V Display version number\n"
59 " --config PATH, -c PATH Set configuration file\n"
60 " --[no-]debug, -d Turn on (off) debugging\n"
0ca6d097 61 " --[no-]syslog Force logging\n"
d6dde5a3
RK
62 "\n"
63 "Generate DisOrder database statistics.\n");
64 xfclose(stdout);
65 exit(0);
66}
67
d6dde5a3 68int main(int argc, char **argv) {
0ca6d097 69 int n, logsyslog = !isatty(2);
d6dde5a3
RK
70 char **stats;
71
72 set_progname(argv);
73 mem_init();
74 if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale");
0ca6d097 75 while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) {
d6dde5a3
RK
76 switch(n) {
77 case 'h': help();
811263fd 78 case 'V': version("disorder-stats");
d6dde5a3
RK
79 case 'c': configfile = optarg; break;
80 case 'd': debugging = 1; break;
81 case 'D': debugging = 0; break;
0ca6d097
RK
82 case 'S': logsyslog = 0; break;
83 case 's': logsyslog = 1; break;
d6dde5a3
RK
84 default: fatal(0, "invalid option");
85 }
86 }
0ca6d097
RK
87 if(logsyslog) {
88 openlog(progname, LOG_PID, LOG_DAEMON);
89 log_default = &log_syslog;
90 }
d6dde5a3
RK
91 if(config_read(0))
92 fatal(0, "cannot read configuration");
d25c4615
RK
93 trackdb_init(TRACKDB_NO_RECOVER);
94 trackdb_open(TRACKDB_NO_UPGRADE);
d6dde5a3
RK
95 stats = trackdb_stats(0);
96 while(*stats)
97 xprintf("%s\n", *stats++);
98 xfclose(stdout);
99 return 0;
100}
101
102
103/*
104Local Variables:
105c-basic-offset:2
106comment-column:40
107fill-column:79
108indent-tabs-mode:nil
109End:
110*/