Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / tools / mkbundle / template_main.c
1 int mono_main (int argc, char* argv[]);
2
3 #include <stdlib.h>
4 #include <string.h>
5 #ifdef _WIN32
6 #include <windows.h>
7 #endif
8
9 static char **mono_options = NULL;
10
11 static int count_mono_options_args (void)
12 {
13         const char *e = getenv ("MONO_BUNDLED_OPTIONS");
14         const char *p, *q;
15         int i, n;
16
17         if (e == NULL)
18                 return 0;
19
20         /* Don't bother with any quoting here. It is unlikely one would
21          * want to pass options containing spaces anyway.
22          */
23
24         p = e;
25         n = 1;
26         while ((q = strchr (p, ' ')) != NULL) {
27                 n++;
28                 p = q + 1;
29         }
30
31         mono_options = malloc (sizeof (char *) * (n + 1));
32
33         p = e;
34         i = 0;
35         while ((q = strchr (p, ' ')) != NULL) {
36                 mono_options[i] = malloc ((q - p) + 1);
37                 memcpy (mono_options[i], p, q - p);
38                 mono_options[i][q - p] = '\0';
39                 i++;
40                 p = q + 1;
41         }
42         mono_options[i++] = strdup (p);
43         mono_options[i] = NULL;
44
45         return n;
46 }
47
48
49 int main (int argc, char* argv[])
50 {
51         char **newargs;
52         int i, k = 0;
53
54         newargs = (char **) malloc (sizeof (char *) * (argc + 2 + count_mono_options_args ()));
55
56         newargs [k++] = argv [0];
57
58         if (mono_options != NULL) {
59                 i = 0;
60                 while (mono_options[i] != NULL)
61                         newargs[k++] = mono_options[i++];
62         }
63
64         newargs [k++] = image_name;
65
66         for (i = 1; i < argc; i++) {
67                 newargs [k++] = argv [i];
68         }
69         newargs [k] = NULL;
70         
71         if (config_dir != NULL && getenv ("MONO_CFG_DIR") == NULL)
72                 mono_set_dirs (getenv ("MONO_PATH"), config_dir);
73         
74         mono_mkbundle_init();
75
76         return mono_main (k, newargs);
77 }