File: test1.c

package info (click to toggle)
regina 0.08d-2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 2,116 kB
  • ctags: 2,999
  • sloc: ansic: 24,435; sh: 1,520; lex: 1,322; yacc: 1,115; makefile: 573; cpp: 280
file content (229 lines) | stat: -rw-r--r-- 5,851 bytes parent folder | download
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
218
219
220
221
222
223
224
225
226
227
228
229


#define INCL_RXSHV	/* Shared variable support */
#define INCL_RXFUNC	/* External functions support */

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "rexxsaa.h"

#if defined(__WATCOMC__) || defined(__IBMC__) || defined(_MSC_VER)
# define DLLNAME "TEST1"
#else
# define DLLNAME "test1.rxlib"
#endif


#define FUNCTION1 Test1Function1
#define FUNCTION2 Test1Function2
#define LOADFUNCS Test1LoadFuncs
#define DROPFUNCS Test1DropFuncs

#define NAME_FUNCTION1 "Test1Function1"
#define NAME_FUNCTION2 "Test1Function2"
#define NAME_LOADFUNCS "Test1LoadFuncs"
#define NAME_DROPFUNCS "Test1DropFuncs"

RexxFunctionHandler Test1Function1;
RexxFunctionHandler Test1Function2;
RexxFunctionHandler Test1LoadFuncs;
RexxFunctionHandler Test1DropFuncs;

/*-----------------------------------------------------------------------------
 * Table entry for a REXX/SQL function.
 *----------------------------------------------------------------------------*/
typedef	struct {
	PSZ	function_name;
	PFN	EntryPoint;
} RexxFunction;

/*-----------------------------------------------------------------------------
 * Table of REXX/SQL Functions. Used to install/de-install functions.
 *----------------------------------------------------------------------------*/
static RexxFunction RexxSqlFunctions[] = {
   {(PSZ)NAME_FUNCTION1,   (PFN)Test1Function1  },
   {(PSZ)NAME_FUNCTION2,   (PFN)Test1Function2  },
   {(PSZ)NAME_DROPFUNCS,   (PFN)Test1DropFuncs  },
   {NULL,NULL}
};

/*-----------------------------------------------------------------------------
 * Uppercases the supplied string.
 *----------------------------------------------------------------------------*/
char *make_upper

#if __STDC__
    (char *str)
#else
    (str)
    char    *str;
#endif

{
 char *save_str=str;
 while(*str)
   {
    if (islower(*str))
       *str = toupper(*str);
    ++str;
   }
 return(save_str);
}

/*-----------------------------------------------------------------------------
 * Allocate memory for a char * based on an RXSTRING
 *----------------------------------------------------------------------------*/
char *AllocString

#if __STDC__
    (char *buf, size_t bufsize)
#else
    (buf, bufsize)
    char    *buf;
    size_t  bufsize;
#endif
{
    char *tempstr=NULL;

    tempstr = (char *)malloc(sizeof(char)*(bufsize+1));
    return tempstr;
}


/*-----------------------------------------------------------------------------
 * Copy a non terminated character array to the nominated buffer (truncate
 * if necessary) and null terminate.
 *----------------------------------------------------------------------------*/
char *MkAsciz

#if __STDC__
    (char *buf, size_t bufsize, char *str, size_t len)
#else
    (buf, bufsize, str, len)
    char    *buf;
    size_t  bufsize;
    char    *str;
    size_t  len;
#endif

{
 bufsize--;	/* Make room for terminating byte */
 if (len > bufsize)
    len = bufsize;
 (void)memcpy(buf, str, len);
 buf[len] = '\0';
 return buf;
}

static void static_show_parameter(ULONG	argc,RXSTRING	argv[],PSZ func_name)
{
 char buf[100];
 if (argc == 0)
   {
    printf("%s(static): *** No parameters passed ***\n",DLLNAME);
    return;
   }
 memcpy(buf,argv[0].strptr,argv[0].strlength);
 buf[argv[0].strlength] = '\0';
 if (strcmp(func_name,buf) != 0)
    printf("%s(static): *** Mismatch of parameters: %s is NOT expected: %s ***\n",
               DLLNAME,buf,func_name);
 return;
}

void global_show_parameter(ULONG	argc,RXSTRING	argv[],PSZ func_name)
{
 char buf[100];
 if (argc == 0)
   {
    printf("%s(global): *** No parameters passed ***\n",DLLNAME);
    return;
   }
 memcpy(buf,argv[0].strptr,argv[0].strlength);
 buf[argv[0].strlength] = '\0';
 if (strcmp(func_name,buf) != 0)
    printf("%s(global): *** Mismatch of parameters: %s is NOT expected: %s ***\n",
               DLLNAME,buf,func_name);
 return;
}

APIRET APIENTRY FUNCTION1
    (PUCHAR		name,ULONG	argc,RXSTRING	argv[],PSZ		stck,RXSTRING	*retstr)
{
 int i=0;
 for (i=0;i<argc;i++)
   printf("%s(Test1Function1): Arg: %d <%s>\n",DLLNAME,i,argv[i].strptr);
 static_show_parameter(argc,argv,NAME_FUNCTION1);
 global_show_parameter(argc,argv,NAME_FUNCTION1);
 strcpy(retstr->strptr,"0");
 retstr->strlength = 1;
 return 0L;
}

APIRET APIENTRY FUNCTION2
    (PUCHAR		name,ULONG	argc,RXSTRING	argv[],PSZ		stck,RXSTRING	*retstr)
{
 int i=0;
 for (i=0;i<argc;i++)
   printf("%s(Test1Function2): Arg: %d <%s>\n",DLLNAME,i,argv[i].strptr);
 static_show_parameter(argc,argv,NAME_FUNCTION2);
 global_show_parameter(argc,argv,NAME_FUNCTION2);
 strcpy(retstr->strptr,"0");
 retstr->strlength = 1;
 return 0L;
}


APIRET APIENTRY DROPFUNCS
    (PUCHAR		name,ULONG	argc,RXSTRING	argv[],PSZ		stck,RXSTRING	*retstr)
{
 int rc=0;
 RexxFunction  *func=NULL;
    
 /* DeRegister all REXX/SQL functions */
 for (func = RexxSqlFunctions; func->function_name; func++)
   {
    rc = RexxDeregisterFunction(func->function_name);
   }
 sprintf(retstr->strptr,"%d",rc);
 retstr->strlength = strlen(retstr->strptr);
 return 0L;
}


/*-----------------------------------------------------------------------------
 * This function is called to initiate REXX/SQL interface.
 *----------------------------------------------------------------------------*/
static int InitRexxSQL

#ifdef __STDC__
    (PSZ progname)
#else
    (progname)
    PSZ progname;
#endif

{
    RexxFunction  *func=NULL;
    ULONG rc=0L;

    /* Register all REXX/SQL functions */
    for (func = RexxSqlFunctions; func->function_name; func++)
      {
        rc = RexxRegisterFunctionDll(func->function_name,DLLNAME,func->function_name);
      }
    return 0;
}

APIRET APIENTRY LOADFUNCS
    (PUCHAR		name,ULONG	argc,RXSTRING	argv[],PSZ		stck,RXSTRING	*retstr)
{
 int rc=0;

 rc = InitRexxSQL(DLLNAME);
 sprintf(retstr->strptr,"%d",rc);
 retstr->strlength = strlen(retstr->strptr);
 return 0L;
}