[gq-commit] gq/src state.c,1.3,1.4 state.h,1.2,1.3
Status: Beta
Brought to you by:
sur5r
From: <sta...@us...> - 2003-10-11 22:34:22
|
Update of /cvsroot/gqclient/gq/src In directory sc8-pr-cvs1:/tmp/cvs-serv22205 Modified Files: state.c state.h Log Message: * Support for storage of lists of strings Index: state.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/state.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** state.c 11 Oct 2003 20:26:07 -0000 1.3 --- state.c 11 Oct 2003 22:34:18 -0000 1.4 *************** *** 26,29 **** --- 26,31 ---- */ + /* $Id$ */ + #include "config.h" #include <stdlib.h> *************** *** 302,305 **** --- 304,360 ---- g_hash_table_insert(e->values, g_strdup(value_name), val); } + } + + const GList *state_value_get_list(const char *state_name, + const char *value_name) + { + struct state_value *val; + struct state_entity *e = lookup_entity(state_name); + assert(e); + assert(e->values); + + val = g_hash_table_lookup(e->values, value_name); + if (val) { + if (val->type == SV_list) { + return val->val.list_val; + } + } + return NULL; + } + + void state_value_set_list(const char *state_name, + const char *value_name, + const GList *n) + { + struct state_value *val; + struct state_entity *e = lookup_entity(state_name); + const GList *I; + + assert(e); + assert(e->values); + + val = g_hash_table_lookup(e->values, value_name); + if (val) { + if (val->type == SV_list) { + if (val->val.list_val && val->free_list_element) { + g_list_foreach(val->val.list_val, + (GFunc) val->free_list_element, NULL); + } + if (val->val.list_val) { + g_list_free(val->val.list_val); + } + val->val.list_val = NULL; + } + } else { + val = new_state_value(SV_list); + val->val.list_val = NULL; + g_hash_table_insert(e->values, g_strdup(value_name), val); + } + + for (I = n ; I ; I = g_list_next(I)) { + val->val.list_val = g_list_append(val->val.list_val, + g_strdup(I->data)); + } + val->free_list_element = (sv_free_list_func) g_free; } Index: state.h =================================================================== RCS file: /cvsroot/gqclient/gq/src/state.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** state.h 11 Oct 2003 20:26:07 -0000 1.2 --- state.h 11 Oct 2003 22:34:18 -0000 1.3 *************** *** 55,58 **** --- 55,68 ---- const char *c); + + const GList *state_value_get_list(const char *state_name, + const char *value_name); + + /* The list set her MUST be a list of strings - nothing else will work */ + void state_value_set_list(const char *state_name, + const char *value_name, + const GList *n); + + gboolean exists_entity(const char *entity_name) ; |