'everything' module: calc

- truncate rest of division with scale=3
- workaround for wrong syntax issue


SVN revision: 41352
This commit is contained in:
Hannes Janetzek 2009-07-15 20:39:33 +00:00
parent fc6c3e8461
commit e1ce008a7e
1 changed files with 36 additions and 14 deletions

View File

@ -13,6 +13,7 @@ static void _item_add(Evry_Plugin *p, char *output, int prio);
static int _cb_sort(const void *data1, const void *data2);
static void _item_icon_get(Evry_Plugin *p, Evry_Item *it, Evas *e);
static int _cb_data(void *data, int type, void *event);
static int _cb_error(void *data, int type, void *event);
static Evry_Plugin *p;
static Ecore_Exe *exe = NULL;
@ -20,6 +21,7 @@ static Eina_List *history = NULL;
static Ecore_Event_Handler *data_handler = NULL;
static Ecore_Event_Handler *error_handler = NULL;
static Ecore_X_Window clipboard_win = 0;
static int error = 0;
EAPI int
evry_plug_calc_init(void)
@ -66,11 +68,13 @@ _begin(Evry_Plugin *p, Evry_Item *it)
{
data_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DATA, _cb_data, p);
exe = ecore_exe_pipe_run("bc",
error_handler = ecore_event_handler_add(ECORE_EXE_EVENT_ERROR, _cb_error, p);
exe = ecore_exe_pipe_run("bc -l",
ECORE_EXE_PIPE_READ |
ECORE_EXE_PIPE_READ_LINE_BUFFERED |
ECORE_EXE_PIPE_WRITE,
ECORE_EXE_PIPE_WRITE |
ECORE_EXE_PIPE_ERROR |
ECORE_EXE_PIPE_ERROR_LINE_BUFFERED,
NULL);
}
@ -95,21 +99,13 @@ _cleanup(Evry_Plugin *p)
}
ecore_event_handler_del(data_handler);
ecore_event_handler_del(error_handler);
data_handler = NULL;
ecore_exe_quit(exe);
exe = NULL;
}
static int
_send_input(const char *input)
{
char buf[1024];
snprintf(buf, 1024, "%s\n", input + (strlen(p->trigger)));
return ecore_exe_send(exe, buf, strlen(buf));
}
static int
_action(Evry_Plugin *p, Evry_Item *it, const char *input)
{
@ -158,14 +154,28 @@ _action(Evry_Plugin *p, Evry_Item *it, const char *input)
static int
_fetch(Evry_Plugin *p, const char *input)
{
char buf[1024];
if (history)
{
p->items = history;
history = NULL;
}
_send_input(input);
snprintf(buf, 1024, "scale=3;%s\n", input + (strlen(p->trigger)));
/* printf("send %s\n",buf); */
ecore_exe_send(exe, buf, strlen(buf));
/* XXX after error we get no response for first input ?! - send a
second time...*/
if (error)
{
ecore_exe_send(exe, buf, strlen(buf));
error = 0;
}
return 1;
}
@ -195,11 +205,13 @@ _cb_data(void *data, int type, void *event)
Ecore_Exe_Event_Data_Line *l;
if (data != p) return 1;
evry_plugin_async_update(p, EVRY_ASYNC_UPDATE_CLEAR);
for (l = ev->lines; l && l->line; l++)
{
/* printf("line %s\n", l->line); */
if (p->items)
{
Evry_Item *it = p->items->data;
@ -215,3 +227,13 @@ _cb_data(void *data, int type, void *event)
return 1;
}
static int
_cb_error(void *data, int type, void *event)
{
error = 1;
/* printf("got error\n"); */
return 1;
}