Dillo v3.1.1-119-g140d9ebd
Loading...
Searching...
No Matches
actions.c
Go to the documentation of this file.
1/*
2 * File: actions.c
3 *
4 * Copyright (C) 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 */
11
12#include "actions.h"
13#include "msg.h"
14#include "../dlib/dlib.h"
15#include <errno.h>
16
17static Dlist *link_actions = NULL;
18
19void
20action_parse(char *line)
21{
22 char *label = strtok(line, ":");
23
24 if (label == NULL || strlen(label) == 0) {
25 MSG("Missing action label, ignoring '%s'\n", line);
26 return;
27 }
28
29 //MSG("Got label='%s'\n", label);
30
31 char *cmd = strtok(NULL, "");
32
33 if (cmd == NULL || strlen(cmd) == 0) {
34 MSG("Missing action command, ignoring '%s'\n", line);
35 return;
36 }
37
38 //MSG("Got action label='%s' cmd='%s'\n", label, cmd);
39
40 Action *action = dMalloc(sizeof(Action));
41 action->label = dStrdup(label);
42 action->cmd = dStrdup(cmd);
43
45}
46
47void
49{
51
53
54 for (int i = 0; i < n; i++) {
55 char *line = dList_nth_data(prefs.link_actions, i);
56 if (line)
57 action_parse(line);
58 }
59}
60
61Dlist *
63{
64 return link_actions;
65}
void action_parse(char *line)
Definition actions.c:20
Dlist * a_Actions_link_get(void)
Definition actions.c:62
void a_Actions_init(void)
Definition actions.c:48
static Dlist * link_actions
Definition actions.c:17
#define MSG(...)
Definition bookmarks.c:46
char * dStrdup(const char *s)
Definition dlib.c:77
Dlist * dList_new(int size)
Create a new empty list.
Definition dlib.c:548
int dList_length(Dlist *lp)
For completing the ADT.
Definition dlib.c:613
void * dList_nth_data(Dlist *lp, int n0)
Return the nth data item, NULL when not found or 'n0' is out of range.
Definition dlib.c:662
void * dMalloc(size_t size)
Definition dlib.c:45
void dList_append(Dlist *lp, void *data)
Append a data item to the list.
Definition dlib.c:597
DilloPrefs prefs
Global Data.
Definition prefs.c:33
char * cmd
Definition actions.h:23
char * label
Definition actions.h:22
Dlist * link_actions
Definition prefs.h:127
Definition dlib.h:131