1 #define INCL_DOSPROCESS
2 #define INCL_DOSSEMAPHORES
3 #define INCL_DOSMODULEMGR
5 #define INCL_DOSEXCEPTIONS
11 * "The Road goes ever on and on, down from the door where it began."
16 /* sbrk is limited to first heap segement so make it big */
17 #pragma runopts(HEAP(8M,500K,ANYWHERE,KEEP,8K,4K) STACK(,,ANY,) ALL31(ON))
19 #pragma runopts(HEAP(2M,500K,ANYWHERE,KEEP,8K,4K) STACK(,,ANY,) ALL31(ON))
27 static void xs_init (pTHX);
28 static PerlInterpreter *my_perl;
30 ULONG PERLEXPORTALL(PCSZ name, LONG rargc, const RXSTRING *rargv, PCSZ queuename, PRXSTRING retstr);
31 ULONG PERLDROPALL(PCSZ name, LONG rargc, const RXSTRING *rargv, PCSZ queuename, PRXSTRING retstr);
32 ULONG PERLDROPALLEXIT(PCSZ name, LONG rargc, const RXSTRING *rargv, PCSZ queuename, PRXSTRING retstr);
34 #if defined (__MINT__) || defined (atarist)
35 /* The Atari operating system doesn't have a dynamic stack. The
36 stack size is determined from this value. */
37 long _stksize = 64 * 1024;
40 /* Register any extra external extensions */
42 /* Do not delete this line--writemain depends on it */
43 EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
48 char *file = __FILE__;
50 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
53 int perlos2_is_inited;
58 /* static char *env[1] = {NULL}; */
60 Perl_OS2_init3(0, 0, 0);
64 init_perl(int doparse)
67 char *argv[3] = {"perl_in_REXX", "-e", ""};
69 if (!perlos2_is_inited) {
70 perlos2_is_inited = 1;
76 my_perl = perl_alloc();
79 perl_construct(my_perl);
80 PL_perl_destruct_level = 1;
84 exitstatus = perl_parse(my_perl, xs_init, 3, argv, (char **)NULL);
88 static char last_error[4096];
91 seterr(char *format, ...)
100 snprintf(s, sizeof(last_error) - (s - last_error), "\n");
104 vsnprintf(s, sizeof(last_error) - (s - last_error), format, va);
108 /* The REXX-callable entrypoints ... */
110 ULONG PERL (PCSZ name, LONG rargc, const RXSTRING *rargv,
111 PCSZ queuename, PRXSTRING retstr)
115 char *argv[3] = {"perl_from_REXX", "-e", buf};
119 return seterr("one argument expected, got %ld", rargc);
120 if (rargv[0].strlength >= sizeof(buf))
121 return seterr("length of the argument %ld exceeds the maximum %ld",
122 rargv[0].strlength, (long)sizeof(buf) - 1);
127 memcpy(buf, rargv[0].strptr, rargv[0].strlength);
128 buf[rargv[0].strlength] = 0;
130 exitstatus = perl_parse(my_perl, xs_init, 3, argv, (char **)NULL);
132 exitstatus = perl_run(my_perl);
135 perl_destruct(my_perl);
143 sprintf(retstr->strptr, "%s", "ok");
144 retstr->strlength = strlen (retstr->strptr);
150 ULONG PERLEXIT (PCSZ name, LONG rargc, const RXSTRING *rargv,
151 PCSZ queuename, PRXSTRING retstr)
154 return seterr("no arguments expected, got %ld", rargc);
159 ULONG PERLTERM (PCSZ name, LONG rargc, const RXSTRING *rargv,
160 PCSZ queuename, PRXSTRING retstr)
163 return seterr("no arguments expected, got %ld", rargc);
165 return seterr("no perl interpreter present");
166 perl_destruct(my_perl);
170 sprintf(retstr->strptr, "%s", "ok");
171 retstr->strlength = strlen (retstr->strptr);
176 ULONG PERLINIT (PCSZ name, LONG rargc, const RXSTRING *rargv,
177 PCSZ queuename, PRXSTRING retstr)
180 return seterr("no argument expected, got %ld", rargc);
184 sprintf(retstr->strptr, "%s", "ok");
185 retstr->strlength = strlen (retstr->strptr);
190 PERLLASTERROR (PCSZ name, LONG rargc, const RXSTRING *rargv, PCSZ queuename, PRXSTRING retstr)
192 int len = strlen(last_error);
194 if (len <= 256 /* Default buffer is 256-char long */
195 || !DosAllocMem((PPVOID)&retstr->strptr, len,
196 PAG_READ|PAG_WRITE|PAG_COMMIT)) {
197 memcpy(retstr->strptr, last_error, len);
198 retstr->strlength = len;
200 strcpy(retstr->strptr, "[Not enough memory to copy the errortext]");
201 retstr->strlength = strlen(retstr->strptr);
207 PERLEVAL (PCSZ name, LONG rargc, const RXSTRING *rargv, PCSZ queuename, PRXSTRING retstr)
215 return seterr("one argument expected, got %ld", rargc);
218 return seterr("error initializing perl");
228 in = sv_2mortal(newSVpvn(rargv[0].strptr, rargv[0].strlength));
229 eval_sv(in, G_SCALAR);
236 ret = seterr(SvPV(ERRSV, n_a));
238 ret = seterr("undefined value returned by Perl-in-REXX");
239 str = SvPV(res, len);
240 if (len <= 256 /* Default buffer is 256-char long */
241 || !DosAllocMem((PPVOID)&retstr->strptr, len,
242 PAG_READ|PAG_WRITE|PAG_COMMIT)) {
243 memcpy(retstr->strptr, str, len);
244 retstr->strlength = len;
246 ret = seterr("Not enough memory for the return string of Perl-in-REXX");
257 const RXSTRING *command, /* command to issue */
258 PUSHORT flags, /* error/failure flags */
259 PRXSTRING retstr ) /* return code */
261 ULONG rc = PERLEVAL(NULL, 1, command, NULL, retstr);
264 *flags = RXSUBCOM_ERROR; /* raise error condition */
266 return 0; /* finished */
269 #define ArrLength(a) (sizeof(a)/sizeof(*(a)))
271 static const struct {
273 RexxFunctionHandler *f;
275 {"PERL", (RexxFunctionHandler *)&PERL},
276 {"PERLTERM", (RexxFunctionHandler *)&PERLTERM},
277 {"PERLINIT", (RexxFunctionHandler *)&PERLINIT},
278 {"PERLEXIT", (RexxFunctionHandler *)&PERLEXIT},
279 {"PERLEVAL", (RexxFunctionHandler *)&PERLEVAL},
280 {"PERLLASTERROR", (RexxFunctionHandler *)&PERLLASTERROR},
281 {"PERLDROPALL", (RexxFunctionHandler *)&PERLDROPALL},
282 {"PERLDROPALLEXIT", (RexxFunctionHandler *)&PERLDROPALLEXIT},
283 /* Should be the last entry */
284 {"PERLEXPORTALL", (RexxFunctionHandler *)&PERLEXPORTALL}
288 PERLEXPORTALL(PCSZ name, LONG rargc, const RXSTRING *rargv, PCSZ queuename, PRXSTRING retstr)
292 while (++i < ArrLength(funcs) - 1)
293 RexxRegisterFunctionExe(funcs[i].name, funcs[i].f);
294 RexxRegisterSubcomExe("EVALPERL", (PFN)&PERLEVALSUBCOMMAND, NULL);
295 retstr->strlength = 0;
300 PERLDROPALL(PCSZ name, LONG rargc, const RXSTRING *rargv, PCSZ queuename, PRXSTRING retstr)
304 while (++i < ArrLength(funcs))
305 RexxDeregisterFunction(funcs[i].name);
306 RexxDeregisterSubcom("EVALPERL", NULL /* Not a DLL version */);
307 retstr->strlength = 0;
312 PERLDROPALLEXIT(PCSZ name, LONG rargc, const RXSTRING *rargv, PCSZ queuename, PRXSTRING retstr)
316 while (++i < ArrLength(funcs))
317 RexxDeregisterFunction(funcs[i].name);
318 RexxDeregisterSubcom("EVALPERL", NULL /* Not a DLL version */);
320 retstr->strlength = 0;