diff options
-rw-r--r-- | INSTALL | 84 | ||||
-rw-r--r-- | Makefile | 128 | ||||
-rw-r--r-- | compat_fgetln.c | 2 | ||||
-rw-r--r-- | compat_fts.c | 2 | ||||
-rw-r--r-- | compat_getsubopt.c | 2 | ||||
-rw-r--r-- | compat_ohash.c | 2 | ||||
-rw-r--r-- | compat_reallocarray.c | 2 | ||||
-rw-r--r-- | compat_sqlite3_errstr.c | 2 | ||||
-rw-r--r-- | compat_strcasestr.c | 2 | ||||
-rw-r--r-- | compat_strlcat.c | 2 | ||||
-rw-r--r-- | compat_strlcpy.c | 2 | ||||
-rw-r--r-- | compat_strsep.c | 2 | ||||
-rw-r--r-- | config.h.post | 42 | ||||
-rw-r--r-- | config.h.pre | 9 | ||||
-rwxr-xr-x | configure | 388 | ||||
-rw-r--r-- | configure.local.example | 189 | ||||
-rw-r--r-- | mandoc.c | 2 | ||||
-rw-r--r-- | mandocdb.c | 4 | ||||
-rw-r--r-- | manpath.c | 2 | ||||
-rw-r--r-- | mansearch.c | 2 | ||||
-rw-r--r-- | preconv.c | 6 | ||||
-rw-r--r-- | read.c | 6 | ||||
-rw-r--r-- | term_ascii.c | 21 | ||||
-rw-r--r-- | test-sqlite3.c | 47 | ||||
-rw-r--r-- | test-wchar.c | 59 |
25 files changed, 747 insertions, 262 deletions
@@ -34,19 +34,51 @@ latest bundled and ported versions of mandoc for various operating systems is maintained at <http://mdocml.bsd.lv/ports.html>. If mandoc is installed, you can check the version by running "mandoc -V". -The version contained in this distribution tarball is listed near -the beginning of the file "Makefile". +You can find the version contained in this distribution tarball +by running "./configure". Regarding how packages and ports are maintained for your operating system, please consult your operating system documentation. To install mandoc manually, the following steps are needed: -1. Decide whether you want to build the base tools mandoc(1), -preconv(1) and demandoc(1) only or whether you also want to build the -database tools apropos(1) and makewhatis(8). For the latter, -the following dependencies are required: +1. If you want to build the CGI program, man.cgi(8), too, run the +command "echo BUILD_CGI=1 > configure.local". -1.1. The SQLite database system, see <http://sqlite.org/>. +2. Run "./configure". +This script attempts autoconfiguration of mandoc for your system. +Read both its standard output and the file "Makefile.local" it +generates. If anything looks wrong or different from what you +wish, read the file "configure.local.example", create and edit +a file "configure.local", and re-run "./configure" until the +result seems right to you. + +3. Run "make". +Any POSIX-compatible make, in particular both BSD make and GNU make, +should work. If the build fails, look at "configure.local.example" +and go back to step 2. + +4. Run "make -n install" and check whether everything will be +installed to the intended places. Otherwise, put some *DIR variables +into "configure.local" and go back to step 2. + +5. Run "sudo make install". If you intend to build a binary +package using some kind of fake root mechanism, you may need a +command like "make DESTDIR=... install". Read the *-install targets +in the "Makefile" to understand how DESTDIR is used. + +6. To set up a man.cgi(8) server, read its manual page. + +7. To use mandoc(1) as your man(1) formatter, read the "Deployment" +section below. + + +Understanding mandoc dependencies +--------------------------------- +The mandoc(1), preconv(1), and demandoc(1) utilities have no external +dependencies. However, makewhatis(8) and apropos(1) depend on the +following software: + +1. The SQLite database system, see <http://sqlite.org/>. The recommended version of SQLite is 3.8.4.3 or newer. The mandoc toolset is known to work with version 3.7.5 or newer. Versions older than 3.8.3 may not achieve full performance due to the @@ -61,41 +93,12 @@ If your system does not have them, the bundled compatibility version will be used, so you need not worry in that case. But be careful: the glibc version of fts(3) is known to be broken on 32bit platforms, see <https://sourceware.org/bugzilla/show_bug.cgi?id=15838>. +If you run into that problem, set "HAVE_FTS=0" in configure.local. 1.3. Marc Espie's ohash(3) library. If your system does not have it, the bundled compatibility version will be used, so you probably need not worry about it. -2. If you choose to build the database tools, too, decide whether -you also want to build the CGI program, man.cgi(8). - -3. Read the beginning of the file "Makefile" from "USER SETTINGS" -to "END OF USER SETTINGS" and edit it as required. In particular, -disable "BUILD_TARGETS += db-build" if you do not want database -support or enable "BUILD_TARGETS += cgi-build" if you do want -the CGI program. - -4. Run "make". No separate "./configure" or "make depend" steps -are needed. The former is run automatically by "make". The latter -is a maintainer target. If you merely want to build the released -version as opposed to doing active development, there is no need -to regenerate the dependency specifications. Any POSIX-compatible -make, in particular both BSD make and GNU make, should work. - -5. Run "make -n install" and check whether everything will be -installed to the intended places. Otherwise, edit the *DIR variables -in the Makefile until it is. - -6. Run "sudo make install". If you intend to build a binary -package using some kind of fake root mechanism, you may need a -command like "make DESTDIR=... install". Read the *-install targets -in the "Makefile" to understand how DESTDIR is used. - -7. To set up a man.cgi(8) server, read its manual page. - -8. To use mandoc(1) as your man(1) formatter, read the "Deployment" -section below. - Checking autoconfiguration quality ---------------------------------- @@ -128,9 +131,9 @@ please report whatever is missing on your platform. The following steps can be used to manually check the automatic configuration on your platform: -1. Run "make clean". +1. Run "make distclean". -2. Run "make config.h" +2. Run "./configure" 3. Read the file "config.log". It shows the compiler commands used to test the libraries installed on your system and the standard @@ -138,8 +141,7 @@ output and standard error output these commands produce. Watch out for unexpected failures. Those are most likely to happen if headers or libraries are installed in unusual places or interfaces defined in unusual headers. You can also look at the file "config.h" and -check that no expected "#define HAVE_*" lines are missing. The -list of tests run can be found in the file "configure". +check that no "#define HAVE_*" differ from your expectations. Deployment @@ -15,106 +15,10 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -VERSION = 1.13.1 - -# === USER SETTINGS ==================================================== - -# --- user settings relevant for all builds ---------------------------- - -# Specify this if you want to hard-code the operating system to appear -# in the lower-left hand corner of -mdoc manuals. -# -# CFLAGS += -DOSNAME="\"OpenBSD 5.5\"" - -# IFF your system supports multi-byte functions (setlocale(), wcwidth(), -# putwchar()) AND has __STDC_ISO_10646__ (that is, wchar_t is simply a -# UCS-4 value) should you define USE_WCHAR. If you define it and your -# system DOESN'T support this, -Tlocale will produce garbage. -# If you don't define it, -Tlocale is a synonym for -Tascii. -# -CFLAGS += -DUSE_WCHAR - -CFLAGS += -g -W -Wall -Wstrict-prototypes -CFLAGS += -Wno-unused-parameter -Wwrite-strings -PREFIX = /usr/local -BINDIR = $(PREFIX)/bin -INCLUDEDIR = $(PREFIX)/include/mandoc -LIBDIR = $(PREFIX)/lib/mandoc -MANDIR = $(PREFIX)/man -EXAMPLEDIR = $(PREFIX)/share/examples/mandoc - -INSTALL = install -INSTALL_PROGRAM = $(INSTALL) -m 0555 -INSTALL_DATA = $(INSTALL) -m 0444 -INSTALL_LIB = $(INSTALL) -m 0444 -INSTALL_SOURCE = $(INSTALL) -m 0644 -INSTALL_MAN = $(INSTALL_DATA) - -# --- user settings related to database support ------------------------ - -# Building apropos(1) and makewhatis(8) requires SQLite3. -# To avoid that dependency, comment the following line. -# -BUILD_TARGETS += db-build - -# The remaining settings in this section -# are only relevant if db-build is enabled. -# Otherwise, they have no effect either way. - -# If your system has manpath(1), uncomment this. This is most any -# system that's not OpenBSD or NetBSD. If uncommented, apropos(1) -# and makewhatis(8) will use manpath(1) to get the MANPATH variable. -# -#CFLAGS += -DUSE_MANPATH - -# On some systems, SQLite3 may be installed below /usr/local. -# In that case, uncomment the following two lines. -# -#CFLAGS += -I/usr/local/include -#DBLIB += -L/usr/local/lib - -# OpenBSD has the ohash functions in libutil. -# Comment the following line if your system doesn't. -# -DBLIB += -lutil - -SBINDIR = $(PREFIX)/sbin - -# --- user settings related to man.cgi --------------------------------- - -# To build man.cgi, copy cgi.h.example to cgi.h, edit it, -# and enable the following line. -# Obviously, this requires that db-build is enabled, too. -# -#BUILD_TARGETS += cgi-build - -# The remaining settings in this section -# are only relevant if cgi-build is enabled. -# Otherwise, they have no effect either way. - -# If your system does not support static binaries, comment this, -# for example on Mac OS X. -# -STATIC = -static - -# Linux requires -pthread for statical linking. -# -#STATIC += -pthread - -WWWPREFIX = /var/www -HTDOCDIR = $(WWWPREFIX)/htdocs -CGIBINDIR = $(WWWPREFIX)/cgi-bin - -# === END OF USER SETTINGS ============================================= - -INSTALL_TARGETS = $(BUILD_TARGETS:-build=-install) - BASEBIN = mandoc preconv demandoc DBBIN = apropos makewhatis CGIBIN = man.cgi -DBLIB += -lsqlite3 - TESTSRCS = test-dirent-namlen.c \ test-fgetln.c \ test-fts.c \ @@ -122,12 +26,14 @@ TESTSRCS = test-dirent-namlen.c \ test-mmap.c \ test-ohash.c \ test-reallocarray.c \ + test-sqlite3.c \ test-sqlite3_errstr.c \ test-strcasestr.c \ test-strlcat.c \ test-strlcpy.c \ test-strptime.c \ - test-strsep.c + test-strsep.c \ + test-wchar.c SRCS = apropos.c \ arch.c \ @@ -204,9 +110,8 @@ DISTFILES = INSTALL \ chars.in \ compat_fts.h \ compat_ohash.h \ - config.h.post \ - config.h.pre \ configure \ + configure.local.example \ demandoc.1 \ eqn.7 \ example.style.css \ @@ -363,9 +268,13 @@ WWW_MANS = apropos.1.html \ WWW_OBJS = mdocml.tar.gz \ mdocml.sha256 +include Makefile.local + +INSTALL_TARGETS = $(BUILD_TARGETS:-build=-install) + # === DEPENDENCY HANDLING ============================================== -all: base-build $(BUILD_TARGETS) +all: base-build $(BUILD_TARGETS) Makefile.local base-build: $(BASEBIN) @@ -381,8 +290,11 @@ include Makefile.depend # === TARGETS CONTAINING SHELL COMMANDS ================================ +distclean: clean + rm -f Makefile.local config.h config.h.old config.log config.log.old + clean: - rm -f libmandoc.a $(LIBMANDOC_OBJS) + rm -f libmandoc.a $(LIBMANDOC_OBJS) $(COMPAT_OBJS) rm -f apropos $(APROPOS_OBJS) rm -f makewhatis $(MAKEWHATIS_OBJS) rm -f preconv $(PRECONV_OBJS) @@ -390,7 +302,6 @@ clean: rm -f manpage $(MANPAGE_OBJS) rm -f demandoc $(DEMANDOC_OBJS) rm -f mandoc $(MANDOC_OBJS) - rm -f config.h config.log $(COMPAT_OBJS) rm -f $(WWW_MANS) $(WWW_OBJS) rm -rf *.dSYM @@ -450,6 +361,10 @@ www-install: www $(INSTALL_DATA) mdocml.sha256 \ $(DESTDIR)$(HTDOCDIR)/snapshots/mdocml-$(VERSION).sha256 +Makefile.local config.h: configure ${TESTSRCS} + @echo "$@ is out of date; please run ./configure" + @exit 1 + depend: config.h mkdep -f Makefile.depend $(CFLAGS) $(SRCS) perl -e 'undef $$/; $$_ = <>; s|/usr/include/\S+||g; \ @@ -485,18 +400,13 @@ mdocml.sha256: mdocml.tar.gz mdocml.tar.gz: $(DISTFILES) mkdir -p .dist/mdocml-$(VERSION)/ - $(INSTALL_SOURCE) $(DISTFILES) .dist/mdocml-$(VERSION) + $(INSTALL) -m 0644 $(DISTFILES) .dist/mdocml-$(VERSION) chmod 755 .dist/mdocml-$(VERSION)/configure ( cd .dist/ && tar zcf ../$@ mdocml-$(VERSION) ) rm -rf .dist/ -config.h: configure config.h.pre config.h.post $(TESTSRCS) - rm -f config.log - CC="$(CC)" CFLAGS="$(CFLAGS)" DBLIB="$(DBLIB)" \ - VERSION="$(VERSION)" ./configure - .PHONY: base-install cgi-install db-install install www-install -.PHONY: clean depend +.PHONY: clean distclean depend .SUFFIXES: .1 .3 .5 .7 .8 .h .SUFFIXES: .1.html .3.html .5.html .7.html .8.html .h.html diff --git a/compat_fgetln.c b/compat_fgetln.c index 667d1f76..3760ab99 100644 --- a/compat_fgetln.c +++ b/compat_fgetln.c @@ -1,6 +1,6 @@ #include "config.h" -#ifdef HAVE_FGETLN +#if HAVE_FGETLN int dummy; diff --git a/compat_fts.c b/compat_fts.c index 6756ad49..08d7628d 100644 --- a/compat_fts.c +++ b/compat_fts.c @@ -1,6 +1,6 @@ #include "config.h" -#ifdef HAVE_FTS +#if HAVE_FTS int dummy; diff --git a/compat_getsubopt.c b/compat_getsubopt.c index 3b22e262..3a4a7d4a 100644 --- a/compat_getsubopt.c +++ b/compat_getsubopt.c @@ -1,6 +1,6 @@ #include "config.h" -#ifdef HAVE_GETSUBOPT +#if HAVE_GETSUBOPT int dummy; diff --git a/compat_ohash.c b/compat_ohash.c index 45c9b6da..cbd60521 100644 --- a/compat_ohash.c +++ b/compat_ohash.c @@ -1,6 +1,6 @@ #include "config.h" -#ifdef HAVE_OHASH +#if HAVE_OHASH int dummy; diff --git a/compat_reallocarray.c b/compat_reallocarray.c index 5fabd0b2..6e96a6ab 100644 --- a/compat_reallocarray.c +++ b/compat_reallocarray.c @@ -1,6 +1,6 @@ #include "config.h" -#ifdef HAVE_REALLOCARRAY +#if HAVE_REALLOCARRAY int dummy; diff --git a/compat_sqlite3_errstr.c b/compat_sqlite3_errstr.c index b4696019..c6238488 100644 --- a/compat_sqlite3_errstr.c +++ b/compat_sqlite3_errstr.c @@ -1,6 +1,6 @@ #include "config.h" -#ifdef HAVE_SQLITE3_ERRSTR +#if HAVE_SQLITE3_ERRSTR int dummy; diff --git a/compat_strcasestr.c b/compat_strcasestr.c index 156cd5d8..0706ee00 100644 --- a/compat_strcasestr.c +++ b/compat_strcasestr.c @@ -1,6 +1,6 @@ #include "config.h" -#ifdef HAVE_STRCASESTR +#if HAVE_STRCASESTR int dummy; diff --git a/compat_strlcat.c b/compat_strlcat.c index 26bddc00..acaae4fb 100644 --- a/compat_strlcat.c +++ b/compat_strlcat.c @@ -1,6 +1,6 @@ #include "config.h" -#ifdef HAVE_STRLCAT +#if HAVE_STRLCAT int dummy; diff --git a/compat_strlcpy.c b/compat_strlcpy.c index ccdf9319..a00d5118 100644 --- a/compat_strlcpy.c +++ b/compat_strlcpy.c @@ -1,6 +1,6 @@ #include "config.h" -#ifdef HAVE_STRLCPY +#if HAVE_STRLCPY int dummy; diff --git a/compat_strsep.c b/compat_strsep.c index 1c7dfef9..348f7ebf 100644 --- a/compat_strsep.c +++ b/compat_strsep.c @@ -1,6 +1,6 @@ #include "config.h" -#ifdef HAVE_STRSEP +#if HAVE_STRSEP int dummy; diff --git a/config.h.post b/config.h.post deleted file mode 100644 index e95f5f53..00000000 --- a/config.h.post +++ /dev/null @@ -1,42 +0,0 @@ -#if !defined(__BEGIN_DECLS) -# ifdef __cplusplus -# define __BEGIN_DECLS extern "C" { -# else -# define __BEGIN_DECLS -# endif -#endif -#if !defined(__END_DECLS) -# ifdef __cplusplus -# define __END_DECLS } -# else -# define __END_DECLS -# endif -#endif - -#ifndef HAVE_FGETLN -extern char *fgetln(FILE *, size_t *); -#endif -#ifndef HAVE_GETSUBOPT -extern int getsubopt(char **, char * const *, char **); -extern char *suboptarg; -#endif -#ifndef HAVE_REALLOCARRAY -extern void *reallocarray(void *, size_t, size_t); -#endif -#ifndef HAVE_SQLITE3_ERRSTR -extern const char *sqlite3_errstr(int); -#endif -#ifndef HAVE_STRCASESTR -extern char *strcasestr(const char *, const char *); -#endif -#ifndef HAVE_STRLCAT -extern size_t strlcat(char *, const char *, size_t); -#endif -#ifndef HAVE_STRLCPY -extern size_t strlcpy(char *, const char *, size_t); -#endif -#ifndef HAVE_STRSEP -extern char *strsep(char **, const char *); -#endif - -#endif /* MANDOC_CONFIG_H */ diff --git a/config.h.pre b/config.h.pre deleted file mode 100644 index 1c3940de..00000000 --- a/config.h.pre +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef MANDOC_CONFIG_H -#define MANDOC_CONFIG_H - -#if defined(__linux__) || defined(__MINT__) -# define _GNU_SOURCE /* getsubopt(), strcasestr(), strptime() */ -#endif - -#include <sys/types.h> -#include <stdio.h> @@ -14,38 +14,378 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -echo "/* RUNNING ./CONFIGURE - SHOULD BE USED ONLY VIA MAKE, READ INSTALL */" - set -e -exec > config.h 2> config.log -CFLAGS="${CFLAGS} -Wno-unused -Werror" +[ -e config.log ] && mv config.log config.log.old +[ -e config.h ] && mv config.h config.h.old + +# Output file descriptor usage: +# 1 (stdout): config.h, Makefile.local +# 2 (stderr): original stderr, usually to the console +# 3: config.log + +exec 3> config.log +echo "config.log: writing..." + +# --- default settings ------------------------------------------------- +# Initialize all variables here, +# such that nothing can leak in from the environment. + +VERSION="1.13.1" +echo "VERSION=\"${VERSION}\"" 1>&2 +echo "VERSION=\"${VERSION}\"" 1>&3 + +OSNAME= + +CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | make -f -` +CFLAGS="-g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings" +DBLIB= +STATIC="-static" + +BUILD_DB=1 +BUILD_CGI=0 + +HAVE_DIRENT_NAMLEN= +HAVE_FGETLN= +HAVE_FTS= +HAVE_GETSUBOPT= +HAVE_MMAP= +HAVE_REALLOCARRAY= +HAVE_STRCASESTR= +HAVE_STRLCAT= +HAVE_STRLCPY= +HAVE_STRPTIME= +HAVE_STRSEP= +HAVE_WCHAR= + +HAVE_SQLITE3= +HAVE_SQLITE3_ERRSTR= +HAVE_OHASH= +HAVE_MANPATH= + +PREFIX="/usr/local" +BINDIR= +SBINDIR= +INCLUDEDIR= +LIBDIR= +MANDIR= +EXAMPLEDIR= + +WWWPREFIX="/var/www" +HTDOCDIR= +CGIBINDIR= + +INSTALL="install" +INSTALL_PROGRAM= +INSTALL_LIB= +INSTALL_MAN= +INSTALL_DATA= + +# --- manual settings from configure.local ----------------------------- + +if [ -e ./configure.local ]; then + echo "configure.local: reading..." 1>&2 + echo "configure.local: reading..." 1>&3 + cat ./configure.local 1>&3 + . ./configure.local +else + echo "configure.local: no (fully automatic configuration)" 1>&2 + echo "configure.local: no (fully automatic configuration)" 1>&3 +fi +echo 1>&3 +# --- tests for config.h ---------------------------------------------- + +COMP="${CC} ${CFLAGS} -Wno-unused -Werror" + +# Check whether this HAVE_ setting is manually overridden. +# If yes, use the override, if no, do not decide anything yet. +# Arguments: lower-case test name, manual value +ismanual() { + [ -z "${2}" ] && return 1 + echo "${1}: manual (${2})" 1>&2 + echo "${1}: manual (${2})" 1>&3 + echo 1>&3 + return 0 +} + +# Run a single autoconfiguration test. +# In case of success, enable the feature. +# In case of failure, do not decide anything yet. +# Arguments: lower-case test name, upper-case test name, additional CFLAGS +singletest() { + cat 1>&3 << __HEREDOC__ +${1}: testing... +${COMP} ${3} -o test-${1} test-${1}.c +__HEREDOC__ + + if ${COMP} ${3} -o "test-${1}" "test-${1}.c" 1>&3 2>&3; then + echo "${1}: ${CC} succeeded" 1>&3 + else + echo "${1}: ${CC} failed with $?" 1>&3 + echo 1>&3 + return 1 + fi + + if ./test-${1} 1>&3 2>&3; then + echo "${1}: yes" 1>&2 + echo "${1}: yes" 1>&3 + echo 1>&3 + eval HAVE_${2}=1 + rm "test-${1}" + return 0 + else + echo "${1}: execution failed with $?" 1>&3 + echo 1>&3 + rm "test-${1}" + return 1 + fi +} + +# Run a complete autoconfiguration test, including the check for +# a manual override and disabling the feature on failure. +# Arguments: lower case name, upper case name, additional CFLAGS runtest() { - echo ${CC} ${CFLAGS} ${3} -o test-${1} test-${1}.c 1>&2 - ${CC} ${CFLAGS} ${3} -o "test-${1}" "test-${1}.c" 1>&2 || return 0 - "./test-${1}" && echo "#define HAVE_${2}" \ - || echo FAILURE: test-${1} returned $? 1>&2 - rm "test-${1}" + eval _manual=\${HAVE_${2}} + ismanual "${1}" "${_manual}" && return 0 + singletest "${1}" "${2}" "${3}" && return 0 + echo "${1}: no" 1>&2 + eval HAVE_${2}=0 + return 1 } -cat config.h.pre +# --- library functions --- +runtest dirent-namlen DIRENT_NAMLEN || true +runtest fgetln FGETLN || true +runtest fts FTS || true +runtest getsubopt GETSUBOPT || true +runtest mmap MMAP || true +runtest reallocarray REALLOCARRAY || true +runtest strcasestr STRCASESTR || true +runtest strlcat STRLCAT || true +runtest strlcpy STRLCPY || true +runtest strptime STRPTIME || true +runtest strsep STRSEP || true +runtest wchar WCHAR || true + +# --- sqlite3 --- +DETECTLIB= +if [ ${BUILD_DB} -eq 0 ]; then + echo "BUILD_DB=0 (manual)" 1>&2 + echo "BUILD_DB=0 (manual)" 1>&3 + echo 1>&3 + HAVE_SQLITE3=0 +elif ismanual sqlite3 "${HAVE_SQLITE3}"; then + DETECTLIB="-lsqlite3" +elif [ -n "${DBLIB}" ]; then + runtest sqlite3 SQLITE3 "${DBLIB}" || true +elif singletest sqlite3 SQLITE3 "-lsqlite3"; then + DETECTLIB="-lsqlite3" +elif runtest sqlite3 SQLITE3 \ + "-I/usr/local/include -L/usr/local/lib -lsqlite3"; then + DETECTLIB="-L/usr/local/lib -lsqlite3" + CFLAGS="${CFLAGS} -I/usr/local/include" +fi +if [ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3} -eq 0 ]; then + echo "BUILD_DB=0 (no sqlite3)" 1>&2 + echo "BUILD_DB=0 (no sqlite3)" 1>&3 + echo 1>&3 + BUILD_DB=0 +fi + +# --- sqlite3_errstr --- +if [ ${BUILD_DB} -eq 0 ]; then + HAVE_SQLITE3_ERRSTR=1 +elif ismanual sqlite3_errstr "${HAVE_SQLITE3_ERRSTR}"; then + : +elif [ -n "${DBLIB}" ]; then + runtest sqlite3_errstr SQLITE3_ERRSTR "${DBLIB}" || true +else + runtest sqlite3_errstr SQLITE3_ERRSTR "${DETECTLIB}" || true +fi + +# --- ohash --- +if [ ${BUILD_DB} -eq 0 ]; then + HAVE_OHASH=1 +elif ismanual ohash "${HAVE_OHASH}"; then + : +elif [ -n "${DBLIB}" ]; then + runtest ohash OHASH "${DBLIB}" || true +elif singletest ohash OHASH; then + : +elif runtest ohash OHASH "-lutil"; then + DETECTLIB="${DETECTLIB} -lutil" +fi + +# --- DBLIB --- +if [ ${BUILD_DB} -eq 0 ]; then + DBLIB= +elif [ -z "${DBLIB}" ]; then + DBLIB="${DETECTLIB}" + echo "DBLIB=\"${DBLIB}\"" 1>&2 + echo "DBLIB=\"${DBLIB}\"" 1>&3 + echo 1>&3 +fi + +# --- manpath --- +if [ ${BUILD_DB} -eq 0 ]; then + HAVE_MANPATH=0 +elif ismanual manpath "${HAVE_MANPATH}"; then + : +elif manpath 1>&3 2>&3; then + echo "manpath: yes" 1>&2 + echo "manpath: yes" 1>&3 + echo 1>&3 + HAVE_MANPATH=1 +else + echo "manpath: no" 1>&2 + echo "manpath: no" 1>&3 + echo 1>&3 + HAVE_MANPATH=0 +fi + +# --- write config.h --- + +exec > config.h + +cat << __HEREDOC__ +#ifndef MANDOC_CONFIG_H +#define MANDOC_CONFIG_H + +#if defined(__linux__) || defined(__MINT__) +#define _GNU_SOURCE /* getsubopt(), strcasestr(), strptime() */ +#endif + +__HEREDOC__ + +[ ${HAVE_FGETLN} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \ + ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \ + && echo "#include <sys/types.h>" +[ ${HAVE_FGETLN} -eq 0 ] && echo "#include <stdio.h>" + echo echo "#define VERSION \"${VERSION}\"" -runtest dirent-namlen DIRENT_NAMLEN -runtest fgetln FGETLN -runtest fts FTS -runtest getsubopt GETSUBOPT -runtest mmap MMAP -runtest ohash OHASH "${DBLIB}" -runtest reallocarray REALLOCARRAY -runtest sqlite3_errstr SQLITE3_ERRSTR "${DBLIB}" -runtest strcasestr STRCASESTR -runtest strlcat STRLCAT -runtest strlcpy STRLCPY -runtest strptime STRPTIME -runtest strsep STRSEP +[ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\"" + +cat << __HEREDOC__ +#define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN} +#define HAVE_FGETLN ${HAVE_FGETLN} +#define HAVE_FTS ${HAVE_FTS} +#define HAVE_GETSUBOPT ${HAVE_GETSUBOPT} +#define HAVE_MMAP ${HAVE_MMAP} +#define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY} +#define HAVE_STRCASESTR ${HAVE_STRCASESTR} +#define HAVE_STRLCAT ${HAVE_STRLCAT} +#define HAVE_STRLCPY ${HAVE_STRLCPY} +#define HAVE_STRPTIME ${HAVE_STRPTIME} +#define HAVE_STRSEP ${HAVE_STRSEP} +#define HAVE_WCHAR ${HAVE_WCHAR} +#define HAVE_SQLITE3_ERRSTR ${HAVE_SQLITE3_ERRSTR} +#define HAVE_OHASH ${HAVE_OHASH} +#define HAVE_MANPATH ${HAVE_MANPATH} + +#if !defined(__BEGIN_DECLS) +# ifdef __cplusplus +# define __BEGIN_DECLS extern "C" { +# else +# define __BEGIN_DECLS +# endif +#endif +#if !defined(__END_DECLS) +# ifdef __cplusplus +# define __END_DECLS } +# else +# define __END_DECLS +# endif +#endif + +__HEREDOC__ + +[ ${HAVE_FGETLN} -eq 0 ] && \ + echo "extern char *fgetln(FILE *, size_t *);" + +if [ ${HAVE_GETSUBOPT} -eq 0 ]; then + echo "extern int getsubopt(char **, char * const *, char **);" + echo "extern char *suboptarg;" +fi + +[ ${HAVE_REALLOCARRAY} -eq 0 ] && \ + echo "extern void *reallocarray(void *, size_t, size_t);" + +[ ${BUILD_DB} -gt 0 -a ${HAVE_SQLITE3_ERRSTR} -eq 0 ] && + echo "extern const char *sqlite3_errstr(int);" + +[ ${HAVE_STRCASESTR} -eq 0 ] && \ + echo "extern char *strcasestr(const char *, const char *);" + +[ ${HAVE_STRLCAT} -eq 0 ] && \ + echo "extern size_t strlcat(char *, const char *, size_t);" + +[ ${HAVE_STRLCPY} -eq 0 ] && \ + echo "extern size_t strlcpy(char *, const char *, size_t);" + +[ ${HAVE_STRSEP} -eq 0 ] && \ + echo "extern char *strsep(char **, const char *);" + echo -cat config.h.post +echo "#endif /* MANDOC_CONFIG_H */" + +echo "config.h: written" 1>&2 +echo "config.h: written" 1>&3 + +# --- tests for Makefile.local ----------------------------------------- + +exec > Makefile.local + +[ -z "${BINDIR}" ] && BINDIR="${PREFIX}/bin" +[ -z "${SBINDIR}" ] && SBINDIR="${PREFIX}/sbin" +[ -z "${INCLUDEDIR}" ] && INCLUDEDIR="${PREFIX}/include/mandoc" +[ -z "${LIBDIR}" ] && LIBDIR="${PREFIX}/lib/mandoc" +[ -z "${MANDIR}" ] && MANDIR="${PREFIX}/man" +[ -z "${EXAMPLEDIR}" ] && EXAMPLEDIR="${PREFIX}/share/examples/mandoc" + +[ -z "${HTDOCDIR}" ] && HTDOCDIR="${WWWPREFIX}/htdocs" +[ -z "${CGIBINDIR}" ] && CGIBINDIR="${WWWPREFIX}/cgi-bin" + +[ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555" +[ -z "${INSTALL_LIB}" ] && INSTALL_LIB="${INSTALL} -m 0444" +[ -z "${INSTALL_MAN}" ] && INSTALL_MAN="${INSTALL} -m 0444" +[ -z "${INSTALL_DATA}" ] && INSTALL_DATA="${INSTALL} -m 0444" + +if [ ${BUILD_DB} -eq 0 -a ${BUILD_CGI} -gt 0 ]; then + echo "BUILD_CGI=0 (no BUILD_DB)" 1>&2 + echo "BUILD_CGI=0 (no BUILD_DB)" 1>&3 + BUILD_CGI=0 +fi + +BUILD_TARGETS="base-build" +[ ${BUILD_DB} -gt 0 ] && BUILD_TARGETS="${BUILD_TARGETS} db-build" +[ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS="${BUILD_TARGETS} cgi-build" + +cat << __HEREDOC__ +VERSION = ${VERSION} +BUILD_TARGETS = ${BUILD_TARGETS} +CFLAGS = ${CFLAGS} +DBLIB = ${DBLIB} +STATIC = ${STATIC} +PREFIX = ${PREFIX} +BINDIR = ${BINDIR} +SBINDIR = ${SBINDIR} +INCLUDEDIR = ${INCLUDEDIR} +LIBDIR = ${LIBDIR} +MANDIR = ${MANDIR} +EXAMPLEDIR = ${EXAMPLEDIR} +WWWPREFIX = ${WWWPREFIX} +HTDOCDIR = ${HTDOCDIR} +CGIBINDIR = ${CGIBINDIR} +INSTALL = ${INSTALL} +INSTALL_PROGRAM = ${INSTALL_PROGRAM} +INSTALL_LIB = ${INSTALL_LIB} +INSTALL_MAN = ${INSTALL_MAN} +INSTALL_DATA = ${INSTALL_DATA} +__HEREDOC__ + +echo "Makefile.local: written" 1>&2 +echo "Makefile.local: written" 1>&3 exit 0 diff --git a/configure.local.example b/configure.local.example new file mode 100644 index 00000000..03e54f97 --- /dev/null +++ b/configure.local.example @@ -0,0 +1,189 @@ +# $Id$ +# +# Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org> +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +# For all settings documented in this file, there are reasonable +# defaults and/or the ./configure script attempts autodetection. +# Consequently, you only need to create a file ./configure.local +# and put any of these settings into it if ./configure autodetection +# fails or if you want to make different choices for other reasons. + +# If autodetection fails, please tell <tech@mdocml.bsd.lv>. + +# We recommend that you write ./configure.local from scratch and +# only put the lines there you need. This file contains examples. +# It is not intended as a template to be copied as a whole. + +# --- user settings relevant for all builds ---------------------------- + +# For -Tutf8 and -Tlocale operation, mandoc(1) requires <locale.h> +# providing setlocale(3) and <wchar.h> providing wcwidth(3) and +# putwchar(3) with a wchar_t storing UCS-4 values. Theoretically, +# the latter should be tested with the __STDC_ISO_10646__ feature +# macro. In practice, many <wchar.h> headers do not provide that +# macro even though they treat wchar_t as UCS-4. So the automatic +# test only checks that wchar_t is wide enough, that is, at least +# four bytes. + +# The following line forces multi-byte support. +# If your C library does not treat wchar_t as UCS-4, the UTF-8 output +# mode will print garbage. + +HAVE_WCHAR=1 + +# The following line disables multi-byte support. +# The output modes -Tutf8 and -Tlocale will be the same as -Tascii. + +HAVE_WCHAR=0 + +# In manual pages written in the mdoc(7) language, the operating system +# version is displayed in the page footer line. If an operating system +# is specified as an argument to the .Os macro, that is always used. +# If the .Os macro has no argument and an operation system is specified +# with the mandoc(1) -Ios= command line option, that is used. +# Otherwise, the uname(3) library function is called at runtime to find +# the name of the operating system. +# If you do not want uname(3) to be called but instead want a fixed +# string to be used, use the following line: + +OSNAME="OpenBSD 5.5" + +# The following installation directories are used. +# It is possible to set only one or a few of these variables, +# there is no need to copy the whole block. +# Even if you set PREFIX to something else, the other variables +# pick it up without copying them all over. + +PREFIX="/usr/local" +BINDIR="${PREFIX}/bin" +SBINDIR="${PREFIX}/sbin" +INCLUDEDIR="${PREFIX}/include/mandoc" +LIBDIR="${PREFIX}/lib/mandoc" +MANDIR="${PREFIX}/man" +EXAMPLEDIR="${PREFIX}/share/examples/mandoc" + +# It is possible to change the utility program used for installation +# and the modes files are installed with. The defaults are: + +INSTALL="install" +INSTALL_PROGRAM="${INSTALL} -m 0555" +INSTALL_LIB="${INSTALL} -m 0444" +INSTALL_MAN="${INSTALL} -m 0444" +INSTALL_DATA="${INSTALL} -m 0444" + +# --- user settings related to database support ------------------------ + +# By default, building makewhatis(8) and apropos(1) is enabled. +# To disable it, for example to avoid the dependency on SQLite3, +# use the following line. It that case, the remaining settings +# in this section are irrelevant. + +BUILD_DB=0 + +# Two libraries are needed: SQLite3 and ohash(3). +# Autoconfiguration tries the following linker flags to find them. +# If none of these work, add a working DBLIB line to configure.local, +# disabling autodetection for library directories. + +DBLIB="-lsqlite3" +DBLIB="-lsqlite3 -lutil" +DBLIB="-L/usr/local/lib -lsqlite3" + +# When library autodetection decides to use -L/usr/local/lib, +# -I/usr/local/include is automatically added to CFLAGS. +# If you manually set DBLIB to something including -L/usr/local/lib, +# chances are you will also need the following line: + +CFLAGS="${CFLAGS} -I/usr/local/include" + +# The man(1) utility needs to know where the manuals reside. +# We know of two ways to tell it: via manpath(1) or man.conf(5). +# The latter is used by OpenBSD and NetBSD, the former by most +# other systems. + +# Force usage of manpath(1). +# If it is not installed or not operational, +# makewhatis(8) and apropos(1) will not work properly. + +HAVE_MANPATH=1 + +# Force usage of man.conf(5). +# If it does not exist or contains no valid configuration, +# makewhatis(8) and apropos(1) will not work properly. + +HAVE_MANPATH=0 + +# --- user settings related man.cgi ------------------------------------ + +# By default, building man.cgi(8) is disabled. To enable it, copy +# cgi.h.example to cgi.h, edit it, and use the following line. +# Obviously, this requires that BUILD_DB is enabled, too. + +BUILD_CGI=1 + +# The remaining settings in this section are only relevant if BUILD_CGI +# is enabled. Otherwise, they have no effect either way. + +# By default, man.cgi(8) is linked statically. +# Some systems do not support static linking, for example Mac OS X. +# In that case, use the following line: + +STATIC= + +# Some systems, for example Linux, require -pthread for static linking: + +STATIC="-static -pthread" + +# Some directories. +# This works just like PREFIX, see above. + +WWWPREFIX="/var/www" +HTDOCDIR="${WWWPREFIX}/htdocs" +CGIBINDIR="${WWWPREFIX}/cgi-bin" + +# --- settings that rarely need to be touched -------------------------- + +# Do not set these variables unless you really need to. + +# You can manually override the compiler to be used. +# But that's rarely useful because ./configure asks your make(1) +# which compiler to use, and that answer will hardly be wrong. + +CC=cc + +# The default compiler flags are: + +CFLAGS="-g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings" + +# In rare cases, it may be required to skip individual automatic tests. +# Each of the following variables can be set to 0 (test will not be run +# and will be regarded as failed) or 1 (test will not be run and will +# be regarded as successful). + +HAVE_DIRENT_NAMLEN=0 +HAVE_FGETLN=0 +HAVE_FTS=0 +HAVE_GETSUBOPT=0 +HAVE_MMAP=0 +HAVE_REALLOCARRAY=0 +HAVE_STRCASESTR=0 +HAVE_STRLCAT=0 +HAVE_STRLCPY=0 +HAVE_STRPTIME=0 +HAVE_STRSEP=0 + +HAVE_SQLITE3=0 +HAVE_SQLITE3_ERRSTR=0 +HAVE_OHASH=0 @@ -455,7 +455,7 @@ a2time(time_t *t, const char *fmt, const char *p) memset(&tm, 0, sizeof(struct tm)); pp = NULL; -#ifdef HAVE_STRPTIME +#if HAVE_STRPTIME pp = strptime(p, fmt, &tm); #endif if (NULL != pp && '\0' == *pp) { @@ -25,7 +25,7 @@ #include <ctype.h> #include <errno.h> #include <fcntl.h> -#ifdef HAVE_FTS +#if HAVE_FTS #include <fts.h> #else #include "compat_fts.h" @@ -39,7 +39,7 @@ #include <string.h> #include <unistd.h> -#ifdef HAVE_OHASH +#if HAVE_OHASH #include <ohash.h> #else #include "compat_ohash.h" @@ -39,7 +39,7 @@ void manpath_parse(struct manpaths *dirs, const char *file, char *defp, char *auxp) { -#ifdef USE_MANPATH +#if HAVE_MANPATH char cmd[(PATH_MAX * 3) + 20]; FILE *stream; char *buf; diff --git a/mansearch.c b/mansearch.c index 58250631..4a74d0db 100644 --- a/mansearch.c +++ b/mansearch.c @@ -32,7 +32,7 @@ #include <string.h> #include <unistd.h> -#ifdef HAVE_OHASH +#if HAVE_OHASH #include <ohash.h> #else #include "compat_ohash.h" @@ -17,7 +17,7 @@ #include "config.h" #include <sys/types.h> -#ifdef HAVE_MMAP +#if HAVE_MMAP #include <sys/stat.h> #include <sys/mman.h> #endif @@ -244,7 +244,7 @@ read_whole_file(const char *f, int fd, size_t off; ssize_t ssz; -#ifdef HAVE_MMAP +#if HAVE_MMAP struct stat st; if (-1 == fstat(fd, &st)) { perror(f); @@ -508,7 +508,7 @@ main(int argc, char *argv[]) rc = EXIT_SUCCESS; out: -#ifdef HAVE_MMAP +#if HAVE_MMAP if (map) munmap(b.buf, b.sz); else @@ -19,7 +19,7 @@ #include "config.h" #include <sys/types.h> -#ifdef HAVE_MMAP +#if HAVE_MMAP #include <sys/stat.h> #include <sys/mman.h> #endif @@ -590,7 +590,7 @@ read_whole_file(struct mparse *curp, const char *file, int fd, size_t off; ssize_t ssz; -#ifdef HAVE_MMAP +#if HAVE_MMAP struct stat st; if (-1 == fstat(fd, &st)) { curp->file_status = MANDOCLEVEL_SYSERR; @@ -763,7 +763,7 @@ mparse_readfd(struct mparse *curp, int fd, const char *file) mparse_parse_buffer(curp, blk, file); -#ifdef HAVE_MMAP +#if HAVE_MMAP if (with_mmap) munmap(blk.buf, blk.sz); else diff --git a/term_ascii.c b/term_ascii.c index b11e222e..248a6ca4 100644 --- a/term_ascii.c +++ b/term_ascii.c @@ -19,14 +19,14 @@ #include <sys/types.h> -#ifdef USE_WCHAR +#if HAVE_WCHAR #include <locale.h> #endif #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> -#ifdef USE_WCHAR +#if HAVE_WCHAR #include <wchar.h> #endif @@ -36,17 +36,6 @@ #include "term.h" #include "main.h" -/* - * Sadly, this doesn't seem to be defined on systems even when they - * support it. For the time being, remove it and let those compiling - * the software decide for themselves what to use. - */ -#if 0 -#if ! defined(__STDC_ISO_10646__) -# undef USE_WCHAR -#endif -#endif - static struct termp *ascii_init(enum termenc, char *); static double ascii_hspan(const struct termp *, const struct roffsu *); @@ -58,7 +47,7 @@ static void ascii_endline(struct termp *); static void ascii_letter(struct termp *, int); static void ascii_setwidth(struct termp *, int, size_t); -#ifdef USE_WCHAR +#if HAVE_WCHAR static void locale_advance(struct termp *, size_t); static void locale_endline(struct termp *); static void locale_letter(struct termp *, int); @@ -90,7 +79,7 @@ ascii_init(enum termenc enc, char *outopts) p->setwidth = ascii_setwidth; p->width = ascii_width; -#ifdef USE_WCHAR +#if HAVE_WCHAR if (TERMENC_ASCII != enc) { v = TERMENC_LOCALE == enc ? setlocale(LC_ALL, "") : @@ -272,7 +261,7 @@ ascii_hspan(const struct termp *p, const struct roffsu *su) return(r); } -#ifdef USE_WCHAR +#if HAVE_WCHAR static size_t locale_width(const struct termp *p, int c) { diff --git a/test-sqlite3.c b/test-sqlite3.c new file mode 100644 index 00000000..af2343e5 --- /dev/null +++ b/test-sqlite3.c @@ -0,0 +1,47 @@ +/* $Id$ */ +/* + * Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <stdio.h> +#include <unistd.h> +#include <sqlite3.h> + +int +main(void) +{ + sqlite3 *db; + + if (sqlite3_open_v2("test.db", &db, + SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, + NULL) != SQLITE_OK) { + perror("test.db"); + fprintf(stderr, "sqlite3_open_v2: %s", sqlite3_errmsg(db)); + return(1); + } + unlink("test.db"); + + if (sqlite3_exec(db, "PRAGMA foreign_keys = ON", + NULL, NULL, NULL) != SQLITE_OK) { + fprintf(stderr, "sqlite3_exec: %s", sqlite3_errmsg(db)); + return(1); + } + + if (sqlite3_close(db) != SQLITE_OK) { + fprintf(stderr, "sqlite3_close: %s", sqlite3_errmsg(db)); + return(1); + } + return(0); +} diff --git a/test-wchar.c b/test-wchar.c new file mode 100644 index 00000000..0dc85ea4 --- /dev/null +++ b/test-wchar.c @@ -0,0 +1,59 @@ +/* $Id$ */ +/* + * Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <locale.h> +#include <stdio.h> +#include <wchar.h> +#include <unistd.h> + +int +main(void) +{ + wchar_t wc; + int width; + + if (setlocale(LC_ALL, "") == NULL) { + fputs("setlocale(LC_ALL, \"\") failed\n", stderr); + return(1); + } + + if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) { + fputs("setlocale(LC_CTYPE, \"en_US.UTF-8\") failed\n", + stderr); + return(1); + } + + if (sizeof(wchar_t) < 4) { + fprintf(stderr, "wchar_t is only %zu bytes\n", + sizeof(wchar_t)); + return(1); + } + + if ((width = wcwidth(L' ')) != 1) { + fprintf(stderr, "wcwidth(L' ') returned %d\n", width); + return(1); + } + + dup2(STDERR_FILENO, STDOUT_FILENO); + wc = L'*'; + if (putwchar(wc) != wc) { + fputs("bad putwchar return value\n", stderr); + return(1); + } + + return(0); +} |