From 1c2518a78b977c927a713560f68fd48f648ac453 Mon Sep 17 00:00:00 2001
From: John Zaitseff <J.Zaitseff@zap.org.au>
Date: Thu, 25 Aug 2011 21:34:41 +1000
Subject: [PATCH] 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!
---
 src/exch.c   |  40 ++++----
 src/game.c   |  13 ++-
 src/help.c   | 115 +++++++++++-----------
 src/intf.c   | 263 ++++++++++++++++++++++++++-------------------------
 src/intf.h   |   6 +-
 src/move.c   |  26 ++---
 src/trader.c |   4 +-
 src/utils.c  |  18 ++--
 src/utils.h  |   8 +-
 9 files changed, 249 insertions(+), 244 deletions(-)

diff --git a/src/exch.c b/src/exch.c
index 71f51dc..3d4d43b 100644
--- a/src/exch.c
+++ b/src/exch.c
@@ -208,7 +208,7 @@ void exchange_stock (void)
 		    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) {
 			found = true;
 			if (company[i].on_map) {
@@ -222,24 +222,24 @@ void exchange_stock (void)
 
 		if (! found) {
 		    switch (key) {
-		    case '1':
+		    case L'1':
 			curs_set(CURS_OFF);
 			show_status(current_player);
 			curs_set(CURS_ON);
 			break;
 
-		    case '2':
+		    case L'2':
 			curs_set(CURS_OFF);
 			show_map(true);
 			curs_set(CURS_ON);
 			break;
 
-		    case '3':
+		    case L'3':
 			selection = SEL_BANK;
 			break;
 
-		    case '4':
-		    case ' ':
+		    case L'4':
+		    case L' ':
 			selection = SEL_EXIT;
 			break;
 
@@ -379,9 +379,9 @@ void visit_bank (void)
 	if (gettxchar(curwin, &key) == OK) {
 	    // Ordinary wide character
 	    switch (key) {
-	    case '1':
-	    case '2':
-	    case '3':
+	    case L'1':
+	    case L'2':
+	    case L'3':
 		left(curwin, getcury(curwin), getcurx(curwin), A_BOLD,
 		     0, 0, 1, "%lc", key);
 		wrefresh(curwin);
@@ -389,7 +389,7 @@ void visit_bank (void)
 		done = true;
 		break;
 
-	    case ' ':
+	    case L' ':
 		done = true;
 		break;
 
@@ -417,7 +417,7 @@ void visit_bank (void)
     curs_set(CURS_OFF);
 
     switch (key) {
-    case '1':
+    case L'1':
 	// Borrow money from the Bank
 	if (credit_limit == 0.0) {
 	    txdlgbox(MAX_DLG_LINES, 50, 8, WCENTER, attr_error_window,
@@ -470,7 +470,7 @@ void visit_bank (void)
 	}
 	break;
 
-    case '2':
+    case L'2':
 	// Repay a debt
 	if (player[current_player].debt == 0.0) {
 	    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) {
 	    // Ordinary wide character
 	    switch (key) {
-	    case '1':
-	    case '2':
-	    case '3':
-	    case '4':
+	    case L'1':
+	    case L'2':
+	    case L'3':
+	    case L'4':
 		left(curwin, getcury(curwin), getcurx(curwin), A_BOLD,
 		     0, 0, 1, "%lc", key);
 		wrefresh(curwin);
@@ -675,7 +675,7 @@ void trade_shares (int num, bool *bid_used)
 		done = true;
 		break;
 
-	    case ' ':
+	    case L' ':
 		done = true;
 		break;
 
@@ -703,7 +703,7 @@ void trade_shares (int num, bool *bid_used)
     curs_set(CURS_OFF);
 
     switch (key) {
-    case '1':
+    case L'1':
 	// Buy stock in company
 	maxshares = player[current_player].cash / company[num].share_price;
 
@@ -748,7 +748,7 @@ void trade_shares (int num, bool *bid_used)
 	}
 	break;
 
-    case '2':
+    case L'2':
 	// Sell stock back to company
 	maxshares = player[current_player].stock_owned[num];
 	if (maxshares == 0) {
@@ -783,7 +783,7 @@ void trade_shares (int num, bool *bid_used)
 	}
 	break;
 
-    case '3':
+    case L'3':
 	// Bid company to issue more shares
 	maxshares = 0;
 	if (! *bid_used && randf() < ownership && randf() < BID_CHANCE) {
diff --git a/src/game.c b/src/game.c
index 46f236d..3ee99bf 100644
--- a/src/game.c
+++ b/src/game.c
@@ -281,12 +281,12 @@ static int ask_number_players (void)
 
 	if (gettxchar(curwin, &key) == OK) {
 	    // 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,
 		     0, 0, 1, "%lc", key);
 		wrefresh(curwin);
 
-		ret = key - '0';
+		ret = key - L'0';
 		done = true;
 	    } else if (wcschr(keycode_contgame, key) != NULL) {
 		left(curwin, getcury(curwin), getcurx(curwin), A_BOLD,
@@ -356,12 +356,12 @@ int ask_game_number (void)
 
 	if (gettxchar(curwin, &key) == OK) {
 	    // Ordinary wide character
-	    if (key >= '1' && key <= '9') {
+	    if (key >= L'1' && key <= L'9') {
 		left(curwin, getcury(curwin), getcurx(curwin), A_BOLD,
 		     0, 0, 1, "%lc", key);
 		wrefresh(curwin);
 
-		ret = key - '0';
+		ret = key - L'0';
 		done = true;
 	    } else {
 		beep();
@@ -574,8 +574,7 @@ void end_game (void)
 		 attr_title, attr_normal, attr_highlight, 0, attr_waitforkey,
 		 _("  Total Value  "),
 		 /* xgettext:c-format */
-		 _("Your total value was ^{%N^}."),
-		 total_value(0));
+		 _("Your total value was ^{%N^}."), total_value(0));
     } else {
 	// Sort players on the basis of total value
 	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++) {
 	    chtype *mapstr = CHTYPE_MAP_VAL(galaxy_map[x][y]);
 
-	    while (*mapstr != '\0') {
+	    while (*mapstr != 0) {
 		waddch(curwin, *mapstr++);
 	    }
 	}
diff --git a/src/help.c b/src/help.c
index 8893d97..e803441 100644
--- a/src/help.c
+++ b/src/help.c
@@ -61,7 +61,7 @@ static const char *help_text[HELP_TEXT_PAGES] = {
     ^^ - Print the circumflex accent (ASCII code U+005E)
     ^N - Switch to using the normal 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>")
     ^e - Switch to using the character rendition used for empty space
     ^o - Switch to using the character rendition used for outposts
@@ -288,149 +288,150 @@ void show_help (void)
 	memset(&mbstate, 0, sizeof(mbstate));
 	outp = outbuf;
 
-	while (*htxt != '\0' && count > maxchar * 2) {
+	while (*htxt != L'\0' && count > maxchar * 2) {
 	    switch (*htxt) {
-	    case '\n':
+	    case L'\n':
 		// Start a new line
 		*outp++ = '\n';
 		count--;
 		break;
 
-	    case '^':
+	    case L'^':
 		// Switch to a different character rendition
 		switch (*++htxt) {
-		case '^':
+		case L'^':
 		    wcbuf[0] = *htxt;
-		    wcbuf[1] = '\0';
+		    wcbuf[1] = L'\0';
 		    goto addwcbuf;
 
-		case 'N':
+		case L'N':
 		    curattr = attr_normal;
 		    break;
 
-		case 'B':
+		case L'B':
 		    curattr = attr_normal | A_BOLD;
 		    break;
 
-		case 'H':
+		case L'H':
 		    curattr = attr_highlight;
 		    break;
 
-		case 'K':
+		case L'K':
 		    curattr = attr_keycode;
 		    break;
 
-		case 'e':
+		case L'e':
 		    curattr = attr_map_empty;
 		    break;
 
-		case 'o':
+		case L'o':
 		    curattr = attr_map_outpost;
 		    break;
 
-		case 's':
+		case L's':
 		    curattr = attr_map_star;
 		    break;
 
-		case 'c':
+		case L'c':
 		    curattr = attr_map_company;
 		    break;
 
-		case 'k':
+		case L'k':
 		    curattr = attr_map_choice;
 		    break;
 
 		default:
-		    wcbuf[0] = '^';
+		    wcbuf[0] = L'^';
 		    wcbuf[1] = *htxt;
-		    wcbuf[2] = '\0';
+		    wcbuf[2] = L'\0';
 		    goto addwcbuf;
 		}
 		break;
 
-	    case '~':
+	    case L'~':
 		// Print a global constant
 		switch (*++htxt) {
-		case '~':
+		case L'~':
 		    wcbuf[0] = *htxt;
-		    wcbuf[1] = '\0';
+		    wcbuf[1] = L'\0';
 		    goto addwcbuf;
 
-		case 'x':
+		case L'x':
 		    swprintf(wcbuf, BIGBUFSIZE, L"%2d", MAX_X);
 		    goto addwcbuf;
 
-		case 'y':
+		case L'y':
 		    swprintf(wcbuf, BIGBUFSIZE, L"%2d", MAX_Y);
 		    goto addwcbuf;
 
-		case 'm':
+		case L'm':
 		    swprintf(wcbuf, BIGBUFSIZE, L"%2d", NUMBER_MOVES);
 		    goto addwcbuf;
 
-		case 'c':
+		case L'c':
 		    swprintf(wcbuf, BIGBUFSIZE, L"%d", MAX_COMPANIES);
 		    goto addwcbuf;
 
-		case 't':
+		case L't':
 		    swprintf(wcbuf, BIGBUFSIZE, L"%2d", DEFAULT_MAX_TURN);
 		    goto addwcbuf;
 
-		case '1':
-		case '2':
-		case '3':
-		case '4':
-		case '5':
-		case '6':
-		case '7':
-		case '8':
-		case '9':
+		case L'1':
+		case L'2':
+		case L'3':
+		case L'4':
+		case L'5':
+		case L'6':
+		case L'7':
+		case L'8':
+		case L'9':
 		    // N-th choice of move, as a key press
 		    wcbuf[0] = PRINTABLE_GAME_MOVE(*htxt - L'1');
-		    wcbuf[1] = '\0';
+		    wcbuf[1] = L'\0';
 		    goto addwcbuf;
 
-		case 'M':
+		case L'M':
 		    // Last choice of move, as a key press
 		    wcbuf[0] = PRINTABLE_GAME_MOVE(NUMBER_MOVES - 1);
-		    wcbuf[1] = '\0';
+		    wcbuf[1] = L'\0';
 		    goto addwcbuf;
 
-		case '.':
+		case L'.':
 		    // Map representation of empty space
 		    wcbuf[0] = PRINTABLE_MAP_VAL(MAP_EMPTY);
-		    wcbuf[1] = '\0';
+		    wcbuf[1] = L'\0';
 		    goto addwcbuf;
 
-		case '+':
+		case L'+':
 		    // Map representation of an outpost
 		    wcbuf[0] = PRINTABLE_MAP_VAL(MAP_OUTPOST);
-		    wcbuf[1] = '\0';
+		    wcbuf[1] = L'\0';
 		    goto addwcbuf;
 
-		case '*':
+		case L'*':
 		    // Map representation of a star
 		    wcbuf[0] = PRINTABLE_MAP_VAL(MAP_STAR);
-		    wcbuf[1] = '\0';
+		    wcbuf[1] = L'\0';
 		    goto addwcbuf;
 
-		case 'A':
-		case 'B':
-		case 'C':
-		case 'D':
-		case 'E':
-		case 'F':
-		case 'G':
-		case 'H':
+		case L'A':
+		case L'B':
+		case L'C':
+		case L'D':
+		case L'E':
+		case L'F':
+		case L'G':
+		case L'H':
 		    // Map representation of company
 		    assert((*htxt - L'A') < MAX_COMPANIES);
 		    wcbuf[0] = PRINTABLE_MAP_VAL(COMPANY_TO_MAP(*htxt - L'A'));
-		    wcbuf[1] = '\0';
+		    wcbuf[1] = L'\0';
 		    goto addwcbuf;
 
 		default:
-		    wcbuf[0] = '~';
+		    wcbuf[0] = L'~';
 		    wcbuf[1] = *htxt;
+		    wcbuf[2] = L'\0';
 		    goto addwcbuf;
 		}
 		break;
@@ -438,10 +439,10 @@ void show_help (void)
 	    default:
 		// Print the character
 		wcbuf[0] = *htxt;
-		wcbuf[1] = '\0';
+		wcbuf[1] = L'\0';
 
 	    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);
 		    for (i = 0, cp = convbuf; i < n; i++, cp++, outp++, count--) {
 			*outp = (unsigned char) *cp | curattr;
@@ -453,14 +454,14 @@ void show_help (void)
 	}
 
 	// 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--) {
 	    *outp = (unsigned char) *cp;
 	}
 	assert(count >= 0);
 
 	// Display the formatted text in outbuf
-	for (outp = outbuf; *outp != '\0'; outp++) {
+	for (outp = outbuf; *outp != 0; outp++) {
 	    if (*outp == '\n') {
 		wmove(curwin, getcury(curwin) + 1, 2);
 	    } else {
diff --git a/src/intf.c b/src/intf.c
index ededde7..bd50c97 100644
--- a/src/intf.c
+++ b/src/intf.c
@@ -111,7 +111,7 @@ typedef struct txwin {
 		     __stringify(_var), s);				\
 	}								\
 	(_var) = xwcsdup(buf);						\
-	(_var)[_checkpos] = '\0';					\
+	(_var)[_checkpos] = L'\0';					\
     } while (0)
 
 #define init_game_chstr(_chvar, _var, _attr, _err)			\
@@ -134,13 +134,13 @@ typedef struct txwin {
 	}								\
 									\
 	if (w == 1) {							\
-	    n = xwcrtomb(convbuf, ' ', &mbstate);			\
+	    n = xwcrtomb(convbuf, L' ', &mbstate);			\
 	    for (int i = 0; i < n; i++) {				\
 		*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++) {					\
 	    *p++ = (unsigned char) convbuf[i];				\
 	}								\
@@ -326,52 +326,52 @@ static int getwch (WINDOW *win, wint_t *wch);
 
 
 /*
-  Function:   cpos_endl - Adjust cpos and st for printing the ending part of buf
-  Parameters: buf       - Pointer to current editing buffer
-              cpos      - Pointer to current cursor position (result)
-              st        - Pointer to current starting offset for buf[] (result)
-              clen      - Current column width of entire string
-              width     - Width of editing field in column spaces
-              len       - Length of string being edited (wchar_t elements)
+  Function:   cpos_end - Adjust cpos and st for printing the ending part of buf
+  Parameters: buf      - Pointer to current editing buffer
+              cpos     - Pointer to current cursor position (result)
+              st       - Pointer to current starting offset for buf[] (result)
+              clen     - Current column width of entire string
+              width    - Width of editing field in column spaces
+              len      - Length of string being edited (wchar_t elements)
   Returns:    (nothing)
 
   This helper function adjusts *cpos and *st so that the cursor is placed
   at the end of the current editing buffer buf[].
 */
-static void cpos_endl (wchar_t *restrict buf, int *restrict cpos,
-		       int *restrict st, int clen, int width, int len);
+static void cpos_end (const wchar_t *restrict buf, int *restrict cpos,
+		      int *restrict st, int clen, int width, int len);
 
 
 /*
-  Function:   cpos_decr - Adjust cpos and st: scroll to the left by w columns
-  Parameters: buf       - Pointer to current editing buffer
-              cpos      - Pointer to current cursor position (result)
-              st        - Pointer to current starting offset for buf[] (result)
-              w         - Number of columns to scroll left
-              width     - Width of editing field in column spaces
+  Function:   cpos_dec - Adjust cpos and st: scroll to the left by w columns
+  Parameters: buf      - Pointer to current editing buffer
+              cpos     - Pointer to current cursor position (result)
+              st       - Pointer to current starting offset for buf[] (result)
+              w        - Number of columns to scroll left
+              width    - Width of editing field in column spaces
   Returns:    (nothing)
 
   This helper function adjusts *cpos and *st so that the cursor is moved
   to the left by w column positions.
 */
-static void cpos_decr (wchar_t *restrict buf, int *restrict cpos,
-		       int *restrict st, int w, int width);
+static void cpos_dec (const wchar_t *restrict buf, int *restrict cpos,
+		      int *restrict st, int w, int width);
 
 
 /*
-  Function:   cpos_incr - Adjust cpos and st: scroll to the right by w columns
-  Parameters: buf       - Pointer to current editing buffer
-              cpos      - Pointer to current cursor position (result)
-              st        - Pointer to current starting offset for buf[] (result)
-              w         - Number of columns to scroll right
-              width     - Width of editing field in column spaces
+  Function:   cpos_inc - Adjust cpos and st: scroll to the right by w columns
+  Parameters: buf      - Pointer to current editing buffer
+              cpos     - Pointer to current cursor position (result)
+              st       - Pointer to current starting offset for buf[] (result)
+              w        - Number of columns to scroll right
+              width    - Width of editing field in column spaces
   Returns:    (nothing)
 
   This helper function adjusts *cpos and *st so that the cursor is moved
   to the right by w column positions.
 */
-static void cpos_incr (wchar_t *restrict buf, int *restrict cpos,
-		       int *restrict st, int w, int width);
+static void cpos_inc (const wchar_t *restrict buf, int *restrict cpos,
+		      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
   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);
 
 
@@ -864,11 +864,11 @@ int mkchstr_parse (const wchar_t *restrict format,
     memset(format_arg, 0, MAXFMTARGS * sizeof(format_arg[0]));
     memset(format_spec, 0, MAXFMTSPECS * sizeof(format_spec[0]));
 
-    while (*format != '\0') {
+    while (*format != L'\0') {
 	switch (*format++) {
-	case '^':
+	case L'^':
 	    // Switch to a different character rendition
-	    if (*format == '\0') {
+	    if (*format == L'\0') {
 		errno = EINVAL;
 		return -1;
 	    } else {
@@ -877,13 +877,13 @@ int mkchstr_parse (const wchar_t *restrict format,
 	    }
 	    break;
 
-	case '%':
+	case L'%':
 	    // Process a conversion specifier
-	    if (*format == '\0') {
+	    if (*format == L'\0') {
 		errno = EINVAL;
 		return -1;
-	    } else if (*format == '%') {
-		// Ignore "%%" specifier
+	    } else if (*format == L'%') {
+		// Ignore "%%" specifier for now
 		format++;
 	    } else {
 		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?
 		int count = 0;
 
-		while (inspec && *format != '\0') {
-		    wchar_t wc = *format++;
-		    switch (wc) {
-		    case '0':
+		while (inspec && *format != L'\0') {
+		    wchar_t c = *format++;
+		    switch (c) {
+		    case L'0':
 			// Zero flag, or part of numeric count
 			if (count == 0) {
 			    // Zero flag is NOT supported
@@ -907,20 +907,20 @@ int mkchstr_parse (const wchar_t *restrict format,
 			count *= 10;
 			break;
 
-		    case '1':
-		    case '2':
-		    case '3':
-		    case '4':
-		    case '5':
-		    case '6':
-		    case '7':
-		    case '8':
-		    case '9':
+		    case L'1':
+		    case L'2':
+		    case L'3':
+		    case L'4':
+		    case L'5':
+		    case L'6':
+		    case L'7':
+		    case L'8':
+		    case L'9':
 			// Part of some numeric count
-			count = count * 10 + (wc - L'0');
+			count = count * 10 + (c - L'0');
 			break;
 
-		    case '$':
+		    case L'$':
 			// Fixed-position argument
 			if (flag_posn || flag_other || count == 0) {
 			    errno = EINVAL;
@@ -937,7 +937,7 @@ int mkchstr_parse (const wchar_t *restrict format,
 			count = 0;
 			break;
 
-		    case '\'':
+		    case L'\'':
 			// Use locale-specific thousands group separator
 			if (format_spec->flag_group) {
 			    errno = EINVAL;
@@ -948,7 +948,7 @@ int mkchstr_parse (const wchar_t *restrict format,
 			flag_other = true;
 			break;
 
-		    case '!':
+		    case L'!':
 			// Omit the locale-specific currency symbol
 			if (format_spec->flag_nosym) {
 			    errno = EINVAL;
@@ -959,7 +959,7 @@ int mkchstr_parse (const wchar_t *restrict format,
 			flag_other = true;
 			break;
 
-		    case '.':
+		    case L'.':
 			// Precision flag
 			if (format_spec->flag_prec || count != 0) {
 			    errno = EINVAL;
@@ -970,7 +970,7 @@ int mkchstr_parse (const wchar_t *restrict format,
 			flag_other = true;
 			break;
 
-		    case 'l':
+		    case L'l':
 			// Long length modifier
 			if (format_spec->flag_long) {
 			    // "ll" is NOT supported
@@ -982,7 +982,7 @@ int mkchstr_parse (const wchar_t *restrict format,
 			flag_other = true;
 			break;
 
-		    case 'c':
+		    case L'c':
 			// Insert a character (char or wchar_t)
 			if (format_spec->flag_group || format_spec->flag_nosym
 			    || format_spec->flag_prec || count != 0) {
@@ -994,7 +994,7 @@ int mkchstr_parse (const wchar_t *restrict format,
 			    TYPE_WCHAR : TYPE_CHAR;
 			goto handlefmt;
 
-		    case 'd':
+		    case L'd':
 			// Insert an integer (int or long int)
 			if (format_spec->flag_nosym || format_spec->flag_prec
 			    || count != 0) {
@@ -1006,7 +1006,7 @@ int mkchstr_parse (const wchar_t *restrict format,
 			    TYPE_LONGINT : TYPE_INT;
 			goto handlefmt;
 
-		    case 'f':
+		    case L'f':
 			// Insert a floating-point number (double)
 			if (format_spec->flag_nosym || format_spec->flag_long ||
 			    (! format_spec->flag_prec && count != 0)) {
@@ -1019,7 +1019,7 @@ int mkchstr_parse (const wchar_t *restrict format,
 			arg_type = TYPE_DOUBLE;
 			goto handlefmt;
 
-		    case 'N':
+		    case L'N':
 			// Insert a monetary amount (double)
 			if (format_spec->flag_group || format_spec->flag_prec
 			    || format_spec->flag_long || count != 0) {
@@ -1030,7 +1030,7 @@ int mkchstr_parse (const wchar_t *restrict format,
 			arg_type = TYPE_DOUBLE;
 			goto handlefmt;
 
-		    case 's':
+		    case L's':
 			// Insert a string (const char * or const wchar_t *)
 			if (format_spec->flag_group || format_spec->flag_nosym
 			    || 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->arg_num = arg_num;
-			format_spec->spec = wc;
+			format_spec->spec = c;
 
 			arg_num++;
 			num_args = MAX(num_args, arg_num);
@@ -1147,11 +1147,11 @@ int mkchstr_add (wchar_t *restrict *restrict outbuf,
 	*line = 0;
     }
 
-    if (**str == '\n') {
+    if (**str == L'\n') {
 	// Start a new line
 
 	if (*line < maxlines - 1) {
-	    *(*outbuf)++ = '\n';
+	    *(*outbuf)++ = L'\n';
 	    *(*attrbuf)++ = 0;
 	    (*count)--;
 	}
@@ -1180,7 +1180,7 @@ int mkchstr_add (wchar_t *restrict *restrict outbuf,
 		// Break on the last space in this line
 		wspc = wcwidth(**lastspc);
 
-		**lastspc = '\n';
+		**lastspc = L'\n';
 		**spcattr = 0;
 
 		widthbuf[*line] = *widthspc;
@@ -1194,7 +1194,7 @@ int mkchstr_add (wchar_t *restrict *restrict outbuf,
 	    } else {
 		// Insert a new-line character (if not on last line)
 		if (*line < maxlines - 1) {
-		    *(*outbuf)++ = '\n';
+		    *(*outbuf)++ = L'\n';
 		    *(*attrbuf)++ = 0;
 		    (*count)--;
 		}
@@ -1212,7 +1212,7 @@ int mkchstr_add (wchar_t *restrict *restrict outbuf,
 		   will ever have combining diacritical marks following a
 		   (line-breaking) space! */
 		while (iswspace(**str)) {
-		    if (*(*str)++ == '\n') {
+		    if (*(*str)++ == L'\n') {
 			break;
 		    }
 		}
@@ -1257,7 +1257,7 @@ void mkchstr_conv (chtype *restrict chbuf, int chbufsize,
     while (! done) {
 	// Make sure we always have enough space for ending shift sequence
 	memcpy(&mbcopy, &mbstate, sizeof(mbstate));
-	endsize = wcrtomb(endbuf, '\0', &mbcopy);
+	endsize = wcrtomb(endbuf, L'\0', &mbcopy);
 	if (endsize == (size_t) -1) {
 	    errno_exit(_("mkchstr_conv: NUL"));
 	}
@@ -1285,7 +1285,7 @@ void mkchstr_conv (chtype *restrict chbuf, int chbufsize,
 	    break;
 	}
 
-	done = (*wcbuf == '\0');
+	done = (*wcbuf == L'\0');
 	wcbuf++;
 	attrbuf++;
     }
@@ -1352,15 +1352,15 @@ int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
     spcattr = NULL;			// Equivalent in attrbuf
     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) {
-	case '^':
+	case L'^':
 	    // Switch to a different character rendition
-	    if (*++wcformat == '\0') {
+	    if (*++wcformat == L'\0') {
 		goto error_inval;
 	    } else {
 		switch (*wcformat) {
-		case '^':
+		case L'^':
 		    if (mkchstr_add(&outbuf, &attrbuf, &count, curattr,
 				    maxlines, maxwidth, &line, &width,
 				    &lastspc, &spcattr, &widthspc, widthbuf,
@@ -1369,18 +1369,18 @@ int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
 		    }
 		    break;
 
-		case '{':
+		case L'{':
 		    curattr = attr_alt1;
 		    wcformat++;
 		    break;
 
-		case '[':
+		case L'[':
 		    curattr = attr_alt2;
 		    wcformat++;
 		    break;
 
-		case '}':
-		case ']':
+		case L'}':
+		case L']':
 		    curattr = attr_norm;
 		    wcformat++;
 		    break;
@@ -1391,11 +1391,11 @@ int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
 	    }
 	    break;
 
-	case '%':
+	case L'%':
 	    // Process a conversion specifier
-	    if (*++wcformat == '\0') {
+	    if (*++wcformat == L'\0') {
 		goto error_inval;
-	    } else if (*wcformat == '%') {
+	    } else if (*wcformat == L'%') {
 		if (mkchstr_add(&outbuf, &attrbuf, &count, curattr, maxlines,
 				maxwidth, &line, &width, &lastspc, &spcattr,
 				&widthspc, widthbuf, widthbufsize, &wcformat)
@@ -1408,7 +1408,7 @@ int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
 		wint_t wc;
 
 		switch (spec->spec) {
-		case 'c':
+		case L'c':
 		    // Insert a character (char or wchar_t) into the output
 		    if (spec->flag_long) {
 			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);
 		    }
 
-		    if (wc == '\0' || wc == WEOF) {
+		    if (wc == L'\0' || wc == WEOF) {
 			wc = EILSEQ_REPL_WC;
 		    }
 
 		    fmtbuf[0] = wc;
-		    fmtbuf[1] = '\0';
+		    fmtbuf[1] = L'\0';
 
 		    str = fmtbuf;
 		    goto insertstr;
 
-		case 'd':
+		case L'd':
 		    // Insert an integer (int or long int) into the output
 		    if (spec->flag_long) {
 			if (swprintf(fmtbuf, BUFSIZE, spec->flag_group ?
@@ -1443,7 +1443,7 @@ int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
 		    str = fmtbuf;
 		    goto insertstr;
 
-		case 'f':
+		case L'f':
 		    // Insert a floating-point number (double) into the output
 		    if (spec->flag_prec) {
 			if (swprintf(fmtbuf, BUFSIZE, spec->flag_group ?
@@ -1460,7 +1460,7 @@ int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
 		    str = fmtbuf;
 		    goto insertstr;
 
-		case 'N':
+		case L'N':
 		    // Insert a monetary amount (double) into the output
 		    {
 			/* strfmon() is not available in a wide-char
@@ -1482,7 +1482,7 @@ int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
 		    str = fmtbuf;
 		    goto insertstr;
 
-		case 's':
+		case L's':
 		    // Insert a string (const char * or const wchar_t *)
 		    if (spec->flag_long) {
 			str = format_arg[spec->arg_num].a.a_wstring;
@@ -1502,7 +1502,7 @@ int vmkchstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
 
 		insertstr:
 		    // 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,
 					maxlines, maxwidth, &line, &width,
 					&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;
 
     if (line >= 0 && line < maxlines) {
@@ -1578,7 +1578,7 @@ int leftch (WINDOW *win, int y, int x, const chtype *restrict chstr,
     assert(widthbuf != NULL);
 
     wmove(win, y, x);
-    for ( ; *chstr != '\0'; chstr++) {
+    for ( ; *chstr != 0; chstr++) {
 	if (*chstr == '\n') {
 	    wmove(win, getcury(win) + 1, x);
 	} else {
@@ -1605,7 +1605,7 @@ int centerch (WINDOW *win, int y, int offset, const chtype *restrict chstr,
     assert(widthbuf != NULL);
 
     wmove(win, y, (getmaxx(win) - widthbuf[ln]) / 2 + offset);
-    for ( ; *chstr != '\0'; chstr++) {
+    for ( ; *chstr != 0; chstr++) {
 	if (*chstr == '\n') {
 	    if (ln++ >= lines) {
 		return ERR;
@@ -1637,7 +1637,7 @@ int rightch (WINDOW *win, int y, int x, const chtype *restrict chstr,
     assert(widthbuf != NULL);
 
     wmove(win, y, x - widthbuf[ln]);
-    for ( ; *chstr != '\0'; chstr++) {
+    for ( ; *chstr != 0; chstr++) {
 	if (*chstr == '\n') {
 	    if (ln++ >= lines) {
 		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,
-		int clen, int width, int len)
+void cpos_end (const wchar_t *restrict buf, int *restrict cpos,
+	       int *restrict st, int clen, int width, int len)
 {
     *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,
-		int w, int width)
+void cpos_dec (const wchar_t *restrict buf, int *restrict cpos,
+	       int *restrict st, int w, int width)
 {
     if (*cpos > 0) {
 	// 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,
-		int w, int width)
+void cpos_inc (const wchar_t *restrict buf, int *restrict cpos,
+	       int *restrict st, int w, int width)
 {
     if (*cpos + w <= width - 1) {
 	// 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
-    cpos_endl(buf, &cpos, &st, clen, width, len);
+    cpos_end(buf, &cpos, &st, clen, width, len);
 
     redraw = true;
     done = false;
@@ -1996,7 +1996,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
 			     buf);
 		}
 
-		cpos_endl(buf, &cpos, &st, clen, width, len);
+		cpos_end(buf, &cpos, &st, clen, width, len);
 
 		mod = true;
 		redraw = true;
@@ -2020,7 +2020,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
 		    pos++;
 
 		    clen += w;
-		    cpos_incr(buf, &cpos, &st, w, width);
+		    cpos_inc(buf, &cpos, &st, w, width);
 
 		    mod = true;
 		    redraw = true;
@@ -2113,7 +2113,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
 		    beep();
 		} else {
 		    pos--;
-		    cpos_decr(buf, &cpos, &st, wcwidth(buf[pos]), width);
+		    cpos_dec(buf, &cpos, &st, wcwidth(buf[pos]), width);
 		    redraw = true;
 		}
 		break;
@@ -2125,7 +2125,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
 		    beep();
 		} else {
 		    pos++;
-		    cpos_incr(buf, &cpos, &st, wcwidth(buf[pos - 1]), width);
+		    cpos_inc(buf, &cpos, &st, wcwidth(buf[pos - 1]), width);
 		    redraw = true;
 		}
 		break;
@@ -2143,7 +2143,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
 	    case KEY_CTRL('E'):
 		// Move cursor to end of string
 		pos = len;
-		cpos_endl(buf, &cpos, &st, clen, width, len);
+		cpos_end(buf, &cpos, &st, clen, width, len);
 		redraw = true;
 		break;
 
@@ -2151,7 +2151,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
 		// Move cursor to start of current or previous word
 		while (pos > 0 && ! iswalnum(buf[pos - 1])) {
 		    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])
 				   || (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
 		       alphanumeric character as alphanumeric. */
 		    pos--;
-		    cpos_decr(buf, &cpos, &st, wcwidth(buf[pos]), width);
+		    cpos_dec(buf, &cpos, &st, wcwidth(buf[pos]), width);
 		}
 		redraw = true;
 		break;
@@ -2168,14 +2168,14 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
 		// Move cursor to end of current or next word
 		while (pos < len && ! iswalnum(buf[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
 		       && (iswalnum(buf[pos]) || wcwidth(buf[pos]) == 0)) {
 		    /* Treat zero-width characters following an
 		       alphanumeric character as alphanumeric. */
 		    pos++;
-		    cpos_incr(buf, &cpos, &st, wcwidth(buf[pos - 1]), width);
+		    cpos_inc(buf, &cpos, &st, wcwidth(buf[pos - 1]), width);
 		}
 		redraw = true;
 		break;
@@ -2194,7 +2194,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
 		    len--;
 		    pos--;
 		    clen -= w;
-		    cpos_decr(buf, &cpos, &st, w, width);
+		    cpos_dec(buf, &cpos, &st, w, width);
 		    mod = true;
 		    redraw = true;
 		}
@@ -2282,13 +2282,13 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
 			i--;
 			int w = wcwidth(buf[i]);
 			ww += w;
-			cpos_decr(buf, &cpos, &st, w, width);
+			cpos_dec(buf, &cpos, &st, w, width);
 		    }
 		    while (i > 0 && ! iswspace(buf[i - 1])) {
 			i--;
 			int w = wcwidth(buf[i]);
 			ww += w;
-			cpos_decr(buf, &cpos, &st, w, width);
+			cpos_dec(buf, &cpos, &st, w, width);
 		    }
 
 		    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;
 
 		    pos++;
-		    cpos_incr(buf, &cpos, &st, w, width);
+		    cpos_inc(buf, &cpos, &st, w, width);
 
 		    mod = 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
 			    while (pos > 0 && ! iswalnum(buf[pos - 1])) {
 				pos--;
-				cpos_decr(buf, &cpos, &st, wcwidth(buf[pos]),
+				cpos_dec(buf, &cpos, &st, wcwidth(buf[pos]),
 					  width);
 			    }
 			    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
 				   alphanumeric character as alphanumeric. */
 				pos--;
-				cpos_decr(buf, &cpos, &st, wcwidth(buf[pos]),
+				cpos_dec(buf, &cpos, &st, wcwidth(buf[pos]),
 					  width);
 			    }
 			    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
 			    while (pos < len && ! iswalnum(buf[pos])) {
 				pos++;
-				cpos_incr(buf, &cpos, &st,
+				cpos_inc(buf, &cpos, &st,
 					  wcwidth(buf[pos - 1]), width);
 			    }
 			    while (pos < len
@@ -2388,7 +2388,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
 				/* Treat zero-width characters following an
 				   alphanumeric character as alphanumeric. */
 				pos++;
-				cpos_incr(buf, &cpos, &st,
+				cpos_inc(buf, &cpos, &st,
 					  wcwidth(buf[pos - 1]), width);
 			    }
 			    redraw = true;
@@ -2436,7 +2436,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
 				    pos--;
 				    int w = wcwidth(buf[pos]);
 				    ww += w;
-				    cpos_decr(buf, &cpos, &st, w, width);
+				    cpos_dec(buf, &cpos, &st, w, width);
 				}
 				while (i < len && iswspace(buf[i])) {
 				    i++;
@@ -2461,7 +2461,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
 
 					int w = wcwidth(c);
 					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
 			    while (pos < len && ! iswalnum(buf[pos])) {
 				pos++;
-				cpos_incr(buf, &cpos, &st,
+				cpos_inc(buf, &cpos, &st,
 					  wcwidth(buf[pos - 1]), width);
 			    }
 			    while (pos < len
@@ -2485,7 +2485,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
 				       || wcwidth(buf[pos]) == 0)) {
 				buf[pos] = towupper(buf[pos]);
 				pos++;
-				cpos_incr(buf, &cpos, &st,
+				cpos_inc(buf, &cpos, &st,
 					  wcwidth(buf[pos - 1]), width);
 			    }
 			    mod = true;
@@ -2497,7 +2497,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
 			    // Convert word (from cursor onwards) to lower case
 			    while (pos < len && ! iswalnum(buf[pos])) {
 				pos++;
-				cpos_incr(buf, &cpos, &st,
+				cpos_inc(buf, &cpos, &st,
 					  wcwidth(buf[pos - 1]), width);
 			    }
 			    while (pos < len
@@ -2505,7 +2505,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
 				       || wcwidth(buf[pos]) == 0)) {
 				buf[pos] = towlower(buf[pos]);
 				pos++;
-				cpos_incr(buf, &cpos, &st,
+				cpos_inc(buf, &cpos, &st,
 					  wcwidth(buf[pos - 1]), width);
 			    }
 			    mod = true;
@@ -2520,7 +2520,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
 				bool first = true;
 				while (pos < len && ! iswalnum(buf[pos])) {
 				    pos++;
-				    cpos_incr(buf, &cpos, &st,
+				    cpos_inc(buf, &cpos, &st,
 					      wcwidth(buf[pos - 1]), width);
 				}
 				while (pos < len
@@ -2533,7 +2533,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
 					buf[pos] = towlower(buf[pos]);
 				    }
 				    pos++;
-				    cpos_incr(buf, &cpos, &st,
+				    cpos_inc(buf, &cpos, &st,
 					      wcwidth(buf[pos - 1]), width);
 				}
 				mod = true;
@@ -2564,7 +2564,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
 				i--;
 				int w = wcwidth(buf[i]);
 				ww += w;
-				cpos_decr(buf, &cpos, &st, w, width);
+				cpos_dec(buf, &cpos, &st, w, width);
 			    }
 			    while (i > 0
 				   && (iswalnum(buf[i - 1])
@@ -2575,7 +2575,7 @@ int gettxline (WINDOW *win, wchar_t *restrict buf, int bufsize,
 				i--;
 				int w = wcwidth(buf[i]);
 				ww += w;
-				cpos_decr(buf, &cpos, &st, w, width);
+				cpos_dec(buf, &cpos, &st, w, width);
 			    }
 
 			    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
     if (*bufptr == NULL) {
 	*bufptr = xmalloc(BUFSIZE * sizeof(wchar_t));
-	**bufptr = '\0';
+	**bufptr = L'\0';
     }
 
     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
 
-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(dest != NULL);
 
     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
     if (isfloat) {
diff --git a/src/intf.h b/src/intf.h
index ede44af..ebdb70d 100644
--- a/src/intf.h
+++ b/src/intf.h
@@ -597,7 +597,7 @@ extern int gettxchar (WINDOW *win, wint_t *wch);
               attr       - Character rendition to use for input field
   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
   the keyboard and places it into the preallocated buffer buf[] of size
   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
   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).
 
   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.
 
   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.
 */
 extern int gettxstr (WINDOW *win, wchar_t *restrict *restrict bufptr,
diff --git a/src/move.c b/src/move.c
index 81ee522..5e5271a 100644
--- a/src/move.c
+++ b/src/move.c
@@ -263,7 +263,7 @@ selection_t get_move (void)
 		    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) {
 			found = true;
 			selection = i;
@@ -282,13 +282,13 @@ selection_t get_move (void)
 
 		if (! found) {
 		    switch (key) {
-		    case '1':
+		    case L'1':
 			curs_set(CURS_OFF);
 			show_status(current_player);
 			curs_set(CURS_ON);
 			break;
 
-		    case '2':
+		    case L'2':
 			selection = SEL_BANKRUPT;
 
 			curs_set(CURS_OFF);
@@ -297,7 +297,7 @@ selection_t get_move (void)
 			     _("^{<2>^} (Declare bankruptcy)"));
 			break;
 
-		    case '3':
+		    case L'3':
 			selection = SEL_SAVE;
 
 			curs_set(CURS_OFF);
@@ -396,12 +396,12 @@ selection_t get_move (void)
 
 		    if (gettxchar(curwin, &key) == OK) {
 			// Ordinary wide character
-			if (key >= '1' && key <= '9') {
+			if (key >= L'1' && key <= L'9') {
 			    left(curwin, getcury(curwin), getcurx(curwin),
 				 A_BOLD, 0, 0, 1, "%lc", key);
 			    wrefresh(curwin);
 
-			    choice = key - '0';
+			    choice = key - L'0';
 			    done = true;
 			} else {
 			    beep();
@@ -504,13 +504,13 @@ void process_move (selection_t selection)
 
 	assign_vals(x, y, left, right, up, down);
 
-	if (left == MAP_EMPTY && right == MAP_EMPTY &&
-	    up   == MAP_EMPTY && down  == MAP_EMPTY) {
+	if (   left == MAP_EMPTY && right == MAP_EMPTY
+	    && up   == MAP_EMPTY && down  == MAP_EMPTY) {
 	    // The position is out in the middle of nowhere...
 	    galaxy_map[x][y] = MAP_OUTPOST;
 
-	} else if (! IS_MAP_COMPANY(left)  && ! IS_MAP_COMPANY(right)
-		   && ! IS_MAP_COMPANY(up) && ! IS_MAP_COMPANY(down)) {
+	} else if (   ! IS_MAP_COMPANY(left) && ! IS_MAP_COMPANY(right)
+		   && ! IS_MAP_COMPANY(up)   && ! IS_MAP_COMPANY(down)) {
 	    // See if a company can be established
 	    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 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 *
 	company[aa].share_return;
     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
     for (int i = 0; i < MAX_COMPANIES; i++) {
 	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
 		+ ((double) player[current_player].stock_owned[i]
 		   / company[i].stock_issued) * company[i].share_price
diff --git a/src/trader.c b/src/trader.c
index 3d3c227..96b85a8 100644
--- a/src/trader.c
+++ b/src/trader.c
@@ -248,8 +248,8 @@ void process_cmdline (int argc, char *argv[])
 
     if (optind < argc && argv[optind] != NULL) {
 	if (*argv[optind] == '-') {
-	    fprintf(stderr, _("%s: invalid operand `%s'\n"), program_name,
-		    argv[optind]);
+	    fprintf(stderr, _("%s: invalid operand `%s'\n"),
+		    program_name, argv[optind]);
 	    show_usage(EXIT_FAILURE);
 	}
 
diff --git a/src/utils.c b/src/utils.c
index 1558b73..39abf31 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -83,7 +83,7 @@ static bool add_currency_symbol = false;	// Do we need to add "$"?
 /***********************************************************************/
 // 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
        character encoding (such as ASCII or UTF-8). */
@@ -109,7 +109,7 @@ const char *home_directory (void)
 {
     if (home_directory_str == NULL) {
 	// Use the HOME environment variable where possible
-	char *home = getenv("HOME");
+	const char *home = getenv("HOME");
 
 	if (home != NULL && *home != '\0') {
 	    home_directory_str = xstrdup(home);
@@ -354,7 +354,7 @@ void init_locale (void)
 /***********************************************************************/
 // 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)
 {
     /* 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_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 (strstr(format, "!") == NULL) {
@@ -382,7 +382,7 @@ ssize_t l_strfmon (char *restrict s, size_t maxsize,
 	    assert(maxsize > (unsigned int) symlen);
 
 	    // Count number of leading spaces
-	    for (p = s, spc = 0; *p == ' '; p++, spc++)
+	    for (p = buf, spc = 0; *p == ' '; p++, spc++)
 		;
 
 	    if (symlen <= spc) {
@@ -394,12 +394,12 @@ ssize_t l_strfmon (char *restrict s, size_t maxsize,
 	    } else {
 		// Make space for currency symbol, then copy it
 
-		memmove(s + symlen - spc, s, maxsize - (symlen - spc));
-		s[maxsize - 1] = '\0';
+		memmove(buf + symlen - spc, buf, maxsize - (symlen - spc));
+		buf[maxsize - 1] = '\0';
 
-		for ( ; *sym != '\0'; sym++, s++) {
+		for ( ; *sym != '\0'; sym++, buf++) {
 		    // Make sure terminating NUL character is NOT copied!
-		    *s = *sym;
+		    *buf = *sym;
 		}
 
 		ret = MIN((unsigned int) ret + symlen - spc, maxsize - 1);
diff --git a/src/utils.h b/src/utils.h
index adfcc8c..1174edf 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -70,7 +70,7 @@ extern wchar_t *mon_thousands_sep;	// Local monetary thousands separator
 
 /*
   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)
 
   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
   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
-  Parameters: s         - Buffer to receive result
+  Parameters: buf       - Buffer to receive result
               maxsize   - Maximum size of buffer
               format    - strfmon() format to use
 	      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
   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);