}
/* Convert to wide characters */
- state->curpos = my_mbstowcs(&state->wbuf, &state->wbuflen, from, buf);
+ state->curpos = mutt_mb_mbstowcs(&state->wbuf, &state->wbuflen, from, buf);
if (savelen)
{
{
/* Initialise wbuf from buf */
state->wbuflen = 0;
- state->lastchar = my_mbstowcs(&state->wbuf, &state->wbuflen, 0, buf);
+ state->lastchar = mutt_mb_mbstowcs(&state->wbuf, &state->wbuflen, 0, buf);
redraw = MUTT_REDRAW_INIT;
}
/* Go to end of line */
state->curpos = state->lastchar;
state->begin =
- width_ceiling(state->wbuf, state->lastchar,
- my_wcswidth(state->wbuf, state->lastchar) - width + 1);
+ mutt_mb_width_ceiling(state->wbuf, state->lastchar,
+ mutt_mb_wcswidth(state->wbuf, state->lastchar) - width + 1);
}
if (state->curpos < state->begin ||
- my_wcswidth(state->wbuf + state->begin, state->curpos - state->begin) >= width)
- state->begin = width_ceiling(state->wbuf, state->lastchar,
- my_wcswidth(state->wbuf, state->curpos) - width / 2);
+ mutt_mb_wcswidth(state->wbuf + state->begin, state->curpos - state->begin) >= width)
+ state->begin = mutt_mb_width_ceiling(state->wbuf, state->lastchar,
+ mutt_mb_wcswidth(state->wbuf, state->curpos) - width / 2);
mutt_window_move(MuttMessageWindow, 0, col);
w = 0;
for (i = state->begin; i < state->lastchar; i++)
{
- w += my_wcwidth(state->wbuf[i]);
+ w += mutt_mb_wcwidth(state->wbuf[i]);
if (w > width)
break;
my_addwch(state->wbuf[i]);
}
mutt_window_clrtoeol(MuttMessageWindow);
mutt_window_move(MuttMessageWindow, 0,
- col + my_wcswidth(state->wbuf + state->begin,
+ col + mutt_mb_wcswidth(state->wbuf + state->begin,
state->curpos - state->begin));
}
mutt_refresh();
state->curpos = state->lastchar;
if (mutt_history_at_scratch(hclass))
{
- my_wcstombs(buf, buflen, state->wbuf, state->curpos);
+ mutt_mb_wcstombs(buf, buflen, state->wbuf, state->curpos);
mutt_history_save_scratch(hclass, buf);
}
replace_part(state, 0, mutt_history_prev(hclass));
state->curpos = state->lastchar;
if (mutt_history_at_scratch(hclass))
{
- my_wcstombs(buf, buflen, state->wbuf, state->curpos);
+ mutt_mb_wcstombs(buf, buflen, state->wbuf, state->curpos);
mutt_history_save_scratch(hclass, buf);
}
replace_part(state, 0, mutt_history_next(hclass));
if (flags & MUTT_EFILE)
{
first = 1; /* clear input if user types a real key later */
- my_wcstombs(buf, buflen, state->wbuf, state->curpos);
+ mutt_mb_wcstombs(buf, buflen, state->wbuf, state->curpos);
mutt_buffy(buf, buflen);
state->curpos = state->lastchar =
- my_mbstowcs(&state->wbuf, &state->wbuflen, 0, buf);
+ mutt_mb_mbstowcs(&state->wbuf, &state->wbuflen, 0, buf);
break;
}
else if (!(flags & MUTT_FILE))
state->tabs++;
if (flags & MUTT_CMD)
{
- for (i = state->curpos; i && !is_shell_char(state->wbuf[i - 1]); i--)
+ for (i = state->curpos; i && !mutt_mb_is_shell_char(state->wbuf[i - 1]); i--)
;
- my_wcstombs(buf, buflen, state->wbuf + i, state->curpos - i);
+ mutt_mb_wcstombs(buf, buflen, state->wbuf + i, state->curpos - i);
if (tempbuf && templen == state->lastchar - i &&
!memcmp(tempbuf, state->wbuf + i, (state->lastchar - i) * sizeof(wchar_t)))
{
;
for (; i < state->lastchar && state->wbuf[i] == ' '; i++)
;
- my_wcstombs(buf, buflen, state->wbuf + i, state->curpos - i);
+ mutt_mb_wcstombs(buf, buflen, state->wbuf + i, state->curpos - i);
r = mutt_alias_complete(buf, buflen);
replace_part(state, i, buf);
if (!r)
;
for (; i < state->lastchar && state->wbuf[i] == ' '; i++)
;
- my_wcstombs(buf, buflen, state->wbuf + i, state->curpos - i);
+ mutt_mb_wcstombs(buf, buflen, state->wbuf + i, state->curpos - i);
r = mutt_label_complete(buf, buflen, state->tabs);
replace_part(state, i, buf);
if (!r)
if (i && i < state->curpos && state->wbuf[i - 1] == '~' && state->wbuf[i] == 'y')
{
i++;
- my_wcstombs(buf, buflen, state->wbuf + i, state->curpos - i);
+ mutt_mb_wcstombs(buf, buflen, state->wbuf + i, state->curpos - i);
r = mutt_label_complete(buf, buflen, state->tabs);
replace_part(state, i, buf);
if (!r)
;
}
- my_wcstombs(buf, buflen, state->wbuf + i, state->curpos - i);
+ mutt_mb_wcstombs(buf, buflen, state->wbuf + i, state->curpos - i);
mutt_query_complete(buf, buflen);
replace_part(state, i, buf);
}
else if (flags & MUTT_COMMAND)
{
- my_wcstombs(buf, buflen, state->wbuf, state->curpos);
+ mutt_mb_wcstombs(buf, buflen, state->wbuf, state->curpos);
i = strlen(buf);
if (i && buf[i - 1] == '=' && mutt_var_value_complete(buf, buflen, i))
state->tabs = 0;
}
else if (flags & (MUTT_FILE | MUTT_EFILE))
{
- my_wcstombs(buf, buflen, state->wbuf, state->curpos);
+ mutt_mb_wcstombs(buf, buflen, state->wbuf, state->curpos);
/* see if the path has changed from the last time */
if ((!tempbuf && !state->lastchar) ||
#ifdef USE_NOTMUCH
else if (flags & MUTT_NM_QUERY)
{
- my_wcstombs(buf, buflen, state->wbuf, state->curpos);
+ mutt_mb_wcstombs(buf, buflen, state->wbuf, state->curpos);
i = strlen(buf);
if (!mutt_nm_query_complete(buf, buflen, i, state->tabs))
BEEP();
}
else if (flags & MUTT_NM_TAG)
{
- my_wcstombs(buf, buflen, state->wbuf, state->curpos);
+ mutt_mb_wcstombs(buf, buflen, state->wbuf, state->curpos);
i = strlen(buf);
if (!mutt_nm_tag_complete(buf, buflen, i, state->tabs))
BEEP();
if (wc == '\r' || wc == '\n')
{
/* Convert from wide characters */
- my_wcstombs(buf, buflen, state->wbuf, state->lastchar);
+ mutt_mb_wcstombs(buf, buflen, state->wbuf, state->lastchar);
if (!pass)
mutt_history_add(hclass, buf, true);
}
else
{
- if (get_initials(mutt_get_name(hdr->env->from), buf2, sizeof(buf2)))
+ if (mutt_mb_get_initials(mutt_get_name(hdr->env->from), buf2, sizeof(buf2)))
{
colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_AUTHOR);
mutt_format_s(dest + colorlen, destlen - colorlen, prefix, buf2);
* | :--------------- | :--------------------------------------------------
* | #ReplacementChar | When a Unicode character can't be displayed, use this instead
*
- * | Function | Description
- * | :-------------- | :---------------------------------------------------------
- * | get_initials() | Turn a name into initials
- * | is_shell_char() | Is character not typically part of a pathname
- * | mutt_charlen() | Count the bytes in a (multibyte) character
- * | my_mbstowcs() | Convert a string from multibyte to wide characters
- * | my_wcstombs() | Convert a string from wide to multibyte characters
- * | my_wcswidth() | Measure the screen width of a string
- * | my_wcwidth() | Measure the screen width of a character
- * | my_width() | Measure a string's display width (in screen columns)
- * | width_ceiling() | Keep the end of the string on-screen
+ * | Function | Description
+ * | :---------------------- | :---------------------------------------------------------
+ * | mutt_mb_charlen() | Count the bytes in a (multibyte) character
+ * | mutt_mb_get_initials() | Turn a name into initials
+ * | mutt_mb_is_shell_char() | Is character not typically part of a pathname
+ * | mutt_mb_mbstowcs() | Convert a string from multibyte to wide characters
+ * | mutt_mb_wcstombs() | Convert a string from wide to multibyte characters
+ * | mutt_mb_wcswidth() | Measure the screen width of a string
+ * | mutt_mb_wcwidth() | Measure the screen width of a character
+ * | mutt_mb_width() | Measure a string's display width (in screen columns)
+ * | mutt_mb_width_ceiling() | Keep the end of the string on-screen
*/
#include "config.h"
wchar_t ReplacementChar = '?';
/**
- * mutt_charlen - Count the bytes in a (multibyte) character
+ * mutt_mb_charlen - Count the bytes in a (multibyte) character
* @param[in] s String to be examined
* @param[out] width Number of screen columns the character would use
* @retval n Number of bytes in the first (multibyte) character of input consumes
* @retval =0 End of input
* @retval >0 Length (bytes)
*/
-int mutt_charlen(const char *s, int *width)
+int mutt_mb_charlen(const char *s, int *width)
{
wchar_t wc;
mbstate_t mbstate;
}
/**
- * get_initials - Turn a name into initials
+ * mutt_mb_get_initials - Turn a name into initials
* @param name String to be converted
* @param buf Buffer for the result
* @param buflen Size of the buffer
* The function saves the first character from each word. Words are delimited
* by whitespace, or hyphens (so "Jean-Pierre" becomes "JP").
*/
-bool get_initials(const char *name, char *buf, int buflen)
+bool mutt_mb_get_initials(const char *name, char *buf, int buflen)
{
if (!name || !buf)
return false;
while (*name)
{
/* Char's length in bytes */
- int clen = mutt_charlen(name, NULL);
+ int clen = mutt_mb_charlen(name, NULL);
if (clen < 1)
return false;
/* Skip to end-of-word */
for (; *name; name += clen)
{
- clen = mutt_charlen(name, NULL);
+ clen = mutt_mb_charlen(name, NULL);
if (clen < 1)
return false;
else if ((clen == 1) && (isspace(*name) || (*name == '-')))
}
/**
- * my_width - Measure a string's display width (in screen columns)
+ * mutt_mb_width - Measure a string's display width (in screen columns)
* @param str String to measure
* @param col Display column (used for expanding tabs)
* @param display will this be displayed to the user?
*
* This is like wcwidth(), but gets const char* not wchar_t*.
*/
-int my_width(const char *str, int col, bool display)
+int mutt_mb_width(const char *str, int col, bool display)
{
wchar_t wc;
int l, w = 0, nl = 0;
}
/**
- * my_wcwidth - Measure the screen width of a character
+ * mutt_mb_wcwidth - Measure the screen width of a character
* @param wc Character to examine
* @retval int Width in screen columns
*/
-int my_wcwidth(wchar_t wc)
+int mutt_mb_wcwidth(wchar_t wc)
{
int n = wcwidth(wc);
if (IsWPrint(wc) && n > 0)
}
/**
- * my_wcswidth - Measure the screen width of a string
+ * mutt_mb_wcswidth - Measure the screen width of a string
* @param s String to measure
* @param n Length of string in characters
* @retval int Width in screen columns
*/
-int my_wcswidth(const wchar_t *s, size_t n)
+int mutt_mb_wcswidth(const wchar_t *s, size_t n)
{
int w = 0;
while (n--)
- w += my_wcwidth(*s++);
+ w += mutt_mb_wcwidth(*s++);
return w;
}
/**
- * width_ceiling - Keep the end of the string on-screen
+ * mutt_mb_width_ceiling - Keep the end of the string on-screen
* @param s String being displayed
* @param n Length of string in characters
* @param w1 Width limit
* Given a string and a width, determine how many characters from the
* beginning of the string should be skipped so that the string fits.
*/
-size_t width_ceiling(const wchar_t *s, size_t n, int w1)
+size_t mutt_mb_width_ceiling(const wchar_t *s, size_t n, int w1)
{
const wchar_t *s0 = s;
int w = 0;
for (; n; s++, n--)
- if ((w += my_wcwidth(*s)) > w1)
+ if ((w += mutt_mb_wcwidth(*s)) > w1)
break;
return s - s0;
}
/**
- * my_wcstombs - Convert a string from wide to multibyte characters
+ * mutt_mb_wcstombs - Convert a string from wide to multibyte characters
* @param dest Buffer for the result
* @param dlen Length of the result buffer
* @param src Source string to convert
* @param slen Length of the source string
*/
-void my_wcstombs(char *dest, size_t dlen, const wchar_t *src, size_t slen)
+void mutt_mb_wcstombs(char *dest, size_t dlen, const wchar_t *src, size_t slen)
{
mbstate_t st;
size_t k;
}
/**
- * my_mbstowcs - Convert a string from multibyte to wide characters
+ * mutt_mb_mbstowcs - Convert a string from multibyte to wide characters
* @param pwbuf Buffer for the result
* @param pwbuflen Length of the result buffer
* @param i Starting index into the result buffer
* @param buf String to convert
* @retval size_t First character after the result
*/
-size_t my_mbstowcs(wchar_t **pwbuf, size_t *pwbuflen, size_t i, char *buf)
+size_t mutt_mb_mbstowcs(wchar_t **pwbuf, size_t *pwbuflen, size_t i, char *buf)
{
wchar_t wc;
mbstate_t st;
}
/**
- * is_shell_char - Is character not typically part of a pathname
+ * mutt_mb_is_shell_char - Is character not typically part of a pathname
* @param ch Character to examine
* @retval true Character is not typically part of a pathname
* @retval false Character is typically part of a pathname
*
* @note The name is very confusing.
*/
-bool is_shell_char(wchar_t ch)
+bool mutt_mb_is_shell_char(wchar_t ch)
{
static const wchar_t shell_chars[] = L"<>&()$?*;{}| "; /* ! not included because it can be part of a pathname in NeoMutt */
return wcschr(shell_chars, ch) != NULL;
#define IsWPrint(wc) (iswprint(wc) || (OPT_LOCALES ? 0 : (wc >= 0xa0)))
#endif
-bool get_initials(const char *name, char *buf, int buflen);
-bool is_shell_char(wchar_t ch);
-int mutt_charlen(const char *s, int *width);
-size_t my_mbstowcs(wchar_t **pwbuf, size_t *pwbuflen, size_t i, char *buf);
-void my_wcstombs(char *dest, size_t dlen, const wchar_t *src, size_t slen);
-int my_wcswidth(const wchar_t *s, size_t n);
-int my_wcwidth(wchar_t wc);
-int my_width(const char *str, int col, bool display);
-size_t width_ceiling(const wchar_t *s, size_t n, int w1);
+int mutt_mb_charlen(const char *s, int *width);
+bool mutt_mb_get_initials(const char *name, char *buf, int buflen);
+bool mutt_mb_is_shell_char(wchar_t ch);
+size_t mutt_mb_mbstowcs(wchar_t **pwbuf, size_t *pwbuflen, size_t i, char *buf);
+void mutt_mb_wcstombs(char *dest, size_t dlen, const wchar_t *src, size_t slen);
+int mutt_mb_wcswidth(const wchar_t *s, size_t n);
+int mutt_mb_wcwidth(wchar_t wc);
+size_t mutt_mb_width_ceiling(const wchar_t *s, size_t n, int w1);
+int mutt_mb_width(const char *str, int col, bool display);
#endif /* _MUTT_MBYTE_H */
* %*X: right justify to EOL, right takes precedence */
int soft = ch == '*';
int pl, pw;
- pl = mutt_charlen(src, &pw);
+ pl = mutt_mb_charlen(src, &pw);
if (pl <= 0)
pl = pw = 1;
{
/* pad to EOL */
int pl, pw, c;
- pl = mutt_charlen(src, &pw);
+ pl = mutt_mb_charlen(src, &pw);
if (pl <= 0)
pl = pw = 1;
{
int tmp, w;
/* in case of error, simply copy byte */
- tmp = mutt_charlen(src, &w);
+ tmp = mutt_mb_charlen(src, &w);
if (tmp < 0)
tmp = w = 1;
if (tmp > 0 && wlen + tmp < destlen)
/* determine width: character cells for display, bytes for sending
* (we get pure ascii only) */
- w = my_width(buf, col, display);
+ w = mutt_mb_width(buf, col, display);
enc = (mutt_strncmp(buf, "=?", 2) == 0);
mutt_debug(5, "mwoh: word=[%s], col=%d, w=%d, next=[0x0%x]\n", buf, col, w, *next);
/* find maximum line width in current header */
if (p)
*p = 0;
- w = my_width(line, 0, display);
+ w = mutt_mb_width(line, 0, display);
if (w > max)
max = w;
if (p)