NeoMutt  2024-04-25-1-g3de005
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
helpers.c File Reference

Shared code. More...

#include "config.h"
#include <stddef.h>
#include <assert.h>
#include <ctype.h>
#include <stdbool.h>
#include "mutt/lib.h"
#include "helpers.h"
#include "definition.h"
#include "mutt_thread.h"
#include "render.h"
+ Include dependency graph for helpers.c:

Go to the source code of this file.

Functions

const struct ExpandoRenderDatafind_get_number (const struct ExpandoRenderData *rdata, int did, int uid)
 Find a get_number() callback function.
 
const struct ExpandoRenderDatafind_get_string (const struct ExpandoRenderData *rdata, int did, int uid)
 Find a get_string() callback function.
 
const char * skip_until_ch (const char *start, char terminator)
 Search a string for a terminator character.
 
static bool is_valid_classic_expando (char ch)
 Is this a valid Expando character?
 
const char * skip_until_classic_expando (const char *start)
 Search through string until we reach an Expando character.
 
const char * skip_classic_expando (const char *str, const struct ExpandoDefinition *defs)
 Skip over the text of an Expando.
 
void buf_lower_special (struct Buffer *buf)
 Convert to lowercase, excluding special characters.
 

Detailed Description

Shared code.

Authors
  • Tóth János
  • 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 helpers.c.

Function Documentation

◆ find_get_number()

const struct ExpandoRenderData * find_get_number ( const struct ExpandoRenderData rdata,
int  did,
int  uid 
)

Find a get_number() callback function.

Parameters
rdataRender data to search
didDomain ID to match
uidUnique ID to match
Return values
ptrMatching Render data

Definition at line 48 of file helpers.c.

50{
51 if (!rdata)
52 return NULL;
53
54 for (; rdata->did != -1; rdata++)
55 {
56 if ((rdata->did == did) && (rdata->uid == uid) && rdata->get_number)
57 {
58 return rdata;
59 }
60 }
61
62 return NULL;
63}
long(* get_number)(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Definition: render.h:79
int did
Domain ID.
Definition: render.h:49
int uid
Unique ID.
Definition: render.h:50
+ Here is the caller graph for this function:

◆ find_get_string()

const struct ExpandoRenderData * find_get_string ( const struct ExpandoRenderData rdata,
int  did,
int  uid 
)

Find a get_string() callback function.

Parameters
rdataRender data to search
didDomain ID to match
uidUnique ID to match
Return values
ptrMatching Render data

Definition at line 72 of file helpers.c.

74{
75 if (!rdata)
76 return NULL;
77
78 for (; rdata->did != -1; rdata++)
79 {
80 if ((rdata->did == did) && (rdata->uid == uid) && rdata->get_string)
81 {
82 return rdata;
83 }
84 }
85
86 return NULL;
87}
void(* get_string)(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Definition: render.h:65
+ Here is the caller graph for this function:

◆ skip_until_ch()

const char * skip_until_ch ( const char *  start,
char  terminator 
)

Search a string for a terminator character.

Parameters
startStart of string
terminatorCharacter to find
Return values
ptrPosition of terminator character, or end-of-string

Definition at line 95 of file helpers.c.

96{
97 while (*start)
98 {
99 if (*start == terminator)
100 {
101 break;
102 }
103
104 start++;
105 }
106
107 return start;
108}
+ Here is the caller graph for this function:

◆ is_valid_classic_expando()

static bool is_valid_classic_expando ( char  ch)
static

Is this a valid Expando character?

Parameters
chCharacter to test
Return values
trueValid Expando character

Definition at line 115 of file helpers.c.

116{
117 // NOTE(g0mb4): Maybe rework this?
118 // if special expandos are added this list must be updated!
119 return isalpha(ch) || (ch == ' ') || (ch == '!') || (ch == '(') ||
120 (ch == '*') || (ch == '>') || (ch == '@') || (ch == '[') ||
121 (ch == '^') || (ch == '{') || (ch == '|');
122}
+ Here is the caller graph for this function:

◆ skip_until_classic_expando()

const char * skip_until_classic_expando ( const char *  start)

Search through string until we reach an Expando character.

Parameters
startWhere to start looking
Return values
ptrMatch, or end-of-string

Definition at line 129 of file helpers.c.

130{
131 while (*start && !is_valid_classic_expando(*start))
132 {
133 start++;
134 }
135
136 return start;
137}
static bool is_valid_classic_expando(char ch)
Is this a valid Expando character?
Definition: helpers.c:115
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ skip_classic_expando()

const char * skip_classic_expando ( const char *  str,
const struct ExpandoDefinition defs 
)

Skip over the text of an Expando.

Parameters
strStarting place
defsExpando definitions
Return values
ptrCharacter after Expando, or end-of-string

Definition at line 145 of file helpers.c.

146{
147 assert(str);
148 if (*str == '\0')
149 return str;
150
151 const struct ExpandoDefinition *definitions = defs;
152
153 while (definitions && definitions->short_name)
154 {
155 const bool is_two_char = mutt_str_len(definitions->short_name) == 2;
156 const char *name = definitions->short_name;
157
158 if (is_two_char && (name[0] == *str) && (name[1] == *(str + 1)))
159 {
160 str++;
161 break;
162 }
163
164 definitions++;
165 }
166
167 str++;
168 return str;
169}
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:490
Definition of a format string.
Definition: definition.h:52
const char * short_name
Short Expando name, e.g. "n".
Definition: definition.h:53
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_lower_special()

void buf_lower_special ( struct Buffer buf)

Convert to lowercase, excluding special characters.

Parameters
bufString to lowercase

The string is transformed in place.

Definition at line 177 of file helpers.c.

178{
179 if (!buf || !buf->data)
180 return;
181
182 char *p = buf->data;
183
184 while (*p)
185 {
186 if (*p == MUTT_SPECIAL_INDEX)
187 {
188 p += 2;
189 continue;
190 }
191 else if (*p < MUTT_TREE_MAX)
192 {
193 p++;
194 continue;
195 }
196
197 *p = tolower((unsigned char) *p);
198 p++;
199 }
200}
@ MUTT_TREE_MAX
Definition: mutt_thread.h:71
@ MUTT_SPECIAL_INDEX
Colour indicator.
Definition: mutt_thread.h:73
char * data
Pointer to data.
Definition: buffer.h:37
+ Here is the caller graph for this function: