fix solid color when using plugin.
[wmaker-crm.git] / src / plugin.c
blob0aca9fdd519d22a8e73042c2fc63bfefcc11873f
1 /* plugin.c- plugin
3 * Window Maker window manager
5 * Copyright (c) hmmm... Should I put everybody's name here?
6 * Where's my lawyer?? -- ]d :D
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
23 * * * * * * * * *
24 * Do you think I should move this code into another file? -- ]d
29 #include "plugin.h"
31 /* GAH! */
32 #ifdef DRAWSTRING_PLUGIN
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <stdarg.h>
39 #ifdef TEXTURE_PLUGIN
40 # ifdef HAVE_DLFCN_H
41 # include <dlfcn.h>
42 # endif
43 #endif
45 #include <proplist.h>
48 void**
49 wPluginPackData(int members, ...)
51 void **p;
52 va_list vp;
53 int i;
54 p = wmalloc(sizeof(void *) * (members + 1));
55 memset(p, 0, sizeof(void *) * (members + 1));
56 p[0] = (void *)members;
57 va_start(vp, members);
58 for(i=1;i<members+1;i++) {
59 p[i] = va_arg(vp, void *);
61 va_end(vp);
62 return p;
65 WFunction *
66 wPluginCreateFunction(int type, char *library_name,
67 char *init_proc_name, char *proc_name, char *free_data_proc_name,
68 proplist_t pl_arg, void *init_data)
70 WFunction *function;
71 _DL_InitDataProc *initProc;
73 function = wmalloc(sizeof(WFunction));
74 memset(function, 0, sizeof(WFunction));
76 function->handle = dlopen(library_name, RTLD_LAZY);
77 if (!function->handle) {
78 wwarning(_("library \"%s\" cound not be opened."), library_name);
79 wfree(function);
80 return NULL;
83 function->proc.any = dlsym(function->handle, proc_name);
84 if (!function->proc.any) {
85 wwarning(_("function \"%s\" not found in library \"%s\""), proc_name, library_name);
86 dlclose(function->handle);
87 wfree(function);
88 return NULL;
91 if (free_data_proc_name) {
92 function->freeData = dlsym(function->handle, free_data_proc_name);
93 if (!function->freeData) {
94 wwarning(_("function \"%s\" not found in library \"%s\""), free_data_proc_name, library_name);
96 dlclose(function->handle);
97 wfree(function);
98 return NULL;
103 if (pl_arg) function->arg = PLDeepCopy(pl_arg);
104 function->data = init_data;
105 if (init_proc_name) {
106 initProc = dlsym(function->handle, init_proc_name);
107 if (initProc) {
108 initProc(function->arg, function->data);
109 } else {
110 /* Where's my english teacher? -- ]d
111 wwarning(_("ignore?"),?);
116 function->type = type;
117 return function;
120 void
121 wPluginDestroyFunction(WFunction *function)
123 if (!function)
124 return;
126 if (function->data) {
127 if (function->freeData)
128 function->freeData(function->arg, function->data);
129 wfree(function->data);
131 if (function->arg) PLRelease(function->arg);
132 wfree(function);
133 return;
137 #endif