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