iview.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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/iview.h>
  8. char *iview_to_text(const iview_t *iview, int level)
  9. {
  10. char *str = NULL;
  11. char *tmp = NULL;
  12. tmp = faux_str_sprintf("%*cVIEW {\n", level, ' ');
  13. faux_str_cat(&str, tmp);
  14. faux_str_free(tmp);
  15. attr2ctext(&str, "name", iview->name, level + 1);
  16. // COMMAND list
  17. if (iview->commands) {
  18. icommand_t **p_icommand = NULL;
  19. tmp = faux_str_sprintf("\n%*cCOMMAND_LIST\n\n", level + 1, ' ');
  20. faux_str_cat(&str, tmp);
  21. faux_str_free(tmp);
  22. for (p_icommand = *iview->commands; *p_icommand; p_icommand++) {
  23. icommand_t *icommand = *p_icommand;
  24. tmp = icommand_to_text(icommand, level + 2);
  25. faux_str_cat(&str, tmp);
  26. faux_str_free(tmp);
  27. }
  28. tmp = faux_str_sprintf("%*cEND_COMMAND_LIST,\n", level + 1, ' ');
  29. faux_str_cat(&str, tmp);
  30. faux_str_free(tmp);
  31. }
  32. tmp = faux_str_sprintf("%*c},\n\n", level, ' ');
  33. faux_str_cat(&str, tmp);
  34. faux_str_free(tmp);
  35. return str;
  36. }