From 2599cbf7ba299ee37533f18ffca5cb066e6568eb Mon Sep 17 00:00:00 2001 From: Tom Balzer Date: Tue, 26 Jun 2018 08:20:54 -0500 Subject: [PATCH] Refactored to create a jobs structure array. --- src/common/guile_helpers.c | 47 +++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/src/common/guile_helpers.c b/src/common/guile_helpers.c index 9a37795..c40faaf 100644 --- a/src/common/guile_helpers.c +++ b/src/common/guile_helpers.c @@ -18,18 +18,24 @@ #include #include +#include "../../include/job.h" #include "../../include/macros.h" #include "../../include/scm_interface.h" #define MANIFEST_LOC "/.config/tomd/init/manifest.scm" -static void load_job(SCM job_list, int index) -{ +#define MAX_JOBS 10 + +static struct job jobs[MAX_JOBS]; + +static struct job load_job(SCM job_list, int index) +{ + struct job ret = { NULL }; SCM scm_cur_job = SCM_ARR(job_list, index); if(scm_is_false(job_predicate(scm_cur_job))){ tomd_p("job %d wasn't a real job type.", index); - return; + return ret; } SCM scm_cmd = get_cmd(scm_cur_job); @@ -53,13 +59,16 @@ static void load_job(SCM job_list, int index) scm_to_locale_string(SCM_ARR(scm_args, j)); } - tomd_p("JOB <%d>:", index); - tomd_p(" cmd:'%s'", job_cmd); + ret.cmd = job_cmd; + for(int j = 0; j < jlen; j++){ - tomd_p(" arg [%d]:'%s'", j, real_args[j]); + ret.args[j] = real_args[j]; } + ret.args[jlen] = NULL; + + return ret; } static void *load_manifest(void *args) @@ -88,12 +97,14 @@ static void *load_manifest(void *args) int i; int len = SCM_LIST_LEN(scm_job_list); + tomd_p("len=%d, max=%d", len, MAX_JOBS); for(i = 0; - i < len; + i < len && i < MAX_JOBS; i++){ - load_job(scm_job_list, i); + jobs[i] = load_job(scm_job_list, i); } tomd_p("looked at %d jobs.", i); + jobs[i].cmd = NULL; } static char *lookup_user_folder(void) @@ -121,4 +132,24 @@ void load_jobs(void) (void *) manifest); tomd_p("Finished loading."); + + int i = 0; + while(1){ + if(i >= MAX_JOBS || + jobs[i].cmd == NULL) { + break; + } + tomd_p("JOB <%d>:", i); + tomd_p(" cmd:'%s'", jobs[i].cmd); + int j = 0; + while(1){ + if(i >= 10 || + jobs[i].args[j] == NULL){ + break; + } + tomd_p(" arg [%d]:'%s'", j, jobs[i].args[j]); + j++; + } + i++; + } } -- 2.20.1