Commit 46e26fe3 by Pascal Obry Committed by Arnaud Charlet

initialize.c: Do not get Unicode command line if Unicode support not activated.

2009-04-17  Pascal Obry  <obry@adacore.com>

	* initialize.c: Do not get Unicode command line if Unicode support not
	activated.
	Add support for wildcard expansion for Unicode parameters on Win32.

	* mingw32.h: Add missing macros when Unicode support not activated.

From-SVN: r146258
parent fabf2749
2009-04-17 Pascal Obry <obry@adacore.com>
* initialize.c: Do not get Unicode command line if Unicode support not
activated.
Add support for wildcard expansion for Unicode parameters on Win32.
* mingw32.h: Add missing macros when Unicode support not activated.
2009-04-17 Javier Miranda <miranda@adacore.com> 2009-04-17 Javier Miranda <miranda@adacore.com>
* sem_ch6.adb (Check_Anonymous_Return): Add missing checks to * sem_ch6.adb (Check_Anonymous_Return): Add missing checks to
...@@ -72,6 +72,52 @@ extern char **gnat_argv; ...@@ -72,6 +72,52 @@ extern char **gnat_argv;
extern void __gnat_plist_init (void); extern void __gnat_plist_init (void);
#endif #endif
#ifdef GNAT_UNICODE_SUPPORT
#define EXPAND_ARGV_RATE 128
static void
append_arg (int *index, LPWSTR value, char ***argv, int *last)
{
int size;
if (*last < *index)
{
char **old_argv = *argv;
int old_last = *last;
int k;
*last += EXPAND_ARGV_RATE;
*argv = (char **) xmalloc ((*last) * sizeof (char *));
for (k=0; k<=old_last; k++)
(*argv)[k] = old_argv[k];
free (old_argv);
}
size = WS2SC (NULL, value, 0);
(*argv)[*index] = (char *) xmalloc (size + 1);
WS2SC ((*argv)[*index], value, size);
(*index)++;
}
static void
adjust_arg (int last, char ***argv)
{
char **old_argv = *argv;
int k;
*argv = (char **) xmalloc (last * sizeof (char *));
for (k=0; k<last; k++)
(*argv)[k] = old_argv[k];
free (old_argv);
}
#endif
void void
__gnat_initialize (void *eh) __gnat_initialize (void *eh)
{ {
...@@ -91,37 +137,73 @@ __gnat_initialize (void *eh) ...@@ -91,37 +137,73 @@ __gnat_initialize (void *eh)
if (codepage != NULL) if (codepage != NULL)
if (strcmp (codepage, "CP_ACP") == 0) if (strcmp (codepage, "CP_ACP") == 0)
CurrentCodePage = CP_ACP; CurrentCodePage = CP_ACP;
else if (strcmp (codepage, "CP_UTF8") == 0) else if (strcmp (codepage, "CP_UTF8") == 0)
CurrentCodePage = CP_UTF8; CurrentCodePage = CP_UTF8;
} }
#endif
/* Adjust gnat_argv to support Unicode characters. */ /* Adjust gnat_argv to support Unicode characters. */
{ {
LPWSTR *wargv; LPWSTR *wargv;
int wargc; int wargc;
int k; int k;
int size; int last;
int argc_expanded = 0;
TCHAR result [MAX_PATH];
wargv = CommandLineToArgvW (GetCommandLineW(), &wargc); wargv = CommandLineToArgvW (GetCommandLineW(), &wargc);
if (wargv != NULL) if (wargv != NULL)
{ {
/* Set gnat_argv with arguments encoded in UTF-8. */ /* Set gnat_argv with arguments encoded in UTF-8. */
gnat_argv = (char **) xmalloc ((wargc + 1) * sizeof (char *)); last = wargc + 1;
gnat_argv = (char **) xmalloc ((last) * sizeof (char *));
/* argv[0] is the executable full path-name. */
SearchPath (NULL, wargv[0], _T(".exe"), MAX_PATH, result, NULL);
append_arg (&argc_expanded, result, &gnat_argv, &last);
for (k=0; k<wargc; k++) for (k=1; k<wargc; k++)
{ {
size = WS2SC (NULL, wargv[k], 0); /* Check for wildcard expansion. */
gnat_argv[k] = (char *) xmalloc (size + 1); if (_tcsstr (wargv[k], _T("?")) != 0 ||
WS2SC (gnat_argv[k], wargv[k], size); _tcsstr (wargv[k], _T("*")) != 0)
{
/* Wilcards are present, append all corresponding matches. */
WIN32_FIND_DATA FileData;
HANDLE hDir = FindFirstFile (wargv[k], &FileData);
if (hDir == INVALID_HANDLE_VALUE)
{
/* No match, append arg as-is. */
append_arg (&argc_expanded, wargv[k], &gnat_argv, &last);
}
else
{
/* Append first match and all remaining ones. */
do {
append_arg (&argc_expanded,
FileData.cFileName, &gnat_argv, &last);
} while (FindNextFile (hDir, &FileData));
FindClose (hDir);
}
}
else
{
/* No wildcard. Store parameter as-is. */
append_arg (&argc_expanded, wargv[k], &gnat_argv, &last);
}
} }
LocalFree (wargv); LocalFree (wargv);
gnat_argc = wargc; gnat_argc = argc_expanded;
adjust_arg (argc_expanded, &gnat_argv);
} }
} }
#endif
/* Note that we do not activate this for the compiler itself to avoid a /* Note that we do not activate this for the compiler itself to avoid a
bootstrap path problem. Older version of gnatbind will generate a call bootstrap path problem. Older version of gnatbind will generate a call
......
...@@ -93,6 +93,8 @@ extern UINT CurrentCodePage; ...@@ -93,6 +93,8 @@ extern UINT CurrentCodePage;
#define WS2S(str,wstr,len) \ #define WS2S(str,wstr,len) \
WideCharToMultiByte (CP_ACP,0,wstr,-1,str,len,NULL,NULL) WideCharToMultiByte (CP_ACP,0,wstr,-1,str,len,NULL,NULL)
#else #else
#define S2WSC(wstr,str,len) strncpy(wstr,str,len)
#define WS2SC(str,wstr,len) strncpy(str,wstr,len)
#define S2WSU(wstr,str,len) strncpy(wstr,str,len) #define S2WSU(wstr,str,len) strncpy(wstr,str,len)
#define WS2SU(str,wstr,len) strncpy(str,wstr,len) #define WS2SU(str,wstr,len) strncpy(str,wstr,len)
#define S2WS(wstr,str,len) strncpy(wstr,str,len) #define S2WS(wstr,str,len) strncpy(wstr,str,len)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment