Making tiny nano a bit tinier by preening out some soft-wrap stuff.
Patch by David Lawrence Ramsey. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4951 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
acda255b47
commit
1102aaa374
|
@ -4,6 +4,8 @@
|
|||
not comparing with an empty string but checking for the final \0.
|
||||
* src/files.c, src/nano.c, src/text.c, src/winio.c: Type fixes in
|
||||
debugging stuff -- line numbers are long, x positions unsigned long.
|
||||
* src/files.c, src/move.c, src/nano.c, src/text.c, src/winio.c:
|
||||
Make tiny nano a bit tinier by preening out some soft-wrap stuff.
|
||||
|
||||
2014-06-09 Benno Schulenberg <bensberg@justemail.net>
|
||||
* src/nano.c (do_input): Remove two superfluous false conditions.
|
||||
|
|
|
@ -1010,8 +1010,8 @@ void do_insertfile(
|
|||
size_t current_x_save = openfile->current_x;
|
||||
ssize_t current_y_save = openfile->current_y;
|
||||
bool edittop_inside = FALSE, meta_key = FALSE, func_key = FALSE;
|
||||
const sc *s;
|
||||
#ifndef NANO_TINY
|
||||
const sc *s;
|
||||
bool right_side_up = FALSE, single_line = FALSE;
|
||||
#endif
|
||||
|
||||
|
@ -1073,9 +1073,9 @@ void do_insertfile(
|
|||
|
||||
ans = mallocstrcpy(ans, answer);
|
||||
|
||||
#ifndef NANO_TINY
|
||||
s = get_shortcut(currmenu, &i, &meta_key);
|
||||
|
||||
#ifndef NANO_TINY
|
||||
#ifndef DISABLE_MULTIBUFFER
|
||||
if (s && s->scfunc == new_buffer_void) {
|
||||
/* Don't allow toggling if we're in view mode. */
|
||||
|
@ -1675,12 +1675,14 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
|
|||
/* The file descriptor we use. */
|
||||
mode_t original_umask = 0;
|
||||
/* Our umask, from when nano started. */
|
||||
#ifndef NANO_TINY
|
||||
bool realexists;
|
||||
/* The result of stat(). TRUE if the file exists, FALSE
|
||||
* otherwise. If name is a link that points nowhere, realexists
|
||||
* is FALSE. */
|
||||
struct stat st;
|
||||
/* The status fields filled in by stat(). */
|
||||
#endif
|
||||
bool anyexists;
|
||||
/* The result of lstat(). The same as realexists, unless name
|
||||
* is a link. */
|
||||
|
@ -1729,10 +1731,10 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
|
|||
goto cleanup_and_exit;
|
||||
}
|
||||
|
||||
#ifndef NANO_TINY
|
||||
/* Check whether the file (at the end of the symlink) exists. */
|
||||
realexists = (stat(realname, &st) != -1);
|
||||
|
||||
#ifndef NANO_TINY
|
||||
/* If we haven't stat()d this file before (say, the user just
|
||||
* specified it interactively), stat and save the value now,
|
||||
* or else we will chase null pointers when we do modtime checks,
|
||||
|
|
15
src/move.c
15
src/move.c
|
@ -55,7 +55,10 @@ void do_page_up(void)
|
|||
/* If there's less than a page of text left on the screen, put the
|
||||
* cursor at the beginning of the first line of the file, and then
|
||||
* update the edit window. */
|
||||
if (openfile->current->lineno == 1 || (!ISSET(SOFTWRAP) &&
|
||||
if (openfile->current->lineno == 1 || (
|
||||
#ifndef NANO_TINY
|
||||
!ISSET(SOFTWRAP) &&
|
||||
#endif
|
||||
openfile->current->lineno <= editwinrows - 2)) {
|
||||
do_first_line();
|
||||
return;
|
||||
|
@ -513,9 +516,9 @@ void do_up(
|
|||
* smooth scrolling mode, or up half a page if we're not. If
|
||||
* scroll_only is TRUE, scroll the edit window up one line
|
||||
* unconditionally. */
|
||||
if (openfile->current_y == 0 || (ISSET(SOFTWRAP) && openfile->edittop->lineno == openfile->current->next->lineno)
|
||||
if (openfile->current_y == 0
|
||||
#ifndef NANO_TINY
|
||||
|| scroll_only
|
||||
|| (ISSET(SOFTWRAP) && openfile->edittop->lineno == openfile->current->next->lineno) || scroll_only
|
||||
#endif
|
||||
)
|
||||
edit_scroll(UP_DIR,
|
||||
|
@ -622,7 +625,11 @@ void do_down(
|
|||
* we were on before and the line we're on now. The former needs to
|
||||
* be redrawn if we're not on the first page, and the latter needs
|
||||
* to be drawn unconditionally. */
|
||||
if (ISSET(SOFTWRAP) || openfile->current_y < editwinrows - 1) {
|
||||
if (openfile->current_y < editwinrows - 1
|
||||
#ifndef NANO_TINY
|
||||
|| ISSET(SOFTWRAP)
|
||||
#endif
|
||||
) {
|
||||
if (need_vertical_update(0))
|
||||
update_line(openfile->current->prev, 0);
|
||||
update_line(openfile->current, openfile->current_x);
|
||||
|
|
15
src/nano.c
15
src/nano.c
|
@ -1761,6 +1761,7 @@ int do_mouse(void)
|
|||
fprintf(stderr, "mouse_y = %d, current_y = %ld\n", mouse_y, (long)openfile->current_y);
|
||||
#endif
|
||||
|
||||
#ifndef NANO_TINY
|
||||
if (ISSET(SOFTWRAP)) {
|
||||
int i = 0;
|
||||
for (openfile->current = openfile->edittop;
|
||||
|
@ -1769,6 +1770,7 @@ int do_mouse(void)
|
|||
openfile->current_y = i;
|
||||
i += strlenpt(openfile->current->data) / COLS;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "do_mouse(): moving to current_y = %d, i %d\n", openfile->current_y, i);
|
||||
|
@ -1961,15 +1963,22 @@ precalc_cleanup:
|
|||
* TRUE. */
|
||||
void do_output(char *output, size_t output_len, bool allow_cntrls)
|
||||
{
|
||||
size_t current_len, orig_lenpt = 0, i = 0;
|
||||
size_t current_len, i = 0;
|
||||
#ifndef NANO_TINY
|
||||
size_t orig_lenpt = 0;
|
||||
#endif
|
||||
|
||||
char *char_buf = charalloc(mb_cur_max());
|
||||
int char_buf_len;
|
||||
|
||||
assert(openfile->current != NULL && openfile->current->data != NULL);
|
||||
|
||||
current_len = strlen(openfile->current->data);
|
||||
|
||||
#ifndef NANO_TINY
|
||||
if (ISSET(SOFTWRAP))
|
||||
orig_lenpt = strlenpt(openfile->current->data);
|
||||
#endif
|
||||
|
||||
while (i < output_len) {
|
||||
/* If allow_cntrls is TRUE, convert nulls and newlines
|
||||
|
@ -2050,11 +2059,13 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
|
|||
#endif
|
||||
}
|
||||
|
||||
/* Well we might also need a full refresh if we've changed the
|
||||
#ifndef NANO_TINY
|
||||
/* Well, we might also need a full refresh if we've changed the
|
||||
* line length to be a new multiple of COLS. */
|
||||
if (ISSET(SOFTWRAP) && edit_refresh_needed == FALSE)
|
||||
if (strlenpt(openfile->current->data) / COLS != orig_lenpt / COLS)
|
||||
edit_refresh_needed = TRUE;
|
||||
#endif
|
||||
|
||||
free(char_buf);
|
||||
|
||||
|
|
|
@ -66,7 +66,9 @@ void do_mark(void)
|
|||
/* Delete the character under the cursor. */
|
||||
void do_deletion(undo_type action)
|
||||
{
|
||||
#ifndef NANO_TINY
|
||||
size_t orig_lenpt = 0;
|
||||
#endif
|
||||
|
||||
assert(openfile->current != NULL && openfile->current->data != NULL && openfile->current_x <= strlen(openfile->current->data));
|
||||
|
||||
|
@ -82,9 +84,10 @@ void do_deletion(undo_type action)
|
|||
|
||||
#ifndef NANO_TINY
|
||||
update_undo(action);
|
||||
#endif
|
||||
|
||||
if (ISSET(SOFTWRAP))
|
||||
orig_lenpt = strlenpt(openfile->current->data);
|
||||
#endif
|
||||
|
||||
/* Let's get dangerous. */
|
||||
charmove(&openfile->current->data[openfile->current_x],
|
||||
|
@ -140,9 +143,11 @@ void do_deletion(undo_type action)
|
|||
} else
|
||||
return;
|
||||
|
||||
#ifndef NANO_TINY
|
||||
if (ISSET(SOFTWRAP) && edit_refresh_needed == FALSE)
|
||||
if (strlenpt(openfile->current->data) / COLS != orig_lenpt / COLS)
|
||||
edit_refresh_needed = TRUE;
|
||||
#endif
|
||||
|
||||
set_modified();
|
||||
|
||||
|
|
26
src/winio.c
26
src/winio.c
|
@ -2447,6 +2447,7 @@ void reset_cursor(void)
|
|||
|
||||
xpt = xplustabs();
|
||||
|
||||
#ifndef NANO_TINY
|
||||
if (ISSET(SOFTWRAP)) {
|
||||
filestruct *tmp;
|
||||
openfile->current_y = 0;
|
||||
|
@ -2457,7 +2458,9 @@ void reset_cursor(void)
|
|||
openfile->current_y += xplustabs() / COLS;
|
||||
if (openfile->current_y < editwinrows)
|
||||
wmove(edit, openfile->current_y, xpt % COLS);
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
openfile->current_y = openfile->current->lineno -
|
||||
openfile->edittop->lineno;
|
||||
|
||||
|
@ -2858,15 +2861,18 @@ int update_line(filestruct *fileptr, size_t index)
|
|||
/* fileptr->data converted to have tabs and control characters
|
||||
* expanded. */
|
||||
size_t page_start;
|
||||
filestruct *tmp;
|
||||
|
||||
assert(fileptr != NULL);
|
||||
|
||||
#ifndef NANO_TINY
|
||||
if (ISSET(SOFTWRAP)) {
|
||||
filestruct *tmp;
|
||||
|
||||
for (tmp = openfile->edittop; tmp && tmp != fileptr; tmp = tmp->next) {
|
||||
line += 1 + (strlenpt(tmp->data) / COLS);
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
line = fileptr->lineno - openfile->edittop->lineno;
|
||||
|
||||
if (line < 0 || line >= editwinrows)
|
||||
|
@ -2877,30 +2883,38 @@ int update_line(filestruct *fileptr, size_t index)
|
|||
|
||||
/* Next, convert variables that index the line to their equivalent
|
||||
* positions in the expanded line. */
|
||||
#ifndef NANO_TINY
|
||||
if (ISSET(SOFTWRAP))
|
||||
index = 0;
|
||||
else
|
||||
#endif
|
||||
index = strnlenpt(fileptr->data, index);
|
||||
page_start = get_page_start(index);
|
||||
|
||||
/* Expand the line, replacing tabs with spaces, and control
|
||||
* characters with their displayed forms. */
|
||||
#ifdef NANO_TINY
|
||||
converted = display_string(fileptr->data, page_start, COLS, TRUE);
|
||||
#else
|
||||
converted = display_string(fileptr->data, page_start, COLS, !ISSET(SOFTWRAP));
|
||||
|
||||
#ifdef DEBUG
|
||||
if (ISSET(SOFTWRAP) && strlen(converted) >= COLS - 2)
|
||||
fprintf(stderr, "update_line(): converted(1) line = %s\n", converted);
|
||||
#endif
|
||||
#endif /* !NANO_TINY */
|
||||
|
||||
/* Paint the line. */
|
||||
edit_draw(fileptr, converted, line, page_start);
|
||||
free(converted);
|
||||
|
||||
#ifndef NANO_TINY
|
||||
if (!ISSET(SOFTWRAP)) {
|
||||
#endif
|
||||
if (page_start > 0)
|
||||
mvwaddch(edit, line, 0, '$');
|
||||
if (strlenpt(fileptr->data) > page_start + COLS)
|
||||
mvwaddch(edit, line, COLS - 1, '$');
|
||||
#ifndef NANO_TINY
|
||||
} else {
|
||||
int full_length = strlenpt(fileptr->data);
|
||||
for (index += COLS; index <= full_length && line < editwinrows; index += COLS) {
|
||||
|
@ -2924,6 +2938,7 @@ int update_line(filestruct *fileptr, size_t index)
|
|||
extralinesused++;
|
||||
}
|
||||
}
|
||||
#endif /* !NANO_TINY */
|
||||
return extralinesused;
|
||||
}
|
||||
|
||||
|
@ -3015,6 +3030,8 @@ void edit_scroll(scroll_dir direction, ssize_t nlines)
|
|||
break;
|
||||
openfile->edittop = openfile->edittop->next;
|
||||
}
|
||||
|
||||
#ifndef NANO_TINY
|
||||
/* Don't over-scroll on long lines. */
|
||||
if (ISSET(SOFTWRAP) && (direction == UP_DIR)) {
|
||||
ssize_t len = strlenpt(openfile->edittop->data) / COLS;
|
||||
|
@ -3022,6 +3039,7 @@ void edit_scroll(scroll_dir direction, ssize_t nlines)
|
|||
if (len > 0)
|
||||
do_redraw = TRUE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Limit nlines to the number of lines we could scroll. */
|
||||
|
@ -3262,8 +3280,10 @@ void edit_update(update_type location)
|
|||
|
||||
for (; goal > 0 && foo->prev != NULL; goal--) {
|
||||
foo = foo->prev;
|
||||
#ifndef NANO_TINY
|
||||
if (ISSET(SOFTWRAP) && foo)
|
||||
goal -= strlenpt(foo->data) / COLS;
|
||||
#endif
|
||||
}
|
||||
openfile->edittop = foo;
|
||||
#ifdef DEBUG
|
||||
|
|
Loading…
Reference in New Issue