ischeme.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include <faux/str.h>
  6. #include <faux/list.h>
  7. #include <faux/error.h>
  8. #include <klish/kview.h>
  9. #include <klish/kscheme.h>
  10. bool_t kview_nested_from_iview(kview_t *kview, iview_t *iview,
  11. faux_error_t *error_stack)
  12. {
  13. if (!kview || !iview) {
  14. if (error_stack)
  15. faux_error_add(error_stack,
  16. kview_strerror(KVIEW_ERROR_INTERNAL));
  17. return BOOL_FALSE;
  18. }
  19. // COMMAND list
  20. if (iview->commands) {
  21. icommand_t **p_icommand = NULL;
  22. for (p_icommand = *iview->commands; *p_icommand; p_icommand++) {
  23. kcommand_t *kcommand = NULL;
  24. icommand_t *icommand = *p_icommand;
  25. printf("command %s\n", icommand->name);
  26. // kcommand = kcommand_from_icommand(icommand, error_stack);
  27. // if (!kcommand)
  28. // continue;
  29. kcommand = kcommand;
  30. }
  31. }
  32. return BOOL_TRUE;
  33. }
  34. kview_t *kview_from_iview(iview_t *iview, faux_error_t *error_stack)
  35. {
  36. kview_t *kview = NULL;
  37. kview_error_e kview_error = KVIEW_ERROR_OK;
  38. ssize_t error_stack_len = 0;
  39. kview = kview_new(iview, &kview_error);
  40. if (!kview) {
  41. if (error_stack) {
  42. char *msg = NULL;
  43. msg = faux_str_sprintf("VIEW \"%s\": %s",
  44. iview->name ? iview->name : "(null)",
  45. kview_strerror(kview_error));
  46. faux_error_add(error_stack, msg);
  47. faux_str_free(msg);
  48. }
  49. return NULL;
  50. }
  51. printf("view %s\n", kview_name(kview));
  52. // Parse nested elements
  53. if (error_stack)
  54. error_stack_len = faux_error_len(error_stack);
  55. kview_nested_from_iview(kview, iview, error_stack);
  56. if (error_stack && (faux_error_len(error_stack) > error_stack_len)) {
  57. char *msg = NULL;
  58. msg = faux_str_sprintf("VIEW \"%s\": Illegal nested elements",
  59. kview_name(kview));
  60. faux_error_add(error_stack, msg);
  61. faux_str_free(msg);
  62. }
  63. return kview;
  64. }
  65. bool_t kptype_nested_from_iptype(kptype_t *kptype, iptype_t *iptype,
  66. faux_error_t *error_stack)
  67. {
  68. if (!kptype || !iptype) {
  69. if (error_stack)
  70. faux_error_add(error_stack,
  71. kptype_strerror(KPTYPE_ERROR_INTERNAL));
  72. return BOOL_FALSE;
  73. }
  74. // ACTION list
  75. if (iptype->actions) {
  76. iaction_t **p_iaction = NULL;
  77. for (p_iaction = *iptype->actions; *p_iaction; p_iaction++) {
  78. kaction_t *kaction = NULL;
  79. iaction_t *iaction = *p_iaction;
  80. iaction = iaction;
  81. printf("action\n");
  82. // kaction = kaction_from_iaction(iaction, error_stack);
  83. // if (!kaction)
  84. // continue;
  85. kaction = kaction;
  86. }
  87. }
  88. return BOOL_TRUE;
  89. }
  90. kptype_t *kptype_from_iptype(iptype_t *iptype, faux_error_t *error_stack)
  91. {
  92. kptype_t *kptype = NULL;
  93. kptype_error_e kptype_error = KPTYPE_ERROR_OK;
  94. ssize_t error_stack_len = 0;
  95. kptype = kptype_new(iptype, &kptype_error);
  96. if (!kptype) {
  97. if (error_stack) {
  98. char *msg = NULL;
  99. msg = faux_str_sprintf("PTYPE \"%s\": %s",
  100. iptype->name ? iptype->name : "(null)",
  101. kptype_strerror(kptype_error));
  102. faux_error_add(error_stack, msg);
  103. faux_str_free(msg);
  104. }
  105. return NULL;
  106. }
  107. printf("ptype %s\n", kptype_name(kptype));
  108. // Parse nested elements
  109. if (error_stack)
  110. error_stack_len = faux_error_len(error_stack);
  111. kptype_nested_from_iptype(kptype, iptype, error_stack);
  112. if (error_stack && (faux_error_len(error_stack) > error_stack_len)) {
  113. char *msg = NULL;
  114. msg = faux_str_sprintf("PTYPE \"%s\": Illegal nested elements",
  115. kptype_name(kptype));
  116. faux_error_add(error_stack, msg);
  117. faux_str_free(msg);
  118. }
  119. return kptype;
  120. }
  121. bool_t kscheme_nested_from_ischeme(kscheme_t *kscheme, ischeme_t *ischeme,
  122. faux_error_t *error_stack)
  123. {
  124. if (!kscheme || !ischeme) {
  125. if (error_stack)
  126. faux_error_add(error_stack,
  127. kscheme_strerror(KSCHEME_ERROR_INTERNAL));
  128. return BOOL_FALSE;
  129. }
  130. // PTYPE list
  131. if (ischeme->ptypes) {
  132. iptype_t **p_iptype = NULL;
  133. for (p_iptype = *ischeme->ptypes; *p_iptype; p_iptype++) {
  134. kptype_t *kptype = NULL;
  135. iptype_t *iptype = *p_iptype;
  136. kptype = kptype_from_iptype(iptype, error_stack);
  137. if (!kptype)
  138. continue;
  139. kscheme_add_ptype(kscheme, kptype);
  140. }
  141. }
  142. // VIEW list
  143. if (ischeme->views) {
  144. iview_t **p_iview = NULL;
  145. for (p_iview = *ischeme->views; *p_iview; p_iview++) {
  146. kview_t *kview = NULL;
  147. iview_t *iview = *p_iview;
  148. kview = kview_from_iview(iview, error_stack);
  149. if (!kview)
  150. continue;
  151. kscheme_add_view(kscheme, kview);
  152. }
  153. }
  154. return BOOL_TRUE;
  155. }
  156. kscheme_t *kscheme_from_ischeme(ischeme_t *ischeme, faux_error_t *error_stack)
  157. {
  158. kscheme_t *kscheme = NULL;
  159. kscheme_error_e kscheme_error = KSCHEME_ERROR_OK;
  160. kscheme = kscheme_new(&kscheme_error);
  161. if (!kscheme) {
  162. if (error_stack)
  163. faux_error_add(error_stack,
  164. kscheme_strerror(kscheme_error));
  165. return NULL;
  166. }
  167. kscheme_nested_from_ischeme(kscheme, ischeme, error_stack);
  168. return kscheme;
  169. }