ischeme.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include <faux/str.h>
  6. #include <klish/khelper.h>
  7. #include <klish/kview.h>
  8. #include <klish/kptype.h>
  9. #include <klish/kscheme.h>
  10. char *ischeme_to_text(const ischeme_t *ischeme, int level)
  11. {
  12. char *str = NULL;
  13. char *tmp = NULL;
  14. tmp = faux_str_sprintf("ischeme_t sch = {\n");
  15. faux_str_cat(&str, tmp);
  16. faux_str_free(tmp);
  17. // PTYPE list
  18. if (ischeme->ptypes) {
  19. iptype_t **p_iptype = NULL;
  20. tmp = faux_str_sprintf("\n%*cPTYPE_LIST\n\n", level, ' ');
  21. faux_str_cat(&str, tmp);
  22. faux_str_free(tmp);
  23. for (p_iptype = *ischeme->ptypes; *p_iptype; p_iptype++) {
  24. iptype_t *iptype = *p_iptype;
  25. tmp = iptype_to_text(iptype, level + 2);
  26. faux_str_cat(&str, tmp);
  27. faux_str_free(tmp);
  28. }
  29. tmp = faux_str_sprintf("%*cEND_PTYPE_LIST,\n", level + 1, ' ');
  30. faux_str_cat(&str, tmp);
  31. faux_str_free(tmp);
  32. }
  33. // VIEW list
  34. if (ischeme->views) {
  35. iview_t **p_iview = NULL;
  36. tmp = faux_str_sprintf("\n%*cVIEW_LIST\n\n", level + 1, ' ');
  37. faux_str_cat(&str, tmp);
  38. faux_str_free(tmp);
  39. for (p_iview = *ischeme->views; *p_iview; p_iview++) {
  40. iview_t *iview = *p_iview;
  41. tmp = iview_to_text(iview, level + 2);
  42. faux_str_cat(&str, tmp);
  43. faux_str_free(tmp);
  44. }
  45. tmp = faux_str_sprintf("%*cEND_VIEW_LIST,\n", level + 1, ' ');
  46. faux_str_cat(&str, tmp);
  47. faux_str_free(tmp);
  48. }
  49. tmp = faux_str_sprintf("};\n");
  50. faux_str_cat(&str, tmp);
  51. faux_str_free(tmp);
  52. return str;
  53. }