-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathhRexx.h
217 lines (175 loc) · 6.01 KB
/
hRexx.h
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/* HREXX.H (c)Copyright Enrico Sorichetti, 2012 */
/* Rexx Interpreter Support */
/* */
/* Released under "The Q Public License Version 1" */
/* (http://www.hercules-390.org/herclic.html) as modifications to */
/* Hercules. */
/* inspired by the previous Rexx implementation by Jan Jaeger */
#ifndef _HREXX_H_
#define _HREXX_H_
#define HAVKEYW( _T_ ) ( strcasecmp( _T_, argv[iarg]) == 0 )
#define HAVABBR( _T_ ) ( strncasecmp( _T_, argv[iarg], argl) == 0 )
// #define CMPARG( _VALUE_ ) strcasecmp( _VALUE_, argv[iarg])
// #define CMPARGL( _VALUE_ ) strncasecmp( _VALUE_, argv[iarg], argl)
#if defined(PATH_MAX)
# define MAX_PATHNAME_LENGTH PATH_MAX + 1
#elif defined(_POSIX_PATH_MAX)
# define MAX_PATHNAME_LENGTH _POSIX_PATH_MAX + 1
#else
# define MAX_PATHNAME_LENGTH 1024 + 1
#endif
#if defined(FILENAME_MAX)
# define MAX_FILENAME_LENGTH FILENAME_MAX + 1
#elif defined(_MAX_FNAME)
# define MAX_FILENAME_LENGTH _MAX_FNAME + 1
#elif defined(_POSIX_NAME_MAX)
# define MAX_FILENAME_LENGTH _POSIX_NAME_MAX + 1
#else
# define MAX_FILENAME_LENGTH 1024 + 1
#endif
#ifndef MAX_ARGS_TO_REXXSTART
#define MAX_ARGS_TO_REXXSTART 64
#endif
#ifndef MAX_ARGS_TO_SUBCOMHANDLER
#define MAX_ARGS_TO_SUBCOMHANDLER 64
#endif
#ifndef WRK_AREA_SIZE
#define WRK_AREA_SIZE 33
#endif
#ifdef _HREXX_C_
#define _HREXX_EXTERN
#else
#define _HREXX_EXTERN extern
#endif
#define REGINA_PACKAGE "Regina"
#define OOREXX_PACKAGE "ooRexx"
#define hSubcom "HERCULES"
#define hSIOExit "HERCSIOE"
#if defined( _MSVC_ )
#define EXTNDELIM ";"
#define EXTENSIONS ".REXX;.rexx;.REX;.rex;.CMD;.cmd;.RX;.rx"
#define PATHDELIM ";"
#define PATHFORMAT "%s\\%s%s"
#define REGINA_LIBRARY "regina.dll"
#define OOREXX_LIBRARY "rexx.dll"
#define OOREXX_API_LIBRARY "rexxapi.dll"
#define OOREXX_UTIL_LIBRARY "rexxutil.dll"
#elif defined ( __APPLE__ )
#define EXTNDELIM ":"
#define EXTENSIONS ".rexx:.rex:.cmd:.rx" /* APPLE is caseless */
#define PATHDELIM ":"
#define PATHFORMAT "%s/%s%s"
#define REGINA_LIBRARY "libregina.dylib"
#define OOREXX_LIBRARY "librexx.dylib"
#define OOREXX_API_LIBRARY "librexxapi.dylib"
#define OOREXX_UTIL_LIBRARY "librexxutil.dylib"
#else
#define EXTNDELIM ":"
#define EXTENSIONS ".REXX:.rexx:.REX:.rex:.CMD:.cmd:.RX:.rx"
#define PATHDELIM ":"
#define PATHFORMAT "%s/%s%s"
#define REGINA_LIBRARY "libregina.so"
#define OOREXX_LIBRARY "librexx.so"
#define OOREXX_API_LIBRARY "librexxapi.so"
#define OOREXX_UTIL_LIBRARY "librexxutil.so"
#endif
#define REXX_START "RexxStart"
#define REXX_REGISTER_FUNCTION "RexxRegisterFunctionExe"
#define REXX_DEREGISTER_FUNCTION "RexxDeregisterFunction"
#define REXX_REGISTER_SUBCOM "RexxRegisterSubcomExe"
#define REXX_DEREGISTER_SUBCOM "RexxDeregisterSubcom"
#define REXX_REGISTER_EXIT "RexxRegisterExitExe"
#define REXX_DEREGISTER_EXIT "RexxDeregisterExit"
#define REXX_ALLOCATE_MEMORY "RexxAllocateMemory"
#define REXX_FREE_MEMORY "RexxFreeMemory"
#define REXX_VARIABLE_POOL "RexxVariablePool"
#define HREXX_ERRORHANDLER_VARNAME "HREXX.ERRORHANDLER"
#define HREXX_PERSISTENTRESPSTEMNAME_VARNAME "HREXX.PERSISTENTRESPSTEMNAME"
#define HREXX_RESPSTEMNAME_VARNAME "HREXX.RESPSTEMNAME"
#if defined ( _MSVC_ )
#define HDLOPEN( _LIBHND_, _LIBNAM_ , _LIBPAR_ ) do {\
_LIBHND_ = LoadLibrary( ( _LIBNAM_ ) );\
if (! ( _LIBHND_ ) ) { \
WRMSG( HHC17531, "E", RexxPackage, ( _LIBNAM_ ) ) ; \
return -1; \
} \
} while (0)
#define HDLCLOSE( _LIBHND_) do {\
if ( FreeLibrary( ( _LIBHND_ ) ) == 0 ) { \
WRMSG( HHC17532, "E", RexxPackage, ( _LIBHND_ ) ) ; \
return -1; \
} \
( _LIBHND_ ) = NULL; \
} while (0)
#define HDLSYM(_SYMHND_, _LIBHND_, _SYMNAM_ ) do {\
( _SYMHND_ ) = (void *) GetProcAddress( ( _LIBHND_ ), ( _SYMNAM_ ) ) ; \
if (! ( _SYMHND_ ) ) { \
WRMSG( HHC17533, "E", RexxPackage, ( _SYMNAM_ ), "") ; \
return -1; \
} \
} while (0)
#else
#if !defined ( OPTION_DYNAMIC_LOAD )
#include <dlfcn.h>
#endif
#define HDLOPEN( _LIBHND_, _LIBNAM_, _LIBPAR_ ) do {\
( _LIBHND_ ) = dlopen( ( _LIBNAM_ ), ( _LIBPAR_ ) );\
if (! ( _LIBHND_ ) ) { \
WRMSG( HHC17530, "E", RexxPackage, dlerror() ) ; \
return -1; \
} \
} while (0)
#define HDLCLOSE( _LIBHND_) do {\
if ( dlclose( ( _LIBHND_ ) ) != 0 ) { \
WRMSG( HHC17530, "E", RexxPackage, dlerror() ) ; \
return -1; \
} \
( _LIBHND_ ) = NULL; \
} while (0)
#define HDLSYM(_SYMHND_, _LIBNAM_, _SYMNAM_ ) do {\
( _SYMHND_ ) = dlsym( ( _LIBNAM_ ), ( _SYMNAM_ ) );\
if (! ( _SYMHND_ ) ) { \
WRMSG( HHC17530, "E", RexxPackage, dlerror() ) ; \
return -1; \
} \
} while (0)
#endif
#ifndef _HREXX_TKCOUNT_C
#define _HREXX_TKCOUNT_C
#ifdef _HREXX_C_
int tkcount(char *str)
{
char *w,*p;
int k;
w = strdup(str);
for (k=0, p = strtok(w, EXTNDELIM ); p; p = strtok(NULL, EXTNDELIM), k++);
free (w);
return (k) ;
}
#else
int tkcount(char *str) ;
#endif /* #ifdef _HREXX_C_ */
#endif /* #ifndef _HREXX_TKCOUNT_C */
#ifndef _HREXX_TRIM_C
#define _HREXX_TRIM_C
#ifdef _HREXX_C_
char *trim(char *str)
{
char *cp1 ;
char *cp2 ;
// skip leading spaces
for (cp1=str ; isspace(*cp1) ; cp1++ ) ;
cp2 = str ;
// shift left remaining chars, via cp2 and terminate string
for ( ; *cp1 ; *cp2++=*cp1++) ;
*cp2-- = 0 ;
// replace trailing spaces with '\0'
while ( cp2 > str && isspace(*cp2) )
*cp2-- = 0 ;
return str ;
}
#else
char *trim(char *str) ;
#endif /* #ifdef _HREXX_C_ */
#endif /* #ifndef _HREXX_TRIM_C */
#endif /* #ifndef _HREXX_H_ */