NeoMutt  2025-12-11-435-g4ac674
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
stailq.c
Go to the documentation of this file.
1
30
36
37#include "config.h"
38#include "mutt/lib.h"
39#include "core/lib.h"
40#include "stailq.h"
41#include "parse/lib.h"
42
52enum CommandResult parse_stailq(const struct Command *cmd, struct Buffer *line,
53 struct ListHead *list,
54 const struct ParseContext *pc, struct ParseError *pe)
55{
56 struct Buffer *err = pe->message;
57
58 if (!MoreArgs(line))
59 {
60 buf_printf(err, _("%s: too few arguments"), cmd->name);
61 return MUTT_CMD_WARNING;
62 }
63
64 struct Buffer *token = buf_pool_get();
65
66 do
67 {
69 add_to_stailq(list, buf_string(token));
70 } while (MoreArgs(line));
71
72 buf_pool_release(&token);
73 return MUTT_CMD_SUCCESS;
74}
75
85enum CommandResult parse_unstailq(const struct Command *cmd,
86 struct Buffer *line, struct ListHead *list,
87 const struct ParseContext *pc, struct ParseError *pe)
88{
89 struct Buffer *err = pe->message;
90
91 if (!MoreArgs(line))
92 {
93 buf_printf(err, _("%s: too few arguments"), cmd->name);
94 return MUTT_CMD_WARNING;
95 }
96
97 struct Buffer *token = buf_pool_get();
98
99 do
100 {
102 /* Check for deletion of entire list */
103 if (mutt_str_equal(buf_string(token), "*"))
104 {
105 mutt_list_free(list);
106 break;
107 }
108 remove_from_stailq(list, buf_string(token));
109 } while (MoreArgs(line));
110
111 buf_pool_release(&token);
112 return MUTT_CMD_SUCCESS;
113}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
CommandResult
Error codes for command_t parse functions.
Definition command.h:37
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition command.h:40
@ MUTT_CMD_WARNING
Warning: Help given to the user.
Definition command.h:39
Convenience wrapper for the core headers.
int parse_extract_token(struct Buffer *dest, struct Buffer *line, TokenFlags flags)
Extract one token from a string.
Definition extract.c:49
#define MoreArgs(buf)
Definition extract.h:31
#define TOKEN_NO_FLAGS
No flags are set.
Definition extract.h:45
enum CommandResult parse_stailq(const struct Command *cmd, struct Buffer *line, struct ListHead *list, const struct ParseContext *pc, struct ParseError *pe)
Parse a list command - Implements Command::parse() -.
Definition stailq.c:52
enum CommandResult parse_unstailq(const struct Command *cmd, struct Buffer *line, struct ListHead *list, const struct ParseContext *pc, struct ParseError *pe)
Parse an unlist command - Implements Command::parse() -.
Definition stailq.c:85
void remove_from_stailq(struct ListHead *head, const char *str)
Remove an item, matching a string, from a List.
Definition list.c:341
void add_to_stailq(struct ListHead *head, const char *str)
Add a string to a list.
Definition list.c:316
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition list.c:123
Convenience wrapper for the library headers.
#define _(a)
Definition message.h:28
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:662
Text parsing functions.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
Parse Stailq Commands.
String manipulation buffer.
Definition buffer.h:36
const char * name
Name of the Command.
Definition command.h:159
Context for config parsing (history/backtrace)
Definition pcontext.h:34
Detailed error information from config parsing.
Definition perror.h:34
struct Buffer * message
Error message.
Definition perror.h:35