AboutSummaryRefsLogTreeCommitDiffStats
diff options
context:
space:
mode:
authorMathieu Lirzin <mthl@gnu.org>2017-04-26 21:54:13 +0200
committerMathieu Lirzin <mthl@gnu.org>2017-09-28 18:13:08 +0200
commitdd30cb9e547f90d0bffc8eb758c58bba0e2c08ad (patch)
treeaefb3e175184bd698e54c67ec16d0d44cde4c296
parentd01195784352b29fe13d0676a2f50d60371d007f (diff)
downloadmcron-dd30cb9e547f90d0bffc8eb758c58bba0e2c08ad.tar.gz
mcron-dd30cb9e547f90d0bffc8eb758c58bba0e2c08ad.tar.bz2
mcron-dd30cb9e547f90d0bffc8eb758c58bba0e2c08ad.zip
utils: Add 'assq_symbol_set_x' function
* src/utils.c (assq_symbol_set_x): New function. * src/mcron.c (parse_opt): Use it.
-rw-r--r--src/cron.c1
-rw-r--r--src/crontab.c1
-rw-r--r--src/mcron.c17
-rw-r--r--src/utils.c9
-rw-r--r--src/utils.h6
5 files changed, 18 insertions, 16 deletions
diff --git a/src/cron.c b/src/cron.c
index 55bcaaf..369f1d1 100644
--- a/src/cron.c
+++ b/src/cron.c
@@ -18,7 +18,6 @@
along with GNU Mcron. If not, see <http://www.gnu.org/licenses/>. */
#include "utils.h"
-#include <libguile.h>
#include <signal.h>
/* Forward declarations. */
diff --git a/src/crontab.c b/src/crontab.c
index a432f1d..16c0be6 100644
--- a/src/crontab.c
+++ b/src/crontab.c
@@ -18,7 +18,6 @@
along with GNU Mcron. If not, see <http://www.gnu.org/licenses/>. */
#include "utils.h"
-#include <libguile.h>
/* Forward declarations. */
static void inner_main (void *closure, int argc, char *argv[]);
diff --git a/src/mcron.c b/src/mcron.c
index 5c63c4b..22cc680 100644
--- a/src/mcron.c
+++ b/src/mcron.c
@@ -19,7 +19,6 @@
#include "utils.h"
#include <argp.h>
-#include <libguile.h>
/* Forward declarations. */
static void inner_main (void *closure, int argc, char *argv[]);
@@ -92,21 +91,18 @@ parse_opt (int key, char *arg, struct argp_state *state)
switch (key)
{
case 's':
- *config = scm_assq_set_x (*config, scm_from_utf8_symbol ("schedule"),
- scm_from_int (atoi (arg)));
+ assq_symbol_set_x (config, "schedule",
+ scm_from_int (atoi (arg)));
break;
case 'd':
- *config = scm_assq_set_x (*config, scm_from_utf8_symbol ("daemon"),
- SCM_BOOL_T);
+ assq_symbol_set_x (config, "daemon", SCM_BOOL_T);
break;
case 'i':
if (strncmp (arg, "vixie", 6) == 0)
- *config = scm_assq_set_x (*config, scm_from_utf8_symbol ("vixie"),
- SCM_BOOL_T);
+ assq_symbol_set_x (config, "vixie", SCM_BOOL_T);
break;
case ARGP_KEY_NO_ARGS:
- *config = scm_assq_set_x (*config, scm_from_utf8_symbol ("files"),
- SCM_EOL);
+ assq_symbol_set_x (config, "files", SCM_EOL);
break;
case ARGP_KEY_ARGS:
{
@@ -117,8 +113,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
for (int i = filec - 1; i >= 0; i--)
lst = scm_cons (scm_from_locale_string (filev[i]), lst);
- *config = scm_assq_set_x (*config, scm_from_utf8_symbol ("files"),
- lst);
+ assq_symbol_set_x (config, "files", lst);
break;
}
case ARGP_KEY_ARG:
diff --git a/src/utils.c b/src/utils.c
index b011e77..3ea05f3 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -18,9 +18,6 @@
#include "utils.h"
#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
void
wrap_env_path (const char *envar, const char *dir)
@@ -42,3 +39,9 @@ wrap_env_path (const char *envar, const char *dir)
free (new_path);
}
}
+
+void
+assq_symbol_set_x (SCM *alst, const char *symbol, SCM val)
+{
+ *alst = scm_assq_set_x (*alst, scm_from_utf8_symbol (symbol), val);
+}
diff --git a/src/utils.h b/src/utils.h
index 5a71afd..910483f 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -19,9 +19,15 @@
#ifndef MCRON_UTILS_H
#define MCRON_UTILS_H
+#include <libguile.h>
+
/**
Append DIR in front of ENVAR environment variable value. If ENVAR is not
defined, then define it with DIR. Bail out if something went wrong. */
extern void wrap_env_path (const char *envar, const char *dir);
+/**
+ In the association list pointed by ALST, set SYMBOL to VAL. */
+extern void assq_symbol_set_x (SCM *alst, const char *symbol, SCM val);
+
#endif /* MCRON_UTILS_H */