blob: 7e197615684d3293459aba2a81a409aad3228b4c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/*
* File: actions.c
*
* Copyright (C) 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*/
#include "actions.h"
#include "msg.h"
#include "../dlib/dlib.h"
#include <errno.h>
static Dlist *link_actions = NULL;
void
action_parse(char *line)
{
char *label = strtok(line, ":");
if (label == NULL || strlen(label) == 0) {
MSG("Missing action label, ignoring '%s'\n", line);
return;
}
//MSG("Got label='%s'\n", label);
char *cmd = strtok(NULL, "");
if (cmd == NULL || strlen(cmd) == 0) {
MSG("Missing action command, ignoring '%s'\n", line);
return;
}
//MSG("Got action label='%s' cmd='%s'\n", label, cmd);
Action *action = dMalloc(sizeof(Action));
action->label = dStrdup(label);
action->cmd = dStrdup(cmd);
dList_append(link_actions, action);
}
void
a_Actions_init(void)
{
int n = dList_length(prefs.link_actions);
link_actions = dList_new(n);
for (int i = 0; i < n; i++) {
char *line = dList_nth_data(prefs.link_actions, i);
if (line)
action_parse(line);
}
}
Dlist *
a_Actions_link_get(void)
{
return link_actions;
}
|