NeoMutt  2023-03-22
Teaching an old dog new tricks
DOXYGEN
string_get()

Get a config item as a string. More...

+ Collaboration diagram for string_get():

Functions

static int address_string_get (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
 Get an Address as a string - Implements ConfigSetType::string_get() -. More...
 
static int bool_string_get (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
 Get a Bool as a string - Implements ConfigSetType::string_get() -. More...
 
static int enum_string_get (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
 Get an Enumeration as a string - Implements ConfigSetType::string_get() -. More...
 
static int long_string_get (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
 Get a Long as a string - Implements ConfigSetType::string_get() -. More...
 
static int mbtable_string_get (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
 Get a MbTable as a string - Implements ConfigSetType::string_get() -. More...
 
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() -. More...
 
static int path_string_get (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
 Get a Path as a string - Implements ConfigSetType::string_get() -. 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 regex_string_get (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
 Get a Regex as a string - Implements ConfigSetType::string_get() -. More...
 
static int slist_string_get (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
 Get a Slist as a string - Implements ConfigSetType::string_get() -. More...
 
static int sort_string_get (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
 Get a Sort as a string - Implements ConfigSetType::string_get() -. More...
 
static int string_string_get (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
 Get a String as a string - Implements ConfigSetType::string_get() -. More...
 

Detailed Description

Get a config item as a string.

Parameters
csConfig items
varVariable to get (may be NULL)
cdefVariable definition
resultBuffer for results or error messages
Return values
numResult, e.g. CSR_SUCCESS

If var is NULL, then the config item's initial value will be returned.

Precondition
cs is not NULL
cdef is not NULL
result is not NULL

Function Documentation

◆ address_string_get()

static int address_string_get ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
struct Buffer result 
)
static

Get an Address as a string - Implements ConfigSetType::string_get() -.

Definition at line 115 of file address.c.

117{
118 if (var)
119 {
120 struct Address *a = *(struct Address **) var;
121 if (a)
122 {
123 mutt_addr_write(result, a, false);
124 }
125 }
126 else
127 {
128 mutt_buffer_addstr(result, (char *) cdef->initial);
129 }
130
131 if (mutt_buffer_is_empty(result))
132 return CSR_SUCCESS | CSR_SUC_EMPTY; /* empty string */
133
134 return CSR_SUCCESS;
135}
size_t mutt_addr_write(struct Buffer *buf, struct Address *addr, bool display)
Write a single Address to a buffer.
Definition: address.c:1024
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:298
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:233
#define CSR_SUC_EMPTY
Value is empty/unset.
Definition: set.h:42
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
An email address.
Definition: address.h:36
intptr_t initial
Initial value.
Definition: set.h:67
+ Here is the call graph for this function:

◆ bool_string_get()

static int bool_string_get ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
struct Buffer result 
)
static

Get a Bool as a string - Implements ConfigSetType::string_get() -.

Definition at line 105 of file bool.c.

107{
108 int index;
109
110 if (var)
111 index = *(bool *) var;
112 else
113 index = (int) cdef->initial;
114
115 if (index > 1)
116 return CSR_ERR_INVALID | CSR_INV_TYPE; /* LCOV_EXCL_LINE */
117
118 mutt_buffer_addstr(result, BoolValues[index]);
119 return CSR_SUCCESS;
120}
const char * BoolValues[]
Valid strings for creating a Bool.
Definition: bool.c:50
#define CSR_ERR_INVALID
Value hasn't been set.
Definition: set.h:38
#define CSR_INV_TYPE
Value is not valid for the type.
Definition: set.h:47
+ Here is the call graph for this function:

◆ enum_string_get()

static int enum_string_get ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
struct Buffer result 
)
static

Get an Enumeration as a string - Implements ConfigSetType::string_get() -.

Definition at line 88 of file enum.c.

90{
91 if (!cs || !cdef)
92 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
93
94 unsigned int value;
95
96 if (var)
97 value = *(unsigned char *) var;
98 else
99 value = (int) cdef->initial;
100
101 struct EnumDef *ed = (struct EnumDef *) cdef->data;
102 if (!ed || !ed->lookup)
103 return CSR_ERR_CODE;
104
105 const char *name = mutt_map_get_name(value, ed->lookup);
106 if (!name)
107 {
108 mutt_debug(LL_DEBUG1, "Variable has an invalid value: %d\n", value);
109 return (CSR_ERR_INVALID | CSR_INV_TYPE);
110 }
111
112 mutt_buffer_addstr(result, name);
113 return CSR_SUCCESS;
114}
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
intptr_t data
Extra variable data.
Definition: set.h:68
An enumeration.
Definition: enum.h:30
+ Here is the call graph for this function:

◆ long_string_get()

static int long_string_get ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
struct Buffer result 
)
static

Get a Long as a string - Implements ConfigSetType::string_get() -.

Definition at line 91 of file long.c.

93{
94 int value;
95
96 if (var)
97 value = *(long *) var;
98 else
99 value = (int) cdef->initial;
100
101 mutt_buffer_printf(result, "%d", value);
102 return CSR_SUCCESS;
103}
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:168
+ Here is the call graph for this function:

◆ mbtable_string_get()

static int mbtable_string_get ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
struct Buffer result 
)
static

Get a MbTable as a string - Implements ConfigSetType::string_get() -.

Definition at line 158 of file mbtable.c.

160{
161 const char *str = NULL;
162
163 if (var)
164 {
165 struct MbTable *table = *(struct MbTable **) var;
166 if (!table || !table->orig_str)
167 return CSR_SUCCESS | CSR_SUC_EMPTY; /* empty string */
168 str = table->orig_str;
169 }
170 else
171 {
172 str = (char *) cdef->initial;
173 }
174
175 mutt_buffer_addstr(result, str);
176 return CSR_SUCCESS;
177}
Multibyte character table.
Definition: mbtable.h:34
char * orig_str
Original string used to generate this object.
Definition: mbtable.h:35
+ Here is the call graph for this function:

◆ number_string_get()

static int number_string_get ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
struct Buffer result 
)
static

Get a Number as a string - Implements ConfigSetType::string_get() -.

Definition at line 98 of file number.c.

100{
101 int value;
102
103 if (var)
104 value = *(short *) var;
105 else
106 value = (int) cdef->initial;
107
108 mutt_buffer_printf(result, "%d", value);
109 return CSR_SUCCESS;
110}
+ Here is the call graph for this function:

◆ path_string_get()

static int path_string_get ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
struct Buffer result 
)
static

Get a Path as a string - Implements ConfigSetType::string_get() -.

Definition at line 136 of file path.c.

138{
139 const char *str = NULL;
140
141 if (var)
142 str = *(const char **) var;
143 else
144 str = (char *) cdef->initial;
145
146 if (!str)
147 return CSR_SUCCESS | CSR_SUC_EMPTY; /* empty path */
148
149 mutt_buffer_addstr(result, str);
150 return CSR_SUCCESS;
151}
+ Here is the call graph for this function:

◆ quad_string_get()

static int quad_string_get ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
struct Buffer result 
)
static

Get a Quad-option as a string - Implements ConfigSetType::string_get() -.

Definition at line 104 of file quad.c.

106{
107 unsigned int value;
108
109 if (var)
110 value = *(char *) var;
111 else
112 value = (int) cdef->initial;
113
114 if (value >= (mutt_array_size(QuadValues) - 1))
115 {
116 mutt_debug(LL_DEBUG1, "Variable has an invalid value: %d\n", value); /* LCOV_EXCL_LINE */
117 return CSR_ERR_INVALID | CSR_INV_TYPE; /* LCOV_EXCL_LINE */
118 }
119
120 mutt_buffer_addstr(result, QuadValues[value]);
121 return CSR_SUCCESS;
122}
#define mutt_array_size(x)
Definition: memory.h:36
const char * QuadValues[]
Valid strings for creating a QuadValue.
Definition: quad.c:49
+ Here is the call graph for this function:

◆ regex_string_get()

static int regex_string_get ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
struct Buffer result 
)
static

Get a Regex as a string - Implements ConfigSetType::string_get() -.

Definition at line 177 of file regex.c.

179{
180 const char *str = NULL;
181
182 if (var)
183 {
184 struct Regex *r = *(struct Regex **) var;
185 if (r)
186 str = r->pattern;
187 }
188 else
189 {
190 str = (char *) cdef->initial;
191 }
192
193 if (!str)
194 return CSR_SUCCESS | CSR_SUC_EMPTY; /* empty string */
195
196 mutt_buffer_addstr(result, str);
197 return CSR_SUCCESS;
198}
Cached regular expression.
Definition: regex3.h:89
char * pattern
printable version
Definition: regex3.h:90
+ Here is the call graph for this function:

◆ slist_string_get()

static int slist_string_get ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
struct Buffer result 
)
static

Get a Slist as a string - Implements ConfigSetType::string_get() -.

Definition at line 112 of file slist.c.

114{
115 if (!cs || !cdef)
116 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
117
118 if (var)
119 {
120 struct Slist *list = *(struct Slist **) var;
121 if (!list)
122 return (CSR_SUCCESS | CSR_SUC_EMPTY); /* empty string */
123
124 slist_to_buffer(list, result);
125 }
126 else
127 {
128 mutt_buffer_addstr(result, (char *) cdef->initial);
129 }
130
131 int rc = CSR_SUCCESS;
132 if (mutt_buffer_is_empty(result))
133 rc |= CSR_SUC_EMPTY;
134
135 return rc;
136}
int slist_to_buffer(const struct Slist *list, struct Buffer *buf)
Export an Slist to a Buffer.
Definition: slist.c:292
String list.
Definition: slist.h:47
+ Here is the call graph for this function:

◆ sort_string_get()

static int sort_string_get ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
struct Buffer result 
)
static

Get a Sort as a string - Implements ConfigSetType::string_get() -.

Definition at line 117 of file sort.c.

119{
120 int sort;
121
122 if (var)
123 sort = *(short *) var;
124 else
125 sort = (int) cdef->initial;
126
127 if (sort & SORT_REVERSE)
129 if (sort & SORT_LAST)
131
132 sort &= SORT_MASK;
133
134 const char *str = NULL;
135
136 str = mutt_map_get_name(sort, (struct Mapping *) cdef->data);
137
138 if (!str)
139 {
140 mutt_debug(LL_DEBUG1, "Variable has an invalid value: %d/%d\n",
141 cdef->type & DT_SUBTYPE_MASK, sort);
143 }
144
145 mutt_buffer_addstr(result, str);
146 return CSR_SUCCESS;
147}
#define PREFIX_REVERSE
Definition: sort.c:41
#define PREFIX_LAST
Definition: sort.c:42
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:74
#define SORT_LAST
Sort thread by last-X, e.g. received date.
Definition: sort2.h:76
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:75
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:66
Mapping between user-readable string and a constant.
Definition: mapping.h:32
#define DT_SUBTYPE_MASK
Mask for the Data Subtype.
Definition: types.h:63
+ Here is the call graph for this function:

◆ string_string_get()

static int string_string_get ( const struct ConfigSet cs,
void *  var,
const struct ConfigDef cdef,
struct Buffer result 
)
static

Get a String as a string - Implements ConfigSetType::string_get() -.

Definition at line 108 of file string.c.

110{
111 const char *str = NULL;
112
113 if (var)
114 str = *(const char **) var;
115 else
116 str = (char *) cdef->initial;
117
118 if (!str)
119 return CSR_SUCCESS | CSR_SUC_EMPTY; /* empty string */
120
121 mutt_buffer_addstr(result, str);
122 return CSR_SUCCESS;
123}
+ Here is the call graph for this function: