Forráskód Böngészése

kentry: 'value' field is original for links

Serj Kalichev 3 éve
szülő
commit
04c50eef8c
4 módosított fájl, 75 hozzáadás és 26 törlés
  1. 34 2
      bin/klishd/klishd.c
  2. 2 2
      klish/kscheme/kentry.c
  3. 12 1
      klish/ksession.h
  4. 27 21
      klish/ksession/ksession_parse.c

+ 34 - 2
bin/klishd/klishd.c

@@ -168,13 +168,45 @@ int main(int argc, char **argv)
 	deploy_db = kdb_new("ischeme", NULL);
 	kdb_load_plugin(deploy_db);
 	kdb_init(deploy_db);
-	kdb_deploy_scheme(deploy_db, scheme);
+//	kdb_deploy_scheme(deploy_db, scheme);
 	kdb_fini(deploy_db);
 	kdb_free(deploy_db);
 	}
 
+	// Parsing
+	{
+	kparse_status_e pstatus = KPARSE_NONE;
+	char *s = NULL;
+	const char *line = "cmd m8 e1";
+	kpargv_t *pargv = NULL;
 	session = ksession_new(scheme, NULL);
-	ksession_parse_line(session, "cmd m1 e1");
+	pstatus = ksession_parse_line(session, line, &pargv);
+	switch (pstatus) {
+	case KPARSE_NONE:
+		s = "None";
+		break;
+	case KPARSE_OK:
+		s = "Ok";
+		break;
+	case KPARSE_INPROGRESS:
+		s = "In progress";
+		break;
+	case KPARSE_NOTFOUND:
+		s = "Not found";
+		break;
+	case KPARSE_INCOMPLETED:
+		s = "Incompleted";
+		break;
+	case KPARSE_ILLEGAL:
+		s = "Illegal";
+		break;
+	case KPARSE_ERROR:
+		s = "Error";
+		break;
+	}
+	printf("Line '%s': %s\n", line, s);
+	}
+
 goto err; // Test purposes
 
 	// Listen socket

+ 2 - 2
klish/kscheme/kentry.c

@@ -149,7 +149,6 @@ static void kentry_free_non_link(kentry_t *entry)
 		return;
 
 	faux_str_free(entry->ptype_str);
-	faux_str_free(entry->value);
 
 	faux_list_free(entry->entrys);
 	faux_list_free(entry->actions);
@@ -162,6 +161,7 @@ static void kentry_free_common(kentry_t *entry)
 		return;
 
 	faux_str_free(entry->name);
+	faux_str_free(entry->value);
 	faux_str_free(entry->help);
 	faux_str_free(entry->ref_str);
 }
@@ -208,7 +208,7 @@ bool_t kentry_link(kentry_t *dst, const kentry_t *src)
 	dst->ptype_str = src->ptype_str;
 	dst->ptype = src->ptype;
 	// ref_str - orig
-	dst->value = src->value;
+	// value - orig
 	dst->restore = src->restore;
 	dst->entrys = src->entrys;
 	dst->actions = src->actions;

+ 12 - 1
klish/ksession.h

@@ -13,6 +13,16 @@
 
 typedef struct ksession_s ksession_t;
 
+typedef enum {
+	KPARSE_NONE,
+	KPARSE_OK,
+	KPARSE_INPROGRESS,
+	KPARSE_NOTFOUND,
+	KPARSE_INCOMPLETED,
+	KPARSE_ILLEGAL,
+	KPARSE_ERROR,
+} kparse_status_e;
+
 
 C_DECL_BEGIN
 
@@ -22,7 +32,8 @@ void ksession_free(ksession_t *session);
 const kscheme_t *ksession_scheme(const ksession_t *session);
 kpath_t *ksession_path(const ksession_t *session);
 
-kpargv_t *ksession_parse_line(ksession_t *session, const char *line);
+kparse_status_e ksession_parse_line(ksession_t *session, const char *line,
+	kpargv_t **parsed_argv);
 
 
 C_DECL_END

+ 27 - 21
klish/ksession/ksession_parse.c

@@ -13,16 +13,6 @@
 #include <klish/kpargv.h>
 #include <klish/ksession.h>
 
-typedef enum {
-	KPARSE_NONE,
-	KPARSE_OK,
-	KPARSE_INPROGRESS,
-	KPARSE_NOTFOUND,
-	KPARSE_INCOMPLETED,
-	KPARSE_ILLEGAL,
-	KPARSE_ERROR,
-} kparse_status_e;
-
 
 static bool_t ksession_validate_arg(kentry_t *entry, const char *arg)
 {
@@ -156,43 +146,59 @@ static kparse_status_e ksession_parse_arg(kentry_t *current_entry,
 }
 
 
-kpargv_t *ksession_parse_line(ksession_t *session, const char *line)
+kparse_status_e ksession_parse_line(ksession_t *session, const char *line,
+	kpargv_t **parsed_argv)
 {
 	faux_argv_t *argv = NULL;
 	faux_argv_node_t *argv_iter = NULL;
 	kentry_t *current_entry = NULL;
 	kpargv_t *pargv = NULL;
+	kparse_status_e pstatus = KPARSE_NONE;
 
+	if (parsed_argv)
+		*parsed_argv = NULL;
 	assert(session);
 	if (!session)
-		return NULL;
+		return KPARSE_ERROR;
 	assert(line);
 	if (!line)
-		return NULL;
+		return KPARSE_ERROR;
 
 	// Split line to arguments
 	argv = faux_argv_new();
 	assert(argv);
 	if (!argv)
-		return NULL;
-	if (faux_argv_parse(argv, line) <= 0) {
+		return KPARSE_ERROR;
+	if (faux_argv_parse(argv, line) < 0) {
 		faux_argv_free(argv);
-		return NULL;
+		return KPARSE_ERROR;
 	}
+printf("AAAAAAAAAAA %ld\n", faux_argv_len(argv));
 	argv_iter = faux_argv_iter(argv);
 
 	current_entry = klevel_entry(kpath_current(ksession_path(session)));
 	pargv = kpargv_new();
 	assert(pargv);
 
-	ksession_parse_arg(current_entry, &argv_iter, pargv);
-
-	printf("KKKKKKKKK %ld\n", kpargv_pargs_len(pargv));
+	pstatus = ksession_parse_arg(current_entry, &argv_iter, pargv);
+	// It's a higher level of parsing, so some statuses can have different
+	// meanings
+/*	if (KPARSE_NONE == pstatus)
+		pstatus = KPARSE_ERROR; // Strange case
+	else if (KPARSE_INPROGRESS == pstatus) {
+		if (NULL == argv_iter) // All args are parsed
+			pstatus = KPARSE_OK;
+		else
+			pstatus = KPARSE_ILLEGAL; // Additional not parsable args
+	}
+*/
+printf("KKKKKKKKK %ld\n", kpargv_pargs_len(pargv));
 
 	if (kpargv_pargs_is_empty(pargv)) {
 		kpargv_free(pargv);
-		return NULL;
+		pargv = NULL;
 	}
+	*parsed_argv = pargv;
 
-	return pargv;
+	return pstatus;
 }