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_confreg.c,v 1.2 2005/06/05 03:56:32 klmitch Exp $ 00019 */ 00027 #include "event_int.h" 00028 00029 #include <stdlib.h> 00030 #include <string.h> 00031 00032 RCSTAG("@(#)$Id: event_attr_confreg.c,v 1.2 2005/06/05 03:56:32 klmitch Exp $"); 00033 00034 ev_err_t 00035 event_attr_confreg(ev_attr_t *attr, const char *name, const char *def, 00036 treeconf_nodown_t nodown, treeconf_change_t change, 00037 void *assoc) 00038 { 00039 int cmp; 00040 ev_varlist_t **ptr, *tmp; 00041 00042 ev_init(); /* initialize library... */ 00043 00044 if (!ea_verify(attr) || !name || /* must be a valid attr */ 00045 /* Don't let the application register variables under the event 00046 * hierarchy. (sizeof(PACKAGE_TARNAME) will include the \0, 00047 * standing in for the "."... 00048 */ 00049 !strncmp(name, PACKAGE_TARNAME ".", sizeof(PACKAGE_TARNAME))) 00050 ev_return(EINVAL); 00051 00052 /* Now, walk the linked list, looking for a variable match and ordering */ 00053 for (ptr = &(ea_varlist(attr)); *ptr; ptr = &(*ptr)->vl_next) 00054 if (!(cmp = strcmp((*ptr)->vl_name, name))) 00055 ev_return(TC_ERR_MULTREG); /* exact match; reject it */ 00056 else if (cmp > 0) /* this entry is larger than what we're inserting */ 00057 break; /* so break out of the loop and we'll insert before it */ 00058 00059 /* OK, now let's allocate a varlist element and initialize it... */ 00060 if (!(tmp = (ev_varlist_t *)malloc(sizeof(ev_varlist_t)))) 00061 ev_return(ENOMEM); 00062 00063 /* Now, let's initialize it for its new place in the list... */ 00064 tmp->vl_next = *ptr; 00065 tmp->vl_prev_p = ptr; 00066 tmp->vl_name = name; 00067 tmp->vl_default = def; 00068 tmp->vl_nodown = nodown; 00069 tmp->vl_change = change; 00070 tmp->vl_assoc = assoc; 00071 00072 /* And, finally, insert it into the list */ 00073 *ptr = tmp; 00074 00075 ev_return(0); 00076 }