X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmini%2Fmain.c;h=784179c64412c86fa7cdb933f081655e69ec94fc;hb=2e59e73e247e8a2a85ef94211c783980a2ef746c;hp=eee91c02d292e6286031514abe1a57a4919dd718;hpb=b87c7e29df7d04e3199e224c8b8e9a41292cec1b;p=mono.git diff --git a/mono/mini/main.c b/mono/mini/main.c index eee91c02d29..784179c6441 100644 --- a/mono/mini/main.c +++ b/mono/mini/main.c @@ -1,13 +1,100 @@ #include #include "mini.h" -#ifndef PLATFORM_WIN32 -#include "buildver.h" +#ifndef HOST_WIN32 +#ifndef BUILDVER_INCLUDED +#include "buildver-boehm.h" #endif +#endif + +/* + * If the MONO_ENV_OPTIONS environment variable is set, it uses this as a + * source of command line arguments that are passed to Mono before the + * command line arguments specified in the command line. + */ +static int +mono_main_with_options (int argc, char *argv []) +{ + const char *env_options = g_getenv ("MONO_ENV_OPTIONS"); + if (env_options != NULL){ + GPtrArray *array = g_ptr_array_new (); + GString *buffer = g_string_new (""); + const char *p; + unsigned i; + gboolean in_quotes = FALSE; + char quote_char = '\0'; + + for (p = env_options; *p; p++){ + switch (*p){ + case ' ': case '\t': + if (!in_quotes) { + if (buffer->len != 0){ + g_ptr_array_add (array, g_strdup (buffer->str)); + g_string_truncate (buffer, 0); + } + } else { + g_string_append_c (buffer, *p); + } + break; + case '\\': + if (p [1]){ + g_string_append_c (buffer, p [1]); + p++; + } + break; + case '\'': + case '"': + if (in_quotes) { + if (quote_char == *p) + in_quotes = FALSE; + else + g_string_append_c (buffer, *p); + } else { + in_quotes = TRUE; + quote_char = *p; + } + break; + default: + g_string_append_c (buffer, *p); + break; + } + } + if (in_quotes) { + fprintf (stderr, "Unmatched quotes in value of MONO_ENV_OPTIONS: [%s]\n", env_options); + exit (1); + } + + if (buffer->len != 0) + g_ptr_array_add (array, g_strdup (buffer->str)); + g_string_free (buffer, TRUE); + + if (array->len > 0){ + int new_argc = array->len + argc; + char **new_argv = g_new (char *, new_argc + 1); + int j; + + new_argv [0] = argv [0]; + + /* First the environment variable settings, to allow the command line options to override */ + for (i = 0; i < array->len; i++) + new_argv [i+1] = g_ptr_array_index (array, i); + i++; + for (j = 1; j < argc; j++) + new_argv [i++] = argv [j]; + new_argv [i] = NULL; -#ifdef PLATFORM_WIN32 + argc = new_argc; + argv = new_argv; + } + g_ptr_array_free (array, TRUE); + } + + return mono_main (argc, argv); +} + +#ifdef HOST_WIN32 int -main () +main (void) { int argc; gunichar2** argvw; @@ -22,7 +109,7 @@ main () LocalFree (argvw); - return mono_main (argc, argv); + return mono_main_with_options (argc, argv); } #else @@ -31,7 +118,8 @@ int main (int argc, char* argv[]) { mono_build_date = build_date; - return mono_main (argc, argv); + + return mono_main_with_options (argc, argv); } #endif