From 1e774d9e6af964148b1260d8af5ab70ec6066d78 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Tue, 24 Jun 2008 17:58:18 -0700 Subject: [PATCH] put center dot into main_main restore smashed arg code, lost in incorrect resolve SVN=124432 --- src/runtime/rt0_amd64_darwin.s | 2 +- src/runtime/runtime.c | 76 ++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/src/runtime/rt0_amd64_darwin.s b/src/runtime/rt0_amd64_darwin.s index e2794183bf..031cc059df 100644 --- a/src/runtime/rt0_amd64_darwin.s +++ b/src/runtime/rt0_amd64_darwin.s @@ -30,7 +30,7 @@ done: CALL args(SB) ADDQ $16, SP CALL check(SB) - CALL main_main(SB) + CALL main·main(SB) CALL sys·exit(SB) CALL notok(SB) POPQ AX diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c index c153163518..c0ad2cce89 100644 --- a/src/runtime/runtime.c +++ b/src/runtime/runtime.c @@ -750,6 +750,82 @@ sys·modf(float64 din, float64 dou1, float64 dou2) FLUSH(&dou2); } +static int32 argc; +static uint8** argv; +static int32 envc; +static uint8** envv; + + +void +args(int32 c, uint8 **v) +{ + argc = c; + argv = v; + envv = v + argc + 1; // skip 0 at end of argv + for (envc = 0; envv[envc] != 0; envc++) + ; +} + +//func argc() int32; // return number of arguments +void +sys_argc(int32 v) +{ + v = argc; + FLUSH(&v); +} + +//func envc() int32; // return number of environment variables +void +sys_envc(int32 v) +{ + v = envc; + FLUSH(&v); +} + +//func argv(i) string; // return argument i +void +sys_argv(int32 i, string s) +{ + uint8* str; + int32 l; + + if(i < 0 || i >= argc) { + s = emptystring; + goto out; + } + + str = argv[i]; + l = findnull((int8*)str); + s = mal(sizeof(s->len)+l); + s->len = l; + mcpy(s->str, str, l); + +out: + FLUSH(&s); +} + +//func envv(i) string; // return argument i +void +sys_envv(int32 i, string s) +{ + uint8* str; + int32 l; + + if(i < 0 || i >= envc) { + s = emptystring; + goto out; + } + + str = envv[i]; + l = findnull((int8*)str); + s = mal(sizeof(s->len)+l); + s->len = l; + mcpy(s->str, str, l); + +out: + FLUSH(&s); +} + check(void) { int8 a; -- 2.48.1