X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=common%2Futils.c;h=d82f3c3cd47b4952085127f16ef8366aee87fe9a;hb=302a260054ea38d3cb97be6d1a3010082c09265d;hp=d7ae7520fc131d232748ad2253a6408f19e6d75f;hpb=b9707562a7a426204bda9a32843eb3677230c91d;p=doldaconnect.git diff --git a/common/utils.c b/common/utils.c index d7ae752..d82f3c3 100644 --- a/common/utils.c +++ b/common/utils.c @@ -1,6 +1,6 @@ /* * Dolda Connect - Modular multiuser Direct Connect-style client - * Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com) + * Copyright (C) 2004 Fredrik Tolf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -801,6 +801,51 @@ char *findfile(char *name, char *homedir, int filldef) } } +struct strpair *newstrpair(char *key, char *val, struct strpair **list) +{ + struct strpair *pair; + + pair = smalloc(sizeof(*pair)); + memset(pair, 0, sizeof(*pair)); + if(key != NULL) + pair->key = sstrdup(key); + if(val != NULL) + pair->val = sstrdup(val); + if(list != NULL) + { + pair->next = *list; + *list = pair; + } + return(pair); +} + +void freestrpair(struct strpair *pair, struct strpair **list) +{ + struct strpair *cur; + + for(cur = *list; cur != NULL; list = &(cur->next), cur = cur->next) + { + if(cur == pair) + { + *list = cur->next; + break; + } + } + free(pair->key); + free(pair->val); + free(pair); +} + +char *spfind(struct strpair *list, char *key) +{ + for(; list != NULL; list = list->next) + { + if(!strcmp(list->key, key)) + return(list->val); + } + return(NULL); +} + struct wcspair *newwcspair(wchar_t *key, wchar_t *val, struct wcspair **list) { struct wcspair *pair; @@ -811,10 +856,8 @@ struct wcspair *newwcspair(wchar_t *key, wchar_t *val, struct wcspair **list) pair->key = swcsdup(key); if(val != NULL) pair->val = swcsdup(val); - if(list == NULL) + if(list != NULL) { - pair->next = NULL; - } else { pair->next = *list; *list = pair; }