From 59dd87d5f886d54e09ac012934aaad1bdfec2be6 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 21 Jul 2015 22:55:39 +0100 Subject: [PATCH 01/25] Fix /help commands spacing --- src/command/commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command/commands.c b/src/command/commands.c index 810772d5..2e377f4e 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -795,7 +795,7 @@ cmd_help(ProfWin *window, gchar **args, struct cmd_help_t help) GList *curr = ordered_commands; while (curr) { Command *cmd = curr->data; - cons_show("%-12s: %s", cmd->cmd, cmd->help.short_help); + cons_show("%-13s: %s", cmd->cmd, cmd->help.short_help); curr = g_list_next(curr); } g_list_free(ordered_commands); From e66f0cf7569f8f959ef3ce7faed4e1a94a97c470 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 22 Jul 2015 00:47:03 +0100 Subject: [PATCH 02/25] Added help example text --- helpexample.txt | 89 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 helpexample.txt diff --git a/helpexample.txt b/helpexample.txt new file mode 100644 index 00000000..4dc40169 --- /dev/null +++ b/helpexample.txt @@ -0,0 +1,89 @@ +ROSTER + +Synopsis: +/roster +/roster online +/roster show [offline|resource|empty] +/roster hide [offline|resource|empty] +/roster by group|presence|none +/roster size +/roster add [] +/roster remove +/roster remove_all contacts +/roster nick +/roster clearnick + +Description: +Manage your roster, and roster display settings. Passing no arguments displays your roster. + +Arguments: +online : Show all online contacts in your roster. +show : Show the roster panel. +show offline : Show offline contacts in the roster panel. +show resource : Show contact's connected resources in the roster panel. +show empty : When grouping by presence, show empty presence groups +hide : Hide the roster panel. +hide offline : Hide offline contacts in the roster panel. +hide resource : Hide contact's connected resources in the roster panel. +hide empty : When grouping by presence, hide empty presence groups +by group : Group contacts in the roster panel by roster group. +by presence : Group contacts in the roster panel by presence. +by none : No grouping in the roster panel. +size : Percentage of the screen taken up by the roster (1-99). +add [] : Add a new item to the roster. +remove : Removes an item from the roster. +remove_all contacts : Remove all items from roster. +nick : Change a contacts nickname. +clearnick : Removes the current nickname. + +Exmaples: +/roster +/roster add someone@contacts.org +/roster add someone@contacts.org Buddy +/roster remove someone@contacts.org +/roster nick myfriend@chat.org My Friend +/roster clearnick kai@server.com +/roster size 15 + +OTR + +Synopsis: +/otr gen +/otr myfp +/otr theirfp +/otr start [] +/otr end +/otr trust +/otr untrust +/otr log on|off|redact +/otr warn on|off +/otr libver +/otr policy manual|opportunistic|always +/otr secret +/otr question +/otr answer + +Description: +Off The Record message encryption commands. + +Arguments: +gen : Generate your private key. +myfp : Show your fingerprint. +theirfp : Show contacts fingerprint. +start : Start an OTR session with current recipient. +start : Start an OTR session with the contact. +end : End the current OTR session. +trust : Indicate that you have verified the contact's fingerprint. +untrust : Indicate the the contact's fingerprint is not verified. +log on : Enable plaintext logging of OTR messages. +log off : Disable logging of OTR messages. +log redact : Log OTR messages as [redacted], the default. +warn on : Show in the titlebar when unencrypted messaging is being used. +warn off : Show in the titlebar when unencrypted messaging is being used. +libver : Show which version of the libotr library is being used. +policy manual : Set the global OTR policy. +policy opportunistici : Set the global OTR policy. +policy always : Set the global OTR policy. +secret : Verify a contacts identity using a shared secret. +question : Verify a contacts identity using a question and expected answer. +answer : Respond to a question answer verification request with your answer. From 22111bf75b34181cdab4f8369e781cb1d857fcfb Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 23 Jul 2015 23:05:33 +0100 Subject: [PATCH 03/25] Moved help and about to new format --- src/command/command.c | 289 +++++++++++++++++++++++------------ src/command/commands.c | 19 +-- src/command/commands.h | 7 +- src/ui/console.c | 36 +++++ src/ui/ui.h | 2 + tests/unittests/ui/stub_ui.c | 2 + 6 files changed, 244 insertions(+), 111 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 9d33f61b..b4b80169 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -109,30 +109,41 @@ GHashTable *commands = NULL; */ static struct cmd_t command_defs[] = { - { "/help", - cmd_help, parse_args, 0, 1, NULL, - { "/help [area|command]", "Help on using Profanity.", - { "/help [area|command]", - "--------------------", - "Help on using Profanity.", - "", - "area : Summary help for commands in a certain area of functionality.", - "command : Full help for a specific command, for example '/help connect'.", - "", - "Use with no arguments to see a list of areas.", - "", - "Example: /help commands", - "Example: /help presence", - "Example: /help who", - NULL } } }, + // NEW STYLE + { "/help", cmd_help, parse_args, 0, 1, NULL, + { NULL, NULL, { NULL }, + { + "/help [|]", + NULL }, - { "/about", - cmd_about, parse_args, 0, 0, NULL, - { "/about", "About Profanity.", - { "/about", - "------", - "Show version and license information.", - NULL } } }, + "Help on using Profanity. Passing no arguments list help areas.", + + { + { "area", "Summary help for commands in a certain area of functionality." }, + { "command", "Full help for a specific command, for example '/help connect'." }, + { NULL, NULL } }, + + { + "/help commands", + "/help presence", + "/help who", + NULL } } }, + + { "/about", cmd_about, parse_args, 0, 0, NULL, + { NULL, NULL, { NULL }, + { + "/about", + NULL }, + + "Show version and license information.", + + { + { NULL, NULL } }, + + { + NULL } } }, + + // OLD STYLE { "/connect", cmd_connect, parse_args, 0, 5, NULL, @@ -153,7 +164,8 @@ static struct cmd_t command_defs[] = "Example: /connect myuser@mycompany.com server talk.google.com", "Example: /connect bob@someplace port 5678", "Example: /connect me@chatty server chatty.com port 5443", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/disconnect", cmd_disconnect, parse_args, 0, 0, NULL, @@ -161,7 +173,8 @@ static struct cmd_t command_defs[] = { "/disconnect", "-----------", "Disconnect from the current chat service.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/msg", cmd_msg, parse_args_with_freetext, 1, 2, NULL, @@ -181,7 +194,8 @@ static struct cmd_t command_defs[] = "Example: /msg otherfriend@server.com", "Example: /msg Bob Here is a private message", "Example: /msg \"My Friend\" Hi, how are you?", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/roster", cmd_roster, parse_args_with_freetext, 0, 3, NULL, @@ -219,7 +233,8 @@ static struct cmd_t command_defs[] = "Example: /roster remove someone@contacts.org (remove the contact)", "Example: /roster nick myfriend@chat.org My Friend", "Example: /roster clearnick kai@server.com (clears nickname)", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/group", cmd_group, parse_args_with_freetext, 0, 3, NULL, @@ -239,7 +254,8 @@ static struct cmd_t command_defs[] = "Example: /group add friends newfriend@server.org", "Example: /group add family Brother (using contacts nickname)", "Example: /group remove colleagues boss@work.com", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/info", cmd_info, parse_args, 0, 1, NULL, @@ -256,7 +272,8 @@ static struct cmd_t command_defs[] = "", "Example: /info mybuddy@chat.server.org", "Example: /info kai", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/caps", cmd_caps, parse_args, 0, 1, NULL, @@ -273,7 +290,8 @@ static struct cmd_t command_defs[] = "Example: /caps mybuddy@chat.server.org/laptop (contact's laptop resource)", "Example: /caps mybuddy@chat.server.org/phone (contact's phone resource)", "Example: /caps bruce (room member)", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/software", cmd_software, parse_args, 0, 1, NULL, @@ -291,7 +309,8 @@ static struct cmd_t command_defs[] = "Example: /software mybuddy@chat.server.org/laptop (contact's laptop resource)", "Example: /software mybuddy@chat.server.org/phone (contact's phone resource)", "Example: /software bruce (room member)", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/status", cmd_status, parse_args, 0, 1, NULL, @@ -307,7 +326,8 @@ static struct cmd_t command_defs[] = "", "Example: /status buddy@server.com", "Example: /status jon", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/resource", cmd_resource, parse_args, 1, 2, &cons_resource_setting, @@ -320,7 +340,8 @@ static struct cmd_t command_defs[] = "off : Let the server choose which resource to route messages to.", "title on|off : Show or hide the current resource in the titlebar.", "message on|off : Show or hide the resource when showing an incoming message.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/join", cmd_join, parse_args, 0, 5, NULL, @@ -342,7 +363,8 @@ static struct cmd_t command_defs[] = "Example: /join jdev@conference.jabber.org nick mynick", "Example: /join private@conference.jabber.org nick mynick password mypassword", "Example: /join jdev (as user@jabber.org will join jdev@conference.jabber.org)", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/leave", cmd_leave, parse_args, 0, 0, NULL, @@ -350,7 +372,8 @@ static struct cmd_t command_defs[] = { "/leave", "------", "Leave the current chat room.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/invite", cmd_invite, parse_args_with_freetext, 1, 2, NULL, @@ -361,7 +384,8 @@ static struct cmd_t command_defs[] = "", "contact : The contact you wish to invite", "message : An optional message to send with the invite.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/invites", cmd_invites, parse_args_with_freetext, 0, 0, NULL, @@ -369,7 +393,8 @@ static struct cmd_t command_defs[] = { "/invites", "--------", "Show all rooms that you have been invited to, and not accepted or declined.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/decline", cmd_decline, parse_args_with_freetext, 1, 1, NULL, @@ -379,7 +404,8 @@ static struct cmd_t command_defs[] = "Decline a chat room invitation.", "", "room : The room for the invite you wish to decline.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/room", cmd_room, parse_args, 1, 1, NULL, @@ -391,7 +417,8 @@ static struct cmd_t command_defs[] = "accept : Accept default room configuration.", "destroy : Reject default room configuration.", "config : Edit room configuration.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/kick", cmd_kick, parse_args_with_freetext, 1, 2, NULL, @@ -402,7 +429,8 @@ static struct cmd_t command_defs[] = "", "nick : Nickname of the occupant to kick from the room.", "reason : Optional reason for kicking the occupant.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/ban", cmd_ban, parse_args_with_freetext, 1, 2, NULL, @@ -413,7 +441,8 @@ static struct cmd_t command_defs[] = "", "jid : Bare JID of the user to ban from the room.", "reason : Optional reason for banning the user.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/subject", cmd_subject, parse_args_with_freetext, 0, 2, NULL, @@ -424,7 +453,8 @@ static struct cmd_t command_defs[] = "", "set subject : Set the room subject.", "clear : Clear the room subject.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/affiliation", cmd_affiliation, parse_args_with_freetext, 1, 4, NULL, @@ -437,7 +467,8 @@ static struct cmd_t command_defs[] = "list [affiliation] : List all users with the specified affiliation, or all if none specified.", "", "The affiliation may be one of owner, admin, member, outcast or none.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/role", cmd_role, parse_args_with_freetext, 1, 4, NULL, @@ -450,7 +481,8 @@ static struct cmd_t command_defs[] = "list [role] : List all occupants with the specified role, or all if none specified.", "", "The role may be one of moderator, participant, visitor or none.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/occupants", cmd_occupants, parse_args, 1, 3, cons_occupants_setting, @@ -466,7 +498,8 @@ static struct cmd_t command_defs[] = "default show|hide : Whether occupants are shown by default in new rooms.", "default show|hide jid : Whether occupants jids are shown by default in new rooms.", "size percent : Percentage of the screen taken by the occupants list in rooms (1-99).", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/form", cmd_form, parse_args, 1, 2, NULL, @@ -479,7 +512,8 @@ static struct cmd_t command_defs[] = "submit : Submit the current form.", "cancel : Cancel changes to the current form.", "help [tag] : Display help for form, or a specific field.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/rooms", cmd_rooms, parse_args, 0, 1, NULL, @@ -494,7 +528,8 @@ static struct cmd_t command_defs[] = "", "Example: /rooms conference.jabber.org", "Example: /rooms (if logged in as me@server.org, is equivalent to /rooms conference.server.org)", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/bookmark", cmd_bookmark, parse_args, 0, 8, NULL, @@ -515,7 +550,8 @@ static struct cmd_t command_defs[] = "join room@server : Join room using the properties associated with the bookmark.", "", "In a chat room, /bookmark with no arguments will bookmark the current room, setting autojoin to \"on\".", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/disco", cmd_disco, parse_args, 1, 2, NULL, @@ -532,7 +568,8 @@ static struct cmd_t command_defs[] = "Example: /disco items myserver.org", "Example: /disco items conference.jabber.org", "Example: /disco info myfriend@server.com/laptop", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/nick", cmd_nick, parse_args_with_freetext, 1, 1, NULL, @@ -545,7 +582,8 @@ static struct cmd_t command_defs[] = "", "Example: /nick kai hansen", "Example: /nick bob", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/win", cmd_win, parse_args, 1, 1, NULL, @@ -555,7 +593,8 @@ static struct cmd_t command_defs[] = "Show the contents of a specific window in the main window area.", "", "num - Window number to display.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/wins", cmd_wins, parse_args, 0, 3, NULL, @@ -569,7 +608,8 @@ static struct cmd_t command_defs[] = "swap source target : Swap windows, target may be an empty position.", "", "Passing no argument will list all currently active windows and information about their usage.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/sub", cmd_sub, parse_args, 1, 2, NULL, @@ -591,7 +631,8 @@ static struct cmd_t command_defs[] = "Example: /sub allow myfriend@jabber.org", "Example: /sub request (whilst in chat with contact)", "Example: /sub sent", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/tiny", cmd_tiny, parse_args, 1, 1, NULL, @@ -603,7 +644,8 @@ static struct cmd_t command_defs[] = "url : The url to make tiny.", "", "Example: /tiny http://www.profanity.im", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/who", cmd_who, parse_args, 0, 2, NULL, @@ -620,7 +662,8 @@ static struct cmd_t command_defs[] = "role : moderator|participant|visitor", "affiliation : owner|admin|member", "group : Filter the results by the specified group.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/close", cmd_close, parse_args, 0, 1, NULL, @@ -634,7 +677,8 @@ static struct cmd_t command_defs[] = "read : Close all windows that have no new messages.", "", "Passing no argument will close the current window.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/clear", cmd_clear, parse_args, 0, 0, NULL, @@ -642,7 +686,8 @@ static struct cmd_t command_defs[] = { "/clear", "------", "Clear the current window.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/quit", cmd_quit, parse_args, 0, 0, NULL, @@ -650,7 +695,8 @@ static struct cmd_t command_defs[] = { "/quit", "-----", "Logout of any current session, and quit Profanity.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/privileges", cmd_privileges, parse_args, 1, 1, &cons_privileges_setting, @@ -658,7 +704,8 @@ static struct cmd_t command_defs[] = { "/privileges on|off", "------------------", "If enabled the room occupants panel will be grouped by role, and role information will be shown in the room.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/beep", cmd_beep, parse_args, 1, 1, &cons_beep_setting, @@ -668,7 +715,8 @@ static struct cmd_t command_defs[] = "Switch the terminal bell on or off.", "The bell will sound when incoming messages are received.", "If the terminal does not support sounds, it may attempt to flash the screen instead.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/encwarn", cmd_encwarn, parse_args, 1, 1, &cons_encwarn_setting, @@ -676,7 +724,8 @@ static struct cmd_t command_defs[] = { "/encwarn on|off", "---------------", "Enabled or disable the unencrypted warning message in the titlebar.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/presence", cmd_presence, parse_args, 1, 1, &cons_presence_setting, @@ -684,7 +733,8 @@ static struct cmd_t command_defs[] = { "/presence on|off", "----------------", "Switch display of the contacts presence in the titlebar on or off.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/wrap", cmd_wrap, parse_args, 1, 1, &cons_wrap_setting, @@ -692,7 +742,8 @@ static struct cmd_t command_defs[] = { "/wrap on|off", "------------", "Enable or disable word wrapping in the main window.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/winstidy", cmd_winstidy, parse_args, 1, 1, &cons_winstidy_setting, @@ -700,7 +751,8 @@ static struct cmd_t command_defs[] = { "/winstidy on|off", "----------------", "Enable or disable auto window tidy.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/time", cmd_time, parse_args, 1, 3, &cons_time_setting, @@ -718,7 +770,8 @@ static struct cmd_t command_defs[] = "See https://developer.gnome.org/glib/stable/glib-GDateTime.html#g-date-time-format for more details.", "Example: /time main set %H:%M (main time will be set to HH:MM)", "Example: /time statusbar set yolo (statusbar time will all be changed to a static yolo)", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/inpblock", cmd_inpblock, parse_args, 2, 2, &cons_inpblock_setting, @@ -729,7 +782,8 @@ static struct cmd_t command_defs[] = "", "timeout millis : Time to wait (1-1000) in milliseconds before reading input from the terminal buffer, default: 1000.", "dynamic on|off : Start with 0 millis and dynamically increase up to timeout when no activity, default: on.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/notify", cmd_notify, parse_args, 2, 3, &cons_notify_setting, @@ -759,7 +813,8 @@ static struct cmd_t command_defs[] = "Example: /notify remind 0 (switch off reminders)", "Example: /notify typing on (enable typing notifications)", "Example: /notify invite on (enable chat room invite notifications)", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/flash", cmd_flash, parse_args, 1, 1, &cons_flash_setting, @@ -768,7 +823,8 @@ static struct cmd_t command_defs[] = "-------------", "Make the terminal flash when incoming messages are received in another window.", "If the terminal doesn't support flashing, it may attempt to beep.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/intype", cmd_intype, parse_args, 1, 1, &cons_intype_setting, @@ -776,7 +832,8 @@ static struct cmd_t command_defs[] = { "/intype on|off", "--------------", "Show when a contact is typing in the console, and in active message window.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/splash", cmd_splash, parse_args, 1, 1, &cons_splash_setting, @@ -784,7 +841,8 @@ static struct cmd_t command_defs[] = { "/splash on|off", "--------------", "Switch on or off the ascii logo on start up and when the /about command is called.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/autoconnect", cmd_autoconnect, parse_args, 1, 2, &cons_autoconnect_setting, @@ -796,7 +854,8 @@ static struct cmd_t command_defs[] = "", "Example: /autoconnect set jc@stuntteam.org (autoconnect with the specified account).", "Example: /autoconnect off (disable autoconnect).", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/vercheck", cmd_vercheck, parse_args, 0, 1, NULL, @@ -804,7 +863,8 @@ static struct cmd_t command_defs[] = { "/vercheck [on|off]", "------------------", "Enable/disable a version check when Profanity starts, and each time the /about command is run.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/titlebar", cmd_titlebar, parse_args, 2, 2, &cons_titlebar_setting, @@ -815,7 +875,8 @@ static struct cmd_t command_defs[] = "", "show : Show current logged in user, and unread messages in the title.", "goodbye : Show a message in the title when exiting profanity.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/alias", cmd_alias, parse_args_with_freetext, 1, 3, NULL, @@ -835,7 +896,8 @@ static struct cmd_t command_defs[] = "Example: /alias list", "", "The above aliases will be available as /friends and /a", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/chlog", cmd_chlog, parse_args, 1, 1, &cons_chlog_setting, @@ -846,7 +908,8 @@ static struct cmd_t command_defs[] = "This setting will be enabled if /history is set to on.", "When disabling this option, /history will also be disabled.", "See the /grlog setting for enabling logging of chat room (groupchat) messages.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/grlog", cmd_grlog, parse_args, 1, 1, &cons_grlog_setting, @@ -855,7 +918,8 @@ static struct cmd_t command_defs[] = "-------------", "Switch chat room logging on or off.", "See the /chlog setting for enabling logging of one to one chat.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/states", cmd_states, parse_args, 1, 1, &cons_states_setting, @@ -863,7 +927,8 @@ static struct cmd_t command_defs[] = { "/states on|off", "--------------", "Send chat state notifications during chat sessions.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/pgp", cmd_pgp, parse_args, 1, 3, NULL, @@ -879,7 +944,8 @@ static struct cmd_t command_defs[] = "start [contact] : Start PGP encrypted chat, current contact will be used if not specified.", "end : End PGP encrypted chat with the current recipient.", "log on|off|redact : PGP message logging, default: redact.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/otr", cmd_otr, parse_args, 1, 3, NULL, @@ -902,7 +968,8 @@ static struct cmd_t command_defs[] = "secret [secret] : Verify a contacts identity using a shared secret.", "question [question] [answer] : Verify a contacts identity using a question and expected answer.", "answer [answer] : Respond to a question answer verification request with your answer.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/outtype", cmd_outtype, parse_args, 1, 1, &cons_outtype_setting, @@ -910,7 +977,8 @@ static struct cmd_t command_defs[] = { "/outtype on|off", "---------------", "Send typing notifications, chat states (/states) will be enabled if this setting is set.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/gone", cmd_gone, parse_args, 1, 1, &cons_gone_setting, @@ -920,7 +988,8 @@ static struct cmd_t command_defs[] = "Send a 'gone' state to the recipient after the specified number of minutes.", "A value of 0 will disable sending this chat state.", "Chat states (/states) will be enabled if this setting is set.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/history", cmd_history, parse_args, 1, 1, &cons_history_setting, @@ -929,7 +998,8 @@ static struct cmd_t command_defs[] = "---------------", "Switch chat history on or off, /chlog will automatically be enabled when this setting is on.", "When history is enabled, previous messages are shown in chat windows.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/log", cmd_log, parse_args, 1, 2, &cons_log_setting, @@ -942,7 +1012,8 @@ static struct cmd_t command_defs[] = "rotate on|off : Rotate log, default on.", "maxsize bytes : With rotate enabled, specifies the max log size, defaults to 1048580 (1MB).", "shared on|off : Share logs between all instances, default: on.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/carbons", cmd_carbons, parse_args, 1, 1, &cons_carbons_setting, @@ -951,7 +1022,8 @@ static struct cmd_t command_defs[] = "---------------", "Enable or disable message carbons.", "The message carbons feature ensures that both sides of all conversations are shared with all the user's clients that implement this protocol.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/receipts", cmd_receipts, parse_args, 2, 2, &cons_receipts_setting, @@ -962,7 +1034,8 @@ static struct cmd_t command_defs[] = "", "send on|off : Enable or disable sending of delivery receipts.", "request on|off : Enable or disable sending of delivery receipt requests.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/reconnect", cmd_reconnect, parse_args, 1, 1, &cons_reconnect_setting, @@ -971,7 +1044,8 @@ static struct cmd_t command_defs[] = "------------------", "Set the reconnect attempt interval in seconds for when the connection is lost.", "A value of 0 will switch off reconnect attempts.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/autoping", cmd_autoping, parse_args, 1, 1, &cons_autoping_setting, @@ -980,7 +1054,8 @@ static struct cmd_t command_defs[] = "-----------------", "Set the number of seconds between server pings, so ensure connection kept alive.", "A value of 0 will switch off autopinging the server.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/ping", cmd_ping, parse_args, 0, 1, NULL, @@ -989,7 +1064,8 @@ static struct cmd_t command_defs[] = "--------------", "Sends an IQ ping stanza to the specified target.", "If no target is supplied, your chat server will be pinged.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/autoaway", cmd_autoaway, parse_args_with_freetext, 2, 2, &cons_autoaway_setting, @@ -1009,7 +1085,8 @@ static struct cmd_t command_defs[] = "Example: /autoaway time 30", "Example: /autoaway message I'm not really doing much", "Example: /autoaway check off", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/priority", cmd_priority, parse_args, 1, 1, &cons_priority_setting, @@ -1021,7 +1098,8 @@ static struct cmd_t command_defs[] = "value : Number between -128 and 127, default: 0.", "", "See the /account command for specific priority settings per presence status.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/account", cmd_account, parse_args, 0, 4, NULL, @@ -1064,7 +1142,8 @@ static struct cmd_t command_defs[] = "Example: /account set me status dnd", "Example: /account set me dnd -1", "Example: /account rename me gtalk", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/prefs", cmd_prefs, parse_args, 0, 1, NULL, @@ -1081,7 +1160,8 @@ static struct cmd_t command_defs[] = "presence : Chat presence preferences.", "", "No argument shows all preferences.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/theme", cmd_theme, parse_args, 1, 2, &cons_theme_setting, @@ -1096,8 +1176,8 @@ static struct cmd_t command_defs[] = "", "Example: /theme list", "Example: /theme load mycooltheme", - NULL } } }, - + NULL, + NULL, NULL, NULL, NULL } } }, { "/statuses", cmd_statuses, parse_args, 2, 2, &cons_statuses_setting, @@ -1121,7 +1201,8 @@ static struct cmd_t command_defs[] = "Example: /statuses console none", "Example: /statuses chat online", "Example: /statuses muc all", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/xmlconsole", cmd_xmlconsole, parse_args, 0, 0, NULL, @@ -1129,7 +1210,8 @@ static struct cmd_t command_defs[] = { "/xmlconsole", "-----------", "Open the XML console to view incoming and outgoing XMPP traffic.", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/away", cmd_away, parse_args_with_freetext, 0, 1, NULL, @@ -1139,7 +1221,8 @@ static struct cmd_t command_defs[] = "Set your status to 'away' with the optional message.", "", "Example: /away Gone for lunch", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/chat", cmd_chat, parse_args_with_freetext, 0, 1, NULL, @@ -1149,7 +1232,8 @@ static struct cmd_t command_defs[] = "Set your status to 'chat', meaning 'available for chat', with the optional message.", "", "Example: /chat Please talk to me!", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/dnd", cmd_dnd, parse_args_with_freetext, 0, 1, NULL, @@ -1159,7 +1243,8 @@ static struct cmd_t command_defs[] = "Set your status to 'dnd', meaning 'do not disturb', with the optional message.", "", "Example: /dnd I'm in the zone", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/online", cmd_online, parse_args_with_freetext, 0, 1, NULL, @@ -1169,7 +1254,8 @@ static struct cmd_t command_defs[] = "Set your status to 'online' with the optional message.", "", "Example: /online Up the Irons!", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, { "/xa", cmd_xa, parse_args_with_freetext, 0, 1, NULL, @@ -1179,7 +1265,8 @@ static struct cmd_t command_defs[] = "Set your status to 'xa', meaning 'extended away', with the optional message.", "", "Example: /xa This meeting is going to be a long one", - NULL } } }, + NULL, + NULL, NULL, NULL, NULL } } }, }; static Autocomplete commands_ac; diff --git a/src/command/commands.c b/src/command/commands.c index 2e377f4e..b5babf3c 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -852,21 +852,22 @@ cmd_help(ProfWin *window, gchar **args, struct cmd_help_t help) char cmd_with_slash[1 + strlen(cmd) + 1]; sprintf(cmd_with_slash, "/%s", cmd); - const gchar **help_text = NULL; Command *command = g_hash_table_lookup(commands, cmd_with_slash); - if (command) { - help_text = command->help.long_help; - } + // old + if (command->help.usage) { + const gchar **help_text = command->help.long_help; + ProfWin *console = wins_get_console(); + cons_show(""); + ui_show_lines(console, help_text); - cons_show(""); - if (help_text) { - ProfWin *console = wins_get_console(); - ui_show_lines(console, help_text); + // new + } else { + cons_show_help(command); + } } else { cons_show("No such command."); } - cons_show(""); } diff --git a/src/command/commands.h b/src/command/commands.h index 0b135d71..bf0f94ae 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -35,13 +35,18 @@ #ifndef COMMANDS_H #define COMMANDS_H -#include "ui/ui.h" +#include "ui/win_types.h" // Command help strings typedef struct cmd_help_t { const gchar *usage; const gchar *short_help; const gchar *long_help[50]; + + const gchar *synopsis[50]; + const gchar *desc; + const gchar *args[50][2]; + const gchar *examples[10]; } CommandHelp; /* diff --git a/src/ui/console.c b/src/ui/console.c index 98691a0a..9b18a599 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -105,6 +105,42 @@ cons_show(const char * const msg, ...) va_end(arg); } +void +cons_show_help(Command *command) +{ + ProfWin *console = wins_get_console(); + + cons_show(""); + + cons_show("Synopsis:"); + ui_show_lines(console, command->help.synopsis); + cons_show(""); + + cons_show("Description:"); + win_println(console, command->help.desc); + + int i; + int maxlen = 0; + for (i = 0; command->help.args[i][0] != NULL; i++) { + if (strlen(command->help.args[i][0]) > maxlen) + maxlen = strlen(command->help.args[i][0]); + } + + if (i > 0) { + cons_show(""); + cons_show("Arguments:"); + for (i = 0; command->help.args[i][0] != NULL; i++) { + win_vprint(console, '-', NULL, 0, 0, "", "%-*s: %s", maxlen + 1, command->help.args[i][0], command->help.args[i][1]); + } + } + + if (g_strv_length((gchar**)command->help.examples) > 0) { + cons_show(""); + cons_show("Examples:"); + ui_show_lines(console, command->help.examples); + } +} + void cons_show_error(const char * const msg, ...) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 637c8f75..58f1ee98 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -35,6 +35,7 @@ #ifndef UI_UI_H #define UI_UI_H +#include "command/commands.h" #include "ui/win_types.h" #include "muc.h" @@ -241,6 +242,7 @@ void ui_inp_history_append(char *inp); void cons_show(const char * const msg, ...); void cons_about(void); void cons_help(void); +void cons_show_help(Command *command); void cons_navigation_help(void); void cons_prefs(void); void cons_show_ui_prefs(void); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 71a577f5..05863fd0 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -358,6 +358,8 @@ void cons_show(const char * const msg, ...) va_end(args); } +void cons_show_help(Command *command) {} + void cons_about(void) {} void cons_help(void) {} void cons_navigation_help(void) {} From 44d7a152a4495cf0238745d91d590d163018cb9b Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 24 Jul 2015 00:33:38 +0100 Subject: [PATCH 04/25] Added connect to new help format --- src/command/command.c | 111 ++++++++++++++++++++++-------------------- src/ui/console.c | 8 +-- 2 files changed, 63 insertions(+), 56 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index b4b80169..e8874f8b 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -104,68 +104,75 @@ static char * _receipts_autocomplete(ProfWin *window, const char * const input); GHashTable *commands = NULL; +#define END_ARGS { NULL, NULL } + + + /* * Command list */ static struct cmd_t command_defs[] = { // NEW STYLE - { "/help", cmd_help, parse_args, 0, 1, NULL, - { NULL, NULL, { NULL }, - { - "/help [|]", - NULL }, + { "/help", + cmd_help, parse_args, 0, 1, NULL, + { NULL, NULL, { NULL }, + { + "/help [|]", + NULL + }, + "Help on using Profanity. Passing no arguments list help areas.", + { + { "area", "Summary help for commands in a certain area of functionality." }, + { "command", "Full help for a specific command, for example '/help connect'." }, + END_ARGS }, + { + "/help commands", + "/help presence", + "/help who", + NULL } } + }, - "Help on using Profanity. Passing no arguments list help areas.", - - { - { "area", "Summary help for commands in a certain area of functionality." }, - { "command", "Full help for a specific command, for example '/help connect'." }, - { NULL, NULL } }, - - { - "/help commands", - "/help presence", - "/help who", - NULL } } }, - - { "/about", cmd_about, parse_args, 0, 0, NULL, - { NULL, NULL, { NULL }, - { - "/about", - NULL }, - - "Show version and license information.", - - { - { NULL, NULL } }, - - { - NULL } } }, - - // OLD STYLE + { "/about", + cmd_about, parse_args, 0, 0, NULL, + { NULL, NULL, { NULL }, + { + "/about", + NULL + }, + "Show version and license information.", + { + END_ARGS }, + { + NULL } } + }, { "/connect", cmd_connect, parse_args, 0, 5, NULL, - { "/connect [account] [server value] [port value]", "Account login.", - { "/connect [account] [server value] [port value]", - "----------------------------------------------", - "Login to a chat service.", - "", - "account : The local account you wish to connect with, or a JID if connecting for the first time.", - "server value : Supply a server if it is different to the domain part of your JID.", - "port value : The port to use if different to the default (5222, or 5223 for SSL).", - "", - "If no account is specified, the default is used if one is configured.", - "A local account is created with the JID as it's name if it doesn't already exist.", - "", - "Example: /connect", - "Example: /connect myuser@gmail.com", - "Example: /connect myuser@mycompany.com server talk.google.com", - "Example: /connect bob@someplace port 5678", - "Example: /connect me@chatty server chatty.com port 5443", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/connect []", + "/connect [server ] [port ]", + NULL + }, + "Login to a chat service. " + "If no account is specified, the default is used if one is configured. " + "A local account is created with the JID as it's name if it doesn't already exist.", + { + { "account", "The local account you wish to connect with, or a JID if connecting for the first time." }, + { "server ", "Supply a server if it is different to the domain part of your JID." }, + { "port ", "The port to use if different to the default (5222, or 5223 for SSL)." }, + END_ARGS }, + { + "/connect", + "/connect myuser@gmail.com", + "/connect myuser@mycompany.com server talk.google.com", + "/connect bob@someplace port 5678", + "/connect me@chatty server chatty.com port 5443", + NULL } } + }, + + // OLD STYLE { "/disconnect", cmd_disconnect, parse_args, 0, 0, NULL, diff --git a/src/ui/console.c b/src/ui/console.c index 9b18a599..20f6803e 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -112,11 +112,11 @@ cons_show_help(Command *command) cons_show(""); - cons_show("Synopsis:"); + win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "Synopsis"); ui_show_lines(console, command->help.synopsis); cons_show(""); - cons_show("Description:"); + win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "Description"); win_println(console, command->help.desc); int i; @@ -128,7 +128,7 @@ cons_show_help(Command *command) if (i > 0) { cons_show(""); - cons_show("Arguments:"); + win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "Arguments"); for (i = 0; command->help.args[i][0] != NULL; i++) { win_vprint(console, '-', NULL, 0, 0, "", "%-*s: %s", maxlen + 1, command->help.args[i][0], command->help.args[i][1]); } @@ -136,7 +136,7 @@ cons_show_help(Command *command) if (g_strv_length((gchar**)command->help.examples) > 0) { cons_show(""); - cons_show("Examples:"); + win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "Examples"); ui_show_lines(console, command->help.examples); } } From a8eb2815539b59bb9afa682edd7fb63b0aa4a9da Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 24 Jul 2015 00:44:56 +0100 Subject: [PATCH 05/25] Added msg to new help format --- src/command/command.c | 63 +++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index e8874f8b..7671fa0c 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -172,37 +172,48 @@ static struct cmd_t command_defs[] = NULL } } }, - // OLD STYLE - { "/disconnect", cmd_disconnect, parse_args, 0, 0, NULL, - { "/disconnect", "Logout of current session.", - { "/disconnect", - "-----------", - "Disconnect from the current chat service.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/disconnect", + NULL + }, + "Disconnect from the current chat service.", + { + END_ARGS }, + { + NULL } } + }, { "/msg", cmd_msg, parse_args_with_freetext, 1, 2, NULL, - { "/msg contact|nick [message]", "Start chat with a user.", - { "/msg contact|nick [message]", - "---------------------------", - "Send a one to one chat message, or a private message to a chat room occupant.", - "", - "contact : The contact's JID, or nickname if one has been set in your roster.", - "nick : A chat room occupant, to whom you wish to send a private message.", - "message : The message to send", - "", - "If the message is omitted, a new chat window will be opened without sending a message.", - "Use quotes if the nickname includes spaces.", - "", - "Example: /msg myfriend@server.com Hey, here's a message!", - "Example: /msg otherfriend@server.com", - "Example: /msg Bob Here is a private message", - "Example: /msg \"My Friend\" Hi, how are you?", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/msg []", + "/msg []", + NULL + }, + "Send a one to one chat message, or a private message to a chat room occupant. " + "If the message is omitted, a new chat window will be opened without sending a message. " + "Use quotes if the nickname includes spaces.", + { + { "", "Open chat window with contact, by JID or nickname." }, + { " []", "Send message to contact, by JID or nickname." }, + { "", "Open private chat window with chat room occupant." }, + { " []", "Send a private message to a chat room occupant." }, + END_ARGS }, + { + "/msg myfriend@server.com Hey, here's a message!", + "/msg otherfriend@server.com", + "/msg Bob Here is a private message", + "/msg \"My Friend\" Hi, how are you?", + NULL } } + }, + + // OLD STYLE + + { "/roster", cmd_roster, parse_args_with_freetext, 0, 3, NULL, From b736883ac4a1ff5ad9ad92b2676360de545747f8 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 24 Jul 2015 21:20:55 +0100 Subject: [PATCH 06/25] Added roster to new help format --- src/command/command.c | 96 ++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 42 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 7671fa0c..ef785089 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -198,10 +198,10 @@ static struct cmd_t command_defs[] = "If the message is omitted, a new chat window will be opened without sending a message. " "Use quotes if the nickname includes spaces.", { - { "", "Open chat window with contact, by JID or nickname." }, + { "", "Open chat window with contact, by JID or nickname." }, { " []", "Send message to contact, by JID or nickname." }, - { "", "Open private chat window with chat room occupant." }, - { " []", "Send a private message to a chat room occupant." }, + { "", "Open private chat window with chat room occupant." }, + { " []", "Send a private message to a chat room occupant." }, END_ARGS }, { "/msg myfriend@server.com Hey, here's a message!", @@ -211,48 +211,60 @@ static struct cmd_t command_defs[] = NULL } } }, - // OLD STYLE - - - { "/roster", cmd_roster, parse_args_with_freetext, 0, 3, NULL, - { "/roster [command] [args..]", "Manage your roster.", - { "/roster [command] [args..]", - "--------------------------", - "Manage your roster, and roster display settings.", - "", - "command - online|show|hide|by|size|add|remove|remove_all|nick|clearnick", - "", - "online : Show all online contacts in your roster.", - "show : Show the roster panel.", - "show offline : Show offline contacts in the roster panel.", - "show resource : Show contact's connected resources in the roster panel.", - "show empty : When grouping by presence, show empty presence groups", - "hide : Hide the roster panel.", - "hide offline : Hide offline contacts in the roster panel.", - "hide resource : Hide contact's connected resources in the roster panel.", - "hide empty : When grouping by presence, hide empty presence groups", - "by group : Group contacts in the roster panel by roster group.", - "by presence : Group contacts in the roster panel by presence.", - "by none : No grouping in the roster panel.", - "size : Percentage of the screen taken up by the roster (1-99).", - "add jid [nick] : Add a new item to the roster.", - "remove jid : Removes an item from the roster.", - "remove_all contacts : Remove all items from roster.", - "nick jid nick : Change a contacts nickname.", - "clearnick jid : Removes the current nickname.", - "", + { NULL, NULL, { NULL }, + { + "/roster", + "/roster online", + "/roster show [offline|resource|empty]", + "/roster hide [offline|resource|empty]", + "/roster by group|presence|none", + "/roster size ", + "/roster add []", + "/roster remove ", + "/roster remove_all contacts", + "/roster nick ", + "/roster clearnick ", + NULL + }, + "Manage your roster, and roster display settings. " "Passing no arguments lists all contacts in your roster.", - "", - "Example: /roster (show your roster)", - "Example: /roster add someone@contacts.org (add the contact)", - "Example: /roster add someone@contacts.org Buddy (add the contact with nickname 'Buddy')", - "Example: /roster remove someone@contacts.org (remove the contact)", - "Example: /roster nick myfriend@chat.org My Friend", - "Example: /roster clearnick kai@server.com (clears nickname)", - NULL, - NULL, NULL, NULL, NULL } } }, + { + { "online", "Show all online contacts in your roster." }, + { "show", "Show the roster panel." }, + { "show offline", "Show offline contacts in the roster panel." }, + { "show resource", "Show contact's connected resources in the roster panel." }, + { "show empty", "When grouping by presence, show empty presence groups." }, + { "show empty", "When grouping by presence, show empty presence groups." }, + { "hide", "Hide the roster panel." }, + { "hide offline", "Hide offline contacts in the roster panel." }, + { "hide resource", "Hide contact's connected resources in the roster panel." }, + { "hide empty", "When grouping by presence, hide empty presence groups." }, + { "by group", "Group contacts in the roster panel by roster group." }, + { "by presence", "Group contacts in the roster panel by presence." }, + { "by none", "No grouping in the roster panel." }, + { "size ", "Percentage of the screen taken up by the roster (1-99)." }, + { "add []", "Add a new item to the roster." }, + { "remove ", "Removes an item from the roster." }, + { "remove_all contacts", "Remove all items from roster." }, + { "nick ", "Change a contacts nickname." }, + { "clearnick ", "Removes the current nickname." }, + END_ARGS }, + { + "/roster", + "/roster add someone@contacts.org", + "/roster add someone@contacts.org Buddy", + "/roster remove someone@contacts.org", + "/roster nick myfriend@chat.org My Friend", + "/roster clearnick kai@server.com", + "/roster size 15", + NULL } } + }, + + + // OLD STYLE + { "/group", cmd_group, parse_args_with_freetext, 0, 3, NULL, From 90dda0e9a0dfd10bcbc4c416031039d9719790c8 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 25 Jul 2015 00:45:20 +0100 Subject: [PATCH 07/25] Added more help to new format --- src/command/command.c | 1248 ++++++++++++++++++++++++----------------- 1 file changed, 744 insertions(+), 504 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index ef785089..b2d3be9b 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -262,651 +262,891 @@ static struct cmd_t command_defs[] = NULL } } }, - - // OLD STYLE - - { "/group", cmd_group, parse_args_with_freetext, 0, 3, NULL, - { "/group [show|add|remove] [group] [contact]", "Manage roster groups.", - { "/group [show|add|remove] [group] [contact]", - "------------------------------------------", - "View, add to, and remove from roster groups.", - "", - "show group : List all roster items a group.", - "add group contact : Added a contact to a group.", - "remove group contact : Remove a contact from a group.", - "", + { NULL, NULL, { NULL }, + { + "/group", + "/group show ", + "/group remove ", + NULL + }, + "View, add to, and remove from roster groups. " "Passing no argument will list all roster groups.", - "", - "Example: /group", - "Example: /group show friends", - "Example: /group add friends newfriend@server.org", - "Example: /group add family Brother (using contacts nickname)", - "Example: /group remove colleagues boss@work.com", - NULL, - NULL, NULL, NULL, NULL } } }, + { + { "show ", "List all roster items a group." }, + { "add ", "Add a contact to a group." }, + { "remove ", "Remove a contact from a group." }, + END_ARGS }, + { + "/group", + "/group show friends", + "/group add friends newfriend@server.org", + "/group add family Brother", + "/group remove colleagues boss@work.com", + NULL } } + }, { "/info", cmd_info, parse_args, 0, 1, NULL, - { "/info [contact|nick]", "Show information about a contact, room, or room member.", - { "/info [contact|nick]", - "--------------------", - "Show information about a contact, room, or room member.", - "", - "contact : The contact you wish to view information about.", - "nick : When in a chat room, the occupant you wish to view information about.", - "", - "Passing no argument in a chat window will use the current recipient.", + { NULL, NULL, { NULL }, + { + "/info", + "/info |", + NULL + }, + "Show information about a contact, room, or room member. " + "Passing no argument in a chat window will use the current recipient. " "Passing no argument in a chat room will display information about the room.", - "", - "Example: /info mybuddy@chat.server.org", - "Example: /info kai", - NULL, - NULL, NULL, NULL, NULL } } }, + { + { "contact", "The contact you wish to view information about." }, + { "nick", "When in a chat room, the occupant you wish to view information about." }, + END_ARGS }, + { + "/info mybuddy@chat.server.org", + "/info kai", + NULL } } + }, { "/caps", cmd_caps, parse_args, 0, 1, NULL, - { "/caps [fulljid|nick]", "Find out a contacts client software capabilities.", - { "/caps [fulljid|nick]", - "--------------------", - "Find out a contacts, or room members client software capabilities.", - "", - "fulljid : If in the console or a chat window, the full JID for which you wish to see capabilities.", - "nick : If in a chat room, nickname for which you wish to see capabilities.", - "", - "If in private chat initiated from a chat room, no parameter is required.", - "", - "Example: /caps mybuddy@chat.server.org/laptop (contact's laptop resource)", - "Example: /caps mybuddy@chat.server.org/phone (contact's phone resource)", - "Example: /caps bruce (room member)", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/caps", + "/caps |", + NULL + }, + "Find out a contacts, or room members client software capabilities. " + "If in private chat initiated from a chat room, no parameter is required.", + { + { "fulljid", "If in the console or a chat window, the full JID for which you wish to see capabilities." }, + { "nick", "If in a chat room, nickname for which you wish to see capabilities." }, + END_ARGS }, + { + "/caps mybuddy@chat.server.org/laptop", + "/caps mybuddy@chat.server.org/phone", + "/caps bruce", + NULL } } + }, { "/software", cmd_software, parse_args, 0, 1, NULL, - { "/software [fulljid|nick]", "Find out software version information about a contacts resource.", - { "/software [fulljid|nick]", - "------------------------", - "Find out a contact, or room members software version information.", - "", - "fulljid : If in the console or a chat window, the full JID for which you wish to see software information.", - "nick : If in a chat room, nickname for which you wish to see software information.", - "", - "If in private chat initiated from a chat room, no parameter is required.", + { NULL, NULL, { NULL }, + { + "/software", + "/software |", + NULL + }, + "Find out a contact, or room members software version information. " + "If in private chat initiated from a chat room, no parameter is required. " "If the contact's software does not support software version requests, nothing will be displayed.", - "", - "Example: /software mybuddy@chat.server.org/laptop (contact's laptop resource)", - "Example: /software mybuddy@chat.server.org/phone (contact's phone resource)", - "Example: /software bruce (room member)", - NULL, - NULL, NULL, NULL, NULL } } }, + { + { "fulljid", "If in the console or a chat window, the full JID for which you wish to see software information." }, + { "nick", "If in a chat room, nickname for which you wish to see software information." }, + END_ARGS }, + { + "/software mybuddy@chat.server.org/laptop", + "/software mybuddy@chat.server.org/phone", + "/software bruce", + NULL } } + }, { "/status", cmd_status, parse_args, 0, 1, NULL, - { "/status [contact|nick]", "Find out a contacts presence information.", - { "/status [contact|nick]", - "----------------------", - "Find out a contact, or room members presence information.", - "", - "contact : The contact who's presence you which to see.", - "nick : If in a chat room, the occupant who's presence you wish to see.", - "", + { NULL, NULL, { NULL }, + { + "/status", + "/status |", + NULL + }, + "Find out a contact, or room members presence information. " "If in a chat window the parameter is not required, the current recipient will be used.", - "", - "Example: /status buddy@server.com", - "Example: /status jon", - NULL, - NULL, NULL, NULL, NULL } } }, + { + { "contact", "The contact who's presence you which to see." }, + { "nick", "If in a chat room, the occupant who's presence you wish to see." }, + END_ARGS }, + { + "/status buddy@server.com", + "/status jon", + NULL } } + }, { "/resource", cmd_resource, parse_args, 1, 2, &cons_resource_setting, - { "/resource set|off|title|message [resource]", "Set the contact's resource, display settings.", - { "/resource set|off|title|message [resource]", - "------------------------------------------", - "Override chat session resource, and manage resource display settings.", - "", - "set resource : Set the resource to which messages will be sent.", - "off : Let the server choose which resource to route messages to.", - "title on|off : Show or hide the current resource in the titlebar.", - "message on|off : Show or hide the resource when showing an incoming message.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/resource set ", + "/resource off", + "/resource title on|off", + "/resource message on|off", + NULL + }, + "Override chat session resource, and manage resource display settings.", + { + { "set ", "Set the resource to which messages will be sent." }, + { "off", "Let the server choose which resource to route messages to." }, + { "title on|off", "Show or hide the current resource in the titlebar." }, + { "message on|off", "Show or hide the resource when showing an incoming message." }, + END_ARGS }, + { + NULL } } + }, { "/join", cmd_join, parse_args, 0, 5, NULL, - { "/join [room] [nick value] [password value]", "Join a chat room.", - { "/join [room] [nick value] [password value]", - "-----------------------------------------", - "Join a chat room at the conference server.", - "", - "room : Bare room JID (the chat server is determined by the 'muc.service' account property) or full room jid." - "nick value : Nickname to use in the room", - "password value : Password if the room requires it.", - "", - "If no room is supplied, a generated name will be used with the format private-chat-[UUID].", - "If no nickname is specified the account preference 'muc.nick' will be used which by default is the localpart of your JID.", - "If the room doesn't exist, and the server allows it, a new one will be created.", - "", - "Example: /join", - "Example: /join jdev@conference.jabber.org", - "Example: /join jdev@conference.jabber.org nick mynick", - "Example: /join private@conference.jabber.org nick mynick password mypassword", - "Example: /join jdev (as user@jabber.org will join jdev@conference.jabber.org)", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/join", + "/join [nick ] [password ]", + NULL + }, + "Join a chat room at the conference server. " + "If no room is supplied, a generated name will be used with the format private-chat-[UUID]. " + "If the domain part is not included in the room name, the account preference 'muc.service' will be used. " + "If no nickname is specified the account preference 'muc.nick' will be used which by default is the localpart of your JID. " + "If the room doesn't exist, and the server allows it, a new one will be created.", + { + { "", "The chat room to join." }, + { "nick ", "Nickname to use in the room." }, + { "password ", "Password if the room requires one." }, + END_ARGS }, + { + "/join", + "/join jdev@conference.jabber.org", + "/join jdev@conference.jabber.org nick mynick", + "/join private@conference.jabber.org nick mynick password mypassword", + "/join jdev", + NULL } } + }, { "/leave", cmd_leave, parse_args, 0, 0, NULL, - { "/leave", "Leave a chat room.", - { "/leave", - "------", - "Leave the current chat room.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/leave", + NULL + }, + "Leave the current chat room.", + { + END_ARGS }, + { + NULL } } + }, { "/invite", cmd_invite, parse_args_with_freetext, 1, 2, NULL, - { "/invite contact [message]", "Invite contact to chat room.", - { "/invite contact [message]", - "-------------------------", - "Send a direct invite to the current chat room.", - "", - "contact : The contact you wish to invite", - "message : An optional message to send with the invite.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/invite []", + NULL + }, + "Send an invite to a contact for the current chat room.", + { + { "", "The contact you wish to invite." }, + { "", "An optional message to send with the invite." }, + END_ARGS }, + { + NULL } } + }, { "/invites", cmd_invites, parse_args_with_freetext, 0, 0, NULL, - { "/invites", "Show outstanding chat room invites.", - { "/invites", - "--------", - "Show all rooms that you have been invited to, and not accepted or declined.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/invites", + NULL + }, + "Show all rooms that you have been invited to, and not accepted or declined.", + { + END_ARGS }, + { + NULL } } + }, { "/decline", cmd_decline, parse_args_with_freetext, 1, 1, NULL, - { "/decline room", "Decline a chat room invite.", - { "/decline room", - "-------------", - "Decline a chat room invitation.", - "", - "room : The room for the invite you wish to decline.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/decline ", + NULL + }, + "Decline a chat room invitation.", + { + { "", "The room for the invite you wish to decline." }, + END_ARGS }, + { + NULL } } + }, { "/room", cmd_room, parse_args, 1, 1, NULL, - { "/room accept|destroy|config", "Room configuration.", - { "/room accept|destroy|config", - "---------------------------", - "Chat room configuration.", - "", - "accept : Accept default room configuration.", - "destroy : Reject default room configuration.", - "config : Edit room configuration.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/room accept|destroy|config", + NULL + }, + "Chat room configuration.", + { + { "accept", "Accept default room configuration." }, + { "destroy", "Reject default room configuration, and destroy the room." }, + { "config", "Edit room configuration." }, + END_ARGS }, + { + NULL } } + }, { "/kick", cmd_kick, parse_args_with_freetext, 1, 2, NULL, - { "/kick nick [reason]", "Kick occupants from chat rooms.", - { "/kick nick [reason]", - "-------------------", - "Kick occupants from chat rooms.", - "", - "nick : Nickname of the occupant to kick from the room.", - "reason : Optional reason for kicking the occupant.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/kick []", + NULL + }, + "Kick occupant from chat room.", + { + { "", "Nickname of the occupant to kick from the room." }, + { "", "Optional reason for kicking the occupant." }, + END_ARGS }, + { + NULL } } + }, { "/ban", cmd_ban, parse_args_with_freetext, 1, 2, NULL, - { "/ban jid [reason]", "Ban users from chat rooms.", - { "/ban jid [reason]", - "-----------------", - "Ban users from chat rooms.", - "", - "jid : Bare JID of the user to ban from the room.", - "reason : Optional reason for banning the user.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/ban []", + NULL + }, + "Ban user from chat room.", + { + { "", "Bare JID of the user to ban from the room." }, + { "", "Optional reason for banning the user." }, + END_ARGS }, + { + NULL } } + }, { "/subject", cmd_subject, parse_args_with_freetext, 0, 2, NULL, - { "/subject set|clear [subject]", "Set or clear room subject.", - { "/subject set|clear [subject]", - "----------------------------", - "Set or clear room subject.", - "", - "set subject : Set the room subject.", - "clear : Clear the room subject.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/subject set ", + "/subject clear", + NULL + }, + "Set or clear room subject.", + { + { "set ", "Set the room subject." }, + { "clear", "Clear the room subject." }, + END_ARGS }, + { + NULL } } + }, { "/affiliation", cmd_affiliation, parse_args_with_freetext, 1, 4, NULL, - { "/affiliation set|list [affiliation] [jid] [reason]", "Manage room affiliations.", - { "/affiliation set|list [affiliation] [jid] [reason]", - "--------------------------------------------------", - "Manage room affiliations.", - "", - "set affiliation jid [reason]: Set the affiliation of user with jid, with an optional reason.", - "list [affiliation] : List all users with the specified affiliation, or all if none specified.", - "", - "The affiliation may be one of owner, admin, member, outcast or none.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/affiliation set []", + "/list []", + NULL + }, + "Manage room affiliations. " + "Affiliation may be one of owner, admin, member, outcast or none.", + { + { "set []", "Set the affiliation of user with jid, with an optional reason." }, + { "list []", "List all users with the specified affiliation, or all if none specified." }, + END_ARGS }, + { + NULL } } + }, { "/role", cmd_role, parse_args_with_freetext, 1, 4, NULL, - { "/role set|list [role] [nick] [reason]", "Manage room roles.", - { "/role set|list [role] [nick] [reason]", - "-------------------------------------", - "Manage room roles.", - "", - "set role nick [reason] : Set the role of occupant with nick, with an optional reason.", - "list [role] : List all occupants with the specified role, or all if none specified.", - "", - "The role may be one of moderator, participant, visitor or none.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/role set []", + "/list []", + NULL + }, + "Manage room roles. " + "Role may be one of moderator, participant, visitor or none.", + { + { "set []", "Set the role of occupant with nick, with an optional reason." }, + { "list []", "List all occupants with the specified role, or all if none specified." }, + END_ARGS }, + { + NULL } } + }, { "/occupants", cmd_occupants, parse_args, 1, 3, cons_occupants_setting, - { "/occupants show|hide|default|size [jid|show|hide|percent] [jid]", "Show or hide room occupants.", - { "/occupants show|hide|default|size [jid|show|hide|percent] [jid]", - "---------------------------------------------------------------", - "Show or hide room occupants, and occupants panel display settings.", - "", - "show : Show the occupants panel in current room.", - "hide : Hide the occupants panel in current room.", - "show jid : Show jid in the occupants panel in current room.", - "hide jid : Hide jid in the occupants panel in current room.", - "default show|hide : Whether occupants are shown by default in new rooms.", - "default show|hide jid : Whether occupants jids are shown by default in new rooms.", - "size percent : Percentage of the screen taken by the occupants list in rooms (1-99).", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/occupants show|hide [jid]", + "/occupants default show|hide [jid]", + "/occupants size []", + NULL + }, + "Show or hide room occupants, and occupants panel display settings.", + { + { "show", "Show the occupants panel in current room." }, + { "hide", "Hide the occupants panel in current room." }, + { "show jid", "Show jid in the occupants panel in current room." }, + { "hide jid", "Hide jid in the occupants panel in current room." }, + { "default show|hide", "Whether occupants are shown by default in new rooms." }, + { "default show|hide jid", "Whether occupants jids are shown by default in new rooms." }, + { "size ", "Percentage of the screen taken by the occupants list in rooms (1-99)." }, + END_ARGS }, + { + NULL } } + }, { "/form", cmd_form, parse_args, 1, 2, NULL, - { "/form show|submit|cancel|help [tag]", "Form handling.", - { "/form show|submit|cancel|help [tag]", - "-----------------------------------", - "Form configuration.", - "", - "show : Show the current form.", - "submit : Submit the current form.", - "cancel : Cancel changes to the current form.", - "help [tag] : Display help for form, or a specific field.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/form show", + "/form submit", + "/form cancel", + "/form help []", + NULL + }, + "Form configuration.", + { + { "show", "Show the current form." }, + { "submit", "Submit the current form." }, + { "cancel", "Cancel changes to the current form." }, + { "help []", "Display help for form, or a specific field." }, + END_ARGS }, + { + NULL } } + }, { "/rooms", cmd_rooms, parse_args, 0, 1, NULL, - { "/rooms [conference-service]", "List chat rooms.", - { "/rooms [conference-service]", - "---------------------------", - "List the chat rooms available at the specified conference service", - "", - "conference-service : The conference service to query.", - "", - "If no argument is supplied, the account preference 'muc.service' is used, 'conference.' by default.", - "", - "Example: /rooms conference.jabber.org", - "Example: /rooms (if logged in as me@server.org, is equivalent to /rooms conference.server.org)", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/rooms []", + NULL + }, + "List the chat rooms available at the specified conference service. " + "If no argument is supplied, the account preference 'muc.service' is used, 'conference.' by default.", + { + { "", "The conference service to query." }, + END_ARGS }, + { + "/rooms conference.jabber.org", + NULL } } + }, { "/bookmark", cmd_bookmark, parse_args, 0, 8, NULL, - { "/bookmark [command] [args..]", "Manage bookmarks.", - { "/bookmark [command] [args..]", - "----------------------------", - "Manage bookmarks and join bookmarked rooms.", - "", - "command : list|add|update|remove|join", - "", - "list : List all bookmarks.", - "add room@server [prop value..] : Add a bookmark for room@server with the following optional properties:", - " nick value : Nickname used in the chat room", - " password value : Password if required, may be stored in plaintext on your server", - " autojoin on|off : Whether to join the room automatically on login.", - "update room@server [prop value..] : Update any of the above properties associated with the bookmark.", - "remove room@server : Remove the bookmark for room@server.", - "join room@server : Join room using the properties associated with the bookmark.", - "", - "In a chat room, /bookmark with no arguments will bookmark the current room, setting autojoin to \"on\".", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/bookmark", + "/bookmark list", + "/bookmark add [nick ] [password ] [autojoin on|off]", + "/bookmark update [nick ] [password ] [autojoin on|off]", + "/bookmark remove ", + "/bookmark join ", + NULL + }, + "Manage bookmarks and join bookmarked rooms. " + "In a chat room, no arguments will bookmark the current room, setting autojoin to \"on\".", + { + { "list", "List all bookmarks." }, + { "add ", "Add a bookmark." }, + { "remove ", "Remove a bookmark." }, + { "update ", "Update the properties associated with a bookmark." }, + { "nick ", "Nickname used in the chat room." }, + { "password ", "Password if required, may be stored in plaintext on your server." }, + { "autojoin on|off", "Whether to join the room automatically on login." }, + { "join ", "Join room using the properties associated with the bookmark." }, + END_ARGS }, + { + NULL } } + }, { "/disco", cmd_disco, parse_args, 1, 2, NULL, - { "/disco info|items entity", "Service discovery.", - { "/disco info|items entity", - "---------------------", - "Find out information about an entities supported services.", - "", - "info : List protocols and features supported by an entity.", - "items : List items associated with an entity.", - "entity : Jabber ID.", - "", - "Example: /disco info myserver.org", - "Example: /disco items myserver.org", - "Example: /disco items conference.jabber.org", - "Example: /disco info myfriend@server.com/laptop", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/disco info []", + "/disco items []", + NULL + }, + "Find out information about an entities supported services. " + "Calling with no arguments will query the server you are currently connected to.", + { + { "info []", "List protocols and features supported by an entity." }, + { "items []", "List items associated with an entity." }, + END_ARGS }, + { + "/disco info", + "/disco items myserver.org", + "/disco items conference.jabber.org", + "/disco info myfriend@server.com/laptop", + NULL } } + }, { "/nick", cmd_nick, parse_args_with_freetext, 1, 1, NULL, - { "/nick nickname", "Change nickname in chat room.", - { "/nick nickname", - "--------------", - "Change the name by which other members of a chat room see you.", - "", - "nickname : The new nickname.", - "", - "Example: /nick kai hansen", - "Example: /nick bob", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/nick ", + NULL + }, + "Change your nickname in the current chat room.", + { + { "", "Your new nickname." }, + END_ARGS }, + { + NULL } } + }, { "/win", cmd_win, parse_args, 1, 1, NULL, - { "/win num", "View a window.", - { "/win num", - "--------", - "Show the contents of a specific window in the main window area.", - "", - "num - Window number to display.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/win ", + NULL + }, + "Move to the specified window.", + { + { "", "Window number to display." }, + END_ARGS }, + { + NULL } } + }, { "/wins", cmd_wins, parse_args, 0, 3, NULL, - { "/wins [tidy|prune|swap] [source target]", "List or tidy active windows.", - { "/wins [tidy|prune|swap] [source target]", - "---------------------------------------", - "Show a list of windows, or tidy or swap.", - "", - "tidy : Move windows so there are no gaps.", - "prune : Close all windows with no unread messages, and then tidy as above.", - "swap source target : Swap windows, target may be an empty position.", - "", - "Passing no argument will list all currently active windows and information about their usage.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/wins tidy", + "/wins prune", + "/wins swap ", + NULL + }, + "Manage windows. " + "Passing no argument will list all currently active windows and information about their usage.", + { + { "tidy", "Move windows so there are no gaps." }, + { "prune", "Close all windows with no unread messages, and then tidy so there are no gaps." }, + { "swap ", "Swap windows, target may be an empty position." }, + END_ARGS }, + { + NULL } } + }, { "/sub", cmd_sub, parse_args, 1, 2, NULL, - { "/sub request|allow|deny|show|sent|received [jid]", "Manage subscriptions.", - { "/sub request|allow|deny|show|sent|received [jid]", - "------------------------------------------------", - "Manage subscriptions to contact presence.", - "", - "request [jid] : Send a subscription request to the user.", - "allow [jid] : Approve a contact's subscription request.", - "deny [jid] : Remove subscription for a contact, or deny a request", - "show [jid] : Show subscription status for a contact.", - "sent : Show all sent subscription requests pending a response.", - "received : Show all received subscription requests awaiting your response.", - "", - "If jid is omitted, the contact of the current window is used.", - "", - "Example: /sub request myfriend@jabber.org", - "Example: /sub allow myfriend@jabber.org", - "Example: /sub request (whilst in chat with contact)", - "Example: /sub sent", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/sub request []", + "/sub allow []", + "/sub deny []", + "/sub show []", + "/sub sent", + "/sub received", + NULL + }, + "Manage subscriptions to contact presence. " + "If jid is omitted, the contact of the current window is used.", + { + { "request []", "Send a subscription request to the user." }, + { "allow []", "Approve a contact's subscription request." }, + { "deny []", "Remove subscription for a contact, or deny a request." }, + { "show []", "Show subscription status for a contact." }, + { "sent", "Show all sent subscription requests pending a response." }, + { "received", "Show all received subscription requests awaiting your response." }, + END_ARGS }, + { + "/sub request myfriend@jabber.org", + "/sub allow myfriend@jabber.org", + "/sub request", + "/sub sent", + NULL } } + }, { "/tiny", cmd_tiny, parse_args, 1, 1, NULL, - { "/tiny url", "Send url as tinyurl in current chat.", - { "/tiny url", - "---------", - "Send url as tinyurl in current chat.", - "", - "url : The url to make tiny.", - "", - "Example: /tiny http://www.profanity.im", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/tiny ", + NULL + }, + "Send url as tinyurl in current chat.", + { + { "", "The url to make tiny." }, + END_ARGS }, + { + "Example: /tiny http://www.profanity.im", + NULL } } + }, { "/who", cmd_who, parse_args, 0, 2, NULL, - { "/who [status|role|affiliation] [group]", "Show contacts/room occupants with chosen status, role or affiliation", - { "/who [status|role|affiliation] [group]", - "--------------------------------------", - "Show contacts/room occupants with chosen status, role or affiliation", - "", - "status : online|offline|away|dnd|xa|chat|available|unavailable|any", - " online : Contacts that are online, chat, away, xa, dnd", - " available : Contacts that are available for chat - online, chat.", - " unavailable : Contacts that are not available for chat - offline, away, xa, dnd.", - " any : Contacts with any status (same as calling with no argument).", - "role : moderator|participant|visitor", - "affiliation : owner|admin|member", - "group : Filter the results by the specified group.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/who", + "/who online|offline|away|dnd|xa|chat|available|unavailable|any []", + "/who moderator|participant|visitor", + "/who owner|admin|member", + NULL + }, + "Show contacts or room occupants with chosen status, role or affiliation", + { + { "offline|away|dnd|xa|chat", "Show contacts or room occupants with specified presence." }, + { "online", "Contacts that are online, chat, away, xa, dnd." }, + { "available", "Contacts that are available for chat - online, chat." }, + { "unavailable", "Contacts that are not available for chat - offline, away, xa, dnd." }, + { "any", "Contacts with any status (same as calling with no argument)." }, + { "", "Filter the results by the specified roster group, not applicable in chat rooms." }, + { "moderator|participant|visitor", "Room occupants with the specified role." }, + { "owner|admin|member", "Room occupants with the specified affiliation." }, + END_ARGS }, + { + "/who", + "/who xa", + "/who online friends", + "/who any family", + "/who particpant", + "/who admin", + NULL } } + }, { "/close", cmd_close, parse_args, 0, 1, NULL, - { "/close [num|read|all]", "Close windows.", - { "/close [num|read|all]", - "---------------------", - "Close the current window, or a number of windows.", - "", - "num : Close the specified window.", - "all : Close all windows.", - "read : Close all windows that have no new messages.", - "", - "Passing no argument will close the current window.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/close []", + "/close all|read", + NULL + }, + "Close windows. " + "Passing no argument closes the current window.", + { + { "", "Close the specified window." }, + { "all", "Close all windows." }, + { "read", "Close all windows that have no unread messages." }, + END_ARGS }, + { + NULL } } + }, { "/clear", cmd_clear, parse_args, 0, 0, NULL, - { "/clear", "Clear current window.", - { "/clear", - "------", - "Clear the current window.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/clear", + NULL + }, + "Clear the current window.", + { + END_ARGS }, + { + NULL } } + }, { "/quit", cmd_quit, parse_args, 0, 0, NULL, - { "/quit", "Quit Profanity.", - { "/quit", - "-----", - "Logout of any current session, and quit Profanity.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/quit", + NULL + }, + "Logout of any current session, and quit Profanity.", + { + END_ARGS }, + { + NULL } } + }, { "/privileges", cmd_privileges, parse_args, 1, 1, &cons_privileges_setting, - { "/privileges on|off", "Show occupant privileges in chat rooms.", - { "/privileges on|off", - "------------------", - "If enabled the room occupants panel will be grouped by role, and role information will be shown in the room.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/privileges on|off", + NULL + }, + "Group occupants panel by role, and show role information in chat rooms.", + { + { "on|off", "Enable or disable privilege information." }, + END_ARGS }, + { + NULL } } + }, { "/beep", cmd_beep, parse_args, 1, 1, &cons_beep_setting, - { "/beep on|off", "Terminal beep on new messages.", - { "/beep on|off", - "------------", - "Switch the terminal bell on or off.", - "The bell will sound when incoming messages are received.", - "If the terminal does not support sounds, it may attempt to flash the screen instead.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/beep on|off", + NULL + }, + "Switch the terminal bell on or off. " + "The bell will sound when incoming messages are received. " + "If the terminal does not support sounds, it may attempt to flash the screen instead.", + { + { "on|off", "Enable or disable terminal bell." }, + END_ARGS }, + { + NULL } } + }, { "/encwarn", cmd_encwarn, parse_args, 1, 1, &cons_encwarn_setting, - { "/encwarn on|off", "Titlebar encryption warning.", - { "/encwarn on|off", - "---------------", - "Enabled or disable the unencrypted warning message in the titlebar.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/encwarn on|off", + NULL + }, + "Titlebar encryption warning.", + { + { "on|off", "Enabled or disable the unencrypted warning message in the titlebar." }, + END_ARGS }, + { + NULL } } + }, { "/presence", cmd_presence, parse_args, 1, 1, &cons_presence_setting, - { "/presence on|off", "Show the contacts presence in the titlebar.", - { "/presence on|off", - "----------------", - "Switch display of the contacts presence in the titlebar on or off.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/presence on|off", + NULL + }, + "Show the contacts presence in the titlebar.", + { + { "on|off", "Switch display of the contacts presence in the titlebar on or off." }, + END_ARGS }, + { + NULL } } + }, { "/wrap", cmd_wrap, parse_args, 1, 1, &cons_wrap_setting, - { "/wrap on|off", "Word wrapping.", - { "/wrap on|off", - "------------", - "Enable or disable word wrapping in the main window.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/wrap on|off", + NULL + }, + "Word wrapping.", + { + { "on|off", "Enable or disable word wrapping in the main window." }, + END_ARGS }, + { + NULL } } + }, { "/winstidy", cmd_winstidy, parse_args, 1, 1, &cons_winstidy_setting, - { "/winstidy on|off", "Auto tidy windows.", - { "/winstidy on|off", - "----------------", - "Enable or disable auto window tidy.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/winstidy on|off", + NULL + }, + "Auto tidy windows, when a window is closed, windows will be moved to fill the gap.", + { + { "on|off", "Enable or disable auto window tidy." }, + END_ARGS }, + { + NULL } } + }, { "/time", cmd_time, parse_args, 1, 3, &cons_time_setting, - { "/time main|statusbar set|off [format]", "Time display.", - { "/time main|statusbar set|off [format]", - "-------------------------------------", - "Configure time display preferences.", - "", - "main set : Change time format to in main window.", - "main off : Do not show time in main window.", - "statusbar set : Change time format to in statusbar.", - "statusbar off : Do not show time in status bar.", - "", - "Time formats are strings supported by g_date_time_format.", - "See https://developer.gnome.org/glib/stable/glib-GDateTime.html#g-date-time-format for more details.", - "Example: /time main set %H:%M (main time will be set to HH:MM)", - "Example: /time statusbar set yolo (statusbar time will all be changed to a static yolo)", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/time main set ", + "/time main off", + "/time statusbar set ", + "/time statusbar off", + NULL + }, + "Configure time display preferences. " + "Time formats are strings supported by g_date_time_format. " + "See https://developer.gnome.org/glib/stable/glib-GDateTime.html#g-date-time-format for more details. " + "Setting the format to an unsupported string, will display the string. " + "If the format contains spaces, it must be surrounded with double quotes.", + { + { "main set ", "Change time format in main window." }, + { "main off", "Do not show time in main window." }, + { "statusbar set ", "Change time format in statusbar." }, + { "statusbar off", "Change time format in status bar." }, + END_ARGS }, + { + "/time main set \"%d-%m-%y %H:%M\"", + "/time main off", + "/time statusbar set %H:%M", + NULL } } + }, { "/inpblock", cmd_inpblock, parse_args, 2, 2, &cons_inpblock_setting, - { "/inpblock timeout|dynamic [millis|on|off]", "Configure input blocking.", - { "/inpblock timeout|dynamic [millis|on|off]", - "-----------------------------------------", - "How long to wait for input before checking for new messages or checking for state changes such as 'idle'.", - "", - "timeout millis : Time to wait (1-1000) in milliseconds before reading input from the terminal buffer, default: 1000.", - "dynamic on|off : Start with 0 millis and dynamically increase up to timeout when no activity, default: on.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/inpblock timeout ", + "/inpblock dynamic on|off", + NULL + }, + "How long to wait for keyboard input before checking for new messages or checking for state changes such as 'idle'.", + { + { "timeout ", "Time to wait (1-1000) in milliseconds before reading input from the terminal buffer, default: 1000." }, + { "dynamic on|off", "Start with 0 millis and dynamically increase up to timeout when no activity, default: on." }, + END_ARGS }, + { + NULL } } + }, { "/notify", cmd_notify, parse_args, 2, 3, &cons_notify_setting, - { "/notify [type value]|[type setting value]", "Control various desktop notifications.", - { "/notify [type value]|[type setting value]", - "-----------------------------------------", - "Settings for various kinds of desktop notifications.", - "", - "message on|off : Notifications for regular messages.", - "message current on|off : Whether messages in the current window trigger notifications.", - "message text on|off : Show message text in message notifications.", - "room on|off|mention : Notifications for chat room messages.", - "room current on|off : Whether chat room messages in the current window trigger notifications.", - "room text on|off : Show message text in chat room message notifications.", - "remind seconds : Notification reminder period for unread messages, use 0 to disable.", - "typing on|off : Notifications when contacts are typing.", - "typing current of|off : Whether typing notifications are triggered for the current window.", - "invite on|off : Notifications for chat room invites.", - "sub on|off : Notifications for subscription requests.", - "", - "Example: /notify message on (enable message notifications)", - "Example: /notify message text on (show message text in notifications)", - "Example: /notify room mention (enable chat room notifications only on mention)", - "Example: /notify room current off (disable room message notifications when window visible)", - "Example: /notify room text off (do not show message text in chat room notifications)", - "Example: /notify remind 10 (remind every 10 seconds)", - "Example: /notify remind 0 (switch off reminders)", - "Example: /notify typing on (enable typing notifications)", - "Example: /notify invite on (enable chat room invite notifications)", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/notify message on|off", + "/notify message current on|off", + "/notify message text on|off", + "/notify room on|off|mention", + "/notify room current on|off", + "/notify room text on|off", + "/notify remind ", + "/notify typing on|off", + "/notify typing current on|off", + "/notify invite on|off", + "/notify sub on|off", + NULL + }, + "Settings for various kinds of desktop notifications.", + { + { "message on|off", "Notifications for regular chat messages." }, + { "message current on|off", "Whether messages in the current window trigger notifications." }, + { "message text on|off", "Show message text in regular message notifications." }, + { "room on|off|mention", "Notifications for chat room messages, mention triggers notifications only when your nick is mentioned." }, + { "room current on|off", "Whether chat room messages in the current window trigger notifications." }, + { "room text on|off", "Show message text in chat room message notifications." }, + { "remind ", "Notification reminder period for unread messages, use 0 to disable." }, + { "typing on|off", "Notifications when contacts are typing." }, + { "typing current on|off", "Whether typing notifications are triggered for the current window." }, + { "invite on|off", "Notifications for chat room invites." }, + { "sub on|off", "Notifications for subscription requests." }, + END_ARGS }, + { + "/notify message on", + "/notify message text on", + "/notify room mention", + "/notify room current off", + "/notify room text off", + "/notify remind 10", + "/notify typing on", + "/notify invite on", + NULL } } + }, { "/flash", cmd_flash, parse_args, 1, 1, &cons_flash_setting, - { "/flash on|off", "Terminal flash on new messages.", - { "/flash on|off", - "-------------", - "Make the terminal flash when incoming messages are received in another window.", - "If the terminal doesn't support flashing, it may attempt to beep.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/flash on|off", + NULL + }, + "Make the terminal flash when incoming messages are received in another window. " + "If the terminal doesn't support flashing, it may attempt to beep.", + { + { "on|off", "Enable or disable terminal flash." }, + END_ARGS }, + { + NULL } } + }, { "/intype", cmd_intype, parse_args, 1, 1, &cons_intype_setting, - { "/intype on|off", "Show when contact is typing.", - { "/intype on|off", - "--------------", - "Show when a contact is typing in the console, and in active message window.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/intype on|off", + NULL + }, + "Show when a contact is typing in the console, and in active message window.", + { + { "on|off", "Enable or disable contact typing messages." }, + END_ARGS }, + { + NULL } } + }, + { "/splash", cmd_splash, parse_args, 1, 1, &cons_splash_setting, - { "/splash on|off", "Splash logo on startup and /about command.", - { "/splash on|off", - "--------------", - "Switch on or off the ascii logo on start up and when the /about command is called.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/splash on|off", + NULL + }, + "Switch on or off the ascii logo on start up and when the /about command is called.", + { + { "on|off", "Enable or disable splash logo." }, + END_ARGS }, + { + NULL } } + }, { "/autoconnect", cmd_autoconnect, parse_args, 1, 2, &cons_autoconnect_setting, - { "/autoconnect set|off [account]", "Set account to autoconnect with.", - { "/autoconnect set|off [account]", - "------------------------------", - "Enable or disable autoconnect on start up.", - "The setting can be overridden by the -a (--account) command line option.", - "", - "Example: /autoconnect set jc@stuntteam.org (autoconnect with the specified account).", - "Example: /autoconnect off (disable autoconnect).", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/autoconnect set ", + "/autoconnect off", + NULL + }, + "Enable or disable autoconnect on start up. " + "The setting can be overridden by the -a (--account) command line option.", + { + { "set ", "Connect with account on start up." }, + { "off", "Disable autoconnect." }, + END_ARGS }, + { + "/autoconnect set jc@stuntteam.org", + "/autoconnect off", + NULL } } + }, { "/vercheck", cmd_vercheck, parse_args, 0, 1, NULL, - { "/vercheck [on|off]", "Check for a new release.", - { "/vercheck [on|off]", - "------------------", - "Enable/disable a version check when Profanity starts, and each time the /about command is run.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/vercheck on|off", + NULL + }, + "Check for new versions when Profanity starts, and when the /about command is run.", + { + { "on|off", "Enable or disable the version check." }, + END_ARGS }, + { + NULL } } + }, { "/titlebar", cmd_titlebar, parse_args, 2, 2, &cons_titlebar_setting, - { "/titlebar show|goodbye on|off", "Manage the terminal window title.", - { "/titlebar show|goodbye on|off", - "-----------------------------", - "Show or hide a title and exit message in the terminal window title.", - "", - "show : Show current logged in user, and unread messages in the title.", - "goodbye : Show a message in the title when exiting profanity.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/titlebar show on|off", + "/titlebar goodbye on|off", + NULL + }, + "Allow Profanity to modify the window title bar.", + { + { "show on|off", "Show current logged in user, and unread messages as the window title." }, + { "goodbye on|off", "Show a message in the title when exiting profanity." }, + END_ARGS }, + { + NULL } } + }, + + + // OLD STYLE + { "/alias", cmd_alias, parse_args_with_freetext, 1, 3, NULL, From 19fb907bc5f44485b437b26a678900c8a2a665cc Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 25 Jul 2015 20:43:16 +0100 Subject: [PATCH 08/25] Generate HTML docs using new help format --- src/command/command.c | 84 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 13 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index b2d3be9b..593adbd9 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -3510,22 +3510,80 @@ command_docgen(void) while (curr) { Command *pcmd = curr->data; - fprintf(toc_fragment, "%s,\n", &pcmd->cmd[1], pcmd->cmd); - fprintf(main_fragment, "\n", &pcmd->cmd[1]); - fprintf(main_fragment, "

%s

\n", pcmd->cmd); - fputs("

Usage:

\n", main_fragment); - fprintf(main_fragment, "

%s

\n", pcmd->help.usage); + // old style + if (pcmd->help.usage) { +// fprintf(toc_fragment, "%s,\n", &pcmd->cmd[1], pcmd->cmd); +// fprintf(main_fragment, "\n", &pcmd->cmd[1]); +// fprintf(main_fragment, "

%s

\n", pcmd->cmd); +// fputs("

Usage:

\n", main_fragment); +// fprintf(main_fragment, "

%s

\n", pcmd->help.usage); +// +// fputs("

Details:

\n", main_fragment); +// fputs("

", main_fragment);
+//            int i = 2;
+//            while (pcmd->help.long_help[i]) {
+//                fprintf(main_fragment, "%s\n", pcmd->help.long_help[i++]);
+//            }
+//            fputs("

\n
back to top


\n", main_fragment); +// fputs("\n", main_fragment); - fputs("

Details:

\n", main_fragment); - fputs("

", main_fragment);
-        int i = 2;
-        while (pcmd->help.long_help[i]) {
-            fprintf(main_fragment, "%s\n", pcmd->help.long_help[i++]);
+        // new style
+        } else {
+            fprintf(toc_fragment, "%s,\n", &pcmd->cmd[1], pcmd->cmd);
+            fprintf(main_fragment, "\n", &pcmd->cmd[1]);
+            fprintf(main_fragment, "

%s

\n", pcmd->cmd); + + fputs("

Synopsis

\n", main_fragment); + fputs("

", main_fragment);
+            int i = 0;
+            while (pcmd->help.synopsis[i]) {
+                char *str1 = str_replace(pcmd->help.synopsis[i], "<", "<");
+                char *str2 = str_replace(str1, ">", ">");
+                fprintf(main_fragment, "%s\n", str2);
+                i++;
+            }
+            fputs("

\n", main_fragment); + + fputs("

Description

\n", main_fragment); + fputs("

", main_fragment); + fprintf(main_fragment, "%s\n", pcmd->help.desc); + fputs("

\n", main_fragment); + + if (pcmd->help.args[0][0] != NULL) { + fputs("

Arguments

\n", main_fragment); + fputs("", main_fragment); + for (i = 0; pcmd->help.args[i][0] != NULL; i++) { + fputs("", main_fragment); + fputs("", main_fragment); + fputs("", main_fragment); + fputs("", main_fragment); + } + fputs("
", main_fragment); + fputs("", main_fragment); + char *str1 = str_replace(pcmd->help.args[i][0], "<", "<"); + char *str2 = str_replace(str1, ">", ">"); + fprintf(main_fragment, "%s", str2); + fputs("", main_fragment); + fputs("", main_fragment); + fprintf(main_fragment, "%s", pcmd->help.args[i][1]); + fputs("
\n", main_fragment); + } + + if (pcmd->help.examples[0] != NULL) { + fputs("

Examples

\n", main_fragment); + fputs("

", main_fragment);
+                int i = 0;
+                while (pcmd->help.examples[i]) {
+                    fprintf(main_fragment, "%s\n", pcmd->help.examples[i]);
+                    i++;
+                }
+                fputs("

\n", main_fragment); + } + + fputs("
back to top


\n", main_fragment); + fputs("\n", main_fragment); } - fputs("

\n
back to top


\n", main_fragment); - fputs("\n", main_fragment); - curr = g_list_next(curr); } From b33f4777d09077b6f3042bc46ed49cfdabfb86bb Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 25 Jul 2015 20:57:21 +0100 Subject: [PATCH 09/25] Fix formatting for variables in new help --- src/command/command.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 593adbd9..83e5bc10 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -123,8 +123,8 @@ static struct cmd_t command_defs[] = }, "Help on using Profanity. Passing no arguments list help areas.", { - { "area", "Summary help for commands in a certain area of functionality." }, - { "command", "Full help for a specific command, for example '/help connect'." }, + { "", "Summary help for commands in a certain area of functionality." }, + { "", "Full help for a specific command, for example '/help connect'." }, END_ARGS }, { "/help commands", @@ -159,9 +159,9 @@ static struct cmd_t command_defs[] = "If no account is specified, the default is used if one is configured. " "A local account is created with the JID as it's name if it doesn't already exist.", { - { "account", "The local account you wish to connect with, or a JID if connecting for the first time." }, - { "server ", "Supply a server if it is different to the domain part of your JID." }, - { "port ", "The port to use if different to the default (5222, or 5223 for SSL)." }, + { "", "The local account you wish to connect with, or a JID if connecting for the first time." }, + { "server ", "Supply a server if it is different to the domain part of your JID." }, + { "port ", "The port to use if different to the default (5222, or 5223 for SSL)." }, END_ARGS }, { "/connect", @@ -299,8 +299,8 @@ static struct cmd_t command_defs[] = "Passing no argument in a chat window will use the current recipient. " "Passing no argument in a chat room will display information about the room.", { - { "contact", "The contact you wish to view information about." }, - { "nick", "When in a chat room, the occupant you wish to view information about." }, + { "", "The contact you wish to view information about." }, + { "", "When in a chat room, the occupant you wish to view information about." }, END_ARGS }, { "/info mybuddy@chat.server.org", @@ -319,8 +319,8 @@ static struct cmd_t command_defs[] = "Find out a contacts, or room members client software capabilities. " "If in private chat initiated from a chat room, no parameter is required.", { - { "fulljid", "If in the console or a chat window, the full JID for which you wish to see capabilities." }, - { "nick", "If in a chat room, nickname for which you wish to see capabilities." }, + { "", "If in the console or a chat window, the full JID for which you wish to see capabilities." }, + { "", "If in a chat room, nickname for which you wish to see capabilities." }, END_ARGS }, { "/caps mybuddy@chat.server.org/laptop", @@ -341,8 +341,8 @@ static struct cmd_t command_defs[] = "If in private chat initiated from a chat room, no parameter is required. " "If the contact's software does not support software version requests, nothing will be displayed.", { - { "fulljid", "If in the console or a chat window, the full JID for which you wish to see software information." }, - { "nick", "If in a chat room, nickname for which you wish to see software information." }, + { "", "If in the console or a chat window, the full JID for which you wish to see software information." }, + { "", "If in a chat room, nickname for which you wish to see software information." }, END_ARGS }, { "/software mybuddy@chat.server.org/laptop", @@ -362,8 +362,8 @@ static struct cmd_t command_defs[] = "Find out a contact, or room members presence information. " "If in a chat window the parameter is not required, the current recipient will be used.", { - { "contact", "The contact who's presence you which to see." }, - { "nick", "If in a chat room, the occupant who's presence you wish to see." }, + { "", "The contact who's presence you which to see." }, + { "", "If in a chat room, the occupant who's presence you wish to see." }, END_ARGS }, { "/status buddy@server.com", @@ -813,7 +813,7 @@ static struct cmd_t command_defs[] = "/who xa", "/who online friends", "/who any family", - "/who particpant", + "/who participant", "/who admin", NULL } } }, @@ -1104,7 +1104,7 @@ static struct cmd_t command_defs[] = "The setting can be overridden by the -a (--account) command line option.", { { "set ", "Connect with account on start up." }, - { "off", "Disable autoconnect." }, + { "off", "Disable autoconnect." }, END_ARGS }, { "/autoconnect set jc@stuntteam.org", From cb7504e67f6d7e7a48dac96d7d2c6ef1a373873f Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 26 Jul 2015 00:17:16 +0100 Subject: [PATCH 10/25] Moved remaining help to new format --- helpexample.txt | 89 ----- src/command/command.c | 822 ++++++++++++++++++++++++++---------------- 2 files changed, 507 insertions(+), 404 deletions(-) delete mode 100644 helpexample.txt diff --git a/helpexample.txt b/helpexample.txt deleted file mode 100644 index 4dc40169..00000000 --- a/helpexample.txt +++ /dev/null @@ -1,89 +0,0 @@ -ROSTER - -Synopsis: -/roster -/roster online -/roster show [offline|resource|empty] -/roster hide [offline|resource|empty] -/roster by group|presence|none -/roster size -/roster add [] -/roster remove -/roster remove_all contacts -/roster nick -/roster clearnick - -Description: -Manage your roster, and roster display settings. Passing no arguments displays your roster. - -Arguments: -online : Show all online contacts in your roster. -show : Show the roster panel. -show offline : Show offline contacts in the roster panel. -show resource : Show contact's connected resources in the roster panel. -show empty : When grouping by presence, show empty presence groups -hide : Hide the roster panel. -hide offline : Hide offline contacts in the roster panel. -hide resource : Hide contact's connected resources in the roster panel. -hide empty : When grouping by presence, hide empty presence groups -by group : Group contacts in the roster panel by roster group. -by presence : Group contacts in the roster panel by presence. -by none : No grouping in the roster panel. -size : Percentage of the screen taken up by the roster (1-99). -add [] : Add a new item to the roster. -remove : Removes an item from the roster. -remove_all contacts : Remove all items from roster. -nick : Change a contacts nickname. -clearnick : Removes the current nickname. - -Exmaples: -/roster -/roster add someone@contacts.org -/roster add someone@contacts.org Buddy -/roster remove someone@contacts.org -/roster nick myfriend@chat.org My Friend -/roster clearnick kai@server.com -/roster size 15 - -OTR - -Synopsis: -/otr gen -/otr myfp -/otr theirfp -/otr start [] -/otr end -/otr trust -/otr untrust -/otr log on|off|redact -/otr warn on|off -/otr libver -/otr policy manual|opportunistic|always -/otr secret -/otr question -/otr answer - -Description: -Off The Record message encryption commands. - -Arguments: -gen : Generate your private key. -myfp : Show your fingerprint. -theirfp : Show contacts fingerprint. -start : Start an OTR session with current recipient. -start : Start an OTR session with the contact. -end : End the current OTR session. -trust : Indicate that you have verified the contact's fingerprint. -untrust : Indicate the the contact's fingerprint is not verified. -log on : Enable plaintext logging of OTR messages. -log off : Disable logging of OTR messages. -log redact : Log OTR messages as [redacted], the default. -warn on : Show in the titlebar when unencrypted messaging is being used. -warn off : Show in the titlebar when unencrypted messaging is being used. -libver : Show which version of the libotr library is being used. -policy manual : Set the global OTR policy. -policy opportunistici : Set the global OTR policy. -policy always : Set the global OTR policy. -secret : Verify a contacts identity using a shared secret. -question : Verify a contacts identity using a question and expected answer. -answer : Respond to a question answer verification request with your answer. diff --git a/src/command/command.c b/src/command/command.c index 83e5bc10..fe332f4b 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1144,399 +1144,591 @@ static struct cmd_t command_defs[] = NULL } } }, - - // OLD STYLE - - { "/alias", cmd_alias, parse_args_with_freetext, 1, 3, NULL, - { "/alias add|remove|list [name value]", "Add your own command aliases.", - { "/alias add|remove|list [name value]", - "-----------------------------------", - "Add, remove or show command aliases.", - "", - "add name value : Add a new command alias.", - "remove name : Remove a command alias.", - "list : List all aliases.", - "", - "Example: /alias add friends /who online friends", - "Example: /alias add /q /quit", - "Example: /alias a /away \"I'm in a meeting.\"", - "Example: /alias remove q", - "Example: /alias list", - "", - "The above aliases will be available as /friends and /a", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/alias list", + "/alias add ", + "/alias remove ", + NULL + }, + "Add, remove or list command aliases.", + { + { "list", "List all aliases." }, + { "add ", "Add a new command alias." }, + { "remove ", "Remove a command alias." }, + END_ARGS }, + { + "/alias add friends /who online friends", + "/alias add /q /quit", + "/alias a /away \"I'm in a meeting.\"", + "/alias remove q", + "/alias list", + NULL } } + }, { "/chlog", cmd_chlog, parse_args, 1, 1, &cons_chlog_setting, - { "/chlog on|off", "Chat logging to file.", - { "/chlog on|off", - "-------------", - "Switch chat logging on or off.", - "This setting will be enabled if /history is set to on.", - "When disabling this option, /history will also be disabled.", - "See the /grlog setting for enabling logging of chat room (groupchat) messages.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/chlog on|off", + NULL + }, + "Switch chat logging on or off. " + "This setting will be enabled if /history is set to on. " + "When disabling this option, /history will also be disabled. " + "See the /grlog setting for enabling logging of chat room (groupchat) messages.", + { + { "on|off", "Enable or disable chat logging." }, + END_ARGS }, + { + NULL } } + }, { "/grlog", cmd_grlog, parse_args, 1, 1, &cons_grlog_setting, - { "/grlog on|off", "Chat logging of chat rooms to file.", - { "/grlog on|off", - "-------------", - "Switch chat room logging on or off.", - "See the /chlog setting for enabling logging of one to one chat.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/grlog on|off", + NULL + }, + "Switch chat room logging on or off. " + "See the /chlog setting for enabling logging of one to one chat.", + { + { "on|off", "Enable or disable chat room logging." }, + END_ARGS }, + { + NULL } } + }, { "/states", cmd_states, parse_args, 1, 1, &cons_states_setting, - { "/states on|off", "Send chat states during a chat session.", - { "/states on|off", - "--------------", - "Send chat state notifications during chat sessions.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/states on|off", + NULL + }, + "Send chat state notifications to recipient during chat sessions, such as typing, paused, active, gone.", + { + { "on|off", "Enable or disable sending of chat state notifications." }, + END_ARGS }, + { + NULL } } + }, { "/pgp", cmd_pgp, parse_args, 1, 3, NULL, - { "/pgp command [args..]", "Open PGP commands.", - { "/pgp command [args..]", - "---------------------", - "Open PGP commands.", - "", - "keys : List all keys.", - "libver : Show which version of the libgpgme library is being used.", - "fps : Show known fingerprints.", - "setkey contact keyid : Manually associate a key ID with a JID.", - "start [contact] : Start PGP encrypted chat, current contact will be used if not specified.", - "end : End PGP encrypted chat with the current recipient.", - "log on|off|redact : PGP message logging, default: redact.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/pgp libver", + "/pgp keys", + "/pgp fps", + "/pgp setkey ", + "/pgp start []", + "/pgp end", + "/pgp log on|off|redact", + NULL + }, + "Open PGP commands to manage keys, and perform PGP encryption during chat sessions. " + "See the /account command to set your own PGP key.", + { + { "libver", "Show which version of the libgpgme library is being used." }, + { "keys", "List all keys." }, + { "fps", "Show known fingerprints." }, + { "setkey ", "Manually associate a key ID with a JID." }, + { "start []", "Start PGP encrypted chat, current contact will be used if not specified." }, + { "end", "End PGP encrypted chat with the current recipient." }, + { "log on|off", "Enable or disable plaintext logging of PGP encrypted messages." }, + { "log redact", "Log PGP encrypted messages, but replace the contents with [redacted]. This is the default." }, + END_ARGS }, + { + "/pgp log off", + "/pgp setkey buddy@buddychat.org BA19CACE5A9592C5", + "/pgp start buddy@buddychat.org", + "/pgp end", + NULL } } + }, { "/otr", cmd_otr, parse_args, 1, 3, NULL, - { "/otr command [args..]", "Off The Record encryption commands.", - { "/otr command [args..]", - "---------------------", - "Off The Record encryption commands.", - "", - "gen : Generate your private key.", - "myfp : Show your fingerprint.", - "theirfp : Show contacts fingerprint.", - "start [contact] : Start an OTR session with contact, or current recipient if omitted.", - "end : End the current OTR session,", - "trust : Indicate that you have verified the contact's fingerprint.", - "untrust : Indicate the the contact's fingerprint is not verified,", - "log on|off|redact : OTR message logging, default: redact.", - "warn on|off : Show in the titlebar when unencrypted messaging is being used.", - "libver : Show which version of the libotr library is being used.", - "policy manual|opportunistic|always : Set the global OTR policy.", - "secret [secret] : Verify a contacts identity using a shared secret.", - "question [question] [answer] : Verify a contacts identity using a question and expected answer.", - "answer [answer] : Respond to a question answer verification request with your answer.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/otr libver", + "/otr gen", + "/otr myfp|theirfp", + "/otr start []", + "/otr end", + "/otr trust|untrust", + "/otr secret ", + "/otr question ", + "/otr answer ", + "/otr policy manual|opportunistic|always", + "/otr log on|off|redact", + NULL + }, + "Off The Record (OTR) commands to manage keys, and perform OTR encryption during chat sessions.", + { + { "libver", "Show which version of the libotr library is being used." }, + { "gen", "Generate your private key." }, + { "myfp", "Show your fingerprint." }, + { "theirfp", "Show contacts fingerprint." }, + { "start []", "Start an OTR session with contact, or current recipient if omitted." }, + { "end", "End the current OTR session," }, + { "trust|untrust", "Indicate whether or not you trust the contact's fingerprint." }, + { "secret ", "Verify a contact's identity using a shared secret." }, + { "question ", "Verify a contact's identity using a question and expected answer." }, + { "answer ", "Respond to a question answer verification request with your answer." }, + { "policy manual", "Set the global OTR policy to manual, OTR sessions must be started manually." }, + { "policy opportunistic", "Set the global OTR policy to opportunistic, and OTR sessions will be attempted upon starting a conversation." }, + { "policy always", "Set the global OTR policy to always, an error will be displayed if an OTR session cannot be initiated upon starting a conversation." }, + { "log on|off", "Enable or disable plaintext logging of OTR encrypted messages." }, + { "log redact", "Log OTR encrypted messages, but replace the contents with [redacted]. This is the default." }, + END_ARGS }, + { + "/otr log off", + "/otr policy manual", + "/otr gen", + "/otr start buddy@buddychat.org", + "/otr myfp", + "/otr theirfp", + "/otr question \"What is the name of my rabbit?\" fiffi", + "/otr end", + NULL } } + }, { "/outtype", cmd_outtype, parse_args, 1, 1, &cons_outtype_setting, - { "/outtype on|off", "Send typing notification to recipient.", - { "/outtype on|off", - "---------------", - "Send typing notifications, chat states (/states) will be enabled if this setting is set.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/outtype on|off", + NULL + }, + "Send typing notifications, chat states (/states) will be enabled if this setting is enabled.", + { + { "on|off", "Enable or disable sending typing notifications." }, + END_ARGS }, + { + NULL } } + }, { "/gone", cmd_gone, parse_args, 1, 1, &cons_gone_setting, - { "/gone minutes", "Send 'gone' state to recipient after a period.", - { "/gone minutes", - "-------------", - "Send a 'gone' state to the recipient after the specified number of minutes.", - "A value of 0 will disable sending this chat state.", - "Chat states (/states) will be enabled if this setting is set.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/gone ", + NULL + }, + "Send a 'gone' state to the recipient after the specified number of minutes. " + "Chat states (/states) will be enabled if this setting is set.", + { + { "", "Number of minutes of inactivity before sending the 'gone' state, a value of 0 will disable sending this state." }, + END_ARGS }, + { + NULL } } + }, { "/history", cmd_history, parse_args, 1, 1, &cons_history_setting, - { "/history on|off", "Chat history in message windows.", - { "/history on|off", - "---------------", - "Switch chat history on or off, /chlog will automatically be enabled when this setting is on.", - "When history is enabled, previous messages are shown in chat windows.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/history on|off", + NULL + }, + "Switch chat history on or off, /chlog will automatically be enabled when this setting is on. " + "When history is enabled, previous messages are shown in chat windows.", + { + { "on|off", "Enable or disable showing chat history." }, + END_ARGS }, + { + NULL } } + }, { "/log", cmd_log, parse_args, 1, 2, &cons_log_setting, - { "/log where|rotate|maxsize|shared [value]", "Manage system logging settings.", - { "/log where|rotate|maxsize|shared [value]", - "----------------------------------------", - "Manage profanity logging settings.", - "", - "where : Show the current log file location.", - "rotate on|off : Rotate log, default on.", - "maxsize bytes : With rotate enabled, specifies the max log size, defaults to 1048580 (1MB).", - "shared on|off : Share logs between all instances, default: on.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/log where", + "/log rotate on|off", + "/log maxsize ", + "/log shared on|off", + NULL + }, + "Manage profanity log settings.", + { + { "where", "Show the current log file location." }, + { "rotate on|off", "Rotate log, default on." }, + { "maxsize ", "With rotate enabled, specifies the max log size, defaults to 1048580 (1MB)." }, + { "shared on|off", "Share logs between all instances, default: on. When off, the process id will be included in the log." }, + END_ARGS }, + { + NULL } } + }, { "/carbons", - cmd_carbons, parse_args, 1, 1, &cons_carbons_setting, - { "/carbons on|off", "Message carbons.", - { "/carbons on|off", - "---------------", - "Enable or disable message carbons.", - "The message carbons feature ensures that both sides of all conversations are shared with all the user's clients that implement this protocol.", - NULL, - NULL, NULL, NULL, NULL } } }, + cmd_carbons, parse_args, 1, 1, &cons_carbons_setting, + { NULL, NULL, { NULL }, + { + "/carbons on|off", + NULL + }, + "Enable or disable message carbons. " + "Message carbons ensure that both sides of all conversations are shared with all the user's clients that implement this protocol.", + { + { "on|off", "Enable or disable message carbons." }, + END_ARGS }, + { + NULL } } + }, { "/receipts", - cmd_receipts, parse_args, 2, 2, &cons_receipts_setting, - { "/receipts send|request on|off", "Message delivery receipts.", - { "/receipts send|request on|off", - "-----------------------------", - "Enable or disable message delivery receipts. The interface will indicate when a message has been received.", - "", - "send on|off : Enable or disable sending of delivery receipts.", - "request on|off : Enable or disable sending of delivery receipt requests.", - NULL, - NULL, NULL, NULL, NULL } } }, + cmd_receipts, parse_args, 2, 2, &cons_receipts_setting, + { NULL, NULL, { NULL }, + { + "/receipts request on|off", + "/receipts send on|off", + NULL + }, + "Enable or disable message delivery receipts. The interface will indicate when a message has been received.", + { + { "request on|off", "Whether or not to request a receipt upon sending a message." }, + { "send on|off", "Whether or not to send a receipt if one has been requested with a received message." }, + END_ARGS }, + { + NULL } } + }, { "/reconnect", cmd_reconnect, parse_args, 1, 1, &cons_reconnect_setting, - { "/reconnect seconds", "Set reconnect interval.", - { "/reconnect seconds", - "------------------", - "Set the reconnect attempt interval in seconds for when the connection is lost.", - "A value of 0 will switch off reconnect attempts.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/reconnect ", + NULL + }, + "Set the reconnect attempt interval for when the connection is lost.", + { + { "", "Number of seconds before attempting to reconnect, a value of 0 disables reconnect." }, + END_ARGS }, + { + NULL } } + }, { "/autoping", cmd_autoping, parse_args, 1, 1, &cons_autoping_setting, - { "/autoping seconds", "Server ping interval.", - { "/autoping seconds", - "-----------------", - "Set the number of seconds between server pings, so ensure connection kept alive.", - "A value of 0 will switch off autopinging the server.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/autoping ", + NULL + }, + "Set the interval between sending ping requests to the server to ensure the connection is kept alive.", + { + { "", "Number of seconds between sending pings, a value of 0 disables autoping." }, + END_ARGS }, + { + NULL } } + }, { "/ping", cmd_ping, parse_args, 0, 1, NULL, - { "/ping [target]", "Send ping IQ request.", - { "/ping [target]", - "--------------", - "Sends an IQ ping stanza to the specified target.", - "If no target is supplied, your chat server will be pinged.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/ping []", + NULL + }, + "Sends an IQ ping stanza to the specified JID. " + "If no JID is supplied, your chat server will be pinged.", + { + { "", "The Jabber ID to send the ping request to." }, + END_ARGS }, + { + NULL } } + }, { "/autoaway", cmd_autoaway, parse_args_with_freetext, 2, 2, &cons_autoaway_setting, - { "/autoaway mode|time|message|check value", "Set auto idle/away properties.", - { "/autoaway mode|time|message|check value", - "---------------------------------------", - "Manage autoway properties.", - "", - "mode idle : Sends idle time, status remains online.", - "mode away : Sends an away presence.", - "mode off : Disabled (default).", - "time minutes : Number of minutes before the presence change is sent, default: 15.", - "message text|off : Optional message to send with the presence change, default: off (disabled).", - "check on|off : When enabled, checks for activity and sends online presence, default: on.", - "", - "Example: /autoaway mode idle", - "Example: /autoaway time 30", - "Example: /autoaway message I'm not really doing much", - "Example: /autoaway check off", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/autoaway mode idle|away|off", + "/autoaway time ", + "/autoaway message |off", + "/autoaway check on|off", + NULL + }, + "Manage autoway settings for idle time.", + { + { "mode idle", "Sends idle time, status remains online." }, + { "mode away", "Sends an away presence." }, + { "mode off", "Disabled (default)." }, + { "time ", "Number of minutes before the presence change is sent, default: 15." }, + { "message ", "Optional message to send with the presence change, default: off (disabled)." }, + { "message off", "Send no message with autoaway presence." }, + { "check on|off", "When enabled, checks for activity and sends online presence, default: on." }, + END_ARGS }, + { + "/autoaway mode idle", + "/autoaway time 30", + "/autoaway message I'm not really doing much", + "/autoaway check off", + NULL } } + }, { "/priority", cmd_priority, parse_args, 1, 1, &cons_priority_setting, - { "/priority value", "Set priority for the current account.", - { "/priority value", - "---------------", - "Set priority for the current account.", - "", - "value : Number between -128 and 127, default: 0.", - "", - "See the /account command for specific priority settings per presence status.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/priority ", + NULL + }, + "Set priority for the current account. " + "See the /account command for specific priority settings per presence status.", + { + { "", "Number between -128 and 127, default: 0." }, + END_ARGS }, + { + NULL } } + }, { "/account", cmd_account, parse_args, 0, 4, NULL, - { "/account [command] [account] [property] [value]", "Manage accounts.", - { "/account [command] [account] [property] [value]", - "-----------------------------------------------", - "Commands for creating and managing accounts.", - "", - "list : List all accounts.", - "show account : Show information about an account.", - "enable account : Enable the account, it will be used for autocomplete.", - "disable account : Disable the account.", - "default [set|off] [account] : Set the default account.", - "add account : Create a new account.", - "remove account : Remove an account.", - "rename account newname : Rename account to newname.", - "set account property value : Set 'property' of 'account' to 'value'.", - "clear account property value : Clear 'property' of 'account'.", - "", - "Account properties.", - "", - "jid : The Jabber ID of the account, account name will be used if not set.", - "server : The chat server, if different to the domainpart of the JID.", - "port : The port used for connecting if not the default (5222, or 5223 for SSL).", - "status : The presence status to use on login, use 'last' to use your last status before logging out.", - "online|chat|away|xa|dnd : Priority for the specified presence.", - "resource : The resource to be used.", - "password : Password for the account, note this is currently stored in plaintext if set.", - "eval_password : Shell command evaluated to retrieve password for the account. Can be used to retrieve password from keyring.", - "muc : The default MUC chat service to use.", - "nick : The default nickname to use when joining chat rooms.", - "otr : Override global OTR policy for this account: manual, opportunistic or always.", - "", - "Example: /account add me", - "Example: /account set me jid me@chatty", - "Example: /account set me server talk.chat.com", - "Example: /account set me port 5111", - "Example: /account set me muc chatservice.mycompany.com", - "Example: /account set me nick dennis", - "Example: /account set me status dnd", - "Example: /account set me dnd -1", - "Example: /account rename me gtalk", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/account", + "/account list", + "/account show ", + "/account enable|disable ", + "/account default set ", + "/account default off", + "/account add ", + "/account remove ", + "/account rename ", + "/account set jid ", + "/account set server ", + "/account set port ", + "/account set status ", + "/account set online|chat|away|xa|dnd ", + "/account set resource ", + "/account set password ", + "/account set eval_password ", + "/account set muc ", + "/account set nick ", + "/account set otr manual|opportunistic|always", + "/account set pgpkeyid ", + "/account clear password", + "/account clear eval_password", + "/account clear server", + "/account clear port", + "/account clear otr", + "/account clear pgpkeyid", + NULL + }, + "Commands for creating and managing accounts. " + "Calling with no arguments will display information for the current account.", + { + { "list", "List all accounts." }, + { "show ", "Show details for the specified account." }, + { "enable ", "Enable the account, it will be used for autocompletion." }, + { "disable ", "Disable the account." }, + { "default set ", "Set the default account, used when no argument passed to the /connect command." }, + { "default off", "Clear the default account setting." }, + { "add ", "Create a new account." }, + { "remove ", "Remove an account." }, + { "rename ", "Rename 'account' to 'newaccount'." }, + { "set jid ", "Set the Jabber ID for the account, account name will be used if not set." }, + { "set server ", "The chat server, if different to the domainpart of the JID." }, + { "set port ", "The port used for connecting if not the default (5222, or 5223 for SSL)." }, + { "set status ", "The presence status to use on login, use 'last' to use your last status before logging out." }, + { "set online|chat|away|xa|dnd ", "Set the priority (-128..127) to use for the specified presence." }, + { "set resource ", "The resource to be used for this account." }, + { "set password ", "Password for the account, note this is currently stored in plaintext if set." }, + { "set eval_password ", "Shell command evaluated to retrieve password for the account. Can be used to retrieve password from keyring." }, + { "set muc ", "The default MUC chat service to use, defaults to 'conference.' where the domain part is from the account JID." }, + { "set nick ", "The default nickname to use when joining chat rooms." }, + { "set otr manual|opportunistic|always", "Override global OTR policy for this account, see /otr." }, + { "set pgpkeyid ", "Set the ID of the PGP key for this account, see /pgp." }, + { "clear server", "Remove the server setting for this account." }, + { "clear port", "Remove the port setting for this account." }, + { "clear password", "Remove the password setting for this account." }, + { "clear eval_password", "Remove the eval_password setting for this account." }, + { "clear otr", "Remove the OTR policy setting for this account." }, + { "clear pgpkeyid", "Remove pgpkeyid associated with this account." }, + END_ARGS }, + { + "/account add me", + "/account set me jid me@chatty", + "/account set me server talk.chat.com", + "/account set me port 5111", + "/account set me muc chatservice.mycompany.com", + "/account set me nick dennis", + "/account set me status dnd", + "/account set me dnd -1", + "/account rename me gtalk", + NULL } } + }, { "/prefs", cmd_prefs, parse_args, 0, 1, NULL, - { "/prefs [ui|desktop|chat|log|conn|presence]", "Show configuration.", - { "/prefs [ui|desktop|chat|log|conn|presence]", - "------------------------------------------", - "Show preferences for different areas of functionality.", - "", - "ui : User interface preferences.", - "desktop : Desktop notification preferences.", - "chat : Chat state preferences.", - "log : Logging preferences.", - "conn : Connection handling preferences.", - "presence : Chat presence preferences.", - "", - "No argument shows all preferences.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/prefs [ui|desktop|chat|log|conn|presence]", + NULL + }, + "Show preferences for different areas of functionality. " + "Passing no arguments shows all preferences.", + { + { "ui", "User interface preferences." }, + { "desktop", "Desktop notification preferences." }, + { "chat", "Chat state preferences." }, + { "log", "Logging preferences." }, + { "conn", "Connection handling preferences." }, + { "presence", "Chat presence preferences." }, + END_ARGS }, + { + NULL } } + }, { "/theme", cmd_theme, parse_args, 1, 2, &cons_theme_setting, - { "/theme list|load|colours [theme-name]", "Change colour theme.", - { "/theme list|load|colours [theme-name]", - "-------------------------------------", - "Load a theme, includes colours and UI options.", - "", - "list : List all available themes.", - "load theme-name : Load the named theme. 'default' will reset to the default theme.", - "colours : Show the colour values as rendered by the terminal.", - "", - "Example: /theme list", - "Example: /theme load mycooltheme", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/theme list", + "/theme load ", + "/theme colours", + NULL + }, + "Load a theme, includes colours and UI options.", + { + { "list", "List all available themes." }, + { "load ", "Load the specified theme. 'default' will reset to the default theme." }, + { "colours", "Show the colour values as rendered by the terminal." }, + END_ARGS }, + { + "/theme list", + "/theme load forest", + NULL } } + }, { "/statuses", cmd_statuses, parse_args, 2, 2, &cons_statuses_setting, - { "/statuses console|chat|muc setting", "Set preferences for presence change messages.", - { "/statuses console|chat|muc setting", - "----------------------------------", - "Configure which presence changes are displayed in various windows.", - "", - "console : Configure what is displayed in the console window.", - "chat : Configure what is displayed in chat windows.", - "muc : Configure what is displayed in chat room windows.", - "", - "Available options are:", - "", - "all : Show all presence changes.", - "online : Show only online/offline changes.", - "none : Don't show any presence changes.", - "", - "The default is 'all' for all windows.", - "", - "Example: /statuses console none", - "Example: /statuses chat online", - "Example: /statuses muc all", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/statuses console|chat|muc all|online|none", + NULL + }, + "Configure which presence changes are displayed in various windows. " + "The default is 'all' for all windows.", + { + { "console", "Configure what is displayed in the console window." }, + { "chat", "Configure what is displayed in chat windows." }, + { "muc", "Configure what is displayed in chat room windows." }, + { "all", "Show all presence changes." }, + { "online", "Show only online/offline changes." }, + { "none", "Don't show any presence changes." }, + END_ARGS }, + { + "/statuses console none", + "/statuses chat online", + "/statuses muc all", + NULL } } + }, { "/xmlconsole", cmd_xmlconsole, parse_args, 0, 0, NULL, - { "/xmlconsole", "Open the XML console", - { "/xmlconsole", - "-----------", - "Open the XML console to view incoming and outgoing XMPP traffic.", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/xmlconsole", + NULL + }, + "Open the XML console to view incoming and outgoing XMPP traffic.", + { + END_ARGS }, + { + NULL } } + }, { "/away", cmd_away, parse_args_with_freetext, 0, 1, NULL, - { "/away [message]", "Set status to away.", - { "/away [message]", - "---------------", - "Set your status to 'away' with the optional message.", - "", - "Example: /away Gone for lunch", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/away []", + NULL + }, + "Set your status to 'away'.", + { + { "", "Optional message to use with the status." }, + END_ARGS }, + { + "/away", + "/away Gone for lunch", + NULL } } + }, { "/chat", cmd_chat, parse_args_with_freetext, 0, 1, NULL, - { "/chat [message]", "Set status to chat (available for chat).", - { "/chat [message]", - "---------------", - "Set your status to 'chat', meaning 'available for chat', with the optional message.", - "", - "Example: /chat Please talk to me!", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/chat []", + NULL + }, + "Set your status to 'chat' (available for chat).", + { + { "", "Optional message to use with the status." }, + END_ARGS }, + { + "/chat", + "/chat Please talk to me!", + NULL } } + }, { "/dnd", cmd_dnd, parse_args_with_freetext, 0, 1, NULL, - { "/dnd [message]", "Set status to dnd (do not disturb).", - { "/dnd [message]", - "--------------", - "Set your status to 'dnd', meaning 'do not disturb', with the optional message.", - "", - "Example: /dnd I'm in the zone", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/dnd []", + NULL + }, + "Set your status to 'dnd' (do not disturb).", + { + { "", "Optional message to use with the status." }, + END_ARGS }, + { + "/dnd", + "/dnd I'm in the zone", + NULL } } + }, { "/online", cmd_online, parse_args_with_freetext, 0, 1, NULL, - { "/online [message]", "Set status to online.", - { "/online [message]", - "-----------------", - "Set your status to 'online' with the optional message.", - "", - "Example: /online Up the Irons!", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/online []", + NULL + }, + "Set your status to 'online'.", + { + { "", "Optional message to use with the status." }, + END_ARGS }, + { + "/online", + "/online Up the Irons!", + NULL } } + }, { "/xa", cmd_xa, parse_args_with_freetext, 0, 1, NULL, - { "/xa [message]", "Set status to xa (extended away).", - { "/xa [message]", - "-------------", - "Set your status to 'xa', meaning 'extended away', with the optional message.", - "", - "Example: /xa This meeting is going to be a long one", - NULL, - NULL, NULL, NULL, NULL } } }, + { NULL, NULL, { NULL }, + { + "/xa []", + NULL + }, + "Set your status to 'xa' (extended away).", + { + { "", "Optional message to use with the status." }, + END_ARGS }, + { + "/xa", + "/xa This meeting is going to be a long one", + NULL } } + }, }; static Autocomplete commands_ac; From 36ebf0fc17f271e79445bfc320bef137bf3582bf Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 26 Jul 2015 01:27:42 +0100 Subject: [PATCH 11/25] Updated help category output --- src/command/command.c | 111 +++++++++++++++++------------------------ src/command/commands.c | 81 +++++++++++++++++++----------- src/ui/console.c | 4 +- 3 files changed, 100 insertions(+), 96 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index fe332f4b..72b4a07a 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -3702,80 +3702,60 @@ command_docgen(void) while (curr) { Command *pcmd = curr->data; + fprintf(toc_fragment, "%s,\n", &pcmd->cmd[1], pcmd->cmd); + fprintf(main_fragment, "\n", &pcmd->cmd[1]); + fprintf(main_fragment, "

%s

\n", pcmd->cmd); - // old style - if (pcmd->help.usage) { -// fprintf(toc_fragment, "%s,\n", &pcmd->cmd[1], pcmd->cmd); -// fprintf(main_fragment, "\n", &pcmd->cmd[1]); -// fprintf(main_fragment, "

%s

\n", pcmd->cmd); -// fputs("

Usage:

\n", main_fragment); -// fprintf(main_fragment, "

%s

\n", pcmd->help.usage); -// -// fputs("

Details:

\n", main_fragment); -// fputs("

", main_fragment);
-//            int i = 2;
-//            while (pcmd->help.long_help[i]) {
-//                fprintf(main_fragment, "%s\n", pcmd->help.long_help[i++]);
-//            }
-//            fputs("

\n
back to top


\n", main_fragment); -// fputs("\n", main_fragment); + fputs("

Synopsis

\n", main_fragment); + fputs("

", main_fragment);
+        int i = 0;
+        while (pcmd->help.synopsis[i]) {
+            char *str1 = str_replace(pcmd->help.synopsis[i], "<", "<");
+            char *str2 = str_replace(str1, ">", ">");
+            fprintf(main_fragment, "%s\n", str2);
+            i++;
+        }
+        fputs("

\n", main_fragment); - // new style - } else { - fprintf(toc_fragment, "%s,\n", &pcmd->cmd[1], pcmd->cmd); - fprintf(main_fragment, "\n", &pcmd->cmd[1]); - fprintf(main_fragment, "

%s

\n", pcmd->cmd); + fputs("

Description

\n", main_fragment); + fputs("

", main_fragment); + fprintf(main_fragment, "%s\n", pcmd->help.desc); + fputs("

\n", main_fragment); - fputs("

Synopsis

\n", main_fragment); + if (pcmd->help.args[0][0] != NULL) { + fputs("

Arguments

\n", main_fragment); + fputs("", main_fragment); + for (i = 0; pcmd->help.args[i][0] != NULL; i++) { + fputs("", main_fragment); + fputs("", main_fragment); + fputs("", main_fragment); + fputs("", main_fragment); + } + fputs("
", main_fragment); + fputs("", main_fragment); + char *str1 = str_replace(pcmd->help.args[i][0], "<", "<"); + char *str2 = str_replace(str1, ">", ">"); + fprintf(main_fragment, "%s", str2); + fputs("", main_fragment); + fputs("", main_fragment); + fprintf(main_fragment, "%s", pcmd->help.args[i][1]); + fputs("
\n", main_fragment); + } + + if (pcmd->help.examples[0] != NULL) { + fputs("

Examples

\n", main_fragment); fputs("

", main_fragment);
             int i = 0;
-            while (pcmd->help.synopsis[i]) {
-                char *str1 = str_replace(pcmd->help.synopsis[i], "<", "<");
-                char *str2 = str_replace(str1, ">", ">");
-                fprintf(main_fragment, "%s\n", str2);
+            while (pcmd->help.examples[i]) {
+                fprintf(main_fragment, "%s\n", pcmd->help.examples[i]);
                 i++;
             }
             fputs("

\n", main_fragment); - - fputs("

Description

\n", main_fragment); - fputs("

", main_fragment); - fprintf(main_fragment, "%s\n", pcmd->help.desc); - fputs("

\n", main_fragment); - - if (pcmd->help.args[0][0] != NULL) { - fputs("

Arguments

\n", main_fragment); - fputs("", main_fragment); - for (i = 0; pcmd->help.args[i][0] != NULL; i++) { - fputs("", main_fragment); - fputs("", main_fragment); - fputs("", main_fragment); - fputs("", main_fragment); - } - fputs("
", main_fragment); - fputs("", main_fragment); - char *str1 = str_replace(pcmd->help.args[i][0], "<", "<"); - char *str2 = str_replace(str1, ">", ">"); - fprintf(main_fragment, "%s", str2); - fputs("", main_fragment); - fputs("", main_fragment); - fprintf(main_fragment, "%s", pcmd->help.args[i][1]); - fputs("
\n", main_fragment); - } - - if (pcmd->help.examples[0] != NULL) { - fputs("

Examples

\n", main_fragment); - fputs("

", main_fragment);
-                int i = 0;
-                while (pcmd->help.examples[i]) {
-                    fprintf(main_fragment, "%s\n", pcmd->help.examples[i]);
-                    i++;
-                }
-                fputs("

\n", main_fragment); - } - - fputs("
back to top


\n", main_fragment); - fputs("\n", main_fragment); } + + fputs("
back to top


\n", main_fragment); + fputs("\n", main_fragment); + curr = g_list_next(curr); } @@ -3783,5 +3763,6 @@ command_docgen(void) fclose(toc_fragment); fclose(main_fragment); + printf("\nProcessed %d commands.\n\n", g_list_length(cmds)); g_list_free(cmds); } diff --git a/src/command/commands.c b/src/command/commands.c index b5babf3c..f8979aec 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -76,7 +76,6 @@ static void _update_presence(const resource_presence_t presence, static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, const char * const display, preference_t pref); static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size); -static gint _compare_commands(Command *a, Command *b); static void _who_room(ProfWin *window, gchar **args, struct cmd_help_t help); static void _who_roster(ProfWin *window, gchar **args, struct cmd_help_t help); @@ -779,8 +778,8 @@ cmd_help(ProfWin *window, gchar **args, struct cmd_help_t help) cons_help(); } else if (strcmp(args[0], "commands") == 0) { cons_show(""); - cons_show("All commands"); - cons_show(""); + ProfWin *console = wins_get_console(); + win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "All commands"); GList *ordered_commands = NULL; GHashTableIter iter; @@ -789,15 +788,36 @@ cmd_help(ProfWin *window, gchar **args, struct cmd_help_t help) g_hash_table_iter_init(&iter, commands); while (g_hash_table_iter_next(&iter, &key, &value)) { - ordered_commands = g_list_insert_sorted(ordered_commands, value, (GCompareFunc)_compare_commands); + Command *pcmd = (Command *)value; + ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0); } + int maxlen = 0; GList *curr = ordered_commands; while (curr) { - Command *cmd = curr->data; - cons_show("%-13s: %s", cmd->cmd, cmd->help.short_help); + gchar *cmd = curr->data; + int len = strlen(cmd); + if (len > maxlen) maxlen = len; curr = g_list_next(curr); } + + GString *cmds = g_string_new(""); + curr = ordered_commands; + int count = 0; + while (curr) { + gchar *cmd = curr->data; + if (count == 5) { + cons_show(cmds->str); + g_string_free(cmds, TRUE); + cmds = g_string_new(""); + count = 0; + } + g_string_append_printf(cmds, "%-*s", maxlen + 1, cmd); + curr = g_list_next(curr); + count++; + } + cons_show(cmds->str); + g_string_free(cmds, TRUE); g_list_free(ordered_commands); g_list_free(curr); @@ -4748,23 +4768,43 @@ _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size) { + ProfWin *console = wins_get_console(); cons_show(""); - cons_show("%s", heading); - cons_show(""); + win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", heading); GList *ordered_commands = NULL; int i; for (i = 0; i < filter_size; i++) { - Command *cmd = g_hash_table_lookup(commands, cmd_filter[i]); - ordered_commands = g_list_insert_sorted(ordered_commands, cmd, (GCompareFunc)_compare_commands); + Command *pcmd = g_hash_table_lookup(commands, cmd_filter[i]); + ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0); } + int maxlen = 0; GList *curr = ordered_commands; while (curr) { - Command *cmd = curr->data; - cons_show("%-12s: %s", cmd->cmd, cmd->help.short_help); + gchar *cmd = curr->data; + int len = strlen(cmd); + if (len > maxlen) maxlen = len; curr = g_list_next(curr); } + + GString *cmds = g_string_new(""); + curr = ordered_commands; + int count = 0; + while (curr) { + gchar *cmd = curr->data; + if (count == 5) { + cons_show(cmds->str); + g_string_free(cmds, TRUE); + cmds = g_string_new(""); + count = 0; + } + g_string_append_printf(cmds, "%-*s", maxlen + 1, cmd); + curr = g_list_next(curr); + count++; + } + cons_show(cmds->str); + g_string_free(cmds, TRUE); g_list_free(ordered_commands); g_list_free(curr); @@ -4772,20 +4812,3 @@ _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size) cons_show("Use /help [command] without the leading slash, for help on a specific command"); cons_show(""); } - -static -gint _compare_commands(Command *a, Command *b) -{ - const char * utf8_str_a = a->cmd; - const char * utf8_str_b = b->cmd; - - gchar *key_a = g_utf8_collate_key(utf8_str_a, -1); - gchar *key_b = g_utf8_collate_key(utf8_str_b, -1); - - gint result = g_strcmp0(key_a, key_b); - - g_free(key_a); - g_free(key_b); - - return result; -} diff --git a/src/ui/console.c b/src/ui/console.c index 20f6803e..67c1da58 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1533,9 +1533,9 @@ cons_help(void) void cons_navigation_help(void) { + ProfWin *console = wins_get_console(); cons_show(""); - cons_show("Navigation:"); - cons_show(""); + win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "Navigation"); cons_show("Alt-1..Alt-0, F1..F10 : Choose window."); cons_show("Alt-LEFT, Alt-RIGHT : Previous/next chat window"); cons_show("PAGEUP, PAGEDOWN : Page the main window."); From 34537e2fb190505a7cf28ac5ca272f831c4b3b2e Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 26 Jul 2015 02:05:53 +0100 Subject: [PATCH 12/25] Removed old command help --- src/command/command.c | 162 +++++++------- src/command/commands.c | 484 ++++++++++++++++++++--------------------- src/command/commands.h | 164 +++++++------- src/ui/console.c | 12 + src/ui/core.c | 15 +- src/ui/ui.h | 3 +- 6 files changed, 414 insertions(+), 426 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 72b4a07a..e5cda05c 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -116,7 +116,7 @@ static struct cmd_t command_defs[] = // NEW STYLE { "/help", cmd_help, parse_args, 0, 1, NULL, - { NULL, NULL, { NULL }, + { { "/help [|]", NULL @@ -135,7 +135,7 @@ static struct cmd_t command_defs[] = { "/about", cmd_about, parse_args, 0, 0, NULL, - { NULL, NULL, { NULL }, + { { "/about", NULL @@ -149,7 +149,7 @@ static struct cmd_t command_defs[] = { "/connect", cmd_connect, parse_args, 0, 5, NULL, - { NULL, NULL, { NULL }, + { { "/connect []", "/connect [server ] [port ]", @@ -174,7 +174,7 @@ static struct cmd_t command_defs[] = { "/disconnect", cmd_disconnect, parse_args, 0, 0, NULL, - { NULL, NULL, { NULL }, + { { "/disconnect", NULL @@ -188,7 +188,7 @@ static struct cmd_t command_defs[] = { "/msg", cmd_msg, parse_args_with_freetext, 1, 2, NULL, - { NULL, NULL, { NULL }, + { { "/msg []", "/msg []", @@ -213,7 +213,7 @@ static struct cmd_t command_defs[] = { "/roster", cmd_roster, parse_args_with_freetext, 0, 3, NULL, - { NULL, NULL, { NULL }, + { { "/roster", "/roster online", @@ -264,7 +264,7 @@ static struct cmd_t command_defs[] = { "/group", cmd_group, parse_args_with_freetext, 0, 3, NULL, - { NULL, NULL, { NULL }, + { { "/group", "/group show ", @@ -289,7 +289,7 @@ static struct cmd_t command_defs[] = { "/info", cmd_info, parse_args, 0, 1, NULL, - { NULL, NULL, { NULL }, + { { "/info", "/info |", @@ -310,7 +310,7 @@ static struct cmd_t command_defs[] = { "/caps", cmd_caps, parse_args, 0, 1, NULL, - { NULL, NULL, { NULL }, + { { "/caps", "/caps |", @@ -331,7 +331,7 @@ static struct cmd_t command_defs[] = { "/software", cmd_software, parse_args, 0, 1, NULL, - { NULL, NULL, { NULL }, + { { "/software", "/software |", @@ -353,7 +353,7 @@ static struct cmd_t command_defs[] = { "/status", cmd_status, parse_args, 0, 1, NULL, - { NULL, NULL, { NULL }, + { { "/status", "/status |", @@ -373,7 +373,7 @@ static struct cmd_t command_defs[] = { "/resource", cmd_resource, parse_args, 1, 2, &cons_resource_setting, - { NULL, NULL, { NULL }, + { { "/resource set ", "/resource off", @@ -394,7 +394,7 @@ static struct cmd_t command_defs[] = { "/join", cmd_join, parse_args, 0, 5, NULL, - { NULL, NULL, { NULL }, + { { "/join", "/join [nick ] [password ]", @@ -421,7 +421,7 @@ static struct cmd_t command_defs[] = { "/leave", cmd_leave, parse_args, 0, 0, NULL, - { NULL, NULL, { NULL }, + { { "/leave", NULL @@ -435,7 +435,7 @@ static struct cmd_t command_defs[] = { "/invite", cmd_invite, parse_args_with_freetext, 1, 2, NULL, - { NULL, NULL, { NULL }, + { { "/invite []", NULL @@ -451,7 +451,7 @@ static struct cmd_t command_defs[] = { "/invites", cmd_invites, parse_args_with_freetext, 0, 0, NULL, - { NULL, NULL, { NULL }, + { { "/invites", NULL @@ -465,7 +465,7 @@ static struct cmd_t command_defs[] = { "/decline", cmd_decline, parse_args_with_freetext, 1, 1, NULL, - { NULL, NULL, { NULL }, + { { "/decline ", NULL @@ -480,7 +480,7 @@ static struct cmd_t command_defs[] = { "/room", cmd_room, parse_args, 1, 1, NULL, - { NULL, NULL, { NULL }, + { { "/room accept|destroy|config", NULL @@ -497,7 +497,7 @@ static struct cmd_t command_defs[] = { "/kick", cmd_kick, parse_args_with_freetext, 1, 2, NULL, - { NULL, NULL, { NULL }, + { { "/kick []", NULL @@ -513,7 +513,7 @@ static struct cmd_t command_defs[] = { "/ban", cmd_ban, parse_args_with_freetext, 1, 2, NULL, - { NULL, NULL, { NULL }, + { { "/ban []", NULL @@ -529,7 +529,7 @@ static struct cmd_t command_defs[] = { "/subject", cmd_subject, parse_args_with_freetext, 0, 2, NULL, - { NULL, NULL, { NULL }, + { { "/subject set ", "/subject clear", @@ -546,7 +546,7 @@ static struct cmd_t command_defs[] = { "/affiliation", cmd_affiliation, parse_args_with_freetext, 1, 4, NULL, - { NULL, NULL, { NULL }, + { { "/affiliation set []", "/list []", @@ -564,7 +564,7 @@ static struct cmd_t command_defs[] = { "/role", cmd_role, parse_args_with_freetext, 1, 4, NULL, - { NULL, NULL, { NULL }, + { { "/role set []", "/list []", @@ -582,7 +582,7 @@ static struct cmd_t command_defs[] = { "/occupants", cmd_occupants, parse_args, 1, 3, cons_occupants_setting, - { NULL, NULL, { NULL }, + { { "/occupants show|hide [jid]", "/occupants default show|hide [jid]", @@ -605,7 +605,7 @@ static struct cmd_t command_defs[] = { "/form", cmd_form, parse_args, 1, 2, NULL, - { NULL, NULL, { NULL }, + { { "/form show", "/form submit", @@ -626,7 +626,7 @@ static struct cmd_t command_defs[] = { "/rooms", cmd_rooms, parse_args, 0, 1, NULL, - { NULL, NULL, { NULL }, + { { "/rooms []", NULL @@ -643,7 +643,7 @@ static struct cmd_t command_defs[] = { "/bookmark", cmd_bookmark, parse_args, 0, 8, NULL, - { NULL, NULL, { NULL }, + { { "/bookmark", "/bookmark list", @@ -671,7 +671,7 @@ static struct cmd_t command_defs[] = { "/disco", cmd_disco, parse_args, 1, 2, NULL, - { NULL, NULL, { NULL }, + { { "/disco info []", "/disco items []", @@ -693,7 +693,7 @@ static struct cmd_t command_defs[] = { "/nick", cmd_nick, parse_args_with_freetext, 1, 1, NULL, - { NULL, NULL, { NULL }, + { { "/nick ", NULL @@ -708,7 +708,7 @@ static struct cmd_t command_defs[] = { "/win", cmd_win, parse_args, 1, 1, NULL, - { NULL, NULL, { NULL }, + { { "/win ", NULL @@ -723,7 +723,7 @@ static struct cmd_t command_defs[] = { "/wins", cmd_wins, parse_args, 0, 3, NULL, - { NULL, NULL, { NULL }, + { { "/wins tidy", "/wins prune", @@ -743,7 +743,7 @@ static struct cmd_t command_defs[] = { "/sub", cmd_sub, parse_args, 1, 2, NULL, - { NULL, NULL, { NULL }, + { { "/sub request []", "/sub allow []", @@ -773,7 +773,7 @@ static struct cmd_t command_defs[] = { "/tiny", cmd_tiny, parse_args, 1, 1, NULL, - { NULL, NULL, { NULL }, + { { "/tiny ", NULL @@ -789,7 +789,7 @@ static struct cmd_t command_defs[] = { "/who", cmd_who, parse_args, 0, 2, NULL, - { NULL, NULL, { NULL }, + { { "/who", "/who online|offline|away|dnd|xa|chat|available|unavailable|any []", @@ -820,7 +820,7 @@ static struct cmd_t command_defs[] = { "/close", cmd_close, parse_args, 0, 1, NULL, - { NULL, NULL, { NULL }, + { { "/close []", "/close all|read", @@ -839,7 +839,7 @@ static struct cmd_t command_defs[] = { "/clear", cmd_clear, parse_args, 0, 0, NULL, - { NULL, NULL, { NULL }, + { { "/clear", NULL @@ -853,7 +853,7 @@ static struct cmd_t command_defs[] = { "/quit", cmd_quit, parse_args, 0, 0, NULL, - { NULL, NULL, { NULL }, + { { "/quit", NULL @@ -867,7 +867,7 @@ static struct cmd_t command_defs[] = { "/privileges", cmd_privileges, parse_args, 1, 1, &cons_privileges_setting, - { NULL, NULL, { NULL }, + { { "/privileges on|off", NULL @@ -882,7 +882,7 @@ static struct cmd_t command_defs[] = { "/beep", cmd_beep, parse_args, 1, 1, &cons_beep_setting, - { NULL, NULL, { NULL }, + { { "/beep on|off", NULL @@ -899,7 +899,7 @@ static struct cmd_t command_defs[] = { "/encwarn", cmd_encwarn, parse_args, 1, 1, &cons_encwarn_setting, - { NULL, NULL, { NULL }, + { { "/encwarn on|off", NULL @@ -914,7 +914,7 @@ static struct cmd_t command_defs[] = { "/presence", cmd_presence, parse_args, 1, 1, &cons_presence_setting, - { NULL, NULL, { NULL }, + { { "/presence on|off", NULL @@ -929,7 +929,7 @@ static struct cmd_t command_defs[] = { "/wrap", cmd_wrap, parse_args, 1, 1, &cons_wrap_setting, - { NULL, NULL, { NULL }, + { { "/wrap on|off", NULL @@ -944,7 +944,7 @@ static struct cmd_t command_defs[] = { "/winstidy", cmd_winstidy, parse_args, 1, 1, &cons_winstidy_setting, - { NULL, NULL, { NULL }, + { { "/winstidy on|off", NULL @@ -959,7 +959,7 @@ static struct cmd_t command_defs[] = { "/time", cmd_time, parse_args, 1, 3, &cons_time_setting, - { NULL, NULL, { NULL }, + { { "/time main set ", "/time main off", @@ -987,7 +987,7 @@ static struct cmd_t command_defs[] = { "/inpblock", cmd_inpblock, parse_args, 2, 2, &cons_inpblock_setting, - { NULL, NULL, { NULL }, + { { "/inpblock timeout ", "/inpblock dynamic on|off", @@ -1004,7 +1004,7 @@ static struct cmd_t command_defs[] = { "/notify", cmd_notify, parse_args, 2, 3, &cons_notify_setting, - { NULL, NULL, { NULL }, + { { "/notify message on|off", "/notify message current on|off", @@ -1047,7 +1047,7 @@ static struct cmd_t command_defs[] = { "/flash", cmd_flash, parse_args, 1, 1, &cons_flash_setting, - { NULL, NULL, { NULL }, + { { "/flash on|off", NULL @@ -1063,7 +1063,7 @@ static struct cmd_t command_defs[] = { "/intype", cmd_intype, parse_args, 1, 1, &cons_intype_setting, - { NULL, NULL, { NULL }, + { { "/intype on|off", NULL @@ -1079,7 +1079,7 @@ static struct cmd_t command_defs[] = { "/splash", cmd_splash, parse_args, 1, 1, &cons_splash_setting, - { NULL, NULL, { NULL }, + { { "/splash on|off", NULL @@ -1094,7 +1094,7 @@ static struct cmd_t command_defs[] = { "/autoconnect", cmd_autoconnect, parse_args, 1, 2, &cons_autoconnect_setting, - { NULL, NULL, { NULL }, + { { "/autoconnect set ", "/autoconnect off", @@ -1114,7 +1114,7 @@ static struct cmd_t command_defs[] = { "/vercheck", cmd_vercheck, parse_args, 0, 1, NULL, - { NULL, NULL, { NULL }, + { { "/vercheck on|off", NULL @@ -1129,7 +1129,7 @@ static struct cmd_t command_defs[] = { "/titlebar", cmd_titlebar, parse_args, 2, 2, &cons_titlebar_setting, - { NULL, NULL, { NULL }, + { { "/titlebar show on|off", "/titlebar goodbye on|off", @@ -1146,7 +1146,7 @@ static struct cmd_t command_defs[] = { "/alias", cmd_alias, parse_args_with_freetext, 1, 3, NULL, - { NULL, NULL, { NULL }, + { { "/alias list", "/alias add ", @@ -1170,7 +1170,7 @@ static struct cmd_t command_defs[] = { "/chlog", cmd_chlog, parse_args, 1, 1, &cons_chlog_setting, - { NULL, NULL, { NULL }, + { { "/chlog on|off", NULL @@ -1188,7 +1188,7 @@ static struct cmd_t command_defs[] = { "/grlog", cmd_grlog, parse_args, 1, 1, &cons_grlog_setting, - { NULL, NULL, { NULL }, + { { "/grlog on|off", NULL @@ -1204,7 +1204,7 @@ static struct cmd_t command_defs[] = { "/states", cmd_states, parse_args, 1, 1, &cons_states_setting, - { NULL, NULL, { NULL }, + { { "/states on|off", NULL @@ -1219,7 +1219,7 @@ static struct cmd_t command_defs[] = { "/pgp", cmd_pgp, parse_args, 1, 3, NULL, - { NULL, NULL, { NULL }, + { { "/pgp libver", "/pgp keys", @@ -1252,7 +1252,7 @@ static struct cmd_t command_defs[] = { "/otr", cmd_otr, parse_args, 1, 3, NULL, - { NULL, NULL, { NULL }, + { { "/otr libver", "/otr gen", @@ -1299,7 +1299,7 @@ static struct cmd_t command_defs[] = { "/outtype", cmd_outtype, parse_args, 1, 1, &cons_outtype_setting, - { NULL, NULL, { NULL }, + { { "/outtype on|off", NULL @@ -1314,7 +1314,7 @@ static struct cmd_t command_defs[] = { "/gone", cmd_gone, parse_args, 1, 1, &cons_gone_setting, - { NULL, NULL, { NULL }, + { { "/gone ", NULL @@ -1330,7 +1330,7 @@ static struct cmd_t command_defs[] = { "/history", cmd_history, parse_args, 1, 1, &cons_history_setting, - { NULL, NULL, { NULL }, + { { "/history on|off", NULL @@ -1346,7 +1346,7 @@ static struct cmd_t command_defs[] = { "/log", cmd_log, parse_args, 1, 2, &cons_log_setting, - { NULL, NULL, { NULL }, + { { "/log where", "/log rotate on|off", @@ -1367,7 +1367,7 @@ static struct cmd_t command_defs[] = { "/carbons", cmd_carbons, parse_args, 1, 1, &cons_carbons_setting, - { NULL, NULL, { NULL }, + { { "/carbons on|off", NULL @@ -1383,7 +1383,7 @@ static struct cmd_t command_defs[] = { "/receipts", cmd_receipts, parse_args, 2, 2, &cons_receipts_setting, - { NULL, NULL, { NULL }, + { { "/receipts request on|off", "/receipts send on|off", @@ -1400,7 +1400,7 @@ static struct cmd_t command_defs[] = { "/reconnect", cmd_reconnect, parse_args, 1, 1, &cons_reconnect_setting, - { NULL, NULL, { NULL }, + { { "/reconnect ", NULL @@ -1415,7 +1415,7 @@ static struct cmd_t command_defs[] = { "/autoping", cmd_autoping, parse_args, 1, 1, &cons_autoping_setting, - { NULL, NULL, { NULL }, + { { "/autoping ", NULL @@ -1430,7 +1430,7 @@ static struct cmd_t command_defs[] = { "/ping", cmd_ping, parse_args, 0, 1, NULL, - { NULL, NULL, { NULL }, + { { "/ping []", NULL @@ -1446,7 +1446,7 @@ static struct cmd_t command_defs[] = { "/autoaway", cmd_autoaway, parse_args_with_freetext, 2, 2, &cons_autoaway_setting, - { NULL, NULL, { NULL }, + { { "/autoaway mode idle|away|off", "/autoaway time ", @@ -1474,7 +1474,7 @@ static struct cmd_t command_defs[] = { "/priority", cmd_priority, parse_args, 1, 1, &cons_priority_setting, - { NULL, NULL, { NULL }, + { { "/priority ", NULL @@ -1490,7 +1490,7 @@ static struct cmd_t command_defs[] = { "/account", cmd_account, parse_args, 0, 4, NULL, - { NULL, NULL, { NULL }, + { { "/account", "/account list", @@ -1567,7 +1567,7 @@ static struct cmd_t command_defs[] = { "/prefs", cmd_prefs, parse_args, 0, 1, NULL, - { NULL, NULL, { NULL }, + { { "/prefs [ui|desktop|chat|log|conn|presence]", NULL @@ -1588,7 +1588,7 @@ static struct cmd_t command_defs[] = { "/theme", cmd_theme, parse_args, 1, 2, &cons_theme_setting, - { NULL, NULL, { NULL }, + { { "/theme list", "/theme load ", @@ -1609,7 +1609,7 @@ static struct cmd_t command_defs[] = { "/statuses", cmd_statuses, parse_args, 2, 2, &cons_statuses_setting, - { NULL, NULL, { NULL }, + { { "/statuses console|chat|muc all|online|none", NULL @@ -1633,7 +1633,7 @@ static struct cmd_t command_defs[] = { "/xmlconsole", cmd_xmlconsole, parse_args, 0, 0, NULL, - { NULL, NULL, { NULL }, + { { "/xmlconsole", NULL @@ -1647,7 +1647,7 @@ static struct cmd_t command_defs[] = { "/away", cmd_away, parse_args_with_freetext, 0, 1, NULL, - { NULL, NULL, { NULL }, + { { "/away []", NULL @@ -1664,7 +1664,7 @@ static struct cmd_t command_defs[] = { "/chat", cmd_chat, parse_args_with_freetext, 0, 1, NULL, - { NULL, NULL, { NULL }, + { { "/chat []", NULL @@ -1681,7 +1681,7 @@ static struct cmd_t command_defs[] = { "/dnd", cmd_dnd, parse_args_with_freetext, 0, 1, NULL, - { NULL, NULL, { NULL }, + { { "/dnd []", NULL @@ -1698,7 +1698,7 @@ static struct cmd_t command_defs[] = { "/online", cmd_online, parse_args_with_freetext, 0, 1, NULL, - { NULL, NULL, { NULL }, + { { "/online []", NULL @@ -1715,7 +1715,7 @@ static struct cmd_t command_defs[] = { "/xa", cmd_xa, parse_args_with_freetext, 0, 1, NULL, - { NULL, NULL, { NULL }, + { { "/xa []", NULL @@ -2502,10 +2502,10 @@ _cmd_execute(ProfWin *window, const char * const command, const char * const inp if (cmd) { gchar **args = cmd->parser(inp, cmd->min_args, cmd->max_args, &result); if (result == FALSE) { - ui_invalid_command_usage(cmd->help.usage, cmd->setting_func); + ui_invalid_command_usage(cmd->cmd, cmd->setting_func); return TRUE; } else { - gboolean result = cmd->func(window, args, cmd->help); + gboolean result = cmd->func(window, args, command); g_strfreev(args); return result; } diff --git a/src/command/commands.c b/src/command/commands.c index f8979aec..6f12f502 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -73,11 +73,11 @@ static void _update_presence(const resource_presence_t presence, const char * const show, gchar **args); -static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, +static gboolean _cmd_set_boolean_preference(gchar *arg, const char * const command, const char * const display, preference_t pref); static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size); -static void _who_room(ProfWin *window, gchar **args, struct cmd_help_t help); -static void _who_roster(ProfWin *window, gchar **args, struct cmd_help_t help); +static void _who_room(ProfWin *window, gchar **args, const char * const command); +static void _who_roster(ProfWin *window, gchar **args, const char * const command); extern GHashTable *commands; @@ -157,7 +157,7 @@ cmd_execute_alias(ProfWin *window, const char * const inp, gboolean *ran) } gboolean -cmd_connect(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_connect(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); if ((conn_status != JABBER_DISCONNECTED) && (conn_status != JABBER_STARTED)) { @@ -170,7 +170,7 @@ cmd_connect(ProfWin *window, gchar **args, struct cmd_help_t help) GHashTable *options = parse_options(&args[args[0] ? 1 : 0], opt_keys, &parsed); if (!parsed) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); cons_show(""); return TRUE; } @@ -261,26 +261,26 @@ cmd_connect(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_account(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_account(ProfWin *window, gchar **args, const char * const command) { - char *command = args[0]; + char *subcmd = args[0]; - if (command == NULL) { + if (subcmd == NULL) { if (jabber_get_connection_status() != JABBER_CONNECTED) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } else { ProfAccount *account = accounts_get_account(jabber_get_account_name()); cons_show_account(account); account_free(account); } - } else if (strcmp(command, "list") == 0) { + } else if (strcmp(subcmd, "list") == 0) { gchar **accounts = accounts_get_list(); cons_show_account_list(accounts); g_strfreev(accounts); - } else if (strcmp(command, "show") == 0) { + } else if (strcmp(subcmd, "show") == 0) { char *account_name = args[1]; if (account_name == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } else { ProfAccount *account = accounts_get_account(account_name); if (account == NULL) { @@ -291,19 +291,19 @@ cmd_account(ProfWin *window, gchar **args, struct cmd_help_t help) account_free(account); } } - } else if (strcmp(command, "add") == 0) { + } else if (strcmp(subcmd, "add") == 0) { char *account_name = args[1]; if (account_name == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } else { accounts_add(account_name, NULL, 0); cons_show("Account created."); cons_show(""); } - } else if (strcmp(command, "remove") == 0) { + } else if (strcmp(subcmd, "remove") == 0) { char *account_name = args[1]; if(!account_name) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } else { char *def = prefs_get_string(PREF_DEFAULT_ACCOUNT); if(accounts_remove(account_name)){ @@ -319,10 +319,10 @@ cmd_account(ProfWin *window, gchar **args, struct cmd_help_t help) cons_show(""); g_free(def); } - } else if (strcmp(command, "enable") == 0) { + } else if (strcmp(subcmd, "enable") == 0) { char *account_name = args[1]; if (account_name == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } else { if (accounts_enable(account_name)) { cons_show("Account enabled."); @@ -332,10 +332,10 @@ cmd_account(ProfWin *window, gchar **args, struct cmd_help_t help) cons_show(""); } } - } else if (strcmp(command, "disable") == 0) { + } else if (strcmp(subcmd, "disable") == 0) { char *account_name = args[1]; if (account_name == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } else { if (accounts_disable(account_name)) { cons_show("Account disabled."); @@ -345,9 +345,9 @@ cmd_account(ProfWin *window, gchar **args, struct cmd_help_t help) cons_show(""); } } - } else if (strcmp(command, "rename") == 0) { + } else if (strcmp(subcmd, "rename") == 0) { if (g_strv_length(args) != 3) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } else { char *account_name = args[1]; char *new_name = args[2]; @@ -360,7 +360,7 @@ cmd_account(ProfWin *window, gchar **args, struct cmd_help_t help) cons_show(""); } } - } else if (strcmp(command, "default") == 0) { + } else if (strcmp(subcmd, "default") == 0) { if(g_strv_length(args) == 1){ char *def = prefs_get_string(PREF_DEFAULT_ACCOUNT); @@ -375,7 +375,7 @@ cmd_account(ProfWin *window, gchar **args, struct cmd_help_t help) prefs_set_string(PREF_DEFAULT_ACCOUNT, NULL); cons_show("Removed default account."); } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } } else if(g_strv_length(args) == 3) { if(strcmp(args[1], "set") == 0){ @@ -386,14 +386,14 @@ cmd_account(ProfWin *window, gchar **args, struct cmd_help_t help) cons_show("Account %s does not exist.", args[2]); } } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } - } else if (strcmp(command, "set") == 0) { + } else if (strcmp(subcmd, "set") == 0) { if (g_strv_length(args) != 4) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } else { char *account_name = args[1]; char *property = args[2]; @@ -536,9 +536,9 @@ cmd_account(ProfWin *window, gchar **args, struct cmd_help_t help) } } } - } else if (strcmp(command, "clear") == 0) { + } else if (strcmp(subcmd, "clear") == 0) { if (g_strv_length(args) != 3) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } else { char *account_name = args[1]; char *property = args[2]; @@ -578,6 +578,7 @@ cmd_account(ProfWin *window, gchar **args, struct cmd_help_t help) } } } else { + cons_bad_cmd_usage(command); cons_show(""); } @@ -585,7 +586,7 @@ cmd_account(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_sub(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_sub(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -599,7 +600,7 @@ cmd_sub(ProfWin *window, gchar **args, struct cmd_help_t help) jid = args[1]; if (subcmd == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -666,7 +667,7 @@ cmd_sub(ProfWin *window, gchar **args, struct cmd_help_t help) } } } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } jid_destroy(jidp); @@ -675,7 +676,7 @@ cmd_sub(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_disconnect(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_disconnect(ProfWin *window, gchar **args, const char * const command) { if (jabber_get_connection_status() == JABBER_CONNECTED) { char *jid = strdup(jabber_get_fulljid()); @@ -697,7 +698,7 @@ cmd_disconnect(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_quit(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_quit(ProfWin *window, gchar **args, const char * const command) { log_info("Profanity is shutting down..."); exit(0); @@ -705,7 +706,7 @@ cmd_quit(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_wins(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_wins(ProfWin *window, gchar **args, const char * const command) { if (args[0] == NULL) { cons_show_wins(); @@ -719,7 +720,7 @@ cmd_wins(ProfWin *window, gchar **args, struct cmd_help_t help) ui_prune_wins(); } else if (strcmp(args[0], "swap") == 0) { if ((args[1] == NULL) || (args[2] == NULL)) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } else { int source_win = atoi(args[1]); int target_win = atoi(args[2]); @@ -744,9 +745,9 @@ cmd_wins(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_winstidy(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_winstidy(ProfWin *window, gchar **args, const char * const command) { - gboolean result = _cmd_set_boolean_preference(args[0], help, "Wins Auto Tidy", PREF_WINS_AUTO_TIDY); + gboolean result = _cmd_set_boolean_preference(args[0], command, "Wins Auto Tidy", PREF_WINS_AUTO_TIDY); if (result && g_strcmp0(args[0], "on") == 0) { ui_tidy_wins(); @@ -756,7 +757,7 @@ cmd_winstidy(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_win(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_win(ProfWin *window, gchar **args, const char * const command) { int num = atoi(args[0]); @@ -771,7 +772,7 @@ cmd_win(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_help(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_help(ProfWin *window, gchar **args, const char * const command) { int num_args = g_strv_length(args); if (num_args == 0) { @@ -874,17 +875,7 @@ cmd_help(ProfWin *window, gchar **args, struct cmd_help_t help) Command *command = g_hash_table_lookup(commands, cmd_with_slash); if (command) { - // old - if (command->help.usage) { - const gchar **help_text = command->help.long_help; - ProfWin *console = wins_get_console(); - cons_show(""); - ui_show_lines(console, help_text); - - // new - } else { - cons_show_help(command); - } + cons_show_help(command); } else { cons_show("No such command."); } @@ -895,14 +886,14 @@ cmd_help(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_about(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_about(ProfWin *window, gchar **args, const char * const command) { ui_about(); return TRUE; } gboolean -cmd_prefs(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_prefs(ProfWin *window, gchar **args, const char * const command) { if (args[0] == NULL) { cons_prefs(); @@ -940,14 +931,14 @@ cmd_prefs(ProfWin *window, gchar **args, struct cmd_help_t help) cons_show_pgp_prefs(); cons_show(""); } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } return TRUE; } gboolean -cmd_theme(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_theme(ProfWin *window, gchar **args, const char * const command) { // list themes if (g_strcmp0(args[0], "list") == 0) { @@ -958,7 +949,7 @@ cmd_theme(ProfWin *window, gchar **args, struct cmd_help_t help) // load a theme } else if (g_strcmp0(args[0], "load") == 0) { if (args[1] == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } else if (theme_load(args[1])) { ui_load_colours(); prefs_set_string(PREF_THEME, args[1]); @@ -982,14 +973,14 @@ cmd_theme(ProfWin *window, gchar **args, struct cmd_help_t help) } else if (g_strcmp0(args[0], "colours") == 0) { cons_theme_colours(); } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } return TRUE; } static void -_who_room(ProfWin *window, gchar **args, struct cmd_help_t help) +_who_room(ProfWin *window, gchar **args, const char * const command) { if ((g_strv_length(args) == 2) && args[1]) { cons_show("Argument group is not applicable to chat rooms."); @@ -1013,7 +1004,7 @@ _who_room(ProfWin *window, gchar **args, struct cmd_help_t help) (g_strcmp0(args[0], "admin") != 0) && (g_strcmp0(args[0], "member") != 0) && (g_strcmp0(args[0], "outcast") != 0)) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return; } @@ -1119,7 +1110,7 @@ _who_room(ProfWin *window, gchar **args, struct cmd_help_t help) } static void -_who_roster(ProfWin *window, gchar **args, struct cmd_help_t help) +_who_roster(ProfWin *window, gchar **args, const char * const command) { char *presence = args[0]; @@ -1134,7 +1125,7 @@ _who_roster(ProfWin *window, gchar **args, struct cmd_help_t help) && (strcmp(presence, "xa") != 0) && (strcmp(presence, "dnd") != 0) && (strcmp(presence, "any") != 0)) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return; } @@ -1332,16 +1323,16 @@ _who_roster(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_who(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_who(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); } else if (window->type == WIN_MUC) { - _who_room(window, args, help); + _who_room(window, args, command); } else { - _who_roster(window, args, help); + _who_roster(window, args, command); } if (window->type != WIN_CONSOLE && window->type != WIN_MUC) { @@ -1352,7 +1343,7 @@ cmd_who(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_msg(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_msg(ProfWin *window, gchar **args, const char * const command) { char *usr = args[0]; char *msg = args[1]; @@ -1419,7 +1410,7 @@ cmd_msg(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_group(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_group(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -1450,7 +1441,7 @@ cmd_group(ProfWin *window, gchar **args, struct cmd_help_t help) if (strcmp(args[0], "show") == 0) { char *group = args[1]; if (group == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -1465,7 +1456,7 @@ cmd_group(ProfWin *window, gchar **args, struct cmd_help_t help) char *contact = args[2]; if ((group == NULL) || (contact == NULL)) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -1496,7 +1487,7 @@ cmd_group(ProfWin *window, gchar **args, struct cmd_help_t help) char *contact = args[2]; if ((group == NULL) || (contact == NULL)) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -1521,12 +1512,12 @@ cmd_group(ProfWin *window, gchar **args, struct cmd_help_t help) return TRUE; } - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } gboolean -cmd_roster(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_roster(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -1557,7 +1548,7 @@ cmd_roster(ProfWin *window, gchar **args, struct cmd_help_t help) // set roster size } else if (g_strcmp0(args[0], "size") == 0) { if (!args[1]) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } int intval = 0; @@ -1607,7 +1598,7 @@ cmd_roster(ProfWin *window, gchar **args, struct cmd_help_t help) } return TRUE; } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } } else if (g_strcmp0(args[0], "hide") == 0) { @@ -1640,7 +1631,7 @@ cmd_roster(ProfWin *window, gchar **args, struct cmd_help_t help) } return TRUE; } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } // roster grouping @@ -1667,7 +1658,7 @@ cmd_roster(ProfWin *window, gchar **args, struct cmd_help_t help) } return TRUE; } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } // add contact @@ -1678,7 +1669,7 @@ cmd_roster(ProfWin *window, gchar **args, struct cmd_help_t help) } char *jid = args[1]; if (jid == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } else { char *name = args[2]; roster_send_add_new(jid, name); @@ -1693,7 +1684,7 @@ cmd_roster(ProfWin *window, gchar **args, struct cmd_help_t help) } char *jid = args[1]; if (jid == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } else { roster_send_remove(jid); } @@ -1701,7 +1692,7 @@ cmd_roster(ProfWin *window, gchar **args, struct cmd_help_t help) } else if (strcmp(args[0], "remove_all") == 0) { if (g_strcmp0(args[1], "contacts") != 0) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } if (conn_status != JABBER_CONNECTED) { @@ -1728,13 +1719,13 @@ cmd_roster(ProfWin *window, gchar **args, struct cmd_help_t help) } char *jid = args[1]; if (jid == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } char *name = args[2]; if (name == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -1762,7 +1753,7 @@ cmd_roster(ProfWin *window, gchar **args, struct cmd_help_t help) } char *jid = args[1]; if (jid == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -1782,31 +1773,31 @@ cmd_roster(ProfWin *window, gchar **args, struct cmd_help_t help) return TRUE; } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } } gboolean -cmd_resource(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_resource(ProfWin *window, gchar **args, const char * const command) { char *cmd = args[0]; char *setting = NULL; if (g_strcmp0(cmd, "message") == 0) { setting = args[1]; if (!setting) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } else { - return _cmd_set_boolean_preference(setting, help, "Message resource", PREF_RESOURCE_MESSAGE); + return _cmd_set_boolean_preference(setting, command, "Message resource", PREF_RESOURCE_MESSAGE); } } else if (g_strcmp0(cmd, "title") == 0) { setting = args[1]; if (!setting) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } else { - return _cmd_set_boolean_preference(setting, help, "Title resource", PREF_RESOURCE_TITLE); + return _cmd_set_boolean_preference(setting, command, "Title resource", PREF_RESOURCE_TITLE); } } @@ -1819,7 +1810,7 @@ cmd_resource(ProfWin *window, gchar **args, struct cmd_help_t help) if (g_strcmp0(cmd, "set") == 0) { char *resource = args[1]; if (!resource) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -1854,13 +1845,13 @@ cmd_resource(ProfWin *window, gchar **args, struct cmd_help_t help) chat_session_remove(chatwin->barejid); return TRUE; } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } } gboolean -cmd_status(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_status(ProfWin *window, gchar **args, const char * const command) { char *usr = args[0]; @@ -1925,7 +1916,7 @@ cmd_status(ProfWin *window, gchar **args, struct cmd_help_t help) } cons_show_status(usr_jid); } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } break; default: @@ -1936,7 +1927,7 @@ cmd_status(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_info(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_info(ProfWin *window, gchar **args, const char * const command) { char *usr = args[0]; @@ -2011,7 +2002,7 @@ cmd_info(ProfWin *window, gchar **args, struct cmd_help_t help) cons_show("No such contact \"%s\" in roster.", usr); } } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } break; default: @@ -2022,7 +2013,7 @@ cmd_info(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_caps(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_caps(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); PContact pcontact = NULL; @@ -2099,7 +2090,7 @@ cmd_caps(ProfWin *window, gchar **args, struct cmd_help_t help) gboolean -cmd_software(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_software(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); Occupant *occupant = NULL; @@ -2163,7 +2154,7 @@ cmd_software(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_join(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_join(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); if (conn_status != JABBER_CONNECTED) { @@ -2225,7 +2216,7 @@ cmd_join(ProfWin *window, gchar **args, struct cmd_help_t help) GHashTable *options = parse_options(&args[1], opt_keys, &parsed); if (!parsed) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); cons_show(""); jid_destroy(room_arg); return TRUE; @@ -2261,7 +2252,7 @@ cmd_join(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_invite(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_invite(ProfWin *window, gchar **args, const char * const command) { char *contact = args[0]; char *reason = args[1]; @@ -2297,7 +2288,7 @@ cmd_invite(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_invites(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_invites(ProfWin *window, gchar **args, const char * const command) { GSList *invites = muc_invites(); cons_show_room_invites(invites); @@ -2306,7 +2297,7 @@ cmd_invites(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_decline(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_decline(ProfWin *window, gchar **args, const char * const command) { if (!muc_invites_contain(args[0])) { cons_show("No such invite exists."); @@ -2537,7 +2528,7 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args) } gboolean -cmd_form(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_form(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2555,7 +2546,7 @@ cmd_form(ProfWin *window, gchar **args, struct cmd_help_t help) (g_strcmp0(args[0], "cancel") != 0) && (g_strcmp0(args[0], "show") != 0) && (g_strcmp0(args[0], "help") != 0)) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -2578,7 +2569,7 @@ cmd_form(ProfWin *window, gchar **args, struct cmd_help_t help) Command *command = g_hash_table_lookup(commands, "/form"); if (command) { - help_text = command->help.long_help; + help_text = command->help.synopsis; } ui_show_lines((ProfWin*) confwin, help_text); @@ -2611,7 +2602,7 @@ cmd_form(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_kick(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_kick(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2637,14 +2628,14 @@ cmd_kick(ProfWin *window, gchar **args, struct cmd_help_t help) win_vprint((ProfWin*) mucwin, '!', NULL, 0, 0, "", "Occupant does not exist: %s", nick); } } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } return TRUE; } gboolean -cmd_ban(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_ban(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2666,13 +2657,13 @@ cmd_ban(ProfWin *window, gchar **args, struct cmd_help_t help) char *reason = args[1]; iq_room_affiliation_set(mucwin->roomjid, jid, "outcast", reason); } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } return TRUE; } gboolean -cmd_subject(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_subject(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2704,7 +2695,7 @@ cmd_subject(ProfWin *window, gchar **args, struct cmd_help_t help) if (args[1]) { message_send_groupchat_subject(mucwin->roomjid, args[1]); } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } return TRUE; } @@ -2714,12 +2705,12 @@ cmd_subject(ProfWin *window, gchar **args, struct cmd_help_t help) return TRUE; } - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } gboolean -cmd_affiliation(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_affiliation(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2735,7 +2726,7 @@ cmd_affiliation(ProfWin *window, gchar **args, struct cmd_help_t help) char *cmd = args[0]; if (cmd == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -2746,7 +2737,7 @@ cmd_affiliation(ProfWin *window, gchar **args, struct cmd_help_t help) (g_strcmp0(affiliation, "member") != 0) && (g_strcmp0(affiliation, "none") != 0) && (g_strcmp0(affiliation, "outcast") != 0)) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -2769,13 +2760,13 @@ cmd_affiliation(ProfWin *window, gchar **args, struct cmd_help_t help) if (g_strcmp0(cmd, "set") == 0) { if (!affiliation) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } char *jid = args[2]; if (jid == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } else { char *reason = args[3]; @@ -2784,12 +2775,12 @@ cmd_affiliation(ProfWin *window, gchar **args, struct cmd_help_t help) } } - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } gboolean -cmd_role(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_role(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2805,7 +2796,7 @@ cmd_role(ProfWin *window, gchar **args, struct cmd_help_t help) char *cmd = args[0]; if (cmd == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -2815,7 +2806,7 @@ cmd_role(ProfWin *window, gchar **args, struct cmd_help_t help) (g_strcmp0(role, "participant") != 0) && (g_strcmp0(role, "moderator") != 0) && (g_strcmp0(role, "none") != 0)) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -2837,13 +2828,13 @@ cmd_role(ProfWin *window, gchar **args, struct cmd_help_t help) if (g_strcmp0(cmd, "set") == 0) { if (!role) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } char *nick = args[2]; if (nick == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } else { char *reason = args[3]; @@ -2852,12 +2843,12 @@ cmd_role(ProfWin *window, gchar **args, struct cmd_help_t help) } } - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } gboolean -cmd_room(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_room(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2874,7 +2865,7 @@ cmd_room(ProfWin *window, gchar **args, struct cmd_help_t help) if ((g_strcmp0(args[0], "accept") != 0) && (g_strcmp0(args[0], "destroy") != 0) && (g_strcmp0(args[0], "config") != 0)) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -2920,7 +2911,7 @@ cmd_room(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_occupants(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_occupants(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2931,7 +2922,7 @@ cmd_occupants(ProfWin *window, gchar **args, struct cmd_help_t help) if (g_strcmp0(args[0], "size") == 0) { if (!args[1]) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } else { int intval = 0; @@ -2970,7 +2961,7 @@ cmd_occupants(ProfWin *window, gchar **args, struct cmd_help_t help) } return TRUE; } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } } @@ -2998,14 +2989,14 @@ cmd_occupants(ProfWin *window, gchar **args, struct cmd_help_t help) ui_room_hide_occupants(mucwin->roomjid); } } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } return TRUE; } gboolean -cmd_rooms(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_rooms(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -3026,7 +3017,7 @@ cmd_rooms(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_bookmark(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_bookmark(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -3052,7 +3043,7 @@ cmd_bookmark(ProfWin *window, gchar **args, struct cmd_help_t help) } else { if (cmd == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -3062,7 +3053,7 @@ cmd_bookmark(ProfWin *window, gchar **args, struct cmd_help_t help) } else { char *jid = args[1]; if (jid == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); cons_show(""); return TRUE; } @@ -3090,7 +3081,7 @@ cmd_bookmark(ProfWin *window, gchar **args, struct cmd_help_t help) GHashTable *options = parse_options(&args[2], opt_keys, &parsed); if (!parsed) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); cons_show(""); return TRUE; } @@ -3101,7 +3092,7 @@ cmd_bookmark(ProfWin *window, gchar **args, struct cmd_help_t help) if (autojoin) { if ((strcmp(autojoin, "on") != 0) && (strcmp(autojoin, "off") != 0)) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); cons_show(""); return TRUE; } @@ -3126,7 +3117,7 @@ cmd_bookmark(ProfWin *window, gchar **args, struct cmd_help_t help) cons_show("No bookmark exists for %s.", jid); } } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } options_destroy(options); @@ -3137,7 +3128,7 @@ cmd_bookmark(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_disco(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_disco(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -3167,7 +3158,7 @@ cmd_disco(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_nick(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_nick(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -3189,14 +3180,14 @@ cmd_nick(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_alias(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_alias(ProfWin *window, gchar **args, const char * const command) { char *subcmd = args[0]; if (strcmp(subcmd, "add") == 0) { char *alias = args[1]; if (alias == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } else { char *alias_p = alias; @@ -3211,7 +3202,7 @@ cmd_alias(ProfWin *window, gchar **args, struct cmd_help_t help) char *value = args[2]; if (value == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); g_string_free(ac_value, TRUE); return TRUE; } else if (cmd_exists(ac_value->str)) { @@ -3230,7 +3221,7 @@ cmd_alias(ProfWin *window, gchar **args, struct cmd_help_t help) } else if (strcmp(subcmd, "remove") == 0) { char *alias = args[1]; if (alias == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } else { if (alias[0] == '/') { @@ -3255,13 +3246,13 @@ cmd_alias(ProfWin *window, gchar **args, struct cmd_help_t help) prefs_free_aliases(aliases); return TRUE; } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } } gboolean -cmd_tiny(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_tiny(ProfWin *window, gchar **args, const char * const command) { char *url = args[0]; @@ -3313,14 +3304,14 @@ cmd_tiny(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_clear(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_clear(ProfWin *window, gchar **args, const char * const command) { ui_clear_win(window); return TRUE; } gboolean -cmd_close(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_close(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); int index = 0; @@ -3392,7 +3383,7 @@ cmd_close(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_leave(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_leave(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); int index = wins_get_current_num(); @@ -3415,9 +3406,9 @@ cmd_leave(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_privileges(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_privileges(ProfWin *window, gchar **args, const char * const command) { - gboolean result = _cmd_set_boolean_preference(args[0], help, "MUC privileges", PREF_MUC_PRIVILEGES); + gboolean result = _cmd_set_boolean_preference(args[0], command, "MUC privileges", PREF_MUC_PRIVILEGES); ui_redraw_all_room_rosters(); @@ -3425,21 +3416,21 @@ cmd_privileges(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_beep(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_beep(ProfWin *window, gchar **args, const char * const command) { - return _cmd_set_boolean_preference(args[0], help, "Sound", PREF_BEEP); + return _cmd_set_boolean_preference(args[0], command, "Sound", PREF_BEEP); } gboolean -cmd_presence(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_presence(ProfWin *window, gchar **args, const char * const command) { - return _cmd_set_boolean_preference(args[0], help, "Contact presence", PREF_PRESENCE); + return _cmd_set_boolean_preference(args[0], command, "Contact presence", PREF_PRESENCE); } gboolean -cmd_wrap(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_wrap(ProfWin *window, gchar **args, const char * const command) { - gboolean result = _cmd_set_boolean_preference(args[0], help, "Word wrap", PREF_WRAP); + gboolean result = _cmd_set_boolean_preference(args[0], command, "Word wrap", PREF_WRAP); wins_resize_all(); @@ -3447,7 +3438,7 @@ cmd_wrap(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_time(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_time(ProfWin *window, gchar **args, const char * const command) { if (g_strcmp0(args[0], "statusbar") == 0) { if (args[1] == NULL) { @@ -3464,7 +3455,7 @@ cmd_time(ProfWin *window, gchar **args, struct cmd_help_t help) ui_redraw(); return TRUE; } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } } else if (g_strcmp0(args[0], "main") == 0) { @@ -3482,19 +3473,19 @@ cmd_time(ProfWin *window, gchar **args, struct cmd_help_t help) wins_resize_all(); return TRUE; } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } } gboolean -cmd_states(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_states(ProfWin *window, gchar **args, const char * const command) { - gboolean result = _cmd_set_boolean_preference(args[0], help, "Sending chat states", + gboolean result = _cmd_set_boolean_preference(args[0], command, "Sending chat states", PREF_STATES); // if disabled, disable outtype and gone @@ -3507,26 +3498,26 @@ cmd_states(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_titlebar(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_titlebar(ProfWin *window, gchar **args, const char * const command) { if (g_strcmp0(args[0], "show") != 0 && g_strcmp0(args[0], "goodbye") != 0) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } if (g_strcmp0(args[0], "show") == 0 && g_strcmp0(args[1], "off") == 0) { ui_clear_win_title(); } if (g_strcmp0(args[0], "show") == 0) { - return _cmd_set_boolean_preference(args[1], help, "Titlebar show", PREF_TITLEBAR_SHOW); + return _cmd_set_boolean_preference(args[1], command, "Titlebar show", PREF_TITLEBAR_SHOW); } else { - return _cmd_set_boolean_preference(args[1], help, "Titlebar goodbye", PREF_TITLEBAR_GOODBYE); + return _cmd_set_boolean_preference(args[1], command, "Titlebar goodbye", PREF_TITLEBAR_GOODBYE); } } gboolean -cmd_outtype(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_outtype(ProfWin *window, gchar **args, const char * const command) { - gboolean result = _cmd_set_boolean_preference(args[0], help, + gboolean result = _cmd_set_boolean_preference(args[0], command, "Sending typing notifications", PREF_OUTTYPE); // if enabled, enable states @@ -3538,7 +3529,7 @@ cmd_outtype(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_gone(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_gone(ProfWin *window, gchar **args, const char * const command) { char *value = args[0]; @@ -3562,7 +3553,7 @@ cmd_gone(ProfWin *window, gchar **args, struct cmd_help_t help) gboolean -cmd_notify(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_notify(ProfWin *window, gchar **args, const char * const command) { char *kind = args[0]; @@ -3570,7 +3561,7 @@ cmd_notify(ProfWin *window, gchar **args, struct cmd_help_t help) if ((strcmp(kind, "message") != 0) && (strcmp(kind, "typing") != 0) && (strcmp(kind, "remind") != 0) && (strcmp(kind, "invite") != 0) && (strcmp(kind, "sub") != 0) && (strcmp(kind, "room") != 0)) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); // set message setting } else if (strcmp(kind, "message") == 0) { @@ -3705,14 +3696,14 @@ cmd_notify(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_inpblock(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_inpblock(ProfWin *window, gchar **args, const char * const command) { char *subcmd = args[0]; char *value = args[1]; if (g_strcmp0(subcmd, "timeout") == 0) { if (value == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -3733,7 +3724,7 @@ cmd_inpblock(ProfWin *window, gchar **args, struct cmd_help_t help) if (g_strcmp0(subcmd, "dynamic") == 0) { if (value == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -3742,23 +3733,23 @@ cmd_inpblock(ProfWin *window, gchar **args, struct cmd_help_t help) return TRUE; } - return _cmd_set_boolean_preference(value, help, "Dynamic input blocking", PREF_INPBLOCK_DYNAMIC); + return _cmd_set_boolean_preference(value, command, "Dynamic input blocking", PREF_INPBLOCK_DYNAMIC); } - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } gboolean -cmd_log(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_log(ProfWin *window, gchar **args, const char * const command) { char *subcmd = args[0]; char *value = args[1]; if (strcmp(subcmd, "maxsize") == 0) { if (value == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -3777,18 +3768,18 @@ cmd_log(ProfWin *window, gchar **args, struct cmd_help_t help) if (strcmp(subcmd, "rotate") == 0) { if (value == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } - return _cmd_set_boolean_preference(value, help, "Log rotate", PREF_LOG_ROTATE); + return _cmd_set_boolean_preference(value, command, "Log rotate", PREF_LOG_ROTATE); } if (strcmp(subcmd, "shared") == 0) { if (value == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } - gboolean result = _cmd_set_boolean_preference(value, help, "Shared log", PREF_LOG_SHARED); + gboolean result = _cmd_set_boolean_preference(value, command, "Shared log", PREF_LOG_SHARED); log_reinit(); return result; } @@ -3799,7 +3790,7 @@ cmd_log(ProfWin *window, gchar **args, struct cmd_help_t help) return TRUE; } - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); /* TODO: make 'level' subcommand for debug level */ @@ -3807,7 +3798,7 @@ cmd_log(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_reconnect(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_reconnect(ProfWin *window, gchar **args, const char * const command) { char *value = args[0]; @@ -3823,7 +3814,7 @@ cmd_reconnect(ProfWin *window, gchar **args, struct cmd_help_t help) } } else { cons_show(err_msg); - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); free(err_msg); } @@ -3831,7 +3822,7 @@ cmd_reconnect(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_autoping(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_autoping(ProfWin *window, gchar **args, const char * const command) { char *value = args[0]; @@ -3848,7 +3839,7 @@ cmd_autoping(ProfWin *window, gchar **args, struct cmd_help_t help) } } else { cons_show(err_msg); - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); free(err_msg); } @@ -3856,7 +3847,7 @@ cmd_autoping(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_ping(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_ping(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -3876,7 +3867,7 @@ cmd_ping(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_autoaway(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_autoaway(ProfWin *window, gchar **args, const char * const command) { char *setting = args[0]; char *value = args[1]; @@ -3927,15 +3918,14 @@ cmd_autoaway(ProfWin *window, gchar **args, struct cmd_help_t help) } if (strcmp(setting, "check") == 0) { - return _cmd_set_boolean_preference(value, help, "Online check", - PREF_AUTOAWAY_CHECK); + return _cmd_set_boolean_preference(value, command, "Online check", PREF_AUTOAWAY_CHECK); } return TRUE; } gboolean -cmd_priority(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_priority(ProfWin *window, gchar **args, const char * const command) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -3963,19 +3953,19 @@ cmd_priority(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_statuses(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_statuses(ProfWin *window, gchar **args, const char * const command) { if (strcmp(args[0], "console") != 0 && strcmp(args[0], "chat") != 0 && strcmp(args[0], "muc") != 0) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } if (strcmp(args[1], "all") != 0 && strcmp(args[1], "online") != 0 && strcmp(args[1], "none") != 0) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -4016,7 +4006,7 @@ cmd_statuses(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_vercheck(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_vercheck(ProfWin *window, gchar **args, const char * const command) { int num_args = g_strv_length(args); @@ -4024,13 +4014,12 @@ cmd_vercheck(ProfWin *window, gchar **args, struct cmd_help_t help) cons_check_version(TRUE); return TRUE; } else { - return _cmd_set_boolean_preference(args[0], help, - "Version checking", PREF_VERCHECK); + return _cmd_set_boolean_preference(args[0], command, "Version checking", PREF_VERCHECK); } } gboolean -cmd_xmlconsole(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_xmlconsole(ProfWin *window, gchar **args, const char * const command) { if (!ui_xmlconsole_exists()) { ui_create_xmlconsole_win(); @@ -4042,28 +4031,25 @@ cmd_xmlconsole(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_flash(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_flash(ProfWin *window, gchar **args, const char * const command) { - return _cmd_set_boolean_preference(args[0], help, - "Screen flash", PREF_FLASH); + return _cmd_set_boolean_preference(args[0], command, "Screen flash", PREF_FLASH); } gboolean -cmd_intype(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_intype(ProfWin *window, gchar **args, const char * const command) { - return _cmd_set_boolean_preference(args[0], help, - "Show contact typing", PREF_INTYPE); + return _cmd_set_boolean_preference(args[0], command, "Show contact typing", PREF_INTYPE); } gboolean -cmd_splash(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_splash(ProfWin *window, gchar **args, const char * const command) { - return _cmd_set_boolean_preference(args[0], help, - "Splash screen", PREF_SPLASH); + return _cmd_set_boolean_preference(args[0], command, "Splash screen", PREF_SPLASH); } gboolean -cmd_autoconnect(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_autoconnect(ProfWin *window, gchar **args, const char * const command) { if (strcmp(args[0], "off") == 0) { prefs_set_string(PREF_CONNECT_ACCOUNT, NULL); @@ -4072,16 +4058,15 @@ cmd_autoconnect(ProfWin *window, gchar **args, struct cmd_help_t help) prefs_set_string(PREF_CONNECT_ACCOUNT, args[1]); cons_show("Autoconnect account set to: %s.", args[1]); } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } return true; } gboolean -cmd_chlog(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_chlog(ProfWin *window, gchar **args, const char * const command) { - gboolean result = _cmd_set_boolean_preference(args[0], help, - "Chat logging", PREF_CHLOG); + gboolean result = _cmd_set_boolean_preference(args[0], command, "Chat logging", PREF_CHLOG); // if set to off, disable history if (result == TRUE && (strcmp(args[0], "off") == 0)) { @@ -4092,19 +4077,17 @@ cmd_chlog(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_grlog(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_grlog(ProfWin *window, gchar **args, const char * const command) { - gboolean result = _cmd_set_boolean_preference(args[0], help, - "Groupchat logging", PREF_GRLOG); + gboolean result = _cmd_set_boolean_preference(args[0], command, "Groupchat logging", PREF_GRLOG); return result; } gboolean -cmd_history(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_history(ProfWin *window, gchar **args, const char * const command) { - gboolean result = _cmd_set_boolean_preference(args[0], help, - "Chat history", PREF_HISTORY); + gboolean result = _cmd_set_boolean_preference(args[0], command, "Chat history", PREF_HISTORY); // if set to on, set chlog if (result == TRUE && (strcmp(args[0], "on") == 0)) { @@ -4115,10 +4098,9 @@ cmd_history(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_carbons(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_carbons(ProfWin *window, gchar **args, const char * const command) { - gboolean result = _cmd_set_boolean_preference(args[0], help, - "Message carbons preference", PREF_CARBONS); + gboolean result = _cmd_set_boolean_preference(args[0], command, "Message carbons preference", PREF_CARBONS); jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -4136,61 +4118,59 @@ cmd_carbons(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_receipts(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_receipts(ProfWin *window, gchar **args, const char * const command) { if (g_strcmp0(args[0], "send") == 0) { - return _cmd_set_boolean_preference(args[1], help, - "Send delivery receipts", PREF_RECEIPTS_SEND); + return _cmd_set_boolean_preference(args[1], command, "Send delivery receipts", PREF_RECEIPTS_SEND); } else if (g_strcmp0(args[0], "request") == 0) { - return _cmd_set_boolean_preference(args[1], help, - "Request delivery receipets", PREF_RECEIPTS_REQUEST); + return _cmd_set_boolean_preference(args[1], command, "Request delivery receipets", PREF_RECEIPTS_REQUEST); } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } } gboolean -cmd_away(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_away(ProfWin *window, gchar **args, const char * const command) { _update_presence(RESOURCE_AWAY, "away", args); return TRUE; } gboolean -cmd_online(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_online(ProfWin *window, gchar **args, const char * const command) { _update_presence(RESOURCE_ONLINE, "online", args); return TRUE; } gboolean -cmd_dnd(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_dnd(ProfWin *window, gchar **args, const char * const command) { _update_presence(RESOURCE_DND, "dnd", args); return TRUE; } gboolean -cmd_chat(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_chat(ProfWin *window, gchar **args, const char * const command) { _update_presence(RESOURCE_CHAT, "chat", args); return TRUE; } gboolean -cmd_xa(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_xa(ProfWin *window, gchar **args, const char * const command) { _update_presence(RESOURCE_XA, "xa", args); return TRUE; } gboolean -cmd_pgp(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_pgp(ProfWin *window, gchar **args, const char * const command) { #ifdef HAVE_LIBGPGME if (args[0] == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -4212,7 +4192,7 @@ cmd_pgp(ProfWin *window, gchar **args, struct cmd_help_t help) cons_show("Chat logging is currently disabled, use '/chlog on' to enable."); } } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } return TRUE; } @@ -4246,13 +4226,13 @@ cmd_pgp(ProfWin *window, gchar **args, struct cmd_help_t help) char *jid = args[1]; if (!args[1]) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } char *keyid = args[2]; if (!args[2]) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -4388,7 +4368,7 @@ cmd_pgp(ProfWin *window, gchar **args, struct cmd_help_t help) return TRUE; } - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; #else cons_show("This version of Profanity has not been built with PGP support enabled"); @@ -4398,11 +4378,11 @@ cmd_pgp(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_otr(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_otr(ProfWin *window, gchar **args, const char * const command) { #ifdef HAVE_LIBOTR if (args[0] == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -4424,7 +4404,7 @@ cmd_otr(ProfWin *window, gchar **args, struct cmd_help_t help) cons_show("Chat logging is currently disabled, use '/chlog on' to enable."); } } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); } return TRUE; @@ -4643,7 +4623,7 @@ cmd_otr(ProfWin *window, gchar **args, struct cmd_help_t help) char *secret = args[1]; if (secret == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -4654,7 +4634,7 @@ cmd_otr(ProfWin *window, gchar **args, struct cmd_help_t help) char *question = args[1]; char *answer = args[2]; if (question == NULL || answer == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -4688,7 +4668,7 @@ cmd_otr(ProfWin *window, gchar **args, struct cmd_help_t help) char *answer = args[1]; if (answer == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -4696,7 +4676,7 @@ cmd_otr(ProfWin *window, gchar **args, struct cmd_help_t help) return TRUE; } else { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } #else @@ -4706,9 +4686,9 @@ cmd_otr(ProfWin *window, gchar **args, struct cmd_help_t help) } gboolean -cmd_encwarn(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_encwarn(ProfWin *window, gchar **args, const char * const command) { - return _cmd_set_boolean_preference(args[0], help, "Encryption warning message", PREF_ENC_WARN); + return _cmd_set_boolean_preference(args[0], command, "Encryption warning message", PREF_ENC_WARN); } // helper function for status change commands @@ -4734,7 +4714,7 @@ _update_presence(const resource_presence_t resource_presence, // helper function for boolean preference commands static gboolean -_cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, +_cmd_set_boolean_preference(gchar *arg, const char * const command, const char * const display, preference_t pref) { GString *enabled = g_string_new(display); @@ -4744,9 +4724,7 @@ _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, g_string_append(disabled, " disabled."); if (arg == NULL) { - char usage[strlen(help.usage) + 8]; - sprintf(usage, "Usage: %s", help.usage); - cons_show(usage); + cons_bad_cmd_usage(command); } else if (strcmp(arg, "on") == 0) { cons_show(enabled->str); prefs_set_boolean(pref, TRUE); @@ -4754,9 +4732,7 @@ _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, cons_show(disabled->str); prefs_set_boolean(pref, FALSE); } else { - char usage[strlen(help.usage) + 8]; - sprintf(usage, "Usage: %s", help.usage); - cons_show(usage); + cons_bad_cmd_usage(command); } g_string_free(enabled, TRUE); diff --git a/src/command/commands.h b/src/command/commands.h index bf0f94ae..70d5d5e0 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -39,10 +39,6 @@ // Command help strings typedef struct cmd_help_t { - const gchar *usage; - const gchar *short_help; - const gchar *long_help[50]; - const gchar *synopsis[50]; const gchar *desc; const gchar *args[50][2]; @@ -61,7 +57,7 @@ typedef struct cmd_help_t { */ typedef struct cmd_t { gchar *cmd; - gboolean (*func)(ProfWin *window, gchar **args, struct cmd_help_t help); + gboolean (*func)(ProfWin *window, gchar **args, const char * const command); gchar** (*parser)(const char * const inp, int min, int max, gboolean *result); int min_args; int max_args; @@ -72,85 +68,85 @@ typedef struct cmd_t { gboolean cmd_execute_alias(ProfWin *window, const char * const inp, gboolean *ran); gboolean cmd_execute_default(ProfWin *window, const char * inp); -gboolean cmd_about(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_account(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_autoaway(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_autoconnect(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_autoping(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_away(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_beep(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_caps(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_chat(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_chlog(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_clear(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_close(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_connect(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_decline(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_disco(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_disconnect(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_dnd(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_flash(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_gone(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_grlog(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_group(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_help(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_history(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_carbons(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_receipts(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_info(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_intype(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_invite(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_invites(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_join(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_leave(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_log(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_msg(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_nick(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_notify(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_online(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_otr(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_pgp(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_outtype(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_prefs(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_priority(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_quit(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_reconnect(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_room(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_rooms(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_bookmark(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_roster(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_software(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_splash(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_states(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_status(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_statuses(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_sub(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_theme(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_tiny(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_titlebar(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_vercheck(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_who(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_win(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_wins(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_winstidy(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_xa(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_alias(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_xmlconsole(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_ping(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_form(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_occupants(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_kick(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_ban(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_subject(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_affiliation(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_role(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_privileges(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_presence(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_wrap(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_time(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_resource(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_inpblock(ProfWin *window, gchar **args, struct cmd_help_t help); -gboolean cmd_encwarn(ProfWin *window, gchar **args, struct cmd_help_t help); +gboolean cmd_about(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_account(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_autoaway(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_autoconnect(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_autoping(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_away(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_beep(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_caps(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_chat(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_chlog(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_clear(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_close(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_connect(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_decline(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_disco(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_disconnect(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_dnd(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_flash(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_gone(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_grlog(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_group(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_help(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_history(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_carbons(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_receipts(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_info(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_intype(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_invite(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_invites(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_join(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_leave(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_log(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_msg(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_nick(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_notify(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_online(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_otr(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_pgp(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_outtype(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_prefs(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_priority(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_quit(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_reconnect(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_room(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_rooms(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_bookmark(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_roster(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_software(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_splash(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_states(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_status(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_statuses(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_sub(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_theme(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_tiny(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_titlebar(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_vercheck(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_who(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_win(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_wins(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_winstidy(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_xa(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_alias(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_xmlconsole(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_ping(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_form(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_occupants(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_kick(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_ban(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_subject(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_affiliation(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_role(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_privileges(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_presence(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_wrap(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_time(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_resource(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_inpblock(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_encwarn(ProfWin *window, gchar **args, const char * const command); gboolean cmd_form_field(ProfWin *window, char *tag, gchar **args); diff --git a/src/ui/console.c b/src/ui/console.c index 67c1da58..027f9e73 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -141,6 +141,18 @@ cons_show_help(Command *command) } } +void +cons_bad_cmd_usage(const char * const cmd) +{ + GString *msg = g_string_new(""); + g_string_printf(msg, "Invalid usage, see '/help %s' for details.", &cmd[1]); + + cons_show(""); + cons_show(msg->str); + + g_string_free(msg, TRUE); +} + void cons_show_error(const char * const msg, ...) { diff --git a/src/ui/core.c b/src/ui/core.c index 5f85a3cd..821de9fe 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -667,22 +667,25 @@ ui_handle_error(const char * const err_msg) } void -ui_invalid_command_usage(const char * const usage, void (*setting_func)(void)) +ui_invalid_command_usage(const char * const cmd, void (*setting_func)(void)) { + GString *msg = g_string_new(""); + g_string_printf(msg, "Invalid usage, see '/help %s' for details.", &cmd[1]); + if (setting_func) { cons_show(""); (*setting_func)(); - cons_show("Usage: %s", usage); + cons_show(msg->str); } else { cons_show(""); - cons_show("Usage: %s", usage); + cons_show(msg->str); ProfWin *current = wins_get_current(); if (current->type == WIN_CHAT) { - char usage_cpy[strlen(usage) + 8]; - sprintf(usage_cpy, "Usage: %s", usage); - ui_current_print_line(usage_cpy); + ui_current_print_line(msg->str); } } + + g_string_free(msg, TRUE); } void diff --git a/src/ui/ui.h b/src/ui/ui.h index 58f1ee98..dba90d2b 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -228,7 +228,7 @@ void ui_input_clear(void); void ui_input_nonblocking(gboolean); void ui_write(char *line, int offset); -void ui_invalid_command_usage(const char * const usage, void (*setting_func)(void)); +void ui_invalid_command_usage(const char * const cmd, void (*setting_func)(void)); void ui_create_xmlconsole_win(void); gboolean ui_xmlconsole_exists(void); @@ -243,6 +243,7 @@ void cons_show(const char * const msg, ...); void cons_about(void); void cons_help(void); void cons_show_help(Command *command); +void cons_bad_cmd_usage(const char * const cmd); void cons_navigation_help(void); void cons_prefs(void); void cons_show_ui_prefs(void); From 4f9a8484292a02e283324b6e7a86ebd95f621127 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 26 Jul 2015 02:09:01 +0100 Subject: [PATCH 13/25] Added message for invalid /wins usage --- src/command/commands.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/command/commands.c b/src/command/commands.c index 6f12f502..6f3dfbf3 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -739,6 +739,8 @@ cmd_wins(ProfWin *window, gchar **args, const char * const command) cons_show("Same source and target window supplied."); } } + } else { + cons_bad_cmd_usage(command); } return TRUE; From 2b725f9144570c8848a050dc52b7e9668c5fcde5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 26 Jul 2015 02:28:45 +0100 Subject: [PATCH 14/25] Reordered command arguments --- src/command/command.c | 2 +- src/command/commands.c | 170 ++++++++++++++++++++--------------------- src/command/commands.h | 160 +++++++++++++++++++------------------- 3 files changed, 166 insertions(+), 166 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index e5cda05c..3c8387dc 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -2505,7 +2505,7 @@ _cmd_execute(ProfWin *window, const char * const command, const char * const inp ui_invalid_command_usage(cmd->cmd, cmd->setting_func); return TRUE; } else { - gboolean result = cmd->func(window, args, command); + gboolean result = cmd->func(window, command, args); g_strfreev(args); return result; } diff --git a/src/command/commands.c b/src/command/commands.c index 6f3dfbf3..1f240cba 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -76,8 +76,8 @@ static void _update_presence(const resource_presence_t presence, static gboolean _cmd_set_boolean_preference(gchar *arg, const char * const command, const char * const display, preference_t pref); static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size); -static void _who_room(ProfWin *window, gchar **args, const char * const command); -static void _who_roster(ProfWin *window, gchar **args, const char * const command); +static void _who_room(ProfWin *window, const char * const command, gchar **args); +static void _who_roster(ProfWin *window, const char * const command, gchar **args); extern GHashTable *commands; @@ -157,7 +157,7 @@ cmd_execute_alias(ProfWin *window, const char * const inp, gboolean *ran) } gboolean -cmd_connect(ProfWin *window, gchar **args, const char * const command) +cmd_connect(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); if ((conn_status != JABBER_DISCONNECTED) && (conn_status != JABBER_STARTED)) { @@ -261,7 +261,7 @@ cmd_connect(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_account(ProfWin *window, gchar **args, const char * const command) +cmd_account(ProfWin *window, const char * const command, gchar **args) { char *subcmd = args[0]; @@ -586,7 +586,7 @@ cmd_account(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_sub(ProfWin *window, gchar **args, const char * const command) +cmd_sub(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -676,7 +676,7 @@ cmd_sub(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_disconnect(ProfWin *window, gchar **args, const char * const command) +cmd_disconnect(ProfWin *window, const char * const command, gchar **args) { if (jabber_get_connection_status() == JABBER_CONNECTED) { char *jid = strdup(jabber_get_fulljid()); @@ -698,7 +698,7 @@ cmd_disconnect(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_quit(ProfWin *window, gchar **args, const char * const command) +cmd_quit(ProfWin *window, const char * const command, gchar **args) { log_info("Profanity is shutting down..."); exit(0); @@ -706,7 +706,7 @@ cmd_quit(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_wins(ProfWin *window, gchar **args, const char * const command) +cmd_wins(ProfWin *window, const char * const command, gchar **args) { if (args[0] == NULL) { cons_show_wins(); @@ -747,7 +747,7 @@ cmd_wins(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_winstidy(ProfWin *window, gchar **args, const char * const command) +cmd_winstidy(ProfWin *window, const char * const command, gchar **args) { gboolean result = _cmd_set_boolean_preference(args[0], command, "Wins Auto Tidy", PREF_WINS_AUTO_TIDY); @@ -759,7 +759,7 @@ cmd_winstidy(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_win(ProfWin *window, gchar **args, const char * const command) +cmd_win(ProfWin *window, const char * const command, gchar **args) { int num = atoi(args[0]); @@ -774,7 +774,7 @@ cmd_win(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_help(ProfWin *window, gchar **args, const char * const command) +cmd_help(ProfWin *window, const char * const command, gchar **args) { int num_args = g_strv_length(args); if (num_args == 0) { @@ -888,14 +888,14 @@ cmd_help(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_about(ProfWin *window, gchar **args, const char * const command) +cmd_about(ProfWin *window, const char * const command, gchar **args) { ui_about(); return TRUE; } gboolean -cmd_prefs(ProfWin *window, gchar **args, const char * const command) +cmd_prefs(ProfWin *window, const char * const command, gchar **args) { if (args[0] == NULL) { cons_prefs(); @@ -940,7 +940,7 @@ cmd_prefs(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_theme(ProfWin *window, gchar **args, const char * const command) +cmd_theme(ProfWin *window, const char * const command, gchar **args) { // list themes if (g_strcmp0(args[0], "list") == 0) { @@ -982,7 +982,7 @@ cmd_theme(ProfWin *window, gchar **args, const char * const command) } static void -_who_room(ProfWin *window, gchar **args, const char * const command) +_who_room(ProfWin *window, const char * const command, gchar **args) { if ((g_strv_length(args) == 2) && args[1]) { cons_show("Argument group is not applicable to chat rooms."); @@ -1112,7 +1112,7 @@ _who_room(ProfWin *window, gchar **args, const char * const command) } static void -_who_roster(ProfWin *window, gchar **args, const char * const command) +_who_roster(ProfWin *window, const char * const command, gchar **args) { char *presence = args[0]; @@ -1325,16 +1325,16 @@ _who_roster(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_who(ProfWin *window, gchar **args, const char * const command) +cmd_who(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); } else if (window->type == WIN_MUC) { - _who_room(window, args, command); + _who_room(window, command, args); } else { - _who_roster(window, args, command); + _who_roster(window, command, args); } if (window->type != WIN_CONSOLE && window->type != WIN_MUC) { @@ -1345,7 +1345,7 @@ cmd_who(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_msg(ProfWin *window, gchar **args, const char * const command) +cmd_msg(ProfWin *window, const char * const command, gchar **args) { char *usr = args[0]; char *msg = args[1]; @@ -1412,7 +1412,7 @@ cmd_msg(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_group(ProfWin *window, gchar **args, const char * const command) +cmd_group(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -1519,7 +1519,7 @@ cmd_group(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_roster(ProfWin *window, gchar **args, const char * const command) +cmd_roster(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -1781,7 +1781,7 @@ cmd_roster(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_resource(ProfWin *window, gchar **args, const char * const command) +cmd_resource(ProfWin *window, const char * const command, gchar **args) { char *cmd = args[0]; char *setting = NULL; @@ -1853,7 +1853,7 @@ cmd_resource(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_status(ProfWin *window, gchar **args, const char * const command) +cmd_status(ProfWin *window, const char * const command, gchar **args) { char *usr = args[0]; @@ -1929,7 +1929,7 @@ cmd_status(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_info(ProfWin *window, gchar **args, const char * const command) +cmd_info(ProfWin *window, const char * const command, gchar **args) { char *usr = args[0]; @@ -2015,7 +2015,7 @@ cmd_info(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_caps(ProfWin *window, gchar **args, const char * const command) +cmd_caps(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); PContact pcontact = NULL; @@ -2092,7 +2092,7 @@ cmd_caps(ProfWin *window, gchar **args, const char * const command) gboolean -cmd_software(ProfWin *window, gchar **args, const char * const command) +cmd_software(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); Occupant *occupant = NULL; @@ -2156,7 +2156,7 @@ cmd_software(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_join(ProfWin *window, gchar **args, const char * const command) +cmd_join(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); if (conn_status != JABBER_CONNECTED) { @@ -2254,7 +2254,7 @@ cmd_join(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_invite(ProfWin *window, gchar **args, const char * const command) +cmd_invite(ProfWin *window, const char * const command, gchar **args) { char *contact = args[0]; char *reason = args[1]; @@ -2290,7 +2290,7 @@ cmd_invite(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_invites(ProfWin *window, gchar **args, const char * const command) +cmd_invites(ProfWin *window, const char * const command, gchar **args) { GSList *invites = muc_invites(); cons_show_room_invites(invites); @@ -2299,7 +2299,7 @@ cmd_invites(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_decline(ProfWin *window, gchar **args, const char * const command) +cmd_decline(ProfWin *window, const char * const command, gchar **args) { if (!muc_invites_contain(args[0])) { cons_show("No such invite exists."); @@ -2530,7 +2530,7 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args) } gboolean -cmd_form(ProfWin *window, gchar **args, const char * const command) +cmd_form(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2604,7 +2604,7 @@ cmd_form(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_kick(ProfWin *window, gchar **args, const char * const command) +cmd_kick(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2637,7 +2637,7 @@ cmd_kick(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_ban(ProfWin *window, gchar **args, const char * const command) +cmd_ban(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2665,7 +2665,7 @@ cmd_ban(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_subject(ProfWin *window, gchar **args, const char * const command) +cmd_subject(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2712,7 +2712,7 @@ cmd_subject(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_affiliation(ProfWin *window, gchar **args, const char * const command) +cmd_affiliation(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2782,7 +2782,7 @@ cmd_affiliation(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_role(ProfWin *window, gchar **args, const char * const command) +cmd_role(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2850,7 +2850,7 @@ cmd_role(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_room(ProfWin *window, gchar **args, const char * const command) +cmd_room(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2913,7 +2913,7 @@ cmd_room(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_occupants(ProfWin *window, gchar **args, const char * const command) +cmd_occupants(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2998,7 +2998,7 @@ cmd_occupants(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_rooms(ProfWin *window, gchar **args, const char * const command) +cmd_rooms(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -3019,7 +3019,7 @@ cmd_rooms(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_bookmark(ProfWin *window, gchar **args, const char * const command) +cmd_bookmark(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -3130,7 +3130,7 @@ cmd_bookmark(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_disco(ProfWin *window, gchar **args, const char * const command) +cmd_disco(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -3160,7 +3160,7 @@ cmd_disco(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_nick(ProfWin *window, gchar **args, const char * const command) +cmd_nick(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -3182,7 +3182,7 @@ cmd_nick(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_alias(ProfWin *window, gchar **args, const char * const command) +cmd_alias(ProfWin *window, const char * const command, gchar **args) { char *subcmd = args[0]; @@ -3254,7 +3254,7 @@ cmd_alias(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_tiny(ProfWin *window, gchar **args, const char * const command) +cmd_tiny(ProfWin *window, const char * const command, gchar **args) { char *url = args[0]; @@ -3306,14 +3306,14 @@ cmd_tiny(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_clear(ProfWin *window, gchar **args, const char * const command) +cmd_clear(ProfWin *window, const char * const command, gchar **args) { ui_clear_win(window); return TRUE; } gboolean -cmd_close(ProfWin *window, gchar **args, const char * const command) +cmd_close(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); int index = 0; @@ -3385,7 +3385,7 @@ cmd_close(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_leave(ProfWin *window, gchar **args, const char * const command) +cmd_leave(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); int index = wins_get_current_num(); @@ -3408,7 +3408,7 @@ cmd_leave(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_privileges(ProfWin *window, gchar **args, const char * const command) +cmd_privileges(ProfWin *window, const char * const command, gchar **args) { gboolean result = _cmd_set_boolean_preference(args[0], command, "MUC privileges", PREF_MUC_PRIVILEGES); @@ -3418,19 +3418,19 @@ cmd_privileges(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_beep(ProfWin *window, gchar **args, const char * const command) +cmd_beep(ProfWin *window, const char * const command, gchar **args) { return _cmd_set_boolean_preference(args[0], command, "Sound", PREF_BEEP); } gboolean -cmd_presence(ProfWin *window, gchar **args, const char * const command) +cmd_presence(ProfWin *window, const char * const command, gchar **args) { return _cmd_set_boolean_preference(args[0], command, "Contact presence", PREF_PRESENCE); } gboolean -cmd_wrap(ProfWin *window, gchar **args, const char * const command) +cmd_wrap(ProfWin *window, const char * const command, gchar **args) { gboolean result = _cmd_set_boolean_preference(args[0], command, "Word wrap", PREF_WRAP); @@ -3440,7 +3440,7 @@ cmd_wrap(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_time(ProfWin *window, gchar **args, const char * const command) +cmd_time(ProfWin *window, const char * const command, gchar **args) { if (g_strcmp0(args[0], "statusbar") == 0) { if (args[1] == NULL) { @@ -3485,7 +3485,7 @@ cmd_time(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_states(ProfWin *window, gchar **args, const char * const command) +cmd_states(ProfWin *window, const char * const command, gchar **args) { gboolean result = _cmd_set_boolean_preference(args[0], command, "Sending chat states", PREF_STATES); @@ -3500,7 +3500,7 @@ cmd_states(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_titlebar(ProfWin *window, gchar **args, const char * const command) +cmd_titlebar(ProfWin *window, const char * const command, gchar **args) { if (g_strcmp0(args[0], "show") != 0 && g_strcmp0(args[0], "goodbye") != 0) { cons_bad_cmd_usage(command); @@ -3517,7 +3517,7 @@ cmd_titlebar(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_outtype(ProfWin *window, gchar **args, const char * const command) +cmd_outtype(ProfWin *window, const char * const command, gchar **args) { gboolean result = _cmd_set_boolean_preference(args[0], command, "Sending typing notifications", PREF_OUTTYPE); @@ -3531,7 +3531,7 @@ cmd_outtype(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_gone(ProfWin *window, gchar **args, const char * const command) +cmd_gone(ProfWin *window, const char * const command, gchar **args) { char *value = args[0]; @@ -3555,7 +3555,7 @@ cmd_gone(ProfWin *window, gchar **args, const char * const command) gboolean -cmd_notify(ProfWin *window, gchar **args, const char * const command) +cmd_notify(ProfWin *window, const char * const command, gchar **args) { char *kind = args[0]; @@ -3698,7 +3698,7 @@ cmd_notify(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_inpblock(ProfWin *window, gchar **args, const char * const command) +cmd_inpblock(ProfWin *window, const char * const command, gchar **args) { char *subcmd = args[0]; char *value = args[1]; @@ -3744,7 +3744,7 @@ cmd_inpblock(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_log(ProfWin *window, gchar **args, const char * const command) +cmd_log(ProfWin *window, const char * const command, gchar **args) { char *subcmd = args[0]; char *value = args[1]; @@ -3800,7 +3800,7 @@ cmd_log(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_reconnect(ProfWin *window, gchar **args, const char * const command) +cmd_reconnect(ProfWin *window, const char * const command, gchar **args) { char *value = args[0]; @@ -3824,7 +3824,7 @@ cmd_reconnect(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_autoping(ProfWin *window, gchar **args, const char * const command) +cmd_autoping(ProfWin *window, const char * const command, gchar **args) { char *value = args[0]; @@ -3849,7 +3849,7 @@ cmd_autoping(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_ping(ProfWin *window, gchar **args, const char * const command) +cmd_ping(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -3869,7 +3869,7 @@ cmd_ping(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_autoaway(ProfWin *window, gchar **args, const char * const command) +cmd_autoaway(ProfWin *window, const char * const command, gchar **args) { char *setting = args[0]; char *value = args[1]; @@ -3927,7 +3927,7 @@ cmd_autoaway(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_priority(ProfWin *window, gchar **args, const char * const command) +cmd_priority(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -3955,7 +3955,7 @@ cmd_priority(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_statuses(ProfWin *window, gchar **args, const char * const command) +cmd_statuses(ProfWin *window, const char * const command, gchar **args) { if (strcmp(args[0], "console") != 0 && strcmp(args[0], "chat") != 0 && @@ -4008,7 +4008,7 @@ cmd_statuses(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_vercheck(ProfWin *window, gchar **args, const char * const command) +cmd_vercheck(ProfWin *window, const char * const command, gchar **args) { int num_args = g_strv_length(args); @@ -4021,7 +4021,7 @@ cmd_vercheck(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_xmlconsole(ProfWin *window, gchar **args, const char * const command) +cmd_xmlconsole(ProfWin *window, const char * const command, gchar **args) { if (!ui_xmlconsole_exists()) { ui_create_xmlconsole_win(); @@ -4033,25 +4033,25 @@ cmd_xmlconsole(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_flash(ProfWin *window, gchar **args, const char * const command) +cmd_flash(ProfWin *window, const char * const command, gchar **args) { return _cmd_set_boolean_preference(args[0], command, "Screen flash", PREF_FLASH); } gboolean -cmd_intype(ProfWin *window, gchar **args, const char * const command) +cmd_intype(ProfWin *window, const char * const command, gchar **args) { return _cmd_set_boolean_preference(args[0], command, "Show contact typing", PREF_INTYPE); } gboolean -cmd_splash(ProfWin *window, gchar **args, const char * const command) +cmd_splash(ProfWin *window, const char * const command, gchar **args) { return _cmd_set_boolean_preference(args[0], command, "Splash screen", PREF_SPLASH); } gboolean -cmd_autoconnect(ProfWin *window, gchar **args, const char * const command) +cmd_autoconnect(ProfWin *window, const char * const command, gchar **args) { if (strcmp(args[0], "off") == 0) { prefs_set_string(PREF_CONNECT_ACCOUNT, NULL); @@ -4066,7 +4066,7 @@ cmd_autoconnect(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_chlog(ProfWin *window, gchar **args, const char * const command) +cmd_chlog(ProfWin *window, const char * const command, gchar **args) { gboolean result = _cmd_set_boolean_preference(args[0], command, "Chat logging", PREF_CHLOG); @@ -4079,7 +4079,7 @@ cmd_chlog(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_grlog(ProfWin *window, gchar **args, const char * const command) +cmd_grlog(ProfWin *window, const char * const command, gchar **args) { gboolean result = _cmd_set_boolean_preference(args[0], command, "Groupchat logging", PREF_GRLOG); @@ -4087,7 +4087,7 @@ cmd_grlog(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_history(ProfWin *window, gchar **args, const char * const command) +cmd_history(ProfWin *window, const char * const command, gchar **args) { gboolean result = _cmd_set_boolean_preference(args[0], command, "Chat history", PREF_HISTORY); @@ -4100,7 +4100,7 @@ cmd_history(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_carbons(ProfWin *window, gchar **args, const char * const command) +cmd_carbons(ProfWin *window, const char * const command, gchar **args) { gboolean result = _cmd_set_boolean_preference(args[0], command, "Message carbons preference", PREF_CARBONS); @@ -4120,7 +4120,7 @@ cmd_carbons(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_receipts(ProfWin *window, gchar **args, const char * const command) +cmd_receipts(ProfWin *window, const char * const command, gchar **args) { if (g_strcmp0(args[0], "send") == 0) { return _cmd_set_boolean_preference(args[1], command, "Send delivery receipts", PREF_RECEIPTS_SEND); @@ -4133,42 +4133,42 @@ cmd_receipts(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_away(ProfWin *window, gchar **args, const char * const command) +cmd_away(ProfWin *window, const char * const command, gchar **args) { _update_presence(RESOURCE_AWAY, "away", args); return TRUE; } gboolean -cmd_online(ProfWin *window, gchar **args, const char * const command) +cmd_online(ProfWin *window, const char * const command, gchar **args) { _update_presence(RESOURCE_ONLINE, "online", args); return TRUE; } gboolean -cmd_dnd(ProfWin *window, gchar **args, const char * const command) +cmd_dnd(ProfWin *window, const char * const command, gchar **args) { _update_presence(RESOURCE_DND, "dnd", args); return TRUE; } gboolean -cmd_chat(ProfWin *window, gchar **args, const char * const command) +cmd_chat(ProfWin *window, const char * const command, gchar **args) { _update_presence(RESOURCE_CHAT, "chat", args); return TRUE; } gboolean -cmd_xa(ProfWin *window, gchar **args, const char * const command) +cmd_xa(ProfWin *window, const char * const command, gchar **args) { _update_presence(RESOURCE_XA, "xa", args); return TRUE; } gboolean -cmd_pgp(ProfWin *window, gchar **args, const char * const command) +cmd_pgp(ProfWin *window, const char * const command, gchar **args) { #ifdef HAVE_LIBGPGME if (args[0] == NULL) { @@ -4380,7 +4380,7 @@ cmd_pgp(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_otr(ProfWin *window, gchar **args, const char * const command) +cmd_otr(ProfWin *window, const char * const command, gchar **args) { #ifdef HAVE_LIBOTR if (args[0] == NULL) { @@ -4688,7 +4688,7 @@ cmd_otr(ProfWin *window, gchar **args, const char * const command) } gboolean -cmd_encwarn(ProfWin *window, gchar **args, const char * const command) +cmd_encwarn(ProfWin *window, const char * const command, gchar **args) { return _cmd_set_boolean_preference(args[0], command, "Encryption warning message", PREF_ENC_WARN); } diff --git a/src/command/commands.h b/src/command/commands.h index 70d5d5e0..46061a7d 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -57,7 +57,7 @@ typedef struct cmd_help_t { */ typedef struct cmd_t { gchar *cmd; - gboolean (*func)(ProfWin *window, gchar **args, const char * const command); + gboolean (*func)(ProfWin *window, const char * const command, gchar **args); gchar** (*parser)(const char * const inp, int min, int max, gboolean *result); int min_args; int max_args; @@ -68,85 +68,85 @@ typedef struct cmd_t { gboolean cmd_execute_alias(ProfWin *window, const char * const inp, gboolean *ran); gboolean cmd_execute_default(ProfWin *window, const char * inp); -gboolean cmd_about(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_account(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_autoaway(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_autoconnect(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_autoping(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_away(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_beep(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_caps(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_chat(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_chlog(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_clear(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_close(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_connect(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_decline(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_disco(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_disconnect(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_dnd(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_flash(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_gone(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_grlog(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_group(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_help(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_history(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_carbons(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_receipts(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_info(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_intype(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_invite(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_invites(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_join(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_leave(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_log(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_msg(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_nick(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_notify(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_online(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_otr(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_pgp(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_outtype(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_prefs(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_priority(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_quit(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_reconnect(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_room(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_rooms(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_bookmark(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_roster(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_software(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_splash(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_states(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_status(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_statuses(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_sub(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_theme(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_tiny(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_titlebar(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_vercheck(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_who(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_win(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_wins(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_winstidy(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_xa(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_alias(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_xmlconsole(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_ping(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_form(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_occupants(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_kick(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_ban(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_subject(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_affiliation(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_role(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_privileges(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_presence(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_wrap(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_time(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_resource(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_inpblock(ProfWin *window, gchar **args, const char * const command); -gboolean cmd_encwarn(ProfWin *window, gchar **args, const char * const command); +gboolean cmd_about(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_account(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_autoaway(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_autoconnect(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_autoping(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_away(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_beep(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_caps(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_chat(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_chlog(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_clear(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_close(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_connect(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_decline(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_disco(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_disconnect(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_dnd(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_flash(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_gone(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_grlog(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_group(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_help(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_history(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_carbons(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_receipts(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_info(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_intype(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_invite(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_invites(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_join(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_leave(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_log(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_msg(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_nick(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_notify(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_online(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_otr(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_pgp(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_outtype(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_prefs(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_priority(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_quit(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_reconnect(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_room(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_rooms(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_bookmark(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_roster(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_software(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_splash(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_states(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_status(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_statuses(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_sub(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_theme(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_tiny(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_titlebar(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_vercheck(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_who(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_win(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_wins(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_winstidy(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_xa(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_alias(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_xmlconsole(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_ping(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_form(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_occupants(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_kick(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_ban(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_subject(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_affiliation(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_role(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_privileges(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_presence(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_wrap(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_time(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_resource(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_inpblock(ProfWin *window, const char * const command, gchar **args); +gboolean cmd_encwarn(ProfWin *window, const char * const command, gchar **args); gboolean cmd_form_field(ProfWin *window, char *tag, gchar **args); From bd32f4dc472b181fdd78c12228313debaaf593d6 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 26 Jul 2015 03:01:14 +0100 Subject: [PATCH 15/25] Show command header in help output --- src/ui/console.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ui/console.c b/src/ui/console.c index 027f9e73..a688d5f2 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -110,6 +110,14 @@ cons_show_help(Command *command) { ProfWin *console = wins_get_console(); + cons_show(""); + win_vprint(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "%s", &command->cmd[1]); + win_print(console, '-', NULL, NO_EOL, THEME_WHITE_BOLD, "", ""); + int i; + for (i = 0; i < strlen(command->cmd) - 1 ; i++) { + win_print(console, '-', NULL, NO_EOL | NO_DATE, THEME_WHITE_BOLD, "", "-"); + } + win_print(console, '-', NULL, NO_DATE, THEME_WHITE_BOLD, "", ""); cons_show(""); win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "Synopsis"); @@ -119,7 +127,6 @@ cons_show_help(Command *command) win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "Description"); win_println(console, command->help.desc); - int i; int maxlen = 0; for (i = 0; command->help.args[i][0] != NULL; i++) { if (strlen(command->help.args[i][0]) > maxlen) From 6986a02ff322af234c21c023b7d91e4d79a8a229 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 26 Jul 2015 19:39:12 +0100 Subject: [PATCH 16/25] Added command definition macros --- src/command/command.c | 558 +++++++++++++++++------------------------- 1 file changed, 229 insertions(+), 329 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 3c8387dc..df6e9f83 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -104,117 +104,100 @@ static char * _receipts_autocomplete(ProfWin *window, const char * const input); GHashTable *commands = NULL; +#define CMD_SYN(...) { { __VA_ARGS__, NULL }, +#define CMD_DESC(desc) desc, +#define CMD_NOARGS() { { NULL, NULL } }, +#define CMD_ARGS(...) { __VA_ARGS__, { NULL, NULL } }, +#define CMD_NOEXAMPLES() { NULL } } +#define CMD_EXAMPLES(...) { __VA_ARGS__, NULL } } + #define END_ARGS { NULL, NULL } - - /* * Command list */ static struct cmd_t command_defs[] = { - // NEW STYLE { "/help", cmd_help, parse_args, 0, 1, NULL, - { - { - "/help [|]", - NULL - }, - "Help on using Profanity. Passing no arguments list help areas.", - { + CMD_SYN( + "/help [|]") + CMD_DESC( + "Help on using Profanity. Passing no arguments list help areas.") + CMD_ARGS( { "", "Summary help for commands in a certain area of functionality." }, - { "", "Full help for a specific command, for example '/help connect'." }, - END_ARGS }, - { + { "", "Full help for a specific command, for example '/help connect'." }) + CMD_EXAMPLES( "/help commands", "/help presence", - "/help who", - NULL } } - }, + "/help who") + }, { "/about", cmd_about, parse_args, 0, 0, NULL, - { - { - "/about", - NULL - }, - "Show version and license information.", - { - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/about") + CMD_DESC( + "Show version and license information.") + CMD_NOARGS() + CMD_NOEXAMPLES() + }, { "/connect", cmd_connect, parse_args, 0, 5, NULL, - { - { + CMD_SYN( "/connect []", - "/connect [server ] [port ]", - NULL - }, + "/connect [server ] [port ]") + CMD_DESC( "Login to a chat service. " "If no account is specified, the default is used if one is configured. " - "A local account is created with the JID as it's name if it doesn't already exist.", - { + "A local account is created with the JID as it's name if it doesn't already exist.") + CMD_ARGS( { "", "The local account you wish to connect with, or a JID if connecting for the first time." }, { "server ", "Supply a server if it is different to the domain part of your JID." }, - { "port ", "The port to use if different to the default (5222, or 5223 for SSL)." }, - END_ARGS }, - { + { "port ", "The port to use if different to the default (5222, or 5223 for SSL)." }) + CMD_EXAMPLES( "/connect", "/connect myuser@gmail.com", "/connect myuser@mycompany.com server talk.google.com", "/connect bob@someplace port 5678", - "/connect me@chatty server chatty.com port 5443", - NULL } } + "/connect me@chatty server chatty.com port 5443") }, { "/disconnect", cmd_disconnect, parse_args, 0, 0, NULL, - { - { - "/disconnect", - NULL - }, - "Disconnect from the current chat service.", - { - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/disconnect") + CMD_DESC( + "Disconnect from the current chat service.") + CMD_NOARGS() + CMD_NOEXAMPLES() + }, { "/msg", cmd_msg, parse_args_with_freetext, 1, 2, NULL, - { - { + CMD_SYN( "/msg []", - "/msg []", - NULL - }, + "/msg []") + CMD_DESC( "Send a one to one chat message, or a private message to a chat room occupant. " "If the message is omitted, a new chat window will be opened without sending a message. " - "Use quotes if the nickname includes spaces.", - { + "Use quotes if the nickname includes spaces.") + CMD_ARGS( { "", "Open chat window with contact, by JID or nickname." }, { " []", "Send message to contact, by JID or nickname." }, { "", "Open private chat window with chat room occupant." }, - { " []", "Send a private message to a chat room occupant." }, - END_ARGS }, - { + { " []", "Send a private message to a chat room occupant." }) + CMD_EXAMPLES( "/msg myfriend@server.com Hey, here's a message!", "/msg otherfriend@server.com", "/msg Bob Here is a private message", - "/msg \"My Friend\" Hi, how are you?", - NULL } } - }, + "/msg \"My Friend\" Hi, how are you?") + }, { "/roster", cmd_roster, parse_args_with_freetext, 0, 3, NULL, - { - { + CMD_SYN( "/roster", "/roster online", "/roster show [offline|resource|empty]", @@ -225,12 +208,11 @@ static struct cmd_t command_defs[] = "/roster remove ", "/roster remove_all contacts", "/roster nick ", - "/roster clearnick ", - NULL - }, - "Manage your roster, and roster display settings. " - "Passing no arguments lists all contacts in your roster.", - { + "/roster clearnick ") + CMD_DESC( + "Manage your roster, and roster display settings. " + "Passing no arguments lists all contacts in your roster.") + CMD_ARGS( { "online", "Show all online contacts in your roster." }, { "show", "Show the roster panel." }, { "show offline", "Show offline contacts in the roster panel." }, @@ -249,397 +231,315 @@ static struct cmd_t command_defs[] = { "remove ", "Removes an item from the roster." }, { "remove_all contacts", "Remove all items from roster." }, { "nick ", "Change a contacts nickname." }, - { "clearnick ", "Removes the current nickname." }, - END_ARGS }, - { + { "clearnick ", "Removes the current nickname." }) + CMD_EXAMPLES( "/roster", "/roster add someone@contacts.org", "/roster add someone@contacts.org Buddy", "/roster remove someone@contacts.org", "/roster nick myfriend@chat.org My Friend", "/roster clearnick kai@server.com", - "/roster size 15", - NULL } } - }, + "/roster size 15") + }, { "/group", cmd_group, parse_args_with_freetext, 0, 3, NULL, - { - { + CMD_SYN( "/group", "/group show ", - "/group remove ", - NULL - }, - "View, add to, and remove from roster groups. " - "Passing no argument will list all roster groups.", - { + "/group remove ") + CMD_DESC( + "View, add to, and remove from roster groups. " + "Passing no argument will list all roster groups.") + CMD_ARGS( { "show ", "List all roster items a group." }, { "add ", "Add a contact to a group." }, - { "remove ", "Remove a contact from a group." }, - END_ARGS }, - { + { "remove ", "Remove a contact from a group." }) + CMD_EXAMPLES( "/group", "/group show friends", "/group add friends newfriend@server.org", "/group add family Brother", - "/group remove colleagues boss@work.com", - NULL } } - }, + "/group remove colleagues boss@work.com") + }, { "/info", cmd_info, parse_args, 0, 1, NULL, - { - { + CMD_SYN( "/info", - "/info |", - NULL - }, - "Show information about a contact, room, or room member. " - "Passing no argument in a chat window will use the current recipient. " - "Passing no argument in a chat room will display information about the room.", - { + "/info |") + CMD_DESC( + "Show information about a contact, room, or room member. " + "Passing no argument in a chat window will use the current recipient. " + "Passing no argument in a chat room will display information about the room.") + CMD_ARGS( { "", "The contact you wish to view information about." }, - { "", "When in a chat room, the occupant you wish to view information about." }, - END_ARGS }, - { + { "", "When in a chat room, the occupant you wish to view information about." }) + CMD_EXAMPLES( "/info mybuddy@chat.server.org", - "/info kai", - NULL } } - }, + "/info kai") + }, { "/caps", cmd_caps, parse_args, 0, 1, NULL, - { - { + CMD_SYN( "/caps", - "/caps |", - NULL - }, + "/caps |") + CMD_DESC( "Find out a contacts, or room members client software capabilities. " - "If in private chat initiated from a chat room, no parameter is required.", - { + "If in private chat initiated from a chat room, no parameter is required.") + CMD_ARGS( { "", "If in the console or a chat window, the full JID for which you wish to see capabilities." }, - { "", "If in a chat room, nickname for which you wish to see capabilities." }, - END_ARGS }, - { + { "", "If in a chat room, nickname for which you wish to see capabilities." }) + CMD_EXAMPLES( "/caps mybuddy@chat.server.org/laptop", "/caps mybuddy@chat.server.org/phone", - "/caps bruce", - NULL } } - }, + "/caps bruce") + }, { "/software", cmd_software, parse_args, 0, 1, NULL, - { - { + CMD_SYN( "/software", - "/software |", - NULL - }, - "Find out a contact, or room members software version information. " - "If in private chat initiated from a chat room, no parameter is required. " - "If the contact's software does not support software version requests, nothing will be displayed.", - { + "/software |") + CMD_DESC( + "Find out a contact, or room members software version information. " + "If in private chat initiated from a chat room, no parameter is required. " + "If the contact's software does not support software version requests, nothing will be displayed.") + CMD_ARGS( { "", "If in the console or a chat window, the full JID for which you wish to see software information." }, - { "", "If in a chat room, nickname for which you wish to see software information." }, - END_ARGS }, - { + { "", "If in a chat room, nickname for which you wish to see software information." }) + CMD_EXAMPLES( "/software mybuddy@chat.server.org/laptop", "/software mybuddy@chat.server.org/phone", - "/software bruce", - NULL } } - }, + "/software bruce") + }, { "/status", cmd_status, parse_args, 0, 1, NULL, - { - { + CMD_SYN( "/status", - "/status |", - NULL - }, - "Find out a contact, or room members presence information. " - "If in a chat window the parameter is not required, the current recipient will be used.", - { + "/status |") + CMD_DESC( + "Find out a contact, or room members presence information. " + "If in a chat window the parameter is not required, the current recipient will be used.") + CMD_ARGS( { "", "The contact who's presence you which to see." }, - { "", "If in a chat room, the occupant who's presence you wish to see." }, - END_ARGS }, - { + { "", "If in a chat room, the occupant who's presence you wish to see." }) + CMD_EXAMPLES( "/status buddy@server.com", - "/status jon", - NULL } } - }, + "/status jon") + }, { "/resource", cmd_resource, parse_args, 1, 2, &cons_resource_setting, - { - { + CMD_SYN( "/resource set ", "/resource off", "/resource title on|off", - "/resource message on|off", - NULL - }, - "Override chat session resource, and manage resource display settings.", - { + "/resource message on|off") + CMD_DESC( + "Override chat session resource, and manage resource display settings.") + CMD_ARGS( { "set ", "Set the resource to which messages will be sent." }, { "off", "Let the server choose which resource to route messages to." }, { "title on|off", "Show or hide the current resource in the titlebar." }, - { "message on|off", "Show or hide the resource when showing an incoming message." }, - END_ARGS }, - { - NULL } } - }, + { "message on|off", "Show or hide the resource when showing an incoming message." }) + CMD_NOEXAMPLES() + }, { "/join", cmd_join, parse_args, 0, 5, NULL, - { - { + CMD_SYN( "/join", - "/join [nick ] [password ]", - NULL - }, + "/join [nick ] [password ]") + CMD_DESC( "Join a chat room at the conference server. " "If no room is supplied, a generated name will be used with the format private-chat-[UUID]. " "If the domain part is not included in the room name, the account preference 'muc.service' will be used. " "If no nickname is specified the account preference 'muc.nick' will be used which by default is the localpart of your JID. " - "If the room doesn't exist, and the server allows it, a new one will be created.", - { - { "", "The chat room to join." }, + "If the room doesn't exist, and the server allows it, a new one will be created.") + CMD_ARGS( + { "", "The chat room to join." }, { "nick ", "Nickname to use in the room." }, - { "password ", "Password if the room requires one." }, - END_ARGS }, - { + { "password ", "Password if the room requires one." }) + CMD_EXAMPLES( "/join", "/join jdev@conference.jabber.org", "/join jdev@conference.jabber.org nick mynick", "/join private@conference.jabber.org nick mynick password mypassword", - "/join jdev", - NULL } } - }, + "/join jdev") + }, { "/leave", cmd_leave, parse_args, 0, 0, NULL, - { - { - "/leave", - NULL - }, - "Leave the current chat room.", - { - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/leave") + CMD_DESC( + "Leave the current chat room.") + CMD_NOARGS() + CMD_NOEXAMPLES() + }, { "/invite", cmd_invite, parse_args_with_freetext, 1, 2, NULL, - { - { - "/invite []", - NULL - }, - "Send an invite to a contact for the current chat room.", - { + CMD_SYN( + "/invite []") + CMD_DESC( + "Send an invite to a contact for the current chat room.") + CMD_ARGS( { "", "The contact you wish to invite." }, - { "", "An optional message to send with the invite." }, - END_ARGS }, - { - NULL } } - }, + { "", "An optional message to send with the invite." }) + CMD_NOEXAMPLES() + }, { "/invites", cmd_invites, parse_args_with_freetext, 0, 0, NULL, - { - { - "/invites", - NULL - }, - "Show all rooms that you have been invited to, and not accepted or declined.", - { - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/invites") + CMD_DESC( + "Show all rooms that you have been invited to, and not accepted or declined.") + CMD_NOARGS() + CMD_NOEXAMPLES() + }, { "/decline", cmd_decline, parse_args_with_freetext, 1, 1, NULL, - { - { - "/decline ", - NULL - }, - "Decline a chat room invitation.", - { - { "", "The room for the invite you wish to decline." }, - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/decline ") + CMD_DESC( + "Decline a chat room invitation.") + CMD_ARGS( + { "", "The room for the invite you wish to decline." }) + CMD_NOEXAMPLES() + }, { "/room", cmd_room, parse_args, 1, 1, NULL, - { - { - "/room accept|destroy|config", - NULL - }, - "Chat room configuration.", - { + CMD_SYN( + "/room accept|destroy|config") + CMD_DESC( + "Chat room configuration.") + CMD_ARGS( { "accept", "Accept default room configuration." }, { "destroy", "Reject default room configuration, and destroy the room." }, - { "config", "Edit room configuration." }, - END_ARGS }, - { - NULL } } - }, + { "config", "Edit room configuration." }) + CMD_NOEXAMPLES() + }, { "/kick", cmd_kick, parse_args_with_freetext, 1, 2, NULL, - { - { - "/kick []", - NULL - }, - "Kick occupant from chat room.", - { + CMD_SYN( + "/kick []") + CMD_DESC( + "Kick occupant from chat room.") + CMD_ARGS( { "", "Nickname of the occupant to kick from the room." }, - { "", "Optional reason for kicking the occupant." }, - END_ARGS }, - { - NULL } } - }, + { "", "Optional reason for kicking the occupant." }) + CMD_NOEXAMPLES() + }, { "/ban", cmd_ban, parse_args_with_freetext, 1, 2, NULL, - { - { - "/ban []", - NULL - }, - "Ban user from chat room.", - { + CMD_SYN( + "/ban []") + CMD_DESC( + "Ban user from chat room.") + CMD_ARGS( { "", "Bare JID of the user to ban from the room." }, - { "", "Optional reason for banning the user." }, - END_ARGS }, - { - NULL } } - }, + { "", "Optional reason for banning the user." }) + CMD_NOEXAMPLES() + }, { "/subject", cmd_subject, parse_args_with_freetext, 0, 2, NULL, - { - { + CMD_SYN( "/subject set ", - "/subject clear", - NULL - }, - "Set or clear room subject.", - { + "/subject clear") + CMD_DESC( + "Set or clear room subject.") + CMD_ARGS( { "set ", "Set the room subject." }, - { "clear", "Clear the room subject." }, - END_ARGS }, - { - NULL } } - }, + { "clear", "Clear the room subject." }) + CMD_NOEXAMPLES() + }, { "/affiliation", cmd_affiliation, parse_args_with_freetext, 1, 4, NULL, - { - { + CMD_SYN( "/affiliation set []", - "/list []", - NULL - }, + "/list []") + CMD_DESC( "Manage room affiliations. " - "Affiliation may be one of owner, admin, member, outcast or none.", - { + "Affiliation may be one of owner, admin, member, outcast or none.") + CMD_ARGS( { "set []", "Set the affiliation of user with jid, with an optional reason." }, - { "list []", "List all users with the specified affiliation, or all if none specified." }, - END_ARGS }, - { - NULL } } - }, + { "list []", "List all users with the specified affiliation, or all if none specified." }) + CMD_NOEXAMPLES() + }, { "/role", cmd_role, parse_args_with_freetext, 1, 4, NULL, - { - { + CMD_SYN( "/role set []", - "/list []", - NULL - }, + "/list []") + CMD_DESC( "Manage room roles. " - "Role may be one of moderator, participant, visitor or none.", - { + "Role may be one of moderator, participant, visitor or none.") + CMD_ARGS( { "set []", "Set the role of occupant with nick, with an optional reason." }, - { "list []", "List all occupants with the specified role, or all if none specified." }, - END_ARGS }, - { - NULL } } - }, + { "list []", "List all occupants with the specified role, or all if none specified." }) + CMD_NOEXAMPLES() + }, { "/occupants", cmd_occupants, parse_args, 1, 3, cons_occupants_setting, - { - { + CMD_SYN( "/occupants show|hide [jid]", "/occupants default show|hide [jid]", - "/occupants size []", - NULL - }, - "Show or hide room occupants, and occupants panel display settings.", - { + "/occupants size []") + CMD_DESC( + "Show or hide room occupants, and occupants panel display settings.") + CMD_ARGS( { "show", "Show the occupants panel in current room." }, { "hide", "Hide the occupants panel in current room." }, { "show jid", "Show jid in the occupants panel in current room." }, { "hide jid", "Hide jid in the occupants panel in current room." }, { "default show|hide", "Whether occupants are shown by default in new rooms." }, { "default show|hide jid", "Whether occupants jids are shown by default in new rooms." }, - { "size ", "Percentage of the screen taken by the occupants list in rooms (1-99)." }, - END_ARGS }, - { - NULL } } - }, + { "size ", "Percentage of the screen taken by the occupants list in rooms (1-99)." }) + CMD_NOEXAMPLES() + }, { "/form", cmd_form, parse_args, 1, 2, NULL, - { - { + CMD_SYN( "/form show", "/form submit", "/form cancel", - "/form help []", - NULL - }, - "Form configuration.", - { + "/form help []") + CMD_DESC( + "Form configuration.") + CMD_ARGS( { "show", "Show the current form." }, { "submit", "Submit the current form." }, { "cancel", "Cancel changes to the current form." }, - { "help []", "Display help for form, or a specific field." }, - END_ARGS }, - { - NULL } } - }, + { "help []", "Display help for form, or a specific field." }) + CMD_NOEXAMPLES() + }, { "/rooms", cmd_rooms, parse_args, 0, 1, NULL, - { - { - "/rooms []", - NULL - }, + CMD_SYN( + "/rooms []") + CMD_DESC( "List the chat rooms available at the specified conference service. " - "If no argument is supplied, the account preference 'muc.service' is used, 'conference.' by default.", - { - { "", "The conference service to query." }, - END_ARGS }, - { - "/rooms conference.jabber.org", - NULL } } - }, + "If no argument is supplied, the account preference 'muc.service' is used, 'conference.' by default.") + CMD_ARGS( + { "", "The conference service to query." }) + CMD_EXAMPLES( + "/rooms conference.jabber.org") + }, { "/bookmark", cmd_bookmark, parse_args, 0, 8, NULL, From 59d5dd73a77b2a85e199ad43e9ba4591b2bfbe08 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 26 Jul 2015 20:43:59 +0100 Subject: [PATCH 17/25] Use command definition macros for remaining commands --- src/command/command.c | 1137 +++++++++++++++++------------------------ 1 file changed, 461 insertions(+), 676 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index df6e9f83..87784780 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -106,13 +106,11 @@ GHashTable *commands = NULL; #define CMD_SYN(...) { { __VA_ARGS__, NULL }, #define CMD_DESC(desc) desc, -#define CMD_NOARGS() { { NULL, NULL } }, +#define CMD_NOARGS { { NULL, NULL } }, #define CMD_ARGS(...) { __VA_ARGS__, { NULL, NULL } }, -#define CMD_NOEXAMPLES() { NULL } } +#define CMD_NOEXAMPLES { NULL } } #define CMD_EXAMPLES(...) { __VA_ARGS__, NULL } } -#define END_ARGS { NULL, NULL } - /* * Command list */ @@ -139,8 +137,8 @@ static struct cmd_t command_defs[] = "/about") CMD_DESC( "Show version and license information.") - CMD_NOARGS() - CMD_NOEXAMPLES() + CMD_NOARGS + CMD_NOEXAMPLES }, { "/connect", @@ -170,8 +168,8 @@ static struct cmd_t command_defs[] = "/disconnect") CMD_DESC( "Disconnect from the current chat service.") - CMD_NOARGS() - CMD_NOEXAMPLES() + CMD_NOARGS + CMD_NOEXAMPLES }, { "/msg", @@ -345,7 +343,7 @@ static struct cmd_t command_defs[] = { "off", "Let the server choose which resource to route messages to." }, { "title on|off", "Show or hide the current resource in the titlebar." }, { "message on|off", "Show or hide the resource when showing an incoming message." }) - CMD_NOEXAMPLES() + CMD_NOEXAMPLES }, { "/join", @@ -377,8 +375,8 @@ static struct cmd_t command_defs[] = "/leave") CMD_DESC( "Leave the current chat room.") - CMD_NOARGS() - CMD_NOEXAMPLES() + CMD_NOARGS + CMD_NOEXAMPLES }, { "/invite", @@ -390,7 +388,7 @@ static struct cmd_t command_defs[] = CMD_ARGS( { "", "The contact you wish to invite." }, { "", "An optional message to send with the invite." }) - CMD_NOEXAMPLES() + CMD_NOEXAMPLES }, { "/invites", @@ -399,8 +397,8 @@ static struct cmd_t command_defs[] = "/invites") CMD_DESC( "Show all rooms that you have been invited to, and not accepted or declined.") - CMD_NOARGS() - CMD_NOEXAMPLES() + CMD_NOARGS + CMD_NOEXAMPLES }, { "/decline", @@ -411,7 +409,7 @@ static struct cmd_t command_defs[] = "Decline a chat room invitation.") CMD_ARGS( { "", "The room for the invite you wish to decline." }) - CMD_NOEXAMPLES() + CMD_NOEXAMPLES }, { "/room", @@ -424,7 +422,7 @@ static struct cmd_t command_defs[] = { "accept", "Accept default room configuration." }, { "destroy", "Reject default room configuration, and destroy the room." }, { "config", "Edit room configuration." }) - CMD_NOEXAMPLES() + CMD_NOEXAMPLES }, { "/kick", @@ -436,7 +434,7 @@ static struct cmd_t command_defs[] = CMD_ARGS( { "", "Nickname of the occupant to kick from the room." }, { "", "Optional reason for kicking the occupant." }) - CMD_NOEXAMPLES() + CMD_NOEXAMPLES }, { "/ban", @@ -448,7 +446,7 @@ static struct cmd_t command_defs[] = CMD_ARGS( { "", "Bare JID of the user to ban from the room." }, { "", "Optional reason for banning the user." }) - CMD_NOEXAMPLES() + CMD_NOEXAMPLES }, { "/subject", @@ -461,7 +459,7 @@ static struct cmd_t command_defs[] = CMD_ARGS( { "set ", "Set the room subject." }, { "clear", "Clear the room subject." }) - CMD_NOEXAMPLES() + CMD_NOEXAMPLES }, { "/affiliation", @@ -475,7 +473,7 @@ static struct cmd_t command_defs[] = CMD_ARGS( { "set []", "Set the affiliation of user with jid, with an optional reason." }, { "list []", "List all users with the specified affiliation, or all if none specified." }) - CMD_NOEXAMPLES() + CMD_NOEXAMPLES }, { "/role", @@ -489,7 +487,7 @@ static struct cmd_t command_defs[] = CMD_ARGS( { "set []", "Set the role of occupant with nick, with an optional reason." }, { "list []", "List all occupants with the specified role, or all if none specified." }) - CMD_NOEXAMPLES() + CMD_NOEXAMPLES }, { "/occupants", @@ -508,7 +506,7 @@ static struct cmd_t command_defs[] = { "default show|hide", "Whether occupants are shown by default in new rooms." }, { "default show|hide jid", "Whether occupants jids are shown by default in new rooms." }, { "size ", "Percentage of the screen taken by the occupants list in rooms (1-99)." }) - CMD_NOEXAMPLES() + CMD_NOEXAMPLES }, { "/form", @@ -525,7 +523,7 @@ static struct cmd_t command_defs[] = { "submit", "Submit the current form." }, { "cancel", "Cancel changes to the current form." }, { "help []", "Display help for form, or a specific field." }) - CMD_NOEXAMPLES() + CMD_NOEXAMPLES }, { "/rooms", @@ -543,19 +541,17 @@ static struct cmd_t command_defs[] = { "/bookmark", cmd_bookmark, parse_args, 0, 8, NULL, - { - { + CMD_SYN( "/bookmark", "/bookmark list", "/bookmark add [nick ] [password ] [autojoin on|off]", "/bookmark update [nick ] [password ] [autojoin on|off]", "/bookmark remove ", - "/bookmark join ", - NULL - }, + "/bookmark join ") + CMD_DESC( "Manage bookmarks and join bookmarked rooms. " - "In a chat room, no arguments will bookmark the current room, setting autojoin to \"on\".", - { + "In a chat room, no arguments will bookmark the current room, setting autojoin to \"on\".") + CMD_ARGS( { "list", "List all bookmarks." }, { "add ", "Add a bookmark." }, { "remove ", "Remove a bookmark." }, @@ -563,142 +559,114 @@ static struct cmd_t command_defs[] = { "nick ", "Nickname used in the chat room." }, { "password ", "Password if required, may be stored in plaintext on your server." }, { "autojoin on|off", "Whether to join the room automatically on login." }, - { "join ", "Join room using the properties associated with the bookmark." }, - END_ARGS }, - { - NULL } } - }, + { "join ", "Join room using the properties associated with the bookmark." }) + CMD_NOEXAMPLES + }, { "/disco", cmd_disco, parse_args, 1, 2, NULL, - { - { + CMD_SYN( "/disco info []", - "/disco items []", - NULL - }, + "/disco items []") + CMD_DESC( "Find out information about an entities supported services. " - "Calling with no arguments will query the server you are currently connected to.", - { + "Calling with no arguments will query the server you are currently connected to.") + CMD_ARGS( { "info []", "List protocols and features supported by an entity." }, - { "items []", "List items associated with an entity." }, - END_ARGS }, - { + { "items []", "List items associated with an entity." }) + CMD_EXAMPLES( "/disco info", "/disco items myserver.org", "/disco items conference.jabber.org", - "/disco info myfriend@server.com/laptop", - NULL } } - }, + "/disco info myfriend@server.com/laptop") + }, { "/nick", cmd_nick, parse_args_with_freetext, 1, 1, NULL, - { - { - "/nick ", - NULL - }, - "Change your nickname in the current chat room.", - { - { "", "Your new nickname." }, - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/nick ") + CMD_DESC( + "Change your nickname in the current chat room.") + CMD_ARGS( + { "", "Your new nickname." }) + CMD_NOEXAMPLES + }, { "/win", cmd_win, parse_args, 1, 1, NULL, - { - { - "/win ", - NULL - }, - "Move to the specified window.", - { - { "", "Window number to display." }, - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/win ") + CMD_DESC( + "Move to the specified window.") + CMD_ARGS( + { "", "Window number to display." }) + CMD_NOEXAMPLES + }, { "/wins", cmd_wins, parse_args, 0, 3, NULL, - { - { + CMD_SYN( "/wins tidy", "/wins prune", - "/wins swap ", - NULL - }, + "/wins swap ") + CMD_DESC( "Manage windows. " - "Passing no argument will list all currently active windows and information about their usage.", - { + "Passing no argument will list all currently active windows and information about their usage.") + CMD_ARGS( { "tidy", "Move windows so there are no gaps." }, { "prune", "Close all windows with no unread messages, and then tidy so there are no gaps." }, - { "swap ", "Swap windows, target may be an empty position." }, - END_ARGS }, - { - NULL } } - }, + { "swap ", "Swap windows, target may be an empty position." }) + CMD_NOEXAMPLES + }, { "/sub", cmd_sub, parse_args, 1, 2, NULL, - { - { + CMD_SYN( "/sub request []", "/sub allow []", "/sub deny []", "/sub show []", "/sub sent", - "/sub received", - NULL - }, + "/sub received") + CMD_DESC( "Manage subscriptions to contact presence. " - "If jid is omitted, the contact of the current window is used.", - { + "If jid is omitted, the contact of the current window is used.") + CMD_ARGS( { "request []", "Send a subscription request to the user." }, { "allow []", "Approve a contact's subscription request." }, { "deny []", "Remove subscription for a contact, or deny a request." }, { "show []", "Show subscription status for a contact." }, { "sent", "Show all sent subscription requests pending a response." }, - { "received", "Show all received subscription requests awaiting your response." }, - END_ARGS }, - { + { "received", "Show all received subscription requests awaiting your response." }) + CMD_EXAMPLES( "/sub request myfriend@jabber.org", "/sub allow myfriend@jabber.org", "/sub request", - "/sub sent", - NULL } } - }, + "/sub sent") + }, { "/tiny", cmd_tiny, parse_args, 1, 1, NULL, - { - { - "/tiny ", - NULL - }, - "Send url as tinyurl in current chat.", - { - { "", "The url to make tiny." }, - END_ARGS }, - { - "Example: /tiny http://www.profanity.im", - NULL } } - }, + CMD_SYN( + "/tiny ") + CMD_DESC( + "Send url as tinyurl in current chat.") + CMD_ARGS( + { "", "The url to make tiny." }) + CMD_EXAMPLES( + "Example: /tiny http://www.profanity.im") + }, { "/who", cmd_who, parse_args, 0, 2, NULL, - { - { + CMD_SYN( "/who", "/who online|offline|away|dnd|xa|chat|available|unavailable|any []", "/who moderator|participant|visitor", - "/who owner|admin|member", - NULL - }, - "Show contacts or room occupants with chosen status, role or affiliation", - { + "/who owner|admin|member") + CMD_DESC( + "Show contacts or room occupants with chosen status, role or affiliation") + CMD_ARGS( { "offline|away|dnd|xa|chat", "Show contacts or room occupants with specified presence." }, { "online", "Contacts that are online, chat, away, xa, dnd." }, { "available", "Contacts that are available for chat - online, chat." }, @@ -706,206 +674,159 @@ static struct cmd_t command_defs[] = { "any", "Contacts with any status (same as calling with no argument)." }, { "", "Filter the results by the specified roster group, not applicable in chat rooms." }, { "moderator|participant|visitor", "Room occupants with the specified role." }, - { "owner|admin|member", "Room occupants with the specified affiliation." }, - END_ARGS }, - { + { "owner|admin|member", "Room occupants with the specified affiliation." }) + CMD_EXAMPLES( "/who", "/who xa", "/who online friends", "/who any family", "/who participant", - "/who admin", - NULL } } - }, + "/who admin") + }, { "/close", cmd_close, parse_args, 0, 1, NULL, - { - { + CMD_SYN( "/close []", - "/close all|read", - NULL - }, + "/close all|read") + CMD_DESC( "Close windows. " - "Passing no argument closes the current window.", - { + "Passing no argument closes the current window.") + CMD_ARGS( { "", "Close the specified window." }, { "all", "Close all windows." }, - { "read", "Close all windows that have no unread messages." }, - END_ARGS }, - { - NULL } } - }, + { "read", "Close all windows that have no unread messages." }) + CMD_NOEXAMPLES + }, { "/clear", cmd_clear, parse_args, 0, 0, NULL, - { - { - "/clear", - NULL - }, - "Clear the current window.", - { - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/clear") + CMD_DESC( + "Clear the current window.") + CMD_NOARGS + CMD_NOEXAMPLES + }, { "/quit", cmd_quit, parse_args, 0, 0, NULL, - { - { - "/quit", - NULL - }, - "Logout of any current session, and quit Profanity.", - { - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/quit") + CMD_DESC( + "Logout of any current session, and quit Profanity.") + CMD_NOARGS + CMD_NOEXAMPLES + }, { "/privileges", cmd_privileges, parse_args, 1, 1, &cons_privileges_setting, - { - { - "/privileges on|off", - NULL - }, - "Group occupants panel by role, and show role information in chat rooms.", - { - { "on|off", "Enable or disable privilege information." }, - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/privileges on|off") + CMD_DESC( + "Group occupants panel by role, and show role information in chat rooms.") + CMD_ARGS( + { "on|off", "Enable or disable privilege information." }) + CMD_NOEXAMPLES + }, { "/beep", cmd_beep, parse_args, 1, 1, &cons_beep_setting, - { - { - "/beep on|off", - NULL - }, + CMD_SYN( + "/beep on|off") + CMD_DESC( "Switch the terminal bell on or off. " "The bell will sound when incoming messages are received. " - "If the terminal does not support sounds, it may attempt to flash the screen instead.", - { - { "on|off", "Enable or disable terminal bell." }, - END_ARGS }, - { - NULL } } - }, + "If the terminal does not support sounds, it may attempt to flash the screen instead.") + CMD_ARGS( + { "on|off", "Enable or disable terminal bell." }) + CMD_NOEXAMPLES + }, { "/encwarn", cmd_encwarn, parse_args, 1, 1, &cons_encwarn_setting, - { - { - "/encwarn on|off", - NULL - }, - "Titlebar encryption warning.", - { - { "on|off", "Enabled or disable the unencrypted warning message in the titlebar." }, - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/encwarn on|off") + CMD_DESC( + "Titlebar encryption warning.") + CMD_ARGS( + { "on|off", "Enabled or disable the unencrypted warning message in the titlebar." }) + CMD_NOEXAMPLES + }, { "/presence", cmd_presence, parse_args, 1, 1, &cons_presence_setting, - { - { - "/presence on|off", - NULL - }, - "Show the contacts presence in the titlebar.", - { - { "on|off", "Switch display of the contacts presence in the titlebar on or off." }, - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/presence on|off") + CMD_DESC( + "Show the contacts presence in the titlebar.") + CMD_ARGS( + { "on|off", "Switch display of the contacts presence in the titlebar on or off." }) + CMD_NOEXAMPLES + }, { "/wrap", cmd_wrap, parse_args, 1, 1, &cons_wrap_setting, - { - { - "/wrap on|off", - NULL - }, - "Word wrapping.", - { - { "on|off", "Enable or disable word wrapping in the main window." }, - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/wrap on|off") + CMD_DESC( + "Word wrapping.") + CMD_ARGS( + { "on|off", "Enable or disable word wrapping in the main window." }) + CMD_NOEXAMPLES + }, { "/winstidy", cmd_winstidy, parse_args, 1, 1, &cons_winstidy_setting, - { - { - "/winstidy on|off", - NULL - }, - "Auto tidy windows, when a window is closed, windows will be moved to fill the gap.", - { - { "on|off", "Enable or disable auto window tidy." }, - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/winstidy on|off") + CMD_DESC( + "Auto tidy windows, when a window is closed, windows will be moved to fill the gap.") + CMD_ARGS( + { "on|off", "Enable or disable auto window tidy." }) + CMD_NOEXAMPLES + }, { "/time", cmd_time, parse_args, 1, 3, &cons_time_setting, - { - { + CMD_SYN( "/time main set ", "/time main off", "/time statusbar set ", - "/time statusbar off", - NULL - }, + "/time statusbar off") + CMD_DESC( "Configure time display preferences. " "Time formats are strings supported by g_date_time_format. " "See https://developer.gnome.org/glib/stable/glib-GDateTime.html#g-date-time-format for more details. " "Setting the format to an unsupported string, will display the string. " - "If the format contains spaces, it must be surrounded with double quotes.", - { + "If the format contains spaces, it must be surrounded with double quotes.") + CMD_ARGS( { "main set ", "Change time format in main window." }, { "main off", "Do not show time in main window." }, { "statusbar set ", "Change time format in statusbar." }, - { "statusbar off", "Change time format in status bar." }, - END_ARGS }, - { + { "statusbar off", "Change time format in status bar." }) + CMD_EXAMPLES( "/time main set \"%d-%m-%y %H:%M\"", "/time main off", - "/time statusbar set %H:%M", - NULL } } - }, + "/time statusbar set %H:%M") + }, { "/inpblock", cmd_inpblock, parse_args, 2, 2, &cons_inpblock_setting, - { - { + CMD_SYN( "/inpblock timeout ", - "/inpblock dynamic on|off", - NULL - }, - "How long to wait for keyboard input before checking for new messages or checking for state changes such as 'idle'.", - { + "/inpblock dynamic on|off") + CMD_DESC( + "How long to wait for keyboard input before checking for new messages or checking for state changes such as 'idle'.") + CMD_ARGS( { "timeout ", "Time to wait (1-1000) in milliseconds before reading input from the terminal buffer, default: 1000." }, - { "dynamic on|off", "Start with 0 millis and dynamically increase up to timeout when no activity, default: on." }, - END_ARGS }, - { - NULL } } - }, + { "dynamic on|off", "Start with 0 millis and dynamically increase up to timeout when no activity, default: on." }) + CMD_NOEXAMPLES + }, { "/notify", cmd_notify, parse_args, 2, 3, &cons_notify_setting, - { - { + CMD_SYN( "/notify message on|off", "/notify message current on|off", "/notify message text on|off", @@ -916,11 +837,10 @@ static struct cmd_t command_defs[] = "/notify typing on|off", "/notify typing current on|off", "/notify invite on|off", - "/notify sub on|off", - NULL - }, - "Settings for various kinds of desktop notifications.", - { + "/notify sub on|off") + CMD_DESC( + "Settings for various kinds of desktop notifications.") + CMD_ARGS( { "message on|off", "Notifications for regular chat messages." }, { "message current on|off", "Whether messages in the current window trigger notifications." }, { "message text on|off", "Show message text in regular message notifications." }, @@ -931,9 +851,8 @@ static struct cmd_t command_defs[] = { "typing on|off", "Notifications when contacts are typing." }, { "typing current on|off", "Whether typing notifications are triggered for the current window." }, { "invite on|off", "Notifications for chat room invites." }, - { "sub on|off", "Notifications for subscription requests." }, - END_ARGS }, - { + { "sub on|off", "Notifications for subscription requests." }) + CMD_EXAMPLES( "/notify message on", "/notify message text on", "/notify room mention", @@ -941,198 +860,154 @@ static struct cmd_t command_defs[] = "/notify room text off", "/notify remind 10", "/notify typing on", - "/notify invite on", - NULL } } - }, + "/notify invite on") + }, { "/flash", cmd_flash, parse_args, 1, 1, &cons_flash_setting, - { - { - "/flash on|off", - NULL - }, + CMD_SYN( + "/flash on|off") + CMD_DESC( "Make the terminal flash when incoming messages are received in another window. " - "If the terminal doesn't support flashing, it may attempt to beep.", - { - { "on|off", "Enable or disable terminal flash." }, - END_ARGS }, - { - NULL } } - }, + "If the terminal doesn't support flashing, it may attempt to beep.") + CMD_ARGS( + { "on|off", "Enable or disable terminal flash." }) + CMD_NOEXAMPLES + }, { "/intype", cmd_intype, parse_args, 1, 1, &cons_intype_setting, - { - { - "/intype on|off", - NULL - }, - "Show when a contact is typing in the console, and in active message window.", - { - { "on|off", "Enable or disable contact typing messages." }, - END_ARGS }, - { - NULL } } - }, - + CMD_SYN( + "/intype on|off") + CMD_DESC( + "Show when a contact is typing in the console, and in active message window.") + CMD_ARGS( + { "on|off", "Enable or disable contact typing messages." }) + CMD_NOEXAMPLES + }, { "/splash", cmd_splash, parse_args, 1, 1, &cons_splash_setting, - { - { - "/splash on|off", - NULL - }, - "Switch on or off the ascii logo on start up and when the /about command is called.", - { - { "on|off", "Enable or disable splash logo." }, - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/splash on|off") + CMD_DESC( + "Switch on or off the ascii logo on start up and when the /about command is called.") + CMD_ARGS( + { "on|off", "Enable or disable splash logo." }) + CMD_NOEXAMPLES + }, { "/autoconnect", cmd_autoconnect, parse_args, 1, 2, &cons_autoconnect_setting, - { - { + CMD_SYN( "/autoconnect set ", - "/autoconnect off", - NULL - }, + "/autoconnect off") + CMD_DESC( "Enable or disable autoconnect on start up. " - "The setting can be overridden by the -a (--account) command line option.", - { + "The setting can be overridden by the -a (--account) command line option.") + CMD_ARGS( { "set ", "Connect with account on start up." }, - { "off", "Disable autoconnect." }, - END_ARGS }, - { + { "off", "Disable autoconnect." }) + CMD_EXAMPLES( "/autoconnect set jc@stuntteam.org", - "/autoconnect off", - NULL } } - }, + "/autoconnect off") + }, { "/vercheck", cmd_vercheck, parse_args, 0, 1, NULL, - { - { - "/vercheck on|off", - NULL - }, - "Check for new versions when Profanity starts, and when the /about command is run.", - { - { "on|off", "Enable or disable the version check." }, - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/vercheck on|off") + CMD_DESC( + "Check for new versions when Profanity starts, and when the /about command is run.") + CMD_ARGS( + { "on|off", "Enable or disable the version check." }) + CMD_NOEXAMPLES + }, { "/titlebar", cmd_titlebar, parse_args, 2, 2, &cons_titlebar_setting, - { - { + CMD_SYN( "/titlebar show on|off", - "/titlebar goodbye on|off", - NULL - }, - "Allow Profanity to modify the window title bar.", - { + "/titlebar goodbye on|off") + CMD_DESC( + "Allow Profanity to modify the window title bar.") + CMD_ARGS( { "show on|off", "Show current logged in user, and unread messages as the window title." }, - { "goodbye on|off", "Show a message in the title when exiting profanity." }, - END_ARGS }, - { - NULL } } - }, + { "goodbye on|off", "Show a message in the title when exiting profanity." }) + CMD_NOEXAMPLES + }, { "/alias", cmd_alias, parse_args_with_freetext, 1, 3, NULL, - { - { + CMD_SYN( "/alias list", "/alias add ", - "/alias remove ", - NULL - }, - "Add, remove or list command aliases.", - { + "/alias remove ") + CMD_DESC( + "Add, remove or list command aliases.") + CMD_ARGS( { "list", "List all aliases." }, { "add ", "Add a new command alias." }, - { "remove ", "Remove a command alias." }, - END_ARGS }, - { + { "remove ", "Remove a command alias." }) + CMD_EXAMPLES( "/alias add friends /who online friends", "/alias add /q /quit", "/alias a /away \"I'm in a meeting.\"", "/alias remove q", - "/alias list", - NULL } } - }, + "/alias list") + }, { "/chlog", cmd_chlog, parse_args, 1, 1, &cons_chlog_setting, - { - { - "/chlog on|off", - NULL - }, + CMD_SYN( + "/chlog on|off") + CMD_DESC( "Switch chat logging on or off. " "This setting will be enabled if /history is set to on. " "When disabling this option, /history will also be disabled. " - "See the /grlog setting for enabling logging of chat room (groupchat) messages.", - { - { "on|off", "Enable or disable chat logging." }, - END_ARGS }, - { - NULL } } - }, + "See the /grlog setting for enabling logging of chat room (groupchat) messages.") + CMD_ARGS( + { "on|off", "Enable or disable chat logging." }) + CMD_NOEXAMPLES + }, { "/grlog", cmd_grlog, parse_args, 1, 1, &cons_grlog_setting, - { - { - "/grlog on|off", - NULL - }, + CMD_SYN( + "/grlog on|off") + CMD_DESC( "Switch chat room logging on or off. " - "See the /chlog setting for enabling logging of one to one chat.", - { - { "on|off", "Enable or disable chat room logging." }, - END_ARGS }, - { - NULL } } - }, + "See the /chlog setting for enabling logging of one to one chat.") + CMD_ARGS( + { "on|off", "Enable or disable chat room logging." }) + CMD_NOEXAMPLES + }, { "/states", cmd_states, parse_args, 1, 1, &cons_states_setting, - { - { - "/states on|off", - NULL - }, - "Send chat state notifications to recipient during chat sessions, such as typing, paused, active, gone.", - { - { "on|off", "Enable or disable sending of chat state notifications." }, - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/states on|off") + CMD_DESC( + "Send chat state notifications to recipient during chat sessions, such as typing, paused, active, gone.") + CMD_ARGS( + { "on|off", "Enable or disable sending of chat state notifications." }) + CMD_NOEXAMPLES + }, { "/pgp", cmd_pgp, parse_args, 1, 3, NULL, - { - { + CMD_SYN( "/pgp libver", "/pgp keys", "/pgp fps", "/pgp setkey ", "/pgp start []", "/pgp end", - "/pgp log on|off|redact", - NULL - }, + "/pgp log on|off|redact") + CMD_DESC( "Open PGP commands to manage keys, and perform PGP encryption during chat sessions. " - "See the /account command to set your own PGP key.", - { + "See the /account command to set your own PGP key.") + CMD_ARGS( { "libver", "Show which version of the libgpgme library is being used." }, { "keys", "List all keys." }, { "fps", "Show known fingerprints." }, @@ -1140,20 +1015,17 @@ static struct cmd_t command_defs[] = { "start []", "Start PGP encrypted chat, current contact will be used if not specified." }, { "end", "End PGP encrypted chat with the current recipient." }, { "log on|off", "Enable or disable plaintext logging of PGP encrypted messages." }, - { "log redact", "Log PGP encrypted messages, but replace the contents with [redacted]. This is the default." }, - END_ARGS }, - { + { "log redact", "Log PGP encrypted messages, but replace the contents with [redacted]. This is the default." }) + CMD_EXAMPLES( "/pgp log off", "/pgp setkey buddy@buddychat.org BA19CACE5A9592C5", "/pgp start buddy@buddychat.org", - "/pgp end", - NULL } } - }, + "/pgp end") + }, { "/otr", cmd_otr, parse_args, 1, 3, NULL, - { - { + CMD_SYN( "/otr libver", "/otr gen", "/otr myfp|theirfp", @@ -1164,11 +1036,10 @@ static struct cmd_t command_defs[] = "/otr question ", "/otr answer ", "/otr policy manual|opportunistic|always", - "/otr log on|off|redact", - NULL - }, - "Off The Record (OTR) commands to manage keys, and perform OTR encryption during chat sessions.", - { + "/otr log on|off|redact") + CMD_DESC( + "Off The Record (OTR) commands to manage keys, and perform OTR encryption during chat sessions.") + CMD_ARGS( { "libver", "Show which version of the libotr library is being used." }, { "gen", "Generate your private key." }, { "myfp", "Show your fingerprint." }, @@ -1183,9 +1054,8 @@ static struct cmd_t command_defs[] = { "policy opportunistic", "Set the global OTR policy to opportunistic, and OTR sessions will be attempted upon starting a conversation." }, { "policy always", "Set the global OTR policy to always, an error will be displayed if an OTR session cannot be initiated upon starting a conversation." }, { "log on|off", "Enable or disable plaintext logging of OTR encrypted messages." }, - { "log redact", "Log OTR encrypted messages, but replace the contents with [redacted]. This is the default." }, - END_ARGS }, - { + { "log redact", "Log OTR encrypted messages, but replace the contents with [redacted]. This is the default." }) + CMD_EXAMPLES( "/otr log off", "/otr policy manual", "/otr gen", @@ -1193,205 +1063,159 @@ static struct cmd_t command_defs[] = "/otr myfp", "/otr theirfp", "/otr question \"What is the name of my rabbit?\" fiffi", - "/otr end", - NULL } } - }, + "/otr end") + }, { "/outtype", cmd_outtype, parse_args, 1, 1, &cons_outtype_setting, - { - { - "/outtype on|off", - NULL - }, - "Send typing notifications, chat states (/states) will be enabled if this setting is enabled.", - { - { "on|off", "Enable or disable sending typing notifications." }, - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/outtype on|off") + CMD_DESC( + "Send typing notifications, chat states (/states) will be enabled if this setting is enabled.") + CMD_ARGS( + { "on|off", "Enable or disable sending typing notifications." }) + CMD_NOEXAMPLES + }, { "/gone", cmd_gone, parse_args, 1, 1, &cons_gone_setting, - { - { - "/gone ", - NULL - }, + CMD_SYN( + "/gone ") + CMD_DESC( "Send a 'gone' state to the recipient after the specified number of minutes. " - "Chat states (/states) will be enabled if this setting is set.", - { - { "", "Number of minutes of inactivity before sending the 'gone' state, a value of 0 will disable sending this state." }, - END_ARGS }, - { - NULL } } - }, + "Chat states (/states) will be enabled if this setting is set.") + CMD_ARGS( + { "", "Number of minutes of inactivity before sending the 'gone' state, a value of 0 will disable sending this state." }) + CMD_NOEXAMPLES + }, { "/history", cmd_history, parse_args, 1, 1, &cons_history_setting, - { - { - "/history on|off", - NULL - }, + CMD_SYN( + "/history on|off") + CMD_DESC( "Switch chat history on or off, /chlog will automatically be enabled when this setting is on. " - "When history is enabled, previous messages are shown in chat windows.", - { - { "on|off", "Enable or disable showing chat history." }, - END_ARGS }, - { - NULL } } - }, + "When history is enabled, previous messages are shown in chat windows.") + CMD_ARGS( + { "on|off", "Enable or disable showing chat history." }) + CMD_NOEXAMPLES + }, { "/log", cmd_log, parse_args, 1, 2, &cons_log_setting, - { - { + CMD_SYN( "/log where", "/log rotate on|off", "/log maxsize ", - "/log shared on|off", - NULL - }, - "Manage profanity log settings.", - { + "/log shared on|off") + CMD_DESC( + "Manage profanity log settings.") + CMD_ARGS( { "where", "Show the current log file location." }, { "rotate on|off", "Rotate log, default on." }, { "maxsize ", "With rotate enabled, specifies the max log size, defaults to 1048580 (1MB)." }, - { "shared on|off", "Share logs between all instances, default: on. When off, the process id will be included in the log." }, - END_ARGS }, - { - NULL } } - }, + { "shared on|off", "Share logs between all instances, default: on. When off, the process id will be included in the log." }) + CMD_NOEXAMPLES + }, { "/carbons", cmd_carbons, parse_args, 1, 1, &cons_carbons_setting, - { - { - "/carbons on|off", - NULL - }, + CMD_SYN( + "/carbons on|off") + CMD_DESC( "Enable or disable message carbons. " - "Message carbons ensure that both sides of all conversations are shared with all the user's clients that implement this protocol.", - { - { "on|off", "Enable or disable message carbons." }, - END_ARGS }, - { - NULL } } - }, + "Message carbons ensure that both sides of all conversations are shared with all the user's clients that implement this protocol.") + CMD_ARGS( + { "on|off", "Enable or disable message carbons." }) + CMD_NOEXAMPLES + }, { "/receipts", cmd_receipts, parse_args, 2, 2, &cons_receipts_setting, - { - { + CMD_SYN( "/receipts request on|off", - "/receipts send on|off", - NULL - }, - "Enable or disable message delivery receipts. The interface will indicate when a message has been received.", - { + "/receipts send on|off") + CMD_DESC( + "Enable or disable message delivery receipts. The interface will indicate when a message has been received.") + CMD_ARGS( { "request on|off", "Whether or not to request a receipt upon sending a message." }, - { "send on|off", "Whether or not to send a receipt if one has been requested with a received message." }, - END_ARGS }, - { - NULL } } - }, + { "send on|off", "Whether or not to send a receipt if one has been requested with a received message." }) + CMD_NOEXAMPLES + }, { "/reconnect", cmd_reconnect, parse_args, 1, 1, &cons_reconnect_setting, - { - { - "/reconnect ", - NULL - }, - "Set the reconnect attempt interval for when the connection is lost.", - { - { "", "Number of seconds before attempting to reconnect, a value of 0 disables reconnect." }, - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/reconnect ") + CMD_DESC( + "Set the reconnect attempt interval for when the connection is lost.") + CMD_ARGS( + { "", "Number of seconds before attempting to reconnect, a value of 0 disables reconnect." }) + CMD_NOEXAMPLES + }, { "/autoping", cmd_autoping, parse_args, 1, 1, &cons_autoping_setting, - { - { - "/autoping ", - NULL - }, - "Set the interval between sending ping requests to the server to ensure the connection is kept alive.", - { - { "", "Number of seconds between sending pings, a value of 0 disables autoping." }, - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/autoping ") + CMD_DESC( + "Set the interval between sending ping requests to the server to ensure the connection is kept alive.") + CMD_ARGS( + { "", "Number of seconds between sending pings, a value of 0 disables autoping." }) + CMD_NOEXAMPLES + }, { "/ping", cmd_ping, parse_args, 0, 1, NULL, - { - { - "/ping []", - NULL - }, + CMD_SYN( + "/ping []") + CMD_DESC( "Sends an IQ ping stanza to the specified JID. " - "If no JID is supplied, your chat server will be pinged.", - { - { "", "The Jabber ID to send the ping request to." }, - END_ARGS }, - { - NULL } } - }, + "If no JID is supplied, your chat server will be pinged.") + CMD_ARGS( + { "", "The Jabber ID to send the ping request to." }) + CMD_NOEXAMPLES + }, { "/autoaway", cmd_autoaway, parse_args_with_freetext, 2, 2, &cons_autoaway_setting, - { - { + CMD_SYN( "/autoaway mode idle|away|off", "/autoaway time ", "/autoaway message |off", - "/autoaway check on|off", - NULL - }, - "Manage autoway settings for idle time.", - { + "/autoaway check on|off") + CMD_DESC( + "Manage autoway settings for idle time.") + CMD_ARGS( { "mode idle", "Sends idle time, status remains online." }, { "mode away", "Sends an away presence." }, { "mode off", "Disabled (default)." }, { "time ", "Number of minutes before the presence change is sent, default: 15." }, { "message ", "Optional message to send with the presence change, default: off (disabled)." }, { "message off", "Send no message with autoaway presence." }, - { "check on|off", "When enabled, checks for activity and sends online presence, default: on." }, - END_ARGS }, - { + { "check on|off", "When enabled, checks for activity and sends online presence, default: on." }) + CMD_EXAMPLES( "/autoaway mode idle", "/autoaway time 30", "/autoaway message I'm not really doing much", - "/autoaway check off", - NULL } } - }, + "/autoaway check off") + }, { "/priority", cmd_priority, parse_args, 1, 1, &cons_priority_setting, - { - { - "/priority ", - NULL - }, + CMD_SYN( + "/priority ") + CMD_DESC( "Set priority for the current account. " - "See the /account command for specific priority settings per presence status.", - { - { "", "Number between -128 and 127, default: 0." }, - END_ARGS }, - { - NULL } } - }, + "See the /account command for specific priority settings per presence status.") + CMD_ARGS( + { "", "Number between -128 and 127, default: 0." }) + CMD_NOEXAMPLES + }, { "/account", cmd_account, parse_args, 0, 4, NULL, - { - { + CMD_SYN( "/account", "/account list", "/account show ", @@ -1418,12 +1242,11 @@ static struct cmd_t command_defs[] = "/account clear server", "/account clear port", "/account clear otr", - "/account clear pgpkeyid", - NULL - }, + "/account clear pgpkeyid") + CMD_DESC( "Commands for creating and managing accounts. " - "Calling with no arguments will display information for the current account.", - { + "Calling with no arguments will display information for the current account.") + CMD_ARGS( { "list", "List all accounts." }, { "show ", "Show details for the specified account." }, { "enable ", "Enable the account, it will be used for autocompletion." }, @@ -1450,9 +1273,8 @@ static struct cmd_t command_defs[] = { "clear password", "Remove the password setting for this account." }, { "clear eval_password", "Remove the eval_password setting for this account." }, { "clear otr", "Remove the OTR policy setting for this account." }, - { "clear pgpkeyid", "Remove pgpkeyid associated with this account." }, - END_ARGS }, - { + { "clear pgpkeyid", "Remove pgpkeyid associated with this account." }) + CMD_EXAMPLES( "/account add me", "/account set me jid me@chatty", "/account set me server talk.chat.com", @@ -1461,174 +1283,137 @@ static struct cmd_t command_defs[] = "/account set me nick dennis", "/account set me status dnd", "/account set me dnd -1", - "/account rename me gtalk", - NULL } } - }, + "/account rename me gtalk") + }, { "/prefs", cmd_prefs, parse_args, 0, 1, NULL, - { - { - "/prefs [ui|desktop|chat|log|conn|presence]", - NULL - }, + CMD_SYN( + "/prefs [ui|desktop|chat|log|conn|presence]") + CMD_DESC( "Show preferences for different areas of functionality. " - "Passing no arguments shows all preferences.", - { + "Passing no arguments shows all preferences.") + CMD_ARGS( { "ui", "User interface preferences." }, { "desktop", "Desktop notification preferences." }, { "chat", "Chat state preferences." }, { "log", "Logging preferences." }, { "conn", "Connection handling preferences." }, - { "presence", "Chat presence preferences." }, - END_ARGS }, - { - NULL } } - }, + { "presence", "Chat presence preferences." }) + CMD_NOEXAMPLES + }, { "/theme", cmd_theme, parse_args, 1, 2, &cons_theme_setting, - { - { + CMD_SYN( "/theme list", "/theme load ", - "/theme colours", - NULL - }, - "Load a theme, includes colours and UI options.", - { + "/theme colours") + CMD_DESC( + "Load a theme, includes colours and UI options.") + CMD_ARGS( { "list", "List all available themes." }, { "load ", "Load the specified theme. 'default' will reset to the default theme." }, - { "colours", "Show the colour values as rendered by the terminal." }, - END_ARGS }, - { + { "colours", "Show the colour values as rendered by the terminal." }) + CMD_EXAMPLES( "/theme list", - "/theme load forest", - NULL } } - }, + "/theme load forest") + }, { "/statuses", cmd_statuses, parse_args, 2, 2, &cons_statuses_setting, - { - { - "/statuses console|chat|muc all|online|none", - NULL - }, + CMD_SYN( + "/statuses console|chat|muc all|online|none") + CMD_DESC( "Configure which presence changes are displayed in various windows. " - "The default is 'all' for all windows.", - { + "The default is 'all' for all windows.") + CMD_ARGS( { "console", "Configure what is displayed in the console window." }, { "chat", "Configure what is displayed in chat windows." }, { "muc", "Configure what is displayed in chat room windows." }, { "all", "Show all presence changes." }, { "online", "Show only online/offline changes." }, - { "none", "Don't show any presence changes." }, - END_ARGS }, - { + { "none", "Don't show any presence changes." }) + CMD_EXAMPLES( "/statuses console none", "/statuses chat online", - "/statuses muc all", - NULL } } - }, + "/statuses muc all") + }, { "/xmlconsole", cmd_xmlconsole, parse_args, 0, 0, NULL, - { - { - "/xmlconsole", - NULL - }, - "Open the XML console to view incoming and outgoing XMPP traffic.", - { - END_ARGS }, - { - NULL } } - }, + CMD_SYN( + "/xmlconsole") + CMD_DESC( + "Open the XML console to view incoming and outgoing XMPP traffic.") + CMD_NOARGS + CMD_NOEXAMPLES + }, { "/away", cmd_away, parse_args_with_freetext, 0, 1, NULL, - { - { - "/away []", - NULL - }, - "Set your status to 'away'.", - { - { "", "Optional message to use with the status." }, - END_ARGS }, - { + CMD_SYN( + "/away []") + CMD_DESC( + "Set your status to 'away'.") + CMD_ARGS( + { "", "Optional message to use with the status." }) + CMD_EXAMPLES( "/away", - "/away Gone for lunch", - NULL } } - }, + "/away Gone for lunch") + }, { "/chat", cmd_chat, parse_args_with_freetext, 0, 1, NULL, - { - { - "/chat []", - NULL - }, - "Set your status to 'chat' (available for chat).", - { - { "", "Optional message to use with the status." }, - END_ARGS }, - { + CMD_SYN( + "/chat []") + CMD_DESC( + "Set your status to 'chat' (available for chat).") + CMD_ARGS( + { "", "Optional message to use with the status." }) + CMD_EXAMPLES( "/chat", - "/chat Please talk to me!", - NULL } } - }, + "/chat Please talk to me!") + }, { "/dnd", cmd_dnd, parse_args_with_freetext, 0, 1, NULL, - { - { - "/dnd []", - NULL - }, - "Set your status to 'dnd' (do not disturb).", - { - { "", "Optional message to use with the status." }, - END_ARGS }, - { + CMD_SYN( + "/dnd []") + CMD_DESC( + "Set your status to 'dnd' (do not disturb).") + CMD_ARGS( + { "", "Optional message to use with the status." }) + CMD_EXAMPLES( "/dnd", - "/dnd I'm in the zone", - NULL } } - }, + "/dnd I'm in the zone") + }, { "/online", cmd_online, parse_args_with_freetext, 0, 1, NULL, - { - { - "/online []", - NULL - }, - "Set your status to 'online'.", - { - { "", "Optional message to use with the status." }, - END_ARGS }, - { + CMD_SYN( + "/online []") + CMD_DESC( + "Set your status to 'online'.") + CMD_ARGS( + { "", "Optional message to use with the status." }) + CMD_EXAMPLES( "/online", - "/online Up the Irons!", - NULL } } - }, + "/online Up the Irons!") + }, { "/xa", cmd_xa, parse_args_with_freetext, 0, 1, NULL, - { - { - "/xa []", - NULL - }, - "Set your status to 'xa' (extended away).", - { - { "", "Optional message to use with the status." }, - END_ARGS }, - { + CMD_SYN( + "/xa []") + CMD_DESC( + "Set your status to 'xa' (extended away).") + CMD_ARGS( + { "", "Optional message to use with the status." }) + CMD_EXAMPLES( "/xa", - "/xa This meeting is going to be a long one", - NULL } } - }, + "/xa This meeting is going to be a long one") + }, }; static Autocomplete commands_ac; From 8119025120b0b511aea8bc3f477d2aff835bd24b Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 27 Jul 2015 00:04:48 +0100 Subject: [PATCH 18/25] Fixed tests for new command format --- Makefile.am | 34 +- src/muc.c | 4 +- tests/unittests/test_cmd_account.c | 325 ++++------------ tests/unittests/test_cmd_alias.c | 65 +--- tests/unittests/test_cmd_bookmark.c | 58 +-- tests/unittests/test_cmd_connect.c | 539 +++++++++++--------------- tests/unittests/test_cmd_disconnect.c | 7 +- tests/unittests/test_cmd_join.c | 33 +- tests/unittests/test_cmd_otr.c | 128 ++---- tests/unittests/test_cmd_pgp.c | 27 +- tests/unittests/test_cmd_rooms.c | 20 +- tests/unittests/test_cmd_roster.c | 80 +--- tests/unittests/test_cmd_statuses.c | 79 +--- tests/unittests/test_cmd_sub.c | 15 +- tests/unittests/ui/stub_ui.c | 6 + tests/unittests/unittests.c | 8 +- 16 files changed, 465 insertions(+), 963 deletions(-) diff --git a/Makefile.am b/Makefile.am index 6fba8900..8f2ccb3f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -68,29 +68,29 @@ unittest_sources = \ tests/unittests/log/stub_log.c \ tests/unittests/config/stub_accounts.c \ tests/unittests/helpers.c tests/unittests/helpers.h \ - tests/unittests/test_cmd_account.c tests/unittests/test_cmd_account.h \ + tests/unittests/test_form.c tests/unittests/test_form.h \ + tests/unittests/test_common.c tests/unittests/test_common.h \ + tests/unittests/test_autocomplete.c tests/unittests/test_autocomplete.h \ + tests/unittests/test_jid.c tests/unittests/test_jid.h \ + tests/unittests/test_parser.c tests/unittests/test_parser.h \ + tests/unittests/test_roster_list.c tests/unittests/test_roster_list.h \ + tests/unittests/test_chat_session.c tests/unittests/test_chat_session.h \ + tests/unittests/test_contact.c tests/unittests/test_contact.h \ + tests/unittests/test_preferences.c tests/unittests/test_preferences.h \ + tests/unittests/test_server_events.c tests/unittests/test_server_events.h \ + tests/unittests/test_muc.c tests/unittests/test_muc.h \ + tests/unittests/test_cmd_statuses.c tests/unittests/test_cmd_statuses.h \ tests/unittests/test_cmd_alias.c tests/unittests/test_cmd_alias.h \ - tests/unittests/test_cmd_bookmark.c tests/unittests/test_cmd_bookmark.h \ tests/unittests/test_cmd_connect.c tests/unittests/test_cmd_connect.h \ - tests/unittests/test_cmd_join.c tests/unittests/test_cmd_join.h \ + tests/unittests/test_cmd_rooms.c tests/unittests/test_cmd_rooms.h \ + tests/unittests/test_cmd_account.c tests/unittests/test_cmd_account.h \ + tests/unittests/test_cmd_sub.c tests/unittests/test_cmd_sub.h \ + tests/unittests/test_cmd_bookmark.c tests/unittests/test_cmd_bookmark.h \ tests/unittests/test_cmd_otr.c tests/unittests/test_cmd_otr.h \ tests/unittests/test_cmd_pgp.c tests/unittests/test_cmd_pgp.h \ - tests/unittests/test_cmd_rooms.c tests/unittests/test_cmd_rooms.h \ + tests/unittests/test_cmd_join.c tests/unittests/test_cmd_join.h \ tests/unittests/test_cmd_roster.c tests/unittests/test_cmd_roster.h \ - tests/unittests/test_cmd_statuses.c tests/unittests/test_cmd_statuses.h \ - tests/unittests/test_cmd_sub.c tests/unittests/test_cmd_sub.h \ tests/unittests/test_cmd_disconnect.c tests/unittests/test_cmd_disconnect.h \ - tests/unittests/test_common.c tests/unittests/test_common.h \ - tests/unittests/test_contact.c tests/unittests/test_contact.h \ - tests/unittests/test_form.c tests/unittests/test_form.h \ - tests/unittests/test_jid.c tests/unittests/test_jid.h \ - tests/unittests/test_muc.c tests/unittests/test_muc.h \ - tests/unittests/test_parser.c tests/unittests/test_parser.h \ - tests/unittests/test_preferences.c tests/unittests/test_preferences.h \ - tests/unittests/test_roster_list.c tests/unittests/test_roster_list.h \ - tests/unittests/test_server_events.c tests/unittests/test_server_events.h \ - tests/unittests/test_autocomplete.c tests/unittests/test_autocomplete.h \ - tests/unittests/test_chat_session.c tests/unittests/test_chat_session.h \ tests/unittests/unittests.c functionaltest_sources = \ diff --git a/src/muc.c b/src/muc.c index 4474976d..8bc530aa 100644 --- a/src/muc.c +++ b/src/muc.c @@ -166,7 +166,9 @@ void muc_invites_clear(void) { autocomplete_clear(invite_ac); - g_hash_table_remove_all(invite_passwords); + if (invite_passwords) { + g_hash_table_remove_all(invite_passwords); + } } void diff --git a/tests/unittests/test_cmd_account.c b/tests/unittests/test_cmd_account.c index 51213eb5..effce3ac 100644 --- a/tests/unittests/test_cmd_account.c +++ b/tests/unittests/test_cmd_account.c @@ -15,26 +15,23 @@ #include "command/commands.h" +#define CMD_ACCOUNT "/account" + void cmd_account_shows_usage_when_not_connected_and_no_args(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { NULL }; will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_shows_account_when_connected_and_no_args(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL, NULL, TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL); gchar *args[] = { NULL }; @@ -46,15 +43,12 @@ void cmd_account_shows_account_when_connected_and_no_args(void **state) expect_memory(cons_show_account, account, account, sizeof(ProfAccount)); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_list_shows_accounts(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "list", NULL }; gchar **accounts = malloc(sizeof(gchar *) * 4); @@ -67,29 +61,22 @@ void cmd_account_list_shows_accounts(void **state) expect_memory(cons_show_account_list, accounts, accounts, sizeof(accounts)); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_show_shows_usage_when_no_arg(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "show", NULL }; - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_show_shows_message_when_account_does_not_exist(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "show", "account_name", NULL }; expect_any(accounts_get_account, name); @@ -98,15 +85,12 @@ void cmd_account_show_shows_message_when_account_does_not_exist(void **state) expect_cons_show("No such account."); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_show_shows_account_when_exists(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "show", "account_name", NULL }; ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL, NULL, TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL); @@ -116,29 +100,22 @@ void cmd_account_show_shows_account_when_exists(void **state) expect_memory(cons_show_account, account, account, sizeof(account)); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_add_shows_usage_when_no_arg(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "add", NULL }; - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_add_adds_account(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "add", "new_account", NULL }; expect_string(accounts_add, jid, "new_account"); @@ -147,29 +124,22 @@ void cmd_account_add_adds_account(void **state) expect_cons_show("Account created."); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_enable_shows_usage_when_no_arg(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "enable", NULL }; - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_enable_enables_account(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "enable", "account_name", NULL }; expect_string(accounts_enable, name, "account_name"); @@ -178,15 +148,12 @@ void cmd_account_enable_enables_account(void **state) expect_cons_show("Account enabled."); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_enable_shows_message_when_account_doesnt_exist(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "enable", "account_name", NULL }; expect_any(accounts_enable, name); @@ -195,29 +162,22 @@ void cmd_account_enable_shows_message_when_account_doesnt_exist(void **state) expect_cons_show("No such account: account_name"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_disable_shows_usage_when_no_arg(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "disable", NULL }; - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_disable_disables_account(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "disable", "account_name", NULL }; expect_string(accounts_disable, name, "account_name"); @@ -226,15 +186,12 @@ void cmd_account_disable_disables_account(void **state) expect_cons_show("Account disabled."); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_disable_shows_message_when_account_doesnt_exist(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "disable", "account_name", NULL }; expect_any(accounts_disable, name); @@ -243,43 +200,32 @@ void cmd_account_disable_shows_message_when_account_doesnt_exist(void **state) expect_cons_show("No such account: account_name"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_rename_shows_usage_when_no_args(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "rename", NULL }; - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_rename_shows_usage_when_one_arg(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "rename", "original_name", NULL }; - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_rename_renames_account(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "rename", "original_name", "new_name", NULL }; expect_string(accounts_rename, account_name, "original_name"); @@ -289,15 +235,12 @@ void cmd_account_rename_renames_account(void **state) expect_cons_show("Account renamed."); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_rename_shows_message_when_not_renamed(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "rename", "original_name", "new_name", NULL }; expect_any(accounts_rename, account_name); @@ -307,57 +250,42 @@ void cmd_account_rename_shows_message_when_not_renamed(void **state) expect_cons_show("Either account original_name doesn't exist, or account new_name already exists."); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_shows_usage_when_no_args(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "set", NULL }; - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_shows_usage_when_one_arg(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "set", "a_account", NULL }; - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_shows_usage_when_two_args(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "set", "a_account", "a_property", NULL }; - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_shows_message_when_account_doesnt_exist(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "a_property", "a_value", NULL }; expect_string(accounts_account_exists, account_name, "a_account"); @@ -366,15 +294,12 @@ void cmd_account_set_shows_message_when_account_doesnt_exist(void **state) expect_cons_show("Account a_account doesn't exist"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_jid_shows_message_for_malformed_jid(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "jid", "@malformed", NULL }; expect_any(accounts_account_exists, account_name); @@ -382,15 +307,12 @@ void cmd_account_set_jid_shows_message_for_malformed_jid(void **state) expect_cons_show("Malformed jid: @malformed"); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_jid_sets_barejid(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "jid", "a_local@a_domain", NULL }; expect_any(accounts_account_exists, account_name); @@ -402,15 +324,12 @@ void cmd_account_set_jid_sets_barejid(void **state) expect_cons_show("Updated jid for account a_account: a_local@a_domain"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_jid_sets_resource(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "jid", "a_local@a_domain/a_resource", NULL }; expect_any(accounts_account_exists, account_name); @@ -427,15 +346,12 @@ void cmd_account_set_jid_sets_resource(void **state) expect_cons_show("Updated resource for account a_account: a_resource"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_server_sets_server(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "server", "a_server", NULL }; expect_any(accounts_account_exists, account_name); @@ -447,15 +363,12 @@ void cmd_account_set_server_sets_server(void **state) expect_cons_show("Updated server for account a_account: a_server"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_resource_sets_resource(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "resource", "a_resource", NULL }; will_return(jabber_get_connection_status, JABBER_DISCONNECTED); @@ -469,15 +382,12 @@ void cmd_account_set_resource_sets_resource(void **state) expect_cons_show("Updated resource for account a_account: a_resource"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_resource_sets_resource_with_online_message(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "resource", "a_resource", NULL }; will_return(jabber_get_connection_status, JABBER_CONNECTED); @@ -491,15 +401,12 @@ void cmd_account_set_resource_sets_resource_with_online_message(void **state) expect_cons_show("Updated resource for account a_account: a_resource, you will need to reconnect to pick up the change."); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_password_sets_password(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "password", "a_password", NULL }; ProfAccount *account = account_new("a_account", NULL, NULL, NULL, TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL); @@ -517,20 +424,16 @@ void cmd_account_set_password_sets_password(void **state) expect_cons_show("Updated password for account a_account"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_eval_password_sets_eval_password(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "eval_password", "a_password", NULL }; ProfAccount *account = account_new("a_account", NULL, NULL, NULL, TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - expect_any(accounts_account_exists, account_name); will_return(accounts_account_exists, TRUE); @@ -543,19 +446,15 @@ void cmd_account_set_eval_password_sets_eval_password(void **state) expect_cons_show("Updated eval_password for account a_account"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_password_when_eval_password_set(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "password", "a_password", NULL }; ProfAccount *account = account_new("a_account", NULL, NULL, "a_password", TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - expect_any(accounts_account_exists, account_name); will_return(accounts_account_exists, TRUE); @@ -564,19 +463,15 @@ void cmd_account_set_password_when_eval_password_set(void **state) { expect_cons_show("Cannot set password when eval_password is set."); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_eval_password_when_password_set(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "eval_password", "a_password", NULL }; ProfAccount *account = account_new("a_account", NULL, "a_password", NULL, TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - expect_any(accounts_account_exists, account_name); will_return(accounts_account_exists, TRUE); @@ -585,15 +480,12 @@ void cmd_account_set_eval_password_when_password_set(void **state) { expect_cons_show("Cannot set eval_password when password is set."); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_muc_sets_muc(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "muc", "a_muc", NULL }; expect_any(accounts_account_exists, account_name); @@ -605,15 +497,12 @@ void cmd_account_set_muc_sets_muc(void **state) expect_cons_show("Updated muc service for account a_account: a_muc"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_nick_sets_nick(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "nick", "a_nick", NULL }; expect_any(accounts_account_exists, account_name); @@ -625,29 +514,22 @@ void cmd_account_set_nick_sets_nick(void **state) expect_cons_show("Updated muc nick for account a_account: a_nick"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_show_message_for_missing_otr_policy(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "Some usage"; gchar *args[] = { "set", "a_account", "otr", NULL }; - expect_cons_show("Usage: Some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_show_message_for_invalid_otr_policy(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "otr", "bad_otr_policy", NULL }; expect_any(accounts_account_exists, account_name); @@ -655,15 +537,12 @@ void cmd_account_show_message_for_invalid_otr_policy(void **state) expect_cons_show("OTR policy must be one of: manual, opportunistic or always."); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_otr_sets_otr(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "otr", "opportunistic", NULL }; expect_any(accounts_account_exists, account_name); @@ -675,15 +554,12 @@ void cmd_account_set_otr_sets_otr(void **state) expect_cons_show("Updated OTR policy for account a_account: opportunistic"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_status_shows_message_when_invalid_status(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "status", "bad_status", NULL }; expect_any(accounts_account_exists, account_name); @@ -692,15 +568,12 @@ void cmd_account_set_status_shows_message_when_invalid_status(void **state) expect_cons_show("Invalid status: bad_status"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_status_sets_status_when_valid(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "status", "away", NULL }; expect_any(accounts_account_exists, account_name); @@ -712,15 +585,12 @@ void cmd_account_set_status_sets_status_when_valid(void **state) expect_cons_show("Updated login status for account a_account: away"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_status_sets_status_when_last(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "status", "last", NULL }; expect_any(accounts_account_exists, account_name); @@ -732,15 +602,12 @@ void cmd_account_set_status_sets_status_when_last(void **state) expect_cons_show("Updated login status for account a_account: last"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_invalid_presence_string_priority_shows_message(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "blah", "10", NULL }; expect_any(accounts_account_exists, account_name); @@ -749,15 +616,12 @@ void cmd_account_set_invalid_presence_string_priority_shows_message(void **state expect_cons_show("Invalid property: blah"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_last_priority_shows_message(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "last", "10", NULL }; expect_any(accounts_account_exists, account_name); @@ -766,15 +630,12 @@ void cmd_account_set_last_priority_shows_message(void **state) expect_cons_show("Invalid property: last"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_online_priority_sets_preference(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "online", "10", NULL }; expect_any(accounts_account_exists, account_name); @@ -788,15 +649,12 @@ void cmd_account_set_online_priority_sets_preference(void **state) expect_cons_show("Updated online priority for account a_account: 10"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_chat_priority_sets_preference(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "chat", "10", NULL }; expect_any(accounts_account_exists, account_name); @@ -810,15 +668,12 @@ void cmd_account_set_chat_priority_sets_preference(void **state) expect_cons_show("Updated chat priority for account a_account: 10"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_away_priority_sets_preference(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "away", "10", NULL }; expect_any(accounts_account_exists, account_name); @@ -832,15 +687,12 @@ void cmd_account_set_away_priority_sets_preference(void **state) expect_cons_show("Updated away priority for account a_account: 10"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_xa_priority_sets_preference(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "xa", "10", NULL }; expect_any(accounts_account_exists, account_name); @@ -854,15 +706,12 @@ void cmd_account_set_xa_priority_sets_preference(void **state) expect_cons_show("Updated xa priority for account a_account: 10"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_dnd_priority_sets_preference(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "dnd", "10", NULL }; expect_any(accounts_account_exists, account_name); @@ -876,15 +725,12 @@ void cmd_account_set_dnd_priority_sets_preference(void **state) expect_cons_show("Updated dnd priority for account a_account: 10"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_priority_too_low_shows_message(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "online", "-150", NULL }; expect_any(accounts_account_exists, account_name); @@ -892,15 +738,12 @@ void cmd_account_set_priority_too_low_shows_message(void **state) expect_cons_show("Value -150 out of range. Must be in -128..127."); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_priority_too_high_shows_message(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "online", "150", NULL }; expect_any(accounts_account_exists, account_name); @@ -908,15 +751,12 @@ void cmd_account_set_priority_too_high_shows_message(void **state) expect_cons_show("Value 150 out of range. Must be in -128..127."); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_priority_when_not_number_shows_message(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "online", "abc", NULL }; expect_any(accounts_account_exists, account_name); @@ -924,15 +764,12 @@ void cmd_account_set_priority_when_not_number_shows_message(void **state) expect_cons_show("Could not convert \"abc\" to a number."); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_priority_when_empty_shows_message(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "online", "", NULL }; expect_any(accounts_account_exists, account_name); @@ -940,18 +777,14 @@ void cmd_account_set_priority_when_empty_shows_message(void **state) expect_cons_show("Could not convert \"\" to a number."); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_set_priority_updates_presence_when_account_connected_with_presence(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "set", "a_account", "online", "10", NULL }; - expect_any(accounts_account_exists, account_name); will_return(accounts_account_exists, TRUE); @@ -984,43 +817,32 @@ void cmd_account_set_priority_updates_presence_when_account_connected_with_prese expect_cons_show("Updated online priority for account a_account: 10"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_clear_shows_usage_when_no_args(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "clear", NULL }; - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_clear_shows_usage_when_one_arg(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "clear", "a_account", NULL }; - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ACCOUNT); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_clear_shows_message_when_account_doesnt_exist(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "clear", "a_account", "a_property", NULL }; expect_string(accounts_account_exists, account_name, "a_account"); @@ -1029,15 +851,12 @@ void cmd_account_clear_shows_message_when_account_doesnt_exist(void **state) expect_cons_show("Account a_account doesn't exist"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } void cmd_account_clear_shows_message_when_invalid_property(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "clear", "a_account", "badproperty", NULL }; expect_any(accounts_account_exists, account_name); @@ -1046,8 +865,6 @@ void cmd_account_clear_shows_message_when_invalid_property(void **state) expect_cons_show("Invalid property: badproperty"); expect_cons_show(""); - gboolean result = cmd_account(NULL, args, *help); + gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); - - free(help); } diff --git a/tests/unittests/test_cmd_alias.c b/tests/unittests/test_cmd_alias.c index 37513f8d..fd8f824f 100644 --- a/tests/unittests/test_cmd_alias.c +++ b/tests/unittests/test_cmd_alias.c @@ -16,82 +16,63 @@ #include "command/command.h" #include "command/commands.h" +#define CMD_ALIAS "/alias" + void cmd_alias_add_shows_usage_when_no_args(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "add", NULL }; - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ALIAS); - gboolean result = cmd_alias(NULL, args, *help); + gboolean result = cmd_alias(NULL, CMD_ALIAS, args); assert_true(result); - - free(help); } void cmd_alias_add_shows_usage_when_no_value(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "add", "alias", NULL }; - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ALIAS); - gboolean result = cmd_alias(NULL, args, *help); + gboolean result = cmd_alias(NULL, CMD_ALIAS, args); assert_true(result); - - free(help); } void cmd_alias_remove_shows_usage_when_no_args(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "remove", NULL }; - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ALIAS); - gboolean result = cmd_alias(NULL, args, *help); + gboolean result = cmd_alias(NULL, CMD_ALIAS, args); assert_true(result); - - free(help); } void cmd_alias_show_usage_when_invalid_subcmd(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "blah", NULL }; - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ALIAS); - gboolean result = cmd_alias(NULL, args, *help); + gboolean result = cmd_alias(NULL, CMD_ALIAS, args); assert_true(result); - - free(help); } void cmd_alias_add_adds_alias(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "add", "hc", "/help commands", NULL }; expect_cons_show("Command alias added /hc -> /help commands"); - gboolean result = cmd_alias(NULL, args, *help); + gboolean result = cmd_alias(NULL, CMD_ALIAS, args); + assert_true(result); char *returned_val = prefs_get_alias("hc"); - - assert_true(result); assert_string_equal("/help commands", returned_val); - - free(help); } void cmd_alias_add_shows_message_when_exists(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "add", "hc", "/help commands", NULL }; cmd_init(); @@ -100,47 +81,37 @@ void cmd_alias_add_shows_message_when_exists(void **state) expect_cons_show("Command or alias '/hc' already exists."); - gboolean result = cmd_alias(NULL, args, *help); + gboolean result = cmd_alias(NULL, CMD_ALIAS, args); assert_true(result); - - free(help); } void cmd_alias_remove_removes_alias(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "remove", "hn", NULL }; prefs_add_alias("hn", "/help navigation"); expect_cons_show("Command alias removed -> /hn"); - gboolean result = cmd_alias(NULL, args, *help); + gboolean result = cmd_alias(NULL, CMD_ALIAS, args); + assert_true(result); char *returned_val = prefs_get_alias("hn"); - - assert_true(result); assert_null(returned_val); - - free(help); } void cmd_alias_remove_shows_message_when_no_alias(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "remove", "hn", NULL }; expect_cons_show("No such command alias /hn"); - gboolean result = cmd_alias(NULL, args, *help); + gboolean result = cmd_alias(NULL, CMD_ALIAS, args); assert_true(result); - - free(help); } void cmd_alias_list_shows_all_aliases(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "list", NULL }; prefs_add_alias("vy", "/vercheck on"); @@ -152,8 +123,6 @@ void cmd_alias_list_shows_all_aliases(void **state) // write a custom checker to check the correct list is passed expect_any(cons_show_aliases, aliases); - gboolean result = cmd_alias(NULL, args, *help); + gboolean result = cmd_alias(NULL, CMD_ALIAS, args); assert_true(result); - - free(help); } diff --git a/tests/unittests/test_cmd_bookmark.c b/tests/unittests/test_cmd_bookmark.c index 04326f98..eafae9b6 100644 --- a/tests/unittests/test_cmd_bookmark.c +++ b/tests/unittests/test_cmd_bookmark.c @@ -20,17 +20,15 @@ #include "helpers.h" +#define CMD_BOOKMARK "/bookmark" + static void test_with_connection_status(jabber_conn_status_t status) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - will_return(jabber_get_connection_status, status); expect_cons_show("You are not currently connected."); - gboolean result = cmd_bookmark(NULL, NULL, *help); + gboolean result = cmd_bookmark(NULL, CMD_BOOKMARK, NULL); assert_true(result); - - free(help); } void cmd_bookmark_shows_message_when_disconnected(void **state) @@ -60,20 +58,16 @@ void cmd_bookmark_shows_message_when_undefined(void **state) void cmd_bookmark_shows_usage_when_no_args(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { NULL }; ProfWin window; window.type = WIN_CONSOLE; will_return(jabber_get_connection_status, JABBER_CONNECTED); - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_BOOKMARK); - gboolean result = cmd_bookmark(&window, args, *help); + gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args); assert_true(result); - - free(help); } static void _free_bookmark(Bookmark *bookmark) @@ -101,7 +95,6 @@ _cmp_bookmark(Bookmark *bm1, Bookmark *bm2) void cmd_bookmark_list_shows_bookmarks(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "list", NULL }; GList *bookmarks = NULL; ProfWin window; @@ -141,17 +134,15 @@ void cmd_bookmark_list_shows_bookmarks(void **state) glist_set_cmp((GCompareFunc)_cmp_bookmark); expect_any(cons_show_bookmarks, list); - gboolean result = cmd_bookmark(&window, args, *help); + gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args); assert_true(result); - free(help); g_list_free_full(bookmarks, (GDestroyNotify)_free_bookmark); } void cmd_bookmark_add_shows_message_when_invalid_jid(void **state) { char *jid = "room"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "add", jid, NULL }; ProfWin window; window.type = WIN_CONSOLE; @@ -160,16 +151,13 @@ void cmd_bookmark_add_shows_message_when_invalid_jid(void **state) expect_cons_show("Can't add bookmark with JID 'room'; should be 'room@domain.tld'"); - gboolean result = cmd_bookmark(&window, args, *help); + gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args); assert_true(result); - - free(help); } void cmd_bookmark_add_adds_bookmark_with_jid(void **state) { char *jid = "room@conf.server"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "add", jid, NULL }; ProfWin window; window.type = WIN_CONSOLE; @@ -184,16 +172,14 @@ void cmd_bookmark_add_adds_bookmark_with_jid(void **state) expect_cons_show("Bookmark added for room@conf.server."); - gboolean result = cmd_bookmark(&window, args, *help); + gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args); assert_true(result); - - free(help); } void cmd_bookmark_add_adds_bookmark_with_jid_nick(void **state) -{ char *jid = "room@conf.server"; +{ + char *jid = "room@conf.server"; char *nick = "bob"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "add", jid, "nick", nick, NULL }; ProfWin window; window.type = WIN_CONSOLE; @@ -208,16 +194,13 @@ void cmd_bookmark_add_adds_bookmark_with_jid_nick(void **state) expect_cons_show("Bookmark added for room@conf.server."); - gboolean result = cmd_bookmark(&window, args, *help); + gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args); assert_true(result); - - free(help); } void cmd_bookmark_add_adds_bookmark_with_jid_autojoin(void **state) { char *jid = "room@conf.server"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "add", jid, "autojoin", "on", NULL }; ProfWin window; window.type = WIN_CONSOLE; @@ -232,17 +215,14 @@ void cmd_bookmark_add_adds_bookmark_with_jid_autojoin(void **state) expect_cons_show("Bookmark added for room@conf.server."); - gboolean result = cmd_bookmark(&window, args, *help); + gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args); assert_true(result); - - free(help); } void cmd_bookmark_add_adds_bookmark_with_jid_nick_autojoin(void **state) { char *jid = "room@conf.server"; char *nick = "bob"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "add", jid, "nick", nick, "autojoin", "on", NULL }; ProfWin window; window.type = WIN_CONSOLE; @@ -257,16 +237,13 @@ void cmd_bookmark_add_adds_bookmark_with_jid_nick_autojoin(void **state) expect_cons_show("Bookmark added for room@conf.server."); - gboolean result = cmd_bookmark(&window, args, *help); + gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args); assert_true(result); - - free(help); } void cmd_bookmark_remove_removes_bookmark(void **state) { char *jid = "room@conf.server"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "remove", jid, NULL }; ProfWin window; window.type = WIN_CONSOLE; @@ -278,16 +255,13 @@ void cmd_bookmark_remove_removes_bookmark(void **state) expect_cons_show("Bookmark removed for room@conf.server."); - gboolean result = cmd_bookmark(&window, args, *help); + gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args); assert_true(result); - - free(help); } void cmd_bookmark_remove_shows_message_when_no_bookmark(void **state) { char *jid = "room@conf.server"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "remove", jid, NULL }; ProfWin window; window.type = WIN_CONSOLE; @@ -299,8 +273,6 @@ void cmd_bookmark_remove_shows_message_when_no_bookmark(void **state) expect_cons_show("No bookmark exists for room@conf.server."); - gboolean result = cmd_bookmark(&window, args, *help); + gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args); assert_true(result); - - free(help); } diff --git a/tests/unittests/test_cmd_connect.c b/tests/unittests/test_cmd_connect.c index b812bf23..88ae75d2 100644 --- a/tests/unittests/test_cmd_connect.c +++ b/tests/unittests/test_cmd_connect.c @@ -14,18 +14,16 @@ #include "command/commands.h" #include "config/accounts.h" +#define CMD_CONNECT "/connect" + static void test_with_connection_status(jabber_conn_status_t status) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - will_return(jabber_get_connection_status, status); expect_cons_show("You are either connected already, or a login is in process."); - gboolean result = cmd_connect(NULL, NULL, *help); + gboolean result = cmd_connect(NULL, CMD_CONNECT, NULL); assert_true(result); - - free(help); } void cmd_connect_shows_message_when_disconnecting(void **state) @@ -48,209 +46,8 @@ void cmd_connect_shows_message_when_undefined(void **state) test_with_connection_status(JABBER_UNDEFINED); } -void cmd_connect_shows_usage_when_no_server_value(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; - gchar *args[] = { "user@server.org", "server", NULL }; - - will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - - expect_cons_show("Usage: some usage"); - expect_cons_show(""); - - gboolean result = cmd_connect(NULL, args, *help); - assert_true(result); - - free(help); -} - -void cmd_connect_shows_usage_when_server_no_port_value(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; - gchar *args[] = { "user@server.org", "server", "aserver", "port", NULL }; - - will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - - expect_cons_show("Usage: some usage"); - expect_cons_show(""); - - gboolean result = cmd_connect(NULL, args, *help); - assert_true(result); - - free(help); -} - -void cmd_connect_shows_usage_when_no_port_value(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; - gchar *args[] = { "user@server.org", "port", NULL }; - - will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - - expect_cons_show("Usage: some usage"); - expect_cons_show(""); - - gboolean result = cmd_connect(NULL, args, *help); - assert_true(result); - - free(help); -} - -void cmd_connect_shows_usage_when_port_no_server_value(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; - gchar *args[] = { "user@server.org", "port", "5678", "server", NULL }; - - will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - - expect_cons_show("Usage: some usage"); - expect_cons_show(""); - - gboolean result = cmd_connect(NULL, args, *help); - assert_true(result); - - free(help); -} - -void cmd_connect_shows_message_when_port_0(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "user@server.org", "port", "0", NULL }; - - will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - - expect_cons_show("Value 0 out of range. Must be in 1..65535."); - expect_cons_show(""); - - gboolean result = cmd_connect(NULL, args, *help); - assert_true(result); - - free(help); -} - -void cmd_connect_shows_message_when_port_minus1(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "user@server.org", "port", "-1", NULL }; - - will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - - expect_cons_show("Value -1 out of range. Must be in 1..65535."); - expect_cons_show(""); - - gboolean result = cmd_connect(NULL, args, *help); - assert_true(result); - - free(help); -} - -void cmd_connect_shows_message_when_port_65536(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "user@server.org", "port", "65536", NULL }; - - will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - - expect_cons_show("Value 65536 out of range. Must be in 1..65535."); - expect_cons_show(""); - - gboolean result = cmd_connect(NULL, args, *help); - assert_true(result); - - free(help); -} - -void cmd_connect_shows_message_when_port_contains_chars(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "user@server.org", "port", "52f66", NULL }; - - will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - - expect_cons_show("Could not convert \"52f66\" to a number."); - expect_cons_show(""); - - gboolean result = cmd_connect(NULL, args, *help); - assert_true(result); - - free(help); -} - -void cmd_connect_shows_usage_when_server_provided_twice(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; - gchar *args[] = { "user@server.org", "server", "server1", "server", "server2", NULL }; - - will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - - expect_cons_show("Usage: some usage"); - expect_cons_show(""); - - gboolean result = cmd_connect(NULL, args, *help); - assert_true(result); - - free(help); -} - -void cmd_connect_shows_usage_when_port_provided_twice(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; - gchar *args[] = { "user@server.org", "port", "1111", "port", "1111", NULL }; - - will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - - expect_cons_show("Usage: some usage"); - expect_cons_show(""); - - gboolean result = cmd_connect(NULL, args, *help); - assert_true(result); - - free(help); -} - -void cmd_connect_shows_usage_when_invalid_first_property(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; - gchar *args[] = { "user@server.org", "wrong", "server", NULL }; - - will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - - expect_cons_show("Usage: some usage"); - expect_cons_show(""); - - gboolean result = cmd_connect(NULL, args, *help); - assert_true(result); - - free(help); -} - -void cmd_connect_shows_usage_when_invalid_second_property(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; - gchar *args[] = { "user@server.org", "server", "aserver", "wrong", "1234", NULL }; - - will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - - expect_cons_show("Usage: some usage"); - expect_cons_show(""); - - gboolean result = cmd_connect(NULL, args, *help); - assert_true(result); - - free(help); -} - void cmd_connect_when_no_account(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "user@server.org", NULL }; will_return(jabber_get_connection_status, JABBER_DISCONNECTED); @@ -268,93 +65,12 @@ void cmd_connect_when_no_account(void **state) expect_value(jabber_connect_with_details, port, 0); will_return(jabber_connect_with_details, JABBER_CONNECTING); - gboolean result = cmd_connect(NULL, args, *help); + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); assert_true(result); - - free(help); -} - -void cmd_connect_with_server_when_provided(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "user@server.org", "server", "aserver", NULL }; - - will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - - expect_string(accounts_get_account, name, "user@server.org"); - will_return(accounts_get_account, NULL); - - will_return(ui_ask_password, strdup("password")); - - expect_cons_show("Connecting as user@server.org"); - - expect_string(jabber_connect_with_details, jid, "user@server.org"); - expect_string(jabber_connect_with_details, passwd, "password"); - expect_string(jabber_connect_with_details, altdomain, "aserver"); - expect_value(jabber_connect_with_details, port, 0); - will_return(jabber_connect_with_details, JABBER_CONNECTING); - - gboolean result = cmd_connect(NULL, args, *help); - assert_true(result); - - free(help); -} - -void cmd_connect_with_port_when_provided(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "user@server.org", "port", "5432", NULL }; - - will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - - expect_string(accounts_get_account, name, "user@server.org"); - will_return(accounts_get_account, NULL); - - will_return(ui_ask_password, strdup("password")); - - expect_cons_show("Connecting as user@server.org"); - - expect_string(jabber_connect_with_details, jid, "user@server.org"); - expect_string(jabber_connect_with_details, passwd, "password"); - expect_value(jabber_connect_with_details, altdomain, NULL); - expect_value(jabber_connect_with_details, port, 5432); - will_return(jabber_connect_with_details, JABBER_CONNECTING); - - gboolean result = cmd_connect(NULL, args, *help); - assert_true(result); - - free(help); -} - -void cmd_connect_with_server_and_port_when_provided(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "user@server.org", "port", "5432", "server", "aserver", NULL }; - - will_return(jabber_get_connection_status, JABBER_DISCONNECTED); - - expect_string(accounts_get_account, name, "user@server.org"); - will_return(accounts_get_account, NULL); - - will_return(ui_ask_password, strdup("password")); - - expect_cons_show("Connecting as user@server.org"); - - expect_string(jabber_connect_with_details, jid, "user@server.org"); - expect_string(jabber_connect_with_details, passwd, "password"); - expect_string(jabber_connect_with_details, altdomain, "aserver"); - expect_value(jabber_connect_with_details, port, 5432); - will_return(jabber_connect_with_details, JABBER_CONNECTING); - - gboolean result = cmd_connect(NULL, args, *help); - assert_true(result); - - free(help); } void cmd_connect_fail_message(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "user@server.org", NULL }; will_return(jabber_get_connection_status, JABBER_DISCONNECTED); @@ -374,15 +90,12 @@ void cmd_connect_fail_message(void **state) expect_cons_show_error("Connection attempt for user@server.org failed."); - gboolean result = cmd_connect(NULL, args, *help); + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); assert_true(result); - - free(help); } void cmd_connect_lowercases_argument(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "USER@server.ORG", NULL }; will_return(jabber_get_connection_status, JABBER_DISCONNECTED); @@ -400,15 +113,12 @@ void cmd_connect_lowercases_argument(void **state) expect_any(jabber_connect_with_details, port); will_return(jabber_connect_with_details, JABBER_CONNECTING); - gboolean result = cmd_connect(NULL, args, *help); + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); assert_true(result); - - free(help); } void cmd_connect_asks_password_when_not_in_account(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "jabber_org", NULL }; ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL, NULL, TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL); @@ -425,15 +135,237 @@ void cmd_connect_asks_password_when_not_in_account(void **state) expect_any(jabber_connect_with_account, account); will_return(jabber_connect_with_account, JABBER_CONNECTING); - gboolean result = cmd_connect(NULL, args, *help); + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); assert_true(result); +} - free(help); +void cmd_connect_shows_usage_when_no_server_value(void **state) +{ + gchar *args[] = { "user@server.org", "server", NULL }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT); + expect_cons_show(""); + + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); + assert_true(result); +} + +void cmd_connect_shows_usage_when_server_no_port_value(void **state) +{ + gchar *args[] = { "user@server.org", "server", "aserver", "port", NULL }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT); + expect_cons_show(""); + + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); + assert_true(result); +} + +void cmd_connect_shows_usage_when_no_port_value(void **state) +{ + gchar *args[] = { "user@server.org", "port", NULL }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT); + expect_cons_show(""); + + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); + assert_true(result); +} + +void cmd_connect_shows_usage_when_port_no_server_value(void **state) +{ + gchar *args[] = { "user@server.org", "port", "5678", "server", NULL }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT); + expect_cons_show(""); + + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); + assert_true(result); +} + +void cmd_connect_shows_message_when_port_0(void **state) +{ + gchar *args[] = { "user@server.org", "port", "0", NULL }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_cons_show("Value 0 out of range. Must be in 1..65535."); + expect_cons_show(""); + + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); + assert_true(result); +} + +void cmd_connect_shows_message_when_port_minus1(void **state) +{ + gchar *args[] = { "user@server.org", "port", "-1", NULL }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_cons_show("Value -1 out of range. Must be in 1..65535."); + expect_cons_show(""); + + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); + assert_true(result); +} + +void cmd_connect_shows_message_when_port_65536(void **state) +{ + gchar *args[] = { "user@server.org", "port", "65536", NULL }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_cons_show("Value 65536 out of range. Must be in 1..65535."); + expect_cons_show(""); + + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); + assert_true(result); +} + +void cmd_connect_shows_message_when_port_contains_chars(void **state) +{ + gchar *args[] = { "user@server.org", "port", "52f66", NULL }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_cons_show("Could not convert \"52f66\" to a number."); + expect_cons_show(""); + + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); + assert_true(result); +} + +void cmd_connect_shows_usage_when_server_provided_twice(void **state) +{ + gchar *args[] = { "user@server.org", "server", "server1", "server", "server2", NULL }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT); + expect_cons_show(""); + + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); + assert_true(result); +} + +void cmd_connect_shows_usage_when_port_provided_twice(void **state) +{ + gchar *args[] = { "user@server.org", "port", "1111", "port", "1111", NULL }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT); + expect_cons_show(""); + + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); + assert_true(result); +} + +void cmd_connect_shows_usage_when_invalid_first_property(void **state) +{ + gchar *args[] = { "user@server.org", "wrong", "server", NULL }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT); + expect_cons_show(""); + + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); + assert_true(result); +} + +void cmd_connect_shows_usage_when_invalid_second_property(void **state) +{ + gchar *args[] = { "user@server.org", "server", "aserver", "wrong", "1234", NULL }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_string(cons_bad_cmd_usage, cmd, CMD_CONNECT); + expect_cons_show(""); + + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); + assert_true(result); +} + +void cmd_connect_with_server_when_provided(void **state) +{ + gchar *args[] = { "user@server.org", "server", "aserver", NULL }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_string(accounts_get_account, name, "user@server.org"); + will_return(accounts_get_account, NULL); + + will_return(ui_ask_password, strdup("password")); + + expect_cons_show("Connecting as user@server.org"); + + expect_string(jabber_connect_with_details, jid, "user@server.org"); + expect_string(jabber_connect_with_details, passwd, "password"); + expect_string(jabber_connect_with_details, altdomain, "aserver"); + expect_value(jabber_connect_with_details, port, 0); + will_return(jabber_connect_with_details, JABBER_CONNECTING); + + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); + assert_true(result); +} + +void cmd_connect_with_port_when_provided(void **state) +{ + gchar *args[] = { "user@server.org", "port", "5432", NULL }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_string(accounts_get_account, name, "user@server.org"); + will_return(accounts_get_account, NULL); + + will_return(ui_ask_password, strdup("password")); + + expect_cons_show("Connecting as user@server.org"); + + expect_string(jabber_connect_with_details, jid, "user@server.org"); + expect_string(jabber_connect_with_details, passwd, "password"); + expect_value(jabber_connect_with_details, altdomain, NULL); + expect_value(jabber_connect_with_details, port, 5432); + will_return(jabber_connect_with_details, JABBER_CONNECTING); + + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); + assert_true(result); +} + +void cmd_connect_with_server_and_port_when_provided(void **state) +{ + gchar *args[] = { "user@server.org", "port", "5432", "server", "aserver", NULL }; + + will_return(jabber_get_connection_status, JABBER_DISCONNECTED); + + expect_string(accounts_get_account, name, "user@server.org"); + will_return(accounts_get_account, NULL); + + will_return(ui_ask_password, strdup("password")); + + expect_cons_show("Connecting as user@server.org"); + + expect_string(jabber_connect_with_details, jid, "user@server.org"); + expect_string(jabber_connect_with_details, passwd, "password"); + expect_string(jabber_connect_with_details, altdomain, "aserver"); + expect_value(jabber_connect_with_details, port, 5432); + will_return(jabber_connect_with_details, JABBER_CONNECTING); + + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); + assert_true(result); } void cmd_connect_shows_message_when_connecting_with_account(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "jabber_org", NULL }; ProfAccount *account = account_new("jabber_org", "user@jabber.org", "password", NULL, TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL); @@ -448,15 +380,12 @@ void cmd_connect_shows_message_when_connecting_with_account(void **state) expect_any(jabber_connect_with_account, account); will_return(jabber_connect_with_account, JABBER_CONNECTING); - gboolean result = cmd_connect(NULL, args, *help); + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); assert_true(result); - - free(help); } void cmd_connect_connects_with_account(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "jabber_org", NULL }; ProfAccount *account = account_new("jabber_org", "me@jabber.org", "password", NULL, TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL); @@ -471,8 +400,6 @@ void cmd_connect_connects_with_account(void **state) expect_memory(jabber_connect_with_account, account, account, sizeof(account)); will_return(jabber_connect_with_account, JABBER_CONNECTING); - gboolean result = cmd_connect(NULL, args, *help); + gboolean result = cmd_connect(NULL, CMD_CONNECT, args); assert_true(result); - - free(help); } diff --git a/tests/unittests/test_cmd_disconnect.c b/tests/unittests/test_cmd_disconnect.c index 957516c2..7ea5b53a 100644 --- a/tests/unittests/test_cmd_disconnect.c +++ b/tests/unittests/test_cmd_disconnect.c @@ -12,10 +12,10 @@ #include "ui/stub_ui.h" +#define CMD_DISCONNECT "/disconnect" + void clears_chat_sessions(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - chat_sessions_init(); roster_init(); chat_session_recipient_active("bob@server.org", "laptop", FALSE); @@ -25,7 +25,7 @@ void clears_chat_sessions(void **state) will_return(jabber_get_fulljid, "myjid@myserver.com"); expect_any_cons_show(); - gboolean result = cmd_disconnect(NULL, NULL, *help); + gboolean result = cmd_disconnect(NULL, CMD_DISCONNECT, NULL); assert_true(result); @@ -33,5 +33,4 @@ void clears_chat_sessions(void **state) ChatSession *session2 = chat_session_get("mike@server.org"); assert_null(session1); assert_null(session2); - free(help); } diff --git a/tests/unittests/test_cmd_join.c b/tests/unittests/test_cmd_join.c index cdb275d9..bec63178 100644 --- a/tests/unittests/test_cmd_join.c +++ b/tests/unittests/test_cmd_join.c @@ -16,18 +16,16 @@ #include "command/commands.h" #include "muc.h" +#define CMD_JOIN "/join" + static void test_with_connection_status(jabber_conn_status_t status) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - will_return(jabber_get_connection_status, status); expect_cons_show("You are not currently connected."); - gboolean result = cmd_join(NULL, NULL, *help); + gboolean result = cmd_join(NULL, CMD_JOIN, NULL); assert_true(result); - - free(help); } void cmd_join_shows_message_when_disconnecting(void **state) @@ -52,7 +50,6 @@ void cmd_join_shows_message_when_undefined(void **state) void cmd_join_shows_error_message_when_invalid_room_jid(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "//@@/", NULL }; will_return(jabber_get_connection_status, JABBER_CONNECTED); @@ -60,10 +57,8 @@ void cmd_join_shows_error_message_when_invalid_room_jid(void **state) expect_cons_show_error("Specified room has incorrect format."); expect_cons_show(""); - gboolean result = cmd_join(NULL, args, *help); + gboolean result = cmd_join(NULL, CMD_JOIN, args); assert_true(result); - - free(help); } void cmd_join_uses_account_mucservice_when_no_service_specified(void **state) @@ -73,7 +68,6 @@ void cmd_join_uses_account_mucservice_when_no_service_specified(void **state) char *nick = "bob"; char *account_service = "conference.server.org"; char *expected_room = "room@conference.server.org"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { room, "nick", nick, NULL }; ProfAccount *account = account_new(account_name, "user@server.org", NULL, NULL, TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, account_service, NULL, NULL, NULL, NULL, NULL, NULL); @@ -90,10 +84,8 @@ void cmd_join_uses_account_mucservice_when_no_service_specified(void **state) expect_string(presence_join_room, nick, nick); expect_value(presence_join_room, passwd, NULL); - gboolean result = cmd_join(NULL, args, *help); + gboolean result = cmd_join(NULL, CMD_JOIN, args); assert_true(result); - - free(help); } void cmd_join_uses_supplied_nick(void **state) @@ -101,7 +93,6 @@ void cmd_join_uses_supplied_nick(void **state) char *account_name = "an_account"; char *room = "room@conf.server.org"; char *nick = "bob"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { room, "nick", nick, NULL }; ProfAccount *account = account_new(account_name, "user@server.org", NULL, NULL, TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL); @@ -118,10 +109,8 @@ void cmd_join_uses_supplied_nick(void **state) expect_string(presence_join_room, nick, nick); expect_value(presence_join_room, passwd, NULL); - gboolean result = cmd_join(NULL, args, *help); + gboolean result = cmd_join(NULL, CMD_JOIN, args); assert_true(result); - - free(help); } void cmd_join_uses_account_nick_when_not_supplied(void **state) @@ -129,7 +118,6 @@ void cmd_join_uses_account_nick_when_not_supplied(void **state) char *account_name = "an_account"; char *room = "room2@conf.server.org"; char *account_nick = "a_nick"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { room, NULL }; ProfAccount *account = account_new(account_name, "user@server.org", NULL, NULL, TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, account_nick, NULL, NULL, NULL, NULL, NULL); @@ -146,10 +134,8 @@ void cmd_join_uses_account_nick_when_not_supplied(void **state) expect_string(presence_join_room, nick, account_nick); expect_value(presence_join_room, passwd, NULL); - gboolean result = cmd_join(NULL, args, *help); + gboolean result = cmd_join(NULL, CMD_JOIN, args); assert_true(result); - - free(help); } void cmd_join_uses_password_when_supplied(void **state) @@ -160,7 +146,6 @@ void cmd_join_uses_password_when_supplied(void **state) char *account_nick = "a_nick"; char *account_service = "a_service"; char *expected_room = "room@a_service"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { room, "password", password, NULL }; ProfAccount *account = account_new(account_name, "user@server.org", NULL, NULL, TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, account_service, account_nick, NULL, NULL, NULL, NULL, NULL); @@ -177,8 +162,6 @@ void cmd_join_uses_password_when_supplied(void **state) expect_string(presence_join_room, nick, account_nick); expect_value(presence_join_room, passwd, password); - gboolean result = cmd_join(NULL, args, *help); + gboolean result = cmd_join(NULL, CMD_JOIN, args); assert_true(result); - - free(help); } diff --git a/tests/unittests/test_cmd_otr.c b/tests/unittests/test_cmd_otr.c index 7d4a3291..90ee7ae4 100644 --- a/tests/unittests/test_cmd_otr.c +++ b/tests/unittests/test_cmd_otr.c @@ -22,86 +22,68 @@ #include "ui/ui.h" #include "ui/stub_ui.h" +#define CMD_OTR "/otr" + #ifdef HAVE_LIBOTR void cmd_otr_shows_usage_when_no_args(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "Some usage"; gchar *args[] = { NULL }; - expect_cons_show("Usage: Some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_OTR); - gboolean result = cmd_otr(NULL, args, *help); + gboolean result = cmd_otr(NULL, CMD_OTR, args); assert_true(result); - - free(help); } void cmd_otr_shows_usage_when_invalid_subcommand(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "Some usage"; gchar *args[] = { "unknown", NULL }; will_return(jabber_get_connection_status, JABBER_CONNECTED); - expect_cons_show("Usage: Some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_OTR); - gboolean result = cmd_otr(NULL, args, *help); + gboolean result = cmd_otr(NULL, CMD_OTR, args); assert_true(result); - - free(help); } void cmd_otr_log_shows_usage_when_no_args(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "Some usage"; gchar *args[] = { "log", NULL }; - expect_cons_show("Usage: Some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_OTR); - gboolean result = cmd_otr(NULL, args, *help); + gboolean result = cmd_otr(NULL, CMD_OTR, args); assert_true(result); - - free(help); } void cmd_otr_log_shows_usage_when_invalid_subcommand(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "Some usage"; gchar *args[] = { "log", "wrong", NULL }; - expect_cons_show("Usage: Some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_OTR); - gboolean result = cmd_otr(NULL, args, *help); + gboolean result = cmd_otr(NULL, CMD_OTR, args); assert_true(result); - - free(help); } void cmd_otr_log_on_enables_logging(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "log", "on", NULL }; prefs_set_string(PREF_OTR_LOG, "off"); prefs_set_boolean(PREF_CHLOG, TRUE); expect_cons_show("OTR messages will be logged as plaintext."); - gboolean result = cmd_otr(NULL, args, *help); + gboolean result = cmd_otr(NULL, CMD_OTR, args); char *pref_otr_log = prefs_get_string(PREF_OTR_LOG); assert_true(result); assert_string_equal("on", pref_otr_log); - - free(help); } void cmd_otr_log_on_shows_warning_when_chlog_disabled(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "log", "on", NULL }; prefs_set_string(PREF_OTR_LOG, "off"); prefs_set_boolean(PREF_CHLOG, FALSE); @@ -109,51 +91,42 @@ void cmd_otr_log_on_shows_warning_when_chlog_disabled(void **state) expect_cons_show("OTR messages will be logged as plaintext."); expect_cons_show("Chat logging is currently disabled, use '/chlog on' to enable."); - gboolean result = cmd_otr(NULL, args, *help); + gboolean result = cmd_otr(NULL, CMD_OTR, args); assert_true(result); - - free(help); } void cmd_otr_log_off_disables_logging(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "log", "off", NULL }; prefs_set_string(PREF_OTR_LOG, "on"); prefs_set_boolean(PREF_CHLOG, TRUE); expect_cons_show("OTR message logging disabled."); - gboolean result = cmd_otr(NULL, args, *help); + gboolean result = cmd_otr(NULL, CMD_OTR, args); char *pref_otr_log = prefs_get_string(PREF_OTR_LOG); assert_true(result); assert_string_equal("off", pref_otr_log); - - free(help); } void cmd_otr_redact_redacts_logging(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "log", "redact", NULL }; prefs_set_string(PREF_OTR_LOG, "on"); prefs_set_boolean(PREF_CHLOG, TRUE); expect_cons_show("OTR messages will be logged as '[redacted]'."); - gboolean result = cmd_otr(NULL, args, *help); + gboolean result = cmd_otr(NULL, CMD_OTR, args); char *pref_otr_log = prefs_get_string(PREF_OTR_LOG); assert_true(result); assert_string_equal("redact", pref_otr_log); - - free(help); } void cmd_otr_log_redact_shows_warning_when_chlog_disabled(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "log", "redact", NULL }; prefs_set_string(PREF_OTR_LOG, "off"); prefs_set_boolean(PREF_CHLOG, FALSE); @@ -161,15 +134,12 @@ void cmd_otr_log_redact_shows_warning_when_chlog_disabled(void **state) expect_cons_show("OTR messages will be logged as '[redacted]'."); expect_cons_show("Chat logging is currently disabled, use '/chlog on' to enable."); - gboolean result = cmd_otr(NULL, args, *help); + gboolean result = cmd_otr(NULL, CMD_OTR, args); assert_true(result); - - free(help); } void cmd_otr_libver_shows_libotr_version(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "libver", NULL }; char *version = "9.9.9"; GString *message = g_string_new("Using libotr version "); @@ -179,41 +149,34 @@ void cmd_otr_libver_shows_libotr_version(void **state) expect_cons_show(message->str); - gboolean result = cmd_otr(NULL, args, *help); + gboolean result = cmd_otr(NULL, CMD_OTR, args); assert_true(result); g_string_free(message, TRUE); - free(help); } void cmd_otr_gen_shows_message_when_not_connected(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "gen", NULL }; will_return(jabber_get_connection_status, JABBER_DISCONNECTED); expect_cons_show("You must be connected with an account to load OTR information."); - gboolean result = cmd_otr(NULL, args, *help); + gboolean result = cmd_otr(NULL, CMD_OTR, args); assert_true(result); - - free(help); } static void test_with_command_and_connection_status(char *command, jabber_conn_status_t status) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { command, NULL }; will_return(jabber_get_connection_status, status); expect_cons_show("You must be connected with an account to load OTR information."); - gboolean result = cmd_otr(NULL, args, *help); + gboolean result = cmd_otr(NULL, CMD_OTR, args); assert_true(result); - - free(help); } void cmd_otr_gen_shows_message_when_disconnected(void **state) @@ -243,7 +206,6 @@ void cmd_otr_gen_shows_message_when_disconnecting(void **state) void cmd_otr_gen_generates_key_for_connected_account(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "gen", NULL }; char *account_name = "myaccount"; ProfAccount *account = account_new(account_name, "me@jabber.org", NULL, NULL, @@ -258,10 +220,8 @@ void cmd_otr_gen_generates_key_for_connected_account(void **state) expect_memory(otr_keygen, account, account, sizeof(ProfAccount)); - gboolean result = cmd_otr(NULL, args, *help); + gboolean result = cmd_otr(NULL, CMD_OTR, args); assert_true(result); - - free(help); } void cmd_otr_myfp_shows_message_when_disconnected(void **state) @@ -291,7 +251,6 @@ void cmd_otr_myfp_shows_message_when_disconnecting(void **state) void cmd_otr_myfp_shows_message_when_no_key(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "myfp", NULL }; will_return(jabber_get_connection_status, JABBER_CONNECTED); @@ -299,16 +258,13 @@ void cmd_otr_myfp_shows_message_when_no_key(void **state) expect_ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'"); - gboolean result = cmd_otr(NULL, args, *help); + gboolean result = cmd_otr(NULL, CMD_OTR, args); assert_true(result); - - free(help); } void cmd_otr_myfp_shows_my_fingerprint(void **state) { char *fingerprint = "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "myfp", NULL }; GString *message = g_string_new("Your OTR fingerprint: "); g_string_append(message, fingerprint); @@ -319,17 +275,15 @@ void cmd_otr_myfp_shows_my_fingerprint(void **state) expect_ui_current_print_formatted_line('!', 0, message->str); - gboolean result = cmd_otr(NULL, args, *help); + gboolean result = cmd_otr(NULL, CMD_OTR, args); assert_true(result); g_string_free(message, TRUE); - free(help); } static void test_cmd_otr_theirfp_from_wintype(win_type_t wintype) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "theirfp", NULL }; ProfWin window; window.type = wintype; @@ -338,10 +292,9 @@ test_cmd_otr_theirfp_from_wintype(win_type_t wintype) expect_ui_current_print_line("You must be in a regular chat window to view a recipient's fingerprint."); - gboolean result = cmd_otr(&window, args, *help); - assert_true(result); + gboolean result = cmd_otr(&window, CMD_OTR, args); - free(help); + assert_true(result); } void cmd_otr_theirfp_shows_message_when_in_console(void **state) @@ -361,7 +314,6 @@ void cmd_otr_theirfp_shows_message_when_in_private(void **state) void cmd_otr_theirfp_shows_message_when_non_otr_chat_window(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "theirfp", NULL }; ProfWin window; @@ -374,17 +326,15 @@ void cmd_otr_theirfp_shows_message_when_non_otr_chat_window(void **state) expect_ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session."); - gboolean result = cmd_otr((ProfWin*)&chatwin, args, *help); - assert_true(result); + gboolean result = cmd_otr((ProfWin*)&chatwin, CMD_OTR, args); - free(help); + assert_true(result); } void cmd_otr_theirfp_shows_fingerprint(void **state) { char *recipient = "someone@chat.com"; char *fingerprint = "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "theirfp", NULL }; GString *message = g_string_new(recipient); g_string_append(message, "'s OTR fingerprint: "); @@ -405,17 +355,15 @@ void cmd_otr_theirfp_shows_fingerprint(void **state) expect_ui_current_print_formatted_line('!', 0, message->str); - gboolean result = cmd_otr((ProfWin*)&chatwin, args, *help); + gboolean result = cmd_otr((ProfWin*)&chatwin, CMD_OTR, args); assert_true(result); g_string_free(message, TRUE); - free(help); } static void test_cmd_otr_start_from_wintype(win_type_t wintype) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "start", NULL }; ProfWin window; window.type = wintype; @@ -424,10 +372,8 @@ test_cmd_otr_start_from_wintype(win_type_t wintype) expect_ui_current_print_line("You must be in a regular chat window to start an OTR session."); - gboolean result = cmd_otr(&window, args, *help); + gboolean result = cmd_otr(&window, CMD_OTR, args); assert_true(result); - - free(help); } void cmd_otr_start_shows_message_when_in_console(void **state) @@ -448,7 +394,6 @@ void cmd_otr_start_shows_message_when_in_private(void **state) void cmd_otr_start_shows_message_when_already_started(void **state) { char *recipient = "someone@server.org"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "start", NULL }; will_return(jabber_get_connection_status, JABBER_CONNECTED); @@ -463,16 +408,13 @@ void cmd_otr_start_shows_message_when_already_started(void **state) expect_ui_current_print_formatted_line('!', 0, "You are already in an OTR session."); - gboolean result = cmd_otr((ProfWin*)&chatwin, args, *help); + gboolean result = cmd_otr((ProfWin*)&chatwin, CMD_OTR, args); assert_true(result); - - free(help); } void cmd_otr_start_shows_message_when_no_key(void **state) { char *recipient = "someone@server.org"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "start", NULL }; will_return(jabber_get_connection_status, JABBER_CONNECTED); @@ -488,10 +430,8 @@ void cmd_otr_start_shows_message_when_no_key(void **state) expect_ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'"); - gboolean result = cmd_otr((ProfWin*)&chatwin, args, *help); + gboolean result = cmd_otr((ProfWin*)&chatwin, CMD_OTR, args); assert_true(result); - - free(help); } void @@ -499,7 +439,6 @@ cmd_otr_start_sends_otr_query_message_to_current_recipeint(void **state) { char *recipient = "buddy@chat.com"; char *query_message = "?OTR?"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "start", NULL }; ProfWin window; @@ -517,23 +456,18 @@ cmd_otr_start_sends_otr_query_message_to_current_recipeint(void **state) expect_string(message_send_chat_otr, barejid, recipient); expect_string(message_send_chat_otr, msg, query_message); - gboolean result = cmd_otr((ProfWin*)&chatwin, args, *help); + gboolean result = cmd_otr((ProfWin*)&chatwin, CMD_OTR, args); assert_true(result); - - free(help); } #else void cmd_otr_shows_message_when_otr_unsupported(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "gen", NULL }; expect_cons_show("This version of Profanity has not been built with OTR support enabled"); - gboolean result = cmd_otr(NULL, args, *help); + gboolean result = cmd_otr(NULL, CMD_OTR, args); assert_true(result); - - free(help); } #endif diff --git a/tests/unittests/test_cmd_pgp.c b/tests/unittests/test_cmd_pgp.c index aef4baf7..b1d0ab52 100644 --- a/tests/unittests/test_cmd_pgp.c +++ b/tests/unittests/test_cmd_pgp.c @@ -12,25 +12,21 @@ #include "ui/stub_ui.h" +#define CMD_PGP "/pgp" + #ifdef HAVE_LIBGPGME void cmd_pgp_shows_usage_when_no_args(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "Some usage"; gchar *args[] = { NULL }; - expect_cons_show("Usage: Some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_PGP); - gboolean result = cmd_pgp(NULL, args, *help); + gboolean result = cmd_pgp(NULL, CMD_PGP, args); assert_true(result); - - free(help); } void cmd_pgp_start_shows_message_when_connection(jabber_conn_status_t conn_status) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "Some usage"; gchar *args[] = { "start", NULL }; ProfWin window; window.type = WIN_CHAT; @@ -39,10 +35,8 @@ void cmd_pgp_start_shows_message_when_connection(jabber_conn_status_t conn_statu expect_cons_show("You must be connected to start PGP encrpytion."); - gboolean result = cmd_pgp(&window, args, *help); + gboolean result = cmd_pgp(&window, CMD_PGP, args); assert_true(result); - - free(help); } void cmd_pgp_start_shows_message_when_disconnected(void **state) @@ -72,8 +66,6 @@ void cmd_pgp_start_shows_message_when_started(void **state) void cmd_pgp_start_shows_message_when_no_arg_in_wintype(win_type_t wintype) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "Some usage"; gchar *args[] = { "start", NULL }; ProfWin window; window.type = wintype; @@ -82,10 +74,8 @@ void cmd_pgp_start_shows_message_when_no_arg_in_wintype(win_type_t wintype) expect_cons_show("You must be in a regular chat window to start PGP encrpytion."); - gboolean result = cmd_pgp(&window, args, *help); + gboolean result = cmd_pgp(&window, CMD_PGP, args); assert_true(result); - - free(help); } void cmd_pgp_start_shows_message_when_no_arg_in_console(void **state) @@ -116,14 +106,11 @@ void cmd_pgp_start_shows_message_when_no_arg_in_xmlconsole(void **state) #else void cmd_pgp_shows_message_when_pgp_unsupported(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "gen", NULL }; expect_cons_show("This version of Profanity has not been built with PGP support enabled"); - gboolean result = cmd_pgp(NULL, args, *help); + gboolean result = cmd_pgp(NULL, CMD_PGP, args); assert_true(result); - - free(help); } #endif diff --git a/tests/unittests/test_cmd_rooms.c b/tests/unittests/test_cmd_rooms.c index c7439f13..4251d9de 100644 --- a/tests/unittests/test_cmd_rooms.c +++ b/tests/unittests/test_cmd_rooms.c @@ -14,18 +14,16 @@ #include "config/accounts.h" #include "command/commands.h" +#define CMD_ROOMS "/rooms" + static void test_with_connection_status(jabber_conn_status_t status) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - will_return(jabber_get_connection_status, status); expect_cons_show("You are not currently connected."); - gboolean result = cmd_rooms(NULL, NULL, *help); + gboolean result = cmd_rooms(NULL, CMD_ROOMS, NULL); assert_true(result); - - free(help); } void cmd_rooms_shows_message_when_disconnected(void **state) @@ -55,7 +53,6 @@ void cmd_rooms_shows_message_when_undefined(void **state) void cmd_rooms_uses_account_default_when_no_arg(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { NULL }; ProfAccount *account = malloc(sizeof(ProfAccount)); account->name = NULL; @@ -81,25 +78,18 @@ void cmd_rooms_uses_account_default_when_no_arg(void **state) expect_string(iq_room_list_request, conferencejid, "default_conf_server"); - gboolean result = cmd_rooms(NULL, args, *help); - + gboolean result = cmd_rooms(NULL, CMD_ROOMS, args); assert_true(result); - - free(help); } void cmd_rooms_arg_used_when_passed(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "conf_server_arg" }; will_return(jabber_get_connection_status, JABBER_CONNECTED); expect_string(iq_room_list_request, conferencejid, "conf_server_arg"); - gboolean result = cmd_rooms(NULL, args, *help); - + gboolean result = cmd_rooms(NULL, CMD_ROOMS, args); assert_true(result); - - free(help); } diff --git a/tests/unittests/test_cmd_roster.c b/tests/unittests/test_cmd_roster.c index 0fd1647a..bcc2193a 100644 --- a/tests/unittests/test_cmd_roster.c +++ b/tests/unittests/test_cmd_roster.c @@ -13,19 +13,18 @@ #include "roster_list.h" #include "command/commands.h" +#define CMD_ROSTER "/roster" + static void test_with_connection_status(jabber_conn_status_t status) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { NULL }; will_return(jabber_get_connection_status, status); expect_cons_show("You are not currently connected."); - gboolean result = cmd_roster(NULL, args, *help); + gboolean result = cmd_roster(NULL, CMD_ROSTER, args); assert_true(result); - - free(help); } void cmd_roster_shows_message_when_disconnecting(void **state) @@ -50,7 +49,6 @@ void cmd_roster_shows_message_when_undefined(void **state) void cmd_roster_shows_roster_when_no_args(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { NULL }; will_return(jabber_get_connection_status, JABBER_CONNECTED); @@ -61,34 +59,28 @@ void cmd_roster_shows_roster_when_no_args(void **state) expect_memory(cons_show_roster, list, roster, sizeof(roster)); - gboolean result = cmd_roster(NULL, args, *help); + gboolean result = cmd_roster(NULL, CMD_ROSTER, args); assert_true(result); - free(help); roster_free(); } void cmd_roster_add_shows_message_when_no_jid(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "add", NULL }; will_return(jabber_get_connection_status, JABBER_CONNECTED); - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER); - gboolean result = cmd_roster(NULL, args, *help); + gboolean result = cmd_roster(NULL, CMD_ROSTER, args); assert_true(result); - - free(help); } void cmd_roster_add_sends_roster_add_request(void **state) { char *jid = "bob@server.org"; char *nick = "bob"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "add", jid, nick, NULL }; will_return(jabber_get_connection_status, JABBER_CONNECTED); @@ -96,80 +88,61 @@ void cmd_roster_add_sends_roster_add_request(void **state) expect_string(roster_send_add_new, barejid, jid); expect_string(roster_send_add_new, name, nick); - gboolean result = cmd_roster(NULL, args, *help); + gboolean result = cmd_roster(NULL, CMD_ROSTER, args); assert_true(result); - - free(help); } void cmd_roster_remove_shows_message_when_no_jid(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "remove", NULL }; will_return(jabber_get_connection_status, JABBER_CONNECTED); - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER); - gboolean result = cmd_roster(NULL, args, *help); + gboolean result = cmd_roster(NULL, CMD_ROSTER, args); assert_true(result); - - free(help); } void cmd_roster_remove_sends_roster_remove_request(void **state) { char *jid = "bob@server.org"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "remove", jid, NULL }; will_return(jabber_get_connection_status, JABBER_CONNECTED); expect_string(roster_send_remove, barejid, jid); - gboolean result = cmd_roster(NULL, args, *help); + gboolean result = cmd_roster(NULL, CMD_ROSTER, args); assert_true(result); - - free(help); } void cmd_roster_nick_shows_message_when_no_jid(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "nick", NULL }; will_return(jabber_get_connection_status, JABBER_CONNECTED); - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER); - gboolean result = cmd_roster(NULL, args, *help); + gboolean result = cmd_roster(NULL, CMD_ROSTER, args); assert_true(result); - - free(help); } void cmd_roster_nick_shows_message_when_no_nick(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "nick", "bob@server.org", NULL }; will_return(jabber_get_connection_status, JABBER_CONNECTED); - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER); - gboolean result = cmd_roster(NULL, args, *help); + gboolean result = cmd_roster(NULL, CMD_ROSTER, args); assert_true(result); - - free(help); } void cmd_roster_nick_shows_message_when_no_contact_exists(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "nick", "bob@server.org", "bobster", NULL }; roster_init(); @@ -178,10 +151,9 @@ void cmd_roster_nick_shows_message_when_no_contact_exists(void **state) expect_cons_show("Contact not found in roster: bob@server.org"); - gboolean result = cmd_roster(NULL, args, *help); + gboolean result = cmd_roster(NULL, CMD_ROSTER, args); assert_true(result); - free(help); roster_free(); } @@ -189,7 +161,6 @@ void cmd_roster_nick_sends_name_change_request(void **state) { char *jid = "bob@server.org"; char *nick = "bobster"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "nick", jid, nick, NULL }; roster_init(); @@ -205,36 +176,28 @@ void cmd_roster_nick_sends_name_change_request(void **state) expect_cons_show("Nickname for bob@server.org set to: bobster."); - gboolean result = cmd_roster(NULL, args, *help); + gboolean result = cmd_roster(NULL, CMD_ROSTER, args); assert_true(result); PContact contact = roster_get_contact(jid); assert_string_equal(p_contact_name(contact), nick); - - free(help); roster_free(); } void cmd_roster_clearnick_shows_message_when_no_jid(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "clearnick", NULL }; will_return(jabber_get_connection_status, JABBER_CONNECTED); - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER); - gboolean result = cmd_roster(NULL, args, *help); + gboolean result = cmd_roster(NULL, CMD_ROSTER, args); assert_true(result); - - free(help); } void cmd_roster_clearnick_shows_message_when_no_contact_exists(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "clearnick", "bob@server.org", NULL }; roster_init(); @@ -243,17 +206,15 @@ void cmd_roster_clearnick_shows_message_when_no_contact_exists(void **state) expect_cons_show("Contact not found in roster: bob@server.org"); - gboolean result = cmd_roster(NULL, args, *help); + gboolean result = cmd_roster(NULL, CMD_ROSTER, args); assert_true(result); - free(help); roster_free(); } void cmd_roster_clearnick_sends_name_change_request_with_empty_nick(void **state) { char *jid = "bob@server.org"; - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "clearnick", jid, NULL }; roster_init(); @@ -269,12 +230,11 @@ void cmd_roster_clearnick_sends_name_change_request_with_empty_nick(void **state expect_cons_show("Nickname for bob@server.org removed."); - gboolean result = cmd_roster(NULL, args, *help); + gboolean result = cmd_roster(NULL, CMD_ROSTER, args); assert_true(result); PContact contact = roster_get_contact(jid); assert_null(p_contact_name(contact)); - free(help); roster_free(); } diff --git a/tests/unittests/test_cmd_statuses.c b/tests/unittests/test_cmd_statuses.c index 0ecb22ae..bd5337c3 100644 --- a/tests/unittests/test_cmd_statuses.c +++ b/tests/unittests/test_cmd_statuses.c @@ -13,211 +13,170 @@ #include "command/commands.h" +#define CMD_STATUSES "/statuses" + void cmd_statuses_shows_usage_when_bad_subcmd(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "badcmd", NULL }; - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_STATUSES); - gboolean result = cmd_statuses(NULL, args, *help); + gboolean result = cmd_statuses(NULL, CMD_STATUSES, args); assert_true(result); - - free(help); } void cmd_statuses_shows_usage_when_bad_console_setting(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "console", "badsetting", NULL }; - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_STATUSES); - gboolean result = cmd_statuses(NULL, args, *help); + gboolean result = cmd_statuses(NULL, CMD_STATUSES, args); assert_true(result); - - free(help); } void cmd_statuses_shows_usage_when_bad_chat_setting(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "chat", "badsetting", NULL }; - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_STATUSES); - gboolean result = cmd_statuses(NULL, args, *help); + gboolean result = cmd_statuses(NULL, CMD_STATUSES, args); assert_true(result); - - free(help); } void cmd_statuses_shows_usage_when_bad_muc_setting(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; gchar *args[] = { "muc", "badsetting", NULL }; - expect_cons_show("Usage: some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_STATUSES); - gboolean result = cmd_statuses(NULL, args, *help); + gboolean result = cmd_statuses(NULL, CMD_STATUSES, args); assert_true(result); - - free(help); } void cmd_statuses_console_sets_all(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "console", "all", NULL }; expect_cons_show("All presence updates will appear in the console."); - gboolean result = cmd_statuses(NULL, args, *help); + gboolean result = cmd_statuses(NULL, CMD_STATUSES, args); char *setting = prefs_get_string(PREF_STATUSES_CONSOLE); assert_non_null(setting); assert_string_equal("all", setting); assert_true(result); - - free(help); } void cmd_statuses_console_sets_online(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "console", "online", NULL }; expect_cons_show("Only online/offline presence updates will appear in the console."); - gboolean result = cmd_statuses(NULL, args, *help); + gboolean result = cmd_statuses(NULL, CMD_STATUSES, args); char *setting = prefs_get_string(PREF_STATUSES_CONSOLE); assert_non_null(setting); assert_string_equal("online", setting); assert_true(result); - - free(help); } void cmd_statuses_console_sets_none(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "console", "none", NULL }; expect_cons_show("Presence updates will not appear in the console."); - gboolean result = cmd_statuses(NULL, args, *help); + gboolean result = cmd_statuses(NULL, CMD_STATUSES, args); char *setting = prefs_get_string(PREF_STATUSES_CONSOLE); assert_non_null(setting); assert_string_equal("none", setting); assert_true(result); - - free(help); } void cmd_statuses_chat_sets_all(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "chat", "all", NULL }; expect_cons_show("All presence updates will appear in chat windows."); - gboolean result = cmd_statuses(NULL, args, *help); + gboolean result = cmd_statuses(NULL, CMD_STATUSES, args); char *setting = prefs_get_string(PREF_STATUSES_CHAT); assert_non_null(setting); assert_string_equal("all", setting); assert_true(result); - - free(help); } void cmd_statuses_chat_sets_online(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "chat", "online", NULL }; expect_cons_show("Only online/offline presence updates will appear in chat windows."); - gboolean result = cmd_statuses(NULL, args, *help); + gboolean result = cmd_statuses(NULL, CMD_STATUSES, args); char *setting = prefs_get_string(PREF_STATUSES_CHAT); assert_non_null(setting); assert_string_equal("online", setting); assert_true(result); - - free(help); } void cmd_statuses_chat_sets_none(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "chat", "none", NULL }; expect_cons_show("Presence updates will not appear in chat windows."); - gboolean result = cmd_statuses(NULL, args, *help); + gboolean result = cmd_statuses(NULL, CMD_STATUSES, args); char *setting = prefs_get_string(PREF_STATUSES_CHAT); assert_non_null(setting); assert_string_equal("none", setting); assert_true(result); - - free(help); } void cmd_statuses_muc_sets_all(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "muc", "all", NULL }; expect_cons_show("All presence updates will appear in chat room windows."); - gboolean result = cmd_statuses(NULL, args, *help); + gboolean result = cmd_statuses(NULL, CMD_STATUSES, args); char *setting = prefs_get_string(PREF_STATUSES_MUC); assert_non_null(setting); assert_string_equal("all", setting); assert_true(result); - - free(help); } void cmd_statuses_muc_sets_online(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "muc", "online", NULL }; expect_cons_show("Only join/leave presence updates will appear in chat room windows."); - gboolean result = cmd_statuses(NULL, args, *help); + gboolean result = cmd_statuses(NULL, CMD_STATUSES, args); char *setting = prefs_get_string(PREF_STATUSES_MUC); assert_non_null(setting); assert_string_equal("online", setting); assert_true(result); - - free(help); } void cmd_statuses_muc_sets_none(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "muc", "none", NULL }; expect_cons_show("Presence updates will not appear in chat room windows."); - gboolean result = cmd_statuses(NULL, args, *help); + gboolean result = cmd_statuses(NULL, CMD_STATUSES, args); char *setting = prefs_get_string(PREF_STATUSES_MUC); assert_non_null(setting); assert_string_equal("none", setting); assert_true(result); - - free(help); } diff --git a/tests/unittests/test_cmd_sub.c b/tests/unittests/test_cmd_sub.c index 55b9de60..62871520 100644 --- a/tests/unittests/test_cmd_sub.c +++ b/tests/unittests/test_cmd_sub.c @@ -13,33 +13,28 @@ #include "command/commands.h" +#define CMD_SUB "/sub" + void cmd_sub_shows_message_when_not_connected(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { NULL }; will_return(jabber_get_connection_status, JABBER_DISCONNECTED); expect_cons_show("You are currently not connected."); - gboolean result = cmd_sub(NULL, args, *help); + gboolean result = cmd_sub(NULL, CMD_SUB, args); assert_true(result); - - free(help); } void cmd_sub_shows_usage_when_no_arg(void **state) { - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "Some usage"; gchar *args[] = { NULL }; will_return(jabber_get_connection_status, JABBER_CONNECTED); - expect_cons_show("Usage: Some usage"); + expect_string(cons_bad_cmd_usage, cmd, CMD_SUB); - gboolean result = cmd_sub(NULL, args, *help); + gboolean result = cmd_sub(NULL, CMD_SUB, args); assert_true(result); - - free(help); } diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 05863fd0..efe70d62 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -398,6 +398,12 @@ void cons_show_roster(GSList * list) check_expected(list); } +void +cons_bad_cmd_usage(const char * const cmd) +{ + check_expected(cmd); +} + void cons_show_roster_group(const char * const group, GSList * list) {} void cons_show_wins(void) {} void cons_show_status(const char * const barejid) {} diff --git a/tests/unittests/unittests.c b/tests/unittests/unittests.c index 61c58e33..0545d6a4 100644 --- a/tests/unittests/unittests.c +++ b/tests/unittests/unittests.c @@ -37,6 +37,7 @@ int main(int argc, char* argv[]) { const UnitTest all_tests[] = { + unit_test(replace_one_substr), unit_test(replace_one_substr_beginning), unit_test(replace_one_substr_end), @@ -214,6 +215,7 @@ int main(int argc, char* argv[]) { unit_test_setup_teardown(removes_chat_session, init_chat_sessions, close_chat_sessions), + unit_test_setup_teardown(cmd_connect_shows_message_when_disconnecting, load_preferences, close_preferences), @@ -238,15 +240,15 @@ int main(int argc, char* argv[]) { unit_test_setup_teardown(cmd_connect_asks_password_when_not_in_account, load_preferences, close_preferences), + unit_test_setup_teardown(cmd_connect_shows_usage_when_no_server_value, + load_preferences, + close_preferences), unit_test_setup_teardown(cmd_connect_shows_message_when_connecting_with_account, load_preferences, close_preferences), unit_test_setup_teardown(cmd_connect_connects_with_account, load_preferences, close_preferences), - unit_test_setup_teardown(cmd_connect_shows_usage_when_no_server_value, - load_preferences, - close_preferences), unit_test_setup_teardown(cmd_connect_shows_usage_when_server_no_port_value, load_preferences, close_preferences), From eb550eedb39fccd845aab82c8ebb8f7af76be180 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 27 Jul 2015 01:06:10 +0100 Subject: [PATCH 19/25] Added tags to command definitions --- src/command/command.c | 223 ++++++++++++++++++++++++++++++++++++++++- src/command/command.h | 3 + src/command/commands.c | 216 ++++++++++++++++++++++++--------------- src/command/commands.h | 1 + src/ui/console.c | 1 + 5 files changed, 358 insertions(+), 86 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 87784780..64cca07f 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -104,11 +104,22 @@ static char * _receipts_autocomplete(ProfWin *window, const char * const input); GHashTable *commands = NULL; -#define CMD_SYN(...) { { __VA_ARGS__, NULL }, +#define CMD_TAG_BASIC "basic" +#define CMD_TAG_CHATTING "chatting" +#define CMD_TAG_GROUPCHAT "groupchat" +#define CMD_TAG_PRESENCES "presences" +#define CMD_TAG_CONTACTS "contacts" +#define CMD_TAG_SERVICE "service" +#define CMD_TAG_SETTINGS "settings" +#define CMD_TAG_UI "ui" + +#define CMD_NOTAGS { { NULL }, +#define CMD_TAGS(...) { { __VA_ARGS__, NULL }, +#define CMD_SYN(...) { __VA_ARGS__, NULL }, #define CMD_DESC(desc) desc, -#define CMD_NOARGS { { NULL, NULL } }, +#define CMD_NOARGS { { NULL, NULL } }, #define CMD_ARGS(...) { __VA_ARGS__, { NULL, NULL } }, -#define CMD_NOEXAMPLES { NULL } } +#define CMD_NOEXAMPLES { NULL } } #define CMD_EXAMPLES(...) { __VA_ARGS__, NULL } } /* @@ -118,6 +129,7 @@ static struct cmd_t command_defs[] = { { "/help", cmd_help, parse_args, 0, 1, NULL, + CMD_NOTAGS CMD_SYN( "/help [|]") CMD_DESC( @@ -133,6 +145,7 @@ static struct cmd_t command_defs[] = { "/about", cmd_about, parse_args, 0, 0, NULL, + CMD_NOTAGS CMD_SYN( "/about") CMD_DESC( @@ -143,6 +156,8 @@ static struct cmd_t command_defs[] = { "/connect", cmd_connect, parse_args, 0, 5, NULL, + CMD_TAGS( + CMD_TAG_BASIC) CMD_SYN( "/connect []", "/connect [server ] [port ]") @@ -164,6 +179,8 @@ static struct cmd_t command_defs[] = { "/disconnect", cmd_disconnect, parse_args, 0, 0, NULL, + CMD_TAGS( + CMD_TAG_BASIC) CMD_SYN( "/disconnect") CMD_DESC( @@ -174,6 +191,10 @@ static struct cmd_t command_defs[] = { "/msg", cmd_msg, parse_args_with_freetext, 1, 2, NULL, + CMD_TAGS( + CMD_TAG_BASIC, + CMD_TAG_CHATTING, + CMD_TAG_GROUPCHAT) CMD_SYN( "/msg []", "/msg []") @@ -195,6 +216,9 @@ static struct cmd_t command_defs[] = { "/roster", cmd_roster, parse_args_with_freetext, 0, 3, NULL, + CMD_TAGS( + CMD_TAG_CONTACTS, + CMD_TAG_UI) CMD_SYN( "/roster", "/roster online", @@ -242,9 +266,12 @@ static struct cmd_t command_defs[] = { "/group", cmd_group, parse_args_with_freetext, 0, 3, NULL, + CMD_TAGS( + CMD_TAG_CONTACTS) CMD_SYN( "/group", "/group show ", + "/group add " "/group remove ") CMD_DESC( "View, add to, and remove from roster groups. " @@ -263,6 +290,7 @@ static struct cmd_t command_defs[] = { "/info", cmd_info, parse_args, 0, 1, NULL, + CMD_NOTAGS CMD_SYN( "/info", "/info |") @@ -280,6 +308,8 @@ static struct cmd_t command_defs[] = { "/caps", cmd_caps, parse_args, 0, 1, NULL, + CMD_TAGS( + CMD_TAG_SERVICE) CMD_SYN( "/caps", "/caps |") @@ -297,6 +327,8 @@ static struct cmd_t command_defs[] = { "/software", cmd_software, parse_args, 0, 1, NULL, + CMD_TAGS( + CMD_TAG_SERVICE) CMD_SYN( "/software", "/software |") @@ -315,6 +347,7 @@ static struct cmd_t command_defs[] = { "/status", cmd_status, parse_args, 0, 1, NULL, + CMD_NOTAGS CMD_SYN( "/status", "/status |") @@ -331,6 +364,8 @@ static struct cmd_t command_defs[] = { "/resource", cmd_resource, parse_args, 1, 2, &cons_resource_setting, + CMD_TAGS( + CMD_TAG_UI) CMD_SYN( "/resource set ", "/resource off", @@ -348,6 +383,9 @@ static struct cmd_t command_defs[] = { "/join", cmd_join, parse_args, 0, 5, NULL, + CMD_TAGS( + CMD_TAG_BASIC, + CMD_TAG_GROUPCHAT) CMD_SYN( "/join", "/join [nick ] [password ]") @@ -371,6 +409,9 @@ static struct cmd_t command_defs[] = { "/leave", cmd_leave, parse_args, 0, 0, NULL, + CMD_TAGS( + CMD_TAG_BASIC, + CMD_TAG_GROUPCHAT) CMD_SYN( "/leave") CMD_DESC( @@ -381,6 +422,8 @@ static struct cmd_t command_defs[] = { "/invite", cmd_invite, parse_args_with_freetext, 1, 2, NULL, + CMD_TAGS( + CMD_TAG_GROUPCHAT) CMD_SYN( "/invite []") CMD_DESC( @@ -393,6 +436,8 @@ static struct cmd_t command_defs[] = { "/invites", cmd_invites, parse_args_with_freetext, 0, 0, NULL, + CMD_TAGS( + CMD_TAG_GROUPCHAT) CMD_SYN( "/invites") CMD_DESC( @@ -403,6 +448,8 @@ static struct cmd_t command_defs[] = { "/decline", cmd_decline, parse_args_with_freetext, 1, 1, NULL, + CMD_TAGS( + CMD_TAG_GROUPCHAT) CMD_SYN( "/decline ") CMD_DESC( @@ -414,6 +461,8 @@ static struct cmd_t command_defs[] = { "/room", cmd_room, parse_args, 1, 1, NULL, + CMD_TAGS( + CMD_TAG_GROUPCHAT) CMD_SYN( "/room accept|destroy|config") CMD_DESC( @@ -427,6 +476,8 @@ static struct cmd_t command_defs[] = { "/kick", cmd_kick, parse_args_with_freetext, 1, 2, NULL, + CMD_TAGS( + CMD_TAG_GROUPCHAT) CMD_SYN( "/kick []") CMD_DESC( @@ -439,6 +490,8 @@ static struct cmd_t command_defs[] = { "/ban", cmd_ban, parse_args_with_freetext, 1, 2, NULL, + CMD_TAGS( + CMD_TAG_GROUPCHAT) CMD_SYN( "/ban []") CMD_DESC( @@ -451,6 +504,8 @@ static struct cmd_t command_defs[] = { "/subject", cmd_subject, parse_args_with_freetext, 0, 2, NULL, + CMD_TAGS( + CMD_TAG_GROUPCHAT) CMD_SYN( "/subject set ", "/subject clear") @@ -464,6 +519,8 @@ static struct cmd_t command_defs[] = { "/affiliation", cmd_affiliation, parse_args_with_freetext, 1, 4, NULL, + CMD_TAGS( + CMD_TAG_GROUPCHAT) CMD_SYN( "/affiliation set []", "/list []") @@ -478,6 +535,8 @@ static struct cmd_t command_defs[] = { "/role", cmd_role, parse_args_with_freetext, 1, 4, NULL, + CMD_TAGS( + CMD_TAG_GROUPCHAT) CMD_SYN( "/role set []", "/list []") @@ -492,6 +551,8 @@ static struct cmd_t command_defs[] = { "/occupants", cmd_occupants, parse_args, 1, 3, cons_occupants_setting, + CMD_TAGS( + CMD_TAG_UI) CMD_SYN( "/occupants show|hide [jid]", "/occupants default show|hide [jid]", @@ -511,6 +572,8 @@ static struct cmd_t command_defs[] = { "/form", cmd_form, parse_args, 1, 2, NULL, + CMD_TAGS( + CMD_TAG_GROUPCHAT) CMD_SYN( "/form show", "/form submit", @@ -528,6 +591,8 @@ static struct cmd_t command_defs[] = { "/rooms", cmd_rooms, parse_args, 0, 1, NULL, + CMD_TAGS( + CMD_TAG_GROUPCHAT) CMD_SYN( "/rooms []") CMD_DESC( @@ -541,6 +606,8 @@ static struct cmd_t command_defs[] = { "/bookmark", cmd_bookmark, parse_args, 0, 8, NULL, + CMD_TAGS( + CMD_TAG_GROUPCHAT) CMD_SYN( "/bookmark", "/bookmark list", @@ -565,6 +632,8 @@ static struct cmd_t command_defs[] = { "/disco", cmd_disco, parse_args, 1, 2, NULL, + CMD_TAGS( + CMD_TAG_SERVICE) CMD_SYN( "/disco info []", "/disco items []") @@ -583,6 +652,9 @@ static struct cmd_t command_defs[] = { "/nick", cmd_nick, parse_args_with_freetext, 1, 1, NULL, + CMD_TAGS( + CMD_TAG_BASIC, + CMD_TAG_GROUPCHAT) CMD_SYN( "/nick ") CMD_DESC( @@ -594,6 +666,9 @@ static struct cmd_t command_defs[] = { "/win", cmd_win, parse_args, 1, 1, NULL, + CMD_TAGS( + CMD_TAG_BASIC, + CMD_TAG_UI) CMD_SYN( "/win ") CMD_DESC( @@ -605,6 +680,9 @@ static struct cmd_t command_defs[] = { "/wins", cmd_wins, parse_args, 0, 3, NULL, + CMD_TAGS( + CMD_TAG_BASIC, + CMD_TAG_UI) CMD_SYN( "/wins tidy", "/wins prune", @@ -621,6 +699,9 @@ static struct cmd_t command_defs[] = { "/sub", cmd_sub, parse_args, 1, 2, NULL, + CMD_TAGS( + CMD_TAG_BASIC, + CMD_TAG_CONTACTS) CMD_SYN( "/sub request []", "/sub allow []", @@ -647,6 +728,8 @@ static struct cmd_t command_defs[] = { "/tiny", cmd_tiny, parse_args, 1, 1, NULL, + CMD_TAGS( + CMD_TAG_CHATTING) CMD_SYN( "/tiny ") CMD_DESC( @@ -659,6 +742,9 @@ static struct cmd_t command_defs[] = { "/who", cmd_who, parse_args, 0, 2, NULL, + CMD_TAGS( + CMD_TAG_BASIC, + CMD_TAG_CONTACTS) CMD_SYN( "/who", "/who online|offline|away|dnd|xa|chat|available|unavailable|any []", @@ -686,6 +772,9 @@ static struct cmd_t command_defs[] = { "/close", cmd_close, parse_args, 0, 1, NULL, + CMD_TAGS( + CMD_TAG_BASIC, + CMD_TAG_CHATTING) CMD_SYN( "/close []", "/close all|read") @@ -701,6 +790,7 @@ static struct cmd_t command_defs[] = { "/clear", cmd_clear, parse_args, 0, 0, NULL, + CMD_NOTAGS CMD_SYN( "/clear") CMD_DESC( @@ -711,6 +801,8 @@ static struct cmd_t command_defs[] = { "/quit", cmd_quit, parse_args, 0, 0, NULL, + CMD_TAGS( + CMD_TAG_BASIC) CMD_SYN( "/quit") CMD_DESC( @@ -721,6 +813,8 @@ static struct cmd_t command_defs[] = { "/privileges", cmd_privileges, parse_args, 1, 1, &cons_privileges_setting, + CMD_TAGS( + CMD_TAG_UI) CMD_SYN( "/privileges on|off") CMD_DESC( @@ -732,6 +826,8 @@ static struct cmd_t command_defs[] = { "/beep", cmd_beep, parse_args, 1, 1, &cons_beep_setting, + CMD_TAGS( + CMD_TAG_UI) CMD_SYN( "/beep on|off") CMD_DESC( @@ -745,6 +841,9 @@ static struct cmd_t command_defs[] = { "/encwarn", cmd_encwarn, parse_args, 1, 1, &cons_encwarn_setting, + CMD_TAGS( + CMD_TAG_CHATTING, + CMD_TAG_UI) CMD_SYN( "/encwarn on|off") CMD_DESC( @@ -756,6 +855,8 @@ static struct cmd_t command_defs[] = { "/presence", cmd_presence, parse_args, 1, 1, &cons_presence_setting, + CMD_TAGS( + CMD_TAG_UI) CMD_SYN( "/presence on|off") CMD_DESC( @@ -767,6 +868,8 @@ static struct cmd_t command_defs[] = { "/wrap", cmd_wrap, parse_args, 1, 1, &cons_wrap_setting, + CMD_TAGS( + CMD_TAG_UI) CMD_SYN( "/wrap on|off") CMD_DESC( @@ -778,6 +881,8 @@ static struct cmd_t command_defs[] = { "/winstidy", cmd_winstidy, parse_args, 1, 1, &cons_winstidy_setting, + CMD_TAGS( + CMD_TAG_UI) CMD_SYN( "/winstidy on|off") CMD_DESC( @@ -789,6 +894,8 @@ static struct cmd_t command_defs[] = { "/time", cmd_time, parse_args, 1, 3, &cons_time_setting, + CMD_TAGS( + CMD_TAG_UI) CMD_SYN( "/time main set ", "/time main off", @@ -813,6 +920,8 @@ static struct cmd_t command_defs[] = { "/inpblock", cmd_inpblock, parse_args, 2, 2, &cons_inpblock_setting, + CMD_TAGS( + CMD_TAG_UI) CMD_SYN( "/inpblock timeout ", "/inpblock dynamic on|off") @@ -826,6 +935,8 @@ static struct cmd_t command_defs[] = { "/notify", cmd_notify, parse_args, 2, 3, &cons_notify_setting, + CMD_TAGS( + CMD_TAG_UI) CMD_SYN( "/notify message on|off", "/notify message current on|off", @@ -865,6 +976,8 @@ static struct cmd_t command_defs[] = { "/flash", cmd_flash, parse_args, 1, 1, &cons_flash_setting, + CMD_TAGS( + CMD_TAG_UI) CMD_SYN( "/flash on|off") CMD_DESC( @@ -877,6 +990,8 @@ static struct cmd_t command_defs[] = { "/intype", cmd_intype, parse_args, 1, 1, &cons_intype_setting, + CMD_TAGS( + CMD_TAG_UI) CMD_SYN( "/intype on|off") CMD_DESC( @@ -888,6 +1003,8 @@ static struct cmd_t command_defs[] = { "/splash", cmd_splash, parse_args, 1, 1, &cons_splash_setting, + CMD_TAGS( + CMD_TAG_UI) CMD_SYN( "/splash on|off") CMD_DESC( @@ -899,6 +1016,8 @@ static struct cmd_t command_defs[] = { "/autoconnect", cmd_autoconnect, parse_args, 1, 2, &cons_autoconnect_setting, + CMD_TAGS( + CMD_TAG_SETTINGS) CMD_SYN( "/autoconnect set ", "/autoconnect off") @@ -915,6 +1034,9 @@ static struct cmd_t command_defs[] = { "/vercheck", cmd_vercheck, parse_args, 0, 1, NULL, + CMD_TAGS( + CMD_TAG_SETTINGS, + CMD_TAG_UI) CMD_SYN( "/vercheck on|off") CMD_DESC( @@ -926,6 +1048,8 @@ static struct cmd_t command_defs[] = { "/titlebar", cmd_titlebar, parse_args, 2, 2, &cons_titlebar_setting, + CMD_TAGS( + CMD_TAG_UI) CMD_SYN( "/titlebar show on|off", "/titlebar goodbye on|off") @@ -939,6 +1063,8 @@ static struct cmd_t command_defs[] = { "/alias", cmd_alias, parse_args_with_freetext, 1, 3, NULL, + CMD_TAGS( + CMD_TAG_SETTINGS) CMD_SYN( "/alias list", "/alias add ", @@ -959,6 +1085,9 @@ static struct cmd_t command_defs[] = { "/chlog", cmd_chlog, parse_args, 1, 1, &cons_chlog_setting, + CMD_TAGS( + CMD_TAG_CHATTING, + CMD_TAG_SETTINGS) CMD_SYN( "/chlog on|off") CMD_DESC( @@ -973,6 +1102,9 @@ static struct cmd_t command_defs[] = { "/grlog", cmd_grlog, parse_args, 1, 1, &cons_grlog_setting, + CMD_TAGS( + CMD_TAG_GROUPCHAT, + CMD_TAG_SETTINGS) CMD_SYN( "/grlog on|off") CMD_DESC( @@ -985,6 +1117,8 @@ static struct cmd_t command_defs[] = { "/states", cmd_states, parse_args, 1, 1, &cons_states_setting, + CMD_TAGS( + CMD_TAG_SETTINGS) CMD_SYN( "/states on|off") CMD_DESC( @@ -996,6 +1130,8 @@ static struct cmd_t command_defs[] = { "/pgp", cmd_pgp, parse_args, 1, 3, NULL, + CMD_TAGS( + CMD_TAG_CHATTING) CMD_SYN( "/pgp libver", "/pgp keys", @@ -1025,6 +1161,8 @@ static struct cmd_t command_defs[] = { "/otr", cmd_otr, parse_args, 1, 3, NULL, + CMD_TAGS( + CMD_TAG_CHATTING) CMD_SYN( "/otr libver", "/otr gen", @@ -1068,6 +1206,8 @@ static struct cmd_t command_defs[] = { "/outtype", cmd_outtype, parse_args, 1, 1, &cons_outtype_setting, + CMD_TAGS( + CMD_TAG_SETTINGS) CMD_SYN( "/outtype on|off") CMD_DESC( @@ -1079,6 +1219,8 @@ static struct cmd_t command_defs[] = { "/gone", cmd_gone, parse_args, 1, 1, &cons_gone_setting, + CMD_TAGS( + CMD_TAG_SETTINGS) CMD_SYN( "/gone ") CMD_DESC( @@ -1091,6 +1233,10 @@ static struct cmd_t command_defs[] = { "/history", cmd_history, parse_args, 1, 1, &cons_history_setting, + CMD_TAGS( + CMD_TAG_CHATTING, + CMD_TAG_SETTINGS, + CMD_TAG_UI) CMD_SYN( "/history on|off") CMD_DESC( @@ -1103,6 +1249,8 @@ static struct cmd_t command_defs[] = { "/log", cmd_log, parse_args, 1, 2, &cons_log_setting, + CMD_TAGS( + CMD_TAG_SETTINGS) CMD_SYN( "/log where", "/log rotate on|off", @@ -1120,6 +1268,9 @@ static struct cmd_t command_defs[] = { "/carbons", cmd_carbons, parse_args, 1, 1, &cons_carbons_setting, + CMD_TAGS( + CMD_TAG_CHATTING, + CMD_TAG_SETTINGS) CMD_SYN( "/carbons on|off") CMD_DESC( @@ -1132,6 +1283,9 @@ static struct cmd_t command_defs[] = { "/receipts", cmd_receipts, parse_args, 2, 2, &cons_receipts_setting, + CMD_TAGS( + CMD_TAG_CHATTING, + CMD_TAG_SETTINGS) CMD_SYN( "/receipts request on|off", "/receipts send on|off") @@ -1145,6 +1299,8 @@ static struct cmd_t command_defs[] = { "/reconnect", cmd_reconnect, parse_args, 1, 1, &cons_reconnect_setting, + CMD_TAGS( + CMD_TAG_SETTINGS) CMD_SYN( "/reconnect ") CMD_DESC( @@ -1156,6 +1312,8 @@ static struct cmd_t command_defs[] = { "/autoping", cmd_autoping, parse_args, 1, 1, &cons_autoping_setting, + CMD_TAGS( + CMD_TAG_SETTINGS) CMD_SYN( "/autoping ") CMD_DESC( @@ -1167,6 +1325,7 @@ static struct cmd_t command_defs[] = { "/ping", cmd_ping, parse_args, 0, 1, NULL, + CMD_NOTAGS CMD_SYN( "/ping []") CMD_DESC( @@ -1179,6 +1338,9 @@ static struct cmd_t command_defs[] = { "/autoaway", cmd_autoaway, parse_args_with_freetext, 2, 2, &cons_autoaway_setting, + CMD_TAGS( + CMD_TAG_PRESENCES, + CMD_TAG_SETTINGS) CMD_SYN( "/autoaway mode idle|away|off", "/autoaway time ", @@ -1203,6 +1365,8 @@ static struct cmd_t command_defs[] = { "/priority", cmd_priority, parse_args, 1, 1, &cons_priority_setting, + CMD_TAGS( + CMD_TAG_PRESENCES) CMD_SYN( "/priority ") CMD_DESC( @@ -1215,6 +1379,8 @@ static struct cmd_t command_defs[] = { "/account", cmd_account, parse_args, 0, 4, NULL, + CMD_TAGS( + CMD_TAG_SETTINGS) CMD_SYN( "/account", "/account list", @@ -1288,6 +1454,9 @@ static struct cmd_t command_defs[] = { "/prefs", cmd_prefs, parse_args, 0, 1, NULL, + CMD_TAGS( + CMD_TAG_SETTINGS, + CMD_TAG_UI) CMD_SYN( "/prefs [ui|desktop|chat|log|conn|presence]") CMD_DESC( @@ -1305,6 +1474,8 @@ static struct cmd_t command_defs[] = { "/theme", cmd_theme, parse_args, 1, 2, &cons_theme_setting, + CMD_TAGS( + CMD_TAG_UI) CMD_SYN( "/theme list", "/theme load ", @@ -1322,6 +1493,8 @@ static struct cmd_t command_defs[] = { "/statuses", cmd_statuses, parse_args, 2, 2, &cons_statuses_setting, + CMD_TAGS( + CMD_TAG_UI) CMD_SYN( "/statuses console|chat|muc all|online|none") CMD_DESC( @@ -1342,6 +1515,8 @@ static struct cmd_t command_defs[] = { "/xmlconsole", cmd_xmlconsole, parse_args, 0, 0, NULL, + CMD_TAGS( + CMD_TAG_UI) CMD_SYN( "/xmlconsole") CMD_DESC( @@ -1352,6 +1527,9 @@ static struct cmd_t command_defs[] = { "/away", cmd_away, parse_args_with_freetext, 0, 1, NULL, + CMD_TAGS( + CMD_TAG_BASIC, + CMD_TAG_PRESENCES) CMD_SYN( "/away []") CMD_DESC( @@ -1365,6 +1543,9 @@ static struct cmd_t command_defs[] = { "/chat", cmd_chat, parse_args_with_freetext, 0, 1, NULL, + CMD_TAGS( + CMD_TAG_BASIC, + CMD_TAG_PRESENCES) CMD_SYN( "/chat []") CMD_DESC( @@ -1378,6 +1559,9 @@ static struct cmd_t command_defs[] = { "/dnd", cmd_dnd, parse_args_with_freetext, 0, 1, NULL, + CMD_TAGS( + CMD_TAG_BASIC, + CMD_TAG_PRESENCES) CMD_SYN( "/dnd []") CMD_DESC( @@ -1391,6 +1575,9 @@ static struct cmd_t command_defs[] = { "/online", cmd_online, parse_args_with_freetext, 0, 1, NULL, + CMD_TAGS( + CMD_TAG_BASIC, + CMD_TAG_PRESENCES) CMD_SYN( "/online []") CMD_DESC( @@ -1404,6 +1591,9 @@ static struct cmd_t command_defs[] = { "/xa", cmd_xa, parse_args_with_freetext, 0, 1, NULL, + CMD_TAGS( + CMD_TAG_BASIC, + CMD_TAG_PRESENCES) CMD_SYN( "/xa []") CMD_DESC( @@ -1494,6 +1684,7 @@ cmd_init(void) autocomplete_add(help_ac, "contacts"); autocomplete_add(help_ac, "service"); autocomplete_add(help_ac, "settings"); + autocomplete_add(help_ac, "ui"); autocomplete_add(help_ac, "navigation"); // load command defs into hash table @@ -2120,6 +2311,32 @@ cmd_reset_autocomplete(ProfWin *window) bookmark_autocomplete_reset(); } +gboolean +cmd_is_tag(const char * const str) +{ + return ((g_strcmp0(str, CMD_TAG_BASIC) == 0) || + (g_strcmp0(str, CMD_TAG_CHATTING) == 0) || + (g_strcmp0(str, CMD_TAG_CONTACTS) == 0) || + (g_strcmp0(str, CMD_TAG_GROUPCHAT) == 0) || + (g_strcmp0(str, CMD_TAG_PRESENCES) == 0) || + (g_strcmp0(str, CMD_TAG_SERVICE) == 0) || + (g_strcmp0(str, CMD_TAG_UI) == 0) || + (g_strcmp0(str, CMD_TAG_SETTINGS) == 0)); +} + +gboolean +cmd_has_tag(Command *pcmd, const char * const tag) +{ + int i = 0; + for (i = 0; pcmd->help.tags[i] != NULL; i++) { + if (g_strcmp0(tag, pcmd->help.tags[i]) == 0) { + return TRUE; + } + } + + return FALSE; +} + /* * Take a line of input and process it, return TRUE if profanity is to * continue, FALSE otherwise diff --git a/src/command/command.h b/src/command/command.h index e6fc7ead..3bfa8915 100644 --- a/src/command/command.h +++ b/src/command/command.h @@ -54,6 +54,9 @@ void cmd_autocomplete_remove_form_fields(DataForm *form); void cmd_alias_add(char *value); void cmd_alias_remove(char *value); +gboolean cmd_is_tag(const char * const str); +gboolean cmd_has_tag(Command *pcmd, const char * const tag); + gboolean cmd_process_input(ProfWin *window, char *inp); void cmd_execute_connect(ProfWin *window, const char * const account); diff --git a/src/command/commands.c b/src/command/commands.c index 1f240cba..40058b0c 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -75,7 +75,7 @@ static void _update_presence(const resource_presence_t presence, const char * const show, gchar **args); static gboolean _cmd_set_boolean_preference(gchar *arg, const char * const command, const char * const display, preference_t pref); -static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size); +//static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size); static void _who_room(ProfWin *window, const char * const command, gchar **args); static void _who_roster(ProfWin *window, const char * const command, gchar **args); @@ -828,46 +828,96 @@ cmd_help(ProfWin *window, const char * const command, gchar **args) cons_show("Use /help [command] without the leading slash, for help on a specific command"); cons_show(""); - } else if (strcmp(args[0], "basic") == 0) { - gchar *filter[] = { "/about", "/clear", "/close", "/connect", - "/disconnect", "/help", "/msg", "/join", "/quit", "/vercheck", - "/wins", "/ping" }; - _cmd_show_filtered_help("Basic commands", filter, ARRAY_SIZE(filter)); +// } else if (strcmp(args[0], "basic") == 0) { +// gchar *filter[] = { "/about", "/clear", "/close", "/connect", +// "/disconnect", "/help", "/msg", "/join", "/quit", "/vercheck", +// "/wins", "/ping" }; +// _cmd_show_filtered_help("Basic commands", filter, ARRAY_SIZE(filter)); +// +// } else if (strcmp(args[0], "chatting") == 0) { +// gchar *filter[] = { "/chlog", "/otr", "/gone", "/history", +// "/info", "/intype", "/msg", "/notify", "/outtype", "/status", +// "/close", "/clear", "/tiny" }; +// _cmd_show_filtered_help("Chat commands", filter, ARRAY_SIZE(filter)); +// +// } else if (strcmp(args[0], "groupchat") == 0) { +// gchar *filter[] = { "/close", "/clear", "/decline", "/grlog", +// "/invite", "/invites", "/join", "/leave", "/notify", "/msg", "/room", +// "/rooms", "/tiny", "/who", "/nick", "/privileges", "/info", "/occupants" }; +// _cmd_show_filtered_help("Groupchat commands", filter, ARRAY_SIZE(filter)); +// +// } else if (strcmp(args[0], "presences") == 0) { +// gchar *filter[] = { "/autoaway", "/away", "/chat", "/dnd", +// "/online", "/priority", "/account", "/status", "/statuses", "/who", +// "/xa" }; +// _cmd_show_filtered_help("Presence commands", filter, ARRAY_SIZE(filter)); +// +// } else if (strcmp(args[0], "contacts") == 0) { +// gchar *filter[] = { "/group", "/roster", "/sub", "/who" }; +// _cmd_show_filtered_help("Roster commands", filter, ARRAY_SIZE(filter)); +// +// } else if (strcmp(args[0], "service") == 0) { +// gchar *filter[] = { "/caps", "/disco", "/info", "/software", "/rooms" }; +// _cmd_show_filtered_help("Service discovery commands", filter, ARRAY_SIZE(filter)); +// +// } else if (strcmp(args[0], "settings") == 0) { +// gchar *filter[] = { "/account", "/autoaway", "/autoping", "/autoconnect", "/beep", +// "/carbons", "/chlog", "/flash", "/gone", "/grlog", "/history", "/intype", +// "/log", "/notify", "/outtype", "/prefs", "/priority", "/reconnect", "/roster", +// "/splash", "/states", "/statuses", "/theme", "/titlebar", "/vercheck", +// "/privileges", "/occupants", "/presence", "/wrap", "/winstidy" }; +// _cmd_show_filtered_help("Settings commands", filter, ARRAY_SIZE(filter)); +// + } else if (cmd_is_tag(args[0])) { + cons_show(""); + ProfWin *console = wins_get_console(); + win_vprint(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "%s commands", args[0]); - } else if (strcmp(args[0], "chatting") == 0) { - gchar *filter[] = { "/chlog", "/otr", "/gone", "/history", - "/info", "/intype", "/msg", "/notify", "/outtype", "/status", - "/close", "/clear", "/tiny" }; - _cmd_show_filtered_help("Chat commands", filter, ARRAY_SIZE(filter)); + GList *ordered_commands = NULL; + GHashTableIter iter; + gpointer key; + gpointer value; - } else if (strcmp(args[0], "groupchat") == 0) { - gchar *filter[] = { "/close", "/clear", "/decline", "/grlog", - "/invite", "/invites", "/join", "/leave", "/notify", "/msg", "/room", - "/rooms", "/tiny", "/who", "/nick", "/privileges", "/info", "/occupants" }; - _cmd_show_filtered_help("Groupchat commands", filter, ARRAY_SIZE(filter)); + g_hash_table_iter_init(&iter, commands); + while (g_hash_table_iter_next(&iter, &key, &value)) { + Command *pcmd = (Command *)value; + if (cmd_has_tag(pcmd, args[0])) { + ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0); + } + } - } else if (strcmp(args[0], "presences") == 0) { - gchar *filter[] = { "/autoaway", "/away", "/chat", "/dnd", - "/online", "/priority", "/account", "/status", "/statuses", "/who", - "/xa" }; - _cmd_show_filtered_help("Presence commands", filter, ARRAY_SIZE(filter)); + int maxlen = 0; + GList *curr = ordered_commands; + while (curr) { + gchar *cmd = curr->data; + int len = strlen(cmd); + if (len > maxlen) maxlen = len; + curr = g_list_next(curr); + } - } else if (strcmp(args[0], "contacts") == 0) { - gchar *filter[] = { "/group", "/roster", "/sub", "/who" }; - _cmd_show_filtered_help("Roster commands", filter, ARRAY_SIZE(filter)); - - } else if (strcmp(args[0], "service") == 0) { - gchar *filter[] = { "/caps", "/disco", "/info", "/software", "/rooms" }; - _cmd_show_filtered_help("Service discovery commands", filter, ARRAY_SIZE(filter)); - - } else if (strcmp(args[0], "settings") == 0) { - gchar *filter[] = { "/account", "/autoaway", "/autoping", "/autoconnect", "/beep", - "/carbons", "/chlog", "/flash", "/gone", "/grlog", "/history", "/intype", - "/log", "/notify", "/outtype", "/prefs", "/priority", "/reconnect", "/roster", - "/splash", "/states", "/statuses", "/theme", "/titlebar", "/vercheck", - "/privileges", "/occupants", "/presence", "/wrap", "/winstidy" }; - _cmd_show_filtered_help("Settings commands", filter, ARRAY_SIZE(filter)); + GString *cmds = g_string_new(""); + curr = ordered_commands; + int count = 0; + while (curr) { + gchar *cmd = curr->data; + if (count == 5) { + cons_show(cmds->str); + g_string_free(cmds, TRUE); + cmds = g_string_new(""); + count = 0; + } + g_string_append_printf(cmds, "%-*s", maxlen + 1, cmd); + curr = g_list_next(curr); + count++; + } + cons_show(cmds->str); + g_string_free(cmds, TRUE); + g_list_free(ordered_commands); + g_list_free(curr); + cons_show(""); + cons_show("Use /help [command] without the leading slash, for help on a specific command"); + cons_show(""); } else if (strcmp(args[0], "navigation") == 0) { cons_navigation_help(); } else { @@ -4743,50 +4793,50 @@ _cmd_set_boolean_preference(gchar *arg, const char * const command, return TRUE; } -static void -_cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size) -{ - ProfWin *console = wins_get_console(); - cons_show(""); - win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", heading); - - GList *ordered_commands = NULL; - int i; - for (i = 0; i < filter_size; i++) { - Command *pcmd = g_hash_table_lookup(commands, cmd_filter[i]); - ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0); - } - - int maxlen = 0; - GList *curr = ordered_commands; - while (curr) { - gchar *cmd = curr->data; - int len = strlen(cmd); - if (len > maxlen) maxlen = len; - curr = g_list_next(curr); - } - - GString *cmds = g_string_new(""); - curr = ordered_commands; - int count = 0; - while (curr) { - gchar *cmd = curr->data; - if (count == 5) { - cons_show(cmds->str); - g_string_free(cmds, TRUE); - cmds = g_string_new(""); - count = 0; - } - g_string_append_printf(cmds, "%-*s", maxlen + 1, cmd); - curr = g_list_next(curr); - count++; - } - cons_show(cmds->str); - g_string_free(cmds, TRUE); - g_list_free(ordered_commands); - g_list_free(curr); - - cons_show(""); - cons_show("Use /help [command] without the leading slash, for help on a specific command"); - cons_show(""); -} +//static void +//_cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size) +//{ +// ProfWin *console = wins_get_console(); +// cons_show(""); +// win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", heading); +// +// GList *ordered_commands = NULL; +// int i; +// for (i = 0; i < filter_size; i++) { +// Command *pcmd = g_hash_table_lookup(commands, cmd_filter[i]); +// ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0); +// } +// +// int maxlen = 0; +// GList *curr = ordered_commands; +// while (curr) { +// gchar *cmd = curr->data; +// int len = strlen(cmd); +// if (len > maxlen) maxlen = len; +// curr = g_list_next(curr); +// } +// +// GString *cmds = g_string_new(""); +// curr = ordered_commands; +// int count = 0; +// while (curr) { +// gchar *cmd = curr->data; +// if (count == 5) { +// cons_show(cmds->str); +// g_string_free(cmds, TRUE); +// cmds = g_string_new(""); +// count = 0; +// } +// g_string_append_printf(cmds, "%-*s", maxlen + 1, cmd); +// curr = g_list_next(curr); +// count++; +// } +// cons_show(cmds->str); +// g_string_free(cmds, TRUE); +// g_list_free(ordered_commands); +// g_list_free(curr); +// +// cons_show(""); +// cons_show("Use /help [command] without the leading slash, for help on a specific command"); +// cons_show(""); +//} diff --git a/src/command/commands.h b/src/command/commands.h index 46061a7d..c158f606 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -39,6 +39,7 @@ // Command help strings typedef struct cmd_help_t { + const gchar *tags[20]; const gchar *synopsis[50]; const gchar *desc; const gchar *args[50][2]; diff --git a/src/ui/console.c b/src/ui/console.c index a688d5f2..32d7e6c6 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1542,6 +1542,7 @@ cons_help(void) cons_show("/help contacts - List commands for manipulating your roster."); cons_show("/help service - List service discovery commands."); cons_show("/help settings - List commands for changing settings."); + cons_show("/help ui - List commands for configuring the user interface."); cons_show("/help navigation - How to navigate around Profanity."); cons_show("/help [command] - Detailed help on a specific command."); cons_show(""); From 08f43bee8edd32a8193997cd96fd97da47655ced Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 27 Jul 2015 23:55:04 +0100 Subject: [PATCH 20/25] Retagged commands --- src/command/command.c | 220 ++++++++++++++++++++++------------------ src/command/command.h | 2 +- src/command/commands.c | 222 +++++++++++++++++------------------------ src/ui/console.c | 21 ++-- 4 files changed, 226 insertions(+), 239 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 64cca07f..182dcc70 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -101,16 +101,16 @@ static char * _titlebar_autocomplete(ProfWin *window, const char * const input); static char * _inpblock_autocomplete(ProfWin *window, const char * const input); static char * _time_autocomplete(ProfWin *window, const char * const input); static char * _receipts_autocomplete(ProfWin *window, const char * const input); +static char * _help_autocomplete(ProfWin *window, const char * const input); GHashTable *commands = NULL; -#define CMD_TAG_BASIC "basic" -#define CMD_TAG_CHATTING "chatting" +#define CMD_TAG_CHAT "chat" #define CMD_TAG_GROUPCHAT "groupchat" -#define CMD_TAG_PRESENCES "presences" -#define CMD_TAG_CONTACTS "contacts" -#define CMD_TAG_SERVICE "service" -#define CMD_TAG_SETTINGS "settings" +#define CMD_TAG_ROSTER "roster" +#define CMD_TAG_PRESENCE "presence" +#define CMD_TAG_CONNECTION "connection" +#define CMD_TAG_DISCOVERY "discovery" #define CMD_TAG_UI "ui" #define CMD_NOTAGS { { NULL }, @@ -128,7 +128,7 @@ GHashTable *commands = NULL; static struct cmd_t command_defs[] = { { "/help", - cmd_help, parse_args, 0, 1, NULL, + cmd_help, parse_args, 0, 2, NULL, CMD_NOTAGS CMD_SYN( "/help [|]") @@ -157,7 +157,7 @@ static struct cmd_t command_defs[] = { "/connect", cmd_connect, parse_args, 0, 5, NULL, CMD_TAGS( - CMD_TAG_BASIC) + CMD_TAG_CONNECTION) CMD_SYN( "/connect []", "/connect [server ] [port ]") @@ -180,7 +180,7 @@ static struct cmd_t command_defs[] = { "/disconnect", cmd_disconnect, parse_args, 0, 0, NULL, CMD_TAGS( - CMD_TAG_BASIC) + CMD_TAG_CONNECTION) CMD_SYN( "/disconnect") CMD_DESC( @@ -192,9 +192,7 @@ static struct cmd_t command_defs[] = { "/msg", cmd_msg, parse_args_with_freetext, 1, 2, NULL, CMD_TAGS( - CMD_TAG_BASIC, - CMD_TAG_CHATTING, - CMD_TAG_GROUPCHAT) + CMD_TAG_CHAT) CMD_SYN( "/msg []", "/msg []") @@ -217,7 +215,7 @@ static struct cmd_t command_defs[] = { "/roster", cmd_roster, parse_args_with_freetext, 0, 3, NULL, CMD_TAGS( - CMD_TAG_CONTACTS, + CMD_TAG_ROSTER, CMD_TAG_UI) CMD_SYN( "/roster", @@ -267,7 +265,8 @@ static struct cmd_t command_defs[] = { "/group", cmd_group, parse_args_with_freetext, 0, 3, NULL, CMD_TAGS( - CMD_TAG_CONTACTS) + CMD_TAG_ROSTER, + CMD_TAG_UI) CMD_SYN( "/group", "/group show ", @@ -290,7 +289,10 @@ static struct cmd_t command_defs[] = { "/info", cmd_info, parse_args, 0, 1, NULL, - CMD_NOTAGS + CMD_TAGS( + CMD_TAG_ROSTER, + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) CMD_SYN( "/info", "/info |") @@ -309,7 +311,9 @@ static struct cmd_t command_defs[] = { "/caps", cmd_caps, parse_args, 0, 1, NULL, CMD_TAGS( - CMD_TAG_SERVICE) + CMD_TAG_DISCOVERY, + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) CMD_SYN( "/caps", "/caps |") @@ -328,7 +332,9 @@ static struct cmd_t command_defs[] = { "/software", cmd_software, parse_args, 0, 1, NULL, CMD_TAGS( - CMD_TAG_SERVICE) + CMD_TAG_DISCOVERY, + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) CMD_SYN( "/software", "/software |") @@ -347,7 +353,9 @@ static struct cmd_t command_defs[] = { "/status", cmd_status, parse_args, 0, 1, NULL, - CMD_NOTAGS + CMD_TAGS( + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) CMD_SYN( "/status", "/status |") @@ -365,6 +373,7 @@ static struct cmd_t command_defs[] = { "/resource", cmd_resource, parse_args, 1, 2, &cons_resource_setting, CMD_TAGS( + CMD_TAG_CHAT, CMD_TAG_UI) CMD_SYN( "/resource set ", @@ -384,7 +393,6 @@ static struct cmd_t command_defs[] = { "/join", cmd_join, parse_args, 0, 5, NULL, CMD_TAGS( - CMD_TAG_BASIC, CMD_TAG_GROUPCHAT) CMD_SYN( "/join", @@ -410,7 +418,6 @@ static struct cmd_t command_defs[] = { "/leave", cmd_leave, parse_args, 0, 0, NULL, CMD_TAGS( - CMD_TAG_BASIC, CMD_TAG_GROUPCHAT) CMD_SYN( "/leave") @@ -552,6 +559,7 @@ static struct cmd_t command_defs[] = { "/occupants", cmd_occupants, parse_args, 1, 3, cons_occupants_setting, CMD_TAGS( + CMD_TAG_GROUPCHAT, CMD_TAG_UI) CMD_SYN( "/occupants show|hide [jid]", @@ -633,7 +641,7 @@ static struct cmd_t command_defs[] = { "/disco", cmd_disco, parse_args, 1, 2, NULL, CMD_TAGS( - CMD_TAG_SERVICE) + CMD_TAG_DISCOVERY) CMD_SYN( "/disco info []", "/disco items []") @@ -653,7 +661,6 @@ static struct cmd_t command_defs[] = { "/nick", cmd_nick, parse_args_with_freetext, 1, 1, NULL, CMD_TAGS( - CMD_TAG_BASIC, CMD_TAG_GROUPCHAT) CMD_SYN( "/nick ") @@ -667,7 +674,6 @@ static struct cmd_t command_defs[] = { "/win", cmd_win, parse_args, 1, 1, NULL, CMD_TAGS( - CMD_TAG_BASIC, CMD_TAG_UI) CMD_SYN( "/win ") @@ -681,7 +687,6 @@ static struct cmd_t command_defs[] = { "/wins", cmd_wins, parse_args, 0, 3, NULL, CMD_TAGS( - CMD_TAG_BASIC, CMD_TAG_UI) CMD_SYN( "/wins tidy", @@ -700,8 +705,7 @@ static struct cmd_t command_defs[] = { "/sub", cmd_sub, parse_args, 1, 2, NULL, CMD_TAGS( - CMD_TAG_BASIC, - CMD_TAG_CONTACTS) + CMD_TAG_ROSTER) CMD_SYN( "/sub request []", "/sub allow []", @@ -729,7 +733,8 @@ static struct cmd_t command_defs[] = { "/tiny", cmd_tiny, parse_args, 1, 1, NULL, CMD_TAGS( - CMD_TAG_CHATTING) + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) CMD_SYN( "/tiny ") CMD_DESC( @@ -743,8 +748,9 @@ static struct cmd_t command_defs[] = { "/who", cmd_who, parse_args, 0, 2, NULL, CMD_TAGS( - CMD_TAG_BASIC, - CMD_TAG_CONTACTS) + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT, + CMD_TAG_ROSTER) CMD_SYN( "/who", "/who online|offline|away|dnd|xa|chat|available|unavailable|any []", @@ -773,8 +779,7 @@ static struct cmd_t command_defs[] = { "/close", cmd_close, parse_args, 0, 1, NULL, CMD_TAGS( - CMD_TAG_BASIC, - CMD_TAG_CHATTING) + CMD_TAG_UI) CMD_SYN( "/close []", "/close all|read") @@ -790,7 +795,8 @@ static struct cmd_t command_defs[] = { "/clear", cmd_clear, parse_args, 0, 0, NULL, - CMD_NOTAGS + CMD_TAGS( + CMD_TAG_UI) CMD_SYN( "/clear") CMD_DESC( @@ -801,8 +807,7 @@ static struct cmd_t command_defs[] = { "/quit", cmd_quit, parse_args, 0, 0, NULL, - CMD_TAGS( - CMD_TAG_BASIC) + CMD_NOTAGS CMD_SYN( "/quit") CMD_DESC( @@ -814,6 +819,7 @@ static struct cmd_t command_defs[] = { "/privileges", cmd_privileges, parse_args, 1, 1, &cons_privileges_setting, CMD_TAGS( + CMD_TAG_GROUPCHAT, CMD_TAG_UI) CMD_SYN( "/privileges on|off") @@ -842,7 +848,7 @@ static struct cmd_t command_defs[] = { "/encwarn", cmd_encwarn, parse_args, 1, 1, &cons_encwarn_setting, CMD_TAGS( - CMD_TAG_CHATTING, + CMD_TAG_CHAT, CMD_TAG_UI) CMD_SYN( "/encwarn on|off") @@ -856,7 +862,8 @@ static struct cmd_t command_defs[] = { "/presence", cmd_presence, parse_args, 1, 1, &cons_presence_setting, CMD_TAGS( - CMD_TAG_UI) + CMD_TAG_UI, + CMD_TAG_CHAT) CMD_SYN( "/presence on|off") CMD_DESC( @@ -936,7 +943,9 @@ static struct cmd_t command_defs[] = { "/notify", cmd_notify, parse_args, 2, 3, &cons_notify_setting, CMD_TAGS( - CMD_TAG_UI) + CMD_TAG_UI, + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) CMD_SYN( "/notify message on|off", "/notify message current on|off", @@ -991,7 +1000,8 @@ static struct cmd_t command_defs[] = { "/intype", cmd_intype, parse_args, 1, 1, &cons_intype_setting, CMD_TAGS( - CMD_TAG_UI) + CMD_TAG_UI, + CMD_TAG_CHAT) CMD_SYN( "/intype on|off") CMD_DESC( @@ -1017,7 +1027,7 @@ static struct cmd_t command_defs[] = { "/autoconnect", cmd_autoconnect, parse_args, 1, 2, &cons_autoconnect_setting, CMD_TAGS( - CMD_TAG_SETTINGS) + CMD_TAG_CONNECTION) CMD_SYN( "/autoconnect set ", "/autoconnect off") @@ -1035,7 +1045,6 @@ static struct cmd_t command_defs[] = { "/vercheck", cmd_vercheck, parse_args, 0, 1, NULL, CMD_TAGS( - CMD_TAG_SETTINGS, CMD_TAG_UI) CMD_SYN( "/vercheck on|off") @@ -1063,8 +1072,7 @@ static struct cmd_t command_defs[] = { "/alias", cmd_alias, parse_args_with_freetext, 1, 3, NULL, - CMD_TAGS( - CMD_TAG_SETTINGS) + CMD_NOTAGS CMD_SYN( "/alias list", "/alias add ", @@ -1086,8 +1094,7 @@ static struct cmd_t command_defs[] = { "/chlog", cmd_chlog, parse_args, 1, 1, &cons_chlog_setting, CMD_TAGS( - CMD_TAG_CHATTING, - CMD_TAG_SETTINGS) + CMD_TAG_CHAT) CMD_SYN( "/chlog on|off") CMD_DESC( @@ -1103,8 +1110,7 @@ static struct cmd_t command_defs[] = { "/grlog", cmd_grlog, parse_args, 1, 1, &cons_grlog_setting, CMD_TAGS( - CMD_TAG_GROUPCHAT, - CMD_TAG_SETTINGS) + CMD_TAG_GROUPCHAT) CMD_SYN( "/grlog on|off") CMD_DESC( @@ -1118,7 +1124,7 @@ static struct cmd_t command_defs[] = { "/states", cmd_states, parse_args, 1, 1, &cons_states_setting, CMD_TAGS( - CMD_TAG_SETTINGS) + CMD_TAG_CHAT) CMD_SYN( "/states on|off") CMD_DESC( @@ -1131,7 +1137,7 @@ static struct cmd_t command_defs[] = { "/pgp", cmd_pgp, parse_args, 1, 3, NULL, CMD_TAGS( - CMD_TAG_CHATTING) + CMD_TAG_CHAT) CMD_SYN( "/pgp libver", "/pgp keys", @@ -1162,7 +1168,7 @@ static struct cmd_t command_defs[] = { "/otr", cmd_otr, parse_args, 1, 3, NULL, CMD_TAGS( - CMD_TAG_CHATTING) + CMD_TAG_CHAT) CMD_SYN( "/otr libver", "/otr gen", @@ -1207,7 +1213,7 @@ static struct cmd_t command_defs[] = { "/outtype", cmd_outtype, parse_args, 1, 1, &cons_outtype_setting, CMD_TAGS( - CMD_TAG_SETTINGS) + CMD_TAG_CHAT) CMD_SYN( "/outtype on|off") CMD_DESC( @@ -1220,7 +1226,7 @@ static struct cmd_t command_defs[] = { "/gone", cmd_gone, parse_args, 1, 1, &cons_gone_setting, CMD_TAGS( - CMD_TAG_SETTINGS) + CMD_TAG_CHAT) CMD_SYN( "/gone ") CMD_DESC( @@ -1234,9 +1240,8 @@ static struct cmd_t command_defs[] = { "/history", cmd_history, parse_args, 1, 1, &cons_history_setting, CMD_TAGS( - CMD_TAG_CHATTING, - CMD_TAG_SETTINGS, - CMD_TAG_UI) + CMD_TAG_UI, + CMD_TAG_CHAT) CMD_SYN( "/history on|off") CMD_DESC( @@ -1249,8 +1254,7 @@ static struct cmd_t command_defs[] = { "/log", cmd_log, parse_args, 1, 2, &cons_log_setting, - CMD_TAGS( - CMD_TAG_SETTINGS) + CMD_NOTAGS CMD_SYN( "/log where", "/log rotate on|off", @@ -1269,8 +1273,7 @@ static struct cmd_t command_defs[] = { "/carbons", cmd_carbons, parse_args, 1, 1, &cons_carbons_setting, CMD_TAGS( - CMD_TAG_CHATTING, - CMD_TAG_SETTINGS) + CMD_TAG_CHAT) CMD_SYN( "/carbons on|off") CMD_DESC( @@ -1284,8 +1287,7 @@ static struct cmd_t command_defs[] = { "/receipts", cmd_receipts, parse_args, 2, 2, &cons_receipts_setting, CMD_TAGS( - CMD_TAG_CHATTING, - CMD_TAG_SETTINGS) + CMD_TAG_CHAT) CMD_SYN( "/receipts request on|off", "/receipts send on|off") @@ -1300,7 +1302,7 @@ static struct cmd_t command_defs[] = { "/reconnect", cmd_reconnect, parse_args, 1, 1, &cons_reconnect_setting, CMD_TAGS( - CMD_TAG_SETTINGS) + CMD_TAG_CONNECTION) CMD_SYN( "/reconnect ") CMD_DESC( @@ -1313,7 +1315,7 @@ static struct cmd_t command_defs[] = { "/autoping", cmd_autoping, parse_args, 1, 1, &cons_autoping_setting, CMD_TAGS( - CMD_TAG_SETTINGS) + CMD_TAG_CONNECTION) CMD_SYN( "/autoping ") CMD_DESC( @@ -1325,7 +1327,8 @@ static struct cmd_t command_defs[] = { "/ping", cmd_ping, parse_args, 0, 1, NULL, - CMD_NOTAGS + CMD_TAGS( + CMD_TAG_CONNECTION) CMD_SYN( "/ping []") CMD_DESC( @@ -1339,8 +1342,7 @@ static struct cmd_t command_defs[] = { "/autoaway", cmd_autoaway, parse_args_with_freetext, 2, 2, &cons_autoaway_setting, CMD_TAGS( - CMD_TAG_PRESENCES, - CMD_TAG_SETTINGS) + CMD_TAG_PRESENCE) CMD_SYN( "/autoaway mode idle|away|off", "/autoaway time ", @@ -1366,7 +1368,7 @@ static struct cmd_t command_defs[] = { "/priority", cmd_priority, parse_args, 1, 1, &cons_priority_setting, CMD_TAGS( - CMD_TAG_PRESENCES) + CMD_TAG_PRESENCE) CMD_SYN( "/priority ") CMD_DESC( @@ -1380,7 +1382,10 @@ static struct cmd_t command_defs[] = { "/account", cmd_account, parse_args, 0, 4, NULL, CMD_TAGS( - CMD_TAG_SETTINGS) + CMD_TAG_CONNECTION + CMD_TAG_PRESENCE, + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) CMD_SYN( "/account", "/account list", @@ -1454,9 +1459,7 @@ static struct cmd_t command_defs[] = { "/prefs", cmd_prefs, parse_args, 0, 1, NULL, - CMD_TAGS( - CMD_TAG_SETTINGS, - CMD_TAG_UI) + CMD_NOTAGS CMD_SYN( "/prefs [ui|desktop|chat|log|conn|presence]") CMD_DESC( @@ -1494,7 +1497,9 @@ static struct cmd_t command_defs[] = { "/statuses", cmd_statuses, parse_args, 2, 2, &cons_statuses_setting, CMD_TAGS( - CMD_TAG_UI) + CMD_TAG_UI, + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) CMD_SYN( "/statuses console|chat|muc all|online|none") CMD_DESC( @@ -1528,8 +1533,7 @@ static struct cmd_t command_defs[] = { "/away", cmd_away, parse_args_with_freetext, 0, 1, NULL, CMD_TAGS( - CMD_TAG_BASIC, - CMD_TAG_PRESENCES) + CMD_TAG_PRESENCE) CMD_SYN( "/away []") CMD_DESC( @@ -1544,8 +1548,7 @@ static struct cmd_t command_defs[] = { "/chat", cmd_chat, parse_args_with_freetext, 0, 1, NULL, CMD_TAGS( - CMD_TAG_BASIC, - CMD_TAG_PRESENCES) + CMD_TAG_PRESENCE) CMD_SYN( "/chat []") CMD_DESC( @@ -1560,8 +1563,7 @@ static struct cmd_t command_defs[] = { "/dnd", cmd_dnd, parse_args_with_freetext, 0, 1, NULL, CMD_TAGS( - CMD_TAG_BASIC, - CMD_TAG_PRESENCES) + CMD_TAG_PRESENCE) CMD_SYN( "/dnd []") CMD_DESC( @@ -1576,8 +1578,7 @@ static struct cmd_t command_defs[] = { "/online", cmd_online, parse_args_with_freetext, 0, 1, NULL, CMD_TAGS( - CMD_TAG_BASIC, - CMD_TAG_PRESENCES) + CMD_TAG_PRESENCE) CMD_SYN( "/online []") CMD_DESC( @@ -1592,8 +1593,7 @@ static struct cmd_t command_defs[] = { "/xa", cmd_xa, parse_args_with_freetext, 0, 1, NULL, CMD_TAGS( - CMD_TAG_BASIC, - CMD_TAG_PRESENCES) + CMD_TAG_PRESENCE) CMD_SYN( "/xa []") CMD_DESC( @@ -1610,6 +1610,7 @@ static Autocomplete commands_ac; static Autocomplete who_room_ac; static Autocomplete who_roster_ac; static Autocomplete help_ac; +static Autocomplete help_commands_ac; static Autocomplete notify_ac; static Autocomplete notify_room_ac; static Autocomplete notify_message_ac; @@ -1677,14 +1678,6 @@ cmd_init(void) help_ac = autocomplete_new(); autocomplete_add(help_ac, "commands"); - autocomplete_add(help_ac, "basic"); - autocomplete_add(help_ac, "chatting"); - autocomplete_add(help_ac, "groupchat"); - autocomplete_add(help_ac, "presences"); - autocomplete_add(help_ac, "contacts"); - autocomplete_add(help_ac, "service"); - autocomplete_add(help_ac, "settings"); - autocomplete_add(help_ac, "ui"); autocomplete_add(help_ac, "navigation"); // load command defs into hash table @@ -1715,6 +1708,15 @@ cmd_init(void) } prefs_free_aliases(aliases); + help_commands_ac = autocomplete_new(); + autocomplete_add(help_commands_ac, "chat"); + autocomplete_add(help_commands_ac, "groupchat"); + autocomplete_add(help_commands_ac, "roster"); + autocomplete_add(help_commands_ac, "presence"); + autocomplete_add(help_commands_ac, "discovery"); + autocomplete_add(help_commands_ac, "connection"); + autocomplete_add(help_commands_ac, "ui"); + prefs_ac = autocomplete_new(); autocomplete_add(prefs_ac, "ui"); autocomplete_add(prefs_ac, "desktop"); @@ -2055,6 +2057,7 @@ cmd_uninit(void) autocomplete_free(who_room_ac); autocomplete_free(who_roster_ac); autocomplete_free(help_ac); + autocomplete_free(help_commands_ac); autocomplete_free(notify_ac); autocomplete_free(notify_message_ac); autocomplete_free(notify_room_ac); @@ -2223,6 +2226,7 @@ cmd_reset_autocomplete(ProfWin *window) prefs_reset_boolean_choice(); presence_reset_sub_request_search(); autocomplete_reset(help_ac); + autocomplete_reset(help_commands_ac); autocomplete_reset(notify_ac); autocomplete_reset(notify_message_ac); autocomplete_reset(notify_room_ac); @@ -2312,16 +2316,15 @@ cmd_reset_autocomplete(ProfWin *window) } gboolean -cmd_is_tag(const char * const str) +cmd_valid_tag(const char * const str) { - return ((g_strcmp0(str, CMD_TAG_BASIC) == 0) || - (g_strcmp0(str, CMD_TAG_CHATTING) == 0) || - (g_strcmp0(str, CMD_TAG_CONTACTS) == 0) || + return ((g_strcmp0(str, CMD_TAG_CHAT) == 0) || (g_strcmp0(str, CMD_TAG_GROUPCHAT) == 0) || - (g_strcmp0(str, CMD_TAG_PRESENCES) == 0) || - (g_strcmp0(str, CMD_TAG_SERVICE) == 0) || - (g_strcmp0(str, CMD_TAG_UI) == 0) || - (g_strcmp0(str, CMD_TAG_SETTINGS) == 0)); + (g_strcmp0(str, CMD_TAG_PRESENCE) == 0) || + (g_strcmp0(str, CMD_TAG_ROSTER) == 0) || + (g_strcmp0(str, CMD_TAG_DISCOVERY) == 0) || + (g_strcmp0(str, CMD_TAG_CONNECTION) == 0) || + (g_strcmp0(str, CMD_TAG_UI) == 0)); } gboolean @@ -2496,8 +2499,8 @@ _cmd_complete_parameters(ProfWin *window, const char * const input) } } - gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins", "/subject", "/room" }; - Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac, subject_ac, room_ac }; + gchar *cmds[] = { "/prefs", "/disco", "/close", "/wins", "/subject", "/room" }; + Autocomplete completers[] = { prefs_ac, disco_ac, close_ac, wins_ac, subject_ac, room_ac }; for (i = 0; i < ARRAY_SIZE(cmds); i++) { result = autocomplete_param_with_ac(input, cmds[i], completers[i], TRUE); @@ -2507,6 +2510,7 @@ _cmd_complete_parameters(ProfWin *window, const char * const input) } GHashTable *ac_funcs = g_hash_table_new(g_str_hash, g_str_equal); + g_hash_table_insert(ac_funcs, "/help", _help_autocomplete); g_hash_table_insert(ac_funcs, "/who", _who_autocomplete); g_hash_table_insert(ac_funcs, "/sub", _sub_autocomplete); g_hash_table_insert(ac_funcs, "/notify", _notify_autocomplete); @@ -3479,6 +3483,24 @@ _connect_autocomplete(ProfWin *window, const char * const input) return NULL; } +static char * +_help_autocomplete(ProfWin *window, const char * const input) +{ + char *result = NULL; + + result = autocomplete_param_with_ac(input, "/help commands", help_commands_ac, TRUE); + if (result) { + return result; + } + + result = autocomplete_param_with_ac(input, "/help", help_ac, TRUE); + if (result) { + return result; + } + + return NULL; +} + static char * _join_autocomplete(ProfWin *window, const char * const input) { diff --git a/src/command/command.h b/src/command/command.h index 3bfa8915..78b4bf78 100644 --- a/src/command/command.h +++ b/src/command/command.h @@ -54,7 +54,7 @@ void cmd_autocomplete_remove_form_fields(DataForm *form); void cmd_alias_add(char *value); void cmd_alias_remove(char *value); -gboolean cmd_is_tag(const char * const str); +gboolean cmd_valid_tag(const char * const str); gboolean cmd_has_tag(Command *pcmd, const char * const tag); gboolean cmd_process_input(ProfWin *window, char *inp); diff --git a/src/command/commands.c b/src/command/commands.c index 40058b0c..d42663b8 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -780,144 +780,110 @@ cmd_help(ProfWin *window, const char * const command, gchar **args) if (num_args == 0) { cons_help(); } else if (strcmp(args[0], "commands") == 0) { - cons_show(""); - ProfWin *console = wins_get_console(); - win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "All commands"); - - GList *ordered_commands = NULL; - GHashTableIter iter; - gpointer key; - gpointer value; - - g_hash_table_iter_init(&iter, commands); - while (g_hash_table_iter_next(&iter, &key, &value)) { - Command *pcmd = (Command *)value; - ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0); - } - - int maxlen = 0; - GList *curr = ordered_commands; - while (curr) { - gchar *cmd = curr->data; - int len = strlen(cmd); - if (len > maxlen) maxlen = len; - curr = g_list_next(curr); - } - - GString *cmds = g_string_new(""); - curr = ordered_commands; - int count = 0; - while (curr) { - gchar *cmd = curr->data; - if (count == 5) { - cons_show(cmds->str); - g_string_free(cmds, TRUE); - cmds = g_string_new(""); - count = 0; + if (args[1]) { + if (!cmd_valid_tag(args[1])) { + cons_bad_cmd_usage(command); + return TRUE; } - g_string_append_printf(cmds, "%-*s", maxlen + 1, cmd); - curr = g_list_next(curr); - count++; - } - cons_show(cmds->str); - g_string_free(cmds, TRUE); - g_list_free(ordered_commands); - g_list_free(curr); - cons_show(""); - cons_show("Use /help [command] without the leading slash, for help on a specific command"); - cons_show(""); + cons_show(""); + ProfWin *console = wins_get_console(); + win_vprint(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "%s commands", args[1]); -// } else if (strcmp(args[0], "basic") == 0) { -// gchar *filter[] = { "/about", "/clear", "/close", "/connect", -// "/disconnect", "/help", "/msg", "/join", "/quit", "/vercheck", -// "/wins", "/ping" }; -// _cmd_show_filtered_help("Basic commands", filter, ARRAY_SIZE(filter)); -// -// } else if (strcmp(args[0], "chatting") == 0) { -// gchar *filter[] = { "/chlog", "/otr", "/gone", "/history", -// "/info", "/intype", "/msg", "/notify", "/outtype", "/status", -// "/close", "/clear", "/tiny" }; -// _cmd_show_filtered_help("Chat commands", filter, ARRAY_SIZE(filter)); -// -// } else if (strcmp(args[0], "groupchat") == 0) { -// gchar *filter[] = { "/close", "/clear", "/decline", "/grlog", -// "/invite", "/invites", "/join", "/leave", "/notify", "/msg", "/room", -// "/rooms", "/tiny", "/who", "/nick", "/privileges", "/info", "/occupants" }; -// _cmd_show_filtered_help("Groupchat commands", filter, ARRAY_SIZE(filter)); -// -// } else if (strcmp(args[0], "presences") == 0) { -// gchar *filter[] = { "/autoaway", "/away", "/chat", "/dnd", -// "/online", "/priority", "/account", "/status", "/statuses", "/who", -// "/xa" }; -// _cmd_show_filtered_help("Presence commands", filter, ARRAY_SIZE(filter)); -// -// } else if (strcmp(args[0], "contacts") == 0) { -// gchar *filter[] = { "/group", "/roster", "/sub", "/who" }; -// _cmd_show_filtered_help("Roster commands", filter, ARRAY_SIZE(filter)); -// -// } else if (strcmp(args[0], "service") == 0) { -// gchar *filter[] = { "/caps", "/disco", "/info", "/software", "/rooms" }; -// _cmd_show_filtered_help("Service discovery commands", filter, ARRAY_SIZE(filter)); -// -// } else if (strcmp(args[0], "settings") == 0) { -// gchar *filter[] = { "/account", "/autoaway", "/autoping", "/autoconnect", "/beep", -// "/carbons", "/chlog", "/flash", "/gone", "/grlog", "/history", "/intype", -// "/log", "/notify", "/outtype", "/prefs", "/priority", "/reconnect", "/roster", -// "/splash", "/states", "/statuses", "/theme", "/titlebar", "/vercheck", -// "/privileges", "/occupants", "/presence", "/wrap", "/winstidy" }; -// _cmd_show_filtered_help("Settings commands", filter, ARRAY_SIZE(filter)); -// - } else if (cmd_is_tag(args[0])) { - cons_show(""); - ProfWin *console = wins_get_console(); - win_vprint(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "%s commands", args[0]); + GList *ordered_commands = NULL; + GHashTableIter iter; + gpointer key; + gpointer value; - GList *ordered_commands = NULL; - GHashTableIter iter; - gpointer key; - gpointer value; + g_hash_table_iter_init(&iter, commands); + while (g_hash_table_iter_next(&iter, &key, &value)) { + Command *pcmd = (Command *)value; + if (cmd_has_tag(pcmd, args[1])) { + ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0); + } + } - g_hash_table_iter_init(&iter, commands); - while (g_hash_table_iter_next(&iter, &key, &value)) { - Command *pcmd = (Command *)value; - if (cmd_has_tag(pcmd, args[0])) { + int maxlen = 0; + GList *curr = ordered_commands; + while (curr) { + gchar *cmd = curr->data; + int len = strlen(cmd); + if (len > maxlen) maxlen = len; + curr = g_list_next(curr); + } + + GString *cmds = g_string_new(""); + curr = ordered_commands; + int count = 0; + while (curr) { + gchar *cmd = curr->data; + if (count == 5) { + cons_show(cmds->str); + g_string_free(cmds, TRUE); + cmds = g_string_new(""); + count = 0; + } + g_string_append_printf(cmds, "%-*s", maxlen + 1, cmd); + curr = g_list_next(curr); + count++; + } + cons_show(cmds->str); + g_string_free(cmds, TRUE); + g_list_free(ordered_commands); + g_list_free(curr); + + cons_show(""); + cons_show("Use /help [command] without the leading slash, for help on a specific command"); + cons_show(""); + } else { + cons_show(""); + ProfWin *console = wins_get_console(); + win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "All commands"); + + GList *ordered_commands = NULL; + GHashTableIter iter; + gpointer key; + gpointer value; + + g_hash_table_iter_init(&iter, commands); + while (g_hash_table_iter_next(&iter, &key, &value)) { + Command *pcmd = (Command *)value; ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0); } - } - int maxlen = 0; - GList *curr = ordered_commands; - while (curr) { - gchar *cmd = curr->data; - int len = strlen(cmd); - if (len > maxlen) maxlen = len; - curr = g_list_next(curr); - } - - GString *cmds = g_string_new(""); - curr = ordered_commands; - int count = 0; - while (curr) { - gchar *cmd = curr->data; - if (count == 5) { - cons_show(cmds->str); - g_string_free(cmds, TRUE); - cmds = g_string_new(""); - count = 0; + int maxlen = 0; + GList *curr = ordered_commands; + while (curr) { + gchar *cmd = curr->data; + int len = strlen(cmd); + if (len > maxlen) maxlen = len; + curr = g_list_next(curr); } - g_string_append_printf(cmds, "%-*s", maxlen + 1, cmd); - curr = g_list_next(curr); - count++; - } - cons_show(cmds->str); - g_string_free(cmds, TRUE); - g_list_free(ordered_commands); - g_list_free(curr); - cons_show(""); - cons_show("Use /help [command] without the leading slash, for help on a specific command"); - cons_show(""); + GString *cmds = g_string_new(""); + curr = ordered_commands; + int count = 0; + while (curr) { + gchar *cmd = curr->data; + if (count == 5) { + cons_show(cmds->str); + g_string_free(cmds, TRUE); + cmds = g_string_new(""); + count = 0; + } + g_string_append_printf(cmds, "%-*s", maxlen + 1, cmd); + curr = g_list_next(curr); + count++; + } + cons_show(cmds->str); + g_string_free(cmds, TRUE); + g_list_free(ordered_commands); + g_list_free(curr); + + cons_show(""); + cons_show("Use /help [command] without the leading slash, for help on a specific command"); + cons_show(""); + } } else if (strcmp(args[0], "navigation") == 0) { cons_navigation_help(); } else { diff --git a/src/ui/console.c b/src/ui/console.c index 32d7e6c6..a1cf9fbf 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1534,17 +1534,16 @@ cons_help(void) cons_show(""); cons_show("Choose a help option:"); cons_show(""); - cons_show("/help commands - List all commands."); - cons_show("/help basic - List basic commands for getting started."); - cons_show("/help chatting - List chat commands."); - cons_show("/help groupchat - List groupchat commands."); - cons_show("/help presences - List commands to change presence."); - cons_show("/help contacts - List commands for manipulating your roster."); - cons_show("/help service - List service discovery commands."); - cons_show("/help settings - List commands for changing settings."); - cons_show("/help ui - List commands for configuring the user interface."); - cons_show("/help navigation - How to navigate around Profanity."); - cons_show("/help [command] - Detailed help on a specific command."); + cons_show("/help commands - List all commands."); + cons_show("/help commands chat - List chat commands."); + cons_show("/help commands groupchat - List groupchat commands."); + cons_show("/help commands roster - List commands for manipulating your roster."); + cons_show("/help commands presence - List commands to change your presence."); + cons_show("/help commands discovery - List service discovery commands."); + cons_show("/help commands connection - List commands related to managing your connection."); + cons_show("/help commands ui - List commands for manipulating the user interface."); + cons_show("/help [command] - Detailed help on a specific command."); + cons_show("/help navigation - How to navigate around Profanity."); cons_show(""); cons_alert(); From 30c1cdd3185cbbc59f79ce16305b1c099ee4044f Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 28 Jul 2015 00:10:18 +0100 Subject: [PATCH 21/25] Refactored showing tagged command help --- src/command/commands.c | 163 ++++++++++++++++------------------------- 1 file changed, 65 insertions(+), 98 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index d42663b8..e26db08f 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -773,6 +773,68 @@ cmd_win(ProfWin *window, const char * const command, gchar **args) return TRUE; } +static void +_cmd_help_cmd_list(const char * const tag) +{ + cons_show(""); + ProfWin *console = wins_get_console(); + if (tag) { + win_vprint(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "%s commands", tag); + } else { + win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "All commands"); + } + + GList *ordered_commands = NULL; + GHashTableIter iter; + gpointer key; + gpointer value; + + g_hash_table_iter_init(&iter, commands); + while (g_hash_table_iter_next(&iter, &key, &value)) { + Command *pcmd = (Command *)value; + if (tag) { + if (cmd_has_tag(pcmd, tag)) { + ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0); + } + } else { + ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0); + } + } + + int maxlen = 0; + GList *curr = ordered_commands; + while (curr) { + gchar *cmd = curr->data; + int len = strlen(cmd); + if (len > maxlen) maxlen = len; + curr = g_list_next(curr); + } + + GString *cmds = g_string_new(""); + curr = ordered_commands; + int count = 0; + while (curr) { + gchar *cmd = curr->data; + if (count == 5) { + cons_show(cmds->str); + g_string_free(cmds, TRUE); + cmds = g_string_new(""); + count = 0; + } + g_string_append_printf(cmds, "%-*s", maxlen + 1, cmd); + curr = g_list_next(curr); + count++; + } + cons_show(cmds->str); + g_string_free(cmds, TRUE); + g_list_free(ordered_commands); + g_list_free(curr); + + cons_show(""); + cons_show("Use /help [command] without the leading slash, for help on a specific command"); + cons_show(""); +} + gboolean cmd_help(ProfWin *window, const char * const command, gchar **args) { @@ -783,106 +845,11 @@ cmd_help(ProfWin *window, const char * const command, gchar **args) if (args[1]) { if (!cmd_valid_tag(args[1])) { cons_bad_cmd_usage(command); - return TRUE; + } else { + _cmd_help_cmd_list(args[1]); } - - cons_show(""); - ProfWin *console = wins_get_console(); - win_vprint(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "%s commands", args[1]); - - GList *ordered_commands = NULL; - GHashTableIter iter; - gpointer key; - gpointer value; - - g_hash_table_iter_init(&iter, commands); - while (g_hash_table_iter_next(&iter, &key, &value)) { - Command *pcmd = (Command *)value; - if (cmd_has_tag(pcmd, args[1])) { - ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0); - } - } - - int maxlen = 0; - GList *curr = ordered_commands; - while (curr) { - gchar *cmd = curr->data; - int len = strlen(cmd); - if (len > maxlen) maxlen = len; - curr = g_list_next(curr); - } - - GString *cmds = g_string_new(""); - curr = ordered_commands; - int count = 0; - while (curr) { - gchar *cmd = curr->data; - if (count == 5) { - cons_show(cmds->str); - g_string_free(cmds, TRUE); - cmds = g_string_new(""); - count = 0; - } - g_string_append_printf(cmds, "%-*s", maxlen + 1, cmd); - curr = g_list_next(curr); - count++; - } - cons_show(cmds->str); - g_string_free(cmds, TRUE); - g_list_free(ordered_commands); - g_list_free(curr); - - cons_show(""); - cons_show("Use /help [command] without the leading slash, for help on a specific command"); - cons_show(""); } else { - cons_show(""); - ProfWin *console = wins_get_console(); - win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "All commands"); - - GList *ordered_commands = NULL; - GHashTableIter iter; - gpointer key; - gpointer value; - - g_hash_table_iter_init(&iter, commands); - while (g_hash_table_iter_next(&iter, &key, &value)) { - Command *pcmd = (Command *)value; - ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0); - } - - int maxlen = 0; - GList *curr = ordered_commands; - while (curr) { - gchar *cmd = curr->data; - int len = strlen(cmd); - if (len > maxlen) maxlen = len; - curr = g_list_next(curr); - } - - GString *cmds = g_string_new(""); - curr = ordered_commands; - int count = 0; - while (curr) { - gchar *cmd = curr->data; - if (count == 5) { - cons_show(cmds->str); - g_string_free(cmds, TRUE); - cmds = g_string_new(""); - count = 0; - } - g_string_append_printf(cmds, "%-*s", maxlen + 1, cmd); - curr = g_list_next(curr); - count++; - } - cons_show(cmds->str); - g_string_free(cmds, TRUE); - g_list_free(ordered_commands); - g_list_free(curr); - - cons_show(""); - cons_show("Use /help [command] without the leading slash, for help on a specific command"); - cons_show(""); + _cmd_help_cmd_list(NULL); } } else if (strcmp(args[0], "navigation") == 0) { cons_navigation_help(); From 5576b88a0498f138939f43a0d7948870939c907d Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 29 Jul 2015 22:48:03 +0100 Subject: [PATCH 22/25] Added indent padding --- src/command/commands.c | 26 +- src/ui/buffer.c | 3 +- src/ui/buffer.h | 3 +- src/ui/console.c | 192 +++++++-------- src/ui/core.c | 452 +++++++++++++++++------------------ src/ui/ui.h | 4 +- src/ui/window.c | 186 ++++++++------ src/ui/window.h | 2 +- src/window_list.c | 2 +- tests/unittests/ui/stub_ui.c | 4 +- 10 files changed, 452 insertions(+), 422 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index e26db08f..86be7bc1 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -779,9 +779,9 @@ _cmd_help_cmd_list(const char * const tag) cons_show(""); ProfWin *console = wins_get_console(); if (tag) { - win_vprint(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "%s commands", tag); + win_vprint(console, '-', 0, NULL, 0, THEME_WHITE_BOLD, "", "%s commands", tag); } else { - win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "All commands"); + win_print(console, '-', 0, NULL, 0, THEME_WHITE_BOLD, "", "All commands"); } GList *ordered_commands = NULL; @@ -1857,7 +1857,7 @@ cmd_status(ProfWin *window, const char * const command, gchar **args) if (occupant) { win_show_occupant(window, occupant); } else { - win_vprint(window, '-', NULL, 0, 0, "", "No such participant \"%s\" in room.", usr); + win_vprint(window, '-', 0, NULL, 0, 0, "", "No such participant \"%s\" in room.", usr); } } else { ui_current_print_line("You must specify a nickname."); @@ -2610,7 +2610,7 @@ cmd_kick(ProfWin *window, const char * const command, gchar **args) char *reason = args[1]; iq_room_kick_occupant(mucwin->roomjid, nick, reason); } else { - win_vprint((ProfWin*) mucwin, '!', NULL, 0, 0, "", "Occupant does not exist: %s", nick); + win_vprint((ProfWin*) mucwin, '!', 0, NULL, 0, 0, "", "Occupant does not exist: %s", nick); } } else { cons_bad_cmd_usage(command); @@ -2668,10 +2668,10 @@ cmd_subject(ProfWin *window, const char * const command, gchar **args) if (args[0] == NULL) { char *subject = muc_subject(mucwin->roomjid); if (subject) { - win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "Room subject: "); - win_vprint(window, '!', NULL, NO_DATE, 0, "", "%s", subject); + win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "Room subject: "); + win_vprint(window, '!', 0, NULL, NO_DATE, 0, "", "%s", subject); } else { - win_print(window, '!', NULL, 0, THEME_ROOMINFO, "", "Room has no subject"); + win_print(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Room has no subject"); } return TRUE; } @@ -2736,7 +2736,7 @@ cmd_affiliation(ProfWin *window, const char * const command, gchar **args) iq_room_affiliation_list(mucwin->roomjid, "member"); iq_room_affiliation_list(mucwin->roomjid, "outcast"); } else if (g_strcmp0(affiliation, "none") == 0) { - win_print((ProfWin*) mucwin, '!', NULL, 0, 0, "", "Cannot list users with no affiliation."); + win_print((ProfWin*) mucwin, '!', 0, NULL, 0, 0, "", "Cannot list users with no affiliation."); } else { iq_room_affiliation_list(mucwin->roomjid, affiliation); } @@ -2804,7 +2804,7 @@ cmd_role(ProfWin *window, const char * const command, gchar **args) iq_room_role_list(mucwin->roomjid, "participant"); iq_room_role_list(mucwin->roomjid, "visitor"); } else if (g_strcmp0(role, "none") == 0) { - win_print((ProfWin*) mucwin, '!', NULL, 0, 0, "", "Cannot list users with no role."); + win_print((ProfWin*) mucwin, '!', 0, NULL, 0, 0, "", "Cannot list users with no role."); } else { iq_room_role_list(mucwin->roomjid, role); } @@ -2866,12 +2866,12 @@ cmd_room(ProfWin *window, const char * const command, gchar **args) if (g_strcmp0(args[0], "accept") == 0) { gboolean requires_config = muc_requires_config(mucwin->roomjid); if (!requires_config) { - win_print(window, '!', NULL, 0, THEME_ROOMINFO, "", "Current room does not require configuration."); + win_print(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Current room does not require configuration."); return TRUE; } else { iq_confirm_instant_room(mucwin->roomjid); muc_set_requires_config(mucwin->roomjid, FALSE); - win_print(window, '!', NULL, 0, THEME_ROOMINFO, "", "Room unlocked."); + win_print(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Room unlocked."); return TRUE; } } @@ -3247,13 +3247,13 @@ cmd_tiny(ProfWin *window, const char * const command, gchar **args) } if (!tinyurl_valid(url)) { - win_vprint(window, '-', NULL, 0, THEME_ERROR, "", "/tiny, badly formed URL: %s", url); + win_vprint(window, '-', 0, NULL, 0, THEME_ERROR, "", "/tiny, badly formed URL: %s", url); return TRUE; } char *tiny = tinyurl_get(url); if (!tiny) { - win_print(window, '-', NULL, 0, THEME_ERROR, "", "Couldn't create tinyurl."); + win_print(window, '-', 0, NULL, 0, THEME_ERROR, "", "Couldn't create tinyurl."); return TRUE; } diff --git a/src/ui/buffer.c b/src/ui/buffer.c index b4771f1a..a464de4e 100644 --- a/src/ui/buffer.c +++ b/src/ui/buffer.c @@ -80,11 +80,12 @@ buffer_free(ProfBuff buffer) } void -buffer_push(ProfBuff buffer, const char show_char, GDateTime *time, +buffer_push(ProfBuff buffer, const char show_char, int pad_indent, GDateTime *time, int flags, theme_item_t theme_item, const char * const from, const char * const message, DeliveryReceipt *receipt) { ProfBuffEntry *e = malloc(sizeof(struct prof_buff_entry_t)); e->show_char = show_char; + e->pad_indent = pad_indent; e->flags = flags; e->theme_item = theme_item; e->time = g_date_time_ref(time); diff --git a/src/ui/buffer.h b/src/ui/buffer.h index cad7eee0..dcee0aff 100644 --- a/src/ui/buffer.h +++ b/src/ui/buffer.h @@ -47,6 +47,7 @@ typedef struct delivery_receipt_t { typedef struct prof_buff_entry_t { char show_char; + int pad_indent; GDateTime *time; int flags; theme_item_t theme_item; @@ -59,7 +60,7 @@ typedef struct prof_buff_t *ProfBuff; ProfBuff buffer_create(); void buffer_free(ProfBuff buffer); -void buffer_push(ProfBuff buffer, const char show_char, GDateTime *time, int flags, theme_item_t theme_item, +void buffer_push(ProfBuff buffer, const char show_char, int pad_indent, GDateTime *time, int flags, theme_item_t theme_item, const char * const from, const char * const message, DeliveryReceipt *receipt); int buffer_size(ProfBuff buffer); ProfBuffEntry* buffer_yield_entry(ProfBuff buffer, int entry); diff --git a/src/ui/console.c b/src/ui/console.c index a1cf9fbf..e3e6f6a3 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -67,14 +67,14 @@ void cons_show_time(void) { ProfWin *console = wins_get_console(); - win_print(console, '-', NULL, NO_EOL, 0, "", ""); + win_print(console, '-', 0, NULL, NO_EOL, 0, "", ""); } void cons_show_word(const char * const word) { ProfWin *console = wins_get_console(); - win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", word); + win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", word); } void @@ -111,20 +111,20 @@ cons_show_help(Command *command) ProfWin *console = wins_get_console(); cons_show(""); - win_vprint(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "%s", &command->cmd[1]); - win_print(console, '-', NULL, NO_EOL, THEME_WHITE_BOLD, "", ""); + win_vprint(console, '-', 0, NULL, 0, THEME_WHITE_BOLD, "", "%s", &command->cmd[1]); + win_print(console, '-', 0, NULL, NO_EOL, THEME_WHITE_BOLD, "", ""); int i; for (i = 0; i < strlen(command->cmd) - 1 ; i++) { - win_print(console, '-', NULL, NO_EOL | NO_DATE, THEME_WHITE_BOLD, "", "-"); + win_print(console, '-', 0, NULL, NO_EOL | NO_DATE, THEME_WHITE_BOLD, "", "-"); } - win_print(console, '-', NULL, NO_DATE, THEME_WHITE_BOLD, "", ""); + win_print(console, '-', 0, NULL, NO_DATE, THEME_WHITE_BOLD, "", ""); cons_show(""); - win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "Synopsis"); + win_print(console, '-', 0, NULL, 0, THEME_WHITE_BOLD, "", "Synopsis"); ui_show_lines(console, command->help.synopsis); cons_show(""); - win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "Description"); + win_print(console, '-', 0, NULL, 0, THEME_WHITE_BOLD, "", "Description"); win_println(console, command->help.desc); int maxlen = 0; @@ -135,15 +135,15 @@ cons_show_help(Command *command) if (i > 0) { cons_show(""); - win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "Arguments"); + win_print(console, '-', 0, NULL, 0, THEME_WHITE_BOLD, "", "Arguments"); for (i = 0; command->help.args[i][0] != NULL; i++) { - win_vprint(console, '-', NULL, 0, 0, "", "%-*s: %s", maxlen + 1, command->help.args[i][0], command->help.args[i][1]); + win_vprint(console, '-', maxlen + 3, NULL, 0, 0, "", "%-*s: %s", maxlen + 1, command->help.args[i][0], command->help.args[i][1]); } } if (g_strv_length((gchar**)command->help.examples) > 0) { cons_show(""); - win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "Examples"); + win_print(console, '-', 0, NULL, 0, THEME_WHITE_BOLD, "", "Examples"); ui_show_lines(console, command->help.examples); } } @@ -168,7 +168,7 @@ cons_show_error(const char * const msg, ...) va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - win_print(console, '-', NULL, 0, THEME_ERROR, "", fmt_msg->str); + win_print(console, '-', 0, NULL, 0, THEME_ERROR, "", fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); @@ -191,7 +191,7 @@ cons_show_typing(const char * const barejid) display_usr = barejid; } - win_vprint(console, '-', NULL, 0, THEME_TYPING, "", "!! %s is typing a message...", display_usr); + win_vprint(console, '-', 0, NULL, 0, THEME_TYPING, "", "!! %s is typing a message...", display_usr); cons_alert(); } @@ -204,7 +204,7 @@ cons_show_incoming_message(const char * const short_from, const int win_index) if (ui_index == 10) { ui_index = 0; } - win_vprint(console, '-', NULL, 0, THEME_INCOMING, "", "<< incoming from %s (%d)", short_from, ui_index); + win_vprint(console, '-', 0, NULL, 0, THEME_INCOMING, "", "<< incoming from %s (%d)", short_from, ui_index); cons_alert(); } @@ -222,16 +222,16 @@ cons_about(void) if (strcmp(PACKAGE_STATUS, "development") == 0) { #ifdef HAVE_GIT_VERSION - win_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %sdev.%s.%s", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION); + win_vprint(console, '-', 0, NULL, 0, 0, "", "Welcome to Profanity, version %sdev.%s.%s", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION); #else - win_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %sdev", PACKAGE_VERSION); + win_vprint(console, '-', 0, NULL, 0, 0, "", "Welcome to Profanity, version %sdev", PACKAGE_VERSION); #endif } else { - win_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %s", PACKAGE_VERSION); + win_vprint(console, '-', 0, NULL, 0, 0, "", "Welcome to Profanity, version %s", PACKAGE_VERSION); } } - win_vprint(console, '-', NULL, 0, 0, "", "Copyright (C) 2012 - 2015 James Booth <%s>.", PACKAGE_BUGREPORT); + win_vprint(console, '-', 0, NULL, 0, 0, "", "Copyright (C) 2012 - 2015 James Booth <%s>.", PACKAGE_BUGREPORT); win_println(console, "License GPLv3+: GNU GPL version 3 or later "); win_println(console, ""); win_println(console, "This is free software; you are free to change and redistribute it."); @@ -260,7 +260,7 @@ cons_check_version(gboolean not_available_msg) if (relase_valid) { if (release_is_new(latest_release)) { - win_vprint(console, '-', NULL, 0, 0, "", "A new version of Profanity is available: %s", latest_release); + win_vprint(console, '-', 0, NULL, 0, 0, "", "A new version of Profanity is available: %s", latest_release); win_println(console, "Check for details."); win_println(console, ""); } else { @@ -280,16 +280,16 @@ void cons_show_login_success(ProfAccount *account) { ProfWin *console = wins_get_console(); - win_vprint(console, '-', NULL, NO_EOL, 0, "", "%s logged in successfully, ", account->jid); + win_vprint(console, '-', 0, NULL, NO_EOL, 0, "", "%s logged in successfully, ", account->jid); resource_presence_t presence = accounts_get_login_presence(account->name); const char *presence_str = string_from_resource_presence(presence); theme_item_t presence_colour = theme_main_presence_attrs(presence_str); - win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", presence_str); - win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " (priority %d)", + win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", presence_str); + win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " (priority %d)", accounts_get_priority_for_presence_type(account->name, presence)); - win_print(console, '-', NULL, NO_DATE, 0, "", "."); + win_print(console, '-', 0, NULL, NO_DATE, 0, "", "."); cons_alert(); } @@ -349,43 +349,43 @@ cons_show_caps(const char * const fulljid, resource_presence_t presence) const char *resource_presence = string_from_resource_presence(presence); theme_item_t presence_colour = theme_main_presence_attrs(resource_presence); - win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", fulljid); - win_print(console, '-', NULL, NO_DATE, 0, "", ":"); + win_vprint(console, '-', 0, NULL, NO_EOL, presence_colour, "", "%s", fulljid); + win_print(console, '-', 0, NULL, NO_DATE, 0, "", ":"); // show identity if (caps->category || caps->type || caps->name) { - win_print(console, '-', NULL, NO_EOL, 0, "", "Identity: "); + win_print(console, '-', 0, NULL, NO_EOL, 0, "", "Identity: "); if (caps->name) { - win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name); + win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->name); if (caps->category || caps->type) { - win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); + win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (caps->type) { - win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type); + win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->type); if (caps->category) { - win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); + win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (caps->category) { - win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category); + win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->category); } win_newline(console); } if (caps->software) { - win_vprint(console, '-', NULL, NO_EOL, 0, "", "Software: %s", caps->software); + win_vprint(console, '-', 0, NULL, NO_EOL, 0, "", "Software: %s", caps->software); } if (caps->software_version) { - win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); + win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } if (caps->software || caps->software_version) { win_newline(console); } if (caps->os) { - win_vprint(console, '-', NULL, NO_EOL, 0, "", "OS: %s", caps->os); + win_vprint(console, '-', 0, NULL, NO_EOL, 0, "", "OS: %s", caps->os); } if (caps->os_version) { - win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); + win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } if (caps->os || caps->os_version) { win_newline(console); @@ -395,7 +395,7 @@ cons_show_caps(const char * const fulljid, resource_presence_t presence) win_println(console, "Features:"); GSList *feature = caps->features; while (feature) { - win_vprint(console, '-', NULL, 0, 0, "", " %s", feature->data); + win_vprint(console, '-', 0, NULL, 0, 0, "", " %s", feature->data); feature = g_slist_next(feature); } } @@ -416,8 +416,8 @@ cons_show_software_version(const char * const jid, const char * const presence, if (name || version || os) { cons_show(""); theme_item_t presence_colour = theme_main_presence_attrs(presence); - win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", jid); - win_print(console, '-', NULL, NO_DATE, 0, "", ":"); + win_vprint(console, '-', 0, NULL, NO_EOL, presence_colour, "", "%s", jid); + win_print(console, '-', 0, NULL, NO_DATE, 0, "", ":"); } if (name) { cons_show("Name : %s", name); @@ -481,9 +481,9 @@ cons_show_room_list(GSList *rooms, const char * const conference_node) cons_show("Chat rooms at %s:", conference_node); while (rooms) { DiscoItem *room = rooms->data; - win_vprint(console, '-', NULL, NO_EOL, 0, "", " %s", room->jid); + win_vprint(console, '-', 0, NULL, NO_EOL, 0, "", " %s", room->jid); if (room->name) { - win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", (%s)", room->name); + win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", (%s)", room->name); } win_newline(console); rooms = g_slist_next(rooms); @@ -515,21 +515,21 @@ cons_show_bookmarks(const GList *list) if (muc_active(item->jid)) { presence_colour = THEME_ONLINE; } - win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s", item->jid); + win_vprint(console, '-', 0, NULL, NO_EOL, presence_colour, "", " %s", item->jid); if (item->nick) { - win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "/%s", item->nick); + win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", "/%s", item->nick); } if (item->autojoin) { - win_print(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (autojoin)"); + win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", " (autojoin)"); } if (item->password) { - win_print(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (private)"); + win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", " (private)"); } if (muc_active(item->jid)) { ProfWin *roomwin = (ProfWin*)wins_get_muc(item->jid); if (roomwin) { int num = wins_get_num(roomwin); - win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%d)", num); + win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", " (%d)", num); } } win_newline(console); @@ -590,11 +590,11 @@ cons_show_disco_items(GSList *items, const char * const jid) cons_show("Service discovery items for %s:", jid); while (items) { DiscoItem *item = items->data; - win_vprint(console, '-', NULL, NO_EOL, 0, "", " %s", item->jid); + win_vprint(console, '-', 0, NULL, NO_EOL, 0, "", " %s", item->jid); if (item->name) { - win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", (%s)", item->name); + win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", (%s)", item->name); } - win_vprint(console, '-', NULL, NO_DATE, 0, "", ""); + win_vprint(console, '-', 0, NULL, NO_DATE, 0, "", ""); items = g_slist_next(items); } } else { @@ -669,7 +669,7 @@ cons_show_account_list(gchar **accounts) (g_strcmp0(jabber_get_account_name(), accounts[i]) == 0)) { resource_presence_t presence = accounts_get_last_presence(accounts[i]); theme_item_t presence_colour = theme_main_presence_attrs(string_from_resource_presence(presence)); - win_vprint(console, '-', NULL, 0, presence_colour, "", "%s", accounts[i]); + win_vprint(console, '-', 0, NULL, 0, presence_colour, "", "%s", accounts[i]); } else { cons_show(accounts[i]); } @@ -798,12 +798,12 @@ cons_show_account(ProfAccount *account) Resource *resource = curr->data; const char *resource_presence = string_from_resource_presence(resource->presence); theme_item_t presence_colour = theme_main_presence_attrs(resource_presence); - win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence); + win_vprint(console, '-', 0, NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence); if (resource->status) { - win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status); + win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status); } - win_vprint(console, '-', NULL, NO_DATE, 0, "", ""); + win_vprint(console, '-', 0, NULL, NO_DATE, 0, "", ""); Jid *jidp = jid_create_from_bare_and_resource(account->jid, resource->name); Capabilities *caps = caps_lookup(jidp->fulljid); jid_destroy(jidp); @@ -811,38 +811,38 @@ cons_show_account(ProfAccount *account) if (caps) { // show identity if (caps->category || caps->type || caps->name) { - win_print(console, '-', NULL, NO_EOL, 0, "", " Identity: "); + win_print(console, '-', 0, NULL, NO_EOL, 0, "", " Identity: "); if (caps->name) { - win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name); + win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->name); if (caps->category || caps->type) { - win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); + win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (caps->type) { - win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type); + win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->type); if (caps->category) { - win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); + win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (caps->category) { - win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category); + win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->category); } win_newline(console); } if (caps->software) { - win_vprint(console, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software); + win_vprint(console, '-', 0, NULL, NO_EOL, 0, "", " Software: %s", caps->software); } if (caps->software_version) { - win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); + win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } if (caps->software || caps->software_version) { win_newline(console); } if (caps->os) { - win_vprint(console, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os); + win_vprint(console, '-', 0, NULL, NO_EOL, 0, "", " OS: %s", caps->os); } if (caps->os_version) { - win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); + win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } if (caps->os || caps->os_version) { win_newline(console); @@ -1554,7 +1554,7 @@ cons_navigation_help(void) { ProfWin *console = wins_get_console(); cons_show(""); - win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "Navigation"); + win_print(console, '-', 0, NULL, 0, THEME_WHITE_BOLD, "", "Navigation"); cons_show("Alt-1..Alt-0, F1..F10 : Choose window."); cons_show("Alt-LEFT, Alt-RIGHT : Previous/next chat window"); cons_show("PAGEUP, PAGEDOWN : Page the main window."); @@ -1659,22 +1659,22 @@ cons_theme_colours(void) ProfWin *console = wins_get_console(); cons_show("Theme colours:"); - win_print(console, '-', NULL, NO_EOL, THEME_WHITE, "", " white "); - win_print(console, '-', NULL, NO_DATE, THEME_WHITE_BOLD, "", " bold_white"); - win_print(console, '-', NULL, NO_EOL, THEME_GREEN, "", " green "); - win_print(console, '-', NULL, NO_DATE, THEME_GREEN_BOLD, "", " bold_green"); - win_print(console, '-', NULL, NO_EOL, THEME_RED, "", " red "); - win_print(console, '-', NULL, NO_DATE, THEME_RED_BOLD, "", " bold_red"); - win_print(console, '-', NULL, NO_EOL, THEME_YELLOW, "", " yellow "); - win_print(console, '-', NULL, NO_DATE, THEME_YELLOW_BOLD, "", " bold_yellow"); - win_print(console, '-', NULL, NO_EOL, THEME_BLUE, "", " blue "); - win_print(console, '-', NULL, NO_DATE, THEME_BLUE_BOLD, "", " bold_blue"); - win_print(console, '-', NULL, NO_EOL, THEME_CYAN, "", " cyan "); - win_print(console, '-', NULL, NO_DATE, THEME_CYAN_BOLD, "", " bold_cyan"); - win_print(console, '-', NULL, NO_EOL, THEME_MAGENTA, "", " magenta "); - win_print(console, '-', NULL, NO_DATE, THEME_MAGENTA_BOLD, "", " bold_magenta"); - win_print(console, '-', NULL, NO_EOL, THEME_BLACK, "", " black "); - win_print(console, '-', NULL, NO_DATE, THEME_BLACK_BOLD, "", " bold_black"); + win_print(console, '-', 0, NULL, NO_EOL, THEME_WHITE, "", " white "); + win_print(console, '-', 0, NULL, NO_DATE, THEME_WHITE_BOLD, "", " bold_white"); + win_print(console, '-', 0, NULL, NO_EOL, THEME_GREEN, "", " green "); + win_print(console, '-', 0, NULL, NO_DATE, THEME_GREEN_BOLD, "", " bold_green"); + win_print(console, '-', 0, NULL, NO_EOL, THEME_RED, "", " red "); + win_print(console, '-', 0, NULL, NO_DATE, THEME_RED_BOLD, "", " bold_red"); + win_print(console, '-', 0, NULL, NO_EOL, THEME_YELLOW, "", " yellow "); + win_print(console, '-', 0, NULL, NO_DATE, THEME_YELLOW_BOLD, "", " bold_yellow"); + win_print(console, '-', 0, NULL, NO_EOL, THEME_BLUE, "", " blue "); + win_print(console, '-', 0, NULL, NO_DATE, THEME_BLUE_BOLD, "", " bold_blue"); + win_print(console, '-', 0, NULL, NO_EOL, THEME_CYAN, "", " cyan "); + win_print(console, '-', 0, NULL, NO_DATE, THEME_CYAN_BOLD, "", " bold_cyan"); + win_print(console, '-', 0, NULL, NO_EOL, THEME_MAGENTA, "", " magenta "); + win_print(console, '-', 0, NULL, NO_DATE, THEME_MAGENTA_BOLD, "", " bold_magenta"); + win_print(console, '-', 0, NULL, NO_EOL, THEME_BLACK, "", " black "); + win_print(console, '-', 0, NULL, NO_DATE, THEME_BLACK_BOLD, "", " bold_black"); cons_show(""); } @@ -1684,23 +1684,23 @@ _cons_splash_logo(void) ProfWin *console = wins_get_console(); win_println(console, "Welcome to"); - win_print(console, '-', NULL, 0, THEME_SPLASH, "", " ___ _ "); - win_print(console, '-', NULL, 0, THEME_SPLASH, "", " / __) (_)_ "); - win_print(console, '-', NULL, 0, THEME_SPLASH, "", " ____ ____ ___ | |__ ____ ____ _| |_ _ _ "); - win_print(console, '-', NULL, 0, THEME_SPLASH, "", "| _ \\ / ___) _ \\| __) _ | _ \\| | _) | | |"); - win_print(console, '-', NULL, 0, THEME_SPLASH, "", "| | | | | | |_| | | ( ( | | | | | | |_| |_| |"); - win_print(console, '-', NULL, 0, THEME_SPLASH, "", "| ||_/|_| \\___/|_| \\_||_|_| |_|_|\\___)__ |"); - win_print(console, '-', NULL, 0, THEME_SPLASH, "", "|_| (____/ "); - win_print(console, '-', NULL, 0, THEME_SPLASH, "", ""); + win_print(console, '-', 0, NULL, 0, THEME_SPLASH, "", " ___ _ "); + win_print(console, '-', 0, NULL, 0, THEME_SPLASH, "", " / __) (_)_ "); + win_print(console, '-', 0, NULL, 0, THEME_SPLASH, "", " ____ ____ ___ | |__ ____ ____ _| |_ _ _ "); + win_print(console, '-', 0, NULL, 0, THEME_SPLASH, "", "| _ \\ / ___) _ \\| __) _ | _ \\| | _) | | |"); + win_print(console, '-', 0, NULL, 0, THEME_SPLASH, "", "| | | | | | |_| | | ( ( | | | | | | |_| |_| |"); + win_print(console, '-', 0, NULL, 0, THEME_SPLASH, "", "| ||_/|_| \\___/|_| \\_||_|_| |_|_|\\___)__ |"); + win_print(console, '-', 0, NULL, 0, THEME_SPLASH, "", "|_| (____/ "); + win_print(console, '-', 0, NULL, 0, THEME_SPLASH, "", ""); if (strcmp(PACKAGE_STATUS, "development") == 0) { #ifdef HAVE_GIT_VERSION - win_vprint(console, '-', NULL, 0, 0, "", "Version %sdev.%s.%s", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION); + win_vprint(console, '-', 0, NULL, 0, 0, "", "Version %sdev.%s.%s", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION); #else - win_vprint(console, '-', NULL, 0, 0, "", "Version %sdev", PACKAGE_VERSION); + win_vprint(console, '-', 0, NULL, 0, 0, "", "Version %sdev", PACKAGE_VERSION); #endif } else { - win_vprint(console, '-', NULL, 0, 0, "", "Version %s", PACKAGE_VERSION); + win_vprint(console, '-', 0, NULL, 0, 0, "", "Version %s", PACKAGE_VERSION); } } @@ -1727,11 +1727,11 @@ _show_roster_contacts(GSList *list, gboolean show_groups) } else { presence_colour = theme_main_presence_attrs("offline"); } - win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", title->str); + win_vprint(console, '-', 0, NULL, NO_EOL, presence_colour, "", title->str); g_string_free(title, TRUE); - win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " - "); + win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " - "); GString *sub = g_string_new(""); sub = g_string_append(sub, p_contact_subscription(contact)); if (p_contact_pending_out(contact)) { @@ -1747,9 +1747,9 @@ _show_roster_contacts(GSList *list, gboolean show_groups) } if (show_groups) { - win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", sub->str); + win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", sub->str); } else { - win_vprint(console, '-', NULL, NO_DATE, presence_colour, "", "%s", sub->str); + win_vprint(console, '-', 0, NULL, NO_DATE, presence_colour, "", "%s", sub->str); } g_string_free(sub, TRUE); @@ -1765,10 +1765,10 @@ _show_roster_contacts(GSList *list, gboolean show_groups) } groups = g_slist_next(groups); } - win_vprint(console, '-', NULL, NO_DATE, 0, "", "%s", groups_str->str); + win_vprint(console, '-', 0, NULL, NO_DATE, 0, "", "%s", groups_str->str); g_string_free(groups_str, TRUE); } else { - win_print(console, '-', NULL, NO_DATE, 0, "", " "); + win_print(console, '-', 0, NULL, NO_DATE, 0, "", " "); } } diff --git a/src/ui/core.c b/src/ui/core.c index 821de9fe..fb647083 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -297,13 +297,13 @@ ui_handle_stanza(const char * const msg) ProfWin *window = (ProfWin*) xmlconsole; if (g_str_has_prefix(msg, "SENT:")) { - win_print(window, '-', NULL, 0, 0, "", "SENT:"); - win_print(window, '-', NULL, 0, THEME_ONLINE, "", &msg[6]); - win_print(window, '-', NULL, 0, THEME_ONLINE, "", ""); + win_print(window, '-', 0, NULL, 0, 0, "", "SENT:"); + win_print(window, '-', 0, NULL, 0, THEME_ONLINE, "", &msg[6]); + win_print(window, '-', 0, NULL, 0, THEME_ONLINE, "", ""); } else if (g_str_has_prefix(msg, "RECV:")) { - win_print(window, '-', NULL, 0, 0, "", "RECV:"); - win_print(window, '-', NULL, 0, THEME_AWAY, "", &msg[6]); - win_print(window, '-', NULL, 0, THEME_AWAY, "", ""); + win_print(window, '-', 0, NULL, 0, 0, "", "RECV:"); + win_print(window, '-', 0, NULL, 0, THEME_AWAY, "", &msg[6]); + win_print(window, '-', 0, NULL, 0, THEME_AWAY, "", ""); } } } @@ -625,7 +625,7 @@ ui_handle_recipient_not_found(const char * const recipient, const char * const e ProfMucWin *mucwin = wins_get_muc(recipient); if (mucwin) { cons_show_error("Room %s not found: %s", recipient, err_msg); - win_vprint((ProfWin*) mucwin, '!', NULL, 0, THEME_ERROR, "", "Room %s not found: %s", recipient, err_msg); + win_vprint((ProfWin*) mucwin, '!', 0, NULL, 0, THEME_ERROR, "", "Room %s not found: %s", recipient, err_msg); return; } } @@ -638,19 +638,19 @@ ui_handle_recipient_error(const char * const recipient, const char * const err_m ProfChatWin *chatwin = wins_get_chat(recipient); if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', NULL, 0, THEME_ERROR, "", "Error from %s: %s", recipient, err_msg); + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, THEME_ERROR, "", "Error from %s: %s", recipient, err_msg); return; } ProfMucWin *mucwin = wins_get_muc(recipient); if (mucwin) { - win_vprint((ProfWin*)mucwin, '!', NULL, 0, THEME_ERROR, "", "Error from %s: %s", recipient, err_msg); + win_vprint((ProfWin*)mucwin, '!', 0, NULL, 0, THEME_ERROR, "", "Error from %s: %s", recipient, err_msg); return; } ProfPrivateWin *privatewin = wins_get_private(recipient); if (privatewin) { - win_vprint((ProfWin*)privatewin, '!', NULL, 0, THEME_ERROR, "", "Error from %s: %s", recipient, err_msg); + win_vprint((ProfWin*)privatewin, '!', 0, NULL, 0, THEME_ERROR, "", "Error from %s: %s", recipient, err_msg); return; } } @@ -896,9 +896,9 @@ ui_gone_secure(const char * const barejid, gboolean trusted) chatwin->enc_mode = PROF_ENC_OTR; chatwin->otr_is_trusted = trusted; if (trusted) { - win_print(window, '!', NULL, 0, THEME_OTR_STARTED_TRUSTED, "", "OTR session started (trusted)."); + win_print(window, '!', 0, NULL, 0, THEME_OTR_STARTED_TRUSTED, "", "OTR session started (trusted)."); } else { - win_print(window, '!', NULL, 0, THEME_OTR_STARTED_UNTRUSTED, "", "OTR session started (untrusted)."); + win_print(window, '!', 0, NULL, 0, THEME_OTR_STARTED_UNTRUSTED, "", "OTR session started (untrusted)."); } if (wins_is_current(window)) { @@ -925,7 +925,7 @@ ui_gone_insecure(const char * const barejid) chatwin->otr_is_trusted = FALSE; ProfWin *window = (ProfWin*)chatwin; - win_print(window, '!', NULL, 0, THEME_OTR_ENDED, "", "OTR session ended."); + win_print(window, '!', 0, NULL, 0, THEME_OTR_ENDED, "", "OTR session ended."); if (wins_is_current(window)) { title_bar_switch(); } @@ -937,7 +937,7 @@ ui_smp_recipient_initiated(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "%s wants to authenticate your identity, use '/otr secret '.", barejid); + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s wants to authenticate your identity, use '/otr secret '.", barejid); } } @@ -946,9 +946,9 @@ ui_smp_recipient_initiated_q(const char * const barejid, const char *question) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "%s wants to authenticate your identity with the following question:", barejid); - win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", " %s", question); - win_print((ProfWin*)chatwin, '!', NULL, 0, 0, "", "use '/otr answer '."); + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s wants to authenticate your identity with the following question:", barejid); + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", " %s", question); + win_print((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "use '/otr answer '."); } } @@ -957,7 +957,7 @@ ui_smp_unsuccessful_sender(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "Authentication failed, the secret you entered does not match the secret entered by %s.", barejid); + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Authentication failed, the secret you entered does not match the secret entered by %s.", barejid); } } @@ -966,7 +966,7 @@ ui_smp_unsuccessful_receiver(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "Authentication failed, the secret entered by %s does not match yours.", barejid); + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Authentication failed, the secret entered by %s does not match yours.", barejid); } } @@ -975,7 +975,7 @@ ui_smp_aborted(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_print((ProfWin*)chatwin, '!', NULL, 0, 0, "", "SMP session aborted."); + win_print((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "SMP session aborted."); } } @@ -984,7 +984,7 @@ ui_smp_successful(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_print((ProfWin*)chatwin, '!', NULL, 0, 0, "", "Authentication successful."); + win_print((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Authentication successful."); } } @@ -993,7 +993,7 @@ ui_smp_answer_success(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "%s successfully authenticated you.", barejid); + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s successfully authenticated you.", barejid); } } @@ -1002,7 +1002,7 @@ ui_smp_answer_failure(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "%s failed to authenticate you.", barejid); + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "%s failed to authenticate you.", barejid); } } @@ -1011,7 +1011,7 @@ ui_otr_authenticating(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "Authenticating %s...", barejid); + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Authenticating %s...", barejid); } } @@ -1020,7 +1020,7 @@ ui_otr_authetication_waiting(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "Awaiting authentication from %s...", barejid); + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, 0, "", "Awaiting authentication from %s...", barejid); } } @@ -1029,7 +1029,7 @@ ui_handle_otr_error(const char * const barejid, const char * const message) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_print((ProfWin*)chatwin, '!', NULL, 0, THEME_ERROR, "", message); + win_print((ProfWin*)chatwin, '!', 0, NULL, 0, THEME_ERROR, "", message); } else { cons_show_error("%s - %s", barejid, message); } @@ -1044,7 +1044,7 @@ ui_trust(const char * const barejid) chatwin->otr_is_trusted = TRUE; ProfWin *window = (ProfWin*)chatwin; - win_print(window, '!', NULL, 0, THEME_OTR_TRUSTED, "", "OTR session trusted."); + win_print(window, '!', 0, NULL, 0, THEME_OTR_TRUSTED, "", "OTR session trusted."); if (wins_is_current(window)) { title_bar_switch(); } @@ -1060,7 +1060,7 @@ ui_untrust(const char * const barejid) chatwin->otr_is_trusted = FALSE; ProfWin *window = (ProfWin*)chatwin; - win_print(window, '!', NULL, 0, THEME_OTR_UNTRUSTED, "", "OTR session untrusted."); + win_print(window, '!', 0, NULL, 0, THEME_OTR_UNTRUSTED, "", "OTR session untrusted."); if (wins_is_current(window)) { title_bar_switch(); } @@ -1163,7 +1163,7 @@ ui_current_print_formatted_line(const char show_char, int attrs, const char * co va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - win_print(current, show_char, NULL, 0, attrs, "", fmt_msg->str); + win_print(current, show_char, 0, NULL, 0, attrs, "", fmt_msg->str); va_end(arg); g_string_free(fmt_msg, TRUE); } @@ -1171,14 +1171,14 @@ ui_current_print_formatted_line(const char show_char, int attrs, const char * co void ui_win_error_line(ProfWin *window, const char * const msg) { - win_print(window, '-', NULL, 0, THEME_ERROR, "", msg); + win_print(window, '-', 0, NULL, 0, THEME_ERROR, "", msg); } void ui_current_error_line(const char * const msg) { ProfWin *current = wins_get_current(); - win_print(current, '-', NULL, 0, THEME_ERROR, "", msg); + win_print(current, '-', 0, NULL, 0, THEME_ERROR, "", msg); } void @@ -1201,7 +1201,7 @@ ui_print_system_msg_from_recipient(const char * const barejid, const char *messa } } - win_vprint(window, '-', NULL, 0, 0, "", "*%s %s", barejid, message); + win_vprint(window, '-', 0, NULL, 0, 0, "", "*%s %s", barejid, message); } void @@ -1233,7 +1233,7 @@ ui_recipient_gone(const char * const barejid, const char * const resource) display_usr = barejid; } - win_vprint((ProfWin*)chatwin, '!', NULL, 0, THEME_GONE, "", "<- %s has left the conversation.", display_usr); + win_vprint((ProfWin*)chatwin, '!', 0, NULL, 0, THEME_GONE, "", "<- %s has left the conversation.", display_usr); } } } @@ -1288,9 +1288,9 @@ void ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id) { if (prefs_get_boolean(PREF_RECEIPTS_REQUEST) && id) { - win_print_with_receipt((ProfWin*)chatwin, '-', NULL, 0, THEME_TEXT_ME, "me", message, id); + win_print_with_receipt((ProfWin*)chatwin, '-', 0, NULL, 0, THEME_TEXT_ME, "me", message, id); } else { - win_print((ProfWin*)chatwin, '-', NULL, 0, THEME_TEXT_ME, "me", message); + win_print((ProfWin*)chatwin, '-', 0, NULL, 0, THEME_TEXT_ME, "me", message); } } @@ -1306,7 +1306,7 @@ ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const messa chat_state_active(chatwin->state); - win_print((ProfWin*)chatwin, '-', NULL, 0, THEME_TEXT_ME, "me", message); + win_print((ProfWin*)chatwin, '-', 0, NULL, 0, THEME_TEXT_ME, "me", message); int num = wins_get_num((ProfWin*)chatwin); status_bar_active(num); @@ -1315,7 +1315,7 @@ ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const messa void ui_outgoing_private_msg(ProfPrivateWin *privwin, const char * const message) { - win_print((ProfWin*)privwin, '-', NULL, 0, THEME_TEXT_ME, "me", message); + win_print((ProfWin*)privwin, '-', 0, NULL, 0, THEME_TEXT_ME, "me", message); } void @@ -1327,18 +1327,18 @@ ui_room_join(const char * const roomjid, gboolean focus) } char *nick = muc_nick(roomjid); - win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "-> You have joined the room as %s", nick); + win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "-> You have joined the room as %s", nick); if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) { char *role = muc_role_str(roomjid); char *affiliation = muc_affiliation_str(roomjid); if (role) { - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", role: %s", role); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", role: %s", role); } if (affiliation) { - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", affiliation: %s", affiliation); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", affiliation: %s", affiliation); } } - win_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); + win_print(window, '!', 0, NULL, NO_DATE, THEME_ROOMINFO, "", ""); if (focus) { @@ -1348,7 +1348,7 @@ ui_room_join(const char * const roomjid, gboolean focus) status_bar_active(num); ProfWin *console = wins_get_console(); char *nick = muc_nick(roomjid); - win_vprint(console, '!', NULL, 0, THEME_TYPING, "", "-> Autojoined %s as %s (%d).", roomjid, nick, num); + win_vprint(console, '!', 0, NULL, 0, THEME_TYPING, "", "-> Autojoined %s as %s (%d).", roomjid, nick, num); } } @@ -1364,14 +1364,14 @@ ui_room_role_change(const char * const roomjid, const char * const role, const c const char * const reason) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "Your role has been changed to: %s", role); + win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "Your role has been changed to: %s", role); if (actor) { - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); } if (reason) { - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); } - win_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); + win_print(window, '!', 0, NULL, NO_DATE, THEME_ROOMINFO, "", ""); } void @@ -1379,14 +1379,14 @@ ui_room_affiliation_change(const char * const roomjid, const char * const affili const char * const reason) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "Your affiliation has been changed to: %s", affiliation); + win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "Your affiliation has been changed to: %s", affiliation); if (actor) { - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); } if (reason) { - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); } - win_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); + win_print(window, '!', 0, NULL, NO_DATE, THEME_ROOMINFO, "", ""); } void @@ -1394,14 +1394,14 @@ ui_room_role_and_affiliation_change(const char * const roomjid, const char * con const char * const actor, const char * const reason) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "Your role and affiliation have been changed, role: %s, affiliation: %s", role, affiliation); + win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "Your role and affiliation have been changed, role: %s, affiliation: %s", role, affiliation); if (actor) { - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); } if (reason) { - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); } - win_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); + win_print(window, '!', 0, NULL, NO_DATE, THEME_ROOMINFO, "", ""); } @@ -1410,14 +1410,14 @@ ui_room_occupant_role_change(const char * const roomjid, const char * const nick const char * const actor, const char * const reason) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "%s's role has been changed to: %s", nick, role); + win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "%s's role has been changed to: %s", nick, role); if (actor) { - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); } if (reason) { - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); } - win_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); + win_print(window, '!', 0, NULL, NO_DATE, THEME_ROOMINFO, "", ""); } void @@ -1425,14 +1425,14 @@ ui_room_occupant_affiliation_change(const char * const roomjid, const char * con const char * const actor, const char * const reason) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "%s's affiliation has been changed to: %s", nick, affiliation); + win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "%s's affiliation has been changed to: %s", nick, affiliation); if (actor) { - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); } if (reason) { - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); } - win_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); + win_print(window, '!', 0, NULL, NO_DATE, THEME_ROOMINFO, "", ""); } void @@ -1440,14 +1440,14 @@ ui_room_occupant_role_and_affiliation_change(const char * const roomjid, const c const char * const affiliation, const char * const actor, const char * const reason) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "%s's role and affiliation have been changed, role: %s, affiliation: %s", nick, role, affiliation); + win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "%s's role and affiliation have been changed, role: %s, affiliation: %s", nick, role, affiliation); if (actor) { - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); } if (reason) { - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); } - win_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); + win_print(window, '!', 0, NULL, NO_DATE, THEME_ROOMINFO, "", ""); } void @@ -1455,8 +1455,8 @@ ui_handle_room_info_error(const char * const roomjid, const char * const error) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); if (window) { - win_vprint(window, '!', NULL, 0, 0, "", "Room info request failed: %s", error); - win_print(window, '-', NULL, 0, 0, "", ""); + win_vprint(window, '!', 0, NULL, 0, 0, "", "Room info request failed: %s", error); + win_print(window, '-', 0, NULL, 0, 0, "", ""); } } @@ -1468,7 +1468,7 @@ ui_show_room_disco_info(const char * const roomjid, GSList *identities, GSList * if ((identities && (g_slist_length(identities) > 0)) || (features && (g_slist_length(features) > 0))) { if (identities) { - win_print(window, '!', NULL, 0, 0, "", "Identities:"); + win_print(window, '!', 0, NULL, 0, 0, "", "Identities:"); } while (identities) { DiscoIdentity *identity = identities->data; // anme trpe, cat @@ -1484,19 +1484,19 @@ ui_show_room_disco_info(const char * const roomjid, GSList *identities, GSList * if (identity->category) { identity_str = g_string_append(identity_str, identity->category); } - win_print(window, '!', NULL, 0, 0, "", identity_str->str); + win_print(window, '!', 0, NULL, 0, 0, "", identity_str->str); g_string_free(identity_str, TRUE); identities = g_slist_next(identities); } if (features) { - win_print(window, '!', NULL, 0, 0, "", "Features:"); + win_print(window, '!', 0, NULL, 0, 0, "", "Features:"); } while (features) { - win_vprint(window, '!', NULL, 0, 0, "", " %s", features->data); + win_vprint(window, '!', 0, NULL, 0, 0, "", " %s", features->data); features = g_slist_next(features); } - win_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', 0, NULL, 0, 0, "", ""); } } } @@ -1510,16 +1510,16 @@ ui_room_roster(const char * const roomjid, GList *roster, const char * const pre } else { if ((roster == NULL) || (g_list_length(roster) == 0)) { if (presence == NULL) { - win_print(window, '!', NULL, 0, THEME_ROOMINFO, "", "Room is empty."); + win_print(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Room is empty."); } else { - win_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", "No occupants %s.", presence); + win_vprint(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "No occupants %s.", presence); } } else { int length = g_list_length(roster); if (presence == NULL) { - win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "%d occupants: ", length); + win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "%d occupants: ", length); } else { - win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "%d %s: ", length, presence); + win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "%d %s: ", length, presence); } while (roster) { @@ -1527,15 +1527,15 @@ ui_room_roster(const char * const roomjid, GList *roster, const char * const pre const char *presence_str = string_from_resource_presence(occupant->presence); theme_item_t presence_colour = theme_main_presence_attrs(presence_str); - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", occupant->nick); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", occupant->nick); if (roster->next) { - win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", "); + win_print(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", ", "); } roster = g_list_next(roster); } - win_print(window, '!', NULL, NO_DATE, THEME_ONLINE, "", ""); + win_print(window, '!', 0, NULL, NO_DATE, THEME_ONLINE, "", ""); } } @@ -1554,7 +1554,7 @@ ui_room_member_offline(const char * const roomjid, const char * const nick) if (window == NULL) { log_error("Received offline presence for room participant %s, but no window open for %s.", nick, roomjid); } else { - win_vprint(window, '!', NULL, 0, THEME_OFFLINE, "", "<- %s has left the room.", nick); + win_vprint(window, '!', 0, NULL, 0, THEME_OFFLINE, "", "<- %s has left the room.", nick); } } @@ -1577,7 +1577,7 @@ ui_room_member_kicked(const char * const roomjid, const char * const nick, const g_string_append(message, reason); } - win_vprint(window, '!', NULL, 0, THEME_OFFLINE, "", "<- %s", message->str); + win_vprint(window, '!', 0, NULL, 0, THEME_OFFLINE, "", "<- %s", message->str); g_string_free(message, TRUE); } } @@ -1601,7 +1601,7 @@ ui_room_member_banned(const char * const roomjid, const char * const nick, const g_string_append(message, reason); } - win_vprint(window, '!', NULL, 0, THEME_OFFLINE, "", "<- %s", message->str); + win_vprint(window, '!', 0, NULL, 0, THEME_OFFLINE, "", "<- %s", message->str); g_string_free(message, TRUE); } } @@ -1614,16 +1614,16 @@ ui_room_member_online(const char * const roomjid, const char * const nick, const if (window == NULL) { log_error("Received online presence for room participant %s, but no window open for %s.", nick, roomjid); } else { - win_vprint(window, '!', NULL, NO_EOL, THEME_ONLINE, "", "-> %s has joined the room", nick); + win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ONLINE, "", "-> %s has joined the room", nick); if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) { if (role) { - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", ", role: %s", role); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", ", role: %s", role); } if (affiliation) { - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", ", affiliation: %s", affiliation); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", ", affiliation: %s", affiliation); } } - win_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); + win_print(window, '!', 0, NULL, NO_DATE, THEME_ROOMINFO, "", ""); } } @@ -1647,7 +1647,7 @@ ui_room_member_nick_change(const char * const roomjid, if (window == NULL) { log_error("Received nick change for room participant %s, but no window open for %s.", old_nick, roomjid); } else { - win_vprint(window, '!', NULL, 0, THEME_THEM, "", "** %s is now known as %s", old_nick, nick); + win_vprint(window, '!', 0, NULL, 0, THEME_THEM, "", "** %s is now known as %s", old_nick, nick); } } @@ -1658,7 +1658,7 @@ ui_room_nick_change(const char * const roomjid, const char * const nick) if (window == NULL) { log_error("Received self nick change %s, but no window open for %s.", nick, roomjid); } else { - win_vprint(window, '!', NULL, 0, THEME_ME, "", "** You are now known as %s", nick); + win_vprint(window, '!', 0, NULL, 0, THEME_ME, "", "** You are now known as %s", nick); } } @@ -1683,7 +1683,7 @@ ui_room_history(const char * const roomjid, const char * const nick, g_string_append(line, message); } - win_print(window, '-', timestamp, NO_COLOUR_DATE, 0, "", line->str); + win_print(window, '-', 0, timestamp, NO_COLOUR_DATE, 0, "", line->str); g_string_free(line, TRUE); } } @@ -1704,12 +1704,12 @@ ui_room_message(const char * const roomjid, const char * const nick, if (g_strcmp0(nick, my_nick) != 0) { if (g_strrstr(message, my_nick)) { - win_print(window, '-', NULL, NO_ME, THEME_ROOMMENTION, nick, message); + win_print(window, '-', 0, NULL, NO_ME, THEME_ROOMMENTION, nick, message); } else { - win_print(window, '-', NULL, NO_ME, THEME_TEXT_THEM, nick, message); + win_print(window, '-', 0, NULL, NO_ME, THEME_TEXT_THEM, nick, message); } } else { - win_print(window, '-', NULL, 0, THEME_TEXT_ME, nick, message); + win_print(window, '-', 0, NULL, 0, THEME_TEXT_ME, nick, message); } // currently in groupchat window @@ -1785,16 +1785,16 @@ ui_room_requires_config(const char * const roomjid) ui_index = 0; } - win_print(window, '-', NULL, 0, 0, "", ""); - win_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", + win_print(window, '-', 0, NULL, 0, 0, "", ""); + win_vprint(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Room locked, requires configuration."); - win_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", + win_vprint(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Use '/room accept' to accept the defaults"); - win_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", + win_vprint(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Use '/room destroy' to cancel and destroy the room"); - win_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", + win_vprint(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Use '/room config' to edit the room configuration"); - win_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', 0, NULL, 0, 0, "", ""); // currently in groupchat window if (wins_is_current(window)) { @@ -1843,16 +1843,16 @@ ui_room_destroyed(const char * const roomjid, const char * const reason, const c ProfWin *console = wins_get_console(); if (reason) { - win_vprint(console, '!', NULL, 0, THEME_TYPING, "", "<- Room destroyed: %s, reason: %s", roomjid, reason); + win_vprint(console, '!', 0, NULL, 0, THEME_TYPING, "", "<- Room destroyed: %s, reason: %s", roomjid, reason); } else { - win_vprint(console, '!', NULL, 0, THEME_TYPING, "", "<- Room destroyed: %s", roomjid); + win_vprint(console, '!', 0, NULL, 0, THEME_TYPING, "", "<- Room destroyed: %s", roomjid); } if (new_jid) { if (password) { - win_vprint(console, '!', NULL, 0, THEME_TYPING, "", "Replacement room: %s, password: %s", new_jid, password); + win_vprint(console, '!', 0, NULL, 0, THEME_TYPING, "", "Replacement room: %s, password: %s", new_jid, password); } else { - win_vprint(console, '!', NULL, 0, THEME_TYPING, "", "Replacement room: %s", new_jid); + win_vprint(console, '!', 0, NULL, 0, THEME_TYPING, "", "Replacement room: %s", new_jid); } } } @@ -1880,7 +1880,7 @@ ui_room_kicked(const char * const roomjid, const char * const actor, const char } ProfWin *console = wins_get_console(); - win_vprint(console, '!', NULL, 0, THEME_TYPING, "", "<- %s", message->str); + win_vprint(console, '!', 0, NULL, 0, THEME_TYPING, "", "<- %s", message->str); g_string_free(message, TRUE); } } @@ -1907,7 +1907,7 @@ ui_room_banned(const char * const roomjid, const char * const actor, const char } ProfWin *console = wins_get_console(); - win_vprint(console, '!', NULL, 0, THEME_TYPING, "", "<- %s", message->str); + win_vprint(console, '!', 0, NULL, 0, THEME_TYPING, "", "<- %s", message->str); g_string_free(message, TRUE); } } @@ -1923,17 +1923,17 @@ ui_room_subject(const char * const roomjid, const char * const nick, const char if (subject) { if (nick) { - win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "*%s has set the room subject: ", nick); - win_vprint(window, '!', NULL, NO_DATE, 0, "", "%s", subject); + win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "*%s has set the room subject: ", nick); + win_vprint(window, '!', 0, NULL, NO_DATE, 0, "", "%s", subject); } else { - win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "Room subject: "); - win_vprint(window, '!', NULL, NO_DATE, 0, "", "%s", subject); + win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "Room subject: "); + win_vprint(window, '!', 0, NULL, NO_DATE, 0, "", "%s", subject); } } else { if (nick) { - win_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", "*%s has cleared the room subject: ", nick); + win_vprint(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "*%s has cleared the room subject: ", nick); } else { - win_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", "Room subject cleared"); + win_vprint(window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Room subject cleared"); } } @@ -1955,7 +1955,7 @@ ui_handle_room_kick_error(const char * const roomjid, const char * const nick, c if (window == NULL) { log_error("Kick error received for %s, but no window open for %s.", nick, roomjid); } else { - win_vprint(window, '!', NULL, 0, THEME_ERROR, "", "Error kicking %s: %s", nick, error); + win_vprint(window, '!', 0, NULL, 0, THEME_ERROR, "", "Error kicking %s: %s", nick, error); } } @@ -1968,8 +1968,8 @@ ui_room_broadcast(const char * const roomjid, const char * const message) } else { int num = wins_get_num(window); - win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "Room message: "); - win_vprint(window, '!', NULL, NO_DATE, 0, "", "%s", message); + win_vprint(window, '!', 0, NULL, NO_EOL, THEME_ROOMINFO, "", "Room message: "); + win_vprint(window, '!', 0, NULL, NO_DATE, 0, "", "%s", message); // currently in groupchat window if (wins_is_current(window)) { @@ -1988,7 +1988,7 @@ ui_handle_room_affiliation_list_error(const char * const roomjid, const char * c { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); if (window) { - win_vprint(window, '!', NULL, 0, THEME_ERROR, "", "Error retrieving %s list: %s", affiliation, error); + win_vprint(window, '!', 0, NULL, 0, THEME_ERROR, "", "Error retrieving %s list: %s", affiliation, error); } } @@ -1998,17 +1998,17 @@ ui_handle_room_affiliation_list(const char * const roomjid, const char * const a ProfWin *window = (ProfWin*)wins_get_muc(roomjid); if (window) { if (jids) { - win_vprint(window, '!', NULL, 0, 0, "", "Affiliation: %s", affiliation); + win_vprint(window, '!', 0, NULL, 0, 0, "", "Affiliation: %s", affiliation); GSList *curr_jid = jids; while (curr_jid) { char *jid = curr_jid->data; - win_vprint(window, '!', NULL, 0, 0, "", " %s", jid); + win_vprint(window, '!', 0, NULL, 0, 0, "", " %s", jid); curr_jid = g_slist_next(curr_jid); } - win_print(window, '!', NULL, 0, 0, "", ""); + win_print(window, '!', 0, NULL, 0, 0, "", ""); } else { - win_vprint(window, '!', NULL, 0, 0, "", "No users found with affiliation: %s", affiliation); - win_print(window, '!', NULL, 0, 0, "", ""); + win_vprint(window, '!', 0, NULL, 0, 0, "", "No users found with affiliation: %s", affiliation); + win_print(window, '!', 0, NULL, 0, 0, "", ""); } } } @@ -2018,7 +2018,7 @@ ui_handle_room_role_list_error(const char * const roomjid, const char * const ro { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); if (window) { - win_vprint(window, '!', NULL, 0, THEME_ERROR, "", "Error retrieving %s list: %s", role, error); + win_vprint(window, '!', 0, NULL, 0, THEME_ERROR, "", "Error retrieving %s list: %s", role, error); } } @@ -2028,26 +2028,26 @@ ui_handle_room_role_list(const char * const roomjid, const char * const role, GS ProfWin *window = (ProfWin*)wins_get_muc(roomjid); if (window) { if (nicks) { - win_vprint(window, '!', NULL, 0, 0, "", "Role: %s", role); + win_vprint(window, '!', 0, NULL, 0, 0, "", "Role: %s", role); GSList *curr_nick = nicks; while (curr_nick) { char *nick = curr_nick->data; Occupant *occupant = muc_roster_item(roomjid, nick); if (occupant) { if (occupant->jid) { - win_vprint(window, '!', NULL, 0, 0, "", " %s (%s)", nick, occupant->jid); + win_vprint(window, '!', 0, NULL, 0, 0, "", " %s (%s)", nick, occupant->jid); } else { - win_vprint(window, '!', NULL, 0, 0, "", " %s", nick); + win_vprint(window, '!', 0, NULL, 0, 0, "", " %s", nick); } } else { - win_vprint(window, '!', NULL, 0, 0, "", " %s", nick); + win_vprint(window, '!', 0, NULL, 0, 0, "", " %s", nick); } curr_nick = g_slist_next(curr_nick); } - win_print(window, '!', NULL, 0, 0, "", ""); + win_print(window, '!', 0, NULL, 0, 0, "", ""); } else { - win_vprint(window, '!', NULL, 0, 0, "", "No occupants found with role: %s", role); - win_print(window, '!', NULL, 0, 0, "", ""); + win_vprint(window, '!', 0, NULL, 0, 0, "", "No occupants found with role: %s", role); + win_print(window, '!', 0, NULL, 0, 0, "", ""); } } } @@ -2058,7 +2058,7 @@ ui_handle_room_affiliation_set_error(const char * const roomjid, const char * co { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); if (window) { - win_vprint(window, '!', NULL, 0, THEME_ERROR, "", "Error setting %s affiliation for %s: %s", affiliation, jid, error); + win_vprint(window, '!', 0, NULL, 0, THEME_ERROR, "", "Error setting %s affiliation for %s: %s", affiliation, jid, error); } } @@ -2068,7 +2068,7 @@ ui_handle_room_role_set_error(const char * const roomjid, const char * const nic { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); if (window) { - win_vprint(window, '!', NULL, 0, THEME_ERROR, "", "Error setting %s role for %s: %s", role, nick, error); + win_vprint(window, '!', 0, NULL, 0, THEME_ERROR, "", "Error setting %s role for %s: %s", role, nick, error); } } @@ -2237,10 +2237,10 @@ ui_show_room_info(ProfMucWin *mucwin) char *affiliation = muc_affiliation_str(mucwin->roomjid); ProfWin *window = (ProfWin*) mucwin; - win_vprint(window, '!', NULL, 0, 0, "", "Room: %s", mucwin->roomjid); - win_vprint(window, '!', NULL, 0, 0, "", "Affiliation: %s", affiliation); - win_vprint(window, '!', NULL, 0, 0, "", "Role: %s", role); - win_print(window, '-', NULL, 0, 0, "", ""); + win_vprint(window, '!', 0, NULL, 0, 0, "", "Room: %s", mucwin->roomjid); + win_vprint(window, '!', 0, NULL, 0, 0, "", "Affiliation: %s", affiliation); + win_vprint(window, '!', 0, NULL, 0, 0, "", "Role: %s", role); + win_print(window, '-', 0, NULL, 0, 0, "", ""); } void @@ -2252,28 +2252,28 @@ ui_show_room_role_list(ProfMucWin *mucwin, muc_role_t role) if (!occupants) { switch (role) { case MUC_ROLE_MODERATOR: - win_print(window, '!', NULL, 0, 0, "", "No moderators found."); + win_print(window, '!', 0, NULL, 0, 0, "", "No moderators found."); break; case MUC_ROLE_PARTICIPANT: - win_print(window, '!', NULL, 0, 0, "", "No participants found."); + win_print(window, '!', 0, NULL, 0, 0, "", "No participants found."); break; case MUC_ROLE_VISITOR: - win_print(window, '!', NULL, 0, 0, "", "No visitors found."); + win_print(window, '!', 0, NULL, 0, 0, "", "No visitors found."); break; default: break; } - win_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', 0, NULL, 0, 0, "", ""); } else { switch (role) { case MUC_ROLE_MODERATOR: - win_print(window, '!', NULL, 0, 0, "", "Moderators:"); + win_print(window, '!', 0, NULL, 0, 0, "", "Moderators:"); break; case MUC_ROLE_PARTICIPANT: - win_print(window, '!', NULL, 0, 0, "", "Participants:"); + win_print(window, '!', 0, NULL, 0, 0, "", "Participants:"); break; case MUC_ROLE_VISITOR: - win_print(window, '!', NULL, 0, 0, "", "Visitors:"); + win_print(window, '!', 0, NULL, 0, 0, "", "Visitors:"); break; default: break; @@ -2284,16 +2284,16 @@ ui_show_room_role_list(ProfMucWin *mucwin, muc_role_t role) Occupant *occupant = curr_occupant->data; if (occupant->role == role) { if (occupant->jid) { - win_vprint(window, '!', NULL, 0, 0, "", " %s (%s)", occupant->nick, occupant->jid); + win_vprint(window, '!', 0, NULL, 0, 0, "", " %s (%s)", occupant->nick, occupant->jid); } else { - win_vprint(window, '!', NULL, 0, 0, "", " %s", occupant->nick); + win_vprint(window, '!', 0, NULL, 0, 0, "", " %s", occupant->nick); } } curr_occupant = g_slist_next(curr_occupant); } - win_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', 0, NULL, 0, 0, "", ""); } } @@ -2306,34 +2306,34 @@ ui_show_room_affiliation_list(ProfMucWin *mucwin, muc_affiliation_t affiliation) if (!occupants) { switch (affiliation) { case MUC_AFFILIATION_OWNER: - win_print(window, '!', NULL, 0, 0, "", "No owners found."); + win_print(window, '!', 0, NULL, 0, 0, "", "No owners found."); break; case MUC_AFFILIATION_ADMIN: - win_print(window, '!', NULL, 0, 0, "", "No admins found."); + win_print(window, '!', 0, NULL, 0, 0, "", "No admins found."); break; case MUC_AFFILIATION_MEMBER: - win_print(window, '!', NULL, 0, 0, "", "No members found."); + win_print(window, '!', 0, NULL, 0, 0, "", "No members found."); break; case MUC_AFFILIATION_OUTCAST: - win_print(window, '!', NULL, 0, 0, "", "No outcasts found."); + win_print(window, '!', 0, NULL, 0, 0, "", "No outcasts found."); break; default: break; } - win_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', 0, NULL, 0, 0, "", ""); } else { switch (affiliation) { case MUC_AFFILIATION_OWNER: - win_print(window, '!', NULL, 0, 0, "", "Owners:"); + win_print(window, '!', 0, NULL, 0, 0, "", "Owners:"); break; case MUC_AFFILIATION_ADMIN: - win_print(window, '!', NULL, 0, 0, "", "Admins:"); + win_print(window, '!', 0, NULL, 0, 0, "", "Admins:"); break; case MUC_AFFILIATION_MEMBER: - win_print(window, '!', NULL, 0, 0, "", "Members:"); + win_print(window, '!', 0, NULL, 0, 0, "", "Members:"); break; case MUC_AFFILIATION_OUTCAST: - win_print(window, '!', NULL, 0, 0, "", "Outcasts:"); + win_print(window, '!', 0, NULL, 0, 0, "", "Outcasts:"); break; default: break; @@ -2344,28 +2344,28 @@ ui_show_room_affiliation_list(ProfMucWin *mucwin, muc_affiliation_t affiliation) Occupant *occupant = curr_occupant->data; if (occupant->affiliation == affiliation) { if (occupant->jid) { - win_vprint(window, '!', NULL, 0, 0, "", " %s (%s)", occupant->nick, occupant->jid); + win_vprint(window, '!', 0, NULL, 0, 0, "", " %s (%s)", occupant->nick, occupant->jid); } else { - win_vprint(window, '!', NULL, 0, 0, "", " %s", occupant->nick); + win_vprint(window, '!', 0, NULL, 0, 0, "", " %s", occupant->nick); } } curr_occupant = g_slist_next(curr_occupant); } - win_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', 0, NULL, 0, 0, "", ""); } } static void _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) { - win_vprint(window, '-', NULL, NO_EOL, THEME_AWAY, "", "[%s] ", tag); - win_vprint(window, '-', NULL, NO_EOL | NO_DATE, 0, "", "%s", field->label); + win_vprint(window, '-', 0, NULL, NO_EOL, THEME_AWAY, "", "[%s] ", tag); + win_vprint(window, '-', 0, NULL, NO_EOL | NO_DATE, 0, "", "%s", field->label); if (field->required) { - win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " (required): "); + win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " (required): "); } else { - win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ": "); + win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ": "); } GSList *values = field->values; @@ -2379,9 +2379,9 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) char *value = curr_value->data; if (value) { if (g_strcmp0(field->var, "muc#roomconfig_roomsecret") == 0) { - win_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", "[hidden]"); + win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", "[hidden]"); } else { - win_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", value); + win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", value); } } } @@ -2391,7 +2391,7 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) if (curr_value) { char *value = curr_value->data; if (value) { - win_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", "[hidden]"); + win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", "[hidden]"); } } win_newline(window); @@ -2403,23 +2403,23 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) char *value = curr_value->data; GString *val_tag = g_string_new(""); g_string_printf(val_tag, "val%d", index++); - win_vprint(window, '-', NULL, 0, THEME_ONLINE, "", " [%s] %s", val_tag->str, value); + win_vprint(window, '-', 0, NULL, 0, THEME_ONLINE, "", " [%s] %s", val_tag->str, value); g_string_free(val_tag, TRUE); curr_value = g_slist_next(curr_value); } break; case FIELD_BOOLEAN: if (curr_value == NULL) { - win_print(window, '-', NULL, NO_DATE, THEME_OFFLINE, "", "FALSE"); + win_print(window, '-', 0, NULL, NO_DATE, THEME_OFFLINE, "", "FALSE"); } else { char *value = curr_value->data; if (value == NULL) { - win_print(window, '-', NULL, NO_DATE, THEME_OFFLINE, "", "FALSE"); + win_print(window, '-', 0, NULL, NO_DATE, THEME_OFFLINE, "", "FALSE"); } else { if (g_strcmp0(value, "0") == 0) { - win_print(window, '-', NULL, NO_DATE, THEME_OFFLINE, "", "FALSE"); + win_print(window, '-', 0, NULL, NO_DATE, THEME_OFFLINE, "", "FALSE"); } else { - win_print(window, '-', NULL, NO_DATE, THEME_ONLINE, "", "TRUE"); + win_print(window, '-', 0, NULL, NO_DATE, THEME_ONLINE, "", "TRUE"); } } } @@ -2433,9 +2433,9 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) while (curr_option) { FormOption *option = curr_option->data; if (g_strcmp0(option->value, value) == 0) { - win_vprint(window, '-', NULL, 0, THEME_ONLINE, "", " [%s] %s", option->value, option->label); + win_vprint(window, '-', 0, NULL, 0, THEME_ONLINE, "", " [%s] %s", option->value, option->label); } else { - win_vprint(window, '-', NULL, 0, THEME_OFFLINE, "", " [%s] %s", option->value, option->label); + win_vprint(window, '-', 0, NULL, 0, THEME_OFFLINE, "", " [%s] %s", option->value, option->label); } curr_option = g_slist_next(curr_option); } @@ -2449,9 +2449,9 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) while (curr_option) { FormOption *option = curr_option->data; if (g_slist_find_custom(curr_value, option->value, (GCompareFunc)g_strcmp0)) { - win_vprint(window, '-', NULL, 0, THEME_ONLINE, "", " [%s] %s", option->value, option->label); + win_vprint(window, '-', 0, NULL, 0, THEME_ONLINE, "", " [%s] %s", option->value, option->label); } else { - win_vprint(window, '-', NULL, 0, THEME_OFFLINE, "", " [%s] %s", option->value, option->label); + win_vprint(window, '-', 0, NULL, 0, THEME_OFFLINE, "", " [%s] %s", option->value, option->label); } curr_option = g_slist_next(curr_option); } @@ -2461,7 +2461,7 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) if (curr_value) { char *value = curr_value->data; if (value) { - win_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", value); + win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", value); } } win_newline(window); @@ -2470,7 +2470,7 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) win_newline(window); while (curr_value) { char *value = curr_value->data; - win_vprint(window, '-', NULL, 0, THEME_ONLINE, "", " %s", value); + win_vprint(window, '-', 0, NULL, 0, THEME_ONLINE, "", " %s", value); curr_value = g_slist_next(curr_value); } break; @@ -2478,7 +2478,7 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) if (curr_value) { char *value = curr_value->data; if (value) { - win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", value); + win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", value); } } win_newline(window); @@ -2493,12 +2493,12 @@ ui_show_form(ProfMucConfWin *confwin) { ProfWin *window = (ProfWin*) confwin; if (confwin->form->title) { - win_print(window, '-', NULL, NO_EOL, 0, "", "Form title: "); - win_print(window, '-', NULL, NO_DATE, 0, "", confwin->form->title); + win_print(window, '-', 0, NULL, NO_EOL, 0, "", "Form title: "); + win_print(window, '-', 0, NULL, NO_DATE, 0, "", confwin->form->title); } else { - win_vprint(window, '-', NULL, 0, 0, "", "Configuration for room %s.", confwin->roomjid); + win_vprint(window, '-', 0, NULL, 0, 0, "", "Configuration for room %s.", confwin->roomjid); } - win_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', 0, NULL, 0, 0, "", ""); ui_show_form_help(confwin); @@ -2510,7 +2510,7 @@ ui_show_form(ProfMucConfWin *confwin) if ((g_strcmp0(field->type, "fixed") == 0) && field->values) { if (field->values) { char *value = field->values->data; - win_print(window, '-', NULL, 0, 0, "", value); + win_print(window, '-', 0, NULL, 0, 0, "", value); } } else if (g_strcmp0(field->type, "hidden") != 0 && field->var) { char *tag = g_hash_table_lookup(confwin->form->var_to_tag, field->var); @@ -2539,11 +2539,11 @@ ui_handle_room_configuration(const char * const roomjid, DataForm *form) ui_ev_focus_win(window); ui_show_form(confwin); - win_print(window, '-', NULL, 0, 0, "", ""); - win_print(window, '-', NULL, 0, 0, "", "Use '/form submit' to save changes."); - win_print(window, '-', NULL, 0, 0, "", "Use '/form cancel' to cancel changes."); - win_print(window, '-', NULL, 0, 0, "", "See '/form help' for more information."); - win_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', 0, NULL, 0, 0, "", ""); + win_print(window, '-', 0, NULL, 0, 0, "", "Use '/form submit' to save changes."); + win_print(window, '-', 0, NULL, 0, 0, "", "Use '/form cancel' to cancel changes."); + win_print(window, '-', 0, NULL, 0, 0, "", "See '/form help' for more information."); + win_print(window, '-', 0, NULL, 0, 0, "", ""); } void @@ -2565,7 +2565,7 @@ ui_handle_room_configuration_form_error(const char * const roomjid, const char * g_string_append(message_str, message); } - win_print(window, '-', NULL, 0, THEME_ERROR, "", message_str->str); + win_print(window, '-', 0, NULL, 0, THEME_ERROR, "", message_str->str); g_string_free(message_str, TRUE); } @@ -2592,7 +2592,7 @@ ui_handle_room_config_submit_result(const char * const roomjid) if (muc_window) { ui_ev_focus_win((ProfWin*)muc_window); - win_print(muc_window, '!', NULL, 0, THEME_ROOMINFO, "", "Room configuration successful"); + win_print(muc_window, '!', 0, NULL, 0, THEME_ROOMINFO, "", "Room configuration successful"); } else { ProfWin *console = wins_get_console(); ui_ev_focus_win(console); @@ -2620,25 +2620,25 @@ ui_handle_room_config_submit_result_error(const char * const roomjid, const char if (form_window) { if (message) { - win_vprint(form_window, '!', NULL, 0, THEME_ERROR, "", "Configuration error: %s", message); + win_vprint(form_window, '!', 0, NULL, 0, THEME_ERROR, "", "Configuration error: %s", message); } else { - win_print(form_window, '!', NULL, 0, THEME_ERROR, "", "Configuration error"); + win_print(form_window, '!', 0, NULL, 0, THEME_ERROR, "", "Configuration error"); } } else if (muc_window) { if (message) { - win_vprint(muc_window, '!', NULL, 0, THEME_ERROR, "", "Configuration error: %s", message); + win_vprint(muc_window, '!', 0, NULL, 0, THEME_ERROR, "", "Configuration error: %s", message); } else { - win_print(muc_window, '!', NULL, 0, THEME_ERROR, "", "Configuration error"); + win_print(muc_window, '!', 0, NULL, 0, THEME_ERROR, "", "Configuration error"); } } else { if (message) { - win_vprint(console, '!', NULL, 0, THEME_ERROR, "", "Configuration error for %s: %s", roomjid, message); + win_vprint(console, '!', 0, NULL, 0, THEME_ERROR, "", "Configuration error for %s: %s", roomjid, message); } else { - win_vprint(console, '!', NULL, 0, THEME_ERROR, "", "Configuration error for %s", roomjid); + win_vprint(console, '!', 0, NULL, 0, THEME_ERROR, "", "Configuration error for %s", roomjid); } } } else { - win_print(console, '!', NULL, 0, THEME_ERROR, "", "Configuration error"); + win_print(console, '!', 0, NULL, 0, THEME_ERROR, "", "Configuration error"); } } @@ -2648,16 +2648,16 @@ ui_show_form_field_help(ProfMucConfWin *confwin, char *tag) ProfWin *window = (ProfWin*) confwin; FormField *field = form_get_field_by_tag(confwin->form, tag); if (field) { - win_print(window, '-', NULL, NO_EOL, 0, "", field->label); + win_print(window, '-', 0, NULL, NO_EOL, 0, "", field->label); if (field->required) { - win_print(window, '-', NULL, NO_DATE, 0, "", " (Required):"); + win_print(window, '-', 0, NULL, NO_DATE, 0, "", " (Required):"); } else { - win_print(window, '-', NULL, NO_DATE, 0, "", ":"); + win_print(window, '-', 0, NULL, NO_DATE, 0, "", ":"); } if (field->description) { - win_vprint(window, '-', NULL, 0, 0, "", " Description : %s", field->description); + win_vprint(window, '-', 0, NULL, 0, 0, "", " Description : %s", field->description); } - win_vprint(window, '-', NULL, 0, 0, "", " Type : %s", field->type); + win_vprint(window, '-', 0, NULL, 0, 0, "", " Type : %s", field->type); int num_values = 0; GSList *curr_option = NULL; @@ -2666,51 +2666,51 @@ ui_show_form_field_help(ProfMucConfWin *confwin, char *tag) switch (field->type_t) { case FIELD_TEXT_SINGLE: case FIELD_TEXT_PRIVATE: - win_vprint(window, '-', NULL, 0, 0, "", " Set : /%s ", tag); - win_print(window, '-', NULL, 0, 0, "", " Where : is any text"); + win_vprint(window, '-', 0, NULL, 0, 0, "", " Set : /%s ", tag); + win_print(window, '-', 0, NULL, 0, 0, "", " Where : is any text"); break; case FIELD_TEXT_MULTI: num_values = form_get_value_count(confwin->form, tag); - win_vprint(window, '-', NULL, 0, 0, "", " Add : /%s add ", tag); - win_print(window, '-', NULL, 0, 0, "", " Where : is any text"); + win_vprint(window, '-', 0, NULL, 0, 0, "", " Add : /%s add ", tag); + win_print(window, '-', 0, NULL, 0, 0, "", " Where : is any text"); if (num_values > 0) { - win_vprint(window, '-', NULL, 0, 0, "", " Remove : /%s remove ", tag); - win_vprint(window, '-', NULL, 0, 0, "", " Where : between 'val1' and 'val%d'", num_values); + win_vprint(window, '-', 0, NULL, 0, 0, "", " Remove : /%s remove ", tag); + win_vprint(window, '-', 0, NULL, 0, 0, "", " Where : between 'val1' and 'val%d'", num_values); } break; case FIELD_BOOLEAN: - win_vprint(window, '-', NULL, 0, 0, "", " Set : /%s ", tag); - win_print(window, '-', NULL, 0, 0, "", " Where : is either 'on' or 'off'"); + win_vprint(window, '-', 0, NULL, 0, 0, "", " Set : /%s ", tag); + win_print(window, '-', 0, NULL, 0, 0, "", " Where : is either 'on' or 'off'"); break; case FIELD_LIST_SINGLE: - win_vprint(window, '-', NULL, 0, 0, "", " Set : /%s ", tag); - win_print(window, '-', NULL, 0, 0, "", " Where : is one of"); + win_vprint(window, '-', 0, NULL, 0, 0, "", " Set : /%s ", tag); + win_print(window, '-', 0, NULL, 0, 0, "", " Where : is one of"); curr_option = field->options; while (curr_option) { option = curr_option->data; - win_vprint(window, '-', NULL, 0, 0, "", " %s", option->value); + win_vprint(window, '-', 0, NULL, 0, 0, "", " %s", option->value); curr_option = g_slist_next(curr_option); } break; case FIELD_LIST_MULTI: - win_vprint(window, '-', NULL, 0, 0, "", " Add : /%s add ", tag); - win_vprint(window, '-', NULL, 0, 0, "", " Remove : /%s remove ", tag); - win_print(window, '-', NULL, 0, 0, "", " Where : is one of"); + win_vprint(window, '-', 0, NULL, 0, 0, "", " Add : /%s add ", tag); + win_vprint(window, '-', 0, NULL, 0, 0, "", " Remove : /%s remove ", tag); + win_print(window, '-', 0, NULL, 0, 0, "", " Where : is one of"); curr_option = field->options; while (curr_option) { option = curr_option->data; - win_vprint(window, '-', NULL, 0, 0, "", " %s", option->value); + win_vprint(window, '-', 0, NULL, 0, 0, "", " %s", option->value); curr_option = g_slist_next(curr_option); } break; case FIELD_JID_SINGLE: - win_vprint(window, '-', NULL, 0, 0, "", " Set : /%s ", tag); - win_print(window, '-', NULL, 0, 0, "", " Where : is a valid Jabber ID"); + win_vprint(window, '-', 0, NULL, 0, 0, "", " Set : /%s ", tag); + win_print(window, '-', 0, NULL, 0, 0, "", " Where : is a valid Jabber ID"); break; case FIELD_JID_MULTI: - win_vprint(window, '-', NULL, 0, 0, "", " Add : /%s add ", tag); - win_vprint(window, '-', NULL, 0, 0, "", " Remove : /%s remove ", tag); - win_print(window, '-', NULL, 0, 0, "", " Where : is a valid Jabber ID"); + win_vprint(window, '-', 0, NULL, 0, 0, "", " Add : /%s add ", tag); + win_vprint(window, '-', 0, NULL, 0, 0, "", " Remove : /%s remove ", tag); + win_print(window, '-', 0, NULL, 0, 0, "", " Where : is a valid Jabber ID"); break; case FIELD_FIXED: case FIELD_UNKNOWN: @@ -2719,7 +2719,7 @@ ui_show_form_field_help(ProfMucConfWin *confwin, char *tag) break; } } else { - win_vprint(window, '-', NULL, 0, 0, "", "No such field %s", tag); + win_vprint(window, '-', 0, NULL, 0, 0, "", "No such field %s", tag); } } @@ -2728,9 +2728,9 @@ ui_show_form_help(ProfMucConfWin *confwin) { if (confwin->form->instructions) { ProfWin *window = (ProfWin*) confwin; - win_print(window, '-', NULL, 0, 0, "", "Supplied instructions:"); - win_print(window, '-', NULL, 0, 0, "", confwin->form->instructions); - win_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', 0, NULL, 0, 0, "", "Supplied instructions:"); + win_print(window, '-', 0, NULL, 0, 0, "", confwin->form->instructions); + win_print(window, '-', 0, NULL, 0, 0, "", ""); } } @@ -2740,7 +2740,7 @@ ui_show_lines(ProfWin *window, const gchar** lines) if (lines) { int i; for (i = 0; lines[i] != NULL; i++) { - win_print(window, '-', NULL, 0, 0, "", lines[i]); + win_print(window, '-', 0, NULL, 0, 0, "", lines[i]); } } } @@ -2808,11 +2808,11 @@ _win_show_history(ProfChatWin *chatwin, const char * const contact) char mm[3]; memcpy(mm, &line[3], 2); mm[2] = '\0'; int imm = atoi(mm); char ss[3]; memcpy(ss, &line[6], 2); ss[2] = '\0'; int iss = atoi(ss); GDateTime *timestamp = g_date_time_new_local(2000, 1, 1, ihh, imm, iss); - win_print((ProfWin*)chatwin, '-', timestamp, NO_COLOUR_DATE, 0, "", curr->data+11); + win_print((ProfWin*)chatwin, '-', 0, timestamp, NO_COLOUR_DATE, 0, "", curr->data+11); g_date_time_unref(timestamp); // header } else { - win_print((ProfWin*)chatwin, '-', NULL, 0, 0, "", curr->data); + win_print((ProfWin*)chatwin, '-', 0, NULL, 0, 0, "", curr->data); } curr = g_slist_next(curr); } diff --git a/src/ui/ui.h b/src/ui/ui.h index dba90d2b..90f29b65 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -352,8 +352,8 @@ void win_hide_subwin(ProfWin *window); void win_show_subwin(ProfWin *window); void win_refresh_without_subwin(ProfWin *window); void win_refresh_with_subwin(ProfWin *window); -void win_print(ProfWin *window, const char show_char, GDateTime *timestamp, int flags, theme_item_t theme_item, const char * const from, const char * const message); -void win_vprint(ProfWin *window, const char show_char, GDateTime *timestamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...); +void win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *timestamp, int flags, theme_item_t theme_item, const char * const from, const char * const message); +void win_vprint(ProfWin *window, const char show_char, int pad_indent, GDateTime *timestamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...); char* win_get_title(ProfWin *window); void win_show_occupant(ProfWin *window, Occupant *occupant); void win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occupant); diff --git a/src/ui/window.c b/src/ui/window.c index 6c76b5f8..bfc992ae 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -59,9 +59,9 @@ #define CEILING(X) (X-(int)(X) > 0 ? (int)(X+1) : (int)(X)) -static void _win_print(ProfWin *window, const char show_char, GDateTime *time, +static void _win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *time, int flags, theme_item_t theme_item, const char * const from, const char * const message, DeliveryReceipt *receipt); -static void _win_print_wrapped(WINDOW *win, const char * const message, size_t indent); +static void _win_print_wrapped(WINDOW *win, const char * const message, size_t indent, int pad_indent); int win_roster_cols(void) @@ -577,14 +577,14 @@ win_show_occupant(ProfWin *window, Occupant *occupant) theme_item_t presence_colour = theme_main_presence_attrs(presence_str); - win_print(window, '-', NULL, NO_EOL, presence_colour, "", occupant->nick); - win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str); + win_print(window, '-', 0, NULL, NO_EOL, presence_colour, "", occupant->nick); + win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str); if (occupant->status) { - win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", occupant->status); + win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", occupant->status); } - win_print(window, '-', NULL, NO_DATE, presence_colour, "", ""); + win_print(window, '-', 0, NULL, NO_DATE, presence_colour, "", ""); } void @@ -599,12 +599,12 @@ win_show_contact(ProfWin *window, PContact contact) theme_item_t presence_colour = theme_main_presence_attrs(presence); if (name) { - win_print(window, '-', NULL, NO_EOL, presence_colour, "", name); + win_print(window, '-', 0, NULL, NO_EOL, presence_colour, "", name); } else { - win_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid); + win_print(window, '-', 0, NULL, NO_EOL, presence_colour, "", barejid); } - win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence); + win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence); if (last_activity) { GDateTime *now = g_date_time_new_now_local(); @@ -617,18 +617,18 @@ win_show_contact(ProfWin *window, PContact contact) int seconds = span / G_TIME_SPAN_SECOND; if (hours > 0) { - win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dh%dm%ds", hours, minutes, seconds); + win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dh%dm%ds", hours, minutes, seconds); } else { - win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dm%ds", minutes, seconds); + win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dm%ds", minutes, seconds); } } if (status) { - win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", p_contact_status(contact)); + win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", p_contact_status(contact)); } - win_print(window, '-', NULL, NO_DATE, presence_colour, "", ""); + win_print(window, '-', 0, NULL, NO_DATE, presence_colour, "", ""); } void @@ -640,21 +640,21 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup theme_item_t presence_colour = theme_main_presence_attrs(presence_str); - win_print(window, '!', NULL, NO_EOL, presence_colour, "", occupant->nick); - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str); + win_print(window, '!', 0, NULL, NO_EOL, presence_colour, "", occupant->nick); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str); if (occupant->status) { - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", occupant->status); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", occupant->status); } win_newline(window); if (occupant->jid) { - win_vprint(window, '!', NULL, 0, 0, "", " Jid: %s", occupant->jid); + win_vprint(window, '!', 0, NULL, 0, 0, "", " Jid: %s", occupant->jid); } - win_vprint(window, '!', NULL, 0, 0, "", " Affiliation: %s", occupant_affiliation); - win_vprint(window, '!', NULL, 0, 0, "", " Role: %s", occupant_role); + win_vprint(window, '!', 0, NULL, 0, 0, "", " Affiliation: %s", occupant_affiliation); + win_vprint(window, '!', 0, NULL, 0, 0, "", " Role: %s", occupant_role); Jid *jidp = jid_create_from_bare_and_resource(room, occupant->nick); Capabilities *caps = caps_lookup(jidp->fulljid); @@ -663,38 +663,38 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup if (caps) { // show identity if (caps->category || caps->type || caps->name) { - win_print(window, '!', NULL, NO_EOL, 0, "", " Identity: "); + win_print(window, '!', 0, NULL, NO_EOL, 0, "", " Identity: "); if (caps->name) { - win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->name); + win_print(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->name); if (caps->category || caps->type) { - win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); + win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (caps->type) { - win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->type); + win_print(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->type); if (caps->category) { - win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", " "); + win_print(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (caps->category) { - win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->category); + win_print(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->category); } win_newline(window); } if (caps->software) { - win_vprint(window, '!', NULL, NO_EOL, 0, "", " Software: %s", caps->software); + win_vprint(window, '!', 0, NULL, NO_EOL, 0, "", " Software: %s", caps->software); } if (caps->software_version) { - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } if (caps->software || caps->software_version) { win_newline(window); } if (caps->os) { - win_vprint(window, '!', NULL, NO_EOL, 0, "", " OS: %s", caps->os); + win_vprint(window, '!', 0, NULL, NO_EOL, 0, "", " OS: %s", caps->os); } if (caps->os_version) { - win_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); + win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } if (caps->os || caps->os_version) { win_newline(window); @@ -702,7 +702,7 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup caps_destroy(caps); } - win_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', 0, NULL, 0, 0, "", ""); } void @@ -716,15 +716,15 @@ win_show_info(ProfWin *window, PContact contact) theme_item_t presence_colour = theme_main_presence_attrs(presence); - win_print(window, '-', NULL, 0, 0, "", ""); - win_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid); + win_print(window, '-', 0, NULL, 0, 0, "", ""); + win_print(window, '-', 0, NULL, NO_EOL, presence_colour, "", barejid); if (name) { - win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%s)", name); + win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", " (%s)", name); } - win_print(window, '-', NULL, NO_DATE, 0, "", ":"); + win_print(window, '-', 0, NULL, NO_DATE, 0, "", ":"); if (sub) { - win_vprint(window, '-', NULL, 0, 0, "", "Subscription: %s", sub); + win_vprint(window, '-', 0, NULL, 0, 0, "", "Subscription: %s", sub); } if (last_activity) { @@ -738,10 +738,10 @@ win_show_info(ProfWin *window, PContact contact) int seconds = span / G_TIME_SPAN_SECOND; if (hours > 0) { - win_vprint(window, '-', NULL, 0, 0, "", "Last activity: %dh%dm%ds", hours, minutes, seconds); + win_vprint(window, '-', 0, NULL, 0, 0, "", "Last activity: %dh%dm%ds", hours, minutes, seconds); } else { - win_vprint(window, '-', NULL, 0, 0, "", "Last activity: %dm%ds", minutes, seconds); + win_vprint(window, '-', 0, NULL, 0, 0, "", "Last activity: %dm%ds", minutes, seconds); } g_date_time_unref(now); @@ -750,7 +750,7 @@ win_show_info(ProfWin *window, PContact contact) GList *resources = p_contact_get_available_resources(contact); GList *ordered_resources = NULL; if (resources) { - win_print(window, '-', NULL, 0, 0, "", "Resources:"); + win_print(window, '-', 0, NULL, 0, 0, "", "Resources:"); // sort in order of availability GList *curr = resources; @@ -768,9 +768,9 @@ win_show_info(ProfWin *window, PContact contact) Resource *resource = curr->data; const char *resource_presence = string_from_resource_presence(resource->presence); theme_item_t presence_colour = theme_main_presence_attrs(resource_presence); - win_vprint(window, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence); + win_vprint(window, '-', 0, NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence); if (resource->status) { - win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status); + win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status); } win_newline(window); @@ -781,38 +781,38 @@ win_show_info(ProfWin *window, PContact contact) if (caps) { // show identity if (caps->category || caps->type || caps->name) { - win_print(window, '-', NULL, NO_EOL, 0, "", " Identity: "); + win_print(window, '-', 0, NULL, NO_EOL, 0, "", " Identity: "); if (caps->name) { - win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name); + win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->name); if (caps->category || caps->type) { - win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); + win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (caps->type) { - win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type); + win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->type); if (caps->category) { - win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); + win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (caps->category) { - win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category); + win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->category); } win_newline(window); } if (caps->software) { - win_vprint(window, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software); + win_vprint(window, '-', 0, NULL, NO_EOL, 0, "", " Software: %s", caps->software); } if (caps->software_version) { - win_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); + win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } if (caps->software || caps->software_version) { win_newline(window); } if (caps->os) { - win_vprint(window, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os); + win_vprint(window, '-', 0, NULL, NO_EOL, 0, "", " OS: %s", caps->os); } if (caps->os_version) { - win_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); + win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } if (caps->os || caps->os_version) { win_newline(window); @@ -842,12 +842,12 @@ win_show_status_string(ProfWin *window, const char * const from, } - win_vprint(window, '-', NULL, NO_EOL, presence_colour, "", "%s %s", pre, from); + win_vprint(window, '-', 0, NULL, NO_EOL, presence_colour, "", "%s %s", pre, from); if (show) - win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", show); + win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", show); else - win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", default_show); + win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", default_show); if (last_activity) { GDateTime *now = g_date_time_new_now_local(); @@ -861,17 +861,17 @@ win_show_status_string(ProfWin *window, const char * const from, int seconds = span / G_TIME_SPAN_SECOND; if (hours > 0) { - win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dh%dm%ds", hours, minutes, seconds); + win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dh%dm%ds", hours, minutes, seconds); } else { - win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dm%ds", minutes, seconds); + win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dm%ds", minutes, seconds); } } if (status) - win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", status); + win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", status); - win_print(window, '-', NULL, NO_DATE, presence_colour, "", ""); + win_print(window, '-', 0, NULL, NO_DATE, presence_colour, "", ""); } @@ -883,7 +883,7 @@ win_print_incoming_message(ProfWin *window, GDateTime *timestamp, { case WIN_CHAT: case WIN_PRIVATE: - win_print(window, '-', timestamp, NO_ME, THEME_TEXT_THEM, from, message); + win_print(window, '-', 0, timestamp, NO_ME, THEME_TEXT_THEM, from, message); break; default: assert(FALSE); @@ -892,31 +892,31 @@ win_print_incoming_message(ProfWin *window, GDateTime *timestamp, } void -win_vprint(ProfWin *window, const char show_char, GDateTime *timestamp, +win_vprint(ProfWin *window, const char show_char, int pad_indent, GDateTime *timestamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...) { va_list arg; va_start(arg, message); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, message, arg); - win_print(window, show_char, timestamp, flags, theme_item, from, fmt_msg->str); + win_print(window, show_char, pad_indent, timestamp, flags, theme_item, from, fmt_msg->str); g_string_free(fmt_msg, TRUE); } void -win_print(ProfWin *window, const char show_char, GDateTime *timestamp, +win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *timestamp, int flags, theme_item_t theme_item, const char * const from, const char * const message) { if (timestamp == NULL) timestamp = g_date_time_new_now_local(); - buffer_push(window->layout->buffer, show_char, timestamp, flags, theme_item, from, message, NULL); - _win_print(window, show_char, timestamp, flags, theme_item, from, message, NULL); + buffer_push(window->layout->buffer, show_char, pad_indent, timestamp, flags, theme_item, from, message, NULL); + _win_print(window, show_char, pad_indent, timestamp, flags, theme_item, from, message, NULL); // TODO: cross-reference.. this should be replaced by a real event-based system ui_input_nonblocking(TRUE); } void -win_print_with_receipt(ProfWin *window, const char show_char, GTimeVal *tstamp, +win_print_with_receipt(ProfWin *window, const char show_char, int pad_indent, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, char *id) { GDateTime *time; @@ -931,8 +931,8 @@ win_print_with_receipt(ProfWin *window, const char show_char, GTimeVal *tstamp, receipt->id = strdup(id); receipt->received = FALSE; - buffer_push(window->layout->buffer, show_char, time, flags, theme_item, from, message, receipt); - _win_print(window, show_char, time, flags, theme_item, from, message, receipt); + buffer_push(window->layout->buffer, show_char, pad_indent, time, flags, theme_item, from, message, receipt); + _win_print(window, show_char, pad_indent, time, flags, theme_item, from, message, receipt); // TODO: cross-reference.. this should be replaced by a real event-based system ui_input_nonblocking(TRUE); } @@ -949,17 +949,17 @@ win_mark_received(ProfWin *window, const char * const id) void win_println(ProfWin *window, const char * const message) { - win_print(window, '-', NULL, 0, 0, "", message); + win_print(window, '-', 0, NULL, 0, 0, "", message); } void win_newline(ProfWin *window) { - win_print(window, '-', NULL, NO_DATE, 0, "", ""); + win_print(window, '-', 0, NULL, NO_DATE, 0, "", ""); } static void -_win_print(ProfWin *window, const char show_char, GDateTime *time, +_win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *time, int flags, theme_item_t theme_item, const char * const from, const char * const message, DeliveryReceipt *receipt) { // flags : 1st bit = 0/1 - me/not me @@ -1028,7 +1028,7 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time, } if (prefs_get_boolean(PREF_WRAP)) { - _win_print_wrapped(window->layout->win, message+offset, indent); + _win_print_wrapped(window->layout->win, message+offset, indent, pad_indent); } else { wprintw(window->layout->win, "%s", message+offset); } @@ -1058,23 +1058,29 @@ _win_indent(WINDOW *win, int size) } static void -_win_print_wrapped(WINDOW *win, const char * const message, size_t indent) +_win_print_wrapped(WINDOW *win, const char * const message, size_t indent, int pad_indent) { + int starty = getcury(win); int wordi = 0; char *word = malloc(strlen(message) + 1); gchar *curr_ch = g_utf8_offset_to_pointer(message, 0); while (*curr_ch != '\0') { + + // handle space if (*curr_ch == ' ') { waddch(win, ' '); curr_ch = g_utf8_next_char(curr_ch); + + // handle newline } else if (*curr_ch == '\n') { waddch(win, '\n'); - _win_indent(win, indent); + _win_indent(win, indent + pad_indent); curr_ch = g_utf8_next_char(curr_ch); + + // handle word } else { - // get word wordi = 0; while (*curr_ch != ' ' && *curr_ch != '\n' && *curr_ch != '\0') { size_t ch_len = mbrlen(curr_ch, 4, NULL); @@ -1087,23 +1093,33 @@ _win_print_wrapped(WINDOW *win, const char * const message, size_t indent) word[wordi] = '\0'; int curx = getcurx(win); + int cury = getcury(win); int maxx = getmaxx(win); + gboolean firstline = (cury == starty); // word larger than line - if (utf8_display_len(word) > (maxx - indent)) { + if ((firstline && (utf8_display_len(word) > (maxx - indent))) || + (!firstline && (utf8_display_len(word) > (maxx - (indent + pad_indent))))) { + gchar *word_ch = g_utf8_offset_to_pointer(word, 0); while(*word_ch != '\0') { curx = getcurx(win); - if (curx < indent) { + cury = getcury(win); + firstline = cury == starty; + + if (firstline && curx < indent) { _win_indent(win, indent); } + if (!firstline && curx < (indent + pad_indent)) { + _win_indent(win, indent + pad_indent); + } gchar copy[wordi++]; g_utf8_strncpy(copy, word_ch, 1); if (curx + utf8_display_len(copy) > maxx) { waddch(win, '\n'); - _win_indent(win, indent); + _win_indent(win, indent + pad_indent); } waddstr(win, copy); @@ -1112,14 +1128,26 @@ _win_print_wrapped(WINDOW *win, const char * const message, size_t indent) } else { if (curx + utf8_display_len(word) > maxx) { waddch(win, '\n'); + _win_indent(win, indent + pad_indent); + } + if (firstline && curx < indent) { _win_indent(win, indent); } - if (curx < indent) { - _win_indent(win, indent); + if (!firstline && curx < (indent + pad_indent)) { + _win_indent(win, indent + pad_indent); } wprintw(win, "%s", word); } } + + // consume first space of next line + int curx = getcurx(win); + int cury = getcury(win); + gboolean firstline = (cury == starty); + + if (!firstline && curx == 0 && *curr_ch == ' ') { + curr_ch = g_utf8_next_char(curr_ch); + } } free(word); @@ -1134,7 +1162,7 @@ win_redraw(ProfWin *window) for (i = 0; i < size; i++) { ProfBuffEntry *e = buffer_yield_entry(window->layout->buffer, i); - _win_print(window, e->show_char, e->time, e->flags, e->theme_item, e->from, e->message, e->receipt); + _win_print(window, e->show_char, e->pad_indent, e->time, e->flags, e->theme_item, e->from, e->message, e->receipt); } } diff --git a/src/ui/window.h b/src/ui/window.h index 35f82f1c..64989e4c 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -61,7 +61,7 @@ void win_show_status_string(ProfWin *window, const char * const from, const char * const default_show); void win_print_incoming_message(ProfWin *window, GDateTime *timestamp, const char * const from, const char * const message); -void win_print_with_receipt(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, +void win_print_with_receipt(ProfWin *window, const char show_char, int pad_indent, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, char *id); void win_newline(ProfWin *window); void win_redraw(ProfWin *window); diff --git a/src/window_list.c b/src/window_list.c index 2892cc53..a300bd82 100644 --- a/src/window_list.c +++ b/src/window_list.c @@ -497,7 +497,7 @@ wins_lost_connection(void) while (curr) { ProfWin *window = curr->data; if (window->type != WIN_CONSOLE) { - win_print(window, '-', NULL, 0, THEME_ERROR, "", "Lost connection."); + win_print(window, '-', 0, NULL, 0, THEME_ERROR, "", "Lost connection."); // if current win, set current_win_dirty if (wins_is_current(window)) { diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index efe70d62..59e2ac9f 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -539,8 +539,8 @@ void win_hide_subwin(ProfWin *window) {} void win_show_subwin(ProfWin *window) {} void win_refresh_without_subwin(ProfWin *window) {} void win_refresh_with_subwin(ProfWin *window) {} -void win_print(ProfWin *window, const char show_char, GDateTime *timestamp, int flags, theme_item_t theme_item, const char * const from, const char * const message) {} -void win_vprint(ProfWin *window, const char show_char, GDateTime *timestamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...) {} +void win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *timestamp, int flags, theme_item_t theme_item, const char * const from, const char * const message) {} +void win_vprint(ProfWin *window, const char show_char, int pad_indent, GDateTime *timestamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...) {} char* win_get_title(ProfWin *window) { return NULL; From 79f618367d1e3a5e1c3fa55798e7e5b01f577273 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 29 Jul 2015 23:03:00 +0100 Subject: [PATCH 23/25] Do not print newline when curs position 0 --- src/ui/window.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ui/window.c b/src/ui/window.c index bfc992ae..1b811a8e 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1034,7 +1034,10 @@ _win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *tim } if ((flags & NO_EOL) == 0) { - wprintw(window->layout->win, "\n"); + int curx = getcurx(window->layout->win); + if (curx != 0) { + wprintw(window->layout->win, "\n"); + } } if (me_message) { From 8ec931eb84896ae261b39cd884d4463338b7f2b2 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 29 Jul 2015 23:48:28 +0100 Subject: [PATCH 24/25] Added cons_show_padded --- src/command/commands.c | 8 ++-- src/event/server_events.c | 6 +-- src/ui/console.c | 80 +++++++++++++++++++++--------------- src/ui/core.c | 4 +- src/ui/ui.h | 3 +- src/ui/window.c | 4 +- tests/unittests/ui/stub_ui.c | 4 +- 7 files changed, 64 insertions(+), 45 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 86be7bc1..ede1b395 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1873,7 +1873,7 @@ cmd_status(ProfWin *window, const char * const command, gchar **args) if (pcontact) { win_show_contact(window, pcontact); } else { - win_println(window, "Error getting contact info."); + win_println(window, 0, "Error getting contact info."); } } break; @@ -1888,7 +1888,7 @@ cmd_status(ProfWin *window, const char * const command, gchar **args) if (occupant) { win_show_occupant(window, occupant); } else { - win_println(window, "Error getting contact info."); + win_println(window, 0, "Error getting contact info."); } jid_destroy(jid); } @@ -1954,7 +1954,7 @@ cmd_info(ProfWin *window, const char * const command, gchar **args) if (pcontact) { win_show_info(window, pcontact); } else { - win_println(window, "Error getting contact info."); + win_println(window, 0, "Error getting contact info."); } } break; @@ -1969,7 +1969,7 @@ cmd_info(ProfWin *window, const char * const command, gchar **args) if (occupant) { win_show_occupant_info(window, jid->barejid, occupant); } else { - win_println(window, "Error getting contact info."); + win_println(window, 0, "Error getting contact info."); } jid_destroy(jid); } diff --git a/src/event/server_events.c b/src/event/server_events.c index df7a4418..ce667136 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -208,12 +208,12 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_m prof_enc_t enc_mode = chatwin->enc_mode; if (enc_message) { if (enc_mode == PROF_ENC_OTR) { - win_println((ProfWin*)chatwin, "PGP encrypted message received whilst in OTR session."); + win_println((ProfWin*)chatwin, 0, "PGP encrypted message received whilst in OTR session."); } else { // PROF_ENC_NONE, PROF_ENC_PGP char *decrypted = p_gpg_decrypt(barejid, enc_message); if (decrypted) { if (enc_mode == PROF_ENC_NONE) { - win_println((ProfWin*)chatwin, "PGP encryption enabled."); + win_println((ProfWin*)chatwin, 0, "PGP encryption enabled."); } ui_incoming_msg(chatwin, resource, decrypted, NULL, new_win); chat_log_pgp_msg_in(barejid, decrypted); @@ -226,7 +226,7 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_m } } else { if (enc_mode == PROF_ENC_PGP) { - win_println((ProfWin*)chatwin, "PGP encryption disabled."); + win_println((ProfWin*)chatwin, 0, "PGP encryption disabled."); ui_incoming_msg(chatwin, resource, message, NULL, new_win); chat_log_msg_in(barejid, message); chatwin->enc_mode = PROF_ENC_NONE; diff --git a/src/ui/console.c b/src/ui/console.c index e3e6f6a3..27b1b81d 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -86,7 +86,7 @@ cons_debug(const char * const msg, ...) va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - win_println(console, fmt_msg->str); + win_println(console, 0, fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); } @@ -100,7 +100,20 @@ cons_show(const char * const msg, ...) va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - win_println(console, fmt_msg->str); + win_println(console, 0, fmt_msg->str); + g_string_free(fmt_msg, TRUE); + va_end(arg); +} + +void +cons_show_padded(int pad, const char * const msg, ...) +{ + ProfWin *console = wins_get_console(); + va_list arg; + va_start(arg, msg); + GString *fmt_msg = g_string_new(NULL); + g_string_vprintf(fmt_msg, msg, arg); + win_println(console, pad, fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); } @@ -125,7 +138,7 @@ cons_show_help(Command *command) cons_show(""); win_print(console, '-', 0, NULL, 0, THEME_WHITE_BOLD, "", "Description"); - win_println(console, command->help.desc); + win_println(console, 0, command->help.desc); int maxlen = 0; for (i = 0; command->help.args[i][0] != NULL; i++) { @@ -232,13 +245,13 @@ cons_about(void) } win_vprint(console, '-', 0, NULL, 0, 0, "", "Copyright (C) 2012 - 2015 James Booth <%s>.", PACKAGE_BUGREPORT); - win_println(console, "License GPLv3+: GNU GPL version 3 or later "); - win_println(console, ""); - win_println(console, "This is free software; you are free to change and redistribute it."); - win_println(console, "There is NO WARRANTY, to the extent permitted by law."); - win_println(console, ""); - win_println(console, "Type '/help' to show complete help."); - win_println(console, ""); + win_println(console, 0, "License GPLv3+: GNU GPL version 3 or later "); + win_println(console, 0, ""); + win_println(console, 0, "This is free software; you are free to change and redistribute it."); + win_println(console, 0, "There is NO WARRANTY, to the extent permitted by law."); + win_println(console, 0, ""); + win_println(console, 0, "Type '/help' to show complete help."); + win_println(console, 0, ""); if (prefs_get_boolean(PREF_VERCHECK)) { cons_check_version(FALSE); @@ -261,12 +274,12 @@ cons_check_version(gboolean not_available_msg) if (relase_valid) { if (release_is_new(latest_release)) { win_vprint(console, '-', 0, NULL, 0, 0, "", "A new version of Profanity is available: %s", latest_release); - win_println(console, "Check for details."); - win_println(console, ""); + win_println(console, 0, "Check for details."); + win_println(console, 0, ""); } else { if (not_available_msg) { - win_println(console, "No new version available."); - win_println(console, ""); + win_println(console, 0, "No new version available."); + win_println(console, 0, ""); } } @@ -303,7 +316,7 @@ cons_show_wins(void) GSList *curr = window_strings; while (curr) { - win_println(console, curr->data); + win_println(console, 0, curr->data); curr = g_slist_next(curr); } g_slist_free_full(window_strings, free); @@ -392,7 +405,7 @@ cons_show_caps(const char * const fulljid, resource_presence_t presence) } if (caps->features) { - win_println(console, "Features:"); + win_println(console, 0, "Features:"); GSList *feature = caps->features; while (feature) { win_vprint(console, '-', 0, NULL, 0, 0, "", " %s", feature->data); @@ -780,7 +793,7 @@ cons_show_account(ProfAccount *account) GList *curr = resources; if (curr) { - win_println(console, "Resources:"); + win_println(console, 0, "Resources:"); // sort in order of availability while (curr) { @@ -1531,19 +1544,21 @@ cons_prefs(void) void cons_help(void) { + int pad = strlen("/help commands connection") + 3; + cons_show(""); cons_show("Choose a help option:"); cons_show(""); - cons_show("/help commands - List all commands."); - cons_show("/help commands chat - List chat commands."); - cons_show("/help commands groupchat - List groupchat commands."); - cons_show("/help commands roster - List commands for manipulating your roster."); - cons_show("/help commands presence - List commands to change your presence."); - cons_show("/help commands discovery - List service discovery commands."); - cons_show("/help commands connection - List commands related to managing your connection."); - cons_show("/help commands ui - List commands for manipulating the user interface."); - cons_show("/help [command] - Detailed help on a specific command."); - cons_show("/help navigation - How to navigate around Profanity."); + cons_show_padded(pad, "/help commands : List all commands."); + cons_show_padded(pad, "/help commands chat : List chat commands."); + cons_show_padded(pad, "/help commands groupchat : List groupchat commands."); + cons_show_padded(pad, "/help commands roster : List commands for manipulating your roster."); + cons_show_padded(pad, "/help commands presence : List commands to change your presence."); + cons_show_padded(pad, "/help commands discovery : List service discovery commands."); + cons_show_padded(pad, "/help commands connection : List commands related to managing your connection."); + cons_show_padded(pad, "/help commands ui : List commands for manipulating the user interface."); + cons_show_padded(pad, "/help [command] : Detailed help on a specific command."); + cons_show_padded(pad, "/help navigation : How to navigate around Profanity."); cons_show(""); cons_alert(); @@ -1552,13 +1567,14 @@ cons_help(void) void cons_navigation_help(void) { + int pad = strlen("Alt-PAGEUP, Alt-PAGEDOWN") + 3; ProfWin *console = wins_get_console(); cons_show(""); win_print(console, '-', 0, NULL, 0, THEME_WHITE_BOLD, "", "Navigation"); - cons_show("Alt-1..Alt-0, F1..F10 : Choose window."); - cons_show("Alt-LEFT, Alt-RIGHT : Previous/next chat window"); - cons_show("PAGEUP, PAGEDOWN : Page the main window."); - cons_show("Alt-PAGEUP, Alt-PAGEDOWN : Page occupants/roster panel."); + cons_show_padded(pad, "Alt-1..Alt-0, F1..F10 : Choose window."); + cons_show_padded(pad, "Alt-LEFT, Alt-RIGHT : Previous/next chat window"); + cons_show_padded(pad, "PAGEUP, PAGEDOWN : Page the main window."); + cons_show_padded(pad, "Alt-PAGEUP, Alt-PAGEDOWN : Page occupants/roster panel."); cons_show(""); cons_alert(); @@ -1682,7 +1698,7 @@ static void _cons_splash_logo(void) { ProfWin *console = wins_get_console(); - win_println(console, "Welcome to"); + win_println(console, 0, "Welcome to"); win_print(console, '-', 0, NULL, 0, THEME_SPLASH, "", " ___ _ "); win_print(console, '-', 0, NULL, 0, THEME_SPLASH, "", " / __) (_)_ "); diff --git a/src/ui/core.c b/src/ui/core.c index fb647083..bbaebe31 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1150,7 +1150,7 @@ ui_current_print_line(const char * const msg, ...) va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - win_println(window, fmt_msg->str); + win_println(window, 0, fmt_msg->str); va_end(arg); g_string_free(fmt_msg, TRUE); } @@ -2526,7 +2526,7 @@ ui_show_form_field(ProfWin *window, DataForm *form, char *tag) { FormField *field = form_get_field_by_tag(form, tag); _ui_handle_form_field(window, tag, field); - win_println(window, ""); + win_println(window, 0, ""); } void diff --git a/src/ui/ui.h b/src/ui/ui.h index 90f29b65..fd81f68a 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -240,6 +240,7 @@ void ui_inp_history_append(char *inp); // console window actions void cons_show(const char * const msg, ...); +void cons_show_padded(int pad, const char * const msg, ...); void cons_about(void); void cons_help(void); void cons_show_help(Command *command); @@ -359,7 +360,7 @@ void win_show_occupant(ProfWin *window, Occupant *occupant); void win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occupant); void win_show_contact(ProfWin *window, PContact contact); void win_show_info(ProfWin *window, PContact contact); -void win_println(ProfWin *window, const char * const message); +void win_println(ProfWin *window, int pad, const char * const message); // desktop notifier actions void notifier_initialise(void); diff --git a/src/ui/window.c b/src/ui/window.c index 1b811a8e..daf701bb 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -947,9 +947,9 @@ win_mark_received(ProfWin *window, const char * const id) } void -win_println(ProfWin *window, const char * const message) +win_println(ProfWin *window, int pad, const char * const message) { - win_print(window, '-', 0, NULL, 0, 0, "", message); + win_print(window, '-', pad, NULL, 0, 0, "", message); } void diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 59e2ac9f..43fc2954 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -358,6 +358,8 @@ void cons_show(const char * const msg, ...) va_end(args); } +void cons_show_padded(int pad, const char * const msg, ...) {} + void cons_show_help(Command *command) {} void cons_about(void) {} @@ -549,7 +551,7 @@ void win_show_occupant(ProfWin *window, Occupant *occupant) {} void win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occupant) {} void win_show_contact(ProfWin *window, PContact contact) {} void win_show_info(ProfWin *window, PContact contact) {} -void win_println(ProfWin *window, const char * const message) {} +void win_println(ProfWin *window, int pad, const char * const message) {} // desktop notifier actions void notifier_uninit(void) {} From 41c93c33502e92583100010b2ca6cb61d1323cff Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 30 Jul 2015 01:31:11 +0100 Subject: [PATCH 25/25] Handle larger than line words in wrapping --- src/ui/window.c | 62 +++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/src/ui/window.c b/src/ui/window.c index daf701bb..95e89849 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1085,6 +1085,7 @@ _win_print_wrapped(WINDOW *win, const char * const message, size_t indent, int p // handle word } else { wordi = 0; + int wordlen = 0; while (*curr_ch != ' ' && *curr_ch != '\n' && *curr_ch != '\0') { size_t ch_len = mbrlen(curr_ch, 4, NULL); int offset = 0; @@ -1094,21 +1095,44 @@ _win_print_wrapped(WINDOW *win, const char * const message, size_t indent, int p curr_ch = g_utf8_next_char(curr_ch); } word[wordi] = '\0'; + wordlen = utf8_display_len(word); int curx = getcurx(win); int cury = getcury(win); int maxx = getmaxx(win); - gboolean firstline = (cury == starty); - // word larger than line - if ((firstline && (utf8_display_len(word) > (maxx - indent))) || - (!firstline && (utf8_display_len(word) > (maxx - (indent + pad_indent))))) { + // wrap required + if (curx + wordlen > maxx) { + int linelen = maxx - (indent + pad_indent); - gchar *word_ch = g_utf8_offset_to_pointer(word, 0); - while(*word_ch != '\0') { + // word larger than line + if (wordlen > linelen) { + gchar *word_ch = g_utf8_offset_to_pointer(word, 0); + while(*word_ch != '\0') { + curx = getcurx(win); + cury = getcury(win); + gboolean firstline = cury == starty; + + if (firstline && curx < indent) { + _win_indent(win, indent); + } + if (!firstline && curx < (indent + pad_indent)) { + _win_indent(win, indent + pad_indent); + } + + gchar copy[wordi+1]; + g_utf8_strncpy(copy, word_ch, 1); + waddstr(win, copy); + + word_ch = g_utf8_next_char(word_ch); + } + + // newline and print word + } else { + waddch(win, '\n'); curx = getcurx(win); cury = getcury(win); - firstline = cury == starty; + gboolean firstline = cury == starty; if (firstline && curx < indent) { _win_indent(win, indent); @@ -1116,30 +1140,22 @@ _win_print_wrapped(WINDOW *win, const char * const message, size_t indent, int p if (!firstline && curx < (indent + pad_indent)) { _win_indent(win, indent + pad_indent); } - - gchar copy[wordi++]; - g_utf8_strncpy(copy, word_ch, 1); - - if (curx + utf8_display_len(copy) > maxx) { - waddch(win, '\n'); - _win_indent(win, indent + pad_indent); - } - waddstr(win, copy); - - word_ch = g_utf8_next_char(word_ch); + waddstr(win, word); } + + // no wrap required } else { - if (curx + utf8_display_len(word) > maxx) { - waddch(win, '\n'); - _win_indent(win, indent + pad_indent); - } + curx = getcurx(win); + cury = getcury(win); + gboolean firstline = cury == starty; + if (firstline && curx < indent) { _win_indent(win, indent); } if (!firstline && curx < (indent + pad_indent)) { _win_indent(win, indent + pad_indent); } - wprintw(win, "%s", word); + waddstr(win, word); } }