shell_ptype.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * shell_find_create_ptype.c
  3. */
  4. #include <assert.h>
  5. #include "private.h"
  6. /*--------------------------------------------------------- */
  7. clish_ptype_t *clish_shell_find_ptype(clish_shell_t *this,
  8. const char *name)
  9. {
  10. return lub_bintree_find(&this->ptype_tree, name);
  11. }
  12. /*--------------------------------------------------------- */
  13. clish_ptype_t *clish_shell_find_create_ptype(clish_shell_t * this,
  14. const char *name, const char *text, const char *pattern,
  15. clish_ptype_method_e method, clish_ptype_preprocess_e preprocess)
  16. {
  17. clish_ptype_t *ptype = lub_bintree_find(&this->ptype_tree, name);
  18. if (!ptype) {
  19. /* create a ptype */
  20. ptype = clish_ptype_new(name, text, pattern,
  21. method, preprocess);
  22. assert(ptype);
  23. clish_shell_insert_ptype(this, ptype);
  24. } else {
  25. if (pattern) {
  26. /* set the pattern */
  27. clish_ptype__set_pattern(ptype, pattern, method);
  28. /* set the preprocess */
  29. clish_ptype__set_preprocess(ptype, preprocess);
  30. }
  31. /* set the help text */
  32. if (text)
  33. clish_ptype__set_text(ptype, text);
  34. }
  35. return ptype;
  36. }
  37. /*--------------------------------------------------------- */
  38. void clish_shell_insert_ptype(clish_shell_t * this, clish_ptype_t * ptype)
  39. {
  40. (void)lub_bintree_insert(&this->ptype_tree, ptype);
  41. }
  42. /*--------------------------------------------------------- */