From: <ny...@us...> - 2006-06-05 23:51:26
|
Revision: 44 Author: nyaochi Date: 2006-06-03 22:18:21 -0700 (Sat, 03 Jun 2006) ViewCVS: http://svn.sourceforge.net/pmplib/?rev=44&view=rev Log Message: ----------- Added a new option (--strip-words, -t) to configure a list of words to be stripped from artist names. Modified Paths: -------------- trunk/frontend/easypmp/common/database.c trunk/frontend/easypmp/common/easypmp.h trunk/frontend/easypmp/cui/option.c Modified: trunk/frontend/easypmp/common/database.c =================================================================== --- trunk/frontend/easypmp/common/database.c 2006-06-04 04:34:08 UTC (rev 43) +++ trunk/frontend/easypmp/common/database.c 2006-06-04 05:18:21 UTC (rev 44) @@ -378,3 +378,62 @@ pmpdb->release(pmpdb); return 0; } + + + +int easypmp_set_strip_words(option_t* opt, const ucs2char_t* str) +{ + size_t i; + const ucs2char_t *p = 0, *q = 0; + + /* + * This function parses a list of strip words specified by comma separated + * values (CSV) and stores them into the option_t instance. Escape by quatation + * mark, eg., "word, " is not allowed at this moment. + */ + + /* Free buffers allocated already. */ + for (i = 0;i < opt->num_strip_words;++i) { + ucs2free(opt->strip_words[i]); + } + ucs2free(opt->strip_words); + + if (str && *str) { + /* Count the number of strip words in str. */ + opt->num_strip_words = 1; + for (p = str;*p;++p) { + if (*p == ',') { + opt->num_strip_words++; + } + } + + /* Allocate an array to store strip words. */ + opt->strip_words = (ucs2char_t**)ucs2malloc(sizeof(ucs2char_t*) * opt->num_strip_words); + if (!opt->strip_words) { + return -1; + } + + /* Parse the list of strip words. */ + p = q = str; + for (i = 0;i < opt->num_strip_words;++i) { + opt->strip_words[i] = 0; + for (;;) { + if (*q == ',' || !*q) { + size_t length = (size_t)(q - p); + opt->strip_words[i] = (ucs2char_t*)ucs2malloc(sizeof(ucs2char_t) * (length+1)); + memset(opt->strip_words[i], 0, sizeof(ucs2char_t) * (length+1)); + ucs2ncpy(opt->strip_words[i], p, length); + opt->strip_words[i][length] = 0; + if (!*q) { + break; + } else { + p = q+1; + } + } + q++; + } + } + } + return 0; +} + Modified: trunk/frontend/easypmp/common/easypmp.h =================================================================== --- trunk/frontend/easypmp/common/easypmp.h 2006-06-04 04:34:08 UTC (rev 43) +++ trunk/frontend/easypmp/common/easypmp.h 2006-06-04 05:18:21 UTC (rev 44) @@ -153,6 +153,12 @@ ); int +easypmp_set_strip_words( + option_t* opt, + const ucs2char_t* str + ); + +int easypmp_playlist( const easypmp_filelist_t* playlists, const easypmp_filelist_t* musics, Modified: trunk/frontend/easypmp/cui/option.c =================================================================== --- trunk/frontend/easypmp/cui/option.c 2006-06-04 04:34:08 UTC (rev 43) +++ trunk/frontend/easypmp/cui/option.c 2006-06-04 05:18:21 UTC (rev 44) @@ -67,6 +67,7 @@ fprintf(fp, " -u, --update Update the existing media database incrementally\n"); fprintf(fp, " -R, --repr Output a database structure in plain text\n"); fprintf(fp, " -l, --repr-level=VAL Specify representation level\n"); + fprintf(fp, " -t, --strip-words=VAL Specify a list (CSV) of words to strip from artist names\n"); fprintf(fp, "\n"); fprintf(fp, "Playlist options:\n"); fprintf(fp, " -P, --playlist Convert playlist files in PLAYLIST directory\n"); @@ -93,42 +94,8 @@ static void set_strip_words(option_t* opt, const char *str) { - size_t i; - const char *p = 0, *q = 0; - - for (i = 0;i < opt->num_strip_words;++i) { - ucs2free(opt->strip_words[i]); - } - ucs2free(opt->strip_words); - - if (str && *str) { - opt->num_strip_words = 1; - for (p = str;*p;++p) { - if (*p == ',') { - opt->num_strip_words++; - } - } - - p = q = str; - opt->strip_words = (ucs2char_t**)ucs2malloc(sizeof(ucs2char_t*) * opt->num_strip_words); - for (i = 0;i < opt->num_strip_words;++i) { - opt->strip_words[i] = 0; - for (;;) { - if (*q == ',' || !*q) { - size_t length = mbstoucs2(0, 0, p, q-p); - opt->strip_words[i] = ucs2malloc(sizeof(ucs2char_t*) * length + 1); - mbstoucs2(opt->strip_words[i], length, p, q-p); - opt->strip_words[i][length] = 0; - if (!*q) { - break; - } else { - p = q+1; - } - } - q++; - } - } - } + ucs2char_t* ucs2str = mbsdupucs2(str); + easypmp_set_strip_words(opt, ucs2str); } int option_parse(option_t* opt, int argc, char *argv[], FILE *fpe) @@ -150,6 +117,7 @@ {"source", required_argument, 0, 'z'}, {"repr", no_argument, 0, 'R'}, {"repr-level", required_argument, 0, 'l'}, + {"strip-words", required_argument, 0, 't'}, {"playlist", no_argument, 0, 'P'}, {"music", no_argument, 0, 'M'}, {"reconvert", no_argument, 0, 'r'}, @@ -167,9 +135,9 @@ {NULL, 0, 0, 0} }; #ifndef _WIN32 - int c = getopt_long(argc, argv, "DuzRl:PMrfsjLd:e:w:Vh", long_options, &option_index); + int c = getopt_long(argc, argv, "DuzRl:t:PMrfsjLd:e:w:Vh", long_options, &option_index); #else - int c = getopt_long(argc, argv, "DuzRl:PMrfsjLd:Vh", long_options, &option_index); + int c = getopt_long(argc, argv, "DuzRl:t:PMrfsjLd:Vh", long_options, &option_index); #endif/*_WIN32*/ if (c == -1) { break; @@ -203,6 +171,9 @@ case 'l': opt->repr_level = atoi(optarg); break; + case 't': + set_strip_words(opt, optarg); + break; case 'P': opt->verb |= (MODE_PLAYLIST | MODE_PLAYLIST_PLAYLIST); break; @@ -227,7 +198,7 @@ case 'd': strcpy(opt->model, optarg); break; -#ifndef _WIN32 +#ifndef _WIN32 case 'e': opt->system_encoding = optarg; break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |