diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-03-20 13:33:11 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-03-20 14:01:39 +0200 |
commit | 58bc8166fca5ba0f86c07636a7ad71ee1457ec38 (patch) | |
tree | b66816aae86afb8b0a5cf784cd89f9abdea776aa | |
parent | 929d8a0d47e8741093bbfd024715a1c7a08cae9e (diff) | |
download | idest-58bc8166fca5ba0f86c07636a7ad71ee1457ec38.tar.gz idest-58bc8166fca5ba0f86c07636a7ad71ee1457ec38.tar.bz2 |
Reindent libid3tag sources.
34 files changed, 4168 insertions, 3729 deletions
diff --git a/libid3tag/compat.h b/libid3tag/compat.h index 8af71ec..eb51f44 100644 --- a/libid3tag/compat.h +++ b/libid3tag/compat.h @@ -19,7 +19,7 @@ * $Id: compat.h,v 1.8 2004/01/23 09:41:32 rob Exp $ */ -# ifndef LIBID3TAG_COMPAT_H +#ifndef LIBID3TAG_COMPAT_H # define LIBID3TAG_COMPAT_H # include "id3tag.h" @@ -38,4 +38,4 @@ struct id3_compat const *id3_compat_lookup(register char const *, int id3_compat_fixup(struct id3_tag *); -# endif +#endif diff --git a/libid3tag/crc.c b/libid3tag/crc.c index 742a5d8..de56ecd 100644 --- a/libid3tag/crc.c +++ b/libid3tag/crc.c @@ -19,17 +19,16 @@ * $Id: crc.c,v 1.11 2004/02/17 02:04:10 rob Exp $ */ -# ifdef HAVE_CONFIG_H -# include "config.h" -# endif +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif -# include "global.h" +#include "global.h" -# include "id3tag.h" -# include "crc.h" +#include "id3tag.h" +#include "crc.h" -static -unsigned long const crc_table[256] = { +static unsigned long const crc_table[256] = { 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, 0xe0d5e91eL, 0x97d2d988L, @@ -107,31 +106,32 @@ unsigned long const crc_table[256] = { * NAME: crc->compute() * DESCRIPTION: calculate CRC-32 value (ISO 3309) */ -unsigned long id3_crc_compute(id3_byte_t const *data, id3_length_t length) +unsigned long +id3_crc_compute(id3_byte_t const *data, id3_length_t length) { - register unsigned long crc; + register unsigned long crc; - for (crc = 0xffffffffL; length >= 8; length -= 8) { - crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); - crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); - crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); - crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); - crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); - crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); - crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); - crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); - } - - switch (length) { - case 7: crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); - case 6: crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); - case 5: crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); - case 4: crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); - case 3: crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); - case 2: crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); - case 1: crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); - case 0: break; - } - - return crc ^ 0xffffffffL; + for (crc = 0xffffffffL; length >= 8; length -= 8) { + crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); + crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); + crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); + crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); + crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); + crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); + crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); + crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); + } + + switch (length) { + case 7: crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); + case 6: crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); + case 5: crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); + case 4: crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); + case 3: crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); + case 2: crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); + case 1: crc = crc_table[(crc ^ *data++) & 0xff] ^ (crc >> 8); + case 0: break; + } + + return crc ^ 0xffffffffL; } diff --git a/libid3tag/crc.h b/libid3tag/crc.h index 89a5a39..055be13 100644 --- a/libid3tag/crc.h +++ b/libid3tag/crc.h @@ -19,11 +19,11 @@ * $Id: crc.h,v 1.8 2004/02/17 02:04:10 rob Exp $ */ -# ifndef LIBID3TAG_CRC_H +#ifndef LIBID3TAG_CRC_H # define LIBID3TAG_CRC_H # include "id3tag.h" unsigned long id3_crc_compute(id3_byte_t const *, id3_length_t); -# endif +#endif diff --git a/libid3tag/debug.c b/libid3tag/debug.c index d91a2c5..a8933be 100644 --- a/libid3tag/debug.c +++ b/libid3tag/debug.c @@ -19,204 +19,212 @@ * $Id: debug.c,v 1.8 2004/01/23 09:41:32 rob Exp $ */ -# ifdef HAVE_CONFIG_H -# include "config.h" -# endif +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif -# include "global.h" +#include "global.h" -# undef malloc -# undef calloc -# undef realloc -# undef free +#undef malloc +#undef calloc +#undef realloc +#undef free -# include <stdio.h> -# include <stdlib.h> -# include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> -# include "debug.h" +#include "debug.h" -# if defined(DEBUG) +#if defined(DEBUG) # define DEBUG_MAGIC 0xdeadbeefL struct debug { - char const *file; - unsigned int line; - size_t size; - struct debug *next; - struct debug *prev; - long int magic; + char const *file; + unsigned int line; + size_t size; + struct debug *next; + struct debug *prev; + long int magic; }; static struct debug *allocated; static int registered; -static -void check(void) +static void +check(void) { - struct debug *debug; + struct debug *debug; - for (debug = allocated; debug; debug = debug->next) { - if (debug->magic != DEBUG_MAGIC) { - fprintf(stderr, "memory corruption\n"); - break; - } + for (debug = allocated; debug; debug = debug->next) { + if (debug->magic != DEBUG_MAGIC) { + fprintf(stderr, "memory corruption\n"); + break; + } - fprintf(stderr, "%s:%u: leaked %lu bytes\n", - debug->file, debug->line, debug->size); - } + fprintf(stderr, "%s:%u: leaked %lu bytes\n", + debug->file, debug->line, debug->size); + } } -void *id3_debug_malloc(size_t size, char const *file, unsigned int line) +void * +id3_debug_malloc(size_t size, char const *file, unsigned int line) { - struct debug *debug; + struct debug *debug; - if (!registered) { - atexit(check); - registered = 1; - } + if (!registered) { + atexit(check); + registered = 1; + } - if (size == 0) - fprintf(stderr, "%s:%u: malloc(0)\n", file, line); + if (size == 0) + fprintf(stderr, "%s:%u: malloc(0)\n", file, line); - debug = malloc(sizeof(*debug) + size); - if (debug == 0) { - fprintf(stderr, "%s:%u: malloc(%lu) failed\n", file, line, size); - return 0; - } + debug = malloc(sizeof(*debug) + size); + if (debug == 0) { + fprintf(stderr, "%s:%u: malloc(%lu) failed\n", file, line, + size); + return 0; + } - debug->magic = DEBUG_MAGIC; + debug->magic = DEBUG_MAGIC; - debug->file = file; - debug->line = line; - debug->size = size; + debug->file = file; + debug->line = line; + debug->size = size; - debug->next = allocated; - debug->prev = 0; + debug->next = allocated; + debug->prev = 0; - if (allocated) - allocated->prev = debug; + if (allocated) + allocated->prev = debug; - allocated = debug; + allocated = debug; - return ++debug; + return ++debug; } -void *id3_debug_calloc(size_t nmemb, size_t size, - char const *file, unsigned int line) +void * +id3_debug_calloc(size_t nmemb, size_t size, + char const *file, unsigned int line) { - void *ptr; + void *ptr; - ptr = id3_debug_malloc(nmemb * size, file, line); - if (ptr) - memset(ptr, 0, nmemb * size); + ptr = id3_debug_malloc(nmemb * size, file, line); + if (ptr) + memset(ptr, 0, nmemb * size); - return ptr; + return ptr; } -void *id3_debug_realloc(void *ptr, size_t size, - char const *file, unsigned int line) +void * +id3_debug_realloc(void *ptr, size_t size, + char const *file, unsigned int line) { - struct debug *debug, *new; + struct debug *debug, *new; - if (size == 0) { - id3_debug_free(ptr, file, line); - return 0; - } + if (size == 0) { + id3_debug_free(ptr, file, line); + return 0; + } - if (ptr == 0) - return id3_debug_malloc(size, file, line); + if (ptr == 0) + return id3_debug_malloc(size, file, line); - debug = ptr; - --debug; + debug = ptr; + --debug; - if (debug->magic != DEBUG_MAGIC) { - fprintf(stderr, "%s:%u: realloc(%p, %lu) memory not allocated\n", - file, line, ptr, size); - return 0; - } + if (debug->magic != DEBUG_MAGIC) { + fprintf(stderr, "%s:%u: realloc(%p, %lu) memory not allocated\n", + file, line, ptr, size); + return 0; + } - new = realloc(debug, sizeof(*debug) + size); - if (new == 0) { - fprintf(stderr, "%s:%u: realloc(%p, %lu) failed\n", file, line, ptr, size); - return 0; - } + new = realloc(debug, sizeof(*debug) + size); + if (new == 0) { + fprintf(stderr, "%s:%u: realloc(%p, %lu) failed\n", + file, line, ptr, size); + return 0; + } - if (allocated == debug) - allocated = new; + if (allocated == debug) + allocated = new; - debug = new; + debug = new; - debug->file = file; - debug->line = line; - debug->size = size; + debug->file = file; + debug->line = line; + debug->size = size; - if (debug->next) - debug->next->prev = debug; - if (debug->prev) - debug->prev->next = debug; + if (debug->next) + debug->next->prev = debug; + if (debug->prev) + debug->prev->next = debug; - return ++debug; + return ++debug; } -void id3_debug_free(void *ptr, char const *file, unsigned int line) +void +id3_debug_free(void *ptr, char const *file, unsigned int line) { - struct debug *debug; + struct debug *debug; - if (ptr == 0) { - fprintf(stderr, "%s:%u: free(0)\n", file, line); - return; - } + if (ptr == 0) { + fprintf(stderr, "%s:%u: free(0)\n", file, line); + return; + } - debug = ptr; - --debug; + debug = ptr; + --debug; - if (debug->magic != DEBUG_MAGIC) { - fprintf(stderr, "%s:%u: free(%p) memory not allocated\n", file, line, ptr); - return; - } + if (debug->magic != DEBUG_MAGIC) { + fprintf(stderr, "%s:%u: free(%p) memory not allocated\n", + file, line, ptr); + return; + } - debug->magic = 0; + debug->magic = 0; - if (debug->next) - debug->next->prev = debug->prev; - if (debug->prev) - debug->prev->next = debug->next; + if (debug->next) + debug->next->prev = debug->prev; + if (debug->prev) + debug->prev->next = debug->next; - if (allocated == debug) - allocated = debug->next; + if (allocated == debug) + allocated = debug->next; - free(debug); + free(debug); } -void *id3_debug_release(void *ptr, char const *file, unsigned int line) +void * +id3_debug_release(void *ptr, char const *file, unsigned int line) { - struct debug *debug; + struct debug *debug; - if (ptr == 0) - return 0; + if (ptr == 0) + return 0; - debug = ptr; - --debug; + debug = ptr; + --debug; - if (debug->magic != DEBUG_MAGIC) { - fprintf(stderr, "%s:%u: release(%p) memory not allocated\n", - file, line, ptr); - return ptr; - } + if (debug->magic != DEBUG_MAGIC) { + fprintf(stderr, "%s:%u: release(%p) memory not allocated\n", + file, line, ptr); + return ptr; + } - if (debug->next) - debug->next->prev = debug->prev; - if (debug->prev) - debug->prev->next = debug->next; + if (debug->next) + debug->next->prev = debug->prev; + if (debug->prev) + debug->prev->next = debug->next; - if (allocated == debug) - allocated = debug->next; + if (allocated == debug) + allocated = debug->next; - memmove(debug, debug + 1, debug->size); + memmove(debug, debug + 1, debug->size); - return debug; + return debug; } -# endif +#endif diff --git a/libid3tag/debug.h b/libid3tag/debug.h index a9b4ce0..c2979ae 100644 --- a/libid3tag/debug.h +++ b/libid3tag/debug.h @@ -19,7 +19,7 @@ * $Id: debug.h,v 1.8 2004/01/23 09:41:32 rob Exp $ */ -# ifndef LIBID3TAG_DEBUG_H +#ifndef LIBID3TAG_DEBUG_H # define LIBID3TAG_DEBUG_H # include <stdlib.h> @@ -31,4 +31,4 @@ void id3_debug_free(void *, char const *, unsigned int); void *id3_debug_release(void *, char const *, unsigned int); -# endif +#endif diff --git a/libid3tag/field.c b/libid3tag/field.c index f2ecc0f..b334b0c 100644 --- a/libid3tag/field.c +++ b/libid3tag/field.c @@ -19,872 +19,929 @@ * $Id: field.c,v 1.16 2004/01/23 09:41:32 rob Exp $ */ -# ifdef HAVE_CONFIG_H -# include "config.h" -# endif +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif -# include "global.h" +#include "global.h" -# include <stdlib.h> -# include <string.h> +#include <stdlib.h> +#include <string.h> -# ifdef HAVE_ASSERT_H -# include <assert.h> -# endif +#ifdef HAVE_ASSERT_H +# include <assert.h> +#endif -# include "id3tag.h" -# include "field.h" -# include "frame.h" -# include "render.h" -# include "ucs4.h" -# include "latin1.h" -# include "parse.h" +#include "id3tag.h" +#include "field.h" +#include "frame.h" +#include "render.h" +#include "ucs4.h" +#include "latin1.h" +#include "parse.h" /* - * NAME: field->init() - * DESCRIPTION: initialize a field to a default value for the given type + * NAME: field->init() + * DESCRIPTION: initialize a field to a default value for the given type */ -void id3_field_init(union id3_field *field, enum id3_field_type type) +void +id3_field_init(union id3_field *field, enum id3_field_type type) { - assert(field); - - switch (field->type = type) { - case ID3_FIELD_TYPE_TEXTENCODING: - case ID3_FIELD_TYPE_INT8: - case ID3_FIELD_TYPE_INT16: - case ID3_FIELD_TYPE_INT24: - case ID3_FIELD_TYPE_INT32: - field->number.value = 0; - break; - - case ID3_FIELD_TYPE_LATIN1: - case ID3_FIELD_TYPE_LATIN1FULL: - field->latin1.ptr = 0; - break; - - case ID3_FIELD_TYPE_LATIN1LIST: - field->latin1list.nstrings = 0; - field->latin1list.strings = 0; - - case ID3_FIELD_TYPE_STRING: - case ID3_FIELD_TYPE_STRINGFULL: - field->string.ptr = 0; - break; - - case ID3_FIELD_TYPE_STRINGLIST: - field->stringlist.nstrings = 0; - field->stringlist.strings = 0; - break; - - case ID3_FIELD_TYPE_LANGUAGE: - strcpy(field->immediate.value, "XXX"); - break; - - case ID3_FIELD_TYPE_FRAMEID: - strcpy(field->immediate.value, "XXXX"); - break; - - case ID3_FIELD_TYPE_DATE: - memset(field->immediate.value, 0, sizeof(field->immediate.value)); - break; - - case ID3_FIELD_TYPE_INT32PLUS: - case ID3_FIELD_TYPE_BINARYDATA: - field->binary.data = 0; - field->binary.length = 0; - break; - } + assert(field); + + switch (field->type = type) { + case ID3_FIELD_TYPE_TEXTENCODING: + case ID3_FIELD_TYPE_INT8: + case ID3_FIELD_TYPE_INT16: + case ID3_FIELD_TYPE_INT24: + case ID3_FIELD_TYPE_INT32: + field->number.value = 0; + break; + + case ID3_FIELD_TYPE_LATIN1: + case ID3_FIELD_TYPE_LATIN1FULL: + field->latin1.ptr = 0; + break; + + case ID3_FIELD_TYPE_LATIN1LIST: + field->latin1list.nstrings = 0; + field->latin1list.strings = 0; + + case ID3_FIELD_TYPE_STRING: + case ID3_FIELD_TYPE_STRINGFULL: + field->string.ptr = 0; + break; + + case ID3_FIELD_TYPE_STRINGLIST: + field->stringlist.nstrings = 0; + field->stringlist.strings = 0; + break; + + case ID3_FIELD_TYPE_LANGUAGE: + strcpy(field->immediate.value, "XXX"); + break; + + case ID3_FIELD_TYPE_FRAMEID: + strcpy(field->immediate.value, "XXXX"); + break; + + case ID3_FIELD_TYPE_DATE: + memset(field->immediate.value, 0, + sizeof(field->immediate.value)); + break; + + case ID3_FIELD_TYPE_INT32PLUS: + case ID3_FIELD_TYPE_BINARYDATA: + field->binary.data = 0; + field->binary.length = 0; + break; + } } /* - * NAME: field->finish() - * DESCRIPTION: reset a field, deallocating memory if necessary + * NAME: field->finish() + * DESCRIPTION: reset a field, deallocating memory if necessary */ -void id3_field_finish(union id3_field *field) +void +id3_field_finish(union id3_field *field) { - unsigned int i; - - assert(field); - - switch (field->type) { - case ID3_FIELD_TYPE_TEXTENCODING: - case ID3_FIELD_TYPE_INT8: - case ID3_FIELD_TYPE_INT16: - case ID3_FIELD_TYPE_INT24: - case ID3_FIELD_TYPE_INT32: - case ID3_FIELD_TYPE_LANGUAGE: - case ID3_FIELD_TYPE_FRAMEID: - case ID3_FIELD_TYPE_DATE: - break; - - case ID3_FIELD_TYPE_LATIN1: - case ID3_FIELD_TYPE_LATIN1FULL: - if (field->latin1.ptr) - free(field->latin1.ptr); - break; - - case ID3_FIELD_TYPE_LATIN1LIST: - for (i = 0; i < field->latin1list.nstrings; ++i) - free(field->latin1list.strings[i]); - - if (field->latin1list.strings) - free(field->latin1list.strings); - break; - - case ID3_FIELD_TYPE_STRING: - case ID3_FIELD_TYPE_STRINGFULL: - if (field->string.ptr) - free(field->string.ptr); - break; - - case ID3_FIELD_TYPE_STRINGLIST: - for (i = 0; i < field->stringlist.nstrings; ++i) - free(field->stringlist.strings[i]); - - if (field->stringlist.strings) - free(field->stringlist.strings); - break; - - case ID3_FIELD_TYPE_INT32PLUS: - case ID3_FIELD_TYPE_BINARYDATA: - if (field->binary.data) - free(field->binary.data); - break; - } - - id3_field_init(field, field->type); + unsigned int i; + + assert(field); + + switch (field->type) { + case ID3_FIELD_TYPE_TEXTENCODING: + case ID3_FIELD_TYPE_INT8: + case ID3_FIELD_TYPE_INT16: + case ID3_FIELD_TYPE_INT24: + case ID3_FIELD_TYPE_INT32: + case ID3_FIELD_TYPE_LANGUAGE: + case ID3_FIELD_TYPE_FRAMEID: + case ID3_FIELD_TYPE_DATE: + break; + + case ID3_FIELD_TYPE_LATIN1: + case ID3_FIELD_TYPE_LATIN1FULL: + if (field->latin1.ptr) + free(field->latin1.ptr); + break; + + case ID3_FIELD_TYPE_LATIN1LIST: + for (i = 0; i < field->latin1list.nstrings; ++i) + free(field->latin1list.strings[i]); + + if (field->latin1list.strings) + free(field->latin1list.strings); + break; + + case ID3_FIELD_TYPE_STRING: + case ID3_FIELD_TYPE_STRINGFULL: + if (field->string.ptr) + free(field->string.ptr); + break; + + case ID3_FIELD_TYPE_STRINGLIST: + for (i = 0; i < field->stringlist.nstrings; ++i) + free(field->stringlist.strings[i]); + + if (field->stringlist.strings) + free(field->stringlist.strings); + break; + + case ID3_FIELD_TYPE_INT32PLUS: + case ID3_FIELD_TYPE_BINARYDATA: + if (field->binary.data) + free(field->binary.data); + break; + } + + id3_field_init(field, field->type); } /* - * NAME: field->type() - * DESCRIPTION: return the value type of a field + * NAME: field->type() + * DESCRIPTION: return the value type of a field */ -enum id3_field_type id3_field_type(union id3_field const *field) +enum id3_field_type +id3_field_type(union id3_field const *field) { - assert(field); + assert(field); - return field->type; + return field->type; } /* - * NAME: field->parse() - * DESCRIPTION: parse a field value + * NAME: field->parse() + * DESCRIPTION: parse a field value */ -int id3_field_parse(union id3_field *field, id3_byte_t const **ptr, - id3_length_t length, enum id3_field_textencoding *encoding) +int +id3_field_parse(union id3_field *field, id3_byte_t const **ptr, + id3_length_t length, enum id3_field_textencoding *encoding) { - assert(field); - - id3_field_finish(field); - - switch (field->type) { - case ID3_FIELD_TYPE_INT32: - if (length < 4) - goto fail; - - field->number.value = id3_parse_uint(ptr, 4); - break; - - case ID3_FIELD_TYPE_INT24: - if (length < 3) - goto fail; - - field->number.value = id3_parse_uint(ptr, 3); - break; - - case ID3_FIELD_TYPE_INT16: - if (length < 2) - goto fail; - - field->number.value = id3_parse_uint(ptr, 2); - break; - - case ID3_FIELD_TYPE_INT8: - case ID3_FIELD_TYPE_TEXTENCODING: - if (length < 1) - goto fail; - - field->number.value = id3_parse_uint(ptr, 1); - - if (field->type == ID3_FIELD_TYPE_TEXTENCODING) - *encoding = field->number.value; - break; - - case ID3_FIELD_TYPE_LANGUAGE: - if (length < 3) - goto fail; - - id3_parse_immediate(ptr, 3, field->immediate.value); - break; - - case ID3_FIELD_TYPE_FRAMEID: - if (length < 4) - goto fail; - - id3_parse_immediate(ptr, 4, field->immediate.value); - break; - - case ID3_FIELD_TYPE_DATE: - if (length < 8) - goto fail; - - id3_parse_immediate(ptr, 8, field->immediate.value); - break; - - case ID3_FIELD_TYPE_LATIN1: - case ID3_FIELD_TYPE_LATIN1FULL: - { - id3_latin1_t *latin1; - - latin1 = id3_parse_latin1(ptr, length, - field->type == ID3_FIELD_TYPE_LATIN1FULL); - if (latin1 == 0) - goto fail; - - field->latin1.ptr = latin1; - } - break; - - case ID3_FIELD_TYPE_LATIN1LIST: - { - id3_byte_t const *end; - id3_latin1_t *latin1, **strings; - - end = *ptr + length; - - while (end - *ptr > 0) { - latin1 = id3_parse_latin1(ptr, end - *ptr, 0); - if (latin1 == 0) - goto fail; - - strings = realloc(field->latin1list.strings, - (field->latin1list.nstrings + 1) * sizeof(*strings)); - if (strings == 0) { - free(latin1); - goto fail; + assert(field); + + id3_field_finish(field); + + switch (field->type) { + case ID3_FIELD_TYPE_INT32: + if (length < 4) + goto fail; + + field->number.value = id3_parse_uint(ptr, 4); + break; + + case ID3_FIELD_TYPE_INT24: + if (length < 3) + goto fail; + + field->number.value = id3_parse_uint(ptr, 3); + break; + + case ID3_FIELD_TYPE_INT16: + if (length < 2) + goto fail; + + field->number.value = id3_parse_uint(ptr, 2); + break; + + case ID3_FIELD_TYPE_INT8: + case ID3_FIELD_TYPE_TEXTENCODING: + if (length < 1) + goto fail; + + field->number.value = id3_parse_uint(ptr, 1); + + if (field->type == ID3_FIELD_TYPE_TEXTENCODING) + *encoding = field->number.value; + break; + + case ID3_FIELD_TYPE_LANGUAGE: + if (length < 3) + goto fail; + + id3_parse_immediate(ptr, 3, field->immediate.value); + break; + + case ID3_FIELD_TYPE_FRAMEID: + if (length < 4) + goto fail; + + id3_parse_immediate(ptr, 4, field->immediate.value); + break; + + case ID3_FIELD_TYPE_DATE: + if (length < 8) + goto fail; + + id3_parse_immediate(ptr, 8, field->immediate.value); + break; + + case ID3_FIELD_TYPE_LATIN1: + case ID3_FIELD_TYPE_LATIN1FULL: + { + id3_latin1_t *latin1; + + latin1 = id3_parse_latin1(ptr, length, + field->type == + ID3_FIELD_TYPE_LATIN1FULL); + if (latin1 == 0) + goto fail; + + field->latin1.ptr = latin1; + } + break; + + case ID3_FIELD_TYPE_LATIN1LIST: + { + id3_byte_t const *end; + id3_latin1_t *latin1, + **strings; + + end = *ptr + length; + + while (end - *ptr > 0) { + latin1 = + id3_parse_latin1(ptr, end - *ptr, 0); + if (latin1 == 0) + goto fail; + + strings = + realloc(field->latin1list.strings, + (field->latin1list.nstrings + + 1) * sizeof(*strings)); + if (strings == 0) { + free(latin1); + goto fail; + } + + field->latin1list.strings = strings; + field->latin1list.strings + [field->latin1list.nstrings++] = latin1; + } + } + break; + + case ID3_FIELD_TYPE_STRING: + case ID3_FIELD_TYPE_STRINGFULL: + { + id3_ucs4_t *ucs4; + + ucs4 = id3_parse_string(ptr, length, *encoding, + field->type == < |