~kevin8t8/mutt

6150d285a5d4252a0e70b87c955502c64ff2f790 — Kevin McCarthy a month ago 95cf171
Clean up Editor Menu interface inside Mutt.

enter_filename() api:

* Rename enter_fname() to _enter_fname()

* Rename mutt_buffer_enter_mailbox() to mutt_enter_mailbox()

* Rename mutt_buffer_enter_filenames() to mutt_enter_filenames()

* Remove 'multiple' and 'fname buffer' parameters from
  mutt_enter_filenames().  Create a temp buffer, and enable multiple
  automatically.  This removes the possibility of mistakenly looking
  at an unpopulated 'fname' parameter for the result.

* Create mutt_enter_filename().  This isn't used currently, but it
  makes sense to have a "single filename" api already set up with
  correct parameters.

get_field() api:

* Rename _mutt_buffer_get_field() to a static _get_field() function.

* Remove _mutt_get_field() and make mutt_get_field() an actual
  function.

* Remove the multiple/files/numfiles parameters, since this
  should only be done through mutt_enter_filenames().

_mutt_enter_string() api:

Add comments to mutt_enter_string() and _mutt_enter_string() headers.
Noting that they should generally not be called directly.  List the
functions that should be used inside Mutt.  Note the behavior of the
multiple parameter.
8 files changed, 74 insertions(+), 43 deletions(-)

M autocrypt/autocrypt.c
M commands.c
M compose.c
M curs_lib.c
M curs_main.c
M enter.c
M protos.h
M send.c
M autocrypt/autocrypt.c => autocrypt/autocrypt.c +1 -1
@@ 860,7 860,7 @@ void mutt_autocrypt_scan_mailboxes (void)
    /* L10N:
       The prompt for a mailbox to scan for Autocrypt: headers
    */
    if ((!mutt_buffer_enter_mailbox (_("Scan mailbox"), folderbuf, 0)) &&
    if ((!mutt_enter_mailbox (_("Scan mailbox"), folderbuf, 0)) &&
        mutt_buffer_len (folderbuf))
    {
      mutt_buffer_expand_path (folderbuf);

M commands.c => commands.c +1 -1
@@ 932,7 932,7 @@ int mutt_save_message (HEADER *h, int delete, int decode, int decrypt)
  }

  mutt_buffer_pretty_mailbox (buf);
  if (mutt_buffer_enter_mailbox (prompt, buf, 0) == -1)
  if (mutt_enter_mailbox (prompt, buf, 0) == -1)
    goto cleanup;
  if (!mutt_buffer_len (buf))
    goto cleanup;

M compose.c => compose.c +3 -5
@@ 1248,12 1248,11 @@ int mutt_compose_menu (SEND_CONTEXT *sctx)
        char *prompt, **files;
        int error, numfiles;

        mutt_buffer_clear (fname);
        prompt = _("Attach file");
        numfiles = 0;
        files = NULL;

        if (mutt_buffer_enter_filenames (prompt, fname, 1, &files, &numfiles) == -1)
        if (mutt_enter_filenames (prompt, &files, &numfiles) == -1)
          break;

        error = 0;


@@ 1298,7 1297,7 @@ int mutt_compose_menu (SEND_CONTEXT *sctx)
          mutt_buffer_pretty_mailbox (fname);
        }

        if ((mutt_buffer_enter_mailbox (prompt, fname, 0) == -1) ||
        if ((mutt_enter_mailbox (prompt, fname, 0) == -1) ||
            !mutt_buffer_len (fname))
          break;



@@ 1820,8 1819,7 @@ int mutt_compose_menu (SEND_CONTEXT *sctx)
        }
        if (actx->idxlen)
          msg->content = actx->idx[0]->content;
        if ((mutt_buffer_enter_mailbox (_("Write message to mailbox"), fname,
                                        0) != -1) &&
        if ((mutt_enter_mailbox (_("Write message to mailbox"), fname, 0) != -1) &&
            mutt_buffer_len (fname))
        {
          mutt_message (_("Writing message to %s ..."), mutt_b2s (fname));

M curs_lib.c => curs_lib.c +41 -25
@@ 208,22 208,8 @@ event_t mutt_getch (void)
  return (ch == ctrl ('G') ? err : ret);
}

int _mutt_get_field (const char *field, char *buf, size_t buflen, int complete, int multiple, char ***files, int *numfiles)
{
  BUFFER *buffer;
  int rc;

  buffer = mutt_buffer_pool_get ();

  mutt_buffer_addstr (buffer, buf);
  rc = _mutt_buffer_get_field (field, buffer, complete, multiple, files, numfiles);
  strfcpy (buf, mutt_b2s (buffer), buflen);

  mutt_buffer_pool_release (&buffer);
  return rc;
}

int _mutt_buffer_get_field (const char *field, BUFFER *buffer, int complete, int multiple, char ***files, int *numfiles)
static int _get_field (const char *field, BUFFER *buffer, int complete,
                       int multiple, char ***files, int *numfiles)
{
  int ret;
  int x;


@@ 262,6 248,26 @@ int _mutt_buffer_get_field (const char *field, BUFFER *buffer, int complete, int
  return (ret);
}

int mutt_get_field (const char *field, char *buf, size_t buflen, int complete)
{
  BUFFER *buffer;
  int rc;

  buffer = mutt_buffer_pool_get ();

  mutt_buffer_addstr (buffer, buf);
  rc = _get_field (field, buffer, complete, 0, NULL, NULL);
  strfcpy (buf, mutt_b2s (buffer), buflen);

  mutt_buffer_pool_release (&buffer);
  return rc;
}

int mutt_buffer_get_field (const char *field, BUFFER *buffer, int complete)
{
  return _get_field (field, buffer, complete, 0, NULL, NULL);
}

int mutt_get_field_unbuffered (char *msg, char *buf, size_t buflen, int flags)
{
  int rc, reset_ignoremacro = 0;


@@ 997,7 1003,7 @@ int mutt_do_pager (const char *banner,
  return rc;
}

static int enter_fname (const char *prompt, BUFFER *fname, int flags,
static int _enter_fname (const char *prompt, BUFFER *fname, int flags,
                        int multiple, char ***files, int *numfiles)
{
  event_t ch;


@@ 1036,9 1042,9 @@ static int enter_fname (const char *prompt, BUFFER *fname, int flags,
    mutt_unget_event (ch.op ? 0 : ch.ch, ch.op ? ch.op : 0);

    mutt_buffer_increase_size (fname, LONG_STRING);
    if (_mutt_buffer_get_field (pc, fname,
                                flags | MUTT_CLEAR,
                                multiple, files, numfiles) != 0)
    if (_get_field (pc, fname,
                    flags | MUTT_CLEAR,
                    multiple, files, numfiles) != 0)
      mutt_buffer_clear (fname);
    FREE (&pc);
  }


@@ 1046,20 1052,30 @@ static int enter_fname (const char *prompt, BUFFER *fname, int flags,
  return 0;
}

int mutt_buffer_enter_mailbox (const char *prompt, BUFFER *fname, int do_incoming)
int mutt_enter_mailbox (const char *prompt, BUFFER *fname, int do_incoming)
{
  int flags = MUTT_MAILBOX;

  if (do_incoming)
    flags |= MUTT_INCOMING;

  return enter_fname (prompt, fname, flags, 0, NULL, NULL);
  return _enter_fname (prompt, fname, flags, 0, NULL, NULL);
}

int mutt_enter_filename (const char *prompt, BUFFER *fname)
{
  return _enter_fname (prompt, fname, MUTT_FILE, 0, NULL, NULL);
}

int mutt_buffer_enter_filenames (const char *prompt, BUFFER *fname,
                                 int multiple, char ***files, int *numfiles)
int mutt_enter_filenames (const char *prompt, char ***files, int *numfiles)
{
  return enter_fname (prompt, fname, MUTT_FILE, multiple, files, numfiles);
  BUFFER *tmp;
  int rc;

  tmp = mutt_buffer_pool_get ();
  rc = _enter_fname (prompt, tmp, MUTT_FILE, 1, files, numfiles);
  mutt_buffer_pool_release (&tmp);
  return rc;
}

void mutt_unget_event (int ch, int op)

M curs_main.c => curs_main.c +1 -1
@@ 1330,7 1330,7 @@ int mutt_index_menu (void)
          }
	  mutt_buffer_buffy (folderbuf);

          if (mutt_buffer_enter_mailbox (cp, folderbuf, 1) == -1)
          if (mutt_enter_mailbox (cp, folderbuf, 1) == -1)
            goto changefoldercleanup;
	}


M enter.c => enter.c +21 -3
@@ 210,13 210,15 @@ static inline int is_shell_char(wchar_t ch)
/* This function is for very basic input, currently used only by the
 * built-in editor.  It does not handle screen redrawing on resizes
 * well, because there is no active menu for the built-in editor.
 * Most callers should prefer mutt_get_field() instead.
 *
 * Most callers should prefer one of the public functions
 * listed in the comment header for _mutt_enter_string().
 *
 * Returns:
 *	0 if input was given
 * 	-1 if abort.
 */
int  mutt_enter_string(char *buf, size_t buflen, int col, int flags)
int mutt_enter_string (char *buf, size_t buflen, int col, int flags)
{
  int rv;
  ENTER_STATE *es = mutt_new_enter_state ();


@@ 237,7 239,23 @@ int  mutt_enter_string(char *buf, size_t buflen, int col, int flags)
  return rv;
}

/*
/* Generic Editor Menu.
 *
 * This function should not be called directly.  It must be wrapped by
 * _get_field().  Instead call one of the public interfaces:
 *
 *   mutt_enter_filename()
 *   mutt_enter_filenames()
 *   mutt_enter_mailbox()
 *
 *   mutt_get_field() / mutt_buffer_get_field()
 *   mutt_get_field_unbuffered() / mutt_get_password()
 *
 * If multiple is set, then the string (or selected files from the
 * browser) will be returned via files and numfiles.
 *
 * Otherwise the string will be returned inside buf.
 *
 * Returns:
 *      1 need to redraw the screen and call me again
 *	0 if input was given

M protos.h => protos.h +5 -6
@@ 323,14 323,13 @@ int mutt_chscmp (const char *s, const char *chs);
#define mutt_is_us_ascii(a) mutt_chscmp (a, "us-ascii")
int mutt_parent_message (CONTEXT *, HEADER *, int);
int mutt_prepare_template(FILE*, CONTEXT *, HEADER *, HEADER *, short);
int mutt_buffer_enter_filenames (const char *, BUFFER *, int, char ***, int *);
int mutt_buffer_enter_mailbox (const char *, BUFFER *, int);
int mutt_enter_filename (const char *prompt, BUFFER *fname);
int mutt_enter_filenames (const char *prompt, char ***files, int *numfiles);
int mutt_enter_mailbox (const char *, BUFFER *, int);
int  mutt_enter_string (char *buf, size_t buflen, int col, int flags);
int _mutt_enter_string (char *, size_t, int, int, int, char ***, int *, ENTER_STATE *);
#define mutt_get_field(A,B,C,D) _mutt_get_field(A,B,C,D,0,NULL,NULL)
int _mutt_get_field (const char *, char *, size_t, int, int, char ***, int *);
#define mutt_buffer_get_field(A,B,C) _mutt_buffer_get_field(A,B,C,0,NULL,NULL)
int _mutt_buffer_get_field (const char *, BUFFER *, int, int, char ***, int *);
int mutt_get_field (const char *, char *, size_t, int);
int mutt_buffer_get_field (const char *, BUFFER *, int);
int mutt_get_hook_type (const char *);
int mutt_get_field_unbuffered (char *, char *, size_t, int);
#define mutt_get_password(A,B,C) mutt_get_field_unbuffered(A,B,C,MUTT_PASS)

M send.c => send.c +1 -1
@@ 1274,7 1274,7 @@ static void save_fcc_mailbox_part (BUFFER *fcc_mailbox, SEND_CONTEXT *sctx,
           This is the prompt to enter an "alternate (m)ailbox" when the
           initial Fcc fails.
        */
        rc = mutt_buffer_enter_mailbox (_("Fcc mailbox"), fcc_mailbox, 0);
        rc = mutt_enter_mailbox (_("Fcc mailbox"), fcc_mailbox, 0);
        if ((rc == -1) || !mutt_buffer_len (fcc_mailbox))
        {
          rc = 0;