diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index e8d0680a..559b3bda 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -1315,7 +1315,7 @@ cmd_ac_add_help(const char* const value)
}
void
-cmd_ac_add_cmd(Command* command)
+cmd_ac_add_cmd(const Command* command)
{
autocomplete_add(commands_ac, command->cmd);
autocomplete_add(help_ac, command->cmd + 1);
diff --git a/src/command/cmd_ac.h b/src/command/cmd_ac.h
index ef715310..ceab49b2 100644
--- a/src/command/cmd_ac.h
+++ b/src/command/cmd_ac.h
@@ -47,7 +47,7 @@ gboolean cmd_ac_exists(char* cmd);
void cmd_ac_add(const char* const value);
void cmd_ac_add_help(const char* const value);
-void cmd_ac_add_cmd(Command* command);
+void cmd_ac_add_cmd(const Command* command);
void cmd_ac_add_alias(ProfAlias* alias);
void cmd_ac_add_alias_value(char* value);
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 83dc1bbf..6b494e1a 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -88,31 +88,14 @@
#define CMD_TAG_UI "ui"
#define CMD_TAG_PLUGINS "plugins"
-#define CMD_MAINFUNC(func) func,
-#define CMD_NOMAINFUNC NULL,
-#define CMD_SUBFUNCS(...) { __VA_ARGS__, { NULL, NULL } },
-#define CMD_NOSUBFUNCS { { NULL, NULL } },
-
-#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 \
- } \
- }
+#define CMD_PREAMBLE(c, p, min, max, set) .cmd = c, .parser = p, .min_args = min, .max_args = max, .setting_func = set,
+#define CMD_MAINFUNC(f) .func = f,
+#define CMD_SUBFUNCS(...) .sub_funcs = { __VA_ARGS__, { NULL, NULL } },
+#define CMD_TAGS(...) .help.tags = { __VA_ARGS__, NULL },
+#define CMD_SYN(...) .help.synopsis = { __VA_ARGS__, NULL },
+#define CMD_DESC(d) .help.desc = d,
+#define CMD_ARGS(...) .help.args = { __VA_ARGS__, { NULL, NULL } },
+#define CMD_EXAMPLES(...) .help.examples = { __VA_ARGS__, NULL }
GHashTable* commands = NULL;
@@ -123,12 +106,10 @@ static gboolean _cmd_has_tag(Command* pcmd, const char* const tag);
*/
// clang-format off
-static struct cmd_t command_defs[] = {
- { "/help",
- parse_args_with_freetext, 0, 2, NULL,
- CMD_NOSUBFUNCS
+static const struct cmd_t command_defs[] = {
+ { CMD_PREAMBLE("/help",
+ parse_args_with_freetext, 0, 2, NULL)
CMD_MAINFUNC(cmd_help)
- CMD_NOTAGS
CMD_SYN(
"/help [||search_all|search_any] []")
CMD_DESC(
@@ -149,22 +130,17 @@ static struct cmd_t command_defs[] = {
"/help who")
},
- { "/about",
- parse_args, 0, 0, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/about",
+ parse_args, 0, 0, NULL)
CMD_MAINFUNC(cmd_about)
- CMD_NOTAGS
CMD_SYN(
"/about")
CMD_DESC(
"Show version and license information.")
- CMD_NOARGS
- CMD_NOEXAMPLES
},
- { "/connect",
- parse_args, 0, 7, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/connect",
+ parse_args, 0, 7, NULL)
CMD_MAINFUNC(cmd_connect)
CMD_TAGS(
CMD_TAG_CONNECTION)
@@ -199,51 +175,48 @@ static struct cmd_t command_defs[] = {
"/connect server.supporting.sasl.anonymous.example")
},
- { "/tls",
- parse_args, 1, 3, NULL,
+ { CMD_PREAMBLE("/tls",
+ parse_args, 1, 3, NULL)
CMD_SUBFUNCS(
{ "certpath", cmd_tls_certpath },
{ "trust", cmd_tls_trust },
{ "trusted", cmd_tls_trusted },
{ "revoke", cmd_tls_revoke },
{ "cert", cmd_tls_cert })
- CMD_NOMAINFUNC
- CMD_TAGS(
- CMD_TAG_CONNECTION,
- CMD_TAG_UI)
- CMD_SYN(
- "/tls allow",
- "/tls always",
- "/tls deny",
- "/tls cert []",
- "/tls trust",
- "/tls trusted",
- "/tls revoke ",
- "/tls certpath",
- "/tls certpath set ",
- "/tls certpath clear",
- "/tls certpath default")
- CMD_DESC(
- "Handle TLS certificates. ")
- CMD_ARGS(
- { "allow", "Allow connection to continue with TLS certificate." },
- { "always", "Always allow connections with TLS certificate." },
- { "deny", "Abort connection." },
- { "cert", "Show the current TLS certificate." },
- { "cert ", "Show details of trusted certificate." },
- { "trust", "Add the current TLS certificate to manually trusted certificates." },
- { "trusted", "List summary of manually trusted certificates (with '/tls always' or '/tls trust')." },
- { "revoke ", "Remove a manually trusted certificate." },
- { "certpath", "Show the trusted certificate path." },
- { "certpath set ", "Specify filesystem path containing trusted certificates." },
- { "certpath clear", "Clear the trusted certificate path." },
- { "certpath default", "Use default system certificate path, if it can be found." })
- CMD_NOEXAMPLES
+ CMD_TAGS(
+ CMD_TAG_CONNECTION,
+ CMD_TAG_UI)
+ CMD_SYN(
+ "/tls allow",
+ "/tls always",
+ "/tls deny",
+ "/tls cert []",
+ "/tls trust",
+ "/tls trusted",
+ "/tls revoke ",
+ "/tls certpath",
+ "/tls certpath set ",
+ "/tls certpath clear",
+ "/tls certpath default")
+ CMD_DESC(
+ "Handle TLS certificates. ")
+ CMD_ARGS(
+ { "allow", "Allow connection to continue with TLS certificate." },
+ { "always", "Always allow connections with TLS certificate." },
+ { "deny", "Abort connection." },
+ { "cert", "Show the current TLS certificate." },
+ { "cert ", "Show details of trusted certificate." },
+ { "trust", "Add the current TLS certificate to manually trusted certificates." },
+ { "trusted", "List summary of manually trusted certificates (with '/tls always' or '/tls trust')." },
+ { "revoke ", "Remove a manually trusted certificate." },
+ { "certpath", "Show the trusted certificate path." },
+ { "certpath set ", "Specify filesystem path containing trusted certificates." },
+ { "certpath clear", "Clear the trusted certificate path." },
+ { "certpath default", "Use default system certificate path, if it can be found." })
},
- { "/disconnect",
- parse_args, 0, 0, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/disconnect",
+ parse_args, 0, 0, NULL)
CMD_MAINFUNC(cmd_disconnect)
CMD_TAGS(
CMD_TAG_CONNECTION)
@@ -251,13 +224,10 @@ static struct cmd_t command_defs[] = {
"/disconnect")
CMD_DESC(
"Disconnect from the current chat service.")
- CMD_NOARGS
- CMD_NOEXAMPLES
},
- { "/msg",
- parse_args_with_freetext, 1, 2, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/msg",
+ parse_args_with_freetext, 1, 2, NULL)
CMD_MAINFUNC(cmd_msg)
CMD_TAGS(
CMD_TAG_CHAT)
@@ -280,8 +250,8 @@ static struct cmd_t command_defs[] = {
"/msg \"My Friend\" Hi, how are you?")
},
- { "/roster",
- parse_args_with_freetext, 0, 4, NULL,
+ { CMD_PREAMBLE("/roster",
+ parse_args_with_freetext, 0, 4, NULL)
CMD_SUBFUNCS(
{ "group", cmd_group })
CMD_MAINFUNC(cmd_roster)
@@ -423,9 +393,8 @@ static struct cmd_t command_defs[] = {
"/roster group remove colleagues boss@work.com")
},
- { "/blocked",
- parse_args_with_freetext, 0, 3, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/blocked",
+ parse_args_with_freetext, 0, 3, NULL)
CMD_MAINFUNC(cmd_blocked)
CMD_TAGS(
CMD_TAG_ROSTER,
@@ -451,9 +420,8 @@ static struct cmd_t command_defs[] = {
"/blocked add profanity@rooms.dismail.de/spammy-user")
},
- { "/info",
- parse_args, 0, 1, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/info",
+ parse_args, 0, 1, NULL)
CMD_MAINFUNC(cmd_info)
CMD_TAGS(
CMD_TAG_ROSTER,
@@ -474,9 +442,8 @@ static struct cmd_t command_defs[] = {
"/info heimdall")
},
- { "/caps",
- parse_args, 0, 1, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/caps",
+ parse_args, 0, 1, NULL)
CMD_MAINFUNC(cmd_caps)
CMD_TAGS(
CMD_TAG_DISCOVERY,
@@ -497,9 +464,8 @@ static struct cmd_t command_defs[] = {
"/caps aegir")
},
- { "/software",
- parse_args, 0, 1, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/software",
+ parse_args, 0, 1, NULL)
CMD_MAINFUNC(cmd_software)
CMD_TAGS(
CMD_TAG_DISCOVERY,
@@ -521,12 +487,11 @@ static struct cmd_t command_defs[] = {
"/software thor")
},
- { "/status",
- parse_args, 2, 3, NULL,
+ { CMD_PREAMBLE("/status",
+ parse_args, 2, 3, NULL)
CMD_SUBFUNCS(
{ "get", cmd_status_get },
{ "set", cmd_status_set })
- CMD_NOMAINFUNC
CMD_TAGS(
CMD_TAG_CHAT,
CMD_TAG_GROUPCHAT)
@@ -547,9 +512,8 @@ static struct cmd_t command_defs[] = {
"/status set online")
},
- { "/resource",
- parse_args, 1, 2, &cons_resource_setting,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/resource",
+ parse_args, 1, 2, &cons_resource_setting)
CMD_MAINFUNC(cmd_resource)
CMD_TAGS(
CMD_TAG_CHAT,
@@ -566,12 +530,10 @@ static struct cmd_t command_defs[] = {
{ "off", "Let the server choose which resource to route messages to." },
{ "title on|off", "Show or hide the current resource in the titlebar." },
{ "message on|off", "Show or hide the resource when showing an incoming message." })
- CMD_NOEXAMPLES
},
- { "/join",
- parse_args, 0, 5, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/join",
+ parse_args, 0, 5, NULL)
CMD_MAINFUNC(cmd_join)
CMD_TAGS(
CMD_TAG_GROUPCHAT)
@@ -598,9 +560,8 @@ static struct cmd_t command_defs[] = {
"/join mychannel")
},
- { "/invite",
- parse_args_with_freetext, 1, 3, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/invite",
+ parse_args_with_freetext, 1, 3, NULL)
CMD_MAINFUNC(cmd_invite)
CMD_TAGS(
CMD_TAG_GROUPCHAT)
@@ -623,9 +584,8 @@ static struct cmd_t command_defs[] = {
"/invite list")
},
- { "/room",
- parse_args, 1, 1, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/room",
+ parse_args, 1, 1, NULL)
CMD_MAINFUNC(cmd_room)
CMD_TAGS(
CMD_TAG_GROUPCHAT)
@@ -637,12 +597,10 @@ static struct cmd_t command_defs[] = {
{ "accept", "Accept default room configuration." },
{ "destroy", "Reject default room configuration, and destroy the room." },
{ "config", "Edit room configuration." })
- CMD_NOEXAMPLES
},
- { "/kick",
- parse_args_with_freetext, 1, 2, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/kick",
+ parse_args_with_freetext, 1, 2, NULL)
CMD_MAINFUNC(cmd_kick)
CMD_TAGS(
CMD_TAG_GROUPCHAT)
@@ -653,11 +611,10 @@ static struct cmd_t command_defs[] = {
CMD_ARGS(
{ "", "Nickname of the occupant to kick from the room." },
{ "", "Optional reason for kicking the occupant." })
- CMD_NOEXAMPLES },
+ },
- { "/ban",
- parse_args_with_freetext, 1, 2, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/ban",
+ parse_args_with_freetext, 1, 2, NULL)
CMD_MAINFUNC(cmd_ban)
CMD_TAGS(
CMD_TAG_GROUPCHAT)
@@ -668,12 +625,10 @@ static struct cmd_t command_defs[] = {
CMD_ARGS(
{ "", "Bare JID of the user to ban from the room." },
{ "", "Optional reason for banning the user." })
- CMD_NOEXAMPLES
},
- { "/subject",
- parse_args_with_freetext, 0, 2, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/subject",
+ parse_args_with_freetext, 0, 2, NULL)
CMD_MAINFUNC(cmd_subject)
CMD_TAGS(
CMD_TAG_GROUPCHAT)
@@ -693,12 +648,10 @@ static struct cmd_t command_defs[] = {
{ "prepend ", "Prepend text to the current room subject, use double quotes if a trailing space is needed." },
{ "append ", "Append text to the current room subject, use double quotes if a preceding space is needed." },
{ "clear", "Clear the room subject." })
- CMD_NOEXAMPLES
},
- { "/affiliation",
- parse_args_with_freetext, 1, 4, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/affiliation",
+ parse_args_with_freetext, 1, 4, NULL)
CMD_MAINFUNC(cmd_affiliation)
CMD_TAGS(
CMD_TAG_GROUPCHAT)
@@ -715,12 +668,10 @@ static struct cmd_t command_defs[] = {
{ "list []", "List all users with the specified affiliation, or all if none specified." },
{ "request", "Request voice."},
{ "register", "Register your nickname with the MUC."})
- CMD_NOEXAMPLES
},
- { "/role",
- parse_args_with_freetext, 1, 4, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/role",
+ parse_args_with_freetext, 1, 4, NULL)
CMD_MAINFUNC(cmd_role)
CMD_TAGS(
CMD_TAG_GROUPCHAT)
@@ -733,12 +684,10 @@ static struct cmd_t command_defs[] = {
CMD_ARGS(
{ "set []", "Set the role of occupant with nick, with an optional reason." },
{ "list []", "List all occupants with the specified role, or all if none specified." })
- CMD_NOEXAMPLES
},
- { "/occupants",
- parse_args, 1, 3, cons_occupants_setting,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/occupants",
+ parse_args, 1, 3, cons_occupants_setting)
CMD_MAINFUNC(cmd_occupants)
CMD_TAGS(
CMD_TAG_GROUPCHAT,
@@ -773,12 +722,10 @@ static struct cmd_t command_defs[] = {
{ "header char ", "Prefix occupants headers with specified character." },
{ "header char none", "Remove occupants header character prefix." },
{ "wrap on|off", "Enable or disable line wrapping in occupants panel." })
- CMD_NOEXAMPLES
},
- { "/form",
- parse_args, 1, 2, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/form",
+ parse_args, 1, 2, NULL)
CMD_MAINFUNC(cmd_form)
CMD_TAGS(
CMD_TAG_GROUPCHAT)
@@ -794,12 +741,10 @@ static struct cmd_t command_defs[] = {
{ "submit", "Submit the current form." },
{ "cancel", "Cancel changes to the current form." },
{ "help []", "Display help for form, or a specific field." })
- CMD_NOEXAMPLES
},
- { "/rooms",
- parse_args, 0, 4, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/rooms",
+ parse_args, 0, 4, NULL)
CMD_MAINFUNC(cmd_rooms)
CMD_TAGS(
CMD_TAG_GROUPCHAT)
@@ -825,8 +770,8 @@ static struct cmd_t command_defs[] = {
"/rooms service conference.jabber.org filter \"News Room\"")
},
- { "/bookmark",
- parse_args, 0, 8, NULL,
+ { CMD_PREAMBLE("/bookmark",
+ parse_args, 0, 8, NULL)
CMD_SUBFUNCS(
{ "ignore", cmd_bookmark_ignore })
CMD_MAINFUNC(cmd_bookmark)
@@ -870,9 +815,8 @@ static struct cmd_t command_defs[] = {
"/bookmark remove room@example.com")
},
- { "/disco",
- parse_args, 1, 2, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/disco",
+ parse_args, 1, 2, NULL)
CMD_MAINFUNC(cmd_disco)
CMD_TAGS(
CMD_TAG_DISCOVERY)
@@ -893,9 +837,8 @@ static struct cmd_t command_defs[] = {
"/disco info odin@valhalla.edda/laptop")
},
- { "/sendfile",
- parse_args_with_freetext, 1, 1, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/sendfile",
+ parse_args_with_freetext, 1, 1, NULL)
CMD_MAINFUNC(cmd_sendfile)
CMD_TAGS(
CMD_TAG_CHAT,
@@ -911,9 +854,8 @@ static struct cmd_t command_defs[] = {
"/sendfile ~/images/sweet_cat.jpg")
},
- { "/lastactivity",
- parse_args, 1, 2, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/lastactivity",
+ parse_args, 1, 2, NULL)
CMD_MAINFUNC(cmd_lastactivity)
CMD_TAGS(
CMD_TAG_PRESENCE)
@@ -933,9 +875,8 @@ static struct cmd_t command_defs[] = {
"/lastactivity get someserver.com")
},
- { "/nick",
- parse_args_with_freetext, 1, 1, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/nick",
+ parse_args_with_freetext, 1, 1, NULL)
CMD_MAINFUNC(cmd_nick)
CMD_TAGS(
CMD_TAG_GROUPCHAT)
@@ -945,12 +886,10 @@ static struct cmd_t command_defs[] = {
"Change your nickname in the current chat room.")
CMD_ARGS(
{ "", "Your new nickname." })
- CMD_NOEXAMPLES
},
- { "/win",
- parse_args, 1, 1, NULL,
- CMD_NOSUBFUNCS
+ { CMD_PREAMBLE("/win",
+ parse_args, 1, 1, NULL)
CMD_MAINFUNC(cmd_win)
CMD_TAGS(
CMD_TAG_UI)
@@ -984,8 +923,8 @@ static struct cmd_t command_defs[] = {
"/win wikipedia")
},
- { "/wins",
- parse_args, 0, 3, NULL,
+ { CMD_PREAMBLE("/wins",
+ parse_args, 0, 3, NULL)
CMD_SUBFUNCS(
{ "unread", cmd_wins_unread },
{ "attention", cmd_wins_attention },
@@ -1008,12 +947,10 @@ static struct cmd_t command_defs[] = {
{ "attention", "List windows that have been marked with the attention flag (alt+v). You can toggle between marked windows with alt+m." },
{ "prune", "Close all windows with no unread messages." },
{ "swap