Blame
Date:
Thu Aug 12 09:09:52 2021 UTC
Message:
replace TAILQ_EMPTY/INSERT_HEAD/TAIL dance with a single TAILQ_INSERT_TAIL Now that all the queues are correctly initialised, there's no need for that dance.
01
2021-07-21
op
/*
02
2021-07-21
op
* Copyright (c) 2021 Omar Polo <op@omarpolo.com>
03
2021-07-21
op
*
04
2021-07-21
op
* Permission to use, copy, modify, and distribute this software for any
05
2021-07-21
op
* purpose with or without fee is hereby granted, provided that the above
06
2021-07-21
op
* copyright notice and this permission notice appear in all copies.
07
2021-07-21
op
*
08
2021-07-21
op
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
09
2021-07-21
op
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
2021-07-21
op
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
2021-07-21
op
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
2021-07-21
op
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
2021-07-21
op
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
2021-07-21
op
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
2021-07-21
op
*/
16
2021-07-21
op
17
2021-07-21
op
#include "compat.h"
18
2021-07-21
op
19
2021-07-21
op
#include <assert.h>
20
2021-07-21
op
#include <stdio.h>
21
2021-07-21
op
#include <stdlib.h>
22
2021-07-21
op
#include <string.h>
23
2021-07-21
op
24
2021-07-21
op
#include "telescope.h"
25
2021-07-21
op
#include "ui.h"
26
2021-07-21
op
27
2021-07-21
op
static void emit_help_item(char *, interactivefn *);
28
2021-07-21
op
static void rec_compute_help(struct kmap *, char *, size_t);
29
2021-07-21
op
30
2021-07-21
op
static void
31
2021-07-21
op
emit_help_item(char *prfx, interactivefn *fn)
32
2021-07-21
op
{
33
2021-07-21
op
struct line *l;
34
2021-07-21
op
struct cmd *cmd;
35
2021-07-21
op
36
2021-07-21
op
for (cmd = cmds; cmd->cmd != NULL; ++cmd) {
37
2021-07-21
op
if (fn == cmd->fn)
38
2021-07-21
op
break;
39
2021-07-21
op
}
40
2021-07-21
op
assert(cmd != NULL);
41
2021-07-21
op
42
2021-07-21
op
if ((l = calloc(1, sizeof(*l))) == NULL)
43
2021-07-21
op
abort();
44
2021-07-21
op
45
2021-07-21
op
l->type = LINE_HELP;
46
2021-07-21
op
l->line = strdup(prfx);
47
2021-07-21
op
l->alt = (char*)cmd->cmd;
48
2021-07-21
op
49
2021-08-12
op
TAILQ_INSERT_TAIL(&helpwin.page.head, l, lines);
50
2021-07-21
op
}
51
2021-07-21
op
52
2021-07-21
op
static void
53
2021-07-21
op
rec_compute_help(struct kmap *keymap, char *prfx, size_t len)
54
2021-07-21
op
{
55
2021-07-21
op
struct keymap *k;
56
2021-07-21
op
char p[32];
57
2021-07-21
op
const char *kn;
58
2021-07-21
op
59
2021-07-21
op
TAILQ_FOREACH(k, &keymap->m, keymaps) {
60
2021-07-21
op
strlcpy(p, prfx, sizeof(p));
61
2021-07-21
op
if (*p != '\0')
62
2021-07-21
op
strlcat(p, " ", sizeof(p));
63
2021-07-21
op
if (k->meta)
64
2021-07-21
op
strlcat(p, "M-", sizeof(p));
65
2021-07-21
op
if ((kn = unkbd(k->key)) != NULL)
66
2021-07-21
op
strlcat(p, kn, sizeof(p));
67
2021-07-21
op
else
68
2021-07-21
op
strlcat(p, ui_keyname(k->key), sizeof(p));
69
2021-07-21
op
70
2021-07-21
op
if (k->fn == NULL)
71
2021-07-21
op
rec_compute_help(&k->map, p, sizeof(p));
72
2021-07-21
op
else
73
2021-07-21
op
emit_help_item(p, k->fn);
74
2021-07-21
op
}
75
2021-07-21
op
}
76
2021-07-21
op
77
2021-07-21
op
void
78
2021-07-21
op
recompute_help(void)
79
2021-07-21
op
{
80
2021-07-21
op
static struct kmap *last_active_map = NULL;
81
2021-07-21
op
char p[32] = { 0 };
82
2021-07-21
op
83
2021-07-21
op
if (last_active_map != current_map) {
84
2021-07-21
op
last_active_map = current_map;
85
2021-07-21
op
86
2021-07-21
op
helpwin.page.name = "*Help*";
87
2021-07-21
op
erase_buffer(&helpwin);
88
2021-07-21
op
rec_compute_help(current_map, p, sizeof(p));
89
2021-07-21
op
wrap_page(&helpwin, help_cols);
90
2021-07-21
op
}
91
2021-07-21
op
}
Omar Polo