update rx (mobile builds).
[mono-project.git] / mono / mini / main.c
blob808dda0c2fa3cc7811cb561cce25921abc1d1ed6
1 #include <config.h>
2 #include "mini.h"
3 #ifndef HOST_WIN32
4 #ifdef HAVE_SGEN_GC
5 #include "buildver-sgen.h"
6 #else
7 #include "buildver.h"
8 #endif
9 #endif
12 * If the MONO_ENV_OPTIONS environment variable is set, it uses this as a
13 * source of command line arguments that are passed to Mono before the
14 * command line arguments specified in the command line.
16 static int
17 mono_main_with_options (int argc, char *argv [])
19 const char *env_options = getenv ("MONO_ENV_OPTIONS");
20 if (env_options != NULL){
21 GPtrArray *array = g_ptr_array_new ();
22 GString *buffer = g_string_new ("");
23 const char *p;
24 int i;
25 gboolean in_quotes = FALSE;
26 char quote_char = '\0';
28 for (p = env_options; *p; p++){
29 switch (*p){
30 case ' ': case '\t':
31 if (!in_quotes) {
32 if (buffer->len != 0){
33 g_ptr_array_add (array, g_strdup (buffer->str));
34 g_string_truncate (buffer, 0);
36 } else {
37 g_string_append_c (buffer, *p);
39 break;
40 case '\\':
41 if (p [1]){
42 g_string_append_c (buffer, p [1]);
43 p++;
45 break;
46 case '\'':
47 case '"':
48 if (in_quotes) {
49 if (quote_char == *p)
50 in_quotes = FALSE;
51 else
52 g_string_append_c (buffer, *p);
53 } else {
54 in_quotes = TRUE;
55 quote_char = *p;
57 break;
58 default:
59 g_string_append_c (buffer, *p);
60 break;
63 if (in_quotes) {
64 fprintf (stderr, "Unmatched quotes in value of MONO_ENV_OPTIONS: [%s]\n", env_options);
65 exit (1);
68 if (buffer->len != 0)
69 g_ptr_array_add (array, g_strdup (buffer->str));
70 g_string_free (buffer, TRUE);
72 if (array->len > 0){
73 int new_argc = array->len + argc;
74 char **new_argv = g_new (char *, new_argc + 1);
75 int j;
77 new_argv [0] = argv [0];
79 /* First the environment variable settings, to allow the command line options to override */
80 for (i = 0; i < array->len; i++)
81 new_argv [i+1] = g_ptr_array_index (array, i);
82 i++;
83 for (j = 1; j < argc; j++)
84 new_argv [i++] = argv [j];
85 new_argv [i] = NULL;
87 argc = new_argc;
88 argv = new_argv;
90 g_ptr_array_free (array, TRUE);
93 return mono_main (argc, argv);
96 #ifdef HOST_WIN32
98 int
99 main ()
101 int argc;
102 gunichar2** argvw;
103 gchar** argv;
104 int i;
106 argvw = CommandLineToArgvW (GetCommandLine (), &argc);
107 argv = g_new0 (gchar*, argc + 1);
108 for (i = 0; i < argc; i++)
109 argv [i] = g_utf16_to_utf8 (argvw [i], -1, NULL, NULL, NULL);
110 argv [argc] = NULL;
112 LocalFree (argvw);
114 return mono_main_with_options (argc, argv);
117 #else
120 main (int argc, char* argv[])
122 mono_build_date = build_date;
124 return mono_main_with_options (argc, argv);
127 #endif