Integrate from ansi branch to mainline.
[p5sagit/p5-mst-13.2.git] / win32 / perllib.c
CommitLineData
0a753a76 1/*
2 * "The Road goes ever on and on, down from the door where it began."
3 */
4
0a753a76 5
6#include "EXTERN.h"
7#include "perl.h"
96e4d5b1 8#include "XSUB.h"
0a753a76 9
0a753a76 10static void xs_init _((void));
11
68dc0745 12__declspec(dllexport) int
13RunPerl(int argc, char **argv, char **env, void *iosubsystem)
0a753a76 14{
68dc0745 15 int exitstatus;
16 PerlInterpreter *my_perl;
0a753a76 17
bbc8f9de 18#ifdef USE_THREADS
19 MUTEX_INIT(&malloc_mutex);
20#endif
21
0a753a76 22 PERL_SYS_INIT(&argc,&argv);
23
24 perl_init_i18nl10n(1);
25
68dc0745 26 if (!(my_perl = perl_alloc()))
27 return (1);
28 perl_construct( my_perl );
29 perl_destruct_level = 0;
0a753a76 30
31 exitstatus = perl_parse( my_perl, xs_init, argc, argv, env);
32 if (!exitstatus) {
33 exitstatus = perl_run( my_perl );
34 }
35
0a753a76 36 perl_destruct( my_perl );
37 perl_free( my_perl );
38
39 PERL_SYS_TERM();
40
68dc0745 41 return (exitstatus);
0a753a76 42}
43
0a753a76 44extern HANDLE PerlDllHandle;
45
68dc0745 46BOOL APIENTRY
47DllMain(HANDLE hModule, /* DLL module handle */
48 DWORD fdwReason, /* reason called */
49 LPVOID lpvReserved) /* reserved */
0a753a76 50{
68dc0745 51 switch (fdwReason) {
52 /* The DLL is attaching to a process due to process
53 * initialization or a call to LoadLibrary.
54 */
55 case DLL_PROCESS_ATTACH:
56/* #define DEFAULT_BINMODE */
0a753a76 57#ifdef DEFAULT_BINMODE
3e3baf6d 58 setmode( fileno( stdin ), O_BINARY );
59 setmode( fileno( stdout ), O_BINARY );
60 setmode( fileno( stderr ), O_BINARY );
61 _fmode = O_BINARY;
0a753a76 62#endif
68dc0745 63 PerlDllHandle = hModule;
64 break;
0a753a76 65
68dc0745 66 /* The DLL is detaching from a process due to
67 * process termination or call to FreeLibrary.
68 */
69 case DLL_PROCESS_DETACH:
70 break;
0a753a76 71
68dc0745 72 /* The attached process creates a new thread. */
73 case DLL_THREAD_ATTACH:
74 break;
0a753a76 75
68dc0745 76 /* The thread of the attached process terminates. */
77 case DLL_THREAD_DETACH:
78 break;
0a753a76 79
68dc0745 80 default:
81 break;
82 }
83 return TRUE;
0a753a76 84}
8b10511d 85
86/* Register any extra external extensions */
87
88char *staticlinkmodules[] = {
89 "DynaLoader",
90 NULL,
91};
92
93EXTERN_C void boot_DynaLoader _((CV* cv));
94
8b10511d 95static void
96xs_init()
97{
98 char *file = __FILE__;
99 dXSUB_SYS;
100 newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
8b10511d 101}
102