Advertisement
Guest User

Untitled

a guest
Jan 24th, 2012
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.40 KB | None | 0 0
  1. #define SEARCH_FUNCTIONS(x, y) \
  2. int \
  3. userfw_find_ ## x (const struct userfw_modlist *m, const char *name, size_t len, struct userfw_ ## x ##_descr **dst) \
  4. { \
  5.         int i, ret = 0; \
  6.         for(i = 0; i < m->nmodules; i++) \
  7.                 ret += userfw_find_ ## x ## _in_module(&(m->modules[i]), name, len, dst); \
  8.         return ret; \
  9. } \
  10.  \
  11. int \
  12. userfw_find_ ## x ## _in_module(const struct userfw_modinfo *m, const char *name, size_t len, struct userfw_ ## x ## _descr **dst) \
  13. { \
  14.         int i, ret = 0; \
  15.         for(i = 0; i < m->n ## y; i++) \
  16.         { \
  17.                 if (memcmp(name, m->y[i].name, MIN(len, USERFW_NAME_LEN)) \
  18.                         && (len >= USERFW_NAME_LEN || m->y[i].name[len] == '\0')) \
  19.                 { \
  20.                         *dst = &(m->y[i]); \
  21.                         ret++; \
  22.                 } \
  23.         } \
  24.         return ret; \
  25. } \
  26.  \
  27. int \
  28. userfw_find_ ## x ## _by_opcode(struct userfw_modinfo *m, opcode_t op, struct userfw_ ## x ## _descr **dst) \
  29. { \
  30.         int i, ret = 0; \
  31.         for(i = 0; i < m->n ## y; i++) \
  32.         { \
  33.                 if (m->y[i].opcode == op) \
  34.                 { \
  35.                         *dst = &(m->y[i]); \
  36.                         ret++; \
  37.                 } \
  38.         } \
  39.         return 0; \
  40. }
  41.  
  42. SEARCH_FUNCTIONS(action, actions);
  43. SEARCH_FUNCTIONS(match, matches);
  44. SEARCH_FUNCTIONS(cmd, cmds);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement