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