aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/initialize.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/ada/initialize.c')
-rw-r--r--gcc/ada/initialize.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/gcc/ada/initialize.c b/gcc/ada/initialize.c
index dbaf80f6ee6..f5acbe6593a 100644
--- a/gcc/ada/initialize.c
+++ b/gcc/ada/initialize.c
@@ -43,6 +43,9 @@
#ifdef IN_RTS
#include "tconfig.h"
#include "tsystem.h"
+/* We don't have libiberty, so use malloc. */
+#define xmalloc(S) malloc (S)
+#define xrealloc(V,S) realloc (V,S)
#else
#include "config.h"
#include "system.h"
@@ -55,17 +58,44 @@
/******************************************/
#if defined (__MINGW32__)
+#include "mingw32.h"
#include <windows.h>
extern void __gnat_init_float (void);
extern void __gnat_install_SEH_handler (void *);
+extern int gnat_argc;
+extern char **gnat_argv;
+
#ifndef RTX
/* Do not define for RTX since it is only used for creating child processes
which is not supported in RTX. */
extern void __gnat_plist_init (void);
#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)
+ {
+ *last += EXPAND_ARGV_RATE;
+ *argv = (char **) xrealloc (*argv, (*last) * sizeof (char *));
+ }
+
+ size = WS2SC (NULL, value, 0);
+ (*argv)[*index] = (char *) xmalloc (size + 1);
+ WS2SC ((*argv)[*index], value, size);
+
+ (*index)++;
+}
+#endif
+
void
__gnat_initialize (void *eh)
{
@@ -75,6 +105,85 @@ __gnat_initialize (void *eh)
given that we have set Max_Digits etc with this in mind */
__gnat_init_float ();
+#ifdef GNAT_UNICODE_SUPPORT
+ /* Set current code page for filenames handling. */
+ {
+ char *codepage = getenv ("GNAT_CODE_PAGE");
+
+ /* Default code page is UTF-8. */
+ CurrentCodePage = CP_UTF8;
+
+ if (codepage != NULL)
+ if (strcmp (codepage, "CP_ACP") == 0)
+ CurrentCodePage = CP_ACP;
+ else if (strcmp (codepage, "CP_UTF8") == 0)
+ CurrentCodePage = CP_UTF8;
+ }
+
+ /* Adjust gnat_argv to support Unicode characters. */
+ {
+ LPWSTR *wargv;
+ int wargc;
+ int k;
+ int last;
+ int argc_expanded = 0;
+ TCHAR result [MAX_PATH];
+
+ wargv = CommandLineToArgvW (GetCommandLineW(), &wargc);
+
+ if (wargv != NULL)
+ {
+ /* Set gnat_argv with arguments encoded in UTF-8. */
+ 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=1; k<wargc; k++)
+ {
+ /* Check for wildcard expansion. */
+ if (_tcsstr (wargv[k], _T("?")) != 0 ||
+ _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);
+ gnat_argc = argc_expanded;
+ gnat_argv = (char **) xrealloc
+ (gnat_argv, argc_expanded * sizeof (char *));
+ }
+ }
+#endif
+
/* 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
to __gnat_initialize() without argument. Therefore we cannot use eh in