Mercurial > MadButterfly
comparison src/shape_path.c @ 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 |
comparison
equal
deleted
inserted
replaced
10:7cfecdce94cc | 11:128af06c876c |
---|---|
19 char *dev_data; /* device space data */ | 19 char *dev_data; /* device space data */ |
20 } sh_path_t; | 20 } sh_path_t; |
21 #define RESERVED_AIXS sizeof(co_aix[2]) | 21 #define RESERVED_AIXS sizeof(co_aix[2]) |
22 | 22 |
23 #define ASSERT(x) | 23 #define ASSERT(x) |
24 #define SKIP_SPACE(x) while(*(x) && isspace(*(x))) { (x)++; } | 24 #define SKIP_SPACE(x) while(*(x) && (isspace(*(x)) || *(x) == ',')) { (x)++; } |
25 #define SKIP_NUM(x) \ | 25 #define SKIP_NUM(x) \ |
26 while(*(x) && \ | 26 while(*(x) && \ |
27 (isdigit(*(x)) || \ | 27 (isdigit(*(x)) || \ |
28 *(x) == '-' || \ | 28 *(x) == '-' || \ |
29 *(x) == '+')) { \ | 29 *(x) == '+' || \ |
30 *(x) == '.')) { \ | |
30 (x)++; \ | 31 (x)++; \ |
31 } | 32 } |
32 #define OK 0 | 33 #define OK 0 |
33 #define ERR -1 | 34 #define ERR -1 |
34 | 35 |
45 char *p, *old; | 46 char *p, *old; |
46 int cmd_cnt, arg_cnt; | 47 int cmd_cnt, arg_cnt; |
47 | 48 |
48 cmd_cnt = arg_cnt = 0; | 49 cmd_cnt = arg_cnt = 0; |
49 p = data; | 50 p = data; |
51 SKIP_SPACE(p); | |
50 while(*p) { | 52 while(*p) { |
51 SKIP_SPACE(p); | |
52 | |
53 switch(*p++) { | 53 switch(*p++) { |
54 case 'c': | 54 case 'c': |
55 case 'C': | 55 case 'C': |
56 while(*p) { | 56 while(*p) { |
57 old = p; | 57 old = p; |
173 break; | 173 break; |
174 default: | 174 default: |
175 return ERR; | 175 return ERR; |
176 } | 176 } |
177 cmd_cnt++; | 177 cmd_cnt++; |
178 SKIP_SPACE(p); | |
178 } | 179 } |
179 | 180 |
180 *cmd_cntp = cmd_cnt; | 181 *cmd_cntp = cmd_cnt; |
181 *arg_cntp = arg_cnt; | 182 *arg_cntp = arg_cnt; |
182 return OK; | 183 return OK; |
191 co_aix *args; | 192 co_aix *args; |
192 | 193 |
193 cmds = path->user_data; | 194 cmds = path->user_data; |
194 args = (co_aix *)(cmds + path->cmd_len); | 195 args = (co_aix *)(cmds + path->cmd_len); |
195 p = data; | 196 p = data; |
197 SKIP_SPACE(p); | |
196 while(*p) { | 198 while(*p) { |
197 SKIP_SPACE(p); | |
198 | |
199 /* Transform all relative to absolute, */ | 199 /* Transform all relative to absolute, */ |
200 *cmds++ = toupper(*p); | 200 *cmds++ = toupper(*p); |
201 switch((cmd = *p++)) { | 201 switch((cmd = *p++)) { |
202 case 'c': | 202 case 'c': |
203 case 'C': | 203 case 'C': |
325 case 'Z': | 325 case 'Z': |
326 break; | 326 break; |
327 default: | 327 default: |
328 return ERR; | 328 return ERR; |
329 } | 329 } |
330 SKIP_SPACE(p); | |
330 } | 331 } |
331 | 332 |
332 return OK; | 333 return OK; |
333 } | 334 } |
334 | 335 |
591 CU_ASSERT(args[10] == 34); | 592 CU_ASSERT(args[10] == 34); |
592 CU_ASSERT(args[11] == 154); | 593 CU_ASSERT(args[11] == 154); |
593 sh_path_free((shape_t *)path); | 594 sh_path_free((shape_t *)path); |
594 } | 595 } |
595 | 596 |
597 void test_spaces_head_tail(void) { | |
598 sh_path_t *path; | |
599 | |
600 path = (sh_path_t *) | |
601 sh_path_new(" M 33 25l33 55C 33 87 44 22 55 99L33 77z "); | |
602 CU_ASSERT(path != NULL); | |
603 sh_path_free((shape_t *)path); | |
604 } | |
605 | |
596 CU_pSuite get_shape_path_suite(void) { | 606 CU_pSuite get_shape_path_suite(void) { |
597 CU_pSuite suite; | 607 CU_pSuite suite; |
598 | 608 |
599 suite = CU_add_suite("Suite_shape_path", NULL, NULL); | 609 suite = CU_add_suite("Suite_shape_path", NULL, NULL); |
600 CU_ADD_TEST(suite, test_sh_path_new); | 610 CU_ADD_TEST(suite, test_sh_path_new); |