Beispiel #1
0
static void handle_triggers(struct term_client *client, char *data,
                            size_t length)
{
    struct term_trigger *trigger = NULL;

    collections_list_traverse_start(client->triggers);

    while ((trigger = collections_list_traverse_next(client->triggers)) != NULL)
    {
        for (int i = 0; i < length; i++) {
            if (data[i] == trigger->trigger_character) {
                /* call closure associated with trigger */
                trigger->closure.handler(trigger->closure.arg);
            }
        }
    }

    collections_list_traverse_end(client->triggers);
}
Beispiel #2
0
/*
 * Returns the next element in the hash table. If
 * a valid element is found, the key is set to the
 * key of the element. If there is no valid element,
 * returns null and key is not modified.
 */
void* collections_hash_traverse_next(collections_hash_table* t, uint64_t *key)
{
	if (t->cur_bucket_num == -1) {
		// if the cur_bucket_num is invalid, 
		// hash traversal has not been started.
		printf("Error: collections_hash_table must be opened for traversal first.\n");
		return NULL;
	}
	
	if (t->cur_bucket_num >= t->num_buckets) {
		// all the buckets have been traversed.
		return NULL;
	} else {
		collections_listnode*	bucket;
		collections_hash_elem*	ret;

		if (t->buckets[t->cur_bucket_num]) {
			bucket = t->buckets[t->cur_bucket_num];
			ret = (collections_hash_elem*) collections_list_traverse_next(bucket);

			if (ret) {
				*key = ret->key;
				return ret->data;
			} else {
				// this list traversal is over.
				// let's close it.
				collections_list_traverse_end(bucket);
			}
		}

		bucket = collections_hash_get_next_valid_bucket(t);
		if (!bucket) {
			return NULL;
		} else {
			ret = (collections_hash_elem*) collections_list_traverse_next(bucket);
			assert(ret != NULL);
		}

		*key = ret->key;
		return ret->data;
	}
}