NeoMutt  2023-11-03-85-g512e01
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() -.
 

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

130{
131 if (var)
132 {
133 struct Address *a = *(struct Address **) var;
134 if (a)
135 {
136 mutt_addr_write(result, a, false);
137 }
138 }
139 else
140 {
141 buf_addstr(result, (char *) cdef->initial);
142 }
143
144 if (buf_is_empty(result))
145 return CSR_SUCCESS | CSR_SUC_EMPTY; /* empty string */
146
147 return CSR_SUCCESS;
148}
size_t mutt_addr_write(struct Buffer *buf, struct Address *addr, bool display)
Write a single Address to a buffer.
Definition: address.c:1047
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:303
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:238
#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 108 of file bool.c.

110{
111 int index;
112
113 if (var)
114 index = *(bool *) var;
115 else
116 index = (int) cdef->initial;
117
118 if (index > 1)
119 return CSR_ERR_INVALID | CSR_INV_TYPE; /* LCOV_EXCL_LINE */
120
121 buf_addstr(result, BoolValues[index]);
122 return CSR_SUCCESS;
123}
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 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 94 of file long.c.

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

178{
179 const char *str = NULL;
180
181 if (var)
182 {
183 struct MbTable *table = *(struct MbTable **) var;
184 if (!table || !table->orig_str)
185 return CSR_SUCCESS | CSR_SUC_EMPTY; /* empty string */
186 str = table->orig_str;
187 }
188 else
189 {
190 str = (char *) cdef->initial;
191 }
192
193 buf_addstr(result, str);
194 return CSR_SUCCESS;
195}
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 90 of file myvar.c.

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

103{
104 int value;
105
106 if (var)
107 value = *(short *) var;
108 else
109 value = (int) cdef->initial;
110
111 buf_printf(result, "%d", value);
112 return CSR_SUCCESS;
113}
+ 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 141 of file path.c.

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

109{
110 unsigned int value;
111
112 if (var)
113 value = *(char *) var;
114 else
115 value = (int) cdef->initial;
116
117 if (value >= (mutt_array_size(QuadValues) - 1))
118 {
119 mutt_debug(LL_DEBUG1, "Variable has an invalid value: %d\n", value); /* LCOV_EXCL_LINE */
120 return CSR_ERR_INVALID | CSR_INV_TYPE; /* LCOV_EXCL_LINE */
121 }
122
123 buf_addstr(result, QuadValues[value]);
124 return CSR_SUCCESS;
125}
#define mutt_array_size(x)
Definition: memory.h:38
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 200 of file regex.c.

202{
203 const char *str = NULL;
204
205 if (var)
206 {
207 struct Regex *r = *(struct Regex **) var;
208 if (r)
209 str = r->pattern;
210 }
211 else
212 {
213 str = (char *) cdef->initial;
214 }
215
216 if (!str)
217 return CSR_SUCCESS | CSR_SUC_EMPTY; /* empty string */
218
219 buf_addstr(result, str);
220 return CSR_SUCCESS;
221}
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 124 of file slist.c.

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

122{
123 int sort;
124
125 if (var)
126 sort = *(short *) var;
127 else
128 sort = (int) cdef->initial;
129
130 if (sort & SORT_REVERSE)
131 buf_addstr(result, PREFIX_REVERSE);
132 if (sort & SORT_LAST)
133 buf_addstr(result, PREFIX_LAST);
134
135 sort &= SORT_MASK;
136
137 const char *str = NULL;
138
139 str = mutt_map_get_name(sort, (struct Mapping *) cdef->data);
140
141 if (!str)
142 {
143 mutt_debug(LL_DEBUG1, "Variable has an invalid value: %d/%d\n",
144 cdef->type & DT_SUBTYPE_MASK, sort);
146 }
147
148 buf_addstr(result, str);
149 return CSR_SUCCESS;
150}
#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:65
+ 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 111 of file string.c.

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