NeoMutt  2020-06-26-250-g349c94
Teaching an old dog new tricks
DOXYGEN
tags.c File Reference

Driver based email tags. More...

#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...
 
static 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 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:876
LinkedList Tag Element.
Definition: tags.h:40
char * name
Tag name.
Definition: tags.h:42
bool hidden
Tag should be hidden.
Definition: tags.h:44
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
void mutt_str_append_item(char **str, const char *item, char sep)
Add string to another separated by sep.
Definition: string.c:471
char * transformed
Transformed name.
Definition: tags.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_tags_add()

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

Add a tag to header.

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

Add a tag to the header tags

Definition at line 80 of file tags.c.

81 {
82  char *new_tag_transformed = mutt_hash_find(TagTransforms, new_tag);
83 
84  struct Tag *tn = mutt_mem_calloc(1, sizeof(struct Tag));
85  tn->name = mutt_str_dup(new_tag);
86  tn->hidden = false;
87  if (new_tag_transformed)
88  tn->transformed = mutt_str_dup(new_tag_transformed);
89 
90  /* filter out hidden tags */
91  if (C_HiddenTags)
92  if (mutt_list_find(&C_HiddenTags->head, new_tag))
93  tn->hidden = true;
94 
95  STAILQ_INSERT_TAIL(list, tn, entries);
96 }
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
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
LinkedList Tag Element.
Definition: tags.h:40
char * name
Tag name.
Definition: tags.h:42
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:375
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:386
struct Slist * C_HiddenTags
Config: Tags that shouldn&#39;t be displayed on screen.
Definition: tags.c:36
struct ListHead head
Definition: slist.h:45
struct ListNode * mutt_list_find(const struct ListHead *h, const char *data)
Find a string in a List.
Definition: list.c:102
bool hidden
Tag should be hidden.
Definition: tags.h:44
struct HashTable * TagTransforms
Lookup table of alternative tag names.
Definition: tags.c:38
char * transformed
Transformed name.
Definition: tags.h:43
+ 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 104 of file tags.c.

105 {
106  if (!list)
107  return;
108 
109  struct Tag *np = STAILQ_FIRST(list);
110  struct Tag *next = NULL;
111  while (np)
112  {
113  next = STAILQ_NEXT(np, entries);
114  FREE(&np->name);
115  FREE(&np->transformed);
116  FREE(&np);
117  np = next;
118  }
119  STAILQ_INIT(list);
120 }
LinkedList Tag Element.
Definition: tags.h:40
char * name
Tag name.
Definition: tags.h:42
#define STAILQ_INIT(head)
Definition: queue.h:369
#define STAILQ_NEXT(elm, field)
Definition: queue.h:397
#define FREE(x)
Definition: memory.h:40
char * transformed
Transformed name.
Definition: tags.h:43
#define STAILQ_FIRST(head)
Definition: queue.h:347
+ 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 130 of file tags.c.

131 {
132  return driver_tags_getter(list, false, true, NULL);
133 }
static char * driver_tags_getter(struct TagList *head, bool show_hidden, bool show_transformed, const char *filter)
Get transformed tags.
Definition: tags.c:50
+ 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 142 of file tags.c.

143 {
144  return driver_tags_getter(list, false, false, NULL);
145 }
static char * driver_tags_getter(struct TagList *head, bool show_hidden, bool show_transformed, const char *filter)
Get transformed tags.
Definition: tags.c:50
+ 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 155 of file tags.c.

156 {
157  return driver_tags_getter(list, true, false, NULL);
158 }
static char * driver_tags_getter(struct TagList *head, bool show_hidden, bool show_transformed, const char *filter)
Get transformed tags.
Definition: tags.c:50
+ 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 169 of file tags.c.

170 {
171  return driver_tags_getter(head, true, true, name);
172 }
char * name
Tag name.
Definition: tags.h:42
static char * driver_tags_getter(struct TagList *head, bool show_hidden, bool show_transformed, const char *filter)
Get transformed tags.
Definition: tags.c:50
+ 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 183 of file tags.c.

184 {
185  if (!head)
186  return false;
187 
188  driver_tags_free(head);
189 
190  if (tags)
191  {
192  struct ListHead hsplit = STAILQ_HEAD_INITIALIZER(hsplit);
193  mutt_list_str_split(&hsplit, tags, ' ');
194  struct ListNode *np = NULL;
195  STAILQ_FOREACH(np, &hsplit, entries)
196  {
197  driver_tags_add(head, np->data);
198  }
199  mutt_list_free(&hsplit);
200  }
201  return true;
202 }
void driver_tags_free(struct TagList *list)
Free tags from a header.
Definition: tags.c:104
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
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
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
char * data
String.
Definition: list.h:36
static void driver_tags_add(struct TagList *list, char *new_tag)
Add a tag to header.
Definition: tags.c:80
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:321
A List node for strings.
Definition: list.h:34
+ 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.