From 9106934d92f6af13bfe1df8cd6886e115aafe22b Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Tue, 22 Jan 2013 21:25:46 +0000 Subject: [PATCH] [QA] Move preferences_load_parse_param() to be a general function --- src/preferences.c | 23 +---------------------- src/util.c | 22 ++++++++++++++++++++++ src/util.h | 2 ++ 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/preferences.c b/src/preferences.c index 58e7a7e9..bcae6243 100644 --- a/src/preferences.c +++ b/src/preferences.c @@ -75,27 +75,6 @@ static gint16 preferences_groups_key_to_index( const gchar *key ) /*****************************/ -/* MAKES A COPY OF THE KEY!!! */ -static gboolean preferences_load_parse_param(gchar *buf, gchar **key, gchar **val ) -{ - gchar *eq_pos; - gint len; - - // comments, special characters in viking file format - if ( buf == NULL || buf[0] == '\0' || buf[0] == '~' || buf[0] == '=' || buf[0] == '#' ) - return FALSE; - eq_pos = strchr ( buf, '=' ); - if ( ! eq_pos ) - return FALSE; - *key = g_strndup ( buf, eq_pos - buf ); - *val = eq_pos + 1; - len = strlen(*val); - if ( len > 0 ) - if ( (*val)[len - 1] == '\n' ) - (*val) [ len - 1 ] = '\0'; /* cut off newline */ - return TRUE; -} - static gboolean preferences_load_from_file() { gchar *fn = g_build_filename(a_get_viking_dir(), VIKING_PREFS_FILE, NULL); @@ -109,7 +88,7 @@ static gboolean preferences_load_from_file() while ( ! feof (f) ) { if (fgets(buf,sizeof(buf),f) == NULL) break; - if ( preferences_load_parse_param(buf, &key, &val ) ) { + if ( split_string_from_file_on_equals(buf, &key, &val ) ) { // if it's not in there, ignore it oldval = g_hash_table_lookup ( values, key ); if ( ! oldval ) { diff --git a/src/util.c b/src/util.c index fe23e846..2e3e28f7 100644 --- a/src/util.c +++ b/src/util.c @@ -125,3 +125,25 @@ GList * str_array_to_glist(gchar* data[]) gl = g_list_prepend(gl, *p); return g_list_reverse(gl); } + +/* MAKES A COPY OF THE KEY!!! */ +gboolean split_string_from_file_on_equals ( gchar *buf, gchar **key, gchar **val ) +{ + gchar *eq_pos; + gint len; + + // comments, special characters in viking file format + if ( buf == NULL || buf[0] == '\0' || buf[0] == '~' || buf[0] == '=' || buf[0] == '#' ) + return FALSE; + eq_pos = strchr ( buf, '=' ); + if ( ! eq_pos ) + return FALSE; + *key = g_strndup ( buf, eq_pos - buf ); + *val = eq_pos + 1; + len = strlen(*val); + if ( len > 0 ) + if ( (*val)[len - 1] == '\n' ) + (*val) [ len - 1 ] = '\0'; /* cut off newline */ + return TRUE; +} + diff --git a/src/util.h b/src/util.h index 12a07fc1..b492b0d9 100644 --- a/src/util.h +++ b/src/util.h @@ -36,6 +36,8 @@ gchar *uri_escape(gchar *str); GList * str_array_to_glist(gchar* data[]); +gboolean split_string_from_file_on_equals ( gchar *buf, gchar **key, gchar **val ); + G_END_DECLS #endif -- 2.39.5