-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlist_func.c
94 lines (84 loc) · 2.05 KB
/
list_func.c
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
/*
** list_func.c for my_select in /home/sebastien/travaux/my_select
**
** Made by sebastien
** Login <[email protected]>
**
** Started on Thu Jan 16 17:51:47 2014 sebastien
** Last update Fri Jan 17 11:34:31 2014 sebastien
*/
#include <stdlib.h>
#include "my_select.h"
static t_func *create_func(char *keycode,
void (*func_ptr)(t_list *root))
{
t_func *new;
new = NULL;
if ((new = (t_func*)malloc(sizeof(*new))))
{
new->keycode = keycode;
new->func_ptr = func_ptr;
new->next = NULL;
}
return (new);
}
static int push_func(t_func **list, char *keycode,
void (*func_ptr)(t_list *root))
{
t_func *tmp;
tmp = *list;
if (*list)
{
while (tmp->next)
tmp = tmp->next;
if ((tmp->next = create_func(keycode, func_ptr)))
return (0);
}
else
if ((*list = create_func(keycode, func_ptr)))
return (0);
puterror("error: could not alloc\n");
return (-1);
}
static char *get_keycode(int i)
{
char *keycode;
keycode = NULL;
(i == 0) ? (keycode = init_prec()) : (0);
(i == 1) ? (keycode = init_next()) : (0);
(i == 2) ? (keycode = init_left()) : (0);
(i == 3) ? (keycode = init_right()) : (0);
(i == 4) ? (keycode = init_select()) : (0);
(i == 5) ? (keycode = init_rm_backspace()) : (0);
(i == 6) ? (keycode = init_rm_del()) : (0);
return (keycode);
}
static void get_func(void (**func_ptr)(t_list *root), int i)
{
(i == 0) ? (*func_ptr = &goto_prec) : (0);
(i == 1) ? (*func_ptr = &goto_next) : (0);
(i == 2) ? (*func_ptr = &goto_left) : (0);
(i == 3) ? (*func_ptr = &goto_right) : (0);
(i == 4) ? (*func_ptr = &select_it) : (0);
(i == 5) ? (*func_ptr = &rm_it) : (0);
(i == 6) ? (*func_ptr = &rm_it) : (0);
}
t_func *init_func(void)
{
t_func *list_func;
int i;
char *keycode;
void (*func_ptr)(t_list *root);
i = 0;
list_func = NULL;
while (i < 7)
{
get_func(&func_ptr, i);
if ((keycode = get_keycode(i)) == NULL)
return (NULL);
if ((push_func(&list_func, keycode, func_ptr)) == -1)
return (NULL);
i = i + 1;
}
return (list_func);
}