chiark / gitweb /
116fed5fd1c057f1fb3bdf34dcae1a3ad55f17ef
[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 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   { 0, 0, 0, 0 }
27 };
28
29 /* display usage message and terminate */
30 static void help(void) {
31   xprintf("Usage:\n"
32           "  trackname [OPTIONS] TRACK CONTEXT PART\n"
33           "Options:\n"
34           "  --help, -h              Display usage message\n"
35           "  --version, -V           Display version number\n"
36           "  --config PATH, -c PATH  Set configuration file\n"
37           "  --debug, -d             Turn on debugging\n");
38   xfclose(stdout);
39   exit(0);
40 }
41
42 int main(int argc, char **argv) {
43   int n;
44   const char *s;
45
46   if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale");
47   while((n = getopt_long(argc, argv, "hVc:d", options, 0)) >= 0) {
48     switch(n) {
49     case 'h': help();
50     case 'V': version("trackname");
51     case 'c': configfile = optarg; break;
52     case 'd': debugging = 1; break;
53     default: fatal(0, "invalid option");
54     }
55   }
56   if(argc - optind < 3) fatal(0, "not enough arguments");
57   if(argc - optind > 3) fatal(0, "too many arguments");
58   if(config_read(0)) fatal(0, "cannot read configuration");
59   s = trackname_part(argv[optind], argv[optind+1], argv[optind+2]);
60   if(!s) fatal(0, "trackname_part returned NULL");
61   xprintf("%s\n", nullcheck(utf82mb(s)));
62   if(fclose(stdout) < 0) fatal(errno, "error closing stdout");
63   return 0;
64 }
65
66 /*
67 Local Variables:
68 c-basic-offset:2
69 comment-column:40
70 End:
71 */