Commit a05f5dd9 authored by Damien George's avatar Damien George
Browse files

Merge branch 'master' of github.com:micropython/micropython

parents e90eefc8 ad1bac63
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <string.h> #include <string.h>
#include "mpconfig.h" #include "mpconfig.h"
#include "misc.h"
#include "gc.h" #include "gc.h"
#if MICROPY_ENABLE_GC #if MICROPY_ENABLE_GC
......
...@@ -58,6 +58,9 @@ test("{:10.4f}", 123.456) ...@@ -58,6 +58,9 @@ test("{:10.4f}", 123.456)
test("{:10.4f}", -123.456) test("{:10.4f}", -123.456)
test("{:10.4g}", 123.456) test("{:10.4g}", 123.456)
test("{:10.4g}", -123.456) test("{:10.4g}", -123.456)
test("{:e}", 100)
test("{:f}", 200)
test("{:g}", 300)
test("{:10.4E}", 123.456) test("{:10.4E}", 123.456)
test("{:10.4E}", -123.456) test("{:10.4E}", -123.456)
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <errno.h>
#include "nlr.h" #include "nlr.h"
#include "misc.h" #include "misc.h"
...@@ -212,13 +213,24 @@ mp_obj_t test_obj_new(int value) { ...@@ -212,13 +213,24 @@ mp_obj_t test_obj_new(int value) {
return o; return o;
} }
int usage(void) { int usage(char **argv) {
printf( printf(
"usage: py [-X <opt>] [-c <command>] [<filename>]\n" "usage: %s [-X <opt>] [-c <command>] [<filename>]\n"
"\n" "\n"
"Implementation specific options:\n" "Implementation specific options:\n", argv[0]
);
int impl_opts_cnt = 0;
#if MICROPY_ENABLE_GC
printf(
" heapsize=<n> -- set the heap size for the GC\n" " heapsize=<n> -- set the heap size for the GC\n"
); );
impl_opts_cnt++;
#endif
if (impl_opts_cnt == 0) {
printf(" (none)\n");
}
return 1; return 1;
} }
...@@ -249,7 +261,7 @@ void pre_process_options(int argc, char **argv) { ...@@ -249,7 +261,7 @@ void pre_process_options(int argc, char **argv) {
if (argv[a][0] == '-') { if (argv[a][0] == '-') {
if (strcmp(argv[a], "-X") == 0) { if (strcmp(argv[a], "-X") == 0) {
if (a + 1 >= argc) { if (a + 1 >= argc) {
exit(usage()); exit(usage(argv));
} }
if (0) { if (0) {
#if MICROPY_ENABLE_GC #if MICROPY_ENABLE_GC
...@@ -257,7 +269,7 @@ void pre_process_options(int argc, char **argv) { ...@@ -257,7 +269,7 @@ void pre_process_options(int argc, char **argv) {
heap_size = strtol(argv[a + 1] + sizeof("heapsize=") - 1, NULL, 0); heap_size = strtol(argv[a + 1] + sizeof("heapsize=") - 1, NULL, 0);
#endif #endif
} else { } else {
exit(usage()); exit(usage(argv));
} }
a++; a++;
} }
...@@ -358,7 +370,7 @@ int main(int argc, char **argv) { ...@@ -358,7 +370,7 @@ int main(int argc, char **argv) {
if (argv[a][0] == '-') { if (argv[a][0] == '-') {
if (strcmp(argv[a], "-c") == 0) { if (strcmp(argv[a], "-c") == 0) {
if (a + 1 >= argc) { if (a + 1 >= argc) {
return usage(); return usage(argv);
} }
do_str(argv[a + 1]); do_str(argv[a + 1]);
executed = true; executed = true;
...@@ -366,16 +378,22 @@ int main(int argc, char **argv) { ...@@ -366,16 +378,22 @@ int main(int argc, char **argv) {
} else if (strcmp(argv[a], "-X") == 0) { } else if (strcmp(argv[a], "-X") == 0) {
a += 1; a += 1;
} else { } else {
return usage(); return usage(argv);
} }
} else { } else {
// Set base dir of the script as first entry in sys.path
char *basedir = realpath(argv[a], NULL); char *basedir = realpath(argv[a], NULL);
if (basedir != NULL) { if (basedir == NULL) {
char *p = strrchr(basedir, '/'); fprintf(stderr, "%s: can't open file '%s': [Errno %d] ", argv[0], argv[1], errno);
path_items[0] = MP_OBJ_NEW_QSTR(qstr_from_strn(basedir, p - basedir)); perror("");
free(basedir); // CPython exits with 2 in such case
exit(2);
} }
// Set base dir of the script as first entry in sys.path
char *p = strrchr(basedir, '/');
path_items[0] = MP_OBJ_NEW_QSTR(qstr_from_strn(basedir, p - basedir));
free(basedir);
for (int i = a; i < argc; i++) { for (int i = a; i < argc; i++) {
mp_obj_list_append(py_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i]))); mp_obj_list_append(py_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i])));
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment