OSDN Git Service

Prepare and publish MinGW.org WSL-5.3.3 release.
[mingw/mingw-org-wsl.git] / mingwrt / main.c
1 /*
2  * main.c
3  *
4  * This file has no copyright assigned and is placed in the Public Domain.
5  * This file is a part of the mingw-runtime package.
6  * No warranty is given; refer to the file DISCLAIMER within the package.
7  *
8  * Extra startup code for applications which do not have a main function
9  * of their own (but do have a WinMain). Generally these are GUI
10  * applications, but they don't *have* to be.
11  *
12  */
13 #include <stdlib.h>
14 #include <process.h>
15 #include <windows.h>
16
17 #define ISSPACE(a)      (a == ' ' || a == '\t')
18
19 extern int PASCAL WinMain (HINSTANCE, HINSTANCE, LPSTR, int);
20
21 int
22 main (int argc, char *argv[], char **envp)
23 {
24   char *szCmd;
25   STARTUPINFO startinfo;
26
27   /* Get the command line passed to the process. */
28   szCmd = GetCommandLineA ();
29   GetStartupInfoA (&startinfo);
30
31   /* Strip off the name of the application and any leading
32    * whitespace. */
33   if (szCmd)
34     {
35       while (ISSPACE (*szCmd))
36         {
37           szCmd++;
38         }
39
40       /* On my system I always get the app name enclosed
41        * in quotes... */
42       if (*szCmd == '\"')
43         {
44           do
45             {
46               szCmd++;
47             }
48           while (*szCmd != '\"' && *szCmd != '\0');
49
50           if (*szCmd == '\"')
51             {
52               szCmd++;
53             }
54         }
55       else
56         {
57           /* If no quotes then assume first token is program
58            * name. */
59           while (!ISSPACE (*szCmd) && *szCmd != '\0')
60             {
61               szCmd++;
62             }
63         }
64
65       while (ISSPACE (*szCmd))
66         {
67           szCmd++;
68         }
69     }
70
71   return WinMain( GetModuleHandle (NULL), NULL, szCmd,
72       (startinfo.dwFlags & STARTF_USESHOWWINDOW)
73         ?  startinfo.wShowWindow
74         : SW_SHOWDEFAULT
75     );
76 }
77