Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/winecrt0/exe_entry.c
12343 views
1
/*
2
* Default entry point for an exe
3
*
4
* Copyright 2005 Alexandre Julliard
5
*
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2.1 of the License, or (at your option) any later version.
10
*
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19
*/
20
21
#if 0
22
#pragma makedep unix
23
#endif
24
25
/* this is actually part of a static lib linked into a .exe.so module, not a real Unix library */
26
#undef WINE_UNIX_LIB
27
28
#include <stdarg.h>
29
#include "windef.h"
30
#include "winbase.h"
31
#include "winternl.h"
32
33
extern int main( int argc, char *argv[] );
34
extern void __wine_init_so_dll(void);
35
36
static char **build_argv( const char *src, int *ret_argc )
37
{
38
char **argv, *arg, *dst;
39
int argc, in_quotes = 0, bcount = 0, len = strlen(src) + 1;
40
41
argc = 2 + len / 2;
42
argv = HeapAlloc( GetProcessHeap(), 0, argc * sizeof(*argv) + len );
43
arg = dst = (char *)(argv + argc);
44
argc = 0;
45
while (*src)
46
{
47
if ((*src == ' ' || *src == '\t') && !in_quotes)
48
{
49
/* skip the remaining spaces */
50
while (*src == ' ' || *src == '\t') src++;
51
if (!*src) break;
52
/* close the argument and copy it */
53
*dst++ = 0;
54
argv[argc++] = arg;
55
/* start with a new argument */
56
arg = dst;
57
bcount = 0;
58
}
59
else if (*src == '\\')
60
{
61
*dst++ = *src++;
62
bcount++;
63
}
64
else if (*src == '"')
65
{
66
if ((bcount & 1) == 0)
67
{
68
/* Preceded by an even number of '\', this is half that
69
* number of '\', plus a '"' which we discard.
70
*/
71
dst -= bcount / 2;
72
src++;
73
if (in_quotes && *src == '"') *dst++ = *src++;
74
else in_quotes = !in_quotes;
75
}
76
else
77
{
78
/* Preceded by an odd number of '\', this is half that
79
* number of '\' followed by a '"'
80
*/
81
dst -= bcount / 2 + 1;
82
*dst++ = *src++;
83
}
84
bcount = 0;
85
}
86
else /* a regular character */
87
{
88
*dst++ = *src++;
89
bcount = 0;
90
}
91
}
92
*dst = 0;
93
argv[argc++] = arg;
94
argv[argc] = NULL;
95
*ret_argc = argc;
96
return argv;
97
}
98
99
DWORD WINAPI __wine_spec_exe_entry( PEB *peb )
100
{
101
int argc;
102
char **argv = build_argv( GetCommandLineA(), &argc );
103
104
__wine_init_so_dll();
105
ExitProcess( main( argc, argv ));
106
}
107
108