X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=sbr%2Ffmt_scan.c;h=b212b1264dd04846cb49320a60e3baa3777c0f1c;hb=0569d6d1631dc90d4f2f2df6bdd0599c7ecc7814;hp=b27f7c6c9f259fa7108f6eb802678e4cc4abb4e5;hpb=6af0c8bb08f8c36e7106ba87f00164b1df3d2774;p=mmh diff --git a/sbr/fmt_scan.c b/sbr/fmt_scan.c index b27f7c6..b212b12 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 } } @@ -343,11 +359,12 @@ fmt_scan (struct format *format, char *scanl, int width, int *dat) case FT_NUM: n = snprintf(cp, ep - cp + 1, "%d", value); - if (n >= 0) + if (n >= 0) { if (n >= ep - cp) { cp = ep; } else cp += n; + } break; case FT_NUMF: cpnumber (&cp, value, fmt->f_width, fmt->f_fill, ep - cp);