117
116
static int show_help_file(const char *file)
119
118
const char *helppath;
120
char tmpbuf[1024], *str, *path, **paths, **tmp;
121
LINEBUF_REC *buffer = NULL;
119
char *path, **paths, **tmp;
124
124
helppath = settings_get_str("help_path");
126
126
paths = g_strsplit(helppath, ":", -1);
129
129
for (tmp = paths; *tmp != NULL; tmp++) {
130
130
/* helpdir/command or helpdir/category/command */
131
131
path = g_strdup_printf("%s/%s", *tmp, file);
132
f = open(path, O_RDONLY);
132
handle = g_io_channel_new_file(path, "r", NULL);
140
140
g_strfreev(paths);
145
g_io_channel_set_encoding(handle, NULL, NULL);
146
buf = g_string_sized_new(512);
145
147
/* just print to screen whatever is in the file */
147
recvlen = read(f, tmpbuf, sizeof(tmpbuf));
149
ret = line_split(tmpbuf, recvlen, &str, &buffer);
151
str = g_strconcat("%|", str, NULL);
152
printtext_string(NULL, NULL, MSGLEVEL_CLIENTCRAP, str);
148
while (g_io_channel_read_line_string(handle, buf, &tpos, NULL) == G_IO_STATUS_NORMAL) {
149
buf->str[tpos] = '\0';
150
g_string_prepend(buf, "%|");
151
printtext_string(NULL, NULL, MSGLEVEL_CLIENTCRAP, buf->str);
157
line_split_free(buffer);
153
g_string_free(buf, TRUE);
155
g_io_channel_unref(handle);
252
248
/* SYNTAX: HELP [<command>] */
253
249
static void cmd_help(const char *data)
257
cmd = g_strdup(data);
258
ptr = cmd+strlen(cmd);
259
while (ptr[-1] == ' ') ptr--; *ptr = '\0';
253
cmd = g_ascii_strdown(data, -1);