free prompt when it isn't used, and add missing stdio.h #includes

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3067 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2005-11-01 18:35:47 +00:00
parent 2b9d6a0e6c
commit 143b8c7b13
2 changed files with 24 additions and 13 deletions

View File

@ -24,6 +24,7 @@
#include <config.h> #include <config.h>
#endif #endif
#include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include "proto.h" #include "proto.h"
@ -33,7 +34,7 @@ static char *prompt = NULL;
* questions. */ * questions. */
static size_t statusbar_x = (size_t)-1; static size_t statusbar_x = (size_t)-1;
/* The cursor position in answer. */ /* The cursor position in answer. */
static bool resetstatuspos = FALSE; static bool reset_statusbar_x = FALSE;
/* Should we reset the cursor position /* Should we reset the cursor position
* at the statusbar prompt? */ * at the statusbar prompt? */
@ -239,7 +240,11 @@ bool do_statusbar_mouse(void)
/* We can click in the statusbar window text to move the /* We can click in the statusbar window text to move the
* cursor. */ * cursor. */
if (wenclose(bottomwin, mouse_y, mouse_x)) { if (wenclose(bottomwin, mouse_y, mouse_x)) {
size_t start_col = strlenpt(prompt) + 1; size_t start_col;
assert(prompt != NULL);
start_col = strlenpt(prompt) + 1;
/* Subtract out the sizes of topwin and edit. */ /* Subtract out the sizes of topwin and edit. */
mouse_y -= (2 - no_more_space()) + editwinrows; mouse_y -= (2 - no_more_space()) + editwinrows;
@ -597,7 +602,7 @@ void nanoget_repaint(const char *buf, size_t x)
size_t start_col, xpt, page_start; size_t start_col, xpt, page_start;
char *expanded; char *expanded;
assert(x <= strlen(buf)); assert(prompt != NULL && x <= strlen(buf);
start_col = strlenpt(prompt) + 1; start_col = strlenpt(prompt) + 1;
xpt = strnlenpt(buf, x); xpt = strnlenpt(buf, x);
@ -621,7 +626,7 @@ void nanoget_repaint(const char *buf, size_t x)
wattroff(bottomwin, A_REVERSE); wattroff(bottomwin, A_REVERSE);
} }
/* Get the input from the keyboard; this should only be called from /* Get the input from the keyboard. This should only be called from
* statusq(). */ * statusq(). */
int nanogetstr(bool allow_tabs, const char *curranswer, int nanogetstr(bool allow_tabs, const char *curranswer,
#ifndef NANO_SMALL #ifndef NANO_SMALL
@ -660,11 +665,11 @@ int nanogetstr(bool allow_tabs, const char *curranswer,
/* Only put statusbar_x at the end of the string if it's /* Only put statusbar_x at the end of the string if it's
* uninitialized, if it would be past the end of curranswer, or if * uninitialized, if it would be past the end of curranswer, or if
* resetstatuspos is TRUE. Otherwise, leave it alone. This is so * reset_statusbar_x is TRUE. Otherwise, leave it alone. This is
* the cursor position stays at the same place if a prompt-changing * so the cursor position stays at the same place if a
* toggle is pressed. */ * prompt-changing toggle is pressed. */
if (statusbar_x == (size_t)-1 || statusbar_x > curranswer_len || if (statusbar_x == (size_t)-1 || statusbar_x > curranswer_len ||
resetstatuspos) reset_statusbar_x)
statusbar_x = curranswer_len; statusbar_x = curranswer_len;
currshortcut = s; currshortcut = s;
@ -821,7 +826,9 @@ int statusq(bool allow_tabs, const shortcut *s, const char *curranswer,
bool list = FALSE; bool list = FALSE;
#endif #endif
prompt = charealloc(prompt, ((COLS - 4) * mb_cur_max()) + 1); assert(prompt == NULL);
prompt = charalloc(prompt, ((COLS - 4) * mb_cur_max()) + 1);
bottombars(s); bottombars(s);
@ -840,16 +847,19 @@ int statusq(bool allow_tabs, const shortcut *s, const char *curranswer,
#endif #endif
); );
resetstatuspos = FALSE; free(prompt);
prompt = NULL;
reset_statusbar_x = FALSE;
switch (retval) { switch (retval) {
case NANO_CANCEL_KEY: case NANO_CANCEL_KEY:
retval = -1; retval = -1;
resetstatuspos = TRUE; reset_statusbar_x = TRUE;
break; break;
case NANO_ENTER_KEY: case NANO_ENTER_KEY:
retval = (answer[0] == '\0') ? -2 : 0; retval = (answer[0] == '\0') ? -2 : 0;
resetstatuspos = TRUE; reset_statusbar_x = TRUE;
break; break;
} }
@ -873,5 +883,5 @@ int statusq(bool allow_tabs, const shortcut *s, const char *curranswer,
void statusq_abort(void) void statusq_abort(void)
{ {
resetstatuspos = TRUE; reset_statusbar_x = TRUE;
} }

View File

@ -24,6 +24,7 @@
#include <config.h> #include <config.h>
#endif #endif
#include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>