]> granicus.if.org Git - mutt/commitdiff
Create mutt_buffer_get_field().
authorKevin McCarthy <kevin@8t8.us>
Sun, 22 Sep 2019 21:11:43 +0000 (14:11 -0700)
committerKevin McCarthy <kevin@8t8.us>
Sun, 22 Sep 2019 21:53:26 +0000 (14:53 -0700)
This will reduce the buffer->dptr fiddling all over the place into one
spot until mutt_enter_string() can be converted.

curs_lib.c
protos.h

index 6db52a81b43919e41de646046cae5276d7156e86..08aa80f2af3f68e95b76cc9d4710b999888c5037 100644 (file)
@@ -208,6 +208,21 @@ event_t mutt_getch (void)
 }
 
 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)
 {
   int ret;
   int x;
@@ -231,9 +246,15 @@ int _mutt_get_field (const char *field, char *buf, size_t buflen, int complete,
     NORMAL_COLOR;
     mutt_refresh ();
     mutt_window_getyx (MuttMessageWindow, NULL, &x);
-    ret = _mutt_enter_string (buf, buflen, x, complete, multiple, files, numfiles, es);
+    ret = _mutt_enter_string (buffer->data, buffer->dsize, x, complete, multiple, files, numfiles, es);
   }
   while (ret == 1);
+
+  if (ret != 0)
+    mutt_buffer_clear (buffer);
+  else
+    mutt_buffer_fix_dptr (buffer);
+
   mutt_window_clearline (MuttMessageWindow, 0);
   mutt_free_enter_state (&es);
 
index 6b98d4411cc6721f9950eac6b6c750c7e1ae0387..10a15701299694cccefa1c1a1444078ca7ceb8ef 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -340,6 +340,8 @@ 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_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)