Mercurial > geeqie.yaz
changeset 217:5bdab7ed4bcd
use quoted_value everywhere
simplify parsing of multiple quoted values on one line
author | nadvornik |
---|---|
date | Mon, 31 Mar 2008 21:09:36 +0000 |
parents | a57b153e7fa4 |
children | f4a0555794a9 |
files | src/collect-io.c src/filelist.c src/rcfile.c src/rcfile.h |
diffstat | 4 files changed, 45 insertions(+), 91 deletions(-) [+] |
line wrap: on
line diff
--- a/src/collect-io.c Mon Mar 31 07:29:03 2008 +0000 +++ b/src/collect-io.c Mon Mar 31 21:09:36 2008 +0000 @@ -112,7 +112,7 @@ } if (s_buf[0]=='\n') continue; - buf = quoted_value(s_buf); + buf = quoted_value(s_buf, NULL); if (buf) { gint valid;
--- a/src/filelist.c Mon Mar 31 07:29:03 2008 +0000 +++ b/src/filelist.c Mon Mar 31 21:09:36 2008 +0000 @@ -371,10 +371,14 @@ { FilterEntry *fe = work->data; work = work->next; + + gchar *extensions = escquote_value(fe->extensions); + gchar *description = escquote_value(fe->description); - fprintf(f, "filter_ext: \"%s%s\" \"%s\" \"%s\"\n", (fe->enabled) ? "" : "#", - fe->key, fe->extensions, - (fe->description) ? fe->description : ""); + fprintf(f, "filter_ext: \"%s%s\" %s %s\n", (fe->enabled) ? "" : "#", + fe->key, extensions, description); + g_free(extensions); + g_free(description); } } @@ -388,40 +392,11 @@ if (!text || text[0] != '"') return; - key = quoted_value(text); + key = quoted_value(text, &p); if (!key) return; - p = text; - p++; - while (*p != '"' && *p != '\0') p++; - if (*p != '"') - { - g_free(key); - return; - } - p++; - while (*p != '"' && *p != '\0') p++; - if (*p != '"') - { - g_free(key); - return; - } - - ext = quoted_value(p); - - p++; - while (*p != '"' && *p != '\0') p++; - if (*p == '"') p++; - while (*p != '"' && *p != '\0') p++; - - if (*p == '"') - { - desc = quoted_value(p); - } - else - { - desc = NULL; - } + ext = quoted_value(p, &p); + desc = quoted_value(p, &p); if (key && key[0] == '#') { @@ -502,7 +477,7 @@ sidecar_ext_list = NULL; if (quoted) - value = quoted_value(text); + value = quoted_value(text, NULL); else value = g_strdup(text);
--- a/src/rcfile.c Mon Mar 31 07:29:03 2008 +0000 +++ b/src/rcfile.c Mon Mar 31 21:09:36 2008 +0000 @@ -23,14 +23,24 @@ * line write/parse routines (private) *----------------------------------------------------------------------------- */ + +/* + returns text without quotes or NULL for empty or broken string + any text up to first '"' is skipped + tail is set to point at the char after the second '"' + or at the ending \0 + +*/ -gchar *quoted_value(const gchar *text) +gchar *quoted_value(const gchar *text, const gchar **tail) { const gchar *ptr; gint c = 0; gint l = strlen(text); gchar *retval = NULL; + if (tail) *tail = text; + if (l == 0) return retval; while (c < l && text[c] !='"') c++; @@ -58,6 +68,7 @@ } } } + if (tail) *tail = text + e + 1; } else /* for compatibility with older formats (<0.3.7) @@ -69,6 +80,7 @@ { retval = g_strndup(text, c); } + if (tail) *tail = text + c; } return retval; @@ -79,7 +91,7 @@ gchar *e; gchar *retval; - if (!text) return g_strdup(""); + if (!text) return g_strdup("\"\""); e = g_strescape(text, ""); if (e) @@ -88,20 +100,15 @@ g_free(e); return retval; } - return g_strdup(""); + return g_strdup("\"\""); } static void write_char_option(FILE *f, gchar *label, gchar *text) { gchar *escval = escquote_value(text); - if (escval) - { - fprintf(f,"%s: %s\n", label, escval); - g_free(escval); - } - else - fprintf(f,"%s: \n", label); + fprintf(f,"%s: %s\n", label, escval); + g_free(escval); } static gchar *read_char_option(FILE *f, gchar *option, gchar *label, gchar *value, gchar *text) @@ -109,7 +116,7 @@ if (strcasecmp(option, label) == 0) { g_free(text); - text = quoted_value(value); + text = quoted_value(value, NULL); } return text; } @@ -120,7 +127,7 @@ { gchar *colorstring = gdk_color_to_string (color); - fprintf(f,"%s: \"%s\"\n", label, colorstring); + write_char_option(f, label, colorstring); g_free(colorstring); } else @@ -131,7 +138,9 @@ { if (strcasecmp(option, label) == 0) { - gdk_color_parse(quoted_value(value), color); + gchar *colorstr = quoted_value(value, NULL); + if (colorstr) gdk_color_parse(colorstr, color); + g_free(colorstr); } return color; } @@ -398,11 +407,11 @@ for (i = 0; i < GQVIEW_EDITOR_SLOTS; i++) { - fprintf(f,"external_%d: \"", i+1); - if (editor_name[i]) fprintf(f, "%s", editor_name[i]); - fprintf(f, "\" \""); - if (editor_command[i]) fprintf(f, "%s", editor_command[i]); - fprintf(f, "\"\n"); + char *qname = escquote_value(editor_name[i]); + char *qcommand = escquote_value(editor_command[i]); + fprintf(f,"external_%d: %s %s\n", i+1, qname, qcommand); + g_free(qname); + g_free(qcommand); } fprintf(f,"\n##### Collection Options #####\n\n"); @@ -693,44 +702,13 @@ i = strtol(option + 9, NULL, 0); if (i > 0 && i <= GQVIEW_EDITOR_SLOTS) { - gchar *ptr1, *ptr2; + const gchar *ptr; i--; - c = 0; - l = strlen(value_all); - ptr1 = value_all; - g_free(editor_name[i]); - editor_name[i] = NULL; g_free(editor_command[i]); - editor_command[i] = NULL; - - while (c<l && value_all[c] !='"') c++; - if (ptr1[c] == '"') - { - c++; - ptr2 = ptr1 + c; - while (c<l && value_all[c] !='"') c++; - if (ptr1[c] == '"') - { - ptr1[c] = '\0'; - if (ptr1 + c - 1 != ptr2) - editor_name[i] = g_strdup(ptr2); - c++; - while (c<l && value_all[c] !='"') c++; - if (ptr1[c] == '"') - { - c++; - ptr2 = ptr1 + c; - while (value_all[c] != '\0') c++; - while (c > 0 && value_all[c] != '"') c--; - if (ptr1[c] == '"' && ptr1 + c > ptr2) - { - ptr1[c] = '\0'; - editor_command[i] = g_strdup(ptr2); - } - } - } - } + + editor_name[i] = quoted_value(value_all, &ptr); + editor_command[i] = quoted_value(ptr, NULL); } }
--- a/src/rcfile.h Mon Mar 31 07:29:03 2008 +0000 +++ b/src/rcfile.h Mon Mar 31 21:09:36 2008 +0000 @@ -14,7 +14,8 @@ #define RCFILE_H -gchar *quoted_value(const gchar *text); +gchar *quoted_value(const gchar *text, const gchar **tail); +gchar *escquote_value(const gchar *text); void save_options(void); void load_options(void);