/* This file is part of Idest. -*- c -*-
Copyright (C) 2009-2011, 2016-2017 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 . */
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",
[],
[])
GROUP([])
OPTION(query,q,[FLIST],
[])
BEGIN
SET_MODE(MODE_QUERY);
if (optarg)
parse_filter_items(optarg);
END
OPTION(all,a,,
[])
BEGIN
SET_MODE(MODE_QUERY);
all_frames = 1;
END
OPTION(set,s,FIELD=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],
[])
BEGIN
SET_MODE(MODE_DELETE);
if (optarg)
parse_filter_items(optarg);
END
OPTION(info,i,,
[])
BEGIN
SET_MODE(MODE_INFO);
END
OPTION(copy,c,FILE,
[])
BEGIN
source_file = optarg;
END
OPTION(list-frames,L,,
[])
BEGIN
SET_MODE(MODE_LIST);
END
OPTION(fixup,f,,
[])
BEGIN
fixup_option = 1;
SET_MODE(MODE_MOD);
END
GROUP([])
OPTION(filter,F,FRAME-LIST,
[])
BEGIN
parse_filter_items(optarg);
END
OPTION(id-version,V,VERSION,
[])
BEGIN
version_option = get_version_list(optarg);
END
OPTION(default-id-version,U,VERSION,
[])
BEGIN
default_version_option = get_version_list(optarg);
END
OPTION(convert,C,VERSION,
[])
BEGIN
convert_version = get_version_list(optarg);
END
OPTION(charset,,CODE,
[