istereo2

annotate libs/imago2/ftype_module.c @ 21:8f41da60b9f5

revert accidentally commited ui change
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 02 Oct 2015 04:55:54 +0300
parents
children
rev   line source
nuclear@2 1 /*
nuclear@2 2 libimago - a multi-format image file input/output library.
nuclear@2 3 Copyright (C) 2010 John Tsiombikas <nuclear@member.fsf.org>
nuclear@2 4
nuclear@2 5 This program is free software: you can redistribute it and/or modify
nuclear@2 6 it under the terms of the GNU Lesser General Public License as published
nuclear@2 7 by the Free Software Foundation, either version 3 of the License, or
nuclear@2 8 (at your option) any later version.
nuclear@2 9
nuclear@2 10 This program is distributed in the hope that it will be useful,
nuclear@2 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
nuclear@2 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
nuclear@2 13 GNU Lesser General Public License for more details.
nuclear@2 14
nuclear@2 15 You should have received a copy of the GNU Lesser General Public License
nuclear@2 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
nuclear@2 17 */
nuclear@2 18
nuclear@2 19 #include <stdlib.h>
nuclear@2 20 #include <string.h>
nuclear@2 21 #include "ftype_module.h"
nuclear@2 22
nuclear@2 23 static struct list_node {
nuclear@2 24 struct ftype_module *module;
nuclear@2 25 struct list_node *next;
nuclear@2 26 } *modules;
nuclear@2 27
nuclear@2 28 /* defined in modules.c which is generated by configure */
nuclear@2 29 void img_modules_init();
nuclear@2 30
nuclear@2 31 static int done_init;
nuclear@2 32
nuclear@2 33 int img_register_module(struct ftype_module *mod)
nuclear@2 34 {
nuclear@2 35 struct list_node *node;
nuclear@2 36
nuclear@2 37 if(!(node = malloc(sizeof *node))) {
nuclear@2 38 return -1;
nuclear@2 39 }
nuclear@2 40
nuclear@2 41 node->module = mod;
nuclear@2 42 node->next = modules;
nuclear@2 43 modules = node;
nuclear@2 44 return 0;
nuclear@2 45 }
nuclear@2 46
nuclear@2 47 struct ftype_module *img_find_format_module(struct img_io *io)
nuclear@2 48 {
nuclear@2 49 struct list_node *node;
nuclear@2 50
nuclear@2 51 if(!done_init) {
nuclear@2 52 img_modules_init();
nuclear@2 53 done_init = 1;
nuclear@2 54 }
nuclear@2 55
nuclear@2 56 node = modules;
nuclear@2 57 while(node) {
nuclear@2 58 if(node->module->check(io) != -1) {
nuclear@2 59 return node->module;
nuclear@2 60 }
nuclear@2 61 node = node->next;
nuclear@2 62 }
nuclear@2 63 return 0;
nuclear@2 64 }
nuclear@2 65
nuclear@2 66 struct ftype_module *img_guess_format(const char *fname)
nuclear@2 67 {
nuclear@2 68 struct list_node *node;
nuclear@2 69 char *suffix;
nuclear@2 70 int suffix_len;
nuclear@2 71
nuclear@2 72 if(!done_init) {
nuclear@2 73 img_modules_init();
nuclear@2 74 done_init = 1;
nuclear@2 75 }
nuclear@2 76
nuclear@2 77 if(!(suffix = strrchr(fname, '.'))) {
nuclear@2 78 return 0; /* no suffix, can't guess ... */
nuclear@2 79 }
nuclear@2 80 suffix_len = strlen(suffix);
nuclear@2 81
nuclear@2 82 node = modules;
nuclear@2 83 while(node) {
nuclear@2 84 char *suflist = node->module->suffix;
nuclear@2 85 char *start, *end;
nuclear@2 86
nuclear@2 87 while(*suflist) {
nuclear@2 88 if(!(start = strstr(suflist, suffix))) {
nuclear@2 89 break;
nuclear@2 90 }
nuclear@2 91 end = start + suffix_len;
nuclear@2 92
nuclear@2 93 if(*end == ':' || *end == 0) {
nuclear@2 94 return node->module; /* found it */
nuclear@2 95 }
nuclear@2 96 suflist = end;
nuclear@2 97 }
nuclear@2 98
nuclear@2 99 node = node->next;
nuclear@2 100 }
nuclear@2 101 return 0;
nuclear@2 102 }
nuclear@2 103
nuclear@2 104 struct ftype_module *img_get_module(int idx)
nuclear@2 105 {
nuclear@2 106 struct list_node *node;
nuclear@2 107
nuclear@2 108 if(!done_init) {
nuclear@2 109 img_modules_init();
nuclear@2 110 done_init = 1;
nuclear@2 111 }
nuclear@2 112
nuclear@2 113 node = modules;
nuclear@2 114 while(node && idx--) {
nuclear@2 115 node = node->next;
nuclear@2 116 }
nuclear@2 117 return node->module;
nuclear@2 118 }