NeoMutt  2018-07-16 +2481-68dcde
Teaching an old dog new tricks
DOXYGEN
quad.h File Reference

Type representing a quad-option. More...

+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  QuadOption {
  MUTT_ABORT = -1, MUTT_NO, MUTT_YES, MUTT_ASKNO,
  MUTT_ASKYES
}
 Possible values for a quad-option. More...
 

Functions

void quad_init (struct ConfigSet *cs)
 Register the Quad-option config type. More...
 
int quad_he_toggle (struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
 Toggle the value of a quad. More...
 

Variables

const char * QuadValues []
 Valid strings for creating a QuadValue. 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.h.

Enumeration Type Documentation

◆ QuadOption

enum QuadOption

Possible values for a quad-option.

Enumerator
MUTT_ABORT 

User aborted the question (with Ctrl-G)

MUTT_NO 

User answered 'No', or assume 'No'.

MUTT_YES 

User answered 'Yes', or assume 'Yes'.

MUTT_ASKNO 

Ask the user, defaulting to 'No'.

MUTT_ASKYES 

Ask the user, defaulting to 'Yes'.

Definition at line 35 of file quad.h.

36 {
37  MUTT_ABORT = -1,
38  MUTT_NO,
39  MUTT_YES,
40  MUTT_ASKNO,
41  MUTT_ASKYES,
42 };
User aborted the question (with Ctrl-G)
Definition: quad.h:37
User answered 'Yes', or assume 'Yes'.
Definition: quad.h:39
Ask the user, defaulting to 'Yes'.
Definition: quad.h:41
User answered 'No', or assume 'No'.
Definition: quad.h:38
Ask the user, defaulting to 'No'.
Definition: quad.h:40

Function Documentation

◆ quad_init()

void quad_init ( struct ConfigSet cs)

Register the Quad-option config type.

Parameters
csConfig items

Definition at line 190 of file quad.c.

191 {
192  const struct ConfigSetType cst_quad = {
193  "quad",
198  quad_reset,
199  NULL,
200  };
201  cs_register_type(cs, DT_QUAD, &cst_quad);
202 }
Type definition for a config item.
Definition: set.h:168
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 cst_string_get()
Definition: quad.c:97
#define DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:36
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 cst_string_set()
Definition: quad.c:49
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 cst_reset()
Definition: quad.c:165
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 cst_native_set()
Definition: quad.c:123
bool cs_register_type(struct ConfigSet *cs, unsigned int type, const struct ConfigSetType *cst)
Register a type of config item.
Definition: set.c:261
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 cst_native_get()
Definition: quad.c:153
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quad_he_toggle()

int quad_he_toggle ( struct ConfigSet cs,
struct HashElem he,
struct Buffer err 
)

Toggle the value of a quad.

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

Definition at line 225 of file quad.c.

226 {
227  if (!cs || !he || !he->data)
228  return CSR_ERR_CODE;
229 
230  if (DTYPE(he->type) != DT_QUAD)
231  return CSR_ERR_CODE;
232 
233  const struct ConfigDef *cdef = he->data;
234  char *var = cdef->var;
235 
236  char value = *var;
237  if ((value < 0) || (value >= (mutt_array_size(QuadValues) - 1)))
238  {
239  mutt_buffer_printf(err, "Invalid quad value: %d", value);
240  return CSR_ERR_INVALID | CSR_INV_TYPE;
241  }
242 
243  *(char *) var = quad_toggle(value);
244 
246  return CSR_SUCCESS;
247 }
union HashKey key
Definition: hash.h:45
static int quad_toggle(int opt)
Toggle (invert) the value of a quad option.
Definition: quad.c:211
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Config item definition.
Definition: set.h:153
const char * QuadValues[]
Valid strings for creating a QuadValue.
Definition: quad.c:42
#define DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:36
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:43
#define mutt_array_size(x)
Definition: memory.h:33
void cs_notify_observers(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum NotifyConfig ev)
Notify all observers of an event.
Definition: set.c:358
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:46
#define CSR_ERR_INVALID
Value hasn&#39;t been set.
Definition: set.h:49
#define CSR_INV_TYPE
Value is not valid for the type.
Definition: set.h:58
Config item has been set.
Definition: set.h:40
void * data
Definition: hash.h:46
void * var
Pointer to the global variable.
Definition: set.h:157
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:47
const char * strkey
Definition: hash.h:35
int type
Definition: hash.h:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ QuadValues

const char* QuadValues[]

Valid strings for creating a QuadValue.

These strings are case-insensitive.

Definition at line 42 of file quad.c.