This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regexec.c: Change variable name in a function
[perl5.git] / NetWare / interface.c
CommitLineData
2986a63f
JH
1
2/*
cdad3b53 3 * Copyright © 2001 Novell, Inc. All Rights Reserved.
2986a63f
JH
4 *
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
7 *
8 */
9
10/*
9219c8de
JH
11 * FILENAME : interface.c
12 * DESCRIPTION : Calling Perl APIs.
13 * Author : SGP
14 * Date Created : January 2001.
15 * Date Modified: July 2nd 2001.
2986a63f
JH
16 */
17
18
19
20#include "interface.h"
9219c8de 21#include "nwtinfo.h"
2986a63f
JH
22
23static void xs_init(pTHX);
24
25EXTERN_C int RunPerl(int argc, char **argv, char **env);
26EXTERN_C void Perl_nw5_init(int *argcp, char ***argvp);
acfe0abc 27EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
2986a63f 28
4d76e4b4
JH
29EXTERN_C BOOL Remove_Thread_Ctx(void);
30
2986a63f
JH
31
32ClsPerlHost::ClsPerlHost()
33{
34
35}
36
37ClsPerlHost::~ClsPerlHost()
38{
39
40}
41
42ClsPerlHost::VersionNumber()
43{
44 return 0;
45}
46
9219c8de
JH
47bool
48ClsPerlHost::RegisterWithThreadTable()
49{
50 return(fnRegisterWithThreadTable());
51}
52
53bool
54ClsPerlHost::UnregisterWithThreadTable()
55{
56 return(fnUnregisterWithThreadTable());
57}
58
2986a63f
JH
59int
60ClsPerlHost::PerlCreate(PerlInterpreter *my_perl)
61{
62/* if (!(my_perl = perl_alloc())) // Allocate memory for Perl.
63 return (1);*/
64 perl_construct(my_perl);
65
66 return 1;
67}
68
69int
70ClsPerlHost::PerlParse(PerlInterpreter *my_perl, int argc, char** argv, char** env)
71{
72 return(perl_parse(my_perl, xs_init, argc, argv, env)); // Parse the command line.
73}
74
75int
76ClsPerlHost::PerlRun(PerlInterpreter *my_perl)
77{
78 return(perl_run(my_perl)); // Run Perl.
79}
80
fe2024f9 81int
2986a63f
JH
82ClsPerlHost::PerlDestroy(PerlInterpreter *my_perl)
83{
fe2024f9 84 return(perl_destruct(my_perl)); // Destructor for Perl.
4d76e4b4
JH
85}
86
87void
88ClsPerlHost::PerlFree(PerlInterpreter *my_perl)
89{
2986a63f
JH
90 perl_free(my_perl); // Free the memory allocated for Perl.
91
4d76e4b4
JH
92 // Remove the thread context set during Perl_set_context
93 // This is added here since for web script there is no other place this gets executed
94 // and it cannot be included into cgi2perl.xs unless this symbol is exported.
95 Remove_Thread_Ctx();
2986a63f
JH
96}
97
98/*============================================================================================
99
100 Function : xs_init
101
102 Description :
103
104 Parameters : pTHX (IN) -
105
106 Returns : Nothing.
107
108==============================================================================================*/
109
110static void xs_init(pTHX)
111{
112 char *file = __FILE__;
113
114 dXSUB_SYS;
115 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
116}
117
118
119EXTERN_C
120int RunPerl(int argc, char **argv, char **env)
121{
122 int exitstatus = 0;
123 ClsPerlHost nlm;
124
125 PerlInterpreter *my_perl = NULL; // defined in Perl.h
126 PerlInterpreter *new_perl = NULL; // defined in Perl.h
127
2986a63f
JH
128 PERL_SYS_INIT(&argc, &argv);
129
130 if (!(my_perl = perl_alloc())) // Allocate memory for Perl.
131 return (1);
132
133 if(nlm.PerlCreate(my_perl))
134 {
135 PL_perl_destruct_level = 0;
136
fe2024f9 137 if(!nlm.PerlParse(my_perl, argc, argv, env))
2986a63f
JH
138 {
139 #if defined(TOP_CLONE) && defined(USE_ITHREADS) // XXXXXX testing
acfe0abc 140 new_perl = perl_clone(my_perl, 1);
2986a63f 141
fe2024f9 142 (void) perl_run(new_perl); // Run Perl.
2986a63f
JH
143 PERL_SET_THX(my_perl);
144 #else
fe2024f9 145 (void) nlm.PerlRun(my_perl);
2986a63f
JH
146 #endif
147 }
fe2024f9 148 exitstatus = nlm.PerlDestroy(my_perl);
2986a63f 149 }
4d76e4b4
JH
150 if(my_perl)
151 nlm.PerlFree(my_perl);
2986a63f
JH
152
153 #ifdef USE_ITHREADS
154 if (new_perl)
155 {
156 PERL_SET_THX(new_perl);
fe2024f9 157 exitstatus = nlm.PerlDestroy(new_perl);
4d76e4b4 158 nlm.PerlFree(my_perl);
2986a63f
JH
159 }
160 #endif
161
162 PERL_SYS_TERM();
163 return exitstatus;
164}
165
166
167// FUNCTION: AllocStdPerl
168//
169// DESCRIPTION:
170// Allocates a standard perl handler that other perl handlers
171// may delegate to. You should call FreeStdPerl to free this
172// instance when you are done with it.
173//
174IPerlHost* AllocStdPerl()
175{
4d76e4b4 176 return (IPerlHost*) new ClsPerlHost();
2986a63f
JH
177}
178
179
180// FUNCTION: FreeStdPerl
181//
182// DESCRIPTION:
183// Frees an instance of a standard perl handler allocated by
184// AllocStdPerl.
185//
186void FreeStdPerl(IPerlHost* pPerlHost)
187{
4d76e4b4
JH
188 if (pPerlHost)
189 delete (ClsPerlHost*) pPerlHost;
2986a63f
JH
190}
191