forked from adesutherland/CMS-370-BREXX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
170 lines (143 loc) · 4.35 KB
/
main.c
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
/*
* main.c
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <cmssys.h>
#include "lstring.h"
#include "rexx.h"
#include "rxdefs.h"
#include "context.h"
void __CRT0(void); /* Entry Point pointer */
/* ------- Includes for any other external library ------- */
#ifdef RXCONIO
extern void __CDECL RxConIOInitialize();
#endif
#ifdef RXMYSQLSTATIC
# include "rxmysql.c"
#endif
/* Compare argument */
int issamearg(const char *arg, const char *val) {
const char *c1 = arg;
const char *c2 = val;
while (*c1 == toupper(*c2)) {
if (*c1 == 0) return 1;
c1++;
c2++;
}
return 0;
}
/* --------------------- main ---------------------- */
int __CDECL
main(int ac, char *av[]) {
Lstr args[MAXARGS], tracestr;
int ia, ir, i;
int returnCode;
int entry_point;
Context *context;
if (!ac) return -1; /* Should never happen! */
if (CMScalltype() != 5) {
if (issamearg("DMSREX", av[0])) {
int version = 0;
int debug = 0;
int error = 0;
/* Temporary aid to register entry point for HRC402DS */
/* Will be removed once BREXX CMS deployment approach confirmed */
/* Entry point for REXX is stored @ 0x90 - NUCRSV6 */
#define REXX_ENTRY_HANDLE 0x90
/* Register Entry Point Address */
entry_point = (int) __CRT0;
CMSSetNUCON((void *) REXX_ENTRY_HANDLE, entry_point);
if (ac > 1) {
if (ac > 2) error = 1;
if (ac == 2) {
if (issamearg("VERSION", av[1])) {
version = 1;
} else if (issamearg("DEBUG", av[1])) {
version = 1;
debug = 1;
__SDEBUG(1);
} else error = 1;
}
}
if (error) {
printf("Invalid arguments\n");
printf(" DMSREX [VERSION|DEBUG]\n");
return -1;
}
if (version) {
printf("BREXX Version %s\n", CMS_VERSION);
}
if (debug) {
printf("BREXX Entry Address is 0x%x saved in NUCON at 0x%x\n",
entry_point, REXX_ENTRY_HANDLE);
}
return 0;
}
}
InitContext();
context = (Context *) CMSGetPG();
for (ia = 0; ia < MAXARGS; ia++) LINITSTR(args[ia]);
LINITSTR(tracestr);
/* Start Processing arguments */
if (CMScalltype() == 5) ia = 0;
else {
ia = 1;
/* Debug flag */
#ifdef __DEBUG__
(context->rexx__debug__) = FALSE;
#endif
if (issamearg("-D", av[ia])) {
ia++;
#ifdef __DEBUG__
(context->rexx__debug__) = TRUE;
__SDEBUG(1);
#else
printf("WARNING: BREXX not compiled with debug, -D ignored\n");
#endif
}
}
/* No program name */
if (ia >= ac) {
return 0;
}
/* --- Initialise --- */
RxInitialize(av[ia]);
/* Trace Flag */
if (CMSGetFlag(TRACEFLAG)) Lscpy(&tracestr, "?A"); /* Trace All? */
/* prepare arguments for program */
if (CMScalltype() == 5) {
ADLEN *param = CMSeplist()->ArgList;
if (param) {
for (i = 0; (int) (param[i].Data) != -1; i++) {
Lmcpy(&args[i], param[i].Data, param[i].Len);
}
}
} else {
for (ir = ia + 1; ir < ac; ir++) {
Lcat(&args[0], av[ir]);
if (ir < ac - 1) Lcat(&args[0], " ");
}
}
Lscpy(&(context->rexxrxReturnResult), "0");
(context->rexxrxReturnCode) = 0;
RxRun(av[ia], NULL, args, &tracestr, NULL);
/* Need to get the result here before RxFinalise() */
returnCode = (context->rexxrxReturnCode);
L2STR(&(context->rexxrxReturnResult));
LASCIIZ((context->rexxrxReturnResult)); /* Make sure its a C str */
CMSreturndata(LSTR(context->rexxrxReturnResult),
LLEN(context->rexxrxReturnResult)); /* If calltype 5 */
/* --- Free everything --- */
RxFinalize();
for (ia = 0; ia < MAXARGS; ia++) LFREESTR(args[ia]);
LFREESTR(tracestr);
#ifdef __DEBUG__
if ((context->rexx__debug__) && mem_allocated()!=0) {
fprintf(STDERR,"\nMemory left allocated: %ld\n",mem_allocated());
mem_list();
}
#endif
return returnCode;
} /* main */