iview.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include <faux/str.h>
  6. #include <faux/conv.h>
  7. #include <klish/khelper.h>
  8. #include <klish/kview.h>
  9. #include <klish/kcommand.h>
  10. char *iview_to_text(const iview_t *iview, int level)
  11. {
  12. char *str = NULL;
  13. char *tmp = NULL;
  14. tmp = faux_str_sprintf("%*cVIEW {\n", level, ' ');
  15. faux_str_cat(&str, tmp);
  16. faux_str_free(tmp);
  17. attr2ctext(&str, "name", iview->name, level + 1);
  18. // COMMAND list
  19. if (iview->commands) {
  20. icommand_t **p_icommand = NULL;
  21. tmp = faux_str_sprintf("\n%*cCOMMAND_LIST\n\n", level + 1, ' ');
  22. faux_str_cat(&str, tmp);
  23. faux_str_free(tmp);
  24. for (p_icommand = *iview->commands; *p_icommand; p_icommand++) {
  25. icommand_t *icommand = *p_icommand;
  26. tmp = icommand_to_text(icommand, level + 2);
  27. faux_str_cat(&str, tmp);
  28. faux_str_free(tmp);
  29. }
  30. tmp = faux_str_sprintf("%*cEND_COMMAND_LIST,\n", level + 1, ' ');
  31. faux_str_cat(&str, tmp);
  32. faux_str_free(tmp);
  33. }
  34. tmp = faux_str_sprintf("%*c},\n\n", level, ' ');
  35. faux_str_cat(&str, tmp);
  36. faux_str_free(tmp);
  37. return str;
  38. }