Пример #1
0
/* Writes a single action to the action set. Overwrites existing actions with
 * the same type in the set. The list order is based on the precedence defined
 * in the specification. */
static void
action_set_write_action(struct action_set *set,
                        struct ofl_action_header *act) {
    struct action_set_entry *entry, *new_entry;

    new_entry = action_set_create_entry(act);

    LIST_FOR_EACH(entry, struct action_set_entry, node, &set->actions) {
        if (entry->action->type == new_entry->action->type) {
            /* replace same type of action */
            list_replace(&new_entry->node, &entry->node);
            /* NOTE: action in entry must not be freed, as it is owned by the
             *       write instruction which added the action to the set */
            free(entry);

            return;
        }
        if (new_entry->order < entry->order) {
            /* insert higher order action before */
            list_insert(&entry->node, &new_entry->node);

            return;
        }
    }

    /* add action to the end of set */
    list_insert(&entry->node, &new_entry->node);
}
Пример #2
0
struct action_set *
action_set_clone(struct action_set *set) {
    struct action_set *s = xmalloc(sizeof(struct action_set));
    struct action_set_entry *entry, *new_entry;

    list_init(&s->actions);
    s->exp = set->exp;

    LIST_FOR_EACH(entry, struct action_set_entry, node, &set->actions) {
        new_entry = action_set_create_entry(entry->action);
        list_push_back(&s->actions, &new_entry->node);
    }

    return s;
}