Skip to content

Commit 65f07d0

Browse files
committed
Rewrite list_* API to make more sense
1 parent 12d6876 commit 65f07d0

18 files changed

+74
-74
lines changed

animation.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,12 @@ void anim_push_context(void)
371371
pthread_mutex_lock(&anim_list.mutex);
372372
if(anim_list.first)
373373
{
374-
list_add(anim_list.first, &anim_list.inactive_ctx);
374+
list_add(&anim_list.inactive_ctx, anim_list.first);
375375
anim_list.first = anim_list.last = NULL;
376376
}
377377
else
378378
{
379-
list_add(&EMPTY_CONTEXT, &anim_list.inactive_ctx);
379+
list_add(&anim_list.inactive_ctx, &EMPTY_CONTEXT);
380380
}
381381
pthread_mutex_unlock(&anim_list.mutex);
382382
}
@@ -402,7 +402,7 @@ void anim_pop_context(void)
402402
last_active_ctx = last_active_ctx->next;
403403
anim_list.last = last_active_ctx;
404404
}
405-
list_rm_at(idx, &anim_list.inactive_ctx, NULL);
405+
list_rm_at(&anim_list.inactive_ctx, idx, NULL);
406406
pthread_mutex_unlock(&anim_list.mutex);
407407
}
408408

containers.c

+16-16
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int list_size(listItself list)
3333
return list_item_count(list)+1;
3434
}
3535

36-
void list_add(void *item, ptrToList list_p)
36+
void list_add(ptrToList list_p, void *item)
3737
{
3838
void ***list = (void***)list_p;
3939

@@ -48,7 +48,7 @@ void list_add(void *item, ptrToList list_p)
4848
(*list)[--i] = item;
4949
}
5050

51-
int list_add_from_list(listItself src_p, ptrToList list_p)
51+
int list_add_from_list(ptrToList list_p, listItself src_p)
5252
{
5353
void **src = (void**)src_p;
5454
void ***list = (void***)list_p;
@@ -71,7 +71,7 @@ int list_add_from_list(listItself src_p, ptrToList list_p)
7171
return len_src-1;
7272
}
7373

74-
int list_rm_opt(int reorder, void *item, ptrToList list_p, callback destroy_callback_p)
74+
int list_rm_opt(ptrToList list_p, void *item, callback destroy_callback_p, int reorder)
7575
{
7676
void ***list = (void***)list_p;
7777
callbackPtr destroy_callback = (callbackPtr)destroy_callback_p;
@@ -113,17 +113,17 @@ int list_rm_opt(int reorder, void *item, ptrToList list_p, callback destroy_call
113113
return -1;
114114
}
115115

116-
int list_rm(void *item, ptrToList list_p, callback destroy_callback_p)
116+
int list_rm(ptrToList list_p, void *item, callback destroy_callback_p)
117117
{
118-
return list_rm_opt(1, item, list_p, destroy_callback_p);
118+
return list_rm_opt(list_p, item, destroy_callback_p, 1);
119119
}
120120

121-
int list_rm_noreorder(void *item, ptrToList list_p, callback destroy_callback_p)
121+
int list_rm_noreorder(ptrToList list_p, void *item, callback destroy_callback_p)
122122
{
123-
return list_rm_opt(0, item, list_p, destroy_callback_p);
123+
return list_rm_opt(list_p, item, destroy_callback_p, 0);
124124
}
125125

126-
int list_rm_at(int idx, ptrToList list_p, callback destroy_callback_p)
126+
int list_rm_at(ptrToList list_p, int idx, callback destroy_callback_p)
127127
{
128128
void ***list = (void***)list_p;
129129
callbackPtr destroy_callback = (callbackPtr)destroy_callback_p;
@@ -171,7 +171,7 @@ void list_clear(ptrToList list_p, callback destroy_callback_p)
171171
*list = NULL;
172172
}
173173

174-
int list_copy(listItself src, ptrToList dest_p)
174+
int list_copy(ptrToList dest_p, listItself src)
175175
{
176176
void **source = (void**)src;
177177
void ***dest = (void***)dest_p;
@@ -191,7 +191,7 @@ int list_copy(listItself src, ptrToList dest_p)
191191
return 0;
192192
}
193193

194-
int list_move(ptrToList source_p, ptrToList dest_p)
194+
int list_move(ptrToList dest_p, ptrToList source_p)
195195
{
196196
void ***source = (void***)source_p;
197197
void ***dest = (void***)dest_p;
@@ -247,8 +247,8 @@ void map_add(map *m, const char *key, void *val, void (*destroy_callback)(void*)
247247

248248
void map_add_not_exist(map *m, const char *key, void *val)
249249
{
250-
list_add(strdup(key), &m->keys);
251-
list_add(val, &m->values);
250+
list_add(&m->keys, strdup(key));
251+
list_add(&m->values, val);
252252
++m->size;
253253
}
254254

@@ -258,8 +258,8 @@ void map_rm(map *m, const char *key, void (*destroy_callback)(void*))
258258
if(idx < 0)
259259
return;
260260

261-
list_rm_at(idx, &m->keys, &free);
262-
list_rm_at(idx, &m->values, destroy_callback);
261+
list_rm_at(&m->keys, idx, &free);
262+
list_rm_at(&m->values, idx, destroy_callback);
263263
--m->size;
264264
}
265265

@@ -323,7 +323,7 @@ void imap_add_not_exist(imap *m, int key, void *val)
323323
m->keys = realloc(m->keys, sizeof(int)*(m->size+1));
324324
m->keys[m->size++] = key;
325325

326-
list_add(val, &m->values);
326+
list_add(&m->values, val);
327327
}
328328

329329
void imap_rm(imap *m, int key, void (*destroy_callback)(void*))
@@ -338,7 +338,7 @@ void imap_rm(imap *m, int key, void (*destroy_callback)(void*))
338338

339339
--m->size;
340340
m->keys = realloc(m->keys, sizeof(int)*m->size);
341-
list_rm_at(idx, &m->values, destroy_callback);
341+
list_rm_at(&m->values, idx, destroy_callback);
342342
}
343343

344344
int imap_find(imap *m, int key)

containers.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ typedef void* listItself; // void **
2424
typedef void* callback;
2525
typedef void(*callbackPtr)(void*);
2626

27-
void list_add(void *item, ptrToList list_p);
28-
int list_add_from_list(listItself src_p, ptrToList list_p);
29-
int list_rm(void *item, ptrToList list_p, callback destroy_callback_p);
30-
int list_rm_noreorder(void *item, ptrToList list_p, callback destroy_callback_p);
31-
int list_rm_opt(int reorder, void *item, ptrToList list_p, callback destroy_callback_p);
32-
int list_rm_at(int idx, ptrToList list_p, callback destroy_callback_p);
27+
void list_add(ptrToList list_p, void *item);
28+
int list_add_from_list(ptrToList list_p, listItself src_p);
29+
int list_rm(ptrToList list_p, void *item, callback destroy_callback_p);
30+
int list_rm_noreorder(ptrToList list_p, void *item, callback destroy_callback_p);
31+
int list_rm_opt(ptrToList list_p, void *item, callback destroy_callback_p, int reorder);
32+
int list_rm_at(ptrToList list_p, int idx, callback destroy_callback_p);
3333
int list_size(listItself list);
3434
int list_item_count(listItself list);
35-
int list_copy(listItself src, ptrToList dest_p);
36-
int list_move(ptrToList source_p, ptrToList dest_p);
35+
int list_copy(ptrToList dest_p, listItself src);
36+
int list_move(ptrToList dest_p, ptrToList source_p);
3737
void list_clear(ptrToList list_p, callback destroy_callback_p);
3838
void list_swap(ptrToList a_p, ptrToList b_p);
3939

framebuffer.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -724,19 +724,19 @@ void fb_add_rect_notfilled(int level, int x, int y, int w, int h, uint32_t color
724724
fb_rect *r;
725725
// top
726726
r = fb_add_rect_lvl(level, x, y, w, thickness, color);
727-
list_add(r, list);
727+
list_add(list, r);
728728

729729
// right
730730
r = fb_add_rect_lvl(level, x + w - thickness, y, thickness, h, color);
731-
list_add(r, list);
731+
list_add(list, r);
732732

733733
// bottom
734734
r = fb_add_rect_lvl(level, x, y + h - thickness, w, thickness, color);
735-
list_add(r, list);
735+
list_add(list, r);
736736

737737
// left
738738
r = fb_add_rect_lvl(level, x, y, thickness, h, color);
739-
list_add(r, list);
739+
list_add(list, r);
740740
}
741741

742742
fb_img *fb_add_img(int level, int x, int y, int w, int h, int img_type, px_type *data)
@@ -860,7 +860,7 @@ void fb_push_context(void)
860860
fb_ctx.first_item = NULL;
861861
pthread_mutex_unlock(&fb_ctx.mutex);
862862

863-
list_add(ctx, &inactive_ctx);
863+
list_add(&inactive_ctx, ctx);
864864
}
865865

866866
void fb_pop_context(void)
@@ -878,7 +878,7 @@ void fb_pop_context(void)
878878
fb_ctx.background_color = ctx->background_color;
879879
pthread_mutex_unlock(&fb_ctx.mutex);
880880

881-
list_rm_noreorder(ctx, &inactive_ctx, &free);
881+
list_rm_noreorder(&inactive_ctx, ctx, &free);
882882

883883
fb_request_draw();
884884
}

framebuffer_png.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ px_type *fb_png_get(const char *path, int w, int h)
256256
e->height = h;
257257
e->refcnt = 1;
258258

259-
list_add(e, &png_cache);
259+
list_add(&png_cache, e);
260260
PNG_LOG("PNG %s (%dx%d) %p added into cache\n", path, w, h, data);
261261
return data;
262262
}
@@ -284,7 +284,7 @@ void fb_png_drop_unused(void)
284284
if((*itr)->refcnt <= 0)
285285
{
286286
PNG_LOG("PNG %s (%dx%d) %p removed from cache\n", (*itr)->path, (*itr)->width, (*itr)->height, data);
287-
list_rm(*itr, &png_cache, &destroy_png_cache_entry);
287+
list_rm(&png_cache, *itr, &destroy_png_cache_entry);
288288
itr = png_cache;
289289
}
290290
else

framebuffer_truetype.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ static void fb_text_render(fb_img *img)
479479
maxW = imax(maxW, line->w);
480480
maxH = imax(maxH, line->h);
481481

482-
list_add(line, &lines);
482+
list_add(&lines, line);
483483
++lines_cnt;
484484
}
485485

fstab.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ struct fstab *fstab_load(const char *path, int resolve_symlinks)
152152
continue;
153153
}
154154

155-
list_add(part, &t->parts);
155+
list_add(&t->parts, part);
156156
++t->count;
157157
part = NULL;
158158
}
@@ -359,7 +359,7 @@ void fstab_add_part(struct fstab *f, const char *dev, const char *path, const ch
359359
fstab_parse_options(p->options_raw, p);
360360
p->options2 = strdup(options2);
361361

362-
list_add(p, &f->parts);
362+
list_add(&f->parts, p);
363363
++f->count;
364364
}
365365

@@ -380,6 +380,6 @@ struct fstab_part *fstab_clone_part(struct fstab_part *p)
380380

381381
void fstab_add_part_struct(struct fstab *f, struct fstab_part *p)
382382
{
383-
list_add(p, &f->parts);
383+
list_add(&f->parts, p);
384384
++f->count;
385385
}

input.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ void input_push_context(void)
474474
mt_handlers = NULL;
475475
pthread_mutex_unlock(&touch_mutex);
476476

477-
list_add(ctx, &inactive_ctx);
477+
list_add(&inactive_ctx, ctx);
478478
}
479479

480480
void input_pop_context(void)
@@ -489,7 +489,7 @@ void input_pop_context(void)
489489
mt_handlers = ctx->handlers;
490490
pthread_mutex_unlock(&touch_mutex);
491491

492-
list_rm_noreorder(ctx, &inactive_ctx, &free);
492+
list_rm_noreorder(&inactive_ctx, ctx, &free);
493493
}
494494

495495
struct keyaction
@@ -551,7 +551,7 @@ void keyaction_add(int x, int y, keyaction_call call, void *data)
551551

552552
pthread_mutex_lock(&keyaction_ctx.lock);
553553

554-
list_add(k, &keyaction_ctx.actions);
554+
list_add(&keyaction_ctx.actions, k);
555555
++keyaction_ctx.actions_len;
556556

557557
qsort(keyaction_ctx.actions, keyaction_ctx.actions_len,
@@ -578,7 +578,7 @@ void keyaction_remove(keyaction_call call, void *data)
578578
keyaction_ctx.cur_act = NULL;
579579
}
580580

581-
list_rm_at(i, &keyaction_ctx.actions, &free);
581+
list_rm_at(&keyaction_ctx.actions, i, &free);
582582
--keyaction_ctx.actions_len;
583583
break;
584584
}

kexec.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ int kexec_load_exec(struct kexec *k)
9292

9393
void kexec_add_arg(struct kexec *k, const char *arg)
9494
{
95-
list_add(strdup(arg), &k->args);
95+
list_add(&k->args, strdup(arg));
9696
}
9797

9898
void kexec_add_arg_prefix(struct kexec *k, const char *prefix, const char *value)
@@ -101,7 +101,7 @@ void kexec_add_arg_prefix(struct kexec *k, const char *prefix, const char *value
101101
char *arg = malloc(len);
102102
snprintf(arg, len, "%s%s", prefix, value);
103103

104-
list_add(arg, &k->args);
104+
list_add(&k->args, arg);
105105
}
106106

107107
void kexec_add_kernel(struct kexec *k, const char *path, int hardboot)

listview.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ listview_item *listview_add_item(listview *view, int id, void *data)
105105
if(!view->items)
106106
keyaction_add(view->x, view->y, listview_keyaction_call, view);
107107

108-
list_add(it, &view->items);
108+
list_add(&view->items, it);
109109
return it;
110110
}
111111

multirom.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ int multirom_default_status(struct multirom_status *s)
434434

435435
multirom_find_rom_icon(rom);
436436

437-
list_add(rom, &add_roms);
437+
list_add(&add_roms, rom);
438438
}
439439

440440
closedir(d);
@@ -697,7 +697,7 @@ void multirom_find_usb_roms(struct multirom_status *s)
697697
{
698698
if(s->roms[i]->partition)
699699
{
700-
list_rm_at(i, &s->roms, &multirom_free_rom);
700+
list_rm_at(&s->roms, i, &multirom_free_rom);
701701
i = 0;
702702
}
703703
else ++i;
@@ -776,7 +776,7 @@ int multirom_scan_partition_for_roms(struct multirom_status *s, struct usb_parti
776776

777777
multirom_find_rom_icon(rom);
778778

779-
list_add(rom, &add_roms);
779+
list_add(&add_roms, rom);
780780
}
781781
closedir(d);
782782

@@ -785,7 +785,7 @@ int multirom_scan_partition_for_roms(struct multirom_status *s, struct usb_parti
785785
// sort roms
786786
qsort(add_roms, list_item_count(add_roms), sizeof(struct multirom_rom*), compare_rom_names);
787787

788-
list_add_from_list(add_roms, &s->roms);
788+
list_add_from_list(&s->roms, add_roms);
789789
list_clear(&add_roms, NULL);
790790
}
791791
return 0;
@@ -2231,7 +2231,7 @@ int multirom_update_partitions(struct multirom_status *s)
22312231

22322232
if(part->fs && multirom_mount_usb(part) == 0)
22332233
{
2234-
list_add(part, &s->partitions);
2234+
list_add(&s->partitions, part);
22352235
ERROR("Found part %s: %s, %s\n", part->name, part->uuid, part->fs);
22362236
}
22372237
else

multirom_ui.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ void multirom_ui_tab_rom_set_empty(void *data, int empty)
654654
p->wrap_w = t->list->w - 100*DPI_MUL;
655655
p->justify = JUSTIFY_CENTER;
656656
t->usb_text = fb_text_finalize(p);
657-
list_add(t->usb_text, &t->ui_elements);
657+
list_add(&t->ui_elements, t->usb_text);
658658

659659
center_text(t->usb_text, t->list->x, -1, t->list->w, -1);
660660
t->usb_text->y = t->list->y + t->list->h*0.2;
@@ -667,7 +667,7 @@ void multirom_ui_tab_rom_set_empty(void *data, int empty)
667667
progdots_destroy(t->usb_prog);
668668
t->usb_prog = NULL;
669669

670-
list_rm(t->usb_text, &t->ui_elements, &fb_remove_item);
670+
list_rm(&t->ui_elements, t->usb_text, &fb_remove_item);
671671
t->usb_text = NULL;
672672
}
673673
}

multirom_ui_themes.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ multirom_themes_info *multirom_ui_init_themes(void)
2929

3030
#define ADD_THEME(RES) \
3131
extern struct multirom_theme theme_info_ ## RES; \
32-
list_add(&theme_info_ ## RES, &i->themes);
32+
list_add(&i->themes, &theme_info_ ## RES);
3333

3434
// universal themes which scale according to DPI_MUL
3535
ADD_THEME(landscape);

0 commit comments

Comments
 (0)