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