FIX: lutil_quvi_init: Pass handle value to quvi_errmsg
[quvi-tool.git] / src / opts / chk.c
blob2bc03f91e27ba1bfc137a2291cf64da081f06767
1 /* quvi
2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of quvi <http://quvi.sourceforge.net/>.
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>.
21 #include "config.h"
23 #include <stdlib.h>
24 #include <glib.h>
26 #include "lutil.h"
27 #include "lopts.h"
29 /* Validate string value to possible values. */
30 gint lopts_chk_str(const gchar *opt_val, const gchar **ok_strv, gchar **dst)
32 gint i,r;
34 *dst = NULL;
36 if (opt_val == NULL)
37 return (EXIT_SUCCESS);
39 for (i=0, r=EXIT_FAILURE; ok_strv[i] != NULL; ++i)
41 if (g_strcmp0(ok_strv[i], opt_val) == 0)
43 r = EXIT_SUCCESS;
44 break;
48 if (r == EXIT_FAILURE)
49 *dst = (gchar*) opt_val;
51 return (r);
54 /* Validate string array of values to possible values. */
55 gint lopts_chk_strv(const gchar **opt_val, const gchar **ok_strv, gchar **dst)
57 gint i, r;
59 *dst = NULL;
61 if (opt_val == NULL)
62 return (EXIT_SUCCESS);
64 for (i=0, r=EXIT_SUCCESS; opt_val[i] != NULL && r == EXIT_SUCCESS; ++i)
65 r = lopts_chk_str(opt_val[i], ok_strv, dst);
67 return (r);
70 /* Validate regex patterns. */
71 gint lopts_chk_re(const gchar **opt_val, gchar **dst)
73 gboolean is_valid;
74 gint r, i;
76 *dst = NULL;
78 if (opt_val == NULL)
79 return (EXIT_SUCCESS);
81 for (i=0, r=EXIT_SUCCESS; opt_val[i] != NULL && r == EXIT_SUCCESS; ++i)
83 lutil_regex_op_new(opt_val[i], &is_valid);
84 if (is_valid == FALSE)
86 *dst = (gchar*) opt_val[i];
87 r = EXIT_FAILURE;
90 return (r);
93 /* vim: set ts=2 sw=2 tw=72 expandtab: */