NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
node_text.c File Reference

Expando Node for Text. More...

#include "config.h"
#include <stdbool.h>
#include <stddef.h>
#include "mutt/lib.h"
#include "node_text.h"
#include "format.h"
#include "node.h"
#include "render.h"
+ Include dependency graph for node_text.c:

Go to the source code of this file.

Functions

static int node_text_render (const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
 Render a Text Node - Implements ExpandoNode::render() -.
 
struct ExpandoNodenode_text_new (const char *text)
 Create a new Text ExpandoNode.
 
struct ExpandoNodenode_text_parse (const char *str, NodeTextTermFlags term_chars, const char **parsed_until)
 Extract a block of text.
 

Detailed Description

Expando Node for Text.

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

Function Documentation

◆ node_text_new()

struct ExpandoNode * node_text_new ( const char *  text)

Create a new Text ExpandoNode.

Parameters
textText to store
Return values
ptrNew Text ExpandoNode
Note
The text will be copied

Definition at line 59 of file node_text.c.

60{
61 struct ExpandoNode *node = node_new();
62
63 node->type = ENT_TEXT;
64 node->text = mutt_str_dup(text);
66
67 return node;
68}
static int node_text_render(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Render a Text Node - Implements ExpandoNode::render() -.
Definition: node_text.c:42
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
struct ExpandoNode * node_new(void)
Create a new empty ExpandoNode.
Definition: node.c:39
@ ENT_TEXT
Plain text.
Definition: node.h:38
Basic Expando Node.
Definition: node.h:67
int(* render)(const struct ExpandoNode *node, const struct ExpandoRenderData *rdata, struct Buffer *buf, int max_cols, void *data, MuttFormatFlags flags)
Definition: node.h:91
const char * text
Node-specific text.
Definition: node.h:73
enum ExpandoNodeType type
Type of Node, e.g. ENT_EXPANDO.
Definition: node.h:68
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_text_parse()

struct ExpandoNode * node_text_parse ( const char *  str,
NodeTextTermFlags  term_chars,
const char **  parsed_until 
)

Extract a block of text.

Parameters
[in]strString to parse
[in]term_charsTerminator characters, e.g. NTE_GREATER
[out]parsed_untilFirst character after parsed text
Return values
ptrNew Text ExpandoNode

Parse as much text as possible until the end of the line, or a terminator character is matched.

May return NULL if a terminator character is found immediately.

Note
\ before a character makes it literal
%% is interpreted as a literal % character
'' is always special

Definition at line 86 of file node_text.c.

88{
89 if (!str || (str[0] == '\0') || !parsed_until)
90 return NULL;
91
92 struct Buffer *text = buf_pool_get();
93
94 while (str[0] != '\0')
95 {
96 if (str[0] == '\\') // Literal character
97 {
98 if (str[1] == '\0')
99 {
100 buf_addch(text, '\\');
101 str++;
102 break;
103 }
104
105 buf_addch(text, str[1]);
106 str += 2;
107 continue;
108 }
109
110 if ((str[0] == '%') && (str[1] == '%')) // Literal %
111 {
112 buf_addch(text, '%');
113 str += 2;
114 continue;
115 }
116
117 if (str[0] == '%') // '%' is always special
118 break;
119
120 if ((str[0] == '&') && (term_chars & NTE_AMPERSAND))
121 break;
122
123 if ((str[0] == '>') && (term_chars & NTE_GREATER))
124 break;
125
126 if ((str[0] == '?') && (term_chars & NTE_QUESTION))
127 break;
128
129 buf_addch(text, str[0]); // Plain text
130 str++;
131 }
132
133 *parsed_until = str; // First unused character
134
135 struct ExpandoNode *node = NULL;
136 if (!buf_is_empty(text))
138
140
141 return node;
142}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:291
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:241
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
struct ExpandoNode * node_text_new(const char *text)
Create a new Text ExpandoNode.
Definition: node_text.c:59
#define NTE_QUESTION
'?' Question mark
Definition: node_text.h:36
#define NTE_GREATER
'>' Greater than
Definition: node_text.h:35
#define NTE_AMPERSAND
'&' Ampersand
Definition: node_text.h:34
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
String manipulation buffer.
Definition: buffer.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function: