From e071cdeeb46b0f667c4847525f78a988c199297d Mon Sep 17 00:00:00 2001 From: JP Rosevear Date: Fri, 27 Oct 2000 12:30:27 +0000 Subject: Get archive field while parsing (map_write_foreach): Write out archive 2000-10-27 JP Rosevear * e-pilot-map.c (map_sax_start_element): Get archive field while parsing (map_write_foreach): Write out archive field (e_pilot_map_pid_is_archived): implement (e_pilot_map_uid_is_archived): ditto (e_pilot_map_insert): Insert new node structures (e_pilot_map_lookup_pid): Take into account the list is now a list of structures (e_pilot_map_lookup_uid): ditto svn path=/trunk/; revision=6224 --- e-util/e-pilot-map.c | 92 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 26 deletions(-) (limited to 'e-util/e-pilot-map.c') diff --git a/e-util/e-pilot-map.c b/e-util/e-pilot-map.c index 3a1b660c60..583e0ad2ec 100644 --- a/e-util/e-pilot-map.c +++ b/e-util/e-pilot-map.c @@ -26,6 +26,19 @@ #include #include +typedef struct +{ + char *uid; + gboolean archived; +} EPilotMapPidNode; + +typedef struct +{ + guint32 pid; + gboolean archived; +} EPilotMapUidNode; + + static void map_set_node_timet (xmlNodePtr node, const char *name, time_t t) { @@ -54,30 +67,28 @@ map_sax_start_element (void *data, const xmlChar *name, } if (!strcmp (name, "map")) { - char *uid = NULL; - guint32 *pid = g_new (guint32, 1); - - *pid = 0; + const char *uid = NULL; + guint32 pid = 0; + gboolean archived = FALSE; while (attrs && *attrs != NULL) { const xmlChar **val = attrs; val++; if (!strcmp (*attrs, "uid")) - uid = g_strdup (*val); + uid = *val; if (!strcmp (*attrs, "pilot_id")) - *pid = strtoul (*val, NULL, 0); + pid = strtoul (*val, NULL, 0); + + if (!strcmp (*attrs, "archived")) + archived = strtoul (*val, NULL, 0)== 1 ? TRUE : FALSE; attrs = ++val; } - if (uid && *pid != 0) { - g_hash_table_insert (map->pid_map, pid, uid); - g_hash_table_insert (map->uid_map, uid, pid); - } else { - g_free (pid); - } + if (uid && pid != 0) + e_pilot_map_insert (map, pid, uid, archived); } } @@ -87,26 +98,47 @@ map_write_foreach (gpointer key, gpointer value, gpointer data) xmlNodePtr root = data; xmlNodePtr mnode; unsigned long *pid = key; - const char *uid = value; + EPilotMapPidNode *pnode = value; char *pidstr; - + mnode = xmlNewChild (root, NULL, "map", NULL); - xmlSetProp (mnode, "uid", uid); + pidstr = g_strdup_printf ("%lu", *pid); xmlSetProp (mnode, "pilot_id", pidstr); g_free (pidstr); + + xmlSetProp (mnode, "uid", pnode->uid); + + if (pnode->archived) + xmlSetProp (mnode, "archived", "1"); + else + xmlSetProp (mnode, "archived", "0"); } gboolean e_pilot_map_pid_is_archived (EPilotMap *map, guint32 pid) { - return FALSE; + EPilotMapPidNode *pnode; + + pnode = g_hash_table_lookup (map->pid_map, &pid); + + if (pnode == NULL) + return FALSE; + + return pnode->archived; } gboolean e_pilot_map_uid_is_archived (EPilotMap *map, const char *uid) { - return FALSE; + EPilotMapUidNode *unode; + + unode = g_hash_table_lookup (map->uid_map, uid); + + if (unode == NULL) + return FALSE; + + return unode->archived; } void @@ -114,35 +146,43 @@ e_pilot_map_insert (EPilotMap *map, guint32 pid, const char *uid, gboolean archi { char *new_uid; guint32 *new_pid = g_new (guint32, 1); + EPilotMapPidNode *pnode = g_new0 (EPilotMapPidNode, 1); + EPilotMapUidNode *unode = g_new0 (EPilotMapUidNode, 1); *new_pid = pid; new_uid = g_strdup (uid); - g_hash_table_insert (map->pid_map, new_pid, new_uid); - g_hash_table_insert (map->uid_map, new_uid, new_pid); + pnode->uid = new_uid; + pnode->archived = archived; + + unode->pid = pid; + unode->archived = archived; + + g_hash_table_insert (map->pid_map, new_pid, pnode); + g_hash_table_insert (map->uid_map, new_uid, unode); } guint32 e_pilot_map_lookup_pid (EPilotMap *map, const char *uid) { - guint32 *pid; + EPilotMapUidNode *unode; - pid = g_hash_table_lookup (map->uid_map, uid); + unode = g_hash_table_lookup (map->uid_map, uid); - if (pid == NULL) + if (unode == NULL) return 0; - return *pid; + return unode->pid; } const char * e_pilot_map_lookup_uid (EPilotMap *map, guint32 pid) { - const char *uid; + EPilotMapPidNode *pnode; - uid = g_hash_table_lookup (map->pid_map, &pid); + pnode = g_hash_table_lookup (map->pid_map, &pid); - return uid; + return pnode->uid; } int -- cgit v1.2.3