2 libcore: library for basic data structures and algorithms.
3 Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "lc_opts_t.h"
25 int lc_opt_type_scan(void *dest, lc_opt_type_t type, const char *str)
27 static const char *fmts[] = {
47 case lc_opt_type_double:
48 case lc_opt_type_string:
49 res = sscanf(str, fmts[type], dest);
51 case lc_opt_type_boolean:
57 strncpy(buf, str, sizeof(buf));
58 for(i = 0, n = strlen(buf); i < n; ++i)
59 buf[i] = tolower(buf[i]);
61 for(i = 0; i < LC_ARRSIZE(bool_vals); ++i) {
62 if(strcmp(buf, bool_vals[i].str) == 0) {
64 *data = bool_vals[i].val;
77 int lc_opt_type_print(char *buf, size_t n, lc_opt_type_t type, void *data)
84 int i = *((int *) data);
85 res = snprintf(buf, n, "%d", i);
88 case lc_opt_type_double:
90 double d = *((double *) data);
91 res = snprintf(buf, n, "%f", d);
94 case lc_opt_type_string:
95 res = snprintf(buf, n, "%s", (const char*) data);
97 case lc_opt_type_boolean:
98 res = snprintf(buf, n, "%s", *((int *) data) ? "yes" : "no");