- When saving or changing file positions, be sure not to ignore
placewewant. Changes to do_int_spell_fix(), findnextstr(),
do_replace_loop(), and do_replace(). (DLR)
+ - Convert current_x to a size_t, and convert some functions that
+ use it as a parameter to use size_t as well. Also change some
+ current_x-related assertions to handle it. (David Benbennick
+ and DLR)
- files.c:
do_insertfile()
- Simplify by reusing variables whereever possible, and add a
- Update the help text to mention replacing and spell checking
only selected text, and also add a few cosmetic fixes to it.
(DLR)
+ do_prev_word()
+ - Tweak to avoid an infinite loop, since current_x is now a
+ size_t and hence is unsigned. (DLR)
do_int_spell_fix()
- Move the REVERSE_SEARCH flag toggling into the NANO_SMALL
#ifdef, since the tiny version of nano doesn't support reverse
#ifndef NANO_SMALL
if (ISSET(CUT_TO_END) && !ISSET(MARK_ISSET)) {
- assert(current_x >= 0 && current_x <= strlen(current->data));
+ assert(current_x <= strlen(current->data));
if (current->data[current_x] == '\0') {
/* If the line is empty and we didn't just cut a non-blank
int editwinrows = 0; /* How many rows long is the edit
window? */
filestruct *current; /* Current buffer pointer */
-int current_x = 0, current_y = 0; /* Current position of X and Y in
- the editor - relative to edit
- window (0,0) */
+size_t current_x = 0; /* Current x-coordinate in the edit
+ window */
+int current_y = 0; /* Current y-coordinate in the edit
+ window */
filestruct *fileage = NULL; /* Our file buffer */
filestruct *edittop = NULL; /* Pointer to the top of the edit
buffer with respect to the
size_t old_pww = placewewant;
#ifndef NANO_SMALL
if (ISSET(SMART_HOME)) {
- int old_current_x = current_x;
+ size_t old_current_x = current_x;
for (current_x = 0; isblank(current->data[current_x]) &&
current->data[current_x] != '\0'; current_x++)
const filestruct *old_current = current;
assert(current != NULL && current->data != NULL);
+ current_x++;
+
/* Skip letters in this word first. */
- while (current_x >= 0 && isalnum(current->data[current_x]))
+ while (current_x > 0 && isalnum(current->data[current_x - 1]))
current_x--;
for (; current != NULL; current = current->prev) {
- while (current_x >= 0 && !isalnum(current->data[current_x]))
+ while (current_x > 0 && !isalnum(current->data[current_x - 1]))
current_x--;
- if (current_x >= 0)
+ if (current_x > 0)
break;
if (current->prev != NULL)
- current_x = strlen(current->prev->data);
+ current_x = strlen(current->prev->data) + 1;
}
+ current_x--;
+
if (current == NULL) {
current = fileage;
current_x = 0;
/* Start from the top of the file. */
edittop = fileage;
current = fileage;
- current_x = -1;
+ current_x = (size_t)-1;
placewewant = 0;
/* Find the first whole-word occurrence of word. */
const char *do_alt_speller(char *tempfile_name)
{
int alt_spell_status, lineno_cur = current->lineno;
- int x_cur = current_x, y_cur = current_y;
- size_t pww_cur = placewewant;
+ size_t x_cur = current_x, pww_cur = placewewant;
+ int y_cur = current_y;
pid_t pid_spell;
char *ptr;
static int arglen = 3;
/* We save these global variables to be restored if the user
* unjustifies. Note that we don't need to save totlines. */
- int current_x_save = current_x, current_y_save = current_y;
+ size_t current_x_save = current_x;
+ int current_y_save = current_y;
long flags_save = flags, totsize_save = totsize;
filestruct *edittop_save = edittop, *current_save = current;
#ifndef NANO_SMALL
int file_mark_beginx; /* Current file's beginning marked
* line's x-coordinate position. */
#endif
- int file_current_x; /* Current file's x-coordinate
+ size_t file_current_x; /* Current file's x-coordinate
* position. */
int file_current_y; /* Current file's y-coordinate
* position. */
extern ssize_t wrap_at;
#endif
extern int editwinrows;
-extern int current_x, current_y, totlines;
+extern size_t current_x;
+extern int current_y;
+extern int totlines;
extern size_t placewewant;
#ifndef NANO_SMALL
extern int mark_beginx;
void do_gotoline(int line, bool 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, size_t pos_pww);
+void do_gotopos(int line, size_t pos_x, int pos_y, size_t pos_pww);
#endif
void do_find_bracket(void);
#ifndef NANO_SMALL
/* Set the cursor at the last character of the replacement
* text, so searching will resume after the replacement
- * text. Note that current_x might be set to -1 here. */
+ * text. Note that current_x might be set to (size_t)-1
+ * here. */
#ifndef NANO_SMALL
if (!ISSET(REVERSE_SEARCH))
#endif
}
#if defined(ENABLE_MULTIBUFFER) || !defined(DISABLE_SPELLER)
-void do_gotopos(int line, int pos_x, int pos_y, size_t pos_pww)
+void do_gotopos(int line, size_t 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. */
{
int kbinput;
bool meta_key, func_key;
- static int x = -1;
+ static size_t x = (size_t)-1;
/* the cursor position in 'answer' */
- int xend;
+ size_t xend;
/* length of 'answer', the status bar text */
bool tabbed = FALSE;
/* used by input_tab() */
resetstatuspos is TRUE. Otherwise, leave it alone. This is so
the cursor position stays at the same place if a prompt-changing
toggle is pressed. */
- if (x == -1 || x > xend || resetstatuspos)
+ if (x == (size_t)-1 || x > xend || resetstatuspos)
x = xend;
answer = charealloc(answer, xend + 1);
return t->ctrlval;
}
}
- assert(0 <= x && x <= xend && xend == strlen(answer));
+ assert(x <= xend && xend == strlen(answer));
if (kbinput != '\t')
tabbed = FALSE;
case NANO_HOME_KEY:
#ifndef NANO_SMALL
if (ISSET(SMART_HOME)) {
- int old_x = x;
+ size_t old_x = x;
for (x = 0; isblank(answer[x]) && x < xend; x++)
;
} /* while (kbinput ...) */
/* We finished putting in an answer; reset x */
- x = -1;
+ x = (size_t)-1;
return kbinput;
}
void do_cursorpos(bool constant)
{
const filestruct *fileptr;
- unsigned long i = 0;
- static unsigned long old_i = 0;
+ size_t i = 0;
+ static size_t old_i = 0;
static long old_totsize = -1;
assert(current != NULL && fileage != NULL && totlines != 0);
_("line %ld/%ld (%d%%), col %lu/%lu (%d%%), char %lu/%ld (%d%%)"),
current->lineno, totlines, linepct,
(unsigned long)xpt, (unsigned long)cur_len, colpct,
- i, totsize, bytepct);
+ (unsigned long)i, totsize, bytepct);
UNSET(DISABLE_CURPOS);
}