1 /*
2 * madplay - MPEG audio decoder and player
3 * Copyright (C) 2000-2004 Robert Leslie
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,
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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * $Id: madtag.c,v 1.2 2004/01/23 09:41:32 rob Exp $
20 */
21
22 # ifdef HAVE_CONFIG_H
23 # include "config.h"
24 # endif
25
26 # include "global.h"
27
28 /* include this first to avoid conflicts with MinGW __argc et al. */
29 # include "getopt.h"
30
31 # include <locale.h>
32 # include <stdio.h>
33 # include <stdlib.h>
34
35 # ifdef HAVE_ASSERT_H
36 # include <assert.h>
37 # endif
38
39 # include <id3tag.h>
40
41 # include "gettext.h"
42
43 # include "tagger.h"
44
45 static
46 struct option const options[] = {
47 { "help", no_argument, 0, 'h' },
48 { "version", no_argument, 0, 'V' },
49 { 0 }
50 };
51
52 char const *argv0;
53
54 # define EPUTS(str) fputs(_(str), stream)
55
56 /*
57 * NAME: show_usage()
58 * DESCRIPTION: display usage message
59 */
60 static
show_usage(int verbose)61 void show_usage(int verbose)
62 {
63 FILE *stream = verbose ? stdout : stderr;
64
65 fprintf(stream, _("Usage: %s [OPTIONS] FILE [...]\n"), argv0);
66
67 if (!verbose) {
68 fprintf(stream, _("Try `%s --help' for more information.\n"), argv0);
69 return;
70 }
71
72 EPUTS(_("Display or modify ID3 tags in FILE(s).\n"));
73
74 /* the following usage text should agree with the option names */
75
76 EPUTS(_("\nMiscellaneous:\n"));
77 EPUTS(_(" -V, --version display version number and exit\n"));
78 EPUTS(_(" -h, --help display this help and exit\n"));
79 }
80
81 # undef EPUTS
82
83 /*
84 * NAME: get_options()
85 * DESCRIPTION: parse command-line options or die
86 */
87 static
get_options(int argc,char * argv[],struct tagger * tagger)88 void get_options(int argc, char *argv[], struct tagger *tagger)
89 {
90 int opt, index;
91
92 while ((opt = getopt_long(argc, argv,
93 "Vh", /* miscellaneous options */
94 options, &index)) != -1) {
95 switch (opt) {
96 case 0:
97 break;
98
99 case 'h':
100 show_usage(1);
101 exit(0);
102
103 case 'V':
104 fprintf(stderr, "%s %s\n %s %s %s\n",
105 _("ID3 Tag Library"), ID3_VERSION,
106 _("Copyright (C)"), ID3_PUBLISHYEAR, ID3_AUTHOR);
107 exit(0);
108
109 case '?':
110 show_usage(0);
111 exit(1);
112
113 default:
114 assert(!"option handler");
115 }
116 }
117
118 if (optind == argc) {
119 show_usage(0);
120 exit(2);
121 }
122 }
123
main(int argc,char * argv[])124 int main(int argc, char *argv[])
125 {
126 struct tagger tagger;
127 int result = 0;
128
129 argv0 = argv[0];
130
131 /* internationalization support */
132
133 # if defined(ENABLE_NLS)
134 setlocale(LC_ALL, "");
135 bindtextdomain(PACKAGE, LOCALEDIR);
136 textdomain(PACKAGE);
137 # endif
138
139 /* initialize and get options */
140
141 tagger_init(&tagger);
142
143 get_options(argc, argv, &tagger);
144
145 /* main processing */
146
147 if (tagger_run(&tagger, argc - optind, (char const **) &argv[optind]) == -1)
148 result = 4;
149
150 /* finish up */
151
152 tagger_finish(&tagger);
153
154 return result;
155 }
156