[SCM] Development fot GoFind! branch, master, updated. 291c5c6c63c87a63249fa042dc91c5453b3dde6e

Miriam Ruiz miriam at miriam.princast.es
Mon Nov 24 18:03:31 UTC 2008


The following commit has been merged in the master branch:
commit 291c5c6c63c87a63249fa042dc91c5453b3dde6e
Author: Miriam Ruiz <miriam at miriam.princast.es>
Date:   Mon Nov 24 19:08:04 2008 +0100

    Changed x-www-browser by sensible-browser
    Removed -Werror from Makefile
    Fixed lua plugin

diff --git a/Makefile b/Makefile
index 1fb3fe3..b6888eb 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-CFLAGS= -O2 -g `pkg-config libtagcoll2 boolstuff-0.1 --cflags` -Wall -Werror -fPIC
+CFLAGS= -O2 -g `pkg-config libtagcoll2 boolstuff-0.1 --cflags` -Wall -fPIC
 #LDFLAGS= -Wl,-z,defs -Wl,--as-needed -Wl,--no-undefined
 LDFLAGS= 
 LIBS= -lept -lept-core -lapt-pkg -lxapian -ldl `pkg-config libtagcoll2 boolstuff-0.1 --libs`
diff --git a/fltk/aux.cpp b/fltk/aux.cpp
index 4319c58..ef9cdd2 100644
--- a/fltk/aux.cpp
+++ b/fltk/aux.cpp
@@ -49,7 +49,7 @@ bool HTMLView::ExternalBrowser(const std::string &uri)
 		return true;
 
 	/* A zero PID indicates that this is the child process */
-	std::string command = std::string("/usr/bin/x-www-browser \"") + uri +"\"";
+	std::string command = std::string("/usr/bin/sensible-browser \"") + uri +"\"";
 	if (execl("/bin/sh", "sh", "-c", command.c_str(), (char *) 0) == -1)
 		ERROR_PRINTF("exec: %s\n", strerror(errno));
 
diff --git a/gui_lua.cpp b/gui_lua.cpp
index b328610..44941fc 100644
--- a/gui_lua.cpp
+++ b/gui_lua.cpp
@@ -52,9 +52,14 @@ using namespace ept::textsearch;
 #include <stdlib.h>
 #include <stdio.h>
 
-extern "C" int init(int argc, const char *argv[])
+static int argc = 0;
+static const char **argv = NULL;
+
+extern "C" int init(int _argc, const char *_argv[])
 {
 	std::cout << _("Lua Plugin successfully loaded") << std::endl;
+	argc = _argc;
+	argv = _argv;
 	return 1; // true
 }
 
@@ -63,6 +68,240 @@ extern "C" void comment(const char *text)
 	std::cout << "# " << text << std::endl;
 }
 
+/******************************************************************************
+ * Copyright (C) 1994-2008 Lua.org, PUC-Rio.  All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ ******************************************************************************/
+
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define lua_c
+
+#include <lua.hpp>
+
+static lua_State *globalL = NULL;
+
+static void lstop (lua_State *L, lua_Debug *ar)
+{
+	(void)ar; /* unused arg. */
+	lua_sethook(L, NULL, 0, 0);
+	luaL_error(L, "interrupted!");
+}
+
+
+static void laction (int i)
+{
+	signal(i, SIG_DFL);
+	/* if another SIGINT happens before lstop, terminate process (default action) */
+	lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
+}
+
+
+static void l_message (const char *msg)
+{
+	fprintf(stderr, "%s\n", msg);
+	fflush(stderr);
+}
+
+
+static int report (lua_State *L, int status)
+{
+	if (status && !lua_isnil(L, -1))
+	{
+		const char *msg = lua_tostring(L, -1);
+		if (msg == NULL) msg = "(error object is not a string)";
+		l_message(msg);
+		lua_pop(L, 1);
+	}
+	return status;
+}
+
+
+static int traceback (lua_State *L)
+{
+	if (!lua_isstring(L, 1)) /* 'message' not a string? */
+		return 1; /* keep it intact */
+	lua_getfield(L, LUA_GLOBALSINDEX, "debug");
+	if (!lua_istable(L, -1))
+	{
+		lua_pop(L, 1);
+		return 1;
+	}
+	lua_getfield(L, -1, "traceback");
+	if (!lua_isfunction(L, -1))
+	{
+		lua_pop(L, 2);
+		return 1;
+	}
+	lua_pushvalue(L, 1); /* pass error message */
+	lua_pushinteger(L, 2); /* skip this function and traceback */
+	lua_call(L, 2, 1); /* call debug.traceback */
+	return 1;
+}
+
+
+static int docall (lua_State *L, int narg, int clear)
+{
+	int status;
+	/* function index */
+	int base = lua_gettop(L) - narg;
+	/* push traceback function */
+	lua_pushcfunction(L, traceback);
+	lua_insert(L, base); /* put it under chunk and args */
+	signal(SIGINT, laction);
+	status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
+	signal(SIGINT, SIG_DFL);
+	lua_remove(L, base); /* remove traceback function */
+	/* force a complete garbage collection in case of errors */
+	if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);
+	return status;
+}
+
+
+static void print_version (void)
+{
+	l_message(LUA_RELEASE "  " LUA_COPYRIGHT);
+}
+
+
+static int getargs (lua_State *L, const char **argv)
+{
+	int argc = 0;
+	while (argv[argc]) argc++; /* count total number of arguments */
+
+	luaL_checkstack(L, argc + 3, "too many arguments to script");
+
+	int i;
+	for (i=0; i < argc; i++)
+		lua_pushstring(L, argv[i]);
+
+	return argc;
+}
+
+
+static int dofile (lua_State *L, const char *name)
+{
+	int status = luaL_loadfile(L, name) || docall(L, 0, 1);
+	return report(L, status);
+}
+
+
+static int dostring (lua_State *L, const char *s, const char *name)
+{
+	int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1);
+	return report(L, status);
+}
+
+
+static int dolibrary (lua_State *L, const char *name)
+{
+	lua_getglobal(L, "require");
+	lua_pushstring(L, name);
+	return report(L, docall(L, 1, 1));
+}
+
+
+static int handle_script (lua_State *L, const char *fname, const char **argv)
+{
+	int status;
+	/* collect arguments */
+	int narg = getargs(L, argv);
+	status = luaL_loadfile(L, fname);
+	lua_insert(L, -(narg+1));
+	if (status == 0)
+		status = docall(L, narg, 0);
+	else
+		lua_pop(L, narg);
+	return report(L, status);
+}
+
+
+static int load_library (lua_State *L, const char *filename)
+{
+	lua_assert(filename != NULL);
+	if (dolibrary(L, filename))
+		return 1; /* stop if file fails */
+	return 0;
+}
+
+
+static int handle_luainit (lua_State *L)
+{
+	const char *init = getenv(LUA_INIT);
+	if (init == NULL) return 0; /* status OK */
+	else if (init[0] == '@')
+		return dofile(L, init+1);
+	else
+		return dostring(L, init, "=" LUA_INIT);
+}
+
+
+struct Smain
+{
+	Smain(int _argc, const char **_argv) : script("lua/script.lua"), argc(_argc), argv(_argv), status(0) { }
+	const char *script;
+	const int argc;
+	const char **argv;
+	int status;
+};
+
+static int pmain (lua_State *L)
+{
+	struct Smain *s = (struct Smain *)lua_touserdata(L, 1);
+	globalL = L;
+	lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
+	luaL_openlibs(L); /* open libraries */
+	lua_gc(L, LUA_GCRESTART, 0);
+	s->status = handle_luainit(L);
+	if (s->status != 0) return 0;
+	printf("Starting LUA Script\n");
+	if (s->script)
+		s->status = handle_script(L, s->script, s->argv);
+	printf("Finished LUA Script\n");
+	if (s->status != 0) return 0;
+	return 0;
+}
+
+
+extern "C" int go(PackageData &pkgdata)
+{
+	int status;
+	struct Smain s(argc, argv);
+	lua_State *L = lua_open(); /* create state */
+	if (L == NULL)
+	{
+		l_message("cannot create state: not enough memory");
+		return EXIT_FAILURE;
+	}
+	status = lua_cpcall(L, &pmain, &s);
+	report(L, status);
+	lua_close(L);
+	return (status || s.status) ? 0 /* FAILURE */ : 1 /* SUCCESS */;
+}
+
+
+
 /* Declare the Lua libraries we wish to use. */
 /* Note: If you are opening and running a file containing Lua code */
 /* using 'lua_dofile(l, "myfile.lua") - you must delcare all the libraries */
@@ -84,25 +323,3 @@ static void openlualibs(lua_State *l)
                	lua_settop(l, 0);
        	}
 }
-
-extern "C" int go(PackageData &pkgdata)
-{
-	/* Declare a Lua State, open the Lua State and load the libraries (see above). */
-	lua_State *l;
-	l = lua_open();
-	openlualibs(l);
-
-	/* You can do what you want here. Note: Remember to update the libraries used (see above) */
-	/* if you add to your program and use new Lua libraries. */
-	/* In the lines below, I load and run the Lua code contained in the file */
-	/* "script.lua". */
-	/* Plus print some text directly from C. */
-	std::cout << "Starting Lua Script" << std::endl;
-	luaL_dofile(l, "lua/script.lua");
-	std::cout << "Finished Lua Script" << std::endl;
-
-	/* Remember to destroy the Lua State */
-	lua_close(l);
-
-	return 1;
-}

-- 
Development fot GoFind!



More information about the Pkg-games-commits mailing list