summaryrefslogtreecommitdiff
path: root/apps/plugins/lib
diff options
context:
space:
mode:
authorRobert Kukla <roolku@rockbox.org>2007-10-09 20:42:20 +0000
committerRobert Kukla <roolku@rockbox.org>2007-10-09 20:42:20 +0000
commitfd3fe45bc14a0a540f2525102551c92a64a73b76 (patch)
tree1ef8103bbfa5b33f684a94bddc5ecb4685ec5e88 /apps/plugins/lib
parentce135909b9393d9824b3f69a70659400480cc069 (diff)
downloadrockbox-fd3fe45bc14a0a540f2525102551c92a64a73b76.tar.gz
rockbox-fd3fe45bc14a0a540f2525102551c92a64a73b76.zip
FS#7487 - mpegplayer - video start time seek with resume
by John S. Gwynne & Brian J. Morey This should stop the patch from breaking again and give them opportunity to improve it further. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15052 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/lib')
-rw-r--r--apps/plugins/lib/configfile.c75
-rw-r--r--apps/plugins/lib/configfile.h32
2 files changed, 105 insertions, 2 deletions
diff --git a/apps/plugins/lib/configfile.c b/apps/plugins/lib/configfile.c
index 0fbba81580..476f776878 100644
--- a/apps/plugins/lib/configfile.c
+++ b/apps/plugins/lib/configfile.c
@@ -55,12 +55,14 @@ int configfile_save(const char *filename, struct configdata *cfg,
55 if(fd < 0) 55 if(fd < 0)
56 return fd*10 - 1; 56 return fd*10 - 1;
57 57
58 cfg_rb->fdprintf(fd, "file version: %d\n", version); 58 /* pre-allocate 10 bytes for INT */
59 cfg_rb->fdprintf(fd, "file version: %10d\n", version);
59 60
60 for(i = 0;i < num_items;i++) { 61 for(i = 0;i < num_items;i++) {
61 switch(cfg[i].type) { 62 switch(cfg[i].type) {
62 case TYPE_INT: 63 case TYPE_INT:
63 cfg_rb->fdprintf(fd, "%s: %d\n", 64 /* pre-allocate 10 bytes for INT */
65 cfg_rb->fdprintf(fd, "%s: %10d\n",
64 cfg[i].name, 66 cfg[i].name,
65 *cfg[i].val); 67 *cfg[i].val);
66 break; 68 break;
@@ -141,3 +143,72 @@ int configfile_load(const char *filename, struct configdata *cfg,
141 cfg_rb->close(fd); 143 cfg_rb->close(fd);
142 return 0; 144 return 0;
143} 145}
146
147int configfile_get_value(const char* filename, const char* name)
148{
149 int fd;
150 char *pname;
151 char *pval;
152 char buf[MAX_PATH];
153
154 get_cfg_filename(buf, MAX_PATH, filename);
155 fd = cfg_rb->open(buf, O_RDONLY);
156 if(fd < 0)
157 return -1;
158
159 while(cfg_rb->read_line(fd, buf, MAX_PATH) > 0)
160 {
161 cfg_rb->settings_parseline(buf, &pname, &pval);
162 if(!cfg_rb->strcmp(name, pname))
163 {
164 cfg_rb->close(fd);
165 return cfg_rb->atoi(pval);
166 }
167 }
168
169 cfg_rb->close(fd);
170 return -1;
171}
172
173int configfile_update_entry(const char* filename, const char* name, int val)
174{
175 int fd;
176 char *pname;
177 char *pval;
178 char path[MAX_PATH];
179 char buf[256];
180 int found = 0;
181 int line_len = 0;
182 int pos = 0;
183
184 /* open the current config file */
185 get_cfg_filename(path, MAX_PATH, filename);
186 fd = cfg_rb->open(path, O_RDWR);
187 if(fd < 0)
188 return -1;
189
190 /* read in the current stored settings */
191 while((line_len = cfg_rb->read_line(fd, buf, 256)) > 0)
192 {
193 cfg_rb->settings_parseline(buf, &pname, &pval);
194
195 if(!cfg_rb->strcmp(name, pname))
196 {
197 found = 1;
198 cfg_rb->lseek(fd, pos, SEEK_SET);
199 /* pre-allocate 10 bytes for INT */
200 cfg_rb->fdprintf(fd, "%s: %10d\n", pname, val);
201 break;
202 }
203 pos += line_len;
204 }
205
206 /* if (name/val) is a new entry just append to file */
207 if (found == 0)
208 /* pre-allocate 10 bytes for INT */
209 cfg_rb->fdprintf(fd, "%s: %10d\n", name, val);
210
211 cfg_rb->close(fd);
212
213 return found;
214}
diff --git a/apps/plugins/lib/configfile.h b/apps/plugins/lib/configfile.h
index fcce7de275..7aa69f3ecf 100644
--- a/apps/plugins/lib/configfile.h
+++ b/apps/plugins/lib/configfile.h
@@ -38,9 +38,41 @@ struct configdata
38}; 38};
39 39
40void configfile_init(struct plugin_api* newrb); 40void configfile_init(struct plugin_api* newrb);
41
42/* configfile_save - Given configdata entries this function will
43 create a config file with these entries, destroying any
44 previous config file of the same name */
41int configfile_save(const char *filename, struct configdata *cfg, 45int configfile_save(const char *filename, struct configdata *cfg,
42 int num_items, int version); 46 int num_items, int version);
47
43int configfile_load(const char *filename, struct configdata *cfg, 48int configfile_load(const char *filename, struct configdata *cfg,
44 int num_items, int min_version); 49 int num_items, int min_version);
45 50
51/* configfile_get_value - Given a key name, this function will
52 return the integer value for that key.
53
54 Input:
55 filename = config file filename
56 name = (name/value) pair name entry
57 Return:
58 value if (name/value) pair is found
59 -1 if entry is not found
60*/
61int configfile_get_value(const char* filename, const char* name);
62
63/* configure_update_entry - Given a key name and integer value
64 this function will update the entry if found, or add it if
65 not found.
66
67 Input:
68 filename = config file filename
69 name = (name/value) pair name entry
70 val = new value for (name/value) pair
71 Return:
72 1 if the (name/value) pair was found and updated with the new value
73 0 if the (name/value) pair was added as a new entry
74 -1 if error
75*/
76int configfile_update_entry(const char* filename, const char* name, int val);
77
46#endif 78#endif