nav.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /** @file nav.c
  2. * @brief Navigation
  3. *
  4. * Example:
  5. * <ACTION sym="nav">
  6. * pop
  7. * push /view_name
  8. * </ACTION>
  9. *
  10. * Possible navigation commands:
  11. * * push <view_name> - Push "view_name" view to new level of path and change
  12. * current path to it.
  13. * * pop [num] - Pop up path levels. Optional "num" argument specifies number
  14. * of levels to pop. Default is 1.
  15. * * top - Pop up to first path level.
  16. * * exit - Exit klish.
  17. */
  18. #include <assert.h>
  19. #include <stdio.h>
  20. #include <unistd.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23. #include <errno.h>
  24. #include <faux/str.h>
  25. #include <faux/list.h>
  26. #include <klish/kcontext.h>
  27. #include <klish/kentry.h>
  28. int klish_nav(kcontext_t *context)
  29. {
  30. kparg_t *parg = NULL;
  31. const kentry_t *entry = NULL;
  32. const char *value = NULL;
  33. const char *command_name = NULL;
  34. // Navigation is suitable only for command actions but not for
  35. // PTYPEs, CONDitions i.e. SERVICE_ACTIONS.
  36. assert(kcontext_type(context) == KCONTEXT_ACTION);
  37. parg = kcontext_candidate_parg(context);
  38. entry = kparg_entry(parg);
  39. value = kparg_value(parg);
  40. command_name = kentry_value(entry);
  41. if (!command_name)
  42. command_name = kentry_name(entry);
  43. if (!command_name)
  44. return -1;
  45. return faux_str_casecmp(value, command_name);
  46. }