1 /* 2 * Copyright (C) 1998-2001 Mark Hessling <M.Hessling@qut.edu.au> 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public 15 * License along with this library; if not, write to the Free 16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 */ 18 19 #ifndef _RXPACK_H 20 #define _RXPACK_H 21 22 #ifdef HAVE_CONFIG_H 23 # include "config.h" 24 #else 25 # include "defines.h" 26 #endif 27 28 #include <stdio.h> 29 30 #ifdef HAVE_CTYPE_H 31 # include <ctype.h> 32 #endif 33 34 #ifdef HAVE_STDLIB_H 35 # include <stdlib.h> 36 #endif 37 38 #ifdef HAVE_STRING_H 39 # include <string.h> 40 #endif 41 42 #ifdef HAVE_ERRNO_H 43 # include <errno.h> 44 #endif 45 46 #ifdef HAVE_ASSERT_H 47 # include <assert.h> 48 #endif 49 50 #ifdef HAVE_SYS_TYPES_H 51 # include <sys/types.h> 52 #endif 53 54 #ifdef HAVE_SYS_STAT_H 55 # include <sys/stat.h> 56 #endif 57 58 #ifdef HAVE_DIRENT_H 59 # include <dirent.h> 60 #endif 61 62 #ifdef HAVE_MALLOC_H 63 # include <malloc.h> 64 #endif 65 66 #ifdef HAVE_MATH_H 67 # include <math.h> 68 #endif 69 70 #ifdef HAVE_STDARG_H 71 # include <stdarg.h> 72 #endif 73 74 #ifdef HAVE_UNISTD_H 75 # include <unistd.h> 76 #endif 77 78 #ifdef HAVE_GETOPT_H 79 # include <getopt.h> 80 #endif 81 82 #ifdef HAVE_IO_H 83 # include <io.h> 84 #endif 85 86 #ifdef HAVE_FCNTL_H 87 # include <fcntl.h> 88 #endif 89 90 /* 91 * All things that this application may require out of os2.h must be 92 * specified here in one place. This is because EMX includes all Rexx 93 * related stuff in os2.h, not in a serperate header file. This makes 94 * it difficult to use another Rexx interpreter with EMX :-( 95 */ 96 #if defined(OS2) || defined(__OS2__) 97 # if !defined(EMXVIDEO) 98 # define INCL_VIO 99 # define INCL_KBD 100 # endif 101 # if defined(USE_OS2REXX) 102 # define INCL_RXSHV /* Shared variable support */ 103 # define INCL_RXFUNC /* External functions support */ 104 # define INCL_RXSYSEXIT /* System exit routines */ 105 # define INCL_RXSUBCOM /* Subcommand routines */ 106 # include <os2.h> 107 # else 108 # include <os2.h> 109 # define INCL_RXSHV /* Shared variable support */ 110 # define INCL_RXFUNC /* External functions support */ 111 # define INCL_RXSYSEXIT /* System exit routines */ 112 # define INCL_RXSUBCOM /* Subcommand routines */ 113 # endif 114 #else 115 # define INCL_RXSHV /* Shared variable support */ 116 # define INCL_RXFUNC /* External functions support */ 117 # define INCL_RXSYSEXIT /* System exit routines */ 118 # define INCL_RXSUBCOM /* Subcommand routines */ 119 #endif 120 121 /* 122 * The following header file is supplied by the application package. 123 * It specifies any application-specific header files and #defines 124 * the following: 125 * RXPACKAGE_MAGIC_NUMBER 12345 - any number 126 * RXPACKAGE_DEBUG_VAR "ENV_VAR" - an env variable enclosed in quotes 127 */ 128 #include "apphead.h" 129 130 #include "rxdef.h" 131 132 #define RETBUFLEN 250 133 134 #if defined(DYNAMIC) 135 # define DYNAMIC_LIBRARY 1 136 #endif 137 138 #ifndef TRUE 139 # define TRUE 1 140 # define FALSE 0 141 #endif 142 143 /* 144 * Run time modes 145 */ 146 #define MODE_DEBUG 1 147 #define MODE_VERBOSE 2 148 #define MODE_INTERNAL 4 149 #define MODE_HALTONERROR 8 150 151 #define REXX_FAIL 1 152 153 #define RXSTRCAT(dst,dstlen,src,srclen) \ 154 { \ 155 memcpy((dst)+(dstlen),(src),(srclen)); \ 156 (dstlen)+=(srclen); \ 157 *((dst)+(dstlen))='\0'; \ 158 } 159 #define RXSTRCPY(dst,dstlen,src,srclen) \ 160 { \ 161 memcpy((dst),(src),(srclen)); \ 162 (dstlen)=(srclen); \ 163 *((dst)+(dstlen))='\0'; \ 164 } 165 166 #if !defined(max) 167 # define max(a,b) (((a) > (b)) ? (a) : (b)) 168 #endif 169 170 #if !defined(min) 171 # define min(a,b) (((a) < (b)) ? (a) : (b)) 172 #endif 173 174 #if !defined(MAX_PATH) 175 # if defined(NAME_MAX) 176 # define MAX_PATH NAME_MAX 177 # elif defined(MAXNAMLEN) 178 # define MAX_PATH MAXNAMLEN 179 # else 180 # define MAX_PATH 255 181 # endif 182 #endif 183 184 typedef int RX_INT; 185 typedef unsigned int RX_UINT; 186 typedef long RX_LONG; 187 typedef unsigned long RX_ULONG; 188 189 /* 190 * Typedef a common "long long" 191 */ 192 #if defined(_MSC_VER) || defined(__LCC__) 193 /* MS VC++ or LCC on Win32 */ 194 typedef signed __int64 rx_long_long; 195 # define RX_LL_FORMAT "%I64d" 196 #elif (defined(__WATCOMC__) && !defined(__QNX__)) || (defined(__GNUC__) && defined(WIN32)) 197 /* Watcom C++ on WIn32 or OS/2 or Cygwin on Win32 */ 198 typedef long long rx_long_long; 199 # define RX_LL_FORMAT "%I64d" 200 #elif defined(HAVE_LONG_LONG) 201 /* Any compiler that supports "long long" */ 202 typedef long long rx_long_long; 203 # define RX_LL_FORMAT "%lld" 204 #else 205 /* No "long long" support; make it "long" */ 206 typedef long rx_long_long; 207 # define RX_LL_FORMAT "%ld" 208 #endif 209 210 #ifdef USE_REXX6000 211 typedef USHORT RexxFunctionHandler(PSZ, ULONG, PRXSTRING, PSZ, PRXSTRING) ; 212 #endif 213 /* 214 * Standard REXX API function - idea borrowed from Patrick McPhee's Regutil 215 */ 216 #define rxfunc(x) APIRET APIENTRY x( RFH_ARG0_TYPE name, RFH_ARG1_TYPE argc, RFH_ARG2_TYPE argv, RFH_ARG3_TYPE stck, RFH_ARG4_TYPE retstr ) 217 218 /*----------------------------------------------------------------------------- 219 * Definition of an external function 220 *----------------------------------------------------------------------------*/ 221 typedef struct { 222 RRFD_ARG0_TYPE ExternalName; 223 RRFE_ARG1_TYPE EntryPoint; 224 RRFD_ARG2_TYPE InternalName; 225 int DllLoad; 226 } RexxFunction; 227 228 /* 229 * The following structure contains all "global" data common to all 230 * external function packages. A similar structure should exists 231 * for package-specific data. 232 */ 233 typedef struct 234 { 235 int RxRunFlags; /* debug/verbose flags */ 236 char FName[100]; /* current function name */ 237 char PreviousConstantPrefix[11]; /* previous constant variables prefix */ 238 char ConstantPrefix[11]; /* constant variables prefix */ 239 FILE *RxTraceFilePointer; /* file pointer for all output */ 240 char RxTraceFileName[MAX_PATH]; /* filename of output file */ 241 int deallocate; /* indicates if rxpack should deallocate this structure */ 242 int terminated; /* indicates if rxpack has called RxTermPackage() for this structure */ 243 } RxPackageGlobalDataDef; 244 245 /* 246 * The following structure contains details of a package's constants 247 */ 248 typedef struct 249 { 250 char *name; /* base name of constant */ 251 int type; /* 0 (numeric), 1 (text), 2 (float), 3 (char) */ 252 long numeric_value; /* numeric value of constant */ 253 char *text_value; /* text value of constant */ 254 double double_value; /* double value of constant */ 255 char char_value; /* char value of constant */ 256 } RxPackageConstantDef; 257 258 typedef int PackageInitialiser( RxPackageGlobalDataDef * ); 259 typedef int PackageTerminator( RxPackageGlobalDataDef * ); 260 261 #ifdef HAVE_PROTO 262 # define Args(a) a 263 #else 264 # define Args(a) () 265 #endif 266 267 RxPackageGlobalDataDef *FunctionPrologue Args(( RxPackageGlobalDataDef *, PackageInitialiser *, char *, ULONG, RFH_ARG2_TYPE )); 268 void FunctionTrace Args(( RxPackageGlobalDataDef *, char *, ... )); 269 long FunctionEpilogue Args(( RxPackageGlobalDataDef *, char *, long )); 270 void InternalTrace Args(( RxPackageGlobalDataDef *, char *, ... )); 271 void RxDisplayError Args(( RxPackageGlobalDataDef *, RFH_ARG0_TYPE, ... )); 272 RxPackageGlobalDataDef *InitRxPackage Args(( RxPackageGlobalDataDef *, PackageInitialiser *, int * )); 273 int TermRxPackage Args(( RxPackageGlobalDataDef **, PackageTerminator *, RexxFunction *, char *, int )); 274 int RegisterRxFunctions Args(( RxPackageGlobalDataDef *, RexxFunction *, char * )); 275 int RegisterRxSubcom Args(( RxPackageGlobalDataDef *, RexxSubcomHandler )); 276 int RegisterRxInit Args(( RxPackageGlobalDataDef *, RexxExitHandler, char *)); 277 int QueryRxFunction Args(( RxPackageGlobalDataDef *, char * )); 278 int DeregisterRxFunctions Args(( RxPackageGlobalDataDef *, RexxFunction *, int )); 279 int SetPackageConstants Args(( RxPackageGlobalDataDef *, RxPackageConstantDef *, char *, int )); 280 char *make_upper Args(( char * )); 281 char *AllocString Args(( char *, int )); 282 char *MkAsciz Args(( char *, int, char *, int )); 283 int SetRexxVariable Args(( RxPackageGlobalDataDef *,char *, int, char *, int )); 284 RXSTRING *GetRexxVariable Args(( RxPackageGlobalDataDef *, char *, RXSTRING *, int )); 285 int *GetRexxVariableInteger Args(( RxPackageGlobalDataDef *, char *, int *, int )); 286 int DropRexxVariable Args(( RxPackageGlobalDataDef *,char *, int )); 287 int StrToInt Args(( RXSTRING *, ULONG * )); 288 int StrToNumber Args(( RXSTRING *, LONG * )); 289 int StrToBool Args(( RXSTRING *, ULONG * )); 290 int RxSetTraceFile Args(( RxPackageGlobalDataDef *, char * )); 291 char *RxGetTraceFile Args(( RxPackageGlobalDataDef * )); 292 int RxSetConstantPrefix Args(( RxPackageGlobalDataDef *, char * )); 293 char *RxGetConstantPrefix Args(( RxPackageGlobalDataDef * )); 294 void RxSetRunFlags Args(( RxPackageGlobalDataDef *, int )); 295 int RxGetRunFlags Args(( RxPackageGlobalDataDef * )); 296 int RxReturn Args(( RxPackageGlobalDataDef *, RXSTRING * )); 297 int RxReturnString Args(( RxPackageGlobalDataDef *, RXSTRING *, char * )); 298 int RxReturnStringAndFree Args(( RxPackageGlobalDataDef *, RXSTRING *, char *, int )); 299 int RxReturnDataAndFree Args(( RxPackageGlobalDataDef *RxPackageGlobalData, RXSTRING *retstr, void *str, long len, int freeit )); 300 int RxReturnNumber Args(( RxPackageGlobalDataDef *, RXSTRING *, long )); 301 int RxReturnUnsignedNumber Args(( RxPackageGlobalDataDef *, RXSTRING *, ULONG )); 302 int RxReturnDouble Args(( RxPackageGlobalDataDef *, RXSTRING *, double )); 303 int RxReturnPointer Args(( RxPackageGlobalDataDef *, RXSTRING *, void * )); 304 int memcmpi Args(( char *, char *, int )); 305 int my_checkparam Args(( RxPackageGlobalDataDef *, RFH_ARG0_TYPE, int, int, int )); 306 int RxStrToInt Args(( RxPackageGlobalDataDef *, RXSTRING *, int * )); 307 int RxStrToUInt Args(( RxPackageGlobalDataDef *, RXSTRING *, unsigned int * )); 308 int RxStrToLong Args(( RxPackageGlobalDataDef *, RXSTRING *, long * )); 309 int RxStrToULong Args(( RxPackageGlobalDataDef *, RXSTRING *, unsigned long * )); 310 int RxStrToDouble Args(( RxPackageGlobalDataDef *, RXSTRING *, double * )); 311 int RxStemToCharArray Args(( RxPackageGlobalDataDef *, RXSTRING *, char *** )); 312 void RxFreeCharArray Args(( char **, int )); 313 int RxStemToIntArray Args(( RxPackageGlobalDataDef *, RXSTRING *, int ** )); 314 void RxFreeIntArray Args(( int * )); 315 int RxStemToUIntArray Args(( RxPackageGlobalDataDef *, RXSTRING *, unsigned int ** )); 316 void RxFreeUIntArray Args(( unsigned int * )); 317 int RxStemToLongArray Args(( RxPackageGlobalDataDef *, RXSTRING *, long ** )); 318 void RxFreeLongArray Args(( long * )); 319 int RxStemToULongArray Args(( RxPackageGlobalDataDef *, RXSTRING *, unsigned long ** )); 320 void RxFreeULongArray Args(( unsigned long * )); 321 int RxNumberToVariable Args(( RxPackageGlobalDataDef *, RXSTRING *, ULONG )); 322 323 #ifdef DEBUG 324 # define DEBUGDUMP(x) {x;} 325 #else 326 # define DEBUGDUMP(x) {} 327 #endif 328 /* 329 * Directory and PATH separators 330 */ 331 #if defined(MSDOS) || ( defined(__WATCOMC__) && !defined(__QNX__) ) || defined(_MSC_VER) || defined(DOS) || defined(OS2) ||defined(__OS2__) || defined(__WINS__) || defined(__EPOC32__) || defined(__LCC__) 332 # define FILE_SEPARATORS "\\/:" 333 # define FILE_SEPARATOR '\\' 334 # define FILE_SEPARATOR_STR "\\" 335 # define PATH_SEPARATOR ';' 336 # define PATH_SEPARATOR_STR ";" 337 #elif defined(VMS) 338 # define FILE_SEPARATORS "]" 339 # define FILE_SEPARATOR ']' 340 # define FILE_SEPARATOR_STR "]" 341 # define PATH_SEPARATOR '?' 342 # define PATH_SEPARATOR_STR "?" 343 #elif defined(MAC) 344 # define FILE_SEPARATOR "]" 345 # define FILE_SEPARATOR ']' 346 # define FILE_SEPARATOR_STR "]" 347 # define PATH_SEPARATOR '?' 348 # define PATH_SEPARATOR_STR "?" 349 #else 350 # define FILE_SEPARATORS "/" 351 # define FILE_SEPARATOR '/' 352 # define FILE_SEPARATOR_STR "/" 353 # define PATH_SEPARATOR ':' 354 # define PATH_SEPARATOR_STR ":" 355 #endif 356 357 #endif /* !_RXPACK_H */ 358