- five custom fields added
- experimental wide character support
- fixed a crash bug in mutt filter
+ - fixed errors in configure.in (especially snprintf-functions were incorrectly
+ detected)
0.5.1
- sort by field command
abook_SOURCES = abook.c database.c filter.c list.c misc.c \
options.c edit.c ldif.c ui.c getname.c \
- getopt.c getopt1.c abook_rl.c \
+ getopt.c getopt1.c abook_rl.c mbswidth.c \
abook.h database.h filter.h list.h misc.h help.h \
options.h edit.h ldif.h abook_curses.h ui.h getname.h \
- getopt.h abook_rl.h
+ getopt.h abook_rl.h mbswidth.h
EXTRA_DIST = ANNOUNCE BUGS FAQ abook.1 abookrc.5 sample.abookrc abook.spec
abook_SOURCES = abook.c database.c filter.c list.c misc.c \
options.c edit.c ldif.c ui.c getname.c \
- getopt.c getopt1.c abook_rl.c \
+ getopt.c getopt1.c abook_rl.c mbswidth.c \
abook.h database.h filter.h list.h misc.h help.h \
options.h edit.h ldif.h abook_curses.h ui.h getname.h \
- getopt.h abook_rl.h
+ getopt.h abook_rl.h mbswidth.h
EXTRA_DIST = ANNOUNCE BUGS FAQ abook.1 abookrc.5 sample.abookrc abook.spec
am_abook_OBJECTS = abook.$(OBJEXT) database.$(OBJEXT) filter.$(OBJEXT) \
list.$(OBJEXT) misc.$(OBJEXT) options.$(OBJEXT) edit.$(OBJEXT) \
ldif.$(OBJEXT) ui.$(OBJEXT) getname.$(OBJEXT) getopt.$(OBJEXT) \
- getopt1.$(OBJEXT) abook_rl.$(OBJEXT)
+ getopt1.$(OBJEXT) abook_rl.$(OBJEXT) mbswidth.$(OBJEXT)
abook_OBJECTS = $(am_abook_OBJECTS)
abook_LDADD = $(LDADD)
abook_DEPENDENCIES =
@AMDEP_TRUE@ ./$(DEPDIR)/filter.Po ./$(DEPDIR)/getname.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/getopt.Po ./$(DEPDIR)/getopt1.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/ldif.Po ./$(DEPDIR)/list.Po \
-@AMDEP_TRUE@ ./$(DEPDIR)/misc.Po ./$(DEPDIR)/options.Po \
-@AMDEP_TRUE@ ./$(DEPDIR)/ui.Po
+@AMDEP_TRUE@ ./$(DEPDIR)/mbswidth.Po ./$(DEPDIR)/misc.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/options.Po ./$(DEPDIR)/ui.Po
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt1.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldif.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbswidth.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/options.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ui.Po@am__quote@
-
+ - grouping
- new file format (xml?)
- custom views, keybindings
#ifdef HANDLE_MULTIBYTE
# include <wchar.h>
+# include <mbswidth.h>
#endif
#define RL_READLINE_NAME "Abook"
static int
rline_calc_point()
{
- char *p;
- int ret = 0;
-
- mbtowc(NULL, NULL, 0);
- for(p = rl_line_buffer;(p - rl_line_buffer) < rl_point;) {
- int a, l;
- wchar_t wc;
-
- if((a = mbtowc(&wc, p, MB_CUR_MAX)) == 0)
- break;
- else if (a == -1)
- return rl_point; /* fall back */
- else
- p += a;
-
- l = wcwidth(wc);
- if(l > 0)
- ret += l;
- }
-
- return ret;
+ return (int)mbsnwidth(rl_line_buffer, rl_point, 0);
}
#endif
/* Handle multibyte characters */
#undef HANDLE_MULTIBYTE
+/* Define to 1 if you have the declaration of `wcwidth', and to 0 if you
+ don't. */
+#undef HAVE_DECL_WCWIDTH
+
/* Define to 1 if you have the <history.h> header file. */
#undef HAVE_HISTORY_H
/* Define to 1 if you have the <locale.h> header file. */
#undef HAVE_LOCALE_H
+/* Define to 1 if you have the `mbrtowc' function. */
+#undef HAVE_MBRTOWC
+
+/* Define to 1 if you have the `mbsinit' function. */
+#undef HAVE_MBSINIT
+
/* Define to 1 if you have the `mbtowc' function. */
#undef HAVE_MBTOWC
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
-/* Define if you have the <ncurses.h> header file. */
-#undef HAVE_NCURSES
-
/* Define to 1 if you have the <ncurses.h> header file. */
#undef HAVE_NCURSES_H
/* Define to 1 if you have the `setlocale' function. */
#undef HAVE_SETLOCALE
-/* Define if snprintf is available. */
+/* Define to 1 if you have the `snprintf' function. */
#undef HAVE_SNPRINTF
/* Define if you have the <stdarg.h> header file. */
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
-/* Define if vsnprintf is available. */
+/* Define to 1 if you have the `vsnprintf' function. */
#undef HAVE_VSNPRINTF
+/* Define if you have the <wchar.h> header file. */
+#undef HAVE_WCHAR_H
+
/* Define to 1 if you have the `wcwidth' function. */
#undef HAVE_WCWIDTH
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--disable-dependency-tracking Speeds up one-time builds
--enable-dependency-tracking Do not reject slow dependency extractors
- --enable-widec Enable wide character support (experimental)
--enable-debug Enable debugging support
Optional Packages:
-cat >>confdefs.h <<\_ACEOF
-#define HAVE_SNPRINTF 0
-_ACEOF
-
-
-cat >>confdefs.h <<\_ACEOF
-#define HAVE_VSNPRINTF 0
-_ACEOF
-
-
-cat >>confdefs.h <<\_ACEOF
-#define HAVE_STDARG_H 0
-_ACEOF
-
-
-cat >>confdefs.h <<\_ACEOF
-#define HAVE_NCURSES 0
-_ACEOF
-
-
# Make sure we can run config.sub.
$ac_config_sub sun4 >/dev/null 2>&1 ||
{ { echo "$as_me:$LINENO: error: cannot run $ac_config_sub" >&5
fi
if test $ac_cv_header_stdarg_h = yes; then
- cat >>confdefs.h <<\_ACEOF
+
+cat >>confdefs.h <<\_ACEOF
#define HAVE_STDARG_H 1
_ACEOF
fi
if test $ac_cv_header_wchar_h = yes; then
- ac_have_wchar_h=yes
+
+ ac_have_wchar_h=yes
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_WCHAR_H 1
+_ACEOF
+
else
ac_have_wchar_h=no
fi
-for ac_func in mbtowc wcwidth
+
+
+for ac_func in mbtowc wcwidth mbrtowc mbsinit
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_func" >&5
fi
done
+echo "$as_me:$LINENO: checking whether wcwidth is declared" >&5
+echo $ECHO_N "checking whether wcwidth is declared... $ECHO_C" >&6
+if test "${ac_cv_have_decl_wcwidth+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_includes_default
+int
+main ()
+{
+#ifndef wcwidth
+ char *p = (char *) wcwidth;
+#endif
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_have_decl_wcwidth=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_have_decl_wcwidth=no
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_have_decl_wcwidth" >&5
+echo "${ECHO_T}$ac_cv_have_decl_wcwidth" >&6
+if test $ac_cv_have_decl_wcwidth = yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_WCWIDTH 1
+_ACEOF
+
+
+else
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_WCWIDTH 0
+_ACEOF
+
+
+fi
+
+
echo "$as_me:$LINENO: checking for wchar_t" >&5
echo $ECHO_N "checking for wchar_t... $ECHO_C" >&6
if test "${ac_cv_type_wchar_t+set}" = set; then
ac_widec_possible=no
fi
-# Check whether --enable-widec or --disable-widec was given.
-if test "${enable_widec+set}" = set; then
- enableval="$enable_widec"
- case "${enableval}" in
- yes) ac_widec_support=true ;;
- no) ac_widec_support=false ;;
- *) { { echo "$as_me:$LINENO: error: bad value ${enableval} for --enable-widec" >&5
-echo "$as_me: error: bad value ${enableval} for --enable-widec" >&2;}
- { (exit 1); exit 1; }; } ;;
- esac
-else
- ac_widec_support=false
-fi;
-
-if test x$ac_widec_support = xtrue -a x$ac_widec_possible != xyes; then
- { { echo "$as_me:$LINENO: error: Wide character support is not possible due to missing wide character functions or wchar.h" >&5
-echo "$as_me: error: Wide character support is not possible due to missing wide character functions or wchar.h" >&2;}
- { (exit 1); exit 1; }; }
-fi
-
abook_cv_curses=/usr
fi
fi;
-if test x$ac_widec_support = xtrue; then
- echo "$as_me:$LINENO: checking for initscr in -lncursesw" >&5
+echo "$as_me:$LINENO: checking for initscr in -lncursesw" >&5
echo $ECHO_N "checking for initscr in -lncursesw... $ECHO_C" >&6
if test "${ac_cv_lib_ncursesw_initscr+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
echo "${ECHO_T}$ac_cv_lib_ncursesw_initscr" >&6
if test $ac_cv_lib_ncursesw_initscr = yes; then
LIBS="$LIBS -lncursesw"
- if test x$abook_cv_curses = x/usr -a -d /usr/include/ncursesw; then
- CPPFLAGS="$CPPFLAGS -I/usr/include/ncursesw"
- fi
+ if test x$abook_cv_curses = x/usr -a -d /usr/include/ncursesw; then
+ CPPFLAGS="$CPPFLAGS -I/usr/include/ncursesw"
+ fi
for ac_header in ncurses.h
do
else
- { { echo "$as_me:$LINENO: error: \"Wide character support is not possible due to missing ncursesw library. Please install it or disable wide character support\"" >&5
-echo "$as_me: error: \"Wide character support is not possible due to missing ncursesw library. Please install it or disable wide character support\"" >&2;}
- { (exit 1); exit 1; }; }
-fi
-
-else
+ ac_widec_possible=no
echo "$as_me:$LINENO: checking for initscr in -lncurses" >&5
echo $ECHO_N "checking for initscr in -lncurses... $ECHO_C" >&6
if test "${ac_cv_lib_ncurses_initscr+set}" = set; then
fi
+
fi
+
abook_cv_readline=/usr
# Check whether --with-readline or --without-readline was given.
fi
-if test x$ac_widec_support = xtrue; then
+if test x$ac_widec_possible = xyes; then
cat >>confdefs.h <<\_ACEOF
#define HANDLE_MULTIBYTE 1
done
-echo "$as_me:$LINENO: checking for snprintf" >&5
-echo $ECHO_N "checking for snprintf... $ECHO_C" >&6
-if test "${ac_cv_func_snprintf+set}" = set; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-else
- cat >conftest.$ac_ext <<_ACEOF
-#line $LINENO "configure"
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-/* System header to define __stub macros and hopefully few prototypes,
- which can conflict with char snprintf (); below.
- Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
- <limits.h> exists even on freestanding compilers. */
-#ifdef __STDC__
-# include <limits.h>
-#else
-# include <assert.h>
-#endif
-/* Override any gcc2 internal prototype to avoid an error. */
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-/* We use char because int might match the return type of a gcc2
- builtin and then its argument prototype would still apply. */
-char snprintf ();
-/* The GNU C library defines this for functions which it implements
- to always fail with ENOSYS. Some functions are actually named
- something starting with __ and the normal name is an alias. */
-#if defined (__stub_snprintf) || defined (__stub___snprintf)
-choke me
-#else
-char (*f) () = snprintf;
-#endif
-#ifdef __cplusplus
-}
-#endif
-int
-main ()
-{
-return f != snprintf;
- ;
- return 0;
-}
-_ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
- (eval $ac_link) 2>&5
- ac_status=$?
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } &&
- { ac_try='test -s conftest$ac_exeext'
- { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
- (eval $ac_try) 2>&5
- ac_status=$?
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); }; }; then
- ac_cv_func_snprintf=yes
-else
- echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-ac_cv_func_snprintf=no
-fi
-rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
-fi
-echo "$as_me:$LINENO: result: $ac_cv_func_snprintf" >&5
-echo "${ECHO_T}$ac_cv_func_snprintf" >&6
-if test $ac_cv_func_snprintf = yes; then
- cat >>confdefs.h <<\_ACEOF
-#define HAVE_SNPRINTF 1
-_ACEOF
-
-fi
-
-echo "$as_me:$LINENO: checking for vsnprintf" >&5
-echo $ECHO_N "checking for vsnprintf... $ECHO_C" >&6
-if test "${ac_cv_func_vsnprintf+set}" = set; then
+for ac_func in snprintf vsnprintf
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
+if eval "test \"\${$as_ac_var+set}\" = set"; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
cat >conftest.$ac_ext <<_ACEOF
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
/* System header to define __stub macros and hopefully few prototypes,
- which can conflict with char vsnprintf (); below.
+ which can conflict with char $ac_func (); below.
Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
<limits.h> exists even on freestanding compilers. */
#ifdef __STDC__
#endif
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
-char vsnprintf ();
+char $ac_func ();
/* The GNU C library defines this for functions which it implements
to always fail with ENOSYS. Some functions are actually named
something starting with __ and the normal name is an alias. */
-#if defined (__stub_vsnprintf) || defined (__stub___vsnprintf)
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
choke me
#else
-char (*f) () = vsnprintf;
+char (*f) () = $ac_func;
#endif
#ifdef __cplusplus
}
int
main ()
{
-return f != vsnprintf;
+return f != $ac_func;
;
return 0;
}
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
- ac_cv_func_vsnprintf=yes
+ eval "$as_ac_var=yes"
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
-ac_cv_func_vsnprintf=no
+eval "$as_ac_var=no"
fi
rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
fi
-echo "$as_me:$LINENO: result: $ac_cv_func_vsnprintf" >&5
-echo "${ECHO_T}$ac_cv_func_vsnprintf" >&6
-if test $ac_cv_func_vsnprintf = yes; then
- cat >>confdefs.h <<\_ACEOF
-#define HAVE_VSNPRINTF 1
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+ cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF
fi
+done
# Check whether --enable-debug or --disable-debug was given.
AM_INIT_AUTOMAKE(abook, 0.5.2pre)
AM_CONFIG_HEADER(config.h)
-AC_DEFINE(HAVE_SNPRINTF, 0, [Define if snprintf is available.])
-AC_DEFINE(HAVE_VSNPRINTF, 0, [Define if vsnprintf is available.])
-AC_DEFINE(HAVE_STDARG_H, 0, [Define if you have the <stdarg.h> header file.])
-AC_DEFINE(HAVE_NCURSES, 0, [Define if you have the <ncurses.h> header file.])
+dnl AC_DEFINE(HAVE_STDARG_H, 0, [Define if you have the <stdarg.h> header file.])
+dnl AC_DEFINE(HAVE_NCURSES_H, 0, [Define if you have the <ncurses.h> header file.])
AC_CANONICAL_HOST
AC_PROG_INSTALL
AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h locale.h termios.h linux/termios.h sys/ioctl.h)
-AC_CHECK_HEADER(stdarg.h,AC_DEFINE(HAVE_STDARG_H),AC_MSG_ERROR([*** stdarg.h is missing on your system ***]))
+AC_CHECK_HEADER(stdarg.h,AC_DEFINE(HAVE_STDARG_H, 1, [Define if you have the <stdarg.h> header file.]),AC_MSG_ERROR([*** stdarg.h is missing on your system ***]))
AC_FUNC_STRCOLL
AC_CHECK_FUNCS(setlocale)
ac_widec_funcs=yes
-AC_CHECK_HEADER(wchar.h,[ac_have_wchar_h=yes], [ac_have_wchar_h=no])
-AC_CHECK_FUNCS(mbtowc wcwidth,,ac_widec_funcs=no)
+AC_CHECK_HEADER(wchar.h,[
+ ac_have_wchar_h=yes
+ AC_DEFINE(HAVE_WCHAR_H, 1, [Define if you have the <wchar.h> header file.])],
+ [ac_have_wchar_h=no])
+AC_CHECK_FUNCS(mbtowc wcwidth mbrtowc mbsinit,,ac_widec_funcs=no)
+AC_CHECK_DECLS(wcwidth)
AC_CHECK_TYPE(wchar_t,,ac_widec_funcs=no)
if test x$ac_widec_funcs = xyes -a x$ac_have_wchar_h = xyes; then
ac_widec_possible=no
fi
-AC_ARG_ENABLE(widec, [ --enable-widec Enable wide character support (experimental) ], [case "${enableval}" in
- yes) ac_widec_support=true ;;
- no) ac_widec_support=false ;;
- *) AC_MSG_ERROR(bad value ${enableval} for --enable-widec) ;;
- esac], [ac_widec_support=false])
-
-if test x$ac_widec_support = xtrue -a x$ac_widec_possible != xyes; then
- AC_MSG_ERROR(Wide character support is not possible due to missing wide character functions or wchar.h)
-fi
-
dnl -------------------
dnl (n)curses detection
dnl -------------------
CPPFLAGS="$CPPFLAGS -I${abook_cv_curses}/include"
fi])
-if test x$ac_widec_support = xtrue; then
- AC_CHECK_LIB(ncursesw, initscr,
- [LIBS="$LIBS -lncursesw"
- if test x$abook_cv_curses = x/usr -a -d /usr/include/ncursesw; then
- CPPFLAGS="$CPPFLAGS -I/usr/include/ncursesw"
- fi
- AC_CHECK_HEADERS(ncurses.h)],[
- AC_MSG_ERROR("Wide character support is not possible due to missing ncursesw library. Please install it or disable wide character support")])
-else
+AC_CHECK_LIB(ncursesw, initscr,
+ [LIBS="$LIBS -lncursesw"
+ if test x$abook_cv_curses = x/usr -a -d /usr/include/ncursesw; then
+ CPPFLAGS="$CPPFLAGS -I/usr/include/ncursesw"
+ fi
+ AC_CHECK_HEADERS(ncurses.h)],[
+ ac_widec_possible=no
AC_CHECK_LIB(ncurses, initscr,
[LIBS="$LIBS -lncurses"
if test x$abook_cv_curses = x/usr -a -d /usr/include/ncurses; then
fi
AC_CHECK_HEADERS(ncurses.h)],
[CF_CURSES_LIBS])
-fi
+ ])
dnl --------------------------
dnl end of (n)curses detection
dnl end of readline detection
dnl -------------------------
-if test x$ac_widec_support = xtrue; then
+if test x$ac_widec_possible = xyes; then
AC_DEFINE(HANDLE_MULTIBYTE, 1, [Handle multibyte characters])
fi
AC_CHECK_FUNCS(resizeterm)
-AC_CHECK_FUNC(snprintf, [AC_DEFINE(HAVE_SNPRINTF)],)
-AC_CHECK_FUNC(vsnprintf, [AC_DEFINE(HAVE_VSNPRINTF)],)
+AC_CHECK_FUNCS(snprintf vsnprintf)
AC_ARG_ENABLE(debug, [ --enable-debug Enable debugging support ], [case "${enableval}" in
yes) debug=true ;;
else
snprintf(header, EDITW_COLS, "%s", database[item][NAME]);
- mvwaddstr(editw, 0, (EDITW_COLS - strlen(header)) / 2,
+ fprintf(stderr, "%d\n", strwidth(header));
+ mvwaddstr(editw, 0, (EDITW_COLS - strwidth(header)) / 2,
header);
free(header);
if(selected[i])
mvwaddch(list, line, 0, '*' );
- mvwaddnstr(list, line, NAMEPOS, database[i][NAME], NAMELEN);
+ mvwaddnstr(list, line, NAMEPOS, database[i][NAME],
+ bytes2width(database[i][NAME], NAMELEN));
if(opt_get_bool(BOOL_SHOW_ALL_EMAILS))
mvwaddnstr(list, line, EMAILPOS, database[i][EMAIL],
- real_emaillen);
+ bytes2width(database[i][EMAIL], real_emaillen));
else {
get_first_email(tmp, i);
- mvwaddnstr(list, line, EMAILPOS, tmp, real_emaillen);
+ mvwaddnstr(list, line, EMAILPOS, tmp,
+ bytes2width(tmp, real_emaillen));
}
if(extra < 0 || !database[i][extra])
extra = extra_alternative;
if(extra >= 0)
mvwaddnstr(list, line, EXTRAPOS,
- safe_str(database[i][extra]),
- EXTRALEN);
+ safe_str(database[i][extra]),
+ bytes2width(safe_str(database[i][extra]), EXTRALEN));
scrollok(list, TRUE);
if(highlight)
refresh_list();
}
-
void
select_none()
{
--- /dev/null
+/* Determine the number of screen columns needed for a string.
+ Copyright (C) 2000-2002 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+/* Written by Bruno Haible <haible@clisp.cons.org>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef HANDLE_MULTIBYTE /* for abook */
+
+/* Specification. */
+#include "mbswidth.h"
+
+/* Get MB_CUR_MAX. */
+#include <stdlib.h>
+
+#include <string.h>
+
+/* Get isprint(). */
+#include <ctype.h>
+
+/* Get mbstate_t, mbrtowc(), mbsinit(), wcwidth(). */
+#if HAVE_WCHAR_H
+# include <wchar.h>
+#endif
+
+/* Get iswprint(), iswcntrl(). */
+#if HAVE_WCTYPE_H
+# include <wctype.h>
+#endif
+#if !defined iswprint && !HAVE_ISWPRINT
+# define iswprint(wc) 1
+#endif
+#if !defined iswcntrl && !HAVE_ISWCNTRL
+# define iswcntrl(wc) 0
+#endif
+
+#ifndef mbsinit
+# if !HAVE_MBSINIT
+# define mbsinit(ps) 1
+# endif
+#endif
+
+#ifndef HAVE_DECL_WCWIDTH
+"this configure-time declaration test was not run"
+#endif
+#if !HAVE_DECL_WCWIDTH
+int wcwidth ();
+#endif
+
+#ifndef wcwidth
+# if !HAVE_WCWIDTH
+/* wcwidth doesn't exist, so assume all printable characters have
+ width 1. */
+# define wcwidth(wc) ((wc) == 0 ? 0 : iswprint (wc) ? 1 : -1)
+# endif
+#endif
+
+/* Get ISPRINT. */
+#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
+# define IN_CTYPE_DOMAIN(c) 1
+#else
+# define IN_CTYPE_DOMAIN(c) isascii(c)
+#endif
+/* Undefine to protect against the definition in wctype.h of solaris2.6. */
+#undef ISPRINT
+#define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
+#undef ISCNTRL
+#define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
+
+/* Returns the number of columns needed to represent the multibyte
+ character string pointed to by STRING. If a non-printable character
+ occurs, and MBSW_REJECT_UNPRINTABLE is specified, -1 is returned.
+ With flags = MBSW_REJECT_INVALID | MBSW_REJECT_UNPRINTABLE, this is
+ the multibyte analogon of the wcswidth function. */
+int
+mbswidth (const char *string, int flags)
+{
+ return mbsnwidth (string, strlen (string), flags);
+}
+
+/* Returns the number of columns needed to represent the multibyte
+ character string pointed to by STRING of length NBYTES. If a
+ non-printable character occurs, and MBSW_REJECT_UNPRINTABLE is
+ specified, -1 is returned. */
+int
+mbsnwidth (const char *string, size_t nbytes, int flags)
+{
+ const char *p = string;
+ const char *plimit = p + nbytes;
+ int width;
+
+ width = 0;
+#if HAVE_MBRTOWC
+ if (MB_CUR_MAX > 1)
+ {
+ while (p < plimit)
+ switch (*p)
+ {
+ case ' ': case '!': case '"': case '#': case '%':
+ case '&': case '\'': case '(': case ')': case '*':
+ case '+': case ',': case '-': case '.': case '/':
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ case ':': case ';': case '<': case '=': case '>':
+ case '?':
+ case 'A': case 'B': case 'C': case 'D': case 'E':
+ case 'F': case 'G': case 'H': case 'I': case 'J':
+ case 'K': case 'L': case 'M': case 'N': case 'O':
+ case 'P': case 'Q': case 'R': case 'S': case 'T':
+ case 'U': case 'V': case 'W': case 'X': case 'Y':
+ case 'Z':
+ case '[': case '\\': case ']': case '^': case '_':
+ case 'a': case 'b': case 'c': case 'd': case 'e':
+ case 'f': case 'g': case 'h': case 'i': case 'j':
+ case 'k': case 'l': case 'm': case 'n': case 'o':
+ case 'p': case 'q': case 'r': case 's': case 't':
+ case 'u': case 'v': case 'w': case 'x': case 'y':
+ case 'z': case '{': case '|': case '}': case '~':
+ /* These characters are printable ASCII characters. */
+ p++;
+ width++;
+ break;
+ default:
+ /* If we have a multibyte sequence, scan it up to its end. */
+ {
+ mbstate_t mbstate;
+ memset (&mbstate, 0, sizeof mbstate);
+ do
+ {
+ wchar_t wc;
+ size_t bytes;
+ int w;
+
+ bytes = mbrtowc (&wc, p, plimit - p, &mbstate);
+
+ if (bytes == (size_t) -1)
+ /* An invalid multibyte sequence was encountered. */
+ {
+ if (!(flags & MBSW_REJECT_INVALID))
+ {
+ p++;
+ width++;
+ break;
+ }
+ else
+ return -1;
+ }
+
+ if (bytes == (size_t) -2)
+ /* An incomplete multibyte character at the end. */
+ {
+ if (!(flags & MBSW_REJECT_INVALID))
+ {
+ p = plimit;
+ width++;
+ break;
+ }
+ else
+ return -1;
+ }
+
+ if (bytes == 0)
+ /* A null wide character was encountered. */
+ bytes = 1;
+
+ w = wcwidth (wc);
+ if (w >= 0)
+ /* A printable multibyte character. */
+ width += w;
+ else
+ /* An unprintable multibyte character. */
+ if (!(flags & MBSW_REJECT_UNPRINTABLE))
+ width += (iswcntrl (wc) ? 0 : 1);
+ else
+ return -1;
+
+ p += bytes;
+ }
+ while (! mbsinit (&mbstate));
+ }
+ break;
+ }
+ return width;
+ }
+#endif
+
+ while (p < plimit)
+ {
+ unsigned char c = (unsigned char) *p++;
+
+ if (ISPRINT (c))
+ width++;
+ else if (!(flags & MBSW_REJECT_UNPRINTABLE))
+ width += (ISCNTRL (c) ? 0 : 1);
+ else
+ return -1;
+ }
+ return width;
+}
+
+int
+mbsnbytes (const char *string, size_t nbytes, int maxwidth, int flags)
+{
+ const char *p = string, *old_p = string;
+ const char *plimit = p + nbytes;
+ int width;
+
+ width = 0;
+#if HAVE_MBRTOWC
+ if (MB_CUR_MAX > 1)
+ {
+ while (p < plimit && width < maxwidth)
+ {
+ old_p = p;
+ switch (*p)
+ {
+ case ' ': case '!': case '"': case '#': case '%':
+ case '&': case '\'': case '(': case ')': case '*':
+ case '+': case ',': case '-': case '.': case '/':
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ case ':': case ';': case '<': case '=': case '>':
+ case '?':
+ case 'A': case 'B': case 'C': case 'D': case 'E':
+ case 'F': case 'G': case 'H': case 'I': case 'J':
+ case 'K': case 'L': case 'M': case 'N': case 'O':
+ case 'P': case 'Q': case 'R': case 'S': case 'T':
+ case 'U': case 'V': case 'W': case 'X': case 'Y':
+ case 'Z':
+ case '[': case '\\': case ']': case '^': case '_':
+ case 'a': case 'b': case 'c': case 'd': case 'e':
+ case 'f': case 'g': case 'h': case 'i': case 'j':
+ case 'k': case 'l': case 'm': case 'n': case 'o':
+ case 'p': case 'q': case 'r': case 's': case 't':
+ case 'u': case 'v': case 'w': case 'x': case 'y':
+ case 'z': case '{': case '|': case '}': case '~':
+ /* These characters are printable ASCII characters. */
+ p++;
+ width++;
+ break;
+ default:
+ /* If we have a multibyte sequence, scan it up to its end. */
+ {
+ mbstate_t mbstate;
+ memset (&mbstate, 0, sizeof mbstate);
+ do
+ {
+ wchar_t wc;
+ size_t bytes;
+ int w;
+
+ bytes = mbrtowc (&wc, p, plimit - p, &mbstate);
+
+ if (bytes == (size_t) -1)
+ /* An invalid multibyte sequence was encountered. */
+ {
+ if (!(flags & MBSW_REJECT_INVALID))
+ {
+ p++;
+ width++;
+ break;
+ }
+ else
+ return -1;
+ }
+
+ if (bytes == (size_t) -2)
+ /* An incomplete multibyte character at the end. */
+ {
+ if (!(flags & MBSW_REJECT_INVALID))
+ {
+ p = plimit;
+ width++;
+ break;
+ }
+ else
+ return -1;
+ }
+
+ if (bytes == 0)
+ /* A null wide character was encountered. */
+ bytes = 1;
+
+ w = wcwidth (wc);
+ if (w >= 0)
+ /* A printable multibyte character. */
+ width += w;
+ else
+ /* An unprintable multibyte character. */
+ if (!(flags & MBSW_REJECT_UNPRINTABLE))
+ width += (iswcntrl (wc) ? 0 : 1);
+ else
+ return -1;
+
+ p += bytes;
+ }
+ while (! mbsinit (&mbstate));
+ }
+ break;
+ }
+ }
+
+ return (width > maxwidth) ? (old_p - string) : (p - string);
+ }
+#endif
+
+ return maxwidth;
+}
+
+#endif /* HANDLE_MULTIBYTE */
--- /dev/null
+/* Determine the number of screen columns needed for a string.
+ Copyright (C) 2000-2002 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#include <stddef.h>
+
+/* Optional flags to influence mbswidth/mbsnwidth behavior. */
+
+/* If this bit is set, return -1 upon finding an invalid or incomplete
+ character. Otherwise, assume invalid characters have width 1. */
+#define MBSW_REJECT_INVALID 1
+
+/* If this bit is set, return -1 upon finding a non-printable character.
+ Otherwise, assume unprintable characters have width 0 if they are
+ control characters and 1 otherwise. */
+#define MBSW_REJECT_UNPRINTABLE 2
+
+/* Returns the number of screen columns needed for STRING. */
+#define mbswidth gnu_mbswidth /* avoid clash with UnixWare 7.1.1 function */
+extern int mbswidth (const char *string, int flags);
+
+/* Returns the number of screen columns needed for the NBYTES bytes
+ starting at BUF. */
+extern int mbsnwidth (const char *buf, size_t nbytes, int flags);
+
+
+extern int mbsnbytes (const char *string, size_t nbytes, int maxwidth, int flags);
+
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
+#ifdef HANDLE_MULTIBYTE
+# include <wchar.h>
+# include "mbswidth.h"
+#endif
#include "misc.h"
#ifdef ABOOK_SRC
# include "abook.h"
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
char *getaline(FILE *f);
+int strwidth(const char *s);
+int bytes2width(const char *s, int width);
+
+
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif