Browse Source

Log __full_line instead __line

git-svn-id: https://klish.googlecode.com/svn/trunk@492 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
163594d8ff
3 changed files with 31 additions and 11 deletions
  1. 1 0
      clish/shell.h
  2. 9 6
      clish/shell/shell_execute.c
  3. 21 5
      clish/shell/shell_var.c

+ 1 - 0
clish/shell.h

@@ -344,6 +344,7 @@ bool_t clish_shell__get_utf8(const clish_shell_t * instance);
 void clish_shell__set_utf8(clish_shell_t * instance, bool_t utf8);
 void clish_shell__set_timeout(clish_shell_t *instance, int timeout);
 char *clish_shell__get_line(clish_context_t *context);
+char *clish_shell__get_full_line(clish_context_t *context);
 char *clish_shell__get_params(clish_context_t *context);
 
 _END_C_DECL

+ 9 - 6
clish/shell/shell_execute.c

@@ -187,7 +187,6 @@ int clish_shell_execute(clish_context_t *context, char **out)
 	sigset_t old_sigs;
 	struct sigaction old_sigint, old_sigquit;
 	clish_view_t *cur_view = clish_shell__get_view(this);
-	char *line = clish_shell__get_line(context);
 
 	assert(cmd);
 	action = clish_command__get_action(cmd);
@@ -276,8 +275,11 @@ int clish_shell_execute(clish_context_t *context, char **out)
 		this->client_hooks->config_fn(context);
 
 	/* Call logging callback */
-	if (this->client_hooks->log_fn)
-		this->client_hooks->log_fn(context, line, result);
+	if (this->client_hooks->log_fn) {
+		char *full_line = clish_shell__get_full_line(context);
+		this->client_hooks->log_fn(context, full_line, result);
+		lub_string_free(full_line);
+	}
 
 	/* Unlock the lockfile */
 	if (lock_fd != -1) {
@@ -289,14 +291,15 @@ int clish_shell_execute(clish_context_t *context, char **out)
 	if (!result) {
 		clish_view_t *view = clish_command__get_view(cmd);
 		/* Save the PWD */
-		if (view)
+		if (view) {
+			char *line = clish_shell__get_line(context);
 			clish_shell__set_pwd(this, line, view,
 				clish_command__get_viewid(cmd), context);
+			lub_string_free(line);
+		}
 	}
 
 error:
-	lub_string_free(line);
-
 	return result;
 }
 

+ 21 - 5
clish/shell/shell_var.c

@@ -74,8 +74,9 @@ static char *find_context_var(const char *name, clish_context_t *this)
 		result = lub_string_dup(clish_command__get_name(
 			clish_command__get_orig(this->cmd)));
 	} else if (!lub_string_nocasecmp(name, "__line")) {
-		if (this->pargv)
-			result = clish_shell__get_line(this);
+		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);
@@ -356,15 +357,18 @@ char *clish_shell__get_params(clish_context_t *context)
 }
 
 /*--------------------------------------------------------- */
-char *clish_shell__get_line(clish_context_t *context)
+static char *internal_get_line(clish_context_t *context, int cmd_type)
 {
 	const clish_command_t *cmd = context->cmd;
 	clish_pargv_t *pargv = context->pargv;
 	char *line = NULL;
 	char *params = NULL;
 
-	lub_string_cat(&line, clish_command__get_name(
-		clish_command__get_cmd(cmd)));
+	if (0 == cmd_type) /* __cmd */
+		lub_string_cat(&line, clish_command__get_name(
+			clish_command__get_cmd(cmd)));
+	else /* __full_cmd */
+		lub_string_cat(&line, clish_command__get_name(cmd));
 
 	if (!pargv)
 		return line;
@@ -379,6 +383,18 @@ char *clish_shell__get_line(clish_context_t *context)
 	return line;
 }
 
+/*--------------------------------------------------------- */
+char *clish_shell__get_line(clish_context_t *context)
+{
+	return internal_get_line(context, 0); /* __cmd */
+}
+
+/*--------------------------------------------------------- */
+char *clish_shell__get_full_line(clish_context_t *context)
+{
+	return internal_get_line(context, 1); /* __full_cmd */
+}
+
 /*--------------------------------------------------------- */
 char *clish_shell_expand_var(const char *name, clish_context_t *context)
 {