edje_cc_out.c: Create an error_and_abort() function and use it.

SVN revision: 35596
This commit is contained in:
Caio Marcelo de Oliveira Filho 2008-08-21 03:58:11 +00:00
parent 5d229801fd
commit 0d378996c8
1 changed files with 89 additions and 134 deletions

View File

@ -88,6 +88,19 @@ static Evas_List *spectrum_slave_lookups= NULL;
unlink(file); \ unlink(file); \
exit(-1); exit(-1);
static void
error_and_abort(Eet_File *ef, const char *fmt, ...)
{
va_list ap;
fprintf(stderr, "%s: Error. ", progname);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
ABORT_WRITE(ef, file_out);
}
void void
data_setup(void) data_setup(void)
{ {
@ -115,26 +128,19 @@ check_image_part_desc (Edje_Part_Collection *pc, Edje_Part *ep,
return; return;
if (epd->image.id == -1) if (epd->image.id == -1)
{ error_and_abort(ef, "Collection %i: image attributes missing for "
fprintf(stderr, "%s: Error. collection %i: image attributes missing " "part \"%s\", description \"%s\" %f\n",
"for part \"%s\", description \"%s\" %f\n", pc->id, ep->name, epd->state.name, epd->state.value);
progname, pc->id, ep->name, epd->state.name, epd->state.value);
ABORT_WRITE(ef, file_out);
}
for (l = epd->image.tween_list; l; l = l->next) for (l = epd->image.tween_list; l; l = l->next)
{ {
Edje_Part_Image_Id *iid = l->data; Edje_Part_Image_Id *iid = l->data;
if (iid->id == -1) if (iid->id == -1)
{ error_and_abort(ef, "Collection %i: tween image id missing for "
fprintf(stderr, "%s: Error. collection %i: tween image id missing " "part \"%s\", description \"%s\" %f\n",
"for part \"%s\", description \"%s\" %f\n", pc->id, ep->name, epd->state.name, epd->state.value);
progname, pc->id, ep->name, epd->state.name, }
epd->state.value);
ABORT_WRITE(ef, file_out);
}
}
} }
static void static void
@ -144,11 +150,8 @@ check_part (Edje_Part_Collection *pc, Edje_Part *ep, Eet_File *ef)
Evas_List *l; Evas_List *l;
if (!epd) if (!epd)
{ error_and_abort(ef, "Collection %i: default description missing "
fprintf(stderr, "%s: Error. collection %i: default description missing " "for part \"%s\"\n", pc->id, ep->name);
"for part \"%s\"\n", progname, pc->id, ep->name);
ABORT_WRITE(ef, file_out);
}
if (ep->type == EDJE_PART_TYPE_IMAGE) if (ep->type == EDJE_PART_TYPE_IMAGE)
{ {
@ -170,12 +173,8 @@ check_program (Edje_Part_Collection *pc, Edje_Program *ep, Eet_File *ef)
case EDJE_ACTION_TYPE_DRAG_VAL_STEP: case EDJE_ACTION_TYPE_DRAG_VAL_STEP:
case EDJE_ACTION_TYPE_DRAG_VAL_PAGE: case EDJE_ACTION_TYPE_DRAG_VAL_PAGE:
if (!ep->targets) if (!ep->targets)
{ error_and_abort(ef, "Collection %i: target missing in program "
fprintf(stderr, "%s: Error. collection %i: " "\"%s\"\n", pc->id, ep->name);
"target missing in program %s\n",
progname, pc->id, ep->name);
ABORT_WRITE(ef, file_out);
}
break; break;
default: default:
break; break;
@ -186,13 +185,10 @@ static void
check_spectrum (Edje_Spectrum_Directory_Entry *se, Eet_File *ef) check_spectrum (Edje_Spectrum_Directory_Entry *se, Eet_File *ef)
{ {
if (!se->entry) if (!se->entry)
fprintf(stderr, "%s: Error. Spectrum missing a name.\n", progname); error_and_abort(ef, "Spectrum missing a name.\n");
else if (!se->color_list) else if (!se->color_list)
fprintf(stderr, "%s: Error. Spectrum %s is empty. At least one color must be given.", progname, se->entry); error_and_abort(ef, "Spectrum %s is empty. At least one color must be "
else "given.", se->entry);
return;
ABORT_WRITE(ef, file_out);
} }
static int static int
@ -214,11 +210,8 @@ data_write_header(Eet_File *ef)
} }
bytes = eet_data_write(ef, edd_edje_file, "edje_file", edje_file, 1); bytes = eet_data_write(ef, edd_edje_file, "edje_file", edje_file, 1);
if (bytes <= 0) if (bytes <= 0)
{ error_and_abort(ef, "Unable to write \"edje_file\" entry to \"%s\" \n",
fprintf(stderr, "%s: Error. unable to write \"edje_file\" entry to \"%s\" \n", file_out);
progname, file_out);
ABORT_WRITE(ef, file_out);
}
} }
if (verbose) if (verbose)
@ -258,11 +251,8 @@ data_write_fonts(Eet_File *ef, int *font_num, int *input_bytes, int *input_raw_b
if (fdata) if (fdata)
{ {
if (fread(fdata, pos, 1, f) != 1) if (fread(fdata, pos, 1, f) != 1)
{ error_and_abort(ef, "Unable to read all of font "
fprintf(stderr, "%s: Error. unable to read all of font file \"%s\"\n", "file \"%s\"\n", fn->file);
progname, fn->file);
ABORT_WRITE(ef, file_out);
}
fsize = pos; fsize = pos;
} }
fclose(f); fclose(f);
@ -286,11 +276,8 @@ data_write_fonts(Eet_File *ef, int *font_num, int *input_bytes, int *input_raw_b
if (fdata) if (fdata)
{ {
if (fread(fdata, pos, 1, f) != 1) if (fread(fdata, pos, 1, f) != 1)
{ error_and_abort(ef, "Unable to read all of font "
fprintf(stderr, "%s: Error. unable to read all of font file \"%s\"\n", "file \"%s\"\n", buf);
progname, buf);
ABORT_WRITE(ef, file_out);
}
fsize = pos; fsize = pos;
} }
fclose(f); fclose(f);
@ -300,9 +287,8 @@ data_write_fonts(Eet_File *ef, int *font_num, int *input_bytes, int *input_raw_b
} }
if (!fdata) if (!fdata)
{ {
fprintf(stderr, "%s: Error. unable to load font part \"%s\" entry to %s \n", error_and_abort(ef, "Unable to load font part \"%s\" entry "
progname, fn->file, file_out); "to %s \n", fn->file, file_out);
ABORT_WRITE(ef, file_out);
} }
else else
{ {
@ -311,18 +297,14 @@ data_write_fonts(Eet_File *ef, int *font_num, int *input_bytes, int *input_raw_b
snprintf(buf, sizeof(buf), "fonts/%s", fn->name); snprintf(buf, sizeof(buf), "fonts/%s", fn->name);
bytes = eet_write(ef, buf, fdata, fsize, 1); bytes = eet_write(ef, buf, fdata, fsize, 1);
if (bytes <= 0) if (bytes <= 0)
{ error_and_abort(ef, "Unable to write font part \"%s\" as \"%s\" "
fprintf(stderr, "%s: Error. unable to write font part \"%s\" as \"%s\" part entry to %s \n", "part entry to %s \n", fn->file, buf, file_out);
progname, fn->file, buf, file_out);
ABORT_WRITE(ef, file_out); *font_num += 1;
} total_bytes += bytes;
else *input_bytes += fsize;
{ *input_raw_bytes += fsize;
*font_num += 1;
total_bytes += bytes;
*input_bytes += fsize;
*input_raw_bytes += fsize;
}
if (verbose) if (verbose)
{ {
printf("%s: Wrote %9i bytes (%4iKb) for \"%s\" font entry \"%s\" compress: [real: %2.1f%%]\n", printf("%s: Wrote %9i bytes (%4iKb) for \"%s\" font entry \"%s\" compress: [real: %2.1f%%]\n",
@ -351,12 +333,12 @@ data_write_images(Eet_File *ef, int *image_num, int *input_bytes, int *input_raw
ecore_init(); ecore_init();
ecore_evas_init(); ecore_evas_init();
ee = ecore_evas_buffer_new(1, 1); ee = ecore_evas_buffer_new(1, 1);
if (!ee) if (!ee)
{ error_and_abort(ef, "Cannot create buffer engine canvas for image "
fprintf(stderr, "Error. cannot create buffer engine canvas for image load.\n"); "load.\n");
ABORT_WRITE(ef, file_out);
}
evas = ecore_evas_get(ee); evas = ecore_evas_get(ee);
for (l = edje_file->image_dir->entries; l; l = l->next) for (l = edje_file->image_dir->entries; l; l = l->next)
{ {
@ -467,23 +449,22 @@ data_write_images(Eet_File *ef, int *image_num, int *input_bytes, int *input_raw
im_alpha, im_alpha,
0, qual, 1); 0, qual, 1);
if (bytes <= 0) if (bytes <= 0)
{ error_and_abort(ef, "Unable to write image part "
fprintf(stderr, "%s: Error. unable to write image part \"%s\" as \"%s\" part entry to %s\n", "\"%s\" as \"%s\" part entry to "
progname, img->entry, buf, file_out); "%s\n", img->entry, buf,
ABORT_WRITE(ef, file_out); file_out);
}
else *image_num += 1;
{ total_bytes += bytes;
*image_num += 1;
total_bytes += bytes;
}
} }
else else
{ {
fprintf(stderr, "%s: Error. unable to load image for image part \"%s\" as \"%s\" part entry to %s\n", error_and_abort(ef, "Unable to load image for "
progname, img->entry, buf, file_out); "image part \"%s\" as \"%s\" part "
ABORT_WRITE(ef, file_out); "entry to %s\n", img->entry, buf,
file_out);
} }
if (verbose) if (verbose)
{ {
struct stat st; struct stat st;
@ -504,9 +485,8 @@ data_write_images(Eet_File *ef, int *image_num, int *input_bytes, int *input_raw
} }
else else
{ {
fprintf(stderr, "%s: Error. unable to load image for image \"%s\" part entry to %s. Missing PNG or JPEG loader modules for Evas or file does not exist, or is not readable.\n", error_and_abort(ef, "Unable to load image for image \"%s\" part entry to %s. Missing PNG or JPEG loader modules for Evas or file does not exist, or is not readable.\n",
progname, img->entry, file_out); img->entry, file_out);
ABORT_WRITE(ef, file_out);
} }
} }
} }
@ -532,11 +512,7 @@ check_groups_names(Eet_File *ef)
Edje_Part_Collection_Directory_Entry *de; Edje_Part_Collection_Directory_Entry *de;
de = l->data; de = l->data;
if (!de->entry) if (!de->entry)
{ error_and_abort(ef, "Collection %i: name missing.\n", de->id);
fprintf(stderr, "%s: Error. collection %i: name missing.\n",
progname, de->id);
ABORT_WRITE(ef, file_out);
}
} }
} }
@ -592,16 +568,12 @@ data_write_groups(Eet_File *ef, int *collection_num)
snprintf(buf, sizeof(buf), "collections/%i", pc->id); snprintf(buf, sizeof(buf), "collections/%i", pc->id);
bytes = eet_data_write(ef, edd_edje_part_collection, buf, pc, 1); bytes = eet_data_write(ef, edd_edje_part_collection, buf, pc, 1);
if (bytes <= 0) if (bytes <= 0)
{ error_and_abort(ef, "Error. Unable to write \"%s\" part entry "
fprintf(stderr, "%s: Error. unable to write \"%s\" part entry to %s \n", "to %s\n", buf, file_out);
progname, buf, file_out);
ABORT_WRITE(ef, file_out); *collection_num += 1;
} total_bytes += bytes;
else
{
*collection_num += 1;
total_bytes += bytes;
}
if (verbose) if (verbose)
{ {
printf("%s: Wrote %9i bytes (%4iKb) for \"%s\" collection entry\n", printf("%s: Wrote %9i bytes (%4iKb) for \"%s\" collection entry\n",
@ -617,11 +589,8 @@ create_script_file(Eet_File *ef, const char *filename, const Code *cd)
{ {
FILE *f = fopen(filename, "wb"); FILE *f = fopen(filename, "wb");
if (!f) if (!f)
{ error_and_abort(ef, "Unable to open temp file \"%s\" for script "
fprintf(stderr, "%s: Error. Unable to open temp file \"%s\" for script compilation \n", "compilation.\n", filename);
progname, filename);
ABORT_WRITE(ef, file_out);
}
Evas_List *ll; Evas_List *ll;
@ -710,40 +679,28 @@ compile_script_file(Eet_File *ef, const char *source, const char *output,
/* accept warnings in the embryo code */ /* accept warnings in the embryo code */
if (ret < 0 || ret > 1) if (ret < 0 || ret > 1)
{ error_and_abort(ef, "Compiling script code not clean.\n");
fprintf(stderr, "%s: Warning. Compiling script code not clean.\n",
progname);
ABORT_WRITE(ef, file_out);
}
f = fopen(output, "rb"); f = fopen(output, "rb");
if (!f) if (!f)
{ error_and_abort(ef, "Unable to open script object \"%s\" for reading.\n",
fprintf(stderr, "%s: Error. Unable to open script object \"%s\" for reading \n", output);
progname, output);
ABORT_WRITE(ef, file_out);
}
int size;
void *data;
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
size = ftell(f); int size = ftell(f);
rewind(f); rewind(f);
if (size > 0) if (size > 0)
{ {
int bt; int bt;
void *data = malloc(size);
data = malloc(size);
if (data) if (data)
{ {
if (fread(data, size, 1, f) != 1) if (fread(data, size, 1, f) != 1)
{ error_and_abort(ef, "Unable to read all of script object "
fprintf(stderr, "%s: Error. Unable to read all of script object \"%s\"\n", "\"%s\"\n", output);
progname, output);
ABORT_WRITE(ef, file_out);
}
snprintf(buf, sizeof(buf), "scripts/%i", script_num); snprintf(buf, sizeof(buf), "scripts/%i", script_num);
bt = eet_write(ef, buf, data, size, 1); bt = eet_write(ef, buf, data, size, 1);
free(data); free(data);
@ -777,11 +734,8 @@ data_write_scripts(Eet_File *ef)
snprintf(tmpn, PATH_MAX, "%s/edje_cc.sma-tmp-XXXXXX", tmpdir); snprintf(tmpn, PATH_MAX, "%s/edje_cc.sma-tmp-XXXXXX", tmpdir);
fd = mkstemp(tmpn); fd = mkstemp(tmpn);
if (fd < 0) if (fd < 0)
{ error_and_abort(ef, "Unable to open temp file \"%s\" for script "
fprintf(stderr, "%s: Error. Unable to open temp file \"%s\" for script compilation \n", "compilation.\n", tmpn);
progname, tmpn);
ABORT_WRITE(ef, file_out);
}
create_script_file(ef, tmpn, cd); create_script_file(ef, tmpn, cd);
close(fd); close(fd);
@ -791,10 +745,11 @@ data_write_scripts(Eet_File *ef)
fd = mkstemp(tmpo); fd = mkstemp(tmpo);
if (fd < 0) if (fd < 0)
{ {
fprintf(stderr, "%s: Error. Unable to open temp file \"%s\" for script compilation \n", unlink(tmpn);
progname, tmpn); error_and_abort(ef, "Unable to open temp file \"%s\" for script "
ABORT_WRITE(ef, file_out); "compilation.\n", tmpn);
} }
compile_script_file(ef, tmpn, tmpo, i); compile_script_file(ef, tmpn, tmpo, i);
close(fd); close(fd);
@ -819,7 +774,7 @@ data_write(void)
ef = eet_open(file_out, EET_FILE_MODE_WRITE); ef = eet_open(file_out, EET_FILE_MODE_WRITE);
if (!ef) if (!ef)
{ {
fprintf(stderr, "%s: Error. unable to open \"%s\" for writing output\n", fprintf(stderr, "%s: Error. Unable to open \"%s\" for writing output\n",
progname, file_out); progname, file_out);
exit(-1); exit(-1);
} }
@ -1013,7 +968,7 @@ data_process_lookups(void)
} }
if (!l) if (!l)
{ {
fprintf(stderr, "%s: Error. unable to find part name %s\n", fprintf(stderr, "%s: Error. Unable to find part name \"%s\".\n",
progname, pl->name); progname, pl->name);
exit(-1); exit(-1);
} }
@ -1041,7 +996,7 @@ data_process_lookups(void)
} }
if (!l) if (!l)
{ {
fprintf(stderr, "%s: Error. unable to find program name %s\n", fprintf(stderr, "%s: Error. Unable to find program name \"%s\".\n",
progname, pl->name); progname, pl->name);
exit(-1); exit(-1);
} }
@ -1066,7 +1021,7 @@ data_process_lookups(void)
} }
if (!l) if (!l)
{ {
fprintf(stderr, "%s: Error. unable to find group name %s\n", fprintf(stderr, "%s: Error. Unable to find group name \"%s\".\n",
progname, gl->name); progname, gl->name);
exit(-1); exit(-1);
} }
@ -1104,7 +1059,7 @@ data_process_lookups(void)
if (!l) if (!l)
{ {
fprintf(stderr, "%s: Error. unable to find image name %s\n", fprintf(stderr, "%s: Error. Unable to find image name \"%s\".\n",
progname, il->name); progname, il->name);
exit(-1); exit(-1);
} }