plugin_init.c 728 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include "private.h"
  5. static char * trim(char *str)
  6. {
  7. size_t len = 0;
  8. const char *first = str;
  9. char *last = str + strlen(str) - 1;
  10. char *new = NULL;
  11. while (first < last && isspace(*first))
  12. ++first;
  13. while (first < last && isspace(*last))
  14. --last;
  15. len = last - first + 1;
  16. new = malloc(len + 1);
  17. memcpy(new, first, len);
  18. new[len] = '\0';
  19. return new;
  20. }
  21. CLISH_PLUGIN_INIT
  22. {
  23. char *conf = clish_plugin__get_conf(plugin);
  24. if (conf) {
  25. scripts_path = trim(conf);
  26. }
  27. if(clish_plugin_init_lua(clish_shell))
  28. return (-1);
  29. clish_plugin__set_name(plugin, "lua_hooks");
  30. clish_plugin_add_sym(plugin, clish_plugin_lua_action, "hook_action");
  31. return 0;
  32. }