ksym.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /** @file ksym.h
  2. *
  3. * @brief Klish symbol
  4. */
  5. #ifndef _klish_ksym_h
  6. #define _klish_ksym_h
  7. #include <klish/kcontext_base.h>
  8. typedef struct ksym_s ksym_t;
  9. // Callback function prototype
  10. typedef int (*ksym_fn)(kcontext_t *context);
  11. // Aliases for permanent flag
  12. #define KSYM_USERDEFINED_PERMANENT TRI_UNDEFINED
  13. #define KSYM_NONPERMANENT TRI_FALSE
  14. #define KSYM_PERMANENT TRI_TRUE
  15. // Aliases for sync flag
  16. #define KSYM_USERDEFINED_SYNC TRI_UNDEFINED
  17. #define KSYM_UNSYNC TRI_FALSE
  18. #define KSYM_SYNC TRI_TRUE
  19. // Aliases for silent flag
  20. #define KSYM_SILENT BOOL_TRUE
  21. #define KSYM_NONSILENT BOOL_FALSE
  22. C_DECL_BEGIN
  23. // ksym_t
  24. ksym_t *ksym_new_ext(const char *name, ksym_fn function,
  25. tri_t permanent, tri_t sync, bool_t silent);
  26. void ksym_free(ksym_t *sym);
  27. // Typical sym definition for external plugins.
  28. static inline ksym_t *ksym_new(const char *name, ksym_fn function)
  29. {
  30. return ksym_new_ext(name, function, KSYM_USERDEFINED_PERMANENT,
  31. KSYM_USERDEFINED_SYNC, KSYM_NONSILENT);
  32. }
  33. // Typical definition for internal syms like PTYPE checkers, simple completion
  34. // and help functions that can write to text buffer but not to stdout.
  35. static inline ksym_t *ksym_new_fast(const char *name, ksym_fn function)
  36. {
  37. return ksym_new_ext(name, function, KSYM_USERDEFINED_PERMANENT,
  38. KSYM_SYNC, KSYM_SILENT);
  39. }
  40. const char *ksym_name(const ksym_t *sym);
  41. ksym_fn ksym_function(const ksym_t *sym);
  42. bool_t ksym_set_function(ksym_t *sym, ksym_fn fn);
  43. tri_t ksym_permanent(const ksym_t *sym);
  44. bool_t ksym_set_permanent(ksym_t *sym, tri_t permanent);
  45. tri_t ksym_sync(const ksym_t *sym);
  46. bool_t ksym_set_sync(ksym_t *sym, tri_t sync);
  47. bool_t ksym_silent(const ksym_t *sym);
  48. bool_t ksym_set_silent(ksym_t *sym, bool_t silent);
  49. C_DECL_END
  50. #endif // _klish_ksym_h