aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Robert Manea <gotmor@gmail.com>2009-10-02 11:15:13 +0200
committerGravatar Robert Manea <gotmor@gmail.com>2009-10-02 11:15:13 +0200
commit85bd94abb4fb507b5d230a06f5f7c2b4138110ca (patch)
tree1ac0d1443f3a7f7c0ad3b8a8ba5c2e13ab67befc
parent93bcfb0d08807a68da314ef844c9cfc9afd07ae9 (diff)
split source into multiple files
-rw-r--r--Makefile34
-rw-r--r--Makefile-new-test48
-rw-r--r--uzbl-core.c176
-rw-r--r--uzbl-core.h61
-rw-r--r--uzbl-events.c145
-rw-r--r--uzbl-events.h29
6 files changed, 249 insertions, 244 deletions
diff --git a/Makefile b/Makefile
index 581a005..2989afe 100644
--- a/Makefile
+++ b/Makefile
@@ -1,20 +1,40 @@
# first entries are for gnu make, 2nd for BSD make. see http://lists.uzbl.org/pipermail/uzbl-dev-uzbl.org/2009-July/000177.html
-CFLAGS:=-std=c99 $(shell pkg-config --cflags gtk+-2.0 webkit-1.0 libsoup-2.4 gthread-2.0) -ggdb -Wall -W -DARCH="\"$(shell uname -m)\"" -lgthread-2.0 -DG_ERRORCHECK_MUTEXES -DCOMMIT="\"$(shell git log | head -n1 | sed "s/.* //")\"" $(CPPFLAGS) -fPIC -W -Wall -Wextra -pedantic -ggdb3
-CFLAGS!=echo -std=c99 `pkg-config --cflags gtk+-2.0 webkit-1.0 libsoup-2.4 gthread-2.0` -ggdb -Wall -W -DARCH='"\""'`uname -m`'"\""' -lgthread-2.0 -DG_ERRORCHECK_MUTEXES -DCOMMIT='"\""'`git log | head -n1 | sed "s/.* //"`'"\""' $(CPPFLAGS) -fPIC -W -Wall -Wextra -pedantic -ggdb3
+CFLAGS:=-std=c99 $(shell pkg-config --cflags gtk+-2.0 webkit-1.0 libsoup-2.4 gthread-2.0) -ggdb -Wall -W -DARCH="\"$(shell uname -m)\"" -lgthread-2.0 -DCOMMIT="\"$(shell git log | head -n1 | sed "s/.* //")\"" $(CPPFLAGS) -fPIC -W -Wall -Wextra -pedantic -ggdb3
+CFLAGS!=echo -std=c99 `pkg-config --cflags gtk+-2.0 webkit-1.0 libsoup-2.4 gthread-2.0` -ggdb -Wall -W -DARCH='"\""'`uname -m`'"\""' -lgthread-2.0 -DCOMMIT='"\""'`git log | head -n1 | sed "s/.* //"`'"\""' $(CPPFLAGS) -fPIC -W -Wall -Wextra -pedantic -ggdb3
LDFLAGS:=$(shell pkg-config --libs gtk+-2.0 webkit-1.0 libsoup-2.4 gthread-2.0) -pthread $(LDFLAGS)
LDFLAGS!=echo `pkg-config --libs gtk+-2.0 webkit-1.0 libsoup-2.4 gthread-2.0` -pthread $(LDFLAGS)
-all: uzbl-browser
+SRC = uzbl-core.c uzbl-events.c
+OBJ = ${SRC:.c=.o}
+
+all: uzbl-browser options
+
+options:
+ @echo uzbl-core build options:
+ @echo "CFLAGS = ${CFLAGS}"
+ @echo "LDFLAGS = ${LDFLAGS}"
+
+.c.o:
+ @echo Compiling $<
+ @${CC} -c ${CFLAGS} $<
+
+${OBJ}: uzbl-core.h uzbl-events.h config.h
+
+uzbl-core: ${OBJ}
+ @echo Linking $<
+ @${CC} -o $@ ${OBJ} ${LDFLAGS}
+
+
uzbl-browser: uzbl-core
PREFIX?=$(DESTDIR)/usr/local
# When compiling unit tests, compile uzbl as a library first
-tests: uzbl-core.o
- $(CC) -DUZBL_LIBRARY -shared -Wl uzbl-core.o -o ./tests/libuzbl-core.so
+tests: uzbl-core.o uzbl-events.o
+ $(CC) -DUZBL_LIBRARY -shared -Wl uzbl-core.o uzbl-events.o -o ./tests/libuzbl-core.so
cd ./tests/; $(MAKE)
test: uzbl-core
@@ -40,9 +60,10 @@ test-share-browser: uzbl-browser
clean:
rm -f uzbl-core
rm -f uzbl-core.o
+ rm -f uzbl-events.o
cd ./tests/; $(MAKE) clean
-install:
+install: all
install -d $(PREFIX)/bin
install -d $(PREFIX)/share/uzbl/docs
install -d $(PREFIX)/share/uzbl/examples
@@ -58,3 +79,4 @@ install:
uninstall:
rm -rf $(PREFIX)/bin/uzbl-*
rm -rf $(PREFIX)/share/uzbl
+
diff --git a/Makefile-new-test b/Makefile-new-test
deleted file mode 100644
index a1efa56..0000000
--- a/Makefile-new-test
+++ /dev/null
@@ -1,48 +0,0 @@
-LIBS := gtk+-2.0 webkit-1.0
-ARCH := $(shell uname -m)
-COMMIT := $(shell git log | head -n1 | sed "s/.* //")
-DEBUG := -ggdb -Wall -W -DG_ERRORCHECK_MUTEXES
-
-CFLAGS := $(shell --cflags $(LIBS)) $(DEBUG) -DARCH="$(ARCH)" -DCOMMIT="\"$(COMMIT)\""
-LDFLAGS := $(shell --libs $(LIBS)) $(LDFLAGS)
-
-PREFIX ?= $(DESTDIR)/usr
-BINDIR ?= $(PREFIX)/bin
-UZBLDATA ?= $(PREFIX)/share/uzbl
-DOCSDIR ?= $(PREFIX)/share/uzbl/docs
-EXMPLSDIR ?= $(PREFIX)/share/uzbl/examples
-
-all: uzbl
-
-uzbl: uzbl.c uzbl.h config.h
-
-%: %.c
- $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LIBS) -o $@ $<
-
-test: uzbl
- ./uzbl --uri http://www.uzbl.org
-
-test-config: uzbl
- ./uzbl --uri http://www.uzbl.org < examples/configs/sampleconfig-dev
-
-test-config-real: uzbl
- ./uzbl --uri http://www.uzbl.org < $(EXMPLSDIR)/configs/sampleconfig
-
-clean:
- rm -f uzbl
-
-install:
- install -d $(BINDIR)
- install -d $(DOCSDIR)
- install -d $(EXMPLSDIR)
- install -D -m755 uzbl $(BINDIR)/uzbl
- cp -ax docs/* $(DOCSDIR)
- cp -ax config.h $(DOCSDIR)
- cp -ax examples/* $(EXMPLSDIR)
- install -D -m644 AUTHORS $(DOCSDIR)
- install -D -m644 README $(DOCSDIR)
-
-
-uninstall:
- rm -rf $(BINDIR)/uzbl
- rm -rf $(UZBLDATA)
diff --git a/uzbl-core.c b/uzbl-core.c
index e86da21..71bc474 100644
--- a/uzbl-core.c
+++ b/uzbl-core.c
@@ -29,36 +29,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
-#define LENGTH(x) (sizeof x / sizeof x[0])
-#define _POSIX_SOURCE
-
-#include <gtk/gtk.h>
-#include <gdk/gdkx.h>
-#include <gdk/gdkkeysyms.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/un.h>
-#include <sys/utsname.h>
-#include <sys/time.h>
-#include <webkit/webkit.h>
-#include <libsoup/soup.h>
-#include <JavaScriptCore/JavaScript.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <assert.h>
-#include <poll.h>
-#include <sys/uio.h>
-#include <sys/ioctl.h>
-#include <assert.h>
#include "uzbl-core.h"
+#include "uzbl-events.h"
#include "config.h"
UzblCore uzbl;
@@ -84,9 +56,17 @@ GOptionEntry entries[] =
{ NULL, 0, 0, 0, NULL, NULL, NULL }
};
-enum ptr_type {TYPE_INT, TYPE_STR, TYPE_FLOAT};
+XDG_Var XDG[] =
+{
+ { "XDG_CONFIG_HOME", "~/.config" },
+ { "XDG_DATA_HOME", "~/.local/share" },
+ { "XDG_CACHE_HOME", "~/.cache" },
+ { "XDG_CONFIG_DIRS", "/etc/xdg" },
+ { "XDG_DATA_DIRS", "/usr/local/share/:/usr/share/" },
+};
/* associate command names to their properties */
+enum ptr_type {TYPE_INT, TYPE_STR, TYPE_FLOAT};
typedef struct {
enum ptr_type type;
union {
@@ -183,38 +163,6 @@ const struct var_name_to_ptr_t {
{ NULL, {.ptr.s = NULL, .type = TYPE_INT, .dump = 0, .writeable = 0, .func = NULL}}
};
-
-/* Event id to name mapping
- * Event names must be in the same
- * order as in 'enum event_type'
- *
- * TODO: Add more useful events
-*/
-const char *event_table[LAST_EVENT] = {
- "LOAD_START" ,
- "LOAD_COMMIT" ,
- "LOAD_FINISH" ,
- "LOAD_ERROR" ,
- "KEY_PRESS" ,
- "KEY_RELEASE" ,
- "DOWNLOAD_REQUEST" ,
- "COMMAND_EXECUTED" ,
- "LINK_HOVER" ,
- "TITLE_CHANGED" ,
- "GEOMETRY_CHANGED" ,
- "WEBINSPECTOR" ,
- "NEW_WINDOW" ,
- "SELECTION_CHANGED",
- "VARIABLE_SET" ,
- "FIFO_SET" ,
- "SOCKET_SET" ,
- "INSTANCE_START" ,
- "INSTANCE_EXIT" ,
- "LOAD_PROGRESS" ,
- "LINK_UNHOVER"
-};
-
-
/* construct a hash from the var_name_to_ptr array for quick access */
void
create_var_to_name_hash() {
@@ -388,110 +336,6 @@ expand(const char *s, guint recurse) {
return g_string_free(buf, FALSE);
}
-void
-event_buffer_timeout(guint sec) {
- struct itimerval t;
- memset(&t, 0, sizeof t);
- t.it_value.tv_sec = sec;
- t.it_value.tv_usec = 0;
- setitimer(ITIMER_REAL, &t, NULL);
-}
-
-
-void
-send_event_socket(GString *msg) {
- GError *error = NULL;
- GString *tmp;
- GIOStatus ret;
- gsize len;
- guint i=0;
-
- if(uzbl.comm.socket_path &&
- uzbl.comm.clientchan &&
- uzbl.comm.clientchan->is_writeable) {
-
- if(uzbl.state.event_buffer) {
- event_buffer_timeout(0);
-
- while(i < uzbl.state.event_buffer->len) {
- tmp = g_ptr_array_index(uzbl.state.event_buffer, i++);
- ret = g_io_channel_write_chars (uzbl.comm.clientchan,
- tmp->str, tmp->len,
- &len, &error);
- /* is g_ptr_array_free(uzbl.state.event_buffer, TRUE) enough? */
- //g_string_free(tmp, TRUE);
- if (ret == G_IO_STATUS_ERROR) {
- g_warning ("Error sending event to socket: %s", error->message);
- }
- g_io_channel_flush(uzbl.comm.clientchan, &error);
- }
- g_ptr_array_free(uzbl.state.event_buffer, TRUE);
- uzbl.state.event_buffer = NULL;
- }
- if(msg) {
- ret = g_io_channel_write_chars (uzbl.comm.clientchan,
- msg->str, msg->len,
- &len, &error);
-
- if (ret == G_IO_STATUS_ERROR) {
- g_warning ("Error sending event to socket: %s", error->message);
- }
- g_io_channel_flush(uzbl.comm.clientchan, &error);
- }
- }
- /* buffer events until a socket is set and connected
- * or a timeout is encountered
- */
- else {
- if(!uzbl.state.event_buffer)
- uzbl.state.event_buffer = g_ptr_array_new();
- g_ptr_array_add(uzbl.state.event_buffer, (gpointer)g_string_new(msg->str));
- }
-}
-
-void
-send_event_stdout(GString *msg) {
- printf("%s", msg->str);
- fflush(stdout);
-}
-
-/*
- * build event string and send over the supported interfaces
- * custom_event == NULL indicates an internal event
-*/
-void
-send_event(int type, const gchar *details, const gchar *custom_event) {
- GString *event_message = g_string_new("");
- gchar *buf, *p_val = NULL;
-
- /* expand shell vars */
- if(details) {
- buf = g_strdup(details);
- p_val = parseenv(g_strdup(buf ? g_strchug(buf) : " "));
- g_free(buf);
- }
-
- /* check for custom events */
- if(custom_event) {
- g_string_printf(event_message, "EVENT [%s] %s %s\n",
- uzbl.state.instance_name, custom_event, p_val);
- }
- /* check wether we support the internal event */
- else if(type < LAST_EVENT) {
- g_string_printf(event_message, "EVENT [%s] %s %s\n",
- uzbl.state.instance_name, event_table[type], p_val);
- }
-
- if(event_message->str) {
- /* TODO: a means to select the interface to which events are sent */
- send_event_stdout(event_message);
- send_event_socket(event_message);
-
- g_string_free(event_message, TRUE);
- }
- g_free(p_val);
-}
-
char *
itos(int val) {
char tmp[20];
diff --git a/uzbl-core.h b/uzbl-core.h
index 854060f..d5fbcb7 100644
--- a/uzbl-core.h
+++ b/uzbl-core.h
@@ -11,6 +11,36 @@
*
*/
+#define _POSIX_SOURCE
+
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+#include <gdk/gdkkeysyms.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/un.h>
+#include <sys/utsname.h>
+#include <sys/time.h>
+#include <webkit/webkit.h>
+#include <libsoup/soup.h>
+#include <JavaScriptCore/JavaScript.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <assert.h>
+#include <poll.h>
+#include <sys/uio.h>
+#include <sys/ioctl.h>
+#include <assert.h>
+
+#define LENGTH(x) (sizeof x / sizeof x[0])
+
/* status bar elements */
typedef struct {
gint load_progress;
@@ -170,42 +200,22 @@ typedef struct {
Window xwin;
} UzblCore;
+/* Main Uzbl object */
+extern UzblCore uzbl;
+
+typedef void sigfunc(int);
typedef struct {
char* name;
char* param;
} Action;
-typedef void sigfunc(int);
-
-/* Event system */
-enum event_type {
- LOAD_START, LOAD_COMMIT, LOAD_FINISH, LOAD_ERROR,
- KEY_PRESS, KEY_RELEASE, DOWNLOAD_REQ, COMMAND_EXECUTED,
- LINK_HOVER, TITLE_CHANGED, GEOMETRY_CHANGED,
- WEBINSPECTOR, NEW_WINDOW, SELECTION_CHANGED,
- VARIABLE_SET, FIFO_SET, SOCKET_SET,
- INSTANCE_START, INSTANCE_EXIT, LOAD_PROGRESS,
- LINK_UNHOVER,
-
- /* must be last entry */
- LAST_EVENT
-};
-
/* XDG Stuff */
typedef struct {
gchar* environmental;
gchar* default_value;
} XDG_Var;
-XDG_Var XDG[] =
-{
- { "XDG_CONFIG_HOME", "~/.config" },
- { "XDG_DATA_HOME", "~/.local/share" },
- { "XDG_CACHE_HOME", "~/.cache" },
- { "XDG_CONFIG_DIRS", "/etc/xdg" },
- { "XDG_DATA_DIRS", "/usr/local/share/:/usr/share/" },
-};
/* Functions */
char *
@@ -229,6 +239,9 @@ catch_sigterm(int s);
sigfunc *
setup_signal(int signe, sigfunc *shandler);
+gchar*
+parseenv (char* string);
+
gboolean
set_var_value(const gchar *name, gchar *val);
diff --git a/uzbl-events.c b/uzbl-events.c
new file mode 100644
index 0000000..b052b6b
--- /dev/null
+++ b/uzbl-events.c
@@ -0,0 +1,145 @@
+/* Uzbl event routines
+ * (c) 2009 by Robert Manea
+*/
+
+#include "uzbl-core.h"
+#include "uzbl-events.h"
+
+UzblCore uzbl;
+
+/* Event id to name mapping
+ * Event names must be in the same
+ * order as in 'enum event_type'
+ *
+ * TODO: Add more useful events
+*/
+const char *event_table[LAST_EVENT] = {
+ "LOAD_START" ,
+ "LOAD_COMMIT" ,
+ "LOAD_FINISH" ,
+ "LOAD_ERROR" ,
+ "KEY_PRESS" ,
+ "KEY_RELEASE" ,
+ "DOWNLOAD_REQUEST" ,
+ "COMMAND_EXECUTED" ,
+ "LINK_HOVER" ,
+ "TITLE_CHANGED" ,
+ "GEOMETRY_CHANGED" ,
+ "WEBINSPECTOR" ,
+ "NEW_WINDOW" ,
+ "SELECTION_CHANGED",
+ "VARIABLE_SET" ,
+ "FIFO_SET" ,
+ "SOCKET_SET" ,
+ "INSTANCE_START" ,
+ "INSTANCE_EXIT" ,
+ "LOAD_PROGRESS" ,
+ "LINK_UNHOVER"
+};
+
+void
+event_buffer_timeout(guint sec) {
+ struct itimerval t;
+ memset(&t, 0, sizeof t);
+ t.it_value.tv_sec = sec;
+ t.it_value.tv_usec = 0;
+ setitimer(ITIMER_REAL, &t, NULL);
+}
+
+
+void
+send_event_socket(GString *msg) {
+ GError *error = NULL;
+ GString *tmp;
+ GIOStatus ret = 0;
+ gsize len;
+ guint i=0;
+
+ if(uzbl.comm.socket_path &&
+ uzbl.comm.clientchan &&
+ uzbl.comm.clientchan->is_writeable) {
+
+ if(uzbl.state.event_buffer) {
+ event_buffer_timeout(0);
+
+ while(i < uzbl.state.event_buffer->len) {
+ tmp = g_ptr_array_index(uzbl.state.event_buffer, i++);
+ ret = g_io_channel_write_chars (uzbl.comm.clientchan,
+ tmp->str, tmp->len,
+ &len, &error);
+ /* is g_ptr_array_free(uzbl.state.event_buffer, TRUE) enough? */
+ //g_string_free(tmp, TRUE);
+ if (ret == G_IO_STATUS_ERROR) {
+ g_warning ("Error sending event to socket: %s", error->message);
+ }
+ g_io_channel_flush(uzbl.comm.clientchan, &error);
+ }
+ g_ptr_array_free(uzbl.state.event_buffer, TRUE);
+ uzbl.state.event_buffer = NULL;
+ }
+ if(msg) {
+ while(!ret ||
+ ret == G_IO_STATUS_AGAIN) {
+ ret = g_io_channel_write_chars (uzbl.comm.clientchan,
+ msg->str, msg->len,
+ &len, &error);
+ }
+
+ if (ret == G_IO_STATUS_ERROR) {
+ g_warning ("Error sending event to socket: %s", error->message);
+ }
+ g_io_channel_flush(uzbl.comm.clientchan, &error);
+ }
+ }
+ /* buffer events until a socket is set and connected
+ * or a timeout is encountered
+ */
+ else {
+ if(!uzbl.state.event_buffer)
+ uzbl.state.event_buffer = g_ptr_array_new();
+ g_ptr_array_add(uzbl.state.event_buffer, (gpointer)g_string_new(msg->str));
+ }
+}
+
+void
+send_event_stdout(GString *msg) {
+ printf("%s", msg->str);
+ fflush(stdout);
+}
+
+/*
+ * build event string and send over the supported interfaces
+ * custom_event == NULL indicates an internal event
+*/
+void
+send_event(int type, const gchar *details, const gchar *custom_event) {
+ GString *event_message = g_string_new("");
+ gchar *buf, *p_val = NULL;
+
+ /* expand shell vars */
+ if(details) {
+ buf = g_strdup(details);
+ p_val = parseenv(g_strdup(buf ? g_strchug(buf) : " "));
+ g_free(buf);
+ }
+
+ /* check for custom events */
+ if(custom_event) {
+ g_string_printf(event_message, "EVENT [%s] %s %s\n",
+ uzbl.state.instance_name, custom_event, p_val);
+ }
+ /* check wether we support the internal event */
+ else if(type < LAST_EVENT) {
+ g_string_printf(event_message, "EVENT [%s] %s %s\n",
+ uzbl.state.instance_name, event_table[type], p_val);
+ }
+
+ if(event_message->str) {
+ /* TODO: a means to select the interface to which events are sent */
+ send_event_stdout(event_message);
+ send_event_socket(event_message);
+
+ g_string_free(event_message, TRUE);
+ }
+ g_free(p_val);
+}
diff --git a/uzbl-events.h b/uzbl-events.h
new file mode 100644
index 0000000..782243d
--- /dev/null
+++ b/uzbl-events.h
@@ -0,0 +1,29 @@
+/* Uzbl event routines
+ * (c) 2009 by Robert Manea
+*/
+
+/* Event system */
+enum event_type {
+ LOAD_START, LOAD_COMMIT, LOAD_FINISH, LOAD_ERROR,
+ KEY_PRESS, KEY_RELEASE, DOWNLOAD_REQ, COMMAND_EXECUTED,
+ LINK_HOVER, TITLE_CHANGED, GEOMETRY_CHANGED,
+ WEBINSPECTOR, NEW_WINDOW, SELECTION_CHANGED,
+ VARIABLE_SET, FIFO_SET, SOCKET_SET,
+ INSTANCE_START, INSTANCE_EXIT, LOAD_PROGRESS,
+ LINK_UNHOVER,
+
+ /* must be last entry */
+ LAST_EVENT
+};
+
+void
+event_buffer_timeout(guint sec);
+
+void
+send_event_socket(GString *msg);
+
+void
+send_event_stdout(GString *msg);
+
+void
+send_event(int type, const gchar *details, const gchar *custom_event);