X-Git-Url: https://git.deb.at/?a=blobdiff_plain;f=misc.c;h=a44c9d2f96a7bfafe721d95120c8c64acfb2cc76;hb=b1b41dce461ab21ae9a2bd26d7a00a381a5f81f8;hp=df853bca38674d56851cf349769dfc50ba388a3e;hpb=6e541862e5e10bbc7e71dcafa4ff60f19272c66f;p=pkg%2Fabook.git diff --git a/misc.c b/misc.c index df853bc..a44c9d2 100644 --- a/misc.c +++ b/misc.c @@ -19,6 +19,10 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif +#ifdef HANDLE_MULTIBYTE +# include +# include "mbswidth.h" +#endif #include "misc.h" #ifdef ABOOK_SRC # include "abook.h" @@ -265,6 +269,28 @@ getaline(FILE *f) return buf; } +int +strwidth(const char *s) +{ + assert(s); +#ifdef HANDLE_MULTIBYTE + return (int)mbswidth(s, 0); +#else + return strlen(s); +#endif +} + +int +bytes2width(const char *s, int width) +{ + assert(s); +#ifdef HANDLE_MULTIBYTE + return mbsnbytes(s, strlen(s), width, 0); +#else + return width; +#endif +} + /************************************************************** * Original: * Patrick Powell Tue Apr 11 09:48:21 PDT 1995