Browse Source

xml2c() for VAR (without ACTION yet)

Serj Kalichev 9 years ago
parent
commit
7031417dfa
3 changed files with 38 additions and 11 deletions
  1. 14 7
      clish/shell/shell_dump.c
  2. 1 0
      clish/var.h
  3. 23 4
      clish/var/var_dump.c

+ 14 - 7
clish/shell/shell_dump.c

@@ -53,7 +53,7 @@ void clish_shell_xml2c(clish_shell_t *this)
 {
 //	clish_view_t *v;
 	clish_ptype_t *t;
-//	clish_var_t *var;
+	clish_var_t *var;
 	lub_bintree_iterator_t iter;
 
 	printf("#include \"private.h\"\n"
@@ -69,6 +69,10 @@ void clish_shell_xml2c(clish_shell_t *this)
 	printf("int clish_shell_load_scheme(clish_shell_t *shell, const char *xml_path)\n"
 		"{\n\n");
 
+	/* Declare vars */
+	printf("clish_var_t *var;\n");
+	printf("\n");
+
 	/* Iterate the tree of types */
 	printf("/*########## PTYPE ##########*/\n\n");
 	t = lub_bintree_findfirst(&this->ptype_tree);
@@ -76,6 +80,15 @@ void clish_shell_xml2c(clish_shell_t *this)
 		t; t = lub_bintree_iterator_next(&iter)) {
 		clish_ptype_xml2c(t);
 	}
+
+	/* Iterate the tree of vars */
+	printf("/*########## VAR ##########*/\n\n");
+	var = lub_bintree_findfirst(&this->var_tree);
+	for (lub_bintree_iterator_init(&iter, &this->var_tree, var);
+		var; var = lub_bintree_iterator_next(&iter)) {
+		clish_var_xml2c(var);
+	}
+
 #if 0
 	v = lub_bintree_findfirst(&this->view_tree);
 	/* iterate the tree of views */
@@ -84,12 +97,6 @@ void clish_shell_xml2c(clish_shell_t *this)
 		clish_view_dump(v);
 	}
 
-	/* iterate the tree of vars */
-	var = lub_bintree_findfirst(&this->var_tree);
-	for (lub_bintree_iterator_init(&iter, &this->var_tree, var);
-		var; var = lub_bintree_iterator_next(&iter)) {
-		clish_var_dump(var);
-	}
 #endif
 
 	printf("\n"

+ 1 - 0
clish/var.h

@@ -22,6 +22,7 @@ clish_var_t *clish_var_new(const char *name);
  *----------------- */
 void clish_var_delete(clish_var_t *instance);
 void clish_var_dump(const clish_var_t *instance);
+void clish_var_xml2c(clish_var_t *instance);
 /*-----------------
  * attributes
  *----------------- */

+ 23 - 4
clish/var/var_dump.c

@@ -1,12 +1,14 @@
-#ifdef DEBUG
-
 /*
  * var_dump.c
  */
 
-#include "lub/dump.h"
-#include "clish/action.h"
 #include "private.h"
+#include "clish/action.h"
+#include "lub/xml2c.h"
+
+#ifdef DEBUG
+
+#include "lub/dump.h"
 
 /*--------------------------------------------------------- */
 void clish_var_dump(const clish_var_t *this)
@@ -25,3 +27,20 @@ void clish_var_dump(const clish_var_t *this)
 /*--------------------------------------------------------- */
 
 #endif /* DEBUG */
+
+void clish_var_xml2c(clish_var_t *this)
+{
+	char *esc_name = xml2c_esc(clish_var__get_name(this));
+	bool_t dynamic = clish_var__get_dynamic(this);
+	char *esc_value = xml2c_esc(clish_var__get_value(this));
+
+	printf("var = clish_var_new(\"%s\");\n", XML2C_STR(esc_name)); /* name */
+	printf("lub_bintree_insert(&shell->var_tree, var);\n"); /* Insert VAR to list */
+	printf("clish_var__set_dynamic(var, %s);\n", XML2C_BOOL(dynamic)); /* dynamic */
+	if (esc_value)
+		printf("clish_var__set_value(var, \"%s\");\n", XML2C_STR(esc_value)); /* value */
+	printf("\n");
+
+	lub_string_free(esc_name);
+	lub_string_free(esc_value);
+}