From: <ny...@us...> - 2006-06-24 17:30:40
|
Revision: 62 Author: nyaochi Date: 2006-06-24 10:30:18 -0700 (Sat, 24 Jun 2006) ViewCVS: http://svn.sourceforge.net/pmplib/?rev=62&view=rev Log Message: ----------- libgmi: migrated from ucs2char_t to wchar_t. Note that libgmi still depends on libucs2 in order to parse WMA and WAV files. Modified Paths: -------------- branches/branch_0.12/include/gmi.h branches/branch_0.12/include/os.h branches/branch_0.12/include/wstring.h branches/branch_0.12/lib/gmi/gmi.c branches/branch_0.12/lib/gmi/gmi_mp3.c branches/branch_0.12/lib/gmi/gmi_vorbis.c branches/branch_0.12/lib/gmi/gmi_wav.c branches/branch_0.12/lib/gmi/gmi_wma.c branches/branch_0.12/lib/wstring/wstring_win32.c branches/branch_0.12/pmp.sln Modified: branches/branch_0.12/include/gmi.h =================================================================== --- branches/branch_0.12/include/gmi.h 2006-06-24 16:49:51 UTC (rev 61) +++ branches/branch_0.12/include/gmi.h 2006-06-24 17:30:18 UTC (rev 62) @@ -54,10 +54,10 @@ GMIAPI int gmi_get( media_info_t* info, - const ucs2char_t *filename, - const ucs2char_t* path_to_music, + const wchar_t *filename, + const wchar_t* path_to_music, int flag, - const ucs2char_t** strip_words, + const wchar_t** strip_words, int num_strip_words ); Modified: branches/branch_0.12/include/os.h =================================================================== --- branches/branch_0.12/include/os.h 2006-06-24 16:49:51 UTC (rev 61) +++ branches/branch_0.12/include/os.h 2006-06-24 17:30:18 UTC (rev 62) @@ -49,6 +49,7 @@ #define getcwd _getcwd #define alloca _alloca #define strnicmp _strnicmp +#define wtoi _wtoi #define PATHCHAR '\\' #define PATHSTR "\\" Modified: branches/branch_0.12/include/wstring.h =================================================================== --- branches/branch_0.12/include/wstring.h 2006-06-24 16:49:51 UTC (rev 61) +++ branches/branch_0.12/include/wstring.h 2006-06-24 17:30:18 UTC (rev 62) @@ -35,6 +35,8 @@ wchar_t *wcsstrip(wchar_t* str); wchar_t *wcsfgets(wchar_t* str, size_t max_bytes, FILE *fp, int is_utf8); +wchar_t* wcsndup(const wchar_t* src, size_t length); +int wcsincmp(const wchar_t* x, const wchar_t* y, size_t n); int has_utf8bom(FILE *fp); Modified: branches/branch_0.12/lib/gmi/gmi.c =================================================================== --- branches/branch_0.12/lib/gmi/gmi.c 2006-06-24 16:49:51 UTC (rev 61) +++ branches/branch_0.12/lib/gmi/gmi.c 2006-06-24 17:30:18 UTC (rev 62) @@ -27,69 +27,70 @@ #endif/*HAVE_CONFIG_H*/ #include <os.h> -#include <ucs2char.h> +#include <wchar.h> +#include <wstring.h> #include <filepath.h> #include <gmi.h> -int gmi_mp3(media_info_t* info, const ucs2char_t *filename); -static const ucs2char_t ucs2cs_ext_mp3[] = {'.','m','p','3',0}; +int gmi_mp3(media_info_t* info, const wchar_t *filename); +static const wchar_t* wcscs_ext_mp3 = L".mp3"; -int gmi_wma(media_info_t* info, const ucs2char_t *filename); -static const ucs2char_t ucs2cs_ext_wma[] = {'.','w','m','a',0}; +int gmi_wma(media_info_t* info, const wchar_t *filename); +static const wchar_t* wcscs_ext_wma = L".wma"; -int gmi_vorbis(media_info_t* info, const ucs2char_t *filename); -static const ucs2char_t ucs2cs_ext_ogg[] = {'.','o','g','g',0}; +int gmi_vorbis(media_info_t* info, const wchar_t *filename); +static const wchar_t* wcscs_ext_ogg = L".ogg"; -int gmi_wav(media_info_t* info, const ucs2char_t *filename); -static const ucs2char_t ucs2cs_ext_wav[] = {'.','w','a','v',0}; +int gmi_wav(media_info_t* info, const wchar_t *filename); +static const wchar_t* wcscs_ext_wav = L".wav"; typedef struct { - int (*func)(media_info_t* info, const ucs2char_t *filename); - const ucs2char_t* ext; + int (*func)(media_info_t* info, const wchar_t *filename); + const wchar_t* ext; } gmi_exports_t; static gmi_exports_t gmi_exports[] = { - {gmi_mp3, ucs2cs_ext_mp3}, - {gmi_wma, ucs2cs_ext_wma}, - {gmi_vorbis, ucs2cs_ext_ogg}, - {gmi_wav, ucs2cs_ext_wav}, + {gmi_mp3, L".mp3"}, + {gmi_wma, L".wma"}, + {gmi_vorbis, L".ogg"}, + {gmi_wav, L".wav"}, {NULL, NULL}, }; static int gmi_get_from_pathname( media_info_t* info, - const ucs2char_t *filename, - const ucs2char_t* path_to_music, + const wchar_t *filename, + const wchar_t* path_to_music, int flag ) { - const ucs2char_t *p = NULL, *q = NULL; - ucs2char_t file[MAX_PATH], path[MAX_PATH]; + const wchar_t *p = NULL, *q = NULL; + wchar_t file[MAX_PATH], path[MAX_PATH]; - ucs2cpy(file, filepath_skippath(filename)); - ucs2cpy(path, filename); + wcscpy(file, filepath_skippath(filename)); + wcscpy(path, filename); filepath_remove_filespec(path); if (flag & GMIF_PARSEMASK) { /* Clear fields according to the type. */ if (flag & GMIF_TITLE) { - ucs2free(info->title); info->title = NULL; + free(info->title); info->title = NULL; } if (flag & GMIF_ALBUM) { - ucs2free(info->album); info->album = NULL; + free(info->album); info->album = NULL; } if (flag & GMIF_GENRE) { - ucs2free(info->genre); info->genre = NULL; + free(info->genre); info->genre = NULL; } if (flag & GMIF_ARTIST) { - ucs2free(info->artist); info->artist = NULL; + free(info->artist); info->artist = NULL; } /* Obtain path name to the music. */ - p = ucs2str(path, path_to_music); + p = wcsstr(path, path_to_music); if (p) { - p += ucs2len(path_to_music); + p += wcslen(path_to_music); } else { p = path; } @@ -98,26 +99,26 @@ if (flag & GMIF_GENRE) { q = filepath_skip_one_directory(p); if (q) { - info->genre = ucs2ndup(p, (q-p) - 1); + info->genre = wcsndup(p, (q-p) - 1); p = q; q = filepath_skip_one_directory(p); if (q) { - info->artist = ucs2ndup(p, (q-p) - 1); + info->artist = wcsndup(p, (q-p) - 1); if (flag & GMIF_ALBUM) { - info->album = ucs2dup(q); + info->album = wcsdup(q); filepath_removeslash(info->album); - filepath_replace_slash(info->album, (ucs2char_t)' '); + filepath_replace_slash(info->album, (wchar_t)' '); } } } } else { q = filepath_skip_one_directory(p); if (q) { - info->artist = ucs2ndup(p, (q-p) - 1); + info->artist = wcsndup(p, (q-p) - 1); if (flag & GMIF_ALBUM) { - info->album = ucs2dup(q); + info->album = wcsdup(q); filepath_removeslash(info->album); - filepath_replace_slash(info->album, (ucs2char_t)' '); + filepath_replace_slash(info->album, (wchar_t)' '); } } } @@ -133,7 +134,7 @@ p++; /* Obtain track number. */ - info->track_number = (uint32_t)ucs2toi(file); + info->track_number = (uint32_t)wtoi(file); if (flag & GMIF_TITLE) { /* Skip space and '_' letters. */ @@ -142,33 +143,33 @@ } /* Obtain track title. */ - info->title = ucs2dup(p); + info->title = wcsdup(p); filepath_remove_extension(info->title); if (!info->title[0]) { /* If track title becomes empty (e.g., 01.mp3), set the filename. */ - ucs2free(info->title); - info->title = ucs2dup(file); + free(info->title); + info->title = wcsdup(file); filepath_remove_extension(info->title); } } } else { /* The filename begins with one numerical letter. */ if (flag & GMIF_TITLE) { - info->title = ucs2dup(file); + info->title = wcsdup(file); filepath_remove_extension(info->title); } } } else { /* The filename does not begin with a numerical letter. */ if (flag & GMIF_TITLE) { - info->title = ucs2dup(file); + info->title = wcsdup(file); filepath_remove_extension(info->title); } } } else { if (flag & GMIF_TITLE) { /* Use filename as a title. */ - info->title = ucs2dup(file); + info->title = wcsdup(file); filepath_remove_extension(info->title); } } @@ -177,10 +178,10 @@ return 0; } -static void strip_head_letters(ucs2char_t* str, size_t offset) +static void strip_head_letters(wchar_t* str, size_t offset) { - if (offset <= ucs2len(str)) { - size_t i, n = ucs2len(str) + 1 - offset; + if (offset <= wcslen(str)) { + size_t i, n = wcslen(str) + 1 - offset; for (i = 0;i < n;++i) { str[i] = str[i+offset]; } @@ -189,10 +190,10 @@ int gmi_get( media_info_t* info, - const ucs2char_t *filename, - const ucs2char_t* path_to_music, + const wchar_t *filename, + const wchar_t* path_to_music, int flag, - const ucs2char_t* strip_words[], + const wchar_t* strip_words[], int num_strip_words ) { @@ -200,8 +201,8 @@ gmi_exports_t* exp = gmi_exports; /* Set the pathname and filename. */ - info->filename = ucs2dup(filename); - info->filesize = ucs2stat_size(filename); + info->filename = wcsdup(filename); + info->filesize = filepath_filesize(filename); if (flag & GMIF_TAG) { while (exp->func) { @@ -223,8 +224,8 @@ if ((flag & GMIF_STRIP_ARTIST) && strip_words) { int i; for (i = 0;i < num_strip_words;++i) { - if (ucs2incmp(info->artist, strip_words[i], ucs2len(strip_words[i])) == 0) { - strip_head_letters(info->artist, ucs2len(strip_words[i])); + if (wcsincmp(info->artist, strip_words[i], wcslen(strip_words[i])) == 0) { + strip_head_letters(info->artist, wcslen(strip_words[i])); break; } } Modified: branches/branch_0.12/lib/gmi/gmi_mp3.c =================================================================== --- branches/branch_0.12/lib/gmi/gmi_mp3.c 2006-06-24 16:49:51 UTC (rev 61) +++ branches/branch_0.12/lib/gmi/gmi_mp3.c 2006-06-24 17:30:18 UTC (rev 62) @@ -33,7 +33,9 @@ #include <string.h> #include <sys/types.h> #include <sys/stat.h> -#include <ucs2char.h> +#include <wchar.h> +#include <wstring.h> +#include <filepath.h> #include <gmi.h> #include <id3tag.h> @@ -201,11 +203,11 @@ return 0; } -static int get_mp3stream_info(mp3header_t* header, const ucs2char_t *filename, uint32_t filesize) +static int get_mp3stream_info(mp3header_t* header, const wchar_t *filename, uint32_t filesize) { int channels = 0; uint8_t buffer[4]; - FILE *fp = ucs2fopen(filename, "rb"); + FILE *fp = filepath_fopen(filename, L"rb"); if (!fp) { return -1; } @@ -268,9 +270,9 @@ } -static ucs2char_t* get_frame_value(struct id3_tag *id3tag, const char *name) +static wchar_t* get_frame_value(struct id3_tag *id3tag, const char *name) { - ucs2char_t* ret = NULL; + wchar_t* ret = NULL; const id3_ucs4_t *value = NULL; struct id3_frame *frame = NULL; union id3_field *field = NULL; @@ -308,30 +310,30 @@ if (encoding == ID3_FIELD_TEXTENCODING_ISO_8859_1) { char *mbs = id3_ucs4_latin1duplicate(value); - ret = mbsdupucs2_music(mbs); /* MBS for music files. */ + ret = mbsdupwcs(mbs); /* MBS for music files. */ free(mbs); return ret; } else { - ucs2char_t* ucs2 = id3_ucs4_utf16duplicate(value); - ret = ucs2dup(ucs2); - free(ucs2); + wchar_t* wcs = id3_ucs4_utf16duplicate(value); + ret = wcsdup(wcs); + free(wcs); return ret; } } -int gmi_mp3(media_info_t* info, const ucs2char_t *filename) +int gmi_mp3(media_info_t* info, const wchar_t *filename) { int i, num_tags = 0; FILE *fp = NULL; mp3header_t mp3header; uint32_t tn = 0; - static const ucs2char_t ucs2_empty[1] = {0}; - ucs2char_t* ucs2 = NULL; + static const wchar_t wcs_empty[1] = {0}; + wchar_t* wcs = NULL; struct id3_file *id3file = NULL; struct id3_tag *id3tag = NULL; /* Open the file with UNICODE filename. This is for better compatibility. */ - fp = ucs2fopen(filename, "rb"); + fp = filepath_fopen(filename, L"rb"); if (!fp) { return -1; } @@ -371,106 +373,106 @@ } /* Obtain track number first. */ - ucs2 = get_frame_value(id3tag, "TRCK"); - if (ucs2 && *ucs2) { - info->track_number = ucs2toi(ucs2); + wcs = get_frame_value(id3tag, "TRCK"); + if (wcs && *wcs) { + info->track_number = wtoi(wcs); } else { info->track_number = 0; } - ucs2free(ucs2); + free(wcs); /* Obtain track title. */ - ucs2 = get_frame_value(id3tag, "TIT2"); - if (ucs2 && *ucs2) { - ucs2free(info->title); - info->title = ucs2dup(ucs2); + wcs = get_frame_value(id3tag, "TIT2"); + if (wcs && *wcs) { + free(info->title); + info->title = wcsdup(wcs); } - ucs2free(ucs2); + free(wcs); /* Set artist field. */ - if (1) ucs2 = get_frame_value(id3tag, "TPE1"); - if (!ucs2) ucs2 = get_frame_value(id3tag, "TPE2"); - if (!ucs2) ucs2 = get_frame_value(id3tag, "TPE3"); - if (!ucs2) ucs2 = get_frame_value(id3tag, "TPE4"); - if (!ucs2) ucs2 = get_frame_value(id3tag, "TCOM"); - if (ucs2 && *ucs2) { - ucs2free(info->artist); - info->artist = ucs2dup(ucs2); + if (1) wcs = get_frame_value(id3tag, "TPE1"); + if (!wcs) wcs = get_frame_value(id3tag, "TPE2"); + if (!wcs) wcs = get_frame_value(id3tag, "TPE3"); + if (!wcs) wcs = get_frame_value(id3tag, "TPE4"); + if (!wcs) wcs = get_frame_value(id3tag, "TCOM"); + if (wcs && *wcs) { + free(info->artist); + info->artist = wcsdup(wcs); } - ucs2free(ucs2); + free(wcs); /* Set composer field. */ - ucs2 = get_frame_value(id3tag, "TCOM"); - if (ucs2 && *ucs2) { - ucs2free(info->composer); - info->composer = ucs2dup(ucs2); + wcs = get_frame_value(id3tag, "TCOM"); + if (wcs && *wcs) { + free(info->composer); + info->composer = wcsdup(wcs); } - ucs2free(ucs2); + free(wcs); /* Set album field. */ - ucs2 = get_frame_value(id3tag, "TALB"); - if (ucs2 && *ucs2) { - ucs2free(info->album); - info->album = ucs2dup(ucs2); + wcs = get_frame_value(id3tag, "TALB"); + if (wcs && *wcs) { + free(info->album); + info->album = wcsdup(wcs); } - ucs2free(ucs2); + free(wcs); /* * TCMP (compilation flag) handling for omnibus albums. * This patch was originally submitted by Espen Matheussen. */ - ucs2 = get_frame_value(id3tag, "TCMP"); - if (ucs2 && *ucs2) { + wcs = get_frame_value(id3tag, "TCMP"); + if (wcs && *wcs) { size_t length = 0; - ucs2char_t* title = NULL; - static ucs2char_t separator[] = {' ','-',' ',0}; + wchar_t* title = NULL; + static wchar_t separator[] = {' ','-',' ',0}; /* Calculate the length of the new title. */ if (info->artist) { - length += ucs2len(info->artist); + length += wcslen(info->artist); } - length += ucs2len(separator); + length += wcslen(separator); if (info->title) { - length += ucs2len(info->title); + length += wcslen(info->title); } /* Construct the new title. */ - title = ucs2malloc(sizeof(ucs2char_t) * (length+1)); + title = (wchar_t*)malloc(sizeof(wchar_t) * (length+1)); if (info->artist) { - ucs2cpy(title, info->artist); + wcscpy(title, info->artist); } - ucs2cat(title, separator); + wcscat(title, separator); if (info->title) { - ucs2cat(title, info->title); + wcscat(title, info->title); } /* Free the previous title and artist. */ - ucs2free(info->title); - ucs2free(info->artist); + free(info->title); + free(info->artist); /* Set the new title and artist. */ info->title = title; - info->artist = mbsdupucs2("Various artists"); + info->artist = mbsdupwcs("Various artists"); } /* Set genre field. */ - ucs2 = get_frame_value(id3tag, "TCON"); - if (ucs2 && *ucs2) { - ucs2free(info->genre); - info->genre = ucs2dup(ucs2); + wcs = get_frame_value(id3tag, "TCON"); + if (wcs && *wcs) { + free(info->genre); + info->genre = wcsdup(wcs); } - ucs2free(ucs2); + free(wcs); /* Set year field. */ - if (1) ucs2 = get_frame_value(id3tag, "TYER"); - if (!ucs2) ucs2 = get_frame_value(id3tag, "TDRC"); - if (ucs2 && *ucs2) { - ucs2free(info->date); - info->date = ucs2dup(ucs2); + if (1) wcs = get_frame_value(id3tag, "TYER"); + if (!wcs) wcs = get_frame_value(id3tag, "TDRC"); + if (wcs && *wcs) { + free(info->date); + info->date = wcsdup(wcs); } else { info->date = 0; } - ucs2free(ucs2); + free(wcs); } /* Parse MPEG audio header. */ Modified: branches/branch_0.12/lib/gmi/gmi_vorbis.c =================================================================== --- branches/branch_0.12/lib/gmi/gmi_vorbis.c 2006-06-24 16:49:51 UTC (rev 61) +++ branches/branch_0.12/lib/gmi/gmi_vorbis.c 2006-06-24 17:30:18 UTC (rev 62) @@ -31,7 +31,9 @@ #include <stdio.h> #include <stdlib.h> #include <memory.h> -#include <ucs2char.h> +#include <wchar.h> +#include <wstring.h> +#include <filepath.h> #include <gmi.h> #include <vorbis/codec.h> @@ -41,7 +43,7 @@ #define strncasecmp strnicmp #endif -int gmi_vorbis(media_info_t* info, const ucs2char_t *filename) +int gmi_vorbis(media_info_t* info, const wchar_t *filename) { int i, ret = 0; long lval = 0; @@ -53,12 +55,12 @@ /* Set the pathname and filename. */ /* - info->filename = ucs2dup(filename); - info->filesize = ucs2stat_size(filename); + info->filename = wcsdup(filename); + info->filesize = wcsstat_size(filename); */ /* Open the target file. */ - fp = ucs2fopen(filename, "rb"); + fp = filepath_fopen(filename, L"rb"); if (!fp) { return -1; } @@ -97,17 +99,17 @@ for (i = 0;i < vc->comments;++i) { const char *fieldvalue = vc->user_comments[i]; if (strncasecmp(fieldvalue, "TITLE=", 6) == 0) { - info->title = utf8dupucs2(fieldvalue+6); + info->title = utf8dupwcs(fieldvalue+6); } else if (strncasecmp(fieldvalue, "ARTIST=", 7) == 0) { - info->artist = utf8dupucs2(fieldvalue+7); + info->artist = utf8dupwcs(fieldvalue+7); } else if (strncasecmp(fieldvalue, "ALBUM=", 6) == 0) { - info->album = utf8dupucs2(fieldvalue+6); + info->album = utf8dupwcs(fieldvalue+6); } else if (strncasecmp(fieldvalue, "GENRE=", 6) == 0) { - info->genre = utf8dupucs2(fieldvalue+6); + info->genre = utf8dupwcs(fieldvalue+6); } else if (strncasecmp(fieldvalue, "TRACKNUMBER=", 12) == 0) { info->track_number = atoi(fieldvalue+12); } else if (strncasecmp(fieldvalue, "DATE=", 5) == 0) { - info->date = utf8dupucs2(fieldvalue+5); + info->date = utf8dupwcs(fieldvalue+5); } } Modified: branches/branch_0.12/lib/gmi/gmi_wav.c =================================================================== --- branches/branch_0.12/lib/gmi/gmi_wav.c 2006-06-24 16:49:51 UTC (rev 61) +++ branches/branch_0.12/lib/gmi/gmi_wav.c 2006-06-24 17:30:18 UTC (rev 62) @@ -102,24 +102,24 @@ switch (ch.id) { case 0x44525049: /* "IPRD" */ - ucs2free(info->album); - info->album = mbsdupucs2_music(buffer); + free(info->album); + info->album = mbsdupwcs(buffer); break; case 0x4D414E49: /* "INAM" */ - ucs2free(info->title); - info->title = mbsdupucs2_music(buffer); + free(info->title); + info->title = mbsdupwcs(buffer); break; case 0x54524149: /* "IART" */ - ucs2free(info->artist); - info->artist = mbsdupucs2_music(buffer); + free(info->artist); + info->artist = mbsdupwcs(buffer); break; case 0x524E4749: /* "IGNR" */ - ucs2free(info->genre); - info->genre = mbsdupucs2_music(buffer); + free(info->genre); + info->genre = mbsdupwcs(buffer); break; case 0x44524349: /* "ICRD" */ - ucs2free(info->date); - info->date = mbsdupucs2_music(buffer); + free(info->date); + info->date = mbsdupwcs(buffer); break; case 0x6974726B: /* "itrk" */ info->track_number = atoi(buffer); @@ -151,7 +151,7 @@ uint16_t channels, sample_bits; /* Open the audio file. */ - fp = ucs2fopen(filename, "rb"); + fp = filepath_fopen(filename, L"rb"); if (!fp) { return -1; } Modified: branches/branch_0.12/lib/gmi/gmi_wma.c =================================================================== --- branches/branch_0.12/lib/gmi/gmi_wma.c 2006-06-24 16:49:51 UTC (rev 61) +++ branches/branch_0.12/lib/gmi/gmi_wma.c 2006-06-24 17:30:18 UTC (rev 62) @@ -31,6 +31,9 @@ #include <stdio.h> #include <stdlib.h> #include <memory.h> +#include <wchar.h> +#include <wstring.h> +#include <filepath.h> #include <ucs2char.h> #include <gmi.h> @@ -157,7 +160,7 @@ FILE *fp = NULL; /* Open the audio file. */ - fp = ucs2fopen(filename, "rb"); + fp = filepath_fopen(filename, L"rb"); if (!fp) { return -1; } @@ -378,6 +381,7 @@ } else if (guid_equals(guid, g_guid_content_description)) { /* Content Description Object (title, artist) */ uint16_t title_bytes, author_bytes; + ucs2char_t* ucs2 = NULL; if (!read_uint16le(&title_bytes, fp)) { goto get_asf_audio_info_error; @@ -391,18 +395,23 @@ /* Release the buffer first to overwrite the information without memory leak. */ free(info->title); - info->title = (ucs2char_t*)malloc(title_bytes+sizeof(ucs2char_t)); - if (!info->title || !read_ucs2le_fixed(info->title, title_bytes/sizeof(ucs2char_t), fp)) { + ucs2 = (ucs2char_t*)malloc(title_bytes+sizeof(ucs2char_t)); + if (!ucs2 || !read_ucs2le_fixed(ucs2, title_bytes/sizeof(ucs2char_t), fp)) { goto get_asf_audio_info_error; } + info->title = ucs2dupwcs(ucs2); + free(ucs2); + ucs2 = NULL; free(info->artist); - info->artist = (ucs2char_t*)malloc(author_bytes+sizeof(ucs2char_t)); - if (!info->artist || !read_ucs2le_fixed(info->artist, author_bytes/sizeof(ucs2char_t), fp)) { + ucs2 = (ucs2char_t*)malloc(author_bytes+sizeof(ucs2char_t)); + if (!ucs2 || !read_ucs2le_fixed(ucs2, author_bytes/sizeof(ucs2char_t), fp)) { goto get_asf_audio_info_error; } + info->artist = ucs2dupwcs(ucs2); + free(ucs2); + ucs2 = NULL; - } else if (guid_equals(guid, g_guid_extended_content_description)) { /* Extended Content Description Object (album, genre, etc.) */ uint16_t j, num_descriptions; @@ -412,6 +421,7 @@ } for (j = 0;j < num_descriptions;j++) { + ucs2char_t* ucs2 = NULL; static const ucs2char_t ucs2cs_wm_albumartist[] = {'w','m','/','a','l','b','u','m','a','r','t','i','s','t',0}; static const ucs2char_t ucs2cs_artist[] = {'a','r','t','i','s','t',0}; static const ucs2char_t ucs2cs_wm_albumtitle[] = {'w','m','/','a','l','b','u','m','t','i','t','l','e',0}; @@ -448,38 +458,53 @@ /* If an artist name was extracted from Content Description, we don't parse wm/albumartist. */ if ((!info->artist || !info->artist[0]) && (ucs2icmp(name, ucs2cs_wm_albumartist) == 0 || ucs2icmp(name, ucs2cs_artist) == 0)) { free(info->artist); - info->artist = (ucs2char_t*)ucs2malloc(value_bytes+sizeof(ucs2char_t)); - if (!info->artist || !read_ucs2le_fixed(info->artist, value_bytes/sizeof(ucs2char_t), fp)) { + ucs2 = (ucs2char_t*)ucs2malloc(value_bytes+sizeof(ucs2char_t)); + if (!ucs2 || !read_ucs2le_fixed(ucs2, value_bytes/sizeof(ucs2char_t), fp)) { goto get_asf_audio_info_error; - } + } + info->artist = ucs2dupwcs(ucs2); + free(ucs2); + ucs2 = NULL; } else if (ucs2icmp(name, ucs2cs_wm_albumtitle) == 0 || ucs2icmp(name, ucs2cs_album) == 0) { free(info->album); - info->album = (ucs2char_t*)ucs2malloc(value_bytes+sizeof(ucs2char_t)); - if (!info->album || !read_ucs2le_fixed(info->album, value_bytes/sizeof(ucs2char_t), fp)) { + ucs2 = (ucs2char_t*)ucs2malloc(value_bytes+sizeof(ucs2char_t)); + if (!ucs2 || !read_ucs2le_fixed(ucs2, value_bytes/sizeof(ucs2char_t), fp)) { goto get_asf_audio_info_error; - } + } + info->album = ucs2dupwcs(ucs2); + free(ucs2); + ucs2 = NULL; } else if (ucs2icmp(name, ucs2cs_wm_genre) == 0 || ucs2icmp(name, ucs2cs_genre) == 0) { free(info->genre); - info->genre = (ucs2char_t*)ucs2malloc(value_bytes+sizeof(ucs2char_t)); - if (!info->genre || !read_ucs2le_fixed(info->genre, value_bytes/sizeof(ucs2char_t), fp)) { + ucs2 = (ucs2char_t*)ucs2malloc(value_bytes+sizeof(ucs2char_t)); + if (!ucs2 || !read_ucs2le_fixed(ucs2, value_bytes/sizeof(ucs2char_t), fp)) { goto get_asf_audio_info_error; } + info->genre = ucs2dupwcs(ucs2); + free(ucs2); + ucs2 = NULL; } else if (ucs2icmp(name, ucs2cs_wm_composer) == 0 || ucs2icmp(name, ucs2cs_composer) == 0) { free(info->composer); - info->composer = (ucs2char_t*)malloc(value_bytes+sizeof(ucs2char_t)); - if (!info->composer || !read_ucs2le_fixed(info->composer, value_bytes/sizeof(ucs2char_t), fp)) { + ucs2 = (ucs2char_t*)malloc(value_bytes+sizeof(ucs2char_t)); + if (!ucs2 || !read_ucs2le_fixed(ucs2, value_bytes/sizeof(ucs2char_t), fp)) { goto get_asf_audio_info_error; } + info->composer = ucs2dupwcs(ucs2); + free(ucs2); + ucs2 = NULL; } else if (ucs2icmp(name, ucs2cs_wm_tracknumber) == 0 || ucs2icmp(name, ucs2cs_tracknumber) == 0) { info->track_number = read_field_as_uint32(value_type, value_bytes, fp); } else if (ucs2icmp(name, ucs2cs_wm_track) == 0) { info->track_number = read_field_as_uint32(value_type, value_bytes, fp) + 1; } else if (ucs2icmp(name, ucs2cs_wm_year) == 0 || ucs2icmp(name, ucs2cs_year) == 0 || ucs2icmp(name, ucs2cs_date) == 0) { free(info->date); - info->date = (ucs2char_t*)ucs2malloc(value_bytes+sizeof(ucs2char_t)); - if (!info->date || !read_ucs2le_fixed(info->date, value_bytes/sizeof(ucs2char_t), fp)) { + ucs2 = (ucs2char_t*)ucs2malloc(value_bytes+sizeof(ucs2char_t)); + if (!ucs2 || !read_ucs2le_fixed(ucs2, value_bytes/sizeof(ucs2char_t), fp)) { goto get_asf_audio_info_error; } + info->date = ucs2dupwcs(ucs2); + free(ucs2); + ucs2 = NULL; } else { if (fseek(fp, value_bytes, SEEK_CUR) != 0) { goto get_asf_audio_info_error; Modified: branches/branch_0.12/lib/wstring/wstring_win32.c =================================================================== --- branches/branch_0.12/lib/wstring/wstring_win32.c 2006-06-24 16:49:51 UTC (rev 61) +++ branches/branch_0.12/lib/wstring/wstring_win32.c 2006-06-24 17:30:18 UTC (rev 62) @@ -31,6 +31,8 @@ #include <wchar.h> #include <string.h> +#define COMP(a, b) ((a)>(b))-((a)<(b)) + char *wcsdupmbs(const wchar_t* src) { size_t dst_size = wcstombs(NULL, src, 0); @@ -232,3 +234,41 @@ } } } + +wchar_t* wcsndup(const wchar_t* src, size_t length) +{ + wchar_t* dst = NULL; + size_t src_length = wcslen(src); + if (length < src_length) { + src_length = length; + } + dst = (wchar_t*)malloc((src_length+1) * sizeof(wchar_t)); + if (dst) { + size_t i; + for (i = 0;i < src_length;i++) { + dst[i] = src[i]; + } + dst[i] = 0; + } + return dst; +} + +int wcsincmp(const wchar_t* x, const wchar_t* y, size_t n) +{ + size_t i; + wchar_t a = 0, b = 0; + + for (i = 0;i < n-1;i++) { + a = towupper(*x); + b = towupper(*y); + if (!*x || !*y || a != b) { + break; + } + x++; + y++; + } + return COMP(a, b); +} + + + Modified: branches/branch_0.12/pmp.sln =================================================================== --- branches/branch_0.12/pmp.sln 2006-06-24 16:49:51 UTC (rev 61) +++ branches/branch_0.12/pmp.sln 2006-06-24 17:30:18 UTC (rev 62) @@ -11,6 +11,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gmi", "lib\gmi\gmi.vcproj", "{3575EFC2-9051-467A-BEB4-E71E2F8664D7}" ProjectSection(ProjectDependencies) = postProject {AA8DA82B-C209-4ABE-ABA1-22352962426D} = {AA8DA82B-C209-4ABE-ABA1-22352962426D} + {59650257-D8E9-4253-827D-8110C3DAAA3D} = {59650257-D8E9-4253-827D-8110C3DAAA3D} {FA6E7B73-7CF8-47DD-A016-77382A1FD904} = {FA6E7B73-7CF8-47DD-A016-77382A1FD904} {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} = {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} EndProjectSection This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |