/*1* Default entry point for an exe2*3* Copyright 2005 Alexandre Julliard4*5* This library is free software; you can redistribute it and/or6* modify it under the terms of the GNU Lesser General Public7* License as published by the Free Software Foundation; either8* version 2.1 of the License, or (at your option) any later version.9*10* This library is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU13* Lesser General Public License for more details.14*15* You should have received a copy of the GNU Lesser General Public16* License along with this library; if not, write to the Free Software17* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA18*/1920#if 021#pragma makedep unix22#endif2324/* this is actually part of a static lib linked into a .exe.so module, not a real Unix library */25#undef WINE_UNIX_LIB2627#include <stdarg.h>28#include "windef.h"29#include "winbase.h"30#include "winternl.h"3132extern int main( int argc, char *argv[] );33extern void __wine_init_so_dll(void);3435static char **build_argv( const char *src, int *ret_argc )36{37char **argv, *arg, *dst;38int argc, in_quotes = 0, bcount = 0, len = strlen(src) + 1;3940argc = 2 + len / 2;41argv = HeapAlloc( GetProcessHeap(), 0, argc * sizeof(*argv) + len );42arg = dst = (char *)(argv + argc);43argc = 0;44while (*src)45{46if ((*src == ' ' || *src == '\t') && !in_quotes)47{48/* skip the remaining spaces */49while (*src == ' ' || *src == '\t') src++;50if (!*src) break;51/* close the argument and copy it */52*dst++ = 0;53argv[argc++] = arg;54/* start with a new argument */55arg = dst;56bcount = 0;57}58else if (*src == '\\')59{60*dst++ = *src++;61bcount++;62}63else if (*src == '"')64{65if ((bcount & 1) == 0)66{67/* Preceded by an even number of '\', this is half that68* number of '\', plus a '"' which we discard.69*/70dst -= bcount / 2;71src++;72if (in_quotes && *src == '"') *dst++ = *src++;73else in_quotes = !in_quotes;74}75else76{77/* Preceded by an odd number of '\', this is half that78* number of '\' followed by a '"'79*/80dst -= bcount / 2 + 1;81*dst++ = *src++;82}83bcount = 0;84}85else /* a regular character */86{87*dst++ = *src++;88bcount = 0;89}90}91*dst = 0;92argv[argc++] = arg;93argv[argc] = NULL;94*ret_argc = argc;95return argv;96}9798DWORD WINAPI __wine_spec_exe_entry( PEB *peb )99{100int argc;101char **argv = build_argv( GetCommandLineA(), &argc );102103__wine_init_so_dll();104ExitProcess( main( argc, argv ));105}106107108