]> git.decadent.org.uk Git - ion3.git/blob - ioncore/reginfo.c
Imported Upstream version 20090110
[ion3.git] / ioncore / reginfo.c
1 /*
2  * ion/ioncore/reginfo.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2009. 
5  *
6  * See the included file LICENSE for details.
7  */
8
9 #include <string.h>
10 #include <ctype.h>
11
12 #include "common.h"
13 #include "region.h"
14 #include <libtu/objp.h>
15 #include "attach.h"
16 #include "reginfo.h"
17
18
19 static WRegClassInfo *reg_class_infos;
20
21
22 /*{{{ Registration */
23
24
25 bool ioncore_register_regclass(ClassDescr *descr, WRegionLoadCreateFn *lc_fn)
26 {
27     WRegClassInfo *info;
28     
29     if(descr==NULL)
30         return FALSE;
31     
32     info=ALLOC(WRegClassInfo);
33     if(info==NULL)
34         return FALSE;
35     
36     info->descr=descr;
37     info->lc_fn=lc_fn;
38     LINK_ITEM(reg_class_infos, info, next, prev);
39     
40     return TRUE;
41 }
42
43
44 void ioncore_unregister_regclass(ClassDescr *descr)
45 {
46     WRegClassInfo *info;
47     
48     for(info=reg_class_infos; info!=NULL; info=info->next){
49         if(descr==info->descr){
50             UNLINK_ITEM(reg_class_infos, info, next, prev);
51             free(info);
52             return;
53         }
54     }
55 }
56
57
58 /*}}}*/
59
60
61 /*{{{ Lookup */
62
63
64 WRegClassInfo *ioncore_lookup_regclass(const char *name, bool inheriting_ok)
65 {
66     WRegClassInfo *info;
67     ClassDescr *descr;
68
69     if(name==NULL)
70         return NULL;
71     
72     for(info=reg_class_infos; info!=NULL; info=info->next){
73         for(descr=info->descr; 
74             descr!=NULL; 
75             descr=(inheriting_ok ? descr->ancestor : NULL)){
76             
77             if(strcmp(descr->name, name)==0){
78                 if(info->lc_fn!=NULL)
79                     return info;
80             }
81         }
82     }
83     return NULL;
84 }
85
86
87 /*}}}*/
88
89