this patch attempts to cleanup the option parsing in client/main.c
I moved the theme path extracting code into utils.c/theme_normalize_path
I also moved the geometry extracting code into utils.c/atog_x and
utils.c/atog_y
Cheers,
Essien
Index: entrance/src/client/main.c
===================================================================
RCS file: /var/cvs/e/e17/apps/entrance/src/client/main.c,v
retrieving revision 1.81
diff -a -u -r1.81 main.c
--- entrance/src/client/main.c 25 Jun 2006 08:49:08 -0000 1.81
+++ entrance/src/client/main.c 27 Jun 2006 01:34:13 -0000
@@ -729,45 +729,23 @@
display = strdup(optarg);
break;
case 'g':
- t = strchr((const char *) optarg, 'x');
- if (!t || t >= (optarg + strlen(optarg)))
- {
- syslog(LOG_CRIT,
- "Invalid argument '%s' given for geometry. Exiting.",
- optarg);
- return (-1);
- }
- else
- {
- g_x = atoi((const char *) optarg);
- g_y = atoi((const char *) (t + 1));
- if (!g_x || !g_y)
- {
- syslog(LOG_CRIT,
- "Invalid argument '%s' given for geometry. Exiting.",
- optarg);
- return (-1);
- }
- fullscreen = 0;
- }
- break;
+ g_x = atog_x(optarg);
+ g_y = atog_y(optarg);
+
+ if (!g_x || !g_y)
+ {
+ syslog(LOG_CRIT,
+ "Invalid argument '%s' given for geometry. Exiting.",
+ optarg);
+ return (-1);
+ }
+
+ fullscreen = 0;
+ break;
case 't':
/* Allow arbitrary paths to theme files */
- t = strchr((const char *) optarg, '/');
- if (t)
- theme = strdup(optarg);
- else
- {
- theme = calloc(1, PATH_MAX);
- t = strrchr((const char *) optarg, '.');
- if (t && !strcmp(t, ".edj"))
- snprintf(theme, PATH_MAX, "%s/themes/%s", PACKAGE_DATA_DIR,
- optarg);
- else
- snprintf(theme, PATH_MAX, "%s/themes/%s.edj",
- PACKAGE_DATA_DIR, optarg);
- }
- break;
+ theme = theme_normalize_path(theme, optarg);
+ break;
case 'T':
testing = 1;
fullscreen = 0;
Index: entrance/src/client/util.c
===================================================================
RCS file: /var/cvs/e/e17/apps/entrance/src/client/util.c,v
retrieving revision 1.4
diff -a -u -r1.4 util.c
--- entrance/src/client/util.c 27 Jun 2004 19:33:28 -0000 1.4
+++ entrance/src/client/util.c 27 Jun 2006 01:34:16 -0000
@@ -1,3 +1,6 @@
+#include <string.h>
+#include <stdlib.h>
+#include "entrance.h"
#include "util.h"
#include <Evas.h>
@@ -74,3 +77,61 @@
if (ENTRANCE_DEBUG)
printf("%s\n", msg);
}
+
+char* theme_normalize_path(char *theme, const char * filename)
+{
+ char* t = strchr((const char *) filename, '/');
+ if (t)
+ theme = strdup(filename);
+ else
+ {
+ theme = calloc(1, PATH_MAX);
+ t = strrchr((const char *) filename, '.');
+ if (t && !strcmp(t, ".edj"))
+ snprintf(theme, PATH_MAX, "%s/themes/%s", PACKAGE_DATA_DIR,
+ filename);
+ else
+ snprintf(theme, PATH_MAX, "%s/themes/%s.edj",
+ PACKAGE_DATA_DIR, filename);
+ }
+
+ return theme;
+}
+
+
+char* gstr_is_valid(const char* gstr)
+{
+ char *t = strchr((const char *) gstr, 'x');
+ if (!t || t >= (gstr + strlen(gstr)))
+ {
+ return NULL;
+ }
+
+ return strdup(t);
+}
+
+/*atog_x (ascii to geometry) named after the manner of atoi*/
+int atog_x(const char* gstr) /*uhh.. i'm innocent honest :P*/
+{
+ char* sep = gstr_is_valid(gstr);
+
+ if(sep) {
+ free(sep);
+ return atoi((const char *) gstr);
+ } else {
+ return 0;
+ }
+}
+
+int atog_y(const char* gstr)
+{
+ char* sep = gstr_is_valid(gstr);
+
+ if(sep) {
+ int y = atoi((const char *) (sep + 1));
+ free(sep);
+ return y;
+ } else {
+ return 0;
+ }
+}
Index: entrance/src/client/util.h
===================================================================
RCS file: /var/cvs/e/e17/apps/entrance/src/client/util.h,v
retrieving revision 1.4
diff -a -u -r1.4 util.h
--- entrance/src/client/util.h 16 Aug 2005 04:03:27 -0000 1.4
+++ entrance/src/client/util.h 27 Jun 2006 01:34:16 -0000
@@ -19,4 +19,9 @@
void entrance_edje_object_resize_intercept_cb(void *data, Evas_Object * o,
Evas_Coord w, Evas_Coord h);
+char* theme_normalize_path(char*, const char*);
+
+int atog_x(const char*);
+int atog_y(const char*);
+
#endif
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel