Skip to content

Commit

Permalink
Fix some more type issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Nov 14, 2023
1 parent 0c39562 commit 2d0abe8
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 58 deletions.
19 changes: 13 additions & 6 deletions ch.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ struct filestate {
thisfile->hashtbl[h].hnext = (bn);

static struct filestate *thisfile;
static int ch_ungotchar = -1;
static unsigned char ch_ungotchar;
static lbool ch_have_ungotchar = FALSE;
static int maxbufs = -1;

extern int autobuf;
Expand Down Expand Up @@ -260,11 +261,11 @@ static int ch_get(void)
* If we read less than a full block, that's ok.
* We use partial block and pick up the rest next time.
*/
if (ch_ungotchar != -1)
if (ch_have_ungotchar)
{
bp->data[bp->datasize] = ch_ungotchar;
n = 1;
ch_ungotchar = -1;
ch_have_ungotchar = FALSE;
} else if (ch_flags & CH_HELPFILE)
{
bp->data[bp->datasize] = helpdata[ch_fpos];
Expand Down Expand Up @@ -372,9 +373,15 @@ static int ch_get(void)
*/
public void ch_ungetchar(int c)
{
if (c != -1 && ch_ungotchar != -1)
error("ch_ungetchar overrun", NULL_PARG);
ch_ungotchar = c;
if (c < 0)
ch_have_ungotchar = FALSE;
else
{
if (ch_have_ungotchar)
error("ch_ungetchar overrun", NULL_PARG);
ch_ungotchar = (unsigned char) c;
ch_have_ungotchar = TRUE;
}
}

#if LOGFILE
Expand Down
10 changes: 5 additions & 5 deletions charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,10 @@ public int binary_char(LWCHAR c)
/*
* Is a given character a "control" character?
*/
public int control_char(LWCHAR c)
public lbool control_char(LWCHAR c)
{
c &= 0377;
if (!is_ascii_char(c))
return FALSE;
return (chardef[c] & IS_CONTROL_CHAR);
}

Expand All @@ -536,7 +537,7 @@ public constant char * prchar(LWCHAR c)
/* {{ This buffer can be overrun if LESSBINFMT is a long string. }} */
static char buf[MAX_PRCHAR_LEN+1];

c &= 0377;
c &= 0377; /*{{type-issue}}*/
if ((c < 128 || !utf_mode) && !control_char(c))
SNPRINTF1(buf, sizeof(buf), "%c", (int) c);
else if (c == ESC)
Expand Down Expand Up @@ -637,8 +638,7 @@ public lbool is_utf8_well_formed(constant char *ss, int slen)
return (FALSE);
} else
{
unsigned char mask;
mask = (~((1 << (8-len)) - 1)) & 0xFF;
unsigned char mask = (~((((unsigned char)1) << (8-len)) - 1)) & 0xFF;
if (s[0] == mask && (s[1] & mask) == 0x80)
return (FALSE);
}
Expand Down
20 changes: 12 additions & 8 deletions cmdbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ static int prompt_col; /* Column of cursor just after prompt */
static char *cp; /* Pointer into cmdbuf */
static int cmd_offset; /* Index into cmdbuf of first displayed char */
static int literal; /* Next input char should not be interpreted */
public ssize_t updown_match = -1; /* Prefix length in up/down movement */
public size_t updown_match; /* Prefix length in up/down movement */
public lbool have_updown_match = FALSE;

#if TAB_COMPLETE_FILENAME
static int cmd_complete(int action);
Expand Down Expand Up @@ -124,7 +125,7 @@ public void cmd_reset(void)
cmd_offset = 0;
literal = 0;
cmd_mbc_buf_len = 0;
updown_match = -1;
have_updown_match = FALSE;
}

/*
Expand All @@ -134,7 +135,7 @@ public void clear_cmd(void)
{
cmd_col = prompt_col = 0;
cmd_mbc_buf_len = 0;
updown_match = -1;
have_updown_match = FALSE;
}

/*
Expand Down Expand Up @@ -193,7 +194,7 @@ static constant char * cmd_step_common(char *p, LWCHAR ch, size_t len, int *pwid

if (len == 1)
{
pr = prchar((int) ch);
pr = prchar(ch);
width = (int) strlen(pr);
} else
{
Expand Down Expand Up @@ -460,7 +461,7 @@ static int cmd_ichar(constant char *cs, size_t clen)
/*
* Reprint the tail of the line from the inserted char.
*/
updown_match = -1;
have_updown_match = FALSE;
cmd_repaint(cp);
cmd_right();
return (CC_OK);
Expand Down Expand Up @@ -503,7 +504,7 @@ static int cmd_erase(void)
/*
* Repaint the buffer after the erased char.
*/
updown_match = -1;
have_updown_match = FALSE;
cmd_repaint(cp);

/*
Expand Down Expand Up @@ -596,7 +597,7 @@ static int cmd_kill(void)
cmd_offset = 0;
cmd_home();
*cp = '\0';
updown_match = -1;
have_updown_match = FALSE;
cmd_repaint(cp);

/*
Expand Down Expand Up @@ -643,8 +644,11 @@ static int cmd_updown(int action)
return (CC_OK);
}

if (updown_match < 0)
if (!have_updown_match)
{
updown_match = ptr_diff(cp, cmdbuf);
have_updown_match = TRUE;
}

/*
* Find the next history entry which matches.
Expand Down
16 changes: 11 additions & 5 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,9 @@ public void dispversion(void)
/*
* Return a character to complete a partial command, if possible.
*/
static LWCHAR getcc_end_command(void)
static char getcc_end_command(void)
{
int ch;
switch (mca)
{
case A_DIGIT:
Expand All @@ -934,7 +935,11 @@ static LWCHAR getcc_end_command(void)
return ('\n');
default:
/* Some other incomplete command. Let user complete it. */
return ((ungot == NULL) ? getchr() : 0);
if (ungot != NULL)
return ('\0');
ch = getchr();
if (ch < 0) ch = '\0';
return (char) ch;
}
}

Expand Down Expand Up @@ -969,14 +974,15 @@ public void getcc_clear(void)
*/
static char getccu(void)
{
char c = 0;
int c = 0;
while (c == 0)
{
if (ungot == NULL)
{
/* Normal case: no ungotten chars.
* Get char from the user. */
c = getchr();
if (c < 0) return ('\0');
} else
{
/* Ungotten chars available:
Expand All @@ -998,7 +1004,7 @@ static char getcc_repl(char constant *orig, char constant *repl, char (*gr_getc)
{
char c;
char keys[16];
int ki = 0;
size_t ki = 0;

c = (*gr_getc)();
if (orig == NULL || orig[0] == '\0')
Expand Down Expand Up @@ -1033,7 +1039,7 @@ static char getcc_repl(char constant *orig, char constant *repl, char (*gr_getc)
/*
* Get command character.
*/
public LWCHAR getcc(void)
public char getcc(void)
{
/* Replace kent (keypad Enter) with a newline. */
return getcc_repl(kent, "\n", getccu, ungetcc);
Expand Down
2 changes: 1 addition & 1 deletion cvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void cvt_text(char *odst, constant char *osrc, int *chpos, size_t *lenp,
{
if (ansi_step(pansi, ch) != ANSI_MID)
break;
ch = *src++;
ch = (LWCHAR) *src++; /* {{ would step_char work? }} */
}
ansi_done(pansi);
} else
Expand Down
2 changes: 1 addition & 1 deletion decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ static void expand_special_keys(unsigned char *table, size_t len)
if (repl == NULL || strlen(repl) > klen)
repl = "\377";
while (*repl != '\0')
*to++ = *repl++;
*to++ = (unsigned char) *repl++; /*{{type-issue}}*/
}
*to++ = '\0';
/*
Expand Down
6 changes: 3 additions & 3 deletions evar.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ static size_t add_evar(struct xbuffer *xbuf, mutable char *buf, size_t len, size
{
constant char *repl = find_replace(replaces, evar, &v);
if (repl == NULL)
xbuf_add_byte(xbuf, evar[v++]);
xbuf_add_char(xbuf, evar[v++]);
else
{
size_t r;
for (r = 0; repl[r] != '\0'; r++)
{
if (repl[r] == '\\') ++r;
xbuf_add_byte(xbuf, repl[r]);
xbuf_add_char(xbuf, repl[r]);
}
}
}
Expand Down Expand Up @@ -186,7 +186,7 @@ public void expand_evars(mutable char *buf, size_t len, struct xbuffer *xbuf)
i = add_evar(xbuf, buf, len, e, evar, term);
} else
{
xbuf_add_byte(xbuf, buf[i++]);
xbuf_add_char(xbuf, buf[i++]);
}
}
}
2 changes: 1 addition & 1 deletion filename.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ static char * readfd(FILE *fd)
int ch;
if ((ch = getc(fd)) == '\n' || ch == EOF)
break;
xbuf_add_char(&xbuf, ch);
xbuf_add_char(&xbuf, (char) ch);
}
xbuf_add_char(&xbuf, '\0');
return (char *) xbuf.data;
Expand Down
17 changes: 9 additions & 8 deletions input.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public POSITION forw_line_seg(POSITION curr_pos, lbool skipeol, lbool rscroll, l
null_line();
return (NULL_POSITION);
}
backchars = pappend(c, new_pos);
backchars = pappend((char) c, new_pos);
new_pos++;
if (backchars > 0)
{
Expand All @@ -161,7 +161,7 @@ public POSITION forw_line_seg(POSITION curr_pos, lbool skipeol, lbool rscroll, l
do
{
new_pos++;
c = ch_forw_get();
c = ch_forw_get(); /* {{ what if c == EOI? }} */
} while (c == ' ' || c == '\t');
backchars = 1;
}
Expand Down Expand Up @@ -214,7 +214,7 @@ public POSITION forw_line_seg(POSITION curr_pos, lbool skipeol, lbool rscroll, l
/*
* Append the char to the line and get the next char.
*/
backchars = pappend(c, ch_tell()-1);
backchars = pappend((char) c, ch_tell()-1);
if (backchars > 0)
{
/*
Expand Down Expand Up @@ -250,10 +250,10 @@ public POSITION forw_line_seg(POSITION curr_pos, lbool skipeol, lbool rscroll, l
do
{
new_pos = ch_tell();
c = ch_forw_get();
c = ch_forw_get(); /* {{ what if c == EOI? }} */
} while (c == ' ' || c == '\t');
if (c == '\r')
c = ch_forw_get();
c = ch_forw_get(); /* {{ what if c == EOI? }} */
if (c == '\n')
new_pos = ch_tell();
} else if (wrap_pos == NULL_POSITION)
Expand Down Expand Up @@ -373,6 +373,7 @@ public POSITION back_line(POSITION curr_pos)
*/
(void) ch_forw_get(); /* Skip the newline */
c = ch_forw_get(); /* First char of "current" line */
/* {{ what if c == EOI? }} */
(void) ch_back_get(); /* Restore our position */
(void) ch_back_get();

Expand Down Expand Up @@ -467,7 +468,7 @@ public POSITION back_line(POSITION curr_pos)
edisp_pos = new_pos;
break;
}
backchars = pappend(c, ch_tell()-1);
backchars = pappend((char) c, ch_tell()-1);
if (backchars > 0)
{
/*
Expand All @@ -494,14 +495,14 @@ public POSITION back_line(POSITION curr_pos)
{
for (;;)
{
c = ch_forw_get();
c = ch_forw_get(); /* {{ what if c == EOI? }} */
if (c == ' ' || c == '\t')
new_pos++;
else
{
if (c == '\r')
{
c = ch_forw_get();
c = ch_forw_get(); /* {{ what if c == EOI? }} */
if (c == '\n')
new_pos++;
}
Expand Down
20 changes: 10 additions & 10 deletions less.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
* These substitutes for C23 stdckdint macros do not set *R on overflow,
* and they assume A and B are nonnegative. That is good enough for us.
*/
#define ckd_add(r, a, b) help_ckd_add(r, a, b, sizeof *(r), signed_expr(*(r)))
#define ckd_mul(r, a, b) help_ckd_mul(r, a, b, sizeof *(r), signed_expr(*(r)))
#define ckd_add(r, a, b) help_ckd_add(r, (uintmax)(a), (uintmax)(b), sizeof *(r), signed_expr(*(r)))
#define ckd_mul(r, a, b) help_ckd_mul(r, (uintmax)(a), (uintmax)(b), sizeof *(r), signed_expr(*(r)))
/* True if the integer expression E, after promotion, is signed. */
#define signed_expr(e) ((TRUE ? 0 : e) - 1 < 0)
#endif
Expand Down Expand Up @@ -144,15 +144,15 @@ void free();
#define TO_LOWER(c) towlower(c)
#else
#if HAVE_UPPER_LOWER
#define IS_UPPER(c) isupper((unsigned char) (c))
#define IS_LOWER(c) islower((unsigned char) (c))
#define TO_UPPER(c) toupper((unsigned char) (c))
#define TO_LOWER(c) tolower((unsigned char) (c))
#define IS_UPPER(c) (is_ascii_char(c) && isupper((unsigned char) (c)))
#define IS_LOWER(c) (is_ascii_char(c) && islower((unsigned char) (c)))
#define TO_UPPER(c) (is_ascii_char(c) ? toupper((unsigned char) (c)) : (c))
#define TO_LOWER(c) (is_ascii_char(c) ? tolower((unsigned char) (c)) : (c))
#else
#define IS_UPPER(c) ASCII_IS_UPPER(c)
#define IS_LOWER(c) ASCII_IS_LOWER(c)
#define TO_UPPER(c) ASCII_TO_UPPER(c)
#define TO_LOWER(c) ASCII_TO_LOWER(c)
#define IS_UPPER(c) (is_ascii_char(c) && ASCII_IS_UPPER(c))
#define IS_LOWER(c) (is_ascii_char(c) && ASCII_IS_LOWER(c))
#define TO_UPPER(c) (is_ascii_char(c) ? ASCII_TO_UPPER(c) : (c))
#define TO_LOWER(c) (is_ascii_char(c) ? ASCII_TO_LOWER(c) : (c))
#endif
#endif

Expand Down
10 changes: 5 additions & 5 deletions line.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ static int expand_linebuf(void)
/*
* Is a character ASCII?
*/
public int is_ascii_char(LWCHAR ch)
public lbool is_ascii_char(LWCHAR ch)
{
return (ch <= 0x7F);
}
Expand Down Expand Up @@ -381,13 +381,13 @@ public void plinestart(POSITION pos)
* Return the width of the line prefix (status column and line number).
* {{ Actual line number can be wider than linenum_width. }}
*/
public size_t line_pfx_width(void)
public int line_pfx_width(void)
{
size_t width = 0;
int width = 0;
if (status_col)
width += (size_t) status_col_width; /*{{type-issue}}*/
width += status_col_width;
if (linenums == OPT_ONPLUS)
width += (size_t) linenum_width + 1; /*{{type-issue}}*/
width += linenum_width + 1;
return width;
}

Expand Down
Loading

0 comments on commit 2d0abe8

Please sign in to comment.