chiark / gitweb /
Merge event scheduling implementation. This fixes defect #6,
[disorder] / server / trackname.c
1 /*
2  * This file is part of DisOrder.
3  * Copyright (C) 2004-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 <config.h>
22 #include "types.h"
23
24 #include <getopt.h>
25 #include <locale.h>
26 #include <errno.h>
27 #include <string.h>
28
29 #include "configuration.h"
30 #include "syscalls.h"
31 #include "log.h"
32 #include "trackname.h"
33 #include "mem.h"
34 #include "charset.h"
35 #include "defs.h"
36 #include "version.h"
37
38 static const struct option options[] = {
39   { "help", no_argument, 0, 'h' },
40   { "version", no_argument, 0, 'V' },
41   { "config", required_argument, 0, 'c' },
42   { "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           "  trackname [OPTIONS] TRACK CONTEXT PART\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           "  --debug, -d             Turn on debugging\n");
55   xfclose(stdout);
56   exit(0);
57 }
58
59 int main(int argc, char **argv) {
60   int n;
61   const char *s;
62
63   if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale");
64   while((n = getopt_long(argc, argv, "hVc:d", options, 0)) >= 0) {
65     switch(n) {
66     case 'h': help();
67     case 'V': version("trackname");
68     case 'c': configfile = optarg; break;
69     case 'd': debugging = 1; break;
70     default: fatal(0, "invalid option");
71     }
72   }
73   if(argc - optind < 3) fatal(0, "not enough arguments");
74   if(argc - optind > 3) fatal(0, "too many arguments");
75   if(config_read(0)) fatal(0, "cannot read configuration");
76   s = trackname_part(argv[optind], argv[optind+1], argv[optind+2]);
77   if(!s) fatal(0, "trackname_part returned NULL");
78   xprintf("%s\n", nullcheck(utf82mb(s)));
79   if(fclose(stdout) < 0) fatal(errno, "error closing stdout");
80   return 0;
81 }
82
83 /*
84 Local Variables:
85 c-basic-offset:2
86 comment-column:40
87 End:
88 */