Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define SEARCH_FUNCTIONS(x, y) \
- int \
- userfw_find_ ## x (const struct userfw_modlist *m, const char *name, size_t len, struct userfw_ ## x ##_descr **dst) \
- { \
- int i, ret = 0; \
- for(i = 0; i < m->nmodules; i++) \
- ret += userfw_find_ ## x ## _in_module(&(m->modules[i]), name, len, dst); \
- return ret; \
- } \
- \
- int \
- userfw_find_ ## x ## _in_module(const struct userfw_modinfo *m, const char *name, size_t len, struct userfw_ ## x ## _descr **dst) \
- { \
- int i, ret = 0; \
- for(i = 0; i < m->n ## y; i++) \
- { \
- if (memcmp(name, m->y[i].name, MIN(len, USERFW_NAME_LEN)) \
- && (len >= USERFW_NAME_LEN || m->y[i].name[len] == '\0')) \
- { \
- *dst = &(m->y[i]); \
- ret++; \
- } \
- } \
- return ret; \
- } \
- \
- int \
- userfw_find_ ## x ## _by_opcode(struct userfw_modinfo *m, opcode_t op, struct userfw_ ## x ## _descr **dst) \
- { \
- int i, ret = 0; \
- for(i = 0; i < m->n ## y; i++) \
- { \
- if (m->y[i].opcode == op) \
- { \
- *dst = &(m->y[i]); \
- ret++; \
- } \
- } \
- return 0; \
- }
- SEARCH_FUNCTIONS(action, actions);
- SEARCH_FUNCTIONS(match, matches);
- SEARCH_FUNCTIONS(cmd, cmds);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement