Added ability to read a startup program from wine.ini file.
[wine/hacks.git] / miscemu / main.c
blobb77a34fdd1695814386b45061c710901588694a6
1 /*
2 * Emulator initialisation code
4 */
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"
19 /***********************************************************************
20 * Emulator initialisation
22 BOOL32 MAIN_EmulatorInit(void)
24 /* Initialize the kernel */
25 if (!MAIN_KernelInit()) return FALSE;
27 /* Initialize relay code */
28 if (!RELAY_Init()) return FALSE;
30 /* Initialize signal handling */
31 if (!SIGNAL_InitEmulator()) return FALSE;
33 /* Create the Win16 printer driver */
34 if (!WIN16DRV_Init()) return FALSE;
36 /* Create the Postscript printer driver (FIXME: should be in Winelib) */
37 if (!PSDRV_Init()) return FALSE;
39 /* Initialize all the USER stuff */
40 return MAIN_UserInit();
44 /**********************************************************************
45 * main
47 int main( int argc, char *argv[] )
49 extern char * DEBUG_argv0;
50 char startProg[256];
51 int i,loaded;
52 HINSTANCE32 handle;
54 __winelib = 0; /* First of all, clear the Winelib flag */
57 * Save this so that the internal debugger can get a hold of it if
58 * it needs to.
60 DEBUG_argv0 = argv[0];
62 /* Create the initial process */
63 if (!PROCESS_Init()) return FALSE;
65 /* Parse command-line */
66 if (!MAIN_WineInit( &argc, argv )) return 1;
68 /* Handle -dll option (hack) */
70 if (Options.dllFlags)
72 if (!BUILTIN_ParseDLLOptions( Options.dllFlags ))
74 MSG("%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",
75 argv[0] );
76 BUILTIN_PrintDLLs();
77 exit(1);
81 /* Initialize everything */
83 if (!MAIN_EmulatorInit()) return 1;
85 /* Initialize CALL32 routines */
86 /* This needs to be done just before task-switching starts */
88 loaded=0;
90 /* Add the Startup Program to the run list */
91 PROFILE_GetWineIniString( "programs", "Startup", "",
92 startProg, sizeof(startProg) );
93 if (startProg[0]) argv[argc++] = startProg;
95 for (i = 1; i < argc; i++)
97 if ((handle = WinExec32( argv[i], SW_SHOWNORMAL )) < 32)
99 MSG("wine: can't exec '%s': ", argv[i]);
100 switch (handle)
102 case 2: MSG("file not found\n" ); break;
103 case 11: MSG("invalid exe file\n" ); break;
104 case 21: MSG("win32 executable\n" ); break; /* FIXME: Obsolete? */
105 default: MSG("error=%d\n", handle ); break;
107 return 1;
109 loaded++;
112 if (!loaded) { /* nothing loaded */
113 MAIN_Usage(argv[0]);
114 return 1;
117 if (!GetNumTasks())
119 MSG("wine: no executable file found.\n" );
120 return 0;
123 if (Options.debug) DEBUG_AddModuleBreakpoints();
125 IF1632_CallLargeStack = (int (*)(int (*func)(), void *arg))CALL32_Init();
126 Yield16(); /* Start the first task */
127 MSG("WinMain: Should never happen: returned from Yield16()\n" );
128 return 0;