1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-02-02 15:08:15 -05:00

Use null check convention in commands.c

This commit is contained in:
James Booth 2015-05-04 22:23:59 +01:00
parent 2b3cc65b52
commit 4acf853b1c

View File

@ -404,7 +404,7 @@ cmd_account(gchar **args, struct cmd_help_t help)
} else { } else {
accounts_set_jid(account_name, jid->barejid); accounts_set_jid(account_name, jid->barejid);
cons_show("Updated jid for account %s: %s", account_name, jid->barejid); cons_show("Updated jid for account %s: %s", account_name, jid->barejid);
if (jid->resourcepart != NULL) { if (jid->resourcepart) {
accounts_set_resource(account_name, jid->resourcepart); accounts_set_resource(account_name, jid->resourcepart);
cons_show("Updated resource for account %s: %s", account_name, jid->resourcepart); cons_show("Updated resource for account %s: %s", account_name, jid->resourcepart);
} }
@ -434,7 +434,7 @@ cmd_account(gchar **args, struct cmd_help_t help)
cons_show("Updated resource for account %s: %s", account_name, value); cons_show("Updated resource for account %s: %s", account_name, value);
cons_show(""); cons_show("");
} else if (strcmp(property, "password") == 0) { } else if (strcmp(property, "password") == 0) {
if(accounts_get_account(account_name)->eval_password != NULL) { if(accounts_get_account(account_name)->eval_password) {
cons_show("Cannot set password when eval_password is set."); cons_show("Cannot set password when eval_password is set.");
} else { } else {
accounts_set_password(account_name, value); accounts_set_password(account_name, value);
@ -442,7 +442,7 @@ cmd_account(gchar **args, struct cmd_help_t help)
cons_show(""); cons_show("");
} }
} else if (strcmp(property, "eval_password") == 0) { } else if (strcmp(property, "eval_password") == 0) {
if(accounts_get_account(account_name)->password != NULL) { if(accounts_get_account(account_name)->password) {
cons_show("Cannot set eval_password when password is set."); cons_show("Cannot set eval_password when password is set.");
} else { } else {
accounts_set_eval_password(account_name, value); accounts_set_eval_password(account_name, value);
@ -755,7 +755,7 @@ cmd_help(gchar **args, struct cmd_help_t help)
} }
GList *curr = ordered_commands; GList *curr = ordered_commands;
while (curr != NULL) { while (curr) {
Command *cmd = curr->data; Command *cmd = curr->data;
cons_show("%-12s: %s", cmd->cmd, cmd->help.short_help); cons_show("%-12s: %s", cmd->cmd, cmd->help.short_help);
curr = g_list_next(curr); curr = g_list_next(curr);
@ -817,12 +817,12 @@ cmd_help(gchar **args, struct cmd_help_t help)
const gchar **help_text = NULL; const gchar **help_text = NULL;
Command *command = g_hash_table_lookup(commands, cmd_with_slash); Command *command = g_hash_table_lookup(commands, cmd_with_slash);
if (command != NULL) { if (command) {
help_text = command->help.long_help; help_text = command->help.long_help;
} }
cons_show(""); cons_show("");
if (help_text != NULL) { if (help_text) {
ProfWin *console = wins_get_console(); ProfWin *console = wins_get_console();
ui_show_lines(console, help_text); ui_show_lines(console, help_text);
} else { } else {
@ -928,13 +928,13 @@ cmd_theme(gchar **args, struct cmd_help_t help)
static void static void
_who_room(gchar **args, struct cmd_help_t help) _who_room(gchar **args, struct cmd_help_t help)
{ {
if ((g_strv_length(args) == 2) && (args[1] != NULL)) { if ((g_strv_length(args) == 2) && args[1]) {
cons_show("Argument group is not applicable to chat rooms."); cons_show("Argument group is not applicable to chat rooms.");
return; return;
} }
// bad arg // bad arg
if (args[0] != NULL && if (args[0] &&
(g_strcmp0(args[0], "online") != 0) && (g_strcmp0(args[0], "online") != 0) &&
(g_strcmp0(args[0], "available") != 0) && (g_strcmp0(args[0], "available") != 0) &&
(g_strcmp0(args[0], "unavailable") != 0) && (g_strcmp0(args[0], "unavailable") != 0) &&
@ -978,7 +978,7 @@ _who_room(gchar **args, struct cmd_help_t help)
} else if (strcmp("available", presence) == 0) { } else if (strcmp("available", presence) == 0) {
GList *filtered = NULL; GList *filtered = NULL;
while (occupants != NULL) { while (occupants) {
Occupant *occupant = occupants->data; Occupant *occupant = occupants->data;
if (muc_occupant_available(occupant)) { if (muc_occupant_available(occupant)) {
filtered = g_list_append(filtered, occupant); filtered = g_list_append(filtered, occupant);
@ -992,7 +992,7 @@ _who_room(gchar **args, struct cmd_help_t help)
} else if (strcmp("unavailable", presence) == 0) { } else if (strcmp("unavailable", presence) == 0) {
GList *filtered = NULL; GList *filtered = NULL;
while (occupants != NULL) { while (occupants) {
Occupant *occupant = occupants->data; Occupant *occupant = occupants->data;
if (!muc_occupant_available(occupant)) { if (!muc_occupant_available(occupant)) {
filtered = g_list_append(filtered, occupant); filtered = g_list_append(filtered, occupant);
@ -1006,7 +1006,7 @@ _who_room(gchar **args, struct cmd_help_t help)
} else { } else {
GList *filtered = NULL; GList *filtered = NULL;
while (occupants != NULL) { while (occupants) {
Occupant *occupant = occupants->data; Occupant *occupant = occupants->data;
const char *presence_str = string_from_resource_presence(occupant->presence); const char *presence_str = string_from_resource_presence(occupant->presence);
if (strcmp(presence_str, presence) == 0) { if (strcmp(presence_str, presence) == 0) {
@ -1060,7 +1060,7 @@ _who_roster(gchar **args, struct cmd_help_t help)
char *presence = args[0]; char *presence = args[0];
// bad arg // bad arg
if ((presence != NULL) if (presence
&& (strcmp(presence, "online") != 0) && (strcmp(presence, "online") != 0)
&& (strcmp(presence, "available") != 0) && (strcmp(presence, "available") != 0)
&& (strcmp(presence, "unavailable") != 0) && (strcmp(presence, "unavailable") != 0)
@ -1075,13 +1075,13 @@ _who_roster(gchar **args, struct cmd_help_t help)
} }
char *group = NULL; char *group = NULL;
if ((g_strv_length(args) == 2) && (args[1] != NULL)) { if ((g_strv_length(args) == 2) && args[1]) {
group = args[1]; group = args[1];
} }
cons_show(""); cons_show("");
GSList *list = NULL; GSList *list = NULL;
if (group != NULL) { if (group) {
list = roster_get_group(group); list = roster_get_group(group);
if (list == NULL) { if (list == NULL) {
cons_show("No such group: %s.", group); cons_show("No such group: %s.", group);
@ -1097,7 +1097,7 @@ _who_roster(gchar **args, struct cmd_help_t help)
// no arg, show all contacts // no arg, show all contacts
if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) { if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) {
if (group != NULL) { if (group) {
if (list == NULL) { if (list == NULL) {
cons_show("No contacts in group %s.", group); cons_show("No contacts in group %s.", group);
} else { } else {
@ -1118,7 +1118,7 @@ _who_roster(gchar **args, struct cmd_help_t help)
GSList *filtered = NULL; GSList *filtered = NULL;
GSList *curr = list; GSList *curr = list;
while (curr != NULL) { while (curr) {
PContact contact = curr->data; PContact contact = curr->data;
if (p_contact_is_available(contact)) { if (p_contact_is_available(contact)) {
filtered = g_slist_append(filtered, contact); filtered = g_slist_append(filtered, contact);
@ -1126,7 +1126,7 @@ _who_roster(gchar **args, struct cmd_help_t help)
curr = g_slist_next(curr); curr = g_slist_next(curr);
} }
if (group != NULL) { if (group) {
if (filtered == NULL) { if (filtered == NULL) {
cons_show("No contacts in group %s are %s.", group, presence); cons_show("No contacts in group %s are %s.", group, presence);
} else { } else {
@ -1148,7 +1148,7 @@ _who_roster(gchar **args, struct cmd_help_t help)
GSList *filtered = NULL; GSList *filtered = NULL;
GSList *curr = list; GSList *curr = list;
while (curr != NULL) { while (curr) {
PContact contact = curr->data; PContact contact = curr->data;
if (!p_contact_is_available(contact)) { if (!p_contact_is_available(contact)) {
filtered = g_slist_append(filtered, contact); filtered = g_slist_append(filtered, contact);
@ -1156,7 +1156,7 @@ _who_roster(gchar **args, struct cmd_help_t help)
curr = g_slist_next(curr); curr = g_slist_next(curr);
} }
if (group != NULL) { if (group) {
if (filtered == NULL) { if (filtered == NULL) {
cons_show("No contacts in group %s are %s.", group, presence); cons_show("No contacts in group %s are %s.", group, presence);
} else { } else {
@ -1178,7 +1178,7 @@ _who_roster(gchar **args, struct cmd_help_t help)
GSList *filtered = NULL; GSList *filtered = NULL;
GSList *curr = list; GSList *curr = list;
while (curr != NULL) { while (curr) {
PContact contact = curr->data; PContact contact = curr->data;
if (p_contact_has_available_resource(contact)) { if (p_contact_has_available_resource(contact)) {
filtered = g_slist_append(filtered, contact); filtered = g_slist_append(filtered, contact);
@ -1186,7 +1186,7 @@ _who_roster(gchar **args, struct cmd_help_t help)
curr = g_slist_next(curr); curr = g_slist_next(curr);
} }
if (group != NULL) { if (group) {
if (filtered == NULL) { if (filtered == NULL) {
cons_show("No contacts in group %s are %s.", group, presence); cons_show("No contacts in group %s are %s.", group, presence);
} else { } else {
@ -1208,7 +1208,7 @@ _who_roster(gchar **args, struct cmd_help_t help)
GSList *filtered = NULL; GSList *filtered = NULL;
GSList *curr = list; GSList *curr = list;
while (curr != NULL) { while (curr) {
PContact contact = curr->data; PContact contact = curr->data;
if (!p_contact_has_available_resource(contact)) { if (!p_contact_has_available_resource(contact)) {
filtered = g_slist_append(filtered, contact); filtered = g_slist_append(filtered, contact);
@ -1216,7 +1216,7 @@ _who_roster(gchar **args, struct cmd_help_t help)
curr = g_slist_next(curr); curr = g_slist_next(curr);
} }
if (group != NULL) { if (group) {
if (filtered == NULL) { if (filtered == NULL) {
cons_show("No contacts in group %s are %s.", group, presence); cons_show("No contacts in group %s are %s.", group, presence);
} else { } else {
@ -1238,7 +1238,7 @@ _who_roster(gchar **args, struct cmd_help_t help)
GSList *filtered = NULL; GSList *filtered = NULL;
GSList *curr = list; GSList *curr = list;
while (curr != NULL) { while (curr) {
PContact contact = curr->data; PContact contact = curr->data;
if (strcmp(p_contact_presence(contact), presence) == 0) { if (strcmp(p_contact_presence(contact), presence) == 0) {
filtered = g_slist_append(filtered, contact); filtered = g_slist_append(filtered, contact);
@ -1246,7 +1246,7 @@ _who_roster(gchar **args, struct cmd_help_t help)
curr = g_slist_next(curr); curr = g_slist_next(curr);
} }
if (group != NULL) { if (group) {
if (filtered == NULL) { if (filtered == NULL) {
cons_show("No contacts in group %s are %s.", group, presence); cons_show("No contacts in group %s are %s.", group, presence);
} else { } else {
@ -1369,9 +1369,9 @@ cmd_group(gchar **args, struct cmd_help_t help)
if (args[0] == NULL) { if (args[0] == NULL) {
GSList *groups = roster_get_groups(); GSList *groups = roster_get_groups();
GSList *curr = groups; GSList *curr = groups;
if (curr != NULL) { if (curr) {
cons_show("Groups:"); cons_show("Groups:");
while (curr != NULL) { while (curr) {
cons_show(" %s", curr->data); cons_show(" %s", curr->data);
curr = g_slist_next(curr); curr = g_slist_next(curr);
} }
@ -1739,7 +1739,7 @@ cmd_status(gchar **args, struct cmd_help_t help)
switch (win_type) switch (win_type)
{ {
case WIN_MUC: case WIN_MUC:
if (usr != NULL) { if (usr) {
ProfMucWin *mucwin = wins_get_current_muc(); ProfMucWin *mucwin = wins_get_current_muc();
ProfWin *window = (ProfWin*) mucwin; ProfWin *window = (ProfWin*) mucwin;
Occupant *occupant = muc_roster_item(mucwin->roomjid, usr); Occupant *occupant = muc_roster_item(mucwin->roomjid, usr);
@ -1753,13 +1753,13 @@ cmd_status(gchar **args, struct cmd_help_t help)
} }
break; break;
case WIN_CHAT: case WIN_CHAT:
if (usr != NULL) { if (usr) {
ui_current_print_line("No parameter required when in chat."); ui_current_print_line("No parameter required when in chat.");
} else { } else {
ProfChatWin *chatwin = wins_get_current_chat(); ProfChatWin *chatwin = wins_get_current_chat();
ProfWin *window = (ProfWin*) chatwin; ProfWin *window = (ProfWin*) chatwin;
PContact pcontact = roster_get_contact(chatwin->barejid); PContact pcontact = roster_get_contact(chatwin->barejid);
if (pcontact != NULL) { if (pcontact) {
win_show_contact(window, pcontact); win_show_contact(window, pcontact);
} else { } else {
win_println(window, "Error getting contact info."); win_println(window, "Error getting contact info.");
@ -1767,7 +1767,7 @@ cmd_status(gchar **args, struct cmd_help_t help)
} }
break; break;
case WIN_PRIVATE: case WIN_PRIVATE:
if (usr != NULL) { if (usr) {
ui_current_print_line("No parameter required when in chat."); ui_current_print_line("No parameter required when in chat.");
} else { } else {
ProfPrivateWin *privatewin = wins_get_current_private(); ProfPrivateWin *privatewin = wins_get_current_private();
@ -1783,7 +1783,7 @@ cmd_status(gchar **args, struct cmd_help_t help)
} }
break; break;
case WIN_CONSOLE: case WIN_CONSOLE:
if (usr != NULL) { if (usr) {
char *usr_jid = roster_barejid_from_name(usr); char *usr_jid = roster_barejid_from_name(usr);
if (usr_jid == NULL) { if (usr_jid == NULL) {
usr_jid = usr; usr_jid = usr;
@ -1840,7 +1840,7 @@ cmd_info(gchar **args, struct cmd_help_t help)
ProfChatWin *chatwin = wins_get_current_chat(); ProfChatWin *chatwin = wins_get_current_chat();
ProfWin *window = (ProfWin*) chatwin; ProfWin *window = (ProfWin*) chatwin;
PContact pcontact = roster_get_contact(chatwin->barejid); PContact pcontact = roster_get_contact(chatwin->barejid);
if (pcontact != NULL) { if (pcontact) {
win_show_info(window, pcontact); win_show_info(window, pcontact);
} else { } else {
win_println(window, "Error getting contact info."); win_println(window, "Error getting contact info.");
@ -1870,7 +1870,7 @@ cmd_info(gchar **args, struct cmd_help_t help)
usr_jid = usr; usr_jid = usr;
} }
pcontact = roster_get_contact(usr_jid); pcontact = roster_get_contact(usr_jid);
if (pcontact != NULL) { if (pcontact) {
cons_show_info(pcontact); cons_show_info(pcontact);
} else { } else {
cons_show("No such contact \"%s\" in roster.", usr); cons_show("No such contact \"%s\" in roster.", usr);
@ -1902,7 +1902,7 @@ cmd_caps(gchar **args, struct cmd_help_t help)
switch (win_type) switch (win_type)
{ {
case WIN_MUC: case WIN_MUC:
if (args[0] != NULL) { if (args[0]) {
ProfMucWin *mucwin = wins_get_current_muc(); ProfMucWin *mucwin = wins_get_current_muc();
occupant = muc_roster_item(mucwin->roomjid, args[0]); occupant = muc_roster_item(mucwin->roomjid, args[0]);
if (occupant) { if (occupant) {
@ -1918,7 +1918,7 @@ cmd_caps(gchar **args, struct cmd_help_t help)
break; break;
case WIN_CHAT: case WIN_CHAT:
case WIN_CONSOLE: case WIN_CONSOLE:
if (args[0] != NULL) { if (args[0]) {
Jid *jid = jid_create(args[0]); Jid *jid = jid_create(args[0]);
if (jid->fulljid == NULL) { if (jid->fulljid == NULL) {
@ -1942,7 +1942,7 @@ cmd_caps(gchar **args, struct cmd_help_t help)
} }
break; break;
case WIN_PRIVATE: case WIN_PRIVATE:
if (args[0] != NULL) { if (args[0]) {
cons_show("No parameter needed to /caps when in private chat."); cons_show("No parameter needed to /caps when in private chat.");
} else { } else {
ProfPrivateWin *privatewin = wins_get_current_private(); ProfPrivateWin *privatewin = wins_get_current_private();
@ -1977,7 +1977,7 @@ cmd_software(gchar **args, struct cmd_help_t help)
switch (win_type) switch (win_type)
{ {
case WIN_MUC: case WIN_MUC:
if (args[0] != NULL) { if (args[0]) {
ProfMucWin *mucwin = wins_get_current_muc(); ProfMucWin *mucwin = wins_get_current_muc();
occupant = muc_roster_item(mucwin->roomjid, args[0]); occupant = muc_roster_item(mucwin->roomjid, args[0]);
if (occupant) { if (occupant) {
@ -1993,7 +1993,7 @@ cmd_software(gchar **args, struct cmd_help_t help)
break; break;
case WIN_CHAT: case WIN_CHAT:
case WIN_CONSOLE: case WIN_CONSOLE:
if (args[0] != NULL) { if (args[0]) {
Jid *jid = jid_create(args[0]); Jid *jid = jid_create(args[0]);
if (jid == NULL || jid->fulljid == NULL) { if (jid == NULL || jid->fulljid == NULL) {
@ -2007,7 +2007,7 @@ cmd_software(gchar **args, struct cmd_help_t help)
} }
break; break;
case WIN_PRIVATE: case WIN_PRIVATE:
if (args[0] != NULL) { if (args[0]) {
cons_show("No parameter needed to /software when in private chat."); cons_show("No parameter needed to /software when in private chat.");
} else { } else {
ProfPrivateWin *privatewin = wins_get_current_private(); ProfPrivateWin *privatewin = wins_get_current_private();
@ -2067,7 +2067,7 @@ cmd_join(gchar **args, struct cmd_help_t help)
ProfAccount *account = accounts_get_account(account_name); ProfAccount *account = accounts_get_account(account_name);
// full room jid supplied (room@server) // full room jid supplied (room@server)
if (room_arg->localpart != NULL) { if (room_arg->localpart) {
room = args[0]; room = args[0];
// server not supplied (room), use account preference // server not supplied (room), use account preference
@ -2142,7 +2142,7 @@ cmd_invite(gchar **args, struct cmd_help_t help)
ProfMucWin *mucwin = wins_get_current_muc(); ProfMucWin *mucwin = wins_get_current_muc();
message_send_invite(mucwin->roomjid, usr_jid, reason); message_send_invite(mucwin->roomjid, usr_jid, reason);
if (reason != NULL) { if (reason) {
cons_show("Room invite sent, contact: %s, room: %s, reason: \"%s\".", cons_show("Room invite sent, contact: %s, room: %s, reason: \"%s\".",
contact, mucwin->roomjid, reason); contact, mucwin->roomjid, reason);
} else { } else {
@ -2427,7 +2427,7 @@ cmd_form(gchar **args, struct cmd_help_t help)
if (g_strcmp0(args[0], "help") == 0) { if (g_strcmp0(args[0], "help") == 0) {
char *tag = args[1]; char *tag = args[1];
if (tag != NULL) { if (tag) {
ui_show_form_field_help(confwin, tag); ui_show_form_field_help(confwin, tag);
} else { } else {
ui_show_form_help(confwin); ui_show_form_help(confwin);
@ -2435,7 +2435,7 @@ cmd_form(gchar **args, struct cmd_help_t help)
const gchar **help_text = NULL; const gchar **help_text = NULL;
Command *command = g_hash_table_lookup(commands, "/form"); Command *command = g_hash_table_lookup(commands, "/form");
if (command != NULL) { if (command) {
help_text = command->help.long_help; help_text = command->help.long_help;
} }
@ -2601,7 +2601,7 @@ cmd_affiliation(gchar **args, struct cmd_help_t help)
} }
char *affiliation = args[1]; char *affiliation = args[1];
if ((affiliation != NULL) && if (affiliation &&
(g_strcmp0(affiliation, "owner") != 0) && (g_strcmp0(affiliation, "owner") != 0) &&
(g_strcmp0(affiliation, "admin") != 0) && (g_strcmp0(affiliation, "admin") != 0) &&
(g_strcmp0(affiliation, "member") != 0) && (g_strcmp0(affiliation, "member") != 0) &&
@ -2671,7 +2671,7 @@ cmd_role(gchar **args, struct cmd_help_t help)
} }
char *role = args[1]; char *role = args[1];
if ((role != NULL ) && if (role &&
(g_strcmp0(role, "visitor") != 0) && (g_strcmp0(role, "visitor") != 0) &&
(g_strcmp0(role, "participant") != 0) && (g_strcmp0(role, "participant") != 0) &&
(g_strcmp0(role, "moderator") != 0) && (g_strcmp0(role, "moderator") != 0) &&
@ -2961,7 +2961,7 @@ cmd_bookmark(gchar **args, struct cmd_help_t help)
char *password = g_hash_table_lookup(options, "password"); char *password = g_hash_table_lookup(options, "password");
char *autojoin = g_hash_table_lookup(options, "autojoin"); char *autojoin = g_hash_table_lookup(options, "autojoin");
if (autojoin != NULL) { if (autojoin) {
if ((strcmp(autojoin, "on") != 0) && (strcmp(autojoin, "off") != 0)) { if ((strcmp(autojoin, "on") != 0) && (strcmp(autojoin, "off") != 0)) {
cons_show("Usage: %s", help.usage); cons_show("Usage: %s", help.usage);
cons_show(""); cons_show("");
@ -3009,7 +3009,7 @@ cmd_disco(gchar **args, struct cmd_help_t help)
} }
GString *jid = g_string_new(""); GString *jid = g_string_new("");
if (args[1] != NULL) { if (args[1]) {
jid = g_string_append(jid, args[1]); jid = g_string_append(jid, args[1]);
} else { } else {
Jid *jidp = jid_create(jabber_get_fulljid()); Jid *jidp = jid_create(jabber_get_fulljid());
@ -4164,7 +4164,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
return TRUE; return TRUE;
} else if (strcmp(args[0], "start") == 0) { } else if (strcmp(args[0], "start") == 0) {
if (args[1] != NULL) { if (args[1]) {
char *contact = args[1]; char *contact = args[1];
char *barejid = roster_barejid_from_name(contact); char *barejid = roster_barejid_from_name(contact);
if (barejid == NULL) { if (barejid == NULL) {
@ -4383,7 +4383,7 @@ _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size)
} }
GList *curr = ordered_commands; GList *curr = ordered_commands;
while (curr != NULL) { while (curr) {
Command *cmd = curr->data; Command *cmd = curr->data;
cons_show("%-12s: %s", cmd->cmd, cmd->help.short_help); cons_show("%-12s: %s", cmd->cmd, cmd->help.short_help);
curr = g_list_next(curr); curr = g_list_next(curr);