# HG changeset patch # User Thinker K.F. Li # Date 1217025255 -28800 # Node ID 128af06c876c334e5d76d58e1713b374ba3546d5 # Parent 7cfecdce94cc5606d618c08237f7b8a5d81d3fdb Fix the bug that data of a path end with white spaces would make system down diff -r 7cfecdce94cc -r 128af06c876c src/X_main.c --- 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); } diff -r 7cfecdce94cc -r 128af06c876c src/mb_types.h --- 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 }; diff -r 7cfecdce94cc -r 128af06c876c src/shape_path.c --- 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;