1 #define INCL_DOSPROCESS
2 #define INCL_DOSSEMAPHORES
3 #define INCL_DOSMODULEMGR
5 #define INCL_DOSEXCEPTIONS
11 * The Road goes ever on and on
12 * Down from the door where it began.
14 * [Bilbo on p.35 of _The Lord of the Rings_, I/i: "A Long-Expected Party"]
15 * [Frodo on p.73 of _The Lord of the Rings_, I/iii: "Three Is Company"]
20 /* sbrk is limited to first heap segement so make it big */
21 #pragma runopts(HEAP(8M,500K,ANYWHERE,KEEP,8K,4K) STACK(,,ANY,) ALL31(ON))
23 #pragma runopts(HEAP(2M,500K,ANYWHERE,KEEP,8K,4K) STACK(,,ANY,) ALL31(ON))
31 static void xs_init (pTHX);
32 static PerlInterpreter *my_perl;
34 ULONG PERLEXPORTALL(PCSZ name, LONG rargc, const RXSTRING *rargv, PCSZ queuename, PRXSTRING retstr);
35 ULONG PERLDROPALL(PCSZ name, LONG rargc, const RXSTRING *rargv, PCSZ queuename, PRXSTRING retstr);
36 ULONG PERLDROPALLEXIT(PCSZ name, LONG rargc, const RXSTRING *rargv, PCSZ queuename, PRXSTRING retstr);
39 /* The Atari operating system doesn't have a dynamic stack. The
40 stack size is determined from this value. */
41 long _stksize = 64 * 1024;
44 /* Register any extra external extensions */
46 /* Do not delete this line--writemain depends on it */
47 EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
52 char *file = __FILE__;
54 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
57 int perlos2_is_inited;
62 /* static char *env[1] = {NULL}; */
64 Perl_OS2_init3(0, 0, 0);
68 init_perl(int doparse)
71 char *argv[3] = {"perl_in_REXX", "-e", ""};
73 if (!perlos2_is_inited) {
74 perlos2_is_inited = 1;
80 my_perl = perl_alloc();
83 perl_construct(my_perl);
84 PL_perl_destruct_level = 1;
88 exitstatus = perl_parse(my_perl, xs_init, 3, argv, (char **)NULL);
92 static char last_error[4096];
95 seterr(char *format, ...)
100 va_start(va, format);
104 snprintf(s, sizeof(last_error) - (s - last_error), "\n");
108 vsnprintf(s, sizeof(last_error) - (s - last_error), format, va);
112 /* The REXX-callable entrypoints ... */
114 ULONG PERL (PCSZ name, LONG rargc, const RXSTRING *rargv,
115 PCSZ queuename, PRXSTRING retstr)
119 char *argv[3] = {"perl_from_REXX", "-e", buf};
123 return seterr("one argument expected, got %ld", rargc);
124 if (rargv[0].strlength >= sizeof(buf))
125 return seterr("length of the argument %ld exceeds the maximum %ld",
126 rargv[0].strlength, (long)sizeof(buf) - 1);
131 memcpy(buf, rargv[0].strptr, rargv[0].strlength);
132 buf[rargv[0].strlength] = 0;
134 exitstatus = perl_parse(my_perl, xs_init, 3, argv, (char **)NULL);
136 exitstatus = perl_run(my_perl);
139 perl_destruct(my_perl);
147 sprintf(retstr->strptr, "%s", "ok");
148 retstr->strlength = strlen (retstr->strptr);
154 ULONG PERLEXIT (PCSZ name, LONG rargc, const RXSTRING *rargv,
155 PCSZ queuename, PRXSTRING retstr)
158 return seterr("no arguments expected, got %ld", rargc);
163 ULONG PERLTERM (PCSZ name, LONG rargc, const RXSTRING *rargv,
164 PCSZ queuename, PRXSTRING retstr)
167 return seterr("no arguments expected, got %ld", rargc);
169 return seterr("no perl interpreter present");
170 perl_destruct(my_perl);
174 sprintf(retstr->strptr, "%s", "ok");
175 retstr->strlength = strlen (retstr->strptr);
180 ULONG PERLINIT (PCSZ name, LONG rargc, const RXSTRING *rargv,
181 PCSZ queuename, PRXSTRING retstr)
184 return seterr("no argument expected, got %ld", rargc);
188 sprintf(retstr->strptr, "%s", "ok");
189 retstr->strlength = strlen (retstr->strptr);
194 PERLLASTERROR (PCSZ name, LONG rargc, const RXSTRING *rargv, PCSZ queuename, PRXSTRING retstr)
196 int len = strlen(last_error);
198 if (len <= 256 /* Default buffer is 256-char long */
199 || !DosAllocMem((PPVOID)&retstr->strptr, len,
200 PAG_READ|PAG_WRITE|PAG_COMMIT)) {
201 memcpy(retstr->strptr, last_error, len);
202 retstr->strlength = len;
204 strcpy(retstr->strptr, "[Not enough memory to copy the errortext]");
205 retstr->strlength = strlen(retstr->strptr);
211 PERLEVAL (PCSZ name, LONG rargc, const RXSTRING *rargv, PCSZ queuename, PRXSTRING retstr)
219 return seterr("one argument expected, got %ld", rargc);
222 return seterr("error initializing perl");
232 in = sv_2mortal(newSVpvn(rargv[0].strptr, rargv[0].strlength));
233 eval_sv(in, G_SCALAR);
240 ret = seterr(SvPV(ERRSV, n_a));
242 ret = seterr("undefined value returned by Perl-in-REXX");
243 str = SvPV(res, len);
244 if (len <= 256 /* Default buffer is 256-char long */
245 || !DosAllocMem((PPVOID)&retstr->strptr, len,
246 PAG_READ|PAG_WRITE|PAG_COMMIT)) {
247 memcpy(retstr->strptr, str, len);
248 retstr->strlength = len;
250 ret = seterr("Not enough memory for the return string of Perl-in-REXX");
261 const RXSTRING *command, /* command to issue */
262 PUSHORT flags, /* error/failure flags */
263 PRXSTRING retstr ) /* return code */
265 ULONG rc = PERLEVAL(NULL, 1, command, NULL, retstr);
268 *flags = RXSUBCOM_ERROR; /* raise error condition */
270 return 0; /* finished */
273 #define ArrLength(a) (sizeof(a)/sizeof(*(a)))
275 static const struct {
277 RexxFunctionHandler *f;
279 {"PERL", (RexxFunctionHandler *)&PERL},
280 {"PERLTERM", (RexxFunctionHandler *)&PERLTERM},
281 {"PERLINIT", (RexxFunctionHandler *)&PERLINIT},
282 {"PERLEXIT", (RexxFunctionHandler *)&PERLEXIT},
283 {"PERLEVAL", (RexxFunctionHandler *)&PERLEVAL},
284 {"PERLLASTERROR", (RexxFunctionHandler *)&PERLLASTERROR},
285 {"PERLDROPALL", (RexxFunctionHandler *)&PERLDROPALL},
286 {"PERLDROPALLEXIT", (RexxFunctionHandler *)&PERLDROPALLEXIT},
287 /* Should be the last entry */
288 {"PERLEXPORTALL", (RexxFunctionHandler *)&PERLEXPORTALL}
292 PERLEXPORTALL(PCSZ name, LONG rargc, const RXSTRING *rargv, PCSZ queuename, PRXSTRING retstr)
296 while (++i < ArrLength(funcs) - 1)
297 RexxRegisterFunctionExe(funcs[i].name, funcs[i].f);
298 RexxRegisterSubcomExe("EVALPERL", (PFN)&PERLEVALSUBCOMMAND, NULL);
299 retstr->strlength = 0;
304 PERLDROPALL(PCSZ name, LONG rargc, const RXSTRING *rargv, PCSZ queuename, PRXSTRING retstr)
308 while (++i < ArrLength(funcs))
309 RexxDeregisterFunction(funcs[i].name);
310 RexxDeregisterSubcom("EVALPERL", NULL /* Not a DLL version */);
311 retstr->strlength = 0;
316 PERLDROPALLEXIT(PCSZ name, LONG rargc, const RXSTRING *rargv, PCSZ queuename, PRXSTRING retstr)
320 while (++i < ArrLength(funcs))
321 RexxDeregisterFunction(funcs[i].name);
322 RexxDeregisterSubcom("EVALPERL", NULL /* Not a DLL version */);
324 retstr->strlength = 0;