Browse Source

Hook wrappers. Dryrun config and log.

Serj Kalichev 11 years ago
parent
commit
cec0a286f0
5 changed files with 33 additions and 12 deletions
  1. 12 2
      bin/clish.c
  2. 8 0
      clish/shell.h
  3. 5 4
      clish/shell/shell_execute.c
  4. 6 4
      clish/shell/shell_new.c
  5. 2 2
      clish/shell/shell_startup.c

+ 12 - 2
bin/clish.c

@@ -52,9 +52,11 @@ int main(int argc, char **argv)
 	bool_t bit8 = BOOL_FALSE;
 	bool_t log = BOOL_FALSE;
 	bool_t dryrun = BOOL_FALSE;
+	bool_t dryrun_config = BOOL_FALSE;
 	const char *xml_path = getenv("CLISH_PATH");
 	const char *view = getenv("CLISH_VIEW");
 	const char *viewid = getenv("CLISH_VIEWID");
+
 	FILE *outfd = stdout;
 	bool_t istimeout = BOOL_FALSE;
 	int timeout = 0;
@@ -64,6 +66,7 @@ int main(int argc, char **argv)
 	const char *histfile = "~/.clish_history";
 	char *histfile_expanded = NULL;
 	unsigned int histsize = 50;
+	clish_sym_t *sym = NULL;
 
 	/* Signal vars */
 	struct sigaction sigpipe_act;
@@ -161,8 +164,8 @@ int main(int argc, char **argv)
 		case 'k':
 			lockless = BOOL_TRUE;
 			dryrun = BOOL_TRUE;
-/*			my_hooks.config_fn = NULL;
-*/			break;
+			dryrun_config = BOOL_TRUE;
+			break;
 		case 't':
 			istimeout = BOOL_TRUE;
 			timeout = atoi(optarg);
@@ -271,6 +274,13 @@ int main(int argc, char **argv)
 		goto end;
 	if (clish_shell_link_plugins(shell) < 0)
 		goto end;
+	/* Dryrun config and log hooks */
+	if (dryrun_config) {
+		if ((sym = clish_shell_get_hook(shell, CLISH_SYM_TYPE_CONFIG)))
+			clish_sym__set_permanent(sym, BOOL_FALSE);
+		if ((sym = clish_shell_get_hook(shell, CLISH_SYM_TYPE_LOG)))
+			clish_sym__set_permanent(sym, BOOL_FALSE);
+	}
 
 	/* Set source of command stream: files or interactive tty */
 	if(optind < argc) {

+ 8 - 0
clish/shell.h

@@ -182,6 +182,14 @@ clish_sym_t *clish_shell_add_unresolved_sym(clish_shell_t *instance,
 	const char *name, int type);
 clish_sym_t *clish_shell_get_hook(const clish_shell_t *instance, int type);
 
+/* Hook wrappers */
+void *clish_shell_check_hook(const clish_context_t *clish_context, int type);
+CLISH_HOOK_INIT(clish_shell_exec_init);
+CLISH_HOOK_FINI(clish_shell_exec_fini);
+CLISH_HOOK_ACCESS(clish_shell_exec_access);
+CLISH_HOOK_CONFIG(clish_shell_exec_config);
+CLISH_HOOK_LOG(clish_shell_exec_log);
+
 _END_C_DECL
 
 #endif				/* _clish_shell_h */

+ 5 - 4
clish/shell/shell_execute.c

@@ -149,13 +149,14 @@ int clish_shell_execute(clish_context_t *context, char **out)
 	}
 
 	/* Call config callback */
-	if (!result && this->hooks_config)
-		SYM_FN(config,this->hooks_config)(context);
+	if (!result)
+		clish_shell_exec_config(context);
 
 	/* Call logging callback */
-	if (clish_shell__get_log(this) && this->hooks_log) {
+	if (clish_shell__get_log(this) &&
+		clish_shell_check_hook(context, CLISH_SYM_TYPE_LOG)) {
 		char *full_line = clish_shell__get_full_line(context);
-		SYM_FN(log,this->hooks_log)(context, full_line, result);
+		clish_shell_exec_log(context, full_line, result);
 		lub_string_free(full_line);
 	}
 

+ 6 - 4
clish/shell/shell_new.c

@@ -219,11 +219,13 @@ clish_shell_t *clish_shell_new(
 }
 
 /*--------------------------------------------------------- */
-void clish_shell_delete(clish_shell_t * this)
+void clish_shell_delete(clish_shell_t *this)
 {
-	/* now call the client finalisation */
-	if (this->hooks[CLISH_SYM_TYPE_FINI])
-		SYM_FN(fini,this->hooks_fini)(this);
+	clish_context_t context;
+	context.shell = this;
+
+	/* Now call the client finalization */
+	clish_shell_exec_fini(&context);
 	clish_shell_fini(this);
 
 	free(this);

+ 2 - 2
clish/shell/shell_startup.c

@@ -25,8 +25,8 @@ int clish_shell_startup(clish_shell_t *this)
 	context.pargv = NULL;
 	
 	/* Call log initialize */
-	if (clish_shell__get_log(this) && this->hooks_log)
-		SYM_FN(log,this->hooks_log)(&context, NULL, 0);
+	if (clish_shell__get_log(this))
+		clish_shell_exec_log(&context, NULL, 0);
 	/* Call startup script */
 	res = clish_shell_execute(&context, NULL);