anplug.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_INIT
  11. {
  12. char *conf;
  13. lub_ini_t *ini;
  14. lub_ini_node_t *iter;
  15. lub_pair_t *pair;
  16. printf("anplug: INIT shell = %p\n", clish_shell);
  17. /* Set a name of plugin to use in sym@plugin */
  18. clish_plugin__set_name(plugin, "another_plug");
  19. /* Add symbols */
  20. clish_plugin_add_sym(plugin, anplug_fn, "an_fn");
  21. /* Show plugin config from <PLUGIN>...</PLUGIN> */
  22. conf = clish_plugin__get_conf(plugin);
  23. ini = lub_ini_new();
  24. lub_ini_parse_str(ini, conf);
  25. /* Iterate INI elements */
  26. for(iter = lub_ini__get_head(ini);
  27. iter; iter = lub_ini__get_next(iter)) {
  28. pair = lub_ini__iter_data(iter);
  29. printf("anplug iter: [%s] = [%s]\n",
  30. lub_pair__get_name(pair),
  31. lub_pair__get_value(pair));
  32. }
  33. /* Get specified config element */
  34. printf("anplug conf: vvv = %s\n", lub_ini_find(ini, "vvv"));
  35. lub_ini_free(ini);
  36. return 0;
  37. }
  38. CLISH_PLUGIN_FINI
  39. {
  40. printf("anplug: FINI this = %p\n", clish_shell);
  41. return 0;
  42. }