Pinvoke symbols according to the new moonlight naming convention.
[mono-project.git] / mono / mini / main.c
blob03b7b919fc4cdb685d987f92f9e3ae17d88ccb0f
1 #include <config.h>
2 #include "mini.h"
3 #ifndef HOST_WIN32
4 #include "buildver.h"
5 #endif
7 /*
8 * If the MONO_ENV_OPTIONS environment variable is set, it uses this as a
9 * source of command line arguments that are passed to Mono before the
10 * command line arguments specified in the command line.
12 static int
13 mono_main_with_options (int argc, char *argv [])
15 const char *env_options = getenv ("MONO_ENV_OPTIONS");
16 if (env_options != NULL){
17 GPtrArray *array = g_ptr_array_new ();
18 GString *buffer = g_string_new ("");
19 const char *p;
20 int i;
22 for (p = env_options; *p; p++){
23 switch (*p){
24 case ' ': case '\t':
25 if (buffer->len != 0){
26 g_ptr_array_add (array, g_strdup (buffer->str));
27 g_string_truncate (buffer, 0);
29 break;
30 case '\\':
31 if (p [1]){
32 g_string_append_c (buffer, p [1]);
33 p++;
35 break;
36 default:
37 g_string_append_c (buffer, *p);
38 break;
41 if (buffer->len != 0)
42 g_ptr_array_add (array, g_strdup (buffer->str));
43 g_string_free (buffer, TRUE);
45 if (array->len > 0){
46 int new_argc = array->len + argc;
47 char **new_argv = g_new (char *, new_argc + 1);
48 int j;
50 new_argv [0] = argv [0];
52 /* First the environment variable settings, to allow the command line options to override */
53 for (i = 0; i < array->len; i++)
54 new_argv [i+1] = g_ptr_array_index (array, i);
55 i++;
56 for (j = 1; j < argc; j++)
57 new_argv [i++] = argv [j];
58 new_argv [i] = NULL;
60 argc = new_argc;
61 argv = new_argv;
63 g_ptr_array_free (array, TRUE);
66 return mono_main (argc, argv);
69 #ifdef HOST_WIN32
71 int
72 main ()
74 int argc;
75 gunichar2** argvw;
76 gchar** argv;
77 int i;
79 argvw = CommandLineToArgvW (GetCommandLine (), &argc);
80 argv = g_new0 (gchar*, argc + 1);
81 for (i = 0; i < argc; i++)
82 argv [i] = g_utf16_to_utf8 (argvw [i], -1, NULL, NULL, NULL);
83 argv [argc] = NULL;
85 LocalFree (argvw);
87 return mono_main_with_options (argc, argv);
90 #else
92 int
93 main (int argc, char* argv[])
95 mono_build_date = build_date;
97 return mono_main_with_options (argc, argv);
100 #endif