NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
quad.c File Reference

Type representing a quad-option. More...

#include "config.h"
#include <stddef.h>
#include <limits.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 (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Quad-option by string - Implements ConfigSetType::string_set() -. More...
 
static int quad_string_get (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
 Get a Quad-option as a string - Implements ConfigSetType::string_get() -. More...
 
static int quad_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Quad-option config item by int - Implements ConfigSetType::native_set() -. More...
 
static intptr_t quad_native_get (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Get an int object from a Quad-option config item - Implements ConfigSetType::native_get() -. More...
 
static int quad_reset (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Quad-option to its initial value - Implements ConfigSetType::reset() -. More...
 
static int quad_toggle (int opt)
 Toggle (invert) the value of a quad option. More...
 
int quad_he_toggle (struct ConfigSubset *sub, struct HashElem *he, struct Buffer *err)
 Toggle the value of a quad. More...
 
int quad_str_toggle (struct ConfigSubset *sub, const char *name, struct Buffer *err)
 Toggle the value of a quad. More...
 

Variables

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

Detailed Description

Type representing a quad-option.

Authors
  • Richard Russon

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

By toggling the low bit, the following are swapped:

Definition at line 189 of file quad.c.

190 {
191  return opt ^= 1;
192 }
+ 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 203 of file quad.c.

204 {
205  if (!sub || !he || !he->data)
206  return CSR_ERR_CODE;
207 
208  struct HashElem *he_base = cs_get_base(he);
209  if (DTYPE(he_base->type) != DT_QUAD)
210  return CSR_ERR_CODE;
211 
212  intptr_t value = cs_he_native_get(sub->cs, he, err);
213  if (value == INT_MIN)
214  return CSR_ERR_CODE;
215 
216  value = quad_toggle(value);
217  int rc = cs_he_native_set(sub->cs, he, value, err);
218 
219  if ((CSR_RESULT(rc) == CSR_SUCCESS) && !(rc & CSR_SUC_NO_CHANGE))
221 
222  return rc;
223 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
void cs_subset_notify_observers(const struct ConfigSubset *sub, struct HashElem *he, enum NotifyConfig ev)
Notify all observers of an event.
Definition: subset.c:229
#define DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:37
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:44
#define CSR_RESULT(x)
Definition: set.h:52
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:790
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
#define CSR_SUC_NO_CHANGE
The value hasn&#39;t changed.
Definition: set.h:44
static int quad_toggle(int opt)
Toggle (invert) the value of a quad option.
Definition: quad.c:189
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:189
Config item has been set.
Definition: subset.h:62
void * data
User-supplied data.
Definition: hash.h:47
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
The item stored in a Hash Table.
Definition: hash.h:43
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
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:685
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quad_str_toggle()

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

Toggle the value of a quad.

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

Definition at line 234 of file quad.c.

235 {
236  struct HashElem *he = cs_subset_create_inheritance(sub, name);
237 
238  return quad_he_toggle(sub, he, err);
239 }
int quad_he_toggle(struct ConfigSubset *sub, struct HashElem *he, struct Buffer *err)
Toggle the value of a quad.
Definition: quad.c:203
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:200
The item stored in a Hash Table.
Definition: hash.h:43
+ Here is the call 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 49 of file quad.c.

◆ cst_quad

const struct ConfigSetType cst_quad
Initial value:
= {
"quad",
NULL,
NULL,
NULL,
}
static int quad_string_get(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
Get a Quad-option as a string - Implements ConfigSetType::string_get() -.
Definition: quad.c:104
static int quad_native_set(const struct ConfigSet *cs, 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:127
static int quad_string_set(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
Set a Quad-option by string - Implements ConfigSetType::string_set() -.
Definition: quad.c:56
#define DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:37
static int quad_reset(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Reset a Quad-option to its initial value - Implements ConfigSetType::reset() -.
Definition: quad.c:163
static intptr_t quad_native_get(const struct ConfigSet *cs, 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:154

Config type representing a quad-option.

Definition at line 244 of file quad.c.