Export global argc/argv variables from libwine and remove the

__wine_get_main_args functions from ntdll.
This commit is contained in:
Alexandre Julliard 2002-05-16 23:16:01 +00:00
parent d8d313d110
commit 702b158e70
6 changed files with 57 additions and 70 deletions

View File

@ -27,7 +27,7 @@
#include "msvcrt/stdlib.h"
#include "msvcrt/string.h"
#include "wine/library.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
@ -158,9 +158,6 @@ static WCHAR *wstrdupa(const char *str)
return wstr;
}
extern int __wine_get_main_args(char*** argv);
extern int __wine_get_wmain_args(WCHAR*** argv);
/* INTERNAL: Since we can't rely on Winelib startup code calling w/getmainargs,
* we initialise data values during DLL loading. When called by a native
* program we simply return the data we've already initialised. This also means
@ -175,8 +172,9 @@ void msvcrt_init_args(void)
MSVCRT__acmdln = _strdup( GetCommandLineA() );
MSVCRT__wcmdln = wstrdupa(MSVCRT__acmdln);
MSVCRT___argc = __wine_get_main_args(&MSVCRT___argv);
__wine_get_wmain_args(&MSVCRT___wargv);
MSVCRT___argc = __wine_main_argc;
MSVCRT___argv = __wine_main_argv;
MSVCRT___wargv = __wine_main_wargv;
TRACE("got '%s', wide = %s argc=%d\n", MSVCRT__acmdln,
debugstr_w(MSVCRT__wcmdln),MSVCRT___argc);

View File

@ -1029,10 +1029,6 @@ name ntdll
@ varargs wine_dbg_printf(str) wine_dbg_printf
@ varargs wine_dbg_log(long str str str) wine_dbg_log
# Command-line
@ cdecl __wine_get_main_args(ptr) __wine_get_main_args
@ cdecl __wine_get_wmain_args(ptr) __wine_get_wmain_args
# Server interface
@ cdecl -norelay wine_server_call(ptr) wine_server_call
@ cdecl wine_server_handle_to_fd(long long ptr ptr ptr) wine_server_handle_to_fd

View File

@ -37,6 +37,10 @@ extern void *wine_dll_load_main_exe( const char *name, int search_path,
char *error, int errorsize );
extern void wine_dll_unload( void *handle );
extern int __wine_main_argc;
extern char **__wine_main_argv;
extern WCHAR **__wine_main_wargv;
/* debugging */
extern void wine_dbg_add_option( const char *name, unsigned char set, unsigned char clear );

View File

@ -34,6 +34,11 @@
#include "winnt.h"
#include "wine/library.h"
/* argc/argv for the Windows application */
int __wine_main_argc = 0;
char **__wine_main_argv = NULL;
WCHAR **__wine_main_wargv = NULL;
#define MAX_DLLS 100
static struct

View File

@ -29,6 +29,7 @@
#include "wine/winbase16.h"
#include "wine/server.h"
#include "wine/library.h"
#include "heap.h"
#include "ntddk.h"
#include "selectors.h"
@ -278,6 +279,40 @@ ENVDB *ENV_InitStartupInfo( handle_t info_handle, size_t info_size,
}
/***********************************************************************
* set_library_argv
*
* Set the Wine library argc/argv global variables.
*/
static void set_library_argv( char **argv )
{
int argc;
WCHAR *p;
WCHAR **wargv;
DWORD total = 0;
for (argc = 0; argv[argc]; argc++)
total += MultiByteToWideChar( CP_ACP, 0, argv[argc], -1, NULL, 0 );
wargv = HeapAlloc( GetProcessHeap(), 0,
total * sizeof(WCHAR) + (argc + 1) * sizeof(*wargv) );
p = (WCHAR *)(wargv + argc + 1);
for (argc = 0; argv[argc]; argc++)
{
DWORD len = MultiByteToWideChar( CP_ACP, 0, argv[argc], -1, p, total );
wargv[argc] = p;
p += len;
total -= len;
}
wargv[argc] = NULL;
__wine_main_argc = argc;
__wine_main_argv = argv;
__wine_main_wargv = wargv;
}
/***********************************************************************
* ENV_BuildCommandLine
*
@ -305,6 +340,8 @@ BOOL ENV_BuildCommandLine( char **argv )
int len;
char *p, **arg;
set_library_argv( argv );
if (current_envdb.cmd_line) goto done; /* already got it from the server */
len = 0;

View File

@ -109,9 +109,6 @@ PDB current_process;
#define PDB32_FILE_APIS_OEM 0x0040 /* File APIs are OEM */
#define PDB32_WIN32S_PROC 0x8000 /* Win32s process */
static int app_argc; /* argc/argv seen by the application */
static char **app_argv;
static WCHAR **app_wargv;
static char main_exe_name[MAX_PATH];
static char *main_exe_name_ptr = main_exe_name;
static HANDLE main_exe_file;
@ -252,7 +249,6 @@ static BOOL process_init( char *argv[] )
/* store the program name */
argv0 = argv[0];
app_argv = argv;
/* Fill the initial process structure */
current_process.exit_code = STILL_ACTIVE;
@ -320,8 +316,6 @@ static BOOL process_init( char *argv[] )
/* Parse command line arguments */
OPTIONS_ParseOptions( !info ? argv : NULL );
app_argc = 0;
while (argv[app_argc]) app_argc++;
ret = MAIN_MainInit();
@ -489,20 +483,19 @@ void PROCESS_InitWine( int argc, char *argv[], LPSTR win16_exe_name, HANDLE *win
/* Initialize everything */
if (!process_init( argv )) exit(1);
if (open_winelib_app( app_argv )) goto found; /* try to open argv[0] as a winelib app */
if (open_winelib_app( argv )) goto found; /* try to open argv[0] as a winelib app */
app_argv++; /* remove argv[0] (wine itself) */
app_argc--;
argv++; /* remove argv[0] (wine itself) */
if (!main_exe_name[0])
{
if (!app_argv[0]) OPTIONS_Usage();
if (!argv[0]) OPTIONS_Usage();
/* open the exe file */
if (!SearchPathA( NULL, app_argv[0], ".exe", sizeof(main_exe_name), main_exe_name, NULL) &&
!SearchPathA( NULL, app_argv[0], NULL, sizeof(main_exe_name), main_exe_name, NULL))
if (!SearchPathA( NULL, argv[0], ".exe", sizeof(main_exe_name), main_exe_name, NULL) &&
!SearchPathA( NULL, argv[0], NULL, sizeof(main_exe_name), main_exe_name, NULL))
{
MESSAGE( "%s: cannot find '%s'\n", argv0, app_argv[0] );
MESSAGE( "%s: cannot find '%s'\n", argv0, argv[0] );
goto error;
}
}
@ -536,7 +529,7 @@ void PROCESS_InitWine( int argc, char *argv[], LPSTR win16_exe_name, HANDLE *win
found:
/* build command line */
if (!ENV_BuildCommandLine( app_argv )) goto error;
if (!ENV_BuildCommandLine( argv )) goto error;
/* create 32-bit module for main exe */
if (!(current_process.module = BUILTIN32_LoadExeModule( current_process.module ))) goto error;
@ -553,52 +546,6 @@ void PROCESS_InitWine( int argc, char *argv[], LPSTR win16_exe_name, HANDLE *win
}
/***********************************************************************
* __wine_get_main_args (NTDLL.@)
*
* Return the argc/argv that the application should see.
* Used by the startup code generated in the .spec.c file.
*/
int __wine_get_main_args( char ***argv )
{
*argv = app_argv;
return app_argc;
}
/***********************************************************************
* __wine_get_wmain_args (NTDLL.@)
*
* Same as __wine_get_main_args but for Unicode.
*/
int __wine_get_wmain_args( WCHAR ***argv )
{
if (!app_wargv)
{
int i;
WCHAR *p;
DWORD total = 0;
for (i = 0; i < app_argc; i++)
total += MultiByteToWideChar( CP_ACP, 0, app_argv[i], -1, NULL, 0 );
app_wargv = HeapAlloc( GetProcessHeap(), 0,
total * sizeof(WCHAR) + (app_argc + 1) * sizeof(*app_wargv) );
p = (WCHAR *)(app_wargv + app_argc + 1);
for (i = 0; i < app_argc; i++)
{
DWORD len = MultiByteToWideChar( CP_ACP, 0, app_argv[i], -1, p, total );
app_wargv[i] = p;
p += len;
total -= len;
}
app_wargv[app_argc] = NULL;
}
*argv = app_wargv;
return app_argc;
}
/***********************************************************************
* build_argv
*