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.zip
rockbox-fd3fe45bc14a0a540f2525102551c92a64a73b76.tar.gz
rockbox-fd3fe45bc14a0a540f2525102551c92a64a73b76.tar.bz2
rockbox-fd3fe45bc14a0a540f2525102551c92a64a73b76.tar.xz
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 0fbba81..476f776 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,
if(fd < 0)
return fd*10 - 1;
- cfg_rb->fdprintf(fd, "file version: %d\n", version);
+ /* pre-allocate 10 bytes for INT */
+ cfg_rb->fdprintf(fd, "file version: %10d\n", version);
for(i = 0;i < num_items;i++) {
switch(cfg[i].type) {
case TYPE_INT:
- cfg_rb->fdprintf(fd, "%s: %d\n",
+ /* pre-allocate 10 bytes for INT */
+ cfg_rb->fdprintf(fd, "%s: %10d\n",
cfg[i].name,
*cfg[i].val);
break;
@@ -141,3 +143,72 @@ int configfile_load(const char *filename, struct configdata *cfg,
cfg_rb->close(fd);
return 0;
}
+
+int configfile_get_value(const char* filename, const char* name)
+{
+ int fd;
+ char *pname;
+ char *pval;
+ char buf[MAX_PATH];
+
+ get_cfg_filename(buf, MAX_PATH, filename);
+ fd = cfg_rb->open(buf, O_RDONLY);
+ if(fd < 0)
+ return -1;
+
+ while(cfg_rb->read_line(fd, buf, MAX_PATH) > 0)
+ {
+ cfg_rb->settings_parseline(buf, &pname, &pval);
+ if(!cfg_rb->strcmp(name, pname))
+ {
+ cfg_rb->close(fd);
+ return cfg_rb->atoi(pval);
+ }
+ }
+
+ cfg_rb->close(fd);
+ return -1;
+}
+
+int configfile_update_entry(const char* filename, const char* name, int val)
+{
+ int fd;
+ char *pname;
+ char *pval;
+ char path[MAX_PATH];
+ char buf[256];
+ int found = 0;
+ int line_len = 0;
+ int pos = 0;
+
+ /* open the current config file */
+ get_cfg_filename(path, MAX_PATH, filename);
+ fd = cfg_rb->open(path, O_RDWR);
+ if(fd < 0)
+ return -1;
+
+ /* read in the current stored settings */
+ while((line_len = cfg_rb->read_line(fd, buf, 256)) > 0)
+ {
+ cfg_rb->settings_parseline(buf, &pname, &pval);
+
+ if(!cfg_rb->strcmp(name, pname))
+ {
+ found = 1;
+ cfg_rb->lseek(fd, pos, SEEK_SET);
+ /* pre-allocate 10 bytes for INT */
+ cfg_rb->fdprintf(fd, "%s: %10d\n", pname, val);
+ break;
+ }
+ pos += line_len;
+ }
+
+ /* if (name/val) is a new entry just append to file */
+ if (found == 0)
+ /* pre-allocate 10 bytes for INT */
+ cfg_rb->fdprintf(fd, "%s: %10d\n", name, val);
+
+ cfg_rb->close(fd);
+
+ return found;
+}
diff --git a/apps/plugins/lib/configfile.h b/apps/plugins/lib/configfile.h
index fcce7de..7aa69f3 100644
--- a/apps/plugins/lib/configfile.h
+++ b/apps/plugins/lib/configfile.h
@@ -38,9 +38,41 @@ struct configdata
};
void configfile_init(struct plugin_api* newrb);
+
+/* configfile_save - Given configdata entries this function will
+ create a config file with these entries, destroying any
+ previous config file of the same name */
int configfile_save(const char *filename, struct configdata *cfg,
int num_items, int version);
+
int configfile_load(const char *filename, struct configdata *cfg,
int num_items, int min_version);
+/* configfile_get_value - Given a key name, this function will
+ return the integer value for that key.
+
+ Input:
+ filename = config file filename
+ name = (name/value) pair name entry
+ Return:
+ value if (name/value) pair is found
+ -1 if entry is not found
+*/
+int configfile_get_value(const char* filename, const char* name);
+
+/* configure_update_entry - Given a key name and integer value
+ this function will update the entry if found, or add it if
+ not found.
+
+ Input:
+ filename = config file filename
+ name = (name/value) pair name entry
+ val = new value for (name/value) pair
+ Return:
+ 1 if the (name/value) pair was found and updated with the new value
+ 0 if the (name/value) pair was added as a new entry
+ -1 if error
+*/
+int configfile_update_entry(const char* filename, const char* name, int val);
+
#endif