From 0df316c55471d33da6e30bca4a2794dec56dd664 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Sun, 22 Sep 2019 14:16:56 -0700 Subject: [PATCH] Convert buffer callers of mutt_get_field() to use buffer version Co-authored-by: Richard Russon --- browser.c | 10 ++++------ curs_lib.c | 9 ++++----- muttlib.c | 10 ++-------- pattern.c | 5 ++--- recvattach.c | 14 ++++---------- test/pattern/dummy.c | 7 +++++++ 6 files changed, 23 insertions(+), 32 deletions(-) diff --git a/browser.c b/browser.c index 012eb8be9..617b5a1e6 100644 --- a/browser.c +++ b/browser.c @@ -1686,8 +1686,8 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags, if (op == OP_CHANGE_DIRECTORY) { /* buf comes from the buffer pool, so defaults to size 1024 */ - int ret = mutt_get_field(_("Chdir to: "), buf->data, buf->dsize, MUTT_FILE); - if ((ret != 0) && (mutt_b2s(buf)[0] == '\0')) + int ret = mutt_buffer_get_field(_("Chdir to: "), buf, MUTT_FILE); + if ((ret != 0) && mutt_buffer_is_empty(buf)) break; } else if (op == OP_GOTO_PARENT) @@ -1695,7 +1695,6 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags, if (mutt_b2s(buf)[0] != '\0') { - mutt_buffer_fix_dptr(buf); mailbox = false; mutt_buffer_expand_path(buf); #ifdef USE_IMAP @@ -1938,7 +1937,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags, case OP_BROWSER_NEW_FILE: 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) + if (mutt_buffer_get_field(_("New file name: "), buf, MUTT_FILE) == 0) { mutt_buffer_strcpy(file, mutt_b2s(buf)); destroy_state(&state); @@ -2073,8 +2072,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags, else snprintf(tmp2, sizeof(tmp2), _("Unsubscribe pattern: ")); /* buf comes from the buffer pool, so defaults to size 1024 */ - if ((mutt_get_field(tmp2, buf->data, buf->dsize, 0) != 0) || - (mutt_b2s(buf)[0] == '\0')) + if ((mutt_buffer_get_field(tmp2, buf, 0) != 0) || mutt_buffer_is_empty(buf)) { break; } diff --git a/curs_lib.c b/curs_lib.c index 1f4b6b9c8..5ad81a601 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -740,12 +740,11 @@ int mutt_buffer_enter_fname_full(const char *prompt, struct Buffer *fname, mutt_unget_event(0, ch.op); 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) + if (mutt_buffer_get_field_full(pc, fname, (mailbox ? MUTT_EFILE : MUTT_FILE) | MUTT_CLEAR, + multiple, files, numfiles) != 0) + { mutt_buffer_reset(fname); - else - mutt_buffer_fix_dptr(fname); + } FREE(&pc); } diff --git a/muttlib.c b/muttlib.c index 47d53efcf..e59caf7fa 100644 --- a/muttlib.c +++ b/muttlib.c @@ -751,14 +751,8 @@ int mutt_check_overwrite(const char *attname, const char *path, struct Buffer *f struct Buffer *tmp = mutt_buffer_pool_get(); mutt_buffer_strcpy(tmp, mutt_path_basename(NONULL(attname))); - if (mutt_get_field(_("File under directory: "), tmp->data, tmp->dsize, - MUTT_FILE | MUTT_CLEAR) != 0) - { - mutt_buffer_pool_release(&tmp); - return -1; - } - mutt_buffer_fix_dptr(tmp); - if (mutt_buffer_is_empty(tmp)) + if ((mutt_buffer_get_field(_("File under directory: "), tmp, MUTT_FILE | MUTT_CLEAR) != 0) || + mutt_buffer_is_empty(tmp)) { mutt_buffer_pool_release(&tmp); return (-1); diff --git a/pattern.c b/pattern.c index 62cc57b11..f5e657db2 100644 --- a/pattern.c +++ b/pattern.c @@ -2422,14 +2422,13 @@ int mutt_pattern_func(int op, char *prompt) mutt_buffer_strcpy(buf, NONULL(Context->pattern)); if (prompt || (op != MUTT_LIMIT)) { - if ((mutt_get_field(prompt, buf->data, buf->dsize, MUTT_PATTERN | MUTT_CLEAR) != 0) || - !(mutt_b2s(buf)[0])) + if ((mutt_buffer_get_field(prompt, buf, MUTT_PATTERN | MUTT_CLEAR) != 0) || + mutt_buffer_is_empty(buf)) { mutt_buffer_pool_release(&buf); return -1; } } - mutt_buffer_fix_dptr(buf); mutt_message(_("Compiling search pattern...")); diff --git a/recvattach.c b/recvattach.c index f5254cf36..89be6427c 100644 --- a/recvattach.c +++ b/recvattach.c @@ -527,14 +527,11 @@ static int query_save_attachment(FILE *fp, struct Body *body, struct Email *e, c prompt = _("Save to file: "); while (prompt) { - if (mutt_get_field(prompt, buf->data, buf->dsize, MUTT_FILE | MUTT_CLEAR) != 0) + if ((mutt_buffer_get_field(prompt, buf, MUTT_FILE | MUTT_CLEAR) != 0) || + mutt_buffer_is_empty(buf)) { - mutt_clear_error(); goto cleanup; } - mutt_buffer_fix_dptr(buf); - if (mutt_buffer_is_empty(buf)) - goto cleanup; prompt = NULL; mutt_buffer_expand_path(buf); @@ -677,14 +674,11 @@ void mutt_save_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, mutt_buffer_strcpy(buf, mutt_path_basename(NONULL(top->filename))); prepend_savedir(buf); - if (mutt_get_field(_("Save to file: "), buf->data, buf->dsize, - MUTT_FILE | MUTT_CLEAR) != 0) + if ((mutt_buffer_get_field(_("Save to file: "), buf, MUTT_FILE | MUTT_CLEAR) != 0) || + mutt_buffer_is_empty(buf)) { goto cleanup; } - mutt_buffer_fix_dptr(buf); - if (mutt_buffer_is_empty(buf)) - goto cleanup; mutt_buffer_expand_path(buf); if (mutt_check_overwrite(top->filename, mutt_b2s(buf), tfile, &opt, NULL)) goto cleanup; diff --git a/test/pattern/dummy.c b/test/pattern/dummy.c index 57b26e593..a17c21eb5 100644 --- a/test/pattern/dummy.c +++ b/test/pattern/dummy.c @@ -28,6 +28,7 @@ struct Address; struct Body; +struct Buffer; struct Email; struct Envelope; struct Mailbox; @@ -86,6 +87,12 @@ pid_t mutt_create_filter(const char *s, FILE **fp_in, FILE **fp_out, FILE **fp_e return -1; } +int mutt_buffer_get_field_full(const char *field, struct Buffer *buf, int complete, + bool multiple, char ***files, int *numfiles) +{ + return -1; +} + int mutt_get_field_full(const char *field, char *buf, size_t buflen, int complete, bool multiple, char ***files, int *numfiles) { -- 2.40.0