NeoMutt  2025-12-11-435-g4ac674
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
quad.c File Reference

Type representing a quad-option. More...

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

Go to the source code of this file.

Functions

static int quad_string_set (void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Quad-option by string - Implements ConfigSetType::string_set() -.
 
static int quad_string_get (void *var, const struct ConfigDef *cdef, struct Buffer *result)
 Get a Quad-option as a string - Implements ConfigSetType::string_get() -.
 
static int quad_native_set (void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Quad-option config item by int - Implements ConfigSetType::native_set() -.
 
static intptr_t quad_native_get (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Get an int object from a Quad-option config item - Implements ConfigSetType::native_get() -.
 
static bool quad_has_been_set (void *var, const struct ConfigDef *cdef)
 Is the config value different to its initial value?
 
static int quad_reset (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Quad-option to its initial value - Implements ConfigSetType::reset() -.
 
static int quad_toggle (int opt)
 Toggle (invert) the value of a quad option.
 
int quad_he_toggle (struct ConfigSubset *sub, struct HashElem *he, struct Buffer *err)
 Toggle the value of a quad.
 

Variables

const char * QuadValues []
 Valid strings for creating a QuadValue.
 
const struct ConfigSetType CstQuad
 Config type representing a quad-option.
 

Detailed Description

Type representing a quad-option.

Authors
  • Richard Russon
  • Pietro Cerutti
  • Alejandro Colomar

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 quad.c.

Function Documentation

◆ quad_toggle()

static int quad_toggle ( int opt)
static

Toggle (invert) the value of a quad option.

Parameters
optValue to toggle
Return values
numNew value

By toggling the low bit, the following are swapped:

Definition at line 210 of file quad.c.

211{
212 return opt ^ 1;
213}
+ Here is the caller graph for this function:

◆ quad_he_toggle()

int quad_he_toggle ( struct ConfigSubset * sub,
struct HashElem * he,
struct Buffer * err )

Toggle the value of a quad.

Parameters
subConfig subset
heHashElem representing config item
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS
See also
quad_toggle()

Definition at line 224 of file quad.c.

225{
226 if (!sub || !he || !he->data)
227 return CSR_ERR_CODE;
228
229 struct HashElem *he_base = cs_get_base(he);
230 if (CONFIG_TYPE(he_base->type) != DT_QUAD)
231 return CSR_ERR_CODE;
232
233 intptr_t value = cs_he_native_get(sub->cs, he, err);
234 if (value == INT_MIN)
235 return CSR_ERR_CODE;
236
237 value = quad_toggle(value);
238 int rc = cs_he_native_set(sub->cs, he, value, err);
239
240 if ((CSR_RESULT(rc) == CSR_SUCCESS) && !(rc & CSR_SUC_NO_CHANGE))
242
243 return rc;
244}
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition set.c:161
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:737
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:842
#define CSR_SUC_NO_CHANGE
The value hasn't changed.
Definition set.h:42
#define CSR_ERR_CODE
Problem with the code.
Definition set.h:34
#define CSR_RESULT(x)
Extract the result code from CSR_* flags.
Definition set.h:52
#define CSR_SUCCESS
Action completed successfully.
Definition set.h:33
static int quad_toggle(int opt)
Toggle (invert) the value of a quad option.
Definition quad.c:210
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:243
@ NT_CONFIG_SET
Config item has been set.
Definition subset.h:61
#define CONFIG_TYPE(t)
Extract the type from the flags.
Definition types.h:50
@ DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition types.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ QuadValues

const char* QuadValues[]
Initial value:
= {
"no", "yes", "ask-no", "ask-yes", NULL,
}

Valid strings for creating a QuadValue.

These strings are case-insensitive.

Definition at line 55 of file quad.c.

55 {
56 "no", "yes", "ask-no", "ask-yes", NULL,
57};

◆ CstQuad

const struct ConfigSetType CstQuad
Initial value:
= {
"quad",
NULL,
NULL,
NULL,
}
static bool quad_has_been_set(void *var, const struct ConfigDef *cdef)
Is the config value different to its initial value?
Definition quad.c:173
static intptr_t quad_native_get(void *var, const struct ConfigDef *cdef, struct Buffer *err)
Get an int object from a Quad-option config item - Implements ConfigSetType::native_get() -.
Definition quad.c:165
static int quad_native_set(void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Set a Quad-option config item by int - Implements ConfigSetType::native_set() -.
Definition quad.c:135
static int quad_reset(void *var, const struct ConfigDef *cdef, struct Buffer *err)
Reset a Quad-option to its initial value - Implements ConfigSetType::reset() -.
Definition quad.c:181
static int quad_string_get(void *var, const struct ConfigDef *cdef, struct Buffer *result)
Get a Quad-option as a string - Implements ConfigSetType::string_get() -.
Definition quad.c:113
static int quad_string_set(void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
Set a Quad-option by string - Implements ConfigSetType::string_set() -.
Definition quad.c:62

Config type representing a quad-option.

Definition at line 249 of file quad.c.

249 {
250 DT_QUAD,
251 "quad",
256 NULL, // string_plus_equals
257 NULL, // string_minus_equals
260 NULL, // destroy
261};