Dumb refactoring of manifest loading.
[tlb/tomd.git] / src / common / guile_helpers.c
index 0f2b4d1..e2bd14f 100644 (file)
 #include <pwd.h>
 
 #include "../../include/macros.h"
+#include "../../include/scm_interface.h"
 
 #define MANIFEST_LOC "/.config/tomd/init/manifest.scm"
 
-static void load_job(void)
+static void load_job(SCM job_list, int index)
 {
-  
+  SCM scm_i =
+    scm_from_signed_integer(index);
+  SCM scm_cur_job =
+    SCM_ARR(job_list, index);
+
+  /* scm_cur_job should be a job */    
+  if(scm_is_false(job_predicate(scm_cur_job))){
+    tomd_p("job %d wasn't a real job type.", index);
+    return;
+  }
+
+  SCM scm_cmd =
+    get_cmd(scm_cur_job);
+  SCM scm_args =
+    get_args(scm_cur_job);
+  SCM scm_start_trigger =
+    get_start_trigger(scm_cur_job);
+  SCM scm_end_trigger =
+    get_end_trigger(scm_cur_job);
+
+  char *job_cmd =
+    scm_to_locale_string(scm_cmd);
+
+  char *real_args[10];
+  int jlen = scm_to_int(scm_length(scm_args));
+  for(int j = 0;
+      j < jlen;
+      j++){
+    real_args[j] =
+      scm_to_locale_string(SCM_ARR(scm_args, j));
+  }
+
+  tomd_p("JOB <%d>:", index);
+  tomd_p("     cmd:'%s'", job_cmd);
+  for(int j = 0;
+      j < jlen;
+      j++){
+    tomd_p(" arg [%d]:'%s'", j, real_args[j]);
+  }
 }
 
 static void *load_manifest(void *args)
@@ -54,75 +93,12 @@ static void *load_manifest(void *args)
     return NULL;
   }
 
-  SCM scm_job_predicate =
-    scm_c_public_ref("tomd job", "c-check-job");
-
-  SCM scm_job_cmd =
-    scm_c_public_ref("tomd job", "c-job-cmd");
-
-  SCM scm_job_args =
-    scm_c_public_ref("tomd job", "c-job-args");
-
-  SCM scm_job_start_trigger =
-    scm_c_public_ref("tomd job", "c-job-start-trigger");
-
-  SCM scm_job_end_trigger =
-    scm_c_public_ref("tomd job", "c-job-end-trigger");
-
-  
-  SCM scm_len = scm_length(scm_job_list);
-  int len = scm_to_int(scm_len);
   int i;
+  int len = SCM_LIST_LEN(scm_job_list);
   for(i = 0;
       i < len;
       i++){
-    SCM scm_i =
-      scm_from_signed_integer(i);
-    SCM scm_cur_job =
-      SCM_ARR(scm_job_list, i);
-
-    /* scm_cur_job should be a job */    
-    if(scm_is_false(scm_call(scm_job_predicate, scm_cur_job, SCM_UNDEFINED))){
-      tomd_p("job %d wasn't a real job type.", i);
-      continue;
-    }
-
-    SCM scm_cmd =
-      scm_call(scm_job_cmd,
-               scm_cur_job,
-               SCM_UNDEFINED);
-    SCM scm_args =
-      scm_call(scm_job_args,
-               scm_cur_job,
-               SCM_UNDEFINED);
-    SCM scm_start_trigger =
-      scm_call(scm_job_start_trigger,
-               scm_cur_job,
-               SCM_UNDEFINED);
-    SCM scm_end_trigger =
-      scm_call(scm_job_end_trigger,
-               scm_cur_job,
-               SCM_UNDEFINED);
-
-    char *job_cmd =
-      scm_to_locale_string(scm_cmd);
-
-    char *real_args[10];
-    int jlen = scm_to_int(scm_length(scm_args));
-    for(int j = 0;
-        j < jlen;
-        j++){
-      real_args[j] =
-        scm_to_locale_string(SCM_ARR(scm_args, j));
-    }
-
-    tomd_p("JOB <%d>:", i);
-    tomd_p("     cmd:'%s'", job_cmd);
-    for(int j = 0;
-        j < jlen;
-        j++){
-      tomd_p(" arg [%d]:'%s'", j, real_args[j]);
-    }
+    load_job(scm_job_list, i);
   }
   tomd_p("looked at %d jobs.", i);
 }