]> git.deb.at Git - pkg/abook.git/blobdiff - misc.c
rl_already_prompted check for old ncurses versions
[pkg/abook.git] / misc.c
diff --git a/misc.c b/misc.c
index df853bca38674d56851cf349769dfc50ba388a3e..4bfe3d353cd710f5a5abb4f54fead49c16b888b0 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -19,6 +19,9 @@
 #ifdef HAVE_CONFIG_H
 #      include "config.h"
 #endif
+#ifdef HANDLE_MULTIBYTE
+#      include <mbswidth.h>
+#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