Add wpseditor, the Google Summer of Code 2008 project of Rostislav Chekan. Closes...
[kugel-rb.git] / utils / wpseditor / libwps / src / proxy.c
blob3a3b8ce4d94df3825ed2aac5f477192c4ca3f842
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "dummies.h"
4 #include "proxy.h"
5 #include "api.h"
6 #include "gwps.h"
7 #include "gwps-common.h"
8 #include <string.h>
10 struct screen screens[NB_SCREENS];
11 struct wps_data wpsdata;
12 struct gui_wps gwps;
13 struct mp3entry id3;
14 struct mp3entry nid3;
16 extern void test_api(struct proxy_api *api);
18 bool debug_wps = true;
19 int wps_verbose_level = 0;
20 int errno_;
21 pfdebugf dbgf = 0;
23 static char pluginbuf[PLUGIN_BUFFER_SIZE];
25 const char* get_model_name(){
26 #ifdef TARGET_MODEL
27 return TARGET_MODEL;
28 #else
29 return "unknown";
30 #endif
33 int read_line(int fd, char* buffer, int buffer_size)
35 int count = 0;
36 int num_read = 0;
38 errno_ = 0;
40 while (count < buffer_size)
42 unsigned char c;
44 if (1 != read(fd, &c, 1))
45 break;
47 num_read++;
49 if ( c == '\n' )
50 break;
52 if ( c == '\r' )
53 continue;
55 buffer[count++] = c;
58 buffer[MIN(count, buffer_size - 1)] = 0;
60 return errno_ ? -1 : num_read;
63 void* plugin_get_buffer(size_t *buffer_size)
65 *buffer_size = PLUGIN_BUFFER_SIZE;
66 return pluginbuf;
69 int checkwps(const char *filename, int verbose){
70 int res;
71 int fd;
73 struct wps_data wps;
74 wps_verbose_level = verbose;
76 fd = open(filename, O_RDONLY);
77 if (fd < 0) {
78 DEBUGF1("Failed to open %s\n",filename);
79 return 2;
81 close(fd);
83 res = wps_data_load(&wps, &screens[0], filename, true);
85 if (!res) {
86 DEBUGF1("WPS parsing failure\n");
87 return 3;
90 DEBUGF1("WPS parsed OK\n");
91 return 0;
94 int wps_init(const char* filename,struct proxy_api *api, bool isfile){
95 int res;
96 if (!api)
97 return 4;
98 dummies_init();
99 test_api(api);
100 set_api(api);
101 wps_data_init(&wpsdata);
102 wps_verbose_level = api->verbose;
103 res = wps_data_load(&wpsdata, &screens[0], filename, isfile);
104 if (!res)
106 DEBUGF1("ERR: WPS parsing failure\n");
107 return 3;
109 DEBUGF1("WPS parsed OK\n");
110 DEBUGF1("\n-------------------------------------------------\n");
111 wps_state.paused = true;
112 gwps.data = &wpsdata;
113 gwps.display = &screens[0];
114 gwps.state = &wps_state;
115 gwps.state->id3 = &id3;
116 gwps.state->nid3 = &nid3;
117 gui_wps[0] = gwps;
118 return res;
121 int wps_display(){
122 DEBUGF3("wps_display(): begin\n");
123 int res = gui_wps_display();
124 DEBUGF3("\nWPS %sdisplayed\n", (res ? "" : "not "));
125 return res;
127 int wps_refresh(){
128 DEBUGF3("-----------------<wps_refresh(): begin>-----------------\n");
129 int res = gui_wps_refresh(&gwps, 0, WPS_REFRESH_ALL);
130 DEBUGF3("\nWPS %srefreshed\n", (res ? "" : "not "));
131 return res;