Browse Source

Refactoring for __cur_depth, __cur_pwd

Conflicts:
	clish/shell/private.h
Serj Kalichev 10 years ago
parent
commit
8cda8cb62a
5 changed files with 24 additions and 39 deletions
  1. 0 4
      clish/shell/private.h
  2. 0 20
      clish/shell/shell_new.c
  3. 0 14
      clish/shell/shell_parse.c
  4. 1 1
      clish/shell/shell_pwd.c
  5. 23 0
      clish/shell/shell_var.c

+ 0 - 4
clish/shell/private.h

@@ -92,10 +92,6 @@ struct clish_shell_s {
 	lub_list_t *plugins; /* List of plugins */
 	lub_list_t *syms; /* List of all used symbols. Must be resolved. */
 
-	/* Static params for var expanding. The refactoring is needed. */
-	clish_param_t *param_depth;
-	clish_param_t *param_pwd;
-
 	/* Userdata list holder */
 	lub_list_t *udata;
 };

+ 0 - 20
clish/shell/shell_new.c

@@ -78,22 +78,6 @@ static void clish_shell_init(clish_shell_t * this,
 	this->default_plugin = BOOL_TRUE; /* Load default plugin by default */
 
 	/* Create internal ptypes and params */
-	/* Current depth */
-	tmp_ptype = clish_shell_find_create_ptype(this,
-		"__DEPTH", "Depth", "[0-9]+",
-		CLISH_PTYPE_REGEXP, CLISH_PTYPE_NONE);
-	assert(tmp_ptype);
-	this->param_depth = clish_param_new("_cur_depth",
-		"Current depth", tmp_ptype);
-	clish_param__set_hidden(this->param_depth, BOOL_TRUE);
-	/* Current pwd */
-	tmp_ptype = clish_shell_find_create_ptype(this,
-		"__PWD", "Path", ".+",
-		CLISH_PTYPE_REGEXP, CLISH_PTYPE_NONE);
-	assert(tmp_ptype);
-	this->param_pwd = clish_param_new("_cur_pwd",
-		"Current path", tmp_ptype);
-	clish_param__set_hidden(this->param_pwd, BOOL_TRUE);
 	/* Args */
 	tmp_ptype = clish_shell_find_create_ptype(this,
 		"internal_ARGS",
@@ -195,10 +179,6 @@ static void clish_shell_fini(clish_shell_t *this)
 	free(this->pwdv);
 	konf_client_free(this->client);
 
-	/* Free internal params */
-	clish_param_delete(this->param_depth);
-	clish_param_delete(this->param_pwd);
-
 	lub_string_free(this->lockfile);
 	lub_string_free(this->default_shebang);
 	free(this->user);

+ 0 - 14
clish/shell/shell_parse.c

@@ -41,20 +41,6 @@ clish_pargv_status_t clish_shell_parse(
 		clish_pargv_delete(*pargv);
 		*pargv = NULL;
 	}
-	if (*pargv) {
-		char str[100];
-		char * tmp;
-		/* Variable __cur_depth */
-		int depth = clish_shell__get_depth(this);
-		snprintf(str, sizeof(str) - 1, "%u", depth);
-		clish_pargv_insert(*pargv, this->param_depth, str);
-		/* Variable __cur_pwd */
-		tmp = clish_shell__get_pwd_full(this, depth);
-		if (tmp) {
-			clish_pargv_insert(*pargv, this->param_pwd, tmp);
-			lub_string_free(tmp);
-		}
-	}
 
 	return result;
 }

+ 1 - 1
clish/shell/shell_pwd.c

@@ -87,7 +87,7 @@ char *clish_shell__get_pwd_line(const clish_shell_t *this, unsigned int index)
 char *clish_shell__get_pwd_full(const clish_shell_t * this, unsigned int depth)
 {
 	char *pwd = NULL;
-	unsigned i;
+	unsigned int i;
 
 	for (i = 1; i <= depth; i++) {
 		const char *str =

+ 23 - 0
clish/shell/shell_var.c

@@ -57,44 +57,56 @@ static char *find_context_var(const char *name, clish_context_t *this)
 			tinyrl__get_width(shell->tinyrl));
 		tmp[sizeof(tmp) - 1] = '\0';
 		result = strdup(tmp);
+
 	} else if (!lub_string_nocasecmp(name, "_height")) {
 		char tmp[5];
 		snprintf(tmp, sizeof(tmp), "%u",
 			tinyrl__get_height(shell->tinyrl));
 		tmp[sizeof(tmp) - 1] = '\0';
 		result = strdup(tmp);
+
 	} else if (!lub_string_nocasecmp(name, "_watchdog_timeout")) {
 		char tmp[5];
 		snprintf(tmp, sizeof(tmp), "%u", shell->wdog_timeout);
 		tmp[sizeof(tmp) - 1] = '\0';
 		result = strdup(tmp);
+
 	} else if (!this->cmd) { /* The vars dependent on command */
 		return NULL;
+
 	} else if (!lub_string_nocasecmp(name, "_full_cmd")) {
 		result = lub_string_dup(clish_command__get_name(this->cmd));
+
 	} else if (!lub_string_nocasecmp(name, "_cmd")) {
 		result = lub_string_dup(clish_command__get_name(
 			clish_command__get_cmd(this->cmd)));
+
 	} else if (!lub_string_nocasecmp(name, "_orig_cmd")) {
 		result = lub_string_dup(clish_command__get_name(
 			clish_command__get_orig(this->cmd)));
+
 	} else if (!lub_string_nocasecmp(name, "_line")) {
 		result = clish_shell__get_line(this);
+
 	} else if (!lub_string_nocasecmp(name, "_full_line")) {
 		result = clish_shell__get_full_line(this);
+
 	} else if (!lub_string_nocasecmp(name, "_params")) {
 		if (this->pargv)
 			result = clish_shell__get_params(this);
+
 	} else if (!lub_string_nocasecmp(name, "_interactive")) {
 		if (clish_shell__get_interactive(this->shell))
 			result = strdup("1");
 		else
 			result = strdup("0");
+
 	} else if (!lub_string_nocasecmp(name, "_isatty")) {
 		if (tinyrl__get_isatty(this->shell->tinyrl))
 			result = strdup("1");
 		else
 			result = strdup("0");
+
 	} else if (lub_string_nocasestr(name, "_prefix") == name) {
 		int idx = 0;
 		int pnum = 0;
@@ -108,6 +120,17 @@ static char *find_context_var(const char *name, clish_context_t *this)
 			result = lub_string_dup(lub_argv__get_arg(argv, idx));
 			lub_argv_delete(argv);
 		}
+
+	} else if (!lub_string_nocasecmp(name, "_cur_depth")) {
+		char tmp[10];
+		int depth = clish_shell__get_depth(shell);
+		snprintf(tmp, sizeof(tmp), "%u", depth);
+		tmp[sizeof(tmp) - 1] = '\0';
+		result = strdup(tmp);
+
+	} else if (!lub_string_nocasecmp(name, "_cur_pwd")) {
+		int depth = clish_shell__get_depth(shell);
+		result = clish_shell__get_pwd_full(shell, depth);
 	}
 
 	return result;