NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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() -.
 
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() -.
 
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() -.
 
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() -.
 
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() -.
 
static int myvar_string_get (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
 Get a MyVar as a string - Implements ConfigSetType::string_get() -.
 
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 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() -.
 
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() -.
 
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() -.
 
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() -.
 
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() -.
 
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() -.
 
static int expando_string_get (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
 Get an Expando as a string - Implements ConfigSetType::string_get() -.
 

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 137 of file config_type.c.

139{
140 if (var)
141 {
142 struct Address *a = *(struct Address **) var;
143 if (a)
144 {
145 mutt_addr_write(result, a, false);
146 }
147 }
148 else
149 {
150 buf_addstr(result, (char *) cdef->initial);
151 }
152
153 if (buf_is_empty(result))
154 return CSR_SUCCESS | CSR_SUC_EMPTY; /* empty string */
155
156 return CSR_SUCCESS;
157}
size_t mutt_addr_write(struct Buffer *buf, struct Address *addr, bool display)
Write a single Address to a buffer.
Definition: address.c:1050
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:291
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:226
#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 109 of file bool.c.

111{
112 int index;
113
114 if (var)
115 index = *(bool *) var;
116 else
117 index = (int) cdef->initial;
118
119 if (index > 1)
120 return CSR_ERR_INVALID | CSR_INV_TYPE; /* LCOV_EXCL_LINE */
121
122 buf_addstr(result, BoolValues[index]);
123 return CSR_SUCCESS;
124}
const char * BoolValues[]
Valid strings for creating a Bool.
Definition: bool.c:51
#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 91 of file enum.c.

93{
94 if (!cs || !cdef)
95 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
96
97 unsigned int value;
98
99 if (var)
100 value = *(unsigned char *) var;
101 else
102 value = (int) cdef->initial;
103
104 struct EnumDef *ed = (struct EnumDef *) cdef->data;
105 if (!ed || !ed->lookup)
106 return CSR_ERR_CODE;
107
108 const char *name = mutt_map_get_name(value, ed->lookup);
109 if (!name)
110 {
111 mutt_debug(LL_DEBUG1, "Variable has an invalid value: %d\n", value);
113 }
114
115 buf_addstr(result, name);
116 return CSR_SUCCESS;
117}
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
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 96 of file long.c.

98{
99 int value;
100
101 if (var)
102 value = *(long *) var;
103 else
104 value = (int) cdef->initial;
105
106 buf_printf(result, "%d", value);
107 return CSR_SUCCESS;
108}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
+ 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 177 of file mbtable.c.

179{
180 const char *str = NULL;
181
182 if (var)
183 {
184 struct MbTable *table = *(struct MbTable **) var;
185 if (!table || !table->orig_str)
186 return CSR_SUCCESS | CSR_SUC_EMPTY; /* empty string */
187 str = table->orig_str;
188 }
189 else
190 {
191 str = (char *) cdef->initial;
192 }
193
194 buf_addstr(result, str);
195 return CSR_SUCCESS;
196}
Multibyte character table.
Definition: mbtable.h:36
char * orig_str
Original string used to generate this object.
Definition: mbtable.h:37
+ Here is the call graph for this function:

◆ myvar_string_get()

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

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

Definition at line 94 of file myvar.c.

96{
97 const char *str = NULL;
98
99 if (var)
100 str = *(const char **) var;
101 else
102 str = (char *) cdef->initial;
103
104 if (!str)
105 return CSR_SUCCESS | CSR_SUC_EMPTY; /* empty myvar */
106
107 buf_addstr(result, str);
108 return CSR_SUCCESS;
109}
+ 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 126 of file number.c.

128{
129 int value;
130
131 if (var)
132 value = native_get(var);
133 else
134 value = (int) cdef->initial;
135
136 buf_printf(result, "%d", value);
137 return CSR_SUCCESS;
138}
static intptr_t native_get(void *var)
Get an int from a Number config item.
Definition: number.c:50
+ 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 144 of file path.c.

146{
147 const char *str = NULL;
148
149 if (var)
150 str = *(const char **) var;
151 else
152 str = (char *) cdef->initial;
153
154 if (!str)
155 return CSR_SUCCESS | CSR_SUC_EMPTY; /* empty path */
156
157 buf_addstr(result, str);
158 return CSR_SUCCESS;
159}
+ 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 111 of file quad.c.

113{
114 unsigned int value;
115
116 if (var)
117 value = *(char *) var;
118 else
119 value = (int) cdef->initial;
120
121 if (value >= (mutt_array_size(QuadValues) - 1))
122 {
123 mutt_debug(LL_DEBUG1, "Variable has an invalid value: %d\n", value); /* LCOV_EXCL_LINE */
124 return CSR_ERR_INVALID | CSR_INV_TYPE; /* LCOV_EXCL_LINE */
125 }
126
127 buf_addstr(result, QuadValues[value]);
128 return CSR_SUCCESS;
129}
#define mutt_array_size(x)
Definition: memory.h:38
const char * QuadValues[]
Valid strings for creating a QuadValue.
Definition: quad.c:53
+ 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 202 of file regex.c.

204{
205 const char *str = NULL;
206
207 if (var)
208 {
209 struct Regex *r = *(struct Regex **) var;
210 if (r)
211 str = r->pattern;
212 }
213 else
214 {
215 str = (char *) cdef->initial;
216 }
217
218 if (!str)
219 return CSR_SUCCESS | CSR_SUC_EMPTY; /* empty string */
220
221 buf_addstr(result, str);
222 return CSR_SUCCESS;
223}
Cached regular expression.
Definition: regex3.h:86
char * pattern
printable version
Definition: regex3.h:87
+ 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 125 of file slist.c.

127{
128 if (!cs || !cdef)
129 return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
130
131 if (var)
132 {
133 struct Slist *list = *(struct Slist **) var;
134 if (!list)
135 return CSR_SUCCESS | CSR_SUC_EMPTY; /* empty string */
136
137 slist_to_buffer(list, result);
138 }
139 else
140 {
141 buf_addstr(result, (char *) cdef->initial);
142 }
143
144 int rc = CSR_SUCCESS;
145 if (buf_is_empty(result))
146 rc |= CSR_SUC_EMPTY;
147
148 return rc;
149}
int slist_to_buffer(const struct Slist *list, struct Buffer *buf)
Export an Slist to a Buffer.
Definition: slist.c:267
String list.
Definition: slist.h:37
+ 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 122 of file sort.c.

124{
125 int sort;
126
127 if (var)
128 sort = *(short *) var;
129 else
130 sort = (int) cdef->initial;
131
132 if (sort & SORT_REVERSE)
133 buf_addstr(result, PREFIX_REVERSE);
134 if (sort & SORT_LAST)
135 buf_addstr(result, PREFIX_LAST);
136
137 sort &= SORT_MASK;
138
139 const char *str = NULL;
140
141 str = mutt_map_get_name(sort, (struct Mapping *) cdef->data);
142
143 if (!str)
144 {
145 mutt_debug(LL_DEBUG1, "Variable has an invalid value: %d/%d\n", cdef->type, sort);
147 }
148
149 buf_addstr(result, str);
150 return CSR_SUCCESS;
151}
#define PREFIX_REVERSE
Definition: sort.c:43
#define PREFIX_LAST
Definition: sort.c:44
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:70
#define SORT_LAST
Sort thread by last-X, e.g. received date.
Definition: sort2.h:72
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:71
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:66
Mapping between user-readable string and a constant.
Definition: mapping.h:33
+ 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 113 of file string.c.

115{
116 const char *str = NULL;
117
118 if (var)
119 str = *(const char **) var;
120 else
121 str = (char *) cdef->initial;
122
123 if (!str)
124 return CSR_SUCCESS | CSR_SUC_EMPTY; /* empty string */
125
126 buf_addstr(result, str);
127 return CSR_SUCCESS;
128}
+ Here is the call graph for this function:

◆ expando_string_get()

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

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

Definition at line 134 of file config_type.c.

136{
137 const char *str = NULL;
138
139 if (var)
140 {
141 struct Expando *exp = *(struct Expando **) var;
142 if (exp)
143 str = exp->string;
144 }
145 else
146 {
147 str = (char *) cdef->initial;
148 }
149
150 if (!str)
151 return CSR_SUCCESS | CSR_SUC_EMPTY; /* empty string */
152
153 buf_addstr(result, str);
154 return CSR_SUCCESS;
155}
Parsed Expando trees.
Definition: expando.h:41
const char * string
Pointer to the parsed string.
Definition: expando.h:42
+ Here is the call graph for this function: