Skip to content

Commit

Permalink
Sort the export formats
Browse files Browse the repository at this point in the history
So that they are ordered the same on all platforms.
  • Loading branch information
guillaumechereau committed Jul 28, 2024
1 parent edccf92 commit ac5caf2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/file_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@ static bool endswith(const char *str, const char *end)
return strcmp(start, end) == 0;
}

static int file_format_cmp(const file_format_t *a, const file_format_t *b)
{
if (b->priority != a->priority) {
return b->priority - a->priority;
}
return strcmp(a->name, b->name);
}

void file_format_register(file_format_t *format)
{
DL_APPEND(file_formats, format);
DL_SORT(file_formats, file_format_cmp);
}

const file_format_t *file_format_get(
Expand Down
1 change: 1 addition & 0 deletions src/file_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct file_format
int (*import_func)(const file_format_t *format, image_t *img,
const char *path);
void (*import_gui)(file_format_t *format);
int priority; // Specifies the order of file_format_iter.
};

void file_format_register(file_format_t *format);
Expand Down
1 change: 1 addition & 0 deletions src/formats/gltf.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,5 @@ FILE_FORMAT_REGISTER(gltf,
.exts_desc = "glTF2",
.export_gui = export_gui,
.export_func = export_as_gltf,
.priority = 100,
)
1 change: 1 addition & 0 deletions src/formats/png.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ FILE_FORMAT_REGISTER(png,
.exts_desc = "png",
.export_gui = export_gui,
.export_func = export_as_png,
.priority = 90,
)

0 comments on commit ac5caf2

Please sign in to comment.