- More minor comment cleanups. (DLR)
- Convert more ints used as boolean values to use TRUE and
FALSE. (David Benbennick and DLR)
- - Change more instances of ints that can never be negative to
- size_t's. (DLR)
+ - Change more instances of ints that have large enough upper
+ bounds and which can never be negative to size_t's, and
+ convert nano to handle them properly. (DLR)
- Convert the shortcut list functions and most related functions
to return void instead of int, as the return values of all
those functions are essentially unused. Changes to
- Move the main terminal initialization functions, aside from
initscr(), into a new terminal_init() function, and convert
nano to use it. (DLR)
+ - Convert placewewant to a size_t, and convert some functions
+ that use it as a parameter to use size_t as well. (David
+ Benbennick and DLR)
- files.c:
close_open_file()
- Tweak to no longer rely on the return values of
Benbennick) DLR: Renamed from parse_int() to parse_num() and
converted to use ssize_t instead of int.
- winio.c:
+ get_kbinput()
+ - Since the only valid values for escapes are 0, 1, and 2,
+ convert it to an int. (DLR)
get_control_kbinput()
- Fix erroneous debugging statement so that nano compiles with
--enable-debug again. (Jon Oberheide)
before then too. (David Benbennick)
- Don't delete the statusbar line on UnCut, since the current
version of Pico doesn't. (DLR)
+ do_cursorpos()
+ - Add assert to check whether totsize is correct. (David
+ Benbennick)
line_len()
- Rename to help_line_len() so as not to conflict with the
line_len variable used elsewhere, and move inside the
char *answer = NULL; /* Answer str to many questions */
int totlines = 0; /* Total number of lines in the file */
long totsize = 0; /* Total number of bytes in the file */
-int placewewant = 0; /* The column we'd like the cursor
+size_t placewewant = 0; /* The column we'd like the cursor
to jump to when we go to the
next or previous line */
void do_first_line(void)
{
- int old_pww = placewewant;
+ size_t old_pww = placewewant;
current = fileage;
placewewant = 0;
current_x = 0;
void do_last_line(void)
{
- int old_pww = placewewant;
+ size_t old_pww = placewewant;
current = filebot;
placewewant = 0;
current_x = 0;
void do_home(void)
{
- int old_pww = placewewant;
+ size_t old_pww = placewewant;
#ifndef NANO_SMALL
if (ISSET(SMART_HOME)) {
int old_current_x = current_x;
void do_end(void)
{
- int old_pww = placewewant;
+ size_t old_pww = placewewant;
current_x = strlen(current->data);
placewewant = xplustabs();
check_statblank();
void do_page_up(void)
{
- int old_pww = placewewant;
+ size_t old_pww = placewewant;
const filestruct *old_current = current;
#ifndef DISABLE_WRAPPING
wrap_reset();
void do_page_down(void)
{
- int old_pww = placewewant;
+ size_t old_pww = placewewant;
const filestruct *old_current = current;
#ifndef DISABLE_WRAPPING
wrap_reset();
void do_left(int allow_update)
{
- int old_pww = placewewant;
+ size_t old_pww = placewewant;
if (current_x > 0)
current_x--;
else if (current != fileage) {
void do_right(int allow_update)
{
- int old_pww = placewewant;
+ size_t old_pww = placewewant;
assert(current_x <= strlen(current->data));
if (current->data[current_x] != '\0')
#ifndef NANO_SMALL
void do_next_word(void)
{
- int old_pww = placewewant;
+ size_t old_pww = placewewant;
const filestruct *current_save = current;
assert(current != NULL && current->data != NULL);
/* Skip letters in this word first. */
while (current->data[current_x] != '\0' &&
- isalnum((int)current->data[current_x]))
+ isalnum((int)current->data[current_x]))
current_x++;
for (; current != NULL; current = current->next) {
/* The same thing for backwards. */
void do_prev_word(void)
{
- int old_pww = placewewant;
+ size_t old_pww = placewewant;
const filestruct *current_save = current;
assert(current != NULL && current->data != NULL);
long file_flags; /* Current file's flags: modification
* status (and marking status, if
* available). */
- int file_placewewant; /* Current file's place we want. */
+ size_t file_placewewant; /* Current file's place we want. */
int file_totlines; /* Current file's total number of
* lines. */
long file_totsize; /* Current file's total size. */
#endif
extern int editwinrows;
extern int current_x, current_y, totlines;
-extern int placewewant;
+extern size_t placewewant;
#ifndef NANO_SMALL
extern int mark_beginx;
#endif
void do_gotoline(ssize_t line, int save_pos);
void do_gotoline_void(void);
#if defined (ENABLE_MULTIBUFFER) || !defined (DISABLE_SPELLER)
-void do_gotopos(int line, int pos_x, int pos_y, int pos_placewewant);
+void do_gotopos(int line, int pos_x, int pos_y, size_t pos_pww);
#endif
void do_find_bracket(void);
#ifndef NANO_SMALL
void edit_add(const filestruct *fileptr, const char *converted, int
yval, size_t start);
void update_line(const filestruct *fileptr, size_t index);
-int need_horizontal_update(int old_placewewant);
-int need_vertical_update(int old_placewewant);
+int need_horizontal_update(size_t old_pww);
+int need_vertical_update(size_t old_pww);
void edit_scroll(updown direction, int nlines);
-void edit_redraw(const filestruct *old_current, int old_pww);
+void edit_redraw(const filestruct *old_current, size_t old_pww);
void edit_refresh(void);
void edit_update(filestruct *fileptr, topmidnone location);
int statusq(int allowtabs, const shortcut *s, const char *def,
/* Search for a string. */
void do_search(void)
{
- size_t old_pww = placewewant, i, fileptr_x = current_x;
- int didfind;
+ size_t old_pww = placewewant, fileptr_x = current_x;
+ int i, didfind;
filestruct *fileptr = current;
#ifndef DISABLE_WRAPPING
int do_replace_loop(const char *needle, const filestruct *real_current,
size_t *real_current_x, int wholewords)
{
- int old_pww = placewewant, replaceall = FALSE, numreplaced = -1;
- size_t current_x_save = current_x;
+ int replaceall = FALSE, numreplaced = -1;
+ size_t old_pww = placewewant, current_x_save = current_x;
const filestruct *current_save = current;
#ifdef HAVE_REGEX_H
/* The starting-line match and bol/eol regex flags. */
}
#if defined(ENABLE_MULTIBUFFER) || !defined(DISABLE_SPELLER)
-void do_gotopos(int line, int pos_x, int pos_y, int pos_placewewant)
+void do_gotopos(int line, int pos_x, int pos_y, size_t pos_pww)
{
/* since do_gotoline() resets the x-coordinate but not the
y-coordinate, set the coordinates up this way */
/* set the rest of the coordinates up */
current_x = pos_x;
- placewewant = pos_placewewant;
+ placewewant = pos_pww;
update_line(current, pos_x);
}
#endif
char ch_under_cursor, wanted_ch;
const char *pos, *brackets = "([{<>}])";
char regexp_pat[] = "[ ]";
- int old_pww = placewewant, current_x_save, count = 1;
+ size_t old_pww, current_x_save;
+ int count = 1;
long flags_save;
filestruct *current_save;
assert(strlen(brackets) % 2 == 0);
wanted_ch = brackets[(strlen(brackets) - 1) - (pos - brackets)];
+ old_pww = placewewant;
current_x_save = current_x;
current_save = current;
flags_save = flags;
#endif
)
{
- static size_t escapes = 0, ascii_digits = 0;
+ static int escapes = 0;
+ static size_t ascii_digits = 0;
int retval = ERR;
#ifndef NANO_SMALL
}
}
}
-
+
#ifdef DEBUG
- fprintf(stderr, "get_translated_kbinput(): kbinput = %d, es = %d, escapes = %d, ascii_digits = %d, retval = %d\n", kbinput, *es, escapes, ascii_digits, retval);
+ fprintf(stderr, "get_translated_kbinput(): kbinput = %d, es = %d, escapes = %d, ascii_digits = %lu, retval = %d\n", kbinput, *es, escapes, (unsigned long)ascii_digits, retval);
#endif
/* Return the result. */
}
#ifdef DEBUG
- fprintf(stderr, "get_ascii_kbinput(): kbinput = %d, ascii_digits = %d, ascii_kbinput = %d, retval = %d\n", kbinput, ascii_digits, ascii_kbinput, retval);
+ fprintf(stderr, "get_ascii_kbinput(): kbinput = %d, ascii_digits = %lu, ascii_kbinput = %d, retval = %d\n", kbinput, (unsigned long)ascii_digits, ascii_kbinput, retval);
#endif
/* If the result is an ASCII character, reset the ASCII character
(*v_len)++;
v_kbinput[0] = kbinput;
#ifdef DEBUG
- fprintf(stderr, "get_verbatim_kbinput(): kbinput = %d, v_len = %d\n", kbinput, *v_len);
+ fprintf(stderr, "get_verbatim_kbinput(): kbinput = %d, v_len = %lu\n", kbinput, (unsigned long)*v_len);
#endif
/* Read any following characters using non-blocking input, until
v_kbinput = (int *)nrealloc(v_kbinput, *v_len * sizeof(int));
v_kbinput[*v_len - 1] = kbinput;
#ifdef DEBUG
- fprintf(stderr, "get_verbatim_kbinput(): kbinput = %d, v_len = %d\n", kbinput, *v_len);
+ fprintf(stderr, "get_verbatim_kbinput(): kbinput = %d, v_len = %lu\n", kbinput, (unsigned long)*v_len);
#endif
}
nodelay(win, FALSE);
retval = kbinput;
#ifdef DEBUG
- fprintf(stderr, "get_untranslated_kbinput(): kbinput = %d, position = %d, ascii_digits = %d\n", kbinput, position, ascii_digits);
+ fprintf(stderr, "get_untranslated_kbinput(): kbinput = %d, position = %lu, ascii_digits = %lu\n", kbinput, (unsigned long)position, (unsigned long)ascii_digits);
#endif
return retval;
void blank_edit(void)
{
- size_t i;
+ int i;
for (i = 0; i < editwinrows; i++)
mvwaddstr(edit, i, 0, hblank);
}
/* Return a nonzero value if we need an update after moving
* horizontally. We need one if the mark is on or if old_pww and
* placewewant are on different pages. */
-int need_horizontal_update(int old_pww)
+int need_horizontal_update(size_t old_pww)
{
return
#ifndef NANO_SMALL
/* Return a nonzero value if we need an update after moving vertically.
* We need one if the mark is on or if old_pww and placewewant
* are on different pages. */
-int need_vertical_update(int old_pww)
+int need_vertical_update(size_t old_pww)
{
return
#ifndef NANO_SMALL
/* Update any lines between old_current and current that need to be
* updated. */
-void edit_redraw(const filestruct *old_current, int old_pww)
+void edit_redraw(const filestruct *old_current, size_t old_pww)
{
int do_refresh = need_vertical_update(0) ||
need_vertical_update(old_pww);
const filestruct *foo = edittop;
#ifdef DEBUG
- fprintf(stderr, "edit_refresh(): edittop->lineno = %ld\n", edittop->lineno);
+ fprintf(stderr, "edit_refresh(): edittop->lineno = %d\n", edittop->lineno);
#endif
while (nlines < editwinrows) {
}
i += current_x;
+ /* Check whether totsize is correct. Else there is a bug
+ * somewhere. */
+ assert(current != filebot || i == totsize);
+
if (constant && ISSET(DISABLE_CURPOS)) {
UNSET(DISABLE_CURPOS);
old_i = i;
* unconditionally; otherwise, only display the position when the
* character values have changed. */
if (!constant || old_i != i || old_totsize != totsize) {
- unsigned long xpt = xplustabs() + 1;
- unsigned long cur_len = strlenpt(current->data) + 1;
+ size_t xpt = xplustabs() + 1;
+ size_t cur_len = strlenpt(current->data) + 1;
int linepct = 100 * current->lineno / totlines;
int colpct = 100 * xpt / cur_len;
int bytepct = totsize == 0 ? 0 : 100 * i / totsize;
statusbar(
_("line %ld/%ld (%d%%), col %lu/%lu (%d%%), char %lu/%ld (%d%%)"),
current->lineno, totlines, linepct,
- xpt, cur_len, colpct,
+ (unsigned long)xpt, (unsigned long)cur_len, colpct,
i, totsize, bytepct);
UNSET(DISABLE_CURPOS);
}
* expect word to have tabs and control characters expanded. */
void do_replace_highlight(int highlight_flag, const char *word)
{
- int y = xplustabs();
+ size_t y = xplustabs();
size_t word_len = strlen(word);
y = get_page_start(y) + COLS - y;