summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-06-20 19:32:56 +0000
committerThomas Martitz <kugel@rockbox.org>2011-06-20 19:32:56 +0000
commit316f9a0238794d5219db5b60bf28f79aa77c8966 (patch)
tree8567af79acb12414bd517f48a8bf649f1d511133
parent19d08c2664582bb37be960de16905b0444eac4c9 (diff)
downloadrockbox-316f9a0238794d5219db5b60bf28f79aa77c8966.tar.gz
rockbox-316f9a0238794d5219db5b60bf28f79aa77c8966.zip
tagtree: Refactor memory allocation to local functions.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30029 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/tagtree.c50
1 files changed, 32 insertions, 18 deletions
diff --git a/apps/tagtree.c b/apps/tagtree.c
index 0d690cea26..653fd6be93 100644
--- a/apps/tagtree.c
+++ b/apps/tagtree.c
@@ -175,6 +175,27 @@ static int current_entry_count;
175 175
176static struct tree_context *tc; 176static struct tree_context *tc;
177 177
178/* a few memory alloc helper */
179static void* tagtree_alloc(size_t size)
180{
181 return buffer_alloc(size);
182}
183
184static void* tagtree_alloc0(size_t size)
185{
186 void* ret = tagtree_alloc(size);
187 memset(ret, 0, size);
188 return ret;
189}
190
191static char* tagtree_strdup(const char* buf)
192{
193 size_t len = strlen(buf) + 1;
194 char* dest = tagtree_alloc(len);
195 strcpy(dest, buf);
196 return dest;
197}
198
178static int get_token_str(char *buf, int size) 199static int get_token_str(char *buf, int size)
179{ 200{
180 /* Find the start. */ 201 /* Find the start. */
@@ -346,13 +367,12 @@ static bool read_clause(struct tagcache_search_clause *clause)
346 if (i<ARRAYLEN(id3_to_search_mapping)) /* runtime search operand found */ 367 if (i<ARRAYLEN(id3_to_search_mapping)) /* runtime search operand found */
347 { 368 {
348 clause->source = source_runtime+i; 369 clause->source = source_runtime+i;
349 clause->str = buffer_alloc(SEARCHSTR_SIZE); 370 clause->str = tagtree_alloc(SEARCHSTR_SIZE);
350 } 371 }
351 else 372 else
352 { 373 {
353 clause->source = source_constant; 374 clause->source = source_constant;
354 clause->str = buffer_alloc(strlen(buf)+1); 375 clause->str = tagtree_strdup(buf);
355 strcpy(clause->str, buf);
356 } 376 }
357 377
358 if (TAGCACHE_IS_NUMERIC(clause->tag)) 378 if (TAGCACHE_IS_NUMERIC(clause->tag))
@@ -418,8 +438,7 @@ static int get_format_str(struct display_format *fmt)
418 if (get_token_str(buf, sizeof buf) < 0) 438 if (get_token_str(buf, sizeof buf) < 0)
419 return -10; 439 return -10;
420 440
421 fmt->formatstr = buffer_alloc(strlen(buf) + 1); 441 fmt->formatstr = tagtree_strdup(buf);
422 strcpy(fmt->formatstr, buf);
423 442
424 while (fmt->tag_count < MAX_TAGS) 443 while (fmt->tag_count < MAX_TAGS)
425 { 444 {
@@ -469,12 +488,12 @@ static int add_format(const char *buf)
469 strp = buf; 488 strp = buf;
470 489
471 if (formats[format_count] == NULL) 490 if (formats[format_count] == NULL)
472 formats[format_count] = buffer_alloc(sizeof(struct display_format)); 491 formats[format_count] = tagtree_alloc0(sizeof(struct display_format));
473 492
474 memset(formats[format_count], 0, sizeof(struct display_format));
475 if (get_format_str(formats[format_count]) < 0) 493 if (get_format_str(formats[format_count]) < 0)
476 { 494 {
477 logf("get_format_str() parser failed!"); 495 logf("get_format_str() parser failed!");
496 memset(formats[format_count], 0, sizeof(struct display_format));
478 return -4; 497 return -4;
479 } 498 }
480 499
@@ -496,7 +515,7 @@ static int add_format(const char *buf)
496 break; 515 break;
497 } 516 }
498 517
499 newclause = buffer_alloc(sizeof(struct tagcache_search_clause)); 518 newclause = tagtree_alloc(sizeof(struct tagcache_search_clause));
500 519
501 formats[format_count]->clause[clause_count] = newclause; 520 formats[format_count]->clause[clause_count] = newclause;
502 if (!read_clause(newclause)) 521 if (!read_clause(newclause))
@@ -560,7 +579,7 @@ static int get_condition(struct search_instruction *inst)
560 return false; 579 return false;
561 } 580 }
562 581
563 new_clause = buffer_alloc(sizeof(struct tagcache_search_clause)); 582 new_clause = tagtree_alloc(sizeof(struct tagcache_search_clause));
564 inst->clause[inst->tagorder_count][clause_count] = new_clause; 583 inst->clause[inst->tagorder_count][clause_count] = new_clause;
565 584
566 if (*strp == '|') 585 if (*strp == '|')
@@ -628,9 +647,8 @@ static bool parse_search(struct menu_entry *entry, const char *str)
628 } 647 }
629 648
630 /* Allocate a new menu unless link is found. */ 649 /* Allocate a new menu unless link is found. */
631 menus[menu_count] = buffer_alloc(sizeof(struct menu_root)); 650 menus[menu_count] = tagtree_alloc0(sizeof(struct menu_root));
632 new_menu = menus[menu_count]; 651 new_menu = menus[menu_count];
633 memset(new_menu, 0, sizeof(struct menu_root));
634 strlcpy(new_menu->id, buf, MAX_MENU_ID_SIZE); 652 strlcpy(new_menu->id, buf, MAX_MENU_ID_SIZE);
635 entry->link = menu_count; 653 entry->link = menu_count;
636 ++menu_count; 654 ++menu_count;
@@ -922,10 +940,9 @@ static int parse_line(int n, const char *buf, void *parameters)
922 940
923 if (menu == NULL) 941 if (menu == NULL)
924 { 942 {
925 menus[menu_count] = buffer_alloc(sizeof(struct menu_root)); 943 menus[menu_count] = tagtree_alloc0(sizeof(struct menu_root));
926 menu = menus[menu_count]; 944 menu = menus[menu_count];
927 ++menu_count; 945 ++menu_count;
928 memset(menu, 0, sizeof(struct menu_root));
929 strlcpy(menu->id, data, MAX_MENU_ID_SIZE); 946 strlcpy(menu->id, data, MAX_MENU_ID_SIZE);
930 } 947 }
931 948
@@ -970,10 +987,7 @@ static int parse_line(int n, const char *buf, void *parameters)
970 987
971 /* Allocate */ 988 /* Allocate */
972 if (menu->items[menu->itemcount] == NULL) 989 if (menu->items[menu->itemcount] == NULL)
973 { 990 menu->items[menu->itemcount] = tagtree_alloc0(sizeof(struct menu_entry));
974 menu->items[menu->itemcount] = buffer_alloc(sizeof(struct menu_entry));
975 memset(menu->items[menu->itemcount], 0, sizeof(struct menu_entry));
976 }
977 991
978 if (!parse_search(menu->items[menu->itemcount], buf)) 992 if (!parse_search(menu->items[menu->itemcount], buf))
979 return 0; 993 return 0;
@@ -1021,7 +1035,7 @@ void tagtree_init(void)
1021 if (rootmenu < 0) 1035 if (rootmenu < 0)
1022 rootmenu = 0; 1036 rootmenu = 0;
1023 1037
1024 uniqbuf = buffer_alloc(UNIQBUF_SIZE); 1038 uniqbuf = tagtree_alloc(UNIQBUF_SIZE);
1025 1039
1026 add_event(PLAYBACK_EVENT_TRACK_BUFFER, false, tagtree_buffer_event); 1040 add_event(PLAYBACK_EVENT_TRACK_BUFFER, false, tagtree_buffer_event);
1027 add_event(PLAYBACK_EVENT_TRACK_FINISH, false, tagtree_track_finish_event); 1041 add_event(PLAYBACK_EVENT_TRACK_FINISH, false, tagtree_track_finish_event);