Mercurial > MadButterfly
annotate src/sprite.c @ 427:8f900da42eed
Make sh_text_draw() passes first test case.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Tue, 28 Jul 2009 15:11:42 +0800 |
parents | 31b6633e3538 |
children | 16116d84bc5e |
rev | line source |
---|---|
228 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <cairo.h> | |
5 #include <dlfcn.h> | |
6 #include <sys/stat.h> | |
7 #include "mb_types.h" | |
8 #include "mb_shapes.h" | |
9 #include "mb_tools.h" | |
10 #include "mb_redraw_man.h" | |
11 #include "mb_observer.h" | |
12 #include "mb_prop.h" | |
13 | |
14 static char *Sprite_Search_Path=NULL; | |
15 static int sprite_search_so(char *path, int len, const char *name) | |
16 { | |
17 struct stat st; | |
18 | |
19 if (Sprite_Search_Path == NULL) { | |
20 Sprite_Search_Path = strdup("/usr/share/madbutterffly"); | |
21 } | |
22 | |
23 snprintf(path, len, "./%s.so", name); | |
24 if (stat(path, &st)==0) { | |
25 return 0; | |
26 } | |
27 snprintf(path, len, "%s/%s.so", Sprite_Search_Path, name); | |
28 if (stat(path, &st)==0) { | |
29 return 0; | |
30 } else { | |
31 return -1; | |
32 } | |
33 } | |
34 | |
35 void sprite_set_search_path(char *path) | |
36 { | |
37 if (Sprite_Search_Path) | |
38 free(Sprite_Search_Path); | |
39 Sprite_Search_Path = strdup(path); | |
40 } | |
41 | |
42 mb_sprite_t *sprite_load(const char *name, redraw_man_t *rdman, coord_t *root) | |
43 { | |
44 char path[1024]; | |
45 const char *s; | |
46 void *handle; | |
47 mb_sprite_t *(*new)(redraw_man_t *, coord_t *); | |
48 mb_sprite_t *obj; | |
49 | |
50 if (sprite_search_so(path, sizeof(path),name)) { | |
51 fprintf(stderr," can not find %s in search path\n", name); | |
52 return NULL; | |
53 } | |
54 handle = dlopen(path,RTLD_LAZY); | |
55 if (handle == NULL) { | |
56 fprintf(stderr, "can not load object %s\n", path); | |
57 return NULL; | |
58 } | |
59 s = name + strlen(name)-1; | |
399
31b6633e3538
- Fix a minor error in src/sprite.c: should check *(s-1) instead of
john.cylee@gmail.com
parents:
228
diff
changeset
|
60 while((s != name) && *(s-1) != '/') s--; |
228 | 61 snprintf(path,sizeof(path), "%s_new", s); |
62 new = dlsym(handle,path); | |
63 if (new == NULL) { | |
64 fprintf(stderr," Can not find symbol %s at module\n", path); | |
65 return NULL; | |
66 } | |
67 obj = new(rdman, root); | |
68 return obj; | |
69 } | |
70 | |
71 /* vim: set ts=4 */ |