1
0

anplug.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "clish/plugin.h"
  4. #include "lub/ini.h"
  5. CLISH_PLUGIN_SYM(anplug_fn)
  6. {
  7. printf("anplug: Another plugin\n");
  8. return 0;
  9. }
  10. CLISH_PLUGIN_FINI(clish_plugin_anplug_fini)
  11. {
  12. printf("anplug: FINI this = %p\n", clish_shell);
  13. return 0;
  14. }
  15. CLISH_PLUGIN_INIT(anplug)
  16. {
  17. char *conf;
  18. lub_ini_t *ini;
  19. lub_ini_node_t *iter;
  20. lub_pair_t *pair;
  21. printf("anplug: INIT shell = %p\n", clish_shell);
  22. /* Set a fini function */
  23. clish_plugin_add_fini(plugin, clish_plugin_anplug_fini);
  24. /* Add symbols */
  25. clish_plugin_add_sym(plugin, anplug_fn, "an_fn");
  26. /* Show plugin config from <PLUGIN>...</PLUGIN> */
  27. conf = clish_plugin__get_conf(plugin);
  28. ini = lub_ini_new();
  29. lub_ini_parse_str(ini, conf);
  30. /* Iterate INI elements */
  31. for(iter = lub_ini__get_head(ini);
  32. iter; iter = lub_ini__get_next(iter)) {
  33. pair = lub_ini__iter_data(iter);
  34. printf("anplug iter: [%s] = [%s]\n",
  35. lub_pair__get_name(pair),
  36. lub_pair__get_value(pair));
  37. }
  38. /* Get specified config element */
  39. printf("anplug conf: vvv = %s\n", lub_ini_find(ini, "vvv"));
  40. lub_ini_free(ini);
  41. return 0;
  42. }