Overview
Comment: | parse environment and add env variables to the kenv struct passed to the entry function; add example code to testbin showing use of kvars |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
81758652b567f93efd964a87e939ba9b |
User & Date: | lexi on 2019-08-24 23:40:15 |
Other Links: | manifest | tags |
Context
2019-08-25
| ||
00:16 | arch: add crude script to generate errno tables from Linux sources check-in: b9dd92f73e user: lachs0r tags: trunk | |
2019-08-24
| ||
23:40 | parse environment and add env variables to the kenv struct passed to the entry function; add example code to testbin showing use of kvars check-in: 81758652b5 user: lexi tags: trunk | |
23:07 | update license statement check-in: c36308ecd9 user: lexi tags: trunk | |
Changes
Modified mod/kcore/boot.rt.c from [a5bf4923b7] to [7899b05286].
1 1 #include <k/core.h> 2 +#include <k/type.h> 2 3 extern stat entry(kenv); 3 4 4 5 unsigned long long 5 6 _boot(unsigned int argc, /* argument count */ 6 7 char** argv, /* arguments */ 7 8 char** envp /* environment */ ) { 9 + 10 + envp ++; /* envp seems to point at a leading null; 11 + this is probably a sign of breakage but 12 + i don't know what else to do about it for 13 + the moment. */ 14 + 15 + char** ep; 16 + /* advance ep until it points at the last element */ 17 + for (ep = envp; *ep != 0; ++ep); 18 + 19 + /* allocate space for each environment variable */ 20 + kvar variables [ep - envp]; 21 + 22 + for (char** v = envp; *v != 0; ++v) { 23 + kvar* var = variables + (v - envp); 24 + var -> name.ptr = *v; 25 + char* i = *v; 26 + for(;*i != '=';++i); 27 + var -> name.size = i - *v; 28 + var -> val.ptr = i + 1; 29 + for(;*i != 0;++i); 30 + 31 + /* there is probably a better way to do this; my 32 + * brain is too foggy to figure one out tho */ 33 + var -> val.size = (i - *v) - var -> name.size; 34 + } 35 + 8 36 kenv e = { 9 37 /* TODO: determine terminal class and set term vs ansi correctly! */ 10 38 { {kiostream_term, 0}, {kiostream_term, 1} }, // chan std 11 39 { {kiostream_closed}, {kiostream_term, 2} }, // chan err 12 - argc, argv, 13 - null // needs parsing 40 + argc, argv, ep - envp, variables 14 41 }; 15 42 return entry(e); 16 43 } 17 -
Modified mod/kcore/core.h from [632e354c90] to [4bc4090351].
13 13 ksraw val; 14 14 char* platform; 15 15 } kvar; 16 16 17 17 typedef struct kenv { 18 18 kiochan std; 19 19 kiochan err; 20 - sz argc; char** argv; 21 - kvar* vars; 20 + sz argc; char** args; 21 + sz varc; kvar* vars; 22 22 } kenv; 23 23 24 24 /* i'm really sorry okay */ 25 25 typedef 26 26 #if (__STDC_VERSION__ >= 199901L) 27 27 _Bool bool; 28 28 #endif
Modified mod/kcore/testbin.exe.c from [175e42b805] to [ba38860055].
5 5 6 6 struct object { 7 7 u8 a; 8 8 s16 b; 9 9 bool c; 10 10 }; 11 11 12 +#define _slit(s) ((ksraw){Kmsz(s),s}) 13 + 12 14 stat_long entry(kenv e) { 13 15 const char msg[] = "hello from libk\n"; 14 16 ksraw ptr = { Kmsz(msg), msg }; 15 17 16 18 bool maybe = true; 17 19 maybe = no; 18 20 ................................................................................ 32 34 33 35 void* top = kmlini(); 34 36 kmres rst = kmlina(1230); 35 37 if(rst.cond != kmcond_ok) return kbad_mem; 36 38 37 39 kmres rst2 = kmlina(789); 38 40 if(rst2.cond != kmcond_ok) return kbad_mem; 41 + 42 + const char varmsg[] = "printing environment variables\n"; 43 + ksraw msgptr = { Kmsz(varmsg), varmsg }; 44 + kiosend(e.std, msgptr, null); 45 + 46 + for (sz i = 0; i < e.varc; ++i) { 47 + kiosend(e.std, _slit(" - "), null); 48 + kiosend(e.std, e.vars[i].name, null); 49 + kiosend(e.std, _slit(" = ["), null); 50 + kiosend(e.std, e.vars[i].val, null); 51 + kiosend(e.std, _slit("]\n"), null); 52 + } 39 53 40 54 return kbad_ok; 41 55 }