1 /*
2 Copyright (C) 2015-2021, Dirk Krause
3 SPDX-License-Identifier: BSD-3-Clause
4 */
5 
6 /*
7 	WARNING: This file was generated by the dkct program (see
8 	http://dktools.sourceforge.net/ for details).
9 	Changes you make here will be lost if dkct is run again!
10 	You should modify the original source and run dkct on it.
11 	Original source: dk4opt05.ctr
12 */
13 
14 /**	@file dk4opt05.c The dk4opt05 module.
15 */
16 
17 
18 #include "dk4conf.h"
19 #include <libdk4c/dk4opt.h>
20 #include <libdk4base/dk4strd.h>
21 #include <libdk4base/dk4mem.h>
22 #include <libdk4maiodd/dk4maiddbl.h>
23 
24 #if DK4_HAVE_ASSERT_H
25 #ifndef	ASSERT_H_INCLUDED
26 #include <assert.h>
27 #define	ASSERT_H_INCLUDED 1
28 #endif
29 #endif
30 
31 
32 int
dk4opt_get_double(double * dptr,dk4_option_t const * optptr,dk4_er_t * erp)33 dk4opt_get_double(double *dptr, dk4_option_t const *optptr, dk4_er_t *erp)
34 {
35   double	 val	= 0.0;
36   int		 back	= 0;
37   int		 res	= 0;
38 #if	DK4_USE_ASSERT
39 	assert(NULL != dptr);
40 	assert(NULL != optptr);
41 #endif
42   if ((NULL != dptr) && (NULL != optptr)) {
43     if (0 != optptr->found) {
44       switch ((optptr->spec).argtype) {
45         case DK4_OPT_ARG_BOOL: {
46 	  if (0 != (optptr->val).b) {
47 	    *dptr = 1.0;
48 	  } else {
49 	    *dptr = 0.0;
50 	  }
51 	  back = 1;
52 	} break;
53 	case DK4_OPT_ARG_SIZE: {
54 	  *dptr = (double)((optptr->val).s);
55 	  back = 1;
56 	} break;
57 	case DK4_OPT_ARG_INT: {
58 	  *dptr = (double)((optptr->val).i);
59 	  back = 1;
60 	} break;
61 	case DK4_OPT_ARG_UNSIGNED: {
62 	  *dptr = (double)((optptr->val).u);
63 	  back = 1;
64 	} break;
65 	case DK4_OPT_ARG_DOUBLE: {
66 	  *dptr = (optptr->val).d;
67 	  back = 1;
68 	} break;
69 	case DK4_OPT_ARG_STRING: {
70 	  if (NULL != (optptr->val).t) {
71 	    res = dk4ma_input_dk_double(
72 	      &val, (optptr->val).t, NULL, 1, erp
73 	    );
74 	    if (0 != res) {
75 	      *dptr = val;
76 	      back = 1;
77 	    }
78 	  } else {
79 	    dk4error_set_simple_error_code(erp, DK4_E_NOT_FOUND);
80 	  }
81 	} break;
82 	default: {
83 	  dk4error_set_simple_error_code(erp, DK4_E_SYNTAX);
84 	} break;
85       }
86     } else {
87       dk4error_set_simple_error_code(erp, DK4_E_NOT_FOUND);
88     }
89   } else {
90     dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
91   }
92   return back;
93 }
94 
95