per DB's patch, convert placewewant to a size_t; also add a few

miscellaneous fixes of mine


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1870 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
David Lawrence Ramsey 2004-07-28 20:46:25 +00:00
parent 2d140c2980
commit 86e851b4e7
8 changed files with 60 additions and 43 deletions

View File

@ -3,8 +3,9 @@ CVS code -
- 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
@ -48,6 +49,9 @@ CVS code -
- 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
@ -127,6 +131,9 @@ CVS code -
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)
@ -136,6 +143,9 @@ CVS code -
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

View File

@ -91,7 +91,7 @@ int resetstatuspos; /* Hack for resetting the status bar
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 */

View File

@ -30,7 +30,7 @@
void do_first_line(void)
{
int old_pww = placewewant;
size_t old_pww = placewewant;
current = fileage;
placewewant = 0;
current_x = 0;
@ -40,7 +40,7 @@ void do_first_line(void)
void do_last_line(void)
{
int old_pww = placewewant;
size_t old_pww = placewewant;
current = filebot;
placewewant = 0;
current_x = 0;
@ -51,7 +51,7 @@ void do_last_line(void)
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;
@ -78,7 +78,7 @@ void do_home(void)
void do_end(void)
{
int old_pww = placewewant;
size_t old_pww = placewewant;
current_x = strlen(current->data);
placewewant = xplustabs();
check_statblank();
@ -88,7 +88,7 @@ void do_end(void)
void do_page_up(void)
{
int old_pww = placewewant;
size_t old_pww = placewewant;
const filestruct *old_current = current;
#ifndef DISABLE_WRAPPING
wrap_reset();
@ -134,7 +134,7 @@ void do_page_up(void)
void do_page_down(void)
{
int old_pww = placewewant;
size_t old_pww = placewewant;
const filestruct *old_current = current;
#ifndef DISABLE_WRAPPING
wrap_reset();
@ -247,7 +247,7 @@ void do_down(void)
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) {
@ -267,7 +267,7 @@ void do_left_void(void)
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')

View File

@ -1158,7 +1158,7 @@ void do_enter(void)
#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);
@ -1190,7 +1190,7 @@ void do_next_word(void)
/* 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);

View File

@ -166,7 +166,7 @@ typedef struct openfilestruct {
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. */

View File

@ -33,7 +33,7 @@ extern ssize_t wrap_at;
#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
@ -406,7 +406,7 @@ void do_replace(void);
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
@ -539,10 +539,10 @@ void reset_cursor(void);
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,

View File

@ -359,8 +359,8 @@ int findnextstr(int can_display_wrap, int wholeword, const filestruct
/* 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
@ -588,8 +588,8 @@ char *replace_line(const char *needle)
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. */
@ -880,7 +880,7 @@ 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)
{
/* since do_gotoline() resets the x-coordinate but not the
y-coordinate, set the coordinates up this way */
@ -893,7 +893,7 @@ void do_gotopos(int line, int pos_x, int pos_y, int pos_placewewant)
/* set the rest of the coordinates up */
current_x = pos_x;
placewewant = pos_placewewant;
placewewant = pos_pww;
update_line(current, pos_x);
}
#endif
@ -904,7 +904,8 @@ void do_find_bracket(void)
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;
@ -919,6 +920,7 @@ void do_find_bracket(void)
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;

View File

@ -193,7 +193,8 @@ int get_translated_kbinput(int kbinput, int *es
#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
@ -415,7 +416,7 @@ int get_translated_kbinput(int kbinput, int *es
}
#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. */
@ -511,7 +512,7 @@ int get_ascii_kbinput(int kbinput, size_t ascii_digits
}
#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
@ -1096,7 +1097,7 @@ int *get_verbatim_kbinput(WINDOW *win, int *v_kbinput, size_t *v_len,
(*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
@ -1111,7 +1112,7 @@ int *get_verbatim_kbinput(WINDOW *win, int *v_kbinput, size_t *v_len,
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);
@ -1230,7 +1231,7 @@ int get_untranslated_kbinput(int kbinput, size_t position, int
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;
@ -1392,7 +1393,7 @@ void blank_titlebar(void)
void blank_edit(void)
{
size_t i;
int i;
for (i = 0; i < editwinrows; i++)
mvwaddstr(edit, i, 0, hblank);
}
@ -2543,7 +2544,7 @@ void update_line(const filestruct *fileptr, size_t index)
/* 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
@ -2555,7 +2556,7 @@ int need_horizontal_update(int old_pww)
/* 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
@ -2630,7 +2631,7 @@ void edit_scroll(updown direction, int nlines)
/* 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);
@ -2689,7 +2690,7 @@ void edit_refresh(void)
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) {
@ -2964,6 +2965,10 @@ void do_cursorpos(int constant)
}
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;
@ -2975,8 +2980,8 @@ void do_cursorpos(int constant)
* 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;
@ -2984,7 +2989,7 @@ void do_cursorpos(int constant)
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);
}
@ -3158,7 +3163,7 @@ void do_help(void)
* 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;