From: <ny...@us...> - 2006-04-05 13:58:16
|
Revision: 8 Author: nyaochi Date: 2006-04-05 06:57:51 -0700 (Wed, 05 Apr 2006) ViewCVS: http://svn.sourceforge.net/pmplib/?rev=8&view=rev Log Message: ----------- More JSPL related work. Modified Paths: -------------- trunk/frontend/easypmp/common/easypmp.h trunk/frontend/easypmp/common/playlist.c trunk/frontend/easypmp/cui/main.c trunk/frontend/easypmp/cui/option.c trunk/include/playlist.h trunk/lib/playlist/jspl.c trunk/lib/playlist/playlist.c Modified: trunk/frontend/easypmp/common/easypmp.h =================================================================== --- trunk/frontend/easypmp/common/easypmp.h 2006-04-04 06:49:42 UTC (rev 7) +++ trunk/frontend/easypmp/common/easypmp.h 2006-04-05 13:57:51 UTC (rev 8) @@ -84,6 +84,7 @@ uint32_t media_info_source; int repr_level; ucs2char_t path_to_root[MAX_PATH]; + ucs2char_t path_to_include[MAX_PATH]; char model[128]; char *system_encoding; char *music_encoding; Modified: trunk/frontend/easypmp/common/playlist.c =================================================================== --- trunk/frontend/easypmp/common/playlist.c 2006-04-04 06:49:42 UTC (rev 7) +++ trunk/frontend/easypmp/common/playlist.c 2006-04-05 13:57:51 UTC (rev 8) @@ -131,7 +131,7 @@ // Read the source playlist playlist_init(&pls); - if (playlist_read(&pls, src, records, num_records, callback_from_playlist, &cd) != 0) { + if (playlist_read(&pls, src, opt->path_to_include, records, num_records, callback_from_playlist, &cd) != 0) { result = EASYPMPE_PLAYLIST_READ; goto error_exit; } Modified: trunk/frontend/easypmp/cui/main.c =================================================================== --- trunk/frontend/easypmp/cui/main.c 2006-04-04 06:49:42 UTC (rev 7) +++ trunk/frontend/easypmp/cui/main.c 2006-04-05 13:57:51 UTC (rev 8) @@ -49,7 +49,7 @@ #endif #define APPLICATION_S "EasyPMP [CUI]" -#define VERSION_S "0.8 alpha" +#define VERSION_S "0.9 alpha" #define COPYRIGHT_S "Copyright (c) 2005-2006 Nyaochi" int database_dump(pmp_t* pmp, FILE *fpo, int level); Modified: trunk/frontend/easypmp/cui/option.c =================================================================== --- trunk/frontend/easypmp/cui/option.c 2006-04-04 06:49:42 UTC (rev 7) +++ trunk/frontend/easypmp/cui/option.c 2006-04-05 13:57:51 UTC (rev 8) @@ -29,6 +29,10 @@ #include <os.h> #include <stdio.h> #include <stdlib.h> +#ifdef _MSC_VER +#include <direct.h> /* getcwd() */ +#endif/*_MSC_VER*/ + #include <ucs2char.h> #include <filepath.h> #include <gmi.h> @@ -94,6 +98,19 @@ opt->media_info_source |= GMIF_TAG; + if (!opt->path_to_include[0]) { + char pwd[MAX_PATH+1]; + ucs2char_t ucs2pwd[MAX_PATH+1]; + ucs2char_t ucs2argv0[MAX_PATH+1]; + + getcwd(pwd, MAX_PATH); + mbstoucs2(ucs2pwd, MAX_PATH, pwd, strlen(pwd)+1); + mbstoucs2(ucs2argv0, MAX_PATH, argv[0], strlen(argv[0])+1); + filepath_relative_to_absolute(opt->path_to_include, ucs2pwd, ucs2argv0); + + filepath_remove_filespec(opt->path_to_include); + } + /* Parse the command-line arguments. */ for (;;) { int this_option_optind = optind ? optind : 1; Modified: trunk/include/playlist.h =================================================================== --- trunk/include/playlist.h 2006-04-04 06:49:42 UTC (rev 7) +++ trunk/include/playlist.h 2006-04-05 13:57:51 UTC (rev 8) @@ -102,6 +102,7 @@ playlist_read( playlists_t* pls, const ucs2char_t* filename, + const ucs2char_t* path_to_include, pmp_record_t* records, int num_records, playlist_callback_t callback, Modified: trunk/lib/playlist/jspl.c =================================================================== --- trunk/lib/playlist/jspl.c 2006-04-04 06:49:42 UTC (rev 7) +++ trunk/lib/playlist/jspl.c 2006-04-05 13:57:51 UTC (rev 8) @@ -40,13 +40,17 @@ #define XP_WIN #include <js/jsapi.h> -#define COMP(a, b) ((a)>(b))-((a)<(b)) +#define MAX_SOURCE_DEPTH 64 struct tag_jspl { JSRuntime *runtime; JSContext *context; JSObject *global; + const ucs2char_t *path_to_include; + const ucs2char_t path_to_source[MAX_PATH][MAX_SOURCE_DEPTH]; + int source_depth; + int num_records; JSObject **records; JSObject *tracks; @@ -56,6 +60,9 @@ }; typedef struct tag_jspl jspl_t; +static int jspl_load_script(jspl_t* jspl, const ucs2char_t* filename); + + static jschar* JS_ucstrdup(JSContext *cx, const ucs2char_t* src, size_t* ptr_length) { size_t i, length = ucs2len(src); @@ -105,6 +112,12 @@ return 0; } +static int object_is_array(JSContext* cx, JSObject* obj) +{ + jsuint length; + return JS_HasArrayLength(cx, obj, &length) ? 1 : 0; +} + static JSBool js_print(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { @@ -136,8 +149,32 @@ return JS_TRUE; } +static JSBool +js_include(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + uintN i, n; + jspl_t* jspl = (jspl_t*)JS_GetContextPrivate(cx); + + for (i = 0, n = 0; i < argc; i++) { + ucs2char_t* ucs2 = NULL; + ucs2char_t filename[MAX_PATH+1]; + JSString *str = JS_ValueToString(cx, argv[i]); + if (!str) { + return JS_FALSE; + } + + ucs2 = JSString_to_ucs2(str); + + filepath_combinepath(filename, MAX_PATH, jspl->path_to_include, ucs2); + jspl_load_script(jspl, filename); + } + + return JS_TRUE; +} + static JSFunctionSpec g_global_functions[] = { - {"print", js_print, 0}, + {"print", js_print, 0}, + {"include", js_include, 0}, {0} }; @@ -311,6 +348,25 @@ return 0; } +static int jspl_init_script(jspl_t* jspl) +{ + static const char *script = + "Math.cmp = function(x, y)\n" + "{\n" + " return ((x)>(y))-((x)<(y));\n" + "};\n" + "\n"; + + static const char *_script = "function dummy() {}\n"; + + jsval retval; + int ret = JS_EvaluateScript(jspl->context, jspl->global, script, strlen(script), "easypmp.js", 1, &retval); + if (!ret) { + return -1; + } + return 0; +} + static int jspl_load_script(jspl_t* jspl, const ucs2char_t* filename) { #if 1 @@ -431,6 +487,7 @@ int playlist_jspl_read( playlists_t* pls, const ucs2char_t *filename, + const ucs2char_t *path_to_include, pmp_record_t* records, int num_records, playlist_callback_t callback, @@ -451,6 +508,8 @@ goto error_exit; } + /* Initialize other fields. */ + jspl->path_to_include = path_to_include; jspl->callback = callback; jspl->instance = instance; @@ -505,7 +564,7 @@ goto error_exit; } - if (JS_IsArrayObject(jspl->context, jsobj)) { + if (object_is_array(jspl->context, jsobj)) { /* Single playlist when the returned value is JavaScript array. */ ret = generate_playlist(jspl, pls, jsobj, name); if (ret != 0) { @@ -532,7 +591,7 @@ if (JS_LookupUCProperty(jspl->context, jsobj, JS_GetStringChars(jsstr_name), JS_GetStringLength(jsstr_name), &jsval_obj)) { if (JSVAL_IS_OBJECT(jsval_obj) && !JSVAL_IS_PRIMITIVE(jsval_obj)) { JSObject* jsobj = JSVAL_TO_OBJECT(jsval_obj); - if (jsobj && JS_IsArrayObject(jspl->context, jsobj)) { + if (jsobj && object_is_array(jspl->context, jsobj)) { ucs2char_t* thisname = JSString_to_ucs2(jsstr_name); ret = generate_playlist(jspl, pls, jsobj, thisname); if (ret != 0) { Modified: trunk/lib/playlist/playlist.c =================================================================== --- trunk/lib/playlist/playlist.c 2006-04-04 06:49:42 UTC (rev 7) +++ trunk/lib/playlist/playlist.c 2006-04-05 13:57:51 UTC (rev 8) @@ -44,6 +44,7 @@ int playlist_jspl_read( playlists_t* pls, const ucs2char_t *filename, + const ucs2char_t *path_to_include, pmp_record_t* records, int num_records, playlist_callback_t callback, @@ -67,6 +68,7 @@ int playlist_read( playlists_t* pls, const ucs2char_t* filename, + const ucs2char_t* path_to_include, pmp_record_t* records, int num_records, playlist_callback_t callback, @@ -80,7 +82,7 @@ } else if (filepath_hasext(filename, ucs2cs_pls)) { return playlist_pls_read(pls, filename); } else if (filepath_hasext(filename, ucs2cs_jspl)) { - return playlist_jspl_read(pls, filename, records, num_records, callback, instance); + return playlist_jspl_read(pls, filename, path_to_include, records, num_records, callback, instance); } else { return -1; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |