sdk-world v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Loading...
Searching...
No Matches
compat.c
1/* C code produced by gperf version 3.0.1 */
2/* Command-line: gperf -tCcTonD -K id -N id3_compat_lookup -s -3 -k '*' compat.gperf */
3
4#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
5 && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
6 && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
7 && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
8 && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
9 && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
10 && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
11 && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
12 && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
13 && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
14 && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
15 && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
16 && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
17 && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
18 && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
19 && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
20 && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
21 && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
22 && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
23 && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
24 && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
25 && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
26 && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
27/* The character set is not based on ISO-646. */
28error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>."
29#endif
30
31#line 1 "compat.gperf"
32
33/*
34 * libid3tag - ID3 tag manipulation library
35 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
36 *
37 * This program is free software; you can redistribute it and/or modify
38 * it under the terms of the GNU General Public License as published by
39 * the Free Software Foundation; either version 2 of the License, or
40 * (at your option) any later version.
41 *
42 * This program is distributed in the hope that it will be useful,
43 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 * GNU General Public License for more details.
46 *
47 * You should have received a copy of the GNU General Public License
48 * along with this program; if not, write to the Free Software
49 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
50 *
51 * Id: compat.gperf,v 1.11 2004/01/23 09:41:32 rob Exp
52 */
53
54# ifdef HAVE_CONFIG_H
55# include "config.h"
56# endif
57
58# include "global.h"
59
60# include <stdlib.h>
61# include <string.h>
62
63# ifdef HAVE_ASSERT_H
64# include <assert.h>
65# endif
66
67# include "id3tag.h"
68# include "compat.h"
69# include "frame.h"
70# include "field.h"
71# include "parse.h"
72# include "ucs4.h"
73
74# define EQ(id) #id, 0
75# define OBSOLETE 0, 0
76# define TX(id) #id, translate_##id
77
78static id3_compat_func_t translate_TCON;
79
80#define TOTAL_KEYWORDS 73
81#define MIN_WORD_LENGTH 3
82#define MAX_WORD_LENGTH 4
83#define MIN_HASH_VALUE 6
84#define MAX_HASH_VALUE 127
85/* maximum key range = 122, duplicates = 0 */
86
87#ifdef __GNUC__
88__inline
89#else
90#ifdef __cplusplus
91inline
92#endif
93#endif
94static unsigned int
95hash (register const char *str, register unsigned int len)
96{
97 static const unsigned char asso_values[] =
98 {
99 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
100 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
101 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
102 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
103 128, 128, 128, 128, 128, 128, 128, 128, 128, 64,
104 58, 20, 15, 128, 128, 128, 128, 128, 128, 128,
105 128, 128, 128, 128, 128, 10, 18, 3, 6, 1,
106 47, 0, 128, 42, 62, 30, 31, 0, 19, 52,
107 10, 24, 8, 30, 5, 3, 30, 8, 25, 47,
108 3, 128, 128, 128, 128, 128, 128, 128, 128, 128,
109 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
110 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
111 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
112 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
113 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
114 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
115 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
116 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
117 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
118 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
119 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
120 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
121 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
122 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
123 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
124 128, 128, 128, 128, 128, 128, 128
125 };
126 register int hval = 0;
127
128 switch (len)
129 {
130 default:
131 hval += asso_values[(unsigned char)str[3]];
132 /*FALLTHROUGH*/
133 case 3:
134 hval += asso_values[(unsigned char)str[2]];
135 /*FALLTHROUGH*/
136 case 2:
137 hval += asso_values[(unsigned char)str[1]+1];
138 /*FALLTHROUGH*/
139 case 1:
140 hval += asso_values[(unsigned char)str[0]];
141 break;
142 }
143 return hval;
144}
145
146#ifdef __GNUC__
147__inline
148#endif
149const struct id3_compat *
150id3_compat_lookup (register const char *str, register unsigned int len)
151{
152 static const struct id3_compat wordlist[] =
153 {
154#line 97 "compat.gperf"
155 {"TLE", EQ(TLEN) /* Length */},
156#line 68 "compat.gperf"
157 {"ETC", EQ(ETCO) /* Event timing codes */},
158#line 126 "compat.gperf"
159 {"ULT", EQ(USLT) /* Unsynchronised lyric/text transcription */},
160#line 123 "compat.gperf"
161 {"TYE", OBSOLETE /* Year [obsolete] */},
162#line 92 "compat.gperf"
163 {"TFT", EQ(TFLT) /* File type */},
164#line 84 "compat.gperf"
165 {"TCM", EQ(TCOM) /* Composer */},
166#line 66 "compat.gperf"
167 {"EQU", OBSOLETE /* Equalization [obsolete] */},
168#line 63 "compat.gperf"
169 {"COM", EQ(COMM) /* Comments */},
170#line 130 "compat.gperf"
171 {"WCM", EQ(WCOM) /* Commercial information */},
172#line 96 "compat.gperf"
173 {"TLA", EQ(TLAN) /* Language(s) */},
174#line 88 "compat.gperf"
175 {"TDA", OBSOLETE /* Date [obsolete] */},
176#line 124 "compat.gperf"
177 {"TYER", OBSOLETE /* Year [obsolete] */},
178#line 83 "compat.gperf"
179 {"TBP", EQ(TBPM) /* BPM (beats per minute) */},
180#line 87 "compat.gperf"
181 {"TCR", EQ(TCOP) /* Copyright message */},
182#line 104 "compat.gperf"
183 {"TOT", EQ(TOAL) /* Original album/movie/show title */},
184#line 89 "compat.gperf"
185 {"TDAT", OBSOLETE /* Date [obsolete] */},
186#line 67 "compat.gperf"
187 {"EQUA", OBSOLETE /* Equalization [obsolete] */},
188#line 102 "compat.gperf"
189 {"TOR", EQ(TDOR) /* Original release year [obsolete] */},
190#line 131 "compat.gperf"
191 {"WCP", EQ(WCOP) /* Copyright/legal information */},
192#line 99 "compat.gperf"
193 {"TOA", EQ(TOPE) /* Original artist(s)/performer(s) */},
194#line 78 "compat.gperf"
195 {"RVA", OBSOLETE /* Relative volume adjustment [obsolete] */},
196#line 120 "compat.gperf"
197 {"TT3", EQ(TIT3) /* Subtitle/description refinement */},
198#line 98 "compat.gperf"
199 {"TMT", EQ(TMED) /* Media type */},
200#line 76 "compat.gperf"
201 {"POP", EQ(POPM) /* Popularimeter */},
202#line 74 "compat.gperf"
203 {"MLL", EQ(MLLT) /* MPEG location lookup table */},
204#line 79 "compat.gperf"
205 {"RVAD", OBSOLETE /* Relative volume adjustment [obsolete] */},
206#line 65 "compat.gperf"
207 {"CRM", OBSOLETE /* Encrypted meta frame [obsolete] */},
208#line 128 "compat.gperf"
209 {"WAR", EQ(WOAR) /* Official artist/performer webpage */},
210#line 80 "compat.gperf"
211 {"SLT", EQ(SYLT) /* Synchronised lyric/text */},
212#line 81 "compat.gperf"
213 {"STC", EQ(SYTC) /* Synchronised tempo codes */},
214#line 95 "compat.gperf"
215 {"TKE", EQ(TKEY) /* Initial key */},
216#line 111 "compat.gperf"
217 {"TRC", EQ(TSRC) /* ISRC (international standard recording code) */},
218#line 109 "compat.gperf"
219 {"TPA", EQ(TPOS) /* Part of a set */},
220#line 117 "compat.gperf"
221 {"TSS", EQ(TSSE) /* Software/hardware and settings used for encoding */},
222#line 112 "compat.gperf"
223 {"TRD", OBSOLETE /* Recording dates [obsolete] */},
224#line 64 "compat.gperf"
225 {"CRA", EQ(AENC) /* Audio encryption */},
226#line 108 "compat.gperf"
227 {"TP4", EQ(TPE4) /* Interpreted, remixed, or otherwise modified by */},
228#line 125 "compat.gperf"
229 {"UFI", EQ(UFID) /* Unique file identifier */},
230#line 101 "compat.gperf"
231 {"TOL", EQ(TOLY) /* Original lyricist(s)/text writer(s) */},
232#line 110 "compat.gperf"
233 {"TPB", EQ(TPUB) /* Publisher */},
234#line 73 "compat.gperf"
235 {"MCI", EQ(MCDI) /* Music CD identifier */},
236#line 107 "compat.gperf"
237 {"TP3", EQ(TPE3) /* Conductor/performer refinement */},
238#line 132 "compat.gperf"
239 {"WPB", EQ(WPUB) /* Publishers official webpage */},
240#line 113 "compat.gperf"
241 {"TRDA", OBSOLETE /* Recording dates [obsolete] */},
242#line 115 "compat.gperf"
243 {"TSI", OBSOLETE /* Size [obsolete] */},
244#line 90 "compat.gperf"
245 {"TDY", EQ(TDLY) /* Playlist delay */},
246#line 82 "compat.gperf"
247 {"TAL", EQ(TALB) /* Album/movie/show title */},
248#line 116 "compat.gperf"
249 {"TSIZ", OBSOLETE /* Size [obsolete] */},
250#line 129 "compat.gperf"
251 {"WAS", EQ(WOAS) /* Official audio source webpage */},
252#line 121 "compat.gperf"
253 {"TXT", EQ(TEXT) /* Lyricist/text writer */},
254#line 62 "compat.gperf"
255 {"CNT", EQ(PCNT) /* Play counter */},
256#line 100 "compat.gperf"
257 {"TOF", EQ(TOFN) /* Original filename */},
258#line 85 "compat.gperf"
259 {"TCO", TX(TCON) /* Content type */},
260#line 114 "compat.gperf"
261 {"TRK", EQ(TRCK) /* Track number/position in set */},
262#line 119 "compat.gperf"
263 {"TT2", EQ(TIT2) /* Title/songname/content description */},
264#line 93 "compat.gperf"
265 {"TIM", OBSOLETE /* Time [obsolete] */},
266#line 94 "compat.gperf"
267 {"TIME", OBSOLETE /* Time [obsolete] */},
268#line 103 "compat.gperf"
269 {"TORY", EQ(TDOR) /* Original release year [obsolete] */},
270#line 91 "compat.gperf"
271 {"TEN", EQ(TENC) /* Encoded by */},
272#line 118 "compat.gperf"
273 {"TT1", EQ(TIT1) /* Content group description */},
274#line 127 "compat.gperf"
275 {"WAF", EQ(WOAF) /* Official audio file webpage */},
276#line 75 "compat.gperf"
277 {"PIC", EQ(APIC) /* Attached picture */},
278#line 122 "compat.gperf"
279 {"TXX", EQ(TXXX) /* User defined text information frame */},
280#line 133 "compat.gperf"
281 {"WXX", EQ(WXXX) /* User defined URL link frame */},
282#line 86 "compat.gperf"
283 {"TCON", TX(TCON) /* Content type */},
284#line 77 "compat.gperf"
285 {"REV", EQ(RVRB) /* Reverb */},
286#line 106 "compat.gperf"
287 {"TP2", EQ(TPE2) /* Band/orchestra/accompaniment */},
288#line 105 "compat.gperf"
289 {"TP1", EQ(TPE1) /* Lead performer(s)/soloist(s) */},
290#line 61 "compat.gperf"
291 {"BUF", EQ(RBUF) /* Recommended buffer size */},
292#line 70 "compat.gperf"
293 {"IPL", EQ(TIPL) /* Involved people list */},
294#line 69 "compat.gperf"
295 {"GEO", EQ(GEOB) /* General encapsulated object */},
296#line 72 "compat.gperf"
297 {"LNK", EQ(LINK) /* Linked information */},
298#line 71 "compat.gperf"
299 {"IPLS", EQ(TIPL) /* Involved people list */}
300 };
301
302 static const short lookup[] =
303 {
304 -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7,
305 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, -1,
306 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
307 -1, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
308 48, 49, -1, -1, 50, -1, 51, 52, -1, 53, 54, 55, 56, -1,
309 57, 58, 59, 60, -1, 61, -1, 62, -1, -1, 63, -1, 64, -1,
310 -1, 65, -1, 66, -1, -1, -1, -1, -1, 67, -1, 68, -1, 69,
311 -1, 70, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
312 -1, 71, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
313 -1, 72
314 };
315
316 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
317 {
318 register int key = hash (str, len);
319
320 if (key <= MAX_HASH_VALUE && key >= 0)
321 {
322 register int index = lookup[key];
323
324 if (index >= 0)
325 {
326 register const char *s = wordlist[index].id;
327
328 if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0')
329 return &wordlist[index];
330 }
331 }
332 }
333 return 0;
334}
335#line 134 "compat.gperf"
336
337
338static
339int translate_TCON(struct id3_frame *frame, char const *oldid,
340 id3_byte_t const *data, id3_length_t length)
341{
342 id3_byte_t const *end;
343 enum id3_field_textencoding encoding;
344 id3_ucs4_t *string = 0, *ptr, *endptr;
345 int result = 0;
346
347 /* translate old TCON syntax into multiple strings */
348
349 assert(frame->nfields == 2);
350
351 encoding = ID3_FIELD_TEXTENCODING_ISO_8859_1;
352
353 end = data + length;
354
355 if (id3_field_parse(&frame->fields[0], &data, end - data, &encoding) == -1)
356 goto fail;
357
358 string = id3_parse_string(&data, end - data, encoding, 0);
359 if (string == 0)
360 goto fail;
361
362 ptr = string;
363 while (*ptr == '(') {
364 if (*++ptr == '(')
365 break;
366
367 endptr = ptr;
368 while (*endptr && *endptr != ')')
369 ++endptr;
370
371 if (*endptr)
372 *endptr++ = 0;
373
374 if (id3_field_addstring(&frame->fields[1], ptr) == -1)
375 goto fail;
376
377 ptr = endptr;
378 }
379
380 if (*ptr && id3_field_addstring(&frame->fields[1], ptr) == -1)
381 goto fail;
382
383 if (0) {
384 fail:
385 result = -1;
386 }
387
388 if (string)
389 free(string);
390
391 return result;
392}
393
394/*
395 * NAME: compat->fixup()
396 * DESCRIPTION: finish compatibility translations
397 */
398int id3_compat_fixup(struct id3_tag *tag)
399{
400 struct id3_frame *frame;
401 unsigned int index;
402 id3_ucs4_t timestamp[17] = { 0 };
403 int result = 0;
404
405 /* create a TDRC frame from obsolete TYER/TDAT/TIME frames */
406
407 /*
408 * TYE/TYER: YYYY
409 * TDA/TDAT: DDMM
410 * TIM/TIME: HHMM
411 *
412 * TDRC: yyyy-MM-ddTHH:mm
413 */
414
415 index = 0;
416 while ((frame = id3_tag_findframe(tag, ID3_FRAME_OBSOLETE, index++))) {
417 char const *id;
418 id3_byte_t const *data, *end;
419 id3_length_t length;
420 enum id3_field_textencoding encoding;
421 id3_ucs4_t *string;
422
423 id = id3_field_getframeid(&frame->fields[0]);
424 assert(id);
425
426 if (strcmp(id, "TYER") != 0 && strcmp(id, "YTYE") != 0 &&
427 strcmp(id, "TDAT") != 0 && strcmp(id, "YTDA") != 0 &&
428 strcmp(id, "TIME") != 0 && strcmp(id, "YTIM") != 0)
429 continue;
430
431 data = id3_field_getbinarydata(&frame->fields[1], &length);
432 assert(data);
433
434 if (length < 1)
435 continue;
436
437 end = data + length;
438
439 encoding = id3_parse_uint(&data, 1);
440 string = id3_parse_string(&data, end - data, encoding, 0);
441
442 if (id3_ucs4_length(string) < 4) {
443 free(string);
444 continue;
445 }
446
447 if (strcmp(id, "TYER") == 0 ||
448 strcmp(id, "YTYE") == 0) {
449 timestamp[0] = string[0];
450 timestamp[1] = string[1];
451 timestamp[2] = string[2];
452 timestamp[3] = string[3];
453 }
454 else if (strcmp(id, "TDAT") == 0 ||
455 strcmp(id, "YTDA") == 0) {
456 timestamp[4] = '-';
457 timestamp[5] = string[2];
458 timestamp[6] = string[3];
459 timestamp[7] = '-';
460 timestamp[8] = string[0];
461 timestamp[9] = string[1];
462 }
463 else { /* TIME or YTIM */
464 timestamp[10] = 'T';
465 timestamp[11] = string[0];
466 timestamp[12] = string[1];
467 timestamp[13] = ':';
468 timestamp[14] = string[2];
469 timestamp[15] = string[3];
470 }
471
472 free(string);
473 }
474
475 if (timestamp[0]) {
476 id3_ucs4_t *strings;
477
478 frame = id3_frame_new("TDRC");
479 if (frame == 0)
480 goto fail;
481
482 strings = timestamp;
483
484 if (id3_field_settextencoding(&frame->fields[0],
485 ID3_FIELD_TEXTENCODING_ISO_8859_1) == -1 ||
486 id3_field_setstrings(&frame->fields[1], 1, &strings) == -1 ||
487 id3_tag_attachframe(tag, frame) == -1) {
488 id3_frame_delete(frame);
489 goto fail;
490 }
491 }
492
493 if (0) {
494 fail:
495 result = -1;
496 }
497
498 return result;
499}