Skip to content

Commit

Permalink
Types.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Nov 14, 2023
1 parent b2e140b commit a82a2a9
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 34 deletions.
2 changes: 1 addition & 1 deletion ch.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ static int ch_get(void)
ch_have_ungotchar = FALSE;
} else if (ch_flags & CH_HELPFILE)
{
bp->data[bp->datasize] = helpdata[ch_fpos];
bp->data[bp->datasize] = (unsigned char) helpdata[ch_fpos];
n = 1;
} else
{
Expand Down
18 changes: 9 additions & 9 deletions charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ public constant char * prutfchar(LWCHAR ch)
/*
* Get the length of a UTF-8 character in bytes.
*/
public int utf_len(unsigned char ch)
public int utf_len(char ch)
{
if ((ch & 0x80) == 0)
return 1;
Expand All @@ -622,29 +622,29 @@ public lbool is_utf8_well_formed(constant char *ss, int slen)
{
int i;
int len;
constant unsigned char *s = (constant unsigned char *) ss;
unsigned char s0 = (unsigned char) ss[0];

if (IS_UTF8_INVALID(s[0]))
if (IS_UTF8_INVALID(s0))
return (FALSE);

len = utf_len(s[0]);
len = utf_len(ss[0]);
if (len > slen)
return (FALSE);
if (len == 1)
return (TRUE);
if (len == 2)
{
if (s[0] < 0xC2)
if (s0 < 0xC2)
return (FALSE);
} else
{
unsigned char mask = (~((1 << (8-len)) - 1)) & 0xFF;
if (s[0] == mask && (s[1] & mask) == 0x80)
unsigned char mask = (unsigned char) (~((1 << (8-len)) - 1));
if (s0 == mask && (ss[1] & mask) == 0x80)
return (FALSE);
}

for (i = 1; i < len; i++)
if (!IS_UTF8_TRAIL(s[i]))
if (!IS_UTF8_TRAIL(ss[i]))
return (FALSE);
return (TRUE);
}
Expand All @@ -666,7 +666,7 @@ public void utf_skip_to_lead(constant char **pp, constant char *limit)
public LWCHAR get_wchar(constant char *sp)
{
constant unsigned char *p = (constant unsigned char *) sp;
switch (utf_len(p[0]))
switch (utf_len(sp[0]))
{
case 1:
default:
Expand Down
1 change: 1 addition & 0 deletions less.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
/* True if the integer expression E, after promotion, is signed. */
#define signed_expr(e) ((TRUE ? 0 : e) - 1 < 0)
#endif
#define muldiv(val,num,den) umuldiv((uintmax)(val), (uintmax)(num), (uintmax)(den))

#include "lang.h"

Expand Down
28 changes: 14 additions & 14 deletions line.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public int pwidth(LWCHAR ch, int a, LWCHAR prev_ch, int prev_a)

if (!utf_mode || is_ascii_char(ch))
{
if (control_char((char)ch))
if (control_char(ch))
{
/*
* Control characters do unpredictable things,
Expand Down Expand Up @@ -759,7 +759,7 @@ static int store_char(LWCHAR ch, int a, constant char *rep, POSITION pos)
replen = 1;
} else
{
replen = utf_len(rep[0]);
replen = (size_t) utf_len(rep[0]); /*{{type-issue}}*/
}

if (cshift == hshift)
Expand All @@ -770,7 +770,7 @@ static int store_char(LWCHAR ch, int a, constant char *rep, POSITION pos)
{
/* Copy shifted ANSI sequences to beginning of line. */
for (i = 0; i < shifted_ansi.end; i++)
add_linebuf(shifted_ansi.data[i], AT_ANSI, 0);
add_linebuf((char) shifted_ansi.data[i], AT_ANSI, 0);
xbuf_reset(&shifted_ansi);
}
}
Expand Down Expand Up @@ -816,10 +816,10 @@ static int store_char(LWCHAR ch, int a, constant char *rep, POSITION pos)

static int store_string(constant char *s, int a, POSITION pos)
{
if (!fits_on_screen(strlen(s), a))
if (!fits_on_screen((int) strlen(s), a))
return 1;
for ( ; *s != 0; s++)
STORE_CHAR(*s, a, NULL, pos);
STORE_CHAR((LWCHAR)*s, a, NULL, pos);
return 0;
}

Expand Down Expand Up @@ -869,7 +869,7 @@ static int flush_mbc_buf(POSITION pos)
int i;

for (i = 0; i < mbc_buf_index; i++)
if (store_prchar(mbc_buf[i], pos))
if (store_prchar((LWCHAR) mbc_buf[i], pos))
return mbc_buf_index - i;
return 0;
}
Expand All @@ -879,7 +879,7 @@ static int flush_mbc_buf(POSITION pos)
* Expand tabs into spaces, handle underlining, boldfacing, etc.
* Returns 0 if ok, 1 if couldn't fit in buffer.
*/
public int pappend(int c, POSITION pos)
public int pappend(char c, POSITION pos)
{
int r;

Expand Down Expand Up @@ -913,14 +913,14 @@ public int pappend(int c, POSITION pos)
* the next char. If the next char is a newline,
* discard the CR.
*/
pendc = c;
pendc = (LWCHAR) c;
pendpos = pos;
return (0);
}

if (!utf_mode)
{
r = do_append(c, NULL, pos);
r = do_append((LWCHAR) c, NULL, pos);
} else
{
/* Perform strict validation in all possible cases. */
Expand All @@ -930,7 +930,7 @@ public int pappend(int c, POSITION pos)
mbc_buf_index = 1;
*mbc_buf = c;
if (IS_ASCII_OCTET(c))
r = do_append(c, NULL, pos);
r = do_append((LWCHAR) c, NULL, pos);
else if (IS_UTF8_LEAD(c))
{
mbc_buf_len = utf_len(c);
Expand Down Expand Up @@ -978,7 +978,7 @@ static int store_control_char(LWCHAR ch, constant char *rep, POSITION pos)
} else
{
/* Output a printable representation of the character. */
STORE_PRCHAR((char) ch, pos);
STORE_PRCHAR(ch, pos);
}
return (0);
}
Expand Down Expand Up @@ -1125,7 +1125,7 @@ static int do_append(LWCHAR ch, constant char *rep, POSITION pos)
STORE_TAB(a, pos);
return (0);
}
if ((!utf_mode || is_ascii_char(ch)) && control_char((char)ch))
if ((!utf_mode || is_ascii_char(ch)) && control_char(ch))
{
return store_control_char(ch, rep, pos);
} else if (utf_mode && ctldisp != OPT_ON && is_ubin_char(ch))
Expand Down Expand Up @@ -1359,7 +1359,7 @@ public POSITION forw_raw_line_len(POSITION curr_pos, ssize_t read_len, constant
break;
}
}
linebuf.buf[n++] = c;
linebuf.buf[n++] = (char) c;
if (read_len >= 0 && n >= read_len)
{
new_pos = ch_tell();
Expand Down Expand Up @@ -1441,7 +1441,7 @@ public POSITION back_raw_line(POSITION curr_pos, constant char **linep, size_t *
*to = *fm;
n = size_linebuf - old_size_linebuf;
}
linebuf.buf[--n] = c;
linebuf.buf[--n] = (char) c;
}
if (linep != NULL)
*linep = &linebuf.buf[n];
Expand Down
6 changes: 3 additions & 3 deletions mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void init_mark(void)
switch (i) {
case MOUSEMARK: letter = '#'; break;
case LASTMARK: letter = '\''; break;
default: letter = (i < 26) ? 'a'+i : 'A'+i-26; break;
default: letter = (char) ((i < 26) ? 'a'+i : 'A'+i-26); break;
}
marks[i].m_letter = letter;
cmark(&marks[i], NULL_IFILE, NULL_POSITION, -1);
Expand Down Expand Up @@ -318,8 +318,8 @@ public char posmark(POSITION pos)
{
if (marks[i].m_ifile == curr_ifile && marks[i].m_scrpos.pos == pos)
{
if (i < 26) return 'a' + i;
if (i < 26*2) return 'A' + (i - 26);
if (i < 26) return (char) ('a' + i);
if (i < 26*2) return (char) ('A' + (i - 26));
return '#';
}
}
Expand Down
6 changes: 3 additions & 3 deletions optfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ public void opt_rscroll(int type, constant char *s)
}
break; }
case QUERY: {
p.p_string = rscroll_char ? prchar(rscroll_char) : "-";
p.p_string = rscroll_char ? prchar((LWCHAR) rscroll_char) : "-";
error("rscroll character is %s", &p);
break; }
}
Expand Down Expand Up @@ -985,7 +985,7 @@ public void opt_intr(int type, constant char *s)
intr_char = CONTROL(s[1]);
break;
case QUERY: {
p.p_string = prchar(intr_char);
p.p_string = prchar((LWCHAR) intr_char);
error("interrupt character is %s", &p);
break; }
}
Expand Down Expand Up @@ -1093,7 +1093,7 @@ public void opt_search_type(int type, constant char *s)
if (def_search_type & SRCH_WRAP) *bp++ = 'W';
for (i = 1; i <= NUM_SEARCH_COLORS; i++)
if (def_search_type & SRCH_SUBSEARCH(i))
*bp++ = '0'+i;
*bp++ = (char) ('0'+i);
if (bp == buf)
*bp++ = '-';
*bp = '\0';
Expand Down
4 changes: 2 additions & 2 deletions option.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public constant char * propt(char c)
{
static char buf[MAX_PRCHAR_LEN+2];

sprintf(buf, "-%s", prchar(c));
sprintf(buf, "-%s", prchar((LWCHAR) c));
return (buf);
}

Expand All @@ -63,7 +63,7 @@ public constant char * propt(char c)
public void scan_option(constant char *s)
{
struct loption *o;
int optc;
char optc;
constant char *optname;
constant char *printopt;
char *str;
Expand Down
2 changes: 1 addition & 1 deletion os.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public constant char * signal_message(int sig)
* and min(VAL, NUM) <= DEN so the result cannot overflow.
* Round to the nearest integer, breaking ties by rounding to even.
*/
public uintmax muldiv(uintmax val, uintmax num, uintmax den)
public uintmax umuldiv(uintmax val, uintmax num, uintmax den)
{
/*
* Like round(val * (double) num / den), but without rounding error.
Expand Down
4 changes: 3 additions & 1 deletion output.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,11 @@ public void set_output(int fd)

/*
* Output a character.
* ch is int for compatibility with tputs.
*/
public int putchr(int c)
public int putchr(int ch)
{
char c = (char) ch;
#if 0 /* fake UTF-8 output for testing */
extern int utf_mode;
if (utf_mode)
Expand Down

0 comments on commit a82a2a9

Please sign in to comment.