Переглянути джерело

Some context API for shell_execute.c

Serj Kalichev 11 роки тому
батько
коміт
744bacdd1b
2 змінених файлів з 10 додано та 11 видалено
  1. 6 7
      clish/shell/shell_execute.c
  2. 4 4
      clish/shell/shell_startup.c

+ 6 - 7
clish/shell/shell_execute.c

@@ -77,8 +77,8 @@ static void clish_shell_unlock(int lock_fd)
 /*----------------------------------------------------------- */
 int clish_shell_execute(clish_context_t *context, char **out)
 {
-	clish_shell_t *this = context->shell;
-	const clish_command_t *cmd = context->cmd;
+	clish_shell_t *this = clish_context__get_shell(context);
+	const clish_command_t *cmd = clish_context__get_cmd(context);
 	int result = 0;
 	char *lock_path = clish_shell__get_lockfile(this);
 	int lock_fd = -1;
@@ -129,7 +129,7 @@ int clish_shell_execute(clish_context_t *context, char **out)
 	}
 
 	/* Execute ACTION */
-	context->action = clish_command__get_action(cmd);
+	clish_context__set_action(context, clish_command__get_action(cmd));
 	result = clish_shell_exec_action(context, out);
 
 	/* Restore SIGINT, SIGQUIT, SIGHUP */
@@ -203,8 +203,8 @@ int clish_shell_exec_action(clish_context_t *context, char **out)
 	clish_sym_t *sym;
 	char *script;
 	clish_hook_action_fn_t *func = NULL;
-	const clish_action_t *action = context->action;
-	clish_shell_t *shell = context->shell;
+	const clish_action_t *action = clish_context__get_action(context);
+	clish_shell_t *shell = clish_context__get_shell(context);
 
 	if (!(sym = clish_action__get_builtin(action)))
 		return 0;
@@ -225,8 +225,7 @@ int clish_shell_exec_action(clish_context_t *context, char **out)
 void *clish_shell_check_hook(const clish_context_t *clish_context, int type)
 {
 	clish_sym_t *sym;
-	clish_context_t *context = (clish_context_t *)clish_context;
-	clish_shell_t *shell = context->shell;
+	clish_shell_t *shell = clish_context__get_shell(clish_context);
 	void *func;
 
 	if (!(sym = shell->hooks[type]))

+ 4 - 4
clish/shell/shell_startup.c

@@ -18,10 +18,10 @@ int clish_shell_startup(clish_shell_t *this)
 	}
 
 	/* Prepare context */
-	context.shell = this;
-	context.cmd = this->startup;
-	context.action = clish_command__get_action(this->startup);
-	context.pargv = NULL;
+	clish_context_init(&context, this);
+	clish_context__set_cmd(&context, this->startup);
+	clish_context__set_action(&context,
+		clish_command__get_action(this->startup));
 
 	banner = clish_command__get_detail(this->startup);
 	if (banner)