1 /*
2  *  The Regina Rexx Interpreter
3  *  Copyright (C) 1993-1994  Anders Christensen <anders@pvv.unit.no>
4  *
5  *  This library is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU Library General Public
7  *  License as published by the Free Software Foundation; either
8  *  version 2 of the License, or (at your option) any later version.
9  *
10  *  This library is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *  Library General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Library General Public
16  *  License along with this library; if not, write to the Free
17  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 #include "rexx.h"
20 
21 #if defined( DYNAMIC_STATIC )
22 typedef void *(*RPFN)( char *);
23 
24 #ifdef HAVE_REXXUTIL_PACKAGE
25 extern void *getRexxUtilFunctionAddress( char *name );
26 #endif
27 
28 #ifdef HAVE_TEST_PACKAGE
29 extern void *getTest1FunctionAddress( char *name );
30 extern void *getTest2FunctionAddress( char *name );
31 #endif
32 
33 #ifdef HAVE_REXXTK_PACKAGE
34 extern void *getRexxTkFunctionAddress( char *name );
35 #endif
36 
37 #ifdef HAVE_REXXCURSES_PACKAGE
38 extern void *getRexxCursesFunctionAddress( char *name );
39 #endif
40 
41 #ifdef HAVE_REXXGD_PACKAGE
42 extern void *getRexxGdFunctionAddress( char *name );
43 #endif
44 
45 #ifdef HAVE_REXXISAM_PACKAGE
46 extern void *getRexxISAMFunctionAddress( char *name );
47 #endif
48 
49 #ifdef HAVE_REXXCURL_PACKAGE
50 extern void *getRexxCURLFunctionAddress( char *name );
51 #endif
52 
53 #ifdef HAVE_REXXSQL_PACKAGE
54 extern void *getRexxSQLFunctionAddress( char *name );
55 #endif
56 
57 #ifdef HAVE_REXXEEC_PACKAGE
58 extern void *getRexxEECFunctionAddress( char *name );
59 #endif
60 
61 #ifdef HAVE_REXXDW_PACKAGE
62 extern void *getRexxDWFunctionAddress( char *name );
63 #endif
64 
65 #ifdef HAVE_REXXCSV_PACKAGE
66 extern void *getRexxCSVFunctionAddress( char *name );
67 #endif
68 
69 #ifdef HAVE_REXXPDF_PACKAGE
70 extern void *getRexxPDFFunctionAddress( char *name );
71 #endif
72 
73 #ifdef HAVE_RXSOCK_PACKAGE
74 extern void *getRxSockFunctionAddress( char *name );
75 #endif
76 
77 #ifndef max
78 # define max(a,b)        (((a) > (b)) ? (a) : (b))
79 #endif
80 
81 #ifndef min
82 # define min(a,b)        (((a) < (b)) ? (a) : (b))
83 #endif
84 
85 static struct
86 {
87     char *name;
88     void *(*funcptr)(char *name);
89 } RexxPackages[] =
90 {
91 #ifdef HAVE_TEST_PACKAGE
92    { "test1", getTest1FunctionAddress} ,
93    { "test2", getTest2FunctionAddress} ,
94 #endif
95 #ifdef HAVE_REXXUTIL_PACKAGE
96    { "regutil", getRexxUtilFunctionAddress} ,
97    { "rexxutil", getRexxUtilFunctionAddress} ,
98 #endif
99 #ifdef HAVE_REXXTK_PACKAGE
100    { "rexxtk", getRexxTkFunctionAddress },
101 #endif
102 #ifdef HAVE_REXXCURSES_PACKAGE
103    { "rxcurses", getRexxCursesFunctionAddress },
104 #endif
105 #ifdef HAVE_REXXGD_PACKAGE
106    { "rexxgd", getRexxGdFunctionAddress },
107 #endif
108 #ifdef HAVE_REXXISAM_PACKAGE
109    { "rexxisam", getRexxISAMFunctionAddress },
110 #endif
111 #ifdef HAVE_REXXCURL_PACKAGE
112    { "rexxcurl", getRexxCURLFunctionAddress },
113 #endif
114 #ifdef HAVE_REXXSQL_PACKAGE
115    { "rexxsql", getRexxSQLFunctionAddress },
116 #endif
117 #ifdef HAVE_REXXEEC_PACKAGE
118    { "rexxeec", getRexxEECFunctionAddress },
119 #endif
120 #ifdef HAVE_RXSOCK_PACKAGE
121    { "rxsock", getRxSockFunctionAddress },
122 #endif
123 #ifdef HAVE_REXXDW_PACKAGE
124    { "rexxdw", getRexxDWFunctionAddress },
125 #endif
126 #ifdef HAVE_REXXCSV_PACKAGE
127    { "rexxcsv", getRexxCSVFunctionAddress },
128 #endif
129 #ifdef HAVE_REXXPDF_PACKAGE
130    { "rexxpdf", getRexxPDFFunctionAddress },
131 #endif
132    { "", NULL },
133 };
my_stricmp(char * str1,char * str2)134 static int my_stricmp( char *str1,char *str2 )
135 {
136    int len1,len2,len,rc;
137 
138    len1 = strlen( str1 );
139    len2 = strlen( str2 );
140    len = min( len1, len2 );
141 
142    rc = mem_cmpic( str1, str2, len );
143    if ( rc != 0 )
144       return rc;
145 
146    if ( len1 > len2 )
147       return(1);
148    if ( len1 < len2 )
149       return(-1);
150    return(0);
151 }
152 
static_dlopen(char * name)153 void *static_dlopen( char *name )
154 {
155    int i, num_packages ;
156    num_packages = sizeof( RexxPackages ) / sizeof( *RexxPackages );
157    for ( i = 0; i < num_packages; i++)
158    {
159       if ( my_stricmp( RexxPackages[i].name, name ) == 0 )
160          return RexxPackages[i].funcptr;
161    }
162    return NULL;
163 }
164 
static_dlsym(void * addr,char * name,void ** faddr)165 int static_dlsym( void *addr, char *name, void **faddr )
166 {
167    RPFN rpaddr = (RPFN)addr;
168    if ( rpaddr == NULL )
169    {
170       return 30;
171    }
172    *faddr = (*rpaddr)( name );
173    if (*faddr == NULL )
174       return 1;
175    else
176       return 0;
177 }
178 
static_list_packages()179 void static_list_packages()
180 {
181    int i, num_packages ;
182    num_packages = ( sizeof( RexxPackages ) / sizeof( *RexxPackages ) ) - 1;
183    for ( i = 0; i < num_packages; i++)
184    {
185       fprintf( stderr, " Statically loaded: %s\n", RexxPackages[i].name );
186    }
187 }
188 #endif
189