found, display "[string] not found" instead of "Replaced 0
occurrences". (DLR)
- utils.c:
+ is_cntrl_char()
+ - Rework to fix a problem with displaying certain high-bit
+ characters. (David Benbennick; reported by Andrzej Marecki)
align()
- Don't just assert that the string passed in isn't NULL; check
that it isn't and only do the alignment when it isn't. (David
charalloc()
- Removed and redefined as a macro that calls nmalloc(). (David
Benbennick)
- is_cntrl_char()
- - Rework to fix a problem with displaying certain high-bit
- characters. (David Benbennick; reported by Andrzej Marecki)
- winio.c:
+ nanogetstr()
+ - Tweak to make the cursor stay in the same place if we hit a
+ prompt-changing toggle while it's in the middle of the string.
+ Also fix minor problem with search history where the current
+ search item could be at the bottom of the history twice in a
+ row under certain conditions. (DLR)
edit_refresh()
- Miscellaneous cleanups that fix a bug where the screen
isn't updated after uncutting chunks of upwardly marked cut
case -2: /* Same string */
#ifdef HAVE_REGEX_H
if (ISSET(USE_REGEXP))
- /* If we're in Pico mode, and answer is "", use
- last_search! */
+ /* If answer is "", use last_search! */
regexp_init(last_search);
#endif
break;
if (fileptr == current && fileptr_x == current_x && didfind != NULL)
statusbar(_("This is the only occurrence"));
else if (current->lineno <= edittop->lineno
- || current->lineno >= editbot->lineno)
+ || current->lineno >= editbot->lineno)
edit_update(current, current_x);
search_abort();
}
#ifndef NANO_SMALL
- if (strcmp(answer, ""))
+ if (answer[0] != '\0')
update_history(&search_history, answer);
#endif /* !NANO_SMALL */
_("Replace with"));
#ifndef NANO_SMALL
- if (i == 0 && strcmp(answer, ""))
+ if (i == 0 && answer[0] != '\0')
update_history(&replace_history, answer);
#endif /* !NANO_SMALL */
/* find first node containing string *s in history list *h */
historytype *find_node(historytype *h, char *s)
{
- for ( ; h->next ; h = h->next)
+ for (; h->next != NULL; h = h->next)
if (strcmp(s, h->data) == 0)
return h;
return NULL;
{
historytype *p;
- if ((p = find_node(h->next, s))) {
- if (p == h->next) /* catch delete and re-insert of same string in 1st node */
+ if ((p = find_node(h->next, s)) != NULL) {
+ if (p == h->next) /* catch delete and re-insert of
+ same string in 1st node */
goto up_hs;
- remove_node(p); /* delete identical older string */
+ remove_node(p); /* delete identical older string */
h->count--;
}
if (h->count == MAX_SEARCH_HISTORY) { /* list 'full', delete oldest */
}
insert_node((historytype *)h, s);
h->count++;
-up_hs:
+ up_hs:
h->current = h->next;
}
/* return a pointer to either the next older history or NULL if no more */
char *get_history_older(historyheadtype *h)
{
- if (h->current->next) { /* any older entries ? */
+ if (h->current->next != NULL) { /* any older entries? */
h->current = h->current->next; /* yes */
return h->current->data; /* return it */
}
char *get_history_newer(historyheadtype *h)
{
- if (h->current->prev) {
+ if (h->current->prev != NULL) {
h->current = h->current->prev;
- if (h->current->prev)
+ if (h->current->prev != NULL)
return h->current->data;
}
return NULL;
{
historytype *p;
- for (p = h->current->next ; p->next ; p = p->next) {
- if ((strncmp(s, p->data, h->len) == 0) && (strlen(p->data) != h->len)) {
+ for (p = h->current->next; p->next != NULL; p = p->next) {
+ if (strncmp(s, p->data, h->len) == 0 && strlen(p->data) != h->len) {
h->current = p;
return p->data;
}
{
historytype *p, *n;
- for (p = h->next ; (n = p->next) ; p = n)
+ for (p = h->next; (n = p->next); p = n)
remove_node(p);
}
)
{
int kbinput;
- int x;
+ static int x = -1;
/* the cursor position in 'answer' */
int xend;
/* length of 'answer', the status bar text */
int last_kbinput = 0, ret2cb = 0;
#endif
xend = strlen(def);
- x = xend;
+
+ /* Only put x at the end of the string if it's uninitialized or if
+ it would be past the end of the string as it is. Otherwise,
+ leave it alone. This is so the cursor position stays at the same
+ place if a prompt-changing toggle is pressed. */
+ if (x == -1 || x > xend)
+ x = xend;
+
answer = (char *)nrealloc(answer, xend + 1);
if (xend > 0)
strcpy(answer, def);
case KEY_UP:
case NANO_UP_KEY:
#ifndef NANO_SMALL
- if (history_list) {
+ if (history_list != NULL) {
/* If there's no previous temp holder, or if we already
arrowed back down to it and (possibly edited it),
case KEY_DOWN:
case NANO_DOWN_KEY:
#ifndef NANO_SMALL
- if (history_list) {
+ if (history_list != NULL) {
/* get newer search from the history list */
if ((history = get_history_newer(history_list)) != NULL) {
answer = mallocstrcpy(answer, history);
xend = strlen(history);
- /* Else if we ran out of history, regurgitate the temporary
- buffer */
+ /* else if we ran out of history, regurgitate the temporary
+ buffer and blow away currentbuf */
} else if (currentbuf != NULL) {
answer = mallocstrcpy(answer, currentbuf);
- xend = strlen(currentbuf);
+ free(currentbuf);
+ currentbuf = NULL;
+ xend = strlen(answer);
ret2cb = 1;
} else {
answer = mallocstrcpy(answer, "");