1
0
mirror of https://git.zap.org.au/git/trader.git synced 2025-02-02 15:08:13 -05:00

Minor clean-up: replace character constants with wide-char versions

Wide-char character constants is not strictly needed for most (all?)
modern C compilers, as ASCII maps to wchar_t directly (as long as
__STDC_ISO_10646__ is defined).  However, it doesn't hurt to be pedantic!
This commit is contained in:
John Zaitseff 2011-08-25 21:34:41 +10:00
parent 61411e3416
commit 1c2518a78b
9 changed files with 249 additions and 244 deletions

View File

@ -208,7 +208,7 @@ void exchange_stock (void)
key = towlower(key); key = towlower(key);
} }
for (i = 0, found = false; keycode_company[i] != '\0'; i++) { for (i = 0, found = false; keycode_company[i] != L'\0'; i++) {
if (keycode_company[i] == key) { if (keycode_company[i] == key) {
found = true; found = true;
if (company[i].on_map) { if (company[i].on_map) {
@ -222,24 +222,24 @@ void exchange_stock (void)
if (! found) { if (! found) {
switch (key) { switch (key) {
case '1': case L'1':
curs_set(CURS_OFF); curs_set(CURS_OFF);
show_status(current_player); show_status(current_player);
curs_set(CURS_ON); curs_set(CURS_ON);
break; break;
case '2': case L'2':
curs_set(CURS_OFF); curs_set(CURS_OFF);
show_map(true); show_map(true);
curs_set(CURS_ON); curs_set(CURS_ON);
break; break;
case '3': case L'3':
selection = SEL_BANK; selection = SEL_BANK;
break; break;
case '4': case L'4':
case ' ': case L' ':
selection = SEL_EXIT; selection = SEL_EXIT;
break; break;
@ -379,9 +379,9 @@ void visit_bank (void)
if (gettxchar(curwin, &key) == OK) { if (gettxchar(curwin, &key) == OK) {
// Ordinary wide character // Ordinary wide character
switch (key) { switch (key) {
case '1': case L'1':
case '2': case L'2':
case '3': case L'3':
left(curwin, getcury(curwin), getcurx(curwin), A_BOLD, left(curwin, getcury(curwin), getcurx(curwin), A_BOLD,
0, 0, 1, "%lc", key); 0, 0, 1, "%lc", key);
wrefresh(curwin); wrefresh(curwin);
@ -389,7 +389,7 @@ void visit_bank (void)
done = true; done = true;
break; break;
case ' ': case L' ':
done = true; done = true;
break; break;
@ -417,7 +417,7 @@ void visit_bank (void)
curs_set(CURS_OFF); curs_set(CURS_OFF);
switch (key) { switch (key) {
case '1': case L'1':
// Borrow money from the Bank // Borrow money from the Bank
if (credit_limit == 0.0) { if (credit_limit == 0.0) {
txdlgbox(MAX_DLG_LINES, 50, 8, WCENTER, attr_error_window, txdlgbox(MAX_DLG_LINES, 50, 8, WCENTER, attr_error_window,
@ -470,7 +470,7 @@ void visit_bank (void)
} }
break; break;
case '2': case L'2':
// Repay a debt // Repay a debt
if (player[current_player].debt == 0.0) { if (player[current_player].debt == 0.0) {
txdlgbox(MAX_DLG_LINES, 50, 8, WCENTER, attr_error_window, txdlgbox(MAX_DLG_LINES, 50, 8, WCENTER, attr_error_window,
@ -664,10 +664,10 @@ void trade_shares (int num, bool *bid_used)
if (gettxchar(curwin, &key) == OK) { if (gettxchar(curwin, &key) == OK) {
// Ordinary wide character // Ordinary wide character
switch (key) { switch (key) {
case '1': case L'1':
case '2': case L'2':
case '3': case L'3':
case '4': case L'4':
left(curwin, getcury(curwin), getcurx(curwin), A_BOLD, left(curwin, getcury(curwin), getcurx(curwin), A_BOLD,
0, 0, 1, "%lc", key); 0, 0, 1, "%lc", key);
wrefresh(curwin); wrefresh(curwin);
@ -675,7 +675,7 @@ void trade_shares (int num, bool *bid_used)
done = true; done = true;
break; break;
case ' ': case L' ':
done = true; done = true;
break; break;
@ -703,7 +703,7 @@ void trade_shares (int num, bool *bid_used)
curs_set(CURS_OFF); curs_set(CURS_OFF);
switch (key) { switch (key) {
case '1': case L'1':
// Buy stock in company // Buy stock in company
maxshares = player[current_player].cash / company[num].share_price; maxshares = player[current_player].cash / company[num].share_price;
@ -748,7 +748,7 @@ void trade_shares (int num, bool *bid_used)
} }
break; break;
case '2': case L'2':
// Sell stock back to company // Sell stock back to company
maxshares = player[current_player].stock_owned[num]; maxshares = player[current_player].stock_owned[num];
if (maxshares == 0) { if (maxshares == 0) {
@ -783,7 +783,7 @@ void trade_shares (int num, bool *bid_used)
} }
break; break;
case '3': case L'3':
// Bid company to issue more shares // Bid company to issue more shares
maxshares = 0; maxshares = 0;
if (! *bid_used && randf() < ownership && randf() < BID_CHANCE) { if (! *bid_used && randf() < ownership && randf() < BID_CHANCE) {

View File

@ -281,12 +281,12 @@ static int ask_number_players (void)
if (gettxchar(curwin, &key) == OK) { if (gettxchar(curwin, &key) == OK) {
// Ordinary wide character // Ordinary wide character
if (key >= '1' && key <= MAX_PLAYERS + '0') { if (key >= L'1' && key <= MAX_PLAYERS + L'0') {
left(curwin, getcury(curwin), getcurx(curwin), A_BOLD, left(curwin, getcury(curwin), getcurx(curwin), A_BOLD,
0, 0, 1, "%lc", key); 0, 0, 1, "%lc", key);
wrefresh(curwin); wrefresh(curwin);
ret = key - '0'; ret = key - L'0';
done = true; done = true;
} else if (wcschr(keycode_contgame, key) != NULL) { } else if (wcschr(keycode_contgame, key) != NULL) {
left(curwin, getcury(curwin), getcurx(curwin), A_BOLD, left(curwin, getcury(curwin), getcurx(curwin), A_BOLD,
@ -356,12 +356,12 @@ int ask_game_number (void)
if (gettxchar(curwin, &key) == OK) { if (gettxchar(curwin, &key) == OK) {
// Ordinary wide character // Ordinary wide character
if (key >= '1' && key <= '9') { if (key >= L'1' && key <= L'9') {
left(curwin, getcury(curwin), getcurx(curwin), A_BOLD, left(curwin, getcury(curwin), getcurx(curwin), A_BOLD,
0, 0, 1, "%lc", key); 0, 0, 1, "%lc", key);
wrefresh(curwin); wrefresh(curwin);
ret = key - '0'; ret = key - L'0';
done = true; done = true;
} else { } else {
beep(); beep();
@ -574,8 +574,7 @@ void end_game (void)
attr_title, attr_normal, attr_highlight, 0, attr_waitforkey, attr_title, attr_normal, attr_highlight, 0, attr_waitforkey,
_(" Total Value "), _(" Total Value "),
/* xgettext:c-format */ /* xgettext:c-format */
_("Your total value was ^{%N^}."), _("Your total value was ^{%N^}."), total_value(0));
total_value(0));
} else { } else {
// Sort players on the basis of total value // Sort players on the basis of total value
for (int i = 0; i < number_players; i++) { for (int i = 0; i < number_players; i++) {
@ -655,7 +654,7 @@ void show_map (bool closewin)
for (int x = 0; x < MAX_X; x++) { for (int x = 0; x < MAX_X; x++) {
chtype *mapstr = CHTYPE_MAP_VAL(galaxy_map[x][y]); chtype *mapstr = CHTYPE_MAP_VAL(galaxy_map[x][y]);
while (*mapstr != '\0') { while (*mapstr != 0) {
waddch(curwin, *mapstr++); waddch(curwin, *mapstr++);
} }
} }

View File

@ -61,7 +61,7 @@ static const char *help_text[HELP_TEXT_PAGES] = {
^^ - Print the circumflex accent (ASCII code U+005E) ^^ - Print the circumflex accent (ASCII code U+005E)
^N - Switch to using the normal character rendition ^N - Switch to using the normal character rendition
^B - Switch to using the bold character rendition ^B - Switch to using the bold character rendition
^B - Switch to using the highlight character rendition ^H - Switch to using the highlight character rendition
^K - Switch to using the keycode character rendition (such as used for "<CTRL><C>") ^K - Switch to using the keycode character rendition (such as used for "<CTRL><C>")
^e - Switch to using the character rendition used for empty space ^e - Switch to using the character rendition used for empty space
^o - Switch to using the character rendition used for outposts ^o - Switch to using the character rendition used for outposts
@ -288,149 +288,150 @@ void show_help (void)
memset(&mbstate, 0, sizeof(mbstate)); memset(&mbstate, 0, sizeof(mbstate));
outp = outbuf; outp = outbuf;
while (*htxt != '\0' && count > maxchar * 2) { while (*htxt != L'\0' && count > maxchar * 2) {
switch (*htxt) { switch (*htxt) {
case '\n': case L'\n':
// Start a new line // Start a new line
*outp++ = '\n'; *outp++ = '\n';
count--; count--;
break; break;
case '^': case L'^':
// Switch to a different character rendition // Switch to a different character rendition
switch (*++htxt) { switch (*++htxt) {
case '^': case L'^':
wcbuf[0] = *htxt; wcbuf[0] = *htxt;
wcbuf[1] = '\0'; wcbuf[1] = L'\0';
goto addwcbuf; goto addwcbuf;
case 'N': case L'N':
curattr = attr_normal; curattr = attr_normal;
break; break;
case 'B': case L'B':
curattr = attr_normal | A_BOLD; curattr = attr_normal | A_BOLD;
break; break;
case 'H': case L'H':
curattr = attr_highlight; curattr = attr_highlight;
break; break;
case 'K': case L'K':
curattr = attr_keycode; curattr = attr_keycode;
break; break;
case 'e': case L'e':
curattr = attr_map_empty; curattr = attr_map_empty;
break; break;
case 'o': case L'o':
curattr = attr_map_outpost; curattr = attr_map_outpost;
break; break;
case 's': case L's':
curattr = attr_map_star; curattr = attr_map_star;
break; break;
case 'c': case L'c':
curattr = attr_map_company; curattr = attr_map_company;
break; break;
case 'k': case L'k':
curattr = attr_map_choice; curattr = attr_map_choice;
break; break;
default: default:
wcbuf[0] = '^'; wcbuf[0] = L'^';
wcbuf[1] = *htxt; wcbuf[1] = *htxt;
wcbuf[2] = '\0'; wcbuf[2] = L'\0';
goto addwcbuf; goto addwcbuf;
} }
break; break;
case '~': case L'~':
// Print a global constant // Print a global constant
switch (*++htxt) { switch (*++htxt) {
case '~': case L'~':
wcbuf[0] = *htxt; wcbuf[0] = *htxt;
wcbuf[1] = '\0'; wcbuf[1] = L'\0';
goto addwcbuf; goto addwcbuf;
case 'x': case L'x':
swprintf(wcbuf, BIGBUFSIZE, L"%2d", MAX_X); swprintf(wcbuf, BIGBUFSIZE, L"%2d", MAX_X);
goto addwcbuf; goto addwcbuf;
case 'y': case L'y':
swprintf(wcbuf, BIGBUFSIZE, L"%2d", MAX_Y); swprintf(wcbuf, BIGBUFSIZE, L"%2d", MAX_Y);
goto addwcbuf; goto addwcbuf;
case 'm': case L'm':
swprintf(wcbuf, BIGBUFSIZE, L"%2d", NUMBER_MOVES); swprintf(wcbuf, BIGBUFSIZE, L"%2d", NUMBER_MOVES);
goto addwcbuf; goto addwcbuf;
case 'c': case L'c':
swprintf(wcbuf, BIGBUFSIZE, L"%d", MAX_COMPANIES); swprintf(wcbuf, BIGBUFSIZE, L"%d", MAX_COMPANIES);
goto addwcbuf; goto addwcbuf;
case 't': case L't':
swprintf(wcbuf, BIGBUFSIZE, L"%2d", DEFAULT_MAX_TURN); swprintf(wcbuf, BIGBUFSIZE, L"%2d", DEFAULT_MAX_TURN);
goto addwcbuf; goto addwcbuf;
case '1': case L'1':
case '2': case L'2':
case '3': case L'3':
case '4': case L'4':
case '5': case L'5':
case '6': case L'6':
case '7': case L'7':
case '8': case L'8':
case '9': case L'9':
// N-th choice of move, as a key press // N-th choice of move, as a key press
wcbuf[0] = PRINTABLE_GAME_MOVE(*htxt - L'1'); wcbuf[0] = PRINTABLE_GAME_MOVE(*htxt - L'1');
wcbuf[1] = '\0'; wcbuf[1] = L'\0';
goto addwcbuf; goto addwcbuf;
case 'M': case L'M':
// Last choice of move, as a key press // Last choice of move, as a key press
wcbuf[0] = PRINTABLE_GAME_MOVE(NUMBER_MOVES - 1); wcbuf[0] = PRINTABLE_GAME_MOVE(NUMBER_MOVES - 1);
wcbuf[1] = '\0'; wcbuf[1] = L'\0';
goto addwcbuf; goto addwcbuf;
case '.': case L'.':
// Map representation of empty space // Map representation of empty space
wcbuf[0] = PRINTABLE_MAP_VAL(MAP_EMPTY); wcbuf[0] = PRINTABLE_MAP_VAL(MAP_EMPTY);
wcbuf[1] = '\0'; wcbuf[1] = L'\0';
goto addwcbuf; goto addwcbuf;
case '+': case L'+':
// Map representation of an outpost // Map representation of an outpost
wcbuf[0] = PRINTABLE_MAP_VAL(MAP_OUTPOST); wcbuf[0] = PRINTABLE_MAP_VAL(MAP_OUTPOST);
wcbuf[1] = '\0'; wcbuf[1] = L'\0';
goto addwcbuf; goto addwcbuf;
case '*': case L'*':
// Map representation of a star // Map representation of a star
wcbuf[0] = PRINTABLE_MAP_VAL(MAP_STAR); wcbuf[0] = PRINTABLE_MAP_VAL(MAP_STAR);
wcbuf[1] = '\0'; wcbuf[1] = L'\0';
goto addwcbuf; goto addwcbuf;
case 'A': case L'A':
case 'B': case L'B':
case 'C': case L'C':
case 'D': case L'D':
case 'E': case L'E':
case 'F': case L'F':
case 'G': case L'G':
case 'H': case L'H':
// Map representation of company // Map representation of company
assert((*htxt - L'A') < MAX_COMPANIES); assert((*htxt - L'A') < MAX_COMPANIES);
wcbuf[0] = PRINTABLE_MAP_VAL(COMPANY_TO_MAP(*htxt - L'A')); wcbuf[0] = PRINTABLE_MAP_VAL(COMPANY_TO_MAP(*htxt - L'A'));
wcbuf[1] = '\0'; wcbuf[1] = L'\0';
goto addwcbuf; goto addwcbuf;
default: default:
wcbuf[0] = '~'; wcbuf[0] = L'~';
wcbuf[1] = *htxt; wcbuf[1] = *htxt;
wcbuf[2] = L'\0';
goto addwcbuf; goto addwcbuf;
} }
break; break;
@ -438,10 +439,10 @@ void show_help (void)
default: default:
// Print the character // Print the character
wcbuf[0] = *htxt; wcbuf[0] = *htxt;
wcbuf[1] = '\0'; wcbuf[1] = L'\0';
addwcbuf: addwcbuf:
for (wchar_t *p = wcbuf; *p != '\0' && count > maxchar * 2; p++) { for (wchar_t *p = wcbuf; *p != L'\0' && count > maxchar * 2; p++) {
n = xwcrtomb(convbuf, *p, &mbstate); n = xwcrtomb(convbuf, *p, &mbstate);
for (i = 0, cp = convbuf; i < n; i++, cp++, outp++, count--) { for (i = 0, cp = convbuf; i < n; i++, cp++, outp++, count--) {
*outp = (unsigned char) *cp | curattr; *outp = (unsigned char) *cp | curattr;
@ -453,14 +454,14 @@ void show_help (void)
} }
// Add the terminating NUL (possibly with a preceding shift sequence) // Add the terminating NUL (possibly with a preceding shift sequence)
n = xwcrtomb(convbuf, '\0', &mbstate); n = xwcrtomb(convbuf, L'\0', &mbstate);
for (i = 0, cp = convbuf; i < n; i++, cp++, outp++, count--) { for (i = 0, cp = convbuf; i < n; i++, cp++, outp++, count--) {
*outp = (unsigned char) *cp; *outp = (unsigned char) *cp;
} }
assert(count >= 0); assert(count >= 0);
// Display the formatted text in outbuf // Display the formatted text in outbuf
for (outp = outbuf; *outp != '\0'; outp++) { for (outp = outbuf; *outp != 0; outp++) {
if (*outp == '\n') { if (*outp == '\n') {
wmove(curwin, getcury(curwin) + 1, 2); wmove(curwin, getcury(curwin) + 1, 2);
} else { } else {

View File

@ -111,7 +111,7 @@ typedef struct txwin {
__stringify(_var), s); \ __stringify(_var), s); \
} \ } \
(_var) = xwcsdup(buf); \ (_var) = xwcsdup(buf); \
(_var)[_checkpos] = '\0'; \ (_var)[_checkpos] = L'\0'; \
} while (0) } while (0)
#define init_game_chstr(_chvar, _var, _attr, _err) \ #define init_game_chstr(_chvar, _var, _attr, _err) \
@ -134,13 +134,13 @@ typedef struct txwin {
} \ } \
\ \
if (w == 1) { \ if (w == 1) { \
n = xwcrtomb(convbuf, ' ', &mbstate); \ n = xwcrtomb(convbuf, L' ', &mbstate); \
for (int i = 0; i < n; i++) { \ for (int i = 0; i < n; i++) { \
*p++ = (unsigned char) convbuf[i] | attr_map_empty; \ *p++ = (unsigned char) convbuf[i] | attr_map_empty; \
} \ } \
} \ } \
\ \
n = xwcrtomb(convbuf, '\0', &mbstate); \ n = xwcrtomb(convbuf, L'\0', &mbstate); \
for (int i = 0; i < n; i++) { \ for (int i = 0; i < n; i++) { \
*p++ = (unsigned char) convbuf[i]; \ *p++ = (unsigned char) convbuf[i]; \
} \ } \
@ -326,7 +326,7 @@ static int getwch (WINDOW *win, wint_t *wch);
/* /*
Function: cpos_endl - Adjust cpos and st for printing the ending part of buf Function: cpos_end - Adjust cpos and st for printing the ending part of buf
Parameters: buf - Pointer to current editing buffer Parameters: buf - Pointer to current editing buffer
cpos - Pointer to current cursor position (result) cpos - Pointer to current cursor position (result)
st - Pointer to current starting offset for buf[] (result) st - Pointer to current starting offset for buf[] (result)
@ -338,12 +338,12 @@ static int getwch (WINDOW *win, wint_t *wch);
This helper function adjusts *cpos and *st so that the cursor is placed This helper function adjusts *cpos and *st so that the cursor is placed
at the end of the current editing buffer buf[]. at the end of the current editing buffer buf[].
*/ */
static void cpos_endl (wchar_t *restrict buf, int *restrict cpos, static void cpos_end (const wchar_t *restrict buf, int *restrict cpos,
int *restrict st, int clen, int width, int len); int *restrict st, int clen, int width, int len);
/* /*
Function: cpos_decr - Adjust cpos and st: scroll to the left by w columns Function: cpos_dec - Adjust cpos and st: scroll to the left by w columns
Parameters: buf - Pointer to current editing buffer Parameters: buf - Pointer to current editing buffer
cpos - Pointer to current cursor position (result) cpos - Pointer to current cursor position (result)
st - Pointer to current starting offset for buf[] (result) st - Pointer to current starting offset for buf[] (result)
@ -354,12 +354,12 @@ static void cpos_endl (wchar_t *restrict buf, int *restrict cpos,
This helper function adjusts *cpos and *st so that the cursor is moved This helper function adjusts *cpos and *st so that the cursor is moved
to the left by w column positions. to the left by w column positions.
*/ */
static void cpos_decr (wchar_t *restrict buf, int *restrict cpos, static void cpos_dec (const wchar_t *restrict buf, int *restrict cpos,
int *restrict st, int w, int width); int *restrict st, int w, int width);
/* /*
Function: cpos_incr - Adjust cpos and st: scroll to the right by w columns Function: cpos_inc - Adjust cpos and st: scroll to the right by w columns
Parameters: buf - Pointer to current editing buffer Parameters: buf - Pointer to current editing buffer
cpos - Pointer to current cursor position (result) cpos - Pointer to current cursor position (result)
st - Pointer to current starting offset for buf[] (result) st - Pointer to current starting offset for buf[] (result)
@ -370,7 +370,7 @@ static void cpos_decr (wchar_t *restrict buf, int *restrict cpos,
This helper function adjusts *cpos and *st so that the cursor is moved This helper function adjusts *cpos and *st so that the cursor is moved
to the right by w column positions. to the right by w column positions.
*/ */
static void cpos_incr (wchar_t *restrict buf, int *restrict cpos, static void cpos_inc (const wchar_t *restrict buf, int *restrict cpos,
int *restrict st, int w, int width); int *restrict st, int w, int width);
@ -389,7 +389,7 @@ static void cpos_incr (wchar_t *restrict buf, int *restrict cpos,
This function is used by gettxdouble() and gettxlong() to share some This function is used by gettxdouble() and gettxlong() to share some
common code. common code.
*/ */
static void txinput_fixup (wchar_t *restrict dest, wchar_t *restrict src, static void txinput_fixup (wchar_t *restrict dest, const wchar_t *restrict src,
bool isfloat); bool isfloat);
@ -864,11 +864,11 @@ int mkchstr_parse (const wchar_t *restrict format,
memset(format_arg, 0, MAXFMTARGS * sizeof(format_arg[0])); memset(format_arg, 0, MAXFMTARGS * sizeof(format_arg[0]));
memset(format_spec, 0, MAXFMTSPECS * sizeof(format_spec[0])); memset(format_spec, 0, MAXFMTSPECS * sizeof(format_spec[0]));
while (*format != '\0') { while (*format != L'\0') {
switch (*format++) { switch (*format++) {
case '^': case L'^':
// Switch to a different character rendition // Switch to a different character rendition
if (*format == '\0') { if (*format == L'\0') {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} else { } else {
@ -877,13 +877,13 @@ int mkchstr_parse (const wchar_t *restrict format,
} }
break; break;
case '%': case L'%':
// Process a conversion specifier // Process a conversion specifier
if (*format == '\0') { if (*format == L'\0') {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} else if (*format == '%') { } else if (*format == L'%') {
// Ignore "%%" specifier // Ignore "%%" specifier for now
format++; format++;
} else { } else {
const wchar_t *start = format; const wchar_t *start = format;
@ -893,10 +893,10 @@ int mkchstr_parse (const wchar_t *restrict format,
bool flag_other = false; // Have we seen something else? bool flag_other = false; // Have we seen something else?
int count = 0; int count = 0;
while (inspec && *format != '\0') { while (inspec && *format != L'\0') {
wchar_t wc = *format++; wchar_t c = *format++;
switch (wc) { switch (c) {
case '0': case L'0':
// Zero flag, or part of numeric count // Zero flag, or part of numeric count
if (count == 0) { if (count == 0) {
// Zero flag is NOT supported // Zero flag is NOT supported
@ -907,20 +907,20 @@ int mkchstr_parse (const wchar_t *restrict format,
count *= 10; count *= 10;
break; break;
case '1': case L'1':
case '2': case L'2':
case '3': case L'3':
case '4': case L'4':
case '5': case L'5':
case '6': case L'6':
case '7': case L'7':
case '8': case L'8':
case '9': case L'9':
// Part of some numeric count // Part of some numeric count
count = count * 10 + (wc - L'0'); count = count * 10 + (c - L'0');
break; break;
case '$': case L'$':
// Fixed-position argument // Fixed-position argument
if (flag_posn || flag_other || count == 0) { if (flag_posn || flag_other || count == 0) {
errno = EINVAL; errno = EINVAL;
@ -937,7 +937,7 @@ int mkchstr_parse (const wchar_t *restrict format,
count = 0; count = 0;
break; break;
case '\'': case L'\'':
// Use locale-specific thousands group separator // Use locale-specific thousands group separator
if (format_spec->flag_group) { if (format_spec->flag_group) {
errno = EINVAL; errno = EINVAL;
@ -948,7 +948,7 @@ int mkchstr_parse (const wchar_t *restrict format,
flag_other = true; flag_other = true;
break; break;
case '!': case L'!':
// Omit the locale-specific currency symbol // Omit the locale-specific currency symbol
if (format_spec->flag_nosym) { if (format_spec->flag_nosym) {
errno = EINVAL; errno = EINVAL;
@ -959,7 +959,7 @@ int mkchstr_parse (const wchar_t *restrict format,
flag_other = true; flag_other = true;
break; break;
case '.': case L'.':
// Precision flag // Precision flag
if (format_spec->flag_prec || count != 0) { if (format_spec->flag_prec || count != 0) {
errno = EINVAL; errno = EINVAL;
@ -970,7 +970,7 @@ int mkchstr_parse (const wchar_t *restrict format,
flag_other = true; flag_other = true;
break; break;
case 'l': case L'l':
// Long length modifier // Long length modifier
if (format_spec->flag_long) { if (format_spec->flag_long) {
// "ll" is NOT supported // "ll" is NOT supported
@ -982,7 +982,7 @@ int mkchstr_parse (const wchar_t *restrict format,
flag_other = true; flag_other = true;
break; break;
case 'c': case L'c':
// Insert a character (char or wchar_t) // Insert a character (char or wchar_t)
if (format_spec->flag_group || format_spec->flag_nosym if (format_spec->flag_group || format_spec->flag_nosym
|| format_spec->flag_prec || count != 0) { || format_spec->flag_prec || count != 0) {
@ -994,7 +994,7 @@ int mkchstr_parse (const wchar_t *restrict format,
TYPE_WCHAR : TYPE_CHAR; TYPE_WCHAR : TYPE_CHAR;
goto handlefmt; goto handlefmt;
case 'd': case L'd':
// Insert an integer (int or long int) // Insert an integer (int or long int)
if (format_spec->flag_nosym || format_spec->flag_prec if (format_spec->flag_nosym || format_spec->flag_prec
|| count != 0) { || count != 0) {
@ -1006,7 +1006,7 @@ int mkchstr_parse (const wchar_t *restrict format,
TYPE_LONGINT : TYPE_INT; TYPE_LONGINT : TYPE_INT;
goto handlefmt; goto handlefmt;
case 'f': case L'f':
// Insert a floating-point number (double) // Insert a floating-point number (double)
if (format_spec->flag_nosym || format_spec->flag_long || if (format_spec->flag_nosym || format_spec->flag_long ||
(! format_spec->flag_prec && count != 0)) { (! format_spec->flag_prec && count != 0)) {
@ -1019,7 +1019,7 @@ int mkchstr_parse (const wchar_t *restrict format,
arg_type = TYPE_DOUBLE; arg_type = TYPE_DOUBLE;
goto handlefmt; goto handlefmt;
case 'N': case L'N':
// Insert a monetary amount (double) // Insert a monetary amount (double)
if (format_spec->flag_group || format_spec->flag_prec if (format_spec->flag_group || format_spec->flag_prec
|| format_spec->flag_long || count != 0) { || format_spec->flag_long || count != 0) {
@ -1030,7 +1030,7 @@ int mkchstr_parse (const wchar_t *restrict format,
arg_type = TYPE_DOUBLE; arg_type = TYPE_DOUBLE;
goto handlefmt; goto handlefmt;
case 's': case L's':
// Insert a string (const char * or const wchar_t *) // Insert a string (const char * or const wchar_t *)
if (format_spec->flag_group || format_spec->flag_nosym if (format_spec->flag_group || format_spec->flag_nosym
|| format_spec->flag_prec || count != 0) { || format_spec->flag_prec || count != 0) {
@ -1056,7 +1056,7 @@ int mkchstr_parse (const wchar_t *restrict format,
format_spec->len = format - start; format_spec->len = format - start;
format_spec->arg_num = arg_num; format_spec->arg_num = arg_num;
format_spec->spec = wc; format_spec->spec = c;
arg_num++; arg_num++;
num_args = MAX(num_args, arg_num); num_args = MAX(num_args, arg_num);
@ -1147,11 +1147,11 @@ int mkchstr_add (wchar_t *restrict *restrict outbuf,
*line = 0; *line = 0;
} }
if (**str == '\n') { if (**str == L'\n') {
// Start a new line // Start a new line
if (*line < maxlines - 1) { if (*line < maxlines - 1) {
*(*outbuf)++ = '\n'; *(*outbuf)++ = L'\n';
*(*attrbuf)++ = 0; *(*attrbuf)++ = 0;
(*count)--; (*count)--;
} }
@ -1180,7 +1180,7 @@ int mkchstr_add (wchar_t *restrict *restrict outbuf,
// Break on the last space in this line // Break on the last space in this line
wspc = wcwidth(**lastspc); wspc = wcwidth(**lastspc);
**lastspc = '\n'; **lastspc = L'\n';
**spcattr = 0; **spcattr = 0;
widthbuf[*line] = *widthspc; widthbuf[*line] = *widthspc;
@ -1194,7 +1194,7 @@ int mkchstr_add (wchar_t *restrict *restrict outbuf,
} else { } else {
// Insert a new-line character (if not on last line) // Insert a new-line character (if not on last line)
if (*line < maxlines - 1) { if (*line < maxlines - 1) {
*(*outbuf)++ = '\n'; *(*outbuf)++ = L'\n';
*(*attrbuf)++ = 0; *(*attrbuf)++ = 0;
(*count)--; (*count)--;
} }
@ -1212,7 +1212,7 @@ int mkchstr_add (wchar_t *restrict *restrict outbuf,
will ever have combining diacritical marks following a will ever have combining diacritical marks following a
(line-breaking) space! */ (line-breaking) space! */
while (iswspace(**str)) { while (iswspace(**str)) {
if (*(*str)++ == '\n') { if (*(*str)++ == L'\n') {
break; break;
} }
} }
@ -1257,7 +1257,7 @@ void mkchstr_conv (chtype *restrict chbuf, int chbufsize,
while (! done) { while (! done) {
// Make sure we always have enough space for ending shift sequence // Make sure we always have enough space for ending shift sequence
memcpy(&mbcopy, &mbstate, sizeof(mbstate)); memcpy(&mbcopy, &mbstate, sizeof(mbstate));
endsize = wcrtomb(endbuf, '\0', &mbcopy); endsize = wcrtomb(endbuf, L'\0', &mbcopy);
if (endsize == (size_t) -1) { if (endsize == (size_t) -1) {
errno_exit(_("mkchstr_conv: NUL")); errno_exit(_("mkchstr_conv: NUL"));
} }
@ -1285,7 +1285,7 @@ void mkchstr_conv (chtype *restrict chbuf, int chbufsize,
break; break;
} }
done = (*wcbuf == '\0'); done = (*wcbuf == L'\0');
wcbuf++; wcbuf++;
attrbuf++; attrbuf++;
} }
@ -1352,15 +1352,15 @@ int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
spcattr = NULL; // Equivalent in attrbuf spcattr = NULL; // Equivalent in attrbuf
widthspc = 0; // Width of line before last space widthspc = 0; // Width of line before last space
while (*wcformat != '\0' && count > 1 && line < maxlines) { while (*wcformat != L'\0' && count > 1 && line < maxlines) {
switch (*wcformat) { switch (*wcformat) {
case '^': case L'^':
// Switch to a different character rendition // Switch to a different character rendition
if (*++wcformat == '\0') { if (*++wcformat == L'\0') {
goto error_inval; goto error_inval;
} else { } else {
switch (*wcformat) { switch (*wcformat) {
case '^': case L'^':
if (mkchstr_add(&outbuf, &attrbuf, &count, curattr, if (mkchstr_add(&outbuf, &attrbuf, &count, curattr,
maxlines, maxwidth, &line, &width, maxlines, maxwidth, &line, &width,
&lastspc, &spcattr, &widthspc, widthbuf, &lastspc, &spcattr, &widthspc, widthbuf,
@ -1369,18 +1369,18 @@ int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
} }
break; break;
case '{': case L'{':
curattr = attr_alt1; curattr = attr_alt1;
wcformat++; wcformat++;
break; break;
case '[': case L'[':
curattr = attr_alt2; curattr = attr_alt2;
wcformat++; wcformat++;
break; break;
case '}': case L'}':
case ']': case L']':
curattr = attr_norm; curattr = attr_norm;
wcformat++; wcformat++;
break; break;
@ -1391,11 +1391,11 @@ int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
} }
break; break;
case '%': case L'%':
// Process a conversion specifier // Process a conversion specifier
if (*++wcformat == '\0') { if (*++wcformat == L'\0') {
goto error_inval; goto error_inval;
} else if (*wcformat == '%') { } else if (*wcformat == L'%') {
if (mkchstr_add(&outbuf, &attrbuf, &count, curattr, maxlines, if (mkchstr_add(&outbuf, &attrbuf, &count, curattr, maxlines,
maxwidth, &line, &width, &lastspc, &spcattr, maxwidth, &line, &width, &lastspc, &spcattr,
&widthspc, widthbuf, widthbufsize, &wcformat) &widthspc, widthbuf, widthbufsize, &wcformat)
@ -1408,7 +1408,7 @@ int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
wint_t wc; wint_t wc;
switch (spec->spec) { switch (spec->spec) {
case 'c': case L'c':
// Insert a character (char or wchar_t) into the output // Insert a character (char or wchar_t) into the output
if (spec->flag_long) { if (spec->flag_long) {
wc = format_arg[spec->arg_num].a.a_wchar; wc = format_arg[spec->arg_num].a.a_wchar;
@ -1416,17 +1416,17 @@ int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
wc = btowc(format_arg[spec->arg_num].a.a_char); wc = btowc(format_arg[spec->arg_num].a.a_char);
} }
if (wc == '\0' || wc == WEOF) { if (wc == L'\0' || wc == WEOF) {
wc = EILSEQ_REPL_WC; wc = EILSEQ_REPL_WC;
} }
fmtbuf[0] = wc; fmtbuf[0] = wc;
fmtbuf[1] = '\0'; fmtbuf[1] = L'\0';
str = fmtbuf; str = fmtbuf;
goto insertstr; goto insertstr;
case 'd': case L'd':
// Insert an integer (int or long int) into the output // Insert an integer (int or long int) into the output
if (spec->flag_long) { if (spec->flag_long) {
if (swprintf(fmtbuf, BUFSIZE, spec->flag_group ? if (swprintf(fmtbuf, BUFSIZE, spec->flag_group ?
@ -1443,7 +1443,7 @@ int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
str = fmtbuf; str = fmtbuf;
goto insertstr; goto insertstr;
case 'f': case L'f':
// Insert a floating-point number (double) into the output // Insert a floating-point number (double) into the output
if (spec->flag_prec) { if (spec->flag_prec) {
if (swprintf(fmtbuf, BUFSIZE, spec->flag_group ? if (swprintf(fmtbuf, BUFSIZE, spec->flag_group ?
@ -1460,7 +1460,7 @@ int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
str = fmtbuf; str = fmtbuf;
goto insertstr; goto insertstr;
case 'N': case L'N':
// Insert a monetary amount (double) into the output // Insert a monetary amount (double) into the output
{ {
/* strfmon() is not available in a wide-char /* strfmon() is not available in a wide-char
@ -1482,7 +1482,7 @@ int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
str = fmtbuf; str = fmtbuf;
goto insertstr; goto insertstr;
case 's': case L's':
// Insert a string (const char * or const wchar_t *) // Insert a string (const char * or const wchar_t *)
if (spec->flag_long) { if (spec->flag_long) {
str = format_arg[spec->arg_num].a.a_wstring; str = format_arg[spec->arg_num].a.a_wstring;
@ -1502,7 +1502,7 @@ int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
insertstr: insertstr:
// Insert the string pointed to by str // Insert the string pointed to by str
while (*str != '\0' && count > 1 && line < maxlines) { while (*str != L'\0' && count > 1 && line < maxlines) {
if (mkchstr_add(&outbuf, &attrbuf, &count, curattr, if (mkchstr_add(&outbuf, &attrbuf, &count, curattr,
maxlines, maxwidth, &line, &width, maxlines, maxwidth, &line, &width,
&lastspc, &spcattr, &widthspc, &lastspc, &spcattr, &widthspc,
@ -1531,7 +1531,7 @@ int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
} }
} }
*outbuf = '\0'; // Terminating NUL character *outbuf = L'\0'; // Terminating NUL character
*attrbuf = 0; *attrbuf = 0;
if (line >= 0 && line < maxlines) { if (line >= 0 && line < maxlines) {
@ -1578,7 +1578,7 @@ int leftch (WINDOW *win, int y, int x, const chtype *restrict chstr,
assert(widthbuf != NULL); assert(widthbuf != NULL);
wmove(win, y, x); wmove(win, y, x);
for ( ; *chstr != '\0'; chstr++) { for ( ; *chstr != 0; chstr++) {
if (*chstr == '\n') { if (*chstr == '\n') {
wmove(win, getcury(win) + 1, x); wmove(win, getcury(win) + 1, x);
} else { } else {
@ -1605,7 +1605,7 @@ int centerch (WINDOW *win, int y, int offset, const chtype *restrict chstr,
assert(widthbuf != NULL); assert(widthbuf != NULL);
wmove(win, y, (getmaxx(win) - widthbuf[ln]) / 2 + offset); wmove(win, y, (getmaxx(win) - widthbuf[ln]) / 2 + offset);
for ( ; *chstr != '\0'; chstr++) { for ( ; *chstr != 0; chstr++) {
if (*chstr == '\n') { if (*chstr == '\n') {
if (ln++ >= lines) { if (ln++ >= lines) {
return ERR; return ERR;
@ -1637,7 +1637,7 @@ int rightch (WINDOW *win, int y, int x, const chtype *restrict chstr,
assert(widthbuf != NULL); assert(widthbuf != NULL);
wmove(win, y, x - widthbuf[ln]); wmove(win, y, x - widthbuf[ln]);
for ( ; *chstr != '\0'; chstr++) { for ( ; *chstr != 0; chstr++) {
if (*chstr == '\n') { if (*chstr == '\n') {
if (ln++ >= lines) { if (ln++ >= lines) {
return ERR; return ERR;
@ -1828,10 +1828,10 @@ int gettxchar (WINDOW *win, wint_t *wch)
/***********************************************************************/ /***********************************************************************/
// cpos_endl: Adjust cpos and st for printing the ending part of buf // cpos_end: Adjust cpos and st for printing the ending part of buf
void cpos_endl (wchar_t *restrict buf, int *restrict cpos, int *restrict st, void cpos_end (const wchar_t *restrict buf, int *restrict cpos,
int clen, int width, int len) int *restrict st, int clen, int width, int len)
{ {
*cpos = MIN(clen, width - 1); *cpos = MIN(clen, width - 1);
@ -1862,10 +1862,10 @@ void cpos_endl (wchar_t *restrict buf, int *restrict cpos, int *restrict st,
/***********************************************************************/ /***********************************************************************/
// cpos_decr: Adjust cpos and st: scroll to the left by w columns // cpos_dec: Adjust cpos and st: scroll to the left by w columns
void cpos_decr (wchar_t *restrict buf, int *restrict cpos, int *restrict st, void cpos_dec (const wchar_t *restrict buf, int *restrict cpos,
int w, int width) int *restrict st, int w, int width)
{ {
if (*cpos > 0) { if (*cpos > 0) {
// Cursor position is not yet in first column // Cursor position is not yet in first column
@ -1886,10 +1886,10 @@ void cpos_decr (wchar_t *restrict buf, int *restrict cpos, int *restrict st,
/***********************************************************************/ /***********************************************************************/
// cpos_incr: Adjust cpos and st: scroll to the right by w columns // cpos_inc: Adjust cpos and st: scroll to the right by w columns
void cpos_incr (wchar_t *restrict buf, int *restrict cpos, int *restrict st, void cpos_inc (const wchar_t *restrict buf, int *restrict cpos,
int w, int width) int *restrict st, int w, int width)
{ {
if (*cpos + w <= width - 1) { if (*cpos + w <= width - 1) {
// Cursor position is not yet in second-last column // Cursor position is not yet in second-last column
@ -1953,7 +1953,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
} }
// Find the point from which buf should be displayed to screen // Find the point from which buf should be displayed to screen
cpos_endl(buf, &cpos, &st, clen, width, len); cpos_end(buf, &cpos, &st, clen, width, len);
redraw = true; redraw = true;
done = false; done = false;
@ -1996,7 +1996,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
buf); buf);
} }
cpos_endl(buf, &cpos, &st, clen, width, len); cpos_end(buf, &cpos, &st, clen, width, len);
mod = true; mod = true;
redraw = true; redraw = true;
@ -2020,7 +2020,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
pos++; pos++;
clen += w; clen += w;
cpos_incr(buf, &cpos, &st, w, width); cpos_inc(buf, &cpos, &st, w, width);
mod = true; mod = true;
redraw = true; redraw = true;
@ -2113,7 +2113,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
beep(); beep();
} else { } else {
pos--; pos--;
cpos_decr(buf, &cpos, &st, wcwidth(buf[pos]), width); cpos_dec(buf, &cpos, &st, wcwidth(buf[pos]), width);
redraw = true; redraw = true;
} }
break; break;
@ -2125,7 +2125,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
beep(); beep();
} else { } else {
pos++; pos++;
cpos_incr(buf, &cpos, &st, wcwidth(buf[pos - 1]), width); cpos_inc(buf, &cpos, &st, wcwidth(buf[pos - 1]), width);
redraw = true; redraw = true;
} }
break; break;
@ -2143,7 +2143,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
case KEY_CTRL('E'): case KEY_CTRL('E'):
// Move cursor to end of string // Move cursor to end of string
pos = len; pos = len;
cpos_endl(buf, &cpos, &st, clen, width, len); cpos_end(buf, &cpos, &st, clen, width, len);
redraw = true; redraw = true;
break; break;
@ -2151,7 +2151,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
// Move cursor to start of current or previous word // Move cursor to start of current or previous word
while (pos > 0 && ! iswalnum(buf[pos - 1])) { while (pos > 0 && ! iswalnum(buf[pos - 1])) {
pos--; pos--;
cpos_decr(buf, &cpos, &st, wcwidth(buf[pos]), width); cpos_dec(buf, &cpos, &st, wcwidth(buf[pos]), width);
} }
while (pos > 0 && (iswalnum(buf[pos - 1]) while (pos > 0 && (iswalnum(buf[pos - 1])
|| (pos > 1 && wcwidth(buf[pos - 1]) == 0 || (pos > 1 && wcwidth(buf[pos - 1]) == 0
@ -2159,7 +2159,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
/* Treat zero-width characters preceded by an /* Treat zero-width characters preceded by an
alphanumeric character as alphanumeric. */ alphanumeric character as alphanumeric. */
pos--; pos--;
cpos_decr(buf, &cpos, &st, wcwidth(buf[pos]), width); cpos_dec(buf, &cpos, &st, wcwidth(buf[pos]), width);
} }
redraw = true; redraw = true;
break; break;
@ -2168,14 +2168,14 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
// Move cursor to end of current or next word // Move cursor to end of current or next word
while (pos < len && ! iswalnum(buf[pos])) { while (pos < len && ! iswalnum(buf[pos])) {
pos++; pos++;
cpos_incr(buf, &cpos, &st, wcwidth(buf[pos - 1]), width); cpos_inc(buf, &cpos, &st, wcwidth(buf[pos - 1]), width);
} }
while (pos < len while (pos < len
&& (iswalnum(buf[pos]) || wcwidth(buf[pos]) == 0)) { && (iswalnum(buf[pos]) || wcwidth(buf[pos]) == 0)) {
/* Treat zero-width characters following an /* Treat zero-width characters following an
alphanumeric character as alphanumeric. */ alphanumeric character as alphanumeric. */
pos++; pos++;
cpos_incr(buf, &cpos, &st, wcwidth(buf[pos - 1]), width); cpos_inc(buf, &cpos, &st, wcwidth(buf[pos - 1]), width);
} }
redraw = true; redraw = true;
break; break;
@ -2194,7 +2194,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
len--; len--;
pos--; pos--;
clen -= w; clen -= w;
cpos_decr(buf, &cpos, &st, w, width); cpos_dec(buf, &cpos, &st, w, width);
mod = true; mod = true;
redraw = true; redraw = true;
} }
@ -2282,13 +2282,13 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
i--; i--;
int w = wcwidth(buf[i]); int w = wcwidth(buf[i]);
ww += w; ww += w;
cpos_decr(buf, &cpos, &st, w, width); cpos_dec(buf, &cpos, &st, w, width);
} }
while (i > 0 && ! iswspace(buf[i - 1])) { while (i > 0 && ! iswspace(buf[i - 1])) {
i--; i--;
int w = wcwidth(buf[i]); int w = wcwidth(buf[i]);
ww += w; ww += w;
cpos_decr(buf, &cpos, &st, w, width); cpos_dec(buf, &cpos, &st, w, width);
} }
wmemmove(buf + i, buf + pos, len - pos + 1); wmemmove(buf + i, buf + pos, len - pos + 1);
@ -2320,7 +2320,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
buf[pos - 1] = c; buf[pos - 1] = c;
pos++; pos++;
cpos_incr(buf, &cpos, &st, w, width); cpos_inc(buf, &cpos, &st, w, width);
mod = true; mod = true;
redraw = true; redraw = true;
@ -2358,7 +2358,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
// Move cursor to start of current or previous word // Move cursor to start of current or previous word
while (pos > 0 && ! iswalnum(buf[pos - 1])) { while (pos > 0 && ! iswalnum(buf[pos - 1])) {
pos--; pos--;
cpos_decr(buf, &cpos, &st, wcwidth(buf[pos]), cpos_dec(buf, &cpos, &st, wcwidth(buf[pos]),
width); width);
} }
while (pos > 0 && (iswalnum(buf[pos - 1]) while (pos > 0 && (iswalnum(buf[pos - 1])
@ -2368,7 +2368,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
/* Treat zero-width characters preceded by an /* Treat zero-width characters preceded by an
alphanumeric character as alphanumeric. */ alphanumeric character as alphanumeric. */
pos--; pos--;
cpos_decr(buf, &cpos, &st, wcwidth(buf[pos]), cpos_dec(buf, &cpos, &st, wcwidth(buf[pos]),
width); width);
} }
redraw = true; redraw = true;
@ -2379,7 +2379,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
// Move cursor to end of current or next word // Move cursor to end of current or next word
while (pos < len && ! iswalnum(buf[pos])) { while (pos < len && ! iswalnum(buf[pos])) {
pos++; pos++;
cpos_incr(buf, &cpos, &st, cpos_inc(buf, &cpos, &st,
wcwidth(buf[pos - 1]), width); wcwidth(buf[pos - 1]), width);
} }
while (pos < len while (pos < len
@ -2388,7 +2388,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
/* Treat zero-width characters following an /* Treat zero-width characters following an
alphanumeric character as alphanumeric. */ alphanumeric character as alphanumeric. */
pos++; pos++;
cpos_incr(buf, &cpos, &st, cpos_inc(buf, &cpos, &st,
wcwidth(buf[pos - 1]), width); wcwidth(buf[pos - 1]), width);
} }
redraw = true; redraw = true;
@ -2436,7 +2436,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
pos--; pos--;
int w = wcwidth(buf[pos]); int w = wcwidth(buf[pos]);
ww += w; ww += w;
cpos_decr(buf, &cpos, &st, w, width); cpos_dec(buf, &cpos, &st, w, width);
} }
while (i < len && iswspace(buf[i])) { while (i < len && iswspace(buf[i])) {
i++; i++;
@ -2461,7 +2461,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
int w = wcwidth(c); int w = wcwidth(c);
clen += w; clen += w;
cpos_incr(buf, &cpos, &st, w, width); cpos_inc(buf, &cpos, &st, w, width);
} }
} }
@ -2477,7 +2477,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
// Convert word (from cursor onwards) to upper case // Convert word (from cursor onwards) to upper case
while (pos < len && ! iswalnum(buf[pos])) { while (pos < len && ! iswalnum(buf[pos])) {
pos++; pos++;
cpos_incr(buf, &cpos, &st, cpos_inc(buf, &cpos, &st,
wcwidth(buf[pos - 1]), width); wcwidth(buf[pos - 1]), width);
} }
while (pos < len while (pos < len
@ -2485,7 +2485,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
|| wcwidth(buf[pos]) == 0)) { || wcwidth(buf[pos]) == 0)) {
buf[pos] = towupper(buf[pos]); buf[pos] = towupper(buf[pos]);
pos++; pos++;
cpos_incr(buf, &cpos, &st, cpos_inc(buf, &cpos, &st,
wcwidth(buf[pos - 1]), width); wcwidth(buf[pos - 1]), width);
} }
mod = true; mod = true;
@ -2497,7 +2497,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
// Convert word (from cursor onwards) to lower case // Convert word (from cursor onwards) to lower case
while (pos < len && ! iswalnum(buf[pos])) { while (pos < len && ! iswalnum(buf[pos])) {
pos++; pos++;
cpos_incr(buf, &cpos, &st, cpos_inc(buf, &cpos, &st,
wcwidth(buf[pos - 1]), width); wcwidth(buf[pos - 1]), width);
} }
while (pos < len while (pos < len
@ -2505,7 +2505,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
|| wcwidth(buf[pos]) == 0)) { || wcwidth(buf[pos]) == 0)) {
buf[pos] = towlower(buf[pos]); buf[pos] = towlower(buf[pos]);
pos++; pos++;
cpos_incr(buf, &cpos, &st, cpos_inc(buf, &cpos, &st,
wcwidth(buf[pos - 1]), width); wcwidth(buf[pos - 1]), width);
} }
mod = true; mod = true;
@ -2520,7 +2520,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
bool first = true; bool first = true;
while (pos < len && ! iswalnum(buf[pos])) { while (pos < len && ! iswalnum(buf[pos])) {
pos++; pos++;
cpos_incr(buf, &cpos, &st, cpos_inc(buf, &cpos, &st,
wcwidth(buf[pos - 1]), width); wcwidth(buf[pos - 1]), width);
} }
while (pos < len while (pos < len
@ -2533,7 +2533,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
buf[pos] = towlower(buf[pos]); buf[pos] = towlower(buf[pos]);
} }
pos++; pos++;
cpos_incr(buf, &cpos, &st, cpos_inc(buf, &cpos, &st,
wcwidth(buf[pos - 1]), width); wcwidth(buf[pos - 1]), width);
} }
mod = true; mod = true;
@ -2564,7 +2564,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
i--; i--;
int w = wcwidth(buf[i]); int w = wcwidth(buf[i]);
ww += w; ww += w;
cpos_decr(buf, &cpos, &st, w, width); cpos_dec(buf, &cpos, &st, w, width);
} }
while (i > 0 while (i > 0
&& (iswalnum(buf[i - 1]) && (iswalnum(buf[i - 1])
@ -2575,7 +2575,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
i--; i--;
int w = wcwidth(buf[i]); int w = wcwidth(buf[i]);
ww += w; ww += w;
cpos_decr(buf, &cpos, &st, w, width); cpos_dec(buf, &cpos, &st, w, width);
} }
wmemmove(buf + i, buf + pos, len - pos + 1); wmemmove(buf + i, buf + pos, len - pos + 1);
@ -2654,7 +2654,7 @@ int gettxstr (WINDOW *win, wchar_t *restrict *restrict bufptr,
// Allocate the result buffer if needed // Allocate the result buffer if needed
if (*bufptr == NULL) { if (*bufptr == NULL) {
*bufptr = xmalloc(BUFSIZE * sizeof(wchar_t)); *bufptr = xmalloc(BUFSIZE * sizeof(wchar_t));
**bufptr = '\0'; **bufptr = L'\0';
} }
return gettxline(win, *bufptr, BUFSIZE, modified, multifield, L"", L"", return gettxline(win, *bufptr, BUFSIZE, modified, multifield, L"", L"",
@ -2665,13 +2665,14 @@ int gettxstr (WINDOW *win, wchar_t *restrict *restrict bufptr,
/***********************************************************************/ /***********************************************************************/
// txinput_fixup: Copy strings with fixup // txinput_fixup: Copy strings with fixup
void txinput_fixup (wchar_t *restrict dest, wchar_t *restrict src, bool isfloat) void txinput_fixup (wchar_t *restrict dest, const wchar_t *restrict src,
bool isfloat)
{ {
assert(src != NULL); assert(src != NULL);
assert(dest != NULL); assert(dest != NULL);
wcsncpy(dest, src, BUFSIZE - 1); wcsncpy(dest, src, BUFSIZE - 1);
dest[BUFSIZE - 1] = '\0'; dest[BUFSIZE - 1] = L'\0';
// Replace mon_decimal_point with decimal_point if these are different // Replace mon_decimal_point with decimal_point if these are different
if (isfloat) { if (isfloat) {

View File

@ -597,7 +597,7 @@ extern int gettxchar (WINDOW *win, wint_t *wch);
attr - Character rendition to use for input field attr - Character rendition to use for input field
Returns: int - Status code: OK, ERR or KEY_ keycode Returns: int - Status code: OK, ERR or KEY_ keycode
This low-level function shows an input field width column spaces long This low-level function shows an input field width column-spaces long
using attr as the character rendition, then reads a line of input from using attr as the character rendition, then reads a line of input from
the keyboard and places it into the preallocated buffer buf[] of size the keyboard and places it into the preallocated buffer buf[] of size
bufsize. On entry, buf[] must contain a valid string; this string is bufsize. On entry, buf[] must contain a valid string; this string is
@ -633,7 +633,7 @@ extern int gettxchar (WINDOW *win, wint_t *wch);
If allowed is not NULL, only characters in that string are allowed to If allowed is not NULL, only characters in that string are allowed to
be entered into the input line. For example, if allowed points to be entered into the input line. For example, if allowed points to
"0123456789abcdefABCDEF", only those characters would be allowed (in L"0123456789abcdefABCDEF", only those characters would be allowed (in
this instance, allowing the user to type in a hexadecimal number). this instance, allowing the user to type in a hexadecimal number).
Note that the character rendition (attributes) in attr may contain a Note that the character rendition (attributes) in attr may contain a
@ -667,7 +667,7 @@ extern int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
malloc(); this buffer is used to store and return the input line. malloc(); this buffer is used to store and return the input line.
Apart from bufptr, all parameters are as used for gettxline(). The Apart from bufptr, all parameters are as used for gettxline(). The
gettxline() parameters emptyval and defaultval are passed as "", gettxline() parameters emptyval and defaultval are passed as L"",
allowed is NULL and stripspc is true. allowed is NULL and stripspc is true.
*/ */
extern int gettxstr (WINDOW *win, wchar_t *restrict *restrict bufptr, extern int gettxstr (WINDOW *win, wchar_t *restrict *restrict bufptr,

View File

@ -263,7 +263,7 @@ selection_t get_move (void)
key = towlower(key); key = towlower(key);
} }
for (i = 0, found = false; keycode_game_move[i] != '\0'; i++) { for (i = 0, found = false; keycode_game_move[i] != L'\0'; i++) {
if (keycode_game_move[i] == key) { if (keycode_game_move[i] == key) {
found = true; found = true;
selection = i; selection = i;
@ -282,13 +282,13 @@ selection_t get_move (void)
if (! found) { if (! found) {
switch (key) { switch (key) {
case '1': case L'1':
curs_set(CURS_OFF); curs_set(CURS_OFF);
show_status(current_player); show_status(current_player);
curs_set(CURS_ON); curs_set(CURS_ON);
break; break;
case '2': case L'2':
selection = SEL_BANKRUPT; selection = SEL_BANKRUPT;
curs_set(CURS_OFF); curs_set(CURS_OFF);
@ -297,7 +297,7 @@ selection_t get_move (void)
_("^{<2>^} (Declare bankruptcy)")); _("^{<2>^} (Declare bankruptcy)"));
break; break;
case '3': case L'3':
selection = SEL_SAVE; selection = SEL_SAVE;
curs_set(CURS_OFF); curs_set(CURS_OFF);
@ -396,12 +396,12 @@ selection_t get_move (void)
if (gettxchar(curwin, &key) == OK) { if (gettxchar(curwin, &key) == OK) {
// Ordinary wide character // Ordinary wide character
if (key >= '1' && key <= '9') { if (key >= L'1' && key <= L'9') {
left(curwin, getcury(curwin), getcurx(curwin), left(curwin, getcury(curwin), getcurx(curwin),
A_BOLD, 0, 0, 1, "%lc", key); A_BOLD, 0, 0, 1, "%lc", key);
wrefresh(curwin); wrefresh(curwin);
choice = key - '0'; choice = key - L'0';
done = true; done = true;
} else { } else {
beep(); beep();
@ -504,12 +504,12 @@ void process_move (selection_t selection)
assign_vals(x, y, left, right, up, down); assign_vals(x, y, left, right, up, down);
if (left == MAP_EMPTY && right == MAP_EMPTY && if ( left == MAP_EMPTY && right == MAP_EMPTY
up == MAP_EMPTY && down == MAP_EMPTY) { && up == MAP_EMPTY && down == MAP_EMPTY) {
// The position is out in the middle of nowhere... // The position is out in the middle of nowhere...
galaxy_map[x][y] = MAP_OUTPOST; galaxy_map[x][y] = MAP_OUTPOST;
} else if (! IS_MAP_COMPANY(left) && ! IS_MAP_COMPANY(right) } else if ( ! IS_MAP_COMPANY(left) && ! IS_MAP_COMPANY(right)
&& ! IS_MAP_COMPANY(up) && ! IS_MAP_COMPANY(down)) { && ! IS_MAP_COMPANY(up) && ! IS_MAP_COMPANY(down)) {
// See if a company can be established // See if a company can be established
try_start_new_company(x, y); try_start_new_company(x, y);
@ -770,6 +770,9 @@ void merge_companies (map_val_t a, map_val_t b)
int aa = MAP_TO_COMPANY(a); int aa = MAP_TO_COMPANY(a);
int bb = MAP_TO_COMPANY(b); int bb = MAP_TO_COMPANY(b);
assert(aa >= 0 && aa < MAX_COMPANIES);
assert(bb >= 0 && bb < MAX_COMPANIES);
double val_aa = company[aa].share_price * company[aa].stock_issued * double val_aa = company[aa].share_price * company[aa].stock_issued *
company[aa].share_return; company[aa].share_return;
double val_bb = company[bb].share_price * company[bb].stock_issued * double val_bb = company[bb].share_price * company[bb].stock_issued *
@ -1137,7 +1140,8 @@ void adjust_values (void)
// Give the current player the companies' dividends // Give the current player the companies' dividends
for (int i = 0; i < MAX_COMPANIES; i++) { for (int i = 0; i < MAX_COMPANIES; i++) {
if (company[i].on_map && company[i].stock_issued != 0) { if (company[i].on_map && company[i].stock_issued != 0) {
player[current_player].cash += player[current_player].stock_owned[i] player[current_player].cash +=
player[current_player].stock_owned[i]
* company[i].share_price * company[i].share_return * company[i].share_price * company[i].share_return
+ ((double) player[current_player].stock_owned[i] + ((double) player[current_player].stock_owned[i]
/ company[i].stock_issued) * company[i].share_price / company[i].stock_issued) * company[i].share_price

View File

@ -248,8 +248,8 @@ void process_cmdline (int argc, char *argv[])
if (optind < argc && argv[optind] != NULL) { if (optind < argc && argv[optind] != NULL) {
if (*argv[optind] == '-') { if (*argv[optind] == '-') {
fprintf(stderr, _("%s: invalid operand `%s'\n"), program_name, fprintf(stderr, _("%s: invalid operand `%s'\n"),
argv[optind]); program_name, argv[optind]);
show_usage(EXIT_FAILURE); show_usage(EXIT_FAILURE);
} }

View File

@ -83,7 +83,7 @@ static bool add_currency_symbol = false; // Do we need to add "$"?
/***********************************************************************/ /***********************************************************************/
// init_program_name: Make the program name canonical // init_program_name: Make the program name canonical
void init_program_name (char *argv0) void init_program_name (const char *argv0)
{ {
/* This implementation assumes a POSIX environment with an ASCII-safe /* This implementation assumes a POSIX environment with an ASCII-safe
character encoding (such as ASCII or UTF-8). */ character encoding (such as ASCII or UTF-8). */
@ -109,7 +109,7 @@ const char *home_directory (void)
{ {
if (home_directory_str == NULL) { if (home_directory_str == NULL) {
// Use the HOME environment variable where possible // Use the HOME environment variable where possible
char *home = getenv("HOME"); const char *home = getenv("HOME");
if (home != NULL && *home != '\0') { if (home != NULL && *home != '\0') {
home_directory_str = xstrdup(home); home_directory_str = xstrdup(home);
@ -354,7 +354,7 @@ void init_locale (void)
/***********************************************************************/ /***********************************************************************/
// l_strfmon: Convert monetary value to a string // l_strfmon: Convert monetary value to a string
ssize_t l_strfmon (char *restrict s, size_t maxsize, ssize_t l_strfmon (char *restrict buf, size_t maxsize,
const char *restrict format, double val) const char *restrict format, double val)
{ {
/* The current implementation assumes MOD_POSIX_P_CS_PRECEDES is 1 /* The current implementation assumes MOD_POSIX_P_CS_PRECEDES is 1
@ -365,7 +365,7 @@ ssize_t l_strfmon (char *restrict s, size_t maxsize,
assert(MOD_POSIX_P_CS_PRECEDES == 1); assert(MOD_POSIX_P_CS_PRECEDES == 1);
assert(MOD_POSIX_P_SEP_BY_SPACE == 0); assert(MOD_POSIX_P_SEP_BY_SPACE == 0);
ssize_t ret = strfmon(s, maxsize, format, val); ssize_t ret = strfmon(buf, maxsize, format, val);
if (ret > 0 && add_currency_symbol) { if (ret > 0 && add_currency_symbol) {
if (strstr(format, "!") == NULL) { if (strstr(format, "!") == NULL) {
@ -382,7 +382,7 @@ ssize_t l_strfmon (char *restrict s, size_t maxsize,
assert(maxsize > (unsigned int) symlen); assert(maxsize > (unsigned int) symlen);
// Count number of leading spaces // Count number of leading spaces
for (p = s, spc = 0; *p == ' '; p++, spc++) for (p = buf, spc = 0; *p == ' '; p++, spc++)
; ;
if (symlen <= spc) { if (symlen <= spc) {
@ -394,12 +394,12 @@ ssize_t l_strfmon (char *restrict s, size_t maxsize,
} else { } else {
// Make space for currency symbol, then copy it // Make space for currency symbol, then copy it
memmove(s + symlen - spc, s, maxsize - (symlen - spc)); memmove(buf + symlen - spc, buf, maxsize - (symlen - spc));
s[maxsize - 1] = '\0'; buf[maxsize - 1] = '\0';
for ( ; *sym != '\0'; sym++, s++) { for ( ; *sym != '\0'; sym++, buf++) {
// Make sure terminating NUL character is NOT copied! // Make sure terminating NUL character is NOT copied!
*s = *sym; *buf = *sym;
} }
ret = MIN((unsigned int) ret + symlen - spc, maxsize - 1); ret = MIN((unsigned int) ret + symlen - spc, maxsize - 1);

View File

@ -70,7 +70,7 @@ extern wchar_t *mon_thousands_sep; // Local monetary thousands separator
/* /*
Function: init_program_name - Make the program name canonical Function: init_program_name - Make the program name canonical
Parameters: argv0 - Same as passed to main() Parameters: argv0 - Same as passed to main() as argv[0]
Returns: (nothing) Returns: (nothing)
This function modifies the argv0 pointer to eliminate any leading This function modifies the argv0 pointer to eliminate any leading
@ -78,7 +78,7 @@ extern wchar_t *mon_thousands_sep; // Local monetary thousands separator
basename of the program. It also saves a copy that can be accessed via basename of the program. It also saves a copy that can be accessed via
the program_name global variable. the program_name global variable.
*/ */
extern void init_program_name (char *argv0); extern void init_program_name (const char *argv0);
/* /*
@ -239,7 +239,7 @@ extern void init_locale (void);
/* /*
Function: l_strfmon - Convert monetary value to a string Function: l_strfmon - Convert monetary value to a string
Parameters: s - Buffer to receive result Parameters: buf - Buffer to receive result
maxsize - Maximum size of buffer maxsize - Maximum size of buffer
format - strfmon() format to use format - strfmon() format to use
val - Monetary value to convert val - Monetary value to convert
@ -251,7 +251,7 @@ extern void init_locale (void);
function overcomes the limitation that the POSIX locale does not define function overcomes the limitation that the POSIX locale does not define
anything for localeconv()->currency_symbol. anything for localeconv()->currency_symbol.
*/ */
extern ssize_t l_strfmon (char *restrict s, size_t maxsize, extern ssize_t l_strfmon (char *restrict buf, size_t maxsize,
const char *restrict format, double val); const char *restrict format, double val);