NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
node_condbool.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <stdio.h>
32#include "mutt/lib.h"
33#include "node_condbool.h"
34#include "helpers.h"
35#include "node.h"
36#include "render.h"
37
41int node_condbool_render(const struct ExpandoNode *node,
42 const struct ExpandoRenderData *rdata, struct Buffer *buf,
43 int max_cols, void *data, MuttFormatFlags flags)
44{
45 ASSERT(node->type == ENT_CONDBOOL);
46
47 const struct ExpandoRenderData *rd_match = find_get_number(rdata, node->did, node->uid);
48 if (rd_match)
49 {
50 const long num = rd_match->get_number(node, data, flags);
51 return (num != 0); // bool-ify
52 }
53
54 rd_match = find_get_string(rdata, node->did, node->uid);
55 if (rd_match)
56 {
57 struct Buffer *buf_str = buf_pool_get();
58 rd_match->get_string(node, data, flags, buf_str);
59 const size_t len = buf_len(buf_str);
60 buf_pool_release(&buf_str);
61
62 return (len > 0); // bool-ify
63 }
64
65 return 0;
66}
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:491
const struct ExpandoRenderData * find_get_number(const struct ExpandoRenderData *rdata, int did, int uid)
Find a get_number() callback function.
Definition: helpers.c:45
const struct ExpandoRenderData * find_get_string(const struct ExpandoRenderData *rdata, int did, int uid)
Find a get_string() callback function.
Definition: helpers.c:69
Shared code.
int node_condbool_render(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Callback for every bool node - Implements ExpandoNode::render() -.
Definition: node_condbool.c:41
Convenience wrapper for the library headers.
Basic Expando Node.
@ ENT_CONDBOOL
True/False boolean condition.
Definition: node.h:42
Expando Node for a Conditional Boolean.
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
Render Expandos using Data.
uint8_t MuttFormatFlags
Flags for expando_render(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: render.h:32
#define ASSERT(COND)
Definition: signal2.h:58
String manipulation buffer.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:37
Basic Expando Node.
Definition: node.h:67
int uid
Unique ID, e.g. ED_EMA_SIZE.
Definition: node.h:70
int did
Domain ID, e.g. ED_EMAIL.
Definition: node.h:69
enum ExpandoNodeType type
Type of Node, e.g. ENT_EXPANDO.
Definition: node.h:68
long(* get_number)(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Definition: render.h:78
void(* get_string)(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Definition: render.h:64