ソースを参照

scheme: Unfinished ischeme_to_text()

Serj Kalichev 3 年 前
コミット
c6a443a822
7 ファイル変更127 行追加3 行削除
  1. 4 0
      bin/klishd/klishd.c
  2. 1 0
      klish/khelper.h
  3. 4 0
      klish/kptype.h
  4. 4 0
      klish/kscheme.h
  5. 3 1
      klish/kscheme/Makefile.am
  6. 51 0
      klish/kscheme/iptype.c
  7. 60 2
      klish/kscheme/ischeme.c

+ 4 - 0
bin/klishd/klishd.c

@@ -198,6 +198,7 @@ int main(int argc, char **argv)
 
 	// Load scheme
 	{
+	char *txt = NULL;
 	faux_error_t *error = faux_error_new();
 	scheme = kscheme_from_ischeme(&sch, error);
 	if (!scheme) {
@@ -205,6 +206,9 @@ int main(int argc, char **argv)
 		faux_error_print(error);
 		goto err;
 	}
+	txt = ischeme_to_text(&sch, 0);
+	printf("%s\n", txt);
+	faux_str_free(txt);
 	}
 
 	// Listen socket

+ 1 - 0
klish/khelper.h

@@ -8,6 +8,7 @@
 #include <faux/faux.h>
 #include <faux/str.h>
 
+
 // Function to get value from structure by name
 #define _KGET(obj, type, name) \
 	type k##obj##_##name(const k##obj##_t *inst)

+ 4 - 0
klish/kptype.h

@@ -29,6 +29,10 @@ typedef enum {
 
 C_DECL_BEGIN
 
+// iptype_t
+char *iptype_to_text(const iptype_t *iptype, int level);
+
+// kptype_t
 void kptype_free(kptype_t *ptype);
 bool_t kptype_parse(kptype_t *ptype, const iptype_t *info, kptype_error_e *error);
 kptype_t *kptype_new(const iptype_t *info, kptype_error_e *error);

+ 4 - 0
klish/kscheme.h

@@ -54,6 +54,10 @@ typedef enum {
 
 C_DECL_BEGIN
 
+// ischeme_t
+char *ischeme_to_text(const ischeme_t *ischeme, int level);
+
+// kscheme_t
 kscheme_t *kscheme_new(kscheme_error_e *error);
 void kscheme_free(kscheme_t *scheme);
 const char *kscheme_strerror(kscheme_error_e error);

+ 3 - 1
klish/kscheme/Makefile.am

@@ -5,5 +5,7 @@ libklish_la_SOURCES += \
 	klish/kscheme/kcommand.c \
 	klish/kscheme/kview.c \
 	klish/kscheme/kscheme.c \
-	klish/kscheme/ischeme.c
+	klish/kscheme/ischeme.c \
+	klish/kscheme/iptype.c
+
 

+ 51 - 0
klish/kscheme/iptype.c

@@ -0,0 +1,51 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#include <faux/str.h>
+#include <klish/khelper.h>
+#include <klish/kptype.h>
+#include <klish/kaction.h>
+
+#define ISCHEME_TAB " "
+
+char *iptype_to_text(const iptype_t *iptype, int level)
+{
+	char *str = NULL;
+	char *tmp = NULL;
+
+	tmp = faux_str_sprintf("%*cPTYPE = {\n", level, ' ');
+	faux_str_cat(&str, tmp);
+	faux_str_free(tmp);
+
+
+/*
+	// PTYPE list
+	if (iptype->ptypes) {
+		iptype_t **p_iptype = NULL;
+
+		tmp = faux_str_sprintf("\n%*sPTYPE_LIST\n\n", level + 1, ISCHEME_TAB);
+		faux_str_cat(&str, tmp);
+		faux_str_free(tmp);
+
+		for (p_iptype = *iptype->ptypes; *p_iptype; p_iptype++) {
+			iptype_t *iptype = *p_iptype;
+
+			tmp = iptype_to_text(iptype, level + 2);
+			faux_str_cat(&str, tmp);
+			faux_str_free(tmp);
+		}
+
+		tmp = faux_str_sprintf("\n%*sEND_PTYPE_LIST,\n", level + 1, ISCHEME_TAB);
+		faux_str_cat(&str, tmp);
+		faux_str_free(tmp);
+	}
+*/
+	tmp = faux_str_sprintf("%*c},\n\n", level, ' ');
+	faux_str_cat(&str, tmp);
+	faux_str_free(tmp);
+iptype = iptype;
+	return str;
+}
+

+ 60 - 2
klish/kscheme/ischeme.c

@@ -4,9 +4,67 @@
 #include <assert.h>
 
 #include <faux/str.h>
-#include <faux/list.h>
-#include <faux/error.h>
+#include <klish/khelper.h>
 #include <klish/kview.h>
+#include <klish/kptype.h>
 #include <klish/kscheme.h>
 
 
+char *ischeme_to_text(const ischeme_t *ischeme, int level)
+{
+	char *str = NULL;
+	char *tmp = NULL;
+
+	tmp = faux_str_sprintf("ischeme_t sch = {\n");
+	faux_str_cat(&str, tmp);
+	faux_str_free(tmp);
+
+	// PTYPE list
+	if (ischeme->ptypes) {
+		iptype_t **p_iptype = NULL;
+
+		tmp = faux_str_sprintf("\n%*cPTYPE_LIST\n\n", level, ' ');
+		faux_str_cat(&str, tmp);
+		faux_str_free(tmp);
+
+		for (p_iptype = *ischeme->ptypes; *p_iptype; p_iptype++) {
+			iptype_t *iptype = *p_iptype;
+
+			tmp = iptype_to_text(iptype, level + 2);
+			faux_str_cat(&str, tmp);
+			faux_str_free(tmp);
+		}
+
+		tmp = faux_str_sprintf("\n%*cEND_PTYPE_LIST,\n", level + 1, ' ');
+		faux_str_cat(&str, tmp);
+		faux_str_free(tmp);
+	}
+/*
+	// VIEW list
+	if (ischeme->views) {
+		iview_t **p_iview = NULL;
+
+		tmp = faux_str_sprintf("\n%*sVIEW_LIST\n\n", level + 1, ISCHEME_TAB);
+		faux_str_cat(&str, tmp);
+		faux_str_free(tmp);
+
+		for (p_iview = *ischeme->views; *p_iview; p_iview++) {
+			iview_t *iview = *p_iview;
+
+			tmp = iview_to_text(iview, level + 2);
+			faux_str_cat(&str, tmp);
+			faux_str_free(tmp);
+		}
+
+		tmp = faux_str_sprintf("\n%*sEND_VIEW_LIST\n", level + 1, ISCHEME_TAB);
+		faux_str_cat(&str, tmp);
+		faux_str_free(tmp);
+	}
+*/
+	tmp = faux_str_sprintf("};\n");
+	faux_str_cat(&str, tmp);
+	faux_str_free(tmp);
+
+	return str;
+}
+