Enlightenment CVS committal
Author : raster
Project : e17
Module : libs/edje
Dir : e17/libs/edje/src/bin
Modified Files:
edje_cc.h edje_cc_handlers.c edje_cc_parse.c
Log Message:
cleaner. centralise type parsing... and error checking
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/edje/src/bin/edje_cc.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- edje_cc.h 11 Jun 2003 13:20:48 -0000 1.1
+++ edje_cc.h 12 Jun 2003 13:02:28 -0000 1.2
@@ -15,6 +15,7 @@
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <stdarg.h>
typedef struct _New_Object_Handler New_Object_Handler;
typedef struct _New_Statement_Handler New_Statement_Handler;
@@ -37,6 +38,13 @@
int object_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 char *file_in;
extern char *file_out;
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/edje/src/bin/edje_cc_handlers.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- edje_cc_handlers.c 11 Jun 2003 14:14:21 -0000 1.2
+++ edje_cc_handlers.c 12 Jun 2003 13:02:28 -0000 1.3
@@ -89,74 +89,38 @@
st_images_image(void)
{
Edje_Image_Directory_Entry *img;
- char *str;
+ int v;
img = evas_list_data(evas_list_last(edje_file->image_dir->entries));
- str = evas_list_nth(params, 0);
- if (str)
+ img->entry = parse_str(0);
+ v = parse_enum(1,
+ "RAW", 0,
+ "COMP", 1,
+ "LOSSY", 2,
+ "USER", 3,
+ NULL);
+ if (v == 0)
{
- img->entry = strdup(str);
- if (!str)
- {
- fprintf(stderr, "%s: Error. memory allocation of %i bytes failed. %s\n",
- progname, strlen(str) + 1, strerror(errno));
- exit(-1);
- }
+ img->source_type = EDJE_IMAGE_SOURCE_TYPE_INLINE_PERFECT;
+ img->source_param = 0;
}
- else
+ else if (v == 1)
{
- fprintf(stderr, "%s: Error. %s:%i: no filename for image as arg 1\n",
- progname, file_in, line);
- exit(-1);
+ img->source_type = EDJE_IMAGE_SOURCE_TYPE_INLINE_PERFECT;
+ img->source_param = 1;
}
- str = evas_list_nth(params, 1);
- if (str)
+ else if (v == 2)
{
- if (!strcasecmp(str, "RAW"))
- {
- 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);
- }
+ img->source_type = EDJE_IMAGE_SOURCE_TYPE_INLINE_LOSSY;
+ img->source_param = 0;
}
- else
+ else if (v == 3)
{
- fprintf(stderr, "%s: Error. %s:%i: no encoding type for image as arg 2\n",
- progname, file_in, line);
- exit(-1);
+ img->source_type = EDJE_IMAGE_SOURCE_TYPE_EXTERNAL;
+ img->source_param = 0;
}
if (img->source_type != EDJE_IMAGE_SOURCE_TYPE_INLINE_LOSSY) return;
- str = evas_list_nth(params, 2);
- 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);
- }
+ img->source_param = parse_int_range(2, 0, 100);
}
static void
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/edje/src/bin/edje_cc_parse.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- edje_cc_parse.c 11 Jun 2003 14:14:23 -0000 1.2
+++ edje_cc_parse.c 12 Jun 2003 13:02:28 -0000 1.3
@@ -348,3 +348,154 @@
}
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;
+}
-------------------------------------------------------
This SF.NET email is sponsored by: eBay
Great deals on office technology -- on eBay now! Click here:
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs