1
0

sym.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * plugin.c
  3. */
  4. #ifdef HAVE_CONFIG_H
  5. #include "config.h"
  6. #endif /* HAVE_CONFIG_H */
  7. #include "private.h"
  8. #include "lub/string.h"
  9. #include "lub/list.h"
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <stdio.h>
  13. #include <assert.h>
  14. #ifdef HAVE_DLFCN_H
  15. #include <dlfcn.h>
  16. #endif
  17. /*--------------------------------------------------------- */
  18. int clish_sym_compare(const void *first, const void *second)
  19. {
  20. const clish_sym_t *f = (const clish_sym_t *)first;
  21. const clish_sym_t *s = (const clish_sym_t *)second;
  22. return strcmp(f->name, s->name);
  23. }
  24. /*--------------------------------------------------------- */
  25. clish_sym_t *clish_sym_new(const char *name, void *func, int type)
  26. {
  27. clish_sym_t *this;
  28. this = malloc(sizeof(*this));
  29. this->name = lub_string_dup(name);
  30. this->func = func;
  31. this->type = type;
  32. this->api = CLISH_SYM_API_SIMPLE;
  33. this->permanent = BOOL_FALSE;
  34. return this;
  35. }
  36. /*--------------------------------------------------------- */
  37. void clish_sym_free(clish_sym_t *this)
  38. {
  39. if (!this)
  40. return;
  41. lub_string_free(this->name);
  42. free(this);
  43. }
  44. /*--------------------------------------------------------- */
  45. int clish_sym_clone(clish_sym_t *dst, clish_sym_t *src)
  46. {
  47. char *name;
  48. if (!dst || !src)
  49. return -1;
  50. name = dst->name;
  51. *dst = *src;
  52. dst->name = name;
  53. return 0;
  54. }
  55. CLISH_SET(sym, const void *, func);
  56. CLISH_GET(sym, const void *, func);
  57. CLISH_SET(sym, bool_t, permanent);
  58. CLISH_GET(sym, bool_t, permanent);
  59. CLISH_SET_STR(sym, name);
  60. CLISH_GET_STR(sym, name);
  61. CLISH_SET(sym, clish_plugin_t *, plugin);
  62. CLISH_GET(sym, clish_plugin_t *, plugin);
  63. CLISH_SET(sym, int, type);
  64. CLISH_GET(sym, int, type);
  65. CLISH_SET(sym, clish_sym_api_e, api);
  66. CLISH_GET(sym, clish_sym_api_e, api);