]> git.decadent.org.uk Git - ion3.git/blob - ioncore/reginfo.c
981588043ee16d8c8465918b7e0db9e9ae941f9a
[ion3.git] / ioncore / reginfo.c
1 /*
2  * ion/ioncore/reginfo.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2007. 
5  *
6  * Ion is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  */
11
12 #include <string.h>
13 #include <ctype.h>
14
15 #include "common.h"
16 #include "region.h"
17 #include <libtu/objp.h>
18 #include "attach.h"
19 #include "reginfo.h"
20
21
22 static WRegClassInfo *reg_class_infos;
23
24
25 /*{{{ Registration */
26
27
28 bool ioncore_register_regclass(ClassDescr *descr, WRegionLoadCreateFn *lc_fn)
29 {
30     WRegClassInfo *info;
31     
32     if(descr==NULL)
33         return FALSE;
34     
35     info=ALLOC(WRegClassInfo);
36     if(info==NULL)
37         return FALSE;
38     
39     info->descr=descr;
40     info->lc_fn=lc_fn;
41     LINK_ITEM(reg_class_infos, info, next, prev);
42     
43     return TRUE;
44 }
45
46
47 void ioncore_unregister_regclass(ClassDescr *descr)
48 {
49     WRegClassInfo *info;
50     
51     for(info=reg_class_infos; info!=NULL; info=info->next){
52         if(descr==info->descr){
53             UNLINK_ITEM(reg_class_infos, info, next, prev);
54             free(info);
55             return;
56         }
57     }
58 }
59
60
61 /*}}}*/
62
63
64 /*{{{ Lookup */
65
66
67 WRegClassInfo *ioncore_lookup_regclass(const char *name, bool inheriting_ok)
68 {
69     WRegClassInfo *info;
70     ClassDescr *descr;
71
72     if(name==NULL)
73         return NULL;
74     
75     for(info=reg_class_infos; info!=NULL; info=info->next){
76         for(descr=info->descr; 
77             descr!=NULL; 
78             descr=(inheriting_ok ? descr->ancestor : NULL)){
79             
80             if(strcmp(descr->name, name)==0){
81                 if(info->lc_fn!=NULL)
82                     return info;
83             }
84         }
85     }
86     return NULL;
87 }
88
89
90 /*}}}*/
91
92