aboutsummaryrefslogtreecommitdiff
path: root/tst/kb.c
blob: 45e6dc5b0ea58d82e062c7fa77e5442ad9a0c9bb (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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

/* EFL Stuff */
#include <Ecore.h>

#define __UNUSED__ __attribute__((unused))

char                   *_priv (char *msg, char *var)
{
    char   *out;

    printf ("> _priv\n");

    out = calloc (sizeof (char), strlen ("PRIV") + 1    /* space */
                  + strlen (var) + 2    /* space: */
                  + strlen (msg) + 3    /* \r\n\0 */
        );

    sprintf (out, "PRIV %s :%s\r\n", var, msg);
    printf ("< _priv:%s\n******\n", out);

    return (out);
}

int del_backslash (char *msg)
{
    int                     i, count;

    for (i = 0, count = 0; msg[i]; i++)
    {
        if (msg[i] == '\n')
        {
            msg[i] = '\0';
            count++;
        }
    }

    return (count);
}


int _kb_get (void __UNUSED__ * data, Ecore_Fd_Handler * fd_handler)
{
    char                   *kb;
    char                   *tmp;
    int                     count;

    printf ("> _kb_get\n");

    printf ("calloc\n");
    kb = calloc (sizeof (char), 200);
    if (kb == NULL)
    {
        fprintf (stderr, "fuck\n");
        exit (-1);
    }

    fflush (stdin);             /* Uh ? */
    fflush (stdout);            /* Uh ? */

    do
    {
        printf ("memset\n");
        memset (kb, 0, 200);
        printf (">read\n");
        count = read (ecore_main_fd_handler_fd_get (fd_handler), kb, 198);
        printf ("<read(%d)\n", count);

        if (count > 0)
        {
            del_backslash (kb);

            tmp = _priv (kb, "test");

            /* for (i=0; i < strlen(tmp) ; i++)
             * {
             * printf ("%d\t: %c\t%c\n", i, kb[i], tmp[i]);
             * }
             */

            printf ("%s\n", tmp);
        }
    }
    while (count >= 198);

    if (count == -1)
        perror ("read");

    if (count == 0)
    {
        printf ("EOF, quit\n");
        ecore_main_loop_quit ();
    }

    printf ("< _kb_get\n");

    free (kb);
    free (tmp);

    return (1);
}

int main ()
{
    Ecore_Fd_Handler       *fd_kb;

    ecore_init ();

    fd_kb = ecore_main_fd_handler_add (STDIN_FILENO, ECORE_FD_READ, _kb_get, NULL, NULL, NULL);

    ecore_main_loop_begin ();

    exit (0);

}