2 * This file is part of DisOrder.
3 * Copyright (C) 2004-2009 Richard Kettlewell
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.
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.
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/>.
18 /** @file server/trackname.c
19 * @brief Utility to run the track name calculator in isolation
21 #include "disorder-server.h"
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' },
31 /* display usage message and terminate */
32 static void help(void) {
34 " trackname [OPTIONS] TRACK CONTEXT PART\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");
44 int main(int argc, char **argv) {
48 if(!setlocale(LC_CTYPE, ""))
49 disorder_fatal(errno, "error calling setlocale");
50 while((n = getopt_long(argc, argv, "hVc:d", options, 0)) >= 0) {
53 case 'V': version("trackname");
54 case 'c': configfile = optarg; break;
55 case 'd': debugging = 1; break;
56 default: disorder_fatal(0, "invalid option");
59 if(argc - optind < 3) disorder_fatal(0, "not enough arguments");
60 if(argc - optind > 3) disorder_fatal(0, "too many arguments");
61 if(config_read(0, NULL)) disorder_fatal(0, "cannot read configuration");
62 s = trackname_part(argv[optind], argv[optind+1], argv[optind+2]);
63 if(!s) disorder_fatal(0, "trackname_part returned NULL");
64 xprintf("%s\n", nullcheck(utf82mb(s)));
65 if(fclose(stdout) < 0) disorder_fatal(errno, "error closing stdout");