prepare move old cruft
[reactos.git] / reactos / lib / crtdll / old cruft / misc / main.c
1 /*
2 * main.c
3 *
4 * Extra startup code for applications which do not have a main function
5 * of their own (but do have a WinMain). Generally these are GUI
6 * applications, but they don't *have* to be.
7 *
8 * This file is part of the Mingw32 package.
9 *
10 * Contributors:
11 * Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
12 *
13 * THIS SOFTWARE IS NOT COPYRIGHTED
14 *
15 * This source code is offered for use in the public domain. You may
16 * use, modify or distribute it freely.
17 *
18 * This code is distributed in the hope that it will be useful but
19 * WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY
20 * DISCLAMED. This includes but is not limited to warrenties of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 *
23 * $Revision: 1.4 $
24 * $Author$
25 * $Date$
26 *
27 */
28
29 #include <precomp.h>
30 #include <msvcrt/stdlib.h>
31 #include <msvcrt/process.h>
32
33
34 #define ISSPACE(a) (a == ' ' || a == '\t')
35
36 extern int PASCAL WinMain (HANDLE hInst, HANDLE hPrevInst, LPSTR szCmdLine, int nShow);
37
38 int main(int argc, char* argv[], char* environ[])
39 {
40 char* szCmd;
41 STARTUPINFO startinfo;
42 int nRet;
43
44 /* Get the command line passed to the process. */
45 szCmd = GetCommandLineA();
46 GetStartupInfoA(&startinfo);
47
48 /* Strip off the name of the application and any leading
49 * whitespace. */
50 if (szCmd)
51 {
52 while(ISSPACE(*szCmd))
53 {
54 szCmd++;
55 }
56
57 /* On my system I always get the app name enclosed
58 * in quotes... */
59 if (*szCmd == '\"')
60 {
61 do
62 {
63 szCmd++;
64 }
65 while (*szCmd != '\"' && *szCmd != '\0');
66
67 if (*szCmd == '\"')
68 {
69 szCmd++;
70 }
71 }
72 else
73 {
74 /* If no quotes then assume first token is program
75 * name. */
76 while (!ISSPACE(*szCmd) && *szCmd != '\0')
77 {
78 szCmd++;
79 }
80 }
81
82 while (ISSPACE(*szCmd))
83 {
84 szCmd++;
85 }
86 }
87
88 nRet = WinMain (GetModuleHandle(NULL), NULL, szCmd,
89 (startinfo.dwFlags & STARTF_USESHOWWINDOW) ?
90 startinfo.wShowWindow : SW_SHOWDEFAULT);
91
92 return nRet;
93 }