Release 980628
[wine] / miscemu / main.c
1 /*
2  * Emulator initialisation code
3  *
4  */
5
6 #include "callback.h"
7 #include "debug.h"
8 #include "debugger.h"
9 #include "main.h"
10 #include "miscemu.h"
11 #include "module.h"
12 #include "options.h"
13 #include "process.h"
14 #include "win16drv.h"
15 #include "psdrv.h"
16 #include "windows.h"
17
18
19 /***********************************************************************
20  *           Emulator initialisation
21  */
22 BOOL32 MAIN_EmulatorInit(void)
23 {
24     /* Initialize the kernel */
25     if (!MAIN_KernelInit()) return FALSE;
26
27     /* Initialize relay code */
28     if (!RELAY_Init()) return FALSE;
29
30       /* Initialize signal handling */
31     if (!SIGNAL_InitEmulator()) return FALSE;
32
33     /* Create the Win16 printer driver */
34     if (!WIN16DRV_Init()) return FALSE;
35
36     /* Create the Postscript printer driver (FIXME: should be in Winelib) */
37     if (!PSDRV_Init()) return FALSE;
38
39     /* Initialize all the USER stuff */
40     return MAIN_UserInit();
41 }
42
43
44 /**********************************************************************
45  *           main
46  */
47 int main( int argc, char *argv[] )
48 {
49     extern char * DEBUG_argv0;
50
51     int i,loaded;
52     HINSTANCE32 handle;
53
54     __winelib = 0;  /* First of all, clear the Winelib flag */
55
56     /*
57      * Save this so that the internal debugger can get a hold of it if
58      * it needs to.
59      */
60     DEBUG_argv0 = argv[0];
61
62     /* Create the initial process */
63     if (!PROCESS_Init()) return FALSE;
64
65     /* Parse command-line */
66     if (!MAIN_WineInit( &argc, argv )) return 1;
67
68     /* Handle -dll option (hack) */
69
70     if (Options.dllFlags)
71     {
72         if (!BUILTIN_ParseDLLOptions( Options.dllFlags ))
73         {
74             MSG("%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",
75                      argv[0] );
76             BUILTIN_PrintDLLs();
77             exit(1);
78         }
79     }
80
81     /* Initialize everything */
82
83     if (!MAIN_EmulatorInit()) return 1;
84
85     /* Initialize CALL32 routines */
86     /* This needs to be done just before task-switching starts */
87     IF1632_CallLargeStack = (int (*)(int (*func)(), void *arg))CALL32_Init();
88
89     loaded=0;
90     for (i = 1; i < argc; i++)
91     {
92         if ((handle = WinExec32( argv[i], SW_SHOWNORMAL )) < 32)
93         {
94             MSG("wine: can't exec '%s': ", argv[i]);
95             switch (handle)
96             {
97             case 2: MSG("file not found\n" ); break;
98             case 11: MSG("invalid exe file\n" ); break;
99             case 21: MSG("win32 executable\n" ); break; /* FIXME: Obsolete? */
100             default: MSG("error=%d\n", handle ); break;
101             }
102             return 1;
103         }
104         loaded++;
105     }
106
107     if (!loaded) { /* nothing loaded */
108         MAIN_Usage(argv[0]);
109         return 1;
110     }
111
112     if (!GetNumTasks())
113     {
114         MSG("wine: no executable file found.\n" );
115         return 0;
116     }
117
118     if (Options.debug) DEBUG_AddModuleBreakpoints();
119
120     Yield16();  /* Start the first task */
121     MSG("WinMain: Should never happen: returned from Yield16()\n" );
122     return 0;
123 }