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