1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
/* This file is part of Idest. -*- c -*-
Copyright (C) 2009-2011 Sergey Poznyakoff
Idest is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
Idest is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Idest. If not, see <http://www.gnu.org/licenses/>. */
static int mode_set = 0;
#define SET_MODE(m) do { \
if (mode_set++ && mode != m) \
error(1, 0, "only one of -q, -s, -d may be used"); \
mode = m; \
} while(0)
static unsigned
get_version_list(const char *arg)
{
unsigned vers = 0;
while (1) {
switch (*arg) {
case '1':
vers |= IDEST_ID3V_1;
break;
case '2':
vers |= IDEST_ID3V_2;
break;
default:
error(1, 0, "invalid or unsupported version near %s",
arg);
}
if (*++arg == ',')
++arg;
else if (*arg == 0)
break;
else
error(1, 0, "malformed version list near %s",
arg);
}
return vers;
}
OPTIONS_BEGIN(gnu, "idest",
[<idest - ID3 Edit and Scripting Tool>],
[<FILE [FILE...]>])
GROUP([<Operation mode>])
OPTION(query,q,[FLIST],
[<query mode>])
BEGIN
SET_MODE(MODE_QUERY);
if (optarg)
parse_filter_items(optarg);
END
OPTION(all,a,,
[<query all frames>])
BEGIN
SET_MODE(MODE_QUERY);
all_frames = 1;
END
OPTION(set,s,FIELD=VALUE,
[<set FIELD to VALUE>])
BEGIN
char *p;
SET_MODE(MODE_MOD);
p = strchr(optarg, '=');
if (!p)
error(1, 0, "missing `=' sign in assignment");
*p++ = 0;
input_list_add_assignment(optarg, p);
END
OPTION(delete,d,[FLIST],
[<delete ID3 tags>])
BEGIN
SET_MODE(MODE_DELETE);
if (optarg)
parse_filter_items(optarg);
END
OPTION(info,i,,
[<display information about ID3 tags>])
BEGIN
SET_MODE(MODE_INFO);
END
OPTION(copy,c,FILE,
[<copy frames from FILE>])
BEGIN
source_file = optarg;
END
OPTION(list-frames,L,,
[<list all supported frames>])
BEGIN
SET_MODE(MODE_LIST);
END
GROUP([<Operation modifiers>])
OPTION(filter,F,FRAME-LIST,
[<operate only on matching frames>])
BEGIN
parse_filter_items(optarg);
END
OPTION(id-version,V,VERSION,
[<write new and changed tags in the given ID3 version>])
BEGIN
version_option = get_version_list(optarg);
END
OPTION(default-id-version,U,VERSION,
[<create new tags in the given ID3 version>])
BEGIN
default_version_option = get_version_list(optarg);
END
OPTION(convert,C,VERSION,
[<convert tags to VERSION>])
BEGIN
convert_version = get_version_list(optarg);
END
OPTION(latin1,,,
[<force latin1 output>])
BEGIN
latin1_option = 1;
END
OPTION(verbose,v,,
[<verbosely list files processed>])
BEGIN
verbose_option = 1;
END
OPTION(describe,D,,
[<print verbose frame descriptions instead of short names>])
BEGIN
describe_option = 1;
END
GROUP([<Backup options>])
OPTION(backup,,[CONTROL],
[<backup before modifying, choose version CONTROL>])
BEGIN
if (optarg)
backup_type = xget_version ("--backup", optarg);
else
backup_type = xget_version ("VERSION_CONTROL",
getenv("VERSION_CONTROL"));
END
OPTION(backup-suffix,,SUF,
[<set backup suffix, instead of the default ~>])
BEGIN
simple_backup_suffix = optarg;
END
OPTION(backup-directory,,DIR,
[<backup to given DIR>])
BEGIN
backup_dir = optarg;
END
IFDEF(GUILE_VERSION,[<
GROUP([<Scripting options>])
OPTION(script,S,FILE,
[<read Guile script from FILE; this stops further argument processing>])
BEGIN
set_guile_argv(argc - optind, argv + optind); /* Save rest of arguments */
*--guile_argv = optarg;
optind = argc; /* Stop argument processing */
END
OPTION(format,H,NAME,
[<apply external format NAME; this stops further argument processing>])
BEGIN
format_name = optarg;
stop = 1; /* Stop argument processing */
END
OPTION(batch,B,NAME,
[<apply batch modification module NAME; this stops further argument processing>])
BEGIN
batch_name = optarg;
stop = 1; /* Stop argument processing */
END
OPTION(dry-run,n,,
[<run the script, print modified frames but do not write them to the file>])
BEGIN
dry_run_option = 1;
END
OPTION(trace,,[LEVEL],
[<start with debugging evaluator and backtraces>])
BEGIN
if (optarg)
guile_debug = atoi(optarg);
else
guile_debug = 1;
END
OPTION(load-path,P,PATH,
[<set load path>])
BEGIN
guile_add_load_path(optarg);
END
>])
OPTIONS_END
void
get_options(int argc, char *argv[])
{
GETOPT(argc, argv)
if (optind < argc && mode == MODE_MOD) {
char *p;
/* See if we've been given any assignment arguments */
while (p = strchr(argv[optind], '=')) {
*p++ = 0;
input_list_add_assignment(argv[optind++], p);
}
}
}
|