Index: mod/kcore/boot.rt.c ================================================================== --- mod/kcore/boot.rt.c +++ mod/kcore/boot.rt.c @@ -1,17 +1,43 @@ #include +#include extern stat entry(kenv); unsigned long long _boot(unsigned int argc, /* argument count */ char** argv, /* arguments */ char** envp /* environment */ ) { + + envp ++; /* envp seems to point at a leading null; + this is probably a sign of breakage but + i don't know what else to do about it for + the moment. */ + + char** ep; + /* advance ep until it points at the last element */ + for (ep = envp; *ep != 0; ++ep); + + /* allocate space for each environment variable */ + kvar variables [ep - envp]; + + for (char** v = envp; *v != 0; ++v) { + kvar* var = variables + (v - envp); + var -> name.ptr = *v; + char* i = *v; + for(;*i != '=';++i); + var -> name.size = i - *v; + var -> val.ptr = i + 1; + for(;*i != 0;++i); + + /* there is probably a better way to do this; my + * brain is too foggy to figure one out tho */ + var -> val.size = (i - *v) - var -> name.size; + } + kenv e = { /* TODO: determine terminal class and set term vs ansi correctly! */ { {kiostream_term, 0}, {kiostream_term, 1} }, // chan std { {kiostream_closed}, {kiostream_term, 2} }, // chan err - argc, argv, - null // needs parsing + argc, argv, ep - envp, variables }; return entry(e); } - Index: mod/kcore/core.h ================================================================== --- mod/kcore/core.h +++ mod/kcore/core.h @@ -15,12 +15,12 @@ } kvar; typedef struct kenv { kiochan std; kiochan err; - sz argc; char** argv; - kvar* vars; + sz argc; char** args; + sz varc; kvar* vars; } kenv; /* i'm really sorry okay */ typedef #if (__STDC_VERSION__ >= 199901L) Index: mod/kcore/testbin.exe.c ================================================================== --- mod/kcore/testbin.exe.c +++ mod/kcore/testbin.exe.c @@ -7,10 +7,12 @@ u8 a; s16 b; bool c; }; +#define _slit(s) ((ksraw){Kmsz(s),s}) + stat_long entry(kenv e) { const char msg[] = "hello from libk\n"; ksraw ptr = { Kmsz(msg), msg }; bool maybe = true; @@ -34,8 +36,20 @@ kmres rst = kmlina(1230); if(rst.cond != kmcond_ok) return kbad_mem; kmres rst2 = kmlina(789); if(rst2.cond != kmcond_ok) return kbad_mem; + + const char varmsg[] = "printing environment variables\n"; + ksraw msgptr = { Kmsz(varmsg), varmsg }; + kiosend(e.std, msgptr, null); + + for (sz i = 0; i < e.varc; ++i) { + kiosend(e.std, _slit(" - "), null); + kiosend(e.std, e.vars[i].name, null); + kiosend(e.std, _slit(" = ["), null); + kiosend(e.std, e.vars[i].val, null); + kiosend(e.std, _slit("]\n"), null); + } return kbad_ok; }