diff options
Diffstat (limited to 'src/fe-gtk/menu.c')
-rw-r--r-- | src/fe-gtk/menu.c | 92 |
1 files changed, 43 insertions, 49 deletions
diff --git a/src/fe-gtk/menu.c b/src/fe-gtk/menu.c index 945f6360..902af92e 100644 --- a/src/fe-gtk/menu.c +++ b/src/fe-gtk/menu.c @@ -137,7 +137,7 @@ nick_command_parse (session *sess, char *cmd, char *nick, char *allnick) /* this can't overflow, since popup->cmd is only 256 */ len = strlen (cmd) + strlen (nick) + strlen (allnick) + 512; - buf = malloc (len); + buf = g_malloc (len); auto_insert (buf, len, cmd, 0, 0, allnick, sess->channel, "", server_get_network (sess->server, TRUE), host, @@ -145,7 +145,7 @@ nick_command_parse (session *sess, char *cmd, char *nick, char *allnick) nick_command (sess, buf); - free (buf); + g_free (buf); } /* userlist button has been clicked */ @@ -166,11 +166,12 @@ userlist_button_cb (GtkWidget * button, char *cmd) if (sess->type == SESS_DIALOG) { /* fake a selection */ - nicks = malloc (sizeof (char *) * 2); + nicks = g_new (char *, 2); nicks[0] = g_strdup (sess->channel); nicks[1] = NULL; num_sel = 1; - } else + } + else { /* find number of selected rows */ nicks = userlist_selection_list (sess->gui->user_tree, &num_sel); @@ -178,14 +179,13 @@ userlist_button_cb (GtkWidget * button, char *cmd) { nick_command_parse (sess, cmd, "", ""); - if (nicks) - free (nicks); + g_free (nicks); return; } } /* create "allnicks" string */ - allnicks = malloc (((NICKLEN + 1) * num_sel) + 1); + allnicks = g_malloc (((NICKLEN + 1) * num_sel) + 1); *allnicks = 0; i = 0; @@ -218,8 +218,8 @@ userlist_button_cb (GtkWidget * button, char *cmd) g_free (nicks[num_sel]); } - free (nicks); - free (allnicks); + g_free (nicks); + g_free (allnicks); } /* a popup-menu-item has been selected */ @@ -393,9 +393,9 @@ toggle_cb (GtkWidget *item, char *pref_name) char buf[256]; if (GTK_CHECK_MENU_ITEM (item)->active) - snprintf (buf, sizeof (buf), "set %s 1", pref_name); + g_snprintf (buf, sizeof (buf), "set %s 1", pref_name); else - snprintf (buf, sizeof (buf), "set %s 0", pref_name); + g_snprintf (buf, sizeof (buf), "set %s 0", pref_name); handle_command (current_sess, buf, FALSE); } @@ -403,12 +403,11 @@ toggle_cb (GtkWidget *item, char *pref_name) static int is_in_path (char *cmd) { - char *prog = g_strdup (cmd + 1); /* 1st char is "!" */ - char *path, *orig; + char *orig = g_strdup (cmd + 1); /* 1st char is "!" */ + char *prog = orig; char **argv; int argc; - orig = prog; /* save for free()ing */ /* special-case these default entries. */ /* 123456789012345678 */ if (strncmp (prog, "gnome-terminal -x ", 18) == 0) @@ -417,15 +416,14 @@ is_in_path (char *cmd) if (g_shell_parse_argv (prog, &argc, &argv, NULL)) { - path = g_find_program_in_path (argv[0]); + char *path = g_find_program_in_path (argv[0]); + g_strfreev (argv); if (path) { g_free (path); g_free (orig); - g_strfreev (argv); return 1; } - g_strfreev (argv); } g_free (orig); @@ -588,7 +586,7 @@ menu_nickinfo_cb (GtkWidget *menu, session *sess) return; /* issue a /WHOIS */ - snprintf (buf, sizeof (buf), "WHOIS %s %s", str_copy, str_copy); + g_snprintf (buf, sizeof (buf), "WHOIS %s %s", str_copy, str_copy); handle_command (sess, buf, FALSE); /* and hide the output */ sess->server->skip_next_whois = 1; @@ -614,30 +612,30 @@ menu_create_nickinfo_menu (struct User *user, GtkWidget *submenu) /* let the translators tweak this if need be */ fmt = _("<tt><b>%-11s</b></tt> %s"); - snprintf (unknown, sizeof (unknown), "<i>%s</i>", _("Unknown")); + g_snprintf (unknown, sizeof (unknown), "<i>%s</i>", _("Unknown")); if (user->realname) { real = strip_color (user->realname, -1, STRIP_ALL|STRIP_ESCMARKUP); - snprintf (buf, sizeof (buf), fmt, _("Real Name:"), real); + g_snprintf (buf, sizeof (buf), fmt, _("Real Name:"), real); g_free (real); } else { - snprintf (buf, sizeof (buf), fmt, _("Real Name:"), unknown); + g_snprintf (buf, sizeof (buf), fmt, _("Real Name:"), unknown); } item = menu_quick_item (0, buf, submenu, XCMENU_MARKUP, 0, 0); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (copy_to_clipboard_cb), user->realname ? user->realname : unknown); - snprintf (buf, sizeof (buf), fmt, _("User:"), + g_snprintf (buf, sizeof (buf), fmt, _("User:"), user->hostname ? user->hostname : unknown); item = menu_quick_item (0, buf, submenu, XCMENU_MARKUP, 0, 0); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (copy_to_clipboard_cb), user->hostname ? user->hostname : unknown); - snprintf (buf, sizeof (buf), fmt, _("Account:"), + g_snprintf (buf, sizeof (buf), fmt, _("Account:"), user->account ? user->account : unknown); item = menu_quick_item (0, buf, submenu, XCMENU_MARKUP, 0, 0); g_signal_connect (G_OBJECT (item), "activate", @@ -647,13 +645,13 @@ menu_create_nickinfo_menu (struct User *user, GtkWidget *submenu) users_country = country (user->hostname); if (users_country) { - snprintf (buf, sizeof (buf), fmt, _ ("Country:"), users_country); + g_snprintf (buf, sizeof (buf), fmt, _ ("Country:"), users_country); item = menu_quick_item (0, buf, submenu, XCMENU_MARKUP, 0, 0); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (copy_to_clipboard_cb), users_country); } - snprintf (buf, sizeof (buf), fmt, _("Server:"), + g_snprintf (buf, sizeof (buf), fmt, _("Server:"), user->servername ? user->servername : unknown); item = menu_quick_item (0, buf, submenu, XCMENU_MARKUP, 0, 0); g_signal_connect (G_OBJECT (item), "activate", @@ -664,12 +662,12 @@ menu_create_nickinfo_menu (struct User *user, GtkWidget *submenu) { char min[96]; - snprintf (min, sizeof (min), _("%u minutes ago"), + g_snprintf (min, sizeof (min), _("%u minutes ago"), (unsigned int) ((time (0) - user->lasttalk) / 60)); - snprintf (buf, sizeof (buf), fmt, _("Last Msg:"), min); + g_snprintf (buf, sizeof (buf), fmt, _("Last Msg:"), min); } else { - snprintf (buf, sizeof (buf), fmt, _("Last Msg:"), unknown); + g_snprintf (buf, sizeof (buf), fmt, _("Last Msg:"), unknown); } menu_quick_item (0, buf, submenu, XCMENU_MARKUP, 0, 0); @@ -679,7 +677,7 @@ menu_create_nickinfo_menu (struct User *user, GtkWidget *submenu) if (away) { char *msg = strip_color (away->message ? away->message : unknown, -1, STRIP_ALL|STRIP_ESCMARKUP); - snprintf (buf, sizeof (buf), fmt, _("Away Msg:"), msg); + g_snprintf (buf, sizeof (buf), fmt, _("Away Msg:"), msg); g_free (msg); item = menu_quick_item (0, buf, submenu, XCMENU_MARKUP, 0, 0); g_signal_connect (G_OBJECT (item), "activate", @@ -728,16 +726,15 @@ menu_nickmenu (session *sess, GdkEventButton *event, char *nick, int num_sel) struct User *user; GtkWidget *submenu, *menu = gtk_menu_new (); - if (str_copy) - free (str_copy); - str_copy = strdup (nick); + g_free (str_copy); + str_copy = g_strdup (nick); submenu_list = 0; /* first time through, might not be 0 */ /* more than 1 nick selected? */ if (num_sel > 1) { - snprintf (buf, sizeof (buf), _("%d nicks selected."), num_sel); + g_snprintf (buf, sizeof (buf), _("%d nicks selected."), num_sel); menu_quick_item (0, buf, menu, 0, 0, 0); menu_quick_item (0, 0, menu, XCMENU_SHADED, 0, 0); } else @@ -938,7 +935,7 @@ open_url_cb (GtkWidget *item, char *url) char buf[512]; /* pass this to /URL so it can handle irc:// */ - snprintf (buf, sizeof (buf), "URL %s", url); + g_snprintf (buf, sizeof (buf), "URL %s", url); handle_command (current_sess, buf, FALSE); } @@ -948,20 +945,19 @@ menu_urlmenu (GdkEventButton *event, char *url) GtkWidget *menu; char *tmp, *chop; - if (str_copy) - free (str_copy); - str_copy = strdup (url); + g_free (str_copy); + str_copy = g_strdup (url); menu = gtk_menu_new (); /* more than 51 chars? Chop it */ if (g_utf8_strlen (str_copy, -1) >= 52) { - tmp = strdup (str_copy); + tmp = g_strdup (str_copy); chop = g_utf8_offset_to_pointer (tmp, 48); chop[0] = chop[1] = chop[2] = '.'; chop[3] = 0; menu_quick_item (0, tmp, menu, XCMENU_SHADED, 0, 0); - free (tmp); + g_free (tmp); } else { menu_quick_item (0, str_copy, menu, XCMENU_SHADED, 0, 0); @@ -988,7 +984,7 @@ menu_chan_cycle (GtkWidget * menu, char *chan) if (current_sess) { - snprintf (tbuf, sizeof tbuf, "CYCLE %s", chan); + g_snprintf (tbuf, sizeof tbuf, "CYCLE %s", chan); handle_command (current_sess, tbuf, FALSE); } } @@ -1000,7 +996,7 @@ menu_chan_part (GtkWidget * menu, char *chan) if (current_sess) { - snprintf (tbuf, sizeof tbuf, "part %s", chan); + g_snprintf (tbuf, sizeof tbuf, "part %s", chan); handle_command (current_sess, tbuf, FALSE); } } @@ -1012,7 +1008,7 @@ menu_chan_join (GtkWidget * menu, char *chan) if (current_sess) { - snprintf (tbuf, sizeof tbuf, "join %s", chan); + g_snprintf (tbuf, sizeof tbuf, "join %s", chan); handle_command (current_sess, tbuf, FALSE); } } @@ -1026,9 +1022,8 @@ menu_chanmenu (struct session *sess, GdkEventButton * event, char *chan) if (find_channel (sess->server, chan)) is_joined = TRUE; - if (str_copy) - free (str_copy); - str_copy = strdup (chan); + g_free (str_copy); + str_copy = g_strdup (chan); menu = gtk_menu_new (); @@ -1074,9 +1069,8 @@ menu_addfavoritemenu (server *serv, GtkWidget *menu, char *channel, gboolean ist if (channel != str_copy) { - if (str_copy) - free (str_copy); - str_copy = strdup (channel); + g_free (str_copy); + str_copy = g_strdup (channel); } if (istree) @@ -1717,7 +1711,7 @@ menu_about (GtkWidget *wid, gpointer sess) "You should have received a copy of the GNU General Public License\n" \ "along with this program. If not, see <http://www.gnu.org/licenses/>"; - g_snprintf (comment, sizeof(comment), "Compiled: "__DATE__"\n" + g_snprintf (comment, sizeof(comment), "" #ifdef WIN32 "Portable Mode: %s\n" "Build Type: x%d\n" |