X-Git-Url: https://git.deb.at/w?a=blobdiff_plain;f=misc.c;h=4bfe3d353cd710f5a5abb4f54fead49c16b888b0;hb=8e362f5a1e900ad2cd11192436b5182e8b0e6ef6;hp=df853bca38674d56851cf349769dfc50ba388a3e;hpb=109ae8e74de4ebce6098900d2c23f666bba2bc63;p=pkg%2Fabook.git diff --git a/misc.c b/misc.c index df853bc..4bfe3d3 100644 --- a/misc.c +++ b/misc.c @@ -19,6 +19,9 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif +#ifdef HANDLE_MULTIBYTE +# include +#endif #include "misc.h" #ifdef ABOOK_SRC # include "abook.h" @@ -265,6 +268,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