Skip to content

Commit

Permalink
WinCon : OpenWATCOM (and probably some other compilers) require varia…
Browse files Browse the repository at this point in the history
…bles to be declared at the start of a block.
  • Loading branch information
Bill-Gray committed May 10, 2023
1 parent fcd894e commit 89e3426
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions wincon/pdcdisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ static void _set_ansi_color(short f, short b, attr_t attr)
{
char esc[64], *p;
short tmp, underline;
bool italic;
bool italic, set_transparent_bg;
int initial_len;

if (f < 16 && !pdc_color[f].mapped)
f = pdc_curstoansi[f];
Expand All @@ -57,13 +58,13 @@ static void _set_ansi_color(short f, short b, attr_t attr)

p = esc + sprintf(esc, "\x1b[");

bool set_transparent_bg = (b == 0 && b != pdc_oldb);
set_transparent_bg = (b == 0 && b != pdc_oldb);
if (set_transparent_bg)
{
p += sprintf(p, "m\x1b[");
pdc_oldb = b;
}
int initial_len = strlen(esc);
}
initial_len = strlen(esc);

if (f != pdc_oldf || set_transparent_bg)
{
Expand All @@ -87,7 +88,7 @@ static void _set_ansi_color(short f, short b, attr_t attr)

if (b != pdc_oldb)
{
if (strlen(esc) > initial_len)
if (strlen(esc) > (size_t)initial_len)
p += sprintf(p, ";");

if (b < 8 && !pdc_color[b].mapped)
Expand All @@ -110,7 +111,7 @@ static void _set_ansi_color(short f, short b, attr_t attr)

if (italic != in_italic || set_transparent_bg)
{
if (strlen(esc) > initial_len )
if (strlen(esc) > (size_t)initial_len )
p += sprintf(p, ";");

if (italic)
Expand All @@ -123,7 +124,7 @@ static void _set_ansi_color(short f, short b, attr_t attr)

if (underline != pdc_oldu || set_transparent_bg)
{
if (strlen(esc) > initial_len )
if (strlen(esc) > (size_t)initial_len )
p += sprintf(p, ";");

if (underline)
Expand Down Expand Up @@ -177,13 +178,13 @@ static void _show_run_of_ansi_characters( const attr_t attr,
ch = ' ';

#ifdef PDC_WIDE
chtype uc = ch & A_CHARTEXT; //o//
if( uc < 0x110000){
if (uc & 0x1F0000){
buffer[n_out++] = (WCHAR)((uc - 0x10000) >> 10 | 0xD800); /* first UTF-16 unit */
buffer[n_out++] = (WCHAR)(uc & 0x3FF) | 0xDC00; /* second UTF-16 unit */
}else
buffer[n_out++] = (WCHAR)uc;
ch &= A_CHARTEXT;
if( ch < 0x110000){
if (ch & 0x1F0000){
buffer[n_out++] = (WCHAR)((ch - 0x10000) >> 10 | 0xD800); /* first UTF-16 unit */
buffer[n_out++] = (WCHAR)(ch & 0x3FF) | 0xDC00; /* second UTF-16 unit */
}else
buffer[n_out++] = (WCHAR)ch;
}
#else
buffer[n_out++] = (char)( ch & A_CHARTEXT);
Expand Down Expand Up @@ -236,14 +237,14 @@ static void _show_run_of_nonansi_characters( attr_t attr,

buffer[n_out].Attributes = mapped_attr;
#ifdef PDC_WIDE
chtype uc = ch & A_CHARTEXT; //o//
if( uc < 0x110000){
if (uc & 0x1F0000){
buffer[n_out++].Char.UnicodeChar = (WCHAR)((uc - 0x10000) >> 10 | 0xD800); /* first UTF-16 unit */
ch &= A_CHARTEXT;
if( ch < 0x110000){
if (ch & 0x1F0000){
buffer[n_out++].Char.UnicodeChar = (WCHAR)((ch - 0x10000) >> 10 | 0xD800); /* first UTF-16 unit */
buffer[n_out].Attributes = mapped_attr;
buffer[n_out++].Char.UnicodeChar = (WCHAR)(uc & 0x3FF) | 0xDC00; /* second UTF-16 unit */
}else
buffer[n_out++].Char.UnicodeChar = (WCHAR)uc;
buffer[n_out++].Char.UnicodeChar = (WCHAR)(ch & 0x3FF) | 0xDC00; /* second UTF-16 unit */
}else
buffer[n_out++].Char.UnicodeChar = (WCHAR)ch;
}
#else
buffer[n_out++].Char.UnicodeChar = (WCHAR)( ch & A_CHARTEXT);
Expand Down

3 comments on commit 89e3426

@GitMensch
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually a C89 issue. Same would happen with VS2008 and earlier, as well as a bunch of other compilers (partially only with c89 mode set / no newer mode set).

@Bill-Gray
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely caught. Apparently, this wasn't allowed in C90, either. Compiling some code with gcc using the options -std=c90 -Wpedantic -Werror, I got

mjd.c:33:4: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

(Same if I made that -std=c89.) I now recall we ran into this issue some time ago with some code on the PDCurses side.

Ideally, I'd modify the commit message. It's not the first time I've been annoyed by the fact that there is no good, or even passable, way of modifying a commit message once it's been pushed to the server (easy to do before then, of course).

@GitMensch
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, I'd modify the commit message. It's not the first time I've been annoyed by the fact that there is no good, or even passable, way of modifying a commit message once it's been pushed to the server (easy to do before then, of course).

:-) yes, I regularly find me adjusting svn commit messages in "my" project (sometimes mine, but mostly the one from others when they have "useful" log messages like "fix"); that works in svn because the message is a property (just as the date, which is sometimes useful to adjust, too) and when you set the repo to allow those changes for some users (actually that should be quite limited) ...

What about changing at least on of the CI workers (the fastest one, so likely a GH action) to use -std=c89 -Wpedantic -Werror where we don't explicit request a newer version in the port's README?

Please sign in to comment.