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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include <k/core.h> extern stat entry(kenv); unsigned long long _boot(unsigned int argc, /* argument count */ char** argv, /* arguments */ char** envp /* environment */ ) { 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 }; return entry(e); } |
> > > > > > > > > > > > > > > > > > > > > > > > > > > > | < < |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
#include <k/core.h> #include <k/type.h> 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, ep - envp, variables }; return entry(e); } |
Modified mod/kcore/core.h from [632e354c90] to [4bc4090351].
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
ksraw val;
char* platform;
} kvar;
typedef struct kenv {
kiochan std;
kiochan err;
sz argc; char** argv;
kvar* vars;
} kenv;
/* i'm really sorry okay */
typedef
#if (__STDC_VERSION__ >= 199901L)
_Bool bool;
#endif
|
| | |
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
ksraw val; char* platform; } kvar; typedef struct kenv { kiochan std; kiochan err; sz argc; char** args; sz varc; kvar* vars; } kenv; /* i'm really sorry okay */ typedef #if (__STDC_VERSION__ >= 199901L) _Bool bool; #endif |
Modified mod/kcore/testbin.exe.c from [175e42b805] to [ba38860055].
5
6
7
8
9
10
11
12
13
14
15
16
17
18
..
32
33
34
35
36
37
38
39
40
41
|
struct object {
u8 a;
s16 b;
bool c;
};
stat_long entry(kenv e) {
const char msg[] = "hello from libk\n";
ksraw ptr = { Kmsz(msg), msg };
bool maybe = true;
maybe = no;
................................................................................
void* top = kmlini();
kmres rst = kmlina(1230);
if(rst.cond != kmcond_ok) return kbad_mem;
kmres rst2 = kmlina(789);
if(rst2.cond != kmcond_ok) return kbad_mem;
return kbad_ok;
}
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
..
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
struct object { 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; maybe = no; ................................................................................ void* top = kmlini(); 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; } |