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-d3aeb78583b8
This commit is contained in:
Benno Schulenberg 2014-06-09 20:26:54 +00:00
parent acda255b47
commit 1102aaa374
6 changed files with 60 additions and 13 deletions

View File

@ -4,6 +4,8 @@
not comparing with an empty string but checking for the final \0. 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 * 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. 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> 2014-06-09 Benno Schulenberg <bensberg@justemail.net>
* src/nano.c (do_input): Remove two superfluous false conditions. * src/nano.c (do_input): Remove two superfluous false conditions.

View File

@ -1010,8 +1010,8 @@ void do_insertfile(
size_t current_x_save = openfile->current_x; size_t current_x_save = openfile->current_x;
ssize_t current_y_save = openfile->current_y; ssize_t current_y_save = openfile->current_y;
bool edittop_inside = FALSE, meta_key = FALSE, func_key = FALSE; bool edittop_inside = FALSE, meta_key = FALSE, func_key = FALSE;
const sc *s;
#ifndef NANO_TINY #ifndef NANO_TINY
const sc *s;
bool right_side_up = FALSE, single_line = FALSE; bool right_side_up = FALSE, single_line = FALSE;
#endif #endif
@ -1073,9 +1073,9 @@ void do_insertfile(
ans = mallocstrcpy(ans, answer); ans = mallocstrcpy(ans, answer);
#ifndef NANO_TINY
s = get_shortcut(currmenu, &i, &meta_key); s = get_shortcut(currmenu, &i, &meta_key);
#ifndef NANO_TINY
#ifndef DISABLE_MULTIBUFFER #ifndef DISABLE_MULTIBUFFER
if (s && s->scfunc == new_buffer_void) { if (s && s->scfunc == new_buffer_void) {
/* Don't allow toggling if we're in view mode. */ /* 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. */ /* The file descriptor we use. */
mode_t original_umask = 0; mode_t original_umask = 0;
/* Our umask, from when nano started. */ /* Our umask, from when nano started. */
#ifndef NANO_TINY
bool realexists; bool realexists;
/* The result of stat(). TRUE if the file exists, FALSE /* The result of stat(). TRUE if the file exists, FALSE
* otherwise. If name is a link that points nowhere, realexists * otherwise. If name is a link that points nowhere, realexists
* is FALSE. */ * is FALSE. */
struct stat st; struct stat st;
/* The status fields filled in by stat(). */ /* The status fields filled in by stat(). */
#endif
bool anyexists; bool anyexists;
/* The result of lstat(). The same as realexists, unless name /* The result of lstat(). The same as realexists, unless name
* is a link. */ * is a link. */
@ -1729,10 +1731,10 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
goto cleanup_and_exit; goto cleanup_and_exit;
} }
#ifndef NANO_TINY
/* Check whether the file (at the end of the symlink) exists. */ /* Check whether the file (at the end of the symlink) exists. */
realexists = (stat(realname, &st) != -1); realexists = (stat(realname, &st) != -1);
#ifndef NANO_TINY
/* If we haven't stat()d this file before (say, the user just /* If we haven't stat()d this file before (say, the user just
* specified it interactively), stat and save the value now, * specified it interactively), stat and save the value now,
* or else we will chase null pointers when we do modtime checks, * or else we will chase null pointers when we do modtime checks,

View File

@ -55,7 +55,10 @@ void do_page_up(void)
/* If there's less than a page of text left on the screen, put the /* 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 * cursor at the beginning of the first line of the file, and then
* update the edit window. */ * 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)) { openfile->current->lineno <= editwinrows - 2)) {
do_first_line(); do_first_line();
return; return;
@ -513,9 +516,9 @@ void do_up(
* smooth scrolling mode, or up half a page if we're not. If * smooth scrolling mode, or up half a page if we're not. If
* scroll_only is TRUE, scroll the edit window up one line * scroll_only is TRUE, scroll the edit window up one line
* unconditionally. */ * unconditionally. */
if (openfile->current_y == 0 || (ISSET(SOFTWRAP) && openfile->edittop->lineno == openfile->current->next->lineno) if (openfile->current_y == 0
#ifndef NANO_TINY #ifndef NANO_TINY
|| scroll_only || (ISSET(SOFTWRAP) && openfile->edittop->lineno == openfile->current->next->lineno) || scroll_only
#endif #endif
) )
edit_scroll(UP_DIR, 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 * 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 * be redrawn if we're not on the first page, and the latter needs
* to be drawn unconditionally. */ * 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)) if (need_vertical_update(0))
update_line(openfile->current->prev, 0); update_line(openfile->current->prev, 0);
update_line(openfile->current, openfile->current_x); update_line(openfile->current, openfile->current_x);

View File

@ -1761,6 +1761,7 @@ int do_mouse(void)
fprintf(stderr, "mouse_y = %d, current_y = %ld\n", mouse_y, (long)openfile->current_y); fprintf(stderr, "mouse_y = %d, current_y = %ld\n", mouse_y, (long)openfile->current_y);
#endif #endif
#ifndef NANO_TINY
if (ISSET(SOFTWRAP)) { if (ISSET(SOFTWRAP)) {
int i = 0; int i = 0;
for (openfile->current = openfile->edittop; for (openfile->current = openfile->edittop;
@ -1769,6 +1770,7 @@ int do_mouse(void)
openfile->current_y = i; openfile->current_y = i;
i += strlenpt(openfile->current->data) / COLS; i += strlenpt(openfile->current->data) / COLS;
} }
#endif
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "do_mouse(): moving to current_y = %d, i %d\n", openfile->current_y, i); fprintf(stderr, "do_mouse(): moving to current_y = %d, i %d\n", openfile->current_y, i);
@ -1961,15 +1963,22 @@ precalc_cleanup:
* TRUE. */ * TRUE. */
void do_output(char *output, size_t output_len, bool allow_cntrls) 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()); char *char_buf = charalloc(mb_cur_max());
int char_buf_len; int char_buf_len;
assert(openfile->current != NULL && openfile->current->data != NULL); assert(openfile->current != NULL && openfile->current->data != NULL);
current_len = strlen(openfile->current->data); current_len = strlen(openfile->current->data);
#ifndef NANO_TINY
if (ISSET(SOFTWRAP)) if (ISSET(SOFTWRAP))
orig_lenpt = strlenpt(openfile->current->data); orig_lenpt = strlenpt(openfile->current->data);
#endif
while (i < output_len) { while (i < output_len) {
/* If allow_cntrls is TRUE, convert nulls and newlines /* 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 #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. */ * line length to be a new multiple of COLS. */
if (ISSET(SOFTWRAP) && edit_refresh_needed == FALSE) if (ISSET(SOFTWRAP) && edit_refresh_needed == FALSE)
if (strlenpt(openfile->current->data) / COLS != orig_lenpt / COLS) if (strlenpt(openfile->current->data) / COLS != orig_lenpt / COLS)
edit_refresh_needed = TRUE; edit_refresh_needed = TRUE;
#endif
free(char_buf); free(char_buf);

View File

@ -66,7 +66,9 @@ void do_mark(void)
/* Delete the character under the cursor. */ /* Delete the character under the cursor. */
void do_deletion(undo_type action) void do_deletion(undo_type action)
{ {
#ifndef NANO_TINY
size_t orig_lenpt = 0; size_t orig_lenpt = 0;
#endif
assert(openfile->current != NULL && openfile->current->data != NULL && openfile->current_x <= strlen(openfile->current->data)); 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 #ifndef NANO_TINY
update_undo(action); update_undo(action);
#endif
if (ISSET(SOFTWRAP)) if (ISSET(SOFTWRAP))
orig_lenpt = strlenpt(openfile->current->data); orig_lenpt = strlenpt(openfile->current->data);
#endif
/* Let's get dangerous. */ /* Let's get dangerous. */
charmove(&openfile->current->data[openfile->current_x], charmove(&openfile->current->data[openfile->current_x],
@ -140,9 +143,11 @@ void do_deletion(undo_type action)
} else } else
return; return;
#ifndef NANO_TINY
if (ISSET(SOFTWRAP) && edit_refresh_needed == FALSE) if (ISSET(SOFTWRAP) && edit_refresh_needed == FALSE)
if (strlenpt(openfile->current->data) / COLS != orig_lenpt / COLS) if (strlenpt(openfile->current->data) / COLS != orig_lenpt / COLS)
edit_refresh_needed = TRUE; edit_refresh_needed = TRUE;
#endif
set_modified(); set_modified();

View File

@ -2447,6 +2447,7 @@ void reset_cursor(void)
xpt = xplustabs(); xpt = xplustabs();
#ifndef NANO_TINY
if (ISSET(SOFTWRAP)) { if (ISSET(SOFTWRAP)) {
filestruct *tmp; filestruct *tmp;
openfile->current_y = 0; openfile->current_y = 0;
@ -2457,7 +2458,9 @@ void reset_cursor(void)
openfile->current_y += xplustabs() / COLS; openfile->current_y += xplustabs() / COLS;
if (openfile->current_y < editwinrows) if (openfile->current_y < editwinrows)
wmove(edit, openfile->current_y, xpt % COLS); wmove(edit, openfile->current_y, xpt % COLS);
} else { } else
#endif
{
openfile->current_y = openfile->current->lineno - openfile->current_y = openfile->current->lineno -
openfile->edittop->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 /* fileptr->data converted to have tabs and control characters
* expanded. */ * expanded. */
size_t page_start; size_t page_start;
filestruct *tmp;
assert(fileptr != NULL); assert(fileptr != NULL);
#ifndef NANO_TINY
if (ISSET(SOFTWRAP)) { if (ISSET(SOFTWRAP)) {
filestruct *tmp;
for (tmp = openfile->edittop; tmp && tmp != fileptr; tmp = tmp->next) { for (tmp = openfile->edittop; tmp && tmp != fileptr; tmp = tmp->next) {
line += 1 + (strlenpt(tmp->data) / COLS); line += 1 + (strlenpt(tmp->data) / COLS);
} }
} else } else
#endif
line = fileptr->lineno - openfile->edittop->lineno; line = fileptr->lineno - openfile->edittop->lineno;
if (line < 0 || line >= editwinrows) 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 /* Next, convert variables that index the line to their equivalent
* positions in the expanded line. */ * positions in the expanded line. */
#ifndef NANO_TINY
if (ISSET(SOFTWRAP)) if (ISSET(SOFTWRAP))
index = 0; index = 0;
else else
#endif
index = strnlenpt(fileptr->data, index); index = strnlenpt(fileptr->data, index);
page_start = get_page_start(index); page_start = get_page_start(index);
/* Expand the line, replacing tabs with spaces, and control /* Expand the line, replacing tabs with spaces, and control
* characters with their displayed forms. */ * 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)); converted = display_string(fileptr->data, page_start, COLS, !ISSET(SOFTWRAP));
#ifdef DEBUG #ifdef DEBUG
if (ISSET(SOFTWRAP) && strlen(converted) >= COLS - 2) if (ISSET(SOFTWRAP) && strlen(converted) >= COLS - 2)
fprintf(stderr, "update_line(): converted(1) line = %s\n", converted); fprintf(stderr, "update_line(): converted(1) line = %s\n", converted);
#endif #endif
#endif /* !NANO_TINY */
/* Paint the line. */ /* Paint the line. */
edit_draw(fileptr, converted, line, page_start); edit_draw(fileptr, converted, line, page_start);
free(converted); free(converted);
#ifndef NANO_TINY
if (!ISSET(SOFTWRAP)) { if (!ISSET(SOFTWRAP)) {
#endif
if (page_start > 0) if (page_start > 0)
mvwaddch(edit, line, 0, '$'); mvwaddch(edit, line, 0, '$');
if (strlenpt(fileptr->data) > page_start + COLS) if (strlenpt(fileptr->data) > page_start + COLS)
mvwaddch(edit, line, COLS - 1, '$'); mvwaddch(edit, line, COLS - 1, '$');
#ifndef NANO_TINY
} else { } else {
int full_length = strlenpt(fileptr->data); int full_length = strlenpt(fileptr->data);
for (index += COLS; index <= full_length && line < editwinrows; index += COLS) { for (index += COLS; index <= full_length && line < editwinrows; index += COLS) {
@ -2924,6 +2938,7 @@ int update_line(filestruct *fileptr, size_t index)
extralinesused++; extralinesused++;
} }
} }
#endif /* !NANO_TINY */
return extralinesused; return extralinesused;
} }
@ -3015,6 +3030,8 @@ void edit_scroll(scroll_dir direction, ssize_t nlines)
break; break;
openfile->edittop = openfile->edittop->next; openfile->edittop = openfile->edittop->next;
} }
#ifndef NANO_TINY
/* Don't over-scroll on long lines. */ /* Don't over-scroll on long lines. */
if (ISSET(SOFTWRAP) && (direction == UP_DIR)) { if (ISSET(SOFTWRAP) && (direction == UP_DIR)) {
ssize_t len = strlenpt(openfile->edittop->data) / COLS; ssize_t len = strlenpt(openfile->edittop->data) / COLS;
@ -3022,6 +3039,7 @@ void edit_scroll(scroll_dir direction, ssize_t nlines)
if (len > 0) if (len > 0)
do_redraw = TRUE; do_redraw = TRUE;
} }
#endif
} }
/* Limit nlines to the number of lines we could scroll. */ /* 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--) { for (; goal > 0 && foo->prev != NULL; goal--) {
foo = foo->prev; foo = foo->prev;
#ifndef NANO_TINY
if (ISSET(SOFTWRAP) && foo) if (ISSET(SOFTWRAP) && foo)
goal -= strlenpt(foo->data) / COLS; goal -= strlenpt(foo->data) / COLS;
#endif
} }
openfile->edittop = foo; openfile->edittop = foo;
#ifdef DEBUG #ifdef DEBUG