浏览代码

kpargv_status_str()

Serj Kalichev 3 年之前
父节点
当前提交
6d7eeab1e0
共有 3 个文件被更改,包括 39 次插入25 次删除
  1. 1 25
      bin/klishd/klishd.c
  2. 2 0
      klish/kpargv.h
  3. 36 0
      klish/ksession/kpargv.c

+ 1 - 25
bin/klishd/klishd.c

@@ -176,7 +176,6 @@ int main(int argc, char **argv)
 
 	// Parsing
 	{
-	char *s = NULL;
 	const char *line = "cmd o1 m7 o2 e1";
 	kpargv_t *pargv = NULL;
 	kpargv_pargs_node_t *p_iter = NULL;
@@ -185,32 +184,9 @@ int main(int argc, char **argv)
 	kpath_push(ksession_path(session), klevel_new(kscheme_find_entry_by_path(scheme, "/main")));
 	pargv = ksession_parse_line(session, line);
 	if (pargv) {
-		switch (kpargv_status(pargv)) {
-		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("Level: %lu, Command: %s, Line '%s': %s\n",
 			kpargv_level(pargv), kentry_name(kpargv_command(pargv)),
-			line, s);
+			line, kpargv_status_str(pargv));
 
 		kparg_t *parg = NULL;
 		p_iter = kpargv_pargs_iter(pargv);

+ 2 - 0
klish/kpargv.h

@@ -46,6 +46,8 @@ void kpargv_free(kpargv_t *pargv);
 // Status
 kpargv_status_e kpargv_status(const kpargv_t *pargv);
 bool_t kpargv_set_status(kpargv_t *pargv, kpargv_status_e status);
+const char *kpargv_status_str(const kpargv_t *pargv);
+
 // Level
 size_t kpargv_level(const kpargv_t *pargv);
 bool_t kpargv_set_level(kpargv_t *pargv, size_t level);

+ 36 - 0
klish/ksession/kpargv.c

@@ -106,3 +106,39 @@ kparg_t *kpargv_entry_exists(const kpargv_t *pargv, const void *entry)
 
 	return (kparg_t *)faux_list_kfind(pargv->pargs, entry);
 }
+
+
+const char *kpargv_status_str(const kpargv_t *pargv)
+{
+	const char *s = "Unknown";
+
+	assert(pargv);
+	if (!pargv)
+		return NULL;
+
+	switch (kpargv_status(pargv)) {
+	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;
+	}
+
+	return s;
+}