commit 5a61017aa0ab81d52c1f3bedf4907826344a269d
parent 3f14090d694f40dea28c9b984ad98800ee713230
Author: hhvn <dev@hhvn.uk>
Date: Fri, 12 Nov 2021 19:10:35 +0000
commands.c config.c hirc.h struct.h: /help command
Diffstat:
M | commands.c | | | 83 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- |
M | config.c | | | 126 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
M | hirc.h | | | 6 | +++++- |
M | struct.h | | | 3 | ++- |
4 files changed, 149 insertions(+), 69 deletions(-)
diff --git a/commands.c b/commands.c
@@ -15,10 +15,25 @@ enum {
};
static struct Command commands[] = {
- {"quit", command_quit},
- {"connect", command_connect},
- {"select", command_select},
- {"set", command_set},
+ {"quit", command_quit, {
+ "usage: /quit",
+ "Cleanup and exit", NULL}},
+ {"connect", command_connect, {
+ "usage: /connect [-network <name>] [-nick <nick>] [-user <user>]",
+ " [-real <comment>] [-tls] [-verify] <host> [port]",
+ "Connect to a network/server", NULL}},
+ {"select", command_select, {
+ "usage: /select [-network <name>] [-channel <name>] [buffer id]",
+ "Select a buffer", NULL}},
+ {"set", command_set, {
+ "usage: /set <variable> [number/range] [end of range]",
+ " /set <variable> string....",
+ "Set a configuration variable.",
+ "Passing only the name prints content.", NULL}},
+ {"help", command_help, {
+ "usage: /help [command or variable]",
+ "Print help information.",
+ "`/help commands` and `/help variables` will list respectively", NULL}},
{NULL, NULL},
};
@@ -194,10 +209,70 @@ void
command_set(char *str) {
char *name, *val;
+ if (!str) {
+ ui_error("/set requires argument", NULL);
+ return;
+ }
name = strtok_r(str, " ", &val);
config_set(name, val);
}
+void
+command_help(char *str) {
+ int cmdonly = 0;
+ int i, j;
+
+ if (!str) {
+ command_help("/help");
+ return;
+ }
+
+ if (strcmp(str, "commands") == 0) {
+ hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :Commands:");
+ for (i=0; commands[i].name && commands[i].func; i++)
+ hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI : %s", commands[i].name);
+ return;
+ }
+
+ if (strcmp(str, "variables") == 0) {
+ hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :Variables:");
+ for (i=0; config[i].name; i++)
+ hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI : %s", config[i].name);
+ return;
+ }
+
+ if (*str == '/') {
+ cmdonly = 1;
+ str++;
+ }
+
+ for (i=0; commands[i].name && commands[i].func; i++) {
+ if (strcmp(commands[i].name, str) == 0) {
+ hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :%s", str);
+ hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :===");
+ for (j=0; commands[i].description[j]; j++)
+ hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :%s", commands[i].description[j]);
+ hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :");
+ return;
+ }
+ }
+
+ if (!cmdonly) {
+ for (i=0; config[i].name; i++) {
+ if (strcmp(config[i].name, str) == 0) {
+ hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :%s", str);
+ hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :===");
+ for (j=0; config[i].description[j]; j++)
+ hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :%s", config[i].description[j]);
+ hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :");
+ return;
+ }
+ }
+ }
+
+ ui_error("no help on '%s'", str);
+}
+
int
command_getopt(char **str, struct CommandOpts *opts) {
char *opt;
diff --git a/config.c b/config.c
@@ -17,117 +17,117 @@ struct Config config[] = {
{"log.dir", 1, Val_string,
.str = "~/.local/hirc",
.strhandle = NULL,
- .description =
- "Directory for hirc to log to.\n"
- "Can contain ~ to refer to $HOME\n"},
+ .description = {
+ "Directory for hirc to log to.",
+ "Can contain ~ to refer to $HOME", NULL}},
{"log.toggle", 1, Val_bool,
.num = 1,
.numhandle = NULL,
- .description =
- "Simple: to log, or not to log\n"},
+ .description = {
+ "Simple: to log, or not to log", NULL}},
{"def.nick", 1, Val_string,
.str = NULL,
.strhandle = NULL,
- .description =
- "Default nickname"},
+ .description = {
+ "Default nickname", NULL}},
{"def.user", 1, Val_string,
.str = NULL,
.strhandle = NULL,
- .description =
- "Default username (nick!..here..@host), \n"
- "may be replaced by identd response\n"},
+ .description = {
+ "Default username (nick!..here..@host), ",
+ "may be replaced by identd response", NULL}},
{"def.real", 1, Val_string,
.str = NULL,
.strhandle = NULL,
- .description =
- "Default \"realname\", seen in /whois\n"},
+ .description = {
+ "Default \"realname\", seen in /whois", NULL}},
{"def.chantypes", 1, Val_string,
.str = "#&!+",
.strhandle = NULL,
- .description =
- "You most likely don't want to touch this.\n"
- "If a server does not supply this in RPL_ISUPPORT,\n"
- "hirc assumes it will use these channel types.\n"},
+ .description = {
+ "You most likely don't want to touch this.",
+ "If a server does not supply this in RPL_ISUPPORT,",
+ "hirc assumes it will use these channel types.", NULL}},
{"def.prefixes", 1, Val_string,
.str = "(ov)@+",
.strhandle = NULL,
- .description =
- "You most likely don't want to touch this.\n"
- "If a server doesn't supply this in the nonstandard\n"
- "RPL_ISUPPORT, it likely won't support nonstandard\n"
- "prefixes.\n"},
+ .description = {
+ "You most likely don't want to touch this.",
+ "If a server doesn't supply this in the nonstandard",
+ "RPL_ISUPPORT, it likely won't support nonstandard",
+ "prefixes.", NULL}},
{"reconnect.interval", 1, Val_nzunsigned,
.num = 10,
.numhandle = NULL,
- .description =
- "Starting reconnect interval in seconds.\n"
- "In reality, for each attempt this will be multipled\n"
- "by the number of failed attemps until it reaches\n"
- "reconnect.maxinterval\n"},
+ .description = {
+ "Starting reconnect interval in seconds.",
+ "In reality, for each attempt this will be multipled",
+ "by the number of failed attemps until it reaches",
+ "reconnect.maxinterval", NULL}},
{"reconnect.maxinterval", 1, Val_nzunsigned,
.num = 600,
.numhandle = NULL,
- .description =
- "Maximum reconnect interval in seconds.\n"
- "See reconnect.interval\n"},
+ .description = {
+ "Maximum reconnect interval in seconds.",
+ "See reconnect.interval", NULL}},
{"nickcolour.self", 1, Val_nzunsigned,
.num = 90,
.numhandle = config_colour_self,
- .description =
- "Colour to use for onself.\n"
- "Must be 0, 99 or anywhere between. 99 is no colours.\n"},
+ .description = {
+ "Colour to use for onself.",
+ "Must be 0, 99 or anywhere between. 99 is no colours.", NULL}},
{"nickcolour.range", 1, Val_range,
.range = {28, 63},
.rangehandle = config_colour_range,
- .description =
- "Range of (mirc extended) colours used to colour nicks\n"
- "Must be 0, 99 or anywhere between. 99 is no colour\n"
- "Giving a single value or two identical values will\n"
- "use that colour only\n"},
+ .description = {
+ "Range of (mirc extended) colours used to colour nicks",
+ "Must be 0, 99 or anywhere between. 99 is no colour",
+ "Giving a single value or two identical values will",
+ "use that colour only", NULL}},
{"nicklist.location", 1, Val_unsigned,
.num = RIGHT,
.numhandle = config_nicklist_location,
- .description =
- "Location of nicklist. May be:\n"
- " 0 - Hidden\n"
- " 1 - Left\n"
- " 2 - Right\n"},
+ .description = {
+ "Location of nicklist. May be:",
+ " 0 - Hidden",
+ " 1 - Left",
+ " 2 - Right", NULL}},
{"nicklist.width", 1, Val_nzunsigned,
.num = 15,
.numhandle = config_nicklist_width,
- .description =
- "Number of columns nicklist will take up.\n"},
+ .description = {
+ "Number of columns nicklist will take up.", NULL}},
{"buflist.location", 1, Val_unsigned,
.num = LEFT,
.numhandle = config_buflist_location,
- .description =
- "Location of nicklist. May be:\n"
- " 0 - Hidden\n"
- " 1 - Left\n"
- " 2 - Right\n"},
+ .description = {
+ "Location of nicklist. May be:",
+ " 0 - Hidden",
+ " 1 - Left",
+ " 2 - Right", NULL}},
{"buflist.width", 1, Val_nzunsigned,
.num = 25,
.numhandle = config_buflist_width,
- .description =
- "Number of columns buflist will take up.\n"},
+ .description = {
+ "Number of columns buflist will take up.", NULL}},
{"misc.pingtime", 1, Val_nzunsigned,
.num = 200,
.numhandle = NULL,
- .description =
- "Wait this many seconds since last received message\n"
- "from server to send PING. If ping.wait seconds\n"
- "elapses since sending a PING, hirc will consider\n"
- "the server disconnected.\n"},
+ .description = {
+ "Wait this many seconds since last received message",
+ "from server to send PING. If ping.wait seconds",
+ "elapses since sending a PING, hirc will consider",
+ "the server disconnected.", NULL}},
{"misc.quitmessage", 1, Val_string,
.str = "pain is temporary",
.strhandle = NULL,
- .description =
- "Message to send on /quit\n"},
+ .description = {
+ "Message to send on /quit", NULL}},
{"misc.partmessage", 1, Val_string,
.str = "pain is temporary",
.strhandle = NULL,
- .description =
- "Message to send on /part\n"},
+ .description = {
+ "Message to send on /part", NULL}},
{NULL},
};
@@ -154,13 +154,13 @@ config_get_print(char *name) {
for (i=0; config[i].name; i++) {
if (strcmp(config[i].name, name) == 0) {
if (config[i].valtype == Val_string)
- hist_format(main_buf, Activity_status, HIST_SHOW, "%s: %s",
+ hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :%s: %s",
name, config[i].str);
else if (config[i].valtype == Val_range)
- hist_format(main_buf, Activity_status, HIST_SHOW, "%s: {%ld, %ld}",
+ hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :%s: {%ld, %ld}",
name, config[i].range[0], config[i].range[1]);
else
- hist_format(main_buf, Activity_status, HIST_SHOW, "%s: %ld",
+ hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :%s: %ld",
name, config[i].num);
return;
}
diff --git a/hirc.h b/hirc.h
@@ -130,8 +130,9 @@ void command_quit(char *str);
void command_connect(char *str);
void command_select(char *str);
void command_set(char *str);
+void command_help(char *str);
-/* config.h */
+/* config.c */
void config_get_print(char *name);
long config_getl(char *name);
char * config_gets(char *name);
@@ -157,4 +158,7 @@ extern struct Selected selected;
extern struct Window windows[Win_last];
extern int uineedredraw;
+/* config.c */
+extern struct Config config[];
+
#endif /* H_HIRC */
diff --git a/struct.h b/struct.h
@@ -122,6 +122,7 @@ struct Handler {
struct Command {
char *name;
void (*func)(char *str);
+ char *description[64];
};
struct CommandOpts {
@@ -143,7 +144,7 @@ struct Config {
char *name;
int isdef;
enum Valtype valtype;
- char *description;
+ char *description[64];
char *str;
long num;
long range[2];