Skip to content

Commit d6d338a

Browse files
committed
Test for 'is this a valid alternative charset character' assumed 16 bits were assigned to A_CHARTEXT. That's always true in upstream PDCurses, but we have 21 bits (for full Unicode characters and 64-bit chtypes) and 8 bits (for narrow-build 32-bit chtypes). Mark Hessling pointed me to a compiler error in the latter case, and there could be display issues on platforms where the error doesn't occur. And in any case, the revised code is easier to look at and understand (no magical 0xff80 constants).
1 parent 70811c6 commit d6d338a

File tree

12 files changed

+26
-23
lines changed

12 files changed

+26
-23
lines changed

curspriv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,6 @@ PDCEX int PDC_wcwidth( const int32_t ucs);
131131

132132
#define INTENTIONALLY_UNUSED_PARAMETER( param) (void)(param)
133133

134+
#define _is_altcharset( ch) (((ch) & (A_ALTCHARSET | (A_CHARTEXT ^ 0x7f))) == A_ALTCHARSET)
135+
134136
#endif /* __CURSES_INTERNALS__ */

dos/pdcdisp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static void _new_packet(attr_t attr, int lineno, int x, int len, const chtype *s
7979

8080
temp_line[j].attr = mapped_attr;
8181

82-
if (ch & A_ALTCHARSET && !(ch & 0x80))
82+
if( _is_altcharset( ch))
8383
ch = acs_map[ch & 0x7f];
8484

8585
temp_line[j].text = ch & 0xff;
@@ -119,7 +119,7 @@ static void _new_packet(attr_t attr, int lineno, int x, int len, const chtype *s
119119
regs.W.bx = mapped_attr;
120120
regs.W.cx = count;
121121

122-
if (ch & A_ALTCHARSET && !(ch & 0xff80))
122+
if( _is_altcharset( ch))
123123
ch = acs_map[ch & 0x7f];
124124

125125
regs.h.al = (unsigned char) (ch & 0xff);

dosvga/pdcdisp.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ static void _new_packet(unsigned long colors, int lineno, int x, int len, const
7171
/* Compute these just once */
7272
for (i = 0; i < len; ++i)
7373
{
74-
chtype glyph = srcp[i];
74+
const chtype glyph = srcp[i];
7575
unsigned ch = glyph & A_CHARTEXT;
76-
if ((glyph & A_ALTCHARSET) != 0 && (ch & 0xff80) == 0)
76+
77+
if( _is_altcharset( glyph))
7778
ch = acs_map[ch];
7879
glyphs[i].font_addr = PDC_state.font_glyph_data(FALSE, ch);
7980
}
@@ -394,7 +395,7 @@ static void _transform_line_8(int lineno, int x, int len, const chtype *srcp)
394395

395396
/* Get the index into the font */
396397
ch = glyph & A_CHARTEXT;
397-
if ((glyph & A_ALTCHARSET) != 0 && (glyph & 0xff80) == 0)
398+
if( _is_altcharset( glyph))
398399
ch = acs_map[ch & 0x7f];
399400

400401
/* Get the address of the font data */

fb/pdcdisp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ static const uint8_t *_get_glyph( const chtype ch, const int cursor_type,
257257
root = 0;
258258
#endif
259259

260-
if( (ch & A_ALTCHARSET) && c < 0x80)
260+
if( _is_altcharset( ch))
261261
c = (int)acs_map[c & 0x7f];
262262
else if( c < (int)' ' || (c >= 0x80 && c <= 0x9f))
263263
c = ' ';

os2/pdcdisp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void _new_packet(attr_t attr, int lineno, int x, int len, const chtype *srcp)
5656
{
5757
chtype ch = srcp[j];
5858

59-
if (ch & A_ALTCHARSET && !(ch & 0xff80))
59+
if( _is_altcharset( ch))
6060
ch = acs_map[ch & 0x7f];
6161

6262
if (blink && blinked_off)

plan9/pdcutil.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ void p9putc(int y, int x, chtype ch)
304304
fg = bg;
305305
bg = t;
306306
}
307-
if (attr & A_ALTCHARSET && !(ch & 0xff80))
307+
if( _is_altcharset( ch))
308308
ch = acs_map[ch & 0x7f];
309309

310310
c = ch & A_CHARTEXT;

sdl1/pdcdisp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,10 @@ void PDC_gotoyx(int row, int col)
257257
#ifdef PDC_WIDE
258258
SDL_FillRect(pdc_screen, &dest, get_pdc_mapped( backgr));
259259

260-
if (!(SP->visibility == 2 && (ch & A_ALTCHARSET && !(ch & 0xff80)) &&
260+
if (!(SP->visibility == 2 && _is_altcharset( ch) &&
261261
_grprint(ch & (0x7f | A_ALTCHARSET), dest)))
262262
{
263-
if (ch & A_ALTCHARSET && !(ch & 0xff80))
263+
if( _is_altcharset( ch))
264264
ch = acs_map[ch & 0x7f];
265265

266266
chstr[0] = ch & A_CHARTEXT;
@@ -295,7 +295,7 @@ void PDC_gotoyx(int row, int col)
295295
}
296296
}
297297
#else
298-
if (ch & A_ALTCHARSET && !(ch & 0xff80))
298+
if( _is_altcharset( ch))
299299
ch = acs_map[ch & 0x7f];
300300

301301
src.x = (ch & 0xff) % 32 * pdc_fwidth;
@@ -378,7 +378,7 @@ void _new_packet(attr_t attr, int lineno, int x, int len, const chtype *srcp)
378378

379379
dest.w = pdc_fwidth;
380380

381-
if (ch & A_ALTCHARSET && !(ch & 0xff80))
381+
if( _is_altcharset( ch))
382382
{
383383
#ifdef PDC_WIDE
384384
if (_grprint(ch & (0x7f | A_ALTCHARSET), dest))

sdl2/pdcdisp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,10 @@ void PDC_gotoyx(int row, int col)
287287
#ifdef PDC_WIDE
288288
SDL_FillRect(pdc_screen, &dest, get_pdc_mapped( backgr));
289289

290-
if (!(SP->visibility == 2 && (ch & A_ALTCHARSET && !(ch & 0xff80)) &&
290+
if (!(SP->visibility == 2 && _is_altcharset( ch) &&
291291
_grprint(ch & (0x7f | A_ALTCHARSET), dest)))
292292
{
293-
if (ch & A_ALTCHARSET && !(ch & 0xff80))
293+
if( _is_altcharset( ch))
294294
ch = acs_map[ch & 0x7f];
295295

296296
chstr[0] = ch & A_CHARTEXT;
@@ -325,7 +325,7 @@ void PDC_gotoyx(int row, int col)
325325
}
326326
}
327327
#else
328-
if (ch & A_ALTCHARSET && !(ch & 0xff80))
328+
if( _is_altcharset( ch))
329329
ch = acs_map[ch & 0x7f];
330330

331331
src.x = (ch & 0xff) % 32 * pdc_fwidth;
@@ -408,7 +408,7 @@ void _new_packet(attr_t attr, int lineno, int x, int len, const chtype *srcp)
408408

409409
dest.w = pdc_fwidth;
410410

411-
if (ch & A_ALTCHARSET && !(ch & 0xff80))
411+
if( _is_altcharset( ch))
412412
{
413413
#ifdef PDC_WIDE
414414
if (_grprint(ch & (0x7f | A_ALTCHARSET), dest))

vt/pdcdisp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp)
232232
chtype changes = *srcp ^ prev_ch;
233233
size_t bytes_out = 0;
234234

235-
if( (*srcp & A_ALTCHARSET) && ch < 0x80)
235+
if( _is_altcharset( *srcp))
236236
ch = (int)acs_map[ch & 0x7f];
237237
if( ch < (int)' ' || (ch >= 0x80 && ch <= 0x9f))
238238
ch = ' ';
@@ -291,7 +291,7 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp)
291291
while( count < len && !((srcp[0] ^ srcp[count]) & ~A_CHARTEXT)
292292
&& (ch = (srcp[count] & A_CHARTEXT)) < (int)MAX_UNICODE)
293293
{
294-
if( (srcp[count] & A_ALTCHARSET) && ch < 0x80)
294+
if( _is_altcharset( srcp[count]))
295295
ch = (int)acs_map[ch & 0x7f];
296296
if( ch < (int)' ' || (ch >= 0x80 && ch <= 0x9f))
297297
ch = ' ';

wincon/pdcdisp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static void _show_run_of_ansi_characters( const attr_t attr,
162162
{
163163
chtype ch = srcp[j];
164164

165-
if (ch & A_ALTCHARSET && !(ch & 0xff80))
165+
if( _is_altcharset( ch))
166166
ch = acs_map[ch & 0x7f];
167167

168168
if (blink && blinked_off)
@@ -214,7 +214,7 @@ static void _show_run_of_nonansi_characters( const attr_t attr,
214214
{
215215
chtype ch = srcp[j];
216216

217-
if (ch & A_ALTCHARSET && !(ch & 0xff80))
217+
if( _is_altcharset( ch))
218218
ch = acs_map[ch & 0x7f];
219219

220220
if (blink && blinked_off)

0 commit comments

Comments
 (0)