Mercurial > MadButterfly
comparison src/sprite.c @ 826:94041f085797
Merge from main stream
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Tue, 14 Sep 2010 05:55:30 +0800 |
parents | 586e50f82c1f |
children | 2cbe3721dc9a |
comparison
equal
deleted
inserted
replaced
825:e83956ba22d7 | 826:94041f085797 |
---|---|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- | |
2 // vim: sw=4:ts=8:sts=4 | |
1 #include <stdio.h> | 3 #include <stdio.h> |
2 #include <stdlib.h> | 4 #include <stdlib.h> |
3 #include <string.h> | 5 #include <string.h> |
4 #include "mb_graph_engine.h" | 6 #include "mb_graph_engine.h" |
5 #include <dlfcn.h> | 7 #include <dlfcn.h> |
20 static char *sprite_search_so(const char *name) { | 22 static char *sprite_search_so(const char *name) { |
21 struct stat st; | 23 struct stat st; |
22 int fsz; | 24 int fsz; |
23 char *fullname; | 25 char *fullname; |
24 int r; | 26 int r; |
25 | 27 |
26 if(sprite_search_path == NULL) | 28 if(sprite_search_path == NULL) |
27 sprite_search_path = strdup("/usr/share/madbutterffly"); | 29 sprite_search_path = strdup("/usr/share/madbutterffly"); |
28 | 30 |
29 fsz = strlen(sprite_search_path) + strlen(name) + 5; | 31 fsz = strlen(sprite_search_path) + strlen(name) + 5; |
30 fullname = (char *)malloc(fsz); | 32 fullname = (char *)malloc(fsz); |
31 | 33 |
32 snprintf(fullname, fsz, "%s/%s.so", sprite_search_path, name); | 34 snprintf(fullname, fsz, "%s/%s.so", sprite_search_path, name); |
33 r = stat(fullname, &st); | 35 r = stat(fullname, &st); |
39 return fullname; | 41 return fullname; |
40 } | 42 } |
41 | 43 |
42 void sprite_set_search_path(char *path) { | 44 void sprite_set_search_path(char *path) { |
43 int sz; | 45 int sz; |
44 | 46 |
45 if (sprite_search_path) | 47 if (sprite_search_path) |
46 free(sprite_search_path); | 48 free(sprite_search_path); |
47 | 49 |
48 sprite_search_path = strdup(path); | 50 sprite_search_path = strdup(path); |
49 | 51 |
50 sz = strlen(sprite_search_path); | 52 sz = strlen(sprite_search_path); |
51 if(sprite_search_path[sz - 1] == '/') | 53 if(sprite_search_path[sz - 1] == '/') |
52 sprite_search_path[sz - 1] = 0; | 54 sprite_search_path[sz - 1] = 0; |
53 } | 55 } |
54 | 56 |
59 const char *bname; | 61 const char *bname; |
60 void *handle; | 62 void *handle; |
61 mb_sprite_t *(*cnstr)(redraw_man_t *, coord_t *); | 63 mb_sprite_t *(*cnstr)(redraw_man_t *, coord_t *); |
62 mb_sprite_t *obj; | 64 mb_sprite_t *obj; |
63 int r; | 65 int r; |
64 | 66 |
65 so_path = sprite_search_so(name); | 67 so_path = sprite_search_so(name); |
66 if(so_path == NULL) | 68 if(so_path == NULL) |
67 return NULL; | 69 return NULL; |
68 | 70 |
69 handle = dlopen(so_path, RTLD_LAZY); | 71 handle = dlopen(so_path, RTLD_LAZY); |
70 free(so_path); | 72 free(so_path); |
71 if (handle == NULL) | 73 if (handle == NULL) |
72 return NULL; | 74 return NULL; |
73 | 75 |
74 bname = strrchr(name, '/'); | 76 bname = strrchr(name, '/'); |
75 if(bname != NULL && strlen(bname) > 250) | 77 if(bname != NULL && strlen(bname) > 250) |
76 return NULL; | 78 return NULL; |
77 | 79 |
78 if(bname == NULL) | 80 if(bname == NULL) |
79 bname = name; | 81 bname = name; |
80 else | 82 else |
81 bname++; | 83 bname++; |
82 | 84 |
83 snprintf(cnstr_name, sizeof(cnstr_name), "%s_new", bname); | 85 snprintf(cnstr_name, sizeof(cnstr_name), "%s_new", bname); |
84 cnstr = dlsym(handle, cnstr_name); | 86 cnstr = dlsym(handle, cnstr_name); |
85 if (cnstr == NULL) | 87 if (cnstr == NULL) |
86 return NULL; | 88 return NULL; |
87 | 89 |
88 obj = cnstr(rdman, root); | 90 obj = cnstr(rdman, root); |
89 | 91 |
90 return obj; | 92 return obj; |
91 } | 93 } |
92 | |
93 /* vim: set ts=4 */ |