summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2011-07-17 14:16:26 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-07-17 14:16:26 (GMT)
commit408c4354aec53a618853d0e716c7a1c014b6c87d (patch) (side-by-side diff)
treede017bcdbd20dccc6d9cf308a577cb0ffbe6f71f
parentd9a94ef4e033021a47dae2b5b476347d770adf66 (diff)
downloadidest-408c4354aec53a618853d0e716c7a1c014b6c87d.tar.gz
idest-408c4354aec53a618853d0e716c7a1c014b6c87d.tar.bz2
New option: --list-frames
* NEWS: Update. * src/cmdline.opt: New option --list-frames (-L) * src/frametab.gperf: Use %global-table option. (frametab_enumerate): New function. * src/idest.h (frametab_enumerate): New proto. * src/main.c: Implement --list-frames.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--NEWS5
-rw-r--r--src/cmdline.opt10
-rw-r--r--src/frametab.gperf37
-rw-r--r--src/idest.h3
-rw-r--r--src/main.c36
5 files changed, 91 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 71b10df..ed6ee32 100644
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,11 @@ The --filter=FRAME-LIST option can be used in conjunction with
to the fields from FRAME-LIST. The `--delete --filter=FRAME-LIST'
is equivalent to `--delete=FRAME-LIST'.
+* New option --list-frames (-L)
+
+Lists the supported frames IDs, along with their qualifiers and
+descriptions.
+
* The --convert option
The argument to --convert option is either a single major version
diff --git a/src/cmdline.opt b/src/cmdline.opt
index 53cabf8..1400d2c 100644
--- a/src/cmdline.opt
+++ b/src/cmdline.opt
@@ -53,6 +53,8 @@ OPTIONS_BEGIN(gnu, "idest",
[<idest - ID3 Edit and Scripting Tool>],
[<FILE [FILE...]>])
+GROUP([<Operation mode>])
+
OPTION(query,q,[FLIST],
[<query mode>])
BEGIN
@@ -101,6 +103,14 @@ 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,
[<with --query, --copy and --delete: operate only on matching frames>])
BEGIN
diff --git a/src/frametab.gperf b/src/frametab.gperf
index 83f3d9d..55ee1ed 100644
--- a/src/frametab.gperf
+++ b/src/frametab.gperf
@@ -460,6 +460,7 @@ wxxx_decode(struct ed_item *item, struct id3_frame const *frame)
%}
%define lookup-function-name idest_frame_lookup_len
+%global-table
struct idest_frametab;
%%
COMM, QUAL(COMM), comm_cmp, comm_encode, comm_decode
@@ -520,11 +521,47 @@ WPAY, 0, NULL, NULL, url_encode, url_decode
WPUB, 0, NULL, NULL, url_encode, url_decode
WXXX, QUAL(WXXX), wxxx_cmp, wxxx_encode, wxxx_decode
%%
+
+static int wordlist_count = sizeof(wordlist)/sizeof(wordlist[0]);
+
const struct idest_frametab *
idest_frame_lookup(const char *str)
{
return idest_frame_lookup_len(str, strlen(str));
}
+
+static int
+frametab_cmp(const void *a, const void *b)
+{
+ struct idest_frametab const *fta = a;
+ struct idest_frametab const *ftb = b;
+ return strcmp(fta->id, ftb->id);
+}
+
+int
+frametab_enumerate(int (*fun)(const struct idest_frametab *, void *),
+ void *data, int sorted)
+{
+ struct idest_frametab *ft;
+ int i;
+
+ if (sorted) {
+ ft = xmalloc(sizeof(wordlist));
+ memcpy(ft, wordlist, sizeof(wordlist));
+ qsort(ft, wordlist_count, sizeof(ft[0]), frametab_cmp);
+ } else
+ ft = wordlist;
+ for (i = 0; i < wordlist_count; i++) {
+ int rc = fun(ft + i, data);
+ if (rc)
+ return rc;
+ }
+ if (sorted)
+ free(ft);
+ return 0;
+}
+
+
/*
Local variables:
mode: c
diff --git a/src/idest.h b/src/idest.h
index 597e34b..2ae2b96 100644
--- a/src/idest.h
+++ b/src/idest.h
@@ -64,6 +64,7 @@ struct ed_item {
#define MODE_MOD 1
#define MODE_DELETE 2
#define MODE_INFO 3
+#define MODE_LIST 4
extern int mode;
extern int latin1_option;
@@ -141,6 +142,8 @@ struct id3_frame *find_matching_frame(struct id3_tag *tag,
const struct ed_item *item,
idest_frame_cmp_t cmp);
int frame_field_from_string(struct id3_frame *frame, int n, const char *value);
+int frametab_enumerate(int (*fun)(const struct idest_frametab *, void *),
+ void *data, int sorted);
/* main.c */
diff --git a/src/main.c b/src/main.c
index c213ec2..2d63b63 100644
--- a/src/main.c
+++ b/src/main.c
@@ -98,7 +98,36 @@ qv_free(size_t qc, char **qv)
free(qv);
}
+#define DESCR_COLUMN 24
+static int
+describe_frame(const struct idest_frametab *ft, void *data)
+{
+ struct id3_frametype const *frametype;
+ int n;
+
+ frametype = id3_frametype_lookup(ft->id, 4);
+ assert(frametype != NULL);
+ printf("%s", ft->id);
+ n = 0;
+ if (ft->qc) {
+ int i;
+ for (i = 0; i < ft->qc; i++)
+ n += printf(":%s", ft->qv[i]);
+ }
+ while (++n < DESCR_COLUMN)
+ putchar(' ');
+
+ printf("%s\n", frametype->description);
+ return 0;
+}
+static void
+list_supported_frames(void)
+{
+ frametab_enumerate(describe_frame, NULL, 1);
+}
+
+
void
verify_mp3(FILE *fp, const char *name)
{
@@ -174,6 +203,13 @@ main(int argc, char **argv)
guile_init(&argc, &argv);
+ if (mode == MODE_LIST) {
+ if (argc)
+ error(1, 0, "extra arguments");
+ list_supported_frames();
+ exit(0);
+ }
+
if (argc == 0)
error(1, 0, "no files");

Return to:

Send suggestions and report system problems to the System administrator.