aboutsummaryrefslogtreecommitdiff
path: root/src/espik_common_handler.c
blob: 6022344d67435e170bcdfaa14d018ac82aebc270 (plain) (blame)
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <Ecore.h>

#include "espik_global.h"
#include "espik.h"
#include "espik_error.h"
#include "espik_common_handler.h"

#define INPUT_LENGHT 200

int	kb_get (void* data __UNUSED__, Ecore_Fd_Handler* fd_handler)
{
	char	kb[INPUT_LENGHT];
	int	count;

	do
	{
		memset (kb, 0, INPUT_LENGHT);
		count = read (ecore_main_fd_handler_fd_get (fd_handler), kb,
			      INPUT_LENGHT - 2);

		if (count > 1)
		{
			del_backslash (kb);
			printf ("%s", kb);
		}
	}
	while (count >= INPUT_LENGHT - 2);

	if (count == -1)
	{
		perror ("read");
		espik_shutdown();
		return (0);
	}

	if (count == 0)
	{
		espik_shutdown();
		return (0);
	}

	return (1);
}