From 78b60cb8de47dfa6ed3297dccf2b9268099bc922 Mon Sep 17 00:00:00 2001 From: "Todd T. Fries" Date: Thu, 26 Jul 2012 14:49:58 -0500 Subject: This diff munges and massages the show_g_object_settings function o move from 'var = g_value_get_foo(&value); valstr = g_strdup_printf("%XX", foo);' to 'valstr = g_strdup_printf("%XX", g_value_get_foo(&value));' .. shrinks code, no change in behavior o add G_TYPE_{{U,}CHAR,LONG} o introduce xt_append_settings() to simplify allthethings() and about_webkit() o rework output to look much more c like o spend way too much effort aligning the /* number flags=0x.... */ comments o compact output and be as c like as possible --- about.c | 155 ++++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 101 insertions(+), 54 deletions(-) (limited to 'about.c') diff --git a/about.c b/about.c index db76510..97ab7a4 100644 --- a/about.c +++ b/about.c @@ -85,6 +85,8 @@ void update_cookie_tabs(struct tab *apart_from); int about_webkit(struct tab *, struct karg *); int allthethings(struct tab *, struct karg *); +extern SoupSession *session; + struct about_type about_list[] = { { XT_URI_ABOUT_ABOUT, xtp_page_ab }, { XT_URI_ABOUT_ALLTHETHINGS, allthethings }, @@ -1976,24 +1978,16 @@ startpage_add(const char *fmt, ...) gchar * show_g_object_settings(GObject *o, char *str, int recurse) { - char *b, *body, *valstr; + char *b, *p, *body, *valstr, *tmpstr; guint n_props = 0; int i; GParamSpec *pspec; const gchar *tname; GValue value; - int typeno; - const gchar *string; - gboolean boolean; - gfloat fp; - gdouble fpd; - gint number; - guint unumber; - int64_t number64; - uint64_t unumber64; + int typeno = 0; GObject *object; GParamSpec **proplist; - char *tmpstr, *tmpsettings; + char *tmpsettings; if (!G_IS_OBJECT(o)) { fprintf(stderr, "%s is not a g_object\n", str); @@ -2001,7 +1995,12 @@ show_g_object_settings(GObject *o, char *str, int recurse) } proplist = g_object_class_list_properties( G_OBJECT_GET_CLASS(o), &n_props); - body = g_strdup_printf("%s: %3d settings\n", str, n_props); + if (n_props == 0) { + body = g_strdup("settings[0] = { }"); + goto end_show_g_objects; + } + + body = g_strdup_printf("settings[%d] = {\n", n_props); for (i=0; i < n_props; i++) { pspec = proplist[i]; tname = G_OBJECT_TYPE_NAME(pspec); @@ -2021,48 +2020,64 @@ show_g_object_settings(GObject *o, char *str, int recurse) typeno = G_TYPE_FUNDAMENTAL( G_VALUE_TYPE(&value) ); switch ( typeno ) { case G_TYPE_ENUM: - number = g_value_get_enum(&value); - valstr = g_strdup_printf("%d", number); + valstr = g_strdup_printf("%d", + g_value_get_enum(&value)); + break; + case G_TYPE_CHAR: + valstr = g_strdup_printf("%c", + g_value_get_schar(&value)); + break; + case G_TYPE_UCHAR: + valstr = g_strdup_printf("%c", + g_value_get_uchar(&value)); + break; + case G_TYPE_LONG: + valstr = g_strdup_printf("%ld", + g_value_get_long(&value)); + break; + case G_TYPE_ULONG: + valstr = g_strdup_printf("%ld", + g_value_get_ulong(&value)); break; case G_TYPE_INT: - number = g_value_get_int(&value); - valstr = g_strdup_printf("%d", number); + valstr = g_strdup_printf("%d", + g_value_get_int(&value)); break; case G_TYPE_INT64: - number64 = (int64_t)g_value_get_int64(&value); - valstr = g_strdup_printf("%" PRIo64, number64); + valstr = g_strdup_printf("%" PRIo64, + /* (int64_t) */ g_value_get_int64(&value)); break; case G_TYPE_UINT: - unumber = g_value_get_uint(&value); - valstr = g_strdup_printf("%d", unumber); + valstr = g_strdup_printf("%d", + g_value_get_uint(&value)); break; case G_TYPE_UINT64: - unumber64 = - (uint64_t)g_value_get_uint64(&value); - valstr = - g_strdup_printf("%" PRIu64, unumber64); + valstr = g_strdup_printf("%" PRIu64, + /* (uint64_t) */ g_value_get_uint64(&value)); break; case G_TYPE_FLAGS: - unumber = g_value_get_flags(&value); - valstr = g_strdup_printf("0x%x", unumber); + valstr = g_strdup_printf("0x%x", + g_value_get_flags(&value)); break; case G_TYPE_BOOLEAN: - boolean = g_value_get_boolean(&value); valstr = g_strdup_printf("%s", - boolean ? "TRUE" : "FALSE"); + g_value_get_boolean(&value) ? "TRUE" : "FALSE"); break; case G_TYPE_FLOAT: - fp = g_value_get_float(&value); - valstr = g_strdup_printf("%f", fp); + valstr = g_strdup_printf("%f", + g_value_get_float(&value)); break; case G_TYPE_DOUBLE: - fpd = g_value_get_double(&value); - valstr = g_strdup_printf("%f", fpd); + valstr = g_strdup_printf("%f", + g_value_get_double(&value)); break; case G_TYPE_STRING: - string = g_value_get_string(&value); valstr = g_strdup_printf("\"%s\"", - string); + g_value_get_string(&value)); + break; + case G_TYPE_POINTER: + valstr = g_strdup_printf("%p", + g_value_get_pointer(&value)); break; case G_TYPE_OBJECT: object = g_value_get_object(&value); @@ -2072,16 +2087,20 @@ show_g_object_settings(GObject *o, char *str, int recurse) str); tmpsettings = show_g_object_settings( object, tmpstr, recurse); + g_free(tmpstr); + if (strrchr(tmpsettings, '\n') != NULL) { valstr = g_strdup_printf( - "{\n%s%s }\n", + "%s%s }", tmpsettings, str); - g_free(tmpstr); g_free(tmpsettings); } else { + valstr = tmpsettings; + } + } else { valstr = g_strdup_printf("<...>"); } } else { - valstr = g_strdup_printf("NULL"); + valstr = g_strdup_printf("settings[] = NULL"); } break; default: @@ -2091,24 +2110,57 @@ show_g_object_settings(GObject *o, char *str, int recurse) } } + tmpstr = g_strdup_printf("%-13s %s%s%s,", tname, pspec->name, + (typeno == G_TYPE_OBJECT) ? "." : " = ", valstr); b = body; - body = g_strdup_printf( - "%s%s: %3d: flags=0x%08x, %-13s %s = %s\n", - body, str, i, pspec->flags, tname, pspec->name, - valstr); + +#define XT_G_OBJECT_SPACING 50 + p = strrchr(tmpstr, '\n'); + if (p == NULL && strlen(tmpstr) > XT_G_OBJECT_SPACING) { + body = g_strdup_printf( + "%s%s %-50s\n%s %50s /* %3d flags=0x%08x */\n", + body, str, tmpstr, str, "", i, pspec->flags); + } else { + char *fmt; + int strspaces; + if (p == NULL) + strspaces = XT_G_OBJECT_SPACING; + else + strspaces = strlen(tmpstr) - (strlen(p) - strlen(str)) + XT_G_OBJECT_SPACING + 5; + fmt = g_strdup_printf("%%s%%s %%-%ds /* %%3d flags=0x%%08x */\n", strspaces); + body = g_strdup_printf(fmt, body, str, tmpstr, i, pspec->flags); + g_free(fmt); + } + g_free(tmpstr); g_free(b); g_free(valstr); } +end_show_g_objects: g_free(proplist); return (body); } +char * +xt_append_settings(char *str, GObject *object, char *name, int recurse) +{ + char *newstr, *settings; + + settings = show_g_object_settings(object, name, recurse); + if (str == NULL) { + str = g_strdup(""); + } + newstr = g_strdup_printf("%s%s %s%s };\n", str, name, settings, name); + g_free(str); + + return newstr; +} + int about_webkit(struct tab *t, struct karg *arg) { char *page, *body, *settingstr; - settingstr = show_g_object_settings(G_OBJECT(t->settings), + settingstr = xt_append_settings(NULL, G_OBJECT(t->settings), "t->settings", 0); body = g_strdup_printf("
%s
\n", settingstr); g_free(settingstr); @@ -2125,22 +2177,17 @@ about_webkit(struct tab *t, struct karg *arg) int allthethings(struct tab *t, struct karg *arg) { - char *page, *body, *b, *settingstr; + char *page, *body, *b; extern GtkWidget *main_window; - body = show_g_object_settings(G_OBJECT(t->wv), "t->wv", 1); - b = body; - settingstr = show_g_object_settings(G_OBJECT(t->inspector), + body = xt_append_settings(NULL, G_OBJECT(t->wv), "t->wv", 1); + body = xt_append_settings(body, G_OBJECT(t->inspector), "t->inspector", 1); - body = g_strdup_printf("%s%s", body, settingstr); - g_free(b); - g_free(settingstr); - b = body; - settingstr = show_g_object_settings(G_OBJECT(main_window), + body = xt_append_settings(body, G_OBJECT(session), + "session", 1); + body = xt_append_settings(body, G_OBJECT(main_window), "main_window", 1); - body = g_strdup_printf("%s%s", body, settingstr); - g_free(b); - g_free(settingstr); + b = body; body = g_strdup_printf("
%scan paste clipboard = %d\n
", body, webkit_web_view_can_paste_clipboard(t->wv)); -- cgit 1.4.1-2-gfad0 From e53d882ad2e852d2d407e3b273328fb3b9d7d08f Mon Sep 17 00:00:00 2001 From: "Todd T. Fries" Date: Tue, 31 Jul 2012 16:23:12 -0500 Subject: cast warnings to oblivion --- about.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'about.c') diff --git a/about.c b/about.c index 97ab7a4..f3701bc 100644 --- a/about.c +++ b/about.c @@ -2045,7 +2045,7 @@ show_g_object_settings(GObject *o, char *str, int recurse) break; case G_TYPE_INT64: valstr = g_strdup_printf("%" PRIo64, - /* (int64_t) */ g_value_get_int64(&value)); + (int64_t) g_value_get_int64(&value)); break; case G_TYPE_UINT: valstr = g_strdup_printf("%d", @@ -2053,7 +2053,7 @@ show_g_object_settings(GObject *o, char *str, int recurse) break; case G_TYPE_UINT64: valstr = g_strdup_printf("%" PRIu64, - /* (uint64_t) */ g_value_get_uint64(&value)); + (uint64_t) g_value_get_uint64(&value)); break; case G_TYPE_FLAGS: valstr = g_strdup_printf("0x%x", -- cgit 1.4.1-2-gfad0 From d01adf2fd22f8121f2996c1d61aae83505e2a0e7 Mon Sep 17 00:00:00 2001 From: "Todd T. Fries" Date: Wed, 8 Aug 2012 10:26:35 -0500 Subject: comment soup session bits for now once the associated warnings go away, this can be re-enabled --- about.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'about.c') diff --git a/about.c b/about.c index f3701bc..54e12a6 100644 --- a/about.c +++ b/about.c @@ -2183,8 +2183,10 @@ allthethings(struct tab *t, struct karg *arg) body = xt_append_settings(NULL, G_OBJECT(t->wv), "t->wv", 1); body = xt_append_settings(body, G_OBJECT(t->inspector), "t->inspector", 1); +#if 0 /* not until warnings are gone */ body = xt_append_settings(body, G_OBJECT(session), "session", 1); +#endif body = xt_append_settings(body, G_OBJECT(main_window), "main_window", 1); -- cgit 1.4.1-2-gfad0 From 34456aad5080dd830ff4af982e7ec1d4dcde2622 Mon Sep 17 00:00:00 2001 From: "Todd T. Fries" Date: Wed, 8 Aug 2012 11:04:09 -0500 Subject: breakout deeply nested function and comment soup session soup session will be exploded in about:allthethings once the warnings associated with exploding it are fixed --- about.c | 200 +++++++++++++++++++++++++++++++------------------------------ xombrero.h | 2 + 2 files changed, 105 insertions(+), 97 deletions(-) (limited to 'about.c') diff --git a/about.c b/about.c index 54e12a6..2125b71 100644 --- a/about.c +++ b/about.c @@ -1974,20 +1974,116 @@ startpage_add(const char *fmt, ...) TAILQ_INSERT_TAIL(&spl, s, entry); } +gchar *show_g_object_settings(GObject *, char *, int); + +char * +xt_g_object_serialize(GValue *value, const gchar *tname, char *str, int recurse) +{ + int typeno = 0; + char *valstr, *tmpstr, *tmpsettings; + GObject *object; + + typeno = G_TYPE_FUNDAMENTAL( G_VALUE_TYPE(value) ); + switch ( typeno ) { + case G_TYPE_ENUM: + valstr = g_strdup_printf("%d", + g_value_get_enum(value)); + break; + case G_TYPE_CHAR: + valstr = g_strdup_printf("%c", + g_value_get_schar(value)); + break; + case G_TYPE_UCHAR: + valstr = g_strdup_printf("%c", + g_value_get_uchar(value)); + break; + case G_TYPE_LONG: + valstr = g_strdup_printf("%ld", + g_value_get_long(value)); + break; + case G_TYPE_ULONG: + valstr = g_strdup_printf("%ld", + g_value_get_ulong(value)); + break; + case G_TYPE_INT: + valstr = g_strdup_printf("%d", + g_value_get_int(value)); + break; + case G_TYPE_INT64: + valstr = g_strdup_printf("%" PRIo64, + (int64_t) g_value_get_int64(value)); + break; + case G_TYPE_UINT: + valstr = g_strdup_printf("%d", + g_value_get_uint(value)); + break; + case G_TYPE_UINT64: + valstr = g_strdup_printf("%" PRIu64, + (uint64_t) g_value_get_uint64(value)); + break; + case G_TYPE_FLAGS: + valstr = g_strdup_printf("0x%x", + g_value_get_flags(value)); + break; + case G_TYPE_BOOLEAN: + valstr = g_strdup_printf("%s", + g_value_get_boolean(value) ? "TRUE" : "FALSE"); + break; + case G_TYPE_FLOAT: + valstr = g_strdup_printf("%f", + g_value_get_float(value)); + break; + case G_TYPE_DOUBLE: + valstr = g_strdup_printf("%f", + g_value_get_double(value)); + break; + case G_TYPE_STRING: + valstr = g_strdup_printf("\"%s\"", + g_value_get_string(value)); + break; + case G_TYPE_POINTER: + valstr = g_strdup_printf("%p", + g_value_get_pointer(value)); + break; + case G_TYPE_OBJECT: + object = g_value_get_object(value); + if (object != NULL) { + if (recurse) { + tmpstr = g_strdup_printf("%s ", str); + tmpsettings = show_g_object_settings( object, + tmpstr, recurse); + g_free(tmpstr); + + if (strrchr(tmpsettings, '\n') != NULL) { + valstr = g_strdup_printf("%s%s }", + tmpsettings, str); + g_free(tmpsettings); + } else { + valstr = tmpsettings; + } + } else { + valstr = g_strdup_printf("<...>"); + } + } else { + valstr = g_strdup_printf("settings[] = NULL"); + } + break; + default: + valstr = g_strdup_printf("type %s unhandled", tname); + } + return valstr; +} gchar * show_g_object_settings(GObject *o, char *str, int recurse) { char *b, *p, *body, *valstr, *tmpstr; guint n_props = 0; - int i; + int i, typeno = 0; GParamSpec *pspec; const gchar *tname; GValue value; - int typeno = 0; - GObject *object; GParamSpec **proplist; - char *tmpsettings; if (!G_IS_OBJECT(o)) { fprintf(stderr, "%s is not a g_object\n", str); @@ -2013,101 +2109,13 @@ show_g_object_settings(GObject *o, char *str, int recurse) g_value_init(&value, G_PARAM_SPEC_VALUE_TYPE(pspec)); g_object_get_property(G_OBJECT(o), pspec->name, &value); + typeno = G_TYPE_FUNDAMENTAL( G_VALUE_TYPE(&value) ); } /* based on the type, recurse and display values */ if (valstr == NULL) { - typeno = G_TYPE_FUNDAMENTAL( G_VALUE_TYPE(&value) ); - switch ( typeno ) { - case G_TYPE_ENUM: - valstr = g_strdup_printf("%d", - g_value_get_enum(&value)); - break; - case G_TYPE_CHAR: - valstr = g_strdup_printf("%c", - g_value_get_schar(&value)); - break; - case G_TYPE_UCHAR: - valstr = g_strdup_printf("%c", - g_value_get_uchar(&value)); - break; - case G_TYPE_LONG: - valstr = g_strdup_printf("%ld", - g_value_get_long(&value)); - break; - case G_TYPE_ULONG: - valstr = g_strdup_printf("%ld", - g_value_get_ulong(&value)); - break; - case G_TYPE_INT: - valstr = g_strdup_printf("%d", - g_value_get_int(&value)); - break; - case G_TYPE_INT64: - valstr = g_strdup_printf("%" PRIo64, - (int64_t) g_value_get_int64(&value)); - break; - case G_TYPE_UINT: - valstr = g_strdup_printf("%d", - g_value_get_uint(&value)); - break; - case G_TYPE_UINT64: - valstr = g_strdup_printf("%" PRIu64, - (uint64_t) g_value_get_uint64(&value)); - break; - case G_TYPE_FLAGS: - valstr = g_strdup_printf("0x%x", - g_value_get_flags(&value)); - break; - case G_TYPE_BOOLEAN: - valstr = g_strdup_printf("%s", - g_value_get_boolean(&value) ? "TRUE" : "FALSE"); - break; - case G_TYPE_FLOAT: - valstr = g_strdup_printf("%f", - g_value_get_float(&value)); - break; - case G_TYPE_DOUBLE: - valstr = g_strdup_printf("%f", - g_value_get_double(&value)); - break; - case G_TYPE_STRING: - valstr = g_strdup_printf("\"%s\"", - g_value_get_string(&value)); - break; - case G_TYPE_POINTER: - valstr = g_strdup_printf("%p", - g_value_get_pointer(&value)); - break; - case G_TYPE_OBJECT: - object = g_value_get_object(&value); - if (object != NULL) { - if (recurse) { - tmpstr = g_strdup_printf("%s ", - str); - tmpsettings = show_g_object_settings( - object, tmpstr, recurse); - g_free(tmpstr); - if (strrchr(tmpsettings, '\n') != NULL) { - valstr = g_strdup_printf( - "%s%s }", - tmpsettings, str); - g_free(tmpsettings); - } else { - valstr = tmpsettings; - } - } else { - valstr = g_strdup_printf("<...>"); - } - } else { - valstr = g_strdup_printf("settings[] = NULL"); - } - break; - default: - valstr = g_strdup_printf( - "type %s unhandled", - tname); - } + valstr = xt_g_object_serialize(&value, tname, str, + recurse); } tmpstr = g_strdup_printf("%-13s %s%s%s,", tname, pspec->name, @@ -2187,8 +2195,6 @@ allthethings(struct tab *t, struct karg *arg) body = xt_append_settings(body, G_OBJECT(session), "session", 1); #endif - body = xt_append_settings(body, G_OBJECT(main_window), - "main_window", 1); b = body; body = g_strdup_printf("
%scan paste clipboard = %d\n
", body, diff --git a/xombrero.h b/xombrero.h index d5da4d9..eb4e6e3 100644 --- a/xombrero.h +++ b/xombrero.h @@ -924,6 +924,8 @@ extern SoupSession *session; extern GtkNotebook *notebook; extern GtkListStore *completion_model; extern uint64_t blocked_cookies; +extern GtkWidget *main_window; +extern SoupSession *session; extern void (*_soup_cookie_jar_add_cookie)(SoupCookieJar *, SoupCookie *); -- cgit 1.4.1-2-gfad0 From 5742cb70caadb4159a7091d60dd17be465f1654d Mon Sep 17 00:00:00 2001 From: "Todd T. Fries" Date: Wed, 8 Aug 2012 10:39:12 -0500 Subject: initial stab at toplevel window infoz --- about.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'about.c') diff --git a/about.c b/about.c index 2125b71..e415938 100644 --- a/about.c +++ b/about.c @@ -2187,6 +2187,8 @@ allthethings(struct tab *t, struct karg *arg) { char *page, *body, *b; extern GtkWidget *main_window; + GList *list, *liter; + int toplevelcount = 0; body = xt_append_settings(NULL, G_OBJECT(t->wv), "t->wv", 1); body = xt_append_settings(body, G_OBJECT(t->inspector), @@ -2195,7 +2197,15 @@ allthethings(struct tab *t, struct karg *arg) body = xt_append_settings(body, G_OBJECT(session), "session", 1); #endif + list = gtk_window_list_toplevels(); + for(liter = list; liter = liter->next; liter != NULL) { + b = g_strdup_printf("toplevel#%x", toplevelcount++); + + body = xt_append_settings(body, G_OBJECT(liter->data), b, 1); + g_free(b); + } + b = body; body = g_strdup_printf("
%scan paste clipboard = %d\n
", body, webkit_web_view_can_paste_clipboard(t->wv)); -- cgit 1.4.1-2-gfad0 From 2428c63de10dfbb128c58aafb29ce1c22db32400 Mon Sep 17 00:00:00 2001 From: "Todd T. Fries" Date: Wed, 8 Aug 2012 10:53:26 -0500 Subject: fix for() loop, s/settings/name of gtk widget/, nix main_window --- about.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'about.c') diff --git a/about.c b/about.c index e415938..0ee45cf 100644 --- a/about.c +++ b/about.c @@ -2084,6 +2084,8 @@ show_g_object_settings(GObject *o, char *str, int recurse) const gchar *tname; GValue value; GParamSpec **proplist; + char *tmpsettings; + const gchar *name; if (!G_IS_OBJECT(o)) { fprintf(stderr, "%s is not a g_object\n", str); @@ -2091,12 +2093,18 @@ show_g_object_settings(GObject *o, char *str, int recurse) } proplist = g_object_class_list_properties( G_OBJECT_GET_CLASS(o), &n_props); + + if (GTK_IS_WIDGET(o)) { + name = gtk_widget_get_name(GTK_WIDGET(o)); + } else { + name = "settings"; + } if (n_props == 0) { - body = g_strdup("settings[0] = { }"); + body = g_strdup_printf("%s[0] = { }", name); goto end_show_g_objects; } - body = g_strdup_printf("settings[%d] = {\n", n_props); + body = g_strdup_printf("%s[%d] = {\n", name, n_props); for (i=0; i < n_props; i++) { pspec = proplist[i]; tname = G_OBJECT_TYPE_NAME(pspec); @@ -2186,7 +2194,6 @@ int allthethings(struct tab *t, struct karg *arg) { char *page, *body, *b; - extern GtkWidget *main_window; GList *list, *liter; int toplevelcount = 0; @@ -2198,7 +2205,7 @@ allthethings(struct tab *t, struct karg *arg) "session", 1); #endif list = gtk_window_list_toplevels(); - for(liter = list; liter = liter->next; liter != NULL) { + for(liter = list; liter != NULL; liter = liter->next) { b = g_strdup_printf("toplevel#%x", toplevelcount++); body = xt_append_settings(body, G_OBJECT(liter->data), b, 1); -- cgit 1.4.1-2-gfad0 From b262f9a713727e4db30e7f24888480c6c023312a Mon Sep 17 00:00:00 2001 From: "Todd T. Fries" Date: Wed, 8 Aug 2012 11:09:13 -0500 Subject: nix unused var --- about.c | 1 - 1 file changed, 1 deletion(-) (limited to 'about.c') diff --git a/about.c b/about.c index 0ee45cf..b1a8777 100644 --- a/about.c +++ b/about.c @@ -2084,7 +2084,6 @@ show_g_object_settings(GObject *o, char *str, int recurse) const gchar *tname; GValue value; GParamSpec **proplist; - char *tmpsettings; const gchar *name; if (!G_IS_OBJECT(o)) { -- cgit 1.4.1-2-gfad0