コード例 #1
0
int main()
{
	wchar_t **enpv, **argv;
	int argc, si = 0;
	__wgetmainargs(&argc, &argv, &enpv, _CRT_glob, &si);
	return wmain(argc, argv);
}
コード例 #2
0
int main() {
  TCHAR **argv, **enpv;
  int argc, si = 0;

  __wgetmainargs(&argc, &argv, &enpv, _CRT_glob, &si);
  return tmain(argc, argv);
}
コード例 #3
0
ファイル: crtexe.c プロジェクト: mysticTot/learn_c
static void __cdecl pre_cpp_init(void) {
#ifdef _RTC
    atexit(_RTC_Terminate);
#endif  /* _RTC */
    /*
     * Get the arguments for the call to main. Note this must be
     * done explicitly, rather than as part of the dll's
     * initialization, to implement optional expansion of wild
     * card chars in filename args
     */
    startinfo.newmode = _newmode;
#ifdef WPRFLAG
    argret = __wgetmainargs(&argc, &argv, &envp,
                            _dowildcard, &startinfo);
#else  /* WPRFLAG */
    argret = __getmainargs(&argc, &argv, &envp,
                           _dowildcard, &startinfo);
#endif  /* WPRFLAG */
#ifndef _SYSCRT

    if (argret < 0) {
        _amsg_exit(_RT_SPACEARG);
    }

#endif  /* _SYSCRT */
}
コード例 #4
0
ファイル: win32_support.c プロジェクト: dingdada/tain335
int win32_cmdline_utf8(int * argc, char *** argv)
{
    int argcounter;
    wchar_t **argv_wide;
    wchar_t **env;
    char *argvptr;
    _startupinfo startup;

    /* That's too lame. */
    if(argv == NULL || argc == NULL) return -1;

    startup.newmode = 0;
    __wgetmainargs(argc, &argv_wide,&env,1, &startup);
    *argv = (char **)calloc(sizeof (char *), *argc);
    if(*argv == NULL) {
        error("Cannot allocate memory for command line.");
        return -1;
    }

    for(argcounter = 0; argcounter < *argc; argcounter++)
    {
        win32_wide_utf8(argv_wide[argcounter], &argvptr, NULL);
        (*argv)[argcounter] = argvptr;
    }
    return 0;
}
コード例 #5
0
ファイル: main.c プロジェクト: cdenix/ps3-mame-0125
int _tmain(int argc, TCHAR **argv)
#endif // __GNUC__
{
	int i, rc;
	char **utf8_argv;

#ifdef __GNUC__
	TCHAR **argv;
#ifdef UNICODE
	// MinGW doesn't support wmain() directly, so we have to jump through some hoops
	extern void __wgetmainargs(int *argc, wchar_t ***wargv, wchar_t ***wenviron, int expand_wildcards, int *startupinfo);
	WCHAR **wenviron;
	int startupinfo;
	__wgetmainargs(&argc, &argv, &wenviron, 0, &startupinfo);
#else // !UNICODE
	argv = a_argv;
#endif // UNICODE
#endif // __GNUC__

#ifdef MALLOC_DEBUG
{
	extern int winalloc_in_main_code;
	winalloc_in_main_code = TRUE;
#endif

	/* convert arguments to UTF-8 */
	utf8_argv = (char **) malloc(argc * sizeof(*argv));
	if (utf8_argv == NULL)
		return 999;
	for (i = 0; i < argc; i++)
	{
		utf8_argv[i] = utf8_from_tstring(argv[i]);
		if (utf8_argv[i] == NULL)
			return 999;
	}

	/* run utf8_main */
	rc = utf8_main(argc, utf8_argv);

	/* free arguments */
	for (i = 0; i < argc; i++)
		free(utf8_argv[i]);
	free(utf8_argv);

#ifdef MALLOC_DEBUG
	{
		void check_unfreed_mem(void);
		check_unfreed_mem();
	}
	winalloc_in_main_code = FALSE;
}
#endif

	return rc;
}
コード例 #6
0
ファイル: crtexe.c プロジェクト: HBelusca/NasuTek-Odyssey
static void __cdecl
pre_cpp_init (void)
{
  startinfo.newmode = _newmode;

#ifdef WPRFLAG
  argret = __wgetmainargs(&argc,&argv,&envp,_dowildcard,&startinfo);
#else
  argret = __getmainargs(&argc,&argv,&envp,_dowildcard,&startinfo);
#endif
}
コード例 #7
0
ファイル: compat_win32.c プロジェクト: John-He-928/fdkaac
void aacenc_getmainargs(int *argc, char ***argv)
{
    int i;
    wchar_t **wargv, **envp;
    _startupinfo si = { 0 };

    __wgetmainargs(argc, &wargv, &envp, 1, &si);
    *argv = malloc((*argc + 1) * sizeof(char*));
    for (i = 0; i < *argc; ++i)
        codepage_encode_wchar(CP_ACP, wargv[i], &(*argv)[i]);
    (*argv)[*argc] = 0;
    __aacenc_argv__ = *argv;
    atexit(aacenc_free_mainargs);
}
コード例 #8
0
ファイル: segmenter.c プロジェクト: Haehnchen/http-segmenter
//----------------------------------------------------------------
// main
// 
int main()
{
    wchar_t ** wenpv = NULL;
    wchar_t ** wargv = NULL;
    int argc = 0;
    int startupInfo = 0;

    __wgetmainargs(&argc, &wargv, &wenpv, 1, &startupInfo);
    
    char ** argv = (char **)malloc(argc * sizeof(char *));
    for (int i = 0; i < argc; i++)
    {
        argv[i] = utf16_to_utf8(wargv[i]);
    }
    
    return main_utf8(argc, argv);
}
コード例 #9
0
ファイル: windows.c プロジェクト: fjrti/subsurface
/* expand-convert the UTF-16 argument list to a list of UTF-8 strings */
void subsurface_command_line_init(gint *argc, gchar ***argv)
{
	wchar_t **wargv, **wenviron;
	gchar **argv_new;
	gchar *s;
	/* for si we assume that a struct address will equal the address
	 * of its first and only int member */
	gint i, n, ret, si;

	/* memory leak tools may reports a potential issue here at a call
	 * to strcpy_s in msvcrt, wich should be a false positive. but even if there
	 * is some kind of a leak, it should be unique and have the same
	 * lifespan as the process heap. */
	ret = __wgetmainargs(&n, &wargv, &wenviron, TRUE, &si);
	if (ret < 0) {
		g_warning("Cannot convert command line");
		return;
	}
	argv_new = g_malloc(sizeof(gchar *) * (n + 1));

	for (i = 0; i < n; ++i) {
		s = g_utf16_to_utf8((gunichar2 *)wargv[i], -1, NULL, NULL, NULL);
		if (!s) {
			g_warning("Cannot convert command line argument (%d) to UTF-8", (i + 1));
			s = "\0";
		}	else if (!g_utf8_validate(s, -1, NULL)) {
			g_warning("Cannot validate command line argument '%s' (%d)", s, (i + 1));
			g_free(s);
			s = "\0";
		}
		argv_new[i] = s;
	}
	argv_new[n] = NULL;

	/* update the argument list and count */
	if (argv && argc) {
		*argv = argv_new;
		*argc = n;
	}
}
コード例 #10
0
ファイル: win_utf8_io.c プロジェクト: Audacity-Team/Audacity
/* retrieve WCHAR commandline, expand wildcards and convert everything to UTF-8 */
int get_utf8_argv(int *argc, char ***argv)
{
	typedef int (__cdecl *__wgetmainargs_)(int*, wchar_t***, wchar_t***, int, int*);
	__wgetmainargs_ __wgetmainargs;
	HMODULE handle;
	int wargc;
	wchar_t **wargv;
	wchar_t **wenv;
	char **utf8argv;
	int ret, i;

	if ((handle = LoadLibrary("msvcrt.dll")) == NULL) return 1;
	if ((__wgetmainargs = (__wgetmainargs_)GetProcAddress(handle, "__wgetmainargs")) == NULL) return 1;
	i = 0;
	if (__wgetmainargs(&wargc, &wargv, &wenv, 1, &i) != 0) return 1;
	if ((utf8argv = (char **)malloc(wargc*sizeof(char*))) == NULL) return 1;
	ret = 0;

	for (i=0; i<wargc; i++) {
		if ((utf8argv[i] = utf8_from_wchar(wargv[i])) == NULL) {
			ret = 1;
			break;
		}
		if (ret != 0) break;
	}

	FreeLibrary(handle);

	if (ret == 0) {
		win_utf8_io_codepage = CP_UTF8;
		*argc = wargc;
		*argv = utf8argv;
	} else {
		free(utf8argv);
	}

	return ret;
}
コード例 #11
0
ファイル: vifm.c プロジェクト: phantasea/vifm
int
main()
{
	extern int _CRT_glob;
	extern void __wgetmainargs(int *, wchar_t ***, wchar_t ***, int, int *);

	char **utf8_argv;
	int i;

	wchar_t **envp, **argv;
	int argc, si = 0;
	__wgetmainargs(&argc, &argv, &envp, _CRT_glob, &si);

	utf8_argv = reallocarray(NULL, argc + 1, sizeof(*utf8_argv));

	for(i = 0; i < argc; ++i)
	{
		utf8_argv[i] = utf8_from_utf16(argv[i]);
	}
	utf8_argv[i] = NULL;

	vifm_exit(vifm_main(argc, utf8_argv));
}
コード例 #12
0
ファイル: wcrtstartup.c プロジェクト: ArildF/masters
int __cdecl wmainCRTStartup()
{
    int mainret;
    struct _startupinfo startupinfo;
    struct _wmainargs wmainargs;

    // initialize the PAL
    PAL_Initialize(NULL, NULL);

    startupinfo.newmode = 0;

    __wgetmainargs(&wmainargs.argc, &wmainargs.argv, &wmainargs.envp, _dowildcard, &startupinfo);

    // call the user supplied main
    mainret = (int)PAL_LocalFrame((PTHREAD_START_ROUTINE)run_wmain, &wmainargs);

    // shutdown the PAL
    PAL_Terminate();

    ExitProcess(mainret);

    //Never reach this point
    return mainret;
}
コード例 #13
0
ファイル: environ.c プロジェクト: hoangduit/reactos
static void test__wenviron(void)
{
    static const WCHAR cat_eq_dogW[] = {'c','a','t','=','d','o','g',0};
    static const WCHAR cat_eqW[] = {'c','a','t','=',0};

    int argc;
    char **argv, **envp = NULL;
    WCHAR **wargv, **wenvp = NULL;
    int i, mode = 0;

    ok( p_wenviron != NULL, "Expected the pointer to _wenviron to be non-NULL\n" );
    if (p_wenviron)
        ok( *p_wenviron == NULL, "Expected _wenviron to be NULL, got %p\n", *p_wenviron );
    else
    {
        win_skip( "Pointer to _wenviron is not valid\n" );
        return;
    }

    /* Examine the returned pointer from __p__wenviron(), if available. */
    if (p__p__wenviron)
    {
        ok( *p__p__wenviron() == NULL,
            "Expected _wenviron pointers to be NULL\n" );
    }
    else
        win_skip( "__p__wenviron() is not available\n" );

    /* __getmainargs doesn't initialize _wenviron. */
    __getmainargs(&argc, &argv, &envp, 0, &mode);

    ok( *p_wenviron == NULL, "Expected _wenviron to be NULL, got %p\n", *p_wenviron);
    ok( envp != NULL, "Expected initial environment block pointer to be non-NULL\n" );
    if (!envp)
    {
        skip( "Initial environment block pointer is not valid\n" );
        return;
    }

    /* Neither does calling the non-Unicode environment manipulation functions. */
    ok( _putenv("cat=dog") == 0, "failed setting cat=dog\n" );
    ok( *p_wenviron == NULL, "Expected _wenviron to be NULL, got %p\n", *p_wenviron);
    ok( _putenv("cat=") == 0, "failed deleting cat\n" );

    /* _wenviron isn't initialized until __wgetmainargs is called or
     * one of the Unicode environment manipulation functions is called. */
    ok( _wputenv(cat_eq_dogW) == 0, "failed setting cat=dog\n" );
    ok( *p_wenviron != NULL, "Expected _wenviron to be non-NULL\n" );
    ok( _wputenv(cat_eqW) == 0, "failed deleting cat\n" );

    __wgetmainargs(&argc, &wargv, &wenvp, 0, &mode);

    ok( *p_wenviron != NULL, "Expected _wenviron to be non-NULL\n" );
    ok( wenvp != NULL, "Expected initial environment block pointer to be non-NULL\n" );
    if (!wenvp)
    {
        skip( "Initial environment block pointer is not valid\n" );
        return;
    }

    /* Examine the returned pointer from __p__wenviron(),
     * if available, after _wenviron is initialized. */
    if (p__p__wenviron)
    {
        ok( *p__p__wenviron() == *p_wenviron,
            "Expected _wenviron pointers to be identical\n" );
    }

    for (i = 0; ; i++)
    {
        if ((*p_wenviron)[i])
        {
            ok( wenvp[i] != NULL, "Expected environment block pointer element to be non-NULL\n" );
            ok( !winetest_strcmpW((*p_wenviron)[i], wenvp[i]),
                "Expected _wenviron and environment block pointer strings (%s vs. %s) to match\n",
                wine_dbgstr_w((*p_wenviron)[i]), wine_dbgstr_w(wenvp[i]) );
        }
        else
        {
            ok( !wenvp[i], "Expected environment block pointer element to be NULL, got %p\n", wenvp[i] );
            break;
        }
    }
}
コード例 #14
0
ファイル: ffmsindex.cpp プロジェクト: tgoyne/ffms2
int main() {
	int argc;
	wchar_t **_argv;
	wchar_t **env;
	int si = 0;
	__wgetmainargs(&argc, &_argv, &env, _CRT_glob, &si);
#else
int wmain(int argc, wchar_t *_argv[]) {
#endif
	char **argv = (char**)malloc(argc*sizeof(char*));
	for (int i=0; i<argc; i++) {
		int len = WideCharToMultiByte(CP_UTF8, 0, _argv[i], -1, NULL, 0, NULL, NULL);
		if (!len) {
			std::cout << "Failed to translate commandline to Unicode" << std::endl;
			return 1;
		}
		char *temp = (char*)malloc(len*sizeof(char));
		len = WideCharToMultiByte(CP_UTF8, 0, _argv[i], -1, temp, len, NULL, NULL);
		if (!len) {
			std::cout << "Failed to translate commandline to Unicode" << std::endl;
			return 1;
		}
		argv[i] = temp;
	}
#else /* defined(_WIN32) && !defined(__MINGW32__) */
int main(int argc, char *argv[]) {
#endif /* defined(_WIN32) && !defined(__MINGW32__) */
	try {
		ParseCMDLine(argc, argv);
	} catch (const char *Error) {
		std::cout << std::endl << Error << std::endl;
		return 1;
	} catch (std::string Error) {
		std::cout << std::endl << Error << std::endl;
		return 1;
	} catch (...) {
		std::cout << std::endl << "Unknown error" << std::endl;
		return 1;
	}

#ifdef _WIN32
	if (FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED))) {
		std::cout << "COM initialization failure" << std::endl;
		return 1;
	}
#endif /* _WIN32 */

	FFMS_Init(0, 1);

	switch (Verbose) {
		case 0: FFMS_SetLogLevel(AV_LOG_QUIET); break;
		case 1: FFMS_SetLogLevel(AV_LOG_WARNING); break;
		case 2: FFMS_SetLogLevel(AV_LOG_INFO); break;
		case 3:	FFMS_SetLogLevel(AV_LOG_VERBOSE); break;
		default: FFMS_SetLogLevel(AV_LOG_DEBUG); // if user used -v 4 or more times, he deserves the spam
	}

	try {
		DoIndexing();
	} catch (const char *Error) {
		std::cout << Error << std::endl;
		if (Index)
			FFMS_DestroyIndex(Index);
		return 1;
	} catch (std::string Error) {
		std::cout << std::endl << Error << std::endl;
		if (Index)
			FFMS_DestroyIndex(Index);
		return 1;
	} catch (...) {
		std::cout << std::endl << "Unknown error" << std::endl;
		if (Index)
			FFMS_DestroyIndex(Index);
		return 1;
	}

	if (Index)
		FFMS_DestroyIndex(Index);
#ifdef _WIN32
	CoUninitialize();
#endif
	return 0;
}
コード例 #15
0
ファイル: msvcrt20.c プロジェクト: HBelusca/NasuTek-Odyssey
/*********************************************************************
 *		__wgetmainargs (MSVCRT20.@)
 *
 * new_mode is not a pointer in msvcrt20.
 */
void CDECL MSVCRT20__wgetmainargs( int *argc, WCHAR** *wargv, WCHAR** *wenvp,
                                   int expand_wildcards, int new_mode )
{
    __wgetmainargs( argc, wargv, wenvp, expand_wildcards, &new_mode );
}