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
No related merge requests found
Showing with 393 additions and 314 deletions
+393 -314
......@@ -38,6 +38,20 @@ CVS code -
wrap_reset() calls with DISABLE_WRAPPING #ifdefs. (DLR)
- Change enum "topmidbotnone" to "topmidnone", as there's no
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:
do_browser()
- Some of the Pico compatibility options in the file browser
......
......@@ -81,7 +81,7 @@ int do_page_up(void)
#endif
}
/* Get the equivalent x-coordinate of the new line. */
current_x = actual_x(current, placewewant);
current_x = actual_x(current->data, placewewant);
edit_refresh();
......@@ -125,7 +125,7 @@ int do_page_down(void)
#endif
}
/* Get the equivalent x-coordinate of the new line. */
current_x = actual_x(current, placewewant);
current_x = actual_x(current->data, placewewant);
edit_refresh();
......@@ -145,7 +145,7 @@ int do_up(void)
assert(current_y == current->lineno - edittop->lineno);
current = current->prev;
current_x = actual_x(current, placewewant);
current_x = actual_x(current->data, placewewant);
if (current_y > 0) {
update_line(current->next, 0);
/* It was necessary to change current first, so the mark
......@@ -175,7 +175,7 @@ int do_down(void)
assert(current_y == current->lineno - edittop->lineno);
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
* cursor's being not on the last row of the edit window. */
......
......@@ -917,7 +917,7 @@ void do_mouse(void)
for(; current_y > mevent.y && current->prev != NULL; current_y--)
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 beyond the line length with the cursor at the end of
......
......@@ -35,6 +35,7 @@
/* Define charalloc as a macro rather than duplicating code */
#define charalloc(howmuch) (char *)nmalloc((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
#define regexec(preg, string, nmatch, pmatch, eflags) regexec_safe(preg, string, nmatch, pmatch, eflags)
#endif
......
......@@ -426,6 +426,10 @@ void *nmalloc(size_t howmuch);
void *nrealloc(void *ptr, size_t howmuch);
char *mallocstrcpy(char *dest, const char *src);
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
int check_wildcard_match(const char *text, const char *pattern);
#endif
......@@ -443,7 +447,7 @@ int do_first_line(void);
int do_last_line(void);
int xpt(const filestruct *fileptr, int index);
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 strlenpt(const char *buf);
void blank_bottombars(void);
......@@ -452,7 +456,8 @@ void blank_edit(void);
void blank_statusbar(void);
void blank_statusbar_refresh(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,
#ifndef NANO_SMALL
historyheadtype *history_list,
......@@ -473,12 +478,9 @@ int get_page_start(int column);
void reset_cursor(void);
void add_marked_sameline(int begin, int end, filestruct *fileptr, int y,
int virt_cur_x, int this_page);
void edit_add(const filestruct *fileptr, int yval, int start
#ifndef NANO_SMALL
, int virt_mark_beginx, int virt_cur_x
#endif
);
void update_line(filestruct *fileptr, int index);
void edit_add(const filestruct *fileptr, const char *converted,
int yval, size_t start);
void update_line(const filestruct *fileptr, size_t index);
void update_cursor(void);
void center_cursor(void);
void edit_refresh(void);
......
......@@ -107,18 +107,22 @@ int search_init(int replacing)
search_init_globals();
/* If we don't already have a backupstring, set it. */
if (backupstring == NULL)
backupstring = mallocstrcpy(backupstring, "");
backupstring = mallocstrcpy(NULL, "");
#ifndef NANO_SMALL
search_history.current = (historytype *)&search_history.next;
#endif
if (last_search[0] != '\0') {
char *disp = display_string(last_search, 0, COLS / 3);
buf = charalloc(COLS / 3 + 7);
/* We use COLS / 3 here because we need to see more on the line */
sprintf(buf, " [%.*s%s]", COLS / 3, last_search,
strlen(last_search) > COLS / 3 ? "..." : "");
sprintf(buf, " [%s%s]", disp,
strlenpt(last_search) > COLS / 3 ? "..." : "");
free(disp);
} else {
buf = charalloc(1);
buf[0] = '\0';
......@@ -132,17 +136,23 @@ int search_init(int replacing)
"%s%s%s%s%s%s",
_("Search"),
#ifndef NANO_SMALL
/* This string is just a modifier for the search prompt,
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,
no grammar is implied */
ISSET(USE_REGEXP) ? _(" [Regexp]") : "",
#ifndef NANO_SMALL
/* This string is just a modifier for the search prompt,
no grammar is implied */
ISSET(REVERSE_SEARCH) ? _(" [Backwards]") : "",
ISSET(REVERSE_SEARCH) ? _(" [Backwards]") :
#endif
"",
replacing ? _(" (to replace)") : "",
buf);
......@@ -150,12 +160,13 @@ int search_init(int replacing)
/* Release buf now that we don't need it anymore */
free(buf);
free(backupstring);
backupstring = NULL;
/* Cancel any search, or just return with no previous search */
if (i == -1 || (i < 0 && last_search[0] == '\0')) {
statusbar(_("Search Cancelled"));
reset_cursor();
free(backupstring);
backupstring = NULL;
#ifndef NANO_SMALL
search_history.current = search_history.next;
#endif
......@@ -169,29 +180,23 @@ int search_init(int replacing)
if (regexp_init(last_search) == 0) {
statusbar(regex_error, last_search);
reset_cursor();
free(backupstring);
backupstring = NULL;
return -3;
}
#endif
break;
case 0: /* They entered something new */
last_replace[0] = '\0';
#ifdef HAVE_REGEX_H
if (ISSET(USE_REGEXP))
if (regexp_init(answer) == 0) {
statusbar(regex_error, answer);
reset_cursor();
free(backupstring);
backupstring = NULL;
#ifndef NANO_SMALL
search_history.current = search_history.next;
#endif
return -3;
}
#endif
free(backupstring);
backupstring = NULL;
last_replace[0] = '\0';
break;
#ifndef NANO_SMALL
case TOGGLE_CASE_KEY:
......@@ -213,8 +218,6 @@ int search_init(int replacing)
backupstring = mallocstrcpy(backupstring, answer);
return -2; /* Call the opposite search function */
case NANO_FROMSEARCHTOGOTO_KEY:
free(backupstring);
backupstring = NULL;
#ifndef NANO_SMALL
search_history.current = search_history.next;
#endif
......@@ -226,8 +229,6 @@ int search_init(int replacing)
return -3;
default:
do_early_abort();
free(backupstring);
backupstring = NULL;
return -3;
}
}
......@@ -631,6 +632,8 @@ int do_replace_loop(const char *prevanswer, const filestruct *begin,
last_replace = mallocstrcpy(last_replace, answer);
while (1) {
size_t match_len;
/* Sweet optimization by Rocco here */
fileptr = findnextstr(fileptr || replaceall || search_last_line,
FALSE, begin, *beginx, prevanswer);
......@@ -651,13 +654,27 @@ int do_replace_loop(const char *prevanswer, const filestruct *begin,
if (numreplaced == -1)
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) {
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);
do_replace_highlight(TRUE, prevanswer);
do_replace_highlight(TRUE, exp_word);
*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);
}
......
......@@ -302,6 +302,28 @@ void new_magicline(void)
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
/*
* 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