File: loaddll

package info (click to toggle)
epic5 2.0.1-1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 4,696 kB
  • ctags: 6,357
  • sloc: ansic: 69,814; makefile: 715; ruby: 227; sh: 178; perl: 13
file content (142 lines) | stat: -rw-r--r-- 2,801 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifdef WANT_DLL

#ifdef NO_DLFCN_H
#   include "../compat/dlfcn.h"
#else
#if defined(__osf1__)
#include <loader.h>
#elif defined(HPUX)
#include <dl.h>
#else
#   include <dlfcn.h>
#endif
#endif

#ifndef RTLD_NOW
#   define RTLD_NOW 1
#endif

#ifndef RTLD_GLOBAL
#   define RTLD_GLOBAL 0
#endif


extern IrcCommandDll *dll_commands;



typedef int (Irc_PackageInitProc)  _((IrcCommandDll **interp));

typedef struct _package_installed {
	struct _package_installed *next;
	char	*name;
} Packages;           

Packages *install_pack = NULL;
                                             
void dll_load _((char *command, char *args, char *subargs))
{
#if defined(__osf__)  /*	OSF /1 1.0/1.1/1.2 and related systems */
ldr_module_t lm;
#elif defined(HPUX)  /* 	HP machines */
	shl_t handle;
#else		     /*		linux SunOS AIX etc */
void *handle = NULL;
#endif
    
char *filename = NULL;
Irc_PackageInitProc *proc1Ptr;
char *p, *procname = NULL;
int code = 0;

	if (command)
	{
		if (install_pack)
		{
			Packages *pkg = install_pack;
			bitchsay("DLL packages installed");
			for ( ; pkg; pkg = pkg->next)
				put_it("DLL %s", pkg->name);
		}
		else
			bitchsay("No dll's loaded");
		return;
	}
	if (!args || !*args)
	{
		userage("LoadDll", "filename.so");
		return;
	}

	filename = next_arg(args, &args);

#if defined(__osf__)
	if ((lm = (Tcl_PackageInitProc *) load(fileName, LDR_NOFLAGS)) == LDR_NULL_MODULE)
	{
		return;
	}       
#elif defined(HPUX)
	if ((handle = shl_load(filename, BIND_IMMEDIATE, 0L)) == NULL)
	{
		return;
	}	
#else
	handle = dlopen(filename, RTLD_NOW | RTLD_GLOBAL);
	if (handle == NULL)
	{
		bitchsay("couldn't load file: %s %s", filename, dlerror());
		return;
	}
#endif

	if ((p = strrchr(filename, '/')))	
		p++;
	else
		p = filename;

	procname  = m_strdup(p);
	if ((p = strchr(procname, '.')))
		*p = 0;

	p = procname;
	*p = toupper(*p);
	p++;
	while (*p)
	{
		*p = tolower(*p++);
	}
	malloc_strcat(&procname, "_Init");
	if (!procname)
		return;
	if (!find_in_list((List **)&install_pack, procname, 0))
	{	
#if defined(__osf__)
		/* OSF1 */
		*proc1Ptr = ldr_lookup_package(pkg, procname);
		code = (proc1Ptr)(&dll_commands);
#elif defined(HPUX)
		/* HPUX */
		if (shl_findsym(&handle, procname, (short) TYPE_PROCEDURE, (void *) proc1Ptr))
			code = (proc1Ptr)(&dll_commands);

#else
		if (!(proc1Ptr = (Irc_PackageInitProc *) dlsym(handle, (char *) procname)))
			bitchsay("UnSuccessful load");
		else
			code = (proc1Ptr)(&dll_commands);
#endif
		if (!code && proc1Ptr)
		{
			Packages *new;
			new = (Packages *) new_malloc(sizeof(Packages));
			new->name = m_strdup(procname);
			add_to_list((List **)&install_pack, (List *)new);
		}
		else if (code)
			bitchsay("Error initiliziing dll");
	}
	else
		bitchsay("Package Already installed");
	new_free(&procname);
}
#endif