NeoMutt  2024-04-25-1-g3de005
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
node_padding.c File Reference

Expando Node for Padding. More...

#include "config.h"
#include <stddef.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "gui/lib.h"
#include "node_padding.h"
#include "definition.h"
#include "node.h"
#include "node_condition.h"
#include "parse.h"
#include "render.h"
+ Include dependency graph for node_padding.c:

Go to the source code of this file.

Functions

struct NodePaddingPrivatenode_padding_private_new (enum ExpandoPadType pad_type)
 Create new Padding private data.
 
void node_padding_private_free (void **ptr)
 Free Padding private data - Implements ExpandoNode::ndata_free()
 
int pad_string (const struct ExpandoNode *node, struct Buffer *buf, int max_cols)
 Pad a buffer with a character.
 
int node_padding_render_eol (const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
 Render End-of-Line Padding - Implements ExpandoNode::render() -.
 
int node_padding_render_hard (const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
 Render Hard Padding - Implements ExpandoNode::render() -.
 
int node_padding_render_soft (const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
 Render Soft Padding - Implements ExpandoNode::render() -.
 
struct ExpandoNodenode_padding_new (enum ExpandoPadType pad_type, const char *start, const char *end)
 Creata new Padding ExpandoNode.
 
struct ExpandoNodenode_padding_parse (const char *str, const char **parsed_until, int did, int uid, ExpandoParserFlags flags, struct ExpandoParseError *error)
 Parse a Padding Expando - Implements ExpandoDefinition::parse() -.
 
void node_padding_repad (struct ExpandoNode **parent)
 Rearrange Padding in a tree of ExpandoNodes.
 

Detailed Description

Expando Node for Padding.

Authors
  • Tóth János
  • 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 node_padding.c.

Function Documentation

◆ node_padding_private_new()

struct NodePaddingPrivate * node_padding_private_new ( enum ExpandoPadType  pad_type)

Create new Padding private data.

Parameters
pad_typePadding type
Return values
ptrNew Padding private data

Definition at line 47 of file node_padding.c.

48{
49 struct NodePaddingPrivate *priv = mutt_mem_calloc(1, sizeof(struct NodePaddingPrivate));
50
51 priv->pad_type = pad_type;
52
53 return priv;
54}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
Private data for a Padding Node.
Definition: node_padding.h:64
enum ExpandoPadType pad_type
Padding type.
Definition: node_padding.h:65
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_padding_private_free()

void node_padding_private_free ( void **  ptr)

Free Padding private data - Implements ExpandoNode::ndata_free()

Parameters
ptrData to free

Definition at line 60 of file node_padding.c.

61{
62 if (!ptr || !*ptr)
63 return;
64
65 FREE(ptr);
66}
#define FREE(x)
Definition: memory.h:45
+ Here is the caller graph for this function:

◆ pad_string()

int pad_string ( const struct ExpandoNode node,
struct Buffer buf,
int  max_cols 
)

Pad a buffer with a character.

Parameters
nodeNode with padding type
bufBuffer to populate
max_colsNumber of screen columns available

Fill buf with the padding char (Node.start) to a maximum of max_cols screen cells.

Definition at line 76 of file node_padding.c.

77{
78 const int pad_len = node->end - node->start;
79 const int pad_cols = mutt_strnwidth(node->start, pad_len);
80 int total_cols = 0;
81
82 while (pad_cols <= max_cols)
83 {
84 buf_addstr_n(buf, node->start, pad_len);
85
86 max_cols -= pad_cols;
87 total_cols += pad_cols;
88 }
89
90 for (; (max_cols > 0); buf++, max_cols--)
91 {
92 buf_addch(buf, ' ');
93 total_cols++;
94 }
95
96 return total_cols;
97}
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
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:240
size_t mutt_strnwidth(const char *s, size_t n)
Measure a string's width in screen cells.
Definition: curs_lib.c:456
const char * end
End of string data.
Definition: node.h:80
const char * start
Start of string data.
Definition: node.h:79
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_padding_new()

struct ExpandoNode * node_padding_new ( enum ExpandoPadType  pad_type,
const char *  start,
const char *  end 
)

Creata new Padding ExpandoNode.

Parameters
pad_typePadding type
startStart of padding character
endEnd of padding character
Return values
ptrNew Padding ExpandoNode

Definition at line 198 of file node_padding.c.

200{
201 struct ExpandoNode *node = node_new();
202
203 node->type = ENT_PADDING;
204 node->start = start;
205 node->end = end;
206
207 switch (pad_type)
208 {
209 case EPT_FILL_EOL:
211 break;
212 case EPT_HARD_FILL:
214 break;
215 case EPT_SOFT_FILL:
217 break;
218 };
219
220 node->ndata = node_padding_private_new(pad_type);
222
223 return node;
224}
int node_padding_render_hard(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Render Hard Padding - Implements ExpandoNode::render() -.
Definition: node_padding.c:121
int node_padding_render_soft(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Render Soft Padding - Implements ExpandoNode::render() -.
Definition: node_padding.c:159
int node_padding_render_eol(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Render End-of-Line Padding - Implements ExpandoNode::render() -.
Definition: node_padding.c:102
struct ExpandoNode * node_new(void)
Create a new empty ExpandoNode.
Definition: node.c:39
@ ENT_PADDING
Padding: soft, hard, EOL.
Definition: node.h:40
void node_padding_private_free(void **ptr)
Free Padding private data - Implements ExpandoNode::ndata_free()
Definition: node_padding.c:60
struct NodePaddingPrivate * node_padding_private_new(enum ExpandoPadType pad_type)
Create new Padding private data.
Definition: node_padding.c:47
@ EPT_FILL_EOL
Fill to the end-of-line.
Definition: node_padding.h:44
@ EPT_SOFT_FILL
Soft-fill: right-hand-side will be truncated.
Definition: node_padding.h:46
@ EPT_HARD_FILL
Hard-fill: left-hand-side will be truncated.
Definition: node_padding.h:45
Basic Expando Node.
Definition: node.h:69
int(* render)(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Definition: node.h:96
void * ndata
Private node data.
Definition: node.h:82
enum ExpandoNodeType type
Type of Node, e.g. ENT_EXPANDO.
Definition: node.h:70
void(* ndata_free)(void **ptr)
Function to free the private node data.
Definition: node.h:83
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_padding_repad()

void node_padding_repad ( struct ExpandoNode **  parent)

Rearrange Padding in a tree of ExpandoNodes.

Parameters
parentParent Node

Definition at line 275 of file node_padding.c.

276{
277 if (!parent || !*parent)
278 return;
279
280 struct ExpandoNode *node = *parent;
281 struct ExpandoNode *prev = NULL;
282 for (; node; prev = node, node = node->next)
283 {
284 if (node->type == ENT_PADDING)
285 {
286 if (node != *parent)
287 ARRAY_SET(&node->children, ENP_LEFT, *parent); // First sibling
288
289 ARRAY_SET(&node->children, ENP_RIGHT, node->next); // Sibling after Padding
290
291 if (prev)
292 prev->next = NULL;
293 node->next = NULL;
294 *parent = node;
295 return;
296 }
297
298 if (node->type == ENT_CONDITION)
299 {
300 struct ExpandoNode **ptr = NULL;
301
302 ptr = ARRAY_GET(&node->children, ENC_TRUE);
304
305 ptr = ARRAY_GET(&node->children, ENC_FALSE);
307 }
308 }
309}
#define ARRAY_SET(head, idx, elem)
Set an element in the array.
Definition: array.h:123
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:109
@ ENT_CONDITION
True/False condition.
Definition: node.h:41
@ ENC_FALSE
Index of False Node.
@ ENC_TRUE
Index of True Node.
void node_padding_repad(struct ExpandoNode **parent)
Rearrange Padding in a tree of ExpandoNodes.
Definition: node_padding.c:275
@ ENP_LEFT
Index of Left-Hand Nodes.
Definition: node_padding.h:56
@ ENP_RIGHT
Index of Right-Hand Nodes.
Definition: node_padding.h:57
struct ExpandoNode * next
Linked list.
Definition: node.h:71
+ Here is the call graph for this function:
+ Here is the caller graph for this function: