changeset 11:128af06c876c

Fix the bug that data of a path end with white spaces would make system down
author Thinker K.F. Li <thinker@branda.to>
date Sat, 26 Jul 2008 06:34:15 +0800
parents 7cfecdce94cc
children 79e9edf4c00a
files src/X_main.c src/mb_types.h src/shape_path.c
diffstat 3 files changed, 27 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/X_main.c	Sat Jul 26 05:32:31 2008 +0800
+++ b/src/X_main.c	Sat Jul 26 06:34:15 2008 +0800
@@ -12,13 +12,13 @@
     shape_t *path;
     coord_t coord;
 
-    path = sh_path_new("m80 80 c 20 5 -30 20 10 30 t -30 0 z");
+    path = sh_path_new("M 22,89.36218 C -34,-0.63782 39,-9.637817 82,12.36218 C 125,34.36218 142,136.36218 142,136.36218 C 100.66667,125.36218 74.26756,123.42795 22,89.36218 z ");
     memset(coord.aggr_matrix, 0, sizeof(co_aix) * 6);
-    coord.aggr_matrix[0] = 1;
-    coord.aggr_matrix[1] = 0.5;
-    coord.aggr_matrix[2] = -30;
-    coord.aggr_matrix[4] = 1;
-    coord.aggr_matrix[5] = -20;
+    coord.aggr_matrix[0] = 0.8;
+    coord.aggr_matrix[1] = 0;
+    coord.aggr_matrix[2] = 20;
+    coord.aggr_matrix[4] = 0.8;
+    coord.aggr_matrix[5] = 20;
     sh_path_transform(path, &coord);
     sh_path_draw(path, cr);
 }
--- a/src/mb_types.h	Sat Jul 26 05:32:31 2008 +0800
+++ b/src/mb_types.h	Sat Jul 26 06:34:15 2008 +0800
@@ -2,6 +2,7 @@
 #define __MB_TYPES_H_
 
 typedef float co_aix;
+typedef struct _shape shape_t;
 
 /*! \brief A coordination system.
  *
@@ -17,14 +18,16 @@
     co_aix aggr_matrix[6];
     struct _coord *parent;
     struct _coord *children, *sibling;
+    shape_t *members;
 } coord_t;
 
 
 typedef struct _geo geo_t;
-typedef struct _shape {
+struct _shape {
     int sh_type;
     geo_t *geo;
-} shape_t;
+    struct _shape *sibling;
+};
 
 enum { SHT_UNKNOW, SHT_PATH, SHT_TEXT };
 
--- a/src/shape_path.c	Sat Jul 26 05:32:31 2008 +0800
+++ b/src/shape_path.c	Sat Jul 26 06:34:15 2008 +0800
@@ -21,12 +21,13 @@
 #define RESERVED_AIXS sizeof(co_aix[2])
 
 #define ASSERT(x)
-#define SKIP_SPACE(x) while(*(x) && isspace(*(x))) { (x)++; }
+#define SKIP_SPACE(x) while(*(x) && (isspace(*(x)) || *(x) == ',')) { (x)++; }
 #define SKIP_NUM(x)					\
     while(*(x) &&					\
 	  (isdigit(*(x)) ||				\
 	   *(x) == '-' ||				\
-	   *(x) == '+'))  {				\
+	   *(x) == '+' ||				\
+	   *(x) == '.'))  {					\
 	(x)++;						\
     }
 #define OK 0
@@ -47,9 +48,8 @@
 
     cmd_cnt = arg_cnt = 0;
     p = data;
+    SKIP_SPACE(p);
     while(*p) {
-	SKIP_SPACE(p);
-
 	switch(*p++) {
 	case 'c':
 	case 'C':
@@ -175,6 +175,7 @@
 	    return ERR;
 	}
 	cmd_cnt++;
+	SKIP_SPACE(p);
     }
 
     *cmd_cntp = cmd_cnt;
@@ -193,9 +194,8 @@
     cmds = path->user_data;
     args = (co_aix *)(cmds + path->cmd_len);
     p = data;
+    SKIP_SPACE(p);
     while(*p) {
-	SKIP_SPACE(p);
-
 	/* Transform all relative to absolute, */
 	*cmds++ = toupper(*p);
 	switch((cmd = *p++)) {
@@ -327,6 +327,7 @@
 	default:
 	    return ERR;
 	}
+	SKIP_SPACE(p);
     }
 
     return OK;
@@ -593,6 +594,15 @@
     sh_path_free((shape_t *)path);
 }
 
+void test_spaces_head_tail(void) {
+    sh_path_t *path;
+
+    path = (sh_path_t *)
+	sh_path_new(" M 33 25l33 55C 33 87 44 22 55 99L33 77z ");
+    CU_ASSERT(path != NULL);
+    sh_path_free((shape_t *)path);
+}
+
 CU_pSuite get_shape_path_suite(void) {
     CU_pSuite suite;