NeoMutt  2024-12-12-14-g7b49f7
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 ExpandoRenderCallback *erc, struct Buffer *buf,
43 int max_cols, void *data, MuttFormatFlags flags)
44{
45 ASSERT(node->type == ENT_CONDBOOL);
46
47 const struct ExpandoRenderCallback *erc_match = find_get_number(erc, node->did, node->uid);
48 if (erc_match)
49 {
50 const long num = erc_match->get_number(node, data, flags);
51 return (num != 0); // bool-ify
52 }
53
54 erc_match = find_get_string(erc, node->did, node->uid);
55 if (erc_match)
56 {
57 struct Buffer *buf_str = buf_pool_get();
58 erc_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 ExpandoRenderCallback * find_get_string(const struct ExpandoRenderCallback *erc, int did, int uid)
Find a get_string() callback function.
Definition: helpers.c:69
const struct ExpandoRenderCallback * find_get_number(const struct ExpandoRenderCallback *erc, int did, int uid)
Find a get_number() callback function.
Definition: helpers.c:45
Shared code.
int node_condbool_render(const struct ExpandoNode *node, const struct ExpandoRenderCallback *erc, 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:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
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
get_string_t get_string
Definition: render.h:80
get_number_t get_number
Definition: render.h:81