plugin_init.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. *
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdint.h>
  7. #include <assert.h>
  8. #include <faux/faux.h>
  9. #include <klish/kplugin.h>
  10. #include <klish/kcontext.h>
  11. #include "private.h"
  12. const uint8_t kplugin_klish_major = KPLUGIN_MAJOR;
  13. const uint8_t kplugin_klish_minor = KPLUGIN_MINOR;
  14. int kplugin_klish_init(kcontext_t *context)
  15. {
  16. kplugin_t *plugin = NULL;
  17. ksym_t *sym = NULL;
  18. assert(context);
  19. plugin = kcontext_plugin(context);
  20. assert(plugin);
  21. // Misc
  22. kplugin_add_syms(plugin, ksym_new_ext("nop", klish_nop,
  23. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
  24. kplugin_add_syms(plugin, ksym_new("tsym", klish_tsym));
  25. // Navigation
  26. // Navigation must be permanent (no dry-run) and sync. Because unsync
  27. // actions will be fork()-ed so it can't change current path.
  28. kplugin_add_syms(plugin, ksym_new_ext("nav", klish_nav,
  29. KSYM_PERMANENT, KSYM_SYNC));
  30. // PTYPEs
  31. // These PTYPEs are simple and fast so set SYNC flag
  32. kplugin_add_syms(plugin, ksym_new_ext("COMMAND", klish_ptype_COMMAND,
  33. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
  34. kplugin_add_syms(plugin, ksym_new_ext("COMMAND_CASE", klish_ptype_COMMAND_CASE,
  35. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
  36. kplugin_add_syms(plugin, ksym_new_ext("INT", klish_ptype_INT,
  37. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
  38. kplugin_add_syms(plugin, ksym_new_ext("UINT", klish_ptype_UINT,
  39. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
  40. kplugin_add_syms(plugin, ksym_new_ext("STRING", klish_ptype_STRING,
  41. KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
  42. return 0;
  43. }
  44. int kplugin_klish_fini(kcontext_t *context)
  45. {
  46. // fprintf(stderr, "Plugin 'klish' fini\n");
  47. context = context;
  48. return 0;
  49. }