Skip to content

Commit 117438b

Browse files
author
cd rubin
committed
.init.mjs handling added
1 parent 6e2e68f commit 117438b

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,15 @@ unicode
2222
unicode_gen
2323
run_octane
2424
run_sunspider_like
25+
examples/hello.aarch64.elf
26+
examples/hello.com.dbg
27+
examples/hello_module.aarch64.elf
28+
examples/hello_module.com.dbg
29+
examples/test_fib.aarch64.elf
30+
examples/test_fib.com.dbg
31+
qjs.aarch64.elf
32+
qjs.com.dbg
33+
qjsc.aarch64.elf
34+
qjsc.com.dbg
35+
run-test262.aarch64.elf
36+
run-test262.com.dbg

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ endif
3737
# force 32 bit build for some utilities
3838
#CONFIG_M32=y
3939
# cosmopolitan build (see https://github.com/jart/cosmopolitan)
40-
#CONFIG_COSMO=y
40+
CONFIG_COSMO=y
4141

4242
# installation directory
4343
PREFIX?=/usr/local

qjs.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,15 @@ int main(int argc, char **argv)
330330
}
331331
#endif
332332

333+
const char init_filename[] = "/zip/.init.mjs";
334+
const int init_file = access( init_filename, F_OK ) == 0;
335+
if ( init_file ) {
336+
//fprintf(stderr, "/zip/.init.mjs FOUND\n");
337+
//module = 1;
338+
//interactive = 0;
339+
load_std = 1;
340+
}
341+
333342
/* cannot use getopt because we want to pass the command line to
334343
the script */
335344
optind = 1;
@@ -507,12 +516,18 @@ int main(int argc, char **argv)
507516
if (eval_buf(ctx, expr, strlen(expr), "<cmdline>", 0))
508517
goto fail;
509518
} else
510-
if (optind >= argc) {
519+
if (optind >= argc && !init_file) {
511520
/* interactive mode */
512521
interactive = 1;
513522
} else {
514523
const char *filename;
515-
filename = argv[optind];
524+
if ( !init_file ) {
525+
filename = argv[optind];
526+
}
527+
else {
528+
filename = init_filename;
529+
}
530+
516531
if (eval_file(ctx, filename, module))
517532
goto fail;
518533
}

0 commit comments

Comments
 (0)