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.
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
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. */
/* 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. */
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,
/* 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;
* 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,
* 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);
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;
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);
* 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
#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);
/* 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));
#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],
} 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();
xpt = xplustabs();
+#ifndef NANO_TINY
if (ISSET(SOFTWRAP)) {
filestruct *tmp;
openfile->current_y = 0;
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;
/* 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)
/* 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) {
extralinesused++;
}
}
+#endif /* !NANO_TINY */
return extralinesused;
}
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;
if (len > 0)
do_redraw = TRUE;
}
+#endif
}
/* Limit nlines to the number of lines we could scroll. */
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