Browse Source

ischeme: Change interface of ischeme_load() due to kdb style

Serj Kalichev 3 years ago
parent
commit
b23c237323
3 changed files with 10 additions and 15 deletions
  1. 2 2
      bin/klishd/klishd.c
  2. 2 1
      klish/ischeme.h
  3. 6 12
      klish/ischeme/ischeme.c

+ 2 - 2
bin/klishd/klishd.c

@@ -136,14 +136,14 @@ int main(int argc, char **argv)
 	}
 
 	// Scheme
+	scheme = kscheme_new();
 	{
 	char *txt = NULL;
 	kcontext_t *context = NULL;
 	bool_t prepare_retcode = BOOL_FALSE;
 
 	// Load scheme
-	scheme = ischeme_load(&sch, error);
-	if (!scheme) {
+	if (!ischeme_load(&sch, scheme, error)) {
 		fprintf(stderr, "Scheme errors:\n");
 		goto err;
 	}

+ 2 - 1
klish/ischeme.h

@@ -48,7 +48,8 @@ C_DECL_BEGIN
 
 bool_t ischeme_parse_nested(const ischeme_t *ischeme, kscheme_t *kscheme,
 	faux_error_t *error);
-kscheme_t *ischeme_load(const ischeme_t *ischeme, faux_error_t *error);
+bool_t ischeme_load(const ischeme_t *ischeme, kscheme_t *kscheme,
+	faux_error_t *error);
 char *ischeme_deploy(const kscheme_t *scheme, int level);
 
 C_DECL_END

+ 6 - 12
klish/ischeme/ischeme.c

@@ -140,23 +140,17 @@ bool_t ischeme_parse_nested(const ischeme_t *ischeme, kscheme_t *kscheme,
 }
 
 
-kscheme_t *ischeme_load(const ischeme_t *ischeme, faux_error_t *error)
+bool_t ischeme_load(const ischeme_t *ischeme, kscheme_t *kscheme,
+	faux_error_t *error)
 {
-	kscheme_t *kscheme = NULL;
-
-	kscheme = kscheme_new();
+	assert(kscheme);
 	if (!kscheme) {
-		faux_error_sprintf(error, TAG": Can't create object");
-		return NULL;
+		faux_error_sprintf(error, TAG": Internal error");
+		return BOOL_FALSE;
 	}
 
 	// Parse nested elements
-	if (!ischeme_parse_nested(ischeme, kscheme, error)) {
-		kscheme_free(kscheme);
-		return NULL;
-	}
-
-	return kscheme;
+	return ischeme_parse_nested(ischeme, kscheme, error);
 }