misc.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. // Print content of ACTION script
  36. int klish_print(kcontext_t *context)
  37. {
  38. const kaction_t *action = NULL;
  39. const char *script = NULL;
  40. action = (kaction_t *)faux_list_data(kcontext_action_iter(context));
  41. script = kaction_script(action);
  42. if (faux_str_is_empty(script))
  43. script = "";
  44. printf("%s\n", script);
  45. return 0;
  46. }
  47. // Symbol to show current path
  48. int klish_pwd(kcontext_t *context)
  49. {
  50. kpath_t *path = NULL;
  51. kpath_levels_node_t *iter = NULL;
  52. klevel_t *level = NULL;
  53. path = ksession_path(kcontext_session(context));
  54. iter = kpath_iter(path);
  55. while ((level = kpath_each(&iter))) {
  56. printf("/%s", kentry_name(klevel_entry(level)));
  57. }
  58. printf("\n");
  59. return 0;
  60. }