-/************/
-
-typedef struct {
- VikLayerParamData data;
- guint8 type;
- gpointer freeme; // because data.s is const and the compiler complains
-} VikLayerTypedParamData;
-
-void layer_typed_param_data_free(gpointer p)
-{
- VikLayerTypedParamData *val = (VikLayerTypedParamData *)p;
- switch ( val->type ) {
- case VIK_LAYER_PARAM_STRING:
- if ( val->freeme )
- g_free ( val->freeme );
- break;
- /* TODO: APPLICABLE TO US? NOTE: string layer works auniquely: data.sl should NOT be free'd when
- * the internals call get_param -- i.e. it should be managed w/in the layer.
- * The value passed by the internals into set_param should also be managed
- * by the layer -- i.e. free'd by the layer.
- */
- case VIK_LAYER_PARAM_STRING_LIST:
- g_critical ( "Param strings not implemented in preferences"); //fake it
- break;
- }
- g_free ( val );
-}
-
-VikLayerTypedParamData *layer_typed_param_data_copy_from_data(guint8 type, VikLayerParamData val) {
- VikLayerTypedParamData *newval = g_new(VikLayerTypedParamData,1);
- newval->data = val;
- newval->type = type;
- switch ( newval->type ) {
- case VIK_LAYER_PARAM_STRING: {
- gchar *s = g_strdup(newval->data.s);
- newval->data.s = s;
- newval->freeme = s;
- break;
- }
- /* TODO: APPLICABLE TO US? NOTE: string layer works auniquely: data.sl should NOT be free'd when
- * the internals call get_param -- i.e. it should be managed w/in the layer.
- * The value passed by the internals into set_param should also be managed
- * by the layer -- i.e. free'd by the layer.
- */
- case VIK_LAYER_PARAM_STRING_LIST:
- g_critical ( "Param strings not implemented in preferences"); //fake it
- break;
- }
- return newval;
-}
-
-/* TODO: share this code with file.c */
-VikLayerTypedParamData *layer_data_typed_param_copy_from_string ( guint8 type, const gchar *str )
-{
- g_assert ( type != VIK_LAYER_PARAM_STRING_LIST );
- VikLayerTypedParamData *rv = g_new(VikLayerTypedParamData,1);
- rv->type = type;
- switch ( type )
- {
- case VIK_LAYER_PARAM_DOUBLE: rv->data.d = strtod(str, NULL); break;
- case VIK_LAYER_PARAM_UINT: rv->data.u = strtoul(str, NULL, 10); break;
- case VIK_LAYER_PARAM_INT: rv->data.i = strtol(str, NULL, 10); break;
- case VIK_LAYER_PARAM_BOOLEAN: rv->data.b = TEST_BOOLEAN(str); break;
- case VIK_LAYER_PARAM_COLOR: memset(&(rv->data.c), 0, sizeof(rv->data.c)); /* default: black */
- gdk_color_parse ( str, &(rv->data.c) ); break;
- /* STRING or STRING_LIST -- if STRING_LIST, just set param to add a STRING */
- default: {
- gchar *s = g_strdup(str);
- rv->data.s = s;
- rv->freeme = s;
- }
- }
- return rv;
-}
-
-/************/
-
-/* 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;
-}
-