Commit 5ffbec56 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

port over some of DB's refactored display code, most importantly the

display_string() function, and convert some parts of nano to use it


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1552 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent b23554fa
Showing with 393 additions and 314 deletions
+393 -314
...@@ -38,6 +38,20 @@ CVS code - ...@@ -38,6 +38,20 @@ CVS code -
wrap_reset() calls with DISABLE_WRAPPING #ifdefs. (DLR) wrap_reset() calls with DISABLE_WRAPPING #ifdefs. (DLR)
- Change enum "topmidbotnone" to "topmidnone", as there's no - Change enum "topmidbotnone" to "topmidnone", as there's no
BOTTOM option anymore. (DLR) BOTTOM option anymore. (DLR)
- Split out the string-displaying routine from update_line()
into a separate function; convert the edit window, statusbar
display, and statusbar prompt to use it, so that they can all
properly display control characters and tabs; free and NULL
the backup search string in one place in the search code
instead of several; and do some other minor refactoring of
related display functions to simplify them. New functions
mark_order() and display_string(); changes to actual_x(),
edit_add(), update_line(), statusbar(), and
do_replace_highlight(). (David Benbennick) DLR: Add minor
cosmetic tweaks, add missing NANO_SMALL #ifdef around the text
for a backwards search in the refactored code, and enclose
dump_buffer() and dump_buffer_reverse() in one ENABLE_DEBUG
#ifdef instead of two.
- files.c: - files.c:
do_browser() do_browser()
- Some of the Pico compatibility options in the file browser - Some of the Pico compatibility options in the file browser
......
...@@ -81,7 +81,7 @@ int do_page_up(void) ...@@ -81,7 +81,7 @@ int do_page_up(void)
#endif #endif
} }
/* Get the equivalent x-coordinate of the new line. */ /* Get the equivalent x-coordinate of the new line. */
current_x = actual_x(current, placewewant); current_x = actual_x(current->data, placewewant);
edit_refresh(); edit_refresh();
...@@ -125,7 +125,7 @@ int do_page_down(void) ...@@ -125,7 +125,7 @@ int do_page_down(void)
#endif #endif
} }
/* Get the equivalent x-coordinate of the new line. */ /* Get the equivalent x-coordinate of the new line. */
current_x = actual_x(current, placewewant); current_x = actual_x(current->data, placewewant);
edit_refresh(); edit_refresh();
...@@ -145,7 +145,7 @@ int do_up(void) ...@@ -145,7 +145,7 @@ int do_up(void)
assert(current_y == current->lineno - edittop->lineno); assert(current_y == current->lineno - edittop->lineno);
current = current->prev; current = current->prev;
current_x = actual_x(current, placewewant); current_x = actual_x(current->data, placewewant);
if (current_y > 0) { if (current_y > 0) {
update_line(current->next, 0); update_line(current->next, 0);
/* It was necessary to change current first, so the mark /* It was necessary to change current first, so the mark
...@@ -175,7 +175,7 @@ int do_down(void) ...@@ -175,7 +175,7 @@ int do_down(void)
assert(current_y == current->lineno - edittop->lineno); assert(current_y == current->lineno - edittop->lineno);
current = current->next; current = current->next;
current_x = actual_x(current, placewewant); current_x = actual_x(current->data, placewewant);
/* Note that current_y is zero-based. This test checks for the /* Note that current_y is zero-based. This test checks for the
* cursor's being not on the last row of the edit window. */ * cursor's being not on the last row of the edit window. */
......
...@@ -917,7 +917,7 @@ void do_mouse(void) ...@@ -917,7 +917,7 @@ void do_mouse(void)
for(; current_y > mevent.y && current->prev != NULL; current_y--) for(; current_y > mevent.y && current->prev != NULL; current_y--)
current = current->prev; current = current->prev;
xcur = actual_x(current, get_page_start(xplustabs()) + mevent.x); xcur = actual_x(current->data, get_page_start(xplustabs()) + mevent.x);
/* Selecting where the cursor is toggles the mark. As does /* Selecting where the cursor is toggles the mark. As does
selecting beyond the line length with the cursor at the end of selecting beyond the line length with the cursor at the end of
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
/* Define charalloc as a macro rather than duplicating code */ /* Define charalloc as a macro rather than duplicating code */
#define charalloc(howmuch) (char *)nmalloc((howmuch) * sizeof(char)) #define charalloc(howmuch) (char *)nmalloc((howmuch) * sizeof(char))
#define charealloc(ptr, howmuch) (char *)nrealloc(ptr, (howmuch) * sizeof(char)) #define charealloc(ptr, howmuch) (char *)nrealloc(ptr, (howmuch) * sizeof(char))
#define charmove(dest, src, n) memmove(dest, src, (n) * sizeof(char))
#ifdef BROKEN_REGEXEC #ifdef BROKEN_REGEXEC
#define regexec(preg, string, nmatch, pmatch, eflags) regexec_safe(preg, string, nmatch, pmatch, eflags) #define regexec(preg, string, nmatch, pmatch, eflags) regexec_safe(preg, string, nmatch, pmatch, eflags)
#endif #endif
......
...@@ -426,6 +426,10 @@ void *nmalloc(size_t howmuch); ...@@ -426,6 +426,10 @@ void *nmalloc(size_t howmuch);
void *nrealloc(void *ptr, size_t howmuch); void *nrealloc(void *ptr, size_t howmuch);
char *mallocstrcpy(char *dest, const char *src); char *mallocstrcpy(char *dest, const char *src);
void new_magicline(void); void new_magicline(void);
#ifndef NANO_SMALL
void mark_order(const filestruct **top, size_t *top_x,
const filestruct **bot, size_t *bot_x);
#endif
#ifndef DISABLE_TABCOMP #ifndef DISABLE_TABCOMP
int check_wildcard_match(const char *text, const char *pattern); int check_wildcard_match(const char *text, const char *pattern);
#endif #endif
...@@ -443,7 +447,7 @@ int do_first_line(void); ...@@ -443,7 +447,7 @@ int do_first_line(void);
int do_last_line(void); int do_last_line(void);
int xpt(const filestruct *fileptr, int index); int xpt(const filestruct *fileptr, int index);
size_t xplustabs(void); size_t xplustabs(void);
size_t actual_x(const filestruct *fileptr, size_t xplus); size_t actual_x(const char *str, size_t xplus);
size_t strnlenpt(const char *buf, size_t size); size_t strnlenpt(const char *buf, size_t size);
size_t strlenpt(const char *buf); size_t strlenpt(const char *buf);
void blank_bottombars(void); void blank_bottombars(void);
...@@ -452,7 +456,8 @@ void blank_edit(void); ...@@ -452,7 +456,8 @@ void blank_edit(void);
void blank_statusbar(void); void blank_statusbar(void);
void blank_statusbar_refresh(void); void blank_statusbar_refresh(void);
void check_statblank(void); void check_statblank(void);
void nanoget_repaint(const char *buf, const char *inputbuf, int x); char *display_string(const char *buf, size_t start_col, int len);
void nanoget_repaint(const char *buf, const char *inputbuf, size_t x);
int nanogetstr(int allowtabs, const char *buf, const char *def, int nanogetstr(int allowtabs, const char *buf, const char *def,
#ifndef NANO_SMALL #ifndef NANO_SMALL
historyheadtype *history_list, historyheadtype *history_list,
...@@ -473,12 +478,9 @@ int get_page_start(int column); ...@@ -473,12 +478,9 @@ int get_page_start(int column);
void reset_cursor(void); void reset_cursor(void);
void add_marked_sameline(int begin, int end, filestruct *fileptr, int y, void add_marked_sameline(int begin, int end, filestruct *fileptr, int y,
int virt_cur_x, int this_page); int virt_cur_x, int this_page);
void edit_add(const filestruct *fileptr, int yval, int start void edit_add(const filestruct *fileptr, const char *converted,
#ifndef NANO_SMALL int yval, size_t start);
, int virt_mark_beginx, int virt_cur_x void update_line(const filestruct *fileptr, size_t index);
#endif
);
void update_line(filestruct *fileptr, int index);
void update_cursor(void); void update_cursor(void);
void center_cursor(void); void center_cursor(void);
void edit_refresh(void); void edit_refresh(void);
......
...@@ -107,18 +107,22 @@ int search_init(int replacing) ...@@ -107,18 +107,22 @@ int search_init(int replacing)
search_init_globals(); search_init_globals();
/* If we don't already have a backupstring, set it. */
if (backupstring == NULL) if (backupstring == NULL)
backupstring = mallocstrcpy(backupstring, ""); backupstring = mallocstrcpy(NULL, "");
#ifndef NANO_SMALL #ifndef NANO_SMALL
search_history.current = (historytype *)&search_history.next; search_history.current = (historytype *)&search_history.next;
#endif #endif
if (last_search[0] != '\0') { if (last_search[0] != '\0') {
char *disp = display_string(last_search, 0, COLS / 3);
buf = charalloc(COLS / 3 + 7); buf = charalloc(COLS / 3 + 7);
/* We use COLS / 3 here because we need to see more on the line */ /* We use COLS / 3 here because we need to see more on the line */
sprintf(buf, " [%.*s%s]", COLS / 3, last_search, sprintf(buf, " [%s%s]", disp,
strlen(last_search) > COLS / 3 ? "..." : ""); strlenpt(last_search) > COLS / 3 ? "..." : "");
free(disp);
} else { } else {
buf = charalloc(1); buf = charalloc(1);
buf[0] = '\0'; buf[0] = '\0';
...@@ -132,17 +136,23 @@ int search_init(int replacing) ...@@ -132,17 +136,23 @@ int search_init(int replacing)
"%s%s%s%s%s%s", "%s%s%s%s%s%s",
_("Search"), _("Search"),
#ifndef NANO_SMALL
/* This string is just a modifier for the search prompt, /* This string is just a modifier for the search prompt,
no grammar is implied */ no grammar is implied */
ISSET(CASE_SENSITIVE) ? _(" [Case Sensitive]") : "", ISSET(CASE_SENSITIVE) ? _(" [Case Sensitive]") :
#endif
"",
/* This string is just a modifier for the search prompt, /* This string is just a modifier for the search prompt,
no grammar is implied */ no grammar is implied */
ISSET(USE_REGEXP) ? _(" [Regexp]") : "", ISSET(USE_REGEXP) ? _(" [Regexp]") : "",
#ifndef NANO_SMALL
/* This string is just a modifier for the search prompt, /* This string is just a modifier for the search prompt,
no grammar is implied */ no grammar is implied */
ISSET(REVERSE_SEARCH) ? _(" [Backwards]") : "", ISSET(REVERSE_SEARCH) ? _(" [Backwards]") :
#endif
"",
replacing ? _(" (to replace)") : "", replacing ? _(" (to replace)") : "",
buf); buf);
...@@ -150,12 +160,13 @@ int search_init(int replacing) ...@@ -150,12 +160,13 @@ int search_init(int replacing)
/* Release buf now that we don't need it anymore */ /* Release buf now that we don't need it anymore */
free(buf); free(buf);
free(backupstring);
backupstring = NULL;
/* Cancel any search, or just return with no previous search */ /* Cancel any search, or just return with no previous search */
if (i == -1 || (i < 0 && last_search[0] == '\0')) { if (i == -1 || (i < 0 && last_search[0] == '\0')) {
statusbar(_("Search Cancelled")); statusbar(_("Search Cancelled"));
reset_cursor(); reset_cursor();
free(backupstring);
backupstring = NULL;
#ifndef NANO_SMALL #ifndef NANO_SMALL
search_history.current = search_history.next; search_history.current = search_history.next;
#endif #endif
...@@ -169,29 +180,23 @@ int search_init(int replacing) ...@@ -169,29 +180,23 @@ int search_init(int replacing)
if (regexp_init(last_search) == 0) { if (regexp_init(last_search) == 0) {
statusbar(regex_error, last_search); statusbar(regex_error, last_search);
reset_cursor(); reset_cursor();
free(backupstring);
backupstring = NULL;
return -3; return -3;
} }
#endif #endif
break; break;
case 0: /* They entered something new */ case 0: /* They entered something new */
last_replace[0] = '\0';
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
if (ISSET(USE_REGEXP)) if (ISSET(USE_REGEXP))
if (regexp_init(answer) == 0) { if (regexp_init(answer) == 0) {
statusbar(regex_error, answer); statusbar(regex_error, answer);
reset_cursor(); reset_cursor();
free(backupstring);
backupstring = NULL;
#ifndef NANO_SMALL #ifndef NANO_SMALL
search_history.current = search_history.next; search_history.current = search_history.next;
#endif #endif
return -3; return -3;
} }
#endif #endif
free(backupstring);
backupstring = NULL;
last_replace[0] = '\0';
break; break;
#ifndef NANO_SMALL #ifndef NANO_SMALL
case TOGGLE_CASE_KEY: case TOGGLE_CASE_KEY:
...@@ -213,8 +218,6 @@ int search_init(int replacing) ...@@ -213,8 +218,6 @@ int search_init(int replacing)
backupstring = mallocstrcpy(backupstring, answer); backupstring = mallocstrcpy(backupstring, answer);
return -2; /* Call the opposite search function */ return -2; /* Call the opposite search function */
case NANO_FROMSEARCHTOGOTO_KEY: case NANO_FROMSEARCHTOGOTO_KEY:
free(backupstring);
backupstring = NULL;
#ifndef NANO_SMALL #ifndef NANO_SMALL
search_history.current = search_history.next; search_history.current = search_history.next;
#endif #endif
...@@ -226,8 +229,6 @@ int search_init(int replacing) ...@@ -226,8 +229,6 @@ int search_init(int replacing)
return -3; return -3;
default: default:
do_early_abort(); do_early_abort();
free(backupstring);
backupstring = NULL;
return -3; return -3;
} }
} }
...@@ -631,6 +632,8 @@ int do_replace_loop(const char *prevanswer, const filestruct *begin, ...@@ -631,6 +632,8 @@ int do_replace_loop(const char *prevanswer, const filestruct *begin,
last_replace = mallocstrcpy(last_replace, answer); last_replace = mallocstrcpy(last_replace, answer);
while (1) { while (1) {
size_t match_len;
/* Sweet optimization by Rocco here */ /* Sweet optimization by Rocco here */
fileptr = findnextstr(fileptr || replaceall || search_last_line, fileptr = findnextstr(fileptr || replaceall || search_last_line,
FALSE, begin, *beginx, prevanswer); FALSE, begin, *beginx, prevanswer);
...@@ -651,13 +654,27 @@ int do_replace_loop(const char *prevanswer, const filestruct *begin, ...@@ -651,13 +654,27 @@ int do_replace_loop(const char *prevanswer, const filestruct *begin,
if (numreplaced == -1) if (numreplaced == -1)
numreplaced = 0; numreplaced = 0;
#ifdef HAVE_REGEX_H
if (ISSET(USE_REGEXP))
match_len = regmatches[0].rm_eo - regmatches[0].rm_so;
else
#endif
match_len = strlen(prevanswer);
if (!replaceall) { if (!replaceall) {
char *exp_word;
size_t xpt = xplustabs();
exp_word = display_string(current->data, xpt,
strnlenpt(current->data, match_len + current_x) - xpt);
curs_set(0); curs_set(0);
do_replace_highlight(TRUE, prevanswer); do_replace_highlight(TRUE, exp_word);
*i = do_yesno(1, 1, _("Replace this instance?")); *i = do_yesno(1, 1, _("Replace this instance?"));
do_replace_highlight(FALSE, prevanswer); do_replace_highlight(FALSE, exp_word);
free(exp_word);
curs_set(1); curs_set(1);
} }
......
...@@ -302,6 +302,28 @@ void new_magicline(void) ...@@ -302,6 +302,28 @@ void new_magicline(void)
totsize++; totsize++;
} }
#ifndef NANO_SMALL
/* Set top_x and bot_x to the top and bottom x-coordinates of the mark,
* respectively, based on the locations of top and bot. */
void mark_order(const filestruct **top, size_t *top_x,
const filestruct **bot, size_t *bot_x)
{
assert(top != NULL && top_x != NULL && bot != NULL && bot_x != NULL);
if ((current->lineno == mark_beginbuf->lineno && current_x > mark_beginx)
|| current->lineno > mark_beginbuf->lineno) {
*top = mark_beginbuf;
*top_x = mark_beginx;
*bot = current;
*bot_x = current_x;
} else {
*bot = mark_beginbuf;
*bot_x = mark_beginx;
*top = current;
*top_x = current_x;
}
}
#endif
#ifndef DISABLE_TABCOMP #ifndef DISABLE_TABCOMP
/* /*
* Routine to see if a text string is matched by a wildcard pattern. * Routine to see if a text string is matched by a wildcard pattern.
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment