diff options
author | William Wilgus <wilgus.william@gmail.com> | 2023-10-03 21:54:19 -0400 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2023-10-03 21:54:19 -0400 |
commit | 6634a60bf0750159ffc34bdff548fac0817e72bc (patch) | |
tree | f91cd7b74cb518c57735ce22cb668f2737cb3fc7 | |
parent | eee48dca39cbbe3cf4ad13bcf1d90bb3492151e5 (diff) | |
download | rockbox-6634a60bf0.tar.gz rockbox-6634a60bf0.zip |
tagcache/tagtree remove static buffer from tagcache_get_next
callers can supply their own buffer
Change-Id: I8996ecfb88e30926296a0cb0563cf6c46977323e
-rw-r--r-- | apps/plugin.c | 15 | ||||
-rw-r--r-- | apps/plugin.h | 29 | ||||
-rw-r--r-- | apps/plugins/pictureflow/pictureflow.c | 25 | ||||
-rw-r--r-- | apps/tagcache.c | 23 | ||||
-rw-r--r-- | apps/tagcache.h | 6 | ||||
-rw-r--r-- | apps/tagtree.c | 6 |
6 files changed, 56 insertions, 48 deletions
diff --git a/apps/plugin.c b/apps/plugin.c index da4d3432f5..b1188fc183 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -351,6 +351,7 @@ static const struct plugin_api rockbox_api = { yesno_pop, /* action handling */ + list_do_action, get_custom_action, get_action, #ifdef HAVE_TOUCHSCREEN @@ -443,6 +444,7 @@ static const struct plugin_api rockbox_api = { /* talking */ talk_id, + talk_idarray, talk_file, talk_file_or_spell, talk_dir_or_spell, @@ -546,6 +548,7 @@ static const struct plugin_api rockbox_api = { /* strings and memory */ snprintf, vsnprintf, + vuprintf, strcpy, strlcpy, strlen, @@ -568,6 +571,7 @@ static const struct plugin_api rockbox_api = { memcmp, strcasestr, strtok_r, + output_dyn_value, /* unicode stuff */ utf8decode, iso_decode, @@ -687,6 +691,8 @@ static const struct plugin_api rockbox_api = { /* playback control */ playlist_get_current, + playlist_get_resume_info, + playlist_get_track_info, playlist_amount, playlist_resume, playlist_resume_track, @@ -769,7 +775,7 @@ static const struct plugin_api rockbox_api = { #if CONFIG_RTC mktime, #endif - + format_time_auto, #if defined(DEBUG) || defined(SIMULATOR) debugf, #endif @@ -827,13 +833,6 @@ static const struct plugin_api rockbox_api = { /* new stuff at the end, sort into place next time the API gets incompatible */ - format_time_auto, - output_dyn_value, - playlist_get_resume_info, - playlist_get_track_info, - list_do_action, - talk_idarray, - }; static int plugin_buffer_handle; diff --git a/apps/plugin.h b/apps/plugin.h index b6dff14b1f..11adf61e9c 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -114,6 +114,7 @@ int plugin_open(const char *plugin, const char *parameter); #include "screen_access.h" #include "onplay.h" #include "screens.h" +#include "vuprintf.h" #ifdef HAVE_ALBUMART #include "albumart.h" @@ -162,7 +163,7 @@ int plugin_open(const char *plugin, const char *parameter); * when this happens please take the opportunity to sort in * any new functions "waiting" at the end of the list. */ -#define PLUGIN_API_VERSION 269 +#define PLUGIN_API_VERSION 270 /* 239 Marks the removal of ARCHOS HWCODEC and CHARCELL */ @@ -404,6 +405,8 @@ struct plugin_api { bool (*yesno_pop)(const char* text); /* action handling */ + bool (*list_do_action)(int context, int timeout, + struct gui_synclist *lists, int *action); int (*get_custom_action)(int context,int timeout, const struct button_mapping* (*get_context_map)(int)); int (*get_action)(int context, int timeout); @@ -504,6 +507,7 @@ struct plugin_api { /* talking */ int (*talk_id)(int32_t id, bool enqueue); + int (*talk_idarray)(const long *idarray, bool enqueue); int (*talk_file)(const char *root, const char *dir, const char *file, const char *ext, const long *prefix_ids, bool enqueue); int (*talk_file_or_spell)(const char *dirname, const char* filename, @@ -623,6 +627,7 @@ struct plugin_api { int (*snprintf)(char *buf, size_t size, const char *fmt, ...) ATTRIBUTE_PRINTF(3, 4); int (*vsnprintf)(char *buf, size_t size, const char *fmt, va_list ap); + int (*vuprintf)(vuprintf_push_cb push, void *userp, const char *fmt, va_list ap); char* (*strcpy)(char *dst, const char *src); size_t (*strlcpy)(char *dst, const char *src, size_t length); size_t (*strlen)(const char *str); @@ -645,6 +650,9 @@ struct plugin_api { int (*memcmp)(const void *s1, const void *s2, size_t n); char *(*strcasestr) (const char* phaystack, const char* pneedle); char* (*strtok_r)(char *ptr, const char *sep, char **end); + char* (*output_dyn_value)(char *buf, int buf_size, int value, + const unsigned char * const *units, + unsigned int unit_count, bool binary_scale); /* unicode stuff */ const unsigned char* (*utf8decode)(const unsigned char *utf8, unsigned short *ucs); unsigned char* (*iso_decode)(const unsigned char *iso, unsigned char *utf8, int cp, int count); @@ -768,7 +776,7 @@ struct plugin_api { void *buffer, long length); bool (*tagcache_search_add_filter)(struct tagcache_search *tcs, int tag, int seek); - bool (*tagcache_get_next)(struct tagcache_search *tcs); + bool (*tagcache_get_next)(struct tagcache_search *tcs, char *buf, long size); bool (*tagcache_retrieve)(struct tagcache_search *tcs, int idxid, int tag, char *buf, long size); void (*tagcache_search_finish)(struct tagcache_search *tcs); @@ -790,6 +798,9 @@ struct plugin_api { /* playback control */ struct playlist_info* (*playlist_get_current)(void); + int (*playlist_get_resume_info)(int *resume_index); + int (*playlist_get_track_info)(struct playlist_info* playlist, int index, + struct playlist_track_info* info); int (*playlist_amount)(void); int (*playlist_resume)(void); void (*playlist_resume_track)(int start_index, unsigned int crc, @@ -896,7 +907,8 @@ struct plugin_api { #if CONFIG_RTC time_t (*mktime)(struct tm *t); #endif - + const char* (*format_time_auto)(char *buffer, int buf_len, long value, + int unit_idx, bool supress_unit); #if defined(DEBUG) || defined(SIMULATOR) void (*debugf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2); #endif @@ -958,17 +970,6 @@ struct plugin_api { /* new stuff at the end, sort into place next time the API gets incompatible */ - const char* (*format_time_auto)(char *buffer, int buf_len, long value, - int unit_idx, bool supress_unit); - char* (*output_dyn_value)(char *buf, int buf_size, int value, - const unsigned char * const *units, - unsigned int unit_count, bool binary_scale); - int (*playlist_get_resume_info)(int *resume_index); - int (*playlist_get_track_info)(struct playlist_info* playlist, int index, - struct playlist_track_info* info); - bool (*list_do_action)(int context, int timeout, - struct gui_synclist *lists, int *action); - int (*talk_idarray)(const long *idarray, bool enqueue); }; /* plugin header */ diff --git a/apps/plugins/pictureflow/pictureflow.c b/apps/plugins/pictureflow/pictureflow.c index 1c380c7f28..87ad1a403f 100644 --- a/apps/plugins/pictureflow/pictureflow.c +++ b/apps/plugins/pictureflow/pictureflow.c @@ -1141,6 +1141,8 @@ static void write_artist_entry(struct tagcache_search *tcs, static int get_tcs_search_res(int type, struct tagcache_search *tcs, void **buf, size_t *bufsz) { + char tcs_buf[TAGCACHE_BUFSZ]; + const long tcs_bufsz = sizeof(tcs_buf); int ret = SUCCESS; unsigned int l, name_idx = 0; void (*writefn)(struct tagcache_search *, int, unsigned int); @@ -1156,7 +1158,7 @@ static int get_tcs_search_res(int type, struct tagcache_search *tcs, data_size = sizeof(struct album_data); } - while (rb->tagcache_get_next(tcs)) + while (rb->tagcache_get_next(tcs, tcs_buf, tcs_bufsz)) { if (rb->button_get(false) > BUTTON_NONE) { @@ -1196,6 +1198,8 @@ static int get_tcs_search_res(int type, struct tagcache_search *tcs, static int create_album_untagged(struct tagcache_search *tcs, void **buf, size_t *bufsz) { + static char tcs_buf[TAGCACHE_BUFSZ]; + const long tcs_bufsz = sizeof(tcs_buf); int ret = SUCCESS; int album_count = pf_idx.album_ct; /* store existing count */ int total_count = pf_idx.album_ct + pf_idx.artist_ct * 2; @@ -1210,7 +1214,7 @@ static int create_album_untagged(struct tagcache_search *tcs, { rb->tagcache_search_add_filter(tcs, tag_album, pf_idx.album_untagged_seek); - while (rb->tagcache_get_next(tcs)) + while (rb->tagcache_get_next(tcs, tcs_buf, tcs_bufsz)) { if (rb->button_get(false) > BUTTON_NONE) { if (confirm_quit()) @@ -1339,6 +1343,8 @@ static int build_artist_index(struct tagcache_search *tcs, static int assign_album_year(void) { + char tcs_buf[TAGCACHE_BUFSZ]; + const long tcs_bufsz = sizeof(tcs_buf); draw_progressbar(0, pf_idx.album_ct, "Assigning Album Year"); for (int album_idx = 0; album_idx < pf_idx.album_ct; album_idx++) { @@ -1367,7 +1373,7 @@ static int assign_album_year(void) rb->tagcache_search_add_filter(&tcs, tag_albumartist, pf_idx.album_index[album_idx].artist_seek); - while (rb->tagcache_get_next(&tcs)) { + while (rb->tagcache_get_next(&tcs, tcs_buf, tcs_bufsz)) { int track_year = rb->tagcache_get_numeric(&tcs, tag_year); if (track_year > album_year) album_year = track_year; @@ -1386,6 +1392,8 @@ static int assign_album_year(void) */ static int create_album_index(void) { + static char tcs_buf[TAGCACHE_BUFSZ]; + const long tcs_bufsz = sizeof(tcs_buf); void *buf = pf_idx.buf; size_t buf_size = pf_idx.buf_sz; @@ -1463,7 +1471,7 @@ static int create_album_index(void) last = 0; final = pf_idx.artist_ct; retry = 0; - if (rb->tagcache_get_next(&tcs)) + if (rb->tagcache_get_next(&tcs, tcs_buf, tcs_bufsz)) { retry_artist_lookup: @@ -1981,6 +1989,8 @@ static int pf_tcs_retrieve_file_name(int fn_idx) */ static void create_track_index(const int slide_index) { + char tcs_buf[TAGCACHE_BUFSZ]; + const long tcs_bufsz = sizeof(tcs_buf); buf_ctx_lock(); if ( slide_index == pf_tracks.cur_idx ) return; @@ -1998,7 +2008,7 @@ static void create_track_index(const int slide_index) int string_index = 0; pf_tracks.count = 0; - while (rb->tagcache_get_next(&tcs)) + while (rb->tagcache_get_next(&tcs, tcs_buf, tcs_bufsz)) { int disc_num = rb->tagcache_get_numeric(&tcs, tag_discnumber); int track_num = rb->tagcache_get_numeric(&tcs, tag_tracknumber); @@ -2073,7 +2083,8 @@ static bool get_albumart_for_index_from_db(const int slide_index, char *buf, int buflen) { bool ret; - + char tcs_buf[TAGCACHE_BUFSZ]; + const long tcs_bufsz = sizeof(tcs_buf); if (tcs.valid || !rb->tagcache_search(&tcs, tag_filename)) return false; @@ -2084,7 +2095,7 @@ static bool get_albumart_for_index_from_db(const int slide_index, char *buf, rb->tagcache_search_add_filter(&tcs, tag_albumartist, pf_idx.album_index[slide_index].artist_seek); - ret = rb->tagcache_get_next(&tcs) && + ret = rb->tagcache_get_next(&tcs, tcs_buf, tcs_bufsz) && retrieve_id3(&id3, tcs.result) && search_albumart_files(&id3, ":", buf, buflen); diff --git a/apps/tagcache.c b/apps/tagcache.c index e60732fb65..170a066a36 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -102,9 +102,6 @@ */ #define TAGCACHE_SUPPORT_FOREIGN_ENDIAN -/* Maximum length of a single tag. */ -#define TAG_MAXLEN (MAX_PATH*2) - /* Allow a little drift to the filename ordering (should not be too high/low). */ #define POS_HISTORY_COUNT 4 @@ -169,9 +166,6 @@ static struct event_queue tagcache_queue SHAREDBSS_ATTR; static long tagcache_stack[(DEFAULT_STACK_SIZE + 0x4000)/sizeof(long)]; static const char tagcache_thread_name[] = "tagcache"; #endif -/* buffer size for all the (stack allocated & static) buffers handling tc data */ -#define TAGCACHE_BUFSZ (TAG_MAXLEN+32) - /* Previous path when scanning directory tree recursively. */ static char curpath[TAGCACHE_BUFSZ]; @@ -1849,11 +1843,8 @@ bool tagcache_search_add_clause(struct tagcache_search *tcs, return true; } -static bool get_next(struct tagcache_search *tcs, bool is_numeric) +static bool get_next(struct tagcache_search *tcs, bool is_numeric, char *buf, long bufsz) { - /* WARNING pointers into buf are used in outside functions */ - static char buf[TAGCACHE_BUFSZ]; - const int bufsz = sizeof(buf); struct tagfile_entry entry; #if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE) long flag = 0; @@ -2001,12 +1992,12 @@ static bool get_next(struct tagcache_search *tcs, bool is_numeric) return true; } -bool tagcache_get_next(struct tagcache_search *tcs) +bool tagcache_get_next(struct tagcache_search *tcs, char *buf, long size) { if (tcs->valid && tagcache_is_usable()) { bool is_numeric = TAGCACHE_IS_NUMERIC(tcs->type); - while (get_next(tcs, is_numeric)) + while (get_next(tcs, is_numeric, buf, size)) { if (tcs->result_len > 1) return true; @@ -3971,8 +3962,6 @@ static bool delete_entry(long idx_id) int tag, i; struct index_entry idx, myidx; struct master_header myhdr; - char buf[TAGCACHE_BUFSZ]; - const int bufsz = sizeof(buf); int in_use[TAG_COUNT]; logf("delete_entry(): %ld", idx_id); @@ -4081,7 +4070,8 @@ static bool delete_entry(long idx_id) /* Skip the header block */ lseek(fd, myidx.tag_seek[tag], SEEK_SET); - switch (read_tagfile_entry_and_tag(fd, &tfe, buf, bufsz)) + switch (read_tagfile_entry_and_tag(fd, &tfe, + build_idx_buf, build_idx_bufsz)) { case e_SUCCESS_LEN_ZERO: logf("deleted_entry(): SUCCESS"); @@ -4099,7 +4089,8 @@ static bool delete_entry(long idx_id) goto cleanup; } - myidx.tag_seek[tag] = crc_32(buf, strlen(buf), 0xffffffff); + myidx.tag_seek[tag] = crc_32(build_idx_buf, + strlen(build_idx_buf), 0xffffffff); } if (in_use[tag]) diff --git a/apps/tagcache.h b/apps/tagcache.h index 3b4df999b9..9cf796fafd 100644 --- a/apps/tagcache.h +++ b/apps/tagcache.h @@ -53,6 +53,10 @@ enum tag_type { tag_artist = 0, tag_album, tag_genre, tag_title, /* Tag to be used on untagged files. */ #define UNTAGGED "<Untagged>" +/* Maximum length of a single tag. */ +#define TAG_MAXLEN (MAX_PATH*2) +/* buffer size for all the (stack allocated & static) buffers handling tc data */ +#define TAGCACHE_BUFSZ (TAG_MAXLEN+32) /* Numeric tags (we can use these tags with conditional clauses). */ #define TAGCACHE_NUMERIC_TAGS ((1LU << tag_year) | (1LU << tag_discnumber) | \ @@ -172,7 +176,7 @@ bool tagcache_search_add_filter(struct tagcache_search *tcs, int tag, int seek); bool tagcache_search_add_clause(struct tagcache_search *tcs, struct tagcache_search_clause *clause); -bool tagcache_get_next(struct tagcache_search *tcs); +bool tagcache_get_next(struct tagcache_search *tcs, char *buf, long size); bool tagcache_retrieve(struct tagcache_search *tcs, int idxid, int tag, char *buf, long size); void tagcache_search_finish(struct tagcache_search *tcs); diff --git a/apps/tagtree.c b/apps/tagtree.c index 78bf6bf255..542b0bb120 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -1448,6 +1448,8 @@ static void tcs_get_basename(struct tagcache_search *tcs, bool is_basename) static int retrieve_entries(struct tree_context *c, int offset, bool init) { + char tcs_buf[TAGCACHE_BUFSZ]; + const long tcs_bufsz = sizeof(tcs_buf); struct tagcache_search tcs; struct display_format *fmt; int i; @@ -1584,7 +1586,7 @@ static int retrieve_entries(struct tree_context *c, int offset, bool init) total_count += 2; } - while (tagcache_get_next(&tcs)) + while (tagcache_get_next(&tcs, tcs_buf, tcs_bufsz)) { if (total_count++ < offset) continue; @@ -1729,7 +1731,7 @@ entry_skip_formatter: return current_entry_count; } - while (tagcache_get_next(&tcs)) + while (tagcache_get_next(&tcs, tcs_buf, tcs_bufsz)) { if (!show_search_progress(false, total_count)) break; |