bringing SDL 1.2.14 from vendor into the main branch
[AROS-Contrib.git] / regina / test1.c
blobb7d7b87aa074d4cde7ea1a40847fb8ece5eca7f1
3 #define INCL_RXSHV /* Shared variable support */
4 #define INCL_RXFUNC /* External functions support */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <ctype.h>
9 #include "rexxsaa.h"
11 #ifdef _MSC_VER
12 /* This picky compiler claims about unused formal parameters.
13 * This is correct but hides (for human eyes) other errors since they
14 * are many and we can't reduce them all.
15 * Error 4100 is "unused formal parameter".
17 # pragma warning(disable:4100)
18 #endif
20 #define DLLNAME "test1"
23 #define FUNCTION1 Test1Function1
24 #define FUNCTION2 Test1Function2
25 #define LOADFUNCS Test1LoadFuncs
26 #define DROPFUNCS Test1DropFuncs
28 #define NAME_FUNCTION1 "Test1Function1"
29 #define NAME_FUNCTION2 "Test1Function2"
30 #define NAME_LOADFUNCS "Test1LoadFuncs"
31 #define NAME_DROPFUNCS "Test1DropFuncs"
33 RexxFunctionHandler Test1Function1;
34 RexxFunctionHandler Test1Function2;
35 RexxFunctionHandler Test1LoadFuncs;
36 RexxFunctionHandler Test1DropFuncs;
38 /*-----------------------------------------------------------------------------
39 * Table entry for a REXX/SQL function.
40 *----------------------------------------------------------------------------*/
41 typedef struct {
42 PSZ function_name;
43 PFN EntryPoint;
44 } RexxFunction;
46 /*-----------------------------------------------------------------------------
47 * Table of REXX/SQL Functions. Used to install/de-install functions.
48 *----------------------------------------------------------------------------*/
49 static const RexxFunction RexxSqlFunctions[] = {
50 {(PSZ)NAME_FUNCTION1, (PFN)Test1Function1 },
51 {(PSZ)NAME_FUNCTION2, (PFN)Test1Function2 },
52 {(PSZ)NAME_DROPFUNCS, (PFN)Test1DropFuncs },
53 {NULL,NULL}
56 /*-----------------------------------------------------------------------------
57 * Uppercases the supplied string.
58 *----------------------------------------------------------------------------*/
59 char *make_upper(char *str)
61 char *save_str=str;
62 while(*str)
64 if (islower(*str))
65 *str = (char) toupper(*str);
66 ++str;
68 return(save_str);
71 /*-----------------------------------------------------------------------------
72 * Copy a non terminated character array to the nominated buffer (truncate
73 * if necessary) and null terminate.
74 *----------------------------------------------------------------------------*/
75 char *MkAsciz(char *buf, size_t bufsize, const char *str, size_t len)
77 bufsize--; /* Make room for terminating byte */
78 if (len > bufsize)
79 len = bufsize;
80 memcpy(buf, str, len);
81 buf[len] = '\0';
82 return buf;
85 static void static_show_parameter(ULONG argc, RXSTRING argv[], PSZ func_name)
87 char buf[100];
88 if (argc == 0)
90 printf("%s(static): *** No parameters passed ***\n",DLLNAME);
91 return;
93 memcpy(buf,argv[0].strptr,argv[0].strlength);
94 buf[argv[0].strlength] = '\0';
95 if (strcmp(func_name,buf) != 0)
96 printf("%s(static): *** Mismatch of parameters: %s is NOT expected: %s ***\n",
97 DLLNAME,buf,func_name);
98 return;
101 void global_show_parameter(ULONG argc, RXSTRING argv[], PSZ func_name)
103 char buf[100];
104 if (argc == 0)
106 printf("%s(global): *** No parameters passed ***\n",DLLNAME);
107 return;
109 memcpy(buf,argv[0].strptr,argv[0].strlength);
110 buf[argv[0].strlength] = '\0';
111 if (strcmp(func_name,buf) != 0)
112 printf("%s(global): *** Mismatch of parameters: %s is NOT expected: %s ***\n",
113 DLLNAME,buf,func_name);
114 return;
117 APIRET APIENTRY FUNCTION1(PCSZ name,ULONG argc,PRXSTRING argv,PCSZ stck,PRXSTRING retstr)
119 int i=0;
120 for (i=0;i<(int) argc;i++)
121 printf("%s(Test1Function1): Arg: %d <%s>\n",DLLNAME,i,argv[i].strptr);
122 static_show_parameter(argc,argv,NAME_FUNCTION1);
123 global_show_parameter(argc,argv,NAME_FUNCTION1);
124 strcpy(retstr->strptr,"0");
125 retstr->strlength = 1;
126 return 0L;
129 APIRET APIENTRY FUNCTION2(PCSZ name,ULONG argc,PRXSTRING argv,PCSZ stck,PRXSTRING retstr)
131 int i=0;
132 for (i=0;i<(int) argc;i++)
133 printf("%s(Test1Function2): Arg: %d <%s>\n",DLLNAME,i,argv[i].strptr);
134 static_show_parameter(argc,argv,NAME_FUNCTION2);
135 global_show_parameter(argc,argv,NAME_FUNCTION2);
136 strcpy(retstr->strptr,"0");
137 retstr->strlength = 1;
138 return 0L;
142 APIRET APIENTRY DROPFUNCS(PCSZ name,ULONG argc,PRXSTRING argv,PCSZ stck,PRXSTRING retstr)
144 int rc=0;
145 const RexxFunction *func=NULL;
147 /* DeRegister all REXX/SQL functions */
148 for (func = RexxSqlFunctions; func->function_name; func++)
149 rc = RexxDeregisterFunction(func->function_name);
150 sprintf(retstr->strptr,"%d",rc);
151 retstr->strlength = strlen(retstr->strptr);
152 return 0L;
156 /*-----------------------------------------------------------------------------
157 * This function is called to initiate REXX/SQL interface.
158 *----------------------------------------------------------------------------*/
159 static int InitRexxSQL(PSZ progname)
161 const RexxFunction *func=NULL;
162 ULONG rc=0L;
164 /* Register all REXX/SQL functions */
165 for (func = RexxSqlFunctions; func->function_name; func++)
166 rc = RexxRegisterFunctionDll(func->function_name,DLLNAME,func->function_name);
168 return 0;
171 APIRET APIENTRY LOADFUNCS(PCSZ name,ULONG argc,PRXSTRING argv,PCSZ stck,PRXSTRING retstr)
173 int rc=0;
175 rc = InitRexxSQL(DLLNAME);
176 sprintf(retstr->strptr,"%d",rc);
177 retstr->strlength = strlen(retstr->strptr);
178 return 0L;