ischeme.c 1.9 KB

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