add various type changes to avoid problems on systems where int and

ssize_t are different sizes.  Make filestruct->lineno a ssize_t (so that
we can avoid negative line numbers at the "Go To Line" prompt),
current_y a ssize_t (in order to hold the maximum difference between two
filestruct->lineno's), totlines a size_t, and change related variables
to match


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2782 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2005-06-28 06:25:34 +00:00
parent 6ad6b85862
commit 2cf6d717f1
10 changed files with 43 additions and 32 deletions

View File

@ -119,6 +119,14 @@ CVS code -
and add it to those regexes that can use it. Changes to
parse_colors(), parse_rcfile(), nanorc.sample, and nanorc.5.
(Brand Huntsman, minor tweaks by DLR)
- Add various type changes to avoid problems on systems where
int and ssize_t are different sizes. Make filestruct->lineno
a ssize_t (so that we can avoid negative line numbers at the
"Go To Line" prompt), current_y a ssize_t (in order to hold
the maximum difference between two filestruct->lineno's),
totlines a size_t, and change related variables to match.
(DLR, initial problem with parse_line_column() found by Mike
Frysinger)
- chars.c:
make_mbstring()
- Change erroneous ENABLE_EXTRA #ifdef to NANO_EXTRA to fix a

View File

@ -511,7 +511,7 @@ void do_insertfile(
char *ans = mallocstrcpy(NULL, "");
/* The last answer the user typed on the statusbar. */
filestruct *edittop_save = edittop;
int current_y_save = current_y;
ssize_t current_y_save = current_y;
bool at_edittop = FALSE;
/* Whether we're at the top of the edit window. */

View File

@ -54,7 +54,7 @@ int editwinrows = 0; /* How many rows long is the edit
filestruct *current; /* Current buffer pointer */
size_t current_x = 0; /* Current x-coordinate in the edit
window */
int current_y = 0; /* Current y-coordinate in the edit
ssize_t 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
@ -102,7 +102,7 @@ char *backup_dir = NULL; /* Backup directory. */
#endif
char *answer = NULL; /* Answer str to many questions */
int totlines = 0; /* Total number of lines in the file */
size_t totlines = 0; /* Total number of lines in the file */
size_t totsize = 0; /* Total number of characters in the
file */
size_t placewewant = 0; /* The column we'd like the cursor

View File

@ -895,8 +895,7 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot,
void copy_from_filestruct(filestruct *file_top, filestruct *file_bot)
{
filestruct *top_save;
int part_totlines;
size_t part_totsize;
size_t part_totlines, part_totsize;
bool at_edittop;
assert(file_top != NULL && file_bot != NULL);
@ -2318,7 +2317,7 @@ const char *do_alt_speller(char *tempfile_name)
{
int alt_spell_status, lineno_save = current->lineno;
size_t current_x_save = current_x, pww_save = placewewant;
int current_y_save = current_y;
ssize_t current_y_save = current_y;
pid_t pid_spell;
char *ptr;
static int arglen = 3;
@ -2333,7 +2332,7 @@ const char *do_alt_speller(char *tempfile_name)
* FALSE if (current, current_x) is. */
filestruct *top, *bot;
size_t top_x, bot_x;
int mbb_lineno_save = 0;
ssize_t mbb_lineno_save = 0;
/* We're going to close the current file, and open the output of
* the alternate spell command. The line that mark_beginbuf
* points to will be freed, so we save the line number and
@ -3077,7 +3076,7 @@ bool find_paragraph(size_t *const quote, size_t *const par)
/* Number of lines in the paragraph we search for. */
filestruct *current_save;
/* The line at the beginning of the paragraph we search for. */
size_t current_y_save;
ssize_t current_y_save;
/* The y-coordinate at the beginning of the paragraph we search
* for. */
@ -3147,7 +3146,7 @@ void do_justify(bool full_justify)
/* We save these global variables to be restored if the user
* unjustifies. Note that we don't need to save totlines. */
size_t current_x_save = current_x, pww_save = placewewant;
int current_y_save = current_y;
ssize_t current_y_save = current_y;
unsigned long flags_save = flags;
size_t totsize_save = totsize;
filestruct *edittop_save = edittop, *current_save = current;
@ -4131,7 +4130,7 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
int main(int argc, char **argv)
{
int optchr;
int startline = 1;
ssize_t startline = 1;
/* Line to try and start at. */
ssize_t startcol = 1;
/* Column to try and start at. */
@ -4608,8 +4607,8 @@ int main(int argc, char **argv)
/* Read all the files after the first one on the command line into
* new buffers. */
{
int i = optind + 1, iline = 1;
ssize_t icol = 1;
int i = optind + 1;
ssize_t iline = 1, icol = 1;
for (; i < argc; i++) {
/* If there's a +LINE or +LINE,COLUMN flag here, it is

View File

@ -162,7 +162,7 @@ typedef struct filestruct {
char *data;
struct filestruct *next; /* Next node. */
struct filestruct *prev; /* Previous node. */
int lineno; /* The line number. */
ssize_t lineno; /* The line number. */
} filestruct;
#ifdef ENABLE_MULTIBUFFER
@ -189,7 +189,7 @@ typedef struct openfilestruct {
size_t current_x; /* Current file's x-coordinate
* position. */
size_t placewewant; /* Current file's place we want. */
int totlines; /* Current file's total number of
size_t totlines; /* Current file's total number of
* lines. */
size_t totsize; /* Current file's total size. */
unsigned long flags; /* Current file's flags: modification

View File

@ -38,8 +38,8 @@ extern ssize_t wrap_at;
#endif
extern int editwinrows;
extern size_t current_x;
extern int current_y;
extern int totlines;
extern ssize_t current_y;
extern size_t totlines;
extern size_t placewewant;
#ifndef NANO_SMALL
extern size_t mark_beginx;
@ -529,7 +529,8 @@ void do_gotolinecolumn(int line, ssize_t column, bool use_answer, bool
interactive, bool save_pos);
void do_gotolinecolumn_void(void);
#if defined(ENABLE_MULTIBUFFER) || !defined(DISABLE_SPELLER)
void do_gotopos(int line, size_t pos_x, int pos_y, size_t pos_pww);
void do_gotopos(ssize_t line, size_t pos_x, ssize_t pos_y, size_t
pos_pww);
#endif
#ifndef NANO_SMALL
#ifdef HAVE_REGEX_H
@ -560,7 +561,7 @@ int regexp_bol_or_eol(const regex_t *preg, const char *string);
int digits(size_t n);
void get_homedir(void);
bool parse_num(const char *str, ssize_t *val);
bool parse_line_column(const char *str, int *line, ssize_t *column);
bool parse_line_column(const char *str, ssize_t *line, ssize_t *column);
void align(char **str);
void null_at(char **data, size_t index);
void unsunder(char *str, size_t true_len);
@ -587,7 +588,7 @@ void remove_magicline(void);
void mark_order(const filestruct **top, size_t *top_x, const filestruct
**bot, size_t *bot_x, bool *right_side_up);
#endif
void get_totals(const filestruct *begin, const filestruct *end, int
void get_totals(const filestruct *begin, const filestruct *end, size_t
*lines, size_t *size);
/* Public functions in winio.c. */

View File

@ -94,7 +94,7 @@ const static rcoption rcopts[] = {
};
static bool errors = FALSE;
static int lineno = 0;
static size_t lineno = 0;
static char *nanorc = NULL;
#ifdef ENABLE_COLOR
static syntaxtype *endsyntax = NULL;
@ -112,7 +112,8 @@ void rcfile_error(const char *msg, ...)
fprintf(stderr, "\n");
if (lineno > 0) {
errors = TRUE;
fprintf(stderr, _("Error in %s on line %d: "), nanorc, lineno);
fprintf(stderr, _("Error in %s on line %lu: "), nanorc,
(unsigned long)lineno);
}
va_start(ap, msg);

View File

@ -302,7 +302,7 @@ bool findnextstr(bool can_display_wrap, bool wholeword, bool
/* The length of the match we found. */
size_t current_x_find = 0;
/* The location of the match we found. */
int current_y_find = current_y;
ssize_t current_y_find = current_y;
/* rev_start might end up 1 character before the start or after the
* end of the line. This won't be a problem because strstrwrapper()
@ -1027,7 +1027,8 @@ void do_gotolinecolumn_void(void)
}
#if defined(ENABLE_MULTIBUFFER) || !defined(DISABLE_SPELLER)
void do_gotopos(int line, size_t pos_x, int pos_y, size_t pos_pww)
void do_gotopos(ssize_t line, size_t pos_x, ssize_t pos_y, size_t
pos_pww)
{
/* Since do_gotolinecolumn() resets the x-coordinate but not the
* y-coordinate, set the coordinates up this way. */

View File

@ -108,7 +108,7 @@ bool parse_num(const char *str, ssize_t *val)
/* Read an int and a ssize_t, separated by a comma, from str, and store
* them in *line and *column (if they're not both NULL). On error, we
* return FALSE. Otherwise, we return TRUE. */
bool parse_line_column(const char *str, int *line, ssize_t *column)
bool parse_line_column(const char *str, ssize_t *line, ssize_t *column)
{
bool retval = TRUE;
const char *comma;
@ -430,7 +430,7 @@ void mark_order(const filestruct **top, size_t *top_x, const filestruct
/* Calculate the number of lines and the number of characters between
* begin and end, and return them in lines and size, respectively. */
void get_totals(const filestruct *begin, const filestruct *end, int
void get_totals(const filestruct *begin, const filestruct *end, size_t
*lines, size_t *size)
{
const filestruct *f;

View File

@ -3572,7 +3572,7 @@ void edit_refresh(void)
const filestruct *foo = edittop;
#ifdef DEBUG
fprintf(stderr, "edit_refresh(): edittop->lineno = %d\n", edittop->lineno);
fprintf(stderr, "edit_refresh(): edittop->lineno = %ld\n", (long)edittop->lineno);
#endif
while (nlines < editwinrows) {
@ -3813,10 +3813,10 @@ void do_cursorpos(bool constant)
int bytepct = (totsize == 0) ? 0 : 100 * i / totsize;
statusbar(
_("line %ld/%ld (%d%%), col %lu/%lu (%d%%), char %lu/%lu (%d%%)"),
current->lineno, totlines, linepct, (unsigned long)xpt,
(unsigned long)cur_len, colpct, (unsigned long)i,
(unsigned long)totsize, bytepct);
_("line %ld/%lu (%d%%), col %lu/%lu (%d%%), char %lu/%lu (%d%%)"),
(long)current->lineno, (unsigned long)totlines, linepct,
(unsigned long)xpt, (unsigned long)cur_len, colpct,
(unsigned long)i, (unsigned long)totsize, bytepct);
disable_cursorpos = FALSE;
}
@ -4052,7 +4052,7 @@ void dump_buffer(const filestruct *inptr)
fprintf(stderr, "Dumping a buffer to stderr...\n");
while (inptr != NULL) {
fprintf(stderr, "(%d) %s\n", inptr->lineno, inptr->data);
fprintf(stderr, "(%ld) %s\n", (long)inptr->lineno, inptr->data);
inptr = inptr->next;
}
}
@ -4063,7 +4063,8 @@ void dump_buffer_reverse(void)
const filestruct *fileptr = filebot;
while (fileptr != NULL) {
fprintf(stderr, "(%d) %s\n", fileptr->lineno, fileptr->data);
fprintf(stderr, "(%ld) %s\n", (long)fileptr->lineno,
fileptr->data);
fileptr = fileptr->prev;
}
}