Build fix.
[AROS-Contrib.git] / regina / test2.c
blob7b00add2410de0ec34f70cdae3e089da7e8b02b0
3 #define INCL_RXSHV /* Shared variable support */
4 #define INCL_RXFUNC /* External functions support */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <ctype.h>
10 #include "rexxsaa.h"
12 #ifdef _MSC_VER
13 /* This picky compiler claims about unused formal parameters.
14 * This is correct but hides (for human eyes) other errors since they
15 * are many and we can't reduce them all.
16 * Error 4100 is "unused formal parameter".
18 # pragma warning(disable:4100)
19 #endif
21 #define DLLNAME "rxtest2"
24 #define FUNCTION1 Test2Function1
25 #define FUNCTION2 Test2Function2
26 #define LOADFUNCS Test2LoadFuncs
27 #define DROPFUNCS Test2DropFuncs
29 #define NAME_FUNCTION1 "Test2Function1"
30 #define NAME_FUNCTION2 "Test2Function2"
31 #define NAME_LOADFUNCS "Test2LoadFuncs"
32 #define NAME_DROPFUNCS "Test2DropFuncs"
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 RexxFunctionHandler Test2Function1;
38 RexxFunctionHandler Test2Function2;
39 RexxFunctionHandler Test2LoadFuncs;
40 RexxFunctionHandler Test2DropFuncs;
41 #ifdef __cplusplus
43 #endif
45 /*-----------------------------------------------------------------------------
46 * Table entry for a REXX function.
47 *----------------------------------------------------------------------------*/
48 typedef struct {
49 PSZ function_name;
50 PFN EntryPoint;
51 } RexxTestFunction;
53 /*-----------------------------------------------------------------------------
54 * Table of REXX Functions. Used to install/de-install functions.
55 *----------------------------------------------------------------------------*/
56 static const RexxTestFunction RexxTestFunctions[] = {
57 {(PSZ)NAME_FUNCTION1, (PFN)Test2Function1 },
58 {(PSZ)NAME_FUNCTION2, (PFN)Test2Function2 },
59 {(PSZ)NAME_DROPFUNCS, (PFN)Test2DropFuncs },
60 {(PSZ)NAME_LOADFUNCS, (PFN)Test2LoadFuncs },
61 {NULL,NULL}
64 static char *make_upper( char *in )
66 int len = strlen( in );
67 int i;
69 for ( i = 0; i < len; i++ )
71 if ( islower( in[i] ) )
72 in[i] = (char)toupper( in[i] );
74 return in;
77 static int set_rexx_variable( char *name, int suffix, char *value, int value_length )
79 SHVBLOCK shv;
80 char variable_name[250];
81 int rc=0;
83 shv.shvnext=NULL; /* only one block */
84 shv.shvcode=RXSHV_SET; /* use direct set */
85 sprintf( variable_name, "%s.%-d", name, suffix );
86 (void)make_upper( variable_name );/* make variable name uppercase */
88 * Now (attempt to) set the REXX variable
89 * Add name/value to SHVBLOCK
91 MAKERXSTRING( shv.shvname, variable_name, strlen( variable_name) );
92 MAKERXSTRING( shv.shvvalue, value, value_length );
94 * One or both of these is needed, too <sigh>
96 shv.shvnamelen = strlen( variable_name );
97 shv.shvvaluelen = value_length;
99 rc = RexxVariablePool( &shv ); /* Set the REXX variable */
100 if ( rc != RXSHV_OK
101 && rc != RXSHV_NEWV)
103 rc = 1;
105 else
106 rc = 0;
107 return rc;
110 static void static_show_parameter(ULONG argc, RXSTRING argv[], PSZ func_name)
112 char buf[100];
113 if (argc == 0)
115 printf(" %s(static): *** No parameters passed ***\n",DLLNAME);
116 return;
118 memcpy(buf,argv[0].strptr,argv[0].strlength);
119 buf[argv[0].strlength] = '\0';
120 if (strcmp(func_name,buf) != 0)
121 printf(" %s(static): *** Mismatch of parameters: %s is NOT expected: %s ***\n",
122 DLLNAME,buf,func_name);
123 return;
126 #if defined(DYNAMIC_STATIC)
127 static void global_show_parameter(ULONG argc, RXSTRING argv[], PSZ func_name)
128 #else
129 void global_show_parameter(ULONG argc, RXSTRING argv[], PSZ func_name)
130 #endif
132 char buf[100];
133 if (argc == 0)
135 printf(" %s(global): *** No parameters passed ***\n",DLLNAME);
136 return;
138 memcpy(buf,argv[0].strptr,argv[0].strlength);
139 buf[argv[0].strlength] = '\0';
140 if (strcmp(func_name,buf) != 0)
141 printf(" %s(global): *** Mismatch of parameters: %s is NOT expected: %s ***\n",
142 DLLNAME,buf,func_name);
143 return;
146 APIRET APIENTRY FUNCTION1(PCSZ name,ULONG argc,PRXSTRING argv,PCSZ stck,PRXSTRING retstr)
148 int i=0;
149 char tmp[50];
151 for ( i = 0; i < (int)argc; i++ )
153 printf(" %s(Test2Function1): Arg: %d <%s>\n", DLLNAME, i, argv[i].strptr );
155 * Set Rexx variables for each argument...
157 if ( set_rexx_variable( (char *)name, i+1, argv[i].strptr, argv[i].strlength ) == 1 )
158 printf( "%s(Test2Function1): Error setting variable for Arg: %d <%s.%d>\n", DLLNAME, i+1, argv[i].strptr, i+1 );
160 sprintf( tmp, "%ld", argc );
161 if ( set_rexx_variable( (char *)name, 0, tmp, strlen( tmp ) ) == 1 )
162 printf( "%s(Test2Function1): Error setting stem index.\n", DLLNAME );
163 static_show_parameter(argc,argv,NAME_FUNCTION1);
164 global_show_parameter(argc,argv,NAME_FUNCTION1);
166 * Set return code...
168 strcpy(retstr->strptr,"0");
169 retstr->strlength = 1;
170 return 0L;
173 APIRET APIENTRY FUNCTION2(PCSZ name,ULONG argc,PRXSTRING argv,PCSZ stck,PRXSTRING retstr)
175 int i=0;
176 char tmp[50];
178 for ( i = 0; i < (int)argc; i++ )
180 printf( " %s(Test2Function2): Arg: %d <%s>\n", DLLNAME, i, argv[i].strptr );
182 * Set Rexx variables for each argument...
184 if ( set_rexx_variable( (char *)name, i+1, argv[i].strptr, argv[i].strlength ) == 1 )
185 printf( "%s(Test2Function2): Error setting variable for Arg: %d <%s.%d>\n", DLLNAME, i+1, argv[i].strptr, i+1 );
187 sprintf( tmp, "%ld", argc );
188 if ( set_rexx_variable( (char *)name, 0, tmp, strlen( tmp ) ) == 1 )
189 printf( "%s(Test12unction2): Error setting stem index.\n", DLLNAME );
190 static_show_parameter(argc,argv,NAME_FUNCTION2);
191 global_show_parameter(argc,argv,NAME_FUNCTION2);
193 * Set return code...
195 strcpy(retstr->strptr,"0");
196 retstr->strlength = 1;
197 return 0L;
201 APIRET APIENTRY DROPFUNCS(PCSZ name,ULONG argc,PRXSTRING argv,PCSZ stck,PRXSTRING retstr)
203 int rc=0;
204 const RexxTestFunction *func=NULL;
206 /* DeRegister all REXX functions */
207 for (func = RexxTestFunctions; func->function_name; func++)
208 rc = RexxDeregisterFunction(func->function_name);
209 sprintf(retstr->strptr,"%d",rc);
210 retstr->strlength = strlen(retstr->strptr);
211 return 0L;
215 /*-----------------------------------------------------------------------------
216 * This function is called to initiate REXX interface.
217 *----------------------------------------------------------------------------*/
218 static int InitTestRexx(PSZ progname)
220 const RexxTestFunction *func=NULL;
221 ULONG rc=0L;
223 /* Register all REXX functions */
224 for (func = RexxTestFunctions; func->function_name; func++)
225 rc = RexxRegisterFunctionDll(func->function_name,DLLNAME,func->function_name);
227 return 0;
230 APIRET APIENTRY LOADFUNCS(PCSZ name,ULONG argc,PRXSTRING argv,PCSZ stck,PRXSTRING retstr)
232 int rc=0;
234 rc = InitTestRexx(DLLNAME);
235 printf(" %s built %s %s\n",DLLNAME,__DATE__,__TIME__);
236 sprintf(retstr->strptr,"%d",rc);
237 retstr->strlength = strlen(retstr->strptr);
238 return 0L;
241 #if defined( DYNAMIC_STATIC )
242 void *getTest2FunctionAddress( char *name )
244 const RexxTestFunction *func=NULL;
245 for (func = RexxTestFunctions; func->function_name; func++)
247 if ( strcmp( func->function_name, name) == 0 )
248 return func->EntryPoint;
250 return NULL;
252 #endif
254 #if !defined( DYNAMIC_STATIC )
255 # ifdef SKYOS
257 * Required as entry point for DLL under SkyOS
259 int DllMain( void )
261 return 0;
263 # endif
264 #endif