2 * libid3tag - ID3 tag manipulation library
3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * $Id: parse.c,v 1.9 2004/01/23 09:41:32 rob Exp $
41 signed long id3_parse_int(id3_byte_t
const **ptr
, unsigned int bytes
)
43 signed long value
= 0;
45 assert(bytes
>= 1 && bytes
<= 4);
51 case 4: value
= (value
<< 8) | *(*ptr
)++;
52 case 3: value
= (value
<< 8) | *(*ptr
)++;
53 case 2: value
= (value
<< 8) | *(*ptr
)++;
54 case 1: value
= (value
<< 8) | *(*ptr
)++;
60 unsigned long id3_parse_uint(id3_byte_t
const **ptr
, unsigned int bytes
)
62 unsigned long value
= 0;
64 assert(bytes
>= 1 && bytes
<= 4);
67 case 4: value
= (value
<< 8) | *(*ptr
)++;
68 case 3: value
= (value
<< 8) | *(*ptr
)++;
69 case 2: value
= (value
<< 8) | *(*ptr
)++;
70 case 1: value
= (value
<< 8) | *(*ptr
)++;
76 unsigned long id3_parse_syncsafe(id3_byte_t
const **ptr
, unsigned int bytes
)
78 unsigned long value
= 0;
80 assert(bytes
== 4 || bytes
== 5);
83 case 5: value
= (value
<< 4) | (*(*ptr
)++ & 0x0f);
84 case 4: value
= (value
<< 7) | (*(*ptr
)++ & 0x7f);
85 value
= (value
<< 7) | (*(*ptr
)++ & 0x7f);
86 value
= (value
<< 7) | (*(*ptr
)++ & 0x7f);
87 value
= (value
<< 7) | (*(*ptr
)++ & 0x7f);
93 void id3_parse_immediate(id3_byte_t
const **ptr
, unsigned int bytes
,
97 assert(bytes
== 8 || bytes
== 4 || bytes
== 3);
100 case 8: *value
++ = *(*ptr
)++;
101 *value
++ = *(*ptr
)++;
102 *value
++ = *(*ptr
)++;
103 *value
++ = *(*ptr
)++;
104 case 4: *value
++ = *(*ptr
)++;
105 case 3: *value
++ = *(*ptr
)++;
106 *value
++ = *(*ptr
)++;
107 *value
++ = *(*ptr
)++;
113 id3_latin1_t
*id3_parse_latin1(id3_byte_t
const **ptr
, id3_length_t length
,
116 id3_byte_t
const *end
;
118 id3_latin1_t
*latin1
;
120 end
= memchr(*ptr
, 0, length
);
128 latin1
= malloc(length
+ 1);
130 memcpy(latin1
, *ptr
, length
);
136 for (check
= latin1
; *check
; ++check
) {
143 *ptr
+= length
+ terminated
;
148 id3_ucs4_t
*id3_parse_string(id3_byte_t
const **ptr
, id3_length_t length
,
149 enum id3_field_textencoding encoding
, int full
)
151 id3_ucs4_t
*ucs4
= 0;
152 enum id3_utf16_byteorder byteorder
= ID3_UTF16_BYTEORDER_ANY
;
155 case ID3_FIELD_TEXTENCODING_ISO_8859_1
:
156 ucs4
= id3_latin1_deserialize(ptr
, length
);
159 case ID3_FIELD_TEXTENCODING_UTF_16BE
:
160 byteorder
= ID3_UTF16_BYTEORDER_BE
;
161 case ID3_FIELD_TEXTENCODING_UTF_16
:
162 ucs4
= id3_utf16_deserialize(ptr
, length
, byteorder
);
165 case ID3_FIELD_TEXTENCODING_UTF_8
:
166 ucs4
= id3_utf8_deserialize(ptr
, length
);
173 for (check
= ucs4
; *check
; ++check
) {
182 id3_byte_t
*id3_parse_binary(id3_byte_t
const **ptr
, id3_length_t length
)
189 data
= malloc(length
);
191 memcpy(data
, *ptr
, length
);