Release 980118
[wine] / loader / main.c
1 /*
2  * Main initialization code
3  */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <fcntl.h>
10 #include <unistd.h>
11 #include <string.h>
12 #include <errno.h>
13 #include "windows.h"
14 #include "module.h"
15 #include "selectors.h"
16 #include "bitmap.h"
17 #include "comm.h"
18 #include "win.h"
19 #include "menu.h"
20 #include "atom.h"
21 #include "dialog.h"
22 #include "drive.h"
23 #include "queue.h"
24 #include "sysmetrics.h"
25 #include "file.h"
26 #include "gdi.h"
27 #include "heap.h"
28 #include "keyboard.h"
29 #include "miscemu.h"
30 #include "neexe.h"
31 #include "options.h"
32 #include "spy.h"
33 #include "task.h"
34 #include "tweak.h"
35 #include "user.h"
36 #include "dce.h"
37 #include "shell.h"
38 #include "winproc.h"
39 #include "stddebug.h"
40 #include "debug.h"
41
42
43 int __winelib = 1;  /* Winelib run-time flag */
44
45 /***********************************************************************
46  *           Kernel initialisation routine
47  */
48 BOOL32 MAIN_KernelInit(void)
49 {
50     extern BOOL32 EVENT_Init(void);
51     extern BOOL32 PROCESS_Init(void);
52     extern BOOL32 VIRTUAL_Init(void);
53
54     /* Initialize virtual memory management */
55     if (!VIRTUAL_Init()) return FALSE;
56
57     /* Create the system and SEGPTR heaps */
58     if (!(SystemHeap = HeapCreate( HEAP_GROWABLE, 0x10000, 0 ))) return FALSE;
59     if (!(SegptrHeap = HeapCreate( HEAP_WINE_SEGPTR, 0, 0 ))) return FALSE;
60
61     /* Create the initial process */
62     if (!PROCESS_Init()) return FALSE;
63
64     /* Initialize signal handling */
65     if (!SIGNAL_Init()) return FALSE;
66
67     /* Load the configuration file */
68     if (!PROFILE_LoadWineIni()) return FALSE;
69
70       /* Initialize DOS memory */
71     if (!DOSMEM_Init()) return FALSE;
72
73     /* Initialise DOS drives */
74     if (!DRIVE_Init()) return FALSE;
75
76     /* Initialise DOS directories */
77     if (!DIR_Init()) return FALSE;
78
79     /* Initialize tasks */
80     if (!TASK_Init()) return FALSE;
81
82       /* Initialize event handling */
83     if (!EVENT_Init()) return FALSE;
84
85     /* Initialize communications */
86     COMM_Init();
87
88     /* Initialize IO-port permissions */
89     IO_port_init();
90
91     return TRUE;
92 }
93
94
95 /***********************************************************************
96  *           USER (and GDI) initialisation routine
97  */
98 BOOL32 MAIN_UserInit(void)
99 {
100     extern BOOL32 WIDGETS_Init(void);
101
102     int queueSize;
103
104     /* Create USER and GDI heap */
105     if (!USER_HeapSel)
106     {
107         USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
108         LocalInit( USER_HeapSel, 0, 0xffff );
109     }
110     if (!GDI_HeapSel)
111     {
112         GDI_HeapSel  = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
113         LocalInit( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
114     }
115
116     /* Initialize Wine tweaks */
117     if (!TWEAK_Init()) return FALSE;
118
119     /* Initialize OEM Bitmaps */
120     if (!OBM_Init()) return FALSE;
121
122     /* registry initialisation */
123     SHELL_LoadRegistry();
124     
125     /* Global atom table initialisation */
126     if (!ATOM_Init()) return FALSE;
127
128     /* GDI initialisation */
129     if (!GDI_Init()) return FALSE;
130
131     /* Initialize system colors and metrics*/
132     SYSMETRICS_Init();
133     SYSCOLOR_Init();
134
135     /* Create the DCEs */
136     DCE_Init();
137
138     /* Initialize keyboard */
139     if (!KEYBOARD_Init()) return FALSE;
140
141     /* Initialize window procedures */
142     if (!WINPROC_Init()) return FALSE;
143
144     /* Initialize built-in window classes */
145     if (!WIDGETS_Init()) return FALSE;
146
147     /* Initialize dialog manager */
148     if (!DIALOG_Init()) return FALSE;
149
150     /* Initialize menus */
151     if (!MENU_Init()) return FALSE;
152
153     /* Create desktop window */
154     if (!WIN_CreateDesktopWindow()) return FALSE;
155
156     /* Initialize message spying */
157     if (!SPY_Init()) return FALSE;
158
159     /* Check wine.conf for old/bad entries */
160     if (!TWEAK_CheckConfiguration()) return FALSE;
161
162     /* Create system message queue */
163     queueSize = GetProfileInt32A( "windows", "TypeAhead", 120 );
164     if (!QUEUE_CreateSysMsgQueue( queueSize )) return FALSE;
165
166     /* Set double click time */
167     SetDoubleClickTime32( GetProfileInt32A("windows","DoubleClickSpeed",452) );
168
169     return TRUE;
170 }
171
172
173 /***********************************************************************
174  *           Winelib initialisation routine
175  */
176 int MAIN_WinelibInit(void)
177 {
178     /* Initialize the kernel */
179     if (!MAIN_KernelInit()) return 0;
180
181     /* Initialize all the USER stuff */
182     if (!MAIN_UserInit()) return 0;
183     return 1;
184 }