2 libimago - a multi-format image file input/output library.
3 Copyright (C) 2010 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 static struct list_node {
24 struct ftype_module *module;
25 struct list_node *next;
28 /* defined in modules.c which is generated by configure */
29 void img_modules_init();
33 int img_register_module(struct ftype_module *mod)
35 struct list_node *node;
37 if(!(node = malloc(sizeof *node))) {
47 struct ftype_module *img_find_format_module(struct img_io *io)
49 struct list_node *node;
58 if(node->module->check(io) != -1) {
66 struct ftype_module *img_guess_format(const char *fname)
68 struct list_node *node;
77 if(!(suffix = strrchr(fname, '.'))) {
78 return 0; /* no suffix, can't guess ... */
80 suffix_len = (int)strlen(suffix);
84 char *suflist = node->module->suffix;
88 if(!(start = strstr(suflist, suffix))) {
91 end = start + suffix_len;
93 if(*end == ':' || *end == 0) {
94 return node->module; /* found it */
104 struct ftype_module *img_get_module(int idx)
106 struct list_node *node;
114 while(node && idx--) {