Blame


1 b1e1e41a 2021-07-14 op /*
2 b1e1e41a 2021-07-14 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 b1e1e41a 2021-07-14 op *
4 b1e1e41a 2021-07-14 op * Permission to use, copy, modify, and distribute this software for any
5 b1e1e41a 2021-07-14 op * purpose with or without fee is hereby granted, provided that the above
6 b1e1e41a 2021-07-14 op * copyright notice and this permission notice appear in all copies.
7 b1e1e41a 2021-07-14 op *
8 b1e1e41a 2021-07-14 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 b1e1e41a 2021-07-14 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 b1e1e41a 2021-07-14 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 b1e1e41a 2021-07-14 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 b1e1e41a 2021-07-14 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 b1e1e41a 2021-07-14 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 b1e1e41a 2021-07-14 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 b1e1e41a 2021-07-14 op */
16 b1e1e41a 2021-07-14 op
17 b1e1e41a 2021-07-14 op #include <stdlib.h>
18 b1e1e41a 2021-07-14 op
19 b1e1e41a 2021-07-14 op #include "compl.h"
20 b1e1e41a 2021-07-14 op #include "telescope.h"
21 b1e1e41a 2021-07-14 op
22 b1e1e41a 2021-07-14 op const char *
23 65601367 2021-07-14 op compl_eecmd(void **data, void **ret)
24 b1e1e41a 2021-07-14 op {
25 b1e1e41a 2021-07-14 op struct cmd **state = (struct cmd **)data;
26 b1e1e41a 2021-07-14 op
27 b1e1e41a 2021-07-14 op /* first time: init the state */
28 b1e1e41a 2021-07-14 op if (*state == NULL)
29 b1e1e41a 2021-07-14 op *state = cmds;
30 b1e1e41a 2021-07-14 op
31 b1e1e41a 2021-07-14 op if ((*state)->cmd == NULL)
32 b1e1e41a 2021-07-14 op return NULL;
33 b1e1e41a 2021-07-14 op
34 af48e20e 2021-07-14 op return (*state)++->cmd;
35 b1e1e41a 2021-07-14 op }
36 65601367 2021-07-14 op
37 65601367 2021-07-14 op const char *
38 65601367 2021-07-14 op compl_ts(void **data, void **ret)
39 65601367 2021-07-14 op {
40 65601367 2021-07-14 op struct tab **tab = (struct tab **)data;
41 65601367 2021-07-14 op
42 65601367 2021-07-14 op /* first time: init the state */
43 65601367 2021-07-14 op if (*tab == NULL)
44 65601367 2021-07-14 op *tab = TAILQ_FIRST(&tabshead);
45 65601367 2021-07-14 op else if ((*tab = TAILQ_NEXT(*tab, tabs)) == NULL)
46 65601367 2021-07-14 op return NULL;
47 65601367 2021-07-14 op
48 65601367 2021-07-14 op *ret = *tab;
49 65601367 2021-07-14 op
50 65601367 2021-07-14 op if (*(*tab)->buffer.page.title == '\0')
51 65601367 2021-07-14 op return (*tab)->hist_cur->h;
52 65601367 2021-07-14 op return (*tab)->buffer.page.title;
53 65601367 2021-07-14 op }