#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);
}