aboutsummaryrefslogtreecommitdiff
path: root/src/idest.h
blob: 83b1d9d8fbb25a546e6d583ee3f6aa84a5493e46 (plain)
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
/* This file is part of Idest.
   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/>. */

#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <getopt.h>
#include <error.h>
#include <progname.h>
#include <xalloc.h>
#include <gl_linked_list.h>
#include <gl_xlist.h>
#include <backupfile.h>
#include <id3tag.h>
#include <frametype.h>
#include <assert.h>

#define gettext(s) s
#define _(s) s
#define N_(s) s

#define DEFAULT_ED_LIST "title,album,track,comment,artist,year,genre"

#define IDEST_ID3V_1 0x01
#define IDEST_ID3V_2 0x02

enum item_id {
	item_title,
	item_artist,
	item_album,
	item_year,
	item_comment,
	item_track,
	item_genre
};

#define ED_ITEM_CONCAT 0x01

struct ed_item {
	char *name;                /* Printable name */
	char id[5];                /* Item ID */
	int qc;                    /* Number of name qualifiers */
	char **qv;                 /* Name qualifiers */
	char *value;               /* Value */
	struct ed_item const *ref; /* Reference item */
};

#define MODE_QUERY  0
#define MODE_MOD    1
#define MODE_DELETE 2
#define MODE_INFO   3
#define MODE_LIST   4

extern int mode;
extern int latin1_option;
extern int describe_option;
extern int verbose_option;
extern int all_frames;
extern char *source_file;
extern struct id3_tag *source_tag;
extern enum backup_type backup_type;
extern char *backup_dir;
extern gl_list_t ed_list;
extern unsigned convert_version;
extern unsigned version_option;
extern unsigned default_version_option;
extern int guile_debug;
extern char *guile_script;
extern char *guile_function;
extern char **guile_argv;

/* idop.c */
int set_frame_value(struct id3_frame *frame, const struct ed_item *item);
void set_tags(const char *name);
void del_tags(const char *name);
char *idest_ucs4_cvt(id3_ucs4_t const *ucs4);
void query_tags(const char *name);
void info_id3(const char *name);

char *field_to_string(union id3_field *field, int isgenre);
int field_binary_from_string(union id3_field *field, const char *str);
char *field_binary_to_string(union id3_field *field);

void input_list_add_assignment(const char *name, const char *value);

void list_supported_frames(void);
	

/* slist.c */
typedef int (*string_list_action_fn) (const char *, void *);

gl_list_t new_string_list(bool allow_duplicates);
int do_string_list(gl_list_t list, string_list_action_fn action, void *data);
void concat_string_list(gl_list_t list, gl_list_t addlist);
void print_string_list(FILE *fp, gl_list_t list);

/* frametab.gperf */
#define IDEST_OK           0
#define IDEST_ERR_NOFIELD  1
#define IDEST_ERR_BADCONV  2
#define IDEST_ERR_SET      3
#define IDEST_ERR_NOTSUPP  4
#define IDEST_ERR_BADTYPE  5
#define IDEST_ERR_BADFIELD 6

extern char *_idest_errstr[];
extern int _idest_nerrs;
const char *idest_strerror(int code);

typedef int (*idest_frame_cmp_t) (struct id3_frame const *frame,
				  const struct ed_item const *item);
typedef int (*idest_frame_encoder_t) (struct id3_frame *frame,
				      const struct ed_item const *item);
typedef int (*idest_frame_decoder_t) (struct ed_item *pitem,
				      struct id3_frame const *frame);


struct idest_frametab {
	const char id[5];
	int qc;
	char **qv;
	idest_frame_cmp_t    cmp;
	idest_frame_encoder_t encode;
	idest_frame_decoder_t decode;
};

const struct idest_frametab *idest_frame_lookup(const char *str);
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 */
const char *name_to_frame_id(const char *name);
int frame_to_item_id(const char *arg);
void qv_free(size_t qc, char **qv);
void parse_filter_items(const char *arg);
void output_list_append(struct ed_item const *item, struct ed_item const *ref);
void output_list_print(void);
void output_list_free(void);


/* editem.c */
void ed_item_zero(struct ed_item *item);
void ed_item_free(struct ed_item *item);
void ed_item_free_content(struct ed_item *item);
int ed_item_qv_cmp(struct ed_item const *a, struct ed_item const *b);
struct ed_item *ed_item_create0(char *name, const char *id);
struct ed_item *ed_item_create(const char *name, const char *id);
struct ed_item *ed_item_dup(struct ed_item const *orig);
struct ed_item *ed_item_from_frame_spec(const char *arg, size_t len);
gl_list_t ed_list_create(void);
void ed_item_print(struct ed_item const *itm);
struct ed_item const *ed_list_locate(gl_list_t list,
				     struct id3_frame *frame,
				     idest_frame_cmp_t cmp);

const char *str_split_col(const char *str, size_t *plen, size_t *pn);


/* backup.c */
int backup_file(const char *file);


/* guile.c */
void guile_init(int *pargc, char ***pargv);
int guile_transform(const char *file, struct id3_tag *tag);
int guile_list(const char *file, struct id3_tag *tag);
void guile_add_load_path(const char *arg);

Return to:

Send suggestions and report system problems to the System administrator.