static Uzbl uzbl;
-
+char *foobar="Just a test";
+
+/* define names and pointers to all config specific variables */
+const struct {
+ char *name;
+ void **ptr;
+} var_name_to_ptr[] = {
+ { "name", (void *)&uzbl.state.instance_name },
+ { "show_status", (void *)&uzbl.behave.show_status },
+ { "insert_mode", (void *)&uzbl.behave.insert_mode },
+ { NULL, NULL }
+}, *n2v_p = var_name_to_ptr;
+
+/* construct a hash from the var_name_to_ptr array for quick access */
+static void
+make_var_to_name_hash() {
+ uzbl.comm.proto_var = g_hash_table_new(g_str_hash, g_str_equal);
+ while(n2v_p->name) {
+ g_hash_table_insert(uzbl.comm.proto_var, n2v_p->name, n2v_p->ptr);
+ n2v_p++;
+ }
+}
/* commandline arguments (set initial values for the state variables) */
static GOptionEntry entries[] =
return;
}
+static gboolean
+get_var_value(gchar *name) {
+ void **p = NULL;
+
+ if( (p = g_hash_table_lookup(uzbl.comm.proto_var, name)) ) {
+ if(!strcmp(name, "name")) {
+ printf("VAR: %s VALUE: %s\n", name, (char *)*p);
+ } else {
+ printf("VAR: %s VALUE: %d\n", name, (int)*p);
+ }
+ }
+ return TRUE;
+}
+
+static gboolean
+set_var_value(gchar *name, gchar *val) {
+ void **p = NULL;
+ char *endp = NULL;
+
+ if( (p = g_hash_table_lookup(uzbl.comm.proto_var, name)) ) {
+ if(!strcmp(name, "name")) {
+ free(*p);
+ *p = g_strdup(val);
+ } else {
+ *p = (int)strtoul(val, &endp, 10);
+ }
+ }
+ return TRUE;
+}
+
static void
+setup_regex() {
+ GError *err=NULL;
+
+ uzbl.comm.get_regex = g_regex_new("^GET\\s+([^ \\n]+)$", 0, 0, &err);
+ uzbl.comm.set_regex = g_regex_new("^SET\\s+([^ ]+)\\s*=\\s*([^\\n].*)$", 0, 0, &err);
+}
+
+static gboolean
control_stdin(GIOChannel *gio, GIOCondition condition) {
- gchar *ctl_line;
+ gchar *ctl_line = NULL;
+ gsize ctl_line_len = 0;
GIOStatus ret;
GError *err = NULL;
- printf("stdin triggered\n");
+ gchar **tokens;
- if (condition & G_IO_HUP) { //FIXME: for some reason, the last command is not interpreted. but when we get here gio->is_readable = FALSE.
+ if (condition & G_IO_HUP) {
ret = g_io_channel_shutdown (gio, FALSE, &err);
- if (ret == G_IO_STATUS_ERROR) {
- g_error ("Stdin: disconnected with HUP, but could not close it!\n");
- } else {
- printf("Stdin: closed on request with HUP\n");
- return;
- }
+ return FALSE;
}
- if(!gio)
- g_error ("Stdin: GIOChannel broke\n");
- ret = g_io_channel_read_line(gio, &ctl_line, NULL, NULL, &err);
- if (ret == G_IO_STATUS_ERROR)
- g_error ("Stdin: Error reading: %s\n", err->message);
- if (ret == G_IO_STATUS_EOF) {
- ret = g_io_channel_shutdown (gio, FALSE, &err);
- if (ret == G_IO_STATUS_ERROR) {
- g_error ("Stdin: disconnected without HUP, but could not close it!\n");
- } else {
- printf("Stdin: closed on request without HUP\n");
+ ret = g_io_channel_read_line(gio, &ctl_line, &ctl_line_len, NULL, &err);
+ if ( (ret == G_IO_STATUS_ERROR) || (ret == G_IO_STATUS_EOF) )
+ return FALSE;
+
+ /* SET command */
+ if(ctl_line[0] == 'S') {
+ tokens = g_regex_split(uzbl.comm.set_regex, ctl_line, 0);
+ if(tokens) {
+ set_var_value(tokens[1], tokens[2]);
+ g_strfreev(tokens);
}
}
- parse_line(ctl_line);
+ /* GET command */
+ else if(ctl_line[0] == 'G') {
+ tokens = g_regex_split(uzbl.comm.get_regex, ctl_line, 0);
+ if(tokens) {
+ get_var_value(tokens[1]);
+ g_strfreev(tokens);
+ }
+ } else
+ printf("Command not understood (%s)\n", ctl_line);
+
g_free(ctl_line);
- printf("stdin...done\n");
- return;
+
+ return TRUE;
}
static void
GIOChannel *chan = NULL;
GError *error = NULL;
- chan = g_io_channel_unix_new (fileno(stdin));
+ chan = g_io_channel_unix_new(fileno(stdin));
if (chan) {
if (!g_io_add_watch(chan, G_IO_IN|G_IO_HUP, (GIOFunc) control_stdin, NULL)) {
g_error ("Stdin: could not add watch\n");
if(setup_signal(SIGTERM, catch_sigterm) == SIG_ERR)
fprintf(stderr, "uzbl: error hooking SIGTERM\n");
+
+ setup_regex();
setup_scanner();
+
if (!uzbl.behave.status_format)
uzbl.behave.status_format = STATUS_DEFAULT;
if (!uzbl.behave.show_status)
update_title();
+ make_var_to_name_hash();
+ create_stdin();
if (uzbl.behave.fifo_dir)
create_fifo ();
if (uzbl.behave.socket_dir)
create_socket ();
- create_stdin ();
gtk_main ();
clean_up();