Browse Source

Use clish_shell_load_plugin() in clish binary

Serj Kalichev 11 years ago
parent
commit
013c1db195
6 changed files with 18 additions and 4 deletions
  1. 8 3
      bin/clish.c
  2. 1 0
      clish/plugin.h
  3. 1 1
      clish/plugin/plugin.c
  4. 3 0
      clish/plugin/plugin_dump.c
  5. 4 0
      clish/shell.h
  6. 1 0
      clish/shell/shell_plugin.c

+ 8 - 3
bin/clish.c

@@ -221,7 +221,7 @@ int main(int argc, char **argv)
 
 	/* Validate command line options */
 	if (utf8 && bit8) {
-		fprintf(stderr, "The -u and -8 options can't be used together.\n");
+		fprintf(stderr, "Error: The -u and -8 options can't be used together.\n");
 		goto end;
 	}
 
@@ -230,7 +230,7 @@ int main(int argc, char **argv)
 		outfd = fopen("/dev/null", "w");
 	shell = clish_shell_new(&my_hooks, NULL, NULL, outfd, stop_on_error);
 	if (!shell) {
-		fprintf(stderr, "Cannot run clish.\n");
+		fprintf(stderr, "Error: Can't run clish.\n");
 		goto end;
 	}
 	/* Load the XML files */
@@ -274,6 +274,11 @@ int main(int argc, char **argv)
 		histfile_expanded = lub_system_tilde_expand(histfile);
 	if (histfile_expanded)
 		clish_shell__restore_history(shell, histfile_expanded);
+	/* Load plugins */
+	if (clish_shell_load_plugins(shell) < 0) {
+		fprintf(stderr, "Error: Can't load plugins.\n");
+		goto end;
+	}
 
 	/* Set source of command stream: files or interactive tty */
 	if(optind < argc) {
@@ -290,7 +295,7 @@ int main(int argc, char **argv)
 	/* Execute startup */
 	running = clish_shell_startup(shell);
 	if (running) {
-		fprintf(stderr, "Cannot startup clish.\n");
+		fprintf(stderr, "Error: Can't startup clish.\n");
 		goto end;
 	}
 

+ 1 - 0
clish/plugin.h

@@ -22,6 +22,7 @@ clish_plugin_fn_t *clish_plugin_get_sym(clish_plugin_t *instance,
 	const char *name);
 int clish_plugin_add_sym(clish_plugin_t *instance,
 	clish_plugin_fn_t *func, const char *name);
+void clish_plugin_dump(const clish_plugin_t *this);
 
 #endif				/* _clish_plugin_h */
 /** @} clish_plugin */

+ 1 - 1
clish/plugin/plugin.c

@@ -152,7 +152,7 @@ void *clish_plugin_load(clish_plugin_t *this)
 	}
 	plugin_init(this);
 
-	return 0;
+	return this->dlhan;
 }
 
 /*--------------------------------------------------------- */

+ 3 - 0
clish/plugin/plugin_dump.c

@@ -24,6 +24,9 @@ void clish_plugin_dump(const clish_plugin_t *this)
 	clish_sym_t *sym;
 
 	lub_dump_printf("plugin(%p)\n", this);
+	lub_dump_printf("name  : %s\n", this->name);
+	lub_dump_printf("file  : %s\n", this->file);
+	lub_dump_printf("dlhan : %p\n", this->dlhan);
 	lub_dump_indent();
 	/* Iterate child elements */
 	for(iter = lub_list__get_head(this->syms);

+ 4 - 0
clish/shell.h

@@ -356,6 +356,10 @@ int clish_shell__restore_history(clish_shell_t *instance, const char *fname);
 void clish_shell__stifle_history(clish_shell_t *instance, unsigned int stifle);
 struct passwd *clish_shell__get_user(clish_shell_t *instance);
 
+/* Plugin functions */
+int clish_shell_load_plugins(clish_shell_t *instance);
+
+
 _END_C_DECL
 
 #endif				/* _clish_shell_h */

+ 1 - 0
clish/shell/shell_plugin.c

@@ -21,6 +21,7 @@ int clish_shell_load_plugins(clish_shell_t *this)
 		plugin = (clish_plugin_t *)lub_list_node__get_data(iter);
 		if (!clish_plugin_load(plugin))
 			return -1;
+		clish_plugin_dump(plugin);
 	}
 
 	return 0;