From 82ffbbdf91743f1b9216cd69dbbe09aff94cd330 Mon Sep 17 00:00:00 2001 From: koral Date: Thu, 3 Feb 2011 14:27:01 +0100 Subject: Cleans/comments uzbl-core.c. --- src/uzbl-core.c | 200 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 106 insertions(+), 94 deletions(-) (limited to 'src') diff --git a/src/uzbl-core.c b/src/uzbl-core.c index 3c6407e..a25cf14 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -186,20 +186,20 @@ return EXP_ERR; * recurse == 1: don't expand '@(command)@' * recurse == 2: don't expand '@@' */ -gchar * -expand(const char *s, guint recurse) { - uzbl_cmdprop *c; +gchar* +expand(const char* s, guint recurse) { + uzbl_cmdprop* c; enum exp_type etype; - char *end_simple_var = "\t^°!\"§$%&/()=?'`'+~*'#-:,;@<>| \\{}[]¹²³¼½"; - char *ret = NULL; - char *vend = NULL; - GError *err = NULL; - gchar *cmd_stdout = NULL; - gchar *mycmd = NULL; - GString *buf = g_string_new(""); - GString *js_ret = g_string_new(""); - - while(s && *s) { + char* end_simple_var = "\t^°!\"§$%&/()=?'`'+~*'#-:,;@<>| \\{}[]¹²³¼½"; + char* ret = NULL; + char* vend = NULL; + GError* err = NULL; + gchar* cmd_stdout = NULL; + gchar* mycmd = NULL; + GString* buf = g_string_new(""); + GString* js_ret = g_string_new(""); + + while (s && *s) { switch(*s) { case '\\': g_string_append_c(buf, *++s); @@ -630,11 +630,12 @@ commands_hash(void) { g_hash_table_insert(uzbl.behave.commands, (gpointer) cmdlist[i].key, &cmdlist[i].value); } + void builtins() { - unsigned int i, - len = LENGTH(cmdlist); - GString *command_list = g_string_new(""); + unsigned int i; + unsigned int len = LENGTH(cmdlist); + GString* command_list = g_string_new(""); for (i = 0; i < len; i++) { g_string_append(command_list, cmdlist[i].key); @@ -1335,37 +1336,37 @@ parse_command(const char *cmd, const char *param, GString *result) { GString *tmp = g_string_new(""); if ((c = g_hash_table_lookup(uzbl.behave.commands, cmd))) { - guint i; - gchar **par = split_quoted(param, TRUE); - GArray *a = g_array_new (TRUE, FALSE, sizeof(gchar*)); - - if (c->no_split) { /* don't split */ - sharg_append(a, param); - } else if (par) { - for (i = 0; i < g_strv_length(par); i++) - sharg_append(a, par[i]); - } + guint i; + gchar **par = split_quoted(param, TRUE); + GArray *a = g_array_new (TRUE, FALSE, sizeof(gchar*)); + + if (c->no_split) { /* don't split */ + sharg_append(a, param); + } else if (par) { + for (i = 0; i < g_strv_length(par); i++) + sharg_append(a, par[i]); + } - if (result == NULL) { - GString *result_print = g_string_new(""); + if (result == NULL) { + GString *result_print = g_string_new(""); - c->function(uzbl.gui.web_view, a, result_print); - if (result_print->len) - printf("%*s\n", (int)result_print->len, result_print->str); + c->function(uzbl.gui.web_view, a, result_print); + if (result_print->len) + printf("%*s\n", (int)result_print->len, result_print->str); - g_string_free(result_print, TRUE); - } else { - c->function(uzbl.gui.web_view, a, result); - } - g_strfreev (par); - g_array_free (a, TRUE); - - if(strcmp("set", cmd) && - strcmp("event", cmd) && - strcmp("request", cmd)) { - g_string_printf(tmp, "%s %s", cmd, param?param:""); - send_event(COMMAND_EXECUTED, tmp->str, NULL); - } + g_string_free(result_print, TRUE); + } else { + c->function(uzbl.gui.web_view, a, result); + } + g_strfreev (par); + g_array_free (a, TRUE); + + if(strcmp("set", cmd) && + strcmp("event", cmd) && + strcmp("request", cmd)) { + g_string_printf(tmp, "%s %s", cmd, param?param:""); + send_event(COMMAND_EXECUTED, tmp->str, NULL); + } } else { g_string_printf (tmp, "%s %s", cmd, param?param:""); @@ -1464,15 +1465,15 @@ set_var_value(const gchar *name, gchar *val) { } void -parse_cmd_line(const char *ctl_line, GString *result) { - size_t len=0; - gchar *ctlstrip = NULL; - gchar *exp_line = NULL; - gchar *work_string = NULL; +parse_cmd_line(const char* ctl_line, GString* result) { + size_t len = 0; + gchar* ctlstrip = NULL; + gchar* exp_line = NULL; + gchar* work_string = NULL; work_string = g_strdup(ctl_line); - /* strip trailing newline */ + /* Strip trailing newline */ len = strlen(ctl_line); if (work_string[len - 1] == '\n') ctlstrip = g_strndup(work_string, len - 1); @@ -1833,8 +1834,9 @@ init_socket(gchar *dir) { /* return dir or, on error, free dir and return NULL * return NULL; } + void -update_title (void) { +update_title(void) { Behaviour *b = &uzbl.behave; const gchar *title_format = b->title_format_long; @@ -1949,11 +1951,12 @@ create_mainbar() { GtkWidget* -create_window () { +create_window() { GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), 800, 600); gtk_widget_set_name (window, "Uzbl browser"); + gtk_window_set_title(GTK_WINDOW(window), "Uzbl browser"); /* if the window has been made small, it shouldn't try to resize itself due * to a long statusbar. */ @@ -1968,8 +1971,9 @@ create_window () { return window; } + GtkPlug* -create_plug () { +create_plug() { GtkPlug* plug = GTK_PLUG (gtk_plug_new (uzbl.state.socket_id)); g_signal_connect (G_OBJECT (plug), "destroy", G_CALLBACK (destroy_cb), NULL); g_signal_connect (G_OBJECT (plug), "key-press-event", G_CALLBACK (key_press_cb), NULL); @@ -2100,10 +2104,11 @@ run_handler (const gchar *act, const gchar *args) { void settings_init () { - State *s = &uzbl.state; - Network *n = &uzbl.net; - - int i; + State* s = &uzbl.state; + Network* n = &uzbl.net; + int i; + + /* Load default config */ for (i = 0; default_config[i].command != NULL; i++) { parse_cmd_line(default_config[i].command, NULL); } @@ -2114,11 +2119,12 @@ settings_init () { } else if (!s->config_file) { - s->config_file = find_xdg_file (0, "/uzbl/config"); + s->config_file = find_xdg_file(0, "/uzbl/config"); } + /* Load config file, if any */ if (s->config_file) { - if(!for_each_line_in_file(s->config_file, parse_cmd_line_cb, NULL)) { + if (!for_each_line_in_file(s->config_file, parse_cmd_line_cb, NULL)) { gchar *tmp = g_strdup_printf("File %s can not be read.", s->config_file); send_event(COMMAND_ERROR, tmp, NULL); g_free(tmp); @@ -2127,17 +2133,17 @@ settings_init () { } else if (uzbl.state.verbose) printf ("No configuration file loaded.\n"); - if(s->connect_socket_names) + if (s->connect_socket_names) init_connect_socket(); g_signal_connect(n->soup_session, "authenticate", G_CALLBACK(handle_authentication), NULL); } -void handle_authentication (SoupSession *session, SoupMessage *msg, SoupAuth *auth, gboolean retrying, gpointer user_data) { +void handle_authentication (SoupSession *session, SoupMessage *msg, SoupAuth *auth, gboolean retrying, gpointer user_data) { (void) user_data; - if(uzbl.behave.authentication_handler && *uzbl.behave.authentication_handler != 0) { + if (uzbl.behave.authentication_handler && *uzbl.behave.authentication_handler != 0) { gchar *info, *host, *realm; gchar *p; @@ -2279,8 +2285,6 @@ set_webview_scroll_adjustments() { * external applications need to do anyhow */ void initialize(int argc, char** argv) { - int i; - /* Parse commandline arguments */ GOptionContext* context = g_option_context_new ("[ uri ] - load a uri by default"); g_option_context_add_main_entries (context, entries, NULL); @@ -2295,14 +2299,10 @@ initialize(int argc, char** argv) { } /* Embedded mode */ - for (i=0; i 1 && !uzbl.state.uri) uri_override = g_strdup(argv[1]); + gboolean verbose_override = uzbl.state.verbose; - settings_init (); + /* Read configuration file */ + settings_init(); + /* Update status bar */ if (!uzbl.behave.show_status) gtk_widget_hide(uzbl.gui.mainbar); else @@ -2480,6 +2476,7 @@ main (int argc, char* argv[]) { /* WebInspector */ set_up_inspector(); + /* Options overriding */ if (verbose_override > uzbl.state.verbose) uzbl.state.verbose = verbose_override; @@ -2488,7 +2485,22 @@ main (int argc, char* argv[]) { g_free(uri_override); } - gtk_main (); + /* Verbose feedback */ + if (uzbl.state.verbose) { + printf("Uzbl start location: %s\n", argv[0]); + if (uzbl.state.socket_id) + printf("plug_id %i\n", gtk_plug_get_id(uzbl.gui.plug)); + else + printf("window_id %i\n",(int) uzbl.xwin); + printf("pid %i\n", getpid ()); + printf("name: %s\n", uzbl.state.instance_name); + printf("commit: %s\n", uzbl.info.commit); + } + + + gtk_main(); + + /* Cleanup and exit*/ clean_up(); return EXIT_SUCCESS; -- cgit v1.2.3