/**************************************************************************
* utils.c *
* *
- * Copyright (C) 1999-2004 Chris Allegretta *
+ * Copyright (C) 1999-2005 Chris Allegretta *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2, or (at your option) *
(*col)++;
wide_str = control_rep((unsigned char)wide_str);
- if (wctomb(ctrl_wide_str, (wchar_t)wide_str) != -1)
- *col += wcwidth(wide_str);
+ if (wctomb(ctrl_wide_str, (wchar_t)wide_str) != -1) {
+ int width = wcwidth(wide_str);
+
+ if (width != -1)
+ *col += width;
+ }
else
(*col)++;
free(ctrl_wide_str);
/* If we have a normal character, get its width in columns
* normally. */
- } else
- *col += wcwidth(wide_str);
+ } else {
+ int width = wcwidth(wide_str);
+
+ if (width != -1)
+ *col += width;
+ }
}
} else {
#endif
if (bad_wide_buf_len != -1)
retval += bad_wide_buf_len;
- else
- retval++;
free(bad_wide_buf);
} else {
wide_buf = control_rep((unsigned char)wide_buf);
#ifdef NANO_WIDE
- if (!ISSET(NO_UTF8)) {
+ if (!ISSET(NO_UTF8))
ctrl_wide_buf_len = wctomb(ctrl_wide_buf,
(wchar_t)wide_buf);
-
- if (ctrl_wide_buf_len == -1) {
- ctrl_wide_buf_len = 1;
- ctrl_wide_buf[0] = ' ';
- }
- } else {
+ else {
#endif
ctrl_wide_buf_len = 1;
ctrl_wide_buf[0] = (unsigned char)wide_buf;
free(ctrl_wide_buf);
- start_col++;
+#ifdef NANO_WIDE
+ if (!ISSET(NO_UTF8)) {
+ int width = wcwidth((wchar_t)wide_buf);
+
+ if (width != -1)
+ start_col += width;
+ } else
+#endif
+ start_col++;
+
start_index += wide_buf_len;
}
- } else if (wcwidth(wide_buf) > 1) {
+ }
+#ifdef NANO_WIDE
+ else if (wcwidth((wchar_t)wide_buf) > 1) {
/* If dollars is TRUE, make room for the "$" at the
* beginning of the line. Also make sure that we don't try
* to display only part of a multicolumn character there. */
start_col++;
start_index += wide_buf_len;
}
+#endif
}
while (index < alloc_len && buf[start_index] != '\0') {
wide_buf = control_rep((unsigned char)wide_buf);
#ifdef NANO_WIDE
- if (!ISSET(NO_UTF8)) {
+ if (!ISSET(NO_UTF8))
ctrl_wide_buf_len = wctomb(ctrl_wide_buf,
(wchar_t)wide_buf);
-
- if (ctrl_wide_buf_len == -1) {
- ctrl_wide_buf_len = 1;
- ctrl_wide_buf[0] = ' ';
- }
- } else {
+ else {
#endif
ctrl_wide_buf_len = 1;
ctrl_wide_buf[0] = (unsigned char)wide_buf;
free(ctrl_wide_buf);
- start_col +=
#ifdef NANO_WIDE
- !ISSET(NO_UTF8) ? wcwidth((wchar_t)wide_buf) :
+ if (!ISSET(NO_UTF8)) {
+ int width = wcwidth((wchar_t)wide_buf);
+
+ if (width != -1)
+ start_col += width;
+ } else
#endif
- 1;
+ start_col++;
} else if (wide_buf == ' ') {
converted[index++] =
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
bad_wide_buf_len = wctomb(bad_wide_buf,
(wchar_t)wide_buf);
- if (bad_wide_buf_len == -1) {
- bad_wide_buf_len = 1;
- bad_wide_buf[0] = ' ';
- }
-
for (i = 0; i < bad_wide_buf_len; i++)
converted[index++] = bad_wide_buf[i];
#ifdef NANO_WIDE
}
- if (!ISSET(NO_UTF8))
- start_col += wcwidth((wchar_t)wide_buf);
- else
+ if (!ISSET(NO_UTF8)) {
+ int width = wcwidth((wchar_t)wide_buf);
+
+ if (width != -1)
+ start_col += width;
+ } else
#endif
start_col++;
}