source: golgotha/src/i4/test/dll_test/test.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 14 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.2 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#include "dll/dll.hh"
10#include "test.hh"
11#include <string.h>
12#include <stdlib.h>
13
14CFoundry *Foundry = 0;
15
16class CBaseFoundry : public CFoundry
17{
18public:
19  CBaseFoundry() : CFoundry(0)
20  {
21    if (Foundry != 0) {
22      printf("Can only build one base foundry!");
23      return;
24    }
25    Foundry = this;     
26  }
27
28  ~CBaseFoundry()
29  {
30    if (Foundry->next!=this)
31      printf("Foundries not destroyed!\n");
32  }
33
34  virtual char *Type() { return "Base"; }
35  virtual CBase *Make(char *name) { printf("Illegal Make!\n"); }
36
37  CBase *Make(char *type, char *name)
38  {
39    CFoundry *p = Foundry;
40    while (p->next != Foundry) {
41      p = p->next;
42      if (!strcmp(type, p->Type()))
43        return p->Make(name);
44    }
45    printf("Couldn't find the [%s] foundry\n", type);
46    return 0;
47  }
48 
49} BaseFoundry;
50
51char dll_name[] =
52"/u/oliy/src/crack/i4/test/dll_test/test1.dll"
53;
54
55char test_name[] =
56"test1"
57;
58
59CBase *Make(char *type, char *name)
60{
61  BaseFoundry.Make(type,name);
62}
63
64void main()
65{
66  i4_dll_file *test_dll[3];
67  test_func test;
68
69#if 1
70  for (int i=0; i<3; i++)
71    test_dll[i] = 0;
72#else
73  for (int i=1; i<3; i++) {
74    dll_name[strlen(dll_name)-5] = '0'+i;
75    test_name[4] = '0'+i;
76
77    test_dll[i] = i4_open_dll(dll_name);
78    test = (test_func)test_dll[i]->find_function(test_name);
79
80    (*test)(1,2);
81  }
82#endif
83
84  int cont = 1;
85  char com[80];
86  CBase *obj=0;
87
88  while (cont) {
89    printf("Test> ");
90    gets(com);
91    switch (com[0])
92    {
93      case 'l':
94      {
95        i4_dll_file *t;
96        int i=atol(com+1);
97
98        dll_name[strlen(dll_name)-5] = '0'+i;
99        test_name[4] = '0'+i;
100
101        if (t = i4_open_dll(dll_name))
102        {
103          test_dll[i] = t;
104          test = (test_func)test_dll[i]->find_function(test_name);
105       
106          if (test)
107            (*test)(1,2);
108          else
109            printf("%s not loaded from dll.\n",test_name);
110        }
111        else
112          printf("%s not loaded.\n",dll_name);
113      } break;
114      case 'u':
115      {
116        int i=atol(com+1);
117
118        if (i>=0 && i<3 && test_dll[i])
119        {
120          delete test_dll[i];
121          test_dll[i] = 0;
122        }
123      } break;
124      case 'n':
125      {
126        char *type, *name;
127       
128        if (obj) {
129          delete obj;
130          obj = 0;
131        }
132        strtok(com," ");
133        type = strtok(0," ");
134        name = strtok(0," ");
135
136        obj = Make(type, name);
137      } break;
138      case 'q':
139        cont = 0;
140        break;
141      default:
142        if (obj)
143          obj->Action(com);
144        break;
145    }
146  }
147
148  if (obj) {
149    delete obj;
150    obj = 0;
151  }
152
153  for (int i=0; i<2; i++)
154    if (test_dll[i])
155      delete test_dll[i];
156}
157
Note: See TracBrowser for help on using the repository browser.