NeoMutt  2024-11-14-138-ge5ca67
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 <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 (const struct ConfigSet *cs, 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 (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
 Get a Number as a string - Implements ConfigSetType::string_get() -.
 
static int number_native_set (const struct ConfigSet *cs, 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 (const struct ConfigSet *cs, 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 (const struct ConfigSet *cs, 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 (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Subtract from a Number by string - Implements ConfigSetType::string_minus_equals() -.
 
static int number_reset (const struct ConfigSet *cs, 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 46 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 50 of file number.c.

51{
52 return (*(intptr_t *) var & TOGGLE_BIT) ? 0 : *(short *) var;
53}
#define TOGGLE_BIT
Definition: number.c:46
+ 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 58 of file number.c.

59{
60 *(intptr_t *) var = 0; // clear any pending toggle status
61 *(short *) var = val;
62}
+ 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 67 of file number.c.

68{
69 *(intptr_t *) var = *(uintptr_t *) var ^ TOGGLE_BIT;
70}
+ 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 301 of file number.c.

302{
303 if (!sub || !he || !he->data)
304 return CSR_ERR_CODE;
305
306 struct HashElem *he_base = cs_get_base(he);
307 if (DTYPE(he_base->type) != DT_NUMBER)
308 return CSR_ERR_CODE;
309
310 struct ConfigDef *cdef = he_base->data;
311 native_toggle(&cdef->var);
312
314
315 return CSR_SUCCESS;
316}
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:36
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
static void native_toggle(void *var)
Toggle a Number config item.
Definition: number.c:67
Definition: set.h:64
intptr_t var
Storage for the variable.
Definition: set.h:85
The item stored in a Hash Table.
Definition: hash.h:43
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:44
void * data
User-supplied data.
Definition: hash.h:46
void cs_subset_notify_observers(const struct ConfigSubset *sub, struct HashElem *he, enum NotifyConfig ev)
Notify all observers of an event.
Definition: subset.c:237
@ NT_CONFIG_SET
Config item has been set.
Definition: subset.h:62
#define DTYPE(t)
Definition: types.h:50
@ DT_NUMBER
a number
Definition: types.h:39
+ 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 intptr_t number_native_get(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Get an int from a Number config item - Implements ConfigSetType::native_get() -.
Definition: number.c:180
static int number_native_set(const struct ConfigSet *cs, 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:143
static int number_reset(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Reset a Number to its initial value - Implements ConfigSetType::reset() -.
Definition: number.c:273
static int number_string_get(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
Get a Number as a string - Implements ConfigSetType::string_get() -.
Definition: number.c:126
static int number_string_minus_equals(const struct ConfigSet *cs, 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(const struct ConfigSet *cs, 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:189
static int number_string_set(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
Set a Number by string - Implements ConfigSetType::string_set() -.
Definition: number.c:75

Config type representing a number.

Definition at line 321 of file number.c.