--- a/marking.c Sat Aug 04 12:17:57 2012 +0200
+++ b/marking.c Sat Aug 04 13:35:52 2012 +0200
@@ -71,29 +71,53 @@
cmd = args[0];
if (args[1]) {
- const char *j = args[1];
- if (check_jid_syntax(j)) {
- scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
- "<%s> is not a valid Jabber ID.", j);
- return;
- }
+ const char *j = args[1];
+ if (check_jid_syntax(j)) {
+ scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
+ "<%s> is not a valid Jabber ID.", j);
+ return;
+ }
jid = jidtodisp(j);
- jfree = TRUE;
- }
+ if (!jid) {
+ scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
+ "Unexpected error.");
+ return;
+ }
+ jfree = TRUE;
+ }
} else
cmd = "set";
+ if (!jid) {
+ // JID was not provided
+ const char *j = NULL;
+
+ if (current_buddy)
+ j = CURRENT_JID;
+
+ if (!j) {
+ scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected.");
+ return;
+ }
+
+ jid = g_strdup(j);
+ jfree = TRUE;
+
+ // TODO: handle group marking :)
+ }
+
+
if (!strcmp (cmd, "set")) {
- if (!g_slist_find_custom (marked_jids, jid ? jid : CURRENT_JID, (GCompareFunc) g_strcmp0)) {
- marked_jids = g_slist_append (marked_jids, jid ? jid : g_strdup (CURRENT_JID));
+ if (!g_slist_find_custom (marked_jids, jid, (GCompareFunc) g_strcmp0)) {
+ marked_jids = g_slist_append (marked_jids, jid);
marked = 1;
jfree = FALSE;
}
} else if (!strcmp (cmd, "clear")) {
- GSList *mel = g_slist_find_custom (marked_jids, jid ? jid : CURRENT_JID, (GCompareFunc) g_strcmp0);
+ GSList *mel = g_slist_find_custom (marked_jids, jid, (GCompareFunc) g_strcmp0);
if (mel) {
g_free (mel->data);
@@ -103,23 +127,26 @@
} else if (!strcmp (cmd, "toggle")) {
- GSList *mel = g_slist_find_custom (marked_jids, jid ? jid : CURRENT_JID, (GCompareFunc) g_strcmp0);
+ GSList *mel = g_slist_find_custom (marked_jids, jid, (GCompareFunc) g_strcmp0);
if (mel) {
g_free (mel->data);
marked_jids = g_slist_delete_link (marked_jids, mel);
marked = 0;
} else {
- marked_jids = g_slist_append (marked_jids, jid ? jid : g_strdup (CURRENT_JID));
+ marked_jids = g_slist_append (marked_jids, jid);
marked = 1;
jfree = FALSE;
}
}
- if (marked == 1)
- scr_write_incoming_message (jid ? jid : CURRENT_JID, "Marked", 0, HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0);
- else if (marked == 0)
- scr_write_incoming_message (jid ? jid : CURRENT_JID, "Mark cleared", 0, HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0);
+ if (marked == 1) {
+ scr_write_incoming_message (jid, "Marked", 0,
+ HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0);
+ } else if (marked == 0) {
+ scr_write_incoming_message (jid, "Mark cleared", 0,
+ HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0);
+ }
if (jfree && jid)
g_free (jid);