1
0

sym.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. this->expand = TRI_UNDEFINED;
  35. return this;
  36. }
  37. /*--------------------------------------------------------- */
  38. void clish_sym_free(void *data)
  39. {
  40. clish_sym_t *this = (clish_sym_t *)data;
  41. if (!data)
  42. return;
  43. lub_string_free(this->name);
  44. free(this);
  45. }
  46. /*--------------------------------------------------------- */
  47. int clish_sym_clone(clish_sym_t *dst, clish_sym_t *src)
  48. {
  49. char *name;
  50. if (!dst || !src)
  51. return -1;
  52. name = dst->name;
  53. *dst = *src;
  54. dst->name = name;
  55. return 0;
  56. }
  57. CLISH_SET(sym, const void *, func);
  58. CLISH_GET(sym, const void *, func);
  59. CLISH_SET(sym, bool_t, permanent);
  60. CLISH_GET(sym, bool_t, permanent);
  61. CLISH_SET(sym, tri_t, expand);
  62. CLISH_GET(sym, tri_t, expand);
  63. CLISH_SET_STR(sym, name);
  64. CLISH_GET_STR(sym, name);
  65. CLISH_SET(sym, clish_plugin_t *, plugin);
  66. CLISH_GET(sym, clish_plugin_t *, plugin);
  67. CLISH_SET(sym, int, type);
  68. CLISH_GET(sym, int, type);
  69. CLISH_SET(sym, clish_sym_api_e, api);
  70. CLISH_GET(sym, clish_sym_api_e, api);