1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Remove double declaration and reduce scope of pcontact

In command/commands.c you declare pcontact at the top of the function.
Later in one case you declare it again and use it in a small scope. And
in the same function you use it again this time from the first
declaration. I think you intended only declaring it one time. At first I
thought about top of the function because its easier to find. Then I saw
that you declare "Jid jid" not at the top too, and I think for the sake
of reducing scope it is better. So I went for this approach.
This commit is contained in:
Michael Vetter 2015-10-09 10:34:58 +02:00
parent de15d47be4
commit 8dfa41ea8e

View File

@ -2012,7 +2012,6 @@ cmd_info(ProfWin *window, const char * const command, gchar **args)
char *usr = args[0]; char *usr = args[0];
jabber_conn_status_t conn_status = jabber_get_connection_status(); jabber_conn_status_t conn_status = jabber_get_connection_status();
PContact pcontact = NULL;
if (conn_status != JABBER_CONNECTED) { if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected."); cons_show("You are not currently connected.");
@ -2075,7 +2074,7 @@ cmd_info(ProfWin *window, const char * const command, gchar **args)
if (usr_jid == NULL) { if (usr_jid == NULL) {
usr_jid = usr; usr_jid = usr;
} }
pcontact = roster_get_contact(usr_jid); PContact pcontact = roster_get_contact(usr_jid);
if (pcontact) { if (pcontact) {
cons_show_info(pcontact); cons_show_info(pcontact);
} else { } else {
@ -2096,7 +2095,6 @@ gboolean
cmd_caps(ProfWin *window, const char * const command, gchar **args) cmd_caps(ProfWin *window, const char * const command, gchar **args)
{ {
jabber_conn_status_t conn_status = jabber_get_connection_status(); jabber_conn_status_t conn_status = jabber_get_connection_status();
PContact pcontact = NULL;
Occupant *occupant = NULL; Occupant *occupant = NULL;
if (conn_status != JABBER_CONNECTED) { if (conn_status != JABBER_CONNECTED) {
@ -2130,7 +2128,7 @@ cmd_caps(ProfWin *window, const char * const command, gchar **args)
if (jid->fulljid == NULL) { if (jid->fulljid == NULL) {
cons_show("You must provide a full jid to the /caps command."); cons_show("You must provide a full jid to the /caps command.");
} else { } else {
pcontact = roster_get_contact(jid->barejid); PContact pcontact = roster_get_contact(jid->barejid);
if (pcontact == NULL) { if (pcontact == NULL) {
cons_show("Contact not found in roster: %s", jid->barejid); cons_show("Contact not found in roster: %s", jid->barejid);
} else { } else {
@ -2173,7 +2171,6 @@ gboolean
cmd_software(ProfWin *window, const char * const command, gchar **args) cmd_software(ProfWin *window, const char * const command, gchar **args)
{ {
jabber_conn_status_t conn_status = jabber_get_connection_status(); jabber_conn_status_t conn_status = jabber_get_connection_status();
Occupant *occupant = NULL;
if (conn_status != JABBER_CONNECTED) { if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected."); cons_show("You are not currently connected.");
@ -2186,7 +2183,7 @@ cmd_software(ProfWin *window, const char * const command, gchar **args)
if (args[0]) { if (args[0]) {
ProfMucWin *mucwin = (ProfMucWin*)window; ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
occupant = muc_roster_item(mucwin->roomjid, args[0]); Occupant *occupant = muc_roster_item(mucwin->roomjid, args[0]);
if (occupant) { if (occupant) {
Jid *jid = jid_create_from_bare_and_resource(mucwin->roomjid, args[0]); Jid *jid = jid_create_from_bare_and_resource(mucwin->roomjid, args[0]);
iq_send_software_version(jid->fulljid); iq_send_software_version(jid->fulljid);