-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcmd.c
51 lines (46 loc) · 1.08 KB
/
cmd.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
/*
** cmd.c for my_select in /home/sebastien/travaux/my_select
**
** Made by sebastien
** Login <[email protected]>
**
** Started on Thu Jan 16 19:56:04 2014 sebastien
** Last update Fri Jan 17 14:42:50 2014 chapui_s
*/
#include <stdlib.h>
#include "my_select.h"
static int do_func(char *buf,
t_func *list_func,
t_list *root)
{
void (*func_tmp)(t_list *root);
while (list_func && my_strcmp(buf, list_func->keycode) != 0)
list_func = list_func->next;
if (list_func)
{
func_tmp = (list_func)->func_ptr;
func_tmp(root);
}
return (0);
}
int get_cmd(void)
{
t_func *list_func;
char buffer[BUFFER_SIZE];
int ret_read;
list_func = NULL;
if ((list_func = init_func()) == NULL)
return (-1);
buf_zero(&buffer[0], BUFFER_SIZE);
while (((ret_read = read(0, buffer, BUFFER_SIZE)) > 0)
&& buffer[0] != '\n')
{
if (ret_read == -1)
return (puterror("error: could not read\n"));
if (buffer[0] == 27 && buffer[1] == 0)
break ;
do_func(&buffer[0], list_func, root_args);
buf_zero(&buffer[0], BUFFER_SIZE);
}
return (0);
}