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: dk4opt03.ctr
12 */
13
14 /** @file dk4opt03.c The dk4opt03 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 <libdk4base/dk4numco.h>
23 #include <libdk4maiodd/dk4maidddi.h>
24
25 #if DK4_HAVE_ASSERT_H
26 #ifndef ASSERT_H_INCLUDED
27 #include <assert.h>
28 #define ASSERT_H_INCLUDED 1
29 #endif
30 #endif
31
32
33
34
35
36
37 int
dk4opt_get_int(dk4_im_t * dptr,dk4_option_t const * optptr,dk4_er_t * erp)38 dk4opt_get_int(dk4_im_t *dptr, dk4_option_t const *optptr, dk4_er_t *erp)
39 {
40 dk4_im_t val = (dk4_im_t)0L;
41 int back = 0;
42 int res = 0;
43 #if DK4_USE_ASSERT
44 assert(NULL != dptr);
45 assert(NULL != optptr);
46 #endif
47 if ((NULL != dptr) && (NULL != optptr)) {
48 if (0 != optptr->found) {
49 switch ((optptr->spec).argtype) {
50 case DK4_OPT_ARG_BOOL: {
51 if (0 != (optptr->val).b) {
52 *dptr = (dk4_im_t)1L;
53 } else {
54 *dptr = (dk4_im_t)0L;
55 }
56 back = 1;
57 } break;
58 case DK4_OPT_ARG_SIZE: {
59 if ((dk4_um_t)DK4_IM_MAX >= (dk4_um_t)((optptr->val).s)) {
60 *dptr = (dk4_im_t)((optptr->val).s);
61 back = 1;
62 } else {
63 dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW);
64 }
65 } break;
66 case DK4_OPT_ARG_INT: {
67 *dptr = (optptr->val).i;
68 back = 1;
69 } break;
70 case DK4_OPT_ARG_UNSIGNED: {
71 if ((dk4_um_t)DK4_IM_MAX >= (dk4_um_t)((optptr->val).u)) {
72 *dptr = (dk4_im_t)((optptr->val).u);
73 back = 1;
74 } else {
75 dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW);
76 }
77 } break;
78 case DK4_OPT_ARG_STRING: {
79 if (NULL != (optptr->val).t) {
80 res = dk4ma_input_dk_dec_dk4_im_t(
81 &val, (optptr->val).t, NULL, 1, erp
82 );
83 if (0 != res) {
84 *dptr = val;
85 back = 1;
86 }
87 }
88 } break;
89 default: {
90 dk4error_set_simple_error_code(erp, DK4_E_SYNTAX);
91 } break;
92 }
93 } else {
94 dk4error_set_simple_error_code(erp, DK4_E_NOT_FOUND);
95 }
96 } else {
97 dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
98 }
99 return back;
100 }
101
102