Skip to content

Commit ac5caf2

Browse files
Sort the export formats
So that they are ordered the same on all platforms.
1 parent edccf92 commit ac5caf2

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

src/file_format.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,18 @@ static bool endswith(const char *str, const char *end)
3434
return strcmp(start, end) == 0;
3535
}
3636

37+
static int file_format_cmp(const file_format_t *a, const file_format_t *b)
38+
{
39+
if (b->priority != a->priority) {
40+
return b->priority - a->priority;
41+
}
42+
return strcmp(a->name, b->name);
43+
}
3744

3845
void file_format_register(file_format_t *format)
3946
{
4047
DL_APPEND(file_formats, format);
48+
DL_SORT(file_formats, file_format_cmp);
4149
}
4250

4351
const file_format_t *file_format_get(

src/file_format.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct file_format
3434
int (*import_func)(const file_format_t *format, image_t *img,
3535
const char *path);
3636
void (*import_gui)(file_format_t *format);
37+
int priority; // Specifies the order of file_format_iter.
3738
};
3839

3940
void file_format_register(file_format_t *format);

src/formats/gltf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,4 +456,5 @@ FILE_FORMAT_REGISTER(gltf,
456456
.exts_desc = "glTF2",
457457
.export_gui = export_gui,
458458
.export_func = export_as_gltf,
459+
.priority = 100,
459460
)

src/formats/png.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,5 @@ FILE_FORMAT_REGISTER(png,
7979
.exts_desc = "png",
8080
.export_gui = export_gui,
8181
.export_func = export_as_png,
82+
.priority = 90,
8283
)

0 commit comments

Comments
 (0)