2007-12-31 07:15:43 -08: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"
|
|
|
|
|
|
|
|
#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-03 16:07:06 -08:00
|
|
|
convert.write(arg, len);
|
2008-01-07 08:38:12 -08:00
|
|
|
convert.write_terminator();
|
2007-12-31 07:15:43 -08:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
FreeAllocStrings(int argc, char **argv)
|
|
|
|
{
|
|
|
|
while (argc) {
|
|
|
|
--argc;
|
|
|
|
delete [] argv[argc];
|
|
|
|
}
|
|
|
|
|
|
|
|
delete [] argv;
|
|
|
|
}
|
|
|
|
|
|
|
|
int wmain(int argc, WCHAR **argv)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
int result = main(argc, argvConverted);
|
|
|
|
FreeAllocStrings(argc, argvConverted);
|
|
|
|
return result;
|
|
|
|
}
|