cleaner. centralise type parsing... and error checking
SVN revision: 7017
This commit is contained in:
parent
dd7fe79b30
commit
228f197d2b
|
@ -15,6 +15,7 @@
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
typedef struct _New_Object_Handler New_Object_Handler;
|
typedef struct _New_Object_Handler New_Object_Handler;
|
||||||
typedef struct _New_Statement_Handler New_Statement_Handler;
|
typedef struct _New_Statement_Handler New_Statement_Handler;
|
||||||
|
@ -37,6 +38,13 @@ void compile(void);
|
||||||
int object_handler_num(void);
|
int object_handler_num(void);
|
||||||
int statement_handler_num(void);
|
int statement_handler_num(void);
|
||||||
|
|
||||||
|
char *parse_str(int n);
|
||||||
|
int parse_enum(int n, ...);
|
||||||
|
int parse_int(int n);
|
||||||
|
int parse_int_range(int n, int f, int t);
|
||||||
|
double parse_float(int n);
|
||||||
|
double parse_float_range(int n, int f, int t);
|
||||||
|
|
||||||
extern Evas_List *img_dirs;
|
extern Evas_List *img_dirs;
|
||||||
extern char *file_in;
|
extern char *file_in;
|
||||||
extern char *file_out;
|
extern char *file_out;
|
||||||
|
|
|
@ -89,74 +89,38 @@ static void
|
||||||
st_images_image(void)
|
st_images_image(void)
|
||||||
{
|
{
|
||||||
Edje_Image_Directory_Entry *img;
|
Edje_Image_Directory_Entry *img;
|
||||||
char *str;
|
int v;
|
||||||
|
|
||||||
img = evas_list_data(evas_list_last(edje_file->image_dir->entries));
|
img = evas_list_data(evas_list_last(edje_file->image_dir->entries));
|
||||||
str = evas_list_nth(params, 0);
|
img->entry = parse_str(0);
|
||||||
if (str)
|
v = parse_enum(1,
|
||||||
|
"RAW", 0,
|
||||||
|
"COMP", 1,
|
||||||
|
"LOSSY", 2,
|
||||||
|
"USER", 3,
|
||||||
|
NULL);
|
||||||
|
if (v == 0)
|
||||||
{
|
{
|
||||||
img->entry = strdup(str);
|
img->source_type = EDJE_IMAGE_SOURCE_TYPE_INLINE_PERFECT;
|
||||||
if (!str)
|
img->source_param = 0;
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: Error. memory allocation of %i bytes failed. %s\n",
|
|
||||||
progname, strlen(str) + 1, strerror(errno));
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else if (v == 1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: Error. %s:%i: no filename for image as arg 1\n",
|
img->source_type = EDJE_IMAGE_SOURCE_TYPE_INLINE_PERFECT;
|
||||||
progname, file_in, line);
|
img->source_param = 1;
|
||||||
exit(-1);
|
|
||||||
}
|
}
|
||||||
str = evas_list_nth(params, 1);
|
else if (v == 2)
|
||||||
if (str)
|
|
||||||
{
|
{
|
||||||
if (!strcasecmp(str, "RAW"))
|
img->source_type = EDJE_IMAGE_SOURCE_TYPE_INLINE_LOSSY;
|
||||||
{
|
img->source_param = 0;
|
||||||
img->source_type = EDJE_IMAGE_SOURCE_TYPE_INLINE_PERFECT;
|
|
||||||
img->source_param = 0;
|
|
||||||
}
|
|
||||||
else if (!strcasecmp(str, "COMP"))
|
|
||||||
{
|
|
||||||
img->source_type = EDJE_IMAGE_SOURCE_TYPE_INLINE_PERFECT;
|
|
||||||
img->source_param = 1;
|
|
||||||
}
|
|
||||||
else if (!strcasecmp(str, "LOSSY"))
|
|
||||||
{
|
|
||||||
img->source_type = EDJE_IMAGE_SOURCE_TYPE_INLINE_LOSSY;
|
|
||||||
img->source_param = 0;
|
|
||||||
}
|
|
||||||
else if (!strcasecmp(str, "USER"))
|
|
||||||
{
|
|
||||||
img->source_type = EDJE_IMAGE_SOURCE_TYPE_EXTERNAL;
|
|
||||||
img->source_param = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: Error. %s:%i: invalid encoding \"%s\" for image as arg 2\n",
|
|
||||||
progname, file_in, line, str);
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else if (v == 3)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: Error. %s:%i: no encoding type for image as arg 2\n",
|
img->source_type = EDJE_IMAGE_SOURCE_TYPE_EXTERNAL;
|
||||||
progname, file_in, line);
|
img->source_param = 0;
|
||||||
exit(-1);
|
|
||||||
}
|
}
|
||||||
if (img->source_type != EDJE_IMAGE_SOURCE_TYPE_INLINE_LOSSY) return;
|
if (img->source_type != EDJE_IMAGE_SOURCE_TYPE_INLINE_LOSSY) return;
|
||||||
str = evas_list_nth(params, 2);
|
img->source_param = parse_int_range(2, 0, 100);
|
||||||
if (str)
|
|
||||||
{
|
|
||||||
img->source_param = atoi(str);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: Error. %s:%i: no encoding quality for lossy as arg 3\n",
|
|
||||||
progname, file_in, line);
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -348,3 +348,154 @@ compile(void)
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
parse_str(int n)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
char *s;
|
||||||
|
|
||||||
|
str = evas_list_nth(params, n);
|
||||||
|
if (!str)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: Error. %s:%i no parameter supplied as argument %i\n",
|
||||||
|
progname, file_in, line, n + 1);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
s = strdup(str);
|
||||||
|
if (!s)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: Error. memory allocation of %i bytes failed. %s\n",
|
||||||
|
progname, strlen(str) + 1, strerror(errno));
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
parse_enum(int n, ...)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
va_list va;
|
||||||
|
|
||||||
|
str = evas_list_nth(params, n);
|
||||||
|
if (!str)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: Error. %s:%i no parameter supplied as argument %i\n",
|
||||||
|
progname, file_in, line, n + 1);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
va_start(va, n);
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
char *s;
|
||||||
|
int v;
|
||||||
|
|
||||||
|
s = va_arg(va, char *);
|
||||||
|
if (!s)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: Error. %s:%i token %s not one of:",
|
||||||
|
progname, file_in, line, str);
|
||||||
|
va_start(va, n);
|
||||||
|
s = va_arg(va, char *);
|
||||||
|
while (s)
|
||||||
|
{
|
||||||
|
v = va_arg(va, int);
|
||||||
|
fprintf(stderr, " %s", s);
|
||||||
|
s = va_arg(va, char *);
|
||||||
|
if (!s) break;
|
||||||
|
}
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
va_end(va);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
v = va_arg(va, int);
|
||||||
|
if (!strcmp(s, str))
|
||||||
|
{
|
||||||
|
va_end(va);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
va_end(va);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
parse_int(int n)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
str = evas_list_nth(params, n);
|
||||||
|
if (!str)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: Error. %s:%i no parameter supplied as argument %i\n",
|
||||||
|
progname, file_in, line, n + 1);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
i = atoi(str);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
parse_int_range(int n, int f, int t)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
str = evas_list_nth(params, n);
|
||||||
|
if (!str)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: Error. %s:%i no parameter supplied as argument %i\n",
|
||||||
|
progname, file_in, line, n + 1);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
i = atoi(str);
|
||||||
|
if ((i < f) || (i > t))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: Error. %s:%i integer %i out of range of %i to %i inclusive\n",
|
||||||
|
progname, file_in, line, i, f, t);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
double
|
||||||
|
parse_float(int n)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
double i;
|
||||||
|
|
||||||
|
str = evas_list_nth(params, n);
|
||||||
|
if (!str)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: Error. %s:%i no parameter supplied as argument %i\n",
|
||||||
|
progname, file_in, line, n + 1);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
i = atof(str);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
double
|
||||||
|
parse_float_range(int n, int f, int t)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
double i;
|
||||||
|
|
||||||
|
str = evas_list_nth(params, n);
|
||||||
|
if (!str)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: Error. %s:%i no parameter supplied as argument %i\n",
|
||||||
|
progname, file_in, line, n + 1);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
i = atoi(str);
|
||||||
|
if ((i < f) || (i > t))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: Error. %s:%i integer %i out of range of %i to %i inclusive\n",
|
||||||
|
progname, file_in, line, i, f, t);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue