shell_find_create_ptype.c 994 B

123456789101112131415161718192021222324252627282930313233343536373839
  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,
  9. const char *text,
  10. const char *pattern,
  11. clish_ptype_method_e method,
  12. clish_ptype_preprocess_e
  13. preprocess)
  14. {
  15. clish_ptype_t *ptype = lub_bintree_find(&this->ptype_tree, name);
  16. if (NULL == ptype) {
  17. /* create a ptype */
  18. ptype =
  19. clish_ptype_new(name, text, pattern, method, preprocess);
  20. assert(ptype);
  21. clish_shell_insert_ptype(this, ptype);
  22. } else {
  23. if (pattern) {
  24. /* set the pattern */
  25. clish_ptype__set_pattern(ptype, pattern, method);
  26. /* set the preprocess */
  27. clish_ptype__set_preprocess(ptype, preprocess);
  28. }
  29. if (text) {
  30. /* set the help text */
  31. clish_ptype__set_text(ptype, text);
  32. }
  33. }
  34. return ptype;
  35. }
  36. /*--------------------------------------------------------- */