diff --git a/Makefile.am b/Makefile.am index 4a0d9dea..72edcd2f 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/command/command.c b/src/command/command.c index 9d33f61b..182dcc70 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -101,1091 +101,1516 @@ 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_CHAT "chat" +#define CMD_TAG_GROUPCHAT "groupchat" +#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 }, +#define CMD_TAGS(...) { { __VA_ARGS__, 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 } } + /* * Command list */ 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 } } }, + cmd_help, parse_args, 0, 2, NULL, + CMD_NOTAGS + 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'." }) + CMD_EXAMPLES( + "/help commands", + "/help presence", + "/help who") + }, { "/about", cmd_about, parse_args, 0, 0, NULL, - { "/about", "About Profanity.", - { "/about", - "------", - "Show version and license information.", - NULL } } }, + CMD_NOTAGS + CMD_SYN( + "/about") + CMD_DESC( + "Show version and license information.") + CMD_NOARGS + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_CONNECTION) + CMD_SYN( + "/connect []", + "/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.") + 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)." }) + 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") + }, { "/disconnect", cmd_disconnect, parse_args, 0, 0, NULL, - { "/disconnect", "Logout of current session.", - { "/disconnect", - "-----------", - "Disconnect from the current chat service.", - NULL } } }, + CMD_TAGS( + CMD_TAG_CONNECTION) + 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, - { "/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 } } }, + CMD_TAGS( + CMD_TAG_CHAT) + CMD_SYN( + "/msg []", + "/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.") + 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." }) + 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?") + }, { "/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.", - "", - "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 } } }, + CMD_TAGS( + CMD_TAG_ROSTER, + CMD_TAG_UI) + CMD_SYN( + "/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 ") + 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." }, + { "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." }) + 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") + }, { "/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.", - "", - "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 } } }, + CMD_TAGS( + CMD_TAG_ROSTER, + CMD_TAG_UI) + CMD_SYN( + "/group", + "/group show ", + "/group add " + "/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." }) + CMD_EXAMPLES( + "/group", + "/group show friends", + "/group add friends newfriend@server.org", + "/group add family Brother", + "/group remove colleagues boss@work.com") + }, { "/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.", - "Passing no argument in a chat room will display information about the room.", - "", - "Example: /info mybuddy@chat.server.org", - "Example: /info kai", - NULL } } }, + CMD_TAGS( + CMD_TAG_ROSTER, + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) + CMD_SYN( + "/info", + "/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." }) + CMD_EXAMPLES( + "/info mybuddy@chat.server.org", + "/info kai") + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_DISCOVERY, + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) + CMD_SYN( + "/caps", + "/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.") + 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." }) + CMD_EXAMPLES( + "/caps mybuddy@chat.server.org/laptop", + "/caps mybuddy@chat.server.org/phone", + "/caps bruce") + }, { "/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.", - "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 } } }, + CMD_TAGS( + CMD_TAG_DISCOVERY, + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) + CMD_SYN( + "/software", + "/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." }) + CMD_EXAMPLES( + "/software mybuddy@chat.server.org/laptop", + "/software mybuddy@chat.server.org/phone", + "/software bruce") + }, { "/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.", - "", - "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 } } }, + CMD_TAGS( + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) + CMD_SYN( + "/status", + "/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." }) + CMD_EXAMPLES( + "/status buddy@server.com", + "/status jon") + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_CHAT, + CMD_TAG_UI) + CMD_SYN( + "/resource set ", + "/resource off", + "/resource title on|off", + "/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." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_GROUPCHAT) + CMD_SYN( + "/join", + "/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.") + CMD_ARGS( + { "", "The chat room to join." }, + { "nick ", "Nickname to use in the room." }, + { "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") + }, { "/leave", cmd_leave, parse_args, 0, 0, NULL, - { "/leave", "Leave a chat room.", - { "/leave", - "------", - "Leave the current chat room.", - NULL } } }, + CMD_TAGS( + CMD_TAG_GROUPCHAT) + 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 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 } } }, + CMD_TAGS( + CMD_TAG_GROUPCHAT) + 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." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_GROUPCHAT) + 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 room", "Decline a chat room invite.", - { "/decline room", - "-------------", - "Decline a chat room invitation.", - "", - "room : The room for the invite you wish to decline.", - NULL } } }, + CMD_TAGS( + CMD_TAG_GROUPCHAT) + 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", "Room configuration.", - { "/room accept|destroy|config", - "---------------------------", - "Chat room configuration.", - "", - "accept : Accept default room configuration.", - "destroy : Reject default room configuration.", - "config : Edit room configuration.", - NULL } } }, + CMD_TAGS( + CMD_TAG_GROUPCHAT) + 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." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_GROUPCHAT) + 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." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_GROUPCHAT) + 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." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_GROUPCHAT) + CMD_SYN( + "/subject set ", + "/subject clear") + CMD_DESC( + "Set or clear room subject.") + CMD_ARGS( + { "set ", "Set the room subject." }, + { "clear", "Clear the room subject." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_GROUPCHAT) + CMD_SYN( + "/affiliation set []", + "/list []") + CMD_DESC( + "Manage room affiliations. " + "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." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_GROUPCHAT) + CMD_SYN( + "/role set []", + "/list []") + CMD_DESC( + "Manage room roles. " + "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." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_GROUPCHAT, + CMD_TAG_UI) + CMD_SYN( + "/occupants show|hide [jid]", + "/occupants default show|hide [jid]", + "/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)." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_GROUPCHAT) + CMD_SYN( + "/form show", + "/form submit", + "/form cancel", + "/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." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_GROUPCHAT) + 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.") + CMD_ARGS( + { "", "The conference service to query." }) + CMD_EXAMPLES( + "/rooms conference.jabber.org") + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_GROUPCHAT) + CMD_SYN( + "/bookmark", + "/bookmark list", + "/bookmark add [nick ] [password ] [autojoin on|off]", + "/bookmark update [nick ] [password ] [autojoin on|off]", + "/bookmark remove ", + "/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\".") + CMD_ARGS( + { "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." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_DISCOVERY) + CMD_SYN( + "/disco info []", + "/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.") + CMD_ARGS( + { "info []", "List protocols and features supported by an entity." }, + { "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") + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_GROUPCHAT) + 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 num", "View a window.", - { "/win num", - "--------", - "Show the contents of a specific window in the main window area.", - "", - "num - Window number to display.", - NULL } } }, + CMD_TAGS( + CMD_TAG_UI) + 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, - { "/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 } } }, + CMD_TAGS( + CMD_TAG_UI) + CMD_SYN( + "/wins tidy", + "/wins prune", + "/wins swap ") + CMD_DESC( + "Manage windows. " + "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." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_ROSTER) + CMD_SYN( + "/sub request []", + "/sub allow []", + "/sub deny []", + "/sub show []", + "/sub sent", + "/sub received") + CMD_DESC( + "Manage subscriptions to contact presence. " + "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." }) + CMD_EXAMPLES( + "/sub request myfriend@jabber.org", + "/sub allow myfriend@jabber.org", + "/sub request", + "/sub sent") + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) + 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, - { "/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 } } }, + CMD_TAGS( + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT, + CMD_TAG_ROSTER) + CMD_SYN( + "/who", + "/who online|offline|away|dnd|xa|chat|available|unavailable|any []", + "/who moderator|participant|visitor", + "/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." }, + { "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." }) + CMD_EXAMPLES( + "/who", + "/who xa", + "/who online friends", + "/who any family", + "/who participant", + "/who admin") + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_UI) + CMD_SYN( + "/close []", + "/close all|read") + CMD_DESC( + "Close windows. " + "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." }) + CMD_NOEXAMPLES + }, { "/clear", cmd_clear, parse_args, 0, 0, NULL, - { "/clear", "Clear current window.", - { "/clear", - "------", - "Clear the current window.", - NULL } } }, + CMD_TAGS( + CMD_TAG_UI) + CMD_SYN( + "/clear") + CMD_DESC( + "Clear the current window.") + CMD_NOARGS + CMD_NOEXAMPLES + }, { "/quit", cmd_quit, parse_args, 0, 0, NULL, - { "/quit", "Quit Profanity.", - { "/quit", - "-----", - "Logout of any current session, and quit Profanity.", - NULL } } }, + CMD_NOTAGS + 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", "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 } } }, + CMD_TAGS( + CMD_TAG_GROUPCHAT, + CMD_TAG_UI) + 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", "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 } } }, + CMD_TAGS( + CMD_TAG_UI) + 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.") + CMD_ARGS( + { "on|off", "Enable or disable terminal bell." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_CHAT, + CMD_TAG_UI) + 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", "Show the contacts presence in the titlebar.", - { "/presence on|off", - "----------------", - "Switch display of the contacts presence in the titlebar on or off.", - NULL } } }, + CMD_TAGS( + CMD_TAG_UI, + CMD_TAG_CHAT) + 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", "Word wrapping.", - { "/wrap on|off", - "------------", - "Enable or disable word wrapping in the main window.", - NULL } } }, + CMD_TAGS( + CMD_TAG_UI) + 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", "Auto tidy windows.", - { "/winstidy on|off", - "----------------", - "Enable or disable auto window tidy.", - NULL } } }, + CMD_TAGS( + CMD_TAG_UI) + 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, - { "/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 } } }, + CMD_TAGS( + CMD_TAG_UI) + CMD_SYN( + "/time main set ", + "/time main off", + "/time statusbar set ", + "/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.") + 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." }) + CMD_EXAMPLES( + "/time main set \"%d-%m-%y %H:%M\"", + "/time main off", + "/time statusbar set %H:%M") + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_UI) + CMD_SYN( + "/inpblock timeout ", + "/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." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_UI, + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) + CMD_SYN( + "/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") + 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." }, + { "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." }) + CMD_EXAMPLES( + "/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") + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_UI) + 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.") + CMD_ARGS( + { "on|off", "Enable or disable terminal flash." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_UI, + CMD_TAG_CHAT) + 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", "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 } } }, + CMD_TAGS( + CMD_TAG_UI) + 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, - { "/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 } } }, + CMD_TAGS( + CMD_TAG_CONNECTION) + CMD_SYN( + "/autoconnect set ", + "/autoconnect off") + CMD_DESC( + "Enable or disable autoconnect on start up. " + "The setting can be overridden by the -a (--account) command line option.") + CMD_ARGS( + { "set ", "Connect with account on start up." }, + { "off", "Disable autoconnect." }) + CMD_EXAMPLES( + "/autoconnect set jc@stuntteam.org", + "/autoconnect off") + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_UI) + 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, - { "/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 } } }, + CMD_TAGS( + CMD_TAG_UI) + CMD_SYN( + "/titlebar show on|off", + "/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." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_NOTAGS + CMD_SYN( + "/alias list", + "/alias add ", + "/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." }) + 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") + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_CHAT) + 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.") + CMD_ARGS( + { "on|off", "Enable or disable chat logging." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_GROUPCHAT) + 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.") + 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", "Send chat states during a chat session.", - { "/states on|off", - "--------------", - "Send chat state notifications during chat sessions.", - NULL } } }, + CMD_TAGS( + CMD_TAG_CHAT) + 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, - { "/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 } } }, + CMD_TAGS( + CMD_TAG_CHAT) + CMD_SYN( + "/pgp libver", + "/pgp keys", + "/pgp fps", + "/pgp setkey ", + "/pgp start []", + "/pgp end", + "/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.") + CMD_ARGS( + { "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." }) + CMD_EXAMPLES( + "/pgp log off", + "/pgp setkey buddy@buddychat.org BA19CACE5A9592C5", + "/pgp start buddy@buddychat.org", + "/pgp end") + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_CHAT) + CMD_SYN( + "/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") + 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." }, + { "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." }) + CMD_EXAMPLES( + "/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") + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_CHAT) + 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 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 } } }, + CMD_TAGS( + CMD_TAG_CHAT) + 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.") + 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", "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 } } }, + CMD_TAGS( + CMD_TAG_UI, + CMD_TAG_CHAT) + 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.") + CMD_ARGS( + { "on|off", "Enable or disable showing chat history." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_NOTAGS + CMD_SYN( + "/log where", + "/log rotate on|off", + "/log maxsize ", + "/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." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + cmd_carbons, parse_args, 1, 1, &cons_carbons_setting, + CMD_TAGS( + CMD_TAG_CHAT) + 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.") + CMD_ARGS( + { "on|off", "Enable or disable message carbons." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + cmd_receipts, parse_args, 2, 2, &cons_receipts_setting, + CMD_TAGS( + CMD_TAG_CHAT) + CMD_SYN( + "/receipts request on|off", + "/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." }) + CMD_NOEXAMPLES + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_CONNECTION) + 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 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 } } }, + CMD_TAGS( + CMD_TAG_CONNECTION) + 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 [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 } } }, + CMD_TAGS( + CMD_TAG_CONNECTION) + 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.") + 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, - { "/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 } } }, + CMD_TAGS( + CMD_TAG_PRESENCE) + CMD_SYN( + "/autoaway mode idle|away|off", + "/autoaway time ", + "/autoaway message |off", + "/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." }) + CMD_EXAMPLES( + "/autoaway mode idle", + "/autoaway time 30", + "/autoaway message I'm not really doing much", + "/autoaway check off") + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_PRESENCE) + CMD_SYN( + "/priority ") + CMD_DESC( + "Set priority for the current account. " + "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, - { "/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 } } }, + CMD_TAGS( + CMD_TAG_CONNECTION + CMD_TAG_PRESENCE, + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) + CMD_SYN( + "/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") + CMD_DESC( + "Commands for creating and managing accounts. " + "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." }, + { "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." }) + CMD_EXAMPLES( + "/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") + }, { "/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 } } }, + CMD_NOTAGS + CMD_SYN( + "/prefs [ui|desktop|chat|log|conn|presence]") + CMD_DESC( + "Show preferences for different areas of functionality. " + "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." }) + CMD_NOEXAMPLES + }, { "/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 } } }, - + CMD_TAGS( + CMD_TAG_UI) + CMD_SYN( + "/theme list", + "/theme load ", + "/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." }) + CMD_EXAMPLES( + "/theme list", + "/theme load forest") + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_UI, + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) + 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.") + 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." }) + CMD_EXAMPLES( + "/statuses console none", + "/statuses chat online", + "/statuses muc all") + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_UI) + 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 [message]", "Set status to away.", - { "/away [message]", - "---------------", - "Set your status to 'away' with the optional message.", - "", - "Example: /away Gone for lunch", - NULL } } }, + CMD_TAGS( + CMD_TAG_PRESENCE) + 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") + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_PRESENCE) + 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!") + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_PRESENCE) + 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") + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_PRESENCE) + 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!") + }, { "/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 } } }, + CMD_TAGS( + CMD_TAG_PRESENCE) + 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") + }, }; 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; @@ -1253,13 +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, "navigation"); // load command defs into hash table @@ -1290,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"); @@ -1630,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); @@ -1798,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); @@ -1886,6 +2315,31 @@ cmd_reset_autocomplete(ProfWin *window) bookmark_autocomplete_reset(); } +gboolean +cmd_valid_tag(const char * const str) +{ + return ((g_strcmp0(str, CMD_TAG_CHAT) == 0) || + (g_strcmp0(str, CMD_TAG_GROUPCHAT) == 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 +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 @@ -1953,10 +2407,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, command, args); g_strfreev(args); return result; } @@ -2045,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); @@ -2056,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); @@ -3028,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) { @@ -3154,19 +3627,57 @@ command_docgen(void) 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); - fputs("

Details:

\n", main_fragment); + fputs("

Synopsis

\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++]);
+        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
back to top


\n", main_fragment); + 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); curr = g_list_next(curr); @@ -3176,5 +3687,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/command.h b/src/command/command.h index e6fc7ead..78b4bf78 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_valid_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 810772d5..ede1b395 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -73,12 +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 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); +//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); extern GHashTable *commands; @@ -158,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, 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)) { @@ -171,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; } @@ -262,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, const char * const command, gchar **args) { - 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) { @@ -292,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)){ @@ -320,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."); @@ -333,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."); @@ -346,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]; @@ -361,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); @@ -376,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){ @@ -387,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]; @@ -537,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]; @@ -579,6 +578,7 @@ cmd_account(ProfWin *window, gchar **args, struct cmd_help_t help) } } } else { + cons_bad_cmd_usage(command); cons_show(""); } @@ -586,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -600,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; } @@ -667,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); @@ -676,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, 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, struct cmd_help_t help) } gboolean -cmd_quit(ProfWin *window, gchar **args, struct cmd_help_t help) +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, struct cmd_help_t help) } gboolean -cmd_wins(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_wins(ProfWin *window, const char * const command, gchar **args) { if (args[0] == NULL) { cons_show_wins(); @@ -720,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]); @@ -739,15 +739,17 @@ cmd_wins(ProfWin *window, gchar **args, struct cmd_help_t help) cons_show("Same source and target window supplied."); } } + } else { + cons_bad_cmd_usage(command); } return TRUE; } gboolean -cmd_winstidy(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_winstidy(ProfWin *window, const char * const command, gchar **args) { - 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(); @@ -757,7 +759,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, const char * const command, gchar **args) { int num = atoi(args[0]); @@ -771,80 +773,84 @@ cmd_win(ProfWin *window, gchar **args, struct cmd_help_t help) return TRUE; } +static void +_cmd_help_cmd_list(const char * const tag) +{ + cons_show(""); + ProfWin *console = wins_get_console(); + if (tag) { + win_vprint(console, '-', 0, NULL, 0, THEME_WHITE_BOLD, "", "%s commands", tag); + } else { + win_print(console, '-', 0, 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, gchar **args, struct cmd_help_t help) +cmd_help(ProfWin *window, const char * const command, gchar **args) { int num_args = g_strv_length(args); if (num_args == 0) { cons_help(); } else if (strcmp(args[0], "commands") == 0) { - cons_show(""); - cons_show("All commands"); - cons_show(""); - - 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)) { - ordered_commands = g_list_insert_sorted(ordered_commands, value, (GCompareFunc)_compare_commands); + if (args[1]) { + if (!cmd_valid_tag(args[1])) { + cons_bad_cmd_usage(command); + } else { + _cmd_help_cmd_list(args[1]); + } + } else { + _cmd_help_cmd_list(NULL); } - - GList *curr = ordered_commands; - while (curr) { - Command *cmd = curr->data; - cons_show("%-12s: %s", cmd->cmd, cmd->help.short_help); - curr = g_list_next(curr); - } - 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], "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 (strcmp(args[0], "navigation") == 0) { cons_navigation_help(); } else { @@ -852,21 +858,12 @@ 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; - } - - cons_show(""); - if (help_text) { - ProfWin *console = wins_get_console(); - ui_show_lines(console, help_text); + cons_show_help(command); } else { cons_show("No such command."); } - cons_show(""); } @@ -874,14 +871,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, const char * const command, gchar **args) { ui_about(); return TRUE; } gboolean -cmd_prefs(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_prefs(ProfWin *window, const char * const command, gchar **args) { if (args[0] == NULL) { cons_prefs(); @@ -919,14 +916,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, const char * const command, gchar **args) { // list themes if (g_strcmp0(args[0], "list") == 0) { @@ -937,7 +934,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]); @@ -961,14 +958,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, const char * const command, gchar **args) { if ((g_strv_length(args) == 2) && args[1]) { cons_show("Argument group is not applicable to chat rooms."); @@ -992,7 +989,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; } @@ -1098,7 +1095,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, const char * const command, gchar **args) { char *presence = args[0]; @@ -1113,7 +1110,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; } @@ -1311,16 +1308,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, 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, help); + _who_room(window, command, args); } else { - _who_roster(window, args, help); + _who_roster(window, command, args); } if (window->type != WIN_CONSOLE && window->type != WIN_MUC) { @@ -1331,7 +1328,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, const char * const command, gchar **args) { char *usr = args[0]; char *msg = args[1]; @@ -1398,7 +1395,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -1429,7 +1426,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; } @@ -1444,7 +1441,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; } @@ -1475,7 +1472,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; } @@ -1500,12 +1497,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -1536,7 +1533,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; @@ -1586,7 +1583,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) { @@ -1619,7 +1616,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 @@ -1646,7 +1643,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 @@ -1657,7 +1654,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); @@ -1672,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 { roster_send_remove(jid); } @@ -1680,7 +1677,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) { @@ -1707,13 +1704,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; } @@ -1741,7 +1738,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; } @@ -1761,31 +1758,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, const char * const command, gchar **args) { 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); } } @@ -1798,7 +1795,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; } @@ -1833,13 +1830,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, const char * const command, gchar **args) { char *usr = args[0]; @@ -1860,7 +1857,7 @@ cmd_status(ProfWin *window, gchar **args, struct cmd_help_t help) 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."); @@ -1876,7 +1873,7 @@ cmd_status(ProfWin *window, gchar **args, struct cmd_help_t help) if (pcontact) { win_show_contact(window, pcontact); } else { - win_println(window, "Error getting contact info."); + win_println(window, 0, "Error getting contact info."); } } break; @@ -1891,7 +1888,7 @@ cmd_status(ProfWin *window, gchar **args, struct cmd_help_t help) 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); } @@ -1904,7 +1901,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: @@ -1915,7 +1912,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, const char * const command, gchar **args) { char *usr = args[0]; @@ -1957,7 +1954,7 @@ cmd_info(ProfWin *window, gchar **args, struct cmd_help_t help) if (pcontact) { win_show_info(window, pcontact); } else { - win_println(window, "Error getting contact info."); + win_println(window, 0, "Error getting contact info."); } } break; @@ -1972,7 +1969,7 @@ cmd_info(ProfWin *window, gchar **args, struct cmd_help_t help) 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); } @@ -1990,7 +1987,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: @@ -2001,7 +1998,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); PContact pcontact = NULL; @@ -2078,7 +2075,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); Occupant *occupant = NULL; @@ -2142,7 +2139,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); if (conn_status != JABBER_CONNECTED) { @@ -2204,7 +2201,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; @@ -2240,7 +2237,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, const char * const command, gchar **args) { char *contact = args[0]; char *reason = args[1]; @@ -2276,7 +2273,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, const char * const command, gchar **args) { GSList *invites = muc_invites(); cons_show_room_invites(invites); @@ -2285,7 +2282,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, const char * const command, gchar **args) { if (!muc_invites_contain(args[0])) { cons_show("No such invite exists."); @@ -2516,7 +2513,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2534,7 +2531,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; } @@ -2557,7 +2554,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); @@ -2590,7 +2587,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2613,17 +2610,17 @@ cmd_kick(ProfWin *window, gchar **args, struct cmd_help_t help) 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_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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2645,13 +2642,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2671,10 +2668,10 @@ cmd_subject(ProfWin *window, gchar **args, struct cmd_help_t help) 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; } @@ -2683,7 +2680,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; } @@ -2693,12 +2690,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2714,7 +2711,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; } @@ -2725,7 +2722,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; } @@ -2739,7 +2736,7 @@ cmd_affiliation(ProfWin *window, gchar **args, struct cmd_help_t help) 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); } @@ -2748,13 +2745,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]; @@ -2763,12 +2760,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2784,7 +2781,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; } @@ -2794,7 +2791,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; } @@ -2807,7 +2804,7 @@ cmd_role(ProfWin *window, gchar **args, struct cmd_help_t help) 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); } @@ -2816,13 +2813,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]; @@ -2831,12 +2828,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2853,7 +2850,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; } @@ -2869,12 +2866,12 @@ cmd_room(ProfWin *window, gchar **args, struct cmd_help_t help) 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; } } @@ -2899,7 +2896,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -2910,7 +2907,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; @@ -2949,7 +2946,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; } } @@ -2977,14 +2974,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -3005,7 +3002,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -3031,7 +3028,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; } @@ -3041,7 +3038,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; } @@ -3069,7 +3066,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; } @@ -3080,7 +3077,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; } @@ -3105,7 +3102,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); @@ -3116,7 +3113,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -3146,7 +3143,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -3168,14 +3165,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, const char * const command, gchar **args) { 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; @@ -3190,7 +3187,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)) { @@ -3209,7 +3206,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] == '/') { @@ -3234,13 +3231,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, const char * const command, gchar **args) { char *url = args[0]; @@ -3250,13 +3247,13 @@ cmd_tiny(ProfWin *window, gchar **args, struct cmd_help_t help) } 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; } @@ -3292,14 +3289,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, const char * const command, gchar **args) { ui_clear_win(window); return TRUE; } gboolean -cmd_close(ProfWin *window, gchar **args, struct cmd_help_t help) +cmd_close(ProfWin *window, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); int index = 0; @@ -3371,7 +3368,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); int index = wins_get_current_num(); @@ -3394,9 +3391,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, const char * const command, gchar **args) { - 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(); @@ -3404,21 +3401,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, const char * const command, gchar **args) { - 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, const char * const command, gchar **args) { - 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, const char * const command, gchar **args) { - 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(); @@ -3426,7 +3423,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, const char * const command, gchar **args) { if (g_strcmp0(args[0], "statusbar") == 0) { if (args[1] == NULL) { @@ -3443,7 +3440,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) { @@ -3461,19 +3458,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, const char * const command, gchar **args) { - 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 @@ -3486,26 +3483,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, const char * const command, gchar **args) { 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, const char * const command, gchar **args) { - 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 @@ -3517,7 +3514,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, const char * const command, gchar **args) { char *value = args[0]; @@ -3541,7 +3538,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, const char * const command, gchar **args) { char *kind = args[0]; @@ -3549,7 +3546,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) { @@ -3684,14 +3681,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, const char * const command, gchar **args) { 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; } @@ -3712,7 +3709,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; } @@ -3721,23 +3718,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, const char * const command, gchar **args) { 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; } @@ -3756,18 +3753,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; } @@ -3778,7 +3775,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 */ @@ -3786,7 +3783,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, const char * const command, gchar **args) { char *value = args[0]; @@ -3802,7 +3799,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); } @@ -3810,7 +3807,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, const char * const command, gchar **args) { char *value = args[0]; @@ -3827,7 +3824,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); } @@ -3835,7 +3832,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -3855,7 +3852,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, const char * const command, gchar **args) { char *setting = args[0]; char *value = args[1]; @@ -3906,15 +3903,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, const char * const command, gchar **args) { jabber_conn_status_t conn_status = jabber_get_connection_status(); @@ -3942,19 +3938,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, const char * const command, gchar **args) { 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; } @@ -3995,7 +3991,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, const char * const command, gchar **args) { int num_args = g_strv_length(args); @@ -4003,13 +3999,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, const char * const command, gchar **args) { if (!ui_xmlconsole_exists()) { ui_create_xmlconsole_win(); @@ -4021,28 +4016,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, const char * const command, gchar **args) { - 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, const char * const command, gchar **args) { - 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, const char * const command, gchar **args) { - 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, const char * const command, gchar **args) { if (strcmp(args[0], "off") == 0) { prefs_set_string(PREF_CONNECT_ACCOUNT, NULL); @@ -4051,16 +4043,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, const char * const command, gchar **args) { - 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)) { @@ -4071,19 +4062,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, const char * const command, gchar **args) { - 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, const char * const command, gchar **args) { - 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)) { @@ -4094,10 +4083,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, const char * const command, gchar **args) { - 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(); @@ -4115,61 +4103,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, const char * const command, gchar **args) { 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, const char * const command, gchar **args) { _update_presence(RESOURCE_AWAY, "away", args); return TRUE; } gboolean -cmd_online(ProfWin *window, gchar **args, struct cmd_help_t help) +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, struct cmd_help_t help) +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, struct cmd_help_t help) +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, struct cmd_help_t help) +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, struct cmd_help_t help) +cmd_pgp(ProfWin *window, const char * const command, gchar **args) { #ifdef HAVE_LIBGPGME if (args[0] == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -4191,7 +4177,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; } @@ -4225,13 +4211,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; } @@ -4367,7 +4353,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"); @@ -4377,11 +4363,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, const char * const command, gchar **args) { #ifdef HAVE_LIBOTR if (args[0] == NULL) { - cons_show("Usage: %s", help.usage); + cons_bad_cmd_usage(command); return TRUE; } @@ -4403,7 +4389,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; @@ -4622,7 +4608,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; } @@ -4633,7 +4619,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; } @@ -4667,7 +4653,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; } @@ -4675,7 +4661,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 @@ -4685,9 +4671,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, const char * const command, gchar **args) { - 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 @@ -4713,7 +4699,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); @@ -4723,9 +4709,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); @@ -4733,9 +4717,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); @@ -4744,47 +4726,50 @@ _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, return TRUE; } -static void -_cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size) -{ - cons_show(""); - cons_show("%s", heading); - cons_show(""); - - 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); - } - - GList *curr = ordered_commands; - while (curr) { - Command *cmd = curr->data; - cons_show("%-12s: %s", cmd->cmd, cmd->help.short_help); - curr = g_list_next(curr); - } - 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 -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; -} +//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 0b135d71..c158f606 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -35,13 +35,15 @@ #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 *tags[20]; + const gchar *synopsis[50]; + const gchar *desc; + const gchar *args[50][2]; + const gchar *examples[10]; } CommandHelp; /* @@ -56,7 +58,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, const char * const command, gchar **args); gchar** (*parser)(const char * const inp, int min, int max, gboolean *result); int min_args; int max_args; @@ -67,85 +69,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, 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); 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/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/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 98691a0a..27b1b81d 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 @@ -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,11 +100,79 @@ 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); +} + +void +cons_show_help(Command *command) +{ + ProfWin *console = wins_get_console(); + + cons_show(""); + 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, '-', 0, NULL, NO_EOL | NO_DATE, THEME_WHITE_BOLD, "", "-"); + } + win_print(console, '-', 0, NULL, NO_DATE, THEME_WHITE_BOLD, "", ""); + cons_show(""); + + win_print(console, '-', 0, NULL, 0, THEME_WHITE_BOLD, "", "Synopsis"); + ui_show_lines(console, command->help.synopsis); + cons_show(""); + + win_print(console, '-', 0, NULL, 0, THEME_WHITE_BOLD, "", "Description"); + win_println(console, 0, command->help.desc); + + 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(""); + win_print(console, '-', 0, NULL, 0, THEME_WHITE_BOLD, "", "Arguments"); + for (i = 0; command->help.args[i][0] != NULL; i++) { + 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, '-', 0, NULL, 0, THEME_WHITE_BOLD, "", "Examples"); + ui_show_lines(console, command->help.examples); + } +} + +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, ...) { @@ -113,7 +181,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); @@ -136,7 +204,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(); } @@ -149,7 +217,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(); } @@ -167,23 +235,23 @@ 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_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_vprint(console, '-', 0, NULL, 0, 0, "", "Copyright (C) 2012 - 2015 James Booth <%s>.", PACKAGE_BUGREPORT); + 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); @@ -205,13 +273,13 @@ 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_println(console, "Check for details."); - win_println(console, ""); + win_vprint(console, '-', 0, NULL, 0, 0, "", "A new version of Profanity is available: %s", latest_release); + 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, ""); } } @@ -225,16 +293,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(); } @@ -248,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); @@ -294,53 +362,53 @@ 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); } if (caps->features) { - win_println(console, "Features:"); + win_println(console, 0, "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); } } @@ -361,8 +429,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); @@ -426,9 +494,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); @@ -460,21 +528,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); @@ -535,11 +603,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 { @@ -614,7 +682,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]); } @@ -725,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) { @@ -743,12 +811,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); @@ -756,38 +824,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); @@ -1476,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 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 navigation - How to navigate around Profanity."); - cons_show("/help [command] - Detailed help on a specific command."); + 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(); @@ -1497,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(""); - cons_show("Navigation:"); - cons_show(""); - 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."); + win_print(console, '-', 0, NULL, 0, THEME_WHITE_BOLD, "", "Navigation"); + 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(); @@ -1604,22 +1675,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(""); } @@ -1627,25 +1698,25 @@ 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, '-', 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); } } @@ -1672,11 +1743,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)) { @@ -1692,9 +1763,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); @@ -1710,10 +1781,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 5f85a3cd..bbaebe31 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; } } @@ -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 @@ -893,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)) { @@ -922,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(); } @@ -934,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); } } @@ -943,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 '."); } } @@ -954,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); } } @@ -963,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); } } @@ -972,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."); } } @@ -981,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."); } } @@ -990,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); } } @@ -999,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); } } @@ -1008,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); } } @@ -1017,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); } } @@ -1026,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); } @@ -1041,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(); } @@ -1057,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(); } @@ -1147,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); } @@ -1160,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); } @@ -1168,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 @@ -1198,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 @@ -1230,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); } } } @@ -1285,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); } } @@ -1303,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); @@ -1312,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 @@ -1324,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) { @@ -1345,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); } } @@ -1361,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 @@ -1376,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 @@ -1391,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, "", ""); } @@ -1407,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 @@ -1422,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 @@ -1437,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 @@ -1452,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, "", ""); } } @@ -1465,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 @@ -1481,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, "", ""); } } } @@ -1507,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) { @@ -1524,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, "", ""); } } @@ -1551,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); } } @@ -1574,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); } } @@ -1598,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); } } @@ -1611,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, "", ""); } } @@ -1644,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); } } @@ -1655,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); } } @@ -1680,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); } } @@ -1701,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 @@ -1782,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)) { @@ -1840,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); } } } @@ -1877,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); } } @@ -1904,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); } } @@ -1920,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"); } } @@ -1952,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); } } @@ -1965,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)) { @@ -1985,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); } } @@ -1995,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, "", ""); } } } @@ -2015,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); } } @@ -2025,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, "", ""); } } } @@ -2055,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); } } @@ -2065,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); } } @@ -2234,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 @@ -2249,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; @@ -2281,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, "", ""); } } @@ -2303,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; @@ -2341,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; @@ -2376,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); } } } @@ -2388,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); @@ -2400,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"); } } } @@ -2430,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); } @@ -2446,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); } @@ -2458,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); @@ -2467,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; @@ -2475,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); @@ -2490,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); @@ -2507,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); @@ -2523,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 @@ -2536,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 @@ -2562,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); } @@ -2589,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); @@ -2617,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"); } } @@ -2645,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; @@ -2663,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: @@ -2716,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); } } @@ -2725,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, "", ""); } } @@ -2737,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]); } } } @@ -2805,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 637c8f75..fd81f68a 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" @@ -227,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); @@ -239,8 +240,11 @@ 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); +void cons_bad_cmd_usage(const char * const cmd); void cons_navigation_help(void); void cons_prefs(void); void cons_show_ui_prefs(void); @@ -349,14 +353,14 @@ 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); 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 6c76b5f8..95e89849 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); } @@ -947,19 +947,19 @@ 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, '-', NULL, 0, 0, "", message); + win_print(window, '-', pad, 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,13 +1028,16 @@ _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); } 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) { @@ -1058,24 +1061,31 @@ _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; + int wordlen = 0; while (*curr_ch != ' ' && *curr_ch != '\n' && *curr_ch != '\0') { size_t ch_len = mbrlen(curr_ch, 4, NULL); int offset = 0; @@ -1085,41 +1095,78 @@ _win_print_wrapped(WINDOW *win, const char * const message, size_t indent) 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); - // word larger than line - if (utf8_display_len(word) > (maxx - indent)) { - gchar *word_ch = g_utf8_offset_to_pointer(word, 0); - while(*word_ch != '\0') { - curx = getcurx(win); - if (curx < indent) { - _win_indent(win, indent); + // wrap required + if (curx + wordlen > maxx) { + int linelen = maxx - (indent + pad_indent); + + // 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); } - gchar copy[wordi++]; - g_utf8_strncpy(copy, word_ch, 1); - - if (curx + utf8_display_len(copy) > maxx) { - waddch(win, '\n'); - _win_indent(win, indent); - } - waddstr(win, copy); - - word_ch = g_utf8_next_char(word_ch); - } - } else { - if (curx + utf8_display_len(word) > maxx) { + // newline and print word + } else { waddch(win, '\n'); + 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); + } + waddstr(win, word); + } + + // no wrap required + } else { + curx = getcurx(win); + cury = getcury(win); + gboolean firstline = cury == starty; + + 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); + waddstr(win, 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 +1181,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/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 71a577f5..43fc2954 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -358,6 +358,10 @@ 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) {} void cons_help(void) {} void cons_navigation_help(void) {} @@ -396,6 +400,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) {} @@ -531,8 +541,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; @@ -541,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) {} 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),