aboutsummaryrefslogtreecommitdiffstats
path: root/sway/list.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-08-04 21:30:40 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-08-04 21:30:40 -0400
commit542ef0c77700e67a95fcd08b5f305d1ab42046e1 (patch)
tree17333ebc1a65a28b9538de2da9264a45fc0cf9a9 /sway/list.c
parentInitial commit (diff)
downloadsway-542ef0c77700e67a95fcd08b5f305d1ab42046e1.tar.gz
sway-542ef0c77700e67a95fcd08b5f305d1ab42046e1.tar.zst
sway-542ef0c77700e67a95fcd08b5f305d1ab42046e1.zip
Pull in some scas code and read i3 config file
Diffstat (limited to 'sway/list.c')
-rw-r--r--sway/list.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/sway/list.c b/sway/list.c
new file mode 100644
index 00000000..120cfbcd
--- /dev/null
+++ b/sway/list.c
@@ -0,0 +1,37 @@
1#include "list.h"
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5
6list_t *create_list() {
7 list_t *list = malloc(sizeof(list_t));
8 list->capacity = 10;
9 list->length = 0;
10 list->items = malloc(sizeof(void*) * list->capacity);
11 return list;
12}
13
14void list_free(list_t *list) {
15 free(list->items);
16 free(list);
17}
18
19void list_add(list_t *list, void *item) {
20 if (list->length == list->capacity) {
21 list->capacity += 10;
22 list->items = realloc(list->items, sizeof(void*) * list->capacity);
23 }
24 list->items[list->length++] = item;
25}
26
27void list_del(list_t *list, int index) {
28 list->length--;
29 memmove(&list->items[index], &list->items[index + 1], sizeof(void*) * (list->capacity - index - 1));
30}
31
32void list_cat(list_t *list, list_t *source) {
33 int i;
34 for (i = 0; i < source->length; ++i) {
35 list_add(list, source->items[i]);
36 }
37}