From 5d22e3cbdd251819a4d2d07b9a12994d5aef778d Mon Sep 17 00:00:00 2001 From: Frank Gevaerts Date: Fri, 29 Aug 2008 21:08:38 +0000 Subject: Add wpseditor, the Google Summer of Code 2008 project of Rostislav Chekan. Closes FS#9327 git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18362 a1c6a512-1295-4272-9138-f99709370657 --- utils/wpseditor/libwps/src/proxy.c | 132 +++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 utils/wpseditor/libwps/src/proxy.c (limited to 'utils/wpseditor/libwps/src/proxy.c') diff --git a/utils/wpseditor/libwps/src/proxy.c b/utils/wpseditor/libwps/src/proxy.c new file mode 100644 index 0000000000..3a3b8ce4d9 --- /dev/null +++ b/utils/wpseditor/libwps/src/proxy.c @@ -0,0 +1,132 @@ +#include +#include +#include "dummies.h" +#include "proxy.h" +#include "api.h" +#include "gwps.h" +#include "gwps-common.h" +#include + +struct screen screens[NB_SCREENS]; +struct wps_data wpsdata; +struct gui_wps gwps; +struct mp3entry id3; +struct mp3entry nid3; + +extern void test_api(struct proxy_api *api); + +bool debug_wps = true; +int wps_verbose_level = 0; +int errno_; +pfdebugf dbgf = 0; + +static char pluginbuf[PLUGIN_BUFFER_SIZE]; + +const char* get_model_name(){ +#ifdef TARGET_MODEL + return TARGET_MODEL; +#else + return "unknown"; +#endif +} + +int read_line(int fd, char* buffer, int buffer_size) +{ + int count = 0; + int num_read = 0; + + errno_ = 0; + + while (count < buffer_size) + { + unsigned char c; + + if (1 != read(fd, &c, 1)) + break; + + num_read++; + + if ( c == '\n' ) + break; + + if ( c == '\r' ) + continue; + + buffer[count++] = c; + } + + buffer[MIN(count, buffer_size - 1)] = 0; + + return errno_ ? -1 : num_read; +} + +void* plugin_get_buffer(size_t *buffer_size) +{ + *buffer_size = PLUGIN_BUFFER_SIZE; + return pluginbuf; +} + +int checkwps(const char *filename, int verbose){ + int res; + int fd; + + struct wps_data wps; + wps_verbose_level = verbose; + + fd = open(filename, O_RDONLY); + if (fd < 0) { + DEBUGF1("Failed to open %s\n",filename); + return 2; + } + close(fd); + + res = wps_data_load(&wps, &screens[0], filename, true); + + if (!res) { + DEBUGF1("WPS parsing failure\n"); + return 3; + } + + DEBUGF1("WPS parsed OK\n"); + return 0; +} + +int wps_init(const char* filename,struct proxy_api *api, bool isfile){ + int res; + if (!api) + return 4; + dummies_init(); + test_api(api); + set_api(api); + wps_data_init(&wpsdata); + wps_verbose_level = api->verbose; + res = wps_data_load(&wpsdata, &screens[0], filename, isfile); + if (!res) + { + DEBUGF1("ERR: WPS parsing failure\n"); + return 3; + } + DEBUGF1("WPS parsed OK\n"); + DEBUGF1("\n-------------------------------------------------\n"); + wps_state.paused = true; + gwps.data = &wpsdata; + gwps.display = &screens[0]; + gwps.state = &wps_state; + gwps.state->id3 = &id3; + gwps.state->nid3 = &nid3; + gui_wps[0] = gwps; + return res; +} + +int wps_display(){ + DEBUGF3("wps_display(): begin\n"); + int res = gui_wps_display(); + DEBUGF3("\nWPS %sdisplayed\n", (res ? "" : "not ")); + return res; +} +int wps_refresh(){ + DEBUGF3("----------------------------------\n"); + int res = gui_wps_refresh(&gwps, 0, WPS_REFRESH_ALL); + DEBUGF3("\nWPS %srefreshed\n", (res ? "" : "not ")); + return res; +} -- cgit v1.2.3