00001 /* 00002 ** Copyright (C) 2005 by Kevin L. Mitchell <klmitch@mit.edu> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 ** 00018 ** @(#)$Id: event_attr_confvar.c,v 1.1 2005/06/04 17:57:03 klmitch Exp $ 00019 */ 00027 #include "event_int.h" 00028 00029 #include <stdlib.h> 00030 #include <string.h> 00031 00032 RCSTAG("@(#)$Id: event_attr_confvar.c,v 1.1 2005/06/04 17:57:03 klmitch Exp $"); 00033 00034 ev_err_t 00035 event_attr_confvar(ev_attr_t *attr, const char *name, const char *value) 00036 { 00037 int cmp; 00038 ev_overvars_t **ptr, *tmp; 00039 00040 ev_init(); /* initialize library... */ 00041 00042 if (!ea_verify(attr) || !name) /* must be a valid attr */ 00043 ev_return(EINVAL); 00044 00045 /* Now, walk the linked list, looking for a variable match and ordering */ 00046 for (ptr = &(ea_ovars(attr)); *ptr; ptr = &(*ptr)->ov_next) 00047 if (!(cmp = strcmp((*ptr)->ov_name, name))) { /* found exact match... */ 00048 /* Change the value of the variable... */ 00049 tmp = *ptr; /* make life easy on ourselves... */ 00050 00051 if (!value) { /* reset to default; just delete this variable */ 00052 if (tmp->ov_next) /* First, clip the thing out of the list... */ 00053 tmp->ov_next->ov_prev_p = tmp->ov_prev_p; 00054 *tmp->ov_prev_p = tmp->ov_next; 00055 00056 free(tmp); /* then release the memory */ 00057 } else if (strcmp(tmp->ov_value, value)) /* if values differ... */ 00058 tmp->ov_value = value; /* just set the new value */ 00059 00060 ev_return(0); /* all done! */ 00061 } else if (cmp > 0) /* this entry is larger than what we're inserting */ 00062 break; /* so break out of the loop and we'll insert before it */ 00063 00064 if (!value) /* an order to reset to defaults. Yeah, right. */ 00065 ev_return(0); /* don't bother :) */ 00066 00067 /* OK, now let's allocate a varlist element and initialize it... */ 00068 if (!(tmp = (ev_overvars_t *)malloc(sizeof(ev_overvars_t)))) 00069 ev_return(ENOMEM); 00070 00071 /* Now, let's initialize it for its new place in the list... */ 00072 tmp->ov_next = *ptr; 00073 tmp->ov_prev_p = ptr; 00074 tmp->ov_name = name; 00075 tmp->ov_value = value; 00076 00077 /* And, finally, insert it into the list */ 00078 *ptr = tmp; 00079 00080 ev_return(0); 00081 }