aboutsummaryrefslogtreecommitdiff
path: root/lib/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/config.c')
-rw-r--r--lib/config.c115
1 files changed, 0 insertions, 115 deletions
diff --git a/lib/config.c b/lib/config.c
deleted file mode 100644
index 8fcb926..0000000
--- a/lib/config.c
+++ /dev/null
@@ -1,115 +0,0 @@
1/* This file is part of Pies.
2 Copyright (C) 2007, 2008, 2009 Sergey Poznyakoff
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17#ifdef HAVE_CONFIG_H
18# include <config.h>
19#endif
20
21#include <libpies.h>
22
23
24char **
25config_array_to_argv (mu_config_value_t *val, mu_debug_t debug)
26{
27 int i, j;
28 int argc;
29 char **argv;
30
31 argc = val->v.arg.c;
32 argv = xcalloc (argc + 1, sizeof (argv[0]));
33 for (i = j = 0; i < argc; i++)
34 {
35 if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING,
36 debug) == 0)
37 argv[j++] = xstrdup (val->v.arg.v[i].v.string);
38 }
39 argv[j] = NULL;
40 return argv;
41}
42
43char *
44config_array_to_string (mu_config_value_t *val, mu_debug_t debug)
45{
46 size_t len = 0;
47 int i;
48 char *str, *p;
49
50 for (i = 0; i < val->v.arg.c; i++)
51 {
52 if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING, debug))
53 return NULL;
54 len += strlen (val->v.arg.v[i].v.string) + 1;
55 }
56
57 str = xmalloc (len);
58 p = str;
59 for (i = 0; i < val->v.arg.c; i++)
60 {
61 size_t n = strlen (val->v.arg.v[i].v.string);
62 memcpy (p, val->v.arg.v[i].v.string, n);
63 p += n;
64 *p++ = ' ';
65 }
66 str[len-1] = 0;
67 return str;
68}
69
70
71int
72config_cb_timeout (struct timeval *pt, mu_debug_t debug,
73 mu_config_value_t *val)
74{
75 int rc;
76 const char *endp;
77 time_t t;
78 const char *str;
79 char *alloc_str = NULL;
80
81 switch (val->type)
82 {
83 case MU_CFG_STRING:
84 str = val->v.string;
85 break;
86
87 case MU_CFG_ARRAY:
88 str = alloc_str = config_array_to_string (val, debug);
89 if (!str)
90 return 1;
91 break;
92
93 case MU_CFG_LIST:
94 mu_cfg_format_error (debug, MU_DEBUG_ERROR,
95 _("unexpected list"));
96 return 1;
97 }
98
99 rc = parse_time_interval (str, &t, &endp);
100 if (rc)
101 mu_cfg_format_error (debug, MU_DEBUG_ERROR,
102 _("unrecognized time format (near `%s')"),
103 endp);
104 else
105 {
106 pt->tv_usec = 0;
107 pt->tv_sec = t;
108 }
109 free (alloc_str);
110 return 0;
111}
112
113
114
115

Return to:

Send suggestions and report system problems to the System administrator.