NeoMutt  2019-11-11
Teaching an old dog new tricks
DOXYGEN
buffer.h
Go to the documentation of this file.
1 
24 #ifndef MUTT_LIB_BUFFER_H
25 #define MUTT_LIB_BUFFER_H
26 
27 #include <stddef.h>
28 #include <stdbool.h>
29 
33 struct Buffer
34 {
35  char *data;
36  char *dptr;
37  size_t dsize;
38 };
39 
40 /* Convert a buffer to a const char * "string" */
41 #define mutt_b2s(buf) ((buf)->data ? (const char *) (buf)->data : "")
42 
43 #define MoreArgs(buf) (*(buf)->dptr && (*(buf)->dptr != ';') && (*(buf)->dptr != '#'))
44 
45 void mutt_buffer_alloc (struct Buffer *buf, size_t size);
46 void mutt_buffer_dealloc (struct Buffer *buf);
47 void mutt_buffer_fix_dptr (struct Buffer *buf);
48 struct Buffer *mutt_buffer_init (struct Buffer *buf);
49 bool mutt_buffer_is_empty (const struct Buffer *buf);
50 size_t mutt_buffer_len (const struct Buffer *buf);
51 struct Buffer mutt_buffer_make (size_t size);
52 void mutt_buffer_reset (struct Buffer *buf);
53 char * mutt_buffer_strdup (struct Buffer *buf);
54 
55 // Functions that APPEND to a Buffer
56 size_t mutt_buffer_addch (struct Buffer *buf, char c);
57 size_t mutt_buffer_addstr (struct Buffer *buf, const char *s);
58 size_t mutt_buffer_addstr_n (struct Buffer *buf, const char *s, size_t len);
59 int mutt_buffer_add_printf (struct Buffer *buf, const char *fmt, ...);
60 
61 // Functions that OVERWRITE a Buffer
62 size_t mutt_buffer_concat_path (struct Buffer *buf, const char *dir, const char *fname);
63 size_t mutt_buffer_concatn_path (struct Buffer *dst, const char *dir, size_t dirlen, const char *fname, size_t fnamelen);
64 size_t mutt_buffer_copy (struct Buffer *dst, const struct Buffer *src);
65 int mutt_buffer_printf (struct Buffer *buf, const char *fmt, ...);
66 size_t mutt_buffer_strcpy (struct Buffer *buf, const char *s);
67 size_t mutt_buffer_strcpy_n (struct Buffer *buf, const char *s, size_t len);
68 size_t mutt_buffer_substrcpy (struct Buffer *buf, const char *beg, const char *end);
69 
70 #endif /* MUTT_LIB_BUFFER_H */
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:356
String manipulation buffer.
Definition: buffer.h:33
size_t mutt_buffer_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer&#39;s contents to another Buffer.
Definition: buffer.c:445
void mutt_buffer_alloc(struct Buffer *buf, size_t size)
Make sure a buffer can store at least new_size bytes.
Definition: buffer.c:265
int mutt_buffer_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:203
size_t mutt_buffer_substrcpy(struct Buffer *buf, const char *beg, const char *end)
Copy a partial string into a Buffer.
Definition: buffer.c:342
size_t dsize
Length of data.
Definition: buffer.h:37
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
size_t mutt_buffer_strcpy_n(struct Buffer *buf, const char *s, size_t len)
Copy a string into a Buffer.
Definition: buffer.c:327
size_t mutt_buffer_addstr_n(struct Buffer *buf, const char *s, size_t len)
Add a string to a Buffer, expanding it if necessary.
Definition: buffer.c:99
char * dptr
Current read/write position.
Definition: buffer.h:36
size_t mutt_buffer_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
Definition: buffer.c:374
char * data
Pointer to data.
Definition: buffer.h:35
void mutt_buffer_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition: buffer.c:181
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:240
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
size_t mutt_buffer_concatn_path(struct Buffer *dst, const char *dir, size_t dirlen, const char *fname, size_t fnamelen)
Join a directory name and a filename.
Definition: buffer.c:411
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:252
char * mutt_buffer_strdup(struct Buffer *buf)
Copy a Buffer&#39;s string.
Definition: buffer.c:432