Browse Source

scheme: Unfinished ptype parsing

Serj Kalichev 3 years ago
parent
commit
e0949bf89a
1 changed files with 80 additions and 2 deletions
  1. 80 2
      klish/kscheme/ischeme.c

+ 80 - 2
klish/kscheme/ischeme.c

@@ -20,7 +20,7 @@ bool_t kview_nested_from_iview(kview_t *kview, iview_t *iview,
 		return BOOL_FALSE;
 	}
 
-	// Command list
+	// COMMAND list
 	if (iview->commands) {
 		icommand_t **p_icommand = NULL;
 		for (p_icommand = *iview->commands; *p_icommand; p_icommand++) {
@@ -74,6 +74,70 @@ kview_t *kview_from_iview(iview_t *iview, faux_error_t *error_stack)
 }
 
 
+bool_t kptype_nested_from_iptype(kptype_t *kptype, iview_t *iptype,
+	faux_error_t *error_stack)
+{
+	if (!kptype || !iptype) {
+		if (error_stack)
+			faux_error_add(error_stack,
+				kptype_strerror(KPTYPE_ERROR_INTERNAL));
+		return BOOL_FALSE;
+	}
+
+	// ACTION list
+	if (iptype->actions) {
+		iaction_t **p_iaction = NULL;
+		for (p_iaction = *iptype->actions; *p_iaction; p_iaction++) {
+			kaction_t *kaction = NULL;
+			iaction_t *iaction = *p_iaction;
+printf("action\n");
+//			kaction = kaction_from_iaction(iaction, error_stack);
+//			if (!kaction)
+//				continue;
+kaction = kaction;
+		}
+	}
+
+	return BOOL_TRUE;
+}
+
+
+kptype_t *kptype_from_iptype(iptype_t *iptype, faux_error_t *error_stack)
+{
+	kptype_t *kptype = NULL;
+	kptype_error_e kptype_error = KPTYPE_ERROR_OK;
+	ssize_t error_stack_len = 0;
+
+	kptype = kptype_new(iptype, &kptype_error);
+	if (!kptype) {
+		if (error_stack) {
+			char *msg = NULL;
+			msg = faux_str_sprintf("PTYPE \"%s\": %s",
+				iptype->name ? iptype->name : "(null)",
+				kptype_strerror(kptype_error));
+			faux_error_add(error_stack, msg);
+			faux_str_free(msg);
+		}
+		return NULL;
+	}
+	printf("ptype %s\n", kptype_name(kptype));
+
+	// Parse nested elements
+	if (error_stack)
+		error_stack_len = faux_error_len(error_stack);
+	kptype_nested_from_iptype(kptype, iptype, error_stack);
+	if (error_stack && (faux_error_len(error_stack) > error_stack_len)) {
+		char *msg = NULL;
+		msg = faux_str_sprintf("PTYPE \"%s\": Illegal nested elements",
+			kptype_name(kview));
+		faux_error_add(error_stack, msg);
+		faux_str_free(msg);
+	}
+
+	return kptype;
+}
+
+
 bool_t kscheme_nested_from_ischeme(kscheme_t *kscheme, ischeme_t *ischeme,
 	faux_error_t *error_stack)
 {
@@ -84,7 +148,21 @@ bool_t kscheme_nested_from_ischeme(kscheme_t *kscheme, ischeme_t *ischeme,
 		return BOOL_FALSE;
 	}
 
-	// View list
+	// PTYPE list
+	if (ischeme->ptypes) {
+		iptype_t **p_iptype = NULL;
+		for (p_iptype = *ischeme->ptypes; *p_iptype; p_iptype++) {
+			kptype_t *kptype = NULL;
+			iptype_t *iptype = *p_iptype;
+
+			kptype = kptype_from_iptype(iptype, error_stack);
+			if (!kptype)
+				continue;
+			kscheme_add_ptype(kscheme, kptype);
+		}
+	}
+
+	// VIEW list
 	if (ischeme->views) {
 		iview_t **p_iview = NULL;
 		for (p_iview = *ischeme->views; *p_iview; p_iview++) {