DLR's latest bits

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1365 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2003-01-16 22:16:38 +00:00
parent 2ad0f6c0ad
commit 09fc4300ec
4 changed files with 42 additions and 27 deletions

View File

@ -199,6 +199,9 @@ Changes
found, display "[string] not found" instead of "Replaced 0 found, display "[string] not found" instead of "Replaced 0
occurrences". (DLR) occurrences". (DLR)
- utils.c: - utils.c:
is_cntrl_char()
- Rework to fix a problem with displaying certain high-bit
characters. (David Benbennick; reported by Andrzej Marecki)
align() align()
- Don't just assert that the string passed in isn't NULL; check - 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 that it isn't and only do the alignment when it isn't. (David
@ -211,10 +214,13 @@ Changes
charalloc() charalloc()
- Removed and redefined as a macro that calls nmalloc(). (David - Removed and redefined as a macro that calls nmalloc(). (David
Benbennick) Benbennick)
is_cntrl_char()
- Rework to fix a problem with displaying certain high-bit
characters. (David Benbennick; reported by Andrzej Marecki)
- winio.c: - 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() edit_refresh()
- Miscellaneous cleanups that fix a bug where the screen - Miscellaneous cleanups that fix a bug where the screen
isn't updated after uncutting chunks of upwardly marked cut isn't updated after uncutting chunks of upwardly marked cut

2
nano.c
View File

@ -2993,7 +2993,7 @@ int main(int argc, char *argv[])
int optchr; int optchr;
int startline = 0; /* Line to try and start at */ int startline = 0; /* Line to try and start at */
int modify_control_seq; int modify_control_seq;
int fill_flag_used = 0; /* Was the fill option used? */ int fill_flag_used = 0; /* Was the fill option used? */
const shortcut *s; const shortcut *s;
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
int preserveopt = 0; /* Did the cmdline include --preserve? */ int preserveopt = 0; /* Did the cmdline include --preserve? */

View File

@ -158,8 +158,7 @@ int search_init(int replacing)
case -2: /* Same string */ case -2: /* Same string */
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
if (ISSET(USE_REGEXP)) if (ISSET(USE_REGEXP))
/* If we're in Pico mode, and answer is "", use /* If answer is "", use last_search! */
last_search! */
regexp_init(last_search); regexp_init(last_search);
#endif #endif
break; break;
@ -405,7 +404,7 @@ int do_search(void)
if (fileptr == current && fileptr_x == current_x && didfind != NULL) if (fileptr == current && fileptr_x == current_x && didfind != NULL)
statusbar(_("This is the only occurrence")); statusbar(_("This is the only occurrence"));
else if (current->lineno <= edittop->lineno else if (current->lineno <= edittop->lineno
|| current->lineno >= editbot->lineno) || current->lineno >= editbot->lineno)
edit_update(current, current_x); edit_update(current, current_x);
search_abort(); search_abort();
@ -687,7 +686,7 @@ int do_replace(void)
} }
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (strcmp(answer, "")) if (answer[0] != '\0')
update_history(&search_history, answer); update_history(&search_history, answer);
#endif /* !NANO_SMALL */ #endif /* !NANO_SMALL */
@ -712,7 +711,7 @@ int do_replace(void)
_("Replace with")); _("Replace with"));
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (i == 0 && strcmp(answer, "")) if (i == 0 && answer[0] != '\0')
update_history(&replace_history, answer); update_history(&replace_history, answer);
#endif /* !NANO_SMALL */ #endif /* !NANO_SMALL */
@ -912,7 +911,7 @@ void history_init(void)
/* find first node containing string *s in history list *h */ /* find first node containing string *s in history list *h */
historytype *find_node(historytype *h, char *s) 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) if (strcmp(s, h->data) == 0)
return h; return h;
return NULL; return NULL;
@ -945,10 +944,11 @@ void update_history(historyheadtype *h, char *s)
{ {
historytype *p; historytype *p;
if ((p = find_node(h->next, s))) { if ((p = find_node(h->next, s)) != NULL) {
if (p == h->next) /* catch delete and re-insert of same string in 1st node */ if (p == h->next) /* catch delete and re-insert of
same string in 1st node */
goto up_hs; goto up_hs;
remove_node(p); /* delete identical older string */ remove_node(p); /* delete identical older string */
h->count--; h->count--;
} }
if (h->count == MAX_SEARCH_HISTORY) { /* list 'full', delete oldest */ if (h->count == MAX_SEARCH_HISTORY) { /* list 'full', delete oldest */
@ -957,14 +957,14 @@ void update_history(historyheadtype *h, char *s)
} }
insert_node((historytype *)h, s); insert_node((historytype *)h, s);
h->count++; h->count++;
up_hs: up_hs:
h->current = h->next; h->current = h->next;
} }
/* return a pointer to either the next older history or NULL if no more */ /* return a pointer to either the next older history or NULL if no more */
char *get_history_older(historyheadtype *h) 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 */ h->current = h->current->next; /* yes */
return h->current->data; /* return it */ return h->current->data; /* return it */
} }
@ -973,9 +973,9 @@ char *get_history_older(historyheadtype *h)
char *get_history_newer(historyheadtype *h) char *get_history_newer(historyheadtype *h)
{ {
if (h->current->prev) { if (h->current->prev != NULL) {
h->current = h->current->prev; h->current = h->current->prev;
if (h->current->prev) if (h->current->prev != NULL)
return h->current->data; return h->current->data;
} }
return NULL; return NULL;
@ -986,8 +986,8 @@ char *get_history_completion(historyheadtype *h, char *s)
{ {
historytype *p; historytype *p;
for (p = h->current->next ; p->next ; p = p->next) { for (p = h->current->next; p->next != NULL; p = p->next) {
if ((strncmp(s, p->data, h->len) == 0) && (strlen(p->data) != h->len)) { if (strncmp(s, p->data, h->len) == 0 && strlen(p->data) != h->len) {
h->current = p; h->current = p;
return p->data; return p->data;
} }
@ -1002,7 +1002,7 @@ void free_history(historyheadtype *h)
{ {
historytype *p, *n; historytype *p, *n;
for (p = h->next ; (n = p->next) ; p = n) for (p = h->next; (n = p->next); p = n)
remove_node(p); remove_node(p);
} }

23
winio.c
View File

@ -197,7 +197,7 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
) )
{ {
int kbinput; int kbinput;
int x; static int x = -1;
/* the cursor position in 'answer' */ /* the cursor position in 'answer' */
int xend; int xend;
/* length of 'answer', the status bar text */ /* length of 'answer', the status bar text */
@ -213,7 +213,14 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
int last_kbinput = 0, ret2cb = 0; int last_kbinput = 0, ret2cb = 0;
#endif #endif
xend = strlen(def); 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); answer = (char *)nrealloc(answer, xend + 1);
if (xend > 0) if (xend > 0)
strcpy(answer, def); strcpy(answer, def);
@ -351,7 +358,7 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
case KEY_UP: case KEY_UP:
case NANO_UP_KEY: case NANO_UP_KEY:
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (history_list) { if (history_list != NULL) {
/* If there's no previous temp holder, or if we already /* If there's no previous temp holder, or if we already
arrowed back down to it and (possibly edited it), arrowed back down to it and (possibly edited it),
@ -376,17 +383,19 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
case KEY_DOWN: case KEY_DOWN:
case NANO_DOWN_KEY: case NANO_DOWN_KEY:
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (history_list) { if (history_list != NULL) {
/* get newer search from the history list */ /* get newer search from the history list */
if ((history = get_history_newer(history_list)) != NULL) { if ((history = get_history_newer(history_list)) != NULL) {
answer = mallocstrcpy(answer, history); answer = mallocstrcpy(answer, history);
xend = strlen(history); xend = strlen(history);
/* Else if we ran out of history, regurgitate the temporary /* else if we ran out of history, regurgitate the temporary
buffer */ buffer and blow away currentbuf */
} else if (currentbuf != NULL) { } else if (currentbuf != NULL) {
answer = mallocstrcpy(answer, currentbuf); answer = mallocstrcpy(answer, currentbuf);
xend = strlen(currentbuf); free(currentbuf);
currentbuf = NULL;
xend = strlen(answer);
ret2cb = 1; ret2cb = 1;
} else { } else {
answer = mallocstrcpy(answer, ""); answer = mallocstrcpy(answer, "");