shell_ptype.c 1.1 KB

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