NeoMutt  2025-01-09-117-gace867
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
number.c File Reference

Type representing a number. More...

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

Go to the source code of this file.

Macros

#define TOGGLE_BIT   ((SHRT_MAX + 1) << 1)
 

Functions

static intptr_t native_get (void *var)
 Get an int from a Number config item.
 
static void native_set (void *var, intptr_t val)
 Set an int into a Number config item.
 
static void native_toggle (void *var)
 Toggle a Number config item.
 
static int number_string_set (void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set a Number by string - Implements ConfigSetType::string_set() -.
 
static int number_string_get (void *var, const struct ConfigDef *cdef, struct Buffer *result)
 Get a Number as a string - Implements ConfigSetType::string_get() -.
 
static int number_native_set (void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set a Number config item by int - Implements ConfigSetType::native_set() -.
 
static intptr_t number_native_get (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Get an int from a Number config item - Implements ConfigSetType::native_get() -.
 
static int number_string_plus_equals (void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Add to a Number by string - Implements ConfigSetType::string_plus_equals() -.
 
static int number_string_minus_equals (void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Subtract from a Number by string - Implements ConfigSetType::string_minus_equals() -.
 
static bool number_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 number_reset (void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset a Number to its initial value - Implements ConfigSetType::reset() -.
 
int number_he_toggle (struct ConfigSubset *sub, struct HashElem *he, struct Buffer *err)
 Toggle the value of a number (value <-> 0)
 

Variables

const struct ConfigSetType CstNumber
 Config type representing a number.
 

Detailed Description

Type representing a number.

Authors
  • Richard Russon
  • Jakub Jindra
  • 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 number.c.

Macro Definition Documentation

◆ TOGGLE_BIT

#define TOGGLE_BIT   ((SHRT_MAX + 1) << 1)

Definition at line 47 of file number.c.

Function Documentation

◆ native_get()

static intptr_t native_get ( void *  var)
static

Get an int from a Number config item.

Definition at line 51 of file number.c.

52{
53 // take care of endianess and always read intptr_t value
54 intptr_t v = *(intptr_t *) var;
55 return (v & TOGGLE_BIT) ? 0 : (short) v;
56}
#define TOGGLE_BIT
Definition: number.c:47
+ Here is the caller graph for this function:

◆ native_set()

static void native_set ( void *  var,
intptr_t  val 
)
static

Set an int into a Number config item.

Definition at line 61 of file number.c.

62{
63 // cast to unsigned short to clear any pending toggle status bits
64 val = (unsigned short) val;
65 *(intptr_t *) var = val;
66}
+ Here is the caller graph for this function:

◆ native_toggle()

static void native_toggle ( void *  var)
static

Toggle a Number config item.

Definition at line 71 of file number.c.

72{
73 *(intptr_t *) var = *(uintptr_t *) var ^ TOGGLE_BIT;
74}
+ Here is the caller graph for this function:

◆ number_he_toggle()

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

Toggle the value of a number (value <-> 0)

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

Definition at line 307 of file number.c.

308{
309 if (!sub || !he || !he->data)
310 return CSR_ERR_CODE;
311
312 struct HashElem *he_base = cs_get_base(he);
313 if (CONFIG_TYPE(he_base->type) != DT_NUMBER)
314 return CSR_ERR_CODE;
315
316 struct ConfigDef *cdef = he_base->data;
317 native_toggle(&cdef->var);
318
320
321 return CSR_SUCCESS;
322}
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:160
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:34
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:33
static void native_toggle(void *var)
Toggle a Number config item.
Definition: number.c:71
Definition: set.h:62
intptr_t var
Storage for the variable.
Definition: set.h:82
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_NUMBER
a number
Definition: types.h:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ CstNumber

const struct ConfigSetType CstNumber
Initial value:
= {
"number",
NULL,
}
static bool number_has_been_set(void *var, const struct ConfigDef *cdef)
Is the config value different to its initial value? - Implements ConfigSetType::has_been_set() -.
Definition: number.c:272
static intptr_t number_native_get(void *var, const struct ConfigDef *cdef, struct Buffer *err)
Get an int from a Number config item - Implements ConfigSetType::native_get() -.
Definition: number.c:182
static int number_native_set(void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Set a Number config item by int - Implements ConfigSetType::native_set() -.
Definition: number.c:146
static int number_reset(void *var, const struct ConfigDef *cdef, struct Buffer *err)
Reset a Number to its initial value - Implements ConfigSetType::reset() -.
Definition: number.c:280
static int number_string_get(void *var, const struct ConfigDef *cdef, struct Buffer *result)
Get a Number as a string - Implements ConfigSetType::string_get() -.
Definition: number.c:130
static int number_string_minus_equals(void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
Subtract from a Number by string - Implements ConfigSetType::string_minus_equals() -.
Definition: number.c:231
static int number_string_plus_equals(void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
Add to a Number by string - Implements ConfigSetType::string_plus_equals() -.
Definition: number.c:190
static int number_string_set(void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
Set a Number by string - Implements ConfigSetType::string_set() -.
Definition: number.c:79

Config type representing a number.

Definition at line 327 of file number.c.