Forráskód Böngészése

Use the new INI-like parser to get Lua scripts dir from XML

Stanislav Galabov 11 éve
szülő
commit
a010cf7752

+ 2 - 2
plugins/lua/lua_init.c

@@ -71,10 +71,10 @@ int clish_plugin_init_lua(clish_shell_t *shell)
 	luaL_openlibs(L);
 
 	if (scripts_path && !load_scripts(L, scripts_path)) {
-		free(scripts_path);
+		lub_string_free(scripts_path);
 		return (-1);
 	}
-	free(scripts_path);
+	lub_string_free(scripts_path);
 
 	clish_shell__set_udata(shell, LUA_UDATA, L);
 

+ 8 - 24
plugins/lua/plugin_init.c

@@ -1,35 +1,19 @@
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
+#include <lub/ini.h>
+#include <lub/string.h>
 
 #include "private.h"
 
-static char * trim(char *str)
-{
-	size_t len = 0;
-	const char *first = str;
-	char *last = str + strlen(str) - 1;
-	char *new = NULL;
-
-	while (first < last && isspace(*first))
-		++first;
-	while (first < last && isspace(*last))
-		--last;
-
-	len = last - first + 1;
-	new = malloc(len + 1);
-	memcpy(new, first, len);
-	new[len] = '\0';
-
-	return new;
-}
-
 CLISH_PLUGIN_INIT
 {
+	lub_ini_t *ini;
 	char *conf = clish_plugin__get_conf(plugin);
 
 	if (conf) {
-		scripts_path = trim(conf);
+		ini = lub_ini_new();
+		lub_ini_parse_str(ini, conf);
+		scripts_path =
+			lub_string_dup(lub_ini_find(ini, LUA_SCRIPTS_DIR));
+		lub_ini_free(ini);
 	}
 
 	if(clish_plugin_init_lua(clish_shell))

+ 1 - 0
plugins/lua/private.h

@@ -8,6 +8,7 @@
 #include <lauxlib.h>
 
 #define LUA_UDATA "lua_state"
+#define LUA_SCRIPTS_DIR "scripts_dir"
 #define LUA_PLUGIN_NAME "lua"
 
 extern char *scripts_path;

+ 1 - 1
xml-examples/lua/startup.xml

@@ -5,7 +5,7 @@
                      http://clish.sourceforge.net/XMLSchema/clish.xsd">
 
      <PLUGIN name="lua" file="clish_plugin_lua.so">
-	 /usr2/klish-rw/xml-examples/lua
+	 scripts_dir="/usr2/klish-rw/xml-examples/lua"
      </PLUGIN>
      <HOOK name="action" builtin="lua@lua"/>