2007-12-31 15:15:43 +00:00
|
|
|
// This file is a .cpp file meant to be included in nsBrowserApp.cpp and other
|
|
|
|
// similar bootstrap code. It converts wide-character windows wmain into UTF-8
|
|
|
|
// narrow-character strings.
|
|
|
|
|
|
|
|
#ifndef XP_WIN
|
|
|
|
#error This file only makes sense on Windows.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "nsUTF8Utils.h"
|
2010-11-15 15:19:57 +00:00
|
|
|
|
|
|
|
#ifndef XRE_DONT_PROTECT_DLL_LOAD
|
2010-11-04 18:45:51 +00:00
|
|
|
#include "nsSetDllDirectory.h"
|
2010-11-15 15:19:57 +00:00
|
|
|
#endif
|
2007-12-31 15:15:43 +00:00
|
|
|
|
2011-04-25 01:02:07 +00:00
|
|
|
#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) && defined(XRE_WANT_DLL_BLOCKLIST)
|
2009-11-04 06:35:20 +00:00
|
|
|
#include "nsWindowsDllBlocklist.cpp"
|
|
|
|
#else
|
|
|
|
#undef XRE_WANT_DLL_BLOCKLIST
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-02-10 08:46:13 +00:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
|
|
|
|
/* MingW currently does not implement a wide version of the
|
|
|
|
startup routines. Workaround is to implement something like
|
|
|
|
it ourselves. See bug 411826 */
|
|
|
|
|
|
|
|
#include <shellapi.h>
|
|
|
|
|
|
|
|
int wmain(int argc, WCHAR **argv);
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
LPWSTR commandLine = GetCommandLineW();
|
|
|
|
int argcw = 0;
|
|
|
|
LPWSTR *argvw = CommandLineToArgvW(commandLine, &argcw);
|
|
|
|
if (!argvw)
|
|
|
|
return 127;
|
|
|
|
|
|
|
|
int result = wmain(argcw, argvw);
|
|
|
|
LocalFree(argvw);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif /* __MINGW32__ */
|
|
|
|
|
2007-12-31 15:15:43 +00:00
|
|
|
#define main NS_internal_main
|
|
|
|
|
|
|
|
int main(int argc, char **argv);
|
|
|
|
|
|
|
|
static char*
|
|
|
|
AllocConvertUTF16toUTF8(const WCHAR *arg)
|
|
|
|
{
|
|
|
|
// be generous... UTF16 units can expand up to 3 UTF8 units
|
|
|
|
int len = wcslen(arg);
|
|
|
|
char *s = new char[len * 3 + 1];
|
|
|
|
if (!s)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ConvertUTF16toUTF8 convert(s);
|
2008-01-04 00:07:06 +00:00
|
|
|
convert.write(arg, len);
|
2008-01-07 16:38:12 +00:00
|
|
|
convert.write_terminator();
|
2007-12-31 15:15:43 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
FreeAllocStrings(int argc, char **argv)
|
|
|
|
{
|
|
|
|
while (argc) {
|
|
|
|
--argc;
|
|
|
|
delete [] argv[argc];
|
|
|
|
}
|
|
|
|
|
|
|
|
delete [] argv;
|
|
|
|
}
|
|
|
|
|
|
|
|
int wmain(int argc, WCHAR **argv)
|
|
|
|
{
|
2010-11-04 18:45:51 +00:00
|
|
|
#ifndef XRE_DONT_PROTECT_DLL_LOAD
|
2011-05-22 06:22:27 +00:00
|
|
|
mozilla::SanitizeEnvironmentVariables();
|
2012-02-08 21:04:21 +00:00
|
|
|
mozilla::NS_SetDllDirectory(L"");
|
2010-11-04 18:45:51 +00:00
|
|
|
#endif
|
2010-09-29 00:33:43 +00:00
|
|
|
|
2009-11-04 06:35:20 +00:00
|
|
|
#ifdef XRE_WANT_DLL_BLOCKLIST
|
|
|
|
SetupDllBlocklist();
|
|
|
|
#endif
|
|
|
|
|
2007-12-31 15:15:43 +00:00
|
|
|
char **argvConverted = new char*[argc + 1];
|
|
|
|
if (!argvConverted)
|
|
|
|
return 127;
|
|
|
|
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
argvConverted[i] = AllocConvertUTF16toUTF8(argv[i]);
|
|
|
|
if (!argvConverted[i]) {
|
|
|
|
return 127;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argvConverted[argc] = NULL;
|
2008-02-10 08:47:09 +00:00
|
|
|
|
2008-02-06 21:53:43 +00:00
|
|
|
// need to save argvConverted copy for later deletion.
|
|
|
|
char **deleteUs = new char*[argc+1];
|
|
|
|
if (!deleteUs) {
|
|
|
|
FreeAllocStrings(argc, argvConverted);
|
|
|
|
return 127;
|
|
|
|
}
|
2009-04-13 15:18:43 +00:00
|
|
|
for (int i = 0; i < argc; i++)
|
2008-02-06 21:53:43 +00:00
|
|
|
deleteUs[i] = argvConverted[i];
|
2007-12-31 15:15:43 +00:00
|
|
|
int result = main(argc, argvConverted);
|
2008-02-10 08:47:09 +00:00
|
|
|
|
2008-02-06 21:53:43 +00:00
|
|
|
delete[] argvConverted;
|
|
|
|
FreeAllocStrings(argc, deleteUs);
|
2008-02-10 08:47:09 +00:00
|
|
|
|
2007-12-31 15:15:43 +00:00
|
|
|
return result;
|
|
|
|
}
|