X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=gcc%2Fada%2Finitialize.c;h=fbbdf6052752eb310eb1fb812288f104e1740398;hb=6fd6922116b3b302cdb11694075fad2daec85184;hp=0b86c2f2f0507ecc84464b8e48842ad0d2015341;hpb=3c8148a687c7bd5c0c1d4ba4ceef949bd1e39e62;p=pf3gnuchains%2Fgcc-fork.git
diff --git a/gcc/ada/initialize.c b/gcc/ada/initialize.c
index 0b86c2f2f05..fbbdf605275 100644
--- a/gcc/ada/initialize.c
+++ b/gcc/ada/initialize.c
@@ -6,24 +6,23 @@
* *
* C Implementation File *
* *
- * Copyright (C) 1992-2005, Free Software Foundation, Inc. *
+ * Copyright (C) 1992-2009, Free Software Foundation, Inc. *
* *
* GNAT is free software; you can redistribute it and/or modify it under *
* terms of the GNU General Public License as published by the Free Soft- *
- * ware Foundation; either version 2, or (at your option) any later ver- *
+ * ware Foundation; either version 3, or (at your option) any later ver- *
* sion. GNAT is distributed in the hope that it will be useful, but WITH- *
* OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
- * for more details. You should have received a copy of the GNU General *
- * Public License distributed with GNAT; see file COPYING. If not, write *
- * to the Free Software Foundation, 51 Franklin Street, Fifth Floor, *
- * Boston, MA 02110-1301, USA. *
+ * or FITNESS FOR A PARTICULAR PURPOSE. *
* *
- * As a special exception, if you link this file with other files to *
- * produce an executable, this file does not by itself cause the resulting *
- * executable to be covered by the GNU General Public License. This except- *
- * ion does not however invalidate any other reasons why the executable *
- * file might be covered by the GNU Public License. *
+ * As a special exception under Section 7 of GPL version 3, you are granted *
+ * additional permissions described in the GCC Runtime Library Exception, *
+ * version 3.1, as published by the Free Software Foundation. *
+ * *
+ * You should have received a copy of the GNU General Public License and *
+ * a copy of the GCC Runtime Library Exception along with this program; *
+ * see the files COPYING3 and COPYING.RUNTIME respectively. If not, see *
+ * . *
* *
* GNAT was originally developed by the GNAT team at New York University. *
* Extensive contributions were provided by Ada Core Technologies Inc. *
@@ -44,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"
@@ -56,14 +58,71 @@
/******************************************/
#if defined (__MINGW32__)
+#include "mingw32.h"
#include
extern void __gnat_init_float (void);
-extern void __gnat_plist_init (void);
extern void __gnat_install_SEH_handler (void *);
+extern int gnat_argc;
+extern char **gnat_argv;
+
+#ifdef GNAT_UNICODE_SUPPORT
+
+#define EXPAND_ARGV_RATE 128
+
+static void
+append_arg (int *index, LPWSTR dir, LPWSTR value,
+ char ***argv, int *last, int quoted)
+{
+ int size;
+ LPWSTR fullvalue;
+ int vallen = _tcslen (value);
+ int dirlen;
+
+ if (dir == NULL)
+ {
+ /* no dir prefix */
+ dirlen = 0;
+ fullvalue = xmalloc ((vallen + 1) * sizeof(TCHAR));
+ }
+ else
+ {
+ /* Add dir first */
+ dirlen = _tcslen (dir);
+
+ fullvalue = xmalloc ((dirlen + vallen + 1) * sizeof(TCHAR));
+ _tcscpy (fullvalue, dir);
+ }
+
+ /* Append value */
+
+ if (quoted)
+ {
+ _tcsncpy (fullvalue + dirlen, value + 1, vallen - 1);
+ fullvalue [dirlen + vallen - sizeof(TCHAR)] = _T('\0');
+ }
+ else
+ _tcscpy (fullvalue + dirlen, value);
+
+ if (*last <= *index)
+ {
+ *last += EXPAND_ARGV_RATE;
+ *argv = (char **) xrealloc (*argv, (*last) * sizeof (char *));
+ }
+
+ size = WS2SC (NULL, fullvalue, 0);
+ (*argv)[*index] = (char *) xmalloc (size + sizeof(TCHAR));
+ WS2SC ((*argv)[*index], fullvalue, size);
+
+ free (fullvalue);
+
+ (*index)++;
+}
+#endif
+
void
-__gnat_initialize (void *eh)
+__gnat_initialize (void *eh ATTRIBUTE_UNUSED)
{
/* Initialize floating-point coprocessor. This call is needed because
the MS libraries default to 64-bit precision instead of 80-bit
@@ -71,9 +130,113 @@ __gnat_initialize (void *eh)
given that we have set Max_Digits etc with this in mind */
__gnat_init_float ();
- /* Initialize a lock for a process handle list - see adaint.c for the
- implementation of __gnat_portable_no_block_spawn, __gnat_portable_wait */
- __gnat_plist_init();
+#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];
+ int quoted;
+
+ 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, NULL, result, &gnat_argv, &last, 0);
+
+ for (k=1; k