NeoMutt  2025-01-09-81-g753ae0
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
bool.c File Reference

Type representing a boolean. More...

#include "config.h"
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "mutt/lib.h"
#include "bool.h"
#include "set.h"
#include "subset.h"
#include "types.h"
+ Include dependency graph for bool.c:

Go to the source code of this file.

Functions

static int bool_string_set (void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Bool by string - Implements ConfigSetType::string_set() -.
 
static int bool_string_get (void *var, const struct ConfigDef *cdef, struct Buffer *result)
 Get a Bool as a string - Implements ConfigSetType::string_get() -.
 
static int bool_native_set (void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Bool config item by bool - Implements ConfigSetType::native_set() -.
 
static intptr_t bool_native_get (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Get a bool from a Bool config item - Implements ConfigSetType::native_get() -.
 
static bool bool_has_been_set (void *var, const struct ConfigDef *cdef)
 Is the config value different to its initial value? - Implements ConfigSetType::has_been_set() -.
 
static int bool_reset (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Bool to its initial value - Implements ConfigSetType::reset() -.
 
int bool_he_toggle (struct ConfigSubset *sub, struct HashElem *he, struct Buffer *err)
 Toggle the value of a bool.
 
int bool_str_toggle (struct ConfigSubset *sub, const char *name, struct Buffer *err)
 Toggle the value of a bool.
 

Variables

const char * BoolValues []
 Valid strings for creating a Bool.
 
const struct ConfigSetType CstBool
 Config type representing an boolean.
 

Detailed Description

Type representing a boolean.

Authors
  • Richard Russon
  • Pietro Cerutti

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file bool.c.

Function Documentation

◆ bool_he_toggle()

int bool_he_toggle ( struct ConfigSubset sub,
struct HashElem he,
struct Buffer err 
)

Toggle the value of a bool.

Parameters
subConfig Subset
heHashElem representing config item
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 201 of file bool.c.

202{
203 if (!sub || !he || !he->data)
204 return CSR_ERR_CODE;
205
206 struct HashElem *he_base = cs_get_base(he);
207 if (CONFIG_TYPE(he_base->type) != DT_BOOL)
208 return CSR_ERR_CODE;
209
210 intptr_t value = cs_he_native_get(sub->cs, he, err);
211 if (value == INT_MIN)
212 return CSR_ERR_CODE;
213
214 int rc = cs_he_native_set(sub->cs, he, !value, err);
215
216 if ((CSR_RESULT(rc) == CSR_SUCCESS) && !(rc & CSR_SUC_NO_CHANGE))
218
219 return rc;
220}
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:160
int cs_he_native_set(const struct ConfigSet *cs, struct HashElem *he, intptr_t value, struct Buffer *err)
Natively set the value of a HashElem config item.
Definition: set.c:760
intptr_t cs_he_native_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
Natively get the value of a HashElem config item.
Definition: set.c:865
#define CSR_SUC_NO_CHANGE
The value hasn't changed.
Definition: set.h:44
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
#define CSR_RESULT(x)
Definition: set.h:52
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:50
The item stored in a Hash Table.
Definition: hash.h:44
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
void * data
User-supplied data.
Definition: hash.h:47
void cs_subset_notify_observers(const struct ConfigSubset *sub, struct HashElem *he, enum NotifyConfig ev)
Notify all observers of an event.
Definition: subset.c:239
@ NT_CONFIG_SET
Config item has been set.
Definition: subset.h:61
#define CONFIG_TYPE(t)
Definition: types.h:49
@ DT_BOOL
boolean option
Definition: types.h:32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bool_str_toggle()

int bool_str_toggle ( struct ConfigSubset sub,
const char *  name,
struct Buffer err 
)

Toggle the value of a bool.

Parameters
subConfig Subset
nameName of config item
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 229 of file bool.c.

230{
231 struct HashElem *he = cs_subset_create_inheritance(sub, name);
232
233 return bool_he_toggle(sub, he, err);
234}
int bool_he_toggle(struct ConfigSubset *sub, struct HashElem *he, struct Buffer *err)
Toggle the value of a bool.
Definition: bool.c:201
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:210
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ BoolValues

const char* BoolValues[]
Initial value:
= {
"no", "yes", "n", "y", "false", "true", "0", "1", "off", "on", NULL,
}

Valid strings for creating a Bool.

These strings are case-insensitive.

Definition at line 51 of file bool.c.

◆ CstBool

const struct ConfigSetType CstBool
Initial value:
= {
"boolean",
NULL,
NULL,
NULL,
}
static bool bool_has_been_set(void *var, const struct ConfigDef *cdef)
Is the config value different to its initial value? - Implements ConfigSetType::has_been_set() -.
Definition: bool.c:166
static intptr_t bool_native_get(void *var, const struct ConfigDef *cdef, struct Buffer *err)
Get a bool from a Bool config item - Implements ConfigSetType::native_get() -.
Definition: bool.c:158
static int bool_native_set(void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Set a Bool config item by bool - Implements ConfigSetType::native_set() -.
Definition: bool.c:128
static int bool_reset(void *var, const struct ConfigDef *cdef, struct Buffer *err)
Reset a Bool to its initial value - Implements ConfigSetType::reset() -.
Definition: bool.c:174
static int bool_string_get(void *var, const struct ConfigDef *cdef, struct Buffer *result)
Get a Bool as a string - Implements ConfigSetType::string_get() -.
Definition: bool.c:109
static int bool_string_set(void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
Set a Bool by string - Implements ConfigSetType::string_set() -.
Definition: bool.c:58

Config type representing an boolean.

Definition at line 239 of file bool.c.