};
#endif
-static struct Buffer *LastDir = NULL;
-static struct Buffer *LastDirBackup = NULL;
+static struct Buffer LastDir = { 0 };
+static struct Buffer LastDirBackup = { 0 };
+
+/**
+ * init_lastdir - Initialise the browser directories
+ *
+ * These keep track of where the browser used to be looking.
+ */
+static void init_lastdir(void)
+{
+ static bool done = false;
+ if (!done)
+ {
+ mutt_buffer_alloc(&LastDir, PATH_MAX);
+ mutt_buffer_alloc(&LastDirBackup, PATH_MAX);
+ done = true;
+ }
+}
/**
* mutt_browser_cleanup - Clean up working Buffers
*/
void mutt_browser_cleanup(void)
{
- mutt_buffer_free(&LastDir);
- mutt_buffer_free(&LastDirBackup);
+ mutt_buffer_dealloc(&LastDir);
+ mutt_buffer_dealloc(&LastDirBackup);
}
/**
{
struct Buffer *path = mutt_buffer_pool_get();
menu->is_mailbox_list = false;
- mutt_buffer_strcpy(path, mutt_b2s(LastDir));
+ mutt_buffer_strcpy(path, mutt_b2s(&LastDir));
mutt_buffer_pretty_mailbox(path);
#ifdef USE_IMAP
if (state->imap_browse && C_ImapListSubscribed)
* The goal is to highlight the good directory if LastDir is the parent dir
* of LastDirBackup (this occurs mostly when one hit "../"). It should also work
* properly when the user is in examine_mailboxes-mode. */
- if (mutt_str_startswith(mutt_b2s(LastDirBackup), mutt_b2s(LastDir), CASE_MATCH))
+ if (mutt_str_startswith(mutt_b2s(&LastDirBackup), mutt_b2s(&LastDir), CASE_MATCH))
{
char target_dir[PATH_MAX] = { 0 };
#ifdef USE_IMAP
/* Check what kind of dir LastDirBackup is. */
- if (imap_path_probe(mutt_b2s(LastDirBackup), NULL) == MUTT_IMAP)
+ if (imap_path_probe(mutt_b2s(&LastDirBackup), NULL) == MUTT_IMAP)
{
- mutt_str_strfcpy(target_dir, mutt_b2s(LastDirBackup), sizeof(target_dir));
+ mutt_str_strfcpy(target_dir, mutt_b2s(&LastDirBackup), sizeof(target_dir));
imap_clean_path(target_dir, sizeof(target_dir));
}
else
#endif
- mutt_str_strfcpy(target_dir, strrchr(mutt_b2s(LastDirBackup), '/') + 1,
+ mutt_str_strfcpy(target_dir, strrchr(mutt_b2s(&LastDirBackup), '/') + 1,
sizeof(target_dir));
/* If we get here, it means that LastDir is the parent directory of
static int file_tag(struct Menu *menu, int sel, int act)
{
struct FolderFile *ff = &(((struct FolderFile *) menu->data)[sel]);
- if (S_ISDIR(ff->mode) || (S_ISLNK(ff->mode) && link_is_dir(mutt_b2s(LastDir), ff->name)))
+ if (S_ISDIR(ff->mode) || (S_ISLNK(ff->mode) && link_is_dir(mutt_b2s(&LastDir), ff->name)))
{
mutt_error(_("Can't attach a directory"));
return 0;
*/
void mutt_browser_select_dir(const char *f)
{
- if (!LastDir)
- {
- LastDir = mutt_buffer_alloc(PATH_MAX);
- LastDirBackup = mutt_buffer_alloc(PATH_MAX);
- }
+ init_lastdir();
- mutt_buffer_strcpy(LastDirBackup, f);
+ mutt_buffer_strcpy(&LastDirBackup, f);
/* Method that will fetch the parent path depending on the type of the path. */
char buf[PATH_MAX];
- mutt_get_parent_path(mutt_b2s(LastDirBackup), buf, sizeof(buf));
- mutt_buffer_strcpy(LastDir, buf);
+ mutt_get_parent_path(mutt_b2s(&LastDirBackup), buf, sizeof(buf));
+ mutt_buffer_strcpy(&LastDir, buf);
}
/**
struct Buffer *buf = mutt_buffer_pool_get();
struct Buffer *prefix = mutt_buffer_pool_get();
- if (!LastDir)
- {
- LastDir = mutt_buffer_alloc(PATH_MAX);
- LastDirBackup = mutt_buffer_alloc(PATH_MAX);
- }
+ init_lastdir();
#ifdef USE_NNTP
if (OptNews)
state.imap_browse = true;
if (imap_browse(mutt_b2s(file), &state) == 0)
{
- mutt_buffer_strcpy(LastDir, state.folder);
+ mutt_buffer_strcpy(&LastDir, state.folder);
browser_sort(&state);
}
}
if (i > 0)
{
if ((mutt_b2s(file))[0] == '/')
- mutt_buffer_strcpy_n(LastDir, mutt_b2s(file), i);
+ mutt_buffer_strcpy_n(&LastDir, mutt_b2s(file), i);
else
{
- mutt_path_getcwd(LastDir);
- mutt_buffer_addch(LastDir, '/');
- mutt_buffer_addstr_n(LastDir, mutt_b2s(file), i);
+ mutt_path_getcwd(&LastDir);
+ mutt_buffer_addch(&LastDir, '/');
+ mutt_buffer_addstr_n(&LastDir, mutt_b2s(file), i);
}
}
else
{
if ((mutt_b2s(file))[0] == '/')
- mutt_buffer_strcpy(LastDir, "/");
+ mutt_buffer_strcpy(&LastDir, "/");
else
- mutt_path_getcwd(LastDir);
+ mutt_path_getcwd(&LastDir);
}
if ((i <= 0) && (mutt_b2s(file)[0] != '/'))
* meaning only with sort methods SUBJECT/DESC for now. */
if (CurrentFolder)
{
- if (mutt_b2s(LastDir)[0] == '\0')
+ if (mutt_b2s(&LastDir)[0] == '\0')
{
/* If browsing in "local"-mode, than we chose to define LastDir to
* MailDir */
case MUTT_MH:
case MUTT_MMDF:
if (C_Folder)
- mutt_buffer_strcpy(LastDir, C_Folder);
+ mutt_buffer_strcpy(&LastDir, C_Folder);
else if (C_Spoolfile)
mutt_browser_select_dir(C_Spoolfile);
break;
break;
}
}
- else if (mutt_str_strcmp(CurrentFolder, mutt_b2s(LastDirBackup)) != 0)
+ else if (mutt_str_strcmp(CurrentFolder, mutt_b2s(&LastDirBackup)) != 0)
{
mutt_browser_select_dir(CurrentFolder);
}
/* When browser tracking feature is disabled, clear LastDirBackup */
if (!browser_track)
- mutt_buffer_reset(LastDirBackup);
+ mutt_buffer_reset(&LastDirBackup);
}
#ifdef USE_IMAP
- if (!mailbox && (imap_path_probe(mutt_b2s(LastDir), NULL) == MUTT_IMAP))
+ if (!mailbox && (imap_path_probe(mutt_b2s(&LastDir), NULL) == MUTT_IMAP))
{
init_state(&state, NULL);
state.imap_browse = true;
- imap_browse(mutt_b2s(LastDir), &state);
+ imap_browse(mutt_b2s(&LastDir), &state);
browser_sort(&state);
}
else
#endif
{
- size_t i = mutt_buffer_len(LastDir);
- while ((i > 0) && (mutt_b2s(LastDir)[--i] == '/'))
- LastDir->data[i] = '\0';
- mutt_buffer_fix_dptr(LastDir);
- if (mutt_b2s(LastDir)[0] == '\0')
- mutt_path_getcwd(LastDir);
+ size_t i = mutt_buffer_len(&LastDir);
+ while ((i > 0) && (mutt_b2s(&LastDir)[--i] == '/'))
+ LastDir.data[i] = '\0';
+ mutt_buffer_fix_dptr(&LastDir);
+ if (mutt_b2s(&LastDir)[0] == '\0')
+ mutt_path_getcwd(&LastDir);
}
}
if (!state.imap_browse)
#endif
{
- if (examine_directory(NULL, &state, mutt_b2s(LastDir), mutt_b2s(prefix)) == -1)
+ if (examine_directory(NULL, &state, mutt_b2s(&LastDir), mutt_b2s(prefix)) == -1)
goto bail;
}
menu = mutt_menu_new(MENU_FOLDER);
if (S_ISDIR(state.entry[menu->current].mode) ||
(S_ISLNK(state.entry[menu->current].mode) &&
- link_is_dir(mutt_b2s(LastDir), state.entry[menu->current].name))
+ link_is_dir(mutt_b2s(&LastDir), state.entry[menu->current].name))
#ifdef USE_IMAP
|| state.entry[menu->current].inferiors
#endif
#endif
else
{
- mutt_buffer_concat_path(buf, mutt_b2s(LastDir),
+ mutt_buffer_concat_path(buf, mutt_b2s(&LastDir),
state.entry[menu->current].name);
}
)
{
/* save the old directory */
- mutt_buffer_strcpy(OldLastDir, mutt_b2s(LastDir));
+ mutt_buffer_strcpy(OldLastDir, mutt_b2s(&LastDir));
if (mutt_str_strcmp(state.entry[menu->current].name, "..") == 0)
{
- size_t lastdirlen = mutt_buffer_len(LastDir);
+ size_t lastdirlen = mutt_buffer_len(&LastDir);
if ((lastdirlen > 1) &&
- (mutt_str_strcmp("..", mutt_b2s(LastDir) + lastdirlen - 2) == 0))
+ (mutt_str_strcmp("..", mutt_b2s(&LastDir) + lastdirlen - 2) == 0))
{
- mutt_buffer_addstr(LastDir, "/..");
+ mutt_buffer_addstr(&LastDir, "/..");
}
else
{
char *p = NULL;
if (lastdirlen > 1)
- p = strrchr(mutt_b2s(LastDir) + 1, '/');
+ p = strrchr(mutt_b2s(&LastDir) + 1, '/');
if (p)
{
*p = '\0';
- mutt_buffer_fix_dptr(LastDir);
+ mutt_buffer_fix_dptr(&LastDir);
}
else
{
- if (mutt_b2s(LastDir)[0] == '/')
- mutt_buffer_strcpy(LastDir, "/");
+ if (mutt_b2s(&LastDir)[0] == '/')
+ mutt_buffer_strcpy(&LastDir, "/");
else
- mutt_buffer_addstr(LastDir, "/..");
+ mutt_buffer_addstr(&LastDir, "/..");
}
}
}
else if (mailbox)
{
- mutt_buffer_strcpy(LastDir, state.entry[menu->current].name);
- mutt_buffer_expand_path(LastDir);
+ mutt_buffer_strcpy(&LastDir, state.entry[menu->current].name);
+ mutt_buffer_expand_path(&LastDir);
}
#ifdef USE_IMAP
else if (state.imap_browse)
{
- mutt_buffer_strcpy(LastDir, state.entry[menu->current].name);
+ mutt_buffer_strcpy(&LastDir, state.entry[menu->current].name);
/* tack on delimiter here */
/* special case "" needs no delimiter */
struct Url *url = url_parse(state.entry[menu->current].name);
if (url->path && (state.entry[menu->current].delim != '\0'))
{
- mutt_buffer_addch(LastDir, state.entry[menu->current].delim);
+ mutt_buffer_addch(&LastDir, state.entry[menu->current].delim);
}
url_free(&url);
}
#endif
else
{
- mutt_buffer_concat_path(tmp, mutt_b2s(LastDir),
+ mutt_buffer_concat_path(tmp, mutt_b2s(&LastDir),
state.entry[menu->current].name);
- mutt_buffer_strcpy(LastDir, mutt_b2s(tmp));
+ mutt_buffer_strcpy(&LastDir, mutt_b2s(tmp));
}
destroy_state(&state);
{
init_state(&state, NULL);
state.imap_browse = true;
- imap_browse(mutt_b2s(LastDir), &state);
+ imap_browse(mutt_b2s(&LastDir), &state);
browser_sort(&state);
menu->data = state.entry;
}
else
#endif
{
- if (examine_directory(menu, &state, mutt_b2s(LastDir), mutt_b2s(prefix)) == -1)
+ if (examine_directory(menu, &state, mutt_b2s(&LastDir), mutt_b2s(prefix)) == -1)
{
/* try to restore the old values */
- mutt_buffer_strcpy(LastDir, mutt_b2s(OldLastDir));
- if (examine_directory(menu, &state, mutt_b2s(LastDir), mutt_b2s(prefix)) == -1)
+ mutt_buffer_strcpy(&LastDir, mutt_b2s(OldLastDir));
+ if (examine_directory(menu, &state, mutt_b2s(&LastDir),
+ mutt_b2s(prefix)) == -1)
{
- mutt_buffer_strcpy(LastDir, NONULL(HomeDir));
+ mutt_buffer_strcpy(&LastDir, NONULL(HomeDir));
goto bail;
}
}
/* resolve paths navigated from GUI */
- if (mutt_path_realpath(LastDir->data) == 0)
+ if (mutt_path_realpath(LastDir.data) == 0)
break;
}
mutt_buffer_strcpy(file, state.entry[menu->current].name);
#endif
else
- mutt_buffer_concat_path(file, mutt_b2s(LastDir),
+ mutt_buffer_concat_path(file, mutt_b2s(&LastDir),
state.entry[menu->current].name);
/* fallthrough */
struct FolderFile ff = state.entry[i];
if (ff.tagged)
{
- mutt_buffer_concat_path(tmp, mutt_b2s(LastDir), ff.name);
+ mutt_buffer_concat_path(tmp, mutt_b2s(&LastDir), ff.name);
mutt_buffer_expand_path(tmp);
tfiles[j++] = mutt_str_strdup(mutt_b2s(tmp));
}
break;
}
- if (imap_mailbox_create(mutt_b2s(LastDir)) == 0)
+ if (imap_mailbox_create(mutt_b2s(&LastDir)) == 0)
{
/* TODO: find a way to detect if the new folder would appear in
* this window, and insert it without starting over. */
destroy_state(&state);
init_state(&state, NULL);
state.imap_browse = true;
- imap_browse(mutt_b2s(LastDir), &state);
+ imap_browse(mutt_b2s(&LastDir), &state);
browser_sort(&state);
menu->data = state.entry;
browser_highlight_default(&state, menu);
destroy_state(&state);
init_state(&state, NULL);
state.imap_browse = true;
- imap_browse(mutt_b2s(LastDir), &state);
+ imap_browse(mutt_b2s(&LastDir), &state);
browser_sort(&state);
menu->data = state.entry;
browser_highlight_default(&state, menu);
break;
#endif
- mutt_buffer_strcpy(buf, mutt_b2s(LastDir));
+ mutt_buffer_strcpy(buf, mutt_b2s(&LastDir));
#ifdef USE_IMAP
if (!state.imap_browse)
#endif
{
/* add '/' at the end of the directory name if not already there */
size_t len = mutt_buffer_len(buf);
- if ((len > 0) && (mutt_b2s(LastDir)[len - 1] != '/'))
+ if ((len > 0) && (mutt_b2s(&LastDir)[len - 1] != '/'))
mutt_buffer_addch(buf, '/');
}
#ifdef USE_IMAP
if (imap_path_probe(mutt_b2s(buf), NULL) == MUTT_IMAP)
{
- mutt_buffer_strcpy(LastDir, mutt_b2s(buf));
+ mutt_buffer_strcpy(&LastDir, mutt_b2s(buf));
destroy_state(&state);
init_state(&state, NULL);
state.imap_browse = true;
- imap_browse(mutt_b2s(LastDir), &state);
+ imap_browse(mutt_b2s(&LastDir), &state);
browser_sort(&state);
menu->data = state.entry;
browser_highlight_default(&state, menu);
{
/* in case dir is relative, make it relative to LastDir,
* not current working dir */
- mutt_buffer_concat_path(tmp, mutt_b2s(LastDir), mutt_b2s(buf));
+ mutt_buffer_concat_path(tmp, mutt_b2s(&LastDir), mutt_b2s(buf));
mutt_buffer_strcpy(buf, mutt_b2s(tmp));
}
/* Resolve path from <chdir>
{
destroy_state(&state);
if (examine_directory(menu, &state, mutt_b2s(buf), mutt_b2s(prefix)) == 0)
- mutt_buffer_strcpy(LastDir, mutt_b2s(buf));
+ mutt_buffer_strcpy(&LastDir, mutt_b2s(buf));
else
{
mutt_error(_("Error scanning directory"));
- if (examine_directory(menu, &state, mutt_b2s(LastDir),
+ if (examine_directory(menu, &state, mutt_b2s(&LastDir),
mutt_b2s(prefix)) == -1)
{
goto bail;
{
init_state(&state, NULL);
state.imap_browse = true;
- imap_browse(mutt_b2s(LastDir), &state);
+ imap_browse(mutt_b2s(&LastDir), &state);
browser_sort(&state);
menu->data = state.entry;
init_menu(&state, menu, title, sizeof(title), mailbox);
}
else
#endif
- if (examine_directory(menu, &state, mutt_b2s(LastDir), NULL) == 0)
+ if (examine_directory(menu, &state, mutt_b2s(&LastDir), NULL) == 0)
init_menu(&state, menu, title, sizeof(title), mailbox);
else
{
if (C_Folder)
{
mutt_debug(LL_DEBUG3, "= hit! Folder: %s, LastDir: %s\n", C_Folder,
- mutt_b2s(LastDir));
+ mutt_b2s(&LastDir));
if (goto_swapper[0] == '\0')
{
- if (mutt_str_strcmp(mutt_b2s(LastDir), C_Folder) != 0)
+ if (mutt_str_strcmp(mutt_b2s(&LastDir), C_Folder) != 0)
{
/* Stores into goto_swapper LastDir, and swaps to C_Folder */
- mutt_str_strfcpy(goto_swapper, mutt_b2s(LastDir), sizeof(goto_swapper));
- mutt_buffer_strcpy(LastDirBackup, mutt_b2s(LastDir));
- mutt_buffer_strcpy(LastDir, C_Folder);
+ mutt_str_strfcpy(goto_swapper, mutt_b2s(&LastDir), sizeof(goto_swapper));
+ mutt_buffer_strcpy(&LastDirBackup, mutt_b2s(&LastDir));
+ mutt_buffer_strcpy(&LastDir, C_Folder);
}
}
else
{
- mutt_buffer_strcpy(LastDirBackup, mutt_b2s(LastDir));
- mutt_buffer_strcpy(LastDir, goto_swapper);
+ mutt_buffer_strcpy(&LastDirBackup, mutt_b2s(&LastDir));
+ mutt_buffer_strcpy(&LastDir, goto_swapper);
goto_swapper[0] = '\0';
}
}
examine_mailboxes(menu, &state);
}
#ifdef USE_IMAP
- else if (imap_path_probe(mutt_b2s(LastDir), NULL) == MUTT_IMAP)
+ else if (imap_path_probe(mutt_b2s(&LastDir), NULL) == MUTT_IMAP)
{
init_state(&state, NULL);
state.imap_browse = true;
- imap_browse(mutt_b2s(LastDir), &state);
+ imap_browse(mutt_b2s(&LastDir), &state);
browser_sort(&state);
menu->data = state.entry;
}
#endif
- else if (examine_directory(menu, &state, mutt_b2s(LastDir), mutt_b2s(prefix)) == -1)
+ else if (examine_directory(menu, &state, mutt_b2s(&LastDir), mutt_b2s(prefix)) == -1)
goto bail;
init_menu(&state, menu, title, sizeof(title), mailbox);
break;
break;
case OP_BROWSER_NEW_FILE:
- mutt_buffer_printf(buf, "%s/", mutt_b2s(LastDir));
+ mutt_buffer_printf(buf, "%s/", mutt_b2s(&LastDir));
/* buf comes from the buffer pool, so defaults to size 1024 */
if (mutt_get_field(_("New file name: "), buf->data, buf->dsize, MUTT_FILE) == 0)
{
#endif
if (S_ISDIR(state.entry[menu->current].mode) ||
(S_ISLNK(state.entry[menu->current].mode) &&
- link_is_dir(mutt_b2s(LastDir), state.entry[menu->current].name)))
+ link_is_dir(mutt_b2s(&LastDir), state.entry[menu->current].name)))
{
mutt_error(_("Can't view a directory"));
break;
{
char buf2[PATH_MAX];
- mutt_path_concat(buf2, mutt_b2s(LastDir),
+ mutt_path_concat(buf2, mutt_b2s(&LastDir),
state.entry[menu->current].name, sizeof(buf2));
struct Body *b = mutt_make_file_attach(buf2);
if (b)
if ((mutt_get_field(":", buf, sizeof(buf), MUTT_COMMAND) != 0) || !buf[0])
return;
- struct Buffer *err = mutt_buffer_alloc(256);
- struct Buffer *token = mutt_buffer_alloc(256);
+ struct Buffer err = { 0 };
+ mutt_buffer_alloc(&err, 256);
+ struct Buffer token = { 0 };
+ mutt_buffer_alloc(&token, 256);
/* check if buf is a valid icommand, else fall back quietly to parse_rc_lines */
- enum CommandResult rc = mutt_parse_icommand(buf, err);
- if (!mutt_buffer_is_empty(err))
+ enum CommandResult rc = mutt_parse_icommand(buf, &err);
+ if (!mutt_buffer_is_empty(&err))
{
/* since errbuf could potentially contain printf() sequences in it,
* we must call mutt_error() in this fashion so that vsprintf()
* doesn't expect more arguments that we passed */
if (rc == MUTT_CMD_ERROR)
- mutt_error("%s", err->data);
+ mutt_error("%s", err.data);
else
- mutt_warning("%s", err->data);
+ mutt_warning("%s", err.data);
}
else if (rc != MUTT_CMD_SUCCESS)
{
- rc = mutt_parse_rc_line(buf, token, err);
- if (!mutt_buffer_is_empty(err))
+ rc = mutt_parse_rc_line(buf, &token, &err);
+ if (!mutt_buffer_is_empty(&err))
{
if (rc == MUTT_CMD_SUCCESS) /* command succeeded with message */
- mutt_message("%s", err->data);
+ mutt_message("%s", err.data);
else /* error executing command */
- mutt_error("%s", err->data);
+ mutt_error("%s", err.data);
}
}
/* else successful command */
- mutt_buffer_free(&token);
- mutt_buffer_free(&err);
+ mutt_buffer_dealloc(&token);
+ mutt_buffer_dealloc(&err);
}
/**
/* We will uncompress to /tmp */
mutt_mktemp(tmp, sizeof(tmp));
- mutt_buffer_strcpy(m->pathbuf, tmp);
+ mutt_buffer_strcpy(&m->pathbuf, tmp);
FILE *fp = mutt_file_fopen(mailbox_path(m), "w");
if (!fp)
bool result = true;
- struct Buffer *value = mutt_buffer_alloc(256);
- struct Buffer *initial = mutt_buffer_alloc(256);
- struct Buffer *tmp = mutt_buffer_alloc(256);
+ struct Buffer value = { 0 };
+ mutt_buffer_alloc(&value, 256);
+ struct Buffer initial = { 0 };
+ mutt_buffer_alloc(&initial, 256);
+ struct Buffer tmp = { 0 };
+ mutt_buffer_alloc(&tmp, 256);
for (size_t i = 0; list[i]; i++)
{
- mutt_buffer_reset(value);
- mutt_buffer_reset(initial);
+ mutt_buffer_reset(&value);
+ mutt_buffer_reset(&initial);
he = list[i];
const int type = DTYPE(he->type);
if ((flags & CS_DUMP_ONLY_CHANGED) || !(flags & CS_DUMP_HIDE_VALUE) ||
(flags & CS_DUMP_SHOW_DEFAULTS))
{
- int rc = cs_he_string_get(cs, he, value);
+ int rc = cs_he_string_get(cs, he, &value);
if (CSR_RESULT(rc) != CSR_SUCCESS)
{
result = false; /* LCOV_EXCL_LINE */
const struct ConfigDef *cdef = he->data;
if ((type == DT_STRING) && IS_SENSITIVE(*cdef) &&
- (flags & CS_DUMP_HIDE_SENSITIVE) && !mutt_buffer_is_empty(value))
+ (flags & CS_DUMP_HIDE_SENSITIVE) && !mutt_buffer_is_empty(&value))
{
- mutt_buffer_reset(value);
- mutt_buffer_addstr(value, "***");
+ mutt_buffer_reset(&value);
+ mutt_buffer_addstr(&value, "***");
}
- if (IS_PATH(he) && (value->data[0] == '/'))
- mutt_pretty_mailbox(value->data, value->dsize);
+ if (IS_PATH(he) && (value.data[0] == '/'))
+ mutt_pretty_mailbox(value.data, value.dsize);
if ((type != DT_BOOL) && (type != DT_NUMBER) && (type != DT_LONG) &&
(type != DT_QUAD) && !(flags & CS_DUMP_NO_ESCAPING))
{
- mutt_buffer_reset(tmp);
- pretty_var(value->data, tmp);
- mutt_buffer_strcpy(value, tmp->data);
+ mutt_buffer_reset(&tmp);
+ pretty_var(value.data, &tmp);
+ mutt_buffer_strcpy(&value, tmp.data);
}
}
/* If necessary, get the default value */
if (flags & (CS_DUMP_ONLY_CHANGED | CS_DUMP_SHOW_DEFAULTS))
{
- int rc = cs_he_initial_get(cs, he, initial);
+ int rc = cs_he_initial_get(cs, he, &initial);
if (CSR_RESULT(rc) != CSR_SUCCESS)
{
result = false; /* LCOV_EXCL_LINE */
}
if (IS_PATH(he) && !(he->type & DT_MAILBOX))
- mutt_pretty_mailbox(initial->data, initial->dsize);
+ mutt_pretty_mailbox(initial.data, initial.dsize);
if ((type != DT_BOOL) && (type != DT_NUMBER) && (type != DT_LONG) &&
(type != DT_QUAD) && !(flags & CS_DUMP_NO_ESCAPING))
{
- mutt_buffer_reset(tmp);
- pretty_var(initial->data, tmp);
- mutt_buffer_strcpy(initial, tmp->data);
+ mutt_buffer_reset(&tmp);
+ pretty_var(initial.data, &tmp);
+ mutt_buffer_strcpy(&initial, tmp.data);
}
}
}
- dump_config_neo(cs, he, value, initial, flags, fp);
+ dump_config_neo(cs, he, &value, &initial, flags, fp);
}
FREE(&list);
- mutt_buffer_free(&value);
- mutt_buffer_free(&initial);
- mutt_buffer_free(&tmp);
+ mutt_buffer_dealloc(&value);
+ mutt_buffer_dealloc(&initial);
+ mutt_buffer_dealloc(&tmp);
return result;
}
if (!cs || !vars)
return false;
- struct Buffer *err = mutt_buffer_new();
+ struct Buffer err = { 0 };
bool rc = true;
for (size_t i = 0; vars[i].name; i++)
{
- if (!reg_one_var(cs, &vars[i], err))
+ if (!reg_one_var(cs, &vars[i], &err))
{
- mutt_debug(LL_DEBUG1, "%s\n", mutt_b2s(err));
+ mutt_debug(LL_DEBUG1, "%s\n", mutt_b2s(&err));
rc = false;
}
}
- mutt_buffer_free(&err);
+ mutt_buffer_dealloc(&err);
return rc;
}
{
struct Mailbox *m = mutt_mem_calloc(1, sizeof(struct Mailbox));
- m->pathbuf = mutt_buffer_new();
+ mutt_buffer_init(&m->pathbuf);
m->notify = notify_new(m, NT_MAILBOX);
return m;
if (m->mdata && m->free_mdata)
m->free_mdata(&m->mdata);
- mutt_buffer_free(&m->pathbuf);
+ mutt_buffer_dealloc(&m->pathbuf);
FREE(&m->name);
FREE(&m->realpath);
notify_free(&m->notify);
*/
struct Mailbox
{
- struct Buffer *pathbuf;
+ struct Buffer pathbuf;
char *realpath; ///< Used for duplicate detection, context comparison, and the sidebar
char *name; ///< A short name for the Mailbox
struct ConfigSubset *sub; ///< Inherited config items
void mailbox_size_sub (struct Mailbox *m, const struct Email *e);
void mailbox_update (struct Mailbox *m);
+/**
+ * mailbox_path - Get the Mailbox's path string
+ * @param m Mailbox
+ * @retval ptr Path string
+ */
static inline const char *mailbox_path(const struct Mailbox *m)
{
- return mutt_b2s(m->pathbuf);
+ return mutt_b2s(&m->pathbuf);
}
#endif /* MUTT_CORE_MAILBOX_H */
else
mutt_unget_event(0, ch.op);
- mutt_buffer_increase_size(fname, 1024);
+ mutt_buffer_alloc(fname, 1024);
if (mutt_get_field_full(pc, fname->data, fname->dsize,
(mailbox ? MUTT_EFILE : MUTT_FILE) | MUTT_CLEAR,
multiple, files, numfiles) != 0)
!mutt_regexlist_match(&UnMailLists, mailbox) &&
!mutt_regexlist_match(&UnSubscribedLists, mailbox))
{
- struct Buffer *err = mutt_buffer_new();
/* mutt_regexlist_add() detects duplicates, so it is safe to
* try to add here without any checks. */
- mutt_regexlist_add(&MailLists, mailbox, REG_ICASE, err);
- mutt_regexlist_add(&SubscribedLists, mailbox, REG_ICASE, err);
- mutt_buffer_free(&err);
+ mutt_regexlist_add(&MailLists, mailbox, REG_ICASE, NULL);
+ mutt_regexlist_add(&SubscribedLists, mailbox, REG_ICASE, NULL);
}
}
* in quite large parameter values. avoid frequent reallocs by
* pre-sizing */
if (allow_value_spaces)
- mutt_buffer_increase_size(buf, mutt_str_strlen(s));
+ mutt_buffer_alloc(buf, mutt_str_strlen(s));
mutt_debug(LL_DEBUG2, "'%s'\n", s);
char key_binding[MAX_SEQ];
km_expand_key(key_binding, MAX_SEQ, map);
- struct Buffer *tmp = mutt_buffer_new();
- escape_string(tmp, map->macro);
+ struct Buffer tmp = { 0 };
+ escape_string(&tmp, map->macro);
if (map->desc)
{
mutt_buffer_add_printf(buf, "macro %s %s \"%s\" \"%s\"\n", menu->name,
- key_binding, tmp->data, map->desc);
+ key_binding, tmp.data, map->desc);
}
else
{
- mutt_buffer_add_printf(buf, "macro %s %s \"%s\"\n", menu->name, key_binding, tmp->data);
+ mutt_buffer_add_printf(buf, "macro %s %s \"%s\"\n", menu->name, key_binding, tmp.data);
}
- mutt_buffer_free(&tmp);
+ mutt_buffer_dealloc(&tmp);
}
/**
return MUTT_CMD_ERROR;
}
- struct Buffer *filebuf = mutt_buffer_alloc(4096);
+ struct Buffer filebuf = { 0 };
+ mutt_buffer_alloc(&filebuf, 4096);
if (dump_all || (mutt_str_strcasecmp(buf->data, "all") == 0))
{
- dump_all_menus(filebuf, bind);
+ dump_all_menus(&filebuf, bind);
}
else
{
{
// L10N: '%s' is the (misspelled) name of the menu, e.g. 'index' or 'pager'
mutt_buffer_printf(err, _("%s: no such menu"), buf->data);
- mutt_buffer_free(&filebuf);
+ mutt_buffer_dealloc(&filebuf);
return MUTT_CMD_ERROR;
}
struct Mapping menu = { buf->data, menu_index };
- dump_menu(filebuf, &menu, bind);
+ dump_menu(&filebuf, &menu, bind);
}
- if (mutt_buffer_is_empty(filebuf))
+ if (mutt_buffer_is_empty(&filebuf))
{
// L10N: '%s' is the name of the menu, e.g. 'index' or 'pager', it might
// L10N: also be 'all' when all menus are affected.
mutt_buffer_printf(err, bind ? _("%s: no binds for this menu") : _("%s: no macros for this menu"),
dump_all ? "all" : buf->data);
- mutt_buffer_free(&filebuf);
+ mutt_buffer_dealloc(&filebuf);
return MUTT_CMD_ERROR;
}
{
// L10N: '%s' is the file name of the temporary file
mutt_buffer_printf(err, _("Could not create temporary file %s"), tempfile);
- mutt_buffer_free(&filebuf);
+ mutt_buffer_dealloc(&filebuf);
return MUTT_CMD_ERROR;
}
- fputs(filebuf->data, fp_out);
+ fputs(filebuf.data, fp_out);
mutt_file_fclose(&fp_out);
- mutt_buffer_free(&filebuf);
+ mutt_buffer_dealloc(&filebuf);
struct Pager info = { 0 };
if (mutt_do_pager((bind) ? "bind" : "macro", tempfile, MUTT_PAGER_NO_FLAGS, &info) == -1)
if (!cmd)
return IMAP_RES_BAD;
- if (mutt_buffer_add_printf(adata->cmdbuf, "%s %s\r\n", cmd->seq, cmdstr) < 0)
+ if (mutt_buffer_add_printf(&adata->cmdbuf, "%s %s\r\n", cmd->seq, cmdstr) < 0)
return IMAP_RES_BAD;
return 0;
if (flags & IMAP_CMD_QUEUE)
return 0;
- if (mutt_buffer_len(adata->cmdbuf) == 0)
+ if (mutt_buffer_len(&adata->cmdbuf) == 0)
return IMAP_RES_BAD;
- rc = mutt_socket_send_d(adata->conn, adata->cmdbuf->data,
+ rc = mutt_socket_send_d(adata->conn, adata->cmdbuf.data,
(flags & IMAP_CMD_PASS) ? IMAP_LOG_PASS : IMAP_LOG_CMD);
- mutt_buffer_reset(adata->cmdbuf);
+ mutt_buffer_reset(&adata->cmdbuf);
/* unidle when command queue is flushed */
if (adata->state == IMAP_IDLE)
/* successfully entered IDLE state */
adata->state = IMAP_IDLE;
/* queue automatic exit when next command is issued */
- mutt_buffer_addstr(adata->cmdbuf, "DONE\r\n");
+ mutt_buffer_addstr(&adata->cmdbuf, "DONE\r\n");
rc = IMAP_RES_OK;
}
if (rc != IMAP_RES_OK)
{
char c;
bool r = false;
- struct Buffer *buf = NULL;
+ struct Buffer buf = { 0 };
if (C_DebugLevel >= IMAP_LOG_LTRL)
- buf = mutt_buffer_alloc(bytes + 10);
+ mutt_buffer_alloc(&buf, bytes + 10);
mutt_debug(LL_DEBUG2, "reading %ld bytes\n", bytes);
mutt_debug(LL_DEBUG1, "error during read, %ld bytes read\n", pos);
adata->status = IMAP_FATAL;
- mutt_buffer_free(&buf);
+ mutt_buffer_dealloc(&buf);
return -1;
}
if (pbar && !(pos % 1024))
mutt_progress_update(pbar, pos, -1);
if (C_DebugLevel >= IMAP_LOG_LTRL)
- mutt_buffer_addch(buf, c);
+ mutt_buffer_addch(&buf, c);
}
if (C_DebugLevel >= IMAP_LOG_LTRL)
{
- mutt_debug(IMAP_LOG_LTRL, "\n%s", buf->data);
- mutt_buffer_free(&buf);
+ mutt_debug(IMAP_LOG_LTRL, "\n%s", buf.data);
+ mutt_buffer_dealloc(&buf);
}
return 0;
}
int rc;
int count = 0;
- struct Buffer *cmd = mutt_buffer_new();
+ struct Buffer cmd = { 0 };
/* We make a copy of the headers just in case resorting doesn't give
exactly the original order (duplicate messages?), because other parts of
do
{
- mutt_buffer_reset(cmd);
- mutt_buffer_add_printf(cmd, "%s ", pre);
- rc = make_msg_set(m, cmd, flag, changed, invert, &pos);
+ mutt_buffer_reset(&cmd);
+ mutt_buffer_add_printf(&cmd, "%s ", pre);
+ rc = make_msg_set(m, &cmd, flag, changed, invert, &pos);
if (rc > 0)
{
- mutt_buffer_add_printf(cmd, " %s", post);
- if (imap_exec(adata, cmd->data, IMAP_CMD_QUEUE) != IMAP_EXEC_SUCCESS)
+ mutt_buffer_add_printf(&cmd, " %s", post);
+ if (imap_exec(adata, cmd.data, IMAP_CMD_QUEUE) != IMAP_EXEC_SUCCESS)
{
rc = -1;
goto out;
rc = count;
out:
- mutt_buffer_free(&cmd);
+ mutt_buffer_dealloc(&cmd);
if (oldsort != C_Sort)
{
C_Sort = oldsort;
char prompt[1024];
int rc = -1;
bool triedcreate = false;
- struct Buffer *sync_cmd = NULL;
enum QuadOption err_continue = MUTT_NO;
struct ImapAccountData *adata = imap_adata_get(m);
if (imap_adata_find(dest, &dest_adata, &dest_mdata) < 0)
return -1;
- sync_cmd = mutt_buffer_new();
+ struct Buffer sync_cmd = { 0 };
/* check that the save-to folder is in the same account */
if (!mutt_account_match(&(adata->conn->account), &(dest_adata->conn->account)))
if (m->emails[i]->active && m->emails[i]->changed &&
m->emails[i]->deleted && !m->emails[i]->purge)
{
- rc = imap_sync_message_for_copy(m, m->emails[i], sync_cmd, &err_continue);
+ rc = imap_sync_message_for_copy(m, m->emails[i], &sync_cmd, &err_continue);
if (rc < 0)
{
mutt_debug(LL_DEBUG1, "could not sync\n");
rc = IMAP_EXEC_SUCCESS;
out:
- mutt_buffer_free(&sync_cmd);
+ mutt_buffer_dealloc(&sync_cmd);
imap_mdata_free((void *) &dest_mdata);
return ((rc == IMAP_EXEC_SUCCESS) ? 0 : -1);
/* fixup path and realpath, mainly to replace / by /INBOX */
char buf[1024];
imap_qualify_path(buf, sizeof(buf), &adata->conn_account, mdata->name);
- mutt_buffer_strcpy(m->pathbuf, buf);
+ mutt_buffer_strcpy(&m->pathbuf, buf);
mutt_str_replace(&m->realpath, mailbox_path(m));
m->mdata = mdata;
if (!m)
return -1;
- struct Buffer *cmd = NULL;
char uid[11];
struct ImapAccountData *adata = imap_adata_get(m);
/* Remove old custom flags */
if (imap_edata_get(e)->flags_remote)
{
- cmd = mutt_buffer_new();
- cmd->dptr = cmd->data;
- mutt_buffer_addstr(cmd, "UID STORE ");
- mutt_buffer_addstr(cmd, uid);
- mutt_buffer_addstr(cmd, " -FLAGS.SILENT (");
- mutt_buffer_addstr(cmd, imap_edata_get(e)->flags_remote);
- mutt_buffer_addstr(cmd, ")");
+ struct Buffer cmd = { 0 };
+ mutt_buffer_addstr(&cmd, "UID STORE ");
+ mutt_buffer_addstr(&cmd, uid);
+ mutt_buffer_addstr(&cmd, " -FLAGS.SILENT (");
+ mutt_buffer_addstr(&cmd, imap_edata_get(e)->flags_remote);
+ mutt_buffer_addstr(&cmd, ")");
/* Should we return here, or we are fine and we could
* continue to add new flags */
- if (imap_exec(adata, cmd->data, IMAP_CMD_NO_FLAGS) != IMAP_EXEC_SUCCESS)
+ int rc = imap_exec(adata, cmd.data, IMAP_CMD_NO_FLAGS);
+ mutt_buffer_dealloc(&cmd);
+ if (rc != IMAP_EXEC_SUCCESS)
{
- mutt_buffer_free(&cmd);
return -1;
}
-
- mutt_buffer_free(&cmd);
}
/* Add new custom flags */
if (buf)
{
- cmd = mutt_buffer_new();
- cmd->dptr = cmd->data;
- mutt_buffer_addstr(cmd, "UID STORE ");
- mutt_buffer_addstr(cmd, uid);
- mutt_buffer_addstr(cmd, " +FLAGS.SILENT (");
- mutt_buffer_addstr(cmd, buf);
- mutt_buffer_addstr(cmd, ")");
+ struct Buffer cmd = { 0 };
+ mutt_buffer_addstr(&cmd, "UID STORE ");
+ mutt_buffer_addstr(&cmd, uid);
+ mutt_buffer_addstr(&cmd, " +FLAGS.SILENT (");
+ mutt_buffer_addstr(&cmd, buf);
+ mutt_buffer_addstr(&cmd, ")");
- if (imap_exec(adata, cmd->data, IMAP_CMD_NO_FLAGS) != IMAP_EXEC_SUCCESS)
+ int rc = imap_exec(adata, cmd.data, IMAP_CMD_NO_FLAGS);
+ mutt_buffer_dealloc(&cmd);
+ if (rc != IMAP_EXEC_SUCCESS)
{
mutt_debug(LL_DEBUG1, "fail to add new flags\n");
- mutt_buffer_free(&cmd);
return -1;
}
-
- mutt_buffer_free(&cmd);
}
/* We are good sync them */
*/
int imap_expand_path(struct Buffer *buf)
{
- mutt_buffer_increase_size(buf, PATH_MAX);
+ mutt_buffer_alloc(buf, PATH_MAX);
return imap_path_canon(buf->data, PATH_MAX);
}
int cmdslots;
int nextcmd;
int lastcmd;
- struct Buffer *cmdbuf;
+ struct Buffer cmdbuf;
char delim;
struct Mailbox *mailbox; /* Current selected mailbox */
struct ImapAccountData *adata = *ptr;
FREE(&adata->capstr);
- mutt_buffer_free(&adata->cmdbuf);
+ mutt_buffer_dealloc(&adata->cmdbuf);
FREE(&adata->buf);
FREE(&adata->cmds);
static unsigned char new_seqid = 'a';
adata->seqid = new_seqid;
- adata->cmdbuf = mutt_buffer_new();
adata->cmdslots = C_ImapPipelineDepth + 2;
adata->cmds = mutt_mem_calloc(adata->cmdslots, sizeof(*adata->cmds));
if (!mdata->hcache)
return -1;
- struct Buffer *b = mutt_buffer_new();
/* The seqset is likely large. Preallocate to reduce reallocs */
- mutt_buffer_increase_size(b, 8192);
- imap_msn_index_to_uid_seqset(b, mdata);
-
- int rc = mutt_hcache_store_raw(mdata->hcache, "/UIDSEQSET", 10, b->data,
- mutt_buffer_len(b) + 1);
- mutt_debug(LL_DEBUG3, "Stored /UIDSEQSET %s\n", b->data);
- mutt_buffer_free(&b);
+ struct Buffer b = { 0 };
+ mutt_buffer_alloc(&b, 8192);
+ imap_msn_index_to_uid_seqset(&b, mdata);
+
+ int rc = mutt_hcache_store_raw(mdata->hcache, "/UIDSEQSET", 10, b.data,
+ mutt_buffer_len(&b) + 1);
+ mutt_debug(LL_DEBUG3, "Stored /UIDSEQSET %s\n", b.data);
+ mutt_buffer_dealloc(&b);
return rc;
}
}
/* keepalive failure in mutt_enter_fname may kill connection. #3028 */
- if (Context && Context->mailbox && (mutt_buffer_is_empty(Context->mailbox->pathbuf)))
+ if (Context && Context->mailbox && (mutt_buffer_is_empty(&Context->mailbox->pathbuf)))
ctx_free(&Context);
if (Context && Context->mailbox)
check = mx_mbox_check(Context->mailbox, &index_hint);
if (check < 0)
{
- if (!Context->mailbox || (mutt_buffer_is_empty(Context->mailbox->pathbuf)))
+ if (!Context->mailbox || (mutt_buffer_is_empty(&Context->mailbox->pathbuf)))
{
/* fatal error occurred */
ctx_free(&Context);
}
/* check for a fatal error, or all messages deleted */
- if (Context && Context->mailbox && mutt_buffer_is_empty(Context->mailbox->pathbuf))
+ if (Context && Context->mailbox &&
+ mutt_buffer_is_empty(&Context->mailbox->pathbuf))
ctx_free(&Context);
/* if we were in the pager, redisplay the message */
{
bool cont = false; /* Set if we want to continue instead of break */
- struct Buffer *folderbuf = mutt_buffer_pool_get();
- mutt_buffer_increase_size(folderbuf, PATH_MAX);
+ struct Buffer *folderbuf = mutt_buffer_alloc(mutt_buffer_pool_get(), PATH_MAX);
struct Mailbox *m = NULL;
char *cp = NULL;
#ifdef USE_NNTP
else
cp = _("Open mailbox");
- if ((op == OP_MAIN_NEXT_UNREAD_MAILBOX) && Context &&
- Context->mailbox && !mutt_buffer_is_empty(Context->mailbox->pathbuf))
+ if ((op == OP_MAIN_NEXT_UNREAD_MAILBOX) && Context && Context->mailbox &&
+ !mutt_buffer_is_empty(&Context->mailbox->pathbuf))
{
mutt_buffer_strcpy(folderbuf, mailbox_path(Context->mailbox));
mutt_buffer_pretty_mailbox(folderbuf);
else
{
if (C_ChangeFolderNext && Context && Context->mailbox &&
- mutt_buffer_is_empty(Context->mailbox->pathbuf))
+ mutt_buffer_is_empty(&Context->mailbox->pathbuf))
{
mutt_buffer_strcpy(folderbuf, mailbox_path(Context->mailbox));
mutt_buffer_pretty_mailbox(folderbuf);
continue;
}
- mutt_buffer_strcpy(m->pathbuf, buf->data);
+ mutt_buffer_strcpy(&m->pathbuf, buf->data);
/* int rc = */ mx_path_canon2(m, C_Folder);
bool new_account = false;
{
char buf[1024];
int need_pause = 0;
- struct Buffer err;
+ struct Buffer err = { 0 };
- mutt_buffer_init(&err);
- mutt_buffer_increase_size(&err, 256);
+ mutt_buffer_alloc(&err, 256);
mutt_grouplist_init();
/* reverse alias keys need to be strdup'ed because of idna conversions */
*/
int mutt_query_variables(struct ListHead *queries)
{
- struct Buffer *value = mutt_buffer_alloc(256);
- struct Buffer *tmp = mutt_buffer_alloc(256);
+ struct Buffer value = { 0 };
+ mutt_buffer_alloc(&value, 256);
+ struct Buffer tmp = { 0 };
+ mutt_buffer_alloc(&tmp, 256);
int rc = 0;
struct ListNode *np = NULL;
STAILQ_FOREACH(np, queries, entries)
{
- mutt_buffer_reset(value);
+ mutt_buffer_reset(&value);
struct HashElem *he = cs_get_elem(Config, np->data);
if (!he)
continue;
}
- int rv = cs_he_string_get(Config, he, value);
+ int rv = cs_he_string_get(Config, he, &value);
if (CSR_RESULT(rv) != CSR_SUCCESS)
{
rc = 1;
int type = DTYPE(he->type);
if (IS_PATH(he) && !(he->type & DT_MAILBOX))
- mutt_pretty_mailbox(value->data, value->dsize);
+ mutt_pretty_mailbox(value.data, value.dsize);
if ((type != DT_BOOL) && (type != DT_NUMBER) && (type != DT_LONG) && (type != DT_QUAD))
{
- mutt_buffer_reset(tmp);
- pretty_var(value->data, tmp);
- mutt_buffer_strcpy(value, tmp->data);
+ mutt_buffer_reset(&tmp);
+ pretty_var(value.data, &tmp);
+ mutt_buffer_strcpy(&value, tmp.data);
}
- dump_config_neo(Config, he, value, NULL, CS_DUMP_NO_FLAGS, stdout);
+ dump_config_neo(Config, he, &value, NULL, CS_DUMP_NO_FLAGS, stdout);
}
- mutt_buffer_free(&value);
- mutt_buffer_free(&tmp);
+ mutt_buffer_dealloc(&value);
+ mutt_buffer_dealloc(&tmp);
return rc; // TEST16: neomutt -Q charset
}
myvarval = myvar_get(var);
if (myvarval)
{
- struct Buffer *pretty = mutt_buffer_alloc(256);
- pretty_var(myvarval, pretty);
- snprintf(pt, buflen - (pt - buf), "%s=%s", var, pretty->data);
- mutt_buffer_free(&pretty);
+ struct Buffer pretty = { 0 };
+ mutt_buffer_alloc(&pretty, 256);
+ pretty_var(myvarval, &pretty);
+ snprintf(pt, buflen - (pt - buf), "%s=%s", var, pretty.data);
+ mutt_buffer_dealloc(&pretty);
return 1;
}
return 0; /* no such variable. */
}
else
{
- struct Buffer *value = mutt_buffer_alloc(256);
- struct Buffer *pretty = mutt_buffer_alloc(256);
- int rc = cs_he_string_get(Config, he, value);
+ struct Buffer value = { 0 };
+ mutt_buffer_alloc(&value, 256);
+ struct Buffer pretty = { 0 };
+ mutt_buffer_alloc(&pretty, 256);
+ int rc = cs_he_string_get(Config, he, &value);
if (CSR_RESULT(rc) == CSR_SUCCESS)
{
- pretty_var(value->data, pretty);
- snprintf(pt, buflen - (pt - buf), "%s=%s", var, pretty->data);
- mutt_buffer_free(&value);
- mutt_buffer_free(&pretty);
+ pretty_var(value.data, &pretty);
+ snprintf(pt, buflen - (pt - buf), "%s=%s", var, pretty.data);
+ mutt_buffer_dealloc(&value);
+ mutt_buffer_dealloc(&pretty);
return 0;
}
- mutt_buffer_free(&value);
- mutt_buffer_free(&pretty);
+ mutt_buffer_dealloc(&value);
+ mutt_buffer_dealloc(&pretty);
return 1;
}
}
"%s inv%s=42", "%s inv%s?", "%s &%s", "%s &%s=42", "%s &%s?",
};
- struct Buffer *tmp = mutt_buffer_alloc(256);
- struct Buffer *err = mutt_buffer_alloc(256);
+ struct Buffer tmp = { 0 };
+ mutt_buffer_alloc(&tmp, 256);
+ struct Buffer err = { 0 };
+ mutt_buffer_alloc(&err, 256);
char line[64];
for (size_t v = 0; v < mutt_array_size(vars); v++)
// printf("COMMAND %s\n", commands[c]);
for (size_t t = 0; t < mutt_array_size(tests); t++)
{
- mutt_buffer_reset(tmp);
- mutt_buffer_reset(err);
+ mutt_buffer_reset(&tmp);
+ mutt_buffer_reset(&err);
snprintf(line, sizeof(line), tests[t], commands[c], vars[v]);
printf("%-26s", line);
- enum CommandResult rc = mutt_parse_rc_line(line, tmp, err);
- printf("%2d %s\n", rc, err->data);
+ enum CommandResult rc = mutt_parse_rc_line(line, &tmp, &err);
+ printf("%2d %s\n", rc, err.data);
}
printf("\n");
}
// printf("\n");
}
- mutt_buffer_free(&tmp);
- mutt_buffer_free(&err);
+ mutt_buffer_dealloc(&tmp);
+ mutt_buffer_dealloc(&err);
}
/**
"record", "signature",
};
- struct Buffer *value = mutt_buffer_alloc(256);
+ struct Buffer value = { 0 };
+ mutt_buffer_alloc(&value, 256);
for (size_t i = 0; i < mutt_array_size(names); i++)
{
struct HashElem *he = cs_get_elem(cs, names[i]);
if (!he)
continue;
- mutt_buffer_reset(value);
- cs_he_initial_get(cs, he, value);
- mutt_expand_path(value->data, value->dsize);
- cs_he_initial_set(cs, he, value->data, NULL);
+ mutt_buffer_reset(&value);
+ cs_he_initial_get(cs, he, &value);
+ mutt_expand_path(value.data, value.dsize);
+ cs_he_initial_set(cs, he, value.data, NULL);
cs_he_reset(cs, he, NULL);
}
- mutt_buffer_free(&value);
+ mutt_buffer_dealloc(&value);
}
/**
int double_dash = argc, nargc = 1;
int rc = 1;
bool repeat_error = false;
- struct Buffer *folder = mutt_buffer_new();
+ struct Buffer folder = { 0 };
MuttLogger = log_disp_terminal;
mutt_list_insert_tail(&Muttrc, mutt_str_strdup(optarg));
break;
case 'f':
- mutt_buffer_strcpy(folder, optarg);
+ mutt_buffer_strcpy(&folder, optarg);
explicit_folder = true;
break;
#ifdef USE_NNTP
if (new_magic)
{
- struct Buffer *err = mutt_buffer_new();
- int r = cs_str_initial_set(Config, "mbox_type", new_magic, err);
+ struct Buffer err = { 0 };
+ int r = cs_str_initial_set(Config, "mbox_type", new_magic, &err);
if (CSR_RESULT(r) != CSR_SUCCESS)
{
- mutt_error(err->data);
- mutt_buffer_free(&err);
+ mutt_error(err.data);
+ mutt_buffer_dealloc(&err);
goto main_curses;
}
- mutt_buffer_free(&err);
cs_str_reset(Config, "mbox_type", NULL);
}
mutt_message(_("No mailbox with new mail"));
goto main_curses; // TEST37: neomutt -Z (no new mail)
}
- mutt_buffer_reset(folder);
- mutt_mailbox_next_buffer(Context ? Context->mailbox : NULL, folder);
+ mutt_buffer_reset(&folder);
+ mutt_mailbox_next_buffer(Context ? Context->mailbox : NULL, &folder);
#ifdef USE_IMAP
C_ImapPassive = passive;
#endif
mutt_error(_("No incoming mailboxes defined"));
goto main_curses; // TEST39: neomutt -n -F /dev/null -y
}
- mutt_buffer_reset(folder);
- mutt_buffer_select_file(folder, MUTT_SEL_FOLDER | MUTT_SEL_MAILBOX, NULL, NULL);
- if (mutt_buffer_len(folder) == 0)
+ mutt_buffer_reset(&folder);
+ mutt_buffer_select_file(&folder, MUTT_SEL_FOLDER | MUTT_SEL_MAILBOX, NULL, NULL);
+ if (mutt_buffer_len(&folder) == 0)
{
goto main_ok; // TEST40: neomutt -y (quit selection)
}
}
- if (mutt_buffer_len(folder) == 0)
+ if (mutt_buffer_len(&folder) == 0)
{
if (C_Spoolfile)
{
// Check if C_Spoolfile corresponds a mailboxes' description.
struct Mailbox *m_desc = mailbox_find_name(C_Spoolfile);
if (m_desc)
- mutt_buffer_strcpy(folder, m_desc->realpath);
+ mutt_buffer_strcpy(&folder, m_desc->realpath);
else
- mutt_buffer_strcpy(folder, C_Spoolfile);
+ mutt_buffer_strcpy(&folder, C_Spoolfile);
}
else if (C_Folder)
- mutt_buffer_strcpy(folder, C_Folder);
+ mutt_buffer_strcpy(&folder, C_Folder);
/* else no folder */
}
if (OptNews)
{
OptNews = false;
- mutt_buffer_increase_size(folder, PATH_MAX);
- nntp_expand_path(folder->data, folder->dsize, &CurrentNewsSrv->conn->account);
+ mutt_buffer_alloc(&folder, PATH_MAX);
+ nntp_expand_path(folder.data, folder.dsize, &CurrentNewsSrv->conn->account);
}
else
#endif
- mutt_buffer_expand_path(folder);
+ mutt_buffer_expand_path(&folder);
- mutt_str_replace(&CurrentFolder, mutt_b2s(folder));
- mutt_str_replace(&LastFolder, mutt_b2s(folder));
+ mutt_str_replace(&CurrentFolder, mutt_b2s(&folder));
+ mutt_str_replace(&LastFolder, mutt_b2s(&folder));
if (flags & MUTT_CLI_IGNORE)
{
/* check to see if there are any messages in the folder */
- switch (mx_check_empty(mutt_b2s(folder)))
+ switch (mx_check_empty(mutt_b2s(&folder)))
{
case -1:
- mutt_perror(mutt_b2s(folder));
+ mutt_perror(mutt_b2s(&folder));
goto main_curses; // TEST41: neomutt -z -f missing
case 1:
mutt_error(_("Mailbox is empty"));
}
}
- mutt_folder_hook(mutt_b2s(folder), NULL);
+ mutt_folder_hook(mutt_b2s(&folder), NULL);
mutt_startup_shutdown_hook(MUTT_STARTUP_HOOK);
notify_send(NeoMutt->notify, NT_GLOBAL, NT_GLOBAL_STARTUP, 0);
repeat_error = true;
- struct Mailbox *m = mx_path_resolve(mutt_b2s(folder));
+ struct Mailbox *m = mx_path_resolve(mutt_b2s(&folder));
Context = mx_mbox_open(m, ((flags & MUTT_CLI_RO) || C_ReadOnly) ? MUTT_READONLY : MUTT_OPEN_NO_FLAGS);
if (!Context)
{
if (repeat_error && ErrorBufMessage)
puts(ErrorBuf);
main_exit:
- mutt_buffer_free(&folder);
+ mutt_buffer_dealloc(&folder);
mutt_list_free(&queries);
crypto_module_free();
mutt_window_free_all();
mutt_file_fclose(&adata->fp);
/* fix up the times so mailbox won't get confused */
- if (m->peekonly && mutt_buffer_is_empty(m->pathbuf) &&
+ if (m->peekonly && mutt_buffer_is_empty(&m->pathbuf) &&
(mutt_file_timespec_compare(&m->mtime, &adata->atime) > 0))
{
#ifdef HAVE_UTIMENSAT
dev_t st_dev;
ino_t st_ino;
struct Monitor *monitor;
- struct Buffer *path_buf; /* access via path only (maybe not initialized) */
+ struct Buffer path_buf; /* access via path only (maybe not initialized) */
};
/**
*/
static void monitor_info_free(struct MonitorInfo *info)
{
- mutt_buffer_free(&info->path_buf);
+ mutt_buffer_dealloc(&info->path_buf);
}
/**
}
if (fmt)
{
- if (!info->path_buf)
- info->path_buf = mutt_buffer_new();
- mutt_buffer_printf(info->path_buf, fmt, info->path);
- info->path = mutt_b2s(info->path_buf);
+ mutt_buffer_printf(&info->path_buf, fmt, info->path);
+ info->path = mutt_b2s(&info->path_buf);
}
if (stat(info->path, &sb) != 0)
return RESOLVE_RES_FAIL_STAT;
if (!buf)
return 0;
- mutt_buffer_increase_size(buf, MAX((len * 2), 1024));
+ mutt_buffer_alloc(buf, MAX((len * 2), 1024));
size_t num = mutt_b64_encode(in, len, buf->data, buf->dsize);
mutt_buffer_fix_dptr(buf);
return num;
if (!buf)
return -1;
- mutt_buffer_increase_size(buf, mutt_str_strlen(in));
+ mutt_buffer_alloc(buf, mutt_str_strlen(in));
int olen = mutt_b64_decode(in, buf->data, buf->dsize);
/* mutt_from_base64 returns raw bytes, so don't terminate the buffer either */
if (olen > 0)
return 0;
if (!buf->data || !buf->dptr || ((buf->dptr + len + 1) > (buf->data + buf->dsize)))
- mutt_buffer_increase_size(buf, buf->dsize + MAX(128, len + 1));
+ mutt_buffer_alloc(buf, buf->dsize + MAX(128, len + 1));
memcpy(buf->dptr, s, len);
buf->dptr += len;
return 0; /* LCOV_EXCL_LINE */
if (!buf->data || !buf->dptr || (buf->dsize < 128))
- mutt_buffer_increase_size(buf, 128);
+ mutt_buffer_alloc(buf, 128);
int doff = buf->dptr - buf->data;
int blen = buf->dsize - doff;
blen = ++len - blen;
if (blen < 128)
blen = 128;
- mutt_buffer_increase_size(buf, buf->dsize + blen);
+ mutt_buffer_alloc(buf, buf->dsize + blen);
len = vsnprintf(buf->dptr, len, fmt, ap_retry);
}
if (len > 0)
}
/**
- * mutt_buffer_alloc - Create a new Buffer
- * @param size Size of Buffer to create
- * @retval ptr Newly allocated Buffer
+ * mutt_buffer_alloc - Make sure a buffer can store at least new_size bytes
+ * @param buf Buffer to change
+ * @param new_size New size
+ * @retval buf The buf argument, useful in
+ * struct Buffer *buf = mutt_buffer_alloc(mutt_buffer_new(), 1024);
*/
-struct Buffer *mutt_buffer_alloc(size_t size)
+struct Buffer *mutt_buffer_alloc(struct Buffer *buf, size_t new_size)
{
- struct Buffer *buf = mutt_mem_calloc(1, sizeof(struct Buffer));
-
- buf->data = mutt_mem_calloc(1, size);
- buf->dptr = buf->data;
- buf->dsize = size;
+ if (buf)
+ {
+ if (!buf->dptr)
+ buf->dptr = buf->data;
+
+ if (new_size > buf->dsize)
+ {
+ size_t offset = (buf->dptr && buf->data) ? buf->dptr - buf->data : 0;
+
+ buf->dsize = new_size;
+ mutt_mem_realloc(&buf->data, buf->dsize);
+ buf->dptr = buf->data + offset;
+ /* This ensures an initially NULL buf->data is now properly terminated. */
+ *buf->dptr = '\0';
+ }
+ }
return buf;
}
+/**
+ * mutt_buffer_dealloc - Release the memory allocated by a buffer
+ * @param buf Buffer to change
+ */
+void mutt_buffer_dealloc(struct Buffer *buf)
+{
+ if (!buf || !buf->data)
+ return;
+
+ FREE(&buf->data);
+}
+
/**
* mutt_buffer_strcpy - Copy a string into a Buffer
* @param buf Buffer to overwrite
mutt_buffer_addstr_n(buf, s, len);
}
-/**
- * mutt_buffer_increase_size - Increase the allocated size of a buffer
- * @param buf Buffer to change
- * @param new_size New size
- */
-void mutt_buffer_increase_size(struct Buffer *buf, size_t new_size)
-{
- if (!buf)
- return;
-
- if (!buf->dptr)
- buf->dptr = buf->data;
-
- if (new_size <= buf->dsize)
- return;
-
- size_t offset = (buf->dptr && buf->data) ? buf->dptr - buf->data : 0;
-
- buf->dsize = new_size;
- mutt_mem_realloc(&buf->data, buf->dsize);
- buf->dptr = buf->data + offset;
- /* This ensures an initially NULL buf->data is now properly terminated. */
- *buf->dptr = '\0';
-}
-
/**
* mutt_buffer_len - Calculate the length of a Buffer
* @param buf Buffer
};
/* Convert a buffer to a const char * "string" */
-#define mutt_b2s(buf) (buf->data ? (const char *) buf->data : "")
+#define mutt_b2s(buf) ((buf)->data ? (const char *) (buf)->data : "")
-#define MoreArgs(buf) (*buf->dptr && (*buf->dptr != ';') && (*buf->dptr != '#'))
+#define MoreArgs(buf) (*(buf)->dptr && (*(buf)->dptr != ';') && (*(buf)->dptr != '#'))
-struct Buffer *mutt_buffer_alloc (size_t size);
+struct Buffer *mutt_buffer_alloc (struct Buffer *buf, size_t size);
+void mutt_buffer_dealloc (struct Buffer *buf);
void mutt_buffer_fix_dptr (struct Buffer *buf);
void mutt_buffer_free (struct Buffer **p);
struct Buffer *mutt_buffer_from (const char *seed);
-void mutt_buffer_increase_size(struct Buffer *buf, size_t new_size);
struct Buffer *mutt_buffer_init (struct Buffer *buf);
bool mutt_buffer_is_empty (const struct Buffer *buf);
size_t mutt_buffer_len (const struct Buffer *buf);
const char *basename = NULL;
int rc = 0;
- struct Buffer *parent = mutt_buffer_alloc(PATH_MAX);
- mutt_buffer_strcpy(parent, NONULL(path));
+ struct Buffer parent = { 0 };
+ mutt_buffer_alloc(&parent, PATH_MAX);
+ mutt_buffer_strcpy(&parent, NONULL(path));
- char *p = strrchr(parent->data, '/');
+ char *p = strrchr(parent.data, '/');
if (p)
{
*p = '\0';
}
else
{
- mutt_buffer_strcpy(parent, ".");
+ mutt_buffer_strcpy(&parent, ".");
basename = path;
}
- mutt_buffer_printf(newdir, "%s/%s", mutt_b2s(parent), ".muttXXXXXX");
+ mutt_buffer_printf(newdir, "%s/%s", mutt_b2s(&parent), ".muttXXXXXX");
if (!mkdtemp(newdir->data))
{
mutt_debug(LL_DEBUG1, "mkdtemp() failed\n");
mutt_buffer_printf(newfile, "%s/%s", newdir->data, NONULL(basename));
cleanup:
- mutt_buffer_free(&parent);
+ mutt_buffer_dealloc(&parent);
return rc;
}
}
else
{
- struct Buffer *abs_oldpath = mutt_buffer_alloc(PATH_MAX);
+ struct Buffer abs_oldpath = { 0 };
+ mutt_buffer_alloc(&abs_oldpath, PATH_MAX);
- if (!mutt_path_getcwd(abs_oldpath))
+ if (!mutt_path_getcwd(&abs_oldpath))
{
- mutt_buffer_free(&abs_oldpath);
+ mutt_buffer_dealloc(&abs_oldpath);
return -1;
}
- mutt_buffer_addch(abs_oldpath, '/');
- mutt_buffer_addstr(abs_oldpath, oldpath);
- if (symlink(mutt_b2s(abs_oldpath), newpath) == -1)
+ mutt_buffer_addch(&abs_oldpath, '/');
+ mutt_buffer_addstr(&abs_oldpath, oldpath);
+ if (symlink(mutt_b2s(&abs_oldpath), newpath) == -1)
{
- mutt_buffer_free(&abs_oldpath);
+ mutt_buffer_dealloc(&abs_oldpath);
return -1;
}
- mutt_buffer_free(&abs_oldpath);
+ mutt_buffer_dealloc(&abs_oldpath);
}
if ((stat(oldpath, &osb) == -1) || (stat(newpath, &nsb) == -1) ||
return -1;
struct dirent *de = NULL;
- struct Buffer *cur = NULL;
struct stat statbuf;
int rc = 0;
/* We avoid using the buffer pool for this function, because it
* invokes recursively to an unknown depth. */
- cur = mutt_buffer_new();
- mutt_buffer_increase_size(cur, PATH_MAX);
+ struct Buffer cur = { 0 };
+ mutt_buffer_alloc(&cur, PATH_MAX);
while ((de = readdir(dirp)))
{
if ((strcmp(".", de->d_name) == 0) || (strcmp("..", de->d_name) == 0))
continue;
- mutt_buffer_printf(cur, "%s/%s", path, de->d_name);
+ mutt_buffer_printf(&cur, "%s/%s", path, de->d_name);
/* XXX make nonrecursive version */
- if (stat(mutt_b2s(cur), &statbuf) == -1)
+ if (stat(mutt_b2s(&cur), &statbuf) == -1)
{
rc = 1;
continue;
}
if (S_ISDIR(statbuf.st_mode))
- rc |= mutt_file_rmtree(mutt_b2s(cur));
+ rc |= mutt_file_rmtree(mutt_b2s(&cur));
else
- rc |= unlink(mutt_b2s(cur));
+ rc |= unlink(mutt_b2s(&cur));
}
closedir(dirp);
rc |= rmdir(path);
- mutt_buffer_free(&cur);
+ mutt_buffer_dealloc(&cur);
return rc;
}
struct stat osb, nsb;
int fd;
- struct Buffer *safe_file = NULL;
- struct Buffer *safe_dir = NULL;
+ struct Buffer safe_file = { 0 };
+ struct Buffer safe_dir = { 0 };
if (flags & O_EXCL)
{
- safe_file = mutt_buffer_alloc(PATH_MAX);
- safe_dir = mutt_buffer_alloc(PATH_MAX);
+ mutt_buffer_alloc(&safe_file, PATH_MAX);
+ mutt_buffer_alloc(&safe_dir, PATH_MAX);
- if (mkwrapdir(path, safe_file, safe_dir) == -1)
+ if (mkwrapdir(path, &safe_file, &safe_dir) == -1)
{
fd = -1;
goto cleanup;
}
- fd = open(mutt_b2s(safe_file), flags, 0600);
+ fd = open(mutt_b2s(&safe_file), flags, 0600);
if (fd < 0)
{
- rmdir(mutt_b2s(safe_dir));
+ rmdir(mutt_b2s(&safe_dir));
goto cleanup;
}
/* NFS and I believe cygwin do not handle movement of open files well */
close(fd);
- if (put_file_in_place(path, mutt_b2s(safe_file), mutt_b2s(safe_dir)) == -1)
+ if (put_file_in_place(path, mutt_b2s(&safe_file), mutt_b2s(&safe_dir)) == -1)
{
fd = -1;
goto cleanup;
}
cleanup:
- mutt_buffer_free(&safe_file);
- mutt_buffer_free(&safe_dir);
+ mutt_buffer_dealloc(&safe_file);
+ mutt_buffer_dealloc(&safe_dir);
return fd;
}
*/
void mutt_buffer_file_expand_fmt_quote(struct Buffer *dest, const char *fmt, const char *src)
{
- struct Buffer *tmp = mutt_buffer_alloc(PATH_MAX);
+ struct Buffer tmp = { 0 };
+ mutt_buffer_alloc(&tmp, PATH_MAX);
- mutt_buffer_quote_filename(tmp, src, true);
- mutt_file_expand_fmt(dest, fmt, mutt_b2s(tmp));
- mutt_buffer_free(&tmp);
+ mutt_buffer_quote_filename(&tmp, src, true);
+ mutt_file_expand_fmt(dest, fmt, mutt_b2s(&tmp));
+ mutt_buffer_dealloc(&tmp);
}
/**
char *p = *s;
mbstate_t mbstate1, mbstate2;
- struct Buffer *b = mutt_buffer_new();
+ struct Buffer buf = { 0 };
memset(&mbstate1, 0, sizeof(mbstate1));
memset(&mbstate2, 0, sizeof(mbstate2));
for (; (k = mbrtowc(&wc, p, MB_LEN_MAX, &mbstate1)); p += k)
continue;
k2 = wcrtomb(scratch, wc, &mbstate2);
scratch[k2] = '\0';
- mutt_buffer_addstr(b, scratch);
+ mutt_buffer_addstr(&buf, scratch);
}
FREE(s);
- *s = b->data ? b->data : mutt_mem_calloc(1, 1);
- FREE(&b);
+ *s = buf.data ? buf.data : mutt_mem_calloc(1, 1);
return 0;
}
if (!cwd)
return NULL;
- mutt_buffer_increase_size(cwd, PATH_MAX);
+ mutt_buffer_alloc(cwd, PATH_MAX);
char *retval = getcwd(cwd->data, cwd->dsize);
while (!retval && (errno == ERANGE))
{
- mutt_buffer_increase_size(cwd, cwd->dsize + 256);
+ mutt_buffer_alloc(cwd, cwd->dsize + 256);
retval = getcwd(cwd->data, cwd->dsize);
}
if (retval)
*/
static void increase_buffer_pool(void)
{
- struct Buffer *newbuf;
BufferPoolLen += BufferPoolIncrement;
mutt_debug(LL_DEBUG1, "%zu\n", BufferPoolLen);
mutt_mem_realloc(&BufferPool, BufferPoolLen * sizeof(struct Buffer *));
while (BufferPoolCount < BufferPoolIncrement)
{
- newbuf = mutt_buffer_alloc(BufferPoolInitialBufferSize);
+ struct Buffer *newbuf =
+ mutt_buffer_alloc(mutt_buffer_new(), BufferPoolInitialBufferSize);
BufferPool[BufferPoolCount++] = newbuf;
}
}
struct ConfigDef *cdef = he->data;
int rc = 0;
- struct Buffer *err = mutt_buffer_alloc(256);
+ struct Buffer err = { 0 };
+ mutt_buffer_alloc(&err, 256);
switch (DTYPE(cdef->type))
{
case DT_STRING:
{
const char *value = lua_tostring(l, -1);
- int rv = cs_he_string_set(Config, he, value, err);
+ int rv = cs_he_string_set(Config, he, value, &err);
if (CSR_RESULT(rv) != CSR_SUCCESS)
rc = -1;
break;
case DT_QUAD:
{
const intptr_t value = lua_tointeger(l, -1);
- int rv = cs_he_native_set(Config, he, value, err);
+ int rv = cs_he_native_set(Config, he, value, &err);
if (CSR_RESULT(rv) != CSR_SUCCESS)
rc = -1;
break;
case DT_BOOL:
{
const intptr_t value = lua_toboolean(l, -1);
- int rv = cs_he_native_set(Config, he, value, err);
+ int rv = cs_he_native_set(Config, he, value, &err);
if (CSR_RESULT(rv) != CSR_SUCCESS)
rc = -1;
break;
break;
}
- mutt_buffer_free(&err);
+ mutt_buffer_dealloc(&err);
return rc;
}
case DT_SORT:
case DT_STRING:
{
- struct Buffer *value = mutt_buffer_alloc(256);
- int rc = cs_he_string_get(Config, he, value);
+ struct Buffer value = { 0 };
+ mutt_buffer_alloc(&value, 256);
+ int rc = cs_he_string_get(Config, he, &value);
if (CSR_RESULT(rc) != CSR_SUCCESS)
{
- mutt_buffer_free(&value);
+ mutt_buffer_dealloc(&value);
return -1;
}
- struct Buffer *escaped = mutt_buffer_alloc(256);
- escape_string(escaped, value->data);
- lua_pushstring(l, escaped->data);
- mutt_buffer_free(&value);
- mutt_buffer_free(&escaped);
+ struct Buffer escaped = { 0 };
+ mutt_buffer_alloc(&escaped, 256);
+ escape_string(&escaped, value.data);
+ lua_pushstring(l, escaped.data);
+ mutt_buffer_dealloc(&value);
+ mutt_buffer_dealloc(&escaped);
return 1;
}
case DT_QUAD:
}
/* check to see if the folder is the currently selected folder before polling */
- if (!m_cur || mutt_buffer_is_empty(m_cur->pathbuf) ||
+ if (!m_cur || mutt_buffer_is_empty(&m_cur->pathbuf) ||
(((m_check->magic == MUTT_IMAP) || (m_check->magic == MUTT_NNTP) ||
(m_check->magic == MUTT_NOTMUCH) || (m_check->magic == MUTT_POP)) ?
(mutt_str_strcmp(mailbox_path(m_check), mailbox_path(m_cur)) != 0) :
default:; /* do nothing */
}
}
- else if (C_CheckMboxSize && m_cur && mutt_buffer_is_empty(m_cur->pathbuf))
+ else if (C_CheckMboxSize && m_cur && mutt_buffer_is_empty(&m_cur->pathbuf))
m_check->size = (off_t) sb.st_size; /* update the size of current folder */
#ifdef USE_SIDEBAR
{
if (np->mailbox->magic == MUTT_NOTMUCH) /* only match real mailboxes */
continue;
- mutt_buffer_expand_path(np->mailbox->pathbuf);
+ mutt_buffer_expand_path(&np->mailbox->pathbuf);
if ((found || (pass > 0)) && np->mailbox->has_new)
{
mutt_buffer_strcpy(s, mailbox_path(np->mailbox));
mutt_addrlist_copy(&e->env->to, al, false);
/* TODO: fix mutt_default_save() to use Buffer */
- mutt_buffer_increase_size(p, PATH_MAX);
+ mutt_buffer_alloc(p, PATH_MAX);
mutt_default_save(p->data, p->dsize, e);
mutt_buffer_fix_dptr(p);
return;
/* This reduces the size of the Buffer, so we can pass it through.
* We adjust the size just to make sure buf->data is not NULL though */
- mutt_buffer_increase_size(buf, PATH_MAX);
+ mutt_buffer_alloc(buf, PATH_MAX);
mutt_pretty_mailbox(buf->data, buf->dsize);
mutt_buffer_fix_dptr(buf);
}
srccopy[n - 1] = '\0';
/* prepare Buffers */
- struct Buffer *srcbuf = mutt_buffer_from(srccopy);
+ struct Buffer srcbuf = { 0 };
+ mutt_buffer_addstr(&srcbuf, srccopy);
/* note: we are resetting dptr and *reading* from the buffer, so we don't
* want to use mutt_buffer_reset(). */
- srcbuf->dptr = srcbuf->data;
- struct Buffer *word = mutt_buffer_new();
- struct Buffer *cmd = mutt_buffer_new();
+ srcbuf.dptr = srcbuf.data;
+ struct Buffer word = { 0 };
+ struct Buffer cmd = { 0 };
/* Iterate expansions across successive arguments */
do
{
/* Extract the command name and copy to command line */
- mutt_debug(LL_DEBUG3, "fmtpipe +++: %s\n", srcbuf->dptr);
- if (word->data)
- *word->data = '\0';
- mutt_extract_token(word, srcbuf, MUTT_TOKEN_NO_FLAGS);
- mutt_debug(LL_DEBUG3, "fmtpipe %2d: %s\n", i++, word->data);
- mutt_buffer_addch(cmd, '\'');
- mutt_expando_format(tmp, sizeof(tmp), 0, cols, word->data, callback,
+ mutt_debug(LL_DEBUG3, "fmtpipe +++: %s\n", srcbuf.dptr);
+ if (word.data)
+ *word.data = '\0';
+ mutt_extract_token(&word, &srcbuf, MUTT_TOKEN_NO_FLAGS);
+ mutt_debug(LL_DEBUG3, "fmtpipe %2d: %s\n", i++, word.data);
+ mutt_buffer_addch(&cmd, '\'');
+ mutt_expando_format(tmp, sizeof(tmp), 0, cols, word.data, callback,
data, flags | MUTT_FORMAT_NOFILTER);
for (char *p = tmp; p && *p; p++)
{
* single-quoted material. double-quoting instead will lead
* shell variable expansions, so break out of the single-quoted
* span, insert a double-quoted single quote, and resume. */
- mutt_buffer_addstr(cmd, "'\"'\"'");
+ mutt_buffer_addstr(&cmd, "'\"'\"'");
}
else
- mutt_buffer_addch(cmd, *p);
+ mutt_buffer_addch(&cmd, *p);
}
- mutt_buffer_addch(cmd, '\'');
- mutt_buffer_addch(cmd, ' ');
- } while (MoreArgs(srcbuf));
+ mutt_buffer_addch(&cmd, '\'');
+ mutt_buffer_addch(&cmd, ' ');
+ } while (MoreArgs(&srcbuf));
- mutt_debug(LL_DEBUG3, "fmtpipe > %s\n", cmd->data);
+ mutt_debug(LL_DEBUG3, "fmtpipe > %s\n", cmd.data);
col -= wlen; /* reset to passed in value */
wptr = buf; /* reset write ptr */
- pid_t pid = mutt_create_filter(cmd->data, NULL, &fp_filter, NULL);
+ pid_t pid = mutt_create_filter(cmd.data, NULL, &fp_filter, NULL);
if (pid != -1)
{
int rc;
*wptr = '\0';
}
- mutt_buffer_free(&cmd);
- mutt_buffer_free(&srcbuf);
- mutt_buffer_free(&word);
+ mutt_buffer_dealloc(&cmd);
+ mutt_buffer_dealloc(&srcbuf);
+ mutt_buffer_dealloc(&word);
return;
}
}
if (rc >= 0)
{
m->mx_ops = mx_get_ops(m->magic);
- mutt_buffer_strcpy(m->pathbuf, m->realpath);
+ mutt_buffer_strcpy(&m->pathbuf, m->realpath);
}
return rc;
m = mailbox_new();
m->flags = MB_HIDDEN;
- mutt_buffer_strcpy(m->pathbuf, path);
+ mutt_buffer_strcpy(&m->pathbuf, path);
mx_path_canon2(m, C_Folder);
return m;
else
email_get_fullpath(e, old_file, sizeof(old_file));
- mutt_buffer_strcpy(m->pathbuf, edata->folder);
+ mutt_buffer_strcpy(&m->pathbuf, edata->folder);
m->magic = edata->magic;
rc = mh_sync_mailbox_message(m, i, h);
- mutt_buffer_strcpy(m->pathbuf, uri);
+ mutt_buffer_strcpy(&m->pathbuf, uri);
m->magic = MUTT_NOTMUCH;
if (rc)
FREE(&edata->oldpath);
}
- mutt_buffer_strcpy(m->pathbuf, uri);
+ mutt_buffer_strcpy(&m->pathbuf, uri);
m->magic = MUTT_NOTMUCH;
nm_db_release(m);
{
static char searchbuf[256] = { 0 };
char buf[1024];
- struct Buffer *helpstr = NULL;
int ch = 0, rc = -1;
bool first = true;
int searchctx = 0;
(rd.line_info[i].syntax)[0].last = -1;
}
- helpstr = mutt_buffer_new();
+ struct Buffer helpstr = { 0 };
mutt_compile_help(buf, sizeof(buf), MENU_PAGER, PagerHelp);
- mutt_buffer_strcpy(helpstr, buf);
+ mutt_buffer_strcpy(&helpstr, buf);
if (IsEmail(extra))
{
mutt_compile_help(buf, sizeof(buf), MENU_PAGER,
PagerNewsHelpExtra :
#endif
PagerHelpExtra);
- mutt_buffer_addch(helpstr, ' ');
- mutt_buffer_addstr(helpstr, buf);
+ mutt_buffer_addch(&helpstr, ' ');
+ mutt_buffer_addstr(&helpstr, buf);
}
if (!InHelp)
{
mutt_make_help(buf, sizeof(buf), _("Help"), MENU_PAGER, OP_HELP);
- mutt_buffer_addch(helpstr, ' ');
- mutt_buffer_addstr(helpstr, buf);
+ mutt_buffer_addch(&helpstr, ' ');
+ mutt_buffer_addstr(&helpstr, buf);
}
- rd.helpstr = mutt_b2s(helpstr);
+ rd.helpstr = mutt_b2s(&helpstr);
rd.index_status_window = mutt_window_new();
rd.index_window = mutt_window_new();
int check = mx_mbox_check(Context->mailbox, &index_hint);
if (check < 0)
{
- if (!Context->mailbox || mutt_buffer_is_empty(Context->mailbox->pathbuf))
+ if (!Context->mailbox || mutt_buffer_is_empty(&Context->mailbox->pathbuf))
{
/* fatal error occurred */
ctx_free(&Context);
mutt_menu_free(&pager_menu);
mutt_menu_free(&rd.menu);
- mutt_buffer_free(&helpstr);
+ mutt_buffer_dealloc(&helpstr);
mutt_window_free(&rd.index_status_window);
mutt_window_free(&rd.index_window);
mutt_window_free(&rd.pager_status_window);
url.path = NULL;
url_tostring(&url, buf, sizeof(buf), 0);
- mutt_buffer_strcpy(m->pathbuf, buf);
+ mutt_buffer_strcpy(&m->pathbuf, buf);
mutt_str_replace(&m->realpath, mailbox_path(m));
struct PopAccountData *adata = m->account->adata;
/* check whether C_Folder is a prefix of the current folder's path */
bool maildir_is_prefix = false;
- if ((mutt_buffer_len(m->pathbuf) > maildirlen) &&
+ if ((mutt_buffer_len(&m->pathbuf) > maildirlen) &&
(mutt_str_strncmp(C_Folder, mailbox_path(m), maildirlen) == 0) &&
C_SidebarDelimChars && strchr(C_SidebarDelimChars, mailbox_path(m)[maildirlen]))
{
{
mutt_str_strfcpy(tmp, m->name, sizeof(tmp));
}
- else if (m && !mutt_buffer_is_empty(m->pathbuf))
+ else if (m && !mutt_buffer_is_empty(&m->pathbuf))
{
mutt_str_strfcpy(tmp, mailbox_path(m), sizeof(tmp));
mutt_pretty_mailbox(tmp, sizeof(tmp));
test/buffer/mutt_buffer_fix_dptr.o \
test/buffer/mutt_buffer_free.o \
test/buffer/mutt_buffer_from.o \
- test/buffer/mutt_buffer_increase_size.o \
test/buffer/mutt_buffer_init.o \
test/buffer/mutt_buffer_is_empty.o \
test/buffer/mutt_buffer_len.o \
}
{
- struct Buffer *buf = mutt_buffer_new();
- TEST_CHECK(mutt_b64_buffer_encode(buf, NULL, 10) == 0);
- mutt_buffer_free(&buf);
+ struct Buffer buf = { 0 };
+ TEST_CHECK(mutt_b64_buffer_encode(&buf, NULL, 10) == 0);
+ mutt_buffer_dealloc(&buf);
}
}
{
TEST_CASE("Empty");
- struct Buffer *buf = mutt_buffer_new();
- TEST_CHECK(mutt_buffer_add_printf(buf, "") == 0);
- TEST_CHECK(strlen(mutt_b2s(buf)) == 0);
- mutt_buffer_free(&buf);
+ struct Buffer buf = { 0 };
+ TEST_CHECK(mutt_buffer_add_printf(&buf, "") == 0);
+ TEST_CHECK(strlen(mutt_b2s(&buf)) == 0);
+ mutt_buffer_dealloc(&buf);
}
{
TEST_CASE("Static");
const char *str = "apple";
- struct Buffer *buf = mutt_buffer_new();
- TEST_CHECK(mutt_buffer_add_printf(buf, str) == 5);
- TEST_CHECK(strcmp(mutt_b2s(buf), str) == 0);
- mutt_buffer_free(&buf);
+ struct Buffer buf = { 0 };
+ TEST_CHECK(mutt_buffer_add_printf(&buf, str) == 5);
+ TEST_CHECK(strcmp(mutt_b2s(&buf), str) == 0);
+ mutt_buffer_dealloc(&buf);
}
{
"apple banana cherry damson elderberry fig guava hawthorn ilama "
"jackfruit kumquat lemon mango nectarine olive papaya quince raspberry "
"strawberry tangerine ugli vanilla wolfberry xigua yew ziziphus";
- struct Buffer *buf = mutt_buffer_new();
- TEST_CHECK(mutt_buffer_add_printf(buf, str) == 195);
- TEST_CHECK(strcmp(mutt_b2s(buf), str) == 0);
- mutt_buffer_free(&buf);
+ struct Buffer buf = { 0 };
+ TEST_CHECK(mutt_buffer_add_printf(&buf, str) == 195);
+ TEST_CHECK(strcmp(mutt_b2s(&buf), str) == 0);
+ mutt_buffer_dealloc(&buf);
}
{
TEST_CASE("Varargs");
const char *str = "apple";
const char *result = "app 1234567 3.1416";
- struct Buffer *buf = mutt_buffer_new();
- TEST_CHECK(mutt_buffer_add_printf(buf, "%.3s %ld %3.4f", str, 1234567, 3.141592654) == 18);
- TEST_CHECK(strcmp(mutt_b2s(buf), result) == 0);
- mutt_buffer_free(&buf);
+ struct Buffer buf = { 0 };
+ TEST_CHECK(mutt_buffer_add_printf(&buf, "%.3s %ld %3.4f", str, 1234567, 3.141592654) == 18);
+ TEST_CHECK(strcmp(mutt_b2s(&buf), result) == 0);
+ mutt_buffer_dealloc(&buf);
}
TEST_CASE("printf to a non-empty Buffer");
}
{
- struct Buffer *buf = mutt_buffer_new();
- TEST_CHECK(mutt_buffer_addch(buf, 'a') == 1);
- TEST_CHECK(strcmp(mutt_b2s(buf), "a") == 0);
- mutt_buffer_free(&buf);
+ struct Buffer buf = { 0 };
+ TEST_CHECK(mutt_buffer_addch(&buf, 'a') == 1);
+ TEST_CHECK(strcmp(mutt_b2s(&buf), "a") == 0);
+ mutt_buffer_dealloc(&buf);
}
{
}
{
- struct Buffer *buf = mutt_buffer_new();
- TEST_CHECK(mutt_buffer_addstr(buf, "apple") == 5);
- TEST_CHECK(strcmp(mutt_b2s(buf), "apple") == 0);
- mutt_buffer_free(&buf);
+ struct Buffer buf = { 0 };
+ TEST_CHECK(mutt_buffer_addstr(&buf, "apple") == 5);
+ TEST_CHECK(strcmp(mutt_b2s(&buf), "apple") == 0);
+ mutt_buffer_dealloc(&buf);
}
{
for (size_t i = 0; i < mutt_array_size(sizes); i++)
{
TEST_CASE_("%ld", sizes[i]);
- struct Buffer *buf = mutt_buffer_new();
- TEST_CHECK(mutt_buffer_addstr_n(buf, str, sizes[i]) == sizes[i]);
- TEST_CHECK(strlen(mutt_b2s(buf)) == MIN(len, sizes[i]));
- TEST_CHECK(strncmp(mutt_b2s(buf), str, sizes[i]) == 0);
- mutt_buffer_free(&buf);
+ struct Buffer buf = { 0 };
+ TEST_CHECK(mutt_buffer_addstr_n(&buf, str, sizes[i]) == sizes[i]);
+ TEST_CHECK(strlen(mutt_b2s(&buf)) == MIN(len, sizes[i]));
+ TEST_CHECK(strncmp(mutt_b2s(&buf), str, sizes[i]) == 0);
+ mutt_buffer_dealloc(&buf);
}
}
#define TEST_NO_MAIN
#include "acutest.h"
#include "config.h"
-#include <stdbool.h>
#include "mutt/mutt.h"
void test_mutt_buffer_alloc(void)
{
- // struct Buffer *mutt_buffer_alloc(size_t size);
+ // void mutt_buffer_alloc(struct Buffer *buf, size_t new_size);
- size_t alloc_tests[] = { 0, 42, 1048576 };
+ {
+ mutt_buffer_alloc(NULL, 10);
+ TEST_CHECK_(1, "mutt_buffer_alloc(NULL, 10)");
+ }
+
+ {
+ struct Buffer buf = { 0 };
+ mutt_buffer_alloc(&buf, 10);
+ TEST_CHECK_(1, "mutt_buffer_alloc(buf, 10)");
+ mutt_buffer_dealloc(&buf);
+ }
- for (size_t i = 0; i < mutt_array_size(alloc_tests); i++)
{
- struct Buffer *buf = NULL;
- TEST_CASE_("%lu", alloc_tests[i]);
- buf = mutt_buffer_alloc(alloc_tests[i]);
- TEST_CHECK(buf != NULL);
- mutt_buffer_free(&buf);
+ const int orig_size = 64;
+ static int sizes[] = { 0, 32, 64, 128 };
+
+ for (size_t i = 0; i < mutt_array_size(sizes); i++)
+ {
+ struct Buffer buf = { 0 };
+ mutt_buffer_alloc(&buf, orig_size);
+ TEST_CASE_("%d", sizes[i]);
+ mutt_buffer_alloc(&buf, sizes[i]);
+ TEST_CHECK(buf.dsize == MAX(orig_size, sizes[i]));
+ mutt_buffer_dealloc(&buf);
+ }
}
}
TEST_CASE_("DIR: '%s' FILE: '%s'", NONULL(concat_test[i][0]),
NONULL(concat_test[i][1]));
{
- struct Buffer *buf = mutt_buffer_new();
- mutt_buffer_concat_path(buf, concat_test[i][0], concat_test[i][1]);
+ struct Buffer buf = { 0 };
+ mutt_buffer_concat_path(&buf, concat_test[i][0], concat_test[i][1]);
if (concat_test[i][2])
{
- TEST_CHECK(strcmp(mutt_b2s(buf), concat_test[i][2]) == 0);
+ TEST_CHECK(strcmp(mutt_b2s(&buf), concat_test[i][2]) == 0);
}
else
{
- if (!TEST_CHECK(strlen(mutt_b2s(buf)) == 0))
+ if (!TEST_CHECK(strlen(mutt_b2s(&buf)) == 0))
{
- TEST_MSG("len = %ld", strlen(mutt_b2s(buf)));
+ TEST_MSG("len = %ld", strlen(mutt_b2s(&buf)));
}
}
- mutt_buffer_free(&buf);
+ mutt_buffer_dealloc(&buf);
}
{
}
{
- struct Buffer *buf = mutt_buffer_new();
- mutt_buffer_fix_dptr(buf);
- TEST_CHECK(mutt_buffer_len(buf) == 0);
- mutt_buffer_free(&buf);
+ struct Buffer buf = { 0 };
+ mutt_buffer_fix_dptr(&buf);
+ TEST_CHECK(mutt_buffer_len(&buf) == 0);
}
{
+++ /dev/null
-/**
- * @file
- * Test code for mutt_buffer_increase_size()
- *
- * @authors
- * Copyright (C) 2019 Richard Russon <rich@flatcap.org>
- *
- * @copyright
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 2 of the License, or (at your option) any later
- * version.
- *
- * 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/>.
- */
-
-#define TEST_NO_MAIN
-#include "acutest.h"
-#include "config.h"
-#include "mutt/mutt.h"
-
-void test_mutt_buffer_increase_size(void)
-{
- // void mutt_buffer_increase_size(struct Buffer *buf, size_t new_size);
-
- {
- mutt_buffer_increase_size(NULL, 10);
- TEST_CHECK_(1, "mutt_buffer_increase_size(NULL, 10)");
- }
-
- {
- struct Buffer *buf = mutt_buffer_new();
- mutt_buffer_increase_size(buf, 10);
- TEST_CHECK_(1, "mutt_buffer_increase_size(buf, 10)");
- mutt_buffer_free(&buf);
- }
-
- {
- const int orig_size = 64;
- static int sizes[] = { 0, 32, 64, 128 };
-
- for (size_t i = 0; i < mutt_array_size(sizes); i++)
- {
- struct Buffer *buf = mutt_buffer_alloc(orig_size);
- TEST_CASE_("%d", sizes[i]);
- mutt_buffer_increase_size(buf, sizes[i]);
- TEST_CHECK(buf->dsize == MAX(orig_size, sizes[i]));
- mutt_buffer_free(&buf);
- }
- }
-}
}
{
- struct Buffer *buf = mutt_buffer_new();
- TEST_CHECK(mutt_buffer_init(buf) != NULL);
- mutt_buffer_free(&buf);
+ struct Buffer buf = { 0 };
+ TEST_CHECK(mutt_buffer_init(&buf) != NULL);
}
}
}
{
- struct Buffer *buf = mutt_buffer_new();
- TEST_CHECK(mutt_buffer_is_empty(buf));
- mutt_buffer_free(&buf);
+ struct Buffer buf = { 0 };
+ TEST_CHECK(mutt_buffer_is_empty(&buf));
}
{
}
{
- struct Buffer *buf = mutt_buffer_new();
- TEST_CHECK(mutt_buffer_len(buf) == 0);
- mutt_buffer_free(&buf);
+ struct Buffer buf = { 0 };
+ TEST_CHECK(mutt_buffer_len(&buf) == 0);
}
{
{
TEST_CASE("Empty");
- struct Buffer *buf = mutt_buffer_new();
- TEST_CHECK(mutt_buffer_printf(buf, "") == 0);
- TEST_CHECK(strlen(mutt_b2s(buf)) == 0);
- mutt_buffer_free(&buf);
+ struct Buffer buf = { 0 };
+ TEST_CHECK(mutt_buffer_printf(&buf, "") == 0);
+ TEST_CHECK(strlen(mutt_b2s(&buf)) == 0);
+ mutt_buffer_dealloc(&buf);
}
{
TEST_CASE("Static");
const char *str = "apple";
- struct Buffer *buf = mutt_buffer_new();
- TEST_CHECK(mutt_buffer_printf(buf, str) == 5);
- TEST_CHECK(strcmp(mutt_b2s(buf), str) == 0);
- mutt_buffer_free(&buf);
+ struct Buffer buf = { 0 };
+ TEST_CHECK(mutt_buffer_printf(&buf, str) == 5);
+ TEST_CHECK(strcmp(mutt_b2s(&buf), str) == 0);
+ mutt_buffer_dealloc(&buf);
}
{
TEST_CASE("Varargs");
const char *str = "apple";
const char *result = "app 1234567 3.1416";
- struct Buffer *buf = mutt_buffer_new();
- TEST_CHECK(mutt_buffer_printf(buf, "%.3s %ld %3.4f", str, 1234567, 3.141592654) == 18);
- TEST_CHECK(strcmp(mutt_b2s(buf), result) == 0);
- mutt_buffer_free(&buf);
+ struct Buffer buf = { 0 };
+ TEST_CHECK(mutt_buffer_printf(&buf, "%.3s %ld %3.4f", str, 1234567, 3.141592654) == 18);
+ TEST_CHECK(strcmp(mutt_b2s(&buf), result) == 0);
+ mutt_buffer_dealloc(&buf);
}
TEST_CASE("printf to a non-empty Buffer");
}
{
- struct Buffer *buf = mutt_buffer_new();
- mutt_buffer_reset(buf);
+ struct Buffer buf = { 0 };
+ mutt_buffer_reset(&buf);
TEST_CHECK_(1, "mutt_buffer_reset(buf)");
- mutt_buffer_free(&buf);
}
{
{
TEST_CASE("Empty");
- struct Buffer *buf = mutt_buffer_new();
- mutt_buffer_strcpy(buf, "");
- TEST_CHECK(strcmp(mutt_b2s(buf), "") == 0);
- mutt_buffer_free(&buf);
+ struct Buffer buf = { 0 };
+ mutt_buffer_strcpy(&buf, "");
+ TEST_CHECK(strcmp(mutt_b2s(&buf), "") == 0);
+ mutt_buffer_dealloc(&buf);
}
{
TEST_CASE("String");
const char *str = "test";
- struct Buffer *buf = mutt_buffer_new();
- mutt_buffer_strcpy(buf, str);
- TEST_CHECK(strcmp(mutt_b2s(buf), str) == 0);
- mutt_buffer_free(&buf);
+ struct Buffer buf = { 0 };
+ mutt_buffer_strcpy(&buf, str);
+ TEST_CHECK(strcmp(mutt_b2s(&buf), str) == 0);
+ mutt_buffer_dealloc(&buf);
}
TEST_CASE("Overwrite a non-empty Buffer");
for (size_t i = 0; i < mutt_array_size(sizes); i++)
{
TEST_CASE_("%ld", sizes[i]);
- struct Buffer *buf = mutt_buffer_new();
- mutt_buffer_strcpy_n(buf, str, sizes[i]);
- TEST_CHECK(strlen(mutt_b2s(buf)) == MIN(len, sizes[i]));
- TEST_CHECK(strncmp(mutt_b2s(buf), str, sizes[i]) == 0);
- mutt_buffer_free(&buf);
+ struct Buffer buf = { 0 };
+ mutt_buffer_strcpy_n(&buf, str, sizes[i]);
+ TEST_CHECK(strlen(mutt_b2s(&buf)) == MIN(len, sizes[i]));
+ TEST_CHECK(strncmp(mutt_b2s(&buf), str, sizes[i]) == 0);
+ mutt_buffer_dealloc(&buf);
}
}
}
{
- struct Buffer *buf = mutt_buffer_alloc(64);
- if (!TEST_CHECK(pretty_var("apple", buf) > 0))
+ struct Buffer buf = { 0 };
+ mutt_buffer_alloc(&buf, 64);
+ if (!TEST_CHECK(pretty_var("apple", &buf) > 0))
{
- mutt_buffer_free(&buf);
+ mutt_buffer_dealloc(&buf);
return false;
}
- if (!TEST_CHECK(mutt_str_strcmp("\"apple\"", mutt_b2s(buf)) == 0))
+ if (!TEST_CHECK(mutt_str_strcmp("\"apple\"", mutt_b2s(&buf)) == 0))
{
- mutt_buffer_free(&buf);
+ mutt_buffer_dealloc(&buf);
return false;
}
- mutt_buffer_free(&buf);
+ mutt_buffer_dealloc(&buf);
}
return true;
const char *before = "apple\nbanana\rcherry\tdamson\\endive\"fig'grape";
const char *after =
"apple\\nbanana\\rcherry\\tdamson\\\\endive\\\"fig'grape";
- struct Buffer *buf = mutt_buffer_alloc(256);
- if (!TEST_CHECK(escape_string(buf, before) > 0))
+ struct Buffer buf = { 0 };
+ mutt_buffer_alloc(&buf, 256);
+ if (!TEST_CHECK(escape_string(&buf, before) > 0))
{
- mutt_buffer_free(&buf);
+ mutt_buffer_dealloc(&buf);
return false;
}
- if (!TEST_CHECK(mutt_str_strcmp(mutt_b2s(buf), after) == 0))
+ if (!TEST_CHECK(mutt_str_strcmp(mutt_b2s(&buf), after) == 0))
{
- mutt_buffer_free(&buf);
+ mutt_buffer_dealloc(&buf);
return false;
}
- mutt_buffer_free(&buf);
+ mutt_buffer_dealloc(&buf);
}
return true;
}
{
- struct Buffer *buf = mutt_buffer_alloc(32);
- mutt_buffer_file_expand_fmt_quote(buf, "apple", NULL);
+ struct Buffer buf = { 0 };
+ mutt_buffer_alloc(&buf, 32);
+ mutt_buffer_file_expand_fmt_quote(&buf, "apple", NULL);
TEST_CHECK_(1, "mutt_buffer_file_expand_fmt_quote(&buf, \"apple\", NULL)");
- mutt_buffer_free(&buf);
+ mutt_buffer_dealloc(&buf);
}
mutt_buffer_pool_free();
NEOMUTT_TEST_ITEM(test_mutt_buffer_fix_dptr) \
NEOMUTT_TEST_ITEM(test_mutt_buffer_free) \
NEOMUTT_TEST_ITEM(test_mutt_buffer_from) \
- NEOMUTT_TEST_ITEM(test_mutt_buffer_increase_size) \
NEOMUTT_TEST_ITEM(test_mutt_buffer_init) \
NEOMUTT_TEST_ITEM(test_mutt_buffer_is_empty) \
NEOMUTT_TEST_ITEM(test_mutt_buffer_len) \
}
{
- struct Buffer *buf = mutt_buffer_new();
- mutt_path_getcwd(buf);
- TEST_CHECK(buf->data[0] == '/');
- mutt_buffer_free(&buf);
+ struct Buffer buf = { 0 };
+ mutt_path_getcwd(&buf);
+ TEST_CHECK(buf.data[0] == '/');
+ mutt_buffer_dealloc(&buf);
}
}
void test_mutt_pattern_comp(void)
{
- struct Buffer *err = mutt_buffer_alloc(1024);
+ struct Buffer err = { 0 };
+ mutt_buffer_alloc(&err, 1024);
{ /* empty */
char *s = "";
- mutt_buffer_reset(err);
- struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+ mutt_buffer_reset(&err);
+ struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
if (!TEST_CHECK(!pat))
{
}
char *msg = "empty pattern";
- if (!TEST_CHECK(!strcmp(err->data, msg)))
+ if (!TEST_CHECK(!strcmp(err.data, msg)))
{
TEST_MSG("Expected: %s", msg);
- TEST_MSG("Actual : %s", err->data);
+ TEST_MSG("Actual : %s", err.data);
}
}
{ /* invalid */
char *s = "x";
- mutt_buffer_reset(err);
- struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+ mutt_buffer_reset(&err);
+ struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
if (!TEST_CHECK(!pat))
{
}
char *msg = "error in pattern at: x";
- if (!TEST_CHECK(!strcmp(err->data, msg)))
+ if (!TEST_CHECK(!strcmp(err.data, msg)))
{
TEST_MSG("Expected: %s", msg);
- TEST_MSG("Actual : %s", err->data);
+ TEST_MSG("Actual : %s", err.data);
}
}
{ /* missing parameter */
char *s = "=s";
- mutt_buffer_reset(err);
- struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+ mutt_buffer_reset(&err);
+ struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
if (!TEST_CHECK(!pat))
{
}
char *msg = "missing parameter";
- if (!TEST_CHECK(!strcmp(err->data, msg)))
+ if (!TEST_CHECK(!strcmp(err.data, msg)))
{
TEST_MSG("Expected: %s", msg);
- TEST_MSG("Actual : %s", err->data);
+ TEST_MSG("Actual : %s", err.data);
}
}
{ /* error in pattern */
char *s = "| =s foo";
- mutt_buffer_reset(err);
- struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+ mutt_buffer_reset(&err);
+ struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
if (!TEST_CHECK(!pat))
{
}
char *msg = "error in pattern at: | =s foo";
- if (!TEST_CHECK(!strcmp(err->data, msg)))
+ if (!TEST_CHECK(!strcmp(err.data, msg)))
{
TEST_MSG("Expected: %s", msg);
- TEST_MSG("Actual : %s", err->data);
+ TEST_MSG("Actual : %s", err.data);
}
}
{
char *s = "=s foobar";
- mutt_buffer_reset(err);
- struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+ mutt_buffer_reset(&err);
+ struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
if (!TEST_CHECK(pat != NULL))
{
}
char *msg = "";
- if (!TEST_CHECK(!strcmp(err->data, msg)))
+ if (!TEST_CHECK(!strcmp(err.data, msg)))
{
TEST_MSG("Expected: %s", msg);
- TEST_MSG("Actual : %s", err->data);
+ TEST_MSG("Actual : %s", err.data);
}
mutt_pattern_free(&pat);
{
char *s = "! =s foobar";
- mutt_buffer_reset(err);
- struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+ mutt_buffer_reset(&err);
+ struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
if (!TEST_CHECK(pat != NULL))
{
}
char *msg = "";
- if (!TEST_CHECK(!strcmp(err->data, msg)))
+ if (!TEST_CHECK(!strcmp(err.data, msg)))
{
TEST_MSG("Expected: %s", msg);
- TEST_MSG("Actual : %s", err->data);
+ TEST_MSG("Actual : %s", err.data);
}
mutt_pattern_free(&pat);
{
char *s = "=s foo =s bar";
- mutt_buffer_reset(err);
- struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+ mutt_buffer_reset(&err);
+ struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
if (!TEST_CHECK(pat != NULL))
{
}
char *msg = "";
- if (!TEST_CHECK(!strcmp(err->data, msg)))
+ if (!TEST_CHECK(!strcmp(err.data, msg)))
{
TEST_MSG("Expected: %s", msg);
- TEST_MSG("Actual : %s", err->data);
+ TEST_MSG("Actual : %s", err.data);
}
mutt_pattern_free(&pat);
{
char *s = "(=s foo =s bar)";
- mutt_buffer_reset(err);
- struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+ mutt_buffer_reset(&err);
+ struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
if (!TEST_CHECK(pat != NULL))
{
}
char *msg = "";
- if (!TEST_CHECK(!strcmp(err->data, msg)))
+ if (!TEST_CHECK(!strcmp(err.data, msg)))
{
TEST_MSG("Expected: %s", msg);
- TEST_MSG("Actual : %s", err->data);
+ TEST_MSG("Actual : %s", err.data);
}
mutt_pattern_free(&pat);
{
char *s = "! (=s foo =s bar)";
- mutt_buffer_reset(err);
- struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+ mutt_buffer_reset(&err);
+ struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
if (!TEST_CHECK(pat != NULL))
{
}
char *msg = "";
- if (!TEST_CHECK(!strcmp(err->data, msg)))
+ if (!TEST_CHECK(!strcmp(err.data, msg)))
{
TEST_MSG("Expected: %s", msg);
- TEST_MSG("Actual : %s", err->data);
+ TEST_MSG("Actual : %s", err.data);
}
mutt_pattern_free(&pat);
{
char *s = "=s foo =s bar =s quux";
- mutt_buffer_reset(err);
- struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+ mutt_buffer_reset(&err);
+ struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
if (!TEST_CHECK(pat != NULL))
{
}
char *msg = "";
- if (!TEST_CHECK(!strcmp(err->data, msg)))
+ if (!TEST_CHECK(!strcmp(err.data, msg)))
{
TEST_MSG("Expected: %s", msg);
- TEST_MSG("Actual : %s", err->data);
+ TEST_MSG("Actual : %s", err.data);
}
mutt_pattern_free(&pat);
{
char *s = "!(=s foo|=s bar) =s quux";
- mutt_buffer_reset(err);
- struct PatternList *pat = mutt_pattern_comp(s, 0, err);
+ mutt_buffer_reset(&err);
+ struct PatternList *pat = mutt_pattern_comp(s, 0, &err);
if (!TEST_CHECK(pat != NULL))
{
}
char *msg = "";
- if (!TEST_CHECK(!strcmp(err->data, msg)))
+ if (!TEST_CHECK(!strcmp(err.data, msg)))
{
TEST_MSG("Expected: %s", msg);
- TEST_MSG("Actual : %s", err->data);
+ TEST_MSG("Actual : %s", err.data);
}
mutt_pattern_free(&pat);
}
- mutt_buffer_free(&err);
+ mutt_buffer_dealloc(&err);
}
{
log_line(__func__);
- struct Buffer *buf = mutt_buffer_new();
+ struct Buffer buf = { 0 };
{ /* handle edge cases */
- struct Regex *rx = regex_new("hello bob", 0, buf);
+ struct Regex *rx = regex_new("hello bob", 0, &buf);
const bool failed = !TEST_CHECK(mutt_regex_match(NULL, NULL) == false) ||
!TEST_CHECK(mutt_regex_match(NULL, "bob the string") == false) ||
}
{ /* handle normal cases */
- struct Regex *rx = regex_new("hell", 0, buf);
+ struct Regex *rx = regex_new("hell", 0, &buf);
const bool failed =
!TEST_CHECK(mutt_regex_match(rx, "hello there")) ||
{ /* test more elaborate regex */
const char *input = "bob bob bob mary bob jonny bob jon jon joe bob";
- struct Regex *rx = regex_new("bob", 0, buf);
+ struct Regex *rx = regex_new("bob", 0, &buf);
const bool result = mutt_regex_capture(rx, input, 0, NULL);
const bool failed = !TEST_CHECK(result);
{ /* test passing simple flags */
const char *input = "BOB";
- struct Regex *rx = regex_new("bob", 0, buf);
+ struct Regex *rx = regex_new("bob", 0, &buf);
const bool failed = !TEST_CHECK(mutt_regex_capture(rx, input, 0, 0));
regex_free(&rx);
return false;
}
- mutt_buffer_free(&buf);
+ mutt_buffer_dealloc(&buf);
return true;
}
const char *bob_line = "definitely bob haha";
const char *not_bob_line = "john dave marty nothing else here";
- struct Buffer *buf = mutt_buffer_new();
+ struct Buffer buf = { 0 };
{
// from: if (regexec(C_PgpGoodSign->regex, bob_line, 0, NULL, 0) == 0)
// to: if (mutt_regex_match(C_PgpGoodSign, bob_line))
- struct Regex *rx = regex_new("bob", 0, buf);
+ struct Regex *rx = regex_new("bob", 0, &buf);
const bool old = regexec(rx->regex, bob_line, 0, NULL, 0) == 0;
const bool new = mutt_regex_match(rx, bob_line);
const bool failed = !TEST_CHECK(old == new);
const int nmatch = 1;
regmatch_t pmatch_1[nmatch], pmatch_2[nmatch];
- struct Regex *rx = regex_new("bob", 0, buf);
+ struct Regex *rx = regex_new("bob", 0, &buf);
const bool old = regexec(rx->regex, bob_line, nmatch, pmatch_1, 0) == 0;
const bool new = mutt_regex_capture(rx, bob_line, 1, pmatch_2);
const bool failed_common_behavior = !TEST_CHECK(old == new);
const int nmatch = 1;
regmatch_t pmatch_1[nmatch], pmatch_2[nmatch];
- struct Regex *rx = regex_new("bob", 0, buf);
+ struct Regex *rx = regex_new("bob", 0, &buf);
const bool old = rx && rx->regex &&
(regexec(rx->regex, bob_line, nmatch, pmatch_1, 0) == 0);
const bool new = mutt_regex_capture(rx, bob_line, 1, pmatch_2);
// tmp->regex.pat_not))
// to: if ((tmp->type & hook) && mutt_regex_match(&tmp->regex, match))
- struct Regex *rx = regex_new("!bob", DT_REGEX_ALLOW_NOT, buf);
+ struct Regex *rx = regex_new("!bob", DT_REGEX_ALLOW_NOT, &buf);
const bool old =
(regexec(rx->regex, not_bob_line, 0, NULL, DT_REGEX_ALLOW_NOT) == 0) ^ rx->pat_not;
const bool new = mutt_regex_match(rx, not_bob_line);
// ^ C_Mask->pat_not))
// to: if(mutt_regex_match(C_Mask, de->d_name))
- struct Regex *rx = regex_new("!bob", DT_REGEX_ALLOW_NOT, buf);
+ struct Regex *rx = regex_new("!bob", DT_REGEX_ALLOW_NOT, &buf);
const bool old = rx && rx->regex &&
!((regexec(rx->regex, not_bob_line, 0, NULL, 0) == 0) ^ rx->pat_not);
const bool new = mutt_regex_match(rx, bob_line);
// from: if (C_Mask && C_Mask->regex &&
// !((regexec(C_Mask->regex, mdata->group, 0, NULL, 0) == 0) ^ C_Mask->pat_not))
// to: if (!mutt_regex_match(C_Mask, mdata->group))
- struct Regex *rx = regex_new("!bob", DT_REGEX_ALLOW_NOT, buf);
+ struct Regex *rx = regex_new("!bob", DT_REGEX_ALLOW_NOT, &buf);
const bool old = (rx && rx->regex) &&
!((regexec(rx->regex, line, 0, NULL, 0) == 0) ^ rx->pat_not);
const bool new = !mutt_regex_match(rx, line);
// if ((regexec(hook->regex.regex, url, 0, NULL, 0) == 0) ^ hook->regex.pat_not)
// if (mutt_regex_match(&hook->regex, url))
- struct Regex *rx = regex_new("bob", 0, buf);
+ struct Regex *rx = regex_new("bob", 0, &buf);
const bool old = (regexec(rx->regex, bob_line, 0, NULL, 0) == 0) ^ rx->pat_not;
const bool new = mutt_regex_match(rx, bob_line);
regex_free(&rx);
return false;
}
- mutt_buffer_free(&buf);
+ mutt_buffer_dealloc(&buf);
return true;
}