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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
int
weechat_trigger_match (t_weechat_trigger *ptr_ign,
char *pattern, char *commands,
char *channels, char *servers)
{
if (strcasecmp (ptr_ign->pattern, pattern) == 0
&& strcasecmp (ptr_ign->commands, commands) == 0
&& strcasecmp (ptr_ign->channels, channels) == 0
&& strcasecmp (ptr_ign->servers, servers) == 0)
return 1;
return 0;
}
t_weechat_trigger *
weechat_trigger_search (char *pattern, char *commands,
char *channels, char *servers)
{
t_weechat_trigger *l;
l = weechat_trigger_list;
while (l)
{
if (weechat_trigger_match (l, pattern, commands, channels, servers))
return l;
l = l->next_trigger;
}
return NULL;
}
int
weechat_trigger_add (t_weechat_plugin *plugin,
char *pattern, char *commands,
char *channels, char *servers)
{
t_weechat_trigger *new;
if (!pattern)
return 0;
if (weechat_trigger_search (pattern, commands, channels, servers))
{
return 2;
}
new = weechat_trigger_alloc (pattern, commands, channels, servers);
if (new)
{
if (weechat_trigger_last)
{
weechat_trigger_last->next_trigger = new;
new->prev_trigger = weechat_trigger_last;
weechat_trigger_last = new;
}
else
{
weechat_trigger_list = new;
weechat_trigger_last = new;
}
return 1;
}
else
plugin->print_server (plugin, "Unable to add trigger, memory allocation failed.");
return 0;
}
int
weechat_trigger_list_del (char *pattern, char *commands,
char *channels, char *servers)
{
char *error;
int number;
t_weechat_trigger *p, *l;
if (!pattern || !weechat_trigger_list)
return 0;
error = NULL;
number = strtol (pattern, &error, 10);
p = NULL;
if (error && (error[0] == '\0') && number > 0)
{
l = weechat_trigger_list;
while (l && number >= 0)
{
number--;
if (number == 0)
p = l;
l = l->next_trigger;
}
}
else
p = weechat_trigger_search (pattern, commands, channels, servers);
if (p)
{
if (p->prev_trigger)
p->prev_trigger->next_trigger = p->next_trigger;
if (p->next_trigger)
p->next_trigger->prev_trigger = p->prev_trigger;
if (p == weechat_trigger_list)
weechat_trigger_list = p->next_trigger;
if (p == weechat_trigger_last)
weechat_trigger_last = p->prev_trigger;
weechat_trigger_free (p);
return 1;
}
return 0;
}
/*
server = plugin->get_info (plugin, "server", NULL);
if (!server)
server = strdup ("*");
if (argc >= 4)
ret = weechat_trigger_add (plugin, argv[0], argv[1], argv[2], argv[3]);
else if (argc == 3)
ret = weechat_trigger_add (plugin, argv[0], argv[1], argv[2], server);
else if (argc == 2)
ret = weechat_trigger_add (plugin, argv[0], argv[1], "*", server);
else if (argc == 1)
ret = weechat_trigger_add (plugin, argv[0], "*", "*", server);
else
{
ret = weechat_trigger_list (plugin);
ret = 1;
}
if (server)
free (server);
if (argc > 0 && ret == 1)
plugin->print_server (plugin, "Trigger: new trigger: on %s/%s: trigger %s from %s",
weechat_trigger_last->servers, weechat_trigger_last->channels,
weechat_trigger_last->commands, weechat_trigger_last->pattern);
else if (ret == 2)
plugin->print_server (plugin, "Trigger: trigger already exists.");
else if (ret == 0)
plugin->print_server (plugin, "Trigger: error: unable to add trigger.");
*/
|