Imported File#ftype spec from rubyspecs.
[rbx.git] / shotgun / main.c
blob5fd16ed187cfac91636709b3f347cfec6b3c50c9
1 #include <string.h>
2 #include <setjmp.h>
3 #include <sys/stat.h>
5 #include "shotgun/config.h"
6 #include "shotgun/lib/shotgun.h"
7 #include "shotgun/lib/machine.h"
8 #include "shotgun/lib/subtend/ruby.h"
9 #include "shotgun/lib/environment.h"
11 /* TODO incorporate system paths calculated at compile time. */
12 static const char *search_path[] = {
13 #ifdef CONFIG_RBAPATH
14 CONFIG_RBAPATH,
15 #endif
16 NULL
19 static char *search_for(const char *evs, const char *file) {
20 char *env;
21 static char path[PATH_MAX];
22 struct stat _st;
23 int i;
25 #define file_exists_p(file) stat(file, &_st) == 0
27 env = getenv(evs);
28 if(env) {
29 if(file_exists_p(env)) return env;
30 return NULL;
33 for(i = 0; search_path[i]; i++) {
34 snprintf(path, PATH_MAX, "%s/%s", search_path[i], file);
35 if(file_exists_p(path)) {
36 return strdup(path);
40 return NULL;
43 int main(int argc, char **argv) {
44 environment e;
45 machine m;
46 char *archive;
48 environment_at_startup();
50 e = environment_new();
51 m = machine_new(e);
52 environment_setup_thread(e, m);
54 machine_setup_normal(m, argc, argv);
56 /* We build up the environment information by looking around
57 * the filesystem now. */
59 /* Find the platform config */
60 e->platform_config = search_for("RBX_PLATFORM_CONF", "platform.conf");
62 /* Find the bootstrap. */
63 archive = search_for("RBX_BOOTSTRAP", "bootstrap");
64 if(!archive) {
65 printf("Unable to find a bootstrap to load!\n");
66 return 1;
68 e->bootstrap_path = archive;
70 /* Find the platform. */
71 archive = search_for("RBX_PLATFORM", "platform");
72 if(!archive) {
73 printf("Unable to find a platform to load!\n");
74 return 1;
77 e->platform_path = archive;
79 /* Find the core. */
80 archive = search_for("RBX_CORE", "core");
81 if(!archive) {
82 printf("Unable to find a core to load!\n");
83 return 1;
86 e->core_path = archive;
88 /* Load the loader.rbc */
89 archive = search_for("RBX_LOADER", "loader.rbc");
90 if(!archive) {
91 printf("Unable to find loader.rbc to load!\n");
92 return 1;
95 e->loader_path = archive;
97 environment_load_machine(e, m);
99 /* Done! */
100 if(m->s->gc_stats) {
101 printf("[GC M %6dK total]\n", m->s->om->ms->allocated_bytes);
104 return 0;