Yattm - unified GTK instant-messaging client logo
   [Generated for version 0.2-17 - Mon Jan 6 19:01:23 GMT+1 2003]

Home - Main Page - Data Structures - File List - Data Fields - Globals

value_pair.c

Go to the documentation of this file.
00001 /*
00002  * Yattm 
00003  *
00004  * Copyright (C) 1999, Torrey Searle <tsearle@uci.edu>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 #include "intl.h"
00022 #include <string.h>
00023 #include <stdlib.h>
00024 #include "value_pair.h"
00025 #include "util.h"
00026 
00027 char * value_pair_get_value( GList * pairs, char * key )
00028 {
00029     GList * node;
00030     for( node = pairs; node; node=node->next)
00031     {
00032         value_pair * vp = node->data;
00033         if(!strcasecmp(key, vp->key))
00034             return unescape_string(vp->value);
00035     }
00036     return NULL;
00037 }
00038 
00039 void value_pair_free( GList * pairs )
00040 {
00041     GList * node;
00042     for( node = pairs; node; node = node->next )
00043     {
00044         g_free(node->data);
00045     }
00046     g_list_free(pairs);
00047 }
00048 
00049 void value_pair_print_values( GList * pairs, FILE * file, int indent )
00050 {
00051     GList * node;
00052     int i;
00053     
00054     for( node = pairs; node; node = node->next )
00055     {
00056         value_pair * vp = node->data;
00057 
00058         for( i = 0; i < indent; i++ )
00059         {
00060             fprintf( file, "\t" );
00061         }
00062 
00063         fprintf(file, "%s=\"%s\"\n", vp->key, vp->value);
00064     }
00065 }
00066 
00067 GList * value_pair_add(GList * list, char * key, char * value)
00068 {
00069     char * tmp = escape_string(value);
00070     value_pair * vp = g_new0(value_pair, 1);
00071     strcpy(vp->key, key);
00072     strcpy(vp->value,tmp);
00073     g_free(tmp);
00074     return g_list_append(list, vp);
00075 }
00076 
00077 GList * value_pair_remove( GList *pairs, char *key )
00078 {
00079     GList * node, *new_list;
00080     void *ptr=NULL;
00081     for( node = pairs; node; node=node->next)
00082     {
00083         value_pair * vp = node->data;
00084         if(vp && !strcasecmp(key, vp->key)) {
00085             ptr=node->data;
00086             new_list= g_list_remove(pairs, node->data);
00087             g_free(ptr);
00088             return(new_list);
00089         }
00090     }
00091     return pairs;
00092 }
00093 
00094 GList * value_pair_update(GList * pairs, GList * new_list)
00095 {
00096 
00097     GList * node;
00098     for( node = new_list; node; node=node->next)
00099     {
00100         value_pair * vp = node->data;
00101         pairs = value_pair_remove(pairs, vp->key);
00102         pairs = value_pair_add(pairs, vp->key, vp->value);
00103     }
00104     return(pairs);
00105 }
00106 

Contact: Andy Maloney     [Documentation generated by doxygen]