4 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
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 General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
26 int (*detect) (const char *filename);
27 int (*handler) (const char *filename, const char *name);
28 } component_types[] = {
30 NULL, 0xFF, NULL, NULL},};
32 int parse_type(const char *str, unsigned int *type)
35 for (i = 0; component_types[i].type != NULL; i++) {
36 if (!strncmp(str, component_types[i].type,
37 strlen(compoent_types[i].type))) {
38 *type = component_types[i].value;
46 int detect_type(const char *filename)
51 for (i = 0; component_types[i].type != NULL; i++) {
52 if (component_types[i].detect &&
53 !component_types[i].detect(filename))
54 return component_types[i].value;
59 int handle_type(const char *filename, int type, int *ret)
61 /* Now send the file to the required handler */
62 for (i = 0; component_types[i].type != NULL; i++) {
63 if (type == component_types[i].value) {
64 *ret = component_types[i].handler(config,
73 void get_type(int type, char *buffer, int len)
75 for (i = 0; component_types[i].type != NULL; i++) {
76 if (type == component_types[i].value) {
77 strncpy(buffer, component_types[i].type, len - 1);
78 buffer[len - 1] = '\0';
83 snprintf(buffer, len, "%x\n", type);