forked from enlightenment/efl
edje_cc_out.c: Splitting data_write_scripts() in smaller pieces.
Now we have one function for creating the script file and another for compiling it. Also tried to avoid lots of nesting by checking for error conditions early and returning (or aborting). Avoided messing with the code logic. SVN revision: 35595
This commit is contained in:
parent
e2d17e6ddf
commit
5d229801fd
|
@ -613,44 +613,21 @@ data_write_groups(Eet_File *ef, int *collection_num)
|
|||
}
|
||||
|
||||
static void
|
||||
data_write_scripts(Eet_File *ef)
|
||||
create_script_file(Eet_File *ef, const char *filename, const Code *cd)
|
||||
{
|
||||
Evas_List *l;
|
||||
int i;
|
||||
FILE *f = fopen(filename, "wb");
|
||||
if (!f)
|
||||
{
|
||||
fprintf(stderr, "%s: Error. Unable to open temp file \"%s\" for script compilation \n",
|
||||
progname, filename);
|
||||
ABORT_WRITE(ef, file_out);
|
||||
}
|
||||
|
||||
for (i = 0, l = codes; l; l = l->next, i++)
|
||||
{
|
||||
Code *cd;
|
||||
int ln = 0;
|
||||
|
||||
cd = l->data;
|
||||
if ((cd->shared) || (cd->programs))
|
||||
{
|
||||
char tmpn[4096];
|
||||
int fd;
|
||||
char *tmpdir;
|
||||
|
||||
#ifdef HAVE_EVIL
|
||||
tmpdir = evil_tmpdir_get();
|
||||
#else
|
||||
tmpdir = "/tmp";
|
||||
#endif
|
||||
snprintf(tmpn, PATH_MAX, "%s/edje_cc.sma-tmp-XXXXXX", tmpdir);
|
||||
fd = mkstemp(tmpn);
|
||||
if (fd >= 0)
|
||||
{
|
||||
FILE *f;
|
||||
char buf[4096];
|
||||
char tmpo[4096];
|
||||
int ret;
|
||||
|
||||
f = fopen(tmpn, "wb");
|
||||
if (f)
|
||||
{
|
||||
Evas_List *ll;
|
||||
|
||||
fprintf(f, "#include <edje>\n");
|
||||
ln = 2;
|
||||
int ln = 2;
|
||||
|
||||
if (cd->shared)
|
||||
{
|
||||
while (ln < (cd->l1 - 1))
|
||||
|
@ -714,17 +691,23 @@ data_write_scripts(Eet_File *ef)
|
|||
ln += cp->l2 - cp->l1 + 1;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
close(fd);
|
||||
snprintf(tmpo, PATH_MAX, "%s/edje_cc.amx-tmp-XXXXXX", tmpdir);
|
||||
fd = mkstemp(tmpo);
|
||||
if (fd >= 0)
|
||||
|
||||
static void
|
||||
compile_script_file(Eet_File *ef, const char *source, const char *output,
|
||||
int script_num)
|
||||
{
|
||||
FILE *f;
|
||||
char buf[4096];
|
||||
int ret;
|
||||
|
||||
snprintf(buf, sizeof(buf),
|
||||
"embryo_cc -i %s/include -o %s %s",
|
||||
e_prefix_data_get(), tmpo, tmpn);
|
||||
e_prefix_data_get(), output, source);
|
||||
ret = system(buf);
|
||||
|
||||
/* accept warnings in the embryo code */
|
||||
if (ret < 0 || ret > 1)
|
||||
{
|
||||
|
@ -732,17 +715,22 @@ data_write_scripts(Eet_File *ef)
|
|||
progname);
|
||||
ABORT_WRITE(ef, file_out);
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
f = fopen(tmpo, "rb");
|
||||
if (f)
|
||||
|
||||
f = fopen(output, "rb");
|
||||
if (!f)
|
||||
{
|
||||
fprintf(stderr, "%s: Error. Unable to open script object \"%s\" for reading \n",
|
||||
progname, output);
|
||||
ABORT_WRITE(ef, file_out);
|
||||
}
|
||||
|
||||
int size;
|
||||
void *data;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
size = ftell(f);
|
||||
rewind(f);
|
||||
|
||||
if (size > 0)
|
||||
{
|
||||
int bt;
|
||||
|
@ -752,23 +740,68 @@ data_write_scripts(Eet_File *ef)
|
|||
{
|
||||
if (fread(data, size, 1, f) != 1)
|
||||
{
|
||||
fprintf(stderr, "%s: Error. unable to read all of script object \"%s\"\n",
|
||||
progname, tmpo);
|
||||
fprintf(stderr, "%s: Error. Unable to read all of script object \"%s\"\n",
|
||||
progname, output);
|
||||
ABORT_WRITE(ef, file_out);
|
||||
}
|
||||
snprintf(buf, sizeof(buf), "scripts/%i", i);
|
||||
snprintf(buf, sizeof(buf), "scripts/%i", script_num);
|
||||
bt = eet_write(ef, buf, data, size, 1);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static void
|
||||
data_write_scripts(Eet_File *ef)
|
||||
{
|
||||
Evas_List *l;
|
||||
int i;
|
||||
|
||||
#ifdef HAVE_EVIL
|
||||
char *tmpdir = evil_tmpdir_get();
|
||||
#else
|
||||
char *tmpdir = "/tmp";
|
||||
#endif
|
||||
|
||||
for (i = 0, l = codes; l; l = l->next, i++)
|
||||
{
|
||||
int fd;
|
||||
Code *cd = l->data;
|
||||
|
||||
if ((!cd->shared) && (!cd->programs))
|
||||
continue;
|
||||
|
||||
char tmpn[4096];
|
||||
snprintf(tmpn, PATH_MAX, "%s/edje_cc.sma-tmp-XXXXXX", tmpdir);
|
||||
fd = mkstemp(tmpn);
|
||||
if (fd < 0)
|
||||
{
|
||||
fprintf(stderr, "%s: Error. Unable to open temp file \"%s\" for script compilation \n",
|
||||
progname, tmpn);
|
||||
ABORT_WRITE(ef, file_out);
|
||||
}
|
||||
|
||||
create_script_file(ef, tmpn, cd);
|
||||
close(fd);
|
||||
|
||||
char tmpo[4096];
|
||||
snprintf(tmpo, PATH_MAX, "%s/edje_cc.amx-tmp-XXXXXX", tmpdir);
|
||||
fd = mkstemp(tmpo);
|
||||
if (fd < 0)
|
||||
{
|
||||
fprintf(stderr, "%s: Error. Unable to open temp file \"%s\" for script compilation \n",
|
||||
progname, tmpn);
|
||||
ABORT_WRITE(ef, file_out);
|
||||
}
|
||||
compile_script_file(ef, tmpn, tmpo, i);
|
||||
close(fd);
|
||||
|
||||
unlink(tmpn);
|
||||
unlink(tmpo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
data_write(void)
|
||||
|
|
Loading…
Reference in New Issue