NeoMutt  2024-04-16-36-g75b6fb
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
commands.c File Reference

Alias commands. More...

#include "config.h"
#include <stdint.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "commands.h"
#include "lib.h"
#include "parse/lib.h"
#include "alias.h"
#include "reverse.h"
+ Include dependency graph for commands.c:

Go to the source code of this file.

Functions

void alias_tags_to_buffer (struct TagList *tl, struct Buffer *buf)
 Write a comma-separated list of tags to a Buffer.
 
void parse_alias_tags (const char *tags, struct TagList *tl)
 Parse a comma-separated list of tags.
 
void parse_alias_comments (struct Alias *alias, const char *com)
 Parse the alias/query comment field.
 
enum CommandResult parse_alias (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'alias' command - Implements Command::parse() -.
 
enum CommandResult parse_unalias (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unalias' command - Implements Command::parse() -.
 

Detailed Description

Alias commands.

Authors
  • Pietro Cerutti
  • 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 commands.c.

Function Documentation

◆ alias_tags_to_buffer()

void alias_tags_to_buffer ( struct TagList *  tl,
struct Buffer buf 
)

Write a comma-separated list of tags to a Buffer.

Parameters
tlTags
bufBuffer for the result

Definition at line 49 of file commands.c.

50{
51 struct Tag *tag = NULL;
52 STAILQ_FOREACH(tag, tl, entries)
53 {
54 buf_addstr(buf, tag->name);
55 if (STAILQ_NEXT(tag, entries))
56 buf_addch(buf, ',');
57 }
58}
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:240
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define STAILQ_NEXT(elm, field)
Definition: queue.h:400
LinkedList Tag Element.
Definition: tags.h:42
char * name
Tag name.
Definition: tags.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_alias_tags()

void parse_alias_tags ( const char *  tags,
struct TagList *  tl 
)

Parse a comma-separated list of tags.

Parameters
tagsComma-separated string
tlTagList for the results

Definition at line 65 of file commands.c.

66{
67 if (!tags || !tl)
68 return;
69
70 struct Slist *sl = slist_parse(tags, D_SLIST_SEP_COMMA);
71 if (slist_is_empty(sl))
72 {
73 slist_free(&sl);
74 return;
75 }
76
77 struct ListNode *np = NULL;
78 STAILQ_FOREACH(np, &sl->head, entries)
79 {
80 struct Tag *tag = tag_new();
81 tag->name = np->data; // Transfer string
82 np->data = NULL;
83 STAILQ_INSERT_TAIL(tl, tag, entries);
84 }
85 slist_free(&sl);
86}
struct Slist * slist_parse(const char *str, uint32_t flags)
Parse a list of strings into a list.
Definition: slist.c:179
bool slist_is_empty(const struct Slist *list)
Is the slist empty?
Definition: slist.c:142
void slist_free(struct Slist **ptr)
Free an Slist object.
Definition: slist.c:126
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:389
A List node for strings.
Definition: list.h:35
char * data
String.
Definition: list.h:36
String list.
Definition: slist.h:37
struct ListHead head
List containing values.
Definition: slist.h:38
struct Tag * tag_new(void)
Create a new Tag.
Definition: tags.c:64
#define D_SLIST_SEP_COMMA
Slist items are comma-separated.
Definition: types.h:111
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_alias_comments()

void parse_alias_comments ( struct Alias alias,
const char *  com 
)

Parse the alias/query comment field.

Parameters
aliasAlias for the result
comComment string

If the comment contains a 'tags:' field, the result will be put in alias.tags

Definition at line 95 of file commands.c.

96{
97 if (!com || (com[0] == '\0'))
98 return;
99
100 const regmatch_t *match = mutt_prex_capture(PREX_ALIAS_TAGS, com);
101 if (match)
102 {
103 const regmatch_t *pre = &match[PREX_ALIAS_TAGS_MATCH_PRE];
104 const regmatch_t *tags = &match[PREX_ALIAS_TAGS_MATCH_TAGS];
105 const regmatch_t *post = &match[PREX_ALIAS_TAGS_MATCH_POST];
106
107 struct Buffer *tmp = buf_pool_get();
108
109 // Extract the tags
110 buf_addstr_n(tmp, com + mutt_regmatch_start(tags),
112 parse_alias_tags(buf_string(tmp), &alias->tags);
113 buf_reset(tmp);
114
115 // Collect all the other text as "comments"
116 buf_addstr_n(tmp, com + mutt_regmatch_start(pre),
118 buf_addstr_n(tmp, com + mutt_regmatch_start(post),
120 alias->comment = buf_strdup(tmp);
121
122 buf_pool_release(&tmp);
123 }
124 else
125 {
126 alias->comment = mutt_str_dup(com);
127 }
128}
void parse_alias_tags(const char *tags, struct TagList *tl)
Parse a comma-separated list of tags.
Definition: commands.c:65
size_t buf_addstr_n(struct Buffer *buf, const char *s, size_t len)
Add a string to a Buffer, expanding it if necessary.
Definition: buffer.c:95
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:75
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:570
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
regmatch_t * mutt_prex_capture(enum Prex which, const char *str)
Match a precompiled regex against a string.
Definition: prex.c:295
@ PREX_ALIAS_TAGS
tags:a,b,c
Definition: prex.h:43
@ PREX_ALIAS_TAGS_MATCH_POST
... tags:a,b,c[ ...]
Definition: prex.h:240
@ PREX_ALIAS_TAGS_MATCH_PRE
[... ]tags:a,b,c ...
Definition: prex.h:237
@ PREX_ALIAS_TAGS_MATCH_TAGS
... tags:[a,b,c] ...
Definition: prex.h:239
static regoff_t mutt_regmatch_end(const regmatch_t *match)
Return the end of a match.
Definition: regex3.h:66
static regoff_t mutt_regmatch_start(const regmatch_t *match)
Return the start of a match.
Definition: regex3.h:56
struct TagList tags
Tags.
Definition: alias.h:39
char * comment
Free-form comment string.
Definition: alias.h:38
String manipulation buffer.
Definition: buffer.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function: