Browse Source

Use viewid while 'test' conditions expanding.

git-svn-id: https://klish.googlecode.com/svn/trunk@251 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
db72aa7235

+ 2 - 1
clish/command.h

@@ -41,7 +41,8 @@ clish_command_diff(const clish_command_t * cmd1, const clish_command_t * cmd2);
 void clish_command_delete(clish_command_t * instance);
 void
 clish_command_insert_param(clish_command_t * instance, clish_param_t * param);
-void clish_command_help(const clish_command_t * instance, const char *line);
+void clish_command_help(const clish_command_t * instance, const char *viewid,
+	const char *line);
 void clish_command_dump(const clish_command_t * instance);
 
 /*-----------------

+ 3 - 2
clish/command/command.c

@@ -169,7 +169,8 @@ void clish_command_insert_param(clish_command_t * this, clish_param_t * param)
 }
 
 /*--------------------------------------------------------- */
-void clish_command_help(const clish_command_t * this, const char *line)
+void clish_command_help(const clish_command_t * this, const char * viewid,
+	const char * line)
 {
 	const char *name = clish_command__get_name(this);
 	unsigned index = lub_argv_wordcount(line);
@@ -199,7 +200,7 @@ void clish_command_help(const clish_command_t * this, const char *line)
 	/* get the parameter definition */
 	last = clish_pargv_create();
 	pargv = clish_pargv_create();
-	clish_pargv_parse(pargv, this, this->paramv,
+	clish_pargv_parse(pargv, this, viewid, this->paramv,
 		argv, &idx, last, index);
 	clish_pargv_delete(pargv);
 	cnt = clish_pargv__get_count(last);

+ 8 - 2
clish/pargv.h

@@ -34,7 +34,10 @@ typedef struct clish_parg_s clish_parg_t;
  * meta functions
  *----------------- */
 clish_pargv_t *clish_pargv_new(const clish_command_t * cmd,
-	const char *line, size_t offset, clish_pargv_status_t * status);
+	const char *viewid,
+	const char *line,
+	size_t offset,
+	clish_pargv_status_t * status);
 /*-----------------
  * methods
  *----------------- */
@@ -46,9 +49,12 @@ int clish_pargv_insert(clish_pargv_t * instance,
 	const clish_param_t * param, const char *value);
 clish_pargv_status_t clish_pargv_parse(clish_pargv_t * instance,
 	const clish_command_t * cmd,
+	const char *viewid,
 	clish_paramv_t * paramv,
 	const lub_argv_t * argv,
-	unsigned *idx, clish_pargv_t * last, unsigned need_index);
+	unsigned *idx,
+	clish_pargv_t * last,
+	unsigned need_index);
 void clish_pargv_dump(const clish_pargv_t * instance);
 /*-----------------
  * attributes 

+ 13 - 6
clish/pargv/pargv.c

@@ -97,6 +97,7 @@ static void set_defaults(clish_pargv_t * this, const clish_command_t * cmd)
 clish_pargv_status_t
 clish_pargv_parse(clish_pargv_t * this,
 	const clish_command_t * cmd,
+	const char *viewid,
 	clish_paramv_t * paramv,
 	const lub_argv_t * argv,
 	unsigned *idx, clish_pargv_t * last, unsigned need_index)
@@ -131,7 +132,7 @@ clish_pargv_parse(clish_pargv_t * this,
 		/* Check the 'test' conditions */
 		if (param) {
 			char *str = clish_param__get_test(param,
-				NULL, cmd, this);
+				viewid, cmd, this);
 			if (str && !lub_system_line_test(str)) {
 				lub_string_free(str);
 				index++;
@@ -242,7 +243,8 @@ clish_pargv_parse(clish_pargv_t * this,
 
 				/* Walk through the nested parameters */
 				if (rec_paramc) {
-					retval = clish_pargv_parse(this, NULL, rec_paramv,
+					retval = clish_pargv_parse(this, NULL,
+						viewid, rec_paramv,
 						argv, idx, last, need_index);
 					if (CLISH_LINE_OK != retval)
 						return retval;
@@ -338,13 +340,15 @@ clish_pargv_parse(clish_pargv_t * this,
 /*--------------------------------------------------------- */
 static clish_pargv_status_t
 clish_pargv_init(clish_pargv_t * this,
-		 const clish_command_t * cmd, const lub_argv_t * argv)
+	const clish_command_t * cmd,
+	const char *viewid,
+	const lub_argv_t * argv)
 {
 	unsigned idx = lub_argv_wordcount(clish_command__get_name(cmd));
 
 	this->pargc = 0;
 
-	return clish_pargv_parse(this, cmd,
+	return clish_pargv_parse(this, cmd, viewid,
 		clish_command__get_paramv(cmd),
 		argv, &idx, NULL, 0);
 }
@@ -363,7 +367,10 @@ clish_pargv_t *clish_pargv_create(void)
 
 /*--------------------------------------------------------- */
 clish_pargv_t *clish_pargv_new(const clish_command_t * cmd,
-	const char *line, size_t offset, clish_pargv_status_t * status)
+	const char *viewid,
+	const char *line,
+	size_t offset,
+	clish_pargv_status_t * status)
 {
 	clish_pargv_t *this = NULL;
 	lub_argv_t *argv = NULL;
@@ -376,7 +383,7 @@ clish_pargv_t *clish_pargv_new(const clish_command_t * cmd,
 		return NULL;
 
 	argv = lub_argv_new(line, offset);
-	*status = clish_pargv_init(this, cmd, argv);
+	*status = clish_pargv_init(this, cmd, viewid, argv);
 	lub_argv_delete(argv);
 	switch (*status) {
 	case CLISH_LINE_OK:

+ 5 - 4
clish/shell/shell_command_generator.c

@@ -47,9 +47,10 @@ const clish_command_t *clish_shell_find_next_completion(const clish_shell_t *
 
 /*--------------------------------------------------------- */
 static char *clish_shell_param_generator(clish_shell_t * this,
-					    const clish_command_t * cmd,
-					    const char *line,
-					    unsigned offset, unsigned state)
+	const clish_command_t * cmd,
+	const char *line,
+	unsigned offset,
+	unsigned state)
 {
 	char *result = NULL;
 	const char *name = clish_command__get_name(cmd);
@@ -80,7 +81,7 @@ static char *clish_shell_param_generator(clish_shell_t * this,
 			}
 			this->context.completion_pargv = clish_pargv_create();
 			pargv = clish_pargv_create();
-			clish_pargv_parse(pargv, cmd, clish_command__get_paramv(cmd),
+			clish_pargv_parse(pargv, cmd, this->viewid, clish_command__get_paramv(cmd),
 				argv, &idx, this->context.completion_pargv, index + idx);
 			clish_pargv_delete(pargv);
 			lub_argv_delete(argv);

+ 2 - 2
clish/shell/shell_help.c

@@ -107,14 +107,14 @@ void clish_shell_help(clish_shell_t * this, const char *line)
 					fprintf(stderr, "%s\n", detail);
 				} else {
 					/* get the command to describe itself */
-					clish_command_help(cmd, line);
+					clish_command_help(cmd, this->viewid, line);
 				}
 				break;
 			}
 		case SHELL_STATE_READY:
 		case SHELL_STATE_SCRIPT_ERROR:
 			/* get the command to provide help */
-			clish_command_help(cmd, line);
+			clish_command_help(cmd, this->viewid, line);
 			break;
 		case SHELL_STATE_INITIALISING:
 		case SHELL_STATE_CLOSING:

+ 1 - 1
clish/shell/shell_parse.c

@@ -15,7 +15,7 @@ clish_pargv_status_t clish_shell_parse(
 	*cmd = clish_shell_resolve_command(this, line);
 	/* Now construct the parameters for the command */
 	if (NULL != *cmd)
-		*pargv = clish_pargv_new(*cmd, line, 0, &result);
+		*pargv = clish_pargv_new(*cmd, this->viewid, line, 0, &result);
 	if (*pargv) {
 		char str[100];
 		char * tmp;