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
22 #include "lc_opts_t.h"
24 int lc_opt_type_scan(void *dest, lc_opt_type_t type, const char *str)
26 static const char *fmts[] = {
46 case lc_opt_type_double:
47 case lc_opt_type_string:
48 res = sscanf(str, fmts[type], dest);
50 case lc_opt_type_boolean:
56 strncpy(buf, str, sizeof(buf));
57 for(i = 0, n = strlen(buf); i < n; ++i)
58 buf[i] = tolower(buf[i]);
60 for(i = 0; i < LC_ARRSIZE(bool_vals); ++i) {
61 if(strcmp(buf, bool_vals[i].str) == 0) {
63 *data = bool_vals[i].val;
76 int lc_opt_type_print(char *buf, size_t n, lc_opt_type_t type, void *data)
83 int i = *((int *) data);
84 res = snprintf(buf, n, "%d", i);
87 case lc_opt_type_double:
89 double d = *((double *) data);
90 res = snprintf(buf, n, "%f", d);
93 case lc_opt_type_string:
94 res = snprintf(buf, n, "%s", (const char*) data);
96 case lc_opt_type_boolean:
97 res = snprintf(buf, n, "%s", *((int *) data) ? "yes" : "no");