2012-05-08 03:35:57 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-09-20 00:52:10 -07:00
|
|
|
#include <sys/wait.h>
|
|
|
|
|
2012-05-08 03:35:57 -07:00
|
|
|
#include <Eina.h>
|
|
|
|
#include <Ecore.h>
|
|
|
|
#include <Eio.h>
|
|
|
|
#ifdef HAVE_EVIL
|
|
|
|
# include <Evil.h>
|
|
|
|
#endif
|
|
|
|
|
2012-09-04 19:44:45 -07:00
|
|
|
static char watchfile[PATH_MAX];
|
|
|
|
static char *edje_cc_command = NULL;
|
|
|
|
static Eina_List *watching = NULL;
|
|
|
|
static Ecore_Timer *timeout = NULL;
|
|
|
|
static Eina_Bool anotate = EINA_FALSE;
|
2012-05-08 03:35:57 -07:00
|
|
|
|
|
|
|
static void
|
|
|
|
read_watch_file(const char *file)
|
|
|
|
{
|
|
|
|
Eina_File *f;
|
|
|
|
Eina_Iterator *it;
|
2012-07-31 00:23:16 -07:00
|
|
|
Eina_File_Line *ln;
|
2012-05-08 03:35:57 -07:00
|
|
|
Eio_Monitor *mon;
|
|
|
|
Eina_List *r = NULL;
|
|
|
|
|
|
|
|
f = eina_file_open(file, EINA_FALSE);
|
|
|
|
if (!f) return ;
|
|
|
|
|
|
|
|
it = eina_file_map_lines(f);
|
|
|
|
if (!it) goto err;
|
|
|
|
|
|
|
|
EINA_ITERATOR_FOREACH(it, ln)
|
|
|
|
{
|
|
|
|
const char *path;
|
2012-09-04 19:44:45 -07:00
|
|
|
Eina_Bool do_append = EINA_TRUE;
|
2012-05-08 03:35:57 -07:00
|
|
|
|
2012-09-03 19:13:05 -07:00
|
|
|
if (ln->length < 4) continue ;
|
2012-09-04 19:44:45 -07:00
|
|
|
if (anotate)
|
|
|
|
{
|
|
|
|
path = eina_stringshare_add_length(ln->start + 3, ln->length - 3);
|
2012-09-17 02:38:20 -07:00
|
|
|
fprintf(stdout, "%c: %s\n", *ln->start, path);
|
2012-09-04 19:44:45 -07:00
|
|
|
if (*ln->start == 'O')
|
|
|
|
do_append = EINA_FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path = eina_stringshare_add_length(ln->start, ln->length);
|
|
|
|
}
|
|
|
|
if (do_append)
|
2012-09-03 19:13:05 -07:00
|
|
|
r = eina_list_append(r, eio_monitor_add(path));
|
2012-05-08 03:35:57 -07:00
|
|
|
eina_stringshare_del(path);
|
|
|
|
}
|
|
|
|
eina_iterator_free(it);
|
|
|
|
|
|
|
|
EINA_LIST_FREE(watching, mon)
|
|
|
|
eio_monitor_del(mon);
|
|
|
|
watching = r;
|
|
|
|
|
|
|
|
err:
|
|
|
|
eina_file_close(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Bool
|
|
|
|
rebuild(void *data __UNUSED__)
|
|
|
|
{
|
2012-05-16 03:37:44 -07:00
|
|
|
double start, end;
|
2012-09-17 02:38:20 -07:00
|
|
|
int ret;
|
2012-05-16 03:37:44 -07:00
|
|
|
|
|
|
|
start = ecore_time_get();
|
2012-09-17 02:38:20 -07:00
|
|
|
fprintf(stdout, "* SYSTEM('%s')\n", edje_cc_command);
|
2012-09-17 03:09:04 -07:00
|
|
|
fflush(stdout);
|
|
|
|
|
2012-09-17 02:38:20 -07:00
|
|
|
ret = system(edje_cc_command);
|
|
|
|
if (WEXITSTATUS(ret) == 0)
|
2012-05-08 03:35:57 -07:00
|
|
|
read_watch_file(watchfile);
|
2012-05-16 03:37:44 -07:00
|
|
|
end = ecore_time_get();
|
2012-09-17 02:38:20 -07:00
|
|
|
fprintf(stdout, "* DONE IN %f\n", end - start);
|
|
|
|
fflush(stdout);
|
2012-05-08 03:35:57 -07:00
|
|
|
|
|
|
|
timeout = NULL;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Bool
|
|
|
|
some_change(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
|
|
|
|
{
|
|
|
|
if (timeout) ecore_timer_del(timeout);
|
|
|
|
timeout = ecore_timer_add(0.5, rebuild, NULL);
|
|
|
|
|
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *watchout;
|
|
|
|
Eina_Strbuf *buf;
|
|
|
|
int tfd;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
eina_init();
|
|
|
|
ecore_init();
|
|
|
|
eio_init();
|
|
|
|
|
|
|
|
if (argc < 2) return -1;
|
2012-09-03 19:13:05 -07:00
|
|
|
|
2012-05-08 03:35:57 -07:00
|
|
|
ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, some_change, NULL);
|
|
|
|
ecore_event_handler_add(EIO_MONITOR_FILE_CREATED, some_change, NULL);
|
|
|
|
ecore_event_handler_add(EIO_MONITOR_FILE_DELETED, some_change, NULL);
|
|
|
|
ecore_event_handler_add(EIO_MONITOR_FILE_CLOSED, some_change, NULL);
|
|
|
|
|
|
|
|
#ifdef HAVE_EVIL
|
|
|
|
watchout = (char *)evil_tmpdir_get();
|
|
|
|
#else
|
|
|
|
watchout = "/tmp";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
snprintf(watchfile, PATH_MAX, "%s/edje_watch-tmp-XXXXXX", watchout);
|
|
|
|
|
|
|
|
tfd = mkstemp(watchfile);
|
|
|
|
if (tfd < 0) return -1;
|
|
|
|
close(tfd);
|
|
|
|
|
|
|
|
buf = eina_strbuf_new();
|
|
|
|
if (!buf) return -1;
|
|
|
|
|
2012-09-17 02:38:20 -07:00
|
|
|
eina_strbuf_append_printf(buf, "%s/edje_cc -fastcomp -w %s ", PACKAGE_BIN_DIR, watchfile);
|
2012-05-08 03:35:57 -07:00
|
|
|
for (i = 1; i < argc; ++i)
|
2012-09-04 19:44:45 -07:00
|
|
|
{
|
|
|
|
if (!strcmp(argv[i], "-anotate"))
|
|
|
|
anotate = EINA_TRUE;
|
|
|
|
eina_strbuf_append_printf(buf, "%s ", argv[i]);
|
|
|
|
}
|
2012-10-25 21:29:58 -07:00
|
|
|
eina_strbuf_append(buf, "> /dev/null");
|
2012-05-08 03:35:57 -07:00
|
|
|
|
|
|
|
edje_cc_command = eina_strbuf_string_steal(buf);
|
|
|
|
|
|
|
|
eina_strbuf_free(buf);
|
|
|
|
|
2012-09-17 02:38:20 -07:00
|
|
|
rebuild(NULL);
|
2012-05-08 03:35:57 -07:00
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
2012-05-11 03:50:47 -07:00
|
|
|
unlink(watchfile);
|
|
|
|
|
2012-05-08 03:35:57 -07:00
|
|
|
eio_shutdown();
|
|
|
|
ecore_shutdown();
|
|
|
|
eina_shutdown();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|