From 396931b65b0e689c32c087fa63e176b558d64b8a Mon Sep 17 00:00:00 2001 From: onefang Date: Fri, 30 Jul 2021 14:01:59 +1000 Subject: Start of getting the details from sims.lua when we get the other sims stuff. --- src/sledjchisl/sledjchisl.c | 88 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index 9834834..5c79138 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -1020,10 +1020,11 @@ struct _simList { int len, num; char **sims; - qtreetbl_t *byTab; + qtreetbl_t *byTab, *simsLua; }; simList *ourSims = NULL; + static int getIntFromIni(qlisttbl_t *ini, char *name) { int ret; @@ -1088,6 +1089,44 @@ static int filterInis(struct dirtree *node) return 0; } +// Get the details from all the .ini or .shini sim files. +// Creates the .shini and sims.lua files if it's an old install. +// TODO - read the .shini and sims.lua if they exist. +/* +ourSims shall be - + int len, num; + char **sims; + qtreetbl_t *byTab, *simsLua; + +byTab has the short name as the key, simData as the value. + Iterate through it looking for target sims if specified in the sledjchisl arguments. + Which can be short name, long name, foo.shini file name. + Though short name is a direct lookup, and "foo.shini" we can strip off the .shini and direct lookup the short name. + So only need to iterate if it's a long name. + Keep in mind the argument might be a user name for IAR backups. Or perhaps a UUID. + +**sims will be in sims.lua order, and maybe include a pointer to the simData. + We really only need to iterate through this at full start up and reverse iterate through it at full shutdown. + So just the tab names in the correct order is fine. + + +if sims.lua doesn't exist + create blank one +else + read it +loop through old config/sim* + if it's not a *.shini file + read *.ini + create *.shini + write *.shini + else + read the *.shini file + add *.shini to ourSims + if it's not in sims.lua, add it to unsorted +write sims.lua if it changed +reorder **sims + +*/ simList *getSims() { if (NULL != ourSims) return ourSims; @@ -1114,6 +1153,53 @@ simList *getSims() int fd = -1; size_t l = strlen(tnm); + ourSims->simsLua = Lua2tree(file, "sims"); + +fprintf(stderr, "DEBUG simsLua table\n"); + qtreetbl_obj_t obj0; + + memset((void*)&obj0, 0, sizeof(obj0)); // must be cleared before call + ourSims->simsLua->lock(ourSims->simsLua); // lock it when thread condition is expected + while(ourSims->simsLua->getnext(ourSims->simsLua, &obj0, false) == true) + { + fprintf(stderr, "%s\n", obj0.name); + qLua *q0 = obj0.data; + + switch (q0->type) + { + case LUA_TBOOLEAN : {fprintf(stderr, " %s = %d\n", obj0.name, q0->v.b); break;} + case LUA_TINTEGER : {fprintf(stderr, " %s = %d\n", obj0.name, q0->v.i); break;} + case LUA_TNUMBER : {fprintf(stderr, " %s = %f\n", obj0.name, q0->v.f); break;} + case LUA_TSTRING : {fprintf(stderr, " %s = %s\n", obj0.name, q0->v.s); break;} + case LUA_TTABLE : {fprintf(stderr, " %s TABLE\n", obj0.name); break;} + default : {fprintf(stderr, " %s ? %s\n", obj0.name, q0->v.s); break;} + } + if (LUA_TTABLE == q0->type) + { + qtreetbl_t *t = q0->v.t; + qtreetbl_obj_t obj1; + + memset((void*)&obj1, 0, sizeof(obj1)); // must be cleared before call + t->lock(t); // lock it when thread condition is expected + while(t->getnext(t, &obj1, false) == true) + { + qLua *q1 = obj1.data; + switch (q1->type) + { + case LUA_TBOOLEAN : {fprintf(stderr, " %s = %d\n", obj1.name, q1->v.b); break;} + case LUA_TINTEGER : {fprintf(stderr, " %s = %d\n", obj1.name, q1->v.i); break;} + case LUA_TNUMBER : {fprintf(stderr, " %s = %f\n", obj1.name, q1->v.f); break;} + case LUA_TSTRING : {fprintf(stderr, " %s = %s\n", obj1.name, q1->v.s); break;} + case LUA_TTABLE : {fprintf(stderr, " %s TABLE\n", obj1.name); break;} + default : {fprintf(stderr, " %s ? %s\n", obj1.name, q1->v.s); break;} + } + } + t->unlock(t); + } + } + ourSims->simsLua->unlock(ourSims->simsLua); + + if (s) { I("Creating sims %s.", file); -- cgit v1.1