utils: Add 'assq_symbol_set_x' function

* src/utils.c (assq_symbol_set_x): New function.
* src/mcron.c (parse_opt): Use it.
This commit is contained in:
Mathieu Lirzin 2017-04-26 21:54:13 +02:00
commit dd30cb9e54
No known key found for this signature in database
GPG key ID: 0ADEE10094604D37
5 changed files with 18 additions and 16 deletions

View file

@ -18,7 +18,6 @@
along with GNU Mcron. If not, see <http://www.gnu.org/licenses/>. */ along with GNU Mcron. If not, see <http://www.gnu.org/licenses/>. */
#include "utils.h" #include "utils.h"
#include <libguile.h>
#include <signal.h> #include <signal.h>
/* Forward declarations. */ /* Forward declarations. */

View file

@ -18,7 +18,6 @@
along with GNU Mcron. If not, see <http://www.gnu.org/licenses/>. */ along with GNU Mcron. If not, see <http://www.gnu.org/licenses/>. */
#include "utils.h" #include "utils.h"
#include <libguile.h>
/* Forward declarations. */ /* Forward declarations. */
static void inner_main (void *closure, int argc, char *argv[]); static void inner_main (void *closure, int argc, char *argv[]);

View file

@ -19,7 +19,6 @@
#include "utils.h" #include "utils.h"
#include <argp.h> #include <argp.h>
#include <libguile.h>
/* Forward declarations. */ /* Forward declarations. */
static void inner_main (void *closure, int argc, char *argv[]); 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) switch (key)
{ {
case 's': case 's':
*config = scm_assq_set_x (*config, scm_from_utf8_symbol ("schedule"), assq_symbol_set_x (config, "schedule",
scm_from_int (atoi (arg))); scm_from_int (atoi (arg)));
break; break;
case 'd': case 'd':
*config = scm_assq_set_x (*config, scm_from_utf8_symbol ("daemon"), assq_symbol_set_x (config, "daemon", SCM_BOOL_T);
SCM_BOOL_T);
break; break;
case 'i': case 'i':
if (strncmp (arg, "vixie", 6) == 0) if (strncmp (arg, "vixie", 6) == 0)
*config = scm_assq_set_x (*config, scm_from_utf8_symbol ("vixie"), assq_symbol_set_x (config, "vixie", SCM_BOOL_T);
SCM_BOOL_T);
break; break;
case ARGP_KEY_NO_ARGS: case ARGP_KEY_NO_ARGS:
*config = scm_assq_set_x (*config, scm_from_utf8_symbol ("files"), assq_symbol_set_x (config, "files", SCM_EOL);
SCM_EOL);
break; break;
case ARGP_KEY_ARGS: 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--) for (int i = filec - 1; i >= 0; i--)
lst = scm_cons (scm_from_locale_string (filev[i]), lst); lst = scm_cons (scm_from_locale_string (filev[i]), lst);
*config = scm_assq_set_x (*config, scm_from_utf8_symbol ("files"), assq_symbol_set_x (config, "files", lst);
lst);
break; break;
} }
case ARGP_KEY_ARG: case ARGP_KEY_ARG:

View file

@ -18,9 +18,6 @@
#include "utils.h" #include "utils.h"
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void void
wrap_env_path (const char *envar, const char *dir) 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); 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);
}

View file

@ -19,9 +19,15 @@
#ifndef MCRON_UTILS_H #ifndef MCRON_UTILS_H
#define MCRON_UTILS_H #define MCRON_UTILS_H
#include <libguile.h>
/** /**
Append DIR in front of ENVAR environment variable value. If ENVAR is not 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. */ defined, then define it with DIR. Bail out if something went wrong. */
extern void wrap_env_path (const char *envar, const char *dir); 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 */ #endif /* MCRON_UTILS_H */