misc.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. *
  3. */
  4. #include <assert.h>
  5. #include <stdio.h>
  6. #include <unistd.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <errno.h>
  10. #include <faux/str.h>
  11. #include <faux/list.h>
  12. #include <klish/kcontext.h>
  13. #include <klish/ksession.h>
  14. #include <klish/kpath.h>
  15. int klish_nop(kcontext_t *context)
  16. {
  17. context = context; // Happy compiler
  18. return 0;
  19. }
  20. // Symbol for testing purposes
  21. int klish_tsym(kcontext_t *context)
  22. {
  23. const kaction_t *action = NULL;
  24. const char *script = NULL;
  25. action = (kaction_t *)faux_list_data(kcontext_action_iter(context));
  26. script = kaction_script(action);
  27. if (faux_str_is_empty(script)) {
  28. printf("[<empty>]\n");
  29. fprintf(stderr, "Empty item\n");
  30. return -1;
  31. }
  32. printf("[%s]\n", script);
  33. return 0;
  34. }
  35. // Symbol to show current path
  36. int klish_pwd(kcontext_t *context)
  37. {
  38. kpath_t *path = NULL;
  39. kpath_levels_node_t *iter = NULL;
  40. klevel_t *level = NULL;
  41. path = ksession_path(kcontext_session(context));
  42. iter = kpath_iter(path);
  43. while ((level = kpath_each(&iter))) {
  44. printf("/%s", kentry_name(klevel_entry(level)));
  45. }
  46. printf("\n");
  47. return 0;
  48. }