Beispiel #1
0
Datei: rpmhook.c Projekt: xrg/RPM
static void rpmhookTableDelItem(rpmhookTable *table, const char *name,
		rpmhookFunc func, void *data,
		int matchfunc, int matchdata)
{
    int n = rpmhookTableFindBucket(table, name);
    rpmhookBucket bucket = &(*table)->bucket[n];
    rpmhookItem item = bucket->item;
    rpmhookItem lastItem = NULL;
    rpmhookItem nextItem;
    while (item) {
	nextItem = item->next;
	if ((!matchfunc || item->func == func) &&
	    (!matchdata || item->data == data)) {
	    free(item);
	    if (lastItem)
		lastItem->next = nextItem;
	    else
		bucket->item = nextItem;
	} else {
	    lastItem = item;
	}
	item = nextItem;
    }
    if (!bucket->item) {
	free(bucket->name);
	bucket->name = NULL;
	(*table)->used--;
    }
}
Beispiel #2
0
Datei: rpmhook.c Projekt: xrg/RPM
static void rpmhookTableCallArgs(rpmhookTable *table, const char *name,
			rpmhookArgs args)
{
    int n = rpmhookTableFindBucket(table, name);
    rpmhookItem item = (*table)->bucket[n].item;
    while (item) {
	if (item->func(args, item->data) != 0)
	    break;
	item = item->next;
    }
}
Beispiel #3
0
Datei: rpmhook.c Projekt: xrg/RPM
static void rpmhookTableAddItem(rpmhookTable *table, const char *name,
				rpmhookFunc func, void *data)
{
    int n = rpmhookTableFindBucket(table, name);
    rpmhookBucket bucket = &(*table)->bucket[n];
    rpmhookItem *item = &bucket->item;
    if (!bucket->name) {
	bucket->name = xstrdup(name);
	(*table)->used++;
    }
    while (*item) item = &(*item)->next;
    *item = xcalloc(1, sizeof(**item));
    (*item)->func = func;
    (*item)->data = data;
}
Beispiel #4
0
Datei: rpmhook.c Projekt: xrg/RPM
static void rpmhookTableRehash(rpmhookTable *table)
{
    rpmhookTable newtable = rpmhookTableNew((*table)->size*2);
    int n, i = 0;

    for (; i != (*table)->size; i++) {
	if ((*table)->bucket[i].name == NULL)
	    continue;
	n = rpmhookTableFindBucket(&newtable, (*table)->bucket[i].name);
	newtable->bucket[n].name = (*table)->bucket[i].name;
	newtable->bucket[n].item = (*table)->bucket[i].item;
    }
    newtable->used = (*table)->used;
    free(*table);
    *table = newtable;
}
Beispiel #5
0
static void rpmhookTableAddItem(rpmhookTable *table, const char *name,
				rpmhookFunc func, void *data)
	/*@modifies *table @*/
{
    int n = rpmhookTableFindBucket(table, name);
    rpmhookBucket bucket = &(*table)->bucket[n];
    rpmhookItem *item = &bucket->item;
    if (!bucket->name) {
	bucket->name = strdup(name);
	(*table)->used++;
    }
    while (*item) item = &(*item)->next;
    *item = (rpmhookItem) xcalloc(1, sizeof(**item));
    (*item)->func = func;
/*@-temptrans@*/
    (*item)->data = data;
/*@=temptrans@*/
}
Beispiel #6
0
static void rpmhookTableRehash(rpmhookTable *table)
	/*@modifies *table @*/
{
    rpmhookTable newtable = rpmhookTableNew((*table)->size*2);
    int n, i = 0;

    for (; i != (*table)->size; i++) {
	if ((*table)->bucket[i].name == NULL)
	    continue;
	n = rpmhookTableFindBucket(&newtable, (*table)->bucket[i].name);
	newtable->bucket[n].name = (*table)->bucket[i].name;
	newtable->bucket[n].item = (*table)->bucket[i].item;
    }
    newtable->used = (*table)->used;
/*@-unqualifiedtrans@*/
    free(*table);
/*@=unqualifiedtrans@*/
    *table = newtable;
}