NeoMutt  2021-02-05-89-gabe350
Teaching an old dog new tricks
DOXYGEN
tags.c File Reference
#include "config.h"
#include <stddef.h>
#include <stdbool.h>
#include "mutt/lib.h"
#include "tags.h"
+ Include dependency graph for tags.c:

Go to the source code of this file.

Functions

static char * driver_tags_getter (struct TagList *head, bool show_hidden, bool show_transformed, const char *filter)
 Get transformed tags. More...
 
void driver_tags_add (struct TagList *list, char *new_tag)
 Add a tag to header. More...
 
void driver_tags_free (struct TagList *list)
 Free tags from a header. More...
 
char * driver_tags_get_transformed (struct TagList *list)
 Get transformed tags. More...
 
char * driver_tags_get (struct TagList *list)
 Get tags. More...
 
char * driver_tags_get_with_hidden (struct TagList *list)
 Get tags with hiddens. More...
 
char * driver_tags_get_transformed_for (struct TagList *head, const char *name)
 Get transformed tag for a tag name from a header. More...
 
bool driver_tags_replace (struct TagList *head, char *tags)
 Replace all tags. More...
 

Variables

struct SlistC_HiddenTags
 Config: Tags that shouldn't be displayed on screen. More...
 
struct HashTableTagTransforms
 Lookup table of alternative tag names. More...
 

Detailed Description

Driver based email tags

Authors
  • Mehdi Abaakouk

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 tags.c.

Function Documentation

◆ driver_tags_getter()

static char* driver_tags_getter ( struct TagList *  head,
bool  show_hidden,
bool  show_transformed,
const char *  filter 
)
static

Get transformed tags.

Parameters
headList of tags
show_hiddenShow hidden tags
show_transformedShow transformed tags
filterMatch tags to this string
Return values
ptrString list of tags

Return a new allocated string containing tags separated by space

Definition at line 50 of file tags.c.

52 {
53  if (!head)
54  return NULL;
55 
56  char *tags = NULL;
57  struct Tag *np = NULL;
58  STAILQ_FOREACH(np, head, entries)
59  {
60  if (filter && !mutt_str_equal(np->name, filter))
61  continue;
62  if (show_hidden || !np->hidden)
63  {
64  if (show_transformed && np->transformed)
65  mutt_str_append_item(&tags, np->transformed, ' ');
66  else
67  mutt_str_append_item(&tags, np->name, ' ');
68  }
69  }
70  return tags;
71 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_tags_add()

void driver_tags_add ( struct TagList *  list,
char *  new_tag 
)

Add a tag to header.

Parameters
[in]listList of tags
[in]new_tagString representing the new tag

Add a tag to the header tags

Note
The ownership of the string is passed to the TagList structure

Definition at line 82 of file tags.c.

83 {
84  char *new_tag_transformed = mutt_hash_find(TagTransforms, new_tag);
85 
86  struct Tag *tn = mutt_mem_calloc(1, sizeof(struct Tag));
87  tn->name = new_tag;
88  tn->hidden = false;
89  if (new_tag_transformed)
90  tn->transformed = mutt_str_dup(new_tag_transformed);
91 
92  /* filter out hidden tags */
93  if (C_HiddenTags)
94  if (mutt_list_find(&C_HiddenTags->head, new_tag))
95  tn->hidden = true;
96 
97  STAILQ_INSERT_TAIL(list, tn, entries);
98 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_tags_free()

void driver_tags_free ( struct TagList *  list)

Free tags from a header.

Parameters
[in]listList of tags

Free the whole tags structure

Definition at line 106 of file tags.c.

107 {
108  if (!list)
109  return;
110 
111  struct Tag *np = STAILQ_FIRST(list);
112  struct Tag *next = NULL;
113  while (np)
114  {
115  next = STAILQ_NEXT(np, entries);
116  FREE(&np->name);
117  FREE(&np->transformed);
118  FREE(&np);
119  np = next;
120  }
121  STAILQ_INIT(list);
122 }
+ Here is the caller graph for this function:

◆ driver_tags_get_transformed()

char* driver_tags_get_transformed ( struct TagList *  list)

Get transformed tags.

Parameters
[in]listList of tags
Return values
ptrString list of tags

Return a new allocated string containing all tags separated by space with transformation

Definition at line 132 of file tags.c.

133 {
134  return driver_tags_getter(list, false, true, NULL);
135 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_tags_get()

char* driver_tags_get ( struct TagList *  list)

Get tags.

Parameters
[in]listList of tags
Return values
ptrString list of tags

Return a new allocated string containing all tags separated by space

Definition at line 144 of file tags.c.

145 {
146  return driver_tags_getter(list, false, false, NULL);
147 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_tags_get_with_hidden()

char* driver_tags_get_with_hidden ( struct TagList *  list)

Get tags with hiddens.

Parameters
[in]listList of tags
Return values
ptrString list of tags

Return a new allocated string containing all tags separated by space even the hiddens.

Definition at line 157 of file tags.c.

158 {
159  return driver_tags_getter(list, true, false, NULL);
160 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_tags_get_transformed_for()

char* driver_tags_get_transformed_for ( struct TagList *  head,
const char *  name 
)

Get transformed tag for a tag name from a header.

Parameters
[in]headList of tags
[in]nameTag to transform
Return values
ptrString tag

Return a new allocated string containing all tags separated by space even the hiddens.

Definition at line 171 of file tags.c.

172 {
173  return driver_tags_getter(head, true, true, name);
174 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_tags_replace()

bool driver_tags_replace ( struct TagList *  head,
char *  tags 
)

Replace all tags.

Parameters
[in]headList of tags
[in]tagsstring of all tags separated by space
Return values
falseNo changes are made
trueTags are updated

Free current tags structures and replace it by new tags

Definition at line 185 of file tags.c.

186 {
187  if (!head)
188  return false;
189 
190  driver_tags_free(head);
191 
192  if (tags)
193  {
194  struct ListHead hsplit = STAILQ_HEAD_INITIALIZER(hsplit);
195  mutt_list_str_split(&hsplit, tags, ' ');
196  struct ListNode *np = NULL;
197  STAILQ_FOREACH(np, &hsplit, entries)
198  {
199  driver_tags_add(head, np->data);
200  }
201  mutt_list_clear(&hsplit);
202  }
203  return true;
204 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ C_HiddenTags

struct Slist* C_HiddenTags

Config: Tags that shouldn't be displayed on screen.

Definition at line 36 of file tags.c.

◆ TagTransforms

struct HashTable* TagTransforms

Lookup table of alternative tag names.

Definition at line 38 of file tags.c.

mutt_str_append_item
void mutt_str_append_item(char **str, const char *item, char sep)
Add string to another separated by sep.
Definition: string.c:466
TagTransforms
struct HashTable * TagTransforms
Lookup table of alternative tag names.
Definition: tags.c:38
STAILQ_INIT
#define STAILQ_INIT(head)
Definition: queue.h:369
mutt_mem_calloc
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
C_HiddenTags
struct Slist * C_HiddenTags
Config: Tags that shouldn't be displayed on screen.
Definition: tags.c:36
ListNode
A List node for strings.
Definition: list.h:34
mutt_list_find
struct ListNode * mutt_list_find(const struct ListHead *h, const char *data)
Find a string in a List.
Definition: list.c:102
driver_tags_free
void driver_tags_free(struct TagList *list)
Free tags from a header.
Definition: tags.c:106
Slist::head
struct ListHead head
Definition: slist.h:48
mutt_str_dup
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
FREE
#define FREE(x)
Definition: memory.h:40
STAILQ_FIRST
#define STAILQ_FIRST(head)
Definition: queue.h:347
Tag::hidden
bool hidden
Tag should be hidden.
Definition: tags.h:44
STAILQ_FOREACH
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
Tag::name
char * name
Tag name.
Definition: tags.h:42
mutt_hash_find
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
Definition: hash.c:354
mutt_str_equal
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
driver_tags_add
void driver_tags_add(struct TagList *list, char *new_tag)
Add a tag to header.
Definition: tags.c:82
Tag
LinkedList Tag Element.
Definition: tags.h:40
STAILQ_HEAD_INITIALIZER
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:321
STAILQ_INSERT_TAIL
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:386
mutt_list_clear
void mutt_list_clear(struct ListHead *h)
Free a list, but NOT its strings.
Definition: list.c:167
mutt_list_str_split
size_t mutt_list_str_split(struct ListHead *head, const char *src, char sep)
Split a string into a list using a separator char.
Definition: list.c:247
ListNode::data
char * data
String.
Definition: list.h:36
Tag::transformed
char * transformed
Transformed name.
Definition: tags.h:43
STAILQ_NEXT
#define STAILQ_NEXT(elm, field)
Definition: queue.h:397
driver_tags_getter
static char * driver_tags_getter(struct TagList *head, bool show_hidden, bool show_transformed, const char *filter)
Get transformed tags.
Definition: tags.c:50