]> git.street.me.uk Git - andy/viking.git/commitdiff
[QA] Move preferences_load_parse_param() to be a general function
authorRob Norris <rw_norris@hotmail.com>
Tue, 22 Jan 2013 21:25:46 +0000 (21:25 +0000)
committerRob Norris <rw_norris@hotmail.com>
Sat, 16 Feb 2013 19:24:11 +0000 (19:24 +0000)
src/preferences.c
src/util.c
src/util.h

index 58e7a7e9d085efbd34093cfa25d395affe3a5492..bcae6243bb0f7ee9bb30773acabc485e6451e41e 100644 (file)
@@ -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 ) {
index fe23e8461c860f3caa12683487cc5017b9e9d90f..2e3e28f751b2cc10162a75450fcb0c5f3b653375 100644 (file)
@@ -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;
+}
+
index 12a07fc1d80c444c34ad35107fbe4be41ec0ccb0..b492b0d90b53f5befeb0fd97c93457c93e3c9bf5 100644 (file)
@@ -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