source: golgotha/src/golg/obj_dll.cc

Last change on this file was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 3.5 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#error this file is not USED!~
10
11#include "obj_dll.hh"
12#include "file/file.hh"
13#include "memory/malloc.hh"
14
15g1_dll_manager_class g1_dll_man;
16
17void g1_dll_manager_class::init()
18{
19  // allocate entries
20  dll = (i4_dll_file **)i4_malloc(MAX_DLLS*sizeof(i4_dll_file *), "dll files");
21  name = (i4_str **)i4_malloc(MAX_DLLS*sizeof(i4_str *), "dll names");
22  dlls = last = 0;
23}
24
25void g1_dll_manager_class::uninit()
26{
27  if (dlls>0)
28    i4_warning("%d dlls not freed!",dlls);
29
30  i4_free(dll);
31  i4_free(name);
32}
33
34w16 g1_dll_manager_class::load(const char *buff)
35{
36  i4_dll_file *new_dll;
37  // find next open entry
38  if (dll[last])
39  {
40    w16 end = last;
41    do
42    {
43      if (++last==MAX_DLLS)
44        last = 0;;
45    } while (last!=end && dll[last]);
46    if (last == end)
47      i4_error("Ran out of dll space");
48  }
49
50  // set global reference & load dll
51  current = last;
52
53  i4_warning("loading [%s].\n",buff);
54  new_dll = i4_open_dll(buff);
55
56  current = INVALID;
57
58  if (!new_dll)
59  {
60    i4_warning("couldn't load dll [%s].", buff);
61    return INVALID;
62  }
63
64  dll[last] = new_dll;
65  name[last] = 0;
66  dlls++;
67
68  return last;
69}
70
71w16 g1_dll_manager_class::load(const i4_const_str &dll_name)
72{
73  char buff[256];
74  w16 ret;
75  i4_os_string(dll_name,buff,sizeof(buff));
76  ret = load(buff);
77  name[ret] = new i4_str(dll_name);
78  return ret;
79}
80
81void g1_dll_manager_class::remove(w16 ref)
82{
83  // sanity check
84  if (ref>=MAX_DLLS || !dll[ref])
85  {
86    i4_warning("Tried to remove invalid DLL.");
87    return;
88  }
89
90  delete dll[ref];
91  dll[ref] = 0;
92  if (name[ref])
93    delete name[ref];
94  name[ref] = 0;
95  last = ref;
96}
97
98void g1_dll_manager_class::remove_all()
99{
100  for (w16 i=0; i<MAX_DLLS; i++)
101    if (dll[i])
102    {
103      delete dll[i];
104      dll[i] = 0;
105      if (name[i])
106        delete name[i];
107      name[i] = 0;
108    }
109  last = 0;
110  dlls = 0;
111}
112
113void g1_load_object_dlls()
114{
115  w32 files, dirs, f,d;
116  i4_str *fullname;
117  i4_str **file, **dir;
118
119
120#ifdef __linux
121  i4_const_str dll_dir=i4gets("linux_dll_dir");
122#elif _WINDOWS
123  i4_const_str dll_dir=i4gets("win32_dll_dir");
124#endif
125
126  i4_file_man.get_directory(dll_dir, file,files, dir,dirs);
127
128  i4_const_str dll_extension(i4gets("dll_extension"));
129  for (f=0; f<files; f++)
130  {
131
132    int is_debug=name->strstr(i4gets("debug_dll_substr"))!=name->end();
133
134    if (extension && *extension == dll_extension &&
135#ifdef DEBUG
136        is_debug
137#else
138        !is_debug
139#endif
140        )
141
142    {
143      fullname = i4gets("dll_fullname").sprintf(256, &i4gets("obj_dll_dir"), file[f]);
144      g1_dll_man.load(*fullname);
145      delete fullname;
146    }
147
148    if (path)
149      delete path;
150    if (name)
151      delete name;
152    if (extension)
153      delete extension;
154  }
155
156  for (f=0; f<files; f++)
157    delete file[f];
158  if (files)
159    i4_free(file);
160
161  for (d=0; d<dirs; d++)
162    delete dir[d];
163  if (dir)
164    i4_free(dir);
165}
166
167void g1_remove_object_dlls()
168{
169  g1_dll_man.remove_all();
170}
Note: See TracBrowser for help on using the repository browser.