diff options
-rw-r--r-- | Makefile | 70 | ||||
-rw-r--r-- | README | 43 | ||||
-rw-r--r-- | examples/config/config | 8 | ||||
-rw-r--r-- | examples/data/plugins/cookies.py | 2 | ||||
-rwxr-xr-x | examples/data/scripts/auth.py | 2 | ||||
-rwxr-xr-x | examples/data/scripts/download.sh | 1 | ||||
-rwxr-xr-x | examples/data/scripts/follow.sh | 2 | ||||
-rwxr-xr-x | examples/data/scripts/formfiller.sh | 2 | ||||
-rwxr-xr-x | examples/data/scripts/load_cookies.sh | 4 | ||||
-rwxr-xr-x | examples/data/scripts/per-site-settings.py | 2 | ||||
-rwxr-xr-x | examples/data/scripts/scheme.py | 2 | ||||
-rwxr-xr-x | examples/data/scripts/session.sh | 6 | ||||
-rw-r--r-- | examples/data/scripts/util/dmenu.sh | 12 | ||||
-rwxr-xr-x | misc/env.sh | 4 | ||||
-rw-r--r-- | src/uzbl-core.c | 64 | ||||
-rw-r--r-- | src/uzbl-core.h | 4 | ||||
-rw-r--r-- | tests/Makefile | 36 | ||||
-rw-r--r-- | tests/test-command.c | 38 |
18 files changed, 131 insertions, 171 deletions
@@ -1,6 +1,12 @@ # first entries are for gnu make, 2nd for BSD make. see http://lists.uzbl.org/pipermail/uzbl-dev-uzbl.org/2009-July/000177.html -REQ_PKGS = libsoup-2.4 gthread-2.0 glib-2.0 +# packagers, set DESTDIR to your "package directory" and PREFIX to the prefix you want to have on the end-user system +# end-users who build from source: don't care about DESTDIR, update PREFIX if you want to +# RUN_PREFIX : what the prefix is when the software is run. usually the same as PREFIX +PREFIX?=/usr/local +INSTALLDIR?=$(DESTDIR)$(PREFIX) +DOCDIR?=$(INSTALLDIR)/share/uzbl/docs +RUN_PREFIX?=$(PREFIX) # gtk2 REQ_PKGS += gtk+-2.0 webkit-1.0 @@ -8,53 +14,58 @@ CPPFLAGS = # gtk3 #REQ_PKGS += gtk+-3.0 webkitgtk-3.0 -#CPPFLAG = -DG_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED +#CPPFLAGS = -DG_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED + +# --- configuration ends here --- + +REQ_PKGS += libsoup-2.4 gthread-2.0 glib-2.0 + +ARCH:=$(shell uname -m) +ARCH!=echo `uname -m` + +COMMIT_HASH:=$(shell ./misc/hash.sh) +COMMIT_HASH!=echo `./misc/hash.sh` + +CPPFLAGS += -DARCH=\"$(ARCH)\" -DCOMMIT=\"$(COMMIT_HASH)\" -CFLAGS:=-std=c99 $(shell pkg-config --cflags $(REQ_PKGS)) -ggdb -Wall -W -DARCH="\"$(shell uname -m)\"" -lgthread-2.0 -DCOMMIT="\"$(shell ./misc/hash.sh)\"" $(CPPFLAGS) -fPIC -W -Wall -Wextra -pedantic -CFLAGS!=echo -std=c99 `pkg-config --cflags $(REQ_PKGS)` -ggdb -Wall -W -DARCH='"\""'`uname -m`'"\""' -lgthread-2.0 -DCOMMIT='"\""'`./misc/hash.sh`'"\""' $(CPPFLAGS) -fPIC -W -Wall -Wextra -pedantic +PKG_CFLAGS:=$(shell pkg-config --cflags $(REQ_PKGS)) +PKG_CFLAGS!=echo pkg-config --cflags $(REQ_PKGS) -UZBL_LDFLAGS:=$(shell pkg-config --libs $(REQ_PKGS) x11) -pthread $(LDFLAGS) -UZBL_LDFLAGS!=echo `pkg-config --libs $(REQ_PKGS) x11` -pthread $(LDFLAGS) +LDLIBS:=$(shell pkg-config --libs $(REQ_PKGS) x11) +LDLIBS!=echo pkg-config --libs $(REQ_PKGS) x11 + +CFLAGS += -std=c99 $(PKG_CFLAGS) -ggdb -W -Wall -Wextra -pedantic -pthread SRC = $(wildcard src/*.c) HEAD = $(wildcard src/*.h) -OBJ = $(foreach obj, $(SRC:.c=.o), $(notdir $(obj))) +OBJ = $(foreach obj, $(SRC:.c=.o), $(notdir $(obj))) +LOBJ = $(foreach obj, $(SRC:.c=.lo), $(notdir $(obj))) all: uzbl-browser uzbl-cookie-manager VPATH:=src -.c.o: - @echo -e "${CC} -c ${CFLAGS} $<" - @${CC} -c ${CFLAGS} $< - ${OBJ}: ${HEAD} uzbl-core: ${OBJ} - @echo -e "\n${CC} -o $@ ${OBJ} ${UZBL_LDFLAGS}" - @${CC} -o $@ ${OBJ} ${UZBL_LDFLAGS} -uzbl-cookie-manager: examples/uzbl-cookie-manager.o src/util.o - @echo -e "\n${CC} -o $@ uzbl-cookie-manager.o util.o ${LDFLAGS} ${shell pkg-config --libs glib-2.0 libsoup-2.4}" - @${CC} -o $@ uzbl-cookie-manager.o util.o ${LDFLAGS} $(shell pkg-config --libs glib-2.0 libsoup-2.4) +uzbl-cookie-manager: examples/uzbl-cookie-manager.o util.o + @echo -e "\n${CC} -o $@ examples/uzbl-cookie-manager.o util.o ${shell pkg-config --libs glib-2.0 libsoup-2.4}" + @${CC} -o $@ examples/uzbl-cookie-manager.o util.o $(shell pkg-config --libs glib-2.0 libsoup-2.4) uzbl-browser: uzbl-core uzbl-cookie-manager -# packagers, set DESTDIR to your "package directory" and PREFIX to the prefix you want to have on the end-user system -# end-users who build from source: don't care about DESTDIR, update PREFIX if you want to -# RUN_PREFIX : what the prefix is when the software is run. usually the same as PREFIX -PREFIX?=/usr/local -INSTALLDIR?=$(DESTDIR)$(PREFIX) -DOCDIR?=$(INSTALLDIR)/share/uzbl/docs -RUN_PREFIX?=$(PREFIX) - # the 'tests' target can never be up to date .PHONY: tests force: +# this is here because the .so needs to be compiled with -fPIC on x86_64 +${LOBJ}: ${SRC} ${HEAD} + $(CC) $(CPPFLAGS) $(CFLAGS) -fPIC -c src/$(@:.lo=.c) -o $@ + # When compiling unit tests, compile uzbl as a library first -tests: ${OBJ} force - $(CC) -shared -Wl ${OBJ} -o ./tests/libuzbl-core.so +tests: ${LOBJ} force + $(CC) -shared -Wl ${LOBJ} -o ./tests/libuzbl-core.so cd ./tests/; $(MAKE) test-uzbl-core: uzbl-core @@ -100,12 +111,7 @@ test-uzbl-tabbed-sandbox: uzbl-browser clean: rm -f uzbl-core rm -f uzbl-cookie-manager - rm -f uzbl-core.o - rm -f events.o - rm -f callbacks.o - rm -f inspector.o - rm -f cookie-jar.o - rm -f util.o + rm -f *.o *.lo find ./examples/ -name "*.pyc" -delete cd ./tests/; $(MAKE) clean rm -rf ./sandbox/ @@ -499,39 +499,36 @@ access to the following environment variables: * `$UZBL_URI`: The URI of the current page. * `$UZBL_TITLE`: The current page title. -These variables are also available as positional arguments `$1` through `$7`, -but this is deprecated and will be removed. - Handler scripts (`download_handler`, `cookie_handler`, `scheme_handler` and `authentication_handler`) are called with special arguments: * download handler - - `$8 url`: The URL of the item to be downloaded. - - `$9 suggested_filename`: A filename suggested by the server or based on the URL. - - `$10 content_type`: The mimetype of the file to be downloaded. - - `$11 total_size`: The size of the file to be downloaded in bytes. This may be inaccurate. + - `$1 url`: The URL of the item to be downloaded. + - `$2 suggested_filename`: A filename suggested by the server or based on the URL. + - `$3 content_type`: The mimetype of the file to be downloaded. + - `$4 total_size`: The size of the file to be downloaded in bytes. This may be inaccurate. * cookie handler - - `$8 GET/PUT`: Whether a cookie should be sent to the server (`GET`) or + - `$1 GET/PUT`: Whether a cookie should be sent to the server (`GET`) or stored by the browser (`PUT`). - - `$9 scheme`: Either `http` or `https`. - - `$10 host`: If current page URL is `www.example.com/somepage`, this could be + - `$2 scheme`: Either `http` or `https`. + - `$3 host`: If current page URL is `www.example.com/somepage`, this could be something else than `example.com`, eg advertising from another host. - - `$11 path`: The request address path. - - `$12 data`: The cookie data. Only included for `PUT` requests. + - `$4 path`: The request address path. + - `$5 data`: The cookie data. Only included for `PUT` requests. * scheme handler - - `$8 URI` of the page to be navigated to + - `$1 URI` of the page to be navigated to * authentication handler: - - `$8`: authentication zone unique identifier - - `$9`: domain part of URL that requests authentication - - `$10`: authentication realm - - `$11`: FALSE if this is the first attempt to authenticate, TRUE otherwise + - `$1`: authentication zone unique identifier + - `$2`: domain part of URL that requests authentication + - `$3`: authentication realm + - `$4`: FALSE if this is the first attempt to authenticate, TRUE otherwise ### Formfiller.sh @@ -577,15 +574,15 @@ Example: Script will be executed on each authentication request. It will receive four auth-related parameters: - $8 authentication zone unique identifier (may be used as 'key') - $9 domain part of URL that requests authentication - $10 authentication realm - $11 FALSE if this is the first attempt to authenticate, TRUE otherwise + $1 authentication zone unique identifier (may be used as 'key') + $2 domain part of URL that requests authentication + $3 authentication realm + $4 FALSE if this is the first attempt to authenticate, TRUE otherwise Script is expected to print exactly two lines of text on stdout (that means its output must contain exactly two '\n' bytes). The first line contains username, the second one - password. -If authentication fails, script will be executed again (with $11 = TRUE). +If authentication fails, script will be executed again (with $4 = TRUE). Non-interactive scripts should handle this case and do not try to authenticate again to avoid loops. If number of '\n' characters in scripts output does not equal 2, authentication will fail. @@ -594,7 +591,7 @@ That means 401 error will be displayed and uzbl won't try to authenticate anymor The simplest example of authentication handler script is: #!/bin/sh -[ "$11" == "TRUE ] && exit +[ "$4" == "TRUE ] && exit echo alice echo wonderland diff --git a/examples/config/config b/examples/config/config index 96b2034..f2d55b0 100644 --- a/examples/config/config +++ b/examples/config/config @@ -49,7 +49,7 @@ set download_handler = sync_spawn @scripts_dir/download.sh # === Dynamic event handlers ================================================= # Open link in new window -@on_event NEW_WINDOW sh 'uzbl-browser ${8:+-u "$8"}' %r +@on_event NEW_WINDOW sh 'uzbl-browser ${1:+-u "$1"}' %r # Open in current window #@on_event NEW_WINDOW uri %s # Open in new tab @@ -186,7 +186,7 @@ set ebind = @mode_bind global,-insert # --- Mouse bindings --------------------------------------------------------- # Middle click open in new window -@bind <Button2> = sh 'if [ "$8" ]; then uzbl-browser -u "$8"; else echo "uri $(xclip -o | sed s/\\\@/%40/g)" > "$UZBL_FIFO"; fi' \@SELECTED_URI +@bind <Button2> = sh 'if [ "$1" ]; then uzbl-browser -u "$1"; else echo "uri $(xclip -o | sed s/\\\@/%40/g)" > "$UZBL_FIFO"; fi' '\@SELECTED_URI' # --- Keyboard bindings ------------------------------------------------------ @@ -273,9 +273,9 @@ set ebind = @mode_bind global,-insert # Yanking & pasting binds @cbind yu = sh 'echo -n "$UZBL_URI" | xclip' -@cbind yU = sh 'echo -n $8 | xclip' \@SELECTED_URI +@cbind yU = sh 'echo -n "$1" | xclip' \@SELECTED_URI @cbind yy = sh 'echo -n "$UZBL_TITLE" | xclip' -@cbind yY = sh 'echo -n $8 | xclip' \@SELECTED_URI +@cbind yY = sh 'echo -n "$1" | xclip' \@SELECTED_URI # Clone current window @cbind c = sh 'uzbl-browser -u "$UZBL_URI"' diff --git a/examples/data/plugins/cookies.py b/examples/data/plugins/cookies.py index c507fd6..c9fe2c3 100644 --- a/examples/data/plugins/cookies.py +++ b/examples/data/plugins/cookies.py @@ -67,7 +67,7 @@ class TextStore(object): self.delete_cookie(None, cookie[:-3]) first = not os.path.exists(self.filename) - with open(self.filename, 'a+') as f: + with open(self.filename, 'a') as f: if first: print >> f, "# HTTP Cookie File" print >> f, '\t'.join(self.as_file(cookie)) diff --git a/examples/data/scripts/auth.py b/examples/data/scripts/auth.py index 9c1b4fc..592a2c6 100755 --- a/examples/data/scripts/auth.py +++ b/examples/data/scripts/auth.py @@ -46,7 +46,7 @@ def getText(authInfo, authHost, authRealm): return rv, output if __name__ == '__main__': - rv, output = getText(sys.argv[8], sys.argv[9], sys.argv[10]) + rv, output = getText(sys.argv[1], sys.argv[2], sys.argv[3]) if (rv == gtk.RESPONSE_OK): print output; else: diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh index df7a571..c410ad2 100755 --- a/examples/data/scripts/download.sh +++ b/examples/data/scripts/download.sh @@ -6,7 +6,6 @@ # that path. # if nothing is printed to stdout, the download will be cancelled. -shift 7 . $UZBL_UTIL_DIR/uzbl-dir.sh # the URL that is being downloaded diff --git a/examples/data/scripts/follow.sh b/examples/data/scripts/follow.sh index 2d666a2..d1560bf 100755 --- a/examples/data/scripts/follow.sh +++ b/examples/data/scripts/follow.sh @@ -3,8 +3,6 @@ # This script is just a wrapper around follow.js that lets us change uzbl's mode # after a link is selected. -shift 7 - # if socat is installed then we can change Uzbl's input mode once a link is # selected; otherwise we just select a link. if ! which socat >/dev/null 2>&1; then diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index 6e04573..c6822e6 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -53,8 +53,6 @@ MODELINE="> vim:ft=formfiller" [ -d "$(dirname $UZBL_FORMS_DIR)" ] || exit 1 [ -d $UZBL_FORMS_DIR ] || mkdir $UZBL_FORMS_DIR || exit 1 -shift 7 - action=$1 domain=$(echo $UZBL_URI | sed 's/\(http\|https\):\/\/\([^\/]\+\)\/.*/\2/') diff --git a/examples/data/scripts/load_cookies.sh b/examples/data/scripts/load_cookies.sh index f4c6886..17ec2ad 100755 --- a/examples/data/scripts/load_cookies.sh +++ b/examples/data/scripts/load_cookies.sh @@ -1,7 +1,7 @@ #!/bin/sh -if [ "$8" != "" ]; then - cookie_file=$8 +if [ "$1" != "" ]; then + cookie_file=$1 else cookie_file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/cookies.txt fi diff --git a/examples/data/scripts/per-site-settings.py b/examples/data/scripts/per-site-settings.py index febfd0f..89df4e6 100755 --- a/examples/data/scripts/per-site-settings.py +++ b/examples/data/scripts/per-site-settings.py @@ -100,7 +100,7 @@ def write_to_socket(commands, sockpath): if __name__ == '__main__': sockpath = os.environ['UZBL_SOCKET'] url = urlparse.urlparse(os.environ['UZBL_URI']) - filepath = sys.argv[8] + filepath = sys.argv[1] mode = os.stat(filepath)[stat.ST_MODE] diff --git a/examples/data/scripts/scheme.py b/examples/data/scripts/scheme.py index 0916466..4b0b7ca 100755 --- a/examples/data/scripts/scheme.py +++ b/examples/data/scripts/scheme.py @@ -13,7 +13,7 @@ def detach_open(cmd): print 'USED' if __name__ == '__main__': - uri = sys.argv[8] + uri = sys.argv[1] u = urlparse.urlparse(uri) if u.scheme == 'mailto': detach_open(['xterm', '-e', 'mail', u.path]) diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index 36e0c19..ee09cf2 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -30,12 +30,6 @@ fi UZBL="uzbl-browser -c $UZBL_CONFIG_FILE" # add custom flags and whatever here. -if [ $# -gt 1 ]; then - # this script is being run from uzbl, rather than standalone - # discard the uzbl arguments - shift 7 -fi - scriptfile=$(readlink -f $0) # this script act="$1" diff --git a/examples/data/scripts/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh index da61cae..354d7d1 100644 --- a/examples/data/scripts/util/dmenu.sh +++ b/examples/data/scripts/util/dmenu.sh @@ -60,10 +60,16 @@ fi if dmenu --help 2>&1 | grep -q '\[-xs\]'; then DMENU_XMMS_ARGS="-xs" DMENU_HAS_XMMS=1 +fi - if echo $DMENU_OPTIONS | grep -q -w 'xmms'; then - DMENU_ARGS="$DMENU_ARGS $DMENU_XMMS_ARGS" - fi +# Detect the tok patch +if dmenu --help 2>&1 | grep -q '\[-t\]'; then + DMENU_XMMS_ARGS="-t" + DMENU_HAS_XMMS=1 +fi + +if echo $DMENU_OPTIONS | grep -q -w 'xmms'; then + DMENU_ARGS="$DMENU_ARGS $DMENU_XMMS_ARGS" fi # Detect the vertical patch diff --git a/misc/env.sh b/misc/env.sh index 0dfedfa..68377f2 100755 --- a/misc/env.sh +++ b/misc/env.sh @@ -10,7 +10,7 @@ # Maybe we should spawn processes from here with an 'exec' at the end? # Re-define our home location inside the sandbox dir. -export HOME=./sandbox/home +export HOME=$(pwd)/sandbox/home # Export default XDG_{DATA,CACHE,..}_HOME locations inside the sandbox # directory according to defaults in the xdg specification. @@ -20,4 +20,4 @@ export XDG_CACHE_HOME=$HOME/.cache export XDG_CONFIG_HOME=$HOME/.config # Needed to run uzbl-browser etc from here. -export PATH="./sandbox/usr/local/bin:$PATH" +export PATH="$(pwd)/sandbox/usr/local/bin:$PATH" diff --git a/src/uzbl-core.c b/src/uzbl-core.c index a33d51d..b7b8b00 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -460,8 +460,9 @@ get_click_context() { if(!uzbl.state.last_button) return -1; - ht = webkit_web_view_get_hit_test_result(g->web_view, uzbl.state.last_button); - g_object_get(ht, "context", &context, NULL); + ht = webkit_web_view_get_hit_test_result (g->web_view, uzbl.state.last_button); + g_object_get (ht, "context", &context, NULL); + g_object_unref (ht); return (gint)context; } @@ -675,7 +676,7 @@ add_to_menu(GArray *argv, guint context) { g->menu_items = g_ptr_array_new(); if(split[1]) - item_cmd = g_strdup(split[1]); + item_cmd = split[1]; if(split[0]) { m = malloc(sizeof(MenuItem)); @@ -685,8 +686,6 @@ add_to_menu(GArray *argv, guint context) { m->issep = FALSE; g_ptr_array_add(g->menu_items, m); } - else - g_free(item_cmd); g_strfreev(split); } @@ -1216,30 +1215,19 @@ sharg_append(GArray *a, const gchar *str) { g_array_append_val(a, s); } -// make sure that the args string you pass can properly be interpreted (eg properly escaped against whitespace, quotes etc) +/* make sure that the args string you pass can properly be interpreted (eg + * properly escaped against whitespace, quotes etc) */ gboolean -run_command (const gchar *command, const guint npre, const gchar **args, - const gboolean sync, char **output_stdout) { - //command <uzbl conf> <uzbl pid> <uzbl win id> <uzbl fifo file> <uzbl socket file> [args] +run_command (const gchar *command, const gchar **args, const gboolean sync, + char **output_stdout) { GError *err = NULL; GArray *a = g_array_new (TRUE, FALSE, sizeof(gchar*)); - gchar *pid = itos(getpid()); - gchar *xwin = itos(uzbl.xwin); guint i; sharg_append(a, command); - for (i = 0; i < npre; i++) /* add n args before the default vars */ - sharg_append(a, args[i]); - sharg_append(a, uzbl.state.config_file); - sharg_append(a, pid); - sharg_append(a, xwin); - sharg_append(a, uzbl.comm.fifo_path); - sharg_append(a, uzbl.comm.socket_path); - sharg_append(a, uzbl.state.uri); - sharg_append(a, uzbl.gui.main_title); - - for (i = npre; i < g_strv_length((gchar**)args); i++) + + for (i = 0; i < g_strv_length((gchar**)args); i++) sharg_append(a, args[i]); gboolean result; @@ -1270,8 +1258,6 @@ run_command (const gchar *command, const guint npre, const gchar **args, g_printerr("error on run_command: %s\n", err->message); g_error_free (err); } - g_free (pid); - g_free (xwin); g_array_free (a, TRUE); return result; } @@ -1316,15 +1302,13 @@ split_quoted(const gchar* src, const gboolean unquote) { void spawn(GArray *argv, gboolean sync, gboolean exec) { gchar *path = NULL; + gchar *arg_car = argv_idx(argv, 0); + const gchar **arg_cdr = &g_array_index(argv, const gchar *, 1); - //TODO: allow more control over argument order so that users can have some arguments before the default ones from run_command, and some after - if (argv_idx(argv, 0) && - ((path = find_existing_file(argv_idx(argv, 0)))) ) { + if (arg_car && (path = find_existing_file(arg_car))) { if (uzbl.comm.sync_stdout) uzbl.comm.sync_stdout = strfree(uzbl.comm.sync_stdout); - run_command(path, 0, - ((const gchar **) (argv->data + sizeof(gchar*))), - sync, sync?&uzbl.comm.sync_stdout:NULL); + run_command(path, arg_cdr, sync, sync?&uzbl.comm.sync_stdout:NULL); // run each line of output from the program as a command if (sync && exec && uzbl.comm.sync_stdout) { gchar *head = uzbl.comm.sync_stdout; @@ -1363,11 +1347,11 @@ spawn_sh(GArray *argv, gboolean sync) { g_printerr ("spawn_sh: shell_cmd is not set!\n"); return; } - guint i; - gchar *spacer = g_strdup(""); - g_array_insert_val(argv, 1, spacer); + gchar **cmd = split_quoted(uzbl.behave.shell_cmd, TRUE); + gchar *cmdname = g_strdup(cmd[0]); + g_array_insert_val(argv, 1, cmdname); for (i = 1; i < g_strv_length(cmd); i++) g_array_prepend_val(argv, cmd[i]); @@ -1376,11 +1360,10 @@ spawn_sh(GArray *argv, gboolean sync) { if (uzbl.comm.sync_stdout) uzbl.comm.sync_stdout = strfree(uzbl.comm.sync_stdout); - run_command(cmd[0], g_strv_length(cmd) + 1, - (const gchar **) argv->data, - sync, sync?&uzbl.comm.sync_stdout:NULL); + run_command(cmd[0], (const gchar **) argv->data, + sync, sync?&uzbl.comm.sync_stdout:NULL); } - g_free (spacer); + g_free (cmdname); g_strfreev (cmd); } @@ -1432,14 +1415,13 @@ parse_command(const char *cmd, const char *param, GString *result) { strcmp("request", cmd)) { g_string_printf(tmp, "%s %s", cmd, param?param:""); send_event(COMMAND_EXECUTED, tmp->str, NULL); - g_string_free(tmp, TRUE); } } else { - gchar *tmp = g_strdup_printf("%s %s", cmd, param?param:""); - send_event(COMMAND_ERROR, tmp, NULL); - g_free(tmp); + g_string_printf (tmp, "%s %s", cmd, param?param:""); + send_event(COMMAND_ERROR, tmp->str, NULL); } + g_string_free(tmp, TRUE); } diff --git a/src/uzbl-core.h b/src/uzbl-core.h index 097fbfc..129c6a5 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -260,8 +260,8 @@ void close_uzbl (WebKitWebView *page, GArray *argv, GString *result); gboolean -run_command(const gchar *command, const guint npre, - const gchar **args, const gboolean sync, char **output_stdout); +run_command(const gchar *command, const gchar **args, const gboolean sync, + char **output_stdout); void spawn_async(WebKitWebView *web_view, GArray *argv, GString *result); diff --git a/tests/Makefile b/tests/Makefile index c35a2f2..2a5e2b6 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,27 +1,41 @@ -REQ_PKGS = libsoup-2.4 gthread-2.0 glib-2.0 - # gtk2 REQ_PKGS += gtk+-2.0 webkit-1.0 -CPPFLAGS = +CPPFLAGS = -I ../ -DERRORCHECK_MUTEXES # gtk3 #REQ_PKGS += gtk+-3.0 webkitgtk-3.0 -#CPPFLAGS = -DGTK3 +#CPPFLAGS = -I ../ -DERRORCHECK_MUTEXES -DG_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED + +# --- configuration ends here --- + +REQ_PKGS += libsoup-2.4 gthread-2.0 glib-2.0 + +ARCH:=$(shell uname -m) +ARCH!=echo `uname -m` -CFLAGS:=-std=c99 -I$(shell pwd)/../ -L$(shell pwd) -luzbl-core $(shell pkg-config --cflags $(REQ_PKGS)) -ggdb -Wall -W -DARCH="\"$(shell uname -m)\"" -lgthread-2.0 -DG_ERRORCHECK_MUTEXES -DCOMMIT="\"$(shell git log | head -n1 | sed "s/.* //")\"" $(CPPFLAGS) -CFLAGS!=echo -std=c99 `pkg-config --cflags $(REQ_PKGS)` -ggdb -Wall -W -DARCH='"\""'`uname -m`'"\""' -lgthread-2.0 -DG_ERRORCHECK_MUTEXES -DCOMMIT='"\""'`git log | head -n1 | sed "s/.* //"`'"\""' $(CPPFLAGS) +COMMIT_HASH:=$(shell cd .. && ./misc/hash.sh) +COMMIT_HASH!=echo `cd .. && ./misc/hash.sh` -LDFLAGS:=$(shell pkg-config --libs $(REQ_PKGS)) -pthread $(LDFLAGS) -LDFLAGS!=echo `pkg-config --libs $(REQ_PKGS)` -pthread $(LDFLAGS) +CPPFLAGS += -DARCH=\"$(ARCH)\" -DCOMMIT=\"$(COMMIT_HASH)\" -GTESTER:=gtester -GTESTER_REPORT:=gtester-report +PKG_CFLAGS:=$(shell pkg-config --cflags $(REQ_PKGS)) +PKG_CFLAGS!=echo pkg-config --cflags $(REQ_PKGS) -TEST_PROGS:=test-expand test-command +LDLIBS:=$(shell pkg-config --libs $(REQ_PKGS) x11) +LDLIBS!=echo pkg-config --libs $(REQ_PKGS) x11 + +CFLAGS += -std=c99 $(PKG_CFLAGS) -ggdb -fPIC -W -Wall -Wextra -pedantic -pthread + +GTESTER = gtester +GTESTER_REPORT = gtester-report + +TEST_PROGS = test-expand test-command all: $(TEST_PROGS) LD_LIBRARY_PATH="$(LD_LIBRARY_PATH):." $(GTESTER) --verbose $(TEST_PROGS) +${TEST_PROGS}: libuzbl-core.so + clean: rm -f $(TEST_PROGS) rm -f libuzbl-core.so diff --git a/tests/test-command.c b/tests/test-command.c index 6194081..7b33405 100644 --- a/tests/test-command.c +++ b/tests/test-command.c @@ -29,33 +29,6 @@ extern UzblCore uzbl; #define INSTANCE_NAME "testing" -gchar* -assert_str_beginswith(GString *expected, gchar *actual) { - gchar *actual_beginning = g_strndup(actual, expected->len); - g_assert_cmpstr(expected->str, ==, actual_beginning); - g_free(actual_beginning); - - /* return the part of the actual string that hasn't been compared yet */ - return &actual[expected->len]; -} - -/* compare the contents of uzbl.comm.sync_stdout to the standard arguments that - * should have been passed. This is meant to be called after something like "sync echo". */ -gchar* -assert_sync_beginswith_stdarg() { - GString *stdargs = g_string_new(""); - - g_string_append_printf(stdargs, "%s %d %d ", uzbl.state.config_file, getpid(), (int)uzbl.xwin); - g_string_append_printf(stdargs, "%s %s ", uzbl.comm.fifo_path, uzbl.comm.socket_path); - g_string_append_printf(stdargs, "%s %s ", uzbl.state.uri, uzbl.gui.main_title); - - gchar *rest = assert_str_beginswith(stdargs, uzbl.comm.sync_stdout); - - g_string_free(stdargs, TRUE); - - return rest; -} - #define ASSERT_EVENT(EF, STR) { read_event(ef); \ g_assert_cmpstr("EVENT [" INSTANCE_NAME "] " STR "\n", ==, ef->event_buffer); } @@ -314,13 +287,10 @@ test_run_handler_arg_order (void) { assert(uzbl.comm.sync_stdout); - /* the result should begin with the standard handler arguments */ - gchar *rest = assert_sync_beginswith_stdarg(); - /* the rest of the result should be the arguments passed to run_handler. */ /* the arguments in the second argument to run_handler should be placed before any * included in the first argument to run handler. */ - g_assert_cmpstr("abc def uvw xyz\n", ==, rest); + g_assert_cmpstr("abc def uvw xyz\n", ==, uzbl.comm.sync_stdout); } void @@ -330,12 +300,8 @@ test_run_handler_expand (void) { assert(uzbl.comm.sync_stdout); - /* the result should begin with the standard handler arguments */ - gchar *rest = assert_sync_beginswith_stdarg(); - - /* the rest of the result should be the arguments passed to run_handler. */ /* the user-specified arguments to the handler should have been expanded */ - g_assert_cmpstr("result: Test uzbl uzr agent\n", ==, rest); + g_assert_cmpstr("result: Test uzbl uzr agent\n", ==, uzbl.comm.sync_stdout); } int |