NeoMutt  2024-12-12-14-g7b49f7
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
regex4.h File Reference

Regex Colour. More...

#include "config.h"
#include <stdbool.h>
#include "mutt/lib.h"
#include "attr.h"
#include "color.h"
+ Include dependency graph for regex4.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  RegexColor
 A regular expression and a color to highlight a line. More...
 

Functions

 STAILQ_HEAD (RegexColorList, RegexColor)
 
void regex_colors_init (void)
 Initialise the Regex colours.
 
void regex_colors_reset (void)
 Reset the Regex colours.
 
void regex_colors_cleanup (void)
 Cleanup the Regex colours.
 
void regex_color_clear (struct RegexColor *rcol)
 Free the contents of a Regex colour.
 
void regex_color_free (struct RegexColorList *list, struct RegexColor **ptr)
 Free a Regex colour.
 
struct RegexColorregex_color_new (void)
 Create a new RegexColor.
 
struct RegexColorList * regex_colors_get_list (enum ColorId cid)
 Return the RegexColorList for a colour id.
 
void regex_color_list_clear (struct RegexColorList *rcl)
 Free the contents of a RegexColorList.
 
bool regex_colors_parse_color_list (enum ColorId cid, const char *pat, struct AttrColor *ac, int *rc, struct Buffer *err)
 Parse a Regex 'color' command.
 
int regex_colors_parse_status_list (enum ColorId cid, const char *pat, struct AttrColor *ac, int match, struct Buffer *err)
 Parse a Regex 'color status' command.
 
bool regex_colors_parse_uncolor (enum ColorId cid, const char *pat, bool uncolor)
 Parse a Regex 'uncolor' command.
 

Detailed Description

Regex Colour.

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 regex4.h.

Function Documentation

◆ STAILQ_HEAD()

STAILQ_HEAD ( RegexColorList  ,
RegexColor   
)

◆ regex_colors_init()

void regex_colors_init ( void  )

Initialise the Regex colours.

Definition at line 68 of file regex.c.

69{
70 color_debug(LL_DEBUG5, "init AttachList, BodyList, etc\n");
86}
struct RegexColorList IndexCollapsedList
List of colours applied to a collapsed thread in the index.
Definition: regex.c:52
struct RegexColorList IndexFlagsList
List of colours applied to the flags in the index.
Definition: regex.c:54
struct RegexColorList IndexAuthorList
List of colours applied to the author in the index.
Definition: regex.c:51
struct RegexColorList IndexSubjectList
List of colours applied to the subject in the index.
Definition: regex.c:59
struct RegexColorList IndexLabelList
List of colours applied to the label in the index.
Definition: regex.c:55
struct RegexColorList StatusList
List of colours applied to the status bar.
Definition: regex.c:62
struct RegexColorList IndexList
List of default colours applied to the index.
Definition: regex.c:56
struct RegexColorList IndexTagList
List of colours applied to tags in the index.
Definition: regex.c:60
struct RegexColorList BodyList
List of colours applied to the email body.
Definition: regex.c:49
struct RegexColorList IndexTagsList
List of colours applied to the tags in the index.
Definition: regex.c:61
struct RegexColorList HeaderList
List of colours applied to the email headers.
Definition: regex.c:50
struct RegexColorList AttachList
List of colours applied to the attachment headers.
Definition: regex.c:48
struct RegexColorList IndexDateList
List of colours applied to the date in the index.
Definition: regex.c:53
struct RegexColorList IndexNumberList
List of colours applied to the message number in the index.
Definition: regex.c:57
struct RegexColorList IndexSizeList
List of colours applied to the size in the index.
Definition: regex.c:58
static int color_debug(enum LogLevel level, const char *format,...)
Definition: debug.h:52
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
#define STAILQ_INIT(head)
Definition: queue.h:372
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regex_colors_reset()

void regex_colors_reset ( void  )

Reset the Regex colours.

Definition at line 91 of file regex.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regex_colors_cleanup()

void regex_colors_cleanup ( void  )

Cleanup the Regex colours.

Definition at line 114 of file regex.c.

115{
117}
void regex_colors_reset(void)
Reset the Regex colours.
Definition: regex.c:91
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regex_color_clear()

void regex_color_clear ( struct RegexColor rcol)

Free the contents of a Regex colour.

Parameters
rcolRegexColor to empty
Note
The RegexColor object isn't freed

Definition at line 125 of file regex.c.

126{
127 if (!rcol)
128 return;
129
130 rcol->match = 0;
131 rcol->stop_matching = false;
132
134 FREE(&rcol->pattern);
135 regfree(&rcol->regex);
137}
void attr_color_clear(struct AttrColor *ac)
Free the contents of an AttrColor.
Definition: attr.c:48
void mutt_pattern_free(struct PatternList **pat)
Free a Pattern.
Definition: compile.c:778
#define FREE(x)
Definition: memory.h:55
regex_t regex
Compiled regex.
Definition: regex4.h:39
struct PatternList * color_pattern
Compiled pattern to speed up index color calculation.
Definition: regex4.h:41
struct AttrColor attr_color
Colour and attributes to apply.
Definition: regex4.h:37
char * pattern
Pattern to match.
Definition: regex4.h:38
bool stop_matching
Used by the pager for body patterns, to prevent the color from being retried once it fails.
Definition: regex4.h:43
int match
Substring to match, 0 for old behaviour.
Definition: regex4.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regex_color_free()

void regex_color_free ( struct RegexColorList *  list,
struct RegexColor **  ptr 
)

Free a Regex colour.

Parameters
listRegexColorList holding the colour
ptrRegexColor to free

Definition at line 144 of file regex.c.

145{
146 if (!ptr || !*ptr)
147 return;
148
149 struct RegexColor *rcol = *ptr;
150 regex_color_clear(rcol);
151
152 FREE(ptr);
153}
void regex_color_clear(struct RegexColor *rcol)
Free the contents of a Regex colour.
Definition: regex.c:125
A regular expression and a color to highlight a line.
Definition: regex4.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regex_color_new()

struct RegexColor * regex_color_new ( void  )

Create a new RegexColor.

Return values
ptrNew RegexColor

Definition at line 159 of file regex.c.

160{
161 return MUTT_MEM_CALLOC(1, struct RegexColor);
162}
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
+ Here is the caller graph for this function:

◆ regex_colors_get_list()

struct RegexColorList * regex_colors_get_list ( enum ColorId  cid)

Return the RegexColorList for a colour id.

Parameters
cidColour Id, e.g. MT_COLOR_BODY
Return values
ptrRegexColorList

Definition at line 190 of file regex.c.

191{
192 switch (cid)
193 {
195 return &AttachList;
196 case MT_COLOR_BODY:
197 return &BodyList;
198 case MT_COLOR_HEADER:
199 return &HeaderList;
200 case MT_COLOR_INDEX:
201 return &IndexList;
203 return &IndexAuthorList;
205 return &IndexCollapsedList;
207 return &IndexDateList;
209 return &IndexFlagsList;
211 return &IndexLabelList;
213 return &IndexNumberList;
215 return &IndexSizeList;
217 return &IndexSubjectList;
219 return &IndexTagList;
221 return &IndexTagsList;
222 case MT_COLOR_STATUS:
223 return &StatusList;
224 default:
225 return NULL;
226 }
227}
@ MT_COLOR_INDEX_AUTHOR
Index: author field.
Definition: color.h:80
@ MT_COLOR_HEADER
Message headers (takes a pattern)
Definition: color.h:49
@ MT_COLOR_STATUS
Status bar (takes a pattern)
Definition: color.h:71
@ MT_COLOR_INDEX_SIZE
Index: size field.
Definition: color.h:86
@ MT_COLOR_INDEX_TAGS
Index: tags field (g, J)
Definition: color.h:89
@ MT_COLOR_INDEX_SUBJECT
Index: subject field.
Definition: color.h:87
@ MT_COLOR_BODY
Pager: highlight body of message (takes a pattern)
Definition: color.h:40
@ MT_COLOR_INDEX_DATE
Index: date field.
Definition: color.h:82
@ MT_COLOR_INDEX_TAG
Index: tag field (G)
Definition: color.h:88
@ MT_COLOR_ATTACH_HEADERS
MIME attachment test (takes a pattern)
Definition: color.h:39
@ MT_COLOR_INDEX_LABEL
Index: label field.
Definition: color.h:84
@ MT_COLOR_INDEX
Index: default colour.
Definition: color.h:79
@ MT_COLOR_INDEX_NUMBER
Index: index number.
Definition: color.h:85
@ MT_COLOR_INDEX_FLAGS
Index: flags field.
Definition: color.h:83
@ MT_COLOR_INDEX_COLLAPSED
Index: number of messages in collapsed thread.
Definition: color.h:81
+ Here is the caller graph for this function:

◆ regex_color_list_clear()

void regex_color_list_clear ( struct RegexColorList *  rcl)

Free the contents of a RegexColorList.

Parameters
rclList to clear

Free each of the RegexColorList in a list.

Note
The list object isn't freed, only emptied

Definition at line 172 of file regex.c.

173{
174 if (!rcl)
175 return;
176
177 struct RegexColor *np = NULL, *tmp = NULL;
178 STAILQ_FOREACH_SAFE(np, rcl, entries, tmp)
179 {
180 STAILQ_REMOVE(rcl, np, RegexColor, entries);
181 regex_color_free(rcl, &np);
182 }
183}
void regex_color_free(struct RegexColorList *list, struct RegexColor **ptr)
Free a Regex colour.
Definition: regex.c:144
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:402
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:362
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regex_colors_parse_color_list()

bool regex_colors_parse_color_list ( enum ColorId  cid,
const char *  pat,
struct AttrColor ac,
int *  rc,
struct Buffer err 
)

Parse a Regex 'color' command.

Parameters
cidColour Id, should be MT_COLOR_STATUS
patRegex pattern
acColour value to use
rcReturn code, e.g. MUTT_CMD_SUCCESS
errBuffer for error messages
Return values
trueColour was parsed

Parse a Regex 'color' command, e.g. "color index green default pattern"

Definition at line 329 of file regex.c.

332{
333 if (cid == MT_COLOR_STATUS)
334 return false;
335
336 struct RegexColorList *rcl = regex_colors_get_list(cid);
337 if (!rcl)
338 return false;
339
340 bool sensitive = false;
341 bool is_index = false;
342 switch (cid)
343 {
345 case MT_COLOR_BODY:
346 sensitive = true;
347 is_index = false;
348 break;
349 case MT_COLOR_HEADER:
350 sensitive = false;
351 is_index = false;
352 break;
353 case MT_COLOR_INDEX:
364 sensitive = true;
365 is_index = true;
366 break;
367 default:
368 return false;
369 }
370
371 *rc = add_pattern(rcl, pat, sensitive, ac, err, is_index, 0);
372
373 struct Buffer *buf = buf_pool_get();
374 get_colorid_name(cid, buf);
375 color_debug(LL_DEBUG5, "NT_COLOR_SET: %s\n", buf->data);
376 buf_pool_release(&buf);
377
378 if (!is_index) // else it will be logged in add_pattern()
379 {
380 struct EventColor ev_c = { cid, NULL };
382 }
383
384 return true;
385}
void get_colorid_name(unsigned int cid, struct Buffer *buf)
Get the name of a color id.
Definition: command.c:128
struct Notify * ColorsNotify
Notifications: ColorId, EventColor.
Definition: notify.c:36
struct RegexColorList * regex_colors_get_list(enum ColorId cid)
Return the RegexColorList for a colour id.
Definition: regex.c:190
static enum CommandResult add_pattern(struct RegexColorList *rcl, const char *s, bool sensitive, struct AttrColor *ac_val, struct Buffer *err, bool is_index, int match)
Associate a colour to a pattern.
Definition: regex.c:243
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:173
@ NT_COLOR_SET
Color has been set.
Definition: notify2.h:43
@ NT_COLOR
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:41
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
String manipulation buffer.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:37
An Event that happened to a Colour.
Definition: notify2.h:55
enum ColorId cid
Colour ID that has changed.
Definition: notify2.h:56
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regex_colors_parse_status_list()

int regex_colors_parse_status_list ( enum ColorId  cid,
const char *  pat,
struct AttrColor ac,
int  match,
struct Buffer err 
)

Parse a Regex 'color status' command.

Parameters
cidColour ID, should be MT_COLOR_STATUS
patRegex pattern
acColour value to use
matchUse the nth regex submatch
errBuffer for error messages
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Definition at line 396 of file regex.c.

398{
399 if (cid != MT_COLOR_STATUS)
400 return MUTT_CMD_ERROR;
401
402 int rc = add_pattern(&StatusList, pat, true, ac, err, false, match);
403 if (rc != MUTT_CMD_SUCCESS)
404 return rc;
405
406 struct Buffer *buf = buf_pool_get();
407 get_colorid_name(cid, buf);
408 color_debug(LL_DEBUG5, "NT_COLOR_SET: %s\n", buf->data);
409 buf_pool_release(&buf);
410
411 struct EventColor ev_c = { cid, NULL };
413
414 return rc;
415}
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition: command.h:39
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition: command.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regex_colors_parse_uncolor()

bool regex_colors_parse_uncolor ( enum ColorId  cid,
const char *  pat,
bool  uncolor 
)

Parse a Regex 'uncolor' command.

Parameters
cidColour Id, e.g. MT_COLOR_STATUS
patPattern to remove (NULL to remove all)
uncolortrue if 'uncolor', false if 'unmono'
Return values
trueIf colours were unset

Definition at line 424 of file regex.c.

425{
426 struct RegexColorList *cl = regex_colors_get_list(cid);
427 if (!cl)
428 return false;
429
430 if (!pat) // Reset all patterns
431 {
432 if (STAILQ_EMPTY(cl))
433 return true;
434
435 mutt_debug(LL_NOTIFY, "NT_COLOR_RESET: [ALL]\n");
436 struct EventColor ev_c = { cid, NULL };
438
440 return true;
441 }
442
443 bool rc = false;
444 struct RegexColor *np = NULL, *prev = NULL;
445 prev = NULL;
446 STAILQ_FOREACH(np, cl, entries)
447 {
448 if (mutt_str_equal(pat, np->pattern))
449 {
450 rc = true;
451
452 color_debug(LL_DEBUG1, "Freeing pattern \"%s\" from XXX\n", pat);
453 if (prev)
454 STAILQ_REMOVE_AFTER(cl, prev, entries);
455 else
456 STAILQ_REMOVE_HEAD(cl, entries);
457
458 mutt_debug(LL_NOTIFY, "NT_COLOR_RESET: XXX\n");
459 struct EventColor ev_c = { cid, &np->attr_color };
461
462 regex_color_free(cl, &np);
463 break;
464 }
465 prev = np;
466 }
467
468 return rc;
469}
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
@ LL_NOTIFY
Log of notifications.
Definition: logging2.h:48
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
@ NT_COLOR_RESET
Color has been reset/removed.
Definition: notify2.h:44
#define STAILQ_REMOVE_HEAD(head, field)
Definition: queue.h:422
#define STAILQ_REMOVE_AFTER(head, elm, field)
Definition: queue.h:416
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define STAILQ_EMPTY(head)
Definition: queue.h:348
+ Here is the call graph for this function:
+ Here is the caller graph for this function: