X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Ffmt_scan.c;h=8475d50e3bbebca160269a6a3478673c2dee9a09;hp=b27f7c6c9f259fa7108f6eb802678e4cc4abb4e5;hb=c0591ef34ea123aa8c709bda122308256d2c84cd;hpb=6af0c8bb08f8c36e7106ba87f00164b1df3d2774 diff --git a/sbr/fmt_scan.c b/sbr/fmt_scan.c index b27f7c6..8475d50 100644 --- a/sbr/fmt_scan.c +++ b/sbr/fmt_scan.c @@ -25,7 +25,10 @@ # include # endif #endif -#include +#ifdef MULTIBYTE_SUPPORT +# include +# include +#endif #define NFMTS MAXARGS @@ -127,8 +130,10 @@ cptrimmed(char **dest, char *str, unsigned int wid, char fill, size_t n) { int remaining; /* remaining output width available */ int c, ljust, w; int end; /* number of input bytes remaining in str */ +#ifdef MULTIBYTE_SUPPORT int char_len; /* bytes in current character */ wchar_t wide_char; +#endif char *sp; /* current position in source string */ char *cp = *dest; /* current position in destination string */ char *ep = cp + n; /* end of destination buffer */ @@ -144,6 +149,7 @@ cptrimmed(char **dest, char *str, unsigned int wid, char fill, size_t n) { mbtowc(NULL, NULL, 0); /* reset shift state */ end = strlen(str); while (*sp && remaining > 0 && end > 0) { +#ifdef MULTIBYTE_SUPPORT char_len = mbtowc(&wide_char, sp, end); if (char_len <= 0 || (cp + char_len > ep)) break; @@ -152,6 +158,11 @@ cptrimmed(char **dest, char *str, unsigned int wid, char fill, size_t n) { if (iswcntrl(wide_char) || iswspace(wide_char)) { sp += char_len; +#else + end--; + if (iscntrl(*sp) || isspace(*sp)) { + sp++; +#endif if (!prevCtrl) { *cp++ = ' '; remaining--; @@ -162,6 +173,7 @@ cptrimmed(char **dest, char *str, unsigned int wid, char fill, size_t n) { } prevCtrl = 0; +#ifdef MULTIBYTE_SUPPORT w = wcwidth(wide_char); if (w >= 0 && remaining >= w) { strncpy(cp, sp, char_len); @@ -169,6 +181,10 @@ cptrimmed(char **dest, char *str, unsigned int wid, char fill, size_t n) { remaining -= w; } sp += char_len; +#else + *cp++ = *sp++; + remaining--; +#endif } }