452fcdf11ed0f887ad2fed27d4a2901872b4368e
[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 (pTHX);
11
12 DllExport int
13 RunPerl(int argc, char **argv, char **env, void *iosubsystem)
14 {
15     int exitstatus;
16     PerlInterpreter *my_perl;
17     struct perl_thread *thr;
18
19 #ifdef PERL_GLOBAL_STRUCT
20 #define PERLVAR(var,type) /**/
21 #define PERLVARI(var,type,init) PL_Vars.var = init;
22 #define PERLVARIC(var,type,init) PL_Vars.var = init;
23 #include "perlvars.h"
24 #undef PERLVAR
25 #undef PERLVARI
26 #undef PERLVARIC
27 #endif
28
29     PERL_SYS_INIT(&argc,&argv);
30
31     if (!(my_perl = perl_alloc()))
32         return (1);
33     perl_construct( my_perl );
34     PL_perl_destruct_level = 0;
35
36     exitstatus = perl_parse(my_perl, xs_init, argc, argv, env);
37     if (!exitstatus) {
38         exitstatus = perl_run( my_perl );
39     }
40
41     perl_destruct( my_perl );
42     perl_free( my_perl );
43
44     PERL_SYS_TERM();
45
46     return (exitstatus);
47 }
48
49 extern HANDLE w32_perldll_handle;
50
51 BOOL APIENTRY
52 DllMain(HANDLE hModule,         /* DLL module handle */
53         DWORD fdwReason,        /* reason called */
54         LPVOID lpvReserved)     /* reserved */
55
56     switch (fdwReason) {
57         /* The DLL is attaching to a process due to process
58          * initialization or a call to LoadLibrary.
59          */
60     case DLL_PROCESS_ATTACH:
61 /* #define DEFAULT_BINMODE */
62 #ifdef DEFAULT_BINMODE
63         setmode( fileno( stdin  ), O_BINARY );
64         setmode( fileno( stdout ), O_BINARY );
65         setmode( fileno( stderr ), O_BINARY );
66         _fmode = O_BINARY;
67 #endif
68         w32_perldll_handle = hModule;
69         break;
70
71         /* The DLL is detaching from a process due to
72          * process termination or call to FreeLibrary.
73          */
74     case DLL_PROCESS_DETACH:
75         break;
76
77         /* The attached process creates a new thread. */
78     case DLL_THREAD_ATTACH:
79         break;
80
81         /* The thread of the attached process terminates. */
82     case DLL_THREAD_DETACH:
83         break;
84
85     default:
86         break;
87     }
88     return TRUE;
89 }
90
91 /* Register any extra external extensions */
92
93 char *staticlinkmodules[] = {
94     "DynaLoader",
95     NULL,
96 };
97
98 EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
99
100 static void
101 xs_init(pTHX)
102 {
103     char *file = __FILE__;
104     dXSUB_SYS;
105     newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
106 }
107