nav.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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.
  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. parg = kcontext_candidate_parg(context);
  35. entry = kparg_entry(parg);
  36. value = kparg_value(parg);
  37. command_name = kentry_value(entry);
  38. if (!command_name)
  39. command_name = kentry_name(entry);
  40. if (!command_name)
  41. return -1;
  42. return faux_str_casecmp(value, command_name);
  43. }