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