Index: stable/11/Makefile.inc1 =================================================================== --- stable/11/Makefile.inc1 (revision 316419) +++ stable/11/Makefile.inc1 (revision 316420) @@ -1,2599 +1,2598 @@ # # $FreeBSD$ # # Make command line options: # -DNO_CLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir # -DNO_CLEAN do not clean at all # -DDB_FROM_SRC use the user/group databases in src/etc instead of # the system database when installing. # -DNO_SHARE do not go into share subdir # -DKERNFAST define NO_KERNEL{CONFIG,CLEAN,OBJ} # -DNO_KERNELCONFIG do not run config in ${MAKE} buildkernel # -DNO_KERNELCLEAN do not run ${MAKE} clean in ${MAKE} buildkernel # -DNO_KERNELOBJ do not run ${MAKE} obj in ${MAKE} buildkernel # -DNO_PORTSUPDATE do not update ports in ${MAKE} update # -DNO_ROOT install without using root privilege # -DNO_DOCUPDATE do not update doc in ${MAKE} update # -DWITHOUT_CTF do not run the DTrace CTF conversion tools on built objects # LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list # LOCAL_ITOOLS="list of tools" to add additional tools to the ITOOLS list # LOCAL_LIB_DIRS="list of dirs" to add additional dirs to libraries target # LOCAL_MTREE="list of mtree files" to process to allow local directories # to be created before files are installed # LOCAL_TOOL_DIRS="list of dirs" to add additional dirs to the build-tools # list # METALOG="path to metadata log" to write permission and ownership # when NO_ROOT is set. (default: ${DESTDIR}/METALOG) # TARGET="machine" to crossbuild world for a different machine type # TARGET_ARCH= may be required when a TARGET supports multiple endians # BUILDENV_SHELL= shell to launch for the buildenv target (def:${SHELL}) # WORLD_FLAGS= additional flags to pass to make(1) during buildworld # KERNEL_FLAGS= additional flags to pass to make(1) during buildkernel # SUBDIR_OVERRIDE="list of dirs" to build rather than everything. # All libraries and includes, and some build tools will still build. # # The intended user-driven targets are: # buildworld - rebuild *everything*, including glue to help do upgrades # installworld- install everything built by "buildworld" # checkworld - run test suite on installed world # doxygen - build API documentation of the kernel # update - convenient way to update your source tree (eg: svn/svnup) # # Standard targets (not defined here) are documented in the makefiles in # /usr/share/mk. These include: # obj depend all install clean cleandepend cleanobj .if !defined(TARGET) || !defined(TARGET_ARCH) .error "Both TARGET and TARGET_ARCH must be defined." .endif SRCDIR?= ${.CURDIR} LOCALBASE?= /usr/local # Cross toolchain changes must be in effect before bsd.compiler.mk # so that gets the right CC, and pass CROSS_TOOLCHAIN to submakes. .if defined(CROSS_TOOLCHAIN) .include "${LOCALBASE}/share/toolchains/${CROSS_TOOLCHAIN}.mk" CROSSENV+=CROSS_TOOLCHAIN="${CROSS_TOOLCHAIN}" .endif .if defined(CROSS_TOOLCHAIN_PREFIX) CROSS_COMPILER_PREFIX?=${CROSS_TOOLCHAIN_PREFIX} .endif XCOMPILERS= CC CXX CPP .for COMPILER in ${XCOMPILERS} .if defined(CROSS_COMPILER_PREFIX) X${COMPILER}?= ${CROSS_COMPILER_PREFIX}${${COMPILER}} .else X${COMPILER}?= ${${COMPILER}} .endif .endfor # If a full path to an external cross compiler is given, don't build # a cross compiler. .if ${XCC:N${CCACHE_BIN}:M/*} MK_CLANG_BOOTSTRAP= no MK_GCC_BOOTSTRAP= no .endif # Pull in COMPILER_TYPE and COMPILER_FREEBSD_VERSION early. .include .include "share/mk/src.opts.mk" # Check if there is a local compiler that can satisfy as an external compiler. # Which compiler is expected to be used? .if ${MK_CLANG_BOOTSTRAP} == "yes" WANT_COMPILER_TYPE= clang .elif ${MK_GCC_BOOTSTRAP} == "yes" WANT_COMPILER_TYPE= gcc .else WANT_COMPILER_TYPE= .endif .if !defined(WANT_COMPILER_FREEBSD_VERSION) .if ${WANT_COMPILER_TYPE} == "clang" WANT_COMPILER_FREEBSD_VERSION_FILE= lib/clang/freebsd_cc_version.h WANT_COMPILER_FREEBSD_VERSION!= \ awk '$$2 == "FREEBSD_CC_VERSION" {printf("%d\n", $$3)}' \ ${SRCDIR}/${WANT_COMPILER_FREEBSD_VERSION_FILE} || echo unknown WANT_COMPILER_VERSION_FILE= lib/clang/include/clang/Basic/Version.inc WANT_COMPILER_VERSION!= \ awk '$$2 == "CLANG_VERSION" {split($$3, a, "."); print a[1] * 10000 + a[2] * 100 + a[3]}' \ ${SRCDIR}/${WANT_COMPILER_VERSION_FILE} || echo unknown .elif ${WANT_COMPILER_TYPE} == "gcc" WANT_COMPILER_FREEBSD_VERSION_FILE= gnu/usr.bin/cc/cc_tools/freebsd-native.h WANT_COMPILER_FREEBSD_VERSION!= \ awk '$$2 == "FBSD_CC_VER" {printf("%d\n", $$3)}' \ ${SRCDIR}/${WANT_COMPILER_FREEBSD_VERSION_FILE} || echo unknown WANT_COMPILER_VERSION_FILE= contrib/gcc/BASE-VER WANT_COMPILER_VERSION!= \ awk -F. '{print $$1 * 10000 + $$2 * 100 + $$3}' \ ${SRCDIR}/${WANT_COMPILER_VERSION_FILE} || echo unknown .endif .export WANT_COMPILER_FREEBSD_VERSION WANT_COMPILER_VERSION .endif # !defined(WANT_COMPILER_FREEBSD_VERSION) # It needs to be the same revision as we would build for the bootstrap. # If the expected vs CC is different then we can't skip. # GCC cannot be used for cross-arch yet. For clang we pass -target later if # TARGET_ARCH!=MACHINE_ARCH. .if ${MK_SYSTEM_COMPILER} == "yes" && \ (${MK_CLANG_BOOTSTRAP} == "yes" || ${MK_GCC_BOOTSTRAP} == "yes") && \ !make(showconfig) && !make(native-xtools) && !make(xdev*) && \ ${WANT_COMPILER_TYPE} == ${COMPILER_TYPE} && \ (${COMPILER_TYPE} == "clang" || ${TARGET_ARCH} == ${MACHINE_ARCH}) && \ ${COMPILER_VERSION} == ${WANT_COMPILER_VERSION} && \ ${COMPILER_FREEBSD_VERSION} == ${WANT_COMPILER_FREEBSD_VERSION} # Everything matches, disable the bootstrap compiler. MK_CLANG_BOOTSTRAP= no MK_GCC_BOOTSTRAP= no USING_SYSTEM_COMPILER= yes .endif # ${WANT_COMPILER_TYPE} == ${COMPILER_TYPE} USING_SYSTEM_COMPILER?= no TEST_SYSTEM_COMPILER_VARS= \ USING_SYSTEM_COMPILER MK_SYSTEM_COMPILER \ MK_CROSS_COMPILER MK_CLANG_BOOTSTRAP MK_GCC_BOOTSTRAP \ WANT_COMPILER_TYPE WANT_COMPILER_VERSION WANT_COMPILER_VERSION_FILE \ WANT_COMPILER_FREEBSD_VERSION WANT_COMPILER_FREEBSD_VERSION_FILE \ CC COMPILER_TYPE COMPILER_VERSION COMPILER_FREEBSD_VERSION test-system-compiler: .PHONY .for v in ${TEST_SYSTEM_COMPILER_VARS} ${_+_}@printf "%-35s= %s\n" "${v}" "${${v}}" .endfor .if ${USING_SYSTEM_COMPILER} == "yes" && \ (make(buildworld) || make(buildkernel) || make(kernel-toolchain) || \ make(toolchain) || make(_cross-tools)) .info SYSTEM_COMPILER: Determined that CC=${CC} matches the source tree. Not bootstrapping a cross-compiler. .endif # For installworld need to ensure that the looked-up compiler metadata is # passed along rather than trying to run cc from the restricted # STRICTTMPPATH. .if ${MK_CLANG_BOOTSTRAP} == "no" && ${MK_GCC_BOOTSTRAP} == "no" .if !defined(X_COMPILER_TYPE) CROSSENV+= COMPILER_VERSION=${COMPILER_VERSION} \ COMPILER_TYPE=${COMPILER_TYPE} \ COMPILER_FREEBSD_VERSION=${COMPILER_FREEBSD_VERSION} .else CROSSENV+= COMPILER_VERSION=${X_COMPILER_VERSION} \ COMPILER_TYPE=${X_COMPILER_TYPE} \ COMPILER_FREEBSD_VERSION=${X_COMPILER_FREEBSD_VERSION} .endif .endif # Handle external binutils. .if defined(CROSS_TOOLCHAIN_PREFIX) CROSS_BINUTILS_PREFIX?=${CROSS_TOOLCHAIN_PREFIX} .endif # If we do not have a bootstrap binutils (because the in-tree one does not # support the target architecture), provide a default cross-binutils prefix. # This allows aarch64 builds, for example, to automatically use the # aarch64-binutils port or package. .if !make(showconfig) .if !empty(BROKEN_OPTIONS:MBINUTILS_BOOTSTRAP) && \ !defined(CROSS_BINUTILS_PREFIX) CROSS_BINUTILS_PREFIX=/usr/local/${TARGET_ARCH}-freebsd/bin/ .if !exists(${CROSS_BINUTILS_PREFIX}) .error In-tree binutils does not support the ${TARGET_ARCH} architecture. Install the ${TARGET_ARCH}-binutils port or package or set CROSS_BINUTILS_PREFIX. .endif .endif .endif XBINUTILS= AS AR LD NM OBJCOPY OBJDUMP RANLIB SIZE STRINGS .for BINUTIL in ${XBINUTILS} .if defined(CROSS_BINUTILS_PREFIX) && \ exists(${CROSS_BINUTILS_PREFIX}${${BINUTIL}}) X${BINUTIL}?= ${CROSS_BINUTILS_PREFIX}${${BINUTIL}} .else X${BINUTIL}?= ${${BINUTIL}} .endif .endfor # We must do lib/ and libexec/ before bin/ in case of a mid-install error to # keep the users system reasonably usable. For static->dynamic root upgrades, # we don't want to install a dynamic binary without rtld and the needed # libraries. More commonly, for dynamic root, we don't want to install a # binary that requires a newer library version that hasn't been installed yet. # This ordering is not a guarantee though. The only guarantee of a working # system here would require fine-grained ordering of all components based # on their dependencies. .if !empty(SUBDIR_OVERRIDE) SUBDIR= ${SUBDIR_OVERRIDE} .else SUBDIR= lib libexec .if !defined(NO_ROOT) && (make(installworld) || make(install)) # Ensure libraries are installed before progressing. SUBDIR+=.WAIT .endif SUBDIR+=bin .if ${MK_CDDL} != "no" SUBDIR+=cddl .endif SUBDIR+=gnu include .if ${MK_KERBEROS} != "no" SUBDIR+=kerberos5 .endif .if ${MK_RESCUE} != "no" SUBDIR+=rescue .endif SUBDIR+=sbin .if ${MK_CRYPT} != "no" SUBDIR+=secure .endif .if !defined(NO_SHARE) SUBDIR+=share .endif SUBDIR+=sys usr.bin usr.sbin .if ${MK_TESTS} != "no" SUBDIR+= tests .endif .if ${MK_OFED} != "no" SUBDIR+=contrib/ofed .endif # Local directories are last, since it is nice to at least get the base # system rebuilt before you do them. .for _DIR in ${LOCAL_DIRS} .if exists(${.CURDIR}/${_DIR}/Makefile) SUBDIR+= ${_DIR} .endif .endfor # Add LOCAL_LIB_DIRS, but only if they will not be picked up as a SUBDIR # of a LOCAL_DIRS directory. This allows LOCAL_DIRS=foo and # LOCAL_LIB_DIRS=foo/lib to behave as expected. .for _DIR in ${LOCAL_DIRS:M*/} ${LOCAL_DIRS:N*/:S|$|/|} _REDUNDANT_LIB_DIRS+= ${LOCAL_LIB_DIRS:M${_DIR}*} .endfor .for _DIR in ${LOCAL_LIB_DIRS} .if empty(_REDUNDANT_LIB_DIRS:M${_DIR}) && exists(${.CURDIR}/${_DIR}/Makefile) SUBDIR+= ${_DIR} .endif .endfor # We must do etc/ last as it hooks into building the man whatis file # by calling 'makedb' in share/man. This is only relevant for # install/distribute so they build the whatis file after every manpage is # installed. .if make(installworld) || make(install) SUBDIR+=.WAIT .endif SUBDIR+=etc .endif # !empty(SUBDIR_OVERRIDE) .if defined(NOCLEAN) .warning NOCLEAN option is deprecated. Use NO_CLEAN instead. NO_CLEAN= ${NOCLEAN} .endif .if defined(NO_CLEANDIR) CLEANDIR= clean cleandepend .else CLEANDIR= cleandir .endif .if ${MK_META_MODE} == "yes" # If filemon is used then we can rely on the build being incremental-safe. # The .meta files will also track the build command and rebuild should # it change. .if empty(.MAKE.MODE:Mnofilemon) NO_CLEAN= t .endif .endif LOCAL_TOOL_DIRS?= PACKAGEDIR?= ${DESTDIR}/${DISTDIR} .if empty(SHELL:M*csh*) BUILDENV_SHELL?=${SHELL} .else BUILDENV_SHELL?=/bin/sh .endif .if !defined(SVN) || empty(SVN) . for _P in /usr/bin /usr/local/bin . for _S in svn svnlite . if exists(${_P}/${_S}) SVN= ${_P}/${_S} . endif . endfor . endfor .endif SVNFLAGS?= -r HEAD MAKEOBJDIRPREFIX?= /usr/obj .if !defined(OSRELDATE) .if exists(/usr/include/osreldate.h) OSRELDATE!= awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \ /usr/include/osreldate.h .else OSRELDATE= 0 .endif .export OSRELDATE .endif # Set VERSION for CTFMERGE to use via the default CTFFLAGS=-L VERSION. .if !defined(_REVISION) _REVISION!= MK_AUTO_OBJ=no ${MAKE} -C ${SRCDIR}/release -V REVISION .export _REVISION .endif .if !defined(_BRANCH) _BRANCH!= MK_AUTO_OBJ=no ${MAKE} -C ${SRCDIR}/release -V BRANCH .export _BRANCH .endif .if !defined(SRCRELDATE) SRCRELDATE!= awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \ ${SRCDIR}/sys/sys/param.h .export SRCRELDATE .endif .if !defined(VERSION) VERSION= FreeBSD ${_REVISION}-${_BRANCH:C/-p[0-9]+$//} ${TARGET_ARCH} ${SRCRELDATE} .export VERSION .endif .if !defined(PKG_VERSION) .if ${_BRANCH:MSTABLE*} || ${_BRANCH:MCURRENT*} || ${_BRANCH:MALPHA*} TIMENOW= %Y%m%d%H%M%S EXTRA_REVISION= .s${TIMENOW:gmtime} .endif .if ${_BRANCH:M*-p*} EXTRA_REVISION= _${_BRANCH:C/.*-p([0-9]+$)/\1/} .endif PKG_VERSION= ${_REVISION}${EXTRA_REVISION} .endif KNOWN_ARCHES?= aarch64/arm64 \ amd64 \ arm \ armeb/arm \ armv6/arm \ i386 \ i386/pc98 \ mips \ mipsel/mips \ mips64el/mips \ mipsn32el/mips \ mips64/mips \ mipsn32/mips \ powerpc \ powerpc64/powerpc \ riscv64/riscv \ sparc64 .if ${TARGET} == ${TARGET_ARCH} _t= ${TARGET} .else _t= ${TARGET_ARCH}/${TARGET} .endif .for _t in ${_t} .if empty(KNOWN_ARCHES:M${_t}) .error Unknown target ${TARGET_ARCH}:${TARGET}. .endif .endfor .if ${TARGET} == ${MACHINE} TARGET_CPUTYPE?=${CPUTYPE} .else TARGET_CPUTYPE?= .endif .if !empty(TARGET_CPUTYPE) _TARGET_CPUTYPE=${TARGET_CPUTYPE} .else _TARGET_CPUTYPE=dummy .endif _CPUTYPE!= MK_AUTO_OBJ=no MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} \ -f /dev/null -m ${.CURDIR}/share/mk -V CPUTYPE .if ${_CPUTYPE} != ${_TARGET_CPUTYPE} .error CPUTYPE global should be set with ?=. .endif .if make(buildworld) BUILD_ARCH!= uname -p .if ${MACHINE_ARCH} != ${BUILD_ARCH} .error To cross-build, set TARGET_ARCH. .endif .endif .if ${MACHINE} == ${TARGET} && ${MACHINE_ARCH} == ${TARGET_ARCH} && !defined(CROSS_BUILD_TESTING) OBJTREE= ${MAKEOBJDIRPREFIX} .else OBJTREE= ${MAKEOBJDIRPREFIX}/${TARGET}.${TARGET_ARCH} .endif WORLDTMP= ${OBJTREE}${.CURDIR}/tmp BPATH= ${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/bin XPATH= ${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin STRICTTMPPATH= ${BPATH}:${XPATH} TMPPATH= ${STRICTTMPPATH}:${PATH} # # Avoid running mktemp(1) unless actually needed. # It may not be functional, e.g., due to new ABI # when in the middle of installing over this system. # .if make(distributeworld) || make(installworld) || make(stageworld) INSTALLTMP!= /usr/bin/mktemp -d -u -t install .endif .if make(stagekernel) || make(distributekernel) TAGS+= kernel PACKAGE= kernel .endif # # Building a world goes through the following stages # # 1. legacy stage [BMAKE] # This stage is responsible for creating compatibility # shims that are needed by the bootstrap-tools, # build-tools and cross-tools stages. These are generally # APIs that tools from one of those three stages need to # build that aren't present on the host. # 1. bootstrap-tools stage [BMAKE] # This stage is responsible for creating programs that # are needed for backward compatibility reasons. They # are not built as cross-tools. # 2. build-tools stage [TMAKE] # This stage is responsible for creating the object # tree and building any tools that are needed during # the build process. Some programs are listed during # this phase because they build binaries to generate # files needed to build these programs. This stage also # builds the 'build-tools' target rather than 'all'. # 3. cross-tools stage [XMAKE] # This stage is responsible for creating any tools that # are needed for building the system. A cross-compiler is one # of them. This differs from build tools in two ways: # 1. the 'all' target is built rather than 'build-tools' # 2. these tools are installed into TMPPATH for stage 4. # 4. world stage [WMAKE] # This stage actually builds the world. # 5. install stage (optional) [IMAKE] # This stage installs a previously built world. # BOOTSTRAPPING?= 0 # Keep these in sync MINIMUM_SUPPORTED_OSREL?= 900044 MINIMUM_SUPPORTED_REL?= 9.1 # Common environment for world related stages CROSSENV+= MAKEOBJDIRPREFIX=${OBJTREE} \ MACHINE_ARCH=${TARGET_ARCH} \ MACHINE=${TARGET} \ CPUTYPE=${TARGET_CPUTYPE} .if ${MK_META_MODE} != "no" # Don't rebuild build-tools targets during normal build. CROSSENV+= BUILD_TOOLS_META=.NOMETA_CMP .endif .if ${MK_GROFF} != "no" CROSSENV+= GROFF_BIN_PATH=${WORLDTMP}/legacy/usr/bin \ GROFF_FONT_PATH=${WORLDTMP}/legacy/usr/share/groff_font \ GROFF_TMAC_PATH=${WORLDTMP}/legacy/usr/share/tmac .endif .if defined(TARGET_CFLAGS) CROSSENV+= ${TARGET_CFLAGS} .endif # bootstrap-tools stage BMAKEENV= INSTALL="sh ${.CURDIR}/tools/install.sh" \ TOOLS_PREFIX=${WORLDTMP} \ PATH=${BPATH}:${PATH} \ WORLDTMP=${WORLDTMP} \ MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}" # need to keep this in sync with targets/pseudo/bootstrap-tools/Makefile BSARGS= DESTDIR= \ BOOTSTRAPPING=${OSRELDATE} \ SSP_CFLAGS= \ MK_HTML=no NO_LINT=yes MK_MAN=no \ -DNO_PIC MK_PROFILE=no -DNO_SHARED \ -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \ MK_CLANG_EXTRAS=no MK_CLANG_FULL=no \ MK_LLDB=no MK_TESTS=no \ MK_INCLUDES=yes BMAKE= MAKEOBJDIRPREFIX=${WORLDTMP} \ ${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \ ${BSARGS} # build-tools stage TMAKE= MAKEOBJDIRPREFIX=${OBJTREE} \ ${BMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \ TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \ DESTDIR= \ BOOTSTRAPPING=${OSRELDATE} \ SSP_CFLAGS= \ -DNO_LINT \ -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \ MK_CLANG_EXTRAS=no MK_CLANG_FULL=no \ MK_LLDB=no MK_TESTS=no # cross-tools stage XMAKE= TOOLS_PREFIX=${WORLDTMP} ${BMAKE} \ TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \ MK_GDB=no MK_TESTS=no # kernel-tools stage KTMAKEENV= INSTALL="sh ${.CURDIR}/tools/install.sh" \ PATH=${BPATH}:${PATH} \ WORLDTMP=${WORLDTMP} KTMAKE= TOOLS_PREFIX=${WORLDTMP} MAKEOBJDIRPREFIX=${WORLDTMP} \ ${KTMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 \ DESTDIR= \ BOOTSTRAPPING=${OSRELDATE} \ SSP_CFLAGS= \ MK_HTML=no -DNO_LINT MK_MAN=no \ -DNO_PIC MK_PROFILE=no -DNO_SHARED \ -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no # world stage WMAKEENV= ${CROSSENV} \ INSTALL="sh ${.CURDIR}/tools/install.sh" \ PATH=${TMPPATH} # make hierarchy HMAKE= PATH=${TMPPATH} ${MAKE} LOCAL_MTREE=${LOCAL_MTREE:Q} .if defined(NO_ROOT) HMAKE+= PATH=${TMPPATH} METALOG=${METALOG} -DNO_ROOT .endif CROSSENV+= CC="${XCC} ${XCFLAGS}" CXX="${XCXX} ${XCXXFLAGS} ${XCFLAGS}" \ CPP="${XCPP} ${XCFLAGS}" \ AS="${XAS}" AR="${XAR}" LD="${XLD}" NM=${XNM} \ OBJDUMP=${XOBJDUMP} OBJCOPY="${XOBJCOPY}" \ RANLIB=${XRANLIB} STRINGS=${XSTRINGS} \ SIZE="${XSIZE}" .if defined(CROSS_BINUTILS_PREFIX) && exists(${CROSS_BINUTILS_PREFIX}) # In the case of xdev-build tools, CROSS_BINUTILS_PREFIX won't be a # directory, but the compiler will look in the right place for its # tools so we don't need to tell it where to look. BFLAGS+= -B${CROSS_BINUTILS_PREFIX} .endif # External compiler needs sysroot and target flags. .if ${MK_CLANG_BOOTSTRAP} == "no" && ${MK_GCC_BOOTSTRAP} == "no" .if !defined(CROSS_BINUTILS_PREFIX) || !exists(${CROSS_BINUTILS_PREFIX}) BFLAGS+= -B${WORLDTMP}/usr/bin .endif .if ${TARGET} == "arm" .if ${TARGET_ARCH:Marmv6*} != "" && ${TARGET_CPUTYPE:M*soft*} == "" TARGET_ABI= gnueabihf .else TARGET_ABI= gnueabi .endif .endif .if defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc # GCC requires -isystem and -L when using a cross-compiler. --sysroot # won't set header path and -L is used to ensure the base library path # is added before the port PREFIX library path. XCFLAGS+= -isystem ${WORLDTMP}/usr/include -L${WORLDTMP}/usr/lib # Force using libc++ for external GCC. # XXX: This should be checking MK_GNUCXX == no .if ${X_COMPILER_VERSION} >= 40800 XCXXFLAGS+= -isystem ${WORLDTMP}/usr/include/c++/v1 -std=c++11 \ -nostdinc++ -L${WORLDTMP}/../lib/libc++ .endif .else TARGET_ABI?= unknown TARGET_TRIPLE?= ${TARGET_ARCH:C/amd64/x86_64/}-${TARGET_ABI}-freebsd11.0 XCFLAGS+= -target ${TARGET_TRIPLE} .endif XCFLAGS+= --sysroot=${WORLDTMP} .endif # ${MK_CLANG_BOOTSTRAP} == "no" && ${MK_GCC_BOOTSTRAP} == "no" .if !empty(BFLAGS) XCFLAGS+= ${BFLAGS} .endif .if ${MK_LIB32} != "no" && (${TARGET_ARCH} == "amd64" || \ ${TARGET_ARCH} == "powerpc64") LIBCOMPAT= 32 .include "Makefile.libcompat" .elif ${MK_LIBSOFT} != "no" && ${TARGET_ARCH} == "armv6" LIBCOMPAT= SOFT .include "Makefile.libcompat" .endif WMAKE= ${WMAKEENV} ${MAKE} ${WORLD_FLAGS} -f Makefile.inc1 DESTDIR=${WORLDTMP} IMAKEENV= ${CROSSENV} IMAKE= ${IMAKEENV} ${MAKE} -f Makefile.inc1 \ ${IMAKE_INSTALL} ${IMAKE_MTREE} .if empty(.MAKEFLAGS:M-n) IMAKEENV+= PATH=${STRICTTMPPATH}:${INSTALLTMP} \ LD_LIBRARY_PATH=${INSTALLTMP} \ PATH_LOCALE=${INSTALLTMP}/locale IMAKE+= __MAKE_SHELL=${INSTALLTMP}/sh .else IMAKEENV+= PATH=${TMPPATH}:${INSTALLTMP} .endif .if defined(DB_FROM_SRC) INSTALLFLAGS+= -N ${.CURDIR}/etc MTREEFLAGS+= -N ${.CURDIR}/etc .endif _INSTALL_DDIR= ${DESTDIR}/${DISTDIR} INSTALL_DDIR= ${_INSTALL_DDIR:S://:/:g:C:/$::} .if defined(NO_ROOT) METALOG?= ${DESTDIR}/${DISTDIR}/METALOG IMAKE+= -DNO_ROOT METALOG=${METALOG} INSTALLFLAGS+= -U -M ${METALOG} -D ${INSTALL_DDIR} MTREEFLAGS+= -W .endif .if defined(BUILD_PKGS) INSTALLFLAGS+= -h sha256 .endif .if defined(DB_FROM_SRC) || defined(NO_ROOT) IMAKE_INSTALL= INSTALL="install ${INSTALLFLAGS}" IMAKE_MTREE= MTREE_CMD="mtree ${MTREEFLAGS}" .endif # kernel stage KMAKEENV= ${WMAKEENV} KMAKE= ${KMAKEENV} ${MAKE} ${.MAKEFLAGS} ${KERNEL_FLAGS} KERNEL=${INSTKERNNAME} # # buildworld # # Attempt to rebuild the entire system, with reasonable chance of # success, regardless of how old your existing system is. # _worldtmp: .PHONY .if ${.CURDIR:C/[^,]//g} != "" # The m4 build of sendmail files doesn't like it if ',' is used # anywhere in the path of it's files. @echo @echo "*** Error: path to source tree contains a comma ','" @echo false .endif @echo @echo "--------------------------------------------------------------" @echo ">>> Rebuilding the temporary build tree" @echo "--------------------------------------------------------------" .if !defined(NO_CLEAN) rm -rf ${WORLDTMP} .if defined(LIBCOMPAT) rm -rf ${LIBCOMPATTMP} .endif .else rm -rf ${WORLDTMP}/legacy/usr/include .endif .for _dir in \ lib lib/casper usr legacy/bin legacy/usr mkdir -p ${WORLDTMP}/${_dir} .endfor mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \ -p ${WORLDTMP}/legacy/usr >/dev/null .if ${MK_GROFF} != "no" mtree -deU -f ${.CURDIR}/etc/mtree/BSD.groff.dist \ -p ${WORLDTMP}/legacy/usr >/dev/null .endif mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \ -p ${WORLDTMP}/legacy/usr/include >/dev/null mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \ -p ${WORLDTMP}/usr >/dev/null mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \ -p ${WORLDTMP}/usr/include >/dev/null ln -sf ${.CURDIR}/sys ${WORLDTMP} .if ${MK_DEBUG_FILES} != "no" # We could instead disable debug files for these build stages mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \ -p ${WORLDTMP}/legacy/usr/lib >/dev/null mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \ -p ${WORLDTMP}/usr/lib >/dev/null .endif .if defined(LIBCOMPAT) mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \ -p ${WORLDTMP}/usr >/dev/null .if ${MK_DEBUG_FILES} != "no" mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \ -p ${WORLDTMP}/legacy/usr/lib/debug/usr >/dev/null mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \ -p ${WORLDTMP}/usr/lib/debug/usr >/dev/null .endif .endif .if ${MK_TESTS} != "no" mkdir -p ${WORLDTMP}${TESTSBASE} mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \ -p ${WORLDTMP}${TESTSBASE} >/dev/null .if ${MK_DEBUG_FILES} != "no" mkdir -p ${WORLDTMP}/usr/lib/debug/${TESTSBASE} mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \ -p ${WORLDTMP}/usr/lib/debug/${TESTSBASE} >/dev/null .endif .endif .for _mtree in ${LOCAL_MTREE} mtree -deU -f ${.CURDIR}/${_mtree} -p ${WORLDTMP} > /dev/null .endfor _legacy: @echo @echo "--------------------------------------------------------------" @echo ">>> stage 1.1: legacy release compatibility shims" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${BMAKE} legacy _bootstrap-tools: @echo @echo "--------------------------------------------------------------" @echo ">>> stage 1.2: bootstrap tools" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools _cleanobj: .if !defined(NO_CLEAN) @echo @echo "--------------------------------------------------------------" @echo ">>> stage 2.1: cleaning up the object tree" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${WMAKE} ${CLEANDIR} .if defined(LIBCOMPAT) ${_+_}cd ${.CURDIR}; ${LIBCOMPATWMAKE} -f Makefile.inc1 ${CLEANDIR} .endif .endif _obj: @echo @echo "--------------------------------------------------------------" @echo ">>> stage 2.2: rebuilding the object tree" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${WMAKE} obj _build-tools: @echo @echo "--------------------------------------------------------------" @echo ">>> stage 2.3: build tools" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${TMAKE} build-tools _cross-tools: @echo @echo "--------------------------------------------------------------" @echo ">>> stage 3: cross tools" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools ${_+_}cd ${.CURDIR}; ${XMAKE} kernel-tools _includes: @echo @echo "--------------------------------------------------------------" @echo ">>> stage 4.1: building includes" @echo "--------------------------------------------------------------" # Special handling for SUBDIR_OVERRIDE in buildworld as they most likely need # headers from default SUBDIR. Do SUBDIR_OVERRIDE includes last. ${_+_}cd ${.CURDIR}; ${WMAKE} SUBDIR_OVERRIDE= SHARED=symlinks \ MK_INCLUDES=yes includes .if !empty(SUBDIR_OVERRIDE) && make(buildworld) ${_+_}cd ${.CURDIR}; ${WMAKE} MK_INCLUDES=yes SHARED=symlinks includes .endif _libraries: @echo @echo "--------------------------------------------------------------" @echo ">>> stage 4.2: building libraries" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; \ ${WMAKE} -DNO_FSCHG MK_HTML=no -DNO_LINT MK_MAN=no \ MK_PROFILE=no MK_TESTS=no MK_TESTS_SUPPORT=${MK_TESTS} libraries everything: .PHONY @echo @echo "--------------------------------------------------------------" @echo ">>> stage 4.3: building everything" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; _PARALLEL_SUBDIR_OK=1 ${WMAKE} all WMAKE_TGTS= WMAKE_TGTS+= _worldtmp _legacy .if empty(SUBDIR_OVERRIDE) WMAKE_TGTS+= _bootstrap-tools .endif WMAKE_TGTS+= _cleanobj _obj _build-tools _cross-tools WMAKE_TGTS+= _includes _libraries WMAKE_TGTS+= everything .if defined(LIBCOMPAT) && empty(SUBDIR_OVERRIDE) WMAKE_TGTS+= build${libcompat} .endif buildworld: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue .PHONY .ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue buildworld_prologue: .PHONY @echo "--------------------------------------------------------------" @echo ">>> World build started on `LC_ALL=C date`" @echo "--------------------------------------------------------------" buildworld_epilogue: .PHONY @echo @echo "--------------------------------------------------------------" @echo ">>> World build completed on `LC_ALL=C date`" @echo "--------------------------------------------------------------" # # We need to have this as a target because the indirection between Makefile # and Makefile.inc1 causes the correct PATH to be used, rather than a # modification of the current environment's PATH. In addition, we need # to quote multiword values. # buildenvvars: .PHONY @echo ${WMAKEENV:Q} ${.MAKE.EXPORTED:@v@$v=\"${$v}\"@} .if ${.TARGETS:Mbuildenv} .if ${.MAKEFLAGS:M-j} .error The buildenv target is incompatible with -j .endif .endif BUILDENV_DIR?= ${.CURDIR} buildenv: .PHONY @echo Entering world for ${TARGET_ARCH}:${TARGET} .if ${BUILDENV_SHELL:M*zsh*} @echo For ZSH you must run: export CPUTYPE=${TARGET_CPUTYPE} .endif @cd ${BUILDENV_DIR} && env ${WMAKEENV} BUILDENV=1 ${BUILDENV_SHELL} \ || true TOOLCHAIN_TGTS= ${WMAKE_TGTS:Neverything:Nbuild${libcompat}} toolchain: ${TOOLCHAIN_TGTS} .PHONY kernel-toolchain: ${TOOLCHAIN_TGTS:N_includes:N_libraries} .PHONY # # installcheck # # Checks to be sure system is ready for installworld/installkernel. # installcheck: _installcheck_world _installcheck_kernel .PHONY _installcheck_world: .PHONY _installcheck_kernel: .PHONY # # Require DESTDIR to be set if installing for a different architecture or # using the user/group database in the source tree. # .if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE} || \ defined(DB_FROM_SRC) .if !make(distributeworld) _installcheck_world: __installcheck_DESTDIR _installcheck_kernel: __installcheck_DESTDIR __installcheck_DESTDIR: .PHONY .if !defined(DESTDIR) || empty(DESTDIR) @echo "ERROR: Please set DESTDIR!"; \ false .endif .endif .endif .if !defined(DB_FROM_SRC) # # Check for missing UIDs/GIDs. # CHECK_UIDS= auditdistd CHECK_GIDS= audit .if ${MK_SENDMAIL} != "no" CHECK_UIDS+= smmsp CHECK_GIDS+= smmsp .endif .if ${MK_PF} != "no" CHECK_UIDS+= proxy CHECK_GIDS+= proxy authpf .endif .if ${MK_UNBOUND} != "no" CHECK_UIDS+= unbound CHECK_GIDS+= unbound .endif _installcheck_world: __installcheck_UGID __installcheck_UGID: .PHONY .for uid in ${CHECK_UIDS} @if ! `id -u ${uid} >/dev/null 2>&1`; then \ echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \ false; \ fi .endfor .for gid in ${CHECK_GIDS} @if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \ echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \ false; \ fi .endfor .endif # # Required install tools to be saved in a scratch dir for safety. # .if ${MK_ZONEINFO} != "no" _zoneinfo= zic tzsetup .endif ITOOLS= [ awk cap_mkdb cat chflags chmod chown cmp cp \ date echo egrep find grep id install ${_install-info} \ ln make mkdir mtree mv pwd_mkdb \ rm sed services_mkdb sh strip sysctl test true uname wc ${_zoneinfo} \ ${LOCAL_ITOOLS} # Needed for share/man .if ${MK_MAN_UTILS} != "no" ITOOLS+=makewhatis .endif # # distributeworld # # Distributes everything compiled by a `buildworld'. # # installworld # # Installs everything compiled by a 'buildworld'. # # Non-base distributions produced by the base system EXTRA_DISTRIBUTIONS= doc .if defined(LIBCOMPAT) EXTRA_DISTRIBUTIONS+= lib${libcompat} .endif .if ${MK_TESTS} != "no" EXTRA_DISTRIBUTIONS+= tests .endif DEBUG_DISTRIBUTIONS= .if ${MK_DEBUG_FILES} != "no" DEBUG_DISTRIBUTIONS+= base ${EXTRA_DISTRIBUTIONS:S,doc,,:S,tests,,} .endif MTREE_MAGIC?= mtree 2.0 distributeworld installworld stageworld: _installcheck_world .PHONY mkdir -p ${INSTALLTMP} progs=$$(for prog in ${ITOOLS}; do \ if progpath=`which $$prog`; then \ echo $$progpath; \ else \ echo "Required tool $$prog not found in PATH." >&2; \ exit 1; \ fi; \ done); \ libs=$$(ldd -f "%o %p\n" -f "%o %p\n" $$progs 2>/dev/null | sort -u | \ while read line; do \ set -- $$line; \ if [ "$$2 $$3" != "not found" ]; then \ echo $$2; \ else \ echo "Required library $$1 not found." >&2; \ exit 1; \ fi; \ done); \ cp $$libs $$progs ${INSTALLTMP} cp -R $${PATH_LOCALE:-"/usr/share/locale"} ${INSTALLTMP}/locale .if defined(NO_ROOT) -mkdir -p ${METALOG:H} echo "#${MTREE_MAGIC}" > ${METALOG} .endif .if make(distributeworld) .for dist in ${EXTRA_DISTRIBUTIONS} -mkdir ${DESTDIR}/${DISTDIR}/${dist} mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \ -p ${DESTDIR}/${DISTDIR}/${dist} >/dev/null mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \ -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \ -p ${DESTDIR}/${DISTDIR}/${dist}/usr/include >/dev/null .if ${MK_DEBUG_FILES} != "no" mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \ -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib >/dev/null .endif .if defined(LIBCOMPAT) mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \ -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null .if ${MK_DEBUG_FILES} != "no" mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \ -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib/debug/usr >/dev/null .endif .endif .if ${MK_TESTS} != "no" && ${dist} == "tests" -mkdir -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE} mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \ -p ${DESTDIR}/${DISTDIR}/${dist}${TESTSBASE} >/dev/null .if ${MK_DEBUG_FILES} != "no" mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \ -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib/debug/${TESTSBASE} >/dev/null .endif .endif .if defined(NO_ROOT) ${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.root.dist | \ sed -e 's#^\./#./${dist}/#' >> ${METALOG} ${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.usr.dist | \ sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG} ${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.include.dist | \ sed -e 's#^\./#./${dist}/usr/include/#' >> ${METALOG} .if defined(LIBCOMPAT) ${IMAKEENV} mtree -C -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist | \ sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG} .endif .endif .endfor -mkdir ${DESTDIR}/${DISTDIR}/base ${_+_}cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \ METALOG=${METALOG} ${IMAKE_INSTALL} ${IMAKE_MTREE} \ DISTBASE=/base DESTDIR=${DESTDIR}/${DISTDIR}/base \ LOCAL_MTREE=${LOCAL_MTREE:Q} distrib-dirs .endif ${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}; \ ${IMAKEENV} rm -rf ${INSTALLTMP} .if make(distributeworld) .for dist in ${EXTRA_DISTRIBUTIONS} find ${DESTDIR}/${DISTDIR}/${dist} -mindepth 1 -type d -empty -delete .endfor .if defined(NO_ROOT) .for dist in base ${EXTRA_DISTRIBUTIONS} @# For each file that exists in this dist, print the corresponding @# line from the METALOG. This relies on the fact that @# a line containing only the filename will sort immediately before @# the relevant mtree line. cd ${DESTDIR}/${DISTDIR}; \ find ./${dist} | sort -u ${METALOG} - | \ awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \ ${DESTDIR}/${DISTDIR}/${dist}.meta .endfor .for dist in ${DEBUG_DISTRIBUTIONS} @# For each file that exists in this dist, print the corresponding @# line from the METALOG. This relies on the fact that @# a line containing only the filename will sort immediately before @# the relevant mtree line. cd ${DESTDIR}/${DISTDIR}; \ find ./${dist}/usr/lib/debug | sort -u ${METALOG} - | \ awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \ ${DESTDIR}/${DISTDIR}/${dist}.debug.meta .endfor .endif .endif packageworld: .PHONY .for dist in base ${EXTRA_DISTRIBUTIONS} .if defined(NO_ROOT) ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \ tar cvf - --exclude usr/lib/debug \ @${DESTDIR}/${DISTDIR}/${dist}.meta | \ ${XZ_CMD} > ${PACKAGEDIR}/${dist}.txz .else ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \ tar cvf - --exclude usr/lib/debug . | \ ${XZ_CMD} > ${PACKAGEDIR}/${dist}.txz .endif .endfor .for dist in ${DEBUG_DISTRIBUTIONS} . if defined(NO_ROOT) ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \ tar cvf - @${DESTDIR}/${DISTDIR}/${dist}.debug.meta | \ ${XZ_CMD} > ${PACKAGEDIR}/${dist}-dbg.txz . else ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \ tar cvLf - usr/lib/debug | \ ${XZ_CMD} > ${PACKAGEDIR}/${dist}-dbg.txz . endif .endfor # # reinstall # # If you have a build server, you can NFS mount the source and obj directories # and do a 'make reinstall' on the *client* to install new binaries from the # most recent server build. # restage reinstall: .MAKE .PHONY @echo "--------------------------------------------------------------" @echo ">>> Making hierarchy" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \ LOCAL_MTREE=${LOCAL_MTREE:Q} hierarchy .if make(restage) @echo "--------------------------------------------------------------" @echo ">>> Making distribution" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \ LOCAL_MTREE=${LOCAL_MTREE:Q} distribution .endif @echo @echo "--------------------------------------------------------------" @echo ">>> Installing everything" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install .if defined(LIBCOMPAT) ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install${libcompat} .endif redistribute: .MAKE .PHONY @echo "--------------------------------------------------------------" @echo ">>> Distributing everything" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute .if defined(LIBCOMPAT) ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute${libcompat} \ DISTRIBUTION=lib${libcompat} .endif distrib-dirs distribution: .MAKE .PHONY ${_+_}cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \ ${IMAKE_INSTALL} ${IMAKE_MTREE} METALOG=${METALOG} ${.TARGET} .if make(distribution) ${_+_}cd ${.CURDIR}; ${CROSSENV} PATH=${TMPPATH} \ ${MAKE} -f Makefile.inc1 ${IMAKE_INSTALL} \ METALOG=${METALOG} MK_TESTS=no installconfig .endif # # buildkernel and installkernel # # Which kernels to build and/or install is specified by setting # KERNCONF. If not defined a GENERIC kernel is built/installed. # Only the existing (depending TARGET) config files are used # for building kernels and only the first of these is designated # as the one being installed. # # Note that we have to use TARGET instead of TARGET_ARCH when # we're in kernel-land. Since only TARGET_ARCH is (expected) to # be set to cross-build, we have to make sure TARGET is set # properly. .if defined(KERNFAST) NO_KERNELCLEAN= t NO_KERNELCONFIG= t NO_KERNELOBJ= t # Shortcut for KERNCONF=Blah -DKERNFAST is now KERNFAST=Blah .if !defined(KERNCONF) && ${KERNFAST} != "1" KERNCONF=${KERNFAST} .endif .endif .if ${TARGET_ARCH} == "powerpc64" KERNCONF?= GENERIC64 .else KERNCONF?= GENERIC .endif INSTKERNNAME?= kernel KERNSRCDIR?= ${.CURDIR}/sys KRNLCONFDIR= ${KERNSRCDIR}/${TARGET}/conf KRNLOBJDIR= ${OBJTREE}${KERNSRCDIR} KERNCONFDIR?= ${KRNLCONFDIR} BUILDKERNELS= INSTALLKERNEL= .if defined(NO_INSTALLKERNEL) # All of the BUILDKERNELS loops start at index 1. BUILDKERNELS+= dummy .endif .for _kernel in ${KERNCONF} .if exists(${KERNCONFDIR}/${_kernel}) BUILDKERNELS+= ${_kernel} .if empty(INSTALLKERNEL) && !defined(NO_INSTALLKERNEL) INSTALLKERNEL= ${_kernel} .endif .endif .endfor ${WMAKE_TGTS:N_worldtmp:Nbuild${libcompat}} ${.ALLTARGETS:M_*:N_worldtmp}: .MAKE .PHONY # # buildkernel # # Builds all kernels defined by BUILDKERNELS. # buildkernel: .MAKE .PHONY .if empty(BUILDKERNELS:Ndummy) @echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \ false .endif @echo .for _kernel in ${BUILDKERNELS:Ndummy} @echo "--------------------------------------------------------------" @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`" @echo "--------------------------------------------------------------" @echo "===> ${_kernel}" mkdir -p ${KRNLOBJDIR} .if !defined(NO_KERNELCONFIG) @echo @echo "--------------------------------------------------------------" @echo ">>> stage 1: configuring the kernel" @echo "--------------------------------------------------------------" cd ${KRNLCONFDIR}; \ PATH=${TMPPATH} \ config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \ -I '${KERNCONFDIR}' '${KERNCONFDIR}/${_kernel}' .endif .if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN) @echo @echo "--------------------------------------------------------------" @echo ">>> stage 2.1: cleaning up the object tree" @echo "--------------------------------------------------------------" ${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR} .endif .if !defined(NO_KERNELOBJ) @echo @echo "--------------------------------------------------------------" @echo ">>> stage 2.2: rebuilding the object tree" @echo "--------------------------------------------------------------" ${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj .endif @echo @echo "--------------------------------------------------------------" @echo ">>> stage 2.3: build tools" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${KTMAKE} kernel-tools @echo @echo "--------------------------------------------------------------" @echo ">>> stage 3.1: building everything" @echo "--------------------------------------------------------------" ${_+_}cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ @echo "--------------------------------------------------------------" @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`" @echo "--------------------------------------------------------------" .endfor NO_INSTALLEXTRAKERNELS?= yes # # installkernel, etc. # # Install the kernel defined by INSTALLKERNEL # installkernel installkernel.debug \ reinstallkernel reinstallkernel.debug: _installcheck_kernel .PHONY .if !defined(NO_INSTALLKERNEL) .if empty(INSTALLKERNEL) @echo "ERROR: No kernel \"${KERNCONF}\" to install."; \ false .endif @echo "--------------------------------------------------------------" @echo ">>> Installing kernel ${INSTALLKERNEL}" @echo "--------------------------------------------------------------" cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \ ${CROSSENV} PATH=${TMPPATH} \ ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//} .endif .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes" .for _kernel in ${BUILDKERNELS:[2..-1]} @echo "--------------------------------------------------------------" @echo ">>> Installing kernel ${_kernel}" @echo "--------------------------------------------------------------" cd ${KRNLOBJDIR}/${_kernel}; \ ${CROSSENV} PATH=${TMPPATH} \ ${MAKE} ${IMAKE_INSTALL} KERNEL=${INSTKERNNAME}.${_kernel} ${.TARGET:S/kernel//} .endfor .endif distributekernel distributekernel.debug: .PHONY .if !defined(NO_INSTALLKERNEL) .if empty(INSTALLKERNEL) @echo "ERROR: No kernel \"${KERNCONF}\" to install."; \ false .endif mkdir -p ${DESTDIR}/${DISTDIR} .if defined(NO_ROOT) @echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.premeta .endif cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \ ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.premeta/} \ ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} KERNEL=${INSTKERNNAME} \ DESTDIR=${INSTALL_DDIR}/kernel \ ${.TARGET:S/distributekernel/install/} .if defined(NO_ROOT) @sed -e 's|^./kernel|.|' ${DESTDIR}/${DISTDIR}/kernel.premeta > \ ${DESTDIR}/${DISTDIR}/kernel.meta .endif .endif .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes" .for _kernel in ${BUILDKERNELS:[2..-1]} .if defined(NO_ROOT) @echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta .endif cd ${KRNLOBJDIR}/${_kernel}; \ ${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.${_kernel}.premeta/} \ ${IMAKE_MTREE} PATH=${TMPPATH} ${MAKE} \ KERNEL=${INSTKERNNAME}.${_kernel} \ DESTDIR=${INSTALL_DDIR}/kernel.${_kernel} \ ${.TARGET:S/distributekernel/install/} .if defined(NO_ROOT) @sed -e "s|^./kernel.${_kernel}|.|" \ ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta > \ ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta .endif .endfor .endif packagekernel: .PHONY .if defined(NO_ROOT) .if !defined(NO_INSTALLKERNEL) cd ${DESTDIR}/${DISTDIR}/kernel; \ tar cvf - --exclude '*.debug' \ @${DESTDIR}/${DISTDIR}/kernel.meta | \ ${XZ_CMD} > ${PACKAGEDIR}/kernel.txz .endif cd ${DESTDIR}/${DISTDIR}/kernel; \ tar cvf - --include '*/*/*.debug' \ @${DESTDIR}/${DISTDIR}/kernel.meta | \ ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes" .for _kernel in ${BUILDKERNELS:[2..-1]} cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \ tar cvf - --exclude '*.debug' \ @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \ ${XZ_CMD} > ${PACKAGEDIR}/kernel.${_kernel}.txz cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \ tar cvf - --include '*/*/*.debug' \ @${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta | \ ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}-dbg.txz .endfor .endif .else .if !defined(NO_INSTALLKERNEL) cd ${DESTDIR}/${DISTDIR}/kernel; \ tar cvf - --exclude '*.debug' . | \ ${XZ_CMD} > ${PACKAGEDIR}/kernel.txz .endif cd ${DESTDIR}/${DISTDIR}/kernel; \ tar cvf - --include '*/*/*.debug' $$(eval find .) | \ ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel-dbg.txz .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes" .for _kernel in ${BUILDKERNELS:[2..-1]} cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \ tar cvf - --exclude '*.debug' . | \ ${XZ_CMD} > ${PACKAGEDIR}/kernel.${_kernel}.txz cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \ tar cvf - --include '*/*/*.debug' $$(eval find .) | \ ${XZ_CMD} > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}-dbg.txz .endfor .endif .endif stagekernel: .PHONY ${_+_}${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} distributekernel PORTSDIR?= /usr/ports WSTAGEDIR?= ${MAKEOBJDIRPREFIX}${.CURDIR}/${TARGET}.${TARGET_ARCH}/worldstage KSTAGEDIR?= ${MAKEOBJDIRPREFIX}${.CURDIR}/${TARGET}.${TARGET_ARCH}/kernelstage REPODIR?= ${MAKEOBJDIRPREFIX}${.CURDIR}/repo PKGSIGNKEY?= # empty .ORDER: stage-packages create-packages .ORDER: create-packages create-world-packages .ORDER: create-packages create-kernel-packages .ORDER: create-packages sign-packages _pkgbootstrap: .PHONY .if !exists(${LOCALBASE}/sbin/pkg) @env ASSUME_ALWAYS_YES=YES pkg bootstrap .endif packages: .PHONY ${_+_}${MAKE} -C ${.CURDIR} PKG_VERSION=${PKG_VERSION} real-packages package-pkg: .PHONY rm -rf /tmp/ports.${TARGET} || : env ${WMAKEENV:Q} SRCDIR=${.CURDIR} PORTSDIR=${PORTSDIR} REVISION=${_REVISION} \ PKG_VERSION=${PKG_VERSION} REPODIR=${REPODIR} WSTAGEDIR=${WSTAGEDIR} \ sh ${.CURDIR}/release/scripts/make-pkg-package.sh real-packages: stage-packages create-packages sign-packages .PHONY stage-packages: .PHONY @mkdir -p ${REPODIR} ${WSTAGEDIR} ${KSTAGEDIR} ${_+_}@cd ${.CURDIR}; \ ${MAKE} DESTDIR=${WSTAGEDIR} -DNO_ROOT -B stageworld ; \ ${MAKE} DESTDIR=${KSTAGEDIR} -DNO_ROOT -B stagekernel create-packages: _pkgbootstrap .PHONY @mkdir -p ${REPODIR} ${_+_}@cd ${.CURDIR}; \ ${MAKE} DESTDIR=${WSTAGEDIR} \ PKG_VERSION=${PKG_VERSION} create-world-packages ; \ ${MAKE} DESTDIR=${KSTAGEDIR} \ PKG_VERSION=${PKG_VERSION} DISTDIR=kernel \ create-kernel-packages create-world-packages: _pkgbootstrap .PHONY @rm -f ${WSTAGEDIR}/*.plist 2>/dev/null || : @cd ${WSTAGEDIR} ; \ awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \ ${WSTAGEDIR}/METALOG @for plist in ${WSTAGEDIR}/*.plist; do \ plist=$${plist##*/} ; \ pkgname=$${plist%.plist} ; \ sh ${SRCDIR}/release/packages/generate-ucl.sh -o $${pkgname} \ -s ${SRCDIR} -u ${WSTAGEDIR}/$${pkgname}.ucl ; \ done @for plist in ${WSTAGEDIR}/*.plist; do \ plist=$${plist##*/} ; \ pkgname=$${plist%.plist} ; \ awk -F\" ' \ /^name/ { printf("===> Creating %s-", $$2); next } \ /^version/ { print $$2; next } \ ' ${WSTAGEDIR}/$${pkgname}.ucl ; \ pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh -o ALLOW_BASE_SHLIBS=yes \ create -M ${WSTAGEDIR}/$${pkgname}.ucl \ -p ${WSTAGEDIR}/$${pkgname}.plist \ -r ${WSTAGEDIR} \ -o ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION} ; \ done create-kernel-packages: _pkgbootstrap .PHONY .if exists(${KSTAGEDIR}/kernel.meta) .for flavor in "" -debug @cd ${KSTAGEDIR}/${DISTDIR} ; \ awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \ -v kernel=yes -v _kernconf=${INSTALLKERNEL} \ ${KSTAGEDIR}/kernel.meta ; \ cap_arg=`cd ${SRCDIR}/etc ; ${MAKE} -VCAP_MKDB_ENDIAN` ; \ pwd_arg=`cd ${SRCDIR}/etc ; ${MAKE} -VPWD_MKDB_ENDIAN` ; \ sed -e "s/%VERSION%/${PKG_VERSION}/" \ -e "s/%PKGNAME%/kernel-${INSTALLKERNEL:tl}${flavor}/" \ -e "s/%COMMENT%/FreeBSD ${INSTALLKERNEL} kernel ${flavor}/" \ -e "s/%DESC%/FreeBSD ${INSTALLKERNEL} kernel ${flavor}/" \ -e "s/%CAP_MKDB_ENDIAN%/$${cap_arg}/g" \ -e "s/%PWD_MKDB_ENDIAN%/$${pwd_arg}/g" \ ${SRCDIR}/release/packages/kernel.ucl \ > ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl ; \ awk -F\" ' \ /name/ { printf("===> Creating %s-", $$2); next } \ /version/ {print $$2; next } ' \ ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl ; \ pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh -o ALLOW_BASE_SHLIBS=yes \ create -M ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl \ -p ${KSTAGEDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.plist \ -r ${KSTAGEDIR}/${DISTDIR} \ -o ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION} .endfor .endif .if ${BUILDKERNELS:[#]} > 1 && ${NO_INSTALLEXTRAKERNELS} != "yes" .for _kernel in ${BUILDKERNELS:[2..-1]} .if exists(${KSTAGEDIR}/kernel.${_kernel}.meta) .for flavor in "" -debug @cd ${KSTAGEDIR}/kernel.${_kernel} ; \ awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \ -v kernel=yes -v _kernconf=${_kernel} \ ${KSTAGEDIR}/kernel.${_kernel}.meta ; \ cap_arg=`cd ${SRCDIR}/etc ; ${MAKE} -VCAP_MKDB_ENDIAN` ; \ pwd_arg=`cd ${SRCDIR}/etc ; ${MAKE} -VPWD_MKDB_ENDIAN` ; \ sed -e "s/%VERSION%/${PKG_VERSION}/" \ -e "s/%PKGNAME%/kernel-${_kernel:tl}${flavor}/" \ -e "s/%COMMENT%/FreeBSD ${_kernel} kernel ${flavor}/" \ -e "s/%DESC%/FreeBSD ${_kernel} kernel ${flavor}/" \ -e "s/%CAP_MKDB_ENDIAN%/$${cap_arg}/g" \ -e "s/%PWD_MKDB_ENDIAN%/$${pwd_arg}/g" \ ${SRCDIR}/release/packages/kernel.ucl \ > ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl ; \ awk -F\" ' \ /name/ { printf("===> Creating %s-", $$2); next } \ /version/ {print $$2; next } ' \ ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl ; \ pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh -o ALLOW_BASE_SHLIBS=yes \ create -M ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl \ -p ${KSTAGEDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.plist \ -r ${KSTAGEDIR}/kernel.${_kernel} \ -o ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION} .endfor .endif .endfor .endif sign-packages: _pkgbootstrap .PHONY @[ -L "${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/latest" ] && \ unlink ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/latest ; \ pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh repo \ -o ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION} \ ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION} \ ${PKGSIGNKEY} ; \ ln -s ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION} \ ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/latest # # # checkworld # # Run test suite on installed world. # checkworld: .PHONY @if [ ! -x "${LOCALBASE}/bin/kyua" ]; then \ echo "You need kyua (devel/kyua) to run the test suite." | /usr/bin/fmt; \ exit 1; \ fi ${_+_}PATH="$$PATH:${LOCALBASE}/bin" kyua test -k ${TESTSBASE}/Kyuafile # # # doxygen # # Build the API documentation with doxygen # doxygen: .PHONY @if [ ! -x "${LOCALBASE}/bin/doxygen" ]; then \ echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \ exit 1; \ fi ${_+_}cd ${.CURDIR}/tools/kerneldoc/subsys; ${MAKE} obj all # # update # # Update the source tree(s), by running svn/svnup to update to the # latest copy. # update: .PHONY .if defined(SVN_UPDATE) @echo "--------------------------------------------------------------" @echo ">>> Updating ${.CURDIR} using Subversion" @echo "--------------------------------------------------------------" @(cd ${.CURDIR}; ${SVN} update ${SVNFLAGS}) .endif # # ------------------------------------------------------------------------ # # From here onwards are utility targets used by the 'make world' and # related targets. If your 'world' breaks, you may like to try to fix # the problem and manually run the following targets to attempt to # complete the build. Beware, this is *not* guaranteed to work, you # need to have a pretty good grip on the current state of the system # to attempt to manually finish it. If in doubt, 'make world' again. # # # legacy: Build compatibility shims for the next three targets. This is a # minimal set of tools and shims necessary to compensate for older systems # which don't have the APIs required by the targets built in bootstrap-tools, # build-tools or cross-tools. # # ELF Tool Chain libraries are needed for ELF tools and dtrace tools. # r296685 fix cross-endian objcopy .if ${BOOTSTRAPPING} < 1100102 _elftoolchain_libs= lib/libelf lib/libdwarf .endif legacy: .PHONY .if ${BOOTSTRAPPING} < ${MINIMUM_SUPPORTED_OSREL} && ${BOOTSTRAPPING} != 0 @echo "ERROR: Source upgrades from versions prior to ${MINIMUM_SUPPORTED_REL} are not supported."; \ false .endif .for _tool in tools/build ${_elftoolchain_libs} ${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,all,install)"; \ cd ${.CURDIR}/${_tool}; \ ${MAKE} DIRPRFX=${_tool}/ obj; \ ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy includes; \ ${MAKE} DIRPRFX=${_tool}/ MK_INCLUDES=no all; \ ${MAKE} DIRPRFX=${_tool}/ MK_INCLUDES=no \ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install .endfor # # bootstrap-tools: Build tools needed for compatibility. These are binaries that # are built to build other binaries in the system. However, the focus of these # binaries is usually quite narrow. Bootstrap tools use the host's compiler and # libraries, augmented by -legacy. # _bt= _bootstrap-tools .if ${MK_GAMES} != "no" _strfile= usr.bin/fortune/strfile .endif .if ${MK_GCC} != "no" && ${MK_CXX} != "no" _gperf= gnu/usr.bin/gperf .endif .if ${MK_SHAREDOCS} != "no" && ${MK_GROFF} != "no" _groff= gnu/usr.bin/groff \ usr.bin/soelim .endif .if ${MK_VT} != "no" _vtfontcvt= usr.bin/vtfontcvt .endif .if ${BOOTSTRAPPING} < 1000033 _libopenbsd= lib/libopenbsd _m4= usr.bin/m4 _lex= usr.bin/lex ${_bt}-usr.bin/m4: ${_bt}-lib/libopenbsd ${_bt}-usr.bin/lex: ${_bt}-usr.bin/m4 .endif # r245440 mtree -N support added # r313404 requires sha384.h for libnetbsd, added to libmd in r292782 .if ${BOOTSTRAPPING} < 1100093 _nmtree= lib/libmd \ lib/libnetbsd \ usr.sbin/nmtree ${_bt}-lib/libnetbsd: ${_bt}-lib/libmd ${_bt}-usr.sbin/nmtree: ${_bt}-lib/libnetbsd .endif .if ${BOOTSTRAPPING} < 1000027 _cat= bin/cat .endif # r264059 support for status= .if ${BOOTSTRAPPING} < 1100017 _dd= bin/dd .endif # r277259 crunchide: Correct 64-bit section header offset # r281674 crunchide: always include both 32- and 64-bit ELF support .if ${BOOTSTRAPPING} < 1100078 _crunchide= usr.sbin/crunch/crunchide .endif # r285986 crunchen: use STRIPBIN rather than STRIP # 1100113: Support MK_AUTO_OBJ # 1100509: META_MODE fixes .if ${BOOTSTRAPPING} < 1100078 || \ (${MK_AUTO_OBJ} == "yes" && ${BOOTSTRAPPING} < 1100114) || \ (${MK_META_MODE} == "yes" && ${BOOTSTRAPPING} < 1200006) _crunchgen= usr.sbin/crunch/crunchgen .endif # r296926 -P keymap search path, MFC to stable/10 in r298297 .if ${BOOTSTRAPPING} < 1003501 || \ (${BOOTSTRAPPING} >= 1100000 && ${BOOTSTRAPPING} < 1100103) _kbdcontrol= usr.sbin/kbdcontrol .endif _yacc= lib/liby \ usr.bin/yacc ${_bt}-usr.bin/yacc: ${_bt}-lib/liby .if ${MK_BSNMP} != "no" _gensnmptree= usr.sbin/bsnmpd/gensnmptree .endif # We need to build tblgen when we're building clang either as # the bootstrap compiler, or as the part of the normal build. .if ${MK_CLANG_BOOTSTRAP} != "no" || ${MK_CLANG} != "no" _clang_tblgen= \ lib/clang/libllvmminimal \ usr.bin/clang/llvm-tblgen \ usr.bin/clang/clang-tblgen ${_bt}-usr.bin/clang/clang-tblgen: ${_bt}-lib/clang/libllvmminimal ${_bt}-usr.bin/clang/llvm-tblgen: ${_bt}-lib/clang/libllvmminimal .endif # Default to building the GPL DTC, but build the BSDL one if users explicitly # request it. _dtc= usr.bin/dtc .if ${MK_GPL_DTC} != "no" _dtc= gnu/usr.bin/dtc .endif .if ${MK_KERBEROS} != "no" _kerberos5_bootstrap_tools= \ kerberos5/tools/make-roken \ kerberos5/lib/libroken \ kerberos5/lib/libvers \ kerberos5/tools/asn1_compile \ kerberos5/tools/slc \ usr.bin/compile_et .ORDER: ${_kerberos5_bootstrap_tools:C/^/${_bt}-/g} .endif # r283777 makewhatis(1) replaced with mandoc version which builds a database. -.if ${MK_MANDOCDB} != "no" && ${BOOTSTRAPPING} < 1100075 +.if ${MK_MANDOCDB} != "no" _libopenbsd?= lib/libopenbsd -_makewhatis= lib/libsqlite3 \ - usr.bin/mandoc -${_bt}-usr.bin/mandoc: ${_bt}-lib/libopenbsd ${_bt}-lib/libsqlite3 +_makewhatis= usr.bin/mandoc +${_bt}-usr.bin/mandoc: ${_bt}-lib/libopenbsd .endif bootstrap-tools: .PHONY # Please document (add comment) why something is in 'bootstrap-tools'. # Try to bound the building of the bootstrap-tool to just the # FreeBSD versions that need the tool built at this stage of the build. .for _tool in \ ${_clang_tblgen} \ ${_kerberos5_bootstrap_tools} \ ${_strfile} \ ${_gperf} \ ${_groff} \ ${_dtc} \ ${_cat} \ ${_dd} \ ${_kbdcontrol} \ usr.bin/lorder \ ${_libopenbsd} \ ${_makewhatis} \ usr.bin/rpcgen \ ${_yacc} \ ${_m4} \ ${_lex} \ usr.bin/xinstall \ ${_gensnmptree} \ usr.sbin/config \ ${_crunchide} \ ${_crunchgen} \ ${_nmtree} \ ${_vtfontcvt} \ usr.bin/localedef ${_bt}-${_tool}: .PHONY .MAKE ${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \ cd ${.CURDIR}/${_tool}; \ ${MAKE} DIRPRFX=${_tool}/ obj; \ ${MAKE} DIRPRFX=${_tool}/ all; \ ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install bootstrap-tools: ${_bt}-${_tool} .endfor # # build-tools: Build special purpose build tools # .if !defined(NO_SHARE) _share= share/syscons/scrnmaps .endif .if ${MK_GCC} != "no" _gcc_tools= gnu/usr.bin/cc/cc_tools .endif .if ${MK_RESCUE} != "no" # rescue includes programs that have build-tools targets _rescue=rescue/rescue .endif .for _tool in \ bin/csh \ bin/sh \ ${LOCAL_TOOL_DIRS} \ lib/ncurses/ncurses \ lib/ncurses/ncursesw \ ${_rescue} \ ${_share} \ usr.bin/awk \ lib/libmagic \ usr.bin/mkesdb_static \ usr.bin/mkcsmapper_static \ usr.bin/vi/catalog build-tools_${_tool}: .PHONY ${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \ cd ${.CURDIR}/${_tool}; \ ${MAKE} DIRPRFX=${_tool}/ obj; \ ${MAKE} DIRPRFX=${_tool}/ build-tools build-tools: build-tools_${_tool} .endfor .for _tool in \ ${_gcc_tools} build-tools_${_tool}: .PHONY ${_+_}@${ECHODIR} "===> ${_tool} (obj,all)"; \ cd ${.CURDIR}/${_tool}; \ ${MAKE} DIRPRFX=${_tool}/ obj; \ ${MAKE} DIRPRFX=${_tool}/ all build-tools: build-tools_${_tool} .endfor # # kernel-tools: Build kernel-building tools # kernel-tools: .PHONY mkdir -p ${MAKEOBJDIRPREFIX}/usr mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \ -p ${MAKEOBJDIRPREFIX}/usr >/dev/null # # cross-tools: All the tools needed to build the rest of the system after # we get done with the earlier stages. It is the last set of tools needed # to begin building the target binaries. # .if ${TARGET_ARCH} != ${MACHINE_ARCH} .if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386" _btxld= usr.sbin/btxld .endif .endif # Rebuild ctfconvert and ctfmerge to avoid difficult-to-diagnose failures # resulting from missing bug fixes or ELF Toolchain updates. .if ${MK_CDDL} != "no" _dtrace_tools= cddl/lib/libctf cddl/usr.bin/ctfconvert \ cddl/usr.bin/ctfmerge .endif # If we're given an XAS, don't build binutils. .if ${XAS:M/*} == "" .if ${MK_BINUTILS_BOOTSTRAP} != "no" _binutils= gnu/usr.bin/binutils .endif .if ${MK_ELFTOOLCHAIN_BOOTSTRAP} != "no" _elftctools= lib/libelftc \ lib/libpe \ usr.bin/elfcopy \ usr.bin/nm \ usr.bin/size \ usr.bin/strings # These are not required by the build, but can be useful for developers who # cross-build on a FreeBSD 10 host: _elftctools+= usr.bin/addr2line .endif .elif ${TARGET_ARCH} != ${MACHINE_ARCH} && ${MK_ELFTOOLCHAIN_BOOTSTRAP} != "no" # If cross-building with an external binutils we still need to build strip for # the target (for at least crunchide). _elftctools= lib/libelftc \ lib/libpe \ usr.bin/elfcopy .endif .if ${MK_CLANG_BOOTSTRAP} != "no" _clang= usr.bin/clang _clang_libs= lib/clang .endif .if ${MK_GCC_BOOTSTRAP} != "no" _cc= gnu/usr.bin/cc .endif .if ${MK_USB} != "no" _usb_tools= sys/boot/usb/tools .endif cross-tools: .MAKE .PHONY .for _tool in \ ${_clang_libs} \ ${_clang} \ ${_binutils} \ ${_elftctools} \ ${_dtrace_tools} \ ${_cc} \ ${_btxld} \ ${_usb_tools} ${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \ cd ${.CURDIR}/${_tool}; \ ${MAKE} DIRPRFX=${_tool}/ obj; \ ${MAKE} DIRPRFX=${_tool}/ all; \ ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install .endfor NXBDESTDIR= ${OBJTREE}/nxb-bin NXBENV= MAKEOBJDIRPREFIX=${OBJTREE}/nxb \ TOOLS_PREFIX= \ INSTALL="sh ${.CURDIR}/tools/install.sh" \ PATH=${PATH}:${OBJTREE}/gperf_for_gcc/usr/bin NXBMAKE= ${NXBENV} ${MAKE} \ LLVM_TBLGEN=${NXBDESTDIR}/usr/bin/llvm-tblgen \ CLANG_TBLGEN=${NXBDESTDIR}/usr/bin/clang-tblgen \ MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH} \ MK_GDB=no MK_TESTS=no \ SSP_CFLAGS= \ MK_HTML=no NO_LINT=yes MK_MAN=no \ -DNO_PIC MK_PROFILE=no -DNO_SHARED \ -DNO_CPU_CFLAGS MK_WARNS=no MK_CTF=no \ MK_CLANG_EXTRAS=no MK_CLANG_FULL=no \ MK_LLDB=no MK_DEBUG_FILES=no # native-xtools is the current target for qemu-user cross builds of ports # via poudriere and the imgact_binmisc kernel module. # For non-clang enabled targets that are still using the in tree gcc # we must build a gperf binary for one instance of its Makefiles. On # clang-enabled systems, the gperf binary is obsolete. native-xtools: .PHONY .if ${MK_GCC_BOOTSTRAP} != "no" mkdir -p ${OBJTREE}/gperf_for_gcc/usr/bin ${_+_}@${ECHODIR} "===> ${_gperf} (obj,all,install)"; \ cd ${.CURDIR}/${_gperf}; \ ${NXBMAKE} DIRPRFX=${_gperf}/ obj; \ ${NXBMAKE} DIRPRFX=${_gperf}/ all; \ ${NXBMAKE} DIRPRFX=${_gperf}/ DESTDIR=${OBJTREE}/gperf_for_gcc install .endif mkdir -p ${NXBDESTDIR}/bin ${NXBDESTDIR}/sbin ${NXBDESTDIR}/usr mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \ -p ${NXBDESTDIR}/usr >/dev/null mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \ -p ${NXBDESTDIR}/usr/include >/dev/null .if ${MK_DEBUG_FILES} != "no" mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \ -p ${NXBDESTDIR}/usr/lib >/dev/null .endif .for _tool in \ bin/cat \ bin/chmod \ bin/cp \ bin/csh \ bin/echo \ bin/expr \ bin/hostname \ bin/ln \ bin/ls \ bin/mkdir \ bin/mv \ bin/ps \ bin/realpath \ bin/rm \ bin/rmdir \ bin/sh \ bin/sleep \ ${_clang_tblgen} \ usr.bin/ar \ ${_binutils} \ ${_elftctools} \ ${_cc} \ ${_gcc_tools} \ ${_clang_libs} \ ${_clang} \ sbin/md5 \ sbin/sysctl \ gnu/usr.bin/diff \ usr.bin/awk \ usr.bin/basename \ usr.bin/bmake \ usr.bin/bzip2 \ usr.bin/cmp \ usr.bin/dirname \ usr.bin/env \ usr.bin/fetch \ usr.bin/find \ usr.bin/grep \ usr.bin/gzip \ usr.bin/id \ usr.bin/lex \ usr.bin/lorder \ usr.bin/mktemp \ usr.bin/mt \ usr.bin/patch \ usr.bin/readelf \ usr.bin/sed \ usr.bin/sort \ usr.bin/tar \ usr.bin/touch \ usr.bin/tr \ usr.bin/true \ usr.bin/uniq \ usr.bin/unzip \ usr.bin/xargs \ usr.bin/xinstall \ usr.bin/xz \ usr.bin/yacc \ usr.sbin/chown ${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \ cd ${.CURDIR}/${_tool}; \ ${NXBMAKE} DIRPRFX=${_tool}/ obj; \ ${NXBMAKE} DIRPRFX=${_tool}/ all; \ ${NXBMAKE} DIRPRFX=${_tool}/ DESTDIR=${NXBDESTDIR} install .endfor # # hierarchy - ensure that all the needed directories are present # hierarchy hier: .MAKE .PHONY ${_+_}cd ${.CURDIR}/etc; ${HMAKE} distrib-dirs # # libraries - build all libraries, and install them under ${DESTDIR}. # # The list of libraries with dependents (${_prebuild_libs}) and their # interdependencies (__L) are built automatically by the # ${.CURDIR}/tools/make_libdeps.sh script. # libraries: .MAKE .PHONY ${_+_}cd ${.CURDIR}; \ ${MAKE} -f Makefile.inc1 _prereq_libs; \ ${MAKE} -f Makefile.inc1 _startup_libs; \ ${MAKE} -f Makefile.inc1 _prebuild_libs; \ ${MAKE} -f Makefile.inc1 _generic_libs # # static libgcc.a prerequisite for shared libc # _prereq_libs= gnu/lib/libssp/libssp_nonshared gnu/lib/libgcc lib/libcompiler_rt # These dependencies are not automatically generated: # # gnu/lib/csu, gnu/lib/libgcc, lib/csu and lib/libc must be built before # all shared libraries for ELF. # _startup_libs= gnu/lib/csu _startup_libs+= lib/csu _startup_libs+= gnu/lib/libgcc _startup_libs+= lib/libcompiler_rt _startup_libs+= lib/libc _startup_libs+= lib/libc_nonshared .if ${MK_LIBCPLUSPLUS} != "no" _startup_libs+= lib/libcxxrt .endif gnu/lib/libgcc__L: lib/libc__L gnu/lib/libgcc__L: lib/libc_nonshared__L .if ${MK_LIBCPLUSPLUS} != "no" lib/libcxxrt__L: gnu/lib/libgcc__L .endif _prebuild_libs= ${_kerberos5_lib_libasn1} \ ${_kerberos5_lib_libhdb} \ ${_kerberos5_lib_libheimbase} \ ${_kerberos5_lib_libheimntlm} \ ${_libsqlite3} \ ${_kerberos5_lib_libheimipcc} \ ${_kerberos5_lib_libhx509} ${_kerberos5_lib_libkrb5} \ ${_kerberos5_lib_libroken} \ ${_kerberos5_lib_libwind} \ lib/libbz2 ${_libcom_err} lib/libcrypt \ lib/libelf lib/libexpat \ lib/libfigpar \ ${_lib_libgssapi} \ lib/libkiconv lib/libkvm lib/liblzma lib/libmd lib/libnv \ ${_lib_casper} \ lib/ncurses/ncurses lib/ncurses/ncursesw \ lib/libopie lib/libpam/libpam ${_lib_libthr} \ ${_lib_libradius} lib/libsbuf lib/libtacplus \ lib/libgeom \ ${_cddl_lib_libumem} ${_cddl_lib_libnvpair} \ ${_cddl_lib_libuutil} \ ${_cddl_lib_libavl} \ ${_cddl_lib_libzfs_core} \ ${_cddl_lib_libctf} \ lib/libutil lib/libpjdlog ${_lib_libypclnt} lib/libz lib/msun \ ${_secure_lib_libcrypto} ${_lib_libldns} \ ${_secure_lib_libssh} ${_secure_lib_libssl} \ gnu/lib/libdialog .if ${MK_GNUCXX} != "no" _prebuild_libs+= gnu/lib/libstdc++ gnu/lib/libsupc++ gnu/lib/libstdc++__L: lib/msun__L gnu/lib/libsupc++__L: gnu/lib/libstdc++__L .endif .if ${MK_LIBCPLUSPLUS} != "no" _prebuild_libs+= lib/libc++ .endif lib/libgeom__L: lib/libexpat__L lib/libkvm__L: lib/libelf__L .if ${MK_LIBTHR} != "no" _lib_libthr= lib/libthr .endif .if ${MK_RADIUS_SUPPORT} != "no" _lib_libradius= lib/libradius .endif .if ${MK_OFED} != "no" _ofed_lib= contrib/ofed/usr.lib _prebuild_libs+= contrib/ofed/usr.lib/libosmcomp _prebuild_libs+= contrib/ofed/usr.lib/libopensm _prebuild_libs+= contrib/ofed/usr.lib/libibcommon _prebuild_libs+= contrib/ofed/usr.lib/libibverbs _prebuild_libs+= contrib/ofed/usr.lib/libibumad contrib/ofed/usr.lib/libopensm__L: lib/libthr__L contrib/ofed/usr.lib/libosmcomp__L: lib/libthr__L contrib/ofed/usr.lib/libibumad__L: contrib/ofed/usr.lib/libibcommon__L .endif .if ${MK_CASPER} != "no" _lib_casper= lib/libcasper .endif lib/libpjdlog__L: lib/libutil__L lib/libcasper__L: lib/libnv__L lib/liblzma__L: lib/libthr__L _generic_libs= ${_cddl_lib} gnu/lib ${_kerberos5_lib} lib ${_secure_lib} usr.bin/lex/lib ${_ofed_lib} .for _DIR in ${LOCAL_LIB_DIRS} .if exists(${.CURDIR}/${_DIR}/Makefile) && empty(_generic_libs:M${_DIR}) _generic_libs+= ${_DIR} .endif .endfor lib/libopie__L lib/libtacplus__L: lib/libmd__L .if ${MK_CDDL} != "no" _cddl_lib_libumem= cddl/lib/libumem _cddl_lib_libnvpair= cddl/lib/libnvpair _cddl_lib_libavl= cddl/lib/libavl _cddl_lib_libuutil= cddl/lib/libuutil _cddl_lib_libzfs_core= cddl/lib/libzfs_core _cddl_lib_libctf= cddl/lib/libctf _cddl_lib= cddl/lib cddl/lib/libzfs_core__L: cddl/lib/libnvpair__L cddl/lib/libzfs__L: lib/libgeom__L cddl/lib/libctf__L: lib/libz__L .endif # cddl/lib/libdtrace requires lib/libproc and lib/librtld_db; it's only built # on select architectures though (see cddl/lib/Makefile) .if ${MACHINE_CPUARCH} != "sparc64" _prebuild_libs+= lib/libproc lib/librtld_db .endif .if ${MK_CRYPT} != "no" .if ${MK_OPENSSL} != "no" _secure_lib_libcrypto= secure/lib/libcrypto _secure_lib_libssl= secure/lib/libssl lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L .if ${MK_LDNS} != "no" _lib_libldns= lib/libldns lib/libldns__L: secure/lib/libcrypto__L .endif .if ${MK_OPENSSH} != "no" _secure_lib_libssh= secure/lib/libssh secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L .if ${MK_LDNS} != "no" secure/lib/libssh__L: lib/libldns__L .endif .if ${MK_GSSAPI} != "no" && ${MK_KERBEROS_SUPPORT} != "no" secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \ kerberos5/lib/libhx509__L kerberos5/lib/libasn1__L lib/libcom_err__L \ lib/libmd__L kerberos5/lib/libroken__L .endif .endif .endif _secure_lib= secure/lib .endif .if ${MK_KERBEROS} != "no" kerberos5/lib/libasn1__L: lib/libcom_err__L kerberos5/lib/libroken__L kerberos5/lib/libhdb__L: kerberos5/lib/libasn1__L lib/libcom_err__L \ kerberos5/lib/libkrb5__L kerberos5/lib/libroken__L \ kerberos5/lib/libwind__L lib/libsqlite3__L kerberos5/lib/libheimntlm__L: secure/lib/libcrypto__L kerberos5/lib/libkrb5__L \ kerberos5/lib/libroken__L lib/libcom_err__L kerberos5/lib/libhx509__L: kerberos5/lib/libasn1__L lib/libcom_err__L \ secure/lib/libcrypto__L kerberos5/lib/libroken__L kerberos5/lib/libwind__L kerberos5/lib/libkrb5__L: kerberos5/lib/libasn1__L lib/libcom_err__L \ lib/libcrypt__L secure/lib/libcrypto__L kerberos5/lib/libhx509__L \ kerberos5/lib/libroken__L kerberos5/lib/libwind__L \ kerberos5/lib/libheimbase__L kerberos5/lib/libheimipcc__L kerberos5/lib/libroken__L: lib/libcrypt__L kerberos5/lib/libwind__L: kerberos5/lib/libroken__L lib/libcom_err__L kerberos5/lib/libheimbase__L: lib/libthr__L kerberos5/lib/libheimipcc__L: kerberos5/lib/libroken__L kerberos5/lib/libheimbase__L lib/libthr__L .endif lib/libsqlite3__L: lib/libthr__L .if ${MK_GSSAPI} != "no" _lib_libgssapi= lib/libgssapi .endif .if ${MK_KERBEROS} != "no" _kerberos5_lib= kerberos5/lib _kerberos5_lib_libasn1= kerberos5/lib/libasn1 _kerberos5_lib_libhdb= kerberos5/lib/libhdb _kerberos5_lib_libheimbase= kerberos5/lib/libheimbase _kerberos5_lib_libkrb5= kerberos5/lib/libkrb5 _kerberos5_lib_libhx509= kerberos5/lib/libhx509 _kerberos5_lib_libroken= kerberos5/lib/libroken _kerberos5_lib_libheimntlm= kerberos5/lib/libheimntlm _libsqlite3= lib/libsqlite3 _kerberos5_lib_libheimipcc= kerberos5/lib/libheimipcc _kerberos5_lib_libwind= kerberos5/lib/libwind _libcom_err= lib/libcom_err .endif .if ${MK_NIS} != "no" _lib_libypclnt= lib/libypclnt .endif .if ${MK_OPENSSL} == "no" lib/libradius__L: lib/libmd__L .endif lib/libproc__L: \ ${_cddl_lib_libctf:D${_cddl_lib_libctf}__L} lib/libelf__L lib/librtld_db__L lib/libutil__L .if ${MK_CXX} != "no" .if ${MK_LIBCPLUSPLUS} != "no" lib/libproc__L: lib/libcxxrt__L .else # This implies MK_GNUCXX != "no"; see lib/libproc lib/libproc__L: gnu/lib/libsupc++__L .endif .endif gnu/lib/libdialog__L: lib/msun__L lib/ncurses/ncursesw__L .for _lib in ${_prereq_libs} ${_lib}__PL: .PHONY .MAKE .if exists(${.CURDIR}/${_lib}) ${_+_}@${ECHODIR} "===> ${_lib} (obj,all,install)"; \ cd ${.CURDIR}/${_lib}; \ ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj; \ ${MAKE} MK_TESTS=no MK_PROFILE=no -DNO_PIC \ DIRPRFX=${_lib}/ all; \ ${MAKE} MK_TESTS=no MK_PROFILE=no -DNO_PIC \ DIRPRFX=${_lib}/ install .endif .endfor .for _lib in ${_startup_libs} ${_prebuild_libs} ${_generic_libs} ${_lib}__L: .PHONY .MAKE .if exists(${.CURDIR}/${_lib}) ${_+_}@${ECHODIR} "===> ${_lib} (obj,all,install)"; \ cd ${.CURDIR}/${_lib}; \ ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ obj; \ ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ all; \ ${MAKE} MK_TESTS=no DIRPRFX=${_lib}/ install .endif .endfor _prereq_libs: ${_prereq_libs:S/$/__PL/} _startup_libs: ${_startup_libs:S/$/__L/} _prebuild_libs: ${_prebuild_libs:S/$/__L/} _generic_libs: ${_generic_libs:S/$/__L/} # Enable SUBDIR_PARALLEL when not calling 'make all', unless called from # 'everything' with _PARALLEL_SUBDIR_OK set. This is because it is unlikely # that running 'make all' from the top-level, especially with a SUBDIR_OVERRIDE # or LOCAL_DIRS set, will have a reliable build if SUBDIRs are built in # parallel. This is safe for the world stage of buildworld though since it has # already built libraries in a proper order and installed includes into # WORLDTMP. Special handling is done for SUBDIR ordering for 'install*' to # avoid trashing a system if it crashes mid-install. .if !make(all) || defined(_PARALLEL_SUBDIR_OK) SUBDIR_PARALLEL= .endif .include .if make(check-old) || make(check-old-dirs) || \ make(check-old-files) || make(check-old-libs) || \ make(delete-old) || make(delete-old-dirs) || \ make(delete-old-files) || make(delete-old-libs) # # check for / delete old files section # .include "ObsoleteFiles.inc" OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \ else you can not start such an application. Consult UPDATING for more \ information regarding how to cope with the removal/revision bump of a \ specific library." .if !defined(BATCH_DELETE_OLD_FILES) RM_I=-i .else RM_I=-v .endif delete-old-files: .PHONY @echo ">>> Removing old files (only deletes safe to delete libs)" # Ask for every old file if the user really wants to remove it. # It's annoying, but better safe than sorry. # NB: We cannot pass the list of OLD_FILES as a parameter because the # argument list will get too long. Using .for/.endfor make "loops" will make # the Makefile parser segfault. @exec 3<&0; \ cd ${.CURDIR}; \ ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \ -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \ while read file; do \ if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \ chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \ rm ${RM_I} "${DESTDIR}/$${file}" <&3; \ fi; \ for ext in debug symbols; do \ if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \ "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \ rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \ <&3; \ fi; \ done; \ done # Remove catpages without corresponding manpages. @exec 3<&0; \ find ${DESTDIR}/usr/share/man/cat* ! -type d | \ sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \ while read catpage; do \ read manpage; \ if [ ! -e "$${manpage}" ]; then \ rm ${RM_I} $${catpage} <&3; \ fi; \ done @echo ">>> Old files removed" check-old-files: .PHONY @echo ">>> Checking for old files" @cd ${.CURDIR}; \ ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \ -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \ while read file; do \ if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \ echo "${DESTDIR}/$${file}"; \ fi; \ for ext in debug symbols; do \ if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \ echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \ fi; \ done; \ done # Check for catpages without corresponding manpages. @find ${DESTDIR}/usr/share/man/cat* ! -type d | \ sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \ while read catpage; do \ read manpage; \ if [ ! -e "$${manpage}" ]; then \ echo $${catpage}; \ fi; \ done delete-old-libs: .PHONY @echo ">>> Removing old libraries" @echo "${OLD_LIBS_MESSAGE}" | fmt @exec 3<&0; \ cd ${.CURDIR}; \ ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \ -V OLD_LIBS | xargs -n1 | \ while read file; do \ if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \ chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \ rm ${RM_I} "${DESTDIR}/$${file}" <&3; \ fi; \ for ext in debug symbols; do \ if ! [ -e "${DESTDIR}/$${file}" ] && [ -f \ "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \ rm ${RM_I} "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" \ <&3; \ fi; \ done; \ done @echo ">>> Old libraries removed" check-old-libs: .PHONY @echo ">>> Checking for old libraries" @cd ${.CURDIR}; \ ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \ -V OLD_LIBS | xargs -n1 | \ while read file; do \ if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \ echo "${DESTDIR}/$${file}"; \ fi; \ for ext in debug symbols; do \ if [ -f "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}" ]; then \ echo "${DESTDIR}${DEBUGDIR}/$${file}.$${ext}"; \ fi; \ done; \ done delete-old-dirs: .PHONY @echo ">>> Removing old directories" @cd ${.CURDIR}; \ ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \ -V OLD_DIRS | xargs -n1 | sort -r | \ while read dir; do \ if [ -d "${DESTDIR}/$${dir}" ]; then \ rmdir -v "${DESTDIR}/$${dir}" || true; \ elif [ -L "${DESTDIR}/$${dir}" ]; then \ echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \ fi; \ if [ -d "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \ rmdir -v "${DESTDIR}${DEBUGDIR}/$${dir}" || true; \ elif [ -L "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \ echo "${DESTDIR}${DEBUGDIR}/$${dir} is a link, please remove everything manually."; \ fi; \ done @echo ">>> Old directories removed" check-old-dirs: .PHONY @echo ">>> Checking for old directories" @cd ${.CURDIR}; \ ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \ -V OLD_DIRS | xargs -n1 | \ while read dir; do \ if [ -d "${DESTDIR}/$${dir}" ]; then \ echo "${DESTDIR}/$${dir}"; \ elif [ -L "${DESTDIR}/$${dir}" ]; then \ echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \ fi; \ if [ -d "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \ echo "${DESTDIR}${DEBUGDIR}/$${dir}"; \ elif [ -L "${DESTDIR}${DEBUGDIR}/$${dir}" ]; then \ echo "${DESTDIR}${DEBUGDIR}/$${dir} is a link, please remove everything manually."; \ fi; \ done delete-old: delete-old-files delete-old-dirs .PHONY @echo "To remove old libraries run '${MAKE_CMD} delete-old-libs'." check-old: check-old-files check-old-libs check-old-dirs .PHONY @echo "To remove old files and directories run '${MAKE_CMD} delete-old'." @echo "To remove old libraries run '${MAKE_CMD} delete-old-libs'." .endif # # showconfig - show build configuration. # showconfig: .PHONY @(${MAKE} -n -f ${.CURDIR}/sys/conf/kern.opts.mk -V dummy -dg1; \ ${MAKE} -n -f ${.CURDIR}/share/mk/src.opts.mk -V dummy -dg1) 2>&1 | grep ^MK_ | sort -u .if !empty(KRNLOBJDIR) && !empty(KERNCONF) DTBOUTPUTPATH= ${KRNLOBJDIR}/${KERNCONF}/ .if !defined(FDT_DTS_FILE) || empty(FDT_DTS_FILE) .if exists(${KERNCONFDIR}/${KERNCONF}) FDT_DTS_FILE!= awk 'BEGIN {FS="="} /^makeoptions[[:space:]]+FDT_DTS_FILE/ {print $$2}' \ '${KERNCONFDIR}/${KERNCONF}' ; echo .endif .endif .endif .if !defined(DTBOUTPUTPATH) || !exists(${DTBOUTPUTPATH}) DTBOUTPUTPATH= ${.CURDIR} .endif # # Build 'standalone' Device Tree Blob # builddtb: .PHONY @PATH=${TMPPATH} MACHINE=${TARGET} \ ${.CURDIR}/sys/tools/fdt/make_dtb.sh ${.CURDIR}/sys \ "${FDT_DTS_FILE}" ${DTBOUTPUTPATH} ############### # cleanworld # In the following, the first 'rm' in a series will usually remove all # files and directories. If it does not, then there are probably some # files with file flags set, so this unsets them and tries the 'rm' a # second time. There are situations where this target will be cleaning # some directories via more than one method, but that duplication is # needed to correctly handle all the possible situations. Removing all # files without file flags set in the first 'rm' instance saves time, # because 'chflags' will need to operate on fewer files afterwards. # # It is expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be # created by bsd.obj.mk, except that we don't want to .include that file # in this makefile. # BW_CANONICALOBJDIR:=${OBJTREE}${.CURDIR} cleanworld: .PHONY .if exists(${BW_CANONICALOBJDIR}/) -rm -rf ${BW_CANONICALOBJDIR}/* -chflags -R 0 ${BW_CANONICALOBJDIR} rm -rf ${BW_CANONICALOBJDIR}/* .endif .if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR} # To be safe in this case, fall back to a 'make cleandir' ${_+_}@cd ${.CURDIR}; ${MAKE} cleandir .endif .if defined(TARGET) && defined(TARGET_ARCH) .if ${TARGET} == ${MACHINE} && ${TARGET_ARCH} == ${MACHINE_ARCH} XDEV_CPUTYPE?=${CPUTYPE} .else XDEV_CPUTYPE?=${TARGET_CPUTYPE} .endif NOFUN=-DNO_FSCHG MK_HTML=no -DNO_LINT \ MK_MAN=no MK_NLS=no MK_PROFILE=no \ MK_KERBEROS=no MK_RESCUE=no MK_TESTS=no MK_WARNS=no \ TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \ CPUTYPE=${XDEV_CPUTYPE} XDDIR=${TARGET_ARCH}-freebsd XDTP?=/usr/${XDDIR} .if ${XDTP:N/*} .error XDTP variable should be an absolute path .endif CDBENV=MAKEOBJDIRPREFIX=${MAKEOBJDIRPREFIX}/${XDDIR} \ INSTALL="sh ${.CURDIR}/tools/install.sh" CDENV= ${CDBENV} \ TOOLS_PREFIX=${XDTP} .if ${WANT_COMPILER_TYPE} == gcc || \ (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == gcc) # GCC requires -isystem and -L when using a cross-compiler. --sysroot # won't set header path and -L is used to ensure the base library path # is added before the port PREFIX library path. CD2CFLAGS+= -isystem ${XDDESTDIR}/usr/include -L${XDDESTDIR}/usr/lib # GCC requires -B to find /usr/lib/crti.o when using a cross-compiler # combined with --sysroot. CD2CFLAGS+= -B${XDDESTDIR}/usr/lib # Force using libc++ for external GCC. # XXX: This should be checking MK_GNUCXX == no .if ${X_COMPILER_VERSION} >= 40800 CD2CXXFLAGS+= -isystem ${XDDESTDIR}/usr/include/c++/v1 -std=c++11 \ -nostdinc++ .endif .endif CD2CFLAGS+= --sysroot=${XDDESTDIR}/ CD2ENV=${CDENV} CC="${CC} ${CD2CFLAGS}" CXX="${CXX} ${CD2CXXFLAGS} ${CD2CFLAGS}" \ CPP="${CPP} ${CD2CFLAGS}" \ MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH} CDTMP= ${MAKEOBJDIRPREFIX}/${XDDIR}/${.CURDIR}/tmp CDMAKE=${CDENV} PATH=${CDTMP}/usr/bin:${PATH} ${MAKE} ${NOFUN} CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDDESTDIR}/usr/bin:${PATH} ${MAKE} ${NOFUN} .if ${MK_META_MODE} != "no" # Don't rebuild build-tools targets during normal build. CD2MAKE+= BUILD_TOOLS_META=.NOMETA_CMP .endif XDDESTDIR=${DESTDIR}/${XDTP} .if !defined(OSREL) OSREL!= uname -r | sed -e 's/[-(].*//' .endif .ORDER: xdev-build xdev-install xdev-links xdev: xdev-build xdev-install .PHONY .ORDER: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools xdev-build: _xb-worldtmp _xb-bootstrap-tools _xb-build-tools _xb-cross-tools .PHONY _xb-worldtmp: .PHONY mkdir -p ${CDTMP}/usr mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \ -p ${CDTMP}/usr >/dev/null _xb-bootstrap-tools: .PHONY .for _tool in \ ${_clang_tblgen} \ ${_gperf} \ ${_yacc} ${_+_}@${ECHODIR} "===> ${_tool} (obj,all,install)"; \ cd ${.CURDIR}/${_tool}; \ ${CDMAKE} DIRPRFX=${_tool}/ obj; \ ${CDMAKE} DIRPRFX=${_tool}/ all; \ ${CDMAKE} DIRPRFX=${_tool}/ DESTDIR=${CDTMP} install .endfor _xb-build-tools: .PHONY ${_+_}@cd ${.CURDIR}; \ ${CDBENV} ${MAKE} -f Makefile.inc1 ${NOFUN} build-tools _xb-cross-tools: .PHONY .for _tool in \ ${_binutils} \ ${_elftctools} \ usr.bin/ar \ ${_clang_libs} \ ${_clang} \ ${_cc} ${_+_}@${ECHODIR} "===> xdev ${_tool} (obj,all)"; \ cd ${.CURDIR}/${_tool}; \ ${CDMAKE} DIRPRFX=${_tool}/ obj; \ ${CDMAKE} DIRPRFX=${_tool}/ all .endfor _xi-mtree: .PHONY ${_+_}@${ECHODIR} "mtree populating ${XDDESTDIR}" mkdir -p ${XDDESTDIR} mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \ -p ${XDDESTDIR} >/dev/null mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \ -p ${XDDESTDIR}/usr >/dev/null mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \ -p ${XDDESTDIR}/usr/include >/dev/null .if defined(LIBCOMPAT) mtree -deU -f ${.CURDIR}/etc/mtree/BSD.lib${libcompat}.dist \ -p ${XDDESTDIR}/usr >/dev/null .endif .if ${MK_TESTS} != "no" mkdir -p ${XDDESTDIR}${TESTSBASE} mtree -deU -f ${.CURDIR}/etc/mtree/BSD.tests.dist \ -p ${XDDESTDIR}${TESTSBASE} >/dev/null .endif .ORDER: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries xdev-install: xdev-build _xi-mtree _xi-cross-tools _xi-includes _xi-libraries .PHONY _xi-cross-tools: .PHONY @echo "_xi-cross-tools" .for _tool in \ ${_binutils} \ ${_elftctools} \ usr.bin/ar \ ${_clang_libs} \ ${_clang} \ ${_cc} ${_+_}@${ECHODIR} "===> xdev ${_tool} (install)"; \ cd ${.CURDIR}/${_tool}; \ ${CDMAKE} DIRPRFX=${_tool}/ install DESTDIR=${XDDESTDIR} .endfor _xi-includes: .PHONY ${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 includes \ DESTDIR=${XDDESTDIR} _xi-libraries: .PHONY ${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 libraries \ DESTDIR=${XDDESTDIR} xdev-links: .PHONY ${_+_}cd ${XDDESTDIR}/usr/bin; \ mkdir -p ../../../../usr/bin; \ for i in *; do \ ln -sf ../../${XDTP}/usr/bin/$$i \ ../../../../usr/bin/${XDDIR}-$$i; \ ln -sf ../../${XDTP}/usr/bin/$$i \ ../../../../usr/bin/${XDDIR}${OSREL}-$$i; \ done .else xdev xdev-build xdev-install xdev-links: .PHONY @echo "*** Error: Both TARGET and TARGET_ARCH must be defined for \"${.TARGET}\" target" .endif Index: stable/11/contrib/mdocml/compat_sqlite3_errstr.c =================================================================== --- stable/11/contrib/mdocml/compat_sqlite3_errstr.c (revision 316419) +++ stable/11/contrib/mdocml/compat_sqlite3_errstr.c (nonexistent) @@ -1,16 +0,0 @@ -#include "config.h" - -#if HAVE_SQLITE3_ERRSTR - -int dummy; - -#else - -const char * -sqlite3_errstr(int rc) -{ - - return rc ? "unknown error" : "not an error"; -} - -#endif Property changes on: stable/11/contrib/mdocml/compat_sqlite3_errstr.c ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: stable/11/contrib/mdocml/test-sqlite3.c =================================================================== --- stable/11/contrib/mdocml/test-sqlite3.c (revision 316419) +++ stable/11/contrib/mdocml/test-sqlite3.c (nonexistent) @@ -1,47 +0,0 @@ -/* $Id: test-sqlite3.c,v 1.2 2015/10/06 18:32:20 schwarze Exp $ */ -/* - * Copyright (c) 2014 Ingo Schwarze - * - * 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 -#include -#include - -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; -} Property changes on: stable/11/contrib/mdocml/test-sqlite3.c ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: stable/11/contrib/mdocml/mansearch_const.c =================================================================== --- stable/11/contrib/mdocml/mansearch_const.c (revision 316419) +++ stable/11/contrib/mdocml/mansearch_const.c (nonexistent) @@ -1,33 +0,0 @@ -/* $Id: mansearch_const.c,v 1.7 2014/12/01 08:05:52 schwarze Exp $ */ -/* - * Copyright (c) 2014 Ingo Schwarze - * - * 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 "config.h" - -#include - -#include - -#include "mansearch.h" - -const int mansearch_keymax = 40; - -const char *const mansearch_keynames[40] = { - "arch", "sec", "Xr", "Ar", "Fa", "Fl", "Dv", "Fn", - "Ic", "Pa", "Cm", "Li", "Em", "Cd", "Va", "Ft", - "Tn", "Er", "Ev", "Sy", "Sh", "In", "Ss", "Ox", - "An", "Mt", "St", "Bx", "At", "Nx", "Fx", "Lk", - "Ms", "Bsx", "Dx", "Rs", "Vt", "Lb", "Nm", "Nd" -}; Property changes on: stable/11/contrib/mdocml/mansearch_const.c ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: stable/11/contrib/mdocml/config.log =================================================================== --- stable/11/contrib/mdocml/config.log (revision 316419) +++ stable/11/contrib/mdocml/config.log (nonexistent) @@ -1,210 +0,0 @@ -configure.local: no (fully automatic configuration) - -dirent-namlen: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-dirent-namlen test-dirent-namlen.c -dirent-namlen: cc succeeded -dirent-namlen: yes - -err: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-err test-err.c -err: cc succeeded -test-err: 1. warnx -test-err: 2. warn: No error: 0 -test-err: 3. err: No error: 0 -err: yes - -fts: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-fts test-fts.c -fts: cc succeeded -fts: yes - -getline: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-getline test-getline.c -test-getline.c:12:9: error: implicit declaration of function 'getline' is invalid in C99 [-Werror,-Wimplicit-function-declaration] - return getline(&line, &linesz, stdin) != -1; - ^ -1 error generated. -getline: cc failed with 1 - -getsubopt: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-getsubopt test-getsubopt.c -getsubopt: cc succeeded -getsubopt: yes - -isblank: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-isblank test-isblank.c -isblank: cc succeeded -isblank: yes - -mkdtemp: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-mkdtemp test-mkdtemp.c -mkdtemp: cc succeeded -mkdtemp: yes - -mmap: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-mmap test-mmap.c -mmap: cc succeeded -mmap: yes - -pledge: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-pledge test-pledge.c -test-pledge.c:6:11: error: implicit declaration of function 'pledge' is invalid in C99 [-Werror,-Wimplicit-function-declaration] - return !!pledge("stdio", NULL); - ^ -1 error generated. -pledge: cc failed with 1 - -progname: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-progname test-progname.c -progname: cc succeeded -progname: yes - -reallocarray: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-reallocarray test-reallocarray.c -reallocarray: cc succeeded -reallocarray: yes - -rewb-bsd: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-rewb-bsd test-rewb-bsd.c -test-rewb-bsd.c:11:42: error: use of undeclared identifier 'NULL' - if (regexec(&re, "the word is here", 0, NULL, 0)) - ^ -test-rewb-bsd.c:13:35: error: use of undeclared identifier 'NULL' - if (regexec(&re, "same word", 0, NULL, 0)) - ^ -test-rewb-bsd.c:15:36: error: use of undeclared identifier 'NULL' - if (regexec(&re, "word again", 0, NULL, 0)) - ^ -test-rewb-bsd.c:17:30: error: use of undeclared identifier 'NULL' - if (regexec(&re, "word", 0, NULL, 0)) - ^ -test-rewb-bsd.c:19:31: error: use of undeclared identifier 'NULL' - if (regexec(&re, "wordy", 0, NULL, 0) != REG_NOMATCH) - ^ -test-rewb-bsd.c:21:31: error: use of undeclared identifier 'NULL' - if (regexec(&re, "sword", 0, NULL, 0) != REG_NOMATCH) - ^ -test-rewb-bsd.c:23:34: error: use of undeclared identifier 'NULL' - if (regexec(&re, "reworded", 0, NULL, 0) != REG_NOMATCH) - ^ -7 errors generated. -rewb-bsd: cc failed with 1 - -rewb-sysv: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-rewb-sysv test-rewb-sysv.c -test-rewb-sysv.c:11:42: error: use of undeclared identifier 'NULL' - if (regexec(&re, "the word is here", 0, NULL, 0)) - ^ -test-rewb-sysv.c:13:35: error: use of undeclared identifier 'NULL' - if (regexec(&re, "same word", 0, NULL, 0)) - ^ -test-rewb-sysv.c:15:36: error: use of undeclared identifier 'NULL' - if (regexec(&re, "word again", 0, NULL, 0)) - ^ -test-rewb-sysv.c:17:30: error: use of undeclared identifier 'NULL' - if (regexec(&re, "word", 0, NULL, 0)) - ^ -test-rewb-sysv.c:19:31: error: use of undeclared identifier 'NULL' - if (regexec(&re, "wordy", 0, NULL, 0) != REG_NOMATCH) - ^ -test-rewb-sysv.c:21:31: error: use of undeclared identifier 'NULL' - if (regexec(&re, "sword", 0, NULL, 0) != REG_NOMATCH) - ^ -test-rewb-sysv.c:23:34: error: use of undeclared identifier 'NULL' - if (regexec(&re, "reworded", 0, NULL, 0) != REG_NOMATCH) - ^ -7 errors generated. -rewb-sysv: cc failed with 1 - -strcasestr: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-strcasestr test-strcasestr.c -strcasestr: cc succeeded -strcasestr: yes - -stringlist: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-stringlist test-stringlist.c -test-stringlist.c:26:26: error: use of undeclared identifier 'NULL' - if ((sl = sl_init()) == NULL) - ^ -1 error generated. -stringlist: cc failed with 1 - -strlcat: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-strlcat test-strlcat.c -strlcat: cc succeeded -strlcat: yes - -strlcpy: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-strlcpy test-strlcpy.c -strlcpy: cc succeeded -strlcpy: yes - -strptime: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-strptime test-strptime.c -strptime: cc succeeded -strptime: yes - -strsep: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-strsep test-strsep.c -strsep: cc succeeded -strsep: yes - -strtonum: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-strtonum test-strtonum.c -strtonum: cc succeeded -strtonum: yes - -vasprintf: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-vasprintf test-vasprintf.c -vasprintf: cc succeeded -vasprintf: yes - -wchar: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-wchar test-wchar.c -wchar: cc succeeded -*wchar: yes - -sqlite3: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -lsqlite3 -o test-sqlite3 test-sqlite3.c -test-sqlite3.c:20:10: fatal error: 'sqlite3.h' file not found -#include - ^ -1 error generated. -sqlite3: cc failed with 1 - -sqlite3: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -I/usr/local/include -L/usr/local/lib -lsqlite3 -o test-sqlite3 test-sqlite3.c -sqlite3: cc succeeded -sqlite3: yes - -sqlite3_errstr: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -L/usr/local/lib -lsqlite3 -o test-sqlite3_errstr test-sqlite3_errstr.c -test-sqlite3_errstr.c:2:10: fatal error: 'sqlite3.h' file not found -#include - ^ -1 error generated. -sqlite3_errstr: cc failed with 1 - -ohash: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -o test-ohash test-ohash.c -test-ohash.c:4:10: fatal error: 'ohash.h' file not found -#include - ^ -1 error generated. -ohash: cc failed with 1 - -ohash: testing... -cc -g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings -Wno-unused -Werror -lutil -o test-ohash test-ohash.c -test-ohash.c:4:10: fatal error: 'ohash.h' file not found -#include - ^ -1 error generated. -ohash: cc failed with 1 - -DBLIB="-L/usr/local/lib -lsqlite3 -lz" - -/usr/share/man:/usr/local/man:/usr/share/openssl/man:/usr/local/lib/perl5/site_perl/man:/usr/local/lib/perl5/5.20/perl/man:/usr/local/share/xpdf/man -manpath: yes - -config.h: written -Makefile.local: written Index: stable/11/contrib/mdocml/test-sqlite3_errstr.c =================================================================== --- stable/11/contrib/mdocml/test-sqlite3_errstr.c (revision 316419) +++ stable/11/contrib/mdocml/test-sqlite3_errstr.c (nonexistent) @@ -1,8 +0,0 @@ -#include -#include - -int -main(void) -{ - return strcmp(sqlite3_errstr(SQLITE_OK), "not an error"); -} Property changes on: stable/11/contrib/mdocml/test-sqlite3_errstr.c ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: stable/11/contrib/mdocml/test-mmap.c =================================================================== --- stable/11/contrib/mdocml/test-mmap.c (revision 316419) +++ stable/11/contrib/mdocml/test-mmap.c (nonexistent) @@ -1,9 +0,0 @@ -#include -#include -#include - -int -main(void) -{ - return mmap(NULL, 1, PROT_READ, MAP_SHARED, -1, 0) != MAP_FAILED; -} Property changes on: stable/11/contrib/mdocml/test-mmap.c ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: stable/11/contrib/mdocml/INSTALL =================================================================== --- stable/11/contrib/mdocml/INSTALL (revision 316419) +++ stable/11/contrib/mdocml/INSTALL (revision 316420) @@ -1,160 +1,146 @@ -$Id: INSTALL,v 1.15 2016/07/14 11:09:06 schwarze Exp $ +$Id: INSTALL,v 1.17 2016/07/19 22:40:33 schwarze Exp $ About mdocml, the portable mandoc distribution ---------------------------------------------- The mandoc manpage compiler toolset is a suite of tools compiling mdoc(7), the roff(7) macro language of choice for BSD manual pages, and man(7), the predominant historical language for UNIX manuals. It includes a man(1) manual viewer and additional tools. For general information, see . In case you have questions or want to provide feedback, read . Consider subscribing to the discuss@ mailing list mentioned on that page. If you intend to help with the development of mandoc, consider subscribing to the tech@ mailing list, too. Enjoy using the mandoc toolset! Ingo Schwarze, Karlsruhe, July 2016 Installation ------------ Before manually installing mandoc on your system, please check whether the newest version of mandoc is already installed by default or available via a binary package or a ports system. A list of the latest bundled and ported versions of mandoc for various operating systems is maintained at . 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. If you want to build the CGI program, man.cgi(8), too, run the command "echo BUILD_CGI=1 > configure.local". Then run "cp cgi.h.examples cgi.h" and edit cgi.h as desired. -2. Run "./configure". +2. Define MANPATH_DEFAULT in configure.local +if /usr/share/man:/usr/X11R6/man:/usr/local/man is not appropriate +for your operating system. + +3. 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. On Solaris 10 and earlier, you may have to run "ksh ./configure" because the native /bin/sh lacks some POSIX features. -3. Run "make". +4. 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 +5. Run "make -n install" and check whether everything will be installed to the intended places. Otherwise, put some *DIR or *NM* -variables into "configure.local" and go back to step 2. +variables into "configure.local" and go back to step 3. -5. Run "sudo make install". If you intend to build a binary +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. -6. If you want to use the integrated man(1) and your system uses -manpath(1), make sure it is configured correctly, in particular, -it returns all directory trees where manual pages are installed. -Otherwise, if your system uses man.conf(5), make sure it contains -a "manpath" line for each directory tree, and the order of these -lines meets your wishes. - -7. If you compiled with database support, run the command "sudo +7. Run the command "sudo makewhatis" to build mandoc.db(5) databases in all the directory trees configured in step 6. Whenever installing new manual pages, re-run makewhatis(8) to update the databases, or apropos(1) will not find the new pages. 8. To set up a man.cgi(8) server, read its manual page. Note that some man(7) pages may contain low-level roff(7) markup that mandoc does not yet understand. On some BSD systems using mandoc, third-party software is vetted on whether it may be formatted with mandoc. If not, groff(1) is pulled in as a dependency and used to install a pre-formatted "catpage" instead of directly as manual page source. Understanding mandoc dependencies --------------------------------- -The mandoc(1), man(1), and demandoc(1) utilities only depend -on the zlib library for decompressing gzipped manual pages, -but makewhatis(8) and apropos(1) depend on the following -additional software: +The following libraries are required: -1. The SQLite database system, see . -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 -missing SQLITE_DETERMINISTIC optimization flag. Versions older -than 3.8.0 may not show full error information if opening a database -fails due to the missing sqlite3_errstr() API. Both are very minor -problems, apropos(1) is fully usable with SQLite 3.7.5. Versions -older than 3.7.5 may or may not work, they have not been tested. +1. zlib for decompressing gzipped manual pages. 2. The fts(3) directory traversion functions. 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 . If you run into that problem, set "HAVE_FTS=0" in configure.local. 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. One of the chief design goals of the mandoc toolbox is to make sure that nothing related to documentation requires C++. Consequently, linking mandoc against any kind of C++ program would defeat the purpose and is not supported. Checking autoconfiguration quality ---------------------------------- If you want to check whether automatic configuration works well on your platform, consider the following: The mandoc package intentionally does not use GNU autoconf because we consider that toolset a blatant example of overengineering that is obsolete nowadays, since all modern operating systems are now reasonably close to POSIX and do not need arcane shell magic any longer. If your system does need such magic, consider upgrading to reasonably modern POSIX-compliant tools rather than asking for autoconf-style workarounds. As far as mandoc is using any features not mandated by ANSI X3.159-1989 ("ANSI C") or IEEE Std 1003.1-2008 ("POSIX") that some modern systems do not have, we intend to provide autoconfiguration tests and compat_*.c implementations. Please report any that turn out to be missing. Note that while we do strive to produce portable code, we do not slavishly restrict ourselves to POSIX-only interfaces. For improved security and readability, we do use well-designed, modern interfaces like reallocarray(3) even if they are still rather uncommon, of course bundling compat_*.c implementations as needed. Where mandoc is using ANSI C or POSIX features that some systems still lack and that compat_*.c implementations can be provided for without too much hassle, we will consider adding them, too, so 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 distclean". 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 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 "#define HAVE_*" differ from your expectations. Index: stable/11/contrib/mdocml/LICENSE =================================================================== --- stable/11/contrib/mdocml/LICENSE (revision 316419) +++ stable/11/contrib/mdocml/LICENSE (revision 316420) @@ -1,52 +1,53 @@ -$Id: LICENSE,v 1.12 2016/07/07 23:46:36 schwarze Exp $ +$Id: LICENSE,v 1.13 2016/10/18 14:15:33 schwarze Exp $ With the exceptions noted below, all code and documentation contained in the mdocml toolkit is protected by the Copyright of the following developers: Copyright (c) 2008-2012, 2014 Kristaps Dzonsons Copyright (c) 2010-2016 Ingo Schwarze Copyright (c) 2009, 2010, 2011, 2012 Joerg Sonnenberger Copyright (c) 2013 Franco Fichtner -Copyright (c) 2014 Baptiste Daroussin +Copyright (c) 2014 Baptiste Daroussin +Copyright (c) 2016 Ed Maste Copyright (c) 1999, 2004 Marc Espie Copyright (c) 1998, 2004, 2010 Todd C. Miller Copyright (c) 2008 Otto Moerbeek Copyright (c) 2004 Ted Unangst Copyright (c) 1994 Christos Zoulas Copyright (c) 2003, 2007, 2008, 2014 Jason McIntyre See the individual source files for information about who contributed to which file during which years. The mdocml distribution as a whole is distributed by its developers under the following license: 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. The following files included from outside sources are protected by other people's Copyright and are distributed under various 2-clause and 3-clause BSD licenses; see these individual files for details. soelim.c, soelim.1: -Copyright (c) 2014 Baptiste Daroussin +Copyright (c) 2014 Baptiste Daroussin compat_err.c, compat_fts.c, compat_fts.h, compat_getsubopt.c, compat_strcasestr.c, compat_strsep.c, man.1: Copyright (c) 1989,1990,1993,1994 The Regents of the University of California compat_stringlist.c, compat_stringlist.h: Copyright (c) 1994 Christos Zoulas Index: stable/11/contrib/mdocml/Makefile =================================================================== --- stable/11/contrib/mdocml/Makefile (revision 316419) +++ stable/11/contrib/mdocml/Makefile (revision 316420) @@ -1,466 +1,478 @@ -# $Id: Makefile,v 1.488 2016/07/12 05:18:38 kristaps Exp $ +# $Id: Makefile,v 1.493 2016/11/19 15:24:51 schwarze Exp $ # # Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons # Copyright (c) 2011, 2013-2016 Ingo Schwarze # # 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. -VERSION = 1.13.4 +VERSION = 1.14.0 # === LIST OF FILES ==================================================== -TESTSRCS = test-dirent-namlen.c \ +TESTSRCS = test-be32toh.c \ + test-dirent-namlen.c \ + test-EFTYPE.c \ test-err.c \ test-fts.c \ test-getline.c \ test-getsubopt.c \ test-isblank.c \ test-mkdtemp.c \ - test-mmap.c \ + test-nanosleep.c \ + test-ntohl.c \ test-ohash.c \ + test-PATH_MAX.c \ test-pledge.c \ test-progname.c \ test-reallocarray.c \ test-rewb-bsd.c \ test-rewb-sysv.c \ test-sandbox_init.c \ - test-sqlite3.c \ - test-sqlite3_errstr.c \ test-strcasestr.c \ test-stringlist.c \ test-strlcat.c \ test-strlcpy.c \ test-strptime.c \ test-strsep.c \ test-strtonum.c \ test-vasprintf.c \ test-wchar.c SRCS = att.c \ cgi.c \ chars.c \ compat_err.c \ compat_fts.c \ compat_getline.c \ compat_getsubopt.c \ compat_isblank.c \ compat_mkdtemp.c \ compat_ohash.c \ compat_progname.c \ compat_reallocarray.c \ - compat_sqlite3_errstr.c \ compat_strcasestr.c \ compat_stringlist.c \ compat_strlcat.c \ compat_strlcpy.c \ compat_strsep.c \ compat_strtonum.c \ compat_vasprintf.c \ + dba.c \ + dba_array.c \ + dba_read.c \ + dba_write.c \ + dbm.c \ + dbm_map.c \ demandoc.c \ eqn.c \ eqn_html.c \ eqn_term.c \ html.c \ lib.c \ main.c \ man.c \ man_hash.c \ man_html.c \ man_macro.c \ man_term.c \ man_validate.c \ mandoc.c \ mandoc_aux.c \ mandoc_ohash.c \ mandocdb.c \ manpage.c \ manpath.c \ mansearch.c \ - mansearch_const.c \ mdoc.c \ mdoc_argv.c \ mdoc_hash.c \ mdoc_html.c \ mdoc_macro.c \ mdoc_man.c \ mdoc_state.c \ mdoc_term.c \ mdoc_validate.c \ msec.c \ out.c \ preconv.c \ read.c \ roff.c \ soelim.c \ st.c \ tag.c \ tbl.c \ tbl_data.c \ tbl_html.c \ tbl_layout.c \ tbl_opts.c \ tbl_term.c \ term.c \ term_ascii.c \ term_ps.c \ tree.c DISTFILES = INSTALL \ LICENSE \ Makefile \ Makefile.depend \ NEWS \ TODO \ apropos.1 \ cgi.h.example \ compat_fts.h \ compat_ohash.h \ compat_stringlist.h \ configure \ configure.local.example \ + dba.h \ + dba_array.h \ + dba_write.h \ + dbm.h \ + dbm_map.h \ demandoc.1 \ eqn.7 \ gmdiff \ html.h \ lib.in \ libman.h \ libmandoc.h \ libmdoc.h \ libroff.h \ main.h \ makewhatis.8 \ man.1 \ man.7 \ man.cgi.3 \ man.cgi.8 \ man.conf.5 \ man.h \ manconf.h \ mandoc.1 \ mandoc.3 \ mandoc.css \ mandoc.db.5 \ mandoc.h \ mandoc_aux.h \ mandoc_char.7 \ mandoc_escape.3 \ mandoc_headers.3 \ mandoc_html.3 \ mandoc_malloc.3 \ mandoc_ohash.h \ mansearch.3 \ mansearch.h \ mchars_alloc.3 \ mdoc.7 \ mdoc.h \ msec.in \ out.h \ predefs.in \ roff.7 \ roff.h \ roff_int.h \ soelim.1 \ st.in \ tag.h \ tbl.3 \ tbl.7 \ term.h \ $(SRCS) \ $(TESTSRCS) LIBMAN_OBJS = man.o \ man_hash.o \ man_macro.o \ man_validate.o LIBMDOC_OBJS = att.o \ lib.o \ mdoc.o \ mdoc_argv.o \ mdoc_hash.o \ mdoc_macro.o \ mdoc_state.o \ mdoc_validate.o \ st.o LIBROFF_OBJS = eqn.o \ roff.o \ tbl.o \ tbl_data.o \ tbl_layout.o \ tbl_opts.o LIBMANDOC_OBJS = $(LIBMAN_OBJS) \ $(LIBMDOC_OBJS) \ $(LIBROFF_OBJS) \ chars.o \ mandoc.o \ mandoc_aux.o \ mandoc_ohash.o \ msec.o \ preconv.o \ read.o COMPAT_OBJS = compat_err.o \ compat_fts.o \ compat_getline.o \ compat_getsubopt.o \ compat_isblank.o \ compat_mkdtemp.o \ compat_ohash.o \ compat_progname.o \ compat_reallocarray.o \ - compat_sqlite3_errstr.o \ compat_strcasestr.o \ compat_strlcat.o \ compat_strlcpy.o \ compat_strsep.o \ compat_strtonum.o \ compat_vasprintf.o MANDOC_HTML_OBJS = eqn_html.o \ html.o \ man_html.o \ mdoc_html.o \ tbl_html.o MANDOC_MAN_OBJS = mdoc_man.o MANDOC_TERM_OBJS = eqn_term.o \ man_term.o \ mdoc_term.o \ term.o \ term_ascii.o \ term_ps.o \ tbl_term.o -BASE_OBJS = $(MANDOC_HTML_OBJS) \ +DBM_OBJS = dbm.o \ + dbm_map.o \ + mansearch.o + +DBA_OBJS = dba.o \ + dba_array.o \ + dba_read.o \ + dba_write.o \ + mandocdb.o + +MAIN_OBJS = $(MANDOC_HTML_OBJS) \ $(MANDOC_MAN_OBJS) \ $(MANDOC_TERM_OBJS) \ + $(DBM_OBJS) \ + $(DBA_OBJS) \ main.o \ manpath.o \ out.o \ tag.o \ tree.o -MAIN_OBJS = $(BASE_OBJS) - -DB_OBJS = mandocdb.o \ - mansearch.o \ - mansearch_const.o - CGI_OBJS = $(MANDOC_HTML_OBJS) \ + $(DBM_OBJS) \ cgi.o \ - mansearch.o \ - mansearch_const.o \ out.o -MANPAGE_OBJS = manpage.o mansearch.o mansearch_const.o manpath.o +MANPAGE_OBJS = $(DBM_OBJS) \ + manpage.o \ + manpath.o DEMANDOC_OBJS = demandoc.o SOELIM_OBJS = soelim.o \ compat_err.o \ compat_getline.o \ compat_progname.o \ compat_reallocarray.o \ compat_stringlist.o WWW_MANS = apropos.1.html \ demandoc.1.html \ man.1.html \ mandoc.1.html \ soelim.1.html \ mandoc.3.html \ mandoc_escape.3.html \ mandoc_headers.3.html \ mandoc_html.3.html \ mandoc_malloc.3.html \ mansearch.3.html \ mchars_alloc.3.html \ tbl.3.html \ man.conf.5.html \ mandoc.db.5.html \ eqn.7.html \ man.7.html \ mandoc_char.7.html \ mdoc.7.html \ roff.7.html \ tbl.7.html \ makewhatis.8.html \ man.cgi.3.html \ man.cgi.8.html \ man.h.html \ manconf.h.html \ mandoc.h.html \ mandoc_aux.h.html \ mansearch.h.html \ mdoc.h.html \ roff.h.html WWW_OBJS = mdocml.tar.gz \ mdocml.sha256 # === USER CONFIGURATION =============================================== include Makefile.local # === DEPENDENCY HANDLING ============================================== all: base-build $(BUILD_TARGETS) Makefile.local base-build: mandoc demandoc soelim cgi-build: man.cgi install: base-install $(INSTALL_TARGETS) www: $(WWW_OBJS) $(WWW_MANS) $(WWW_MANS): mandoc -.PHONY: base-install cgi-install db-install install www-install +.PHONY: base-install cgi-install install www-install .PHONY: clean distclean depend 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) $(COMPAT_OBJS) - rm -f mandoc $(BASE_OBJS) $(DB_OBJS) + rm -f mandoc $(MAIN_OBJS) rm -f man.cgi $(CGI_OBJS) rm -f manpage $(MANPAGE_OBJS) rm -f demandoc $(DEMANDOC_OBJS) rm -f soelim $(SOELIM_OBJS) rm -f $(WWW_MANS) $(WWW_OBJS) rm -rf *.dSYM base-install: base-build mkdir -p $(DESTDIR)$(BINDIR) - mkdir -p $(DESTDIR)$(LIBDIR) - mkdir -p $(DESTDIR)$(INCLUDEDIR) + mkdir -p $(DESTDIR)$(SBINDIR) mkdir -p $(DESTDIR)$(MANDIR)/man1 - mkdir -p $(DESTDIR)$(MANDIR)/man3 mkdir -p $(DESTDIR)$(MANDIR)/man5 mkdir -p $(DESTDIR)$(MANDIR)/man7 + mkdir -p $(DESTDIR)$(MANDIR)/man8 $(INSTALL_PROGRAM) mandoc demandoc $(DESTDIR)$(BINDIR) $(INSTALL_PROGRAM) soelim $(DESTDIR)$(BINDIR)/$(BINM_SOELIM) ln -f $(DESTDIR)$(BINDIR)/mandoc $(DESTDIR)$(BINDIR)/$(BINM_MAN) - $(INSTALL_LIB) libmandoc.a $(DESTDIR)$(LIBDIR) - $(INSTALL_LIB) man.h mandoc.h mandoc_aux.h mdoc.h roff.h \ - $(DESTDIR)$(INCLUDEDIR) + ln -f $(DESTDIR)$(BINDIR)/mandoc $(DESTDIR)$(BINDIR)/$(BINM_APROPOS) + ln -f $(DESTDIR)$(BINDIR)/mandoc $(DESTDIR)$(BINDIR)/$(BINM_WHATIS) + ln -f $(DESTDIR)$(BINDIR)/mandoc \ + $(DESTDIR)$(SBINDIR)/$(BINM_MAKEWHATIS) $(INSTALL_MAN) mandoc.1 demandoc.1 $(DESTDIR)$(MANDIR)/man1 $(INSTALL_MAN) soelim.1 $(DESTDIR)$(MANDIR)/man1/$(BINM_SOELIM).1 $(INSTALL_MAN) man.1 $(DESTDIR)$(MANDIR)/man1/$(BINM_MAN).1 - $(INSTALL_MAN) mandoc.3 mandoc_escape.3 mandoc_malloc.3 \ - mchars_alloc.3 tbl.3 $(DESTDIR)$(MANDIR)/man3 + $(INSTALL_MAN) apropos.1 $(DESTDIR)$(MANDIR)/man1/$(BINM_APROPOS).1 + ln -f $(DESTDIR)$(MANDIR)/man1/$(BINM_APROPOS).1 \ + $(DESTDIR)$(MANDIR)/man1/$(BINM_WHATIS).1 $(INSTALL_MAN) man.conf.5 $(DESTDIR)$(MANDIR)/man5/${MANM_MANCONF}.5 + $(INSTALL_MAN) mandoc.db.5 $(DESTDIR)$(MANDIR)/man5 $(INSTALL_MAN) man.7 $(DESTDIR)$(MANDIR)/man7/${MANM_MAN}.7 $(INSTALL_MAN) mdoc.7 $(DESTDIR)$(MANDIR)/man7/${MANM_MDOC}.7 $(INSTALL_MAN) roff.7 $(DESTDIR)$(MANDIR)/man7/${MANM_ROFF}.7 $(INSTALL_MAN) eqn.7 $(DESTDIR)$(MANDIR)/man7/${MANM_EQN}.7 $(INSTALL_MAN) tbl.7 $(DESTDIR)$(MANDIR)/man7/${MANM_TBL}.7 $(INSTALL_MAN) mandoc_char.7 $(DESTDIR)$(MANDIR)/man7 - -db-install: base-build - mkdir -p $(DESTDIR)$(BINDIR) - mkdir -p $(DESTDIR)$(SBINDIR) - mkdir -p $(DESTDIR)$(MANDIR)/man1 - mkdir -p $(DESTDIR)$(MANDIR)/man3 - mkdir -p $(DESTDIR)$(MANDIR)/man5 - mkdir -p $(DESTDIR)$(MANDIR)/man8 - ln -f $(DESTDIR)$(BINDIR)/mandoc $(DESTDIR)$(BINDIR)/$(BINM_APROPOS) - ln -f $(DESTDIR)$(BINDIR)/mandoc $(DESTDIR)$(BINDIR)/$(BINM_WHATIS) - ln -f $(DESTDIR)$(BINDIR)/mandoc \ - $(DESTDIR)$(SBINDIR)/$(BINM_MAKEWHATIS) - $(INSTALL_MAN) apropos.1 $(DESTDIR)$(MANDIR)/man1/$(BINM_APROPOS).1 - ln -f $(DESTDIR)$(MANDIR)/man1/$(BINM_APROPOS).1 \ - $(DESTDIR)$(MANDIR)/man1/$(BINM_WHATIS).1 - $(INSTALL_MAN) mansearch.3 $(DESTDIR)$(MANDIR)/man3 - $(INSTALL_MAN) mandoc.db.5 $(DESTDIR)$(MANDIR)/man5 $(INSTALL_MAN) makewhatis.8 \ $(DESTDIR)$(MANDIR)/man8/$(BINM_MAKEWHATIS).8 + +lib-install: base-build + mkdir -p $(DESTDIR)$(LIBDIR) + mkdir -p $(DESTDIR)$(INCLUDEDIR) + mkdir -p $(DESTDIR)$(MANDIR)/man3 + $(INSTALL_LIB) libmandoc.a $(DESTDIR)$(LIBDIR) + $(INSTALL_LIB) man.h mandoc.h mandoc_aux.h mdoc.h roff.h \ + $(DESTDIR)$(INCLUDEDIR) + $(INSTALL_MAN) mandoc.3 mandoc_escape.3 mandoc_malloc.3 \ + mansearch.3 mchars_alloc.3 tbl.3 $(DESTDIR)$(MANDIR)/man3 cgi-install: cgi-build mkdir -p $(DESTDIR)$(CGIBINDIR) mkdir -p $(DESTDIR)$(HTDOCDIR) $(INSTALL_PROGRAM) man.cgi $(DESTDIR)$(CGIBINDIR) $(INSTALL_DATA) mandoc.css $(DESTDIR)$(HTDOCDIR) Makefile.local config.h: configure ${TESTSRCS} @echo "$@ is out of date; please run ./configure" @exit 1 libmandoc.a: $(COMPAT_OBJS) $(LIBMANDOC_OBJS) ar rs $@ $(COMPAT_OBJS) $(LIBMANDOC_OBJS) mandoc: $(MAIN_OBJS) libmandoc.a $(CC) -o $@ $(LDFLAGS) $(MAIN_OBJS) libmandoc.a $(LDADD) manpage: $(MANPAGE_OBJS) libmandoc.a $(CC) -o $@ $(LDFLAGS) $(MANPAGE_OBJS) libmandoc.a $(LDADD) man.cgi: $(CGI_OBJS) libmandoc.a $(CC) $(STATIC) -o $@ $(LDFLAGS) $(CGI_OBJS) libmandoc.a $(LDADD) demandoc: $(DEMANDOC_OBJS) libmandoc.a $(CC) -o $@ $(LDFLAGS) $(DEMANDOC_OBJS) libmandoc.a $(LDADD) soelim: $(SOELIM_OBJS) $(CC) -o $@ $(LDFLAGS) $(SOELIM_OBJS) # --- maintainer targets --- www-install: www mkdir -p $(HTDOCDIR)/snapshots $(INSTALL_DATA) $(WWW_MANS) mandoc.css $(HTDOCDIR) $(INSTALL_DATA) $(WWW_OBJS) $(HTDOCDIR)/snapshots $(INSTALL_DATA) mdocml.tar.gz \ $(HTDOCDIR)/snapshots/mdocml-$(VERSION).tar.gz $(INSTALL_DATA) mdocml.sha256 \ $(HTDOCDIR)/snapshots/mdocml-$(VERSION).sha256 depend: config.h mkdep -f Makefile.depend $(CFLAGS) $(SRCS) perl -e 'undef $$/; $$_ = <>; s|/usr/include/\S+||g; \ s|\\\n||g; s| +| |g; s| $$||mg; print;' \ Makefile.depend > Makefile.tmp mv Makefile.tmp Makefile.depend dist: mdocml.sha256 mdocml.sha256: mdocml.tar.gz sha256 mdocml.tar.gz > $@ mdocml.tar.gz: $(DISTFILES) mkdir -p .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/ # === SUFFIX RULES ===================================================== .SUFFIXES: .1 .3 .5 .7 .8 .h .SUFFIXES: .1.html .3.html .5.html .7.html .8.html .h.html .h.h.html: highlight -I $< > $@ .1.1.html .3.3.html .5.5.html .7.7.html .8.8.html: mandoc ./mandoc -Thtml -Wall,stop \ -Ostyle=mandoc.css,man=%N.%S.html,includes=%I.html $< > $@ Index: stable/11/contrib/mdocml/Makefile.depend =================================================================== --- stable/11/contrib/mdocml/Makefile.depend (revision 316419) +++ stable/11/contrib/mdocml/Makefile.depend (revision 316420) @@ -1,68 +1,72 @@ att.o: att.c config.h roff.h mdoc.h libmdoc.h cgi.o: cgi.c config.h mandoc_aux.h mandoc.h roff.h mdoc.h man.h main.h manconf.h mansearch.h cgi.h chars.o: chars.c config.h mandoc.h mandoc_aux.h mandoc_ohash.h compat_ohash.h libmandoc.h compat_err.o: compat_err.c config.h compat_fts.o: compat_fts.c config.h compat_fts.h compat_getline.o: compat_getline.c config.h compat_getsubopt.o: compat_getsubopt.c config.h compat_isblank.o: compat_isblank.c config.h compat_mkdtemp.o: compat_mkdtemp.c config.h compat_ohash.o: compat_ohash.c config.h compat_ohash.h compat_progname.o: compat_progname.c config.h compat_reallocarray.o: compat_reallocarray.c config.h -compat_sqlite3_errstr.o: compat_sqlite3_errstr.c config.h compat_strcasestr.o: compat_strcasestr.c config.h compat_stringlist.o: compat_stringlist.c config.h compat_stringlist.h compat_strlcat.o: compat_strlcat.c config.h compat_strlcpy.o: compat_strlcpy.c config.h compat_strsep.o: compat_strsep.c config.h compat_strtonum.o: compat_strtonum.c config.h compat_vasprintf.o: compat_vasprintf.c config.h +dba.o: dba.c config.h mandoc_aux.h mandoc_ohash.h compat_ohash.h mansearch.h dba_write.h dba_array.h dba.h +dba_array.o: dba_array.c mandoc_aux.h dba_write.h dba_array.h +dba_read.o: dba_read.c mandoc_aux.h mansearch.h dba_array.h dba.h dbm.h +dba_write.o: dba_write.c config.h dba_write.h +dbm.o: dbm.c config.h mansearch.h dbm_map.h dbm.h +dbm_map.o: dbm_map.c config.h mansearch.h dbm_map.h dbm.h demandoc.o: demandoc.c config.h roff.h man.h mdoc.h mandoc.h eqn.o: eqn.c config.h mandoc.h mandoc_aux.h libmandoc.h libroff.h eqn_html.o: eqn_html.c config.h mandoc.h out.h html.h eqn_term.o: eqn_term.c config.h mandoc.h out.h term.h html.o: html.c config.h mandoc.h mandoc_aux.h out.h html.h manconf.h main.h lib.o: lib.c config.h roff.h mdoc.h libmdoc.h lib.in main.o: main.c config.h mandoc_aux.h mandoc.h roff.h mdoc.h man.h tag.h main.h manconf.h mansearch.h man.o: man.c config.h mandoc_aux.h mandoc.h roff.h man.h libmandoc.h roff_int.h libman.h -man_hash.o: man_hash.c config.h roff.h man.h libman.h +man_hash.o: man_hash.c config.h mandoc.h roff.h man.h libmandoc.h libman.h man_html.o: man_html.c config.h mandoc_aux.h roff.h man.h out.h html.h main.h man_macro.o: man_macro.c config.h mandoc.h roff.h man.h libmandoc.h roff_int.h libman.h man_term.o: man_term.c config.h mandoc_aux.h mandoc.h roff.h man.h out.h term.h main.h man_validate.o: man_validate.c config.h mandoc_aux.h mandoc.h roff.h man.h libmandoc.h roff_int.h libman.h mandoc.o: mandoc.c config.h mandoc.h mandoc_aux.h libmandoc.h mandoc_aux.o: mandoc_aux.c config.h mandoc.h mandoc_aux.h mandoc_ohash.o: mandoc_ohash.c mandoc_aux.h mandoc_ohash.h compat_ohash.h -mandocdb.o: mandocdb.c config.h compat_fts.h mandoc_aux.h mandoc_ohash.h compat_ohash.h mandoc.h roff.h mdoc.h man.h manconf.h mansearch.h +mandocdb.o: mandocdb.c config.h compat_fts.h mandoc_aux.h mandoc_ohash.h compat_ohash.h mandoc.h roff.h mdoc.h man.h manconf.h mansearch.h dba_array.h dba.h manpage.o: manpage.c config.h manconf.h mansearch.h manpath.o: manpath.c config.h mandoc_aux.h manconf.h -mansearch.o: mansearch.c config.h mandoc.h mandoc_aux.h mandoc_ohash.h compat_ohash.h manconf.h mansearch.h -mansearch_const.o: mansearch_const.c config.h mansearch.h +mansearch.o: mansearch.c config.h mandoc.h mandoc_aux.h mandoc_ohash.h compat_ohash.h manconf.h mansearch.h dbm.h mdoc.o: mdoc.c config.h mandoc_aux.h mandoc.h roff.h mdoc.h libmandoc.h roff_int.h libmdoc.h -mdoc_argv.o: mdoc_argv.c config.h mandoc_aux.h mandoc.h roff.h mdoc.h libmandoc.h libmdoc.h -mdoc_hash.o: mdoc_hash.c config.h roff.h mdoc.h libmdoc.h +mdoc_argv.o: mdoc_argv.c config.h mandoc_aux.h mandoc.h roff.h mdoc.h libmandoc.h roff_int.h libmdoc.h +mdoc_hash.o: mdoc_hash.c config.h mandoc.h roff.h mdoc.h libmandoc.h libmdoc.h mdoc_html.o: mdoc_html.c config.h mandoc_aux.h roff.h mdoc.h out.h html.h main.h mdoc_macro.o: mdoc_macro.c config.h mandoc.h roff.h mdoc.h libmandoc.h roff_int.h libmdoc.h mdoc_man.o: mdoc_man.c config.h mandoc_aux.h mandoc.h roff.h mdoc.h man.h out.h main.h mdoc_state.o: mdoc_state.c mandoc.h roff.h mdoc.h libmandoc.h libmdoc.h mdoc_term.o: mdoc_term.c config.h mandoc_aux.h mandoc.h roff.h mdoc.h out.h term.h tag.h main.h mdoc_validate.o: mdoc_validate.c config.h mandoc_aux.h mandoc.h roff.h mdoc.h libmandoc.h roff_int.h libmdoc.h msec.o: msec.c config.h mandoc.h libmandoc.h msec.in out.o: out.c config.h mandoc_aux.h mandoc.h out.h preconv.o: preconv.c config.h mandoc.h libmandoc.h read.o: read.c config.h mandoc_aux.h mandoc.h roff.h mdoc.h man.h libmandoc.h roff_int.h roff.o: roff.c config.h mandoc.h mandoc_aux.h roff.h libmandoc.h roff_int.h libroff.h predefs.in soelim.o: soelim.c config.h compat_stringlist.h st.o: st.c config.h roff.h mdoc.h libmdoc.h st.in tag.o: tag.c config.h mandoc_aux.h mandoc_ohash.h compat_ohash.h tag.h tbl.o: tbl.c config.h mandoc.h mandoc_aux.h libmandoc.h libroff.h tbl_data.o: tbl_data.c config.h mandoc.h mandoc_aux.h libmandoc.h libroff.h tbl_html.o: tbl_html.c config.h mandoc.h out.h html.h tbl_layout.o: tbl_layout.c config.h mandoc.h mandoc_aux.h libmandoc.h libroff.h tbl_opts.o: tbl_opts.c config.h mandoc.h libmandoc.h libroff.h tbl_term.o: tbl_term.c config.h mandoc.h out.h term.h term.o: term.c config.h mandoc.h mandoc_aux.h out.h term.h main.h term_ascii.o: term_ascii.c config.h mandoc.h mandoc_aux.h out.h term.h manconf.h main.h term_ps.o: term_ps.c config.h mandoc_aux.h out.h term.h manconf.h main.h tree.o: tree.c config.h mandoc.h roff.h mdoc.h man.h main.h Index: stable/11/contrib/mdocml/TODO =================================================================== --- stable/11/contrib/mdocml/TODO (revision 316419) +++ stable/11/contrib/mdocml/TODO (revision 316420) @@ -1,673 +1,662 @@ ************************************************************************ * Official mandoc TODO. -* $Id: TODO,v 1.218 2016/06/05 21:06:04 schwarze Exp $ +* $Id: TODO,v 1.223 2017/01/17 15:32:43 schwarze Exp $ ************************************************************************ Many issues are annotated for difficulty as follows: - loc = locality of the issue * single file issue, affects file only, or very few ** single module issue, affects several files of one module *** cross-module issue, significantly impacts multiple modules and may require substantial changes to internal interfaces - exist = difficulty of the existing code in this area * affected code is straightforward and easy to read and change ** affected code is somewhat complex, but once you understand the design, not particularly difficult to understand *** affected code uses a special, exceptionally tricky design - algo = difficulty of the new algorithm to be written * the required logic and code is straightforward ** the required logic is somewhat complex and needs a careful design *** the required logic is exceptionally tricky, maybe an approach to solve that is not even known yet - size = the amount of code to be written or changed * a small number of lines (at most 100, usually much less) ** a considerable amount of code (several dozen to a few hundred) *** a large amount of code (many hundreds, maybe thousands) - imp = importance of the issue * mostly for completeness ** would be nice to have *** issue causes considerable inconvenience Obviously, as the issues have not been solved yet, these annotations are mere guesses, and some may be wrong. ************************************************************************ -* crashes -************************************************************************ - -- The abort() in bufcat(), html.c, can be triggered via buffmt_includes() - by running -Thtml -Oincludes on a file containing a long .In argument. - Fixing this will probably require reworking the whole bufcat() concept. - loc ** exist * algo * size ** imp ** - -************************************************************************ * missing features ************************************************************************ --- missing roff features ---------------------------------------------- - .ad (adjust margins) .ad l -- adjust left margin only (flush left) .ad r -- adjust right margin only (flush right) .ad c -- center text on line .ad b -- adjust both margins (alias: .ad n) .na -- temporarily disable adjustment without changing the mode .ad -- re-enable adjustment without changing the mode Adjustment mode is ignored while in no-fill mode (.nf). loc *** exist *** algo ** size ** imp ** (parser reorg would help) - .fc (field control) found by naddy@ in xloadimage(1) loc ** exist *** algo * size * imp * - .nr third argument (auto-increment step size, requires \n+) found by bentley@ in sbcl(1) Mon, 9 Dec 2013 18:36:57 -0700 loc * exist * algo * size * imp ** - .ns (no-space mode) occurs in xine-config(1) when implementing this, also let .TH set it reported by brad@ Sat, 15 Jan 2011 15:45:23 -0500 loc *** exist *** algo *** size ** imp * - .ta (tab settings) #1 most important issue naddy@ Mon, 16 Feb 2015 20:59:17 +0100 ircbug(1) gnats(1) reported by brad@ Sat, 15 Jan 2011 15:50:51 -0500 also Tcl_NewStringObj(3) via wiz@ Wed, 5 Mar 2014 22:27:43 +0100 also posix2time(3) Carsten Kunze Mon, 1 Dec 2014 13:03:10 +0100 loc ** exist *** algo ** size ** imp *** - .ti (temporary indent) found by naddy@ in xloadimage(1) [devel/libvstr] vstr(3) found by bentley@ in nmh(1) Mon, 23 Apr 2012 13:38:28 -0600 loc ** exist ** algo ** size * imp ** (parser reorg helps a lot) - .while and .shift found by jca@ in ratpoison(1) Sun, 30 Jun 2013 12:01:09 +0200 loc * exist ** algo ** size ** imp ** - \h horizontal move #2 most important issue naddy@ Mon, 16 Feb 2015 20:59:17 +0100 found in cclive(1) nasm(1) bogofilter(1) asciidoc/DocBook output bentley@ on discuss@ Sat, 21 Sep 2013 22:29:34 -0600 naddy@ Thu, 4 Dec 2014 16:26:41 +0100 loc ** exist ** algo ** size * imp *** (parser reorg helps a lot) - \n+ and \n- numerical register increment and decrement found by bentley@ in sbcl(1) Mon, 9 Dec 2013 18:36:57 -0700 loc * exist * algo * size * imp ** - \n(.$ macro argument count number register; ocserv(8) by autogen found by sthen@ Thu, 19 Feb 2015 22:03:01 +0000 loc * exist ** algo * size * imp ** - \w'' improve width measurements would not be very useful without an expression parser, see below needed for Tcl_NewStringObj(3) via wiz@ Wed, 5 Mar 2014 22:27:43 +0100 loc ** exist *** algo *** size * imp *** - \\ in high-level macro arguments Currently, \\ is expanded in two situations: 1) macro and string definition (roff.c setstrn()) 2) macro argument parsing (mandoc.c mandoc_getarg()) For user defined macros, the second happens in time because of ROFF_REPARSE. But for standard high-level macros, it only happens after entering the high level parsers, which is too late because the code doesn't get back to roff.c roff_res() from that point. Because this requires distinguishing requests, user-defined macros and standard macros on the roff_res() level, it is hard to solve without the parser reorg. Found by naddy@ in devel/cutils cobfusc(1) Mon, 16 Feb 2015 19:10:52 +0100 loc *** exist *** algo *** size ** imp * - using undefined strings or macros defines them to be empty wl@ Mon, 14 Nov 2011 14:37:01 +0000 loc * exist * algo * size * imp * --- missing mdoc features ---------------------------------------------- - .Bl -column .Xo support is missing ultimate goal: restore .Xr and .Dv to lib/libc/compat-43/sigvec.3 lib/libc/gen/signal.3 lib/libc/sys/sigaction.2 loc * exist *** algo *** size * imp ** - edge case: decide how to deal with blk_full bad nesting, e.g. .Sh .Nm .Bk .Nm .Ek .Sh found by jmc@ in ssh-keygen(1) from jmc@ Wed, 14 Jul 2010 18:10:32 +0100 loc * exist *** algo *** size ** imp ** - .Bd -centered implies -filled, not -unfilled, which is not easy to implement; it requires code similar to .ce, which we don't have either. Besides, groff has bug causing text right *before* .Bd -centered to be centered as well. loc *** exist *** algo ** size ** imp ** (parser reorg would help) - .Bd -filled should not be the same as .Bd -ragged, but align both the left and right margin. In groff, it is implemented in terms of .ad b, which we don't have either. Found in cksum(1). loc *** exist *** algo ** size ** imp ** (parser reorg would help) - implement blank `Bl -column', such as .Bl -column .It foo Ta bar .El loc * exist *** algo *** size * imp * - explicitly disallow nested `Bl -column', which would clobber internal flags defined for struct mdoc_macro loc * exist * algo * size * imp ** - In .Bl -column .It, the end of the line probably has to be regarded as an implicit .Ta, if there could be one, see the following mildly ugly code from login.conf(5): .Bl -column minpasswordlen program xetcxmotd .It path Ta path Ta value of Dv _PATH_DEFPATH .br Default search path. reported by Michal Mazurek via jmc@ Thu, 7 Apr 2011 16:00:53 +0059 loc * exist *** algo ** size * imp ** - inside `.Bl -column' phrases, punctuation is handled like normal text, e.g. `.Bl -column .It Fl x . Ta ...' should give "-x -." - inside `.Bl -column' phrases, TERMP_IGNDELIM handling by `Pf' is not safe, e.g. `.Bl -column .It Pf a b .' gives "ab." but should give "ab ." - check whether it is correct that `D1' uses INDENT+1; does it need its own constant? loc * exist ** algo ** size * imp ** - prohibit `Nm' from having non-text HEAD children (e.g., NetBSD mDNSShared/dns-sd.1) (mdoc_html.c and mdoc_term.c `Nm' handlers can be slightly simplified) - support translated section names e.g. x11/scrotwm scrotwm_es.1:21:2: error: NAME section must be first that one uses NOMBRE because it is spanish... deraadt tends to think that section-dependent macro behaviour is a bad idea in the first place, so this may be irrelevant loc ** exist ** algo ** size * imp ** - When there is free text in the SYNOPSIS and that free text contains the .Nm macro, groff somehow understands to treat the .Nm as an in-line macro, while mandoc treats it as a block macro and breaks the line. No idea how the logic for distinguishing in-line and block instances should be, needs investigation. uqs@ Thu, 2 Jun 2011 11:03:51 +0200 uqs@ Thu, 2 Jun 2011 11:33:35 +0200 loc * exist ** algo *** size * imp ** --- missing man features ----------------------------------------------- - -T[x]html doesn't stipulate non-collapsing spaces in literal mode --- missing tbl features ----------------------------------------------- - horizontal lines in the layout still consume data cells and can be mixed with actual data on the same table line synaptics(4) found by tedu@ Mon, 17 Aug 2015 21:17:42 -0400 loc ** exist ** algo ** size ** imp *** +- break long text into lines inside cells + net/lftp(1) from jirib via bentley@ Sep 13, 2016 + +- layout l1 for a column of max text width 3 reduces the following + inter-column spacing for groff, but not for mandoc + net/lftp(1) from jirib via bentley@ Sep 13, 2016 + - the "w" layout option is ignored synaptics(4) found by tedu@ Mon, 17 Aug 2015 21:17:42 -0400 loc * exist * algo * size * imp ** - the "s" layout column specifier is used for placement of data into columns, but ignored during column width calculations synaptics(4) found by tedu@ Mon, 17 Aug 2015 21:17:42 -0400 loc * exist ** algo *** size * imp ** - support mdoc(7) and man(7) macros inside tbl(7) code; probably requires the parser reorg and letting tbl(7) use roff_node such that macro sets can mix; informed by bapt@ that FreeBSD needs this. loc *** exist ** algo *** size ** imp *** - look at the POSIX manuals in the books/man-pages-posix port, they use some unsupported tbl(7) features. loc * exist ** algo ** size ** imp *** - use Unicode U+2500 to U+256C for table borders in tbl(7) -Tutf-8 output suggested by bentley@ Tue, 14 Oct 2014 04:10:55 -0600 loc * exist ** algo * size * imp ** --- missing eqn features ----------------------------------------------- - In a matrix, break the output line after each matrix line. Found in the discussion at CDBUG 2015. Suggested by Avi Weinstock. loc * exist * algo * size * imp ** - The "size" keyword is parsed, but ignored by the formatter. loc * exist * algo * size * imp * - The spacing characters `~', `^', and tab are currently ignored, see User's Guide (Second Edition) page 2 section 4. loc * exist * algo ** size * imp ** - Mark and lineup are parsed and ignored, see User's Guide (Second Edition) page 5 section 15. loc ** exist ** algo ** size ** imp ** --- missing misc features ---------------------------------------------- - italic correction (\/) in PostScript mode Werner LEMBERG on groff at gnu dot org Sun, 10 Nov 2013 12:47:46 loc ** exist ** algo * size * imp * - change the default PAGER to more -Es and use the pager even for apropos title line output; req by bapt@ loc * exist * algo * size * imp *** - makewhatis(8) for preformatted pages: parse the section number from the header line and compare to the section number from the directory name loc * exist * algo * size * imp ** - Does makewhatis(8) detect missing NAME sections, missing names, and missing descriptions in all the file formats? loc * exist * algo * size * imp *** - clean up escape sequence handling, creating three classes: (1) fully implemented, or parsed and ignored without loss of content (2) unimplemented, potentially causing loss of content or serious mangling of formatting (e.g. \n) -> ERROR see textproc/mgdiff(1) for nice examples (3) undefined, just output the character -> perhaps WARNING loc *** exist ** algo ** size ** imp *** (parser reorg helps) - kettenis wants base roff, ms, and me Fri, 1 Jan 2010 22:13:15 +0100 (CET) loc ** exist ** algo ** size *** imp * - Vsevolod Stakhov (FreeBSD) needs either a markdown output formatter for mandoc -mdoc or a markdown to mdoc converter because they have to maintain manuals needed both in markdown and mdoc format. Look at the libsoldout (markdown -> whatever) loc * exist * algo * size ** imp ** --- compatibility checks ----------------------------------------------- - is .Bk implemented correctly in modern groff? sobrado@ Tue, 19 Apr 2011 22:12:55 +0200 - compare output to Heirloom roff, Solaris roff, and http://repo.or.cz/w/neatroff.git http://litcave.rudi.ir/ - look at AT&T DWB http://www2.research.att.com/sw/download Carsten Kunze has patches Mon, 4 Aug 2014 17:01:28 +0200 - look at pages generated from reStructeredText, e.g. devel/mercurial hg(1) These are a weird mixture of man(7) and custom autogenerated low-level roff stuff. Figure out to what extent we can cope. For details, see http://docutils.sourceforge.net/rst.html noted by stsp@ Sat, 24 Apr 2010 09:17:55 +0200 reminded by nicm@ Mon, 3 May 2010 09:52:41 +0100 - look at pages generated from ronn(1) github.com/rtomayko/ronn (based on markdown) - look at pages generated from Texinfo source by yat2m, e.g. security/gnupg First impression is not that bad. - look at pages generated by pandoc; see https://github.com/jgm/pandoc/blob/master/src/Text/Pandoc/Writers/Man.hs porting planned by kili@ Thu, 19 Jun 2014 19:46:28 +0200 - check compatibility with Plan9: http://swtch.com/usr/local/plan9/tmac/tmac.an http://swtch.com/plan9port/man/man7/man.html "Anthony J. Bentley" 28 Dec 2010 21:58:40 -0700 - check compatibility with COHERENT troff: http://www.nesssoftware.com/home/mwc/source.php - check compatibility with the man(7) formatter https://raw.githubusercontent.com/rofl0r/hardcore-utils/master/man.c - check compatibility with http://ikiwiki.info/plugins/contrib/mandoc/ https://github.com/schmonz/ikiwiki/compare/mandoc Amitai Schlair Mon, 19 May 2014 14:05:53 -0400 ************************************************************************ * formatting issues: ugly output ************************************************************************ - revisit empty in-line macros look at the difference between "Em x Em ." and "Sq x Em ." Carsten Kunze Fri, 12 Dec 2014 00:15:41 +0100 loc *** exist *** algo *** size * imp ** - a column list with blank `Ta' cells triggers a spurious start-with-whitespace printing of a newline - In .Bl -column, .It a"bc" shows the quotes in groff, but not in mandoc loc * exist *** algo ** size * imp ** - In .Bl -column, .It Em AuthenticationKey Length ought to render "Key Length" with emphasis, too, see OpenBSD iked.conf(5). reported again Nicolas Joly via wiz@ Wed, 12 Oct 2011 00:20:00 +0200 loc * exist *** algo *** size ** imp *** - empty phrases in .Bl column produce too few blanks try e.g. .Bl -column It Ta Ta reported by millert Fri, 02 Apr 2010 16:13:46 -0400 loc * exist *** algo *** size * imp ** - .%T can have trailing punctuation. Currently, it puts the trailing punctuation into a trailing MDOC_TEXT element inside its own scope. That element should rather be outside its scope, such that the punctuation does not get underlines. This is not trivial to implement because .%T then needs some features of in_line_eoln() - slurp all arguments into one single text element - and one feature of in_line() - put trailing punctuation out of scope. Found in mount_nfs(8) and exports(5), search for "Appendix". loc ** exist ** algo *** size * imp ** - Trailing punctuation after .%T triggers EOS spacing, at least outside .Rs (eek!). Simply setting ARGSFL_DELIM for .%T is not the right solution, it sends mandoc into an endless loop. reported by Nicolas Joly Sat, 17 Nov 2012 11:49:54 +0100 loc * exist ** algo ** size * imp ** - global variables in the SYNOPSIS of section 3 pages .Vt vs .Vt/.Va vs .Ft/.Va vs .Ft/.Fa ... from kristaps@ Tue, 08 Jun 2010 11:13:32 +0200 - in enclosures, mandoc sometimes fancies a bogus end of sentence reminded by jmc@ Thu, 23 Sep 2010 18:13:39 +0059 loc * exist ** algo *** size * imp *** - a line starting with "\fB something" counts as starting with whitespace and triggers a line break; found in audio/normalize-mp3(1) loc ** exist * algo ** size * imp ** - formatting /usr/local/man/man1/latex2man.1 with groff and mandoc reveals lots of bugs both in groff and mandoc... reported by bentley@ Wed, 22 May 2013 23:49:30 -0600 --- PDF issues --------------------------------------------------------- - PDF output doesn't use a monospaced font for .Bd -literal Example: "mandoc -Tpdf afterboot.8 > output.pdf && pdfviewer output.pdf". Search the text "Routing tables". Also check what PostScript mode does when fixing this. reported by juanfra@ Wed, 04 Jun 2014 21:44:58 +0200 instructions from juanfra@ Wed, 11 Jun 2014 02:21:01 +0200 add a new <> block to the PDF files with /BaseFont /Courier and change the /Name from /F0 to the new font (/F5 (?)). loc * exist ** algo ** size * imp ** --- HTML issues -------------------------------------------------------- -
formatting is ugly hints are easy to find on the web, e.g. http://stackoverflow.com/questions/1713048/ see also matthew@ Fri, 18 Jul 2014 19:25:12 -0700 loc * exist * algo ** size * imp *** - In -man -Thtml, .nf does not preserve indentation. It should either convert blanks to   or use
 rather than 
(like .Bd -literal does). Reported by afresh1@ 12 Apr 2016 14:35:45 -0700 - .Bf at the beginning of a paragraph inserts a bogus 1ex horizontal space, see for example random(3). Introduced in http://mdocml.bsd.lv/cgi-bin/cvsweb/mdoc_html.c.diff?r1=1.91&r2=1.92 reported by deraadt@ Mon, 28 Sep 2015 20:14:13 -0600 (MDT) loc ** exist ** algo ** size * imp * - jsg on icb, Nov 3, 2014: try to guess Xr in man(7) for hyperlinking - The tables used to render the three-part page headers actually force the width of the to the max-width given for . Not yet sure how to fix that... Observed by an Anonymous Coward on undeadly.org: http://undeadly.org/cgi?action=article&sid=20140925064244&pid=1 loc * exist * algo ** size * imp *** - consider whether can be used for Ar Dv Er Ev Fa Va. from bentley@ Wed, 13 Aug 2014 09:17:55 -0600 - generate tags in HTML idea from florian@ Tue, 7 Apr 2015 00:26:28 +0000 may be possible to implement with .Lk img://something.png alt_text - check https://github.com/trentm/mdocml ************************************************************************ * formatting issues: gratuitous differences ************************************************************************ - .Fn reopens a new scope after punctuation in mandoc, but closes its scope for good in groff. Do we want to change mandoc or groff? Steffen Nurpmeso Sat, 08 Nov 2014 13:34:59 +0100 loc * exist ** algo ** size * imp ** - In .Bl -enum -width 0n, groff continues one the same line after the number, mandoc breaks the line. mail to kristaps@ Mon, 20 Jul 2009 02:21:39 +0200 loc * exist ** algo ** size * imp ** - .Pp between two .It in .Bl -column should produce one, not two blank lines, see e.g. login.conf(5). reported by jmc@ Sun, 17 Apr 2011 14:04:58 +0059 reported again by sthen@ Wed, 18 Jan 2012 02:09:39 +0000 (UTC) loc * exist *** algo ** size * imp ** - If the *first* line after .It is .Pp, break the line right after the tag, do not pad with space characters before breaking. See the description of the a, c, and i commands in sed(1). loc * exist ** algo ** size * imp ** - If the first line after .It is .D1, do not assert a blank line in between, see for example tmux(1). reported by nicm@ 13 Jan 2011 00:18:57 +0000 loc * exist ** algo ** size * imp ** - Trailing punctuation after .It should trigger EOS spacing. reported by Nicolas Joly Sat, 17 Nov 2012 11:49:54 +0100 Probably, this should be fixed somewhere in termp_it_pre(), not sure. loc * exist ** algo ** size * imp ** - .Nx 1.0a should be "NetBSD 1.0A", not "NetBSD 1.0a", see OpenBSD ccdconfig(8). loc * exist * algo * size * imp ** - In .Bl -tag, if a tag exceeds the right margin and must be continued on the next line, it must be indented by -width, not width+1; see "rule block|pass" in OpenBSD ifconfig(8). loc * exist *** algo ** size * imp ** - When the -width string contains macros, the macros must be rendered before measuring the width, for example .Bl -tag -width ".Dv message" in magic(5), located in src/usr.bin/file, is the same as -width 7n, not -width 11n. The same applies to .Bl -column column widths; reported again by Nicolas Joly Thu, 1 Mar 2012 13:41:26 +0100 via wiz@ 5 Mar reported again by Franco Fichtner Fri, 27 Sep 2013 21:02:28 +0200 loc *** exist *** algo *** size ** imp *** An easy partial fix would be to just skip the first word if it starts with a dot, including any following white space, when measuring. loc * exist * algo * size * imp *** - The \& zero-width character counts as output. That is, when it is alone on a line between two .Pp, we want three blank lines, not two as in mandoc. loc ** exist ** algo ** size * imp ** - Header lines of excessive length: Port OpenBSD man_term.c rev. 1.25 to mdoc_term.c and document it in mdoc(7) and man(7) COMPATIBILITY found while talking to Chris Bennett loc * exist * algo * size * imp * - Sequences of multiple man(7) paragraphs (.PP, .IP) interspersed with .ps and .nf/.fi produce execessive blank lines, see libJudy and graphics/dcmtk. The parser reorg may help with this. - trailing whitespace must be ignored even when followed by a font escape, see for example makes \fBdig \fR operate in batch mode in dig(1). loc ** exist ** algo ** size * imp ** ************************************************************************ -* portability -************************************************************************ - -- systems having UTF-8 but not en_US.UTF-8 - call locale(1) from ./configure, select a UTF-8-locale, - and use that for test-wchar.c and term_ascii.c - to Markus Waldeck Sat, 18 Jul 2015 01:55:37 +0200 - loc * exist * algo * size * imp * - -************************************************************************ * warning issues ************************************************************************ - provide a way in mandoc(1) to warn about broken .Xr links; probably cannot be on by default in -Tlint because it needs to access the manpath and mandoc.db(3) after parsing. asked for by jmc@ Fri, 4 Dec 2015 22:39:40 +0000 - Report errors in -O suboption parsing. loc * exist * algo * size * imp ** - warn when .Sh or .Ss contain other macros Steffen Nurpmeso, savannah.gnu.org/bugs/index.php?45034 loc * exist * algo * size * imp ** - check that MANDOCERR_BADTAB is thrown in the right cases, i.e. when finding a literal tab character in fill mode, and possibly change the wording of the warning message to refer to fill mode, not literal mode See the mail from Werner LEMBERG on the groff list, Fri, 14 Feb 2014 18:54:42 +0100 (CET) loc * exist ** algo ** size * imp ** - warn about attempts to call non-callable macros Steffen Nurpmeso Tue, 11 Nov 2014 22:55:16 +0100 Note that formatting is inconsistent in groff. .Fn Po prints "Po()", .Ar Sh prints "file ..." and no "Sh". Relatively hard because the relevant code is scattered all over mdoc_macro.c and all subtly different. loc ** exist ** algo ** size ** imp ** - warn about "new sentence, new line" loc ** exist ** algo *** size * imp ** - mandoc_special does not really check the escape sequence, but just the overall format loc ** exist ** algo *** size ** imp ** - integrate mdoclint into mandoc ("end-of-line whitespace" thread) from jmc@ Mon, 13 Jul 2009 17:12:09 +0100 from kristaps@ Mon, 13 Jul 2009 18:34:53 +0200 from jmc@ Mon, 13 Jul 2009 17:45:37 +0059 from kristaps@ Mon, 13 Jul 2009 19:02:03 +0200 (mostly done, check what remains) - -Tlint parser errors and warnings to stdout to tech@mdocml, naddy@ Wed, 28 Sep 2011 11:21:46 +0200 wait! kristaps@ Sun, 02 Oct 2011 17:12:52 +0200 ************************************************************************ * documentation issues ************************************************************************ - mention hyphenation rules: breaking at letter-letter in text mode (not macro args) proper hyphenation is unimplemented - talk about spacing around delimiters to jmc@, kristaps@ Sat, 23 Apr 2011 17:41:27 +0200 - mark macros as: page structure domain, manual domain, general text domain is this useful? - mention /usr/share/misc/mdoc.template in mdoc(7)? - Is all the content from http://www.std.com/obi/BSD/doc/usd/28.tbl/tbl covered in tbl(7)? ************************************************************************ * performance issues ************************************************************************ - Why are we using MAP_SHARED, not MAP_PRIVATE for mmap(2)? - How does SQLITE_CONFIG_PAGECACHE actually work? Document it! from kristaps@ Sat, 09 Aug 2014 13:51:36 +0200 Several areas can be cleaned up to make mandoc even faster. These are - improve hashing mechanism for macros (quite important: performance) - improve hashing mechanism for characters (not as important) - the PDF file is HUGE: this can be reduced by using relative offsets - instead of re-initialising the roff predefined-strings set before each parse, create a read-only version the first time and copy it loc * exist ** algo ** size * imp ** ************************************************************************ * structural issues ************************************************************************ +- POSIX says in the documentation of sysconf(3) that PATH_MAX + is allowed to be so large that it is a bad idea to use it + for sizing static buffers. So use dynamic buffers throughout. + See the file test-PATH_MAX.c for details. + Found by Aaron M. Ucko in the GNU Hurd via Bdale Garbee, + https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=829624 + - We use the input line number at several places to distinguish same-line from different-line input. That plainly doesn't work with user-defined macros, leading to random breakage. - Find better ways to prevent endless loops in roff(7) macro and string expansion. - Finish cleanup of date handling. Decide which formats should be recognized where. Update both mdoc(7) and man(7) documentation. Triggered by Tim van der Molen Tue, 22 Feb 2011 20:30:45 +0100 - struct mparse refactoring Steffen Nurpmeso Thu, 04 Sep 2014 12:50:00 +0200 - -- Consider creating some views that will make the database more - readable from the sqlite3 shell. Consider using them to - abstract from the database structure, too. - suggested by espie@ Sat, 19 Apr 2014 14:52:57 +0200 ************************************************************************ * CGI issues ************************************************************************ - Enable HTTP compression by detecting gzip encoding and filtering output through libz. - Sandbox (see OpenSSH). - Enable caching support via HTTP 304 and If-Modified-Since. - Allow for cgi.h to be overridden by CGI environment variables. Otherwise, binary distributions will inherit the compile-time behaviour, which is not optimal. - Have Mac OSX systems automatically disable -static compilation of the CGI: -static isn't supported. ************************************************************************ * to improve in the groff_mdoc(7) macros ************************************************************************ - use uname(1) to set doc-default-operating-system at install time tobimensch Mon, 1 Dec 2014 00:25:07 +0100 Index: stable/11/contrib/mdocml/cgi.c =================================================================== --- stable/11/contrib/mdocml/cgi.c (revision 316419) +++ stable/11/contrib/mdocml/cgi.c (revision 316420) @@ -1,1186 +1,1179 @@ -/* $Id: cgi.c,v 1.135 2016/07/11 22:48:37 schwarze Exp $ */ +/* $Id: cgi.c,v 1.144 2017/01/21 01:20:31 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons - * Copyright (c) 2014, 2015, 2016 Ingo Schwarze + * Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze * * 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 AUTHORS DISCLAIM ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #include "mandoc_aux.h" #include "mandoc.h" #include "roff.h" #include "mdoc.h" #include "man.h" #include "main.h" #include "manconf.h" #include "mansearch.h" #include "cgi.h" /* * A query as passed to the search function. */ struct query { char *manpath; /* desired manual directory */ char *arch; /* architecture */ char *sec; /* manual section */ char *query; /* unparsed query expression */ int equal; /* match whole names, not substrings */ }; struct req { struct query q; char **p; /* array of available manpaths */ size_t psz; /* number of available manpaths */ int isquery; /* QUERY_STRING used, not PATH_INFO */ }; enum focus { FOCUS_NONE = 0, FOCUS_QUERY }; static void html_print(const char *); static void html_putchar(char); static int http_decode(char *); static void parse_manpath_conf(struct req *); static void parse_path_info(struct req *req, const char *path); static void parse_query_string(struct req *, const char *); static void pg_error_badrequest(const char *); static void pg_error_internal(void); static void pg_index(const struct req *); static void pg_noresult(const struct req *, const char *); static void pg_search(const struct req *); static void pg_searchres(const struct req *, struct manpage *, size_t); static void pg_show(struct req *, const char *); static void resp_begin_html(int, const char *); static void resp_begin_http(int, const char *); static void resp_catman(const struct req *, const char *); static void resp_copy(const char *); static void resp_end_html(void); static void resp_format(const struct req *, const char *); static void resp_searchform(const struct req *, enum focus); static void resp_show(const struct req *, const char *); static void set_query_attr(char **, char **); static int validate_filename(const char *); static int validate_manpath(const struct req *, const char *); static int validate_urifrag(const char *); static const char *scriptname = SCRIPT_NAME; static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9}; static const char *const sec_numbers[] = { "0", "1", "2", "3", "3p", "4", "5", "6", "7", "8", "9" }; static const char *const sec_names[] = { "All Sections", "1 - General Commands", "2 - System Calls", "3 - Library Functions", "3p - Perl Library", "4 - Device Drivers", "5 - File Formats", "6 - Games", "7 - Miscellaneous Information", "8 - System Manager\'s Manual", "9 - Kernel Developer\'s Manual" }; static const int sec_MAX = sizeof(sec_names) / sizeof(char *); static const char *const arch_names[] = { - "amd64", "alpha", "armish", "armv7", - "hppa", "hppa64", "i386", "landisk", + "amd64", "alpha", "armv7", + "hppa", "i386", "landisk", "loongson", "luna88k", "macppc", "mips64", - "octeon", "sgi", "socppc", "sparc", - "sparc64", "zaurus", - "amiga", "arc", "arm32", "atari", - "aviion", "beagle", "cats", "hp300", + "octeon", "sgi", "socppc", "sparc64", + "amiga", "arc", "armish", "arm32", + "atari", "aviion", "beagle", "cats", + "hppa64", "hp300", "ia64", "mac68k", "mvme68k", "mvme88k", "mvmeppc", "palm", "pc532", "pegasos", - "pmax", "powerpc", "solbourne", "sun3", - "vax", "wgrisc", "x68k" + "pmax", "powerpc", "solbourne", "sparc", + "sun3", "vax", "wgrisc", "x68k", + "zaurus" }; static const int arch_MAX = sizeof(arch_names) / sizeof(char *); /* * Print a character, escaping HTML along the way. * This will pass non-ASCII straight to output: be warned! */ static void html_putchar(char c) { switch (c) { case ('"'): - printf(""e;"); + printf("""); break; case ('&'): printf("&"); break; case ('>'): printf(">"); break; case ('<'): printf("<"); break; default: putchar((unsigned char)c); break; } } /* * Call through to html_putchar(). * Accepts NULL strings. */ static void html_print(const char *p) { if (NULL == p) return; while ('\0' != *p) html_putchar(*p++); } /* * Transfer the responsibility for the allocated string *val * to the query structure. */ static void set_query_attr(char **attr, char **val) { free(*attr); if (**val == '\0') { *attr = NULL; free(*val); } else *attr = *val; *val = NULL; } /* * Parse the QUERY_STRING for key-value pairs * and store the values into the query structure. */ static void parse_query_string(struct req *req, const char *qs) { char *key, *val; size_t keysz, valsz; req->isquery = 1; req->q.manpath = NULL; req->q.arch = NULL; req->q.sec = NULL; req->q.query = NULL; req->q.equal = 1; key = val = NULL; while (*qs != '\0') { /* Parse one key. */ keysz = strcspn(qs, "=;&"); key = mandoc_strndup(qs, keysz); qs += keysz; if (*qs != '=') goto next; /* Parse one value. */ valsz = strcspn(++qs, ";&"); val = mandoc_strndup(qs, valsz); qs += valsz; /* Decode and catch encoding errors. */ if ( ! (http_decode(key) && http_decode(val))) goto next; /* Handle key-value pairs. */ if ( ! strcmp(key, "query")) set_query_attr(&req->q.query, &val); else if ( ! strcmp(key, "apropos")) req->q.equal = !strcmp(val, "0"); else if ( ! strcmp(key, "manpath")) { #ifdef COMPAT_OLDURI if ( ! strncmp(val, "OpenBSD ", 8)) { val[7] = '-'; if ('C' == val[8]) val[8] = 'c'; } #endif set_query_attr(&req->q.manpath, &val); } else if ( ! (strcmp(key, "sec") #ifdef COMPAT_OLDURI && strcmp(key, "sektion") #endif )) { if ( ! strcmp(val, "0")) *val = '\0'; set_query_attr(&req->q.sec, &val); } else if ( ! strcmp(key, "arch")) { if ( ! strcmp(val, "default")) *val = '\0'; set_query_attr(&req->q.arch, &val); } /* * The key must be freed in any case. * The val may have been handed over to the query * structure, in which case it is now NULL. */ next: free(key); key = NULL; free(val); val = NULL; if (*qs != '\0') qs++; } } /* * HTTP-decode a string. The standard explanation is that this turns * "%4e+foo" into "n foo" in the regular way. This is done in-place * over the allocated string. */ static int http_decode(char *p) { char hex[3]; char *q; int c; hex[2] = '\0'; q = p; for ( ; '\0' != *p; p++, q++) { if ('%' == *p) { if ('\0' == (hex[0] = *(p + 1))) return 0; if ('\0' == (hex[1] = *(p + 2))) return 0; if (1 != sscanf(hex, "%x", &c)) return 0; if ('\0' == c) return 0; *q = (char)c; p += 2; } else *q = '+' == *p ? ' ' : *p; } *q = '\0'; return 1; } static void resp_begin_http(int code, const char *msg) { if (200 != code) printf("Status: %d %s\r\n", code, msg); printf("Content-Type: text/html; charset=utf-8\r\n" "Cache-Control: no-cache\r\n" "Pragma: no-cache\r\n" "\r\n"); fflush(stdout); } static void resp_copy(const char *filename) { char buf[4096]; ssize_t sz; int fd; if ((fd = open(filename, O_RDONLY)) != -1) { fflush(stdout); while ((sz = read(fd, buf, sizeof(buf))) > 0) write(STDOUT_FILENO, buf, sz); + close(fd); } } static void resp_begin_html(int code, const char *msg) { resp_begin_http(code, msg); printf("\n" "\n" "\n" - "\n" - "\n" + " \n" - "%s\n" + " %s\n" "\n" - "\n" - "\n", + "\n", CSS_DIR, CUSTOMIZE_TITLE); resp_copy(MAN_DIR "/header.html"); } static void resp_end_html(void) { resp_copy(MAN_DIR "/footer.html"); puts("\n" ""); } static void resp_searchform(const struct req *req, enum focus focus) { int i; - puts(""); - printf("
\n" - "
\n" - "
\n" - "Manual Page Search Parameters\n", + printf("\n" + "
\n" + " Manual Page Search Parameters\n", scriptname); /* Write query input box. */ - printf("q.query != NULL) html_print(req->q.query); printf( "\" size=\"40\""); if (focus == FOCUS_QUERY) printf(" autofocus"); puts(">"); /* Write submission buttons. */ - printf( "\n" - "\n
\n"); + " \n" + "
\n"); /* Write section selector. */ - puts(""); for (i = 0; i < sec_MAX; i++) { - printf("\n", sec_names[i]); } - puts(""); + puts(" "); /* Write architecture selector. */ - printf( ""); + puts(" "); /* Write manpath selector. */ if (req->psz > 1) { - puts(""); for (i = 0; i < (int)req->psz; i++) { - printf(""); } - puts(""); + puts(" "); } - puts("
\n" - "\n" - "
"); - puts(""); + puts(" \n" + ""); } static int validate_urifrag(const char *frag) { while ('\0' != *frag) { if ( ! (isalnum((unsigned char)*frag) || '-' == *frag || '.' == *frag || '/' == *frag || '_' == *frag)) return 0; frag++; } return 1; } static int validate_manpath(const struct req *req, const char* manpath) { size_t i; for (i = 0; i < req->psz; i++) if ( ! strcmp(manpath, req->p[i])) return 1; return 0; } static int validate_filename(const char *file) { if ('.' == file[0] && '/' == file[1]) file += 2; return ! (strstr(file, "../") || strstr(file, "/..") || (strncmp(file, "man", 3) && strncmp(file, "cat", 3))); } static void pg_index(const struct req *req) { resp_begin_html(200, NULL); resp_searchform(req, FOCUS_QUERY); printf("

\n" "This web interface is documented in the\n" - "man.cgi(8)\n" + "man.cgi(8)\n" "manual, and the\n" - "apropos(1)\n" + "apropos(1)\n" "manual explains the query syntax.\n" "

\n", scriptname, *scriptname == '\0' ? "" : "/", scriptname, *scriptname == '\0' ? "" : "/"); resp_end_html(); } static void pg_noresult(const struct req *req, const char *msg) { resp_begin_html(200, NULL); resp_searchform(req, FOCUS_QUERY); puts("

"); puts(msg); puts("

"); resp_end_html(); } static void pg_error_badrequest(const char *msg) { resp_begin_html(400, "Bad Request"); puts("

Bad Request

\n" "

\n"); puts(msg); printf("Try again from the\n" "main page.\n" "

", scriptname); resp_end_html(); } static void pg_error_internal(void) { resp_begin_html(500, "Internal Server Error"); puts("

Internal Server Error

"); resp_end_html(); } static void pg_searchres(const struct req *req, struct manpage *r, size_t sz) { char *arch, *archend; const char *sec; size_t i, iuse; int archprio, archpriouse; int prio, priouse; for (i = 0; i < sz; i++) { if (validate_filename(r[i].file)) continue; warnx("invalid filename %s in %s database", r[i].file, req->q.manpath); pg_error_internal(); return; } if (req->isquery && sz == 1) { /* * If we have just one result, then jump there now * without any delay. */ printf("Status: 303 See Other\r\n"); printf("Location: http://%s/%s%s%s/%s", HTTP_HOST, scriptname, *scriptname == '\0' ? "" : "/", req->q.manpath, r[0].file); printf("\r\n" "Content-Type: text/html; charset=utf-8\r\n" "\r\n"); return; } resp_begin_html(200, NULL); resp_searchform(req, req->q.equal || sz == 1 ? FOCUS_NONE : FOCUS_QUERY); if (sz > 1) { - puts("
"); - puts(""); - + puts("
"); for (i = 0; i < sz; i++) { - printf("\n" - "\n" - "\n" + " \n" - ""); + puts("\n" + " "); } - - puts("
\n" - "\n" + " " + "", scriptname, *scriptname == '\0' ? "" : "/", req->q.manpath, r[i].file); - printf("\">"); html_print(r[i].names); - printf("\n" - ""); + printf(""); html_print(r[i].output); - puts("
\n" - "
"); + puts(""); } /* * In man(1) mode, show one of the pages * even if more than one is found. */ if (req->q.equal || sz == 1) { puts("
"); iuse = 0; priouse = 20; archpriouse = 3; for (i = 0; i < sz; i++) { sec = r[i].file; sec += strcspn(sec, "123456789"); if (sec[0] == '\0') continue; prio = sec_prios[sec[0] - '1']; if (sec[1] != '/') prio += 10; if (req->q.arch == NULL) { archprio = ((arch = strchr(sec + 1, '/')) == NULL) ? 3 : ((archend = strchr(arch + 1, '/')) == NULL) ? 0 : strncmp(arch, "amd64/", archend - arch) ? 2 : 1; if (archprio < archpriouse) { archpriouse = archprio; priouse = prio; iuse = i; continue; } if (archprio > archpriouse) continue; } if (prio >= priouse) continue; priouse = prio; iuse = i; } resp_show(req, r[iuse].file); } resp_end_html(); } static void resp_catman(const struct req *req, const char *file) { FILE *f; char *p; size_t sz; ssize_t len; int i; int italic, bold; if ((f = fopen(file, "r")) == NULL) { puts("

You specified an invalid manual file.

"); return; } puts("
\n" "
");
 
 	p = NULL;
 	sz = 0;
 
 	while ((len = getline(&p, &sz, f)) != -1) {
 		bold = italic = 0;
 		for (i = 0; i < len - 1; i++) {
 			/*
 			 * This means that the catpage is out of state.
 			 * Ignore it and keep going (although the
 			 * catpage is bogus).
 			 */
 
 			if ('\b' == p[i] || '\n' == p[i])
 				continue;
 
 			/*
 			 * Print a regular character.
 			 * Close out any bold/italic scopes.
 			 * If we're in back-space mode, make sure we'll
 			 * have something to enter when we backspace.
 			 */
 
 			if ('\b' != p[i + 1]) {
 				if (italic)
 					printf("");
 				if (bold)
 					printf("");
 				italic = bold = 0;
 				html_putchar(p[i]);
 				continue;
 			} else if (i + 2 >= len)
 				continue;
 
 			/* Italic mode. */
 
 			if ('_' == p[i]) {
 				if (bold)
 					printf("");
 				if ( ! italic)
 					printf("");
 				bold = 0;
 				italic = 1;
 				i += 2;
 				html_putchar(p[i]);
 				continue;
 			}
 
 			/*
 			 * Handle funny behaviour troff-isms.
 			 * These grok'd from the original man2html.c.
 			 */
 
 			if (('+' == p[i] && 'o' == p[i + 2]) ||
 					('o' == p[i] && '+' == p[i + 2]) ||
 					('|' == p[i] && '=' == p[i + 2]) ||
 					('=' == p[i] && '|' == p[i + 2]) ||
 					('*' == p[i] && '=' == p[i + 2]) ||
 					('=' == p[i] && '*' == p[i + 2]) ||
 					('*' == p[i] && '|' == p[i + 2]) ||
 					('|' == p[i] && '*' == p[i + 2]))  {
 				if (italic)
 					printf("");
 				if (bold)
 					printf("");
 				italic = bold = 0;
 				putchar('*');
 				i += 2;
 				continue;
 			} else if (('|' == p[i] && '-' == p[i + 2]) ||
 					('-' == p[i] && '|' == p[i + 1]) ||
 					('+' == p[i] && '-' == p[i + 1]) ||
 					('-' == p[i] && '+' == p[i + 1]) ||
 					('+' == p[i] && '|' == p[i + 1]) ||
 					('|' == p[i] && '+' == p[i + 1]))  {
 				if (italic)
 					printf("");
 				if (bold)
 					printf("");
 				italic = bold = 0;
 				putchar('+');
 				i += 2;
 				continue;
 			}
 
 			/* Bold mode. */
 
 			if (italic)
 				printf("");
 			if ( ! bold)
 				printf("");
 			bold = 1;
 			italic = 0;
 			i += 2;
 			html_putchar(p[i]);
 		}
 
 		/*
 		 * Clean up the last character.
 		 * We can get to a newline; don't print that.
 		 */
 
 		if (italic)
 			printf("");
 		if (bold)
 			printf("");
 
 		if (i == len - 1 && p[i] != '\n')
 			html_putchar(p[i]);
 
 		putchar('\n');
 	}
 	free(p);
 
 	puts("
\n" "
"); fclose(f); } static void resp_format(const struct req *req, const char *file) { struct manoutput conf; struct mparse *mp; struct roff_man *man; void *vp; int fd; int usepath; if (-1 == (fd = open(file, O_RDONLY, 0))) { puts("

You specified an invalid manual file.

"); return; } mchars_alloc(); - mp = mparse_alloc(MPARSE_SO, MANDOCLEVEL_BADARG, NULL, req->q.manpath); + mp = mparse_alloc(MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1, + MANDOCLEVEL_BADARG, NULL, req->q.manpath); mparse_readfd(mp, fd, file); close(fd); memset(&conf, 0, sizeof(conf)); conf.fragment = 1; usepath = strcmp(req->q.manpath, req->p[0]); mandoc_asprintf(&conf.man, "/%s%s%%N.%%S", usepath ? req->q.manpath : "", usepath ? "/" : ""); mparse_result(mp, &man, NULL); if (man == NULL) { warnx("fatal mandoc error: %s/%s", req->q.manpath, file); pg_error_internal(); mparse_free(mp); mchars_free(); return; } vp = html_alloc(&conf); if (man->macroset == MACROSET_MDOC) { mdoc_validate(man); html_mdoc(vp, man); } else { man_validate(man); html_man(vp, man); } html_free(vp); mparse_free(mp); mchars_free(); free(conf.man); } static void resp_show(const struct req *req, const char *file) { if ('.' == file[0] && '/' == file[1]) file += 2; if ('c' == *file) resp_catman(req, file); else resp_format(req, file); } static void pg_show(struct req *req, const char *fullpath) { char *manpath; const char *file; if ((file = strchr(fullpath, '/')) == NULL) { pg_error_badrequest( "You did not specify a page to show."); return; } manpath = mandoc_strndup(fullpath, file - fullpath); file++; if ( ! validate_manpath(req, manpath)) { pg_error_badrequest( "You specified an invalid manpath."); free(manpath); return; } /* * Begin by chdir()ing into the manpath. * This way we can pick up the database files, which are * relative to the manpath root. */ if (chdir(manpath) == -1) { warn("chdir %s", manpath); pg_error_internal(); free(manpath); return; } free(manpath); if ( ! validate_filename(file)) { pg_error_badrequest( "You specified an invalid manual file."); return; } resp_begin_html(200, NULL); resp_searchform(req, FOCUS_NONE); resp_show(req, file); resp_end_html(); } static void pg_search(const struct req *req) { struct mansearch search; struct manpaths paths; struct manpage *res; char **argv; char *query, *rp, *wp; size_t ressz; int argc; /* * Begin by chdir()ing into the root of the manpath. * This way we can pick up the database files, which are * relative to the manpath root. */ if (chdir(req->q.manpath) == -1) { warn("chdir %s", req->q.manpath); pg_error_internal(); return; } search.arch = req->q.arch; search.sec = req->q.sec; search.outkey = "Nd"; search.argmode = req->q.equal ? ARG_NAME : ARG_EXPR; search.firstmatch = 1; paths.sz = 1; paths.paths = mandoc_malloc(sizeof(char *)); paths.paths[0] = mandoc_strdup("."); /* * Break apart at spaces with backslash-escaping. */ argc = 0; argv = NULL; rp = query = mandoc_strdup(req->q.query); for (;;) { while (isspace((unsigned char)*rp)) rp++; if (*rp == '\0') break; argv = mandoc_reallocarray(argv, argc + 1, sizeof(char *)); argv[argc++] = wp = rp; for (;;) { if (isspace((unsigned char)*rp)) { *wp = '\0'; rp++; break; } if (rp[0] == '\\' && rp[1] != '\0') rp++; if (wp != rp) *wp = *rp; if (*rp == '\0') break; wp++; rp++; } } if (0 == mansearch(&search, &paths, argc, argv, &res, &ressz)) pg_noresult(req, "You entered an invalid query."); else if (0 == ressz) pg_noresult(req, "No results found."); else pg_searchres(req, res, ressz); free(query); mansearch_free(res, ressz); free(paths.paths[0]); free(paths.paths); } int main(void) { struct req req; struct itimerval itimer; const char *path; const char *querystring; int i; /* Poor man's ReDoS mitigation. */ itimer.it_value.tv_sec = 2; itimer.it_value.tv_usec = 0; itimer.it_interval.tv_sec = 2; itimer.it_interval.tv_usec = 0; if (setitimer(ITIMER_VIRTUAL, &itimer, NULL) == -1) { warn("setitimer"); pg_error_internal(); return EXIT_FAILURE; } /* * First we change directory into the MAN_DIR so that * subsequent scanning for manpath directories is rooted * relative to the same position. */ if (chdir(MAN_DIR) == -1) { warn("MAN_DIR: %s", MAN_DIR); pg_error_internal(); return EXIT_FAILURE; } memset(&req, 0, sizeof(struct req)); req.q.equal = 1; parse_manpath_conf(&req); /* Parse the path info and the query string. */ if ((path = getenv("PATH_INFO")) == NULL) path = ""; else if (*path == '/') path++; if (*path != '\0') { parse_path_info(&req, path); if (req.q.manpath == NULL || access(path, F_OK) == -1) path = ""; } else if ((querystring = getenv("QUERY_STRING")) != NULL) parse_query_string(&req, querystring); /* Validate parsed data and add defaults. */ if (req.q.manpath == NULL) req.q.manpath = mandoc_strdup(req.p[0]); else if ( ! validate_manpath(&req, req.q.manpath)) { pg_error_badrequest( "You specified an invalid manpath."); return EXIT_FAILURE; } if ( ! (NULL == req.q.arch || validate_urifrag(req.q.arch))) { pg_error_badrequest( "You specified an invalid architecture."); return EXIT_FAILURE; } /* Dispatch to the three different pages. */ if ('\0' != *path) pg_show(&req, path); else if (NULL != req.q.query) pg_search(&req); else pg_index(&req); free(req.q.manpath); free(req.q.arch); free(req.q.sec); free(req.q.query); for (i = 0; i < (int)req.psz; i++) free(req.p[i]); free(req.p); return EXIT_SUCCESS; } /* * If PATH_INFO is not a file name, translate it to a query. */ static void parse_path_info(struct req *req, const char *path) { char *dir[4]; int i; req->isquery = 0; req->q.equal = 1; req->q.manpath = mandoc_strdup(path); req->q.arch = NULL; /* Mandatory manual page name. */ if ((req->q.query = strrchr(req->q.manpath, '/')) == NULL) { req->q.query = req->q.manpath; req->q.manpath = NULL; } else *req->q.query++ = '\0'; /* Optional trailing section. */ if ((req->q.sec = strrchr(req->q.query, '.')) != NULL) { if(isdigit((unsigned char)req->q.sec[1])) { *req->q.sec++ = '\0'; req->q.sec = mandoc_strdup(req->q.sec); } else req->q.sec = NULL; } /* Handle the case of name[.section] only. */ if (req->q.manpath == NULL) return; req->q.query = mandoc_strdup(req->q.query); /* Split directory components. */ dir[i = 0] = req->q.manpath; while ((dir[i + 1] = strchr(dir[i], '/')) != NULL) { if (++i == 3) { pg_error_badrequest( "You specified too many directory components."); exit(EXIT_FAILURE); } *dir[i]++ = '\0'; } /* Optional manpath. */ if ((i = validate_manpath(req, req->q.manpath)) == 0) req->q.manpath = NULL; else if (dir[1] == NULL) return; /* Optional section. */ if (strncmp(dir[i], "man", 3) == 0) { free(req->q.sec); req->q.sec = mandoc_strdup(dir[i++] + 3); } if (dir[i] == NULL) { if (req->q.manpath == NULL) free(dir[0]); return; } if (dir[i + 1] != NULL) { pg_error_badrequest( "You specified an invalid directory component."); exit(EXIT_FAILURE); } /* Optional architecture. */ if (i) { req->q.arch = mandoc_strdup(dir[i]); if (req->q.manpath == NULL) free(dir[0]); } else req->q.arch = dir[0]; } /* * Scan for indexable paths. */ static void parse_manpath_conf(struct req *req) { FILE *fp; char *dp; size_t dpsz; ssize_t len; if ((fp = fopen("manpath.conf", "r")) == NULL) { warn("%s/manpath.conf", MAN_DIR); pg_error_internal(); exit(EXIT_FAILURE); } dp = NULL; dpsz = 0; while ((len = getline(&dp, &dpsz, fp)) != -1) { if (dp[len - 1] == '\n') dp[--len] = '\0'; req->p = mandoc_realloc(req->p, (req->psz + 1) * sizeof(char *)); if ( ! validate_urifrag(dp)) { warnx("%s/manpath.conf contains " "unsafe path \"%s\"", MAN_DIR, dp); pg_error_internal(); exit(EXIT_FAILURE); } if (strchr(dp, '/') != NULL) { warnx("%s/manpath.conf contains " "path with slash \"%s\"", MAN_DIR, dp); pg_error_internal(); exit(EXIT_FAILURE); } req->p[req->psz++] = dp; dp = NULL; dpsz = 0; } free(dp); if (req->p == NULL) { warnx("%s/manpath.conf is empty", MAN_DIR); pg_error_internal(); exit(EXIT_FAILURE); } } Index: stable/11/contrib/mdocml/compat_fts.c =================================================================== --- stable/11/contrib/mdocml/compat_fts.c (revision 316419) +++ stable/11/contrib/mdocml/compat_fts.c (revision 316420) @@ -1,657 +1,708 @@ #include "config.h" #if HAVE_FTS int dummy; #else -/* $Id: compat_fts.c,v 1.9 2015/03/18 19:29:48 schwarze Exp $ */ -/* $OpenBSD: fts.c,v 1.50 2015/01/16 16:48:51 deraadt Exp $ */ +/* $Id: compat_fts.c,v 1.12 2016/10/18 23:58:12 schwarze Exp $ */ +/* $OpenBSD: fts.c,v 1.56 2016/09/21 04:38:56 guenther Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include "compat_fts.h" #define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b)) static FTSENT *fts_alloc(FTS *, const char *, size_t); static FTSENT *fts_build(FTS *); static void fts_lfree(FTSENT *); static void fts_load(FTS *, FTSENT *); static size_t fts_maxarglen(char * const *); static void fts_padjust(FTS *, FTSENT *); static int fts_palloc(FTS *, size_t); +static FTSENT *fts_sort(FTS *, FTSENT *, int); static unsigned short fts_stat(FTS *, FTSENT *); #define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2]))) #ifndef O_DIRECTORY #define O_DIRECTORY 0 #endif #ifndef O_CLOEXEC #define O_CLOEXEC 0 #endif +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif #define CLR(opt) (sp->fts_options &= ~(opt)) #define ISSET(opt) (sp->fts_options & (opt)) #define SET(opt) (sp->fts_options |= (opt)) FTS * -fts_open(char * const *argv, int options, void *dummy) +fts_open(char * const *argv, int options, + int (*compar)(const FTSENT **, const FTSENT **)) { FTS *sp; FTSENT *p, *root; int nitems; FTSENT *parent, *tmp; - size_t len; /* Options check. */ if (options & ~FTS_OPTIONMASK) { errno = EINVAL; return (NULL); } + /* At least one path must be specified. */ + if (*argv == NULL) { + errno = EINVAL; + return (NULL); + } + /* Allocate/initialize the stream */ if ((sp = calloc(1, sizeof(FTS))) == NULL) return (NULL); + sp->fts_compar = compar; sp->fts_options = options; /* * Start out with 1K of path space, and enough, in any case, * to hold the user's paths. */ if (fts_palloc(sp, MAXIMUM(fts_maxarglen(argv), PATH_MAX))) goto mem1; /* Allocate/initialize root's parent. */ if ((parent = fts_alloc(sp, "", 0)) == NULL) goto mem2; parent->fts_level = FTS_ROOTPARENTLEVEL; /* Allocate/initialize root(s). */ for (root = NULL, nitems = 0; *argv; ++argv, ++nitems) { - /* Don't allow zero-length paths. */ - if ((len = strlen(*argv)) == 0) { - errno = ENOENT; + if ((p = fts_alloc(sp, *argv, strlen(*argv))) == NULL) goto mem3; - } - - if ((p = fts_alloc(sp, *argv, len)) == NULL) - goto mem3; p->fts_level = FTS_ROOTLEVEL; p->fts_parent = parent; p->fts_accpath = p->fts_name; p->fts_info = fts_stat(sp, p); /* Command-line "." and ".." are real directories. */ if (p->fts_info == FTS_DOT) p->fts_info = FTS_D; - p->fts_link = NULL; - if (root == NULL) - tmp = root = p; - else { - tmp->fts_link = p; - tmp = p; + /* + * If comparison routine supplied, traverse in sorted + * order; otherwise traverse in the order specified. + */ + if (compar) { + p->fts_link = root; + root = p; + } else { + p->fts_link = NULL; + if (root == NULL) + tmp = root = p; + else { + tmp->fts_link = p; + tmp = p; + } } } + if (compar && nitems > 1) + root = fts_sort(sp, root, nitems); /* * Allocate a dummy pointer and make fts_read think that we've just * finished the node before the root(s); set p->fts_info to FTS_INIT * so that everything about the "current" node is ignored. */ if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL) goto mem3; sp->fts_cur->fts_link = root; sp->fts_cur->fts_info = FTS_INIT; if (nitems == 0) free(parent); return (sp); mem3: fts_lfree(root); free(parent); mem2: free(sp->fts_path); mem1: free(sp); return (NULL); } static void fts_load(FTS *sp, FTSENT *p) { size_t len; char *cp; /* * Load the stream structure for the next traversal. Since we don't * actually enter the directory until after the preorder visit, set * the fts_accpath field specially so the chdir gets done to the right * place and the user can access the first node. From fts_open it's * known that the path will fit. */ len = p->fts_pathlen = p->fts_namelen; memmove(sp->fts_path, p->fts_name, len + 1); if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) { len = strlen(++cp); memmove(p->fts_name, cp, len + 1); p->fts_namelen = len; } p->fts_accpath = p->fts_path = sp->fts_path; sp->fts_dev = p->fts_dev; } int fts_close(FTS *sp) { FTSENT *freep, *p; /* * This still works if we haven't read anything -- the dummy structure * points to the root list, so we step through to the end of the root * list which has a valid parent pointer. */ if (sp->fts_cur) { for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) { freep = p; p = p->fts_link ? p->fts_link : p->fts_parent; free(freep); } free(p); } /* Free up child linked list, sort array, path buffer, stream ptr.*/ if (sp->fts_child) fts_lfree(sp->fts_child); + free(sp->fts_array); free(sp->fts_path); free(sp); return (0); } /* * Special case of "/" at the end of the path so that slashes aren't * appended which would cause paths to be written as "....//foo". */ #define NAPPEND(p) \ (p->fts_path[p->fts_pathlen - 1] == '/' \ ? p->fts_pathlen - 1 : p->fts_pathlen) FTSENT * fts_read(FTS *sp) { FTSENT *p, *tmp; int instr; char *t; /* If finished or unrecoverable error, return NULL. */ if (sp->fts_cur == NULL || ISSET(FTS_STOP)) return (NULL); /* Set current node pointer. */ p = sp->fts_cur; /* Save and zero out user instructions. */ instr = p->fts_instr; p->fts_instr = FTS_NOINSTR; /* Directory in pre-order. */ if (p->fts_info == FTS_D) { /* If skipped or crossed mount point, do post-order visit. */ if (instr == FTS_SKIP || (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) { if (sp->fts_child) { fts_lfree(sp->fts_child); sp->fts_child = NULL; } p->fts_info = FTS_DP; return (p); } /* * If haven't read do so. If the read fails, fts_build sets * FTS_STOP or the fts_info field of the node. */ if (sp->fts_child) { /* nothing */ } else if ((sp->fts_child = fts_build(sp)) == NULL) { if (ISSET(FTS_STOP)) return (NULL); return (p); } p = sp->fts_child; sp->fts_child = NULL; goto name; } /* Move to the next node on this level. */ next: tmp = p; if ((p = p->fts_link)) { free(tmp); /* * If reached the top, return to the original directory (or * the root of the tree), and load the paths for the next root. */ if (p->fts_level == FTS_ROOTLEVEL) { fts_load(sp, p); return (sp->fts_cur = p); } /* * User may have called fts_set on the node. If skipped, * ignore. If followed, get a file descriptor so we can * get back if necessary. */ if (p->fts_instr == FTS_SKIP) goto next; name: t = sp->fts_path + NAPPEND(p->fts_parent); *t++ = '/'; memmove(t, p->fts_name, p->fts_namelen + 1); return (sp->fts_cur = p); } /* Move up to the parent node. */ p = tmp->fts_parent; free(tmp); if (p->fts_level == FTS_ROOTPARENTLEVEL) { /* * Done; free everything up and set errno to 0 so the user * can distinguish between error and EOF. */ free(p); errno = 0; return (sp->fts_cur = NULL); } /* NUL terminate the pathname. */ sp->fts_path[p->fts_pathlen] = '\0'; p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP; return (sp->fts_cur = p); } /* * Fts_set takes the stream as an argument although it's not used in this * implementation; it would be necessary if anyone wanted to add global * semantics to fts using fts_set. An error return is allowed for similar * reasons. */ -/* ARGSUSED */ int fts_set(FTS *sp, FTSENT *p, int instr) { if (instr && instr != FTS_NOINSTR && instr != FTS_SKIP) { errno = EINVAL; return (1); } p->fts_instr = instr; return (0); } /* * This is the tricky part -- do not casually change *anything* in here. The * idea is to build the linked list of entries that are used by fts_children * and fts_read. There are lots of special cases. * * The real slowdown in walking the tree is the stat calls. If FTS_NOSTAT is * set and it's a physical walk (so that symbolic links can't be directories), * we can do things quickly. First, if it's a 4.4BSD file system, the type * of the file is in the directory entry. Otherwise, we assume that the number * of subdirectories in a node is equal to the number of links to the parent. * The former skips all stat calls. The latter skips stat calls in any leaf * directories and for any files after the subdirectories in the directory have * been found, cutting the stat calls by about 2/3. */ static FTSENT * fts_build(FTS *sp) { struct dirent *dp; FTSENT *p, *head; FTSENT *cur, *tail; DIR *dirp; void *oldaddr; size_t dlen, len, maxlen; int nitems, level, doadjust; int saved_errno; char *cp; /* Set current node pointer. */ cur = sp->fts_cur; /* * Open the directory for reading. If this fails, we're done. * If being called from fts_read, set the fts_info field. */ if ((dirp = opendir(cur->fts_accpath)) == NULL) { cur->fts_info = FTS_DNR; cur->fts_errno = errno; return (NULL); } /* * Figure out the max file name length that can be stored in the * current path -- the inner loop allocates more path as necessary. * We really wouldn't have to do the maxlen calculations here, we * could do them in fts_read before returning the path, but it's a * lot easier here since the length is part of the dirent structure. * * If not changing directories set a pointer so that can just append * each new name into the path. */ len = NAPPEND(cur); cp = sp->fts_path + len; *cp++ = '/'; len++; maxlen = sp->fts_pathlen - len; /* * fts_level is signed so we must prevent it from wrapping * around to FTS_ROOTLEVEL and FTS_ROOTPARENTLEVEL. */ level = cur->fts_level; if (level < FTS_MAXLEVEL) level++; /* Read the directory, attaching each entry to the `link' pointer. */ doadjust = 0; for (head = tail = NULL, nitems = 0; dirp && (dp = readdir(dirp));) { if (ISDOT(dp->d_name)) continue; #if HAVE_DIRENT_NAMLEN dlen = dp->d_namlen; #else dlen = strlen(dp->d_name); #endif if (!(p = fts_alloc(sp, dp->d_name, dlen))) goto mem1; if (dlen >= maxlen) { /* include space for NUL */ oldaddr = sp->fts_path; if (fts_palloc(sp, dlen + len + 1)) { /* * No more memory for path or structures. Save * errno, free up the current structure and the * structures already allocated. */ mem1: saved_errno = errno; - if (p) - free(p); + free(p); fts_lfree(head); (void)closedir(dirp); cur->fts_info = FTS_ERR; SET(FTS_STOP); errno = saved_errno; return (NULL); } /* Did realloc() change the pointer? */ if (oldaddr != sp->fts_path) { doadjust = 1; cp = sp->fts_path + len; } maxlen = sp->fts_pathlen - len; } p->fts_level = level; p->fts_parent = sp->fts_cur; p->fts_pathlen = len + dlen; if (p->fts_pathlen < len) { /* * If we wrap, free up the current structure and * the structures already allocated, then error * out with ENAMETOOLONG. */ free(p); fts_lfree(head); (void)closedir(dirp); cur->fts_info = FTS_ERR; SET(FTS_STOP); errno = ENAMETOOLONG; return (NULL); } /* Build a file name for fts_stat to stat. */ p->fts_accpath = p->fts_path; memmove(cp, p->fts_name, p->fts_namelen + 1); /* Stat it. */ p->fts_info = fts_stat(sp, p); /* We walk in directory order so "ls -f" doesn't get upset. */ p->fts_link = NULL; if (head == NULL) head = tail = p; else { tail->fts_link = p; tail = p; } ++nitems; } if (dirp) (void)closedir(dirp); /* * If realloc() changed the address of the path, adjust the * addresses for the rest of the tree and the dir list. */ if (doadjust) fts_padjust(sp, head); /* * If not changing directories, reset the path back to original * state. */ if (len == sp->fts_pathlen || nitems == 0) --cp; *cp = '\0'; /* If didn't find anything, return NULL. */ if (!nitems) { cur->fts_info = FTS_DP; return (NULL); } + + /* Sort the entries. */ + if (sp->fts_compar && nitems > 1) + head = fts_sort(sp, head, nitems); return (head); } static unsigned short fts_stat(FTS *sp, FTSENT *p) { FTSENT *t; dev_t dev; ino_t ino; struct stat *sbp; /* If user needs stat info, stat buffer already allocated. */ sbp = p->fts_statp; if (lstat(p->fts_accpath, sbp)) { p->fts_errno = errno; memset(sbp, 0, sizeof(struct stat)); return (FTS_NS); } if (S_ISDIR(sbp->st_mode)) { /* * Set the device/inode. Used to find cycles and check for * crossing mount points. Also remember the link count, used * in fts_build to limit the number of stat calls. It is * understood that these fields are only referenced if fts_info * is set to FTS_D. */ dev = p->fts_dev = sbp->st_dev; ino = p->fts_ino = sbp->st_ino; p->fts_nlink = sbp->st_nlink; if (ISDOT(p->fts_name)) return (FTS_DOT); /* * Cycle detection is done by brute force when the directory * is first encountered. If the tree gets deep enough or the * number of symbolic links to directories is high enough, * something faster might be worthwhile. */ for (t = p->fts_parent; t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent) if (ino == t->fts_ino && dev == t->fts_dev) { p->fts_cycle = t; return (FTS_DC); } return (FTS_D); } if (S_ISLNK(sbp->st_mode)) return (FTS_SL); if (S_ISREG(sbp->st_mode)) return (FTS_F); return (FTS_DEFAULT); } static FTSENT * +fts_sort(FTS *sp, FTSENT *head, int nitems) +{ + FTSENT **ap, *p; + + /* + * Construct an array of pointers to the structures and call qsort(3). + * Reassemble the array in the order returned by qsort. If unable to + * sort for memory reasons, return the directory entries in their + * current order. Allocate enough space for the current needs plus + * 40 so don't realloc one entry at a time. + */ + if (nitems > sp->fts_nitems) { + struct _ftsent **a; + + sp->fts_nitems = nitems + 40; + if ((a = reallocarray(sp->fts_array, + sp->fts_nitems, sizeof(FTSENT *))) == NULL) { + free(sp->fts_array); + sp->fts_array = NULL; + sp->fts_nitems = 0; + return (head); + } + sp->fts_array = a; + } + for (ap = sp->fts_array, p = head; p; p = p->fts_link) + *ap++ = p; + qsort(sp->fts_array, nitems, sizeof(FTSENT *), sp->fts_compar); + for (head = *(ap = sp->fts_array); --nitems; ++ap) + ap[0]->fts_link = ap[1]; + ap[0]->fts_link = NULL; + return (head); +} + +static FTSENT * fts_alloc(FTS *sp, const char *name, size_t namelen) { FTSENT *p; size_t len; len = sizeof(FTSENT) + namelen; if ((p = calloc(1, len)) == NULL) return (NULL); p->fts_path = sp->fts_path; p->fts_namelen = namelen; p->fts_instr = FTS_NOINSTR; p->fts_statp = malloc(sizeof(struct stat)); if (p->fts_statp == NULL) { free(p); return (NULL); } memcpy(p->fts_name, name, namelen); return (p); } static void fts_lfree(FTSENT *head) { FTSENT *p; /* Free a linked list of structures. */ while ((p = head)) { head = head->fts_link; free(p); } } /* * Allow essentially unlimited paths; find, rm, ls should all work on any tree. * Most systems will allow creation of paths much longer than PATH_MAX, even * though the kernel won't resolve them. Add the size (not just what's needed) * plus 256 bytes so don't realloc the path 2 bytes at a time. */ static int fts_palloc(FTS *sp, size_t more) { char *p; /* * Check for possible wraparound. */ more += 256; if (sp->fts_pathlen + more < sp->fts_pathlen) { - if (sp->fts_path) - free(sp->fts_path); + free(sp->fts_path); sp->fts_path = NULL; errno = ENAMETOOLONG; return (1); } sp->fts_pathlen += more; p = realloc(sp->fts_path, sp->fts_pathlen); if (p == NULL) { - if (sp->fts_path) - free(sp->fts_path); + free(sp->fts_path); sp->fts_path = NULL; return (1); } sp->fts_path = p; return (0); } /* * When the path is realloc'd, have to fix all of the pointers in structures * already returned. */ static void fts_padjust(FTS *sp, FTSENT *head) { FTSENT *p; char *addr = sp->fts_path; #define ADJUST(p) { \ if ((p)->fts_accpath != (p)->fts_name) { \ (p)->fts_accpath = \ (char *)addr + ((p)->fts_accpath - (p)->fts_path); \ } \ (p)->fts_path = addr; \ } /* Adjust the current set of children. */ for (p = sp->fts_child; p; p = p->fts_link) ADJUST(p); /* Adjust the rest of the tree, including the current level. */ for (p = head; p->fts_level >= FTS_ROOTLEVEL;) { ADJUST(p); p = p->fts_link ? p->fts_link : p->fts_parent; } } static size_t fts_maxarglen(char * const *argv) { size_t len, max; for (max = 0; *argv; ++argv) if ((len = strlen(*argv)) > max) max = len; return (max + 1); } #endif Index: stable/11/contrib/mdocml/compat_fts.h =================================================================== --- stable/11/contrib/mdocml/compat_fts.h (revision 316419) +++ stable/11/contrib/mdocml/compat_fts.h (revision 316420) @@ -1,101 +1,105 @@ /* $OpenBSD: fts.h,v 1.14 2012/12/05 23:19:57 deraadt Exp $ */ /* $NetBSD: fts.h,v 1.7 2012/03/01 16:18:51 hans Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)fts.h 8.3 (Berkeley) 8/14/94 */ #ifndef _FTS_H_ #define _FTS_H_ typedef struct { struct _ftsent *fts_cur; /* current node */ struct _ftsent *fts_child; /* linked list of children */ + struct _ftsent **fts_array; /* sort array */ dev_t fts_dev; /* starting device # */ char *fts_path; /* path for this descent */ size_t fts_pathlen; /* sizeof(path) */ + int fts_nitems; /* elements in the sort array */ + int (*fts_compar)(); /* compare function */ #define FTS_NOCHDIR 0x0004 /* don't change directories */ #define FTS_PHYSICAL 0x0010 /* physical walk */ #define FTS_XDEV 0x0040 /* don't cross devices */ #define FTS_OPTIONMASK 0x0054 /* valid user option mask */ #define FTS_STOP 0x2000 /* (private) unrecoverable error */ int fts_options; /* fts_open options, global flags */ } FTS; typedef struct _ftsent { struct _ftsent *fts_cycle; /* cycle node */ struct _ftsent *fts_parent; /* parent directory */ struct _ftsent *fts_link; /* next file in directory */ char *fts_accpath; /* access path */ char *fts_path; /* root path */ int fts_errno; /* errno for this node */ size_t fts_pathlen; /* strlen(fts_path) */ size_t fts_namelen; /* strlen(fts_name) */ ino_t fts_ino; /* inode */ dev_t fts_dev; /* device */ nlink_t fts_nlink; /* link count */ #define FTS_ROOTPARENTLEVEL -1 #define FTS_ROOTLEVEL 0 #define FTS_MAXLEVEL 0x7fffffff int fts_level; /* depth (-1 to N) */ #define FTS_D 1 /* preorder directory */ #define FTS_DC 2 /* directory that causes cycles */ #define FTS_DEFAULT 3 /* none of the above */ #define FTS_DNR 4 /* unreadable directory */ #define FTS_DOT 5 /* dot or dot-dot */ #define FTS_DP 6 /* postorder directory */ #define FTS_ERR 7 /* error; errno is set */ #define FTS_F 8 /* regular file */ #define FTS_INIT 9 /* initialized only */ #define FTS_NS 10 /* stat(2) failed */ #define FTS_NSOK 11 /* no stat(2) requested */ #define FTS_SL 12 /* symbolic link */ unsigned short fts_info; /* user flags for FTSENT structure */ #define FTS_NOINSTR 3 /* no instructions */ #define FTS_SKIP 4 /* discard node */ unsigned short fts_instr; /* fts_set() instructions */ struct stat *fts_statp; /* stat(2) information */ char fts_name[1]; /* file name */ } FTSENT; int fts_close(FTS *); -FTS *fts_open(char * const *, int, void *); +FTS *fts_open(char * const *, int, + int (*)(const FTSENT **, const FTSENT **)); FTSENT *fts_read(FTS *); int fts_set(FTS *, FTSENT *, int); #endif /* !_FTS_H_ */ Index: stable/11/contrib/mdocml/config.h =================================================================== --- stable/11/contrib/mdocml/config.h (revision 316419) +++ stable/11/contrib/mdocml/config.h (revision 316420) @@ -1,52 +1,49 @@ #ifdef __cplusplus #error "Do not use C++. See the INSTALL file." #endif -#ifndef MANDOC_CONFIG_H -#define MANDOC_CONFIG_H +#if !defined(__GNUC__) || (__GNUC__ < 4) +#define __attribute__(x) +#endif #if defined(__linux__) || defined(__MINT__) #define _GNU_SOURCE /* See test-*.c what needs this. */ #endif -#include -#include #define MAN_CONF_FILE "/etc/man.conf" +#define MANPATH_DEFAULT "/usr/share/man:/usr/local/man" +#define UTF8_LOCALE "en_US.UTF-8" #define HAVE_DIRENT_NAMLEN 1 +#define HAVE_ENDIAN 0 #define HAVE_ERR 1 #define HAVE_FTS 1 #define HAVE_GETLINE 1 #define HAVE_GETSUBOPT 1 #define HAVE_ISBLANK 1 #define HAVE_MKDTEMP 1 -#define HAVE_MMAP 1 +#define HAVE_NTOHL 1 #define HAVE_PLEDGE 0 #define HAVE_PROGNAME 1 #define HAVE_REALLOCARRAY 1 -#define HAVE_REWB_BSD 0 -#define HAVE_REWB_SYSV 0 +#define HAVE_REWB_BSD 1 +#define HAVE_REWB_SYSV 1 +#define HAVE_SANDBOX_INIT 0 #define HAVE_STRCASESTR 1 #define HAVE_STRINGLIST 1 #define HAVE_STRLCAT 1 #define HAVE_STRLCPY 1 #define HAVE_STRPTIME 1 #define HAVE_STRSEP 1 #define HAVE_STRTONUM 1 +#define HAVE_SYS_ENDIAN 1 #define HAVE_VASPRINTF 1 #define HAVE_WCHAR 1 -#define HAVE_SQLITE3 1 -#define HAVE_SQLITE3_ERRSTR 0 #define HAVE_OHASH 1 -#define HAVE_MANPATH 1 +#define HAVE_FTS_COMPARE_CONST 1 #define BINM_APROPOS "apropos" #define BINM_MAKEWHATIS "makewhatis" #define BINM_MAN "man" #define BINM_SOELIM "soelim" #define BINM_WHATIS "whatis" - -extern ssize_t getline(char **, size_t *, FILE *); -extern const char *sqlite3_errstr(int); - -#endif /* MANDOC_CONFIG_H */ Index: stable/11/contrib/mdocml/configure =================================================================== --- stable/11/contrib/mdocml/configure (revision 316419) +++ stable/11/contrib/mdocml/configure (revision 316420) @@ -1,470 +1,474 @@ #!/bin/sh # +# $Id: configure,v 1.55 2017/01/12 15:45:05 schwarze Exp $ +# # Copyright (c) 2014, 2015, 2016 Ingo Schwarze # # 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. set -e [ -w config.log ] && mv config.log config.log.old [ -w 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. MANPATH_DEFAULT="/usr/share/man:/usr/X11R6/man:/usr/local/man" OSNAME= +UTF8_LOCALE= -CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | make -f -` -CFLAGS="-g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings" +CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | env -i make -sf -` +CFLAGS="-g -W -Wall -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings" +CFLAGS="${CFLAGS} -Wno-unused-parameter" LDADD= LDFLAGS= +LD_NANOSLEEP= LD_OHASH= -LD_SQLITE3= STATIC="-static" -BUILD_DB=1 BUILD_CGI=0 +INSTALL_LIBMANDOC=0 HAVE_DIRENT_NAMLEN= +HAVE_EFTYPE= +HAVE_ENDIAN= HAVE_ERR= HAVE_FTS= +HAVE_FTS_COMPARE_CONST= HAVE_GETLINE= HAVE_GETSUBOPT= HAVE_ISBLANK= HAVE_MKDTEMP= -HAVE_MMAP= +HAVE_NANOSLEEP= +HAVE_NTOHL= +HAVE_OHASH= +HAVE_PATH_MAX= HAVE_PLEDGE= HAVE_PROGNAME= HAVE_REALLOCARRAY= HAVE_REWB_BSD= HAVE_REWB_SYSV= HAVE_SANDBOX_INIT= HAVE_STRCASESTR= HAVE_STRINGLIST= HAVE_STRLCAT= HAVE_STRLCPY= HAVE_STRPTIME= HAVE_STRSEP= HAVE_STRTONUM= +HAVE_SYS_ENDIAN= HAVE_VASPRINTF= HAVE_WCHAR= -HAVE_SQLITE3= -HAVE_SQLITE3_ERRSTR= -HAVE_OHASH= -HAVE_MANPATH= - PREFIX="/usr/local" BINDIR= SBINDIR= INCLUDEDIR= LIBDIR= MANDIR= HOMEBREWDIR= WWWPREFIX="/var/www" HTDOCDIR= CGIBINDIR= BINM_APROPOS="apropos" BINM_MAKEWHATIS="makewhatis" BINM_MAN="man" BINM_SOELIM="soelim" BINM_WHATIS="whatis" MANM_MAN="man" MANM_MANCONF="man.conf" MANM_MDOC="mdoc" MANM_ROFF="roff" MANM_EQN="eqn" MANM_TBL="tbl" INSTALL="install" INSTALL_PROGRAM= INSTALL_LIB= INSTALL_MAN= INSTALL_DATA= # --- manual settings from configure.local ----------------------------- if [ -r ./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 + [ -z "${3}" ] && return 1 + echo "${1}: manual (HAVE_${2}=${3})" 1>&2 + echo "${1}: manual (HAVE_${2}=${3})" 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 +${1}${3}: testing... +${COMP} -o test-${1} test-${1}.c ${3} __HEREDOC__ - if ${COMP} ${3} -o "test-${1}" "test-${1}.c" 1>&3 2>&3; then - echo "${1}: ${CC} succeeded" 1>&3 + if ${COMP} -o "test-${1}" "test-${1}.c" ${3} 1>&3 2>&3; then + echo "${1}${3}: ${CC} succeeded" 1>&3 else - echo "${1}: ${CC} failed with $?" 1>&3 + echo "${1}${3}: ${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}: yes" 1>&2 + echo "${1}${3}: 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}: 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() { eval _manual=\${HAVE_${2}} - ismanual "${1}" "${_manual}" && return 0 + ismanual "${1}" "${2}" "${_manual}" && return 0 singletest "${1}" "${2}" "${3}" && return 0 - echo "${1}: no" 1>&2 + echo "${1}${3}: no" 1>&2 eval HAVE_${2}=0 return 1 } +# Select a UTF-8 locale. +get_locale() { + [ -n "${HAVE_WCHAR}" ] && [ "${HAVE_WCHAR}" -eq 0 ] && return 0 + ismanual UTF8_LOCALE UTF8_LOCALE "$UTF8_LOCALE" && return 0 + echo "UTF8_LOCALE: testing..." 1>&3 + UTF8_LOCALE=`locale -a | grep -i '^en_US\.UTF-*8$' | head -n 1` + if [ -z "${UTF8_LOCALE}" ]; then + UTF8_LOCALE=`locale -a | grep -i '\.UTF-*8' | head -n 1` + [ -n "${UTF8_LOCALE}" ] || return 1 + fi + echo "UTF8_LOCALE=${UTF8_LOCALE}" 1>&2 + echo "UTF8_LOCALE=${UTF8_LOCALE}" 1>&3 + echo 1>&3 + return 0; +} + + # --- library functions --- runtest dirent-namlen DIRENT_NAMLEN || true +runtest be32toh ENDIAN || true +runtest be32toh SYS_ENDIAN -DSYS_ENDIAN || true +runtest EFTYPE EFTYPE || true runtest err ERR || true -runtest fts FTS || true runtest getline GETLINE || true runtest getsubopt GETSUBOPT || true runtest isblank ISBLANK || true runtest mkdtemp MKDTEMP || true -runtest mmap MMAP || true +runtest ntohl NTOHL || true +runtest PATH_MAX PATH_MAX || true runtest pledge PLEDGE || true runtest sandbox_init SANDBOX_INIT || true runtest progname PROGNAME || true runtest reallocarray REALLOCARRAY || true runtest rewb-bsd REWB_BSD || true runtest rewb-sysv REWB_SYSV || true runtest strcasestr STRCASESTR || true runtest stringlist STRINGLIST || true runtest strlcat STRLCAT || true runtest strlcpy STRLCPY || true runtest strptime STRPTIME || true runtest strsep STRSEP || true runtest strtonum STRTONUM || true runtest vasprintf VASPRINTF || true -runtest wchar WCHAR || true -# --- sqlite3 --- -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 - if [ -z "${LD_SQLITE3}" ]; then - LD_SQLITE3="-lsqlite3" - fi -elif [ -n "${LD_SQLITE3}" ]; then - runtest sqlite3 SQLITE3 "${LD_SQLITE3}" || true -elif singletest sqlite3 SQLITE3 "-lsqlite3"; then - LD_SQLITE3="-lsqlite3" -elif runtest sqlite3 SQLITE3 \ - "-I/usr/local/include -L/usr/local/lib -lsqlite3"; then - LD_SQLITE3="-L/usr/local/lib -lsqlite3" - CFLAGS="${CFLAGS} -I/usr/local/include" +if [ ${HAVE_ENDIAN} -eq 0 -a \ + ${HAVE_SYS_ENDIAN} -eq 0 -a \ + ${HAVE_NTOHL} -eq 0 ]; then + echo "FATAL: no endian conversion functions found" 1>&2 + echo "FATAL: no endian conversion functions found" 1>&3 + exit 1 fi -if [ ${HAVE_SQLITE3} -eq 0 ]; then - LD_SQLITE3= - if [ ${BUILD_DB} -gt 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 + +if ismanual fts FTS ${HAVE_FTS}; then + HAVE_FTS_COMPARE_CONST=0 +elif runtest fts FTS_COMPARE_CONST -DFTS_COMPARE_CONST; then + HAVE_FTS=1 +else + runtest fts FTS || true fi -# --- sqlite3_errstr --- -if [ ${BUILD_DB} -eq 0 ]; then - HAVE_SQLITE3_ERRSTR=1 -elif ismanual sqlite3_errstr "${HAVE_SQLITE3_ERRSTR}"; then - : +# --- wide character and locale support --- +if get_locale; then + runtest wchar WCHAR -DUTF8_LOCALE=\"${UTF8_LOCALE}\" || true else - runtest sqlite3_errstr SQLITE3_ERRSTR "${LD_SQLITE3}" || true + HAVE_WCHAR=0 + echo "wchar: no (no UTF8_LOCALE)" 1>&2 + echo "wchar: no (no UTF8_LOCALE)" 1>&3 fi +# --- nanosleep --- +if [ -n "${LD_NANOSLEEP}" ]; then + runtest nanosleep NANOSLEEP "${LD_NANOSLEEP}" || true +elif singletest nanosleep NANOSLEEP; then + : +elif runtest nanosleep NANOSLEEP "-lrt"; then + LD_NANOSLEEP="-lrt" +fi +if [ "${HAVE_NANOSLEEP}" -eq 0 ]; then + echo "FATAL: nanosleep: no" 1>&2 + echo "FATAL: nanosleep: no" 1>&3 + exit 1 +fi + # --- ohash --- -if ismanual ohash "${HAVE_OHASH}"; then +if ismanual ohash OHASH "${HAVE_OHASH}"; then : elif [ -n "${LD_OHASH}" ]; then runtest ohash OHASH "${LD_OHASH}" || true elif singletest ohash OHASH; then : elif runtest ohash OHASH "-lutil"; then LD_OHASH="-lutil" fi if [ "${HAVE_OHASH}" -eq 0 ]; then LD_OHASH= fi # --- LDADD --- -LDADD="${LDADD} ${LD_SQLITE3} ${LD_OHASH} -lz" +LDADD="${LDADD} ${LD_NANOSLEEP} ${LD_OHASH} -lz" echo "LDADD=\"${LDADD}\"" 1>&2 echo "LDADD=\"${LDADD}\"" 1>&3 echo 1>&3 -# --- manpath --- -if 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__ #ifdef __cplusplus #error "Do not use C++. See the INSTALL file." #endif -#ifndef MANDOC_CONFIG_H -#define MANDOC_CONFIG_H +#if !defined(__GNUC__) || (__GNUC__ < 4) +#define __attribute__(x) +#endif #if defined(__linux__) || defined(__MINT__) #define _GNU_SOURCE /* See test-*.c what needs this. */ #endif __HEREDOC__ [ ${HAVE_GETLINE} -eq 0 -o ${HAVE_REALLOCARRAY} -eq 0 -o \ ${HAVE_STRLCAT} -eq 0 -o ${HAVE_STRLCPY} -eq 0 ] \ && echo "#include " [ ${HAVE_VASPRINTF} -eq 0 ] && echo "#include " [ ${HAVE_GETLINE} -eq 0 ] && echo "#include " echo echo "#define MAN_CONF_FILE \"/etc/${MANM_MANCONF}\"" echo "#define MANPATH_DEFAULT \"${MANPATH_DEFAULT}\"" [ -n "${OSNAME}" ] && echo "#define OSNAME \"${OSNAME}\"" +[ -n "${UTF8_LOCALE}" ] && echo "#define UTF8_LOCALE \"${UTF8_LOCALE}\"" [ -n "${HOMEBREWDIR}" ] && echo "#define HOMEBREWDIR \"${HOMEBREWDIR}\"" +[ ${HAVE_EFTYPE} -eq 0 ] && echo "#define EFTYPE EINVAL" +[ ${HAVE_PATH_MAX} -eq 0 ] && echo "#define PATH_MAX 4096" +if [ ${HAVE_ENDIAN} -eq 0 -a ${HAVE_SYS_ENDIAN} -eq 0 ]; then + echo "#define be32toh ntohl" + echo "#define htobe32 htonl" +fi cat << __HEREDOC__ #define HAVE_DIRENT_NAMLEN ${HAVE_DIRENT_NAMLEN} +#define HAVE_ENDIAN ${HAVE_ENDIAN} #define HAVE_ERR ${HAVE_ERR} #define HAVE_FTS ${HAVE_FTS} +#define HAVE_FTS_COMPARE_CONST ${HAVE_FTS_COMPARE_CONST} #define HAVE_GETLINE ${HAVE_GETLINE} #define HAVE_GETSUBOPT ${HAVE_GETSUBOPT} #define HAVE_ISBLANK ${HAVE_ISBLANK} #define HAVE_MKDTEMP ${HAVE_MKDTEMP} -#define HAVE_MMAP ${HAVE_MMAP} +#define HAVE_NTOHL ${HAVE_NTOHL} #define HAVE_PLEDGE ${HAVE_PLEDGE} #define HAVE_PROGNAME ${HAVE_PROGNAME} #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY} #define HAVE_REWB_BSD ${HAVE_REWB_BSD} #define HAVE_REWB_SYSV ${HAVE_REWB_SYSV} #define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT} #define HAVE_STRCASESTR ${HAVE_STRCASESTR} #define HAVE_STRINGLIST ${HAVE_STRINGLIST} #define HAVE_STRLCAT ${HAVE_STRLCAT} #define HAVE_STRLCPY ${HAVE_STRLCPY} #define HAVE_STRPTIME ${HAVE_STRPTIME} #define HAVE_STRSEP ${HAVE_STRSEP} #define HAVE_STRTONUM ${HAVE_STRTONUM} +#define HAVE_SYS_ENDIAN ${HAVE_SYS_ENDIAN} #define HAVE_VASPRINTF ${HAVE_VASPRINTF} #define HAVE_WCHAR ${HAVE_WCHAR} -#define HAVE_SQLITE3 ${HAVE_SQLITE3} -#define HAVE_SQLITE3_ERRSTR ${HAVE_SQLITE3_ERRSTR} #define HAVE_OHASH ${HAVE_OHASH} -#define HAVE_MANPATH ${HAVE_MANPATH} #define BINM_APROPOS "${BINM_APROPOS}" #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}" #define BINM_MAN "${BINM_MAN}" #define BINM_SOELIM "${BINM_SOELIM}" #define BINM_WHATIS "${BINM_WHATIS}" __HEREDOC__ if [ ${HAVE_ERR} -eq 0 ]; then echo "extern void err(int, const char *, ...);" echo "extern void errx(int, const char *, ...);" echo "extern void warn(const char *, ...);" echo "extern void warnx(const char *, ...);" fi [ ${HAVE_GETLINE} -eq 0 ] && \ echo "extern ssize_t getline(char **, size_t *, FILE *);" [ ${HAVE_GETSUBOPT} -eq 0 ] && \ echo "extern int getsubopt(char **, char * const *, char **);" [ ${HAVE_ISBLANK} -eq 0 ] && \ echo "extern int isblank(int);" [ ${HAVE_MKDTEMP} -eq 0 ] && \ echo "extern char *mkdtemp(char *);" if [ ${HAVE_PROGNAME} -eq 0 ]; then echo "extern const char *getprogname(void);" echo "extern void setprogname(const char *);" 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 *);" [ ${HAVE_STRTONUM} -eq 0 ] && \ echo "extern long long strtonum(const char *, long long, long long, const char **);" [ ${HAVE_VASPRINTF} -eq 0 ] && \ echo "extern int vasprintf(char **, const char *, va_list);" -echo -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 "${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_CGI} -gt 0 ] && BUILD_TARGETS="${BUILD_TARGETS} cgi-build" -INSTALL_TARGETS="base-install" -[ ${BUILD_DB} -gt 0 ] && INSTALL_TARGETS="${INSTALL_TARGETS} db-install" +BUILD_TARGETS= +[ ${BUILD_CGI} -gt 0 ] && BUILD_TARGETS="cgi-build" +INSTALL_TARGETS= +[ ${INSTALL_LIBMANDOC} -gt 0 ] && INSTALL_TARGETS="lib-install" [ ${BUILD_CGI} -gt 0 ] && INSTALL_TARGETS="${INSTALL_TARGETS} cgi-install" cat << __HEREDOC__ BUILD_TARGETS = ${BUILD_TARGETS} INSTALL_TARGETS = ${INSTALL_TARGETS} CC = ${CC} CFLAGS = ${CFLAGS} LDADD = ${LDADD} LDFLAGS = ${LDFLAGS} STATIC = ${STATIC} PREFIX = ${PREFIX} BINDIR = ${BINDIR} SBINDIR = ${SBINDIR} INCLUDEDIR = ${INCLUDEDIR} LIBDIR = ${LIBDIR} MANDIR = ${MANDIR} WWWPREFIX = ${WWWPREFIX} HTDOCDIR = ${HTDOCDIR} CGIBINDIR = ${CGIBINDIR} BINM_APROPOS = ${BINM_APROPOS} BINM_MAKEWHATIS = ${BINM_MAKEWHATIS} BINM_MAN = ${BINM_MAN} BINM_SOELIM = ${BINM_SOELIM} BINM_WHATIS = ${BINM_WHATIS} MANM_MAN = ${MANM_MAN} MANM_MANCONF = ${MANM_MANCONF} MANM_MDOC = ${MANM_MDOC} MANM_ROFF = ${MANM_ROFF} MANM_EQN = ${MANM_EQN} MANM_TBL = ${MANM_TBL} INSTALL = ${INSTALL} INSTALL_PROGRAM = ${INSTALL_PROGRAM} INSTALL_LIB = ${INSTALL_LIB} INSTALL_MAN = ${INSTALL_MAN} INSTALL_DATA = ${INSTALL_DATA} __HEREDOC__ - -[ ${BUILD_DB} -gt 0 ] && \ - echo "MAIN_OBJS = \$(BASE_OBJS) \$(DB_OBJS)" echo "Makefile.local: written" 1>&2 echo "Makefile.local: written" 1>&3 exit 0 Index: stable/11/contrib/mdocml/configure.local.example =================================================================== --- stable/11/contrib/mdocml/configure.local.example (revision 316419) +++ stable/11/contrib/mdocml/configure.local.example (revision 316420) @@ -1,281 +1,269 @@ -# $Id: configure.local.example,v 1.13 2016/07/14 11:09:06 schwarze Exp $ +# $Id: configure.local.example,v 1.22 2016/11/19 15:24:51 schwarze Exp $ # # Copyright (c) 2014, 2015, 2016 Ingo Schwarze # # 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 . # 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 # providing setlocale(3) and 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 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 +# For -Tutf8 mode, mandoc needs to set an arbitrary locale having +# a UTF-8 character set. If autodetection of a suitable locale +# fails or selects an undesirable locale, you can manually choose +# the locale for -Tutf8 mode: + +UTF8_LOCALE=en_US.UTF-8 + # When man(1) or apropos(1) is called without -m and -M options, -# MANPATH is not set in the environment, man.conf(5) is not available -# and manpath(1) not used, manuals are searched for in the following -# directory trees by default. +# MANPATH is not set in the environment, and man.conf(5) is not +# available, manuals are searched for in the following directory +# trees by default. MANPATH_DEFAULT="/usr/share/man:/usr/X11R6/man:/usr/local/man" # 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.9" +OSNAME="OpenBSD 6.0" # 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" -# 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, -# man(1), 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, -# man(1), makewhatis(8), and apropos(1) will not work properly. -HAVE_MANPATH=0 - # Some distributions may want to avoid naming conflicts # with the configuration files of other man(1) implementations. # This changes the name of the installed section 5 manual page as well. MANM_MANCONF="mandoc.conf" # default is "man.conf" # Some distributions may want to avoid naming conflicts among manuals. # If you want to change the names of installed section 7 manual pages, # the following alternative names are suggested. # The suffix ".7" will automatically be appended. # It is possible to set only one or a few of these variables, # there is no need to copy the whole block. MANM_MAN="mandoc_man" # default is "man" MANM_MDOC="mandoc_mdoc" # default is "mdoc" MANM_ROFF="mandoc_roff" # default is "roff" MANM_EQN="mandoc_eqn" # default is "eqn" MANM_TBL="mandoc_tbl" # default is "tbl" -# Some distributions may want to avoid naming conflicts -# with other man(1) and soelim(1) utilities. +# Some distributions may want to avoid naming conflicts with +# other man(1), apropos(1), makewhatis(8), or soelim(1) utilities. # If you want to change the names of binary programs, # the following alternative names are suggested. # Using different names is possible as well. -# This changes the names of the installed section 1 manual pages as well. +# This changes the names of the installed section 1 and section 8 +# manual pages as well. +# It is possible to set only one or two of these variables, +# there is no need to copy the whole block. BINM_MAN=mman # default is "man" +BINM_APROPOS=mapropos # default is "apropos" +BINM_WHATIS=mwhatis # default is "whatis" +BINM_MAKEWHATIS=mandocdb # default is "makewhatis" BINM_SOELIM=msoelim # default is "soelim" # Before falling back to the bundled version of the ohash(3) hashing # library, autoconfiguration tries the following linker flag to # link against your system version. If you do have ohash(3) on # your system but it needs different linker flags, set the following # variable to specify the required linker flags. LD_OHASH="-lutil" -# Some platforms may need additional linker flags to link against libmandoc -# that are not autodetected. -# For example, Solaris 9 and 10 need -lrt for nanosleep(2). +# When library autodetection decides to use -L/usr/local/lib, +# -I/usr/local/include is automatically added to CFLAGS. +# If you manually set LD_OHASH to something including -L/usr/local/lib, +# chances are you will also need the following line: -LDADD="-lrt" +CFLAGS="${CFLAGS} -I/usr/local/include" +# Some platforms may need an additional linker flag for nanosleep(2). +# If none is needed or it is -lrt, it is autodetected. +# Otherwise, set the following variable. + +LD_NANOSLEEP="-lrt" + +# Some platforms might need additional linker flags to link against +# libmandoc that are not autodetected, though no such cases are +# currently known. + +LDADD="-lm" + # Some systems may want to set additional linker flags for all the # binaries, not only for those using libmandoc, for example for # hardening options. LDFLAGS="-Wl,-z,relro" # 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 - -# Autoconfiguration tries the following linker flags to find the -# SQLite3 library installed on your system. If none of these work, -# set the following variable to specify the required linker flags. - -LD_SQLITE3="-lsqlite3" -LD_SQLITE3="-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 LD_SQLITE3 to something including -L/usr/local/lib, -# chances are you will also need the following line: - -CFLAGS="${CFLAGS} -I/usr/local/include" - -# Some distributions may want to avoid naming conflicts -# with another implementation of apropos(1) and makewhatis(8). -# If you want to change the names of the binary programs, -# the following alternative names are suggested. -# Using other names is possible as well. -# This changes the names of the installed section 1 and section 8 -# manual pages as well. -# It is possible to set only one or two of these variables, -# there is no need to copy the whole block. - -BINM_APROPOS=mapropos # default is "apropos" -BINM_WHATIS=mwhatis # default is "whatis" -BINM_MAKEWHATIS=mandocdb # default is "makewhatis" - # When using the "homebrew" package manager on Mac OS X, the actual # manuals are located in a so-called "cellar" and only symlinked # into the manual trees. To allow mandoc to follow such symlinks, # you have to specify the physical location of the cellar as returned # by realpath(3), for example: PREFIX="/usr/local" HOMEBREWDIR="${PREFIX}/Cellar" -# --- user settings related man.cgi ------------------------------------ +# --- user settings for the mandoc(3) library -------------------------- +# By default, libmandoc.a is not installed. It is almost never needed +# because there is almost no non-mandoc software out there using this +# library. The one notable exception is NetBSD apropos(1). +# So, when building for the NetBSD base system - but not for NetBSD +# ports nor for pkgsrc! - you may want the following: + +INSTALL_LIBMANDOC=1 + +# The following settings are only used when INSTALL_LIBMANDOC is set. + +INCLUDEDIR="${PREFIX}/include/mandoc" +LIBDIR="${PREFIX}/lib/mandoc" + +# --- user settings related to 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 # IBM AIX may need: CC=xlc # The default compiler flags are: CFLAGS="-g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings" # IBM AIX xlc does not support -W; in that case, please use: CFLAGS="-g" # 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_ENDIAN=0 +HAVE_EFTYPE=0 HAVE_ERR=0 -HAVE_FTS=0 +HAVE_FTS=0 # Setting this implies HAVE_FTS_COMPARE_CONST=0. +HAVE_FTS_COMPARE_CONST=0 # Setting this implies HAVE_FTS=1. HAVE_GETLINE=0 HAVE_GETSUBOPT=0 HAVE_ISBLANK=0 HAVE_MKDTEMP=0 -HAVE_MMAP=0 +HAVE_NTOHL=0 +HAVE_OHASH=0 +HAVE_PATH_MAX=0 HAVE_PLEDGE=0 HAVE_PROGNAME=0 HAVE_REALLOCARRAY=0 HAVE_REWB_BSD=0 HAVE_REWB_SYSV=0 HAVE_STRCASESTR=0 HAVE_STRINGLIST=0 HAVE_STRLCAT=0 HAVE_STRLCPY=0 HAVE_STRPTIME=0 HAVE_STRSEP=0 HAVE_STRTONUM=0 +HAVE_SYS_ENDIAN=0 HAVE_VASPRINTF=0 HAVE_WCHAR=0 - -HAVE_SQLITE3=0 -HAVE_SQLITE3_ERRSTR=0 -HAVE_OHASH=0 Index: stable/11/contrib/mdocml/dba.c =================================================================== --- stable/11/contrib/mdocml/dba.c (nonexistent) +++ stable/11/contrib/mdocml/dba.c (revision 316420) @@ -0,0 +1,508 @@ +/* $Id: dba.c,v 1.9 2017/01/15 15:28:55 schwarze Exp $ */ +/* + * Copyright (c) 2016, 2017 Ingo Schwarze + * + * 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. + * + * Allocation-based version of the mandoc database, for read-write access. + * The interface is defined in "dba.h". + */ +#include "config.h" + +#include +#if HAVE_ENDIAN +#include +#elif HAVE_SYS_ENDIAN +#include +#elif HAVE_NTOHL +#include +#endif +#include +#include +#include +#include +#include +#include + +#include "mandoc_aux.h" +#include "mandoc_ohash.h" +#include "mansearch.h" +#include "dba_write.h" +#include "dba_array.h" +#include "dba.h" + +struct macro_entry { + struct dba_array *pages; + char value[]; +}; + +static void *prepend(const char *, char); +static void dba_pages_write(struct dba_array *); +static int compare_names(const void *, const void *); +static int compare_strings(const void *, const void *); + +static struct macro_entry + *get_macro_entry(struct ohash *, const char *, int32_t); +static void dba_macros_write(struct dba_array *); +static void dba_macro_write(struct ohash *); +static int compare_entries(const void *, const void *); + + +/*** top-level functions **********************************************/ + +struct dba * +dba_new(int32_t npages) +{ + struct dba *dba; + struct ohash *macro; + int32_t im; + + dba = mandoc_malloc(sizeof(*dba)); + dba->pages = dba_array_new(npages, DBA_GROW); + dba->macros = dba_array_new(MACRO_MAX, 0); + for (im = 0; im < MACRO_MAX; im++) { + macro = mandoc_malloc(sizeof(*macro)); + mandoc_ohash_init(macro, 4, + offsetof(struct macro_entry, value)); + dba_array_set(dba->macros, im, macro); + } + return dba; +} + +void +dba_free(struct dba *dba) +{ + struct dba_array *page; + struct ohash *macro; + struct macro_entry *entry; + unsigned int slot; + + dba_array_FOREACH(dba->macros, macro) { + for (entry = ohash_first(macro, &slot); entry != NULL; + entry = ohash_next(macro, &slot)) { + dba_array_free(entry->pages); + free(entry); + } + ohash_delete(macro); + free(macro); + } + dba_array_free(dba->macros); + + dba_array_undel(dba->pages); + dba_array_FOREACH(dba->pages, page) { + dba_array_free(dba_array_get(page, DBP_NAME)); + dba_array_free(dba_array_get(page, DBP_SECT)); + dba_array_free(dba_array_get(page, DBP_ARCH)); + free(dba_array_get(page, DBP_DESC)); + dba_array_free(dba_array_get(page, DBP_FILE)); + dba_array_free(page); + } + dba_array_free(dba->pages); + + free(dba); +} + +/* + * Write the complete mandoc database to disk; the format is: + * - One integer each for magic and version. + * - One pointer each to the macros table and to the final magic. + * - The pages table. + * - The macros table. + * - And at the very end, the magic integer again. + */ +int +dba_write(const char *fname, struct dba *dba) +{ + int save_errno; + int32_t pos_end, pos_macros, pos_macros_ptr; + + if (dba_open(fname) == -1) + return -1; + dba_int_write(MANDOCDB_MAGIC); + dba_int_write(MANDOCDB_VERSION); + pos_macros_ptr = dba_skip(1, 2); + dba_pages_write(dba->pages); + pos_macros = dba_tell(); + dba_macros_write(dba->macros); + pos_end = dba_tell(); + dba_int_write(MANDOCDB_MAGIC); + dba_seek(pos_macros_ptr); + dba_int_write(pos_macros); + dba_int_write(pos_end); + if (dba_close() == -1) { + save_errno = errno; + unlink(fname); + errno = save_errno; + return -1; + } + return 0; +} + + +/*** functions for handling pages *************************************/ + +/* + * Create a new page and append it to the pages table. + */ +struct dba_array * +dba_page_new(struct dba_array *pages, const char *arch, + const char *desc, const char *file, enum form form) +{ + struct dba_array *page, *entry; + + page = dba_array_new(DBP_MAX, 0); + entry = dba_array_new(1, DBA_STR | DBA_GROW); + dba_array_add(page, entry); + entry = dba_array_new(1, DBA_STR | DBA_GROW); + dba_array_add(page, entry); + if (arch != NULL && *arch != '\0') { + entry = dba_array_new(1, DBA_STR | DBA_GROW); + dba_array_add(entry, (void *)arch); + } else + entry = NULL; + dba_array_add(page, entry); + dba_array_add(page, mandoc_strdup(desc)); + entry = dba_array_new(1, DBA_STR | DBA_GROW); + dba_array_add(entry, prepend(file, form)); + dba_array_add(page, entry); + dba_array_add(pages, page); + return page; +} + +/* + * Add a section, architecture, or file name to an existing page. + * Passing the NULL pointer for the architecture makes the page MI. + * In that case, any earlier or later architectures are ignored. + */ +void +dba_page_add(struct dba_array *page, int32_t ie, const char *str) +{ + struct dba_array *entries; + char *entry; + + entries = dba_array_get(page, ie); + if (ie == DBP_ARCH) { + if (entries == NULL) + return; + if (str == NULL || *str == '\0') { + dba_array_free(entries); + dba_array_set(page, DBP_ARCH, NULL); + return; + } + } + if (*str == '\0') + return; + dba_array_FOREACH(entries, entry) { + if (ie == DBP_FILE && *entry < ' ') + entry++; + if (strcmp(entry, str) == 0) + return; + } + dba_array_add(entries, (void *)str); +} + +/* + * Add an additional name to an existing page. + */ +void +dba_page_alias(struct dba_array *page, const char *name, uint64_t mask) +{ + struct dba_array *entries; + char *entry; + char maskbyte; + + if (*name == '\0') + return; + maskbyte = mask & NAME_MASK; + entries = dba_array_get(page, DBP_NAME); + dba_array_FOREACH(entries, entry) { + if (strcmp(entry + 1, name) == 0) { + *entry |= maskbyte; + return; + } + } + dba_array_add(entries, prepend(name, maskbyte)); +} + +/* + * Return a pointer to a temporary copy of instr with inbyte prepended. + */ +static void * +prepend(const char *instr, char inbyte) +{ + static char *outstr = NULL; + static size_t outlen = 0; + size_t newlen; + + newlen = strlen(instr) + 1; + if (newlen > outlen) { + outstr = mandoc_realloc(outstr, newlen + 1); + outlen = newlen; + } + *outstr = inbyte; + memcpy(outstr + 1, instr, newlen); + return outstr; +} + +/* + * Write the pages table to disk; the format is: + * - One integer containing the number of pages. + * - For each page, five pointers to the names, sections, + * architectures, description, and file names of the page. + * MI pages write 0 instead of the architecture pointer. + * - One list each for names, sections, architectures, descriptions and + * file names. The description for each page ends with a NUL byte. + * For all the other lists, each string ends with a NUL byte, + * and the last string for a page ends with two NUL bytes. + * - To assure alignment of following integers, + * the end is padded with NUL bytes up to a multiple of four bytes. + */ +static void +dba_pages_write(struct dba_array *pages) +{ + struct dba_array *page, *entry; + int32_t pos_pages, pos_end; + + pos_pages = dba_array_writelen(pages, 5); + dba_array_FOREACH(pages, page) { + dba_array_setpos(page, DBP_NAME, dba_tell()); + entry = dba_array_get(page, DBP_NAME); + dba_array_sort(entry, compare_names); + dba_array_writelst(entry); + } + dba_array_FOREACH(pages, page) { + dba_array_setpos(page, DBP_SECT, dba_tell()); + entry = dba_array_get(page, DBP_SECT); + dba_array_sort(entry, compare_strings); + dba_array_writelst(entry); + } + dba_array_FOREACH(pages, page) { + if ((entry = dba_array_get(page, DBP_ARCH)) != NULL) { + dba_array_setpos(page, DBP_ARCH, dba_tell()); + dba_array_sort(entry, compare_strings); + dba_array_writelst(entry); + } else + dba_array_setpos(page, DBP_ARCH, 0); + } + dba_array_FOREACH(pages, page) { + dba_array_setpos(page, DBP_DESC, dba_tell()); + dba_str_write(dba_array_get(page, DBP_DESC)); + } + dba_array_FOREACH(pages, page) { + dba_array_setpos(page, DBP_FILE, dba_tell()); + dba_array_writelst(dba_array_get(page, DBP_FILE)); + } + pos_end = dba_align(); + dba_seek(pos_pages); + dba_array_FOREACH(pages, page) + dba_array_writepos(page); + dba_seek(pos_end); +} + +static int +compare_names(const void *vp1, const void *vp2) +{ + const char *cp1, *cp2; + int diff; + + cp1 = *(char **)vp1; + cp2 = *(char **)vp2; + return (diff = *cp2 - *cp1) ? diff : + strcasecmp(cp1 + 1, cp2 + 1); +} + +static int +compare_strings(const void *vp1, const void *vp2) +{ + const char *cp1, *cp2; + + cp1 = *(char **)vp1; + cp2 = *(char **)vp2; + return strcmp(cp1, cp2); +} + +/*** functions for handling macros ************************************/ + +/* + * In the hash table for a single macro, look up an entry by + * the macro value or add an empty one if it doesn't exist yet. + */ +static struct macro_entry * +get_macro_entry(struct ohash *macro, const char *value, int32_t np) +{ + struct macro_entry *entry; + size_t len; + unsigned int slot; + + slot = ohash_qlookup(macro, value); + if ((entry = ohash_find(macro, slot)) == NULL) { + len = strlen(value) + 1; + entry = mandoc_malloc(sizeof(*entry) + len); + memcpy(&entry->value, value, len); + entry->pages = dba_array_new(np, DBA_GROW); + ohash_insert(macro, slot, entry); + } + return entry; +} + +/* + * In addition to get_macro_entry(), add multiple page references, + * converting them from the on-disk format (byte offsets in the file) + * to page pointers in memory. + */ +void +dba_macro_new(struct dba *dba, int32_t im, const char *value, + const int32_t *pp) +{ + struct macro_entry *entry; + const int32_t *ip; + int32_t np; + + np = 0; + for (ip = pp; *ip; ip++) + np++; + + entry = get_macro_entry(dba_array_get(dba->macros, im), value, np); + for (ip = pp; *ip; ip++) + dba_array_add(entry->pages, dba_array_get(dba->pages, + be32toh(*ip) / 5 / sizeof(*ip) - 1)); +} + +/* + * In addition to get_macro_entry(), add one page reference, + * directly taking the in-memory page pointer as an argument. + */ +void +dba_macro_add(struct dba_array *macros, int32_t im, const char *value, + struct dba_array *page) +{ + struct macro_entry *entry; + + if (*value == '\0') + return; + entry = get_macro_entry(dba_array_get(macros, im), value, 1); + dba_array_add(entry->pages, page); +} + +/* + * Write the macros table to disk; the format is: + * - The number of macro tables (actually, MACRO_MAX). + * - That number of pointers to the individual macro tables. + * - The individual macro tables. + */ +static void +dba_macros_write(struct dba_array *macros) +{ + struct ohash *macro; + int32_t im, pos_macros, pos_end; + + pos_macros = dba_array_writelen(macros, 1); + im = 0; + dba_array_FOREACH(macros, macro) { + dba_array_setpos(macros, im++, dba_tell()); + dba_macro_write(macro); + } + pos_end = dba_tell(); + dba_seek(pos_macros); + dba_array_writepos(macros); + dba_seek(pos_end); +} + +/* + * Write one individual macro table to disk; the format is: + * - The number of entries in the table. + * - For each entry, two pointers, the first one to the value + * and the second one to the list of pages. + * - A list of values, each ending in a NUL byte. + * - To assure alignment of following integers, + * padding with NUL bytes up to a multiple of four bytes. + * - A list of pointers to pages, each list ending in a 0 integer. + */ +static void +dba_macro_write(struct ohash *macro) +{ + struct macro_entry **entries, *entry; + struct dba_array *page; + int32_t *kpos, *dpos; + unsigned int ie, ne, slot; + int use; + int32_t addr, pos_macro, pos_end; + + /* Temporary storage for filtering and sorting. */ + + ne = ohash_entries(macro); + entries = mandoc_reallocarray(NULL, ne, sizeof(*entries)); + kpos = mandoc_reallocarray(NULL, ne, sizeof(*kpos)); + dpos = mandoc_reallocarray(NULL, ne, sizeof(*dpos)); + + /* Build a list of non-empty entries and sort it. */ + + ne = 0; + for (entry = ohash_first(macro, &slot); entry != NULL; + entry = ohash_next(macro, &slot)) { + use = 0; + dba_array_FOREACH(entry->pages, page) + if (dba_array_getpos(page)) + use = 1; + if (use) + entries[ne++] = entry; + } + qsort(entries, ne, sizeof(*entries), compare_entries); + + /* Number of entries, and space for the pointer pairs. */ + + dba_int_write(ne); + pos_macro = dba_skip(2, ne); + + /* String table. */ + + for (ie = 0; ie < ne; ie++) { + kpos[ie] = dba_tell(); + dba_str_write(entries[ie]->value); + } + dba_align(); + + /* Pages table. */ + + for (ie = 0; ie < ne; ie++) { + dpos[ie] = dba_tell(); + dba_array_FOREACH(entries[ie]->pages, page) + if ((addr = dba_array_getpos(page))) + dba_int_write(addr); + dba_int_write(0); + } + pos_end = dba_tell(); + + /* Fill in the pointer pairs. */ + + dba_seek(pos_macro); + for (ie = 0; ie < ne; ie++) { + dba_int_write(kpos[ie]); + dba_int_write(dpos[ie]); + } + dba_seek(pos_end); + + free(entries); + free(kpos); + free(dpos); +} + +static int +compare_entries(const void *vp1, const void *vp2) +{ + const struct macro_entry *ep1, *ep2; + + ep1 = *(struct macro_entry **)vp1; + ep2 = *(struct macro_entry **)vp2; + return strcmp(ep1->value, ep2->value); +} Property changes on: stable/11/contrib/mdocml/dba.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: stable/11/contrib/mdocml/dba.h =================================================================== --- stable/11/contrib/mdocml/dba.h (nonexistent) +++ stable/11/contrib/mdocml/dba.h (revision 316420) @@ -0,0 +1,50 @@ +/* $Id: dba.h,v 1.2 2016/08/17 20:46:56 schwarze Exp $ */ +/* + * Copyright (c) 2016 Ingo Schwarze + * + * 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. + * + * Public interface of the allocation-based version + * of the mandoc database, for read-write access. + * To be used by dba.c, dba_read.c, and makewhatis(8). + */ + +#define DBP_NAME 0 +#define DBP_SECT 1 +#define DBP_ARCH 2 +#define DBP_DESC 3 +#define DBP_FILE 4 +#define DBP_MAX 5 + +struct dba_array; + +struct dba { + struct dba_array *pages; + struct dba_array *macros; +}; + + +struct dba *dba_new(int32_t); +void dba_free(struct dba *); +struct dba *dba_read(const char *); +int dba_write(const char *, struct dba *); + +struct dba_array *dba_page_new(struct dba_array *, const char *, + const char *, const char *, enum form); +void dba_page_add(struct dba_array *, int32_t, const char *); +void dba_page_alias(struct dba_array *, const char *, uint64_t); + +void dba_macro_new(struct dba *, int32_t, + const char *, const int32_t *); +void dba_macro_add(struct dba_array *, int32_t, + const char *, struct dba_array *); Property changes on: stable/11/contrib/mdocml/dba.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: stable/11/contrib/mdocml/dba_array.c =================================================================== --- stable/11/contrib/mdocml/dba_array.c (nonexistent) +++ stable/11/contrib/mdocml/dba_array.c (revision 316420) @@ -0,0 +1,188 @@ +/* $Id: dba_array.c,v 1.1 2016/07/19 21:31:55 schwarze Exp $ */ +/* + * Copyright (c) 2016 Ingo Schwarze + * + * 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. + * + * Allocation-based arrays for the mandoc database, for read-write access. + * The interface is defined in "dba_array.h". + */ +#include +#include +#include +#include + +#include "mandoc_aux.h" +#include "dba_write.h" +#include "dba_array.h" + +struct dba_array { + void **ep; /* Array of entries. */ + int32_t *em; /* Array of map positions. */ + int flags; + int32_t ea; /* Entries allocated. */ + int32_t eu; /* Entries used (including deleted). */ + int32_t ed; /* Entries deleted. */ + int32_t ec; /* Currently active entry. */ + int32_t pos; /* Map position of this array. */ +}; + + +struct dba_array * +dba_array_new(int32_t ea, int flags) +{ + struct dba_array *array; + + assert(ea > 0); + array = mandoc_malloc(sizeof(*array)); + array->ep = mandoc_reallocarray(NULL, ea, sizeof(*array->ep)); + array->em = mandoc_reallocarray(NULL, ea, sizeof(*array->em)); + array->ea = ea; + array->eu = 0; + array->ed = 0; + array->ec = 0; + array->flags = flags; + array->pos = 0; + return array; +} + +void +dba_array_free(struct dba_array *array) +{ + int32_t ie; + + if (array == NULL) + return; + if (array->flags & DBA_STR) + for (ie = 0; ie < array->eu; ie++) + free(array->ep[ie]); + free(array->ep); + free(array->em); + free(array); +} + +void +dba_array_set(struct dba_array *array, int32_t ie, void *entry) +{ + assert(ie >= 0); + assert(ie < array->ea); + assert(ie <= array->eu); + if (ie == array->eu) + array->eu++; + if (array->flags & DBA_STR) + entry = mandoc_strdup(entry); + array->ep[ie] = entry; + array->em[ie] = 0; +} + +void +dba_array_add(struct dba_array *array, void *entry) +{ + if (array->eu == array->ea) { + assert(array->flags & DBA_GROW); + array->ep = mandoc_reallocarray(array->ep, + 2, sizeof(*array->ep) * array->ea); + array->em = mandoc_reallocarray(array->em, + 2, sizeof(*array->em) * array->ea); + array->ea *= 2; + } + dba_array_set(array, array->eu, entry); +} + +void * +dba_array_get(struct dba_array *array, int32_t ie) +{ + if (ie < 0 || ie >= array->eu || array->em[ie] == -1) + return NULL; + return array->ep[ie]; +} + +void +dba_array_start(struct dba_array *array) +{ + array->ec = array->eu; +} + +void * +dba_array_next(struct dba_array *array) +{ + if (array->ec < array->eu) + array->ec++; + else + array->ec = 0; + while (array->ec < array->eu && array->em[array->ec] == -1) + array->ec++; + return array->ec < array->eu ? array->ep[array->ec] : NULL; +} + +void +dba_array_del(struct dba_array *array) +{ + if (array->ec < array->eu && array->em[array->ec] != -1) { + array->em[array->ec] = -1; + array->ed++; + } +} + +void +dba_array_undel(struct dba_array *array) +{ + memset(array->em, 0, sizeof(*array->em) * array->eu); +} + +void +dba_array_setpos(struct dba_array *array, int32_t ie, int32_t pos) +{ + array->em[ie] = pos; +} + +int32_t +dba_array_getpos(struct dba_array *array) +{ + return array->pos; +} + +void +dba_array_sort(struct dba_array *array, dba_compare_func func) +{ + assert(array->ed == 0); + qsort(array->ep, array->eu, sizeof(*array->ep), func); +} + +int32_t +dba_array_writelen(struct dba_array *array, int32_t nmemb) +{ + dba_int_write(array->eu - array->ed); + return dba_skip(nmemb, array->eu - array->ed); +} + +void +dba_array_writepos(struct dba_array *array) +{ + int32_t ie; + + array->pos = dba_tell(); + for (ie = 0; ie < array->eu; ie++) + if (array->em[ie] != -1) + dba_int_write(array->em[ie]); +} + +void +dba_array_writelst(struct dba_array *array) +{ + const char *str; + + dba_array_FOREACH(array, str) + dba_str_write(str); + dba_char_write('\0'); +} Property changes on: stable/11/contrib/mdocml/dba_array.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: stable/11/contrib/mdocml/dba_array.h =================================================================== --- stable/11/contrib/mdocml/dba_array.h (nonexistent) +++ stable/11/contrib/mdocml/dba_array.h (revision 316420) @@ -0,0 +1,47 @@ +/* $Id: dba_array.h,v 1.1 2016/07/19 21:31:55 schwarze Exp $ */ +/* + * Copyright (c) 2016 Ingo Schwarze + * + * 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. + * + * Public interface for allocation-based arrays + * for the mandoc database, for read-write access. + * To be used by dba*.c and by makewhatis(8). + */ + +struct dba_array; + +#define DBA_STR 0x01 /* Map contains strings, not pointers. */ +#define DBA_GROW 0x02 /* Allow the array to grow. */ + +#define dba_array_FOREACH(a, e) \ + dba_array_start(a); \ + while (((e) = dba_array_next(a)) != NULL) + +typedef int dba_compare_func(const void *, const void *); + +struct dba_array *dba_array_new(int32_t, int); +void dba_array_free(struct dba_array *); +void dba_array_set(struct dba_array *, int32_t, void *); +void dba_array_add(struct dba_array *, void *); +void *dba_array_get(struct dba_array *, int32_t); +void dba_array_start(struct dba_array *); +void *dba_array_next(struct dba_array *); +void dba_array_del(struct dba_array *); +void dba_array_undel(struct dba_array *); +void dba_array_setpos(struct dba_array *, int32_t, int32_t); +int32_t dba_array_getpos(struct dba_array *); +void dba_array_sort(struct dba_array *, dba_compare_func); +int32_t dba_array_writelen(struct dba_array *, int32_t); +void dba_array_writepos(struct dba_array *); +void dba_array_writelst(struct dba_array *); Property changes on: stable/11/contrib/mdocml/dba_array.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: stable/11/contrib/mdocml/dba_read.c =================================================================== --- stable/11/contrib/mdocml/dba_read.c (nonexistent) +++ stable/11/contrib/mdocml/dba_read.c (revision 316420) @@ -0,0 +1,72 @@ +/* $Id: dba_read.c,v 1.4 2016/08/17 20:46:56 schwarze Exp $ */ +/* + * Copyright (c) 2016 Ingo Schwarze + * + * 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. + * + * Function to read the mandoc database from disk into RAM, + * such that data can be added or removed. + * The interface is defined in "dba.h". + * This file is seperate from dba.c because this also uses "dbm.h". + */ +#include +#include +#include +#include +#include + +#include "mandoc_aux.h" +#include "mansearch.h" +#include "dba_array.h" +#include "dba.h" +#include "dbm.h" + + +struct dba * +dba_read(const char *fname) +{ + struct dba *dba; + struct dba_array *page; + struct dbm_page *pdata; + struct dbm_macro *mdata; + const char *cp; + int32_t im, ip, iv, npages; + + if (dbm_open(fname) == -1) + return NULL; + npages = dbm_page_count(); + dba = dba_new(npages < 128 ? 128 : npages); + for (ip = 0; ip < npages; ip++) { + pdata = dbm_page_get(ip); + page = dba_page_new(dba->pages, pdata->arch, + pdata->desc, pdata->file + 1, *pdata->file); + for (cp = pdata->name; *cp != '\0'; cp = strchr(cp, '\0') + 1) + dba_page_add(page, DBP_NAME, cp); + for (cp = pdata->sect; *cp != '\0'; cp = strchr(cp, '\0') + 1) + dba_page_add(page, DBP_SECT, cp); + if ((cp = pdata->arch) != NULL) + while (*(cp = strchr(cp, '\0') + 1) != '\0') + dba_page_add(page, DBP_ARCH, cp); + cp = pdata->file; + while (*(cp = strchr(cp, '\0') + 1) != '\0') + dba_page_add(page, DBP_FILE, cp); + } + for (im = 0; im < MACRO_MAX; im++) { + for (iv = 0; iv < dbm_macro_count(im); iv++) { + mdata = dbm_macro_get(im, iv); + dba_macro_new(dba, im, mdata->value, mdata->pp); + } + } + dbm_close(); + return dba; +} Property changes on: stable/11/contrib/mdocml/dba_read.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: stable/11/contrib/mdocml/dba_write.c =================================================================== --- stable/11/contrib/mdocml/dba_write.c (nonexistent) +++ stable/11/contrib/mdocml/dba_write.c (revision 316420) @@ -0,0 +1,127 @@ +/* $Id: dba_write.c,v 1.3 2016/08/05 23:15:08 schwarze Exp $ */ +/* + * Copyright (c) 2016 Ingo Schwarze + * + * 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. + * + * Low-level functions for serializing allocation-based data to disk. + * The interface is defined in "dba_write.h". + */ +#include "config.h" + +#include +#if HAVE_ENDIAN +#include +#elif HAVE_SYS_ENDIAN +#include +#elif HAVE_NTOHL +#include +#endif +#if HAVE_ERR +#include +#endif +#include +#include +#include +#include + +#include "dba_write.h" + +static FILE *ofp; + + +int +dba_open(const char *fname) +{ + ofp = fopen(fname, "w"); + return ofp == NULL ? -1 : 0; +} + +int +dba_close(void) +{ + return fclose(ofp) == EOF ? -1 : 0; +} + +int32_t +dba_tell(void) +{ + long pos; + + if ((pos = ftell(ofp)) == -1) + err(1, "ftell"); + if (pos >= INT32_MAX) { + errno = EOVERFLOW; + err(1, "ftell = %ld", pos); + } + return pos; +} + +void +dba_seek(int32_t pos) +{ + if (fseek(ofp, pos, SEEK_SET) == -1) + err(1, "fseek(%d)", pos); +} + +int32_t +dba_align(void) +{ + int32_t pos; + + pos = dba_tell(); + while (pos & 3) { + dba_char_write('\0'); + pos++; + } + return pos; +} + +int32_t +dba_skip(int32_t nmemb, int32_t sz) +{ + const int32_t out[5] = {0, 0, 0, 0, 0}; + int32_t i, pos; + + assert(sz >= 0); + assert(nmemb > 0); + assert(nmemb <= 5); + pos = dba_tell(); + for (i = 0; i < sz; i++) + if (nmemb - fwrite(&out, sizeof(out[0]), nmemb, ofp)) + err(1, "fwrite"); + return pos; +} + +void +dba_char_write(int c) +{ + if (putc(c, ofp) == EOF) + err(1, "fputc"); +} + +void +dba_str_write(const char *str) +{ + if (fputs(str, ofp) == EOF) + err(1, "fputs"); + dba_char_write('\0'); +} + +void +dba_int_write(int32_t i) +{ + i = htobe32(i); + if (fwrite(&i, sizeof(i), 1, ofp) != 1) + err(1, "fwrite"); +} Property changes on: stable/11/contrib/mdocml/dba_write.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: stable/11/contrib/mdocml/dba_write.h =================================================================== --- stable/11/contrib/mdocml/dba_write.h (nonexistent) +++ stable/11/contrib/mdocml/dba_write.h (revision 316420) @@ -0,0 +1,30 @@ +/* $Id: dba_write.h,v 1.1 2016/07/19 21:31:55 schwarze Exp $ */ +/* + * Copyright (c) 2016 Ingo Schwarze + * + * 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. + * + * Internal interface to low-level functions + * for serializing allocation-based data to disk. + * For use by dba_array.c and dba.c only. + */ + +int dba_open(const char *); +int dba_close(void); +int32_t dba_tell(void); +void dba_seek(int32_t); +int32_t dba_align(void); +int32_t dba_skip(int32_t, int32_t); +void dba_char_write(int); +void dba_str_write(const char *); +void dba_int_write(int32_t); Property changes on: stable/11/contrib/mdocml/dba_write.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: stable/11/contrib/mdocml/dbm.c =================================================================== --- stable/11/contrib/mdocml/dbm.c (nonexistent) +++ stable/11/contrib/mdocml/dbm.c (revision 316420) @@ -0,0 +1,480 @@ +/* $Id: dbm.c,v 1.5 2016/10/18 22:27:25 schwarze Exp $ */ +/* + * Copyright (c) 2016 Ingo Schwarze + * + * 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. + * + * Map-based version of the mandoc database, for read-only access. + * The interface is defined in "dbm.h". + */ +#include "config.h" + +#include +#if HAVE_ENDIAN +#include +#elif HAVE_SYS_ENDIAN +#include +#elif HAVE_NTOHL +#include +#endif +#if HAVE_ERR +#include +#endif +#include +#include +#include +#include +#include +#include + +#include "mansearch.h" +#include "dbm_map.h" +#include "dbm.h" + +struct macro { + int32_t value; + int32_t pages; +}; + +struct page { + int32_t name; + int32_t sect; + int32_t arch; + int32_t desc; + int32_t file; +}; + +enum iter { + ITER_NONE = 0, + ITER_NAME, + ITER_SECT, + ITER_ARCH, + ITER_DESC, + ITER_MACRO +}; + +static struct macro *macros[MACRO_MAX]; +static int32_t nvals[MACRO_MAX]; +static struct page *pages; +static int32_t npages; +static enum iter iteration; + +static struct dbm_res page_bytitle(enum iter, const struct dbm_match *); +static struct dbm_res page_byarch(const struct dbm_match *); +static struct dbm_res page_bymacro(int32_t, const struct dbm_match *); +static char *macro_bypage(int32_t, int32_t); + + +/*** top level functions **********************************************/ + +/* + * Open a disk-based mandoc database for read-only access. + * Map the pages and macros[] arrays. + * Return 0 on success. Return -1 and set errno on failure. + */ +int +dbm_open(const char *fname) +{ + const int32_t *mp, *ep; + int32_t im; + + if (dbm_map(fname) == -1) + return -1; + + if ((npages = be32toh(*dbm_getint(4))) < 0) { + warnx("dbm_open(%s): Invalid number of pages: %d", + fname, npages); + goto fail; + } + pages = (struct page *)dbm_getint(5); + + if ((mp = dbm_get(*dbm_getint(2))) == NULL) { + warnx("dbm_open(%s): Invalid offset of macros array", fname); + goto fail; + } + if (be32toh(*mp) != MACRO_MAX) { + warnx("dbm_open(%s): Invalid number of macros: %d", + fname, be32toh(*mp)); + goto fail; + } + for (im = 0; im < MACRO_MAX; im++) { + if ((ep = dbm_get(*++mp)) == NULL) { + warnx("dbm_open(%s): Invalid offset of macro %d", + fname, im); + goto fail; + } + nvals[im] = be32toh(*ep); + macros[im] = (struct macro *)++ep; + } + return 0; + +fail: + dbm_unmap(); + errno = EFTYPE; + return -1; +} + +void +dbm_close(void) +{ + dbm_unmap(); +} + + +/*** functions for handling pages *************************************/ + +int32_t +dbm_page_count(void) +{ + return npages; +} + +/* + * Give the caller pointers to the data for one manual page. + */ +struct dbm_page * +dbm_page_get(int32_t ip) +{ + static struct dbm_page res; + + assert(ip >= 0); + assert(ip < npages); + res.name = dbm_get(pages[ip].name); + if (res.name == NULL) + res.name = "(NULL)"; + res.sect = dbm_get(pages[ip].sect); + if (res.sect == NULL) + res.sect = "(NULL)"; + res.arch = pages[ip].arch ? dbm_get(pages[ip].arch) : NULL; + res.desc = dbm_get(pages[ip].desc); + if (res.desc == NULL) + res.desc = "(NULL)"; + res.file = dbm_get(pages[ip].file); + if (res.file == NULL) + res.file = " (NULL)"; + res.addr = dbm_addr(pages + ip); + return &res; +} + +/* + * Functions to start filtered iterations over manual pages. + */ +void +dbm_page_byname(const struct dbm_match *match) +{ + assert(match != NULL); + page_bytitle(ITER_NAME, match); +} + +void +dbm_page_bysect(const struct dbm_match *match) +{ + assert(match != NULL); + page_bytitle(ITER_SECT, match); +} + +void +dbm_page_byarch(const struct dbm_match *match) +{ + assert(match != NULL); + page_byarch(match); +} + +void +dbm_page_bydesc(const struct dbm_match *match) +{ + assert(match != NULL); + page_bytitle(ITER_DESC, match); +} + +void +dbm_page_bymacro(int32_t im, const struct dbm_match *match) +{ + assert(im >= 0); + assert(im < MACRO_MAX); + assert(match != NULL); + page_bymacro(im, match); +} + +/* + * Return the number of the next manual page in the current iteration. + */ +struct dbm_res +dbm_page_next(void) +{ + struct dbm_res res = {-1, 0}; + + switch(iteration) { + case ITER_NONE: + return res; + case ITER_ARCH: + return page_byarch(NULL); + case ITER_MACRO: + return page_bymacro(0, NULL); + default: + return page_bytitle(iteration, NULL); + } +} + +/* + * Functions implementing the iteration over manual pages. + */ +static struct dbm_res +page_bytitle(enum iter arg_iter, const struct dbm_match *arg_match) +{ + static const struct dbm_match *match; + static const char *cp; + static int32_t ip; + struct dbm_res res = {-1, 0}; + + assert(arg_iter == ITER_NAME || arg_iter == ITER_DESC || + arg_iter == ITER_SECT); + + /* Initialize for a new iteration. */ + + if (arg_match != NULL) { + iteration = arg_iter; + match = arg_match; + switch (iteration) { + case ITER_NAME: + cp = dbm_get(pages[0].name); + break; + case ITER_SECT: + cp = dbm_get(pages[0].sect); + break; + case ITER_DESC: + cp = dbm_get(pages[0].desc); + break; + default: + abort(); + } + if (cp == NULL) { + iteration = ITER_NONE; + match = NULL; + cp = NULL; + ip = npages; + } else + ip = 0; + return res; + } + + /* Search for a name. */ + + while (ip < npages) { + if (iteration == ITER_NAME) + cp++; + if (dbm_match(match, cp)) + break; + cp = strchr(cp, '\0') + 1; + if (iteration == ITER_DESC) + ip++; + else if (*cp == '\0') { + cp++; + ip++; + } + } + + /* Reached the end without a match. */ + + if (ip == npages) { + iteration = ITER_NONE; + match = NULL; + cp = NULL; + return res; + } + + /* Found a match; save the quality for later retrieval. */ + + res.page = ip; + res.bits = iteration == ITER_NAME ? cp[-1] : 0; + + /* Skip the remaining names of this page. */ + + if (++ip < npages) { + do { + cp++; + } while (cp[-1] != '\0' || + (iteration != ITER_DESC && cp[-2] != '\0')); + } + return res; +} + +static struct dbm_res +page_byarch(const struct dbm_match *arg_match) +{ + static const struct dbm_match *match; + struct dbm_res res = {-1, 0}; + static int32_t ip; + const char *cp; + + /* Initialize for a new iteration. */ + + if (arg_match != NULL) { + iteration = ITER_ARCH; + match = arg_match; + ip = 0; + return res; + } + + /* Search for an architecture. */ + + for ( ; ip < npages; ip++) + if (pages[ip].arch) + for (cp = dbm_get(pages[ip].arch); + *cp != '\0'; + cp = strchr(cp, '\0') + 1) + if (dbm_match(match, cp)) { + res.page = ip++; + return res; + } + + /* Reached the end without a match. */ + + iteration = ITER_NONE; + match = NULL; + return res; +} + +static struct dbm_res +page_bymacro(int32_t arg_im, const struct dbm_match *arg_match) +{ + static const struct dbm_match *match; + static const int32_t *pp; + static const char *cp; + static int32_t im, iv; + struct dbm_res res = {-1, 0}; + + assert(im >= 0); + assert(im < MACRO_MAX); + + /* Initialize for a new iteration. */ + + if (arg_match != NULL) { + iteration = ITER_MACRO; + match = arg_match; + im = arg_im; + cp = nvals[im] ? dbm_get(macros[im]->value) : NULL; + pp = NULL; + iv = -1; + return res; + } + if (iteration != ITER_MACRO) + return res; + + /* Find the next matching macro value. */ + + while (pp == NULL || *pp == 0) { + if (++iv == nvals[im]) { + iteration = ITER_NONE; + return res; + } + if (iv) + cp = strchr(cp, '\0') + 1; + if (dbm_match(match, cp)) + pp = dbm_get(macros[im][iv].pages); + } + + /* Found a matching page. */ + + res.page = (struct page *)dbm_get(*pp++) - pages; + return res; +} + + +/*** functions for handling macros ************************************/ + +int32_t +dbm_macro_count(int32_t im) +{ + assert(im >= 0); + assert(im < MACRO_MAX); + return nvals[im]; +} + +struct dbm_macro * +dbm_macro_get(int32_t im, int32_t iv) +{ + static struct dbm_macro macro; + + assert(im >= 0); + assert(im < MACRO_MAX); + assert(iv >= 0); + assert(iv < nvals[im]); + macro.value = dbm_get(macros[im][iv].value); + macro.pp = dbm_get(macros[im][iv].pages); + return ¯o; +} + +/* + * Filtered iteration over macro entries. + */ +void +dbm_macro_bypage(int32_t im, int32_t ip) +{ + assert(im >= 0); + assert(im < MACRO_MAX); + assert(ip != 0); + macro_bypage(im, ip); +} + +char * +dbm_macro_next(void) +{ + return macro_bypage(MACRO_MAX, 0); +} + +static char * +macro_bypage(int32_t arg_im, int32_t arg_ip) +{ + static const int32_t *pp; + static int32_t im, ip, iv; + + /* Initialize for a new iteration. */ + + if (arg_im < MACRO_MAX && arg_ip != 0) { + im = arg_im; + ip = arg_ip; + pp = dbm_get(macros[im]->pages); + iv = 0; + return NULL; + } + if (im >= MACRO_MAX) + return NULL; + + /* Search for the next value. */ + + while (iv < nvals[im]) { + if (*pp == ip) + break; + if (*pp == 0) + iv++; + pp++; + } + + /* Reached the end without a match. */ + + if (iv == nvals[im]) { + im = MACRO_MAX; + ip = 0; + pp = NULL; + return NULL; + } + + /* Found a match; skip the remaining pages of this entry. */ + + if (++iv < nvals[im]) + while (*pp++ != 0) + continue; + + return dbm_get(macros[im][iv - 1].value); +} Property changes on: stable/11/contrib/mdocml/dbm.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: stable/11/contrib/mdocml/dbm.h =================================================================== --- stable/11/contrib/mdocml/dbm.h (nonexistent) +++ stable/11/contrib/mdocml/dbm.h (revision 316420) @@ -0,0 +1,68 @@ +/* $Id: dbm.h,v 1.1 2016/07/19 21:31:55 schwarze Exp $ */ +/* + * Copyright (c) 2016 Ingo Schwarze + * + * 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. + * + * Public interface for the map-based version + * of the mandoc database, for read-only access. + * To be used by dbm*.c, dba_read.c, and man(1) and apropos(1). + */ + +enum dbm_mtype { + DBM_EXACT = 0, + DBM_SUB, + DBM_REGEX +}; + +struct dbm_match { + regex_t *re; + const char *str; + enum dbm_mtype type; +}; + +struct dbm_res { + int32_t page; + int32_t bits; +}; + +struct dbm_page { + const char *name; + const char *sect; + const char *arch; + const char *desc; + const char *file; + int32_t addr; +}; + +struct dbm_macro { + const char *value; + const int32_t *pp; +}; + +int dbm_open(const char *); +void dbm_close(void); + +int32_t dbm_page_count(void); +struct dbm_page *dbm_page_get(int32_t); +void dbm_page_byname(const struct dbm_match *); +void dbm_page_bysect(const struct dbm_match *); +void dbm_page_byarch(const struct dbm_match *); +void dbm_page_bydesc(const struct dbm_match *); +void dbm_page_bymacro(int32_t, const struct dbm_match *); +struct dbm_res dbm_page_next(void); + +int32_t dbm_macro_count(int32_t); +struct dbm_macro *dbm_macro_get(int32_t, int32_t); +void dbm_macro_bypage(int32_t, int32_t); +char *dbm_macro_next(void); Property changes on: stable/11/contrib/mdocml/dbm.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: stable/11/contrib/mdocml/dbm_map.c =================================================================== --- stable/11/contrib/mdocml/dbm_map.c (nonexistent) +++ stable/11/contrib/mdocml/dbm_map.c (revision 316420) @@ -0,0 +1,194 @@ +/* $Id: dbm_map.c,v 1.7 2016/10/22 10:09:27 schwarze Exp $ */ +/* + * Copyright (c) 2016 Ingo Schwarze + * + * 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. + * + * Low-level routines for the map-based version + * of the mandoc database, for read-only access. + * The interface is defined in "dbm_map.h". + */ +#include "config.h" + +#include +#include +#include + +#if HAVE_ENDIAN +#include +#elif HAVE_SYS_ENDIAN +#include +#elif HAVE_NTOHL +#include +#endif +#if HAVE_ERR +#include +#endif +#include +#include +#include +#include +#include +#include +#include + +#include "mansearch.h" +#include "dbm_map.h" +#include "dbm.h" + +static struct stat st; +static char *dbm_base; +static int ifd; +static int32_t max_offset; + +/* + * Open a disk-based database for read-only access. + * Validate the file format as far as it is not mandoc-specific. + * Return 0 on success. Return -1 and set errno on failure. + */ +int +dbm_map(const char *fname) +{ + int save_errno; + const int32_t *magic; + + if ((ifd = open(fname, O_RDONLY)) == -1) + return -1; + if (fstat(ifd, &st) == -1) + goto fail; + if (st.st_size < 5) { + warnx("dbm_map(%s): File too short", fname); + errno = EFTYPE; + goto fail; + } + if (st.st_size > INT32_MAX) { + errno = EFBIG; + goto fail; + } + if ((dbm_base = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, + ifd, 0)) == MAP_FAILED) + goto fail; + magic = dbm_getint(0); + if (be32toh(*magic) != MANDOCDB_MAGIC) { + if (strncmp(dbm_base, "SQLite format 3", 15)) + warnx("dbm_map(%s): " + "Bad initial magic %x (expected %x)", + fname, be32toh(*magic), MANDOCDB_MAGIC); + else + warnx("dbm_map(%s): " + "Obsolete format based on SQLite 3", + fname); + errno = EFTYPE; + goto fail; + } + magic = dbm_getint(1); + if (be32toh(*magic) != MANDOCDB_VERSION) { + warnx("dbm_map(%s): Bad version number %d (expected %d)", + fname, be32toh(*magic), MANDOCDB_VERSION); + errno = EFTYPE; + goto fail; + } + max_offset = be32toh(*dbm_getint(3)) + sizeof(int32_t); + if (st.st_size != max_offset) { + warnx("dbm_map(%s): Inconsistent file size %lld (expected %d)", + fname, (long long)st.st_size, max_offset); + errno = EFTYPE; + goto fail; + } + if ((magic = dbm_get(*dbm_getint(3))) == NULL) { + errno = EFTYPE; + goto fail; + } + if (be32toh(*magic) != MANDOCDB_MAGIC) { + warnx("dbm_map(%s): Bad final magic %x (expected %x)", + fname, be32toh(*magic), MANDOCDB_MAGIC); + errno = EFTYPE; + goto fail; + } + return 0; + +fail: + save_errno = errno; + close(ifd); + errno = save_errno; + return -1; +} + +void +dbm_unmap(void) +{ + if (munmap(dbm_base, st.st_size) == -1) + warn("dbm_unmap: munmap"); + if (close(ifd) == -1) + warn("dbm_unmap: close"); + dbm_base = (char *)-1; +} + +/* + * Take a raw integer as it was read from the database. + * Interpret it as an offset into the database file + * and return a pointer to that place in the file. + */ +void * +dbm_get(int32_t offset) +{ + offset = be32toh(offset); + if (offset < 0) { + warnx("dbm_get: Database corrupt: offset %d", offset); + return NULL; + } + if (offset >= max_offset) { + warnx("dbm_get: Database corrupt: offset %d > %d", + offset, max_offset); + return NULL; + } + return dbm_base + offset; +} + +/* + * Assume the database starts with some integers. + * Assume they are numbered starting from 0, increasing. + * Get a pointer to one with the number "offset". + */ +int32_t * +dbm_getint(int32_t offset) +{ + return (int32_t *)dbm_base + offset; +} + +/* + * The reverse of dbm_get(). + * Take pointer into the database file + * and convert it to the raw integer + * that would be used to refer to that place in the file. + */ +int32_t +dbm_addr(const void *p) +{ + return htobe32((char *)p - dbm_base); +} + +int +dbm_match(const struct dbm_match *match, const char *str) +{ + switch (match->type) { + case DBM_EXACT: + return strcmp(str, match->str) == 0; + case DBM_SUB: + return strcasestr(str, match->str) != NULL; + case DBM_REGEX: + return regexec(match->re, str, 0, NULL, 0) == 0; + default: + abort(); + } +} Property changes on: stable/11/contrib/mdocml/dbm_map.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: stable/11/contrib/mdocml/dbm_map.h =================================================================== --- stable/11/contrib/mdocml/dbm_map.h (nonexistent) +++ stable/11/contrib/mdocml/dbm_map.h (revision 316420) @@ -0,0 +1,29 @@ +/* $Id: dbm_map.h,v 1.1 2016/07/19 21:31:55 schwarze Exp $ */ +/* + * Copyright (c) 2016 Ingo Schwarze + * + * 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. + * + * Private interface for low-level routines for the map-based version + * of the mandoc database, for read-only access. + * To be used by dbm*.c only. + */ + +struct dbm_match; + +int dbm_map(const char *); +void dbm_unmap(void); +void *dbm_get(int32_t); +int32_t *dbm_getint(int32_t); +int32_t dbm_addr(const void *); +int dbm_match(const struct dbm_match *, const char *); Property changes on: stable/11/contrib/mdocml/dbm_map.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: stable/11/contrib/mdocml/demandoc.c =================================================================== --- stable/11/contrib/mdocml/demandoc.c (revision 316419) +++ stable/11/contrib/mdocml/demandoc.c (revision 316420) @@ -1,263 +1,263 @@ -/* $Id: demandoc.c,v 1.27 2016/07/09 15:24:19 schwarze Exp $ */ +/* $Id: demandoc.c,v 1.28 2017/01/10 13:47:00 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * * 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 "config.h" #include #include #include #include #include #include #include #include "roff.h" #include "man.h" #include "mdoc.h" #include "mandoc.h" static void pline(int, int *, int *, int); static void pman(const struct roff_node *, int *, int *, int); static void pmandoc(struct mparse *, int, const char *, int); static void pmdoc(const struct roff_node *, int *, int *, int); static void pstring(const char *, int, int *, int); static void usage(void); static const char *progname; int main(int argc, char *argv[]) { struct mparse *mp; int ch, fd, i, list; extern int optind; if (argc < 1) progname = "demandoc"; else if ((progname = strrchr(argv[0], '/')) == NULL) progname = argv[0]; else ++progname; mp = NULL; list = 0; while (-1 != (ch = getopt(argc, argv, "ikm:pw"))) switch (ch) { case ('i'): /* FALLTHROUGH */ case ('k'): /* FALLTHROUGH */ case ('m'): /* FALLTHROUGH */ case ('p'): break; case ('w'): list = 1; break; default: usage(); return (int)MANDOCLEVEL_BADARG; } argc -= optind; argv += optind; mchars_alloc(); mp = mparse_alloc(MPARSE_SO, MANDOCLEVEL_BADARG, NULL, NULL); assert(mp); if (argc < 1) pmandoc(mp, STDIN_FILENO, "", list); for (i = 0; i < argc; i++) { mparse_reset(mp); if ((fd = mparse_open(mp, argv[i])) == -1) { perror(argv[i]); continue; } pmandoc(mp, fd, argv[i], list); } mparse_free(mp); mchars_free(); return (int)MANDOCLEVEL_OK; } static void usage(void) { fprintf(stderr, "usage: %s [-w] [files...]\n", progname); } static void pmandoc(struct mparse *mp, int fd, const char *fn, int list) { struct roff_man *man; int line, col; mparse_readfd(mp, fd, fn); close(fd); mparse_result(mp, &man, NULL); line = 1; col = 0; if (man == NULL) return; if (man->macroset == MACROSET_MDOC) { mdoc_validate(man); pmdoc(man->first->child, &line, &col, list); } else { man_validate(man); pman(man->first->child, &line, &col, list); } if ( ! list) putchar('\n'); } /* * Strip the escapes out of a string, emitting the results. */ static void pstring(const char *p, int col, int *colp, int list) { enum mandoc_esc esc; const char *start, *end; int emit; /* * Print as many column spaces til we achieve parity with the * input document. */ again: if (list && '\0' != *p) { while (isspace((unsigned char)*p)) p++; while ('\'' == *p || '(' == *p || '"' == *p) p++; emit = isalpha((unsigned char)p[0]) && isalpha((unsigned char)p[1]); for (start = p; '\0' != *p; p++) if ('\\' == *p) { p++; esc = mandoc_escape(&p, NULL, NULL); if (ESCAPE_ERROR == esc) return; emit = 0; } else if (isspace((unsigned char)*p)) break; end = p - 1; while (end > start) if ('.' == *end || ',' == *end || '\'' == *end || '"' == *end || ')' == *end || '!' == *end || '?' == *end || ':' == *end || ';' == *end) end--; else break; if (emit && end - start >= 1) { for ( ; start <= end; start++) if (ASCII_HYPH == *start) putchar('-'); else putchar((unsigned char)*start); putchar('\n'); } if (isspace((unsigned char)*p)) goto again; return; } while (*colp < col) { putchar(' '); (*colp)++; } /* * Print the input word, skipping any special characters. */ while ('\0' != *p) if ('\\' == *p) { p++; esc = mandoc_escape(&p, NULL, NULL); if (ESCAPE_ERROR == esc) break; } else { putchar((unsigned char )*p++); (*colp)++; } } static void pline(int line, int *linep, int *col, int list) { if (list) return; /* * Print out as many lines as needed to reach parity with the * original input. */ while (*linep < line) { putchar('\n'); (*linep)++; } *col = 0; } static void pmdoc(const struct roff_node *p, int *line, int *col, int list) { for ( ; p; p = p->next) { - if (MDOC_LINE & p->flags) + if (NODE_LINE & p->flags) pline(p->line, line, col, list); if (ROFFT_TEXT == p->type) pstring(p->string, p->pos, col, list); if (p->child) pmdoc(p->child, line, col, list); } } static void pman(const struct roff_node *p, int *line, int *col, int list) { for ( ; p; p = p->next) { - if (MAN_LINE & p->flags) + if (NODE_LINE & p->flags) pline(p->line, line, col, list); if (ROFFT_TEXT == p->type) pstring(p->string, p->pos, col, list); if (p->child) pman(p->child, line, col, list); } } Index: stable/11/contrib/mdocml/eqn_html.c =================================================================== --- stable/11/contrib/mdocml/eqn_html.c (revision 316419) +++ stable/11/contrib/mdocml/eqn_html.c (revision 316420) @@ -1,192 +1,186 @@ -/* $Id: eqn_html.c,v 1.10 2014/10/12 19:31:41 schwarze Exp $ */ +/* $Id: eqn_html.c,v 1.11 2017/01/17 01:47:51 schwarze Exp $ */ /* * Copyright (c) 2011, 2014 Kristaps Dzonsons + * Copyright (c) 2017 Ingo Schwarze * * 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 "config.h" #include #include #include #include #include #include "mandoc.h" #include "out.h" #include "html.h" static void eqn_box(struct html *p, const struct eqn_box *bp) { struct tag *post, *row, *cell, *t; - struct htmlpair tag[2]; const struct eqn_box *child, *parent; size_t i, j, rows; if (NULL == bp) return; post = NULL; /* * Special handling for a matrix, which is presented to us in * column order, but must be printed in row-order. */ if (EQN_MATRIX == bp->type) { if (NULL == bp->first) goto out; if (EQN_LIST != bp->first->type) { eqn_box(p, bp->first); goto out; } if (NULL == (parent = bp->first->first)) goto out; /* Estimate the number of rows, first. */ if (NULL == (child = parent->first)) goto out; for (rows = 0; NULL != child; rows++) child = child->next; /* Print row-by-row. */ - post = print_otag(p, TAG_MTABLE, 0, NULL); + post = print_otag(p, TAG_MTABLE, ""); for (i = 0; i < rows; i++) { parent = bp->first->first; - row = print_otag(p, TAG_MTR, 0, NULL); + row = print_otag(p, TAG_MTR, ""); while (NULL != parent) { child = parent->first; for (j = 0; j < i; j++) { if (NULL == child) break; child = child->next; } - cell = print_otag - (p, TAG_MTD, 0, NULL); + cell = print_otag(p, TAG_MTD, ""); /* * If we have no data for this * particular cell, then print a * placeholder and continue--don't puke. */ if (NULL != child) eqn_box(p, child->first); print_tagq(p, cell); parent = parent->next; } print_tagq(p, row); } goto out; } switch (bp->pos) { case (EQNPOS_TO): - post = print_otag(p, TAG_MOVER, 0, NULL); + post = print_otag(p, TAG_MOVER, ""); break; case (EQNPOS_SUP): - post = print_otag(p, TAG_MSUP, 0, NULL); + post = print_otag(p, TAG_MSUP, ""); break; case (EQNPOS_FROM): - post = print_otag(p, TAG_MUNDER, 0, NULL); + post = print_otag(p, TAG_MUNDER, ""); break; case (EQNPOS_SUB): - post = print_otag(p, TAG_MSUB, 0, NULL); + post = print_otag(p, TAG_MSUB, ""); break; case (EQNPOS_OVER): - post = print_otag(p, TAG_MFRAC, 0, NULL); + post = print_otag(p, TAG_MFRAC, ""); break; case (EQNPOS_FROMTO): - post = print_otag(p, TAG_MUNDEROVER, 0, NULL); + post = print_otag(p, TAG_MUNDEROVER, ""); break; case (EQNPOS_SUBSUP): - post = print_otag(p, TAG_MSUBSUP, 0, NULL); + post = print_otag(p, TAG_MSUBSUP, ""); break; case (EQNPOS_SQRT): - post = print_otag(p, TAG_MSQRT, 0, NULL); + post = print_otag(p, TAG_MSQRT, ""); break; default: break; } if (bp->top || bp->bottom) { assert(NULL == post); if (bp->top && NULL == bp->bottom) - post = print_otag(p, TAG_MOVER, 0, NULL); + post = print_otag(p, TAG_MOVER, ""); else if (bp->top && bp->bottom) - post = print_otag(p, TAG_MUNDEROVER, 0, NULL); + post = print_otag(p, TAG_MUNDEROVER, ""); else if (bp->bottom) - post = print_otag(p, TAG_MUNDER, 0, NULL); + post = print_otag(p, TAG_MUNDER, ""); } if (EQN_PILE == bp->type) { assert(NULL == post); if (bp->first != NULL && bp->first->type == EQN_LIST) - post = print_otag(p, TAG_MTABLE, 0, NULL); + post = print_otag(p, TAG_MTABLE, ""); } else if (bp->type == EQN_LIST && bp->parent && bp->parent->type == EQN_PILE) { assert(NULL == post); - post = print_otag(p, TAG_MTR, 0, NULL); - print_otag(p, TAG_MTD, 0, NULL); + post = print_otag(p, TAG_MTR, ""); + print_otag(p, TAG_MTD, ""); } if (NULL != bp->text) { assert(NULL == post); - post = print_otag(p, TAG_MI, 0, NULL); + post = print_otag(p, TAG_MI, ""); print_text(p, bp->text); } else if (NULL == post) { - if (NULL != bp->left || NULL != bp->right) { - PAIR_INIT(&tag[0], ATTR_OPEN, - NULL == bp->left ? "" : bp->left); - PAIR_INIT(&tag[1], ATTR_CLOSE, - NULL == bp->right ? "" : bp->right); - post = print_otag(p, TAG_MFENCED, 2, tag); - } + if (NULL != bp->left || NULL != bp->right) + post = print_otag(p, TAG_MFENCED, "??", + "open", bp->left == NULL ? "" : bp->left, + "close", bp->right == NULL ? "" : bp->right); if (NULL == post) - post = print_otag(p, TAG_MROW, 0, NULL); + post = print_otag(p, TAG_MROW, ""); else - print_otag(p, TAG_MROW, 0, NULL); + print_otag(p, TAG_MROW, ""); } eqn_box(p, bp->first); out: if (NULL != bp->bottom) { - t = print_otag(p, TAG_MO, 0, NULL); + t = print_otag(p, TAG_MO, ""); print_text(p, bp->bottom); print_tagq(p, t); } if (NULL != bp->top) { - t = print_otag(p, TAG_MO, 0, NULL); + t = print_otag(p, TAG_MO, ""); print_text(p, bp->top); print_tagq(p, t); } if (NULL != post) print_tagq(p, post); eqn_box(p, bp->next); } void print_eqn(struct html *p, const struct eqn *ep) { - struct htmlpair tag; struct tag *t; - PAIR_CLASS_INIT(&tag, "eqn"); - t = print_otag(p, TAG_MATH, 1, &tag); + t = print_otag(p, TAG_MATH, "c", "eqn"); p->flags |= HTML_NONOSPACE; eqn_box(p, ep->root); p->flags &= ~HTML_NONOSPACE; print_tagq(p, t); } Index: stable/11/contrib/mdocml/html.c =================================================================== --- stable/11/contrib/mdocml/html.c (revision 316419) +++ stable/11/contrib/mdocml/html.c (revision 316420) @@ -1,727 +1,898 @@ -/* $Id: html.c,v 1.192 2016/01/04 12:45:29 schwarze Exp $ */ +/* $Id: html.c,v 1.200 2017/01/21 02:29:57 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons - * Copyright (c) 2011-2015 Ingo Schwarze + * Copyright (c) 2011-2015, 2017 Ingo Schwarze * * 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 AUTHORS DISCLAIM ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h" #include #include #include #include #include #include #include #include #include #include "mandoc.h" #include "mandoc_aux.h" #include "out.h" #include "html.h" #include "manconf.h" #include "main.h" struct htmldata { const char *name; int flags; -#define HTML_CLRLINE (1 << 0) -#define HTML_NOSTACK (1 << 1) -#define HTML_AUTOCLOSE (1 << 2) /* Tag has auto-closure. */ +#define HTML_NOSTACK (1 << 0) +#define HTML_AUTOCLOSE (1 << 1) +#define HTML_NLBEFORE (1 << 2) +#define HTML_NLBEGIN (1 << 3) +#define HTML_NLEND (1 << 4) +#define HTML_NLAFTER (1 << 5) +#define HTML_NLAROUND (HTML_NLBEFORE | HTML_NLAFTER) +#define HTML_NLINSIDE (HTML_NLBEGIN | HTML_NLEND) +#define HTML_NLALL (HTML_NLAROUND | HTML_NLINSIDE) +#define HTML_INDENT (1 << 6) +#define HTML_NOINDENT (1 << 7) }; static const struct htmldata htmltags[TAG_MAX] = { - {"html", HTML_CLRLINE}, /* TAG_HTML */ - {"head", HTML_CLRLINE}, /* TAG_HEAD */ - {"body", HTML_CLRLINE}, /* TAG_BODY */ - {"meta", HTML_CLRLINE | HTML_NOSTACK | HTML_AUTOCLOSE}, /* TAG_META */ - {"title", HTML_CLRLINE}, /* TAG_TITLE */ - {"div", HTML_CLRLINE}, /* TAG_DIV */ - {"h1", 0}, /* TAG_H1 */ - {"h2", 0}, /* TAG_H2 */ - {"span", 0}, /* TAG_SPAN */ - {"link", HTML_CLRLINE | HTML_NOSTACK | HTML_AUTOCLOSE}, /* TAG_LINK */ - {"br", HTML_CLRLINE | HTML_NOSTACK | HTML_AUTOCLOSE}, /* TAG_BR */ - {"a", 0}, /* TAG_A */ - {"table", HTML_CLRLINE}, /* TAG_TABLE */ - {"tbody", HTML_CLRLINE}, /* TAG_TBODY */ - {"col", HTML_CLRLINE | HTML_NOSTACK | HTML_AUTOCLOSE}, /* TAG_COL */ - {"tr", HTML_CLRLINE}, /* TAG_TR */ - {"td", HTML_CLRLINE}, /* TAG_TD */ - {"li", HTML_CLRLINE}, /* TAG_LI */ - {"ul", HTML_CLRLINE}, /* TAG_UL */ - {"ol", HTML_CLRLINE}, /* TAG_OL */ - {"dl", HTML_CLRLINE}, /* TAG_DL */ - {"dt", HTML_CLRLINE}, /* TAG_DT */ - {"dd", HTML_CLRLINE}, /* TAG_DD */ - {"blockquote", HTML_CLRLINE}, /* TAG_BLOCKQUOTE */ - {"pre", HTML_CLRLINE }, /* TAG_PRE */ - {"b", 0 }, /* TAG_B */ - {"i", 0 }, /* TAG_I */ - {"code", 0 }, /* TAG_CODE */ - {"small", 0 }, /* TAG_SMALL */ - {"style", HTML_CLRLINE}, /* TAG_STYLE */ - {"math", HTML_CLRLINE}, /* TAG_MATH */ - {"mrow", 0}, /* TAG_MROW */ - {"mi", 0}, /* TAG_MI */ - {"mo", 0}, /* TAG_MO */ - {"msup", 0}, /* TAG_MSUP */ - {"msub", 0}, /* TAG_MSUB */ - {"msubsup", 0}, /* TAG_MSUBSUP */ - {"mfrac", 0}, /* TAG_MFRAC */ - {"msqrt", 0}, /* TAG_MSQRT */ - {"mfenced", 0}, /* TAG_MFENCED */ - {"mtable", 0}, /* TAG_MTABLE */ - {"mtr", 0}, /* TAG_MTR */ - {"mtd", 0}, /* TAG_MTD */ - {"munderover", 0}, /* TAG_MUNDEROVER */ - {"munder", 0}, /* TAG_MUNDER*/ - {"mover", 0}, /* TAG_MOVER*/ + {"html", HTML_NLALL}, + {"head", HTML_NLALL | HTML_INDENT}, + {"body", HTML_NLALL}, + {"meta", HTML_NOSTACK | HTML_AUTOCLOSE | HTML_NLALL}, + {"title", HTML_NLAROUND}, + {"div", HTML_NLAROUND}, + {"h1", HTML_NLAROUND}, + {"h2", HTML_NLAROUND}, + {"span", 0}, + {"link", HTML_NOSTACK | HTML_AUTOCLOSE | HTML_NLALL}, + {"br", HTML_NOSTACK | HTML_AUTOCLOSE | HTML_NLALL}, + {"a", 0}, + {"table", HTML_NLALL | HTML_INDENT}, + {"tbody", HTML_NLALL | HTML_INDENT}, + {"col", HTML_NOSTACK | HTML_AUTOCLOSE | HTML_NLALL}, + {"tr", HTML_NLALL | HTML_INDENT}, + {"td", HTML_NLAROUND}, + {"li", HTML_NLAROUND | HTML_INDENT}, + {"ul", HTML_NLALL | HTML_INDENT}, + {"ol", HTML_NLALL | HTML_INDENT}, + {"dl", HTML_NLALL | HTML_INDENT}, + {"dt", HTML_NLAROUND}, + {"dd", HTML_NLAROUND | HTML_INDENT}, + {"pre", HTML_NLALL | HTML_NOINDENT}, + {"b", 0}, + {"i", 0}, + {"code", 0}, + {"small", 0}, + {"style", HTML_NLALL | HTML_INDENT}, + {"math", HTML_NLALL | HTML_INDENT}, + {"mrow", 0}, + {"mi", 0}, + {"mo", 0}, + {"msup", 0}, + {"msub", 0}, + {"msubsup", 0}, + {"mfrac", 0}, + {"msqrt", 0}, + {"mfenced", 0}, + {"mtable", 0}, + {"mtr", 0}, + {"mtd", 0}, + {"munderover", 0}, + {"munder", 0}, + {"mover", 0}, }; -static const char *const htmlattrs[ATTR_MAX] = { - "name", /* ATTR_NAME */ - "rel", /* ATTR_REL */ - "href", /* ATTR_HREF */ - "type", /* ATTR_TYPE */ - "media", /* ATTR_MEDIA */ - "class", /* ATTR_CLASS */ - "style", /* ATTR_STYLE */ - "id", /* ATTR_ID */ - "colspan", /* ATTR_COLSPAN */ - "charset", /* ATTR_CHARSET */ - "open", /* ATTR_OPEN */ - "close", /* ATTR_CLOSE */ - "mathvariant", /* ATTR_MATHVARIANT */ -}; - static const char *const roffscales[SCALE_MAX] = { "cm", /* SCALE_CM */ "in", /* SCALE_IN */ "pc", /* SCALE_PC */ "pt", /* SCALE_PT */ "em", /* SCALE_EM */ "em", /* SCALE_MM */ "ex", /* SCALE_EN */ "ex", /* SCALE_BU */ "em", /* SCALE_VS */ "ex", /* SCALE_FS */ }; -static void bufncat(struct html *, const char *, size_t); +static void a2width(const char *, struct roffsu *); +static void print_byte(struct html *, char); +static void print_endline(struct html *); +static void print_endword(struct html *); +static void print_indent(struct html *); +static void print_word(struct html *, const char *); + static void print_ctag(struct html *, struct tag *); -static int print_escape(char); -static int print_encode(struct html *, const char *, int); +static int print_escape(struct html *, char); +static int print_encode(struct html *, const char *, const char *, int); +static void print_href(struct html *, const char *, const char *, int); static void print_metaf(struct html *, enum mandoc_esc); -static void print_attr(struct html *, const char *, const char *); void * html_alloc(const struct manoutput *outopts) { struct html *h; h = mandoc_calloc(1, sizeof(struct html)); h->tags.head = NULL; h->style = outopts->style; h->base_man = outopts->man; h->base_includes = outopts->includes; if (outopts->fragment) h->oflags |= HTML_FRAGMENT; return h; } void html_free(void *p) { struct tag *tag; struct html *h; h = (struct html *)p; while ((tag = h->tags.head) != NULL) { h->tags.head = tag->next; free(tag); } free(h); } void print_gen_head(struct html *h) { - struct htmlpair tag[4]; struct tag *t; - tag[0].key = ATTR_CHARSET; - tag[0].val = "utf-8"; - print_otag(h, TAG_META, 1, tag); + print_otag(h, TAG_META, "?", "charset", "utf-8"); /* * Print a default style-sheet. */ - t = print_otag(h, TAG_STYLE, 0, NULL); - print_text(h, "table.head, table.foot { width: 100%; }\n" - "td.head-rtitle, td.foot-os { text-align: right; }\n" - "td.head-vol { text-align: center; }\n" - "table.foot td { width: 50%; }\n" - "table.head td { width: 33%; }\n" - "div.spacer { margin: 1em 0; }\n"); + + t = print_otag(h, TAG_STYLE, ""); + print_text(h, "table.head, table.foot { width: 100%; }"); + print_endline(h); + print_text(h, "td.head-rtitle, td.foot-os { text-align: right; }"); + print_endline(h); + print_text(h, "td.head-vol { text-align: center; }"); + print_endline(h); + print_text(h, "div.Pp { margin: 1ex 0ex; }"); print_tagq(h, t); - if (h->style) { - tag[0].key = ATTR_REL; - tag[0].val = "stylesheet"; - tag[1].key = ATTR_HREF; - tag[1].val = h->style; - tag[2].key = ATTR_TYPE; - tag[2].val = "text/css"; - tag[3].key = ATTR_MEDIA; - tag[3].val = "all"; - print_otag(h, TAG_LINK, 4, tag); - } + if (h->style) + print_otag(h, TAG_LINK, "?h??", "rel", "stylesheet", + h->style, "type", "text/css", "media", "all"); } static void print_metaf(struct html *h, enum mandoc_esc deco) { enum htmlfont font; switch (deco) { case ESCAPE_FONTPREV: font = h->metal; break; case ESCAPE_FONTITALIC: font = HTMLFONT_ITALIC; break; case ESCAPE_FONTBOLD: font = HTMLFONT_BOLD; break; case ESCAPE_FONTBI: font = HTMLFONT_BI; break; case ESCAPE_FONT: case ESCAPE_FONTROMAN: font = HTMLFONT_NONE; break; default: abort(); } if (h->metaf) { print_tagq(h, h->metaf); h->metaf = NULL; } h->metal = h->metac; h->metac = font; switch (font) { case HTMLFONT_ITALIC: - h->metaf = print_otag(h, TAG_I, 0, NULL); + h->metaf = print_otag(h, TAG_I, ""); break; case HTMLFONT_BOLD: - h->metaf = print_otag(h, TAG_B, 0, NULL); + h->metaf = print_otag(h, TAG_B, ""); break; case HTMLFONT_BI: - h->metaf = print_otag(h, TAG_B, 0, NULL); - print_otag(h, TAG_I, 0, NULL); + h->metaf = print_otag(h, TAG_B, ""); + print_otag(h, TAG_I, ""); break; default: break; } } int html_strlen(const char *cp) { size_t rsz; int skip, sz; /* * Account for escaped sequences within string length * calculations. This follows the logic in term_strlen() as we * must calculate the width of produced strings. * Assume that characters are always width of "1". This is * hacky, but it gets the job done for approximation of widths. */ sz = 0; skip = 0; while (1) { rsz = strcspn(cp, "\\"); if (rsz) { cp += rsz; if (skip) { skip = 0; rsz--; } sz += rsz; } if ('\0' == *cp) break; cp++; switch (mandoc_escape(&cp, NULL, NULL)) { case ESCAPE_ERROR: return sz; case ESCAPE_UNICODE: case ESCAPE_NUMBERED: case ESCAPE_SPECIAL: case ESCAPE_OVERSTRIKE: if (skip) skip = 0; else sz++; break; case ESCAPE_SKIPCHAR: skip = 1; break; default: break; } } return sz; } static int -print_escape(char c) +print_escape(struct html *h, char c) { switch (c) { case '<': - printf("<"); + print_word(h, "<"); break; case '>': - printf(">"); + print_word(h, ">"); break; case '&': - printf("&"); + print_word(h, "&"); break; case '"': - printf("""); + print_word(h, """); break; case ASCII_NBRSP: - printf(" "); + print_word(h, " "); break; case ASCII_HYPH: - putchar('-'); + print_byte(h, '-'); break; case ASCII_BREAK: break; default: return 0; } return 1; } static int -print_encode(struct html *h, const char *p, int norecurse) +print_encode(struct html *h, const char *p, const char *pend, int norecurse) { + char numbuf[16]; size_t sz; int c, len, nospace; const char *seq; enum mandoc_esc esc; static const char rejs[9] = { '\\', '<', '>', '&', '"', ASCII_NBRSP, ASCII_HYPH, ASCII_BREAK, '\0' }; + if (pend == NULL) + pend = strchr(p, '\0'); + nospace = 0; - while ('\0' != *p) { + while (p < pend) { if (HTML_SKIPCHAR & h->flags && '\\' != *p) { h->flags &= ~HTML_SKIPCHAR; p++; continue; } - sz = strcspn(p, rejs); + for (sz = strcspn(p, rejs); sz-- && p < pend; p++) + if (*p == ' ') + print_endword(h); + else + print_byte(h, *p); - fwrite(p, 1, sz, stdout); - p += (int)sz; - - if ('\0' == *p) + if (p >= pend) break; - if (print_escape(*p++)) + if (print_escape(h, *p++)) continue; esc = mandoc_escape(&p, &seq, &len); if (ESCAPE_ERROR == esc) break; switch (esc) { case ESCAPE_FONT: case ESCAPE_FONTPREV: case ESCAPE_FONTBOLD: case ESCAPE_FONTITALIC: case ESCAPE_FONTBI: case ESCAPE_FONTROMAN: if (0 == norecurse) print_metaf(h, esc); continue; case ESCAPE_SKIPCHAR: h->flags |= HTML_SKIPCHAR; continue; default: break; } if (h->flags & HTML_SKIPCHAR) { h->flags &= ~HTML_SKIPCHAR; continue; } switch (esc) { case ESCAPE_UNICODE: /* Skip past "u" header. */ c = mchars_num2uc(seq + 1, len - 1); break; case ESCAPE_NUMBERED: c = mchars_num2char(seq, len); if (c < 0) continue; break; case ESCAPE_SPECIAL: c = mchars_spec2cp(seq, len); if (c <= 0) continue; break; case ESCAPE_NOSPACE: if ('\0' == *p) nospace = 1; continue; case ESCAPE_OVERSTRIKE: if (len == 0) continue; c = seq[len - 1]; break; default: continue; } if ((c < 0x20 && c != 0x09) || (c > 0x7E && c < 0xA0)) c = 0xFFFD; - if (c > 0x7E) - printf("&#%d;", c); - else if ( ! print_escape(c)) - putchar(c); + if (c > 0x7E) { + (void)snprintf(numbuf, sizeof(numbuf), "&#%d;", c); + print_word(h, numbuf); + } else if (print_escape(h, c) == 0) + print_byte(h, c); } return nospace; } static void -print_attr(struct html *h, const char *key, const char *val) +print_href(struct html *h, const char *name, const char *sec, int man) { - printf(" %s=\"", key); - (void)print_encode(h, val, 1); - putchar('\"'); + const char *p, *pp; + + pp = man ? h->base_man : h->base_includes; + while ((p = strchr(pp, '%')) != NULL) { + print_encode(h, pp, p, 1); + if (man && p[1] == 'S') { + if (sec == NULL) + print_byte(h, '1'); + else + print_encode(h, sec, NULL, 1); + } else if ((man && p[1] == 'N') || + (man == 0 && p[1] == 'I')) + print_encode(h, name, NULL, 1); + else + print_encode(h, p, p + 2, 1); + pp = p + 2; + } + if (*pp != '\0') + print_encode(h, pp, NULL, 1); } struct tag * -print_otag(struct html *h, enum htmltag tag, - int sz, const struct htmlpair *p) +print_otag(struct html *h, enum htmltag tag, const char *fmt, ...) { - int i; + va_list ap; + struct roffsu mysu, *su; + char numbuf[16]; struct tag *t; + const char *attr; + char *s; + double v; + int i, have_style, tflags; + tflags = htmltags[tag].flags; + /* Push this tags onto the stack of open scopes. */ - if ( ! (HTML_NOSTACK & htmltags[tag].flags)) { + if ((tflags & HTML_NOSTACK) == 0) { t = mandoc_malloc(sizeof(struct tag)); t->tag = tag; t->next = h->tags.head; h->tags.head = t; } else t = NULL; - if ( ! (HTML_NOSPACE & h->flags)) - if ( ! (HTML_CLRLINE & htmltags[tag].flags)) { - /* Manage keeps! */ - if ( ! (HTML_KEEP & h->flags)) { - if (HTML_PREKEEP & h->flags) - h->flags |= HTML_KEEP; - putchar(' '); - } else - printf(" "); + if (tflags & HTML_NLBEFORE) + print_endline(h); + if (h->col == 0) + print_indent(h); + else if ((h->flags & HTML_NOSPACE) == 0) { + if (h->flags & HTML_KEEP) + print_word(h, " "); + else { + if (h->flags & HTML_PREKEEP) + h->flags |= HTML_KEEP; + print_endword(h); } + } if ( ! (h->flags & HTML_NONOSPACE)) h->flags &= ~HTML_NOSPACE; else h->flags |= HTML_NOSPACE; /* Print out the tag name and attributes. */ - printf("<%s", htmltags[tag].name); - for (i = 0; i < sz; i++) - print_attr(h, htmlattrs[p[i].key], p[i].val); + print_byte(h, '<'); + print_word(h, htmltags[tag].name); + va_start(ap, fmt); + + have_style = 0; + while (*fmt != '\0') { + if (*fmt == 's') { + print_word(h, " style=\""); + have_style = 1; + fmt++; + break; + } + s = va_arg(ap, char *); + switch (*fmt++) { + case 'c': + attr = "class"; + break; + case 'h': + attr = "href"; + break; + case 'i': + attr = "id"; + break; + case '?': + attr = s; + s = va_arg(ap, char *); + break; + default: + abort(); + } + print_byte(h, ' '); + print_word(h, attr); + print_byte(h, '='); + print_byte(h, '"'); + switch (*fmt) { + case 'M': + print_href(h, s, va_arg(ap, char *), 1); + fmt++; + break; + case 'I': + print_href(h, s, NULL, 0); + fmt++; + break; + case 'R': + print_byte(h, '#'); + fmt++; + /* FALLTHROUGH */ + default: + print_encode(h, s, NULL, 1); + break; + } + print_byte(h, '"'); + } + + /* Print out styles. */ + + s = NULL; + su = &mysu; + while (*fmt != '\0') { + + /* First letter: input argument type. */ + + switch (*fmt++) { + case 'h': + i = va_arg(ap, int); + SCALE_HS_INIT(su, i); + break; + case 's': + s = va_arg(ap, char *); + break; + case 'u': + su = va_arg(ap, struct roffsu *); + break; + case 'v': + i = va_arg(ap, int); + SCALE_VS_INIT(su, i); + break; + case 'w': + s = va_arg(ap, char *); + a2width(s, su); + break; + default: + abort(); + } + + /* Second letter: style name. */ + + switch (*fmt++) { + case 'b': + attr = "margin-bottom"; + break; + case 'h': + attr = "height"; + break; + case 'i': + attr = "text-indent"; + break; + case 'l': + attr = "margin-left"; + break; + case 't': + attr = "margin-top"; + break; + case 'w': + attr = "width"; + break; + case 'W': + attr = "min-width"; + break; + case '?': + print_word(h, s); + print_byte(h, ':'); + print_byte(h, ' '); + print_word(h, va_arg(ap, char *)); + print_byte(h, ';'); + if (*fmt != '\0') + print_byte(h, ' '); + continue; + default: + abort(); + } + v = su->scale; + if (su->unit == SCALE_MM && (v /= 100.0) == 0.0) + v = 1.0; + else if (su->unit == SCALE_BU) + v /= 24.0; + print_word(h, attr); + print_byte(h, ':'); + print_byte(h, ' '); + (void)snprintf(numbuf, sizeof(numbuf), "%.2f", v); + print_word(h, numbuf); + print_word(h, roffscales[su->unit]); + print_byte(h, ';'); + if (*fmt != '\0') + print_byte(h, ' '); + } + if (have_style) + print_byte(h, '"'); + + va_end(ap); + /* Accommodate for "well-formed" singleton escaping. */ if (HTML_AUTOCLOSE & htmltags[tag].flags) - putchar('/'); + print_byte(h, '/'); - putchar('>'); + print_byte(h, '>'); - h->flags |= HTML_NOSPACE; + if (tflags & HTML_NLBEGIN) + print_endline(h); + else + h->flags |= HTML_NOSPACE; - if ((HTML_AUTOCLOSE | HTML_CLRLINE) & htmltags[tag].flags) - putchar('\n'); + if (tflags & HTML_INDENT) + h->indent++; + if (tflags & HTML_NOINDENT) + h->noindent++; return t; } static void print_ctag(struct html *h, struct tag *tag) { + int tflags; /* * Remember to close out and nullify the current * meta-font and table, if applicable. */ if (tag == h->metaf) h->metaf = NULL; if (tag == h->tblt) h->tblt = NULL; - printf("", htmltags[tag->tag].name); - if (HTML_CLRLINE & htmltags[tag->tag].flags) { - h->flags |= HTML_NOSPACE; - putchar('\n'); - } + tflags = htmltags[tag->tag].flags; + if (tflags & HTML_INDENT) + h->indent--; + if (tflags & HTML_NOINDENT) + h->noindent--; + if (tflags & HTML_NLEND) + print_endline(h); + print_indent(h); + print_byte(h, '<'); + print_byte(h, '/'); + print_word(h, htmltags[tag->tag].name); + print_byte(h, '>'); + if (tflags & HTML_NLAFTER) + print_endline(h); + h->tags.head = tag->next; free(tag); } void print_gen_decls(struct html *h) { - - puts(""); + print_word(h, ""); + print_endline(h); } void print_text(struct html *h, const char *word) { - - if ( ! (HTML_NOSPACE & h->flags)) { - /* Manage keeps! */ + if (h->col && (h->flags & HTML_NOSPACE) == 0) { if ( ! (HTML_KEEP & h->flags)) { if (HTML_PREKEEP & h->flags) h->flags |= HTML_KEEP; - putchar(' '); + print_endword(h); } else - printf(" "); + print_word(h, " "); } assert(NULL == h->metaf); switch (h->metac) { case HTMLFONT_ITALIC: - h->metaf = print_otag(h, TAG_I, 0, NULL); + h->metaf = print_otag(h, TAG_I, ""); break; case HTMLFONT_BOLD: - h->metaf = print_otag(h, TAG_B, 0, NULL); + h->metaf = print_otag(h, TAG_B, ""); break; case HTMLFONT_BI: - h->metaf = print_otag(h, TAG_B, 0, NULL); - print_otag(h, TAG_I, 0, NULL); + h->metaf = print_otag(h, TAG_B, ""); + print_otag(h, TAG_I, ""); break; default: + print_indent(h); break; } assert(word); - if ( ! print_encode(h, word, 0)) { + if ( ! print_encode(h, word, NULL, 0)) { if ( ! (h->flags & HTML_NONOSPACE)) h->flags &= ~HTML_NOSPACE; h->flags &= ~HTML_NONEWLINE; } else h->flags |= HTML_NOSPACE | HTML_NONEWLINE; if (h->metaf) { print_tagq(h, h->metaf); h->metaf = NULL; } h->flags &= ~HTML_IGNDELIM; } void print_tagq(struct html *h, const struct tag *until) { struct tag *tag; while ((tag = h->tags.head) != NULL) { print_ctag(h, tag); if (until && tag == until) return; } } void print_stagq(struct html *h, const struct tag *suntil) { struct tag *tag; while ((tag = h->tags.head) != NULL) { if (suntil && tag == suntil) return; print_ctag(h, tag); } } void print_paragraph(struct html *h) { struct tag *t; - struct htmlpair tag; - PAIR_CLASS_INIT(&tag, "spacer"); - t = print_otag(h, TAG_DIV, 1, &tag); + t = print_otag(h, TAG_DIV, "c", "Pp"); print_tagq(h, t); } -void -bufinit(struct html *h) -{ +/*********************************************************************** + * Low level output functions. + * They implement line breaking using a short static buffer. + ***********************************************************************/ - h->buf[0] = '\0'; - h->buflen = 0; -} - -void -bufcat_style(struct html *h, const char *key, const char *val) +/* + * Buffer one HTML output byte. + * If the buffer is full, flush and deactivate it and start a new line. + * If the buffer is inactive, print directly. + */ +static void +print_byte(struct html *h, char c) { + if ((h->flags & HTML_BUFFER) == 0) { + putchar(c); + h->col++; + return; + } - bufcat(h, key); - bufcat(h, ":"); - bufcat(h, val); - bufcat(h, ";"); -} + if (h->col + h->bufcol < sizeof(h->buf)) { + h->buf[h->bufcol++] = c; + return; + } -void -bufcat(struct html *h, const char *p) -{ - - /* - * XXX This is broken and not easy to fix. - * When using the -Oincludes option, buffmt_includes() - * may pass in strings overrunning BUFSIZ, causing a crash. - */ - - h->buflen = strlcat(h->buf, p, BUFSIZ); - assert(h->buflen < BUFSIZ); + putchar('\n'); + h->col = 0; + print_indent(h); + putchar(' '); + putchar(' '); + fwrite(h->buf, h->bufcol, 1, stdout); + putchar(c); + h->col = (h->indent + 1) * 2 + h->bufcol + 1; + h->bufcol = 0; + h->flags &= ~HTML_BUFFER; } -void -bufcat_fmt(struct html *h, const char *fmt, ...) +/* + * If something was printed on the current output line, end it. + * Not to be called right after print_indent(). + */ +static void +print_endline(struct html *h) { - va_list ap; + if (h->col == 0) + return; - va_start(ap, fmt); - (void)vsnprintf(h->buf + (int)h->buflen, - BUFSIZ - h->buflen - 1, fmt, ap); - va_end(ap); - h->buflen = strlen(h->buf); + if (h->bufcol) { + putchar(' '); + fwrite(h->buf, h->bufcol, 1, stdout); + h->bufcol = 0; + } + putchar('\n'); + h->col = 0; + h->flags |= HTML_NOSPACE; + h->flags &= ~HTML_BUFFER; } +/* + * Flush the HTML output buffer. + * If it is inactive, activate it. + */ static void -bufncat(struct html *h, const char *p, size_t sz) +print_endword(struct html *h) { + if (h->noindent) { + print_byte(h, ' '); + return; + } - assert(h->buflen + sz + 1 < BUFSIZ); - strncat(h->buf, p, sz); - h->buflen += sz; -} - -void -buffmt_includes(struct html *h, const char *name) -{ - const char *p, *pp; - - pp = h->base_includes; - - bufinit(h); - while (NULL != (p = strchr(pp, '%'))) { - bufncat(h, pp, (size_t)(p - pp)); - switch (*(p + 1)) { - case'I': - bufcat(h, name); - break; - default: - bufncat(h, p, 2); - break; - } - pp = p + 2; + if ((h->flags & HTML_BUFFER) == 0) { + h->col++; + h->flags |= HTML_BUFFER; + } else if (h->bufcol) { + putchar(' '); + fwrite(h->buf, h->bufcol, 1, stdout); + h->col += h->bufcol + 1; } - if (pp) - bufcat(h, pp); + h->bufcol = 0; } -void -buffmt_man(struct html *h, const char *name, const char *sec) +/* + * If at the beginning of a new output line, + * perform indentation and mark the line as containing output. + * Make sure to really produce some output right afterwards, + * but do not use print_otag() for producing it. + */ +static void +print_indent(struct html *h) { - const char *p, *pp; + size_t i; - pp = h->base_man; + if (h->col) + return; - bufinit(h); - while (NULL != (p = strchr(pp, '%'))) { - bufncat(h, pp, (size_t)(p - pp)); - switch (*(p + 1)) { - case 'S': - bufcat(h, sec ? sec : "1"); - break; - case 'N': - bufcat_fmt(h, "%s", name); - break; - default: - bufncat(h, p, 2); - break; - } - pp = p + 2; + if (h->noindent == 0) { + h->col = h->indent * 2; + for (i = 0; i < h->col; i++) + putchar(' '); } - if (pp) - bufcat(h, pp); + h->flags &= ~HTML_NOSPACE; } -void -bufcat_su(struct html *h, const char *p, const struct roffsu *su) +/* + * Print or buffer some characters + * depending on the current HTML output buffer state. + */ +static void +print_word(struct html *h, const char *cp) { - double v; - - v = su->scale; - if (SCALE_MM == su->unit && 0.0 == (v /= 100.0)) - v = 1.0; - else if (SCALE_BU == su->unit) - v /= 24.0; - - bufcat_fmt(h, "%s: %.2f%s;", p, v, roffscales[su->unit]); + while (*cp != '\0') + print_byte(h, *cp++); } -void -bufcat_id(struct html *h, const char *src) +/* + * Calculate the scaling unit passed in a `-width' argument. This uses + * either a native scaling unit (e.g., 1i, 2m) or the string length of + * the value. + */ +static void +a2width(const char *p, struct roffsu *su) { - - /* Cf. . */ - - for (; '\0' != *src; src++) - bufncat(h, *src == ' ' ? "_" : src, 1); + if (a2roffsu(p, su, SCALE_MAX) < 2) { + su->unit = SCALE_EN; + su->scale = html_strlen(p); + } else if (su->scale < 0.0) + su->scale = 0.0; } Index: stable/11/contrib/mdocml/html.h =================================================================== --- stable/11/contrib/mdocml/html.h (revision 316419) +++ stable/11/contrib/mdocml/html.h (revision 316420) @@ -1,176 +1,131 @@ -/* $Id: html.h,v 1.72 2015/11/07 14:01:16 schwarze Exp $ */ +/* $Id: html.h,v 1.78 2017/01/19 16:59:30 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons + * Copyright (c) 2017 Ingo Schwarze * * 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. */ enum htmltag { TAG_HTML, TAG_HEAD, TAG_BODY, TAG_META, TAG_TITLE, TAG_DIV, TAG_H1, TAG_H2, TAG_SPAN, TAG_LINK, TAG_BR, TAG_A, TAG_TABLE, TAG_TBODY, TAG_COL, TAG_TR, TAG_TD, TAG_LI, TAG_UL, TAG_OL, TAG_DL, TAG_DT, TAG_DD, - TAG_BLOCKQUOTE, TAG_PRE, TAG_B, TAG_I, TAG_CODE, TAG_SMALL, TAG_STYLE, TAG_MATH, TAG_MROW, TAG_MI, TAG_MO, TAG_MSUP, TAG_MSUB, TAG_MSUBSUP, TAG_MFRAC, TAG_MSQRT, TAG_MFENCED, TAG_MTABLE, TAG_MTR, TAG_MTD, TAG_MUNDEROVER, TAG_MUNDER, TAG_MOVER, TAG_MAX }; -enum htmlattr { - ATTR_NAME, - ATTR_REL, - ATTR_HREF, - ATTR_TYPE, - ATTR_MEDIA, - ATTR_CLASS, - ATTR_STYLE, - ATTR_ID, - ATTR_COLSPAN, - ATTR_CHARSET, - ATTR_OPEN, - ATTR_CLOSE, - ATTR_MATHVARIANT, - ATTR_MAX -}; - enum htmlfont { HTMLFONT_NONE = 0, HTMLFONT_BOLD, HTMLFONT_ITALIC, HTMLFONT_BI, HTMLFONT_MAX }; struct tag { struct tag *next; enum htmltag tag; }; struct tagq { struct tag *head; }; -struct htmlpair { - enum htmlattr key; - const char *val; -}; - -#define PAIR_INIT(p, t, v) \ - do { \ - (p)->key = (t); \ - (p)->val = (v); \ - } while (/* CONSTCOND */ 0) - -#define PAIR_ID_INIT(p, v) PAIR_INIT(p, ATTR_ID, v) -#define PAIR_CLASS_INIT(p, v) PAIR_INIT(p, ATTR_CLASS, v) -#define PAIR_HREF_INIT(p, v) PAIR_INIT(p, ATTR_HREF, v) -#define PAIR_STYLE_INIT(p, h) PAIR_INIT(p, ATTR_STYLE, (h)->buf) - struct html { int flags; #define HTML_NOSPACE (1 << 0) /* suppress next space */ #define HTML_IGNDELIM (1 << 1) #define HTML_KEEP (1 << 2) #define HTML_PREKEEP (1 << 3) #define HTML_NONOSPACE (1 << 4) /* never add spaces */ #define HTML_LITERAL (1 << 5) /* literal (e.g.,
) context */
 #define	HTML_SKIPCHAR	 (1 << 6) /* skip the next character */
 #define	HTML_NOSPLIT	 (1 << 7) /* do not break line before .An */
 #define	HTML_SPLIT	 (1 << 8) /* break line before .An */
 #define	HTML_NONEWLINE	 (1 << 9) /* No line break in nofill mode. */
+#define	HTML_BUFFER	 (1 << 10) /* Collect a word to see if it fits. */
+	size_t		  indent; /* current output indentation level */
+	int		  noindent; /* indent disabled by 
 */
+	size_t		  col; /* current output byte position */
+	size_t		  bufcol; /* current buf byte position */
+	char		  buf[80]; /* output buffer */
 	struct tagq	  tags; /* stack of open tags */
 	struct rofftbl	  tbl; /* current table */
 	struct tag	 *tblt; /* current open table scope */
 	char		 *base_man; /* base for manpage href */
 	char		 *base_includes; /* base for include href */
 	char		 *style; /* style-sheet URI */
-	char		  buf[BUFSIZ]; /* see bufcat and friends */
-	size_t		  buflen;
 	struct tag	 *metaf; /* current open font scope */
 	enum htmlfont	  metal; /* last used font */
 	enum htmlfont	  metac; /* current font mode */
 	int		  oflags; /* output options */
 #define	HTML_FRAGMENT	 (1 << 0) /* don't emit HTML/HEAD/BODY */
 };
 
 
 struct	tbl_span;
 struct	eqn;
 
 void		  print_gen_decls(struct html *);
 void		  print_gen_head(struct html *);
-struct tag	 *print_otag(struct html *, enum htmltag,
-				int, const struct htmlpair *);
+struct tag	 *print_otag(struct html *, enum htmltag, const char *, ...);
 void		  print_tagq(struct html *, const struct tag *);
 void		  print_stagq(struct html *, const struct tag *);
 void		  print_text(struct html *, const char *);
 void		  print_tblclose(struct html *);
 void		  print_tbl(struct html *, const struct tbl_span *);
 void		  print_eqn(struct html *, const struct eqn *);
 void		  print_paragraph(struct html *);
-
-#if __GNUC__ - 0 >= 4
-__attribute__((__format__ (__printf__, 2, 3)))
-#endif
-void		  bufcat_fmt(struct html *, const char *, ...);
-void		  bufcat(struct html *, const char *);
-void		  bufcat_id(struct html *, const char *);
-void		  bufcat_style(struct html *,
-			const char *, const char *);
-void		  bufcat_su(struct html *, const char *,
-			const struct roffsu *);
-void		  bufinit(struct html *);
-void		  buffmt_man(struct html *,
-			const char *, const char *);
-void		  buffmt_includes(struct html *, const char *);
 
 int		  html_strlen(const char *);
Index: stable/11/contrib/mdocml/lib.in
===================================================================
--- stable/11/contrib/mdocml/lib.in	(revision 316419)
+++ stable/11/contrib/mdocml/lib.in	(revision 316420)
@@ -1,128 +1,131 @@
-/*	$Id: lib.in,v 1.18 2014/01/06 00:53:33 schwarze Exp $ */
+/*	$Id: lib.in,v 1.19 2016/11/23 20:22:13 schwarze Exp $ */
 /*
  * Copyright (c) 2009 Kristaps Dzonsons 
  * Copyright (c) 2009, 2012 Joerg Sonnenberger 
  *
  * 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.
  */
 
 /*
  * These are all possible .Lb strings.  When a new library is added, add
  * its short-string to the left-hand side and formatted string to the
  * right-hand side.
  *
  * Be sure to escape strings.
  */
 
 LINE("lib80211",	"802.11 Wireless Network Management Library (lib80211, \\-l80211)")
 LINE("libarchive",	"Streaming Archive Library (libarchive, \\-larchive)")
 LINE("libarm",		"ARM Architecture Library (libarm, \\-larm)")
 LINE("libarm32",	"ARM32 Architecture Library (libarm32, \\-larm32)")
 LINE("libbluetooth",	"Bluetooth Library (libbluetooth, \\-lbluetooth)")
 LINE("libbsm",		"Basic Security Module Library (libbsm, \\-lbsm)")
 LINE("libc",		"Standard C\\~Library (libc, \\-lc)")
 LINE("libc_r",		"Reentrant C\\~Library (libc_r, \\-lc_r)")
 LINE("libcalendar",	"Calendar Arithmetic Library (libcalendar, \\-lcalendar)")
 LINE("libcam",		"Common Access Method User Library (libcam, \\-lcam)")
 LINE("libcasper",	"Casper Library (libcasper, \\-lcapser)")
 LINE("libcdk",		"Curses Development Kit Library (libcdk, \\-lcdk)")
 LINE("libcipher",	"FreeSec Crypt Library (libcipher, \\-lcipher)")
 LINE("libcompat",	"Compatibility Library (libcompat, \\-lcompat)")
 LINE("libcrypt",	"Crypt Library (libcrypt, \\-lcrypt)")
 LINE("libcurses",	"Curses Library (libcurses, \\-lcurses)")
 LINE("libcuse", 	"Userland Character Device Library (libcuse, \\-lcuse)")
 LINE("libdevattr",	"Device attribute and event library (libdevattr, \\-ldevattr)")
 LINE("libdevctl",	"Device Control Library (libdevctl, \\-ldevctl)")
 LINE("libdevinfo",	"Device and Resource Information Utility Library (libdevinfo, \\-ldevinfo)")
 LINE("libdevstat",	"Device Statistics Library (libdevstat, \\-ldevstat)")
 LINE("libdisk",		"Interface to Slice and Partition Labels Library (libdisk, \\-ldisk)")
 LINE("libdm",		"Device Mapper Library (libdm, \\-ldm)")
 LINE("libdwarf",	"DWARF Access Library (libdwarf, \\-ldwarf)")
 LINE("libedit",		"Command Line Editor Library (libedit, \\-ledit)")
 LINE("libefi",		"EFI Runtime Services Library (libefi, \\-lefi)")
 LINE("libelf",		"ELF Access Library (libelf, \\-lelf)")
 LINE("libevent",	"Event Notification Library (libevent, \\-levent)")
 LINE("libexecinfo",	"Backtrace Information Library (libexecinfo, \\-lexecinfo)")
 LINE("libfetch",	"File Transfer Library (libfetch, \\-lfetch)")
 LINE("libfsid",		"Filesystem Identification Library (libfsid, \\-lfsid)")
 LINE("libftpio",	"FTP Connection Management Library (libftpio, \\-lftpio)")
 LINE("libform",		"Curses Form Library (libform, \\-lform)")
 LINE("libgeom",		"Userland API Library for Kernel GEOM subsystem (libgeom, \\-lgeom)")
 LINE("libgpio",		"General-Purpose Input Output (GPIO) library (libgpio, \\-lgpio)")
 LINE("libhammer",	"HAMMER Filesystem Userland Library (libhammer, \\-lhammer)")
 LINE("libi386",		"i386 Architecture Library (libi386, \\-li386)")
 LINE("libintl",		"Internationalized Message Handling Library (libintl, \\-lintl)")
 LINE("libipsec",	"IPsec Policy Control Library (libipsec, \\-lipsec)")
 LINE("libiscsi",	"iSCSI protocol library (libiscsi, \\-liscsi)")
 LINE("libisns",		"Internet Storage Name Service Library (libisns, \\-lisns)")
 LINE("libjail",		"Jail Library (libjail, \\-ljail)")
 LINE("libkcore",	"Kernel Memory Core Access Library (libkcore, \\-lkcore)")
 LINE("libkiconv",	"Kernel-side iconv Library (libkiconv, \\-lkiconv)")
 LINE("libkse",		"N:M Threading Library (libkse, \\-lkse)")
 LINE("libkvm",		"Kernel Data Access Library (libkvm, \\-lkvm)")
 LINE("libm",		"Math Library (libm, \\-lm)")
 LINE("libm68k",		"m68k Architecture Library (libm68k, \\-lm68k)")
 LINE("libmagic",	"Magic Number Recognition Library (libmagic, \\-lmagic)")
 LINE("libmandoc",	"Mandoc Macro Compiler Library (libmandoc, \\-lmandoc)")
 LINE("libmd",		"Message Digest (MD4, MD5, etc.) Support Library (libmd, \\-lmd)")
 LINE("libmemstat",	"Kernel Memory Allocator Statistics Library (libmemstat, \\-lmemstat)")
 LINE("libmenu",		"Curses Menu Library (libmenu, \\-lmenu)")
 LINE("libmj",		"Minimalist JSON library (libmj, \\-lmj)")
 LINE("libnetgraph",	"Netgraph User Library (libnetgraph, \\-lnetgraph)")
 LINE("libnetpgp",	"Netpgp Signing, Verification, Encryption and Decryption (libnetpgp, \\-lnetpgp)")
 LINE("libnetpgpverify",	"Netpgp Verification (libnetpgpverify, \\-lnetpgpverify)")
 LINE("libnpf",		"NPF Packet Filter Library (libnpf, \\-lnpf)")
 LINE("libnv",		"Name/value pairs library (libnv, \\-lnv)")
 LINE("libossaudio",	"OSS Audio Emulation Library (libossaudio, \\-lossaudio)")
 LINE("libpam",		"Pluggable Authentication Module Library (libpam, \\-lpam)")
-LINE("libpcap",		"Packet Capture Library (libpcap, \\-lpcap)")
+LINE("libpanel",	"Z-order for curses windows (libpanel, \\-lpanel)")
+LINE("libpcap",		"Packet capture Library (libpcap, \\-lpcap)")
 LINE("libpci",		"PCI Bus Access Library (libpci, \\-lpci)")
 LINE("libpmc",		"Performance Counters Library (libpmc, \\-lpmc)")
 LINE("libppath",	"Property-List Paths Library (libppath, \\-lppath)")
 LINE("libposix",	"POSIX Compatibility Library (libposix, \\-lposix)")
 LINE("libposix1e",	"POSIX.1e Security API Library (libposix1e, \\-lposix1e)")
 LINE("libppath",	"Property-List Paths Library (libppath, \\-lppath)")
 LINE("libproc",		"Processor Monitoring and Analysis Library (libproc, \\-lproc)")
 LINE("libprocstat",	"Process and Files Information Retrieval (libprocstat, \\-lprocstat)")
 LINE("libprop",		"Property Container Object Library (libprop, \\-lprop)")
 LINE("libpthread",	"POSIX Threads Library (libpthread, \\-lpthread)")
+LINE("libpthread_dbg",	"POSIX Debug Threads Library (libpthread_dbg, \\-lpthread_dbg)")
 LINE("libpuffs",	"puffs Convenience Library (libpuffs, \\-lpuffs)")
 LINE("libquota",	"Disk Quota Access and Control Library (libquota, \\-lquota)")
 LINE("libradius",	"RADIUS Client Library (libradius, \\-lradius)")
 LINE("librefuse",	"File System in Userspace Convenience Library (librefuse, \\-lrefuse)")
 LINE("libresolv",	"DNS Resolver Library (libresolv, \\-lresolv)")
 LINE("librpcsec_gss",	"RPC GSS-API Authentication Library (librpcsec_gss, \\-lrpcsec_gss)")
 LINE("librpcsvc",	"RPC Service Library (librpcsvc, \\-lrpcsvc)")
 LINE("librt",		"POSIX Real\\-time Library (librt, \\-lrt)")
-LINE("librtld_db",	"Run-time Linker Debugging Library (librtld_db, \\-lrtld_db)")
+LINE("librtld_db",	"Debugging interface to the runtime linker Library (librtld_db, \\-lrtld_db)")
+LINE("librumpclient",	"Clientside Stubs for rump Kernel Remote Protocols (librumpclient, \\-lrumpclient)")
 LINE("libsaslc",	"Simple Authentication and Security Layer client library (libsaslc, \\-lsaslc)")
 LINE("libsbuf",		"Safe String Composition Library (libsbuf, \\-lsbuf)")
 LINE("libsdp",		"Bluetooth Service Discovery Protocol User Library (libsdp, \\-lsdp)")
 LINE("libssp",		"Buffer Overflow Protection Library (libssp, \\-lssp)")
 LINE("libstdthreads",	"C11 Threads Library (libstdthreads, \\-lstdthreads)")
 LINE("libSystem",	"System Library (libSystem, \\-lSystem)")
 LINE("libsysdecode",	"System Argument Decoding Library (libsysdecode, \\-lsysdecode)")
 LINE("libtacplus",	"TACACS+ Client Library (libtacplus, \\-ltacplus)")
 LINE("libtcplay",	"TrueCrypt-compatible API library (libtcplay, \\-ltcplay)")
 LINE("libtermcap",	"Termcap Access Library (libtermcap, \\-ltermcap)")
 LINE("libterminfo",	"Terminal Information Library (libterminfo, \\-lterminfo)")
 LINE("libthr",		"1:1 Threading Library (libthr, \\-lthr)")
 LINE("libufs",		"UFS File System Access Library (libufs, \\-lufs)")
 LINE("libugidfw",	"File System Firewall Interface Library (libugidfw, \\-lugidfw)")
 LINE("libulog",		"User Login Record Library (libulog, \\-lulog)")
 LINE("libusbhid",	"USB Human Interface Devices Library (libusbhid, \\-lusbhid)")
 LINE("libutil",		"System Utilities Library (libutil, \\-lutil)")
 LINE("libvgl",		"Video Graphics Library (libvgl, \\-lvgl)")
 LINE("libx86_64",	"x86_64 Architecture Library (libx86_64, \\-lx86_64)")
 LINE("libxo",		"Text, XML, JSON, and HTML Output Emission Library (libxo, \\-lxo)")
 LINE("libz",		"Compression Library (libz, \\-lz)")
Index: stable/11/contrib/mdocml/libmandoc.h
===================================================================
--- stable/11/contrib/mdocml/libmandoc.h	(revision 316419)
+++ stable/11/contrib/mdocml/libmandoc.h	(revision 316420)
@@ -1,84 +1,82 @@
-/*	$Id: libmandoc.h,v 1.63 2016/07/07 19:19:01 schwarze Exp $ */
+/*	$Id: libmandoc.h,v 1.64 2016/07/19 13:36:13 schwarze Exp $ */
 /*
  * Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons 
  * Copyright (c) 2013, 2014, 2015 Ingo Schwarze 
  *
  * 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 AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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.
  */
 
 enum	rofferr {
 	ROFF_CONT, /* continue processing line */
 	ROFF_RERUN, /* re-run roff interpreter with offset */
 	ROFF_APPEND, /* re-run main parser, appending next line */
 	ROFF_REPARSE, /* re-run main parser on the result */
 	ROFF_SO, /* include another file */
 	ROFF_IGN, /* ignore current line */
 	ROFF_TBL, /* a table row was successfully parsed */
 	ROFF_EQN /* an equation was successfully parsed */
 };
 
 struct	buf {
 	char	*buf;
 	size_t	 sz;
 };
 
 
 struct	mparse;
 struct	tbl_span;
 struct	eqn;
 struct	roff;
 struct	roff_man;
 
 void		 mandoc_msg(enum mandocerr, struct mparse *,
 			int, int, const char *);
-#if __GNUC__ - 0 >= 4
-__attribute__((__format__ (__printf__, 5, 6)))
-#endif
 void		 mandoc_vmsg(enum mandocerr, struct mparse *,
-			int, int, const char *, ...);
+			int, int, const char *, ...)
+			__attribute__((__format__ (printf, 5, 6)));
 char		*mandoc_getarg(struct mparse *, char **, int, int *);
 char		*mandoc_normdate(struct mparse *, char *, int, int);
 int		 mandoc_eos(const char *, size_t);
 int		 mandoc_strntoi(const char *, size_t, int);
 const char	*mandoc_a2msec(const char*);
 
 void		 mdoc_hash_init(void);
 int		 mdoc_parseln(struct roff_man *, int, char *, int);
 void		 mdoc_endparse(struct roff_man *);
 
 void		 man_hash_init(void);
 int		 man_parseln(struct roff_man *, int, char *, int);
 void		 man_endparse(struct roff_man *);
 
 int		 preconv_cue(const struct buf *, size_t);
 int		 preconv_encode(struct buf *, size_t *,
 			struct buf *, size_t *, int *);
 
 void		 roff_free(struct roff *);
 struct roff	*roff_alloc(struct mparse *, int);
 void		 roff_reset(struct roff *);
 void		 roff_man_free(struct roff_man *);
 struct roff_man	*roff_man_alloc(struct roff *, struct mparse *,
 			const char *, int);
 void		 roff_man_reset(struct roff_man *);
 enum rofferr	 roff_parseln(struct roff *, int, struct buf *, int *);
 void		 roff_endparse(struct roff *);
 void		 roff_setreg(struct roff *, const char *, int, char sign);
 int		 roff_getreg(const struct roff *, const char *);
 char		*roff_strdup(const struct roff *, const char *);
 int		 roff_getcontrol(const struct roff *,
 			const char *, int *);
 int		 roff_getformat(const struct roff *);
 
 const struct tbl_span	*roff_span(const struct roff *);
 const struct eqn	*roff_eqn(const struct roff *);
Index: stable/11/contrib/mdocml/main.c
===================================================================
--- stable/11/contrib/mdocml/main.c	(revision 316419)
+++ stable/11/contrib/mdocml/main.c	(revision 316420)
@@ -1,1108 +1,1102 @@
-/*	$Id: main.c,v 1.269 2016/07/12 05:18:38 kristaps Exp $ */
+/*	$Id: main.c,v 1.279 2017/01/09 17:49:57 schwarze Exp $ */
 /*
  * Copyright (c) 2008-2012 Kristaps Dzonsons 
- * Copyright (c) 2010-2012, 2014-2016 Ingo Schwarze 
+ * Copyright (c) 2010-2012, 2014-2017 Ingo Schwarze 
  * Copyright (c) 2010 Joerg Sonnenberger 
  *
  * 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 AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h"
 
 #include 
 #include 	/* MACHINE */
 #include 
 
 #include 
 #include 
 #if HAVE_ERR
 #include 
 #endif
 #include 
 #include 
 #include 
 #if HAVE_SANDBOX_INIT
 #include 
 #endif
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 
 #include "mandoc_aux.h"
 #include "mandoc.h"
 #include "roff.h"
 #include "mdoc.h"
 #include "man.h"
 #include "tag.h"
 #include "main.h"
 #include "manconf.h"
 #include "mansearch.h"
 
-#if !defined(__GNUC__) || (__GNUC__ < 2)
-# if !defined(lint)
-#  define __attribute__(x)
-# endif
-#endif /* !defined(__GNUC__) || (__GNUC__ < 2) */
-
 enum	outmode {
 	OUTMODE_DEF = 0,
 	OUTMODE_FLN,
 	OUTMODE_LST,
 	OUTMODE_ALL,
 	OUTMODE_INT,
 	OUTMODE_ONE
 };
 
 enum	outt {
 	OUTT_ASCII = 0,	/* -Tascii */
 	OUTT_LOCALE,	/* -Tlocale */
 	OUTT_UTF8,	/* -Tutf8 */
 	OUTT_TREE,	/* -Ttree */
 	OUTT_MAN,	/* -Tman */
 	OUTT_HTML,	/* -Thtml */
 	OUTT_LINT,	/* -Tlint */
 	OUTT_PS,	/* -Tps */
 	OUTT_PDF	/* -Tpdf */
 };
 
 struct	curparse {
 	struct mparse	 *mp;
 	enum mandoclevel  wlevel;	/* ignore messages below this */
 	int		  wstop;	/* stop after a file with a warning */
 	enum outt	  outtype;	/* which output to use */
 	void		 *outdata;	/* data for output */
 	struct manoutput *outopts;	/* output options */
 };
 
+
+int			  mandocdb(int, char *[]);
+
 static	int		  fs_lookup(const struct manpaths *,
 				size_t ipath, const char *,
 				const char *, const char *,
 				struct manpage **, size_t *);
 static	void		  fs_search(const struct mansearch *,
 				const struct manpaths *, int, char**,
 				struct manpage **, size_t *);
 static	int		  koptions(int *, char *);
-#if HAVE_SQLITE3
-int			  mandocdb(int, char**);
-#endif
 static	int		  moptions(int *, char *);
 static	void		  mmsg(enum mandocerr, enum mandoclevel,
 				const char *, int, int, const char *);
+static	void		  outdata_alloc(struct curparse *);
 static	void		  parse(struct curparse *, int, const char *);
 static	void		  passthrough(const char *, int, int);
 static	pid_t		  spawn_pager(struct tag_files *);
 static	int		  toptions(struct curparse *, char *);
 static	void		  usage(enum argmode) __attribute__((noreturn));
 static	int		  woptions(struct curparse *, char *);
 
 static	const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9};
 static	char		  help_arg[] = "help";
 static	char		 *help_argv[] = {help_arg, NULL};
 static	enum mandoclevel  rc;
 
 
 int
 main(int argc, char *argv[])
 {
 	struct manconf	 conf;
 	struct curparse	 curp;
 	struct mansearch search;
 	struct tag_files *tag_files;
 	const char	*progname;
 	char		*auxpaths;
 	char		*defos;
 	unsigned char	*uc;
 	struct manpage	*res, *resp;
 	char		*conf_file, *defpaths;
 	const char	*sec;
 	size_t		 i, sz;
 	int		 prio, best_prio;
 	enum outmode	 outmode;
 	int		 fd;
 	int		 show_usage;
 	int		 options;
 	int		 use_pager;
 	int		 status, signum;
 	int		 c;
 	pid_t		 pager_pid, tc_pgid, man_pgid, pid;
 
 #if HAVE_PROGNAME
 	progname = getprogname();
 #else
 	if (argc < 1)
 		progname = mandoc_strdup("mandoc");
 	else if ((progname = strrchr(argv[0], '/')) == NULL)
 		progname = argv[0];
 	else
 		++progname;
 	setprogname(progname);
 #endif
 
-#if HAVE_SQLITE3
 	if (strncmp(progname, "mandocdb", 8) == 0 ||
 	    strcmp(progname, BINM_MAKEWHATIS) == 0)
 		return mandocdb(argc, argv);
-#endif
 
 #if HAVE_PLEDGE
 	if (pledge("stdio rpath tmppath tty proc exec flock", NULL) == -1)
 		err((int)MANDOCLEVEL_SYSERR, "pledge");
 #endif
 
 #if HAVE_SANDBOX_INIT
 	if (sandbox_init(kSBXProfileNoInternet, SANDBOX_NAMED, NULL) == -1)
 		errx((int)MANDOCLEVEL_SYSERR, "sandbox_init");
 #endif
 
 	/* Search options. */
 
 	memset(&conf, 0, sizeof(conf));
 	conf_file = defpaths = NULL;
 	auxpaths = NULL;
 
 	memset(&search, 0, sizeof(struct mansearch));
 	search.outkey = "Nd";
 
 	if (strcmp(progname, BINM_MAN) == 0)
 		search.argmode = ARG_NAME;
 	else if (strcmp(progname, BINM_APROPOS) == 0)
 		search.argmode = ARG_EXPR;
 	else if (strcmp(progname, BINM_WHATIS) == 0)
 		search.argmode = ARG_WORD;
 	else if (strncmp(progname, "help", 4) == 0)
 		search.argmode = ARG_NAME;
 	else
 		search.argmode = ARG_FILE;
 
 	/* Parser and formatter options. */
 
 	memset(&curp, 0, sizeof(struct curparse));
 	curp.outtype = OUTT_LOCALE;
 	curp.wlevel  = MANDOCLEVEL_BADARG;
 	curp.outopts = &conf.output;
 	options = MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1;
 	defos = NULL;
 
 	use_pager = 1;
 	tag_files = NULL;
 	show_usage = 0;
 	outmode = OUTMODE_DEF;
 
 	while (-1 != (c = getopt(argc, argv,
 			"aC:cfhI:iK:klM:m:O:S:s:T:VW:w"))) {
 		switch (c) {
 		case 'a':
 			outmode = OUTMODE_ALL;
 			break;
 		case 'C':
 			conf_file = optarg;
 			break;
 		case 'c':
 			use_pager = 0;
 			break;
 		case 'f':
 			search.argmode = ARG_WORD;
 			break;
 		case 'h':
 			conf.output.synopsisonly = 1;
 			use_pager = 0;
 			outmode = OUTMODE_ALL;
 			break;
 		case 'I':
 			if (strncmp(optarg, "os=", 3)) {
 				warnx("-I %s: Bad argument", optarg);
 				return (int)MANDOCLEVEL_BADARG;
 			}
 			if (defos) {
 				warnx("-I %s: Duplicate argument", optarg);
 				return (int)MANDOCLEVEL_BADARG;
 			}
 			defos = mandoc_strdup(optarg + 3);
 			break;
 		case 'i':
 			outmode = OUTMODE_INT;
 			break;
 		case 'K':
 			if ( ! koptions(&options, optarg))
 				return (int)MANDOCLEVEL_BADARG;
 			break;
 		case 'k':
 			search.argmode = ARG_EXPR;
 			break;
 		case 'l':
 			search.argmode = ARG_FILE;
 			outmode = OUTMODE_ALL;
 			break;
 		case 'M':
 			defpaths = optarg;
 			break;
 		case 'm':
 			auxpaths = optarg;
 			break;
 		case 'O':
 			search.outkey = optarg;
 			while (optarg != NULL)
 				manconf_output(&conf.output,
 				    strsep(&optarg, ","));
 			break;
 		case 'S':
 			search.arch = optarg;
 			break;
 		case 's':
 			search.sec = optarg;
 			break;
 		case 'T':
 			if ( ! toptions(&curp, optarg))
 				return (int)MANDOCLEVEL_BADARG;
 			break;
 		case 'W':
 			if ( ! woptions(&curp, optarg))
 				return (int)MANDOCLEVEL_BADARG;
 			break;
 		case 'w':
 			outmode = OUTMODE_FLN;
 			break;
 		default:
 			show_usage = 1;
 			break;
 		}
 	}
 
 	if (show_usage)
 		usage(search.argmode);
 
 	/* Postprocess options. */
 
 	if (outmode == OUTMODE_DEF) {
 		switch (search.argmode) {
 		case ARG_FILE:
 			outmode = OUTMODE_ALL;
 			use_pager = 0;
 			break;
 		case ARG_NAME:
 			outmode = OUTMODE_ONE;
 			break;
 		default:
 			outmode = OUTMODE_LST;
 			break;
 		}
 	}
 
 	if (outmode == OUTMODE_FLN ||
 	    outmode == OUTMODE_LST ||
 	    !isatty(STDOUT_FILENO))
 		use_pager = 0;
 
 #if HAVE_PLEDGE
 	if (!use_pager)
 		if (pledge("stdio rpath flock", NULL) == -1)
 			err((int)MANDOCLEVEL_SYSERR, "pledge");
 #endif
 
 	/* Parse arguments. */
 
 	if (argc > 0) {
 		argc -= optind;
 		argv += optind;
 	}
 	resp = NULL;
 
 	/*
 	 * Quirks for help(1)
 	 * and for a man(1) section argument without -s.
 	 */
 
 	if (search.argmode == ARG_NAME) {
 		if (*progname == 'h') {
 			if (argc == 0) {
 				argv = help_argv;
 				argc = 1;
 			}
 		} else if (argc > 1 &&
 		    ((uc = (unsigned char *)argv[0]) != NULL) &&
 		    ((isdigit(uc[0]) && (uc[1] == '\0' ||
 		      (isalpha(uc[1]) && uc[2] == '\0'))) ||
 		     (uc[0] == 'n' && uc[1] == '\0'))) {
 			search.sec = (char *)uc;
 			argv++;
 			argc--;
 		}
 		if (search.arch == NULL)
 			search.arch = getenv("MACHINE");
 #ifdef MACHINE
 		if (search.arch == NULL)
 			search.arch = MACHINE;
 #endif
 	}
 
 	rc = MANDOCLEVEL_OK;
 
 	/* man(1), whatis(1), apropos(1) */
 
 	if (search.argmode != ARG_FILE) {
-		if (argc == 0)
-			usage(search.argmode);
-
 		if (search.argmode == ARG_NAME &&
 		    outmode == OUTMODE_ONE)
 			search.firstmatch = 1;
 
 		/* Access the mandoc database. */
 
 		manconf_parse(&conf, conf_file, defpaths, auxpaths);
-#if HAVE_SQLITE3
-		mansearch_setup(1);
 		if ( ! mansearch(&search, &conf.manpath,
 		    argc, argv, &res, &sz))
 			usage(search.argmode);
-#else
-		if (search.argmode != ARG_NAME) {
-			fputs("mandoc: database support not compiled in\n",
-			    stderr);
-			return (int)MANDOCLEVEL_BADARG;
-		}
-		sz = 0;
-#endif
 
 		if (sz == 0) {
 			if (search.argmode == ARG_NAME)
 				fs_search(&search, &conf.manpath,
 				    argc, argv, &res, &sz);
 			else
 				warnx("nothing appropriate");
 		}
 
 		if (sz == 0) {
 			rc = MANDOCLEVEL_BADARG;
 			goto out;
 		}
 
 		/*
 		 * For standard man(1) and -a output mode,
 		 * prepare for copying filename pointers
 		 * into the program parameter array.
 		 */
 
 		if (outmode == OUTMODE_ONE) {
 			argc = 1;
 			best_prio = 20;
 		} else if (outmode == OUTMODE_ALL)
 			argc = (int)sz;
 
 		/* Iterate all matching manuals. */
 
 		resp = res;
 		for (i = 0; i < sz; i++) {
 			if (outmode == OUTMODE_FLN)
 				puts(res[i].file);
 			else if (outmode == OUTMODE_LST)
 				printf("%s - %s\n", res[i].names,
 				    res[i].output == NULL ? "" :
 				    res[i].output);
 			else if (outmode == OUTMODE_ONE) {
 				/* Search for the best section. */
 				sec = res[i].file;
 				sec += strcspn(sec, "123456789");
 				if (sec[0] == '\0')
 					continue;
 				prio = sec_prios[sec[0] - '1'];
 				if (sec[1] != '/')
 					prio += 10;
 				if (prio >= best_prio)
 					continue;
 				best_prio = prio;
 				resp = res + i;
 			}
 		}
 
 		/*
 		 * For man(1), -a and -i output mode, fall through
 		 * to the main mandoc(1) code iterating files
 		 * and running the parsers on each of them.
 		 */
 
 		if (outmode == OUTMODE_FLN || outmode == OUTMODE_LST)
 			goto out;
 	}
 
 	/* mandoc(1) */
 
 #if HAVE_PLEDGE
 	if (use_pager) {
 		if (pledge("stdio rpath tmppath tty proc exec", NULL) == -1)
 			err((int)MANDOCLEVEL_SYSERR, "pledge");
 	} else {
 		if (pledge("stdio rpath", NULL) == -1)
 			err((int)MANDOCLEVEL_SYSERR, "pledge");
 	}
 #endif
 
 	if (search.argmode == ARG_FILE && ! moptions(&options, auxpaths))
 		return (int)MANDOCLEVEL_BADARG;
 
 	mchars_alloc();
 	curp.mp = mparse_alloc(options, curp.wlevel, mmsg, defos);
 
 	/*
 	 * Conditionally start up the lookaside buffer before parsing.
 	 */
 	if (OUTT_MAN == curp.outtype)
 		mparse_keep(curp.mp);
 
 	if (argc < 1) {
 		if (use_pager)
 			tag_files = tag_init();
 		parse(&curp, STDIN_FILENO, "");
 	}
 
 	while (argc > 0) {
 		fd = mparse_open(curp.mp, resp != NULL ? resp->file : *argv);
 		if (fd != -1) {
 			if (use_pager) {
 				tag_files = tag_init();
 				use_pager = 0;
 			}
 
 			if (resp == NULL)
 				parse(&curp, fd, *argv);
-			else if (resp->form & FORM_SRC) {
+			else if (resp->form == FORM_SRC) {
 				/* For .so only; ignore failure. */
 				chdir(conf.manpath.paths[resp->ipath]);
 				parse(&curp, fd, resp->file);
 			} else
 				passthrough(resp->file, fd,
 				    conf.output.synopsisonly);
 
-			if (argc > 1 && curp.outtype <= OUTT_UTF8)
+			if (argc > 1 && curp.outtype <= OUTT_UTF8) {
+				if (curp.outdata == NULL)
+					outdata_alloc(&curp);
 				terminal_sepline(curp.outdata);
+			}
 		} else if (rc < MANDOCLEVEL_ERROR)
 			rc = MANDOCLEVEL_ERROR;
 
 		if (MANDOCLEVEL_OK != rc && curp.wstop)
 			break;
 
 		if (resp != NULL)
 			resp++;
 		else
 			argv++;
 		if (--argc)
 			mparse_reset(curp.mp);
 	}
 
 	if (curp.outdata != NULL) {
 		switch (curp.outtype) {
 		case OUTT_HTML:
 			html_free(curp.outdata);
 			break;
 		case OUTT_UTF8:
 		case OUTT_LOCALE:
 		case OUTT_ASCII:
 			ascii_free(curp.outdata);
 			break;
 		case OUTT_PDF:
 		case OUTT_PS:
 			pspdf_free(curp.outdata);
 			break;
 		default:
 			break;
 		}
 	}
 	mparse_free(curp.mp);
 	mchars_free();
 
 out:
 	if (search.argmode != ARG_FILE) {
 		manconf_free(&conf);
-#if HAVE_SQLITE3
 		mansearch_free(res, sz);
-		mansearch_setup(0);
-#endif
 	}
 
 	free(defos);
 
 	/*
 	 * When using a pager, finish writing both temporary files,
 	 * fork it, wait for the user to close it, and clean up.
 	 */
 
 	if (tag_files != NULL) {
 		fclose(stdout);
 		tag_write();
 		man_pgid = getpgid(0);
 		tag_files->tcpgid = man_pgid == getpid() ?
 		    getpgid(getppid()) : man_pgid;
 		pager_pid = 0;
 		signum = SIGSTOP;
 		for (;;) {
 
 			/* Stop here until moved to the foreground. */
 
-			tc_pgid = tcgetpgrp(STDIN_FILENO);
+			tc_pgid = tcgetpgrp(tag_files->ofd);
 			if (tc_pgid != man_pgid) {
 				if (tc_pgid == pager_pid) {
-					(void)tcsetpgrp(STDIN_FILENO,
+					(void)tcsetpgrp(tag_files->ofd,
 					    man_pgid);
 					if (signum == SIGTTIN)
 						continue;
 				} else
 					tag_files->tcpgid = tc_pgid;
 				kill(0, signum);
 				continue;
 			}
 
 			/* Once in the foreground, activate the pager. */
 
 			if (pager_pid) {
-				(void)tcsetpgrp(STDIN_FILENO, pager_pid);
+				(void)tcsetpgrp(tag_files->ofd, pager_pid);
 				kill(pager_pid, SIGCONT);
 			} else
 				pager_pid = spawn_pager(tag_files);
 
 			/* Wait for the pager to stop or exit. */
 
 			while ((pid = waitpid(pager_pid, &status,
 			    WUNTRACED)) == -1 && errno == EINTR)
 				continue;
 
 			if (pid == -1) {
 				warn("wait");
 				rc = MANDOCLEVEL_SYSERR;
 				break;
 			}
 			if (!WIFSTOPPED(status))
 				break;
 
 			signum = WSTOPSIG(status);
 		}
 		tag_unlink();
 	}
 
 	return (int)rc;
 }
 
 static void
 usage(enum argmode argmode)
 {
 
 	switch (argmode) {
 	case ARG_FILE:
 		fputs("usage: mandoc [-acfhkl] [-I os=name] "
 		    "[-K encoding] [-mformat] [-O option]\n"
 		    "\t      [-T output] [-W level] [file ...]\n", stderr);
 		break;
 	case ARG_NAME:
 		fputs("usage: man [-acfhklw] [-C file] [-I os=name] "
 		    "[-K encoding] [-M path] [-m path]\n"
 		    "\t   [-O option=value] [-S subsection] [-s section] "
 		    "[-T output] [-W level]\n"
 		    "\t   [section] name ...\n", stderr);
 		break;
 	case ARG_WORD:
 		fputs("usage: whatis [-acfhklw] [-C file] "
 		    "[-M path] [-m path] [-O outkey] [-S arch]\n"
 		    "\t      [-s section] name ...\n", stderr);
 		break;
 	case ARG_EXPR:
 		fputs("usage: apropos [-acfhklw] [-C file] "
 		    "[-M path] [-m path] [-O outkey] [-S arch]\n"
 		    "\t       [-s section] expression ...\n", stderr);
 		break;
 	}
 	exit((int)MANDOCLEVEL_BADARG);
 }
 
 static int
 fs_lookup(const struct manpaths *paths, size_t ipath,
 	const char *sec, const char *arch, const char *name,
 	struct manpage **res, size_t *ressz)
 {
 	glob_t		 globinfo;
 	struct manpage	*page;
 	char		*file;
-	int		 form, globres;
+	int		 globres;
+	enum form	 form;
 
 	form = FORM_SRC;
 	mandoc_asprintf(&file, "%s/man%s/%s.%s",
 	    paths->paths[ipath], sec, name, sec);
 	if (access(file, R_OK) != -1)
 		goto found;
 	free(file);
 
 	mandoc_asprintf(&file, "%s/cat%s/%s.0",
 	    paths->paths[ipath], sec, name);
 	if (access(file, R_OK) != -1) {
 		form = FORM_CAT;
 		goto found;
 	}
 	free(file);
 
 	if (arch != NULL) {
 		mandoc_asprintf(&file, "%s/man%s/%s/%s.%s",
 		    paths->paths[ipath], sec, arch, name, sec);
 		if (access(file, R_OK) != -1)
 			goto found;
 		free(file);
 	}
 
 	mandoc_asprintf(&file, "%s/man%s/%s.[01-9]*",
 	    paths->paths[ipath], sec, name);
 	globres = glob(file, 0, NULL, &globinfo);
 	if (globres != 0 && globres != GLOB_NOMATCH)
 		warn("%s: glob", file);
 	free(file);
 	if (globres == 0)
 		file = mandoc_strdup(*globinfo.gl_pathv);
 	globfree(&globinfo);
 	if (globres != 0)
 		return 0;
 
 found:
-#if HAVE_SQLITE3
 	warnx("outdated mandoc.db lacks %s(%s) entry, run %s %s",
 	    name, sec, BINM_MAKEWHATIS, paths->paths[ipath]);
-#endif
 	*res = mandoc_reallocarray(*res, ++*ressz, sizeof(struct manpage));
 	page = *res + (*ressz - 1);
 	page->file = file;
 	page->names = NULL;
 	page->output = NULL;
 	page->ipath = ipath;
 	page->bits = NAME_FILE & NAME_MASK;
 	page->sec = (*sec >= '1' && *sec <= '9') ? *sec - '1' + 1 : 10;
 	page->form = form;
 	return 1;
 }
 
 static void
 fs_search(const struct mansearch *cfg, const struct manpaths *paths,
 	int argc, char **argv, struct manpage **res, size_t *ressz)
 {
 	const char *const sections[] =
 	    {"1", "8", "6", "2", "3", "5", "7", "4", "9", "3p"};
 	const size_t nsec = sizeof(sections)/sizeof(sections[0]);
 
 	size_t		 ipath, isec, lastsz;
 
 	assert(cfg->argmode == ARG_NAME);
 
 	*res = NULL;
 	*ressz = lastsz = 0;
 	while (argc) {
 		for (ipath = 0; ipath < paths->sz; ipath++) {
 			if (cfg->sec != NULL) {
 				if (fs_lookup(paths, ipath, cfg->sec,
 				    cfg->arch, *argv, res, ressz) &&
 				    cfg->firstmatch)
 					return;
 			} else for (isec = 0; isec < nsec; isec++)
 				if (fs_lookup(paths, ipath, sections[isec],
 				    cfg->arch, *argv, res, ressz) &&
 				    cfg->firstmatch)
 					return;
 		}
 		if (*ressz == lastsz)
 			warnx("No entry for %s in the manual.", *argv);
 		lastsz = *ressz;
 		argv++;
 		argc--;
 	}
 }
 
 static void
 parse(struct curparse *curp, int fd, const char *file)
 {
 	enum mandoclevel  rctmp;
 	struct roff_man	 *man;
 
 	/* Begin by parsing the file itself. */
 
 	assert(file);
 	assert(fd >= 0);
 
 	rctmp = mparse_readfd(curp->mp, fd, file);
 	if (fd != STDIN_FILENO)
 		close(fd);
 	if (rc < rctmp)
 		rc = rctmp;
 
 	/*
 	 * With -Wstop and warnings or errors of at least the requested
 	 * level, do not produce output.
 	 */
 
 	if (rctmp != MANDOCLEVEL_OK && curp->wstop)
 		return;
 
-	/* If unset, allocate output dev now (if applicable). */
+	if (curp->outdata == NULL)
+		outdata_alloc(curp);
 
-	if (curp->outdata == NULL) {
-		switch (curp->outtype) {
-		case OUTT_HTML:
-			curp->outdata = html_alloc(curp->outopts);
-			break;
-		case OUTT_UTF8:
-			curp->outdata = utf8_alloc(curp->outopts);
-			break;
-		case OUTT_LOCALE:
-			curp->outdata = locale_alloc(curp->outopts);
-			break;
-		case OUTT_ASCII:
-			curp->outdata = ascii_alloc(curp->outopts);
-			break;
-		case OUTT_PDF:
-			curp->outdata = pdf_alloc(curp->outopts);
-			break;
-		case OUTT_PS:
-			curp->outdata = ps_alloc(curp->outopts);
-			break;
-		default:
-			break;
-		}
-	}
-
 	mparse_result(curp->mp, &man, NULL);
 
 	/* Execute the out device, if it exists. */
 
 	if (man == NULL)
 		return;
 	if (man->macroset == MACROSET_MDOC) {
 		mdoc_validate(man);
 		switch (curp->outtype) {
 		case OUTT_HTML:
 			html_mdoc(curp->outdata, man);
 			break;
 		case OUTT_TREE:
 			tree_mdoc(curp->outdata, man);
 			break;
 		case OUTT_MAN:
 			man_mdoc(curp->outdata, man);
 			break;
 		case OUTT_PDF:
 		case OUTT_ASCII:
 		case OUTT_UTF8:
 		case OUTT_LOCALE:
 		case OUTT_PS:
 			terminal_mdoc(curp->outdata, man);
 			break;
 		default:
 			break;
 		}
 	}
 	if (man->macroset == MACROSET_MAN) {
 		man_validate(man);
 		switch (curp->outtype) {
 		case OUTT_HTML:
 			html_man(curp->outdata, man);
 			break;
 		case OUTT_TREE:
 			tree_man(curp->outdata, man);
 			break;
 		case OUTT_MAN:
 			man_man(curp->outdata, man);
 			break;
 		case OUTT_PDF:
 		case OUTT_ASCII:
 		case OUTT_UTF8:
 		case OUTT_LOCALE:
 		case OUTT_PS:
 			terminal_man(curp->outdata, man);
 			break;
 		default:
 			break;
 		}
 	}
+	mparse_updaterc(curp->mp, &rc);
 }
 
 static void
+outdata_alloc(struct curparse *curp)
+{
+	switch (curp->outtype) {
+	case OUTT_HTML:
+		curp->outdata = html_alloc(curp->outopts);
+		break;
+	case OUTT_UTF8:
+		curp->outdata = utf8_alloc(curp->outopts);
+		break;
+	case OUTT_LOCALE:
+		curp->outdata = locale_alloc(curp->outopts);
+		break;
+	case OUTT_ASCII:
+		curp->outdata = ascii_alloc(curp->outopts);
+		break;
+	case OUTT_PDF:
+		curp->outdata = pdf_alloc(curp->outopts);
+		break;
+	case OUTT_PS:
+		curp->outdata = ps_alloc(curp->outopts);
+		break;
+	default:
+		break;
+	}
+}
+
+static void
 passthrough(const char *file, int fd, int synopsis_only)
 {
 	const char	 synb[] = "S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS";
 	const char	 synr[] = "SYNOPSIS";
 
 	FILE		*stream;
 	const char	*syscall;
 	char		*line, *cp;
 	size_t		 linesz;
+	ssize_t		 len, written;
 	int		 print;
 
 	line = NULL;
 	linesz = 0;
 
+	if (fflush(stdout) == EOF) {
+		syscall = "fflush";
+		goto fail;
+	}
+
 	if ((stream = fdopen(fd, "r")) == NULL) {
 		close(fd);
 		syscall = "fdopen";
 		goto fail;
 	}
 
 	print = 0;
-	while (getline(&line, &linesz, stream) != -1) {
+	while ((len = getline(&line, &linesz, stream)) != -1) {
 		cp = line;
 		if (synopsis_only) {
 			if (print) {
 				if ( ! isspace((unsigned char)*cp))
 					goto done;
-				while (isspace((unsigned char)*cp))
+				while (isspace((unsigned char)*cp)) {
 					cp++;
+					len--;
+				}
 			} else {
 				if (strcmp(cp, synb) == 0 ||
 				    strcmp(cp, synr) == 0)
 					print = 1;
 				continue;
 			}
 		}
-		if (fputs(cp, stdout)) {
+		for (; len > 0; len -= written) {
+			if ((written = write(STDOUT_FILENO, cp, len)) != -1)
+				continue;
 			fclose(stream);
-			syscall = "fputs";
+			syscall = "write";
 			goto fail;
 		}
 	}
 
 	if (ferror(stream)) {
 		fclose(stream);
 		syscall = "getline";
 		goto fail;
 	}
 
 done:
 	free(line);
 	fclose(stream);
 	return;
 
 fail:
 	free(line);
 	warn("%s: SYSERR: %s", file, syscall);
 	if (rc < MANDOCLEVEL_SYSERR)
 		rc = MANDOCLEVEL_SYSERR;
 }
 
 static int
 koptions(int *options, char *arg)
 {
 
 	if ( ! strcmp(arg, "utf-8")) {
 		*options |=  MPARSE_UTF8;
 		*options &= ~MPARSE_LATIN1;
 	} else if ( ! strcmp(arg, "iso-8859-1")) {
 		*options |=  MPARSE_LATIN1;
 		*options &= ~MPARSE_UTF8;
 	} else if ( ! strcmp(arg, "us-ascii")) {
 		*options &= ~(MPARSE_UTF8 | MPARSE_LATIN1);
 	} else {
 		warnx("-K %s: Bad argument", arg);
 		return 0;
 	}
 	return 1;
 }
 
 static int
 moptions(int *options, char *arg)
 {
 
 	if (arg == NULL)
 		/* nothing to do */;
 	else if (0 == strcmp(arg, "doc"))
 		*options |= MPARSE_MDOC;
 	else if (0 == strcmp(arg, "andoc"))
 		/* nothing to do */;
 	else if (0 == strcmp(arg, "an"))
 		*options |= MPARSE_MAN;
 	else {
 		warnx("-m %s: Bad argument", arg);
 		return 0;
 	}
 
 	return 1;
 }
 
 static int
 toptions(struct curparse *curp, char *arg)
 {
 
 	if (0 == strcmp(arg, "ascii"))
 		curp->outtype = OUTT_ASCII;
 	else if (0 == strcmp(arg, "lint")) {
 		curp->outtype = OUTT_LINT;
 		curp->wlevel  = MANDOCLEVEL_WARNING;
 	} else if (0 == strcmp(arg, "tree"))
 		curp->outtype = OUTT_TREE;
 	else if (0 == strcmp(arg, "man"))
 		curp->outtype = OUTT_MAN;
 	else if (0 == strcmp(arg, "html"))
 		curp->outtype = OUTT_HTML;
 	else if (0 == strcmp(arg, "utf8"))
 		curp->outtype = OUTT_UTF8;
 	else if (0 == strcmp(arg, "locale"))
 		curp->outtype = OUTT_LOCALE;
 	else if (0 == strcmp(arg, "xhtml"))
 		curp->outtype = OUTT_HTML;
 	else if (0 == strcmp(arg, "ps"))
 		curp->outtype = OUTT_PS;
 	else if (0 == strcmp(arg, "pdf"))
 		curp->outtype = OUTT_PDF;
 	else {
 		warnx("-T %s: Bad argument", arg);
 		return 0;
 	}
 
 	return 1;
 }
 
 static int
 woptions(struct curparse *curp, char *arg)
 {
 	char		*v, *o;
 	const char	*toks[7];
 
 	toks[0] = "stop";
 	toks[1] = "all";
 	toks[2] = "warning";
 	toks[3] = "error";
 	toks[4] = "unsupp";
 	toks[5] = "fatal";
 	toks[6] = NULL;
 
 	while (*arg) {
 		o = arg;
-		switch (getsubopt(&arg, UNCONST(toks), &v)) {
+		switch (getsubopt(&arg, (char * const *)toks, &v)) {
 		case 0:
 			curp->wstop = 1;
 			break;
 		case 1:
 		case 2:
 			curp->wlevel = MANDOCLEVEL_WARNING;
 			break;
 		case 3:
 			curp->wlevel = MANDOCLEVEL_ERROR;
 			break;
 		case 4:
 			curp->wlevel = MANDOCLEVEL_UNSUPP;
 			break;
 		case 5:
 			curp->wlevel = MANDOCLEVEL_BADARG;
 			break;
 		default:
 			warnx("-W %s: Bad argument", o);
 			return 0;
 		}
 	}
 
 	return 1;
 }
 
 static void
 mmsg(enum mandocerr t, enum mandoclevel lvl,
 		const char *file, int line, int col, const char *msg)
 {
 	const char	*mparse_msg;
 
-	fprintf(stderr, "%s: %s:", getprogname(), file);
+	fprintf(stderr, "%s: %s:", getprogname(),
+	    file == NULL ? "" : file);
 
 	if (line)
 		fprintf(stderr, "%d:%d:", line, col + 1);
 
 	fprintf(stderr, " %s", mparse_strlevel(lvl));
 
 	if (NULL != (mparse_msg = mparse_strerror(t)))
 		fprintf(stderr, ": %s", mparse_msg);
 
 	if (msg)
 		fprintf(stderr, ": %s", msg);
 
 	fputc('\n', stderr);
 }
 
 static pid_t
 spawn_pager(struct tag_files *tag_files)
 {
 	const struct timespec timeout = { 0, 100000000 };  /* 0.1s */
 #define MAX_PAGER_ARGS 16
 	char		*argv[MAX_PAGER_ARGS];
 	const char	*pager;
 	char		*cp;
 	size_t		 cmdlen;
 	int		 argc;
 	pid_t		 pager_pid;
 
 	pager = getenv("MANPAGER");
 	if (pager == NULL || *pager == '\0')
 		pager = getenv("PAGER");
 	if (pager == NULL || *pager == '\0')
 		pager = "more -s";
 	cp = mandoc_strdup(pager);
 
 	/*
 	 * Parse the pager command into words.
 	 * Intentionally do not do anything fancy here.
 	 */
 
 	argc = 0;
 	while (argc + 4 < MAX_PAGER_ARGS) {
 		argv[argc++] = cp;
 		cp = strchr(cp, ' ');
 		if (cp == NULL)
 			break;
 		*cp++ = '\0';
 		while (*cp == ' ')
 			cp++;
 		if (*cp == '\0')
 			break;
 	}
 
 	/* For less(1), use the tag file. */
 
 	if ((cmdlen = strlen(argv[0])) >= 4) {
 		cp = argv[0] + cmdlen - 4;
 		if (strcmp(cp, "less") == 0) {
 			argv[argc++] = mandoc_strdup("-T");
 			argv[argc++] = tag_files->tfn;
 		}
 	}
 	argv[argc++] = tag_files->ofn;
 	argv[argc] = NULL;
 
 	switch (pager_pid = fork()) {
 	case -1:
 		err((int)MANDOCLEVEL_SYSERR, "fork");
 	case 0:
 		break;
 	default:
 		(void)setpgid(pager_pid, 0);
-		(void)tcsetpgrp(STDIN_FILENO, pager_pid);
+		(void)tcsetpgrp(tag_files->ofd, pager_pid);
 #if HAVE_PLEDGE
 		if (pledge("stdio rpath tmppath tty proc", NULL) == -1)
 			err((int)MANDOCLEVEL_SYSERR, "pledge");
 #endif
 		tag_files->pager_pid = pager_pid;
 		return pager_pid;
 	}
 
 	/* The child process becomes the pager. */
 
 	if (dup2(tag_files->ofd, STDOUT_FILENO) == -1)
 		err((int)MANDOCLEVEL_SYSERR, "pager stdout");
 	close(tag_files->ofd);
 	close(tag_files->tfd);
 
 	/* Do not start the pager before controlling the terminal. */
 
-	while (tcgetpgrp(STDIN_FILENO) != getpid())
+	while (tcgetpgrp(STDOUT_FILENO) != getpid())
 		nanosleep(&timeout, NULL);
 
 	execvp(argv[0], argv);
 	err((int)MANDOCLEVEL_SYSERR, "exec %s", argv[0]);
 }
Index: stable/11/contrib/mdocml/main.h
===================================================================
--- stable/11/contrib/mdocml/main.h	(revision 316419)
+++ stable/11/contrib/mdocml/main.h	(revision 316420)
@@ -1,53 +1,51 @@
-/*	$Id: main.h,v 1.25 2016/07/08 22:29:05 schwarze Exp $ */
+/*	$Id: main.h,v 1.26 2016/07/15 19:33:01 schwarze Exp $ */
 /*
  * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons 
  * Copyright (c) 2014, 2015 Ingo Schwarze 
  *
  * 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 AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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.
  */
-
-#define	UNCONST(a)	((void *)(uintptr_t)(const void *)(a))
 
 struct	roff_man;
 struct	manoutput;
 
 /*
  * Definitions for main.c-visible output device functions, e.g., -Thtml
  * and -Tascii.  Note that ascii_alloc() is named as such in
  * anticipation of latin1_alloc() and so on, all of which map into the
  * terminal output routines with different character settings.
  */
 
 void		 *html_alloc(const struct manoutput *);
 void		  html_mdoc(void *, const struct roff_man *);
 void		  html_man(void *, const struct roff_man *);
 void		  html_free(void *);
 
 void		  tree_mdoc(void *, const struct roff_man *);
 void		  tree_man(void *, const struct roff_man *);
 
 void		  man_mdoc(void *, const struct roff_man *);
 void		  man_man(void *, const struct roff_man *);
 
 void		 *locale_alloc(const struct manoutput *);
 void		 *utf8_alloc(const struct manoutput *);
 void		 *ascii_alloc(const struct manoutput *);
 void		  ascii_free(void *);
 
 void		 *pdf_alloc(const struct manoutput *);
 void		 *ps_alloc(const struct manoutput *);
 void		  pspdf_free(void *);
 
 void		  terminal_mdoc(void *, const struct roff_man *);
 void		  terminal_man(void *, const struct roff_man *);
 void		  terminal_sepline(void *);
Index: stable/11/contrib/mdocml/makewhatis.8
===================================================================
--- stable/11/contrib/mdocml/makewhatis.8	(revision 316419)
+++ stable/11/contrib/mdocml/makewhatis.8	(revision 316420)
@@ -1,217 +1,215 @@
-.\"	$Id: makewhatis.8,v 1.3 2014/08/17 21:03:06 schwarze Exp $
+.\"	$Id: makewhatis.8,v 1.4 2016/07/19 22:40:33 schwarze Exp $
 .\"
 .\" Copyright (c) 2011, 2012 Kristaps Dzonsons 
 .\" Copyright (c) 2011, 2012 Ingo Schwarze 
 .\"
 .\" 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.
 .\"
-.Dd $Mdocdate: August 17 2014 $
+.Dd $Mdocdate: July 19 2016 $
 .Dt MAKEWHATIS 8
 .Os
 .Sh NAME
 .Nm makewhatis
 .Nd index UNIX manuals
 .Sh SYNOPSIS
 .Nm
 .Op Fl aDnpQ
 .Op Fl T Cm utf8
 .Op Fl C Ar file
 .Nm
 .Op Fl aDnpQ
 .Op Fl T Cm utf8
 .Ar dir ...
 .Nm
 .Op Fl DnpQ
 .Op Fl T Cm utf8
 .Fl d Ar dir
 .Op Ar
 .Nm
 .Op Fl Dnp
 .Op Fl T Cm utf8
 .Fl u Ar dir
 .Op Ar
 .Nm
 .Op Fl DQ
 .Fl t Ar
 .Sh DESCRIPTION
 The
 .Nm
 utility extracts keywords from
 .Ux
 manuals and indexes them in a database for fast retrieval by
 .Xr apropos 1 ,
 .Xr whatis 1 ,
 and
 .Xr man 1 Ns 's
 .Fl k
 option.
 .Pp
 By default,
 .Nm
 creates a database in each
 .Ar dir
 using the files
 .Sm off
 .Sy man Ar section Li /
 .Op Ar arch Li /
 .Ar title . section
 .Sm on
 and
 .Sm off
 .Sy cat Ar section Li /
 .Op Ar arch Li /
 .Ar title . Sy 0
 .Sm on
 in that directory.
 Existing databases are replaced.
 If
 .Ar dir
 is not provided,
 .Nm
 uses the default paths stipulated by
-.Xr manpath 1 ,
-or
 .Xr man.conf 5 .
 .Pp
 The arguments are as follows:
 .Bl -tag -width "-C file"
 .It Fl a
 Use all directories and files found below
 .Ar dir ... .
 .It Fl C Ar file
 Specify an alternative configuration
 .Ar file
 in
 .Xr man.conf 5
 format.
 .It Fl D
 Display all files added or removed to the index.
 With a second
 .Fl D ,
 also show all keywords added for each file.
 .It Fl d Ar dir
 Merge (remove and re-add)
 .Ar
 to the database in
 .Ar dir .
 .It Fl n
 Do not create or modify any database; scan and parse only,
 and print manual page names and descriptions to standard output.
 .It Fl p
 Print warnings about potential problems with manual pages
 to the standard error output.
 .It Fl Q
 Quickly build reduced-size databases
 by reading only the NAME sections of manuals.
 The resulting databases will usually contain names and descriptions only.
 .It Fl T Cm utf8
 Use UTF-8 encoding instead of ASCII for strings stored in the databases.
 .It Fl t Ar
 Check the given
 .Ar files
 for potential problems.
 Implies
 .Fl a ,
 .Fl n ,
 and
 .Fl p .
 All diagnostic messages are printed to the standard output;
 the standard error output is not used.
 .It Fl u Ar dir
 Remove
 .Ar
 from the database in
 .Ar dir .
 .El
 .Pp
 If fatal parse errors are encountered while parsing, the offending file
 is printed to stderr, omitted from the index, and the parse continues
 with the next input file.
 .Sh FILES
 .Bl -tag -width Ds
 .It Pa mandoc.db
 A database of manpages relative to the directory of the file.
 This file is portable across architectures and systems, so long as the
 manpage hierarchy it indexes does not change.
 .It Pa /etc/man.conf
 The default
 .Xr man 1
 configuration file.
 .El
 .Sh EXIT STATUS
 The
 .Nm
 utility exits with one of the following values:
 .Pp
 .Bl -tag -width Ds -compact
 .It 0
 No errors occurred.
 .It 5
 Invalid command line arguments were specified.
 No input files have been read.
 .It 6
 An operating system error occurred, for example memory exhaustion or an
 error accessing input files.
 Such errors cause
 .Nm
 to exit at once, possibly in the middle of parsing or formatting a file.
 The output databases are corrupt and should be removed.
 .El
 .Sh SEE ALSO
 .Xr apropos 1 ,
 .Xr man 1 ,
 .Xr whatis 1 ,
 .Xr man.conf 5
 .Sh HISTORY
 A
 .Nm
 utility first appeared in
 .Bx 2 .
 It was rewritten in
 .Xr perl 1
 for
 .Ox 2.7
 and in C for
 .Ox 5.6 .
 .Pp
 The
 .Ar dir
 argument first appeared in
 .Nx 1.0 ;
 the options
 .Fl dpt
 in
 .Ox 2.7 ;
 the option
 .Fl u
 in
 .Ox 3.4 ;
 and the options
 .Fl aCDnQT
 in
 .Ox 5.6 .
 .Sh AUTHORS
 .An -nosplit
 .An Bill Joy
 wrote the original
 .Bx
 .Nm
 in February 1979,
 .An Marc Espie
 started the Perl version in 2000,
 and the current version of
 .Nm
 was written by
 .An Kristaps Dzonsons Aq Mt kristaps@bsd.lv
 and
 .An Ingo Schwarze Aq Mt schwarze@openbsd.org .
Index: stable/11/contrib/mdocml/man.1
===================================================================
--- stable/11/contrib/mdocml/man.1	(revision 316419)
+++ stable/11/contrib/mdocml/man.1	(revision 316420)
@@ -1,427 +1,435 @@
-.\"	$Id: man.1,v 1.17 2016/07/01 20:24:04 schwarze Exp $
+.\"	$Id: man.1,v 1.20 2017/01/06 01:34:57 schwarze Exp $
 .\"
 .\" Copyright (c) 1989, 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
 .\" Copyright (c) 2003, 2007, 2008, 2014 Jason McIntyre 
 .\" Copyright (c) 2010, 2011, 2014, 2015 Ingo Schwarze 
 .\"
 .\" Redistribution and use in source and binary forms, with or without
 .\" modification, are permitted provided that the following conditions
 .\" are met:
 .\" 1. Redistributions of source code must retain the above copyright
 .\"    notice, this list of conditions and the following disclaimer.
 .\" 2. Redistributions in binary form must reproduce the above copyright
 .\"    notice, this list of conditions and the following disclaimer in the
 .\"    documentation and/or other materials provided with the distribution.
 .\" 3. Neither the name of the University nor the names of its contributors
 .\"    may be used to endorse or promote products derived from this software
 .\"    without specific prior written permission.
 .\"
 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)man.1	8.2 (Berkeley) 1/2/94
 .\"
-.Dd $Mdocdate: July 1 2016 $
+.Dd $Mdocdate: January 6 2017 $
 .Dt MAN 1
 .Os
 .Sh NAME
 .Nm man
 .Nd display manual pages
 .Sh SYNOPSIS
 .Nm man
 .Op Fl acfhklw
 .Op Fl C Ar file
 .Op Fl I Cm os Ns = Ns Ar name
 .Op Fl K Ar encoding
 .Op Fl M Ar path
 .Op Fl m Ar path
 .Op Fl O Ar option Ns = Ns Ar value
 .Op Fl S Ar subsection
 .Op Fl s Ar section
 .Op Fl T Ar output
 .Op Fl W Ar level
 .Op Ar section
 .Ar name ...
 .Sh DESCRIPTION
 The
 .Nm
 utility
 displays the
 manual pages entitled
 .Ar name .
 Pages may be selected according to
 a specific category
 .Pq Ar section
 or
 machine architecture
 .Pq Ar subsection .
 .Pp
 The options are as follows:
 .Bl -tag -width Ds
 .It Fl a
-Display all of the manual pages for a specified
-.Ar section
-and
-.Ar name
-combination.
-Normally, only the first manual page found is displayed.
+Display all matching manual pages.
+Normally, only the first page found is displayed.
 .It Fl C Ar file
 Use the specified
 .Ar file
 instead of the default configuration file.
 This permits users to configure their own manual environment.
 See
 .Xr man.conf 5
 for a description of the contents of this file.
 .It Fl c
 Copy the manual page to the standard output instead of using
 .Xr more 1
 to paginate it.
 This is done by default if the standard output is not a terminal device.
 .It Fl f
 A synonym for
 .Xr whatis 1 .
 It searches for
 .Ar name
 in manual page names and displays the header lines from all matching pages.
 The search is case insensitive and matches whole words only.
 This overrides any earlier
 .Fl k
 and
 .Fl l
 options.
+.It Fl h
+Display only the SYNOPSIS lines of the requested manual pages.
+Implies
+.Fl a
+and
+.Fl c .
 .It Fl I Cm os Ns = Ns Ar name
 Override the default operating system
 .Ar name
 for the
 .Xr mdoc 7
 .Ic \&Os
 and for the
 .Xr man 7
 .Ic \&TH
 macro.
-.It Fl h
-Display only the SYNOPSIS lines of the requested manual pages.
-Implies
-.Fl a
-and
-.Fl c .
 .It Fl K Ar encoding
 Specify the input encoding.
 The supported
 .Ar encoding
 arguments are
 .Cm us-ascii ,
 .Cm iso-8859-1 ,
 and
 .Cm utf-8 .
 By default, the encoding is automatically detected as described in the
 .Xr mandoc 1
 manual.
 .It Fl k
 A synonym for
 .Xr apropos 1 .
 Instead of
 .Ar name ,
 an expression can be provided using the syntax described in the
 .Xr apropos 1
 manual.
 By default, it displays the header lines of all matching pages.
 This overrides any earlier
 .Fl f
 and
 .Fl l
 options.
 .It Fl l
 A synonym for
 .Xr mandoc 1
 .Fl a .
 The
 .Ar name
 arguments are interpreted as filenames.
 No search is done and
 .Ar file ,
 .Ar path ,
 .Ar section ,
 and
 .Ar subsection
 are ignored.
 This overrides any earlier
 .Fl f ,
 .Fl k ,
 and
 .Fl w
 options.
 .It Fl M Ar path
 Override the list of standard directories which
 .Nm
 searches for manual pages.
 The supplied
 .Ar path
 must be a colon
 .Pq Ql \&:
 separated list of directories.
 This search path may also be set using the environment variable
 .Ev MANPATH .
 .It Fl m Ar path
 Augment the list of standard directories which
 .Nm
 searches for manual pages.
 The supplied
 .Ar path
 must be a colon
 .Pq Ql \&:
 separated list of directories.
 These directories will be searched before the standard directories or
 the directories specified using the
 .Fl M
 option or the
 .Ev MANPATH
 environment variable.
 .It Fl O Ar option Ns = Ns Ar value
 Comma-separated output options.
 For each output format, the available options are described in the
 .Xr mandoc 1
 manual.
 .It Fl S Ar subsection
 Restricts the directories that
 .Nm
 will search to those of a specific
 .Xr machine 1
 architecture.
 .Ar subsection
 is case insensitive.
 .Pp
 By default manual pages for all architectures are installed.
 Therefore this option can be used to view pages for one
 architecture whilst using another.
 .Pp
 This option overrides the
 .Ev MACHINE
 environment variable.
 .It Oo Fl s Oc Ar section
 Only select manuals from the specified
 .Ar section .
 The currently available sections are:
 .Pp
 .Bl -tag -width "localXXX" -offset indent -compact
 .It 1
 General commands
 .Pq tools and utilities .
 .It 2
 System calls and error numbers.
 .It 3
 Library functions.
 .It 3p
 .Xr perl 1
 programmer's reference guide.
 .It 4
 Device drivers.
 .It 5
 File formats.
 .It 6
 Games.
 .It 7
 Miscellaneous information.
 .It 8
 System maintenance and operation commands.
 .It 9
 Kernel internals.
 .El
 .It Fl T Ar output
 Select the output format.
 The default is
 .Cm locale .
 The other output modes
 .Cm ascii ,
 .Cm html ,
 .Cm lint ,
 .Cm man ,
 .Cm pdf ,
 .Cm ps ,
 .Cm tree ,
 and
 .Cm utf8
 are described in the
 .Xr mandoc 1
 manual.
 .It Fl W Ar level
 Specify the minimum message
 .Ar level
 to be reported on the standard error output and to affect the exit status.
 The
 .Ar level
 can be
 .Cm warning ,
 .Cm error ,
 or
 .Cm unsupp ;
 .Cm all
 is an alias for
 .Cm warning .
 By default,
 .Nm
 is silent.
 See the
 .Xr mandoc 1
 manual for details.
 .It Fl w
 List the pathnames of the manual pages which
 .Nm
 would display for the specified
 .Ar section
 and
 .Ar name
 combination.
 .El
 .Pp
 Guidelines for writing
 man pages can be found in
 .Xr mdoc 7 .
 .Pp
 If both a formatted and an unformatted version of the same manual page,
 for example
 .Pa cat1/foo.0
 and
 .Pa man1/foo.1 ,
 exist in the same directory, and at least one of them is selected,
 only the newer one is used.
 However, if both the
 .Fl a
 and the
 .Fl w
 options are specified, both file names are printed.
 .Sh ENVIRONMENT
 .Bl -tag -width MANPATHX
 .It Ev MACHINE
 As some manual pages are intended only for specific architectures,
 .Nm
 searches any subdirectories,
 with the same name as the current architecture,
 in every directory which it searches.
 Machine specific areas are checked before general areas.
 The current machine type may be overridden by setting the environment
 variable
 .Ev MACHINE
 to the name of a specific architecture,
 or with the
 .Fl S
 option.
 .Ev MACHINE
 is case insensitive.
 .It Ev MANPAGER
 Any non-empty value of the environment variable
 .Ev MANPAGER
 will be used instead of the standard pagination program,
 .Xr more 1 .
 If
 .Xr less 1
 is used, the interactive
 .Ic :t
 command can be used to go to the definitions of various terms, for
 example command line options, command modifiers, internal commands,
-and environment variables.
+environment variables, function names, preprocessor macros,
+.Xr errno 2
+values, and some other emphasized words.
+Some terms may have defining text at more than one place.
+In that case, the
+.Xr less 1
+interactive commands
+.Ic t
+and
+.Ic T
+can be used to move to the next and to the previous place providing
+information about the term last searched for with
+.Ic :t .
 .It Ev MANPATH
 The standard search path used by
 .Nm
 may be overridden by specifying a path in the
 .Ev MANPATH
 environment
 variable.
 The format of the path is a colon
 .Pq Ql \&:
 separated list of directories.
 .It Ev PAGER
 Specifies the pagination program to use when
 .Ev MANPAGER
 is not defined.
 If neither PAGER nor MANPAGER is defined,
 .Xr more 1
 .Fl s
 will be used.
 .El
 .Sh FILES
 .Bl -tag -width /etc/man.conf -compact
 .It Pa /etc/man.conf
 default man configuration file
 .El
 .Sh EXIT STATUS
 .Ex -std man
 .Sh SEE ALSO
 .Xr apropos 1 ,
 .Xr intro 1 ,
 .Xr whatis 1 ,
 .Xr whereis 1 ,
 .Xr intro 2 ,
 .Xr intro 3 ,
 .Xr intro 4 ,
 .Xr intro 5 ,
 .Xr man.conf 5 ,
 .Xr intro 6 ,
 .Xr intro 7 ,
 .Xr mdoc 7 ,
 .Xr intro 8 ,
 .Xr intro 9
 .Sh STANDARDS
 The
 .Nm
 utility is compliant with the
 .St -p1003.1-2008
 specification.
 .Pp
 The flags
 .Op Fl aCcfhIKlMmOSsTWw ,
 as well as the environment variables
 .Ev MACHINE ,
 .Ev MANPAGER ,
 and
 .Ev MANPATH ,
 are extensions to that specification.
 .Sh HISTORY
 A
 .Nm
 command first appeared in
 .At v3 .
 .Pp
 The
 .Fl w
 option first appeared in
 .At v7 ;
 .Fl f
 and
 .Fl k
 in
 .Bx 4 ;
 .Fl M
 in
 .Bx 4.3 ;
 .Fl a
 in
 .Bx 4.3 Tahoe ;
 .Fl c
 and
 .Fl m
 in
 .Bx 4.3 Reno ;
 .Fl h
 in
 .Bx 4.3 Net/2 ;
 .Fl C
 in
 .Nx 1.0 ;
 and
 .Fl s
 and
 .Fl S
 in
 .Ox 2.3 .
Index: stable/11/contrib/mdocml/man.c
===================================================================
--- stable/11/contrib/mdocml/man.c	(revision 316419)
+++ stable/11/contrib/mdocml/man.c	(revision 316420)
@@ -1,369 +1,369 @@
-/*	$Id: man.c,v 1.166 2015/10/22 21:54:23 schwarze Exp $ */
+/*	$Id: man.c,v 1.167 2017/01/10 13:47:00 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons 
  * Copyright (c) 2013, 2014, 2015 Ingo Schwarze 
  * Copyright (c) 2011 Joerg Sonnenberger 
  *
  * 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 AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h"
 
 #include 
 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 
 #include "mandoc_aux.h"
 #include "mandoc.h"
 #include "roff.h"
 #include "man.h"
 #include "libmandoc.h"
 #include "roff_int.h"
 #include "libman.h"
 
 const	char *const __man_macronames[MAN_MAX] = {
 	"br",		"TH",		"SH",		"SS",
 	"TP",		"LP",		"PP",		"P",
 	"IP",		"HP",		"SM",		"SB",
 	"BI",		"IB",		"BR",		"RB",
 	"R",		"B",		"I",		"IR",
 	"RI",		"sp",		"nf",
 	"fi",		"RE",		"RS",		"DT",
 	"UC",		"PD",		"AT",		"in",
 	"ft",		"OP",		"EX",		"EE",
 	"UR",		"UE",		"ll"
 	};
 
 const	char * const *man_macronames = __man_macronames;
 
 static	void		 man_descope(struct roff_man *, int, int);
 static	int		 man_ptext(struct roff_man *, int, char *, int);
 static	int		 man_pmacro(struct roff_man *, int, char *, int);
 
 
 int
 man_parseln(struct roff_man *man, int ln, char *buf, int offs)
 {
 
 	if (man->last->type != ROFFT_EQN || ln > man->last->line)
 		man->flags |= MAN_NEWLINE;
 
 	return roff_getcontrol(man->roff, buf, &offs) ?
 	    man_pmacro(man, ln, buf, offs) :
 	    man_ptext(man, ln, buf, offs);
 }
 
 static void
 man_descope(struct roff_man *man, int line, int offs)
 {
 	/*
 	 * Co-ordinate what happens with having a next-line scope open:
 	 * first close out the element scope (if applicable), then close
 	 * out the block scope (also if applicable).
 	 */
 
 	if (man->flags & MAN_ELINE) {
 		man->flags &= ~MAN_ELINE;
 		man_unscope(man, man->last->parent);
 	}
 	if ( ! (man->flags & MAN_BLINE))
 		return;
 	man->flags &= ~MAN_BLINE;
 	man_unscope(man, man->last->parent);
 	roff_body_alloc(man, line, offs, man->last->tok);
 }
 
 static int
 man_ptext(struct roff_man *man, int line, char *buf, int offs)
 {
 	int		 i;
 
 	/* Literal free-form text whitespace is preserved. */
 
 	if (man->flags & MAN_LITERAL) {
 		roff_word_alloc(man, line, offs, buf + offs);
 		man_descope(man, line, offs);
 		return 1;
 	}
 
 	for (i = offs; buf[i] == ' '; i++)
 		/* Skip leading whitespace. */ ;
 
 	/*
 	 * Blank lines are ignored right after headings
 	 * but add a single vertical space elsewhere.
 	 */
 
 	if (buf[i] == '\0') {
 		/* Allocate a blank entry. */
 		if (man->last->tok != MAN_SH &&
 		    man->last->tok != MAN_SS) {
 			roff_elem_alloc(man, line, offs, MAN_sp);
 			man->next = ROFF_NEXT_SIBLING;
 		}
 		return 1;
 	}
 
 	/*
 	 * Warn if the last un-escaped character is whitespace. Then
 	 * strip away the remaining spaces (tabs stay!).
 	 */
 
 	i = (int)strlen(buf);
 	assert(i);
 
 	if (' ' == buf[i - 1] || '\t' == buf[i - 1]) {
 		if (i > 1 && '\\' != buf[i - 2])
 			mandoc_msg(MANDOCERR_SPACE_EOL, man->parse,
 			    line, i - 1, NULL);
 
 		for (--i; i && ' ' == buf[i]; i--)
 			/* Spin back to non-space. */ ;
 
 		/* Jump ahead of escaped whitespace. */
 		i += '\\' == buf[i] ? 2 : 1;
 
 		buf[i] = '\0';
 	}
 	roff_word_alloc(man, line, offs, buf + offs);
 
 	/*
 	 * End-of-sentence check.  If the last character is an unescaped
 	 * EOS character, then flag the node as being the end of a
 	 * sentence.  The front-end will know how to interpret this.
 	 */
 
 	assert(i);
 	if (mandoc_eos(buf, (size_t)i))
-		man->last->flags |= MAN_EOS;
+		man->last->flags |= NODE_EOS;
 
 	man_descope(man, line, offs);
 	return 1;
 }
 
 static int
 man_pmacro(struct roff_man *man, int ln, char *buf, int offs)
 {
 	struct roff_node *n;
 	const char	*cp;
 	int		 tok;
 	int		 i, ppos;
 	int		 bline;
 	char		 mac[5];
 
 	ppos = offs;
 
 	/*
 	 * Copy the first word into a nil-terminated buffer.
 	 * Stop when a space, tab, escape, or eoln is encountered.
 	 */
 
 	i = 0;
 	while (i < 4 && strchr(" \t\\", buf[offs]) == NULL)
 		mac[i++] = buf[offs++];
 
 	mac[i] = '\0';
 
 	tok = (i > 0 && i < 4) ? man_hash_find(mac) : TOKEN_NONE;
 
 	if (tok == TOKEN_NONE) {
 		mandoc_msg(MANDOCERR_MACRO, man->parse,
 		    ln, ppos, buf + ppos - 1);
 		return 1;
 	}
 
 	/* Skip a leading escape sequence or tab. */
 
 	switch (buf[offs]) {
 	case '\\':
 		cp = buf + offs + 1;
 		mandoc_escape(&cp, NULL, NULL);
 		offs = cp - buf;
 		break;
 	case '\t':
 		offs++;
 		break;
 	default:
 		break;
 	}
 
 	/* Jump to the next non-whitespace word. */
 
 	while (buf[offs] && buf[offs] == ' ')
 		offs++;
 
 	/*
 	 * Trailing whitespace.  Note that tabs are allowed to be passed
 	 * into the parser as "text", so we only warn about spaces here.
 	 */
 
 	if (buf[offs] == '\0' && buf[offs - 1] == ' ')
 		mandoc_msg(MANDOCERR_SPACE_EOL, man->parse,
 		    ln, offs - 1, NULL);
 
 	/*
 	 * Some macros break next-line scopes; otherwise, remember
 	 * whether we are in next-line scope for a block head.
 	 */
 
 	man_breakscope(man, tok);
 	bline = man->flags & MAN_BLINE;
 
 	/* Call to handler... */
 
 	assert(man_macros[tok].fp);
 	(*man_macros[tok].fp)(man, tok, ln, ppos, &offs, buf);
 
 	/* In quick mode (for mandocdb), abort after the NAME section. */
 
 	if (man->quick && tok == MAN_SH) {
 		n = man->last;
 		if (n->type == ROFFT_BODY &&
 		    strcmp(n->prev->child->string, "NAME"))
 			return 2;
 	}
 
 	/*
 	 * If we are in a next-line scope for a block head,
 	 * close it out now and switch to the body,
 	 * unless the next-line scope is allowed to continue.
 	 */
 
 	if ( ! bline || man->flags & MAN_ELINE ||
 	    man_macros[tok].flags & MAN_NSCOPED)
 		return 1;
 
 	assert(man->flags & MAN_BLINE);
 	man->flags &= ~MAN_BLINE;
 
 	man_unscope(man, man->last->parent);
 	roff_body_alloc(man, ln, ppos, man->last->tok);
 	return 1;
 }
 
 void
 man_breakscope(struct roff_man *man, int tok)
 {
 	struct roff_node *n;
 
 	/*
 	 * An element next line scope is open,
 	 * and the new macro is not allowed inside elements.
 	 * Delete the element that is being broken.
 	 */
 
 	if (man->flags & MAN_ELINE && (tok == TOKEN_NONE ||
 	    ! (man_macros[tok].flags & MAN_NSCOPED))) {
 		n = man->last;
 		assert(n->type != ROFFT_TEXT);
 		if (man_macros[n->tok].flags & MAN_NSCOPED)
 			n = n->parent;
 
 		mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse,
 		    n->line, n->pos, "%s breaks %s",
 		    tok == TOKEN_NONE ? "TS" : man_macronames[tok],
 		    man_macronames[n->tok]);
 
 		roff_node_delete(man, n);
 		man->flags &= ~MAN_ELINE;
 	}
 
 	/*
 	 * Weird special case:
 	 * Switching fill mode closes section headers.
 	 */
 
 	if (man->flags & MAN_BLINE &&
 	    (tok == MAN_nf || tok == MAN_fi) &&
 	    (man->last->tok == MAN_SH || man->last->tok == MAN_SS)) {
 		n = man->last;
 		man_unscope(man, n);
 		roff_body_alloc(man, n->line, n->pos, n->tok);
 		man->flags &= ~MAN_BLINE;
 	}
 
 	/*
 	 * A block header next line scope is open,
 	 * and the new macro is not allowed inside block headers.
 	 * Delete the block that is being broken.
 	 */
 
 	if (man->flags & MAN_BLINE && (tok == TOKEN_NONE ||
 	    man_macros[tok].flags & MAN_BSCOPE)) {
 		n = man->last;
 		if (n->type == ROFFT_TEXT)
 			n = n->parent;
 		if ( ! (man_macros[n->tok].flags & MAN_BSCOPE))
 			n = n->parent;
 
 		assert(n->type == ROFFT_HEAD);
 		n = n->parent;
 		assert(n->type == ROFFT_BLOCK);
 		assert(man_macros[n->tok].flags & MAN_SCOPED);
 
 		mandoc_vmsg(MANDOCERR_BLK_LINE, man->parse,
 		    n->line, n->pos, "%s breaks %s",
 		    tok == TOKEN_NONE ? "TS" : man_macronames[tok],
 		    man_macronames[n->tok]);
 
 		roff_node_delete(man, n);
 		man->flags &= ~MAN_BLINE;
 	}
 }
 
 const struct mparse *
 man_mparse(const struct roff_man *man)
 {
 
 	assert(man && man->parse);
 	return man->parse;
 }
 
 void
 man_state(struct roff_man *man, struct roff_node *n)
 {
 
 	switch(n->tok) {
 	case MAN_nf:
 	case MAN_EX:
-		if (man->flags & MAN_LITERAL && ! (n->flags & MAN_VALID))
+		if (man->flags & MAN_LITERAL && ! (n->flags & NODE_VALID))
 			mandoc_msg(MANDOCERR_NF_SKIP, man->parse,
 			    n->line, n->pos, "nf");
 		man->flags |= MAN_LITERAL;
 		break;
 	case MAN_fi:
 	case MAN_EE:
 		if ( ! (man->flags & MAN_LITERAL) &&
-		     ! (n->flags & MAN_VALID))
+		     ! (n->flags & NODE_VALID))
 			mandoc_msg(MANDOCERR_FI_SKIP, man->parse,
 			    n->line, n->pos, "fi");
 		man->flags &= ~MAN_LITERAL;
 		break;
 	default:
 		break;
 	}
-	man->last->flags |= MAN_VALID;
+	man->last->flags |= NODE_VALID;
 }
 
 void
 man_validate(struct roff_man *man)
 {
 
 	man->last = man->first;
 	man_node_validate(man);
 	man->flags &= ~MAN_LITERAL;
 }
Index: stable/11/contrib/mdocml/man.conf.5
===================================================================
--- stable/11/contrib/mdocml/man.conf.5	(revision 316419)
+++ stable/11/contrib/mdocml/man.conf.5	(revision 316420)
@@ -1,131 +1,131 @@
-.\"	$Id: man.conf.5,v 1.3 2015/03/27 21:33:20 schwarze Exp $
+.\"	$Id: man.conf.5,v 1.4 2016/12/28 22:52:17 schwarze Exp $
 .\"
 .\" Copyright (c) 2015 Ingo Schwarze 
 .\"
 .\" 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.
 .\"
-.Dd $Mdocdate: March 27 2015 $
+.Dd $Mdocdate: December 28 2016 $
 .Dt MAN.CONF 5
 .Os
 .Sh NAME
 .Nm man.conf
 .Nd configuration file for man
 .Sh DESCRIPTION
 This is the configuration file
 for the
 .Xr man 1 ,
 .Xr apropos 1 ,
 and
 .Xr makewhatis 8
 utilities.
 Its presence, and all directives, are optional.
 .Pp
 This file is an ASCII text file.
 Leading whitespace on lines, lines starting with
 .Sq # ,
 and blank lines are ignored.
 Words are separated by whitespace.
 The first word on each line is the name of a configuration directive.
 .Pp
 The following directives are supported:
 .Bl -tag -width Ds
 .It Ic manpath Ar path
 Override the default search
 .Ar path
 for
 .Xr man 1 ,
 .Xr apropos 1 ,
 and
 .Xr makewhatis 8 .
 It can be used multiple times to specify multiple paths,
 with the order determining the manual page search order.
 .Pp
 Each path is a tree containing subdirectories
 whose names consist of the strings
 .Sq man
 and/or
 .Sq cat
 followed by the names of sections, usually single digits.
 The former are supposed to contain unformatted manual pages in
 .Xr mdoc 7
 and/or
 .Xr man 7
 format; file names should end with the name of the section
 preceded by a dot.
 The latter should contain preformatted manual pages;
 file names should end with
 .Ql .0 .
 .Pp
 Creating a
 .Xr mandoc.db 5
 database with
 .Xr makewhatis 8
 in each directory configured with
 .Ic manpath
 is recommended and necessary for
 .Xr apropos 1
 to work, but not strictly required for
 .Xr man 1 .
 .It Ic output Ar option Op Ar value
 Configure the default value of an output option.
 These directives are overridden by the
 .Fl O
 command line options of the same names.
 For details, see the
 .Xr mandoc 1
 manual.
 .Pp
 .Bl -column fragment integer "ascii, utf8" -compact
 .It Ar option   Ta Ar value Ta used by Fl T Ta purpose
 .It Ta Ta Ta
 .It Ic fragment Ta none     Ta Cm html Ta print only body
 .It Ic includes Ta string   Ta Cm html Ta path to header files
 .It Ic indent   Ta integer  Ta Cm ascii , utf8 Ta left margin
-.It Ic man      Ta string   Ta Cm html Ta path for Xr links
+.It Ic man      Ta string   Ta Cm html Ta path for \&Xr links
 .It Ic paper    Ta string   Ta Cm ps , pdf Ta paper size
 .It Ic style    Ta string   Ta Cm html Ta CSS file
 .It Ic width    Ta integer  Ta Cm ascii , utf8 Ta right margin
 .El
 .It Ic _whatdb Ar path Ns Cm /whatis.db
 This directive provides the same functionality as
 .Ic manpath ,
 but using a historic and misleading syntax.
 It is kept for backward compatibility for now,
 but will eventually be removed.
 .El
 .Sh FILES
 .Pa /etc/man.conf
 .Sh EXAMPLES
 The following configuration file reproduces the defaults:
 installing it is equivalent to not having a
 .Nm
 file at all.
 .Bd -literal -offset indent
 manpath /usr/share/man
 manpath /usr/X11R6/man
 manpath /usr/local/man
 .Ed
 .Sh SEE ALSO
 .Xr apropos 1 ,
 .Xr man 1 ,
 .Xr makewhatis 8
 .Sh HISTORY
 A relatively complicated
 .Nm
 file format first appeared in
 .Bx 4.3 Reno .
 For
 .Ox 5.8 ,
 it was redesigned from scratch, aiming for simplicity.
 .Sh AUTHORS
 .An Ingo Schwarze Aq Mt schwarze@openbsd.org
Index: stable/11/contrib/mdocml/man_hash.c
===================================================================
--- stable/11/contrib/mdocml/man_hash.c	(revision 316419)
+++ stable/11/contrib/mdocml/man_hash.c	(revision 316420)
@@ -1,101 +1,103 @@
-/*	$Id: man_hash.c,v 1.34 2015/10/06 18:32:19 schwarze Exp $ */
+/*	$Id: man_hash.c,v 1.35 2016/07/15 18:03:45 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons 
  * Copyright (c) 2015 Ingo Schwarze 
  *
  * 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 "config.h"
 
 #include 
 
 #include 
 #include 
 #include 
 #include 
 
+#include "mandoc.h"
 #include "roff.h"
 #include "man.h"
+#include "libmandoc.h"
 #include "libman.h"
 
 #define	HASH_DEPTH	 6
 
 #define	HASH_ROW(x) do { \
 		if (isupper((unsigned char)(x))) \
 			(x) -= 65; \
 		else \
 			(x) -= 97; \
 		(x) *= HASH_DEPTH; \
 	} while (/* CONSTCOND */ 0)
 
 /*
  * Lookup table is indexed first by lower-case first letter (plus one
  * for the period, which is stored in the last row), then by lower or
  * uppercase second letter.  Buckets correspond to the index of the
  * macro (the integer value of the enum stored as a char to save a bit
  * of space).
  */
 static	unsigned char	 table[26 * HASH_DEPTH];
 
 
 void
 man_hash_init(void)
 {
 	int		 i, j, x;
 
 	if (*table != '\0')
 		return;
 
 	memset(table, UCHAR_MAX, sizeof(table));
 
 	for (i = 0; i < (int)MAN_MAX; i++) {
 		x = man_macronames[i][0];
 
 		assert(isalpha((unsigned char)x));
 
 		HASH_ROW(x);
 
 		for (j = 0; j < HASH_DEPTH; j++)
 			if (UCHAR_MAX == table[x + j]) {
 				table[x + j] = (unsigned char)i;
 				break;
 			}
 
 		assert(j < HASH_DEPTH);
 	}
 }
 
 int
 man_hash_find(const char *tmp)
 {
 	int		 x, y, i;
 	int		 tok;
 
 	if ('\0' == (x = tmp[0]))
 		return TOKEN_NONE;
 	if ( ! (isalpha((unsigned char)x)))
 		return TOKEN_NONE;
 
 	HASH_ROW(x);
 
 	for (i = 0; i < HASH_DEPTH; i++) {
 		if (UCHAR_MAX == (y = table[x + i]))
 			return TOKEN_NONE;
 
 		tok = y;
 		if (0 == strcmp(tmp, man_macronames[tok]))
 			return tok;
 	}
 
 	return TOKEN_NONE;
 }
Index: stable/11/contrib/mdocml/man_html.c
===================================================================
--- stable/11/contrib/mdocml/man_html.c	(revision 316419)
+++ stable/11/contrib/mdocml/man_html.c	(revision 316420)
@@ -1,671 +1,616 @@
-/*	$Id: man_html.c,v 1.120 2016/01/08 17:48:09 schwarze Exp $ */
+/*	$Id: man_html.c,v 1.129 2017/01/21 01:20:32 schwarze Exp $ */
 /*
  * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons 
- * Copyright (c) 2013, 2014, 2015 Ingo Schwarze 
+ * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze 
  *
  * 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 AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h"
 
 #include 
 
 #include 
 #include 
 #include 
 #include 
 #include 
 
 #include "mandoc_aux.h"
 #include "roff.h"
 #include "man.h"
 #include "out.h"
 #include "html.h"
 #include "main.h"
 
 /* TODO: preserve ident widths. */
 /* FIXME: have PD set the default vspace width. */
 
 #define	INDENT		  5
 
 #define	MAN_ARGS	  const struct roff_meta *man, \
 			  const struct roff_node *n, \
 			  struct mhtml *mh, \
 			  struct html *h
 
 struct	mhtml {
 	int		  fl;
 #define	MANH_LITERAL	 (1 << 0) /* literal context */
 };
 
 struct	htmlman {
 	int		(*pre)(MAN_ARGS);
 	int		(*post)(MAN_ARGS);
 };
 
 static	void		  print_bvspace(struct html *,
 				const struct roff_node *);
 static	void		  print_man_head(MAN_ARGS);
 static	void		  print_man_nodelist(MAN_ARGS);
 static	void		  print_man_node(MAN_ARGS);
 static	int		  a2width(const struct roff_node *,
 				struct roffsu *);
 static	int		  man_B_pre(MAN_ARGS);
 static	int		  man_HP_pre(MAN_ARGS);
 static	int		  man_IP_pre(MAN_ARGS);
 static	int		  man_I_pre(MAN_ARGS);
 static	int		  man_OP_pre(MAN_ARGS);
 static	int		  man_PP_pre(MAN_ARGS);
 static	int		  man_RS_pre(MAN_ARGS);
 static	int		  man_SH_pre(MAN_ARGS);
 static	int		  man_SM_pre(MAN_ARGS);
 static	int		  man_SS_pre(MAN_ARGS);
 static	int		  man_UR_pre(MAN_ARGS);
 static	int		  man_alt_pre(MAN_ARGS);
 static	int		  man_br_pre(MAN_ARGS);
 static	int		  man_ign_pre(MAN_ARGS);
 static	int		  man_in_pre(MAN_ARGS);
 static	int		  man_literal_pre(MAN_ARGS);
 static	void		  man_root_post(MAN_ARGS);
 static	void		  man_root_pre(MAN_ARGS);
 
 static	const struct htmlman mans[MAN_MAX] = {
 	{ man_br_pre, NULL }, /* br */
 	{ NULL, NULL }, /* TH */
 	{ man_SH_pre, NULL }, /* SH */
 	{ man_SS_pre, NULL }, /* SS */
 	{ man_IP_pre, NULL }, /* TP */
 	{ man_PP_pre, NULL }, /* LP */
 	{ man_PP_pre, NULL }, /* PP */
 	{ man_PP_pre, NULL }, /* P */
 	{ man_IP_pre, NULL }, /* IP */
 	{ man_HP_pre, NULL }, /* HP */
 	{ man_SM_pre, NULL }, /* SM */
 	{ man_SM_pre, NULL }, /* SB */
 	{ man_alt_pre, NULL }, /* BI */
 	{ man_alt_pre, NULL }, /* IB */
 	{ man_alt_pre, NULL }, /* BR */
 	{ man_alt_pre, NULL }, /* RB */
 	{ NULL, NULL }, /* R */
 	{ man_B_pre, NULL }, /* B */
 	{ man_I_pre, NULL }, /* I */
 	{ man_alt_pre, NULL }, /* IR */
 	{ man_alt_pre, NULL }, /* RI */
 	{ man_br_pre, NULL }, /* sp */
 	{ man_literal_pre, NULL }, /* nf */
 	{ man_literal_pre, NULL }, /* fi */
 	{ NULL, NULL }, /* RE */
 	{ man_RS_pre, NULL }, /* RS */
 	{ man_ign_pre, NULL }, /* DT */
 	{ man_ign_pre, NULL }, /* UC */
 	{ man_ign_pre, NULL }, /* PD */
 	{ man_ign_pre, NULL }, /* AT */
 	{ man_in_pre, NULL }, /* in */
 	{ man_ign_pre, NULL }, /* ft */
 	{ man_OP_pre, NULL }, /* OP */
 	{ man_literal_pre, NULL }, /* EX */
 	{ man_literal_pre, NULL }, /* EE */
 	{ man_UR_pre, NULL }, /* UR */
 	{ NULL, NULL }, /* UE */
 	{ man_ign_pre, NULL }, /* ll */
 };
 
 
 /*
  * Printing leading vertical space before a block.
  * This is used for the paragraph macros.
  * The rules are pretty simple, since there's very little nesting going
  * on here.  Basically, if we're the first within another block (SS/SH),
  * then don't emit vertical space.  If we are (RS), then do.  If not the
  * first, print it.
  */
 static void
 print_bvspace(struct html *h, const struct roff_node *n)
 {
 
 	if (n->body && n->body->child)
 		if (n->body->child->type == ROFFT_TBL)
 			return;
 
 	if (n->parent->type == ROFFT_ROOT || n->parent->tok != MAN_RS)
 		if (NULL == n->prev)
 			return;
 
 	print_paragraph(h);
 }
 
 void
 html_man(void *arg, const struct roff_man *man)
 {
 	struct mhtml	 mh;
-	struct htmlpair	 tag;
 	struct html	*h;
-	struct tag	*t, *tt;
+	struct tag	*t;
 
 	memset(&mh, 0, sizeof(mh));
-	PAIR_CLASS_INIT(&tag, "mandoc");
 	h = (struct html *)arg;
 
-	if ( ! (HTML_FRAGMENT & h->oflags)) {
+	if ((h->oflags & HTML_FRAGMENT) == 0) {
 		print_gen_decls(h);
-		t = print_otag(h, TAG_HTML, 0, NULL);
-		tt = print_otag(h, TAG_HEAD, 0, NULL);
+		print_otag(h, TAG_HTML, "");
+		t = print_otag(h, TAG_HEAD, "");
 		print_man_head(&man->meta, man->first, &mh, h);
-		print_tagq(h, tt);
-		print_otag(h, TAG_BODY, 0, NULL);
-		print_otag(h, TAG_DIV, 1, &tag);
-	} else
-		t = print_otag(h, TAG_DIV, 1, &tag);
+		print_tagq(h, t);
+		print_otag(h, TAG_BODY, "");
+	}
 
-	print_man_nodelist(&man->meta, man->first, &mh, h);
+	man_root_pre(&man->meta, man->first, &mh, h);
+	t = print_otag(h, TAG_DIV, "c", "manual-text");
+	print_man_nodelist(&man->meta, man->first->child, &mh, h);
 	print_tagq(h, t);
-	putchar('\n');
+	man_root_post(&man->meta, man->first, &mh, h);
+	print_tagq(h, NULL);
 }
 
 static void
 print_man_head(MAN_ARGS)
 {
+	char	*cp;
 
 	print_gen_head(h);
-	assert(man->title);
-	assert(man->msec);
-	bufcat_fmt(h, "%s(%s)", man->title, man->msec);
-	print_otag(h, TAG_TITLE, 0, NULL);
-	print_text(h, h->buf);
+	mandoc_asprintf(&cp, "%s(%s)", man->title, man->msec);
+	print_otag(h, TAG_TITLE, "");
+	print_text(h, cp);
+	free(cp);
 }
 
 static void
 print_man_nodelist(MAN_ARGS)
 {
 
 	while (n != NULL) {
 		print_man_node(man, n, mh, h);
 		n = n->next;
 	}
 }
 
 static void
 print_man_node(MAN_ARGS)
 {
 	int		 child;
 	struct tag	*t;
 
 	child = 1;
 	t = h->tags.head;
 
 	switch (n->type) {
-	case ROFFT_ROOT:
-		man_root_pre(man, n, mh, h);
-		break;
 	case ROFFT_TEXT:
 		if ('\0' == *n->string) {
 			print_paragraph(h);
 			return;
 		}
-		if (n->flags & MAN_LINE && (*n->string == ' ' ||
+		if (n->flags & NODE_LINE && (*n->string == ' ' ||
 		    (n->prev != NULL && mh->fl & MANH_LITERAL &&
 		     ! (h->flags & HTML_NONEWLINE))))
-			print_otag(h, TAG_BR, 0, NULL);
+			print_otag(h, TAG_BR, "");
 		print_text(h, n->string);
 		return;
 	case ROFFT_EQN:
-		if (n->flags & MAN_LINE)
-			putchar('\n');
 		print_eqn(h, n->eqn);
 		break;
 	case ROFFT_TBL:
 		/*
 		 * This will take care of initialising all of the table
 		 * state data for the first table, then tearing it down
 		 * for the last one.
 		 */
 		print_tbl(h, n->span);
 		return;
 	default:
 		/*
 		 * Close out scope of font prior to opening a macro
 		 * scope.
 		 */
 		if (HTMLFONT_NONE != h->metac) {
 			h->metal = h->metac;
 			h->metac = HTMLFONT_NONE;
 		}
 
 		/*
 		 * Close out the current table, if it's open, and unset
 		 * the "meta" table state.  This will be reopened on the
 		 * next table element.
 		 */
 		if (h->tblt) {
 			print_tblclose(h);
 			t = h->tags.head;
 		}
 		if (mans[n->tok].pre)
 			child = (*mans[n->tok].pre)(man, n, mh, h);
 		break;
 	}
 
 	if (child && n->child)
 		print_man_nodelist(man, n->child, mh, h);
 
 	/* This will automatically close out any font scope. */
 	print_stagq(h, t);
 
 	switch (n->type) {
-	case ROFFT_ROOT:
-		man_root_post(man, n, mh, h);
-		break;
 	case ROFFT_EQN:
 		break;
 	default:
 		if (mans[n->tok].post)
 			(*mans[n->tok].post)(man, n, mh, h);
 		break;
 	}
 }
 
 static int
 a2width(const struct roff_node *n, struct roffsu *su)
 {
 
 	if (n->type != ROFFT_TEXT)
 		return 0;
 	if (a2roffsu(n->string, su, SCALE_EN))
 		return 1;
 
 	return 0;
 }
 
 static void
 man_root_pre(MAN_ARGS)
 {
-	struct htmlpair	 tag;
 	struct tag	*t, *tt;
 	char		*title;
 
 	assert(man->title);
 	assert(man->msec);
 	mandoc_asprintf(&title, "%s(%s)", man->title, man->msec);
 
-	PAIR_CLASS_INIT(&tag, "head");
-	t = print_otag(h, TAG_TABLE, 1, &tag);
+	t = print_otag(h, TAG_TABLE, "c", "head");
+	print_otag(h, TAG_TBODY, "");
+	tt = print_otag(h, TAG_TR, "");
 
-	print_otag(h, TAG_TBODY, 0, NULL);
-
-	tt = print_otag(h, TAG_TR, 0, NULL);
-
-	PAIR_CLASS_INIT(&tag, "head-ltitle");
-	print_otag(h, TAG_TD, 1, &tag);
+	print_otag(h, TAG_TD, "c", "head-ltitle");
 	print_text(h, title);
 	print_stagq(h, tt);
 
-	PAIR_CLASS_INIT(&tag, "head-vol");
-	print_otag(h, TAG_TD, 1, &tag);
+	print_otag(h, TAG_TD, "c", "head-vol");
 	if (NULL != man->vol)
 		print_text(h, man->vol);
 	print_stagq(h, tt);
 
-	PAIR_CLASS_INIT(&tag, "head-rtitle");
-	print_otag(h, TAG_TD, 1, &tag);
+	print_otag(h, TAG_TD, "c", "head-rtitle");
 	print_text(h, title);
 	print_tagq(h, t);
 	free(title);
 }
 
 static void
 man_root_post(MAN_ARGS)
 {
-	struct htmlpair	 tag;
 	struct tag	*t, *tt;
 
-	PAIR_CLASS_INIT(&tag, "foot");
-	t = print_otag(h, TAG_TABLE, 1, &tag);
+	t = print_otag(h, TAG_TABLE, "c", "foot");
+	tt = print_otag(h, TAG_TR, "");
 
-	tt = print_otag(h, TAG_TR, 0, NULL);
-
-	PAIR_CLASS_INIT(&tag, "foot-date");
-	print_otag(h, TAG_TD, 1, &tag);
-
-	assert(man->date);
+	print_otag(h, TAG_TD, "c", "foot-date");
 	print_text(h, man->date);
 	print_stagq(h, tt);
 
-	PAIR_CLASS_INIT(&tag, "foot-os");
-	print_otag(h, TAG_TD, 1, &tag);
-
+	print_otag(h, TAG_TD, "c", "foot-os");
 	if (man->os)
 		print_text(h, man->os);
 	print_tagq(h, t);
 }
 
 
 static int
 man_br_pre(MAN_ARGS)
 {
 	struct roffsu	 su;
-	struct htmlpair	 tag;
 
 	SCALE_VS_INIT(&su, 1);
 
 	if (MAN_sp == n->tok) {
 		if (NULL != (n = n->child))
 			if ( ! a2roffsu(n->string, &su, SCALE_VS))
 				su.scale = 1.0;
 	} else
 		su.scale = 0.0;
 
-	bufinit(h);
-	bufcat_su(h, "height", &su);
-	PAIR_STYLE_INIT(&tag, h);
-	print_otag(h, TAG_DIV, 1, &tag);
+	print_otag(h, TAG_DIV, "suh", &su);
 
 	/* So the div isn't empty: */
 	print_text(h, "\\~");
 
 	return 0;
 }
 
 static int
 man_SH_pre(MAN_ARGS)
 {
-	struct htmlpair	 tag;
-
 	if (n->type == ROFFT_BLOCK) {
 		mh->fl &= ~MANH_LITERAL;
-		PAIR_CLASS_INIT(&tag, "section");
-		print_otag(h, TAG_DIV, 1, &tag);
 		return 1;
 	} else if (n->type == ROFFT_BODY)
 		return 1;
 
-	print_otag(h, TAG_H1, 0, NULL);
+	print_otag(h, TAG_H1, "c", "Sh");
 	return 1;
 }
 
 static int
 man_alt_pre(MAN_ARGS)
 {
 	const struct roff_node	*nn;
 	int		 i, savelit;
 	enum htmltag	 fp;
 	struct tag	*t;
 
 	if ((savelit = mh->fl & MANH_LITERAL))
-		print_otag(h, TAG_BR, 0, NULL);
+		print_otag(h, TAG_BR, "");
 
 	mh->fl &= ~MANH_LITERAL;
 
 	for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
 		t = NULL;
 		switch (n->tok) {
 		case MAN_BI:
 			fp = i % 2 ? TAG_I : TAG_B;
 			break;
 		case MAN_IB:
 			fp = i % 2 ? TAG_B : TAG_I;
 			break;
 		case MAN_RI:
 			fp = i % 2 ? TAG_I : TAG_MAX;
 			break;
 		case MAN_IR:
 			fp = i % 2 ? TAG_MAX : TAG_I;
 			break;
 		case MAN_BR:
 			fp = i % 2 ? TAG_MAX : TAG_B;
 			break;
 		case MAN_RB:
 			fp = i % 2 ? TAG_B : TAG_MAX;
 			break;
 		default:
 			abort();
 		}
 
 		if (i)
 			h->flags |= HTML_NOSPACE;
 
 		if (TAG_MAX != fp)
-			t = print_otag(h, fp, 0, NULL);
+			t = print_otag(h, fp, "");
 
 		print_man_node(man, nn, mh, h);
 
 		if (t)
 			print_tagq(h, t);
 	}
 
 	if (savelit)
 		mh->fl |= MANH_LITERAL;
 
 	return 0;
 }
 
 static int
 man_SM_pre(MAN_ARGS)
 {
-
-	print_otag(h, TAG_SMALL, 0, NULL);
+	print_otag(h, TAG_SMALL, "");
 	if (MAN_SB == n->tok)
-		print_otag(h, TAG_B, 0, NULL);
+		print_otag(h, TAG_B, "");
 	return 1;
 }
 
 static int
 man_SS_pre(MAN_ARGS)
 {
-	struct htmlpair	 tag;
-
 	if (n->type == ROFFT_BLOCK) {
 		mh->fl &= ~MANH_LITERAL;
-		PAIR_CLASS_INIT(&tag, "subsection");
-		print_otag(h, TAG_DIV, 1, &tag);
 		return 1;
 	} else if (n->type == ROFFT_BODY)
 		return 1;
 
-	print_otag(h, TAG_H2, 0, NULL);
+	print_otag(h, TAG_H2, "c", "Ss");
 	return 1;
 }
 
 static int
 man_PP_pre(MAN_ARGS)
 {
 
 	if (n->type == ROFFT_HEAD)
 		return 0;
 	else if (n->type == ROFFT_BLOCK)
 		print_bvspace(h, n);
 
 	return 1;
 }
 
 static int
 man_IP_pre(MAN_ARGS)
 {
 	const struct roff_node	*nn;
 
 	if (n->type == ROFFT_BODY) {
-		print_otag(h, TAG_DD, 0, NULL);
+		print_otag(h, TAG_DD, "c", "It-tag");
 		return 1;
 	} else if (n->type != ROFFT_HEAD) {
-		print_otag(h, TAG_DL, 0, NULL);
+		print_otag(h, TAG_DL, "c", "Bl-tag");
 		return 1;
 	}
 
 	/* FIXME: width specification. */
 
-	print_otag(h, TAG_DT, 0, NULL);
+	print_otag(h, TAG_DT, "c", "It-tag");
 
 	/* For IP, only print the first header element. */
 
 	if (MAN_IP == n->tok && n->child)
 		print_man_node(man, n->child, mh, h);
 
 	/* For TP, only print next-line header elements. */
 
 	if (MAN_TP == n->tok) {
 		nn = n->child;
-		while (NULL != nn && 0 == (MAN_LINE & nn->flags))
+		while (NULL != nn && 0 == (NODE_LINE & nn->flags))
 			nn = nn->next;
 		while (NULL != nn) {
 			print_man_node(man, nn, mh, h);
 			nn = nn->next;
 		}
 	}
 
 	return 0;
 }
 
 static int
 man_HP_pre(MAN_ARGS)
 {
-	struct htmlpair	 tag[2];
-	struct roffsu	 su;
+	struct roffsu	 sum, sui;
 	const struct roff_node *np;
 
 	if (n->type == ROFFT_HEAD)
 		return 0;
 	else if (n->type != ROFFT_BLOCK)
 		return 1;
 
 	np = n->head->child;
 
-	if (NULL == np || ! a2width(np, &su))
-		SCALE_HS_INIT(&su, INDENT);
+	if (np == NULL || !a2width(np, &sum))
+		SCALE_HS_INIT(&sum, INDENT);
 
-	bufinit(h);
+	sui.unit = sum.unit;
+	sui.scale = -sum.scale;
 
 	print_bvspace(h, n);
-	bufcat_su(h, "margin-left", &su);
-	su.scale = -su.scale;
-	bufcat_su(h, "text-indent", &su);
-	PAIR_STYLE_INIT(&tag[0], h);
-	PAIR_CLASS_INIT(&tag[1], "spacer");
-	print_otag(h, TAG_DIV, 2, tag);
+	print_otag(h, TAG_DIV, "csului", "Pp", &sum, &sui);
 	return 1;
 }
 
 static int
 man_OP_pre(MAN_ARGS)
 {
 	struct tag	*tt;
-	struct htmlpair	 tag;
 
 	print_text(h, "[");
 	h->flags |= HTML_NOSPACE;
-	PAIR_CLASS_INIT(&tag, "opt");
-	tt = print_otag(h, TAG_SPAN, 1, &tag);
+	tt = print_otag(h, TAG_SPAN, "c", "Op");
 
 	if (NULL != (n = n->child)) {
-		print_otag(h, TAG_B, 0, NULL);
+		print_otag(h, TAG_B, "");
 		print_text(h, n->string);
 	}
 
 	print_stagq(h, tt);
 
 	if (NULL != n && NULL != n->next) {
-		print_otag(h, TAG_I, 0, NULL);
+		print_otag(h, TAG_I, "");
 		print_text(h, n->next->string);
 	}
 
 	print_stagq(h, tt);
 	h->flags |= HTML_NOSPACE;
 	print_text(h, "]");
 	return 0;
 }
 
 static int
 man_B_pre(MAN_ARGS)
 {
-
-	print_otag(h, TAG_B, 0, NULL);
+	print_otag(h, TAG_B, "");
 	return 1;
 }
 
 static int
 man_I_pre(MAN_ARGS)
 {
-
-	print_otag(h, TAG_I, 0, NULL);
+	print_otag(h, TAG_I, "");
 	return 1;
 }
 
 static int
 man_literal_pre(MAN_ARGS)
 {
 
 	if (MAN_fi == n->tok || MAN_EE == n->tok) {
-		print_otag(h, TAG_BR, 0, NULL);
+		print_otag(h, TAG_BR, "");
 		mh->fl &= ~MANH_LITERAL;
 	} else
 		mh->fl |= MANH_LITERAL;
 
 	return 0;
 }
 
 static int
 man_in_pre(MAN_ARGS)
 {
-
-	print_otag(h, TAG_BR, 0, NULL);
+	print_otag(h, TAG_BR, "");
 	return 0;
 }
 
 static int
 man_ign_pre(MAN_ARGS)
 {
 
 	return 0;
 }
 
 static int
 man_RS_pre(MAN_ARGS)
 {
-	struct htmlpair	 tag;
 	struct roffsu	 su;
 
 	if (n->type == ROFFT_HEAD)
 		return 0;
 	else if (n->type == ROFFT_BODY)
 		return 1;
 
 	SCALE_HS_INIT(&su, INDENT);
 	if (n->head->child)
 		a2width(n->head->child, &su);
 
-	bufinit(h);
-	bufcat_su(h, "margin-left", &su);
-	PAIR_STYLE_INIT(&tag, h);
-	print_otag(h, TAG_DIV, 1, &tag);
+	print_otag(h, TAG_DIV, "sul", &su);
 	return 1;
 }
 
 static int
 man_UR_pre(MAN_ARGS)
 {
-	struct htmlpair		 tag[2];
-
 	n = n->child;
 	assert(n->type == ROFFT_HEAD);
 	if (n->child != NULL) {
 		assert(n->child->type == ROFFT_TEXT);
-		PAIR_CLASS_INIT(&tag[0], "link-ext");
-		PAIR_HREF_INIT(&tag[1], n->child->string);
-		print_otag(h, TAG_A, 2, tag);
+		print_otag(h, TAG_A, "ch", "Lk", n->child->string);
 	}
 
 	assert(n->next->type == ROFFT_BODY);
 	if (n->next->child != NULL)
 		n = n->next;
 
 	print_man_nodelist(man, n->child, mh, h);
 
 	return 0;
 }
Index: stable/11/contrib/mdocml/man_macro.c
===================================================================
--- stable/11/contrib/mdocml/man_macro.c	(revision 316419)
+++ stable/11/contrib/mdocml/man_macro.c	(revision 316420)
@@ -1,413 +1,413 @@
-/*	$Id: man_macro.c,v 1.114 2016/01/08 17:48:09 schwarze Exp $ */
+/*	$Id: man_macro.c,v 1.115 2017/01/10 13:47:00 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons 
  * Copyright (c) 2012, 2013, 2014, 2015 Ingo Schwarze 
  * Copyright (c) 2013 Franco Fichtner 
  *
  * 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 AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h"
 
 #include 
 
 #include 
 #include 
 #include 
 #include 
 
 #include "mandoc.h"
 #include "roff.h"
 #include "man.h"
 #include "libmandoc.h"
 #include "roff_int.h"
 #include "libman.h"
 
 static	void		 blk_close(MACRO_PROT_ARGS);
 static	void		 blk_exp(MACRO_PROT_ARGS);
 static	void		 blk_imp(MACRO_PROT_ARGS);
 static	void		 in_line_eoln(MACRO_PROT_ARGS);
 static	int		 man_args(struct roff_man *, int,
 				int *, char *, char **);
 static	void		 rew_scope(struct roff_man *, int);
 
 const	struct man_macro __man_macros[MAN_MAX] = {
 	{ in_line_eoln, MAN_NSCOPED }, /* br */
 	{ in_line_eoln, MAN_BSCOPE }, /* TH */
 	{ blk_imp, MAN_BSCOPE | MAN_SCOPED }, /* SH */
 	{ blk_imp, MAN_BSCOPE | MAN_SCOPED }, /* SS */
 	{ blk_imp, MAN_BSCOPE | MAN_SCOPED }, /* TP */
 	{ blk_imp, MAN_BSCOPE }, /* LP */
 	{ blk_imp, MAN_BSCOPE }, /* PP */
 	{ blk_imp, MAN_BSCOPE }, /* P */
 	{ blk_imp, MAN_BSCOPE }, /* IP */
 	{ blk_imp, MAN_BSCOPE }, /* HP */
 	{ in_line_eoln, MAN_SCOPED | MAN_JOIN }, /* SM */
 	{ in_line_eoln, MAN_SCOPED | MAN_JOIN }, /* SB */
 	{ in_line_eoln, 0 }, /* BI */
 	{ in_line_eoln, 0 }, /* IB */
 	{ in_line_eoln, 0 }, /* BR */
 	{ in_line_eoln, 0 }, /* RB */
 	{ in_line_eoln, MAN_SCOPED | MAN_JOIN }, /* R */
 	{ in_line_eoln, MAN_SCOPED | MAN_JOIN }, /* B */
 	{ in_line_eoln, MAN_SCOPED | MAN_JOIN }, /* I */
 	{ in_line_eoln, 0 }, /* IR */
 	{ in_line_eoln, 0 }, /* RI */
 	{ in_line_eoln, MAN_NSCOPED }, /* sp */
 	{ in_line_eoln, MAN_NSCOPED }, /* nf */
 	{ in_line_eoln, MAN_NSCOPED }, /* fi */
 	{ blk_close, MAN_BSCOPE }, /* RE */
 	{ blk_exp, MAN_BSCOPE }, /* RS */
 	{ in_line_eoln, 0 }, /* DT */
 	{ in_line_eoln, 0 }, /* UC */
 	{ in_line_eoln, MAN_NSCOPED }, /* PD */
 	{ in_line_eoln, 0 }, /* AT */
 	{ in_line_eoln, 0 }, /* in */
 	{ in_line_eoln, 0 }, /* ft */
 	{ in_line_eoln, 0 }, /* OP */
 	{ in_line_eoln, MAN_BSCOPE }, /* EX */
 	{ in_line_eoln, MAN_BSCOPE }, /* EE */
 	{ blk_exp, MAN_BSCOPE }, /* UR */
 	{ blk_close, MAN_BSCOPE }, /* UE */
 	{ in_line_eoln, 0 }, /* ll */
 };
 
 const	struct man_macro * const man_macros = __man_macros;
 
 
 void
 man_unscope(struct roff_man *man, const struct roff_node *to)
 {
 	struct roff_node *n;
 
 	to = to->parent;
 	n = man->last;
 	while (n != to) {
 
 		/* Reached the end of the document? */
 
-		if (to == NULL && ! (n->flags & MAN_VALID)) {
+		if (to == NULL && ! (n->flags & NODE_VALID)) {
 			if (man->flags & (MAN_BLINE | MAN_ELINE) &&
 			    man_macros[n->tok].flags & MAN_SCOPED) {
 				mandoc_vmsg(MANDOCERR_BLK_LINE,
 				    man->parse, n->line, n->pos,
 				    "EOF breaks %s",
 				    man_macronames[n->tok]);
 				if (man->flags & MAN_ELINE)
 					man->flags &= ~MAN_ELINE;
 				else {
 					assert(n->type == ROFFT_HEAD);
 					n = n->parent;
 					man->flags &= ~MAN_BLINE;
 				}
 				man->last = n;
 				n = n->parent;
 				roff_node_delete(man, man->last);
 				continue;
 			}
 			if (n->type == ROFFT_BLOCK &&
 			    man_macros[n->tok].fp == blk_exp)
 				mandoc_msg(MANDOCERR_BLK_NOEND,
 				    man->parse, n->line, n->pos,
 				    man_macronames[n->tok]);
 		}
 
 		/*
 		 * We might delete the man->last node
 		 * in the post-validation phase.
 		 * Save a pointer to the parent such that
 		 * we know where to continue the iteration.
 		 */
 
 		man->last = n;
 		n = n->parent;
-		man->last->flags |= MAN_VALID;
+		man->last->flags |= NODE_VALID;
 	}
 
 	/*
 	 * If we ended up at the parent of the node we were
 	 * supposed to rewind to, that means the target node
 	 * got deleted, so add the next node we parse as a child
 	 * of the parent instead of as a sibling of the target.
 	 */
 
 	man->next = (man->last == to) ?
 	    ROFF_NEXT_CHILD : ROFF_NEXT_SIBLING;
 }
 
 /*
  * Rewinding entails ascending the parse tree until a coherent point,
  * for example, the `SH' macro will close out any intervening `SS'
  * scopes.  When a scope is closed, it must be validated and actioned.
  */
 static void
 rew_scope(struct roff_man *man, int tok)
 {
 	struct roff_node *n;
 
 	/* Preserve empty paragraphs before RS. */
 
 	n = man->last;
 	if (tok == MAN_RS && n->child == NULL &&
 	    (n->tok == MAN_P || n->tok == MAN_PP || n->tok == MAN_LP))
 		return;
 
 	for (;;) {
 		if (n->type == ROFFT_ROOT)
 			return;
-		if (n->flags & MAN_VALID) {
+		if (n->flags & NODE_VALID) {
 			n = n->parent;
 			continue;
 		}
 		if (n->type != ROFFT_BLOCK) {
 			if (n->parent->type == ROFFT_ROOT) {
 				man_unscope(man, n);
 				return;
 			} else {
 				n = n->parent;
 				continue;
 			}
 		}
 		if (tok != MAN_SH && (n->tok == MAN_SH ||
 		    (tok != MAN_SS && (n->tok == MAN_SS ||
 		     man_macros[n->tok].fp == blk_exp))))
 			return;
 		man_unscope(man, n);
 		n = man->last;
 	}
 }
 
 
 /*
  * Close out a generic explicit macro.
  */
 void
 blk_close(MACRO_PROT_ARGS)
 {
 	int			 ntok;
 	const struct roff_node	*nn;
 	char			*p;
 	int			 nrew, target;
 
 	nrew = 1;
 	switch (tok) {
 	case MAN_RE:
 		ntok = MAN_RS;
 		if ( ! man_args(man, line, pos, buf, &p))
 			break;
 		for (nn = man->last->parent; nn; nn = nn->parent)
 			if (nn->tok == ntok && nn->type == ROFFT_BLOCK)
 				nrew++;
 		target = strtol(p, &p, 10);
 		if (*p != '\0')
 			mandoc_vmsg(MANDOCERR_ARG_EXCESS, man->parse,
 			    line, p - buf, "RE ... %s", p);
 		if (target == 0)
 			target = 1;
 		nrew -= target;
 		if (nrew < 1) {
 			mandoc_vmsg(MANDOCERR_RE_NOTOPEN, man->parse,
 			    line, ppos, "RE %d", target);
 			return;
 		}
 		break;
 	case MAN_UE:
 		ntok = MAN_UR;
 		break;
 	default:
 		abort();
 	}
 
 	for (nn = man->last->parent; nn; nn = nn->parent)
 		if (nn->tok == ntok && nn->type == ROFFT_BLOCK && ! --nrew)
 			break;
 
 	if (nn == NULL) {
 		mandoc_msg(MANDOCERR_BLK_NOTOPEN, man->parse,
 		    line, ppos, man_macronames[tok]);
 		rew_scope(man, MAN_PP);
 	} else {
 		line = man->last->line;
 		ppos = man->last->pos;
 		ntok = man->last->tok;
 		man_unscope(man, nn);
 
 		/* Move a trailing paragraph behind the block. */
 
 		if (ntok == MAN_LP || ntok == MAN_PP || ntok == MAN_P) {
 			*pos = strlen(buf);
 			blk_imp(man, ntok, line, ppos, pos, buf);
 		}
 	}
 }
 
 void
 blk_exp(MACRO_PROT_ARGS)
 {
 	struct roff_node *head;
 	char		*p;
 	int		 la;
 
 	rew_scope(man, tok);
 	roff_block_alloc(man, line, ppos, tok);
 	head = roff_head_alloc(man, line, ppos, tok);
 
 	la = *pos;
 	if (man_args(man, line, pos, buf, &p))
 		roff_word_alloc(man, line, la, p);
 
 	if (buf[*pos] != '\0')
 		mandoc_vmsg(MANDOCERR_ARG_EXCESS,
 		    man->parse, line, *pos, "%s ... %s",
 		    man_macronames[tok], buf + *pos);
 
 	man_unscope(man, head);
 	roff_body_alloc(man, line, ppos, tok);
 }
 
 /*
  * Parse an implicit-block macro.  These contain a ROFFT_HEAD and a
  * ROFFT_BODY contained within a ROFFT_BLOCK.  Rules for closing out other
  * scopes, such as `SH' closing out an `SS', are defined in the rew
  * routines.
  */
 void
 blk_imp(MACRO_PROT_ARGS)
 {
 	int		 la;
 	char		*p;
 	struct roff_node *n;
 
 	rew_scope(man, tok);
 	n = roff_block_alloc(man, line, ppos, tok);
 	if (n->tok == MAN_SH || n->tok == MAN_SS)
 		man->flags &= ~MAN_LITERAL;
 	n = roff_head_alloc(man, line, ppos, tok);
 
 	/* Add line arguments. */
 
 	for (;;) {
 		la = *pos;
 		if ( ! man_args(man, line, pos, buf, &p))
 			break;
 		roff_word_alloc(man, line, la, p);
 	}
 
 	/*
 	 * For macros having optional next-line scope,
 	 * keep the head open if there were no arguments.
 	 * For `TP', always keep the head open.
 	 */
 
 	if (man_macros[tok].flags & MAN_SCOPED &&
 	    (tok == MAN_TP || n == man->last)) {
 		man->flags |= MAN_BLINE;
 		return;
 	}
 
 	/* Close out the head and open the body. */
 
 	man_unscope(man, n);
 	roff_body_alloc(man, line, ppos, tok);
 }
 
 void
 in_line_eoln(MACRO_PROT_ARGS)
 {
 	int		 la;
 	char		*p;
 	struct roff_node *n;
 
 	roff_elem_alloc(man, line, ppos, tok);
 	n = man->last;
 
 	for (;;) {
 		if (buf[*pos] != '\0' && (tok == MAN_br ||
 		    tok == MAN_fi || tok == MAN_nf)) {
 			mandoc_vmsg(MANDOCERR_ARG_SKIP,
 			    man->parse, line, *pos, "%s %s",
 			    man_macronames[tok], buf + *pos);
 			break;
 		}
 		if (buf[*pos] != '\0' && man->last != n &&
 		    (tok == MAN_PD || tok == MAN_ft || tok == MAN_sp)) {
 			mandoc_vmsg(MANDOCERR_ARG_EXCESS,
 			    man->parse, line, *pos, "%s ... %s",
 			    man_macronames[tok], buf + *pos);
 			break;
 		}
 		la = *pos;
 		if ( ! man_args(man, line, pos, buf, &p))
 			break;
 		if (man_macros[tok].flags & MAN_JOIN &&
 		    man->last->type == ROFFT_TEXT)
 			roff_word_append(man, p);
 		else
 			roff_word_alloc(man, line, la, p);
 	}
 
 	/*
-	 * Append MAN_EOS in case the last snipped argument
+	 * Append NODE_EOS in case the last snipped argument
 	 * ends with a dot, e.g. `.IR syslog (3).'
 	 */
 
 	if (n != man->last &&
 	    mandoc_eos(man->last->string, strlen(man->last->string)))
-		man->last->flags |= MAN_EOS;
+		man->last->flags |= NODE_EOS;
 
 	/*
 	 * If no arguments are specified and this is MAN_SCOPED (i.e.,
 	 * next-line scoped), then set our mode to indicate that we're
 	 * waiting for terms to load into our context.
 	 */
 
 	if (n == man->last && man_macros[tok].flags & MAN_SCOPED) {
 		assert( ! (man_macros[tok].flags & MAN_NSCOPED));
 		man->flags |= MAN_ELINE;
 		return;
 	}
 
 	assert(man->last->type != ROFFT_ROOT);
 	man->next = ROFF_NEXT_SIBLING;
 
 	/* Rewind our element scope. */
 
 	for ( ; man->last; man->last = man->last->parent) {
 		man_state(man, man->last);
 		if (man->last == n)
 			break;
 	}
 }
 
 void
 man_endparse(struct roff_man *man)
 {
 
 	man_unscope(man, man->first);
 	man->flags &= ~MAN_LITERAL;
 }
 
 static int
 man_args(struct roff_man *man, int line, int *pos, char *buf, char **v)
 {
 	char	 *start;
 
 	assert(*pos);
 	*v = start = buf + *pos;
 	assert(' ' != *start);
 
 	if ('\0' == *start)
 		return 0;
 
 	*v = mandoc_getarg(man->parse, v, line, pos);
 	return 1;
 }
Index: stable/11/contrib/mdocml/man_term.c
===================================================================
--- stable/11/contrib/mdocml/man_term.c	(revision 316419)
+++ stable/11/contrib/mdocml/man_term.c	(revision 316420)
@@ -1,1177 +1,1177 @@
-/*	$Id: man_term.c,v 1.187 2016/01/08 17:48:09 schwarze Exp $ */
+/*	$Id: man_term.c,v 1.188 2017/01/10 13:47:00 schwarze Exp $ */
 /*
  * Copyright (c) 2008-2012 Kristaps Dzonsons 
  * Copyright (c) 2010-2015 Ingo Schwarze 
  *
  * 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 AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h"
 
 #include 
 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 
 #include "mandoc_aux.h"
 #include "mandoc.h"
 #include "roff.h"
 #include "man.h"
 #include "out.h"
 #include "term.h"
 #include "main.h"
 
 #define	MAXMARGINS	  64 /* maximum number of indented scopes */
 
 struct	mtermp {
 	int		  fl;
 #define	MANT_LITERAL	 (1 << 0)
 	int		  lmargin[MAXMARGINS]; /* margins (incl. vis. page) */
 	int		  lmargincur; /* index of current margin */
 	int		  lmarginsz; /* actual number of nested margins */
 	size_t		  offset; /* default offset to visible page */
 	int		  pardist; /* vert. space before par., unit: [v] */
 };
 
 #define	DECL_ARGS	  struct termp *p, \
 			  struct mtermp *mt, \
 			  struct roff_node *n, \
 			  const struct roff_meta *meta
 
 struct	termact {
 	int		(*pre)(DECL_ARGS);
 	void		(*post)(DECL_ARGS);
 	int		  flags;
 #define	MAN_NOTEXT	 (1 << 0) /* Never has text children. */
 };
 
 static	void		  print_man_nodelist(DECL_ARGS);
 static	void		  print_man_node(DECL_ARGS);
 static	void		  print_man_head(struct termp *,
 				const struct roff_meta *);
 static	void		  print_man_foot(struct termp *,
 				const struct roff_meta *);
 static	void		  print_bvspace(struct termp *,
 				const struct roff_node *, int);
 
 static	int		  pre_B(DECL_ARGS);
 static	int		  pre_HP(DECL_ARGS);
 static	int		  pre_I(DECL_ARGS);
 static	int		  pre_IP(DECL_ARGS);
 static	int		  pre_OP(DECL_ARGS);
 static	int		  pre_PD(DECL_ARGS);
 static	int		  pre_PP(DECL_ARGS);
 static	int		  pre_RS(DECL_ARGS);
 static	int		  pre_SH(DECL_ARGS);
 static	int		  pre_SS(DECL_ARGS);
 static	int		  pre_TP(DECL_ARGS);
 static	int		  pre_UR(DECL_ARGS);
 static	int		  pre_alternate(DECL_ARGS);
 static	int		  pre_ft(DECL_ARGS);
 static	int		  pre_ign(DECL_ARGS);
 static	int		  pre_in(DECL_ARGS);
 static	int		  pre_literal(DECL_ARGS);
 static	int		  pre_ll(DECL_ARGS);
 static	int		  pre_sp(DECL_ARGS);
 
 static	void		  post_IP(DECL_ARGS);
 static	void		  post_HP(DECL_ARGS);
 static	void		  post_RS(DECL_ARGS);
 static	void		  post_SH(DECL_ARGS);
 static	void		  post_SS(DECL_ARGS);
 static	void		  post_TP(DECL_ARGS);
 static	void		  post_UR(DECL_ARGS);
 
 static	const struct termact termacts[MAN_MAX] = {
 	{ pre_sp, NULL, MAN_NOTEXT }, /* br */
 	{ NULL, NULL, 0 }, /* TH */
 	{ pre_SH, post_SH, 0 }, /* SH */
 	{ pre_SS, post_SS, 0 }, /* SS */
 	{ pre_TP, post_TP, 0 }, /* TP */
 	{ pre_PP, NULL, 0 }, /* LP */
 	{ pre_PP, NULL, 0 }, /* PP */
 	{ pre_PP, NULL, 0 }, /* P */
 	{ pre_IP, post_IP, 0 }, /* IP */
 	{ pre_HP, post_HP, 0 }, /* HP */
 	{ NULL, NULL, 0 }, /* SM */
 	{ pre_B, NULL, 0 }, /* SB */
 	{ pre_alternate, NULL, 0 }, /* BI */
 	{ pre_alternate, NULL, 0 }, /* IB */
 	{ pre_alternate, NULL, 0 }, /* BR */
 	{ pre_alternate, NULL, 0 }, /* RB */
 	{ NULL, NULL, 0 }, /* R */
 	{ pre_B, NULL, 0 }, /* B */
 	{ pre_I, NULL, 0 }, /* I */
 	{ pre_alternate, NULL, 0 }, /* IR */
 	{ pre_alternate, NULL, 0 }, /* RI */
 	{ pre_sp, NULL, MAN_NOTEXT }, /* sp */
 	{ pre_literal, NULL, 0 }, /* nf */
 	{ pre_literal, NULL, 0 }, /* fi */
 	{ NULL, NULL, 0 }, /* RE */
 	{ pre_RS, post_RS, 0 }, /* RS */
 	{ pre_ign, NULL, 0 }, /* DT */
 	{ pre_ign, NULL, MAN_NOTEXT }, /* UC */
 	{ pre_PD, NULL, MAN_NOTEXT }, /* PD */
 	{ pre_ign, NULL, 0 }, /* AT */
 	{ pre_in, NULL, MAN_NOTEXT }, /* in */
 	{ pre_ft, NULL, MAN_NOTEXT }, /* ft */
 	{ pre_OP, NULL, 0 }, /* OP */
 	{ pre_literal, NULL, 0 }, /* EX */
 	{ pre_literal, NULL, 0 }, /* EE */
 	{ pre_UR, post_UR, 0 }, /* UR */
 	{ NULL, NULL, 0 }, /* UE */
 	{ pre_ll, NULL, MAN_NOTEXT }, /* ll */
 };
 
 
 void
 terminal_man(void *arg, const struct roff_man *man)
 {
 	struct termp		*p;
 	struct roff_node	*n;
 	struct mtermp		 mt;
 
 	p = (struct termp *)arg;
 	p->overstep = 0;
 	p->rmargin = p->maxrmargin = p->defrmargin;
 	p->tabwidth = term_len(p, 5);
 
 	memset(&mt, 0, sizeof(struct mtermp));
 	mt.lmargin[mt.lmargincur] = term_len(p, p->defindent);
 	mt.offset = term_len(p, p->defindent);
 	mt.pardist = 1;
 
 	n = man->first->child;
 	if (p->synopsisonly) {
 		while (n != NULL) {
 			if (n->tok == MAN_SH &&
 			    n->child->child->type == ROFFT_TEXT &&
 			    !strcmp(n->child->child->string, "SYNOPSIS")) {
 				if (n->child->next->child != NULL)
 					print_man_nodelist(p, &mt,
 					    n->child->next->child,
 					    &man->meta);
 				term_newln(p);
 				break;
 			}
 			n = n->next;
 		}
 	} else {
 		if (p->defindent == 0)
 			p->defindent = 7;
 		term_begin(p, print_man_head, print_man_foot, &man->meta);
 		p->flags |= TERMP_NOSPACE;
 		if (n != NULL)
 			print_man_nodelist(p, &mt, n, &man->meta);
 		term_end(p);
 	}
 }
 
 /*
  * Printing leading vertical space before a block.
  * This is used for the paragraph macros.
  * The rules are pretty simple, since there's very little nesting going
  * on here.  Basically, if we're the first within another block (SS/SH),
  * then don't emit vertical space.  If we are (RS), then do.  If not the
  * first, print it.
  */
 static void
 print_bvspace(struct termp *p, const struct roff_node *n, int pardist)
 {
 	int	 i;
 
 	term_newln(p);
 
 	if (n->body && n->body->child)
 		if (n->body->child->type == ROFFT_TBL)
 			return;
 
 	if (n->parent->type == ROFFT_ROOT || n->parent->tok != MAN_RS)
 		if (NULL == n->prev)
 			return;
 
 	for (i = 0; i < pardist; i++)
 		term_vspace(p);
 }
 
 
 static int
 pre_ign(DECL_ARGS)
 {
 
 	return 0;
 }
 
 static int
 pre_ll(DECL_ARGS)
 {
 
 	term_setwidth(p, n->child != NULL ? n->child->string : NULL);
 	return 0;
 }
 
 static int
 pre_I(DECL_ARGS)
 {
 
 	term_fontrepl(p, TERMFONT_UNDER);
 	return 1;
 }
 
 static int
 pre_literal(DECL_ARGS)
 {
 
 	term_newln(p);
 
 	if (MAN_nf == n->tok || MAN_EX == n->tok)
 		mt->fl |= MANT_LITERAL;
 	else
 		mt->fl &= ~MANT_LITERAL;
 
 	/*
 	 * Unlike .IP and .TP, .HP does not have a HEAD.
 	 * So in case a second call to term_flushln() is needed,
 	 * indentation has to be set up explicitly.
 	 */
 	if (MAN_HP == n->parent->tok && p->rmargin < p->maxrmargin) {
 		p->offset = p->rmargin;
 		p->rmargin = p->maxrmargin;
 		p->trailspace = 0;
 		p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
 		p->flags |= TERMP_NOSPACE;
 	}
 
 	return 0;
 }
 
 static int
 pre_PD(DECL_ARGS)
 {
 	struct roffsu	 su;
 
 	n = n->child;
 	if (n == NULL) {
 		mt->pardist = 1;
 		return 0;
 	}
 	assert(n->type == ROFFT_TEXT);
 	if (a2roffsu(n->string, &su, SCALE_VS))
 		mt->pardist = term_vspan(p, &su);
 	return 0;
 }
 
 static int
 pre_alternate(DECL_ARGS)
 {
 	enum termfont		 font[2];
 	struct roff_node	*nn;
 	int			 savelit, i;
 
 	switch (n->tok) {
 	case MAN_RB:
 		font[0] = TERMFONT_NONE;
 		font[1] = TERMFONT_BOLD;
 		break;
 	case MAN_RI:
 		font[0] = TERMFONT_NONE;
 		font[1] = TERMFONT_UNDER;
 		break;
 	case MAN_BR:
 		font[0] = TERMFONT_BOLD;
 		font[1] = TERMFONT_NONE;
 		break;
 	case MAN_BI:
 		font[0] = TERMFONT_BOLD;
 		font[1] = TERMFONT_UNDER;
 		break;
 	case MAN_IR:
 		font[0] = TERMFONT_UNDER;
 		font[1] = TERMFONT_NONE;
 		break;
 	case MAN_IB:
 		font[0] = TERMFONT_UNDER;
 		font[1] = TERMFONT_BOLD;
 		break;
 	default:
 		abort();
 	}
 
 	savelit = MANT_LITERAL & mt->fl;
 	mt->fl &= ~MANT_LITERAL;
 
 	for (i = 0, nn = n->child; nn; nn = nn->next, i = 1 - i) {
 		term_fontrepl(p, font[i]);
 		if (savelit && NULL == nn->next)
 			mt->fl |= MANT_LITERAL;
 		assert(nn->type == ROFFT_TEXT);
 		term_word(p, nn->string);
-		if (nn->flags & MAN_EOS)
+		if (nn->flags & NODE_EOS)
                 	p->flags |= TERMP_SENTENCE;
 		if (nn->next)
 			p->flags |= TERMP_NOSPACE;
 	}
 
 	return 0;
 }
 
 static int
 pre_B(DECL_ARGS)
 {
 
 	term_fontrepl(p, TERMFONT_BOLD);
 	return 1;
 }
 
 static int
 pre_OP(DECL_ARGS)
 {
 
 	term_word(p, "[");
 	p->flags |= TERMP_NOSPACE;
 
 	if (NULL != (n = n->child)) {
 		term_fontrepl(p, TERMFONT_BOLD);
 		term_word(p, n->string);
 	}
 	if (NULL != n && NULL != n->next) {
 		term_fontrepl(p, TERMFONT_UNDER);
 		term_word(p, n->next->string);
 	}
 
 	term_fontrepl(p, TERMFONT_NONE);
 	p->flags |= TERMP_NOSPACE;
 	term_word(p, "]");
 	return 0;
 }
 
 static int
 pre_ft(DECL_ARGS)
 {
 	const char	*cp;
 
 	if (NULL == n->child) {
 		term_fontlast(p);
 		return 0;
 	}
 
 	cp = n->child->string;
 	switch (*cp) {
 	case '4':
 	case '3':
 	case 'B':
 		term_fontrepl(p, TERMFONT_BOLD);
 		break;
 	case '2':
 	case 'I':
 		term_fontrepl(p, TERMFONT_UNDER);
 		break;
 	case 'P':
 		term_fontlast(p);
 		break;
 	case '1':
 	case 'C':
 	case 'R':
 		term_fontrepl(p, TERMFONT_NONE);
 		break;
 	default:
 		break;
 	}
 	return 0;
 }
 
 static int
 pre_in(DECL_ARGS)
 {
 	struct roffsu	 su;
 	const char	*cp;
 	size_t		 v;
 	int		 less;
 
 	term_newln(p);
 
 	if (NULL == n->child) {
 		p->offset = mt->offset;
 		return 0;
 	}
 
 	cp = n->child->string;
 	less = 0;
 
 	if ('-' == *cp)
 		less = -1;
 	else if ('+' == *cp)
 		less = 1;
 	else
 		cp--;
 
 	if ( ! a2roffsu(++cp, &su, SCALE_EN))
 		return 0;
 
 	v = (term_hspan(p, &su) + 11) / 24;
 
 	if (less < 0)
 		p->offset -= p->offset > v ? v : p->offset;
 	else if (less > 0)
 		p->offset += v;
 	else
 		p->offset = v;
 	if (p->offset > SHRT_MAX)
 		p->offset = term_len(p, p->defindent);
 
 	return 0;
 }
 
 static int
 pre_sp(DECL_ARGS)
 {
 	struct roffsu	 su;
 	int		 i, len;
 
 	if ((NULL == n->prev && n->parent)) {
 		switch (n->parent->tok) {
 		case MAN_SH:
 		case MAN_SS:
 		case MAN_PP:
 		case MAN_LP:
 		case MAN_P:
 			return 0;
 		default:
 			break;
 		}
 	}
 
 	if (n->tok == MAN_br)
 		len = 0;
 	else if (n->child == NULL)
 		len = 1;
 	else {
 		if ( ! a2roffsu(n->child->string, &su, SCALE_VS))
 			su.scale = 1.0;
 		len = term_vspan(p, &su);
 	}
 
 	if (len == 0)
 		term_newln(p);
 	else if (len < 0)
 		p->skipvsp -= len;
 	else
 		for (i = 0; i < len; i++)
 			term_vspace(p);
 
 	/*
 	 * Handle an explicit break request in the same way
 	 * as an overflowing line.
 	 */
 
 	if (p->flags & TERMP_BRIND) {
 		p->offset = p->rmargin;
 		p->rmargin = p->maxrmargin;
 		p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
 	}
 
 	return 0;
 }
 
 static int
 pre_HP(DECL_ARGS)
 {
 	struct roffsu		 su;
 	const struct roff_node	*nn;
 	int			 len;
 
 	switch (n->type) {
 	case ROFFT_BLOCK:
 		print_bvspace(p, n, mt->pardist);
 		return 1;
 	case ROFFT_BODY:
 		break;
 	default:
 		return 0;
 	}
 
 	if ( ! (MANT_LITERAL & mt->fl)) {
 		p->flags |= TERMP_NOBREAK | TERMP_BRIND;
 		p->trailspace = 2;
 	}
 
 	/* Calculate offset. */
 
 	if ((nn = n->parent->head->child) != NULL &&
 	    a2roffsu(nn->string, &su, SCALE_EN)) {
 		len = term_hspan(p, &su) / 24;
 		if (len < 0 && (size_t)(-len) > mt->offset)
 			len = -mt->offset;
 		else if (len > SHRT_MAX)
 			len = term_len(p, p->defindent);
 		mt->lmargin[mt->lmargincur] = len;
 	} else
 		len = mt->lmargin[mt->lmargincur];
 
 	p->offset = mt->offset;
 	p->rmargin = mt->offset + len;
 	return 1;
 }
 
 static void
 post_HP(DECL_ARGS)
 {
 
 	switch (n->type) {
 	case ROFFT_BODY:
 		term_newln(p);
 
 		/*
 		 * Compatibility with a groff bug.
 		 * The .HP macro uses the undocumented .tag request
 		 * which causes a line break and cancels no-space
 		 * mode even if there isn't any output.
 		 */
 
 		if (n->child == NULL)
 			term_vspace(p);
 
 		p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
 		p->trailspace = 0;
 		p->offset = mt->offset;
 		p->rmargin = p->maxrmargin;
 		break;
 	default:
 		break;
 	}
 }
 
 static int
 pre_PP(DECL_ARGS)
 {
 
 	switch (n->type) {
 	case ROFFT_BLOCK:
 		mt->lmargin[mt->lmargincur] = term_len(p, p->defindent);
 		print_bvspace(p, n, mt->pardist);
 		break;
 	default:
 		p->offset = mt->offset;
 		break;
 	}
 
 	return n->type != ROFFT_HEAD;
 }
 
 static int
 pre_IP(DECL_ARGS)
 {
 	struct roffsu		 su;
 	const struct roff_node	*nn;
 	int			 len, savelit;
 
 	switch (n->type) {
 	case ROFFT_BODY:
 		p->flags |= TERMP_NOSPACE;
 		break;
 	case ROFFT_HEAD:
 		p->flags |= TERMP_NOBREAK;
 		p->trailspace = 1;
 		break;
 	case ROFFT_BLOCK:
 		print_bvspace(p, n, mt->pardist);
 		/* FALLTHROUGH */
 	default:
 		return 1;
 	}
 
 	/* Calculate the offset from the optional second argument. */
 	if ((nn = n->parent->head->child) != NULL &&
 	    (nn = nn->next) != NULL &&
 	    a2roffsu(nn->string, &su, SCALE_EN)) {
 		len = term_hspan(p, &su) / 24;
 		if (len < 0 && (size_t)(-len) > mt->offset)
 			len = -mt->offset;
 		else if (len > SHRT_MAX)
 			len = term_len(p, p->defindent);
 		mt->lmargin[mt->lmargincur] = len;
 	} else
 		len = mt->lmargin[mt->lmargincur];
 
 	switch (n->type) {
 	case ROFFT_HEAD:
 		p->offset = mt->offset;
 		p->rmargin = mt->offset + len;
 
 		savelit = MANT_LITERAL & mt->fl;
 		mt->fl &= ~MANT_LITERAL;
 
 		if (n->child)
 			print_man_node(p, mt, n->child, meta);
 
 		if (savelit)
 			mt->fl |= MANT_LITERAL;
 
 		return 0;
 	case ROFFT_BODY:
 		p->offset = mt->offset + len;
 		p->rmargin = p->maxrmargin;
 		break;
 	default:
 		break;
 	}
 
 	return 1;
 }
 
 static void
 post_IP(DECL_ARGS)
 {
 
 	switch (n->type) {
 	case ROFFT_HEAD:
 		term_flushln(p);
 		p->flags &= ~TERMP_NOBREAK;
 		p->trailspace = 0;
 		p->rmargin = p->maxrmargin;
 		break;
 	case ROFFT_BODY:
 		term_newln(p);
 		p->offset = mt->offset;
 		break;
 	default:
 		break;
 	}
 }
 
 static int
 pre_TP(DECL_ARGS)
 {
 	struct roffsu		 su;
 	struct roff_node	*nn;
 	int			 len, savelit;
 
 	switch (n->type) {
 	case ROFFT_HEAD:
 		p->flags |= TERMP_NOBREAK | TERMP_BRTRSP;
 		p->trailspace = 1;
 		break;
 	case ROFFT_BODY:
 		p->flags |= TERMP_NOSPACE;
 		break;
 	case ROFFT_BLOCK:
 		print_bvspace(p, n, mt->pardist);
 		/* FALLTHROUGH */
 	default:
 		return 1;
 	}
 
 	/* Calculate offset. */
 
 	if ((nn = n->parent->head->child) != NULL &&
-	    nn->string != NULL && ! (MAN_LINE & nn->flags) &&
+	    nn->string != NULL && ! (NODE_LINE & nn->flags) &&
 	    a2roffsu(nn->string, &su, SCALE_EN)) {
 		len = term_hspan(p, &su) / 24;
 		if (len < 0 && (size_t)(-len) > mt->offset)
 			len = -mt->offset;
 		else if (len > SHRT_MAX)
 			len = term_len(p, p->defindent);
 		mt->lmargin[mt->lmargincur] = len;
 	} else
 		len = mt->lmargin[mt->lmargincur];
 
 	switch (n->type) {
 	case ROFFT_HEAD:
 		p->offset = mt->offset;
 		p->rmargin = mt->offset + len;
 
 		savelit = MANT_LITERAL & mt->fl;
 		mt->fl &= ~MANT_LITERAL;
 
 		/* Don't print same-line elements. */
 		nn = n->child;
-		while (NULL != nn && 0 == (MAN_LINE & nn->flags))
+		while (NULL != nn && 0 == (NODE_LINE & nn->flags))
 			nn = nn->next;
 
 		while (NULL != nn) {
 			print_man_node(p, mt, nn, meta);
 			nn = nn->next;
 		}
 
 		if (savelit)
 			mt->fl |= MANT_LITERAL;
 		return 0;
 	case ROFFT_BODY:
 		p->offset = mt->offset + len;
 		p->rmargin = p->maxrmargin;
 		p->trailspace = 0;
 		p->flags &= ~(TERMP_NOBREAK | TERMP_BRTRSP);
 		break;
 	default:
 		break;
 	}
 
 	return 1;
 }
 
 static void
 post_TP(DECL_ARGS)
 {
 
 	switch (n->type) {
 	case ROFFT_HEAD:
 		term_flushln(p);
 		break;
 	case ROFFT_BODY:
 		term_newln(p);
 		p->offset = mt->offset;
 		break;
 	default:
 		break;
 	}
 }
 
 static int
 pre_SS(DECL_ARGS)
 {
 	int	 i;
 
 	switch (n->type) {
 	case ROFFT_BLOCK:
 		mt->fl &= ~MANT_LITERAL;
 		mt->lmargin[mt->lmargincur] = term_len(p, p->defindent);
 		mt->offset = term_len(p, p->defindent);
 
 		/*
 		 * No vertical space before the first subsection
 		 * and after an empty subsection.
 		 */
 
 		do {
 			n = n->prev;
 		} while (n != NULL && n->tok != TOKEN_NONE &&
 		    termacts[n->tok].flags & MAN_NOTEXT);
 		if (n == NULL || (n->tok == MAN_SS && n->body->child == NULL))
 			break;
 
 		for (i = 0; i < mt->pardist; i++)
 			term_vspace(p);
 		break;
 	case ROFFT_HEAD:
 		term_fontrepl(p, TERMFONT_BOLD);
 		p->offset = term_len(p, 3);
 		p->rmargin = mt->offset;
 		p->trailspace = mt->offset;
 		p->flags |= TERMP_NOBREAK | TERMP_BRIND;
 		break;
 	case ROFFT_BODY:
 		p->offset = mt->offset;
 		p->rmargin = p->maxrmargin;
 		p->trailspace = 0;
 		p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
 		break;
 	default:
 		break;
 	}
 
 	return 1;
 }
 
 static void
 post_SS(DECL_ARGS)
 {
 
 	switch (n->type) {
 	case ROFFT_HEAD:
 		term_newln(p);
 		break;
 	case ROFFT_BODY:
 		term_newln(p);
 		break;
 	default:
 		break;
 	}
 }
 
 static int
 pre_SH(DECL_ARGS)
 {
 	int	 i;
 
 	switch (n->type) {
 	case ROFFT_BLOCK:
 		mt->fl &= ~MANT_LITERAL;
 		mt->lmargin[mt->lmargincur] = term_len(p, p->defindent);
 		mt->offset = term_len(p, p->defindent);
 
 		/*
 		 * No vertical space before the first section
 		 * and after an empty section.
 		 */
 
 		do {
 			n = n->prev;
 		} while (n != NULL && termacts[n->tok].flags & MAN_NOTEXT);
 		if (n == NULL || (n->tok == MAN_SH && n->body->child == NULL))
 			break;
 
 		for (i = 0; i < mt->pardist; i++)
 			term_vspace(p);
 		break;
 	case ROFFT_HEAD:
 		term_fontrepl(p, TERMFONT_BOLD);
 		p->offset = 0;
 		p->rmargin = mt->offset;
 		p->trailspace = mt->offset;
 		p->flags |= TERMP_NOBREAK | TERMP_BRIND;
 		break;
 	case ROFFT_BODY:
 		p->offset = mt->offset;
 		p->rmargin = p->maxrmargin;
 		p->trailspace = 0;
 		p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
 		break;
 	default:
 		break;
 	}
 
 	return 1;
 }
 
 static void
 post_SH(DECL_ARGS)
 {
 
 	switch (n->type) {
 	case ROFFT_HEAD:
 		term_newln(p);
 		break;
 	case ROFFT_BODY:
 		term_newln(p);
 		break;
 	default:
 		break;
 	}
 }
 
 static int
 pre_RS(DECL_ARGS)
 {
 	struct roffsu	 su;
 
 	switch (n->type) {
 	case ROFFT_BLOCK:
 		term_newln(p);
 		return 1;
 	case ROFFT_HEAD:
 		return 0;
 	default:
 		break;
 	}
 
 	n = n->parent->head;
 	n->aux = SHRT_MAX + 1;
 	if (n->child == NULL)
 		n->aux = mt->lmargin[mt->lmargincur];
 	else if (a2roffsu(n->child->string, &su, SCALE_EN))
 		n->aux = term_hspan(p, &su) / 24;
 	if (n->aux < 0 && (size_t)(-n->aux) > mt->offset)
 		n->aux = -mt->offset;
 	else if (n->aux > SHRT_MAX)
 		n->aux = term_len(p, p->defindent);
 
 	mt->offset += n->aux;
 	p->offset = mt->offset;
 	p->rmargin = p->maxrmargin;
 
 	if (++mt->lmarginsz < MAXMARGINS)
 		mt->lmargincur = mt->lmarginsz;
 
 	mt->lmargin[mt->lmargincur] = term_len(p, p->defindent);
 	return 1;
 }
 
 static void
 post_RS(DECL_ARGS)
 {
 
 	switch (n->type) {
 	case ROFFT_BLOCK:
 		return;
 	case ROFFT_HEAD:
 		return;
 	default:
 		term_newln(p);
 		break;
 	}
 
 	mt->offset -= n->parent->head->aux;
 	p->offset = mt->offset;
 
 	if (--mt->lmarginsz < MAXMARGINS)
 		mt->lmargincur = mt->lmarginsz;
 }
 
 static int
 pre_UR(DECL_ARGS)
 {
 
 	return n->type != ROFFT_HEAD;
 }
 
 static void
 post_UR(DECL_ARGS)
 {
 
 	if (n->type != ROFFT_BLOCK)
 		return;
 
 	term_word(p, "<");
 	p->flags |= TERMP_NOSPACE;
 
 	if (NULL != n->child->child)
 		print_man_node(p, mt, n->child->child, meta);
 
 	p->flags |= TERMP_NOSPACE;
 	term_word(p, ">");
 }
 
 static void
 print_man_node(DECL_ARGS)
 {
 	size_t		 rm, rmax;
 	int		 c;
 
 	switch (n->type) {
 	case ROFFT_TEXT:
 		/*
 		 * If we have a blank line, output a vertical space.
 		 * If we have a space as the first character, break
 		 * before printing the line's data.
 		 */
 		if ('\0' == *n->string) {
 			term_vspace(p);
 			return;
-		} else if (' ' == *n->string && MAN_LINE & n->flags)
+		} else if (' ' == *n->string && NODE_LINE & n->flags)
 			term_newln(p);
 
 		term_word(p, n->string);
 		goto out;
 
 	case ROFFT_EQN:
-		if ( ! (n->flags & MAN_LINE))
+		if ( ! (n->flags & NODE_LINE))
 			p->flags |= TERMP_NOSPACE;
 		term_eqn(p, n->eqn);
-		if (n->next != NULL && ! (n->next->flags & MAN_LINE))
+		if (n->next != NULL && ! (n->next->flags & NODE_LINE))
 			p->flags |= TERMP_NOSPACE;
 		return;
 	case ROFFT_TBL:
 		if (p->tbl.cols == NULL)
 			term_vspace(p);
 		term_tbl(p, n->span);
 		return;
 	default:
 		break;
 	}
 
 	if ( ! (MAN_NOTEXT & termacts[n->tok].flags))
 		term_fontrepl(p, TERMFONT_NONE);
 
 	c = 1;
 	if (termacts[n->tok].pre)
 		c = (*termacts[n->tok].pre)(p, mt, n, meta);
 
 	if (c && n->child)
 		print_man_nodelist(p, mt, n->child, meta);
 
 	if (termacts[n->tok].post)
 		(*termacts[n->tok].post)(p, mt, n, meta);
 	if ( ! (MAN_NOTEXT & termacts[n->tok].flags))
 		term_fontrepl(p, TERMFONT_NONE);
 
 out:
 	/*
 	 * If we're in a literal context, make sure that words
 	 * together on the same line stay together.  This is a
 	 * POST-printing call, so we check the NEXT word.  Since
 	 * -man doesn't have nested macros, we don't need to be
 	 * more specific than this.
 	 */
 	if (mt->fl & MANT_LITERAL &&
 	    ! (p->flags & (TERMP_NOBREAK | TERMP_NONEWLINE)) &&
-	    (n->next == NULL || n->next->flags & MAN_LINE)) {
+	    (n->next == NULL || n->next->flags & NODE_LINE)) {
 		rm = p->rmargin;
 		rmax = p->maxrmargin;
 		p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
 		p->flags |= TERMP_NOSPACE;
 		if (n->string != NULL && *n->string != '\0')
 			term_flushln(p);
 		else
 			term_newln(p);
 		if (rm < rmax && n->parent->tok == MAN_HP) {
 			p->offset = rm;
 			p->rmargin = rmax;
 		} else
 			p->rmargin = rm;
 		p->maxrmargin = rmax;
 	}
-	if (MAN_EOS & n->flags)
+	if (NODE_EOS & n->flags)
 		p->flags |= TERMP_SENTENCE;
 }
 
 
 static void
 print_man_nodelist(DECL_ARGS)
 {
 
 	while (n != NULL) {
 		print_man_node(p, mt, n, meta);
 		n = n->next;
 	}
 }
 
 static void
 print_man_foot(struct termp *p, const struct roff_meta *meta)
 {
 	char			*title;
 	size_t			 datelen, titlen;
 
 	assert(meta->title);
 	assert(meta->msec);
 	assert(meta->date);
 
 	term_fontrepl(p, TERMFONT_NONE);
 
 	if (meta->hasbody)
 		term_vspace(p);
 
 	/*
 	 * Temporary, undocumented option to imitate mdoc(7) output.
 	 * In the bottom right corner, use the operating system
 	 * instead of the title.
 	 */
 
 	if ( ! p->mdocstyle) {
 		if (meta->hasbody) {
 			term_vspace(p);
 			term_vspace(p);
 		}
 		mandoc_asprintf(&title, "%s(%s)",
 		    meta->title, meta->msec);
 	} else if (meta->os) {
 		title = mandoc_strdup(meta->os);
 	} else {
 		title = mandoc_strdup("");
 	}
 	datelen = term_strlen(p, meta->date);
 
 	/* Bottom left corner: operating system. */
 
 	p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
 	p->trailspace = 1;
 	p->offset = 0;
 	p->rmargin = p->maxrmargin > datelen ?
 	    (p->maxrmargin + term_len(p, 1) - datelen) / 2 : 0;
 
 	if (meta->os)
 		term_word(p, meta->os);
 	term_flushln(p);
 
 	/* At the bottom in the middle: manual date. */
 
 	p->offset = p->rmargin;
 	titlen = term_strlen(p, title);
 	p->rmargin = p->maxrmargin > titlen ? p->maxrmargin - titlen : 0;
 	p->flags |= TERMP_NOSPACE;
 
 	term_word(p, meta->date);
 	term_flushln(p);
 
 	/* Bottom right corner: manual title and section. */
 
 	p->flags &= ~TERMP_NOBREAK;
 	p->flags |= TERMP_NOSPACE;
 	p->trailspace = 0;
 	p->offset = p->rmargin;
 	p->rmargin = p->maxrmargin;
 
 	term_word(p, title);
 	term_flushln(p);
 	free(title);
 }
 
 static void
 print_man_head(struct termp *p, const struct roff_meta *meta)
 {
 	const char		*volume;
 	char			*title;
 	size_t			 vollen, titlen;
 
 	assert(meta->title);
 	assert(meta->msec);
 
 	volume = NULL == meta->vol ? "" : meta->vol;
 	vollen = term_strlen(p, volume);
 
 	/* Top left corner: manual title and section. */
 
 	mandoc_asprintf(&title, "%s(%s)", meta->title, meta->msec);
 	titlen = term_strlen(p, title);
 
 	p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
 	p->trailspace = 1;
 	p->offset = 0;
 	p->rmargin = 2 * (titlen+1) + vollen < p->maxrmargin ?
 	    (p->maxrmargin - vollen + term_len(p, 1)) / 2 :
 	    vollen < p->maxrmargin ? p->maxrmargin - vollen : 0;
 
 	term_word(p, title);
 	term_flushln(p);
 
 	/* At the top in the middle: manual volume. */
 
 	p->flags |= TERMP_NOSPACE;
 	p->offset = p->rmargin;
 	p->rmargin = p->offset + vollen + titlen < p->maxrmargin ?
 	    p->maxrmargin - titlen : p->maxrmargin;
 
 	term_word(p, volume);
 	term_flushln(p);
 
 	/* Top right corner: title and section, again. */
 
 	p->flags &= ~TERMP_NOBREAK;
 	p->trailspace = 0;
 	if (p->rmargin + titlen <= p->maxrmargin) {
 		p->flags |= TERMP_NOSPACE;
 		p->offset = p->rmargin;
 		p->rmargin = p->maxrmargin;
 		term_word(p, title);
 		term_flushln(p);
 	}
 
 	p->flags &= ~TERMP_NOSPACE;
 	p->offset = 0;
 	p->rmargin = p->maxrmargin;
 
 	/*
 	 * Groff prints three blank lines before the content.
 	 * Do the same, except in the temporary, undocumented
 	 * mode imitating mdoc(7) output.
 	 */
 
 	term_vspace(p);
 	if ( ! p->mdocstyle) {
 		term_vspace(p);
 		term_vspace(p);
 	}
 	free(title);
 }
Index: stable/11/contrib/mdocml/mandoc.1
===================================================================
--- stable/11/contrib/mdocml/mandoc.1	(revision 316419)
+++ stable/11/contrib/mdocml/mandoc.1	(revision 316420)
@@ -1,1823 +1,1842 @@
-.\"	$Id: mandoc.1,v 1.164 2015/11/05 17:47:51 schwarze Exp $
+.\"	$Id: mandoc.1,v 1.171 2017/01/21 02:32:39 schwarze Exp $
 .\"
 .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons 
-.\" Copyright (c) 2012, 2014, 2015 Ingo Schwarze 
+.\" Copyright (c) 2012, 2014-2017 Ingo Schwarze 
 .\"
 .\" 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.
 .\"
-.Dd $Mdocdate: November 5 2015 $
+.Dd $Mdocdate: January 21 2017 $
 .Dt MANDOC 1
 .Os
 .Sh NAME
 .Nm mandoc
 .Nd format and display UNIX manuals
 .Sh SYNOPSIS
 .Nm mandoc
 .Op Fl acfhkl
 .Op Fl I Cm os Ns = Ns Ar name
 .Op Fl K Ar encoding
 .Op Fl m Ns Ar format
 .Op Fl O Ar option
 .Op Fl T Ar output
 .Op Fl W Ar level
 .Op Ar
 .Sh DESCRIPTION
 The
 .Nm
 utility formats
 .Ux
 manual pages for display.
 .Pp
 By default,
 .Nm
 reads
 .Xr mdoc 7
 or
 .Xr man 7
 text from stdin, implying
 .Fl m Ns Cm andoc ,
 and produces
 .Fl T Cm locale
 output.
 .Pp
 The options are as follows:
 .Bl -tag -width Ds
 .It Fl a
 If the standard output is a terminal device and
 .Fl c
 is not specified, use
 .Xr more 1
 to paginate the output, just like
 .Xr man 1
 would.
 .It Fl c
 Copy the formatted manual pages to the standard output without using
 .Xr more 1
 to paginate them.
 This is the default.
 It can be specified to override
 .Fl a .
 .It Fl f
 A synonym for
 .Xr whatis 1 .
 This overrides any earlier
 .Fl k
 and
 .Fl l
 options.
+.It Fl h
+Display only the SYNOPSIS lines.
+Implies
+.Fl c .
 .It Fl I Cm os Ns = Ns Ar name
 Override the default operating system
 .Ar name
 for the
 .Xr mdoc 7
 .Sq \&Os
 and for the
 .Xr man 7
 .Sq \&TH
 macro.
-.It Fl h
-Display only the SYNOPSIS lines.
-Implies
-.Fl c .
 .It Fl K Ar encoding
 Specify the input encoding.
 The supported
 .Ar encoding
 arguments are
 .Cm us-ascii ,
 .Cm iso-8859-1 ,
 and
 .Cm utf-8 .
 If not specified, autodetection uses the first match:
 .Bl -tag -width iso-8859-1
 .It Cm utf-8
 if the first three bytes of the input file
 are the UTF-8 byte order mark (BOM, 0xefbbbf)
 .It Ar encoding
 if the first or second line of the input file matches the
 .Sy emacs
 mode line format
 .Pp
 .D1 .\e" -*- Oo ...; Oc coding: Ar encoding ; No -*-
 .It Cm utf-8
 if the first non-ASCII byte in the file introduces a valid UTF-8 sequence
 .It Cm iso-8859-1
 otherwise
 .El
 .It Fl k
 A synonym for
 .Xr apropos 1 .
 This overrides any earlier
 .Fl f
 and
 .Fl l
 options.
 .It Fl l
 A synonym for
 .Fl a .
 Also reverts any earlier
 .Fl f
 and
 .Fl k
 options.
 .It Fl m Ns Ar format
 Input format.
 See
 .Sx Input Formats
 for available formats.
 Defaults to
 .Fl m Ns Cm andoc .
 .It Fl O Ar option
 Comma-separated output options.
 .It Fl T Ar output
 Output format.
 See
 .Sx Output Formats
 for available formats.
 Defaults to
 .Fl T Cm locale .
 .It Fl W Ar level
 Specify the minimum message
 .Ar level
 to be reported on the standard error output and to affect the exit status.
 The
 .Ar level
 can be
 .Cm warning ,
 .Cm error ,
 or
 .Cm unsupp ;
 .Cm all
 is an alias for
 .Cm warning .
 By default,
 .Nm
 is silent.
 See
 .Sx EXIT STATUS
 and
 .Sx DIAGNOSTICS
 for details.
 .Pp
 The special option
 .Fl W Cm stop
 tells
 .Nm
 to exit after parsing a file that causes warnings or errors of at least
 the requested level.
 No formatted output will be produced from that file.
 If both a
 .Ar level
 and
 .Cm stop
 are requested, they can be joined with a comma, for example
 .Fl W Cm error , Ns Cm stop .
 .It Ar file
 Read input from zero or more files.
 If unspecified, reads from stdin.
 If multiple files are specified,
 .Nm
 will halt with the first failed parse.
 .El
 .Pp
 In
 .Fl f
 and
 .Fl k
 mode,
 .Nm
 also supports the options
 .Fl CMmOSsw
 described in the
 .Xr apropos 1
 manual.
 .Ss Input Formats
 The
 .Nm
 utility accepts
 .Xr mdoc 7
 and
 .Xr man 7
 input with
 .Fl m Ns Cm doc
 and
 .Fl m Ns Cm an ,
 respectively.
 The
 .Xr mdoc 7
 format is
 .Em strongly
 recommended;
 .Xr man 7
 should only be used for legacy manuals.
 .Pp
 A third option,
 .Fl m Ns Cm andoc ,
 which is also the default, determines encoding on-the-fly: if the first
 non-comment macro is
 .Sq \&Dd
 or
 .Sq \&Dt ,
 the
 .Xr mdoc 7
 parser is used; otherwise, the
 .Xr man 7
 parser is used.
 .Pp
 If multiple
 files are specified with
 .Fl m Ns Cm andoc ,
 each has its file-type determined this way.
 If multiple files are
 specified and
 .Fl m Ns Cm doc
 or
 .Fl m Ns Cm an
 is specified, then this format is used exclusively.
 .Ss Output Formats
 The
 .Nm
 utility accepts the following
 .Fl T
 arguments, which correspond to output modes:
 .Bl -tag -width "-T locale"
 .It Fl T Cm ascii
 Produce 7-bit ASCII output.
 See
 .Sx ASCII Output .
 .It Fl T Cm html
 Produce HTML5, CSS1, and MathML output.
 See
 .Sx HTML Output .
 .It Fl T Cm lint
 Parse only: produce no output.
 Implies
 .Fl W Cm warning .
 .It Fl T Cm locale
 Encode output using the current locale.
 This is the default.
 See
 .Sx Locale Output .
 .It Fl T Cm man
 Produce
 .Xr man 7
 format output.
 See
 .Sx Man Output .
 .It Fl T Cm pdf
 Produce PDF output.
 See
 .Sx PDF Output .
 .It Fl T Cm ps
 Produce PostScript output.
 See
 .Sx PostScript Output .
 .It Fl T Cm tree
 Produce an indented parse tree.
 See
 .Sx Syntax tree output .
 .It Fl T Cm utf8
 Encode output in the UTF\-8 multi-byte format.
 See
 .Sx UTF\-8 Output .
 .It Fl T Cm xhtml
 This is a synonym for
 .Fl T Cm html .
 .El
 .Pp
 If multiple input files are specified, these will be processed by the
 corresponding filter in-order.
 .Ss ASCII Output
 Output produced by
 .Fl T Cm ascii
 is rendered in standard 7-bit ASCII documented in
 .Xr ascii 7 .
 .Pp
 Font styles are applied by using back-spaced encoding such that an
 underlined character
 .Sq c
 is rendered as
 .Sq _ Ns \e[bs] Ns c ,
 where
 .Sq \e[bs]
 is the back-space character number 8.
 Emboldened characters are rendered as
 .Sq c Ns \e[bs] Ns c .
 .Pp
 The special characters documented in
 .Xr mandoc_char 7
 are rendered best-effort in an ASCII equivalent.
 .Pp
 Output width is limited to 78 visible columns unless literal input lines
 exceed this limit.
 .Pp
 The following
 .Fl O
 arguments are accepted:
 .Bl -tag -width Ds
 .It Cm indent Ns = Ns Ar indent
 The left margin for normal text is set to
 .Ar indent
 blank characters instead of the default of five for
 .Xr mdoc 7
 and seven for
 .Xr man 7 .
 Increasing this is not recommended; it may result in degraded formatting,
 for example overfull lines or ugly line breaks.
 .It Cm width Ns = Ns Ar width
 The output width is set to
 .Ar width ,
 which will normalise to \(>=58.
 .El
 .Ss HTML Output
 Output produced by
 .Fl T Cm html
 conforms to HTML5 using optional self-closing tags.
 Default styles use only CSS1.
 Equations rendered from
 .Xr eqn 7
 blocks use MathML.
 .Pp
 The
 .Pa mandoc.css
 file documents style-sheet classes available for customising output.
 If a style-sheet is not specified with
 .Fl O Cm style ,
 .Fl T Cm html
 defaults to simple output (via an embedded style-sheet)
 readable in any graphical or text-based web
 browser.
 .Pp
 Special characters are rendered in decimal-encoded UTF\-8.
 .Pp
 The following
 .Fl O
 arguments are accepted:
 .Bl -tag -width Ds
 .It Cm fragment
 Omit the  declaration and the , , and 
 elements and only emit the subtree below the  element.
 The
 .Cm style
 argument will be ignored.
 This is useful when embedding manual content within existing documents.
 .It Cm includes Ns = Ns Ar fmt
 The string
 .Ar fmt ,
 for example,
 .Ar ../src/%I.html ,
 is used as a template for linked header files (usually via the
 .Sq \&In
 macro).
 Instances of
 .Sq \&%I
 are replaced with the include filename.
 The default is not to present a
 hyperlink.
 .It Cm man Ns = Ns Ar fmt
 The string
 .Ar fmt ,
 for example,
 .Ar ../html%S/%N.%S.html ,
 is used as a template for linked manuals (usually via the
 .Sq \&Xr
 macro).
 Instances of
 .Sq \&%N
 and
 .Sq %S
 are replaced with the linked manual's name and section, respectively.
 If no section is included, section 1 is assumed.
 The default is not to
 present a hyperlink.
 .It Cm style Ns = Ns Ar style.css
 The file
 .Ar style.css
 is used for an external style-sheet.
 This must be a valid absolute or
 relative URI.
 .El
 .Ss Locale Output
 Locale-depending output encoding is triggered with
 .Fl T Cm locale .
 This is the default.
 .Pp
 This option is not available on all systems: systems without locale
 support, or those whose internal representation is not natively UCS-4,
 will fall back to
 .Fl T Cm ascii .
 See
 .Sx ASCII Output
 for font style specification and available command-line arguments.
 .Ss Man Output
 Translate input format into
 .Xr man 7
 output format.
 This is useful for distributing manual sources to legacy systems
 lacking
 .Xr mdoc 7
 formatters.
 .Pp
 If
 .Xr mdoc 7
 is passed as input, it is translated into
 .Xr man 7 .
 If the input format is
 .Xr man 7 ,
 the input is copied to the output, expanding any
 .Xr roff 7
 .Sq so
 requests.
 The parser is also run, and as usual, the
 .Fl W
 level controls which
 .Sx DIAGNOSTICS
 are displayed before copying the input to the output.
 .Ss PDF Output
 PDF-1.1 output may be generated by
 .Fl T Cm pdf .
 See
 .Sx PostScript Output
 for
 .Fl O
 arguments and defaults.
 .Ss PostScript Output
 PostScript
 .Qq Adobe-3.0
 Level-2 pages may be generated by
 .Fl T Cm ps .
 Output pages default to letter sized and are rendered in the Times font
 family, 11-point.
 Margins are calculated as 1/9 the page length and width.
 Line-height is 1.4m.
 .Pp
 Special characters are rendered as in
 .Sx ASCII Output .
 .Pp
 The following
 .Fl O
 arguments are accepted:
 .Bl -tag -width Ds
 .It Cm paper Ns = Ns Ar name
 The paper size
 .Ar name
 may be one of
 .Ar a3 ,
 .Ar a4 ,
 .Ar a5 ,
 .Ar legal ,
 or
 .Ar letter .
 You may also manually specify dimensions as
 .Ar NNxNN ,
 width by height in millimetres.
 If an unknown value is encountered,
 .Ar letter
 is used.
 .El
 .Ss UTF\-8 Output
 Use
 .Fl T Cm utf8
 to force a UTF\-8 locale.
 See
 .Sx Locale Output
 for details and options.
 .Ss Syntax tree output
 Use
 .Fl T Cm tree
 to show a human readable representation of the syntax tree.
 It is useful for debugging the source code of manual pages.
 The exact format is subject to change, so don't write parsers for it.
-Each output line shows one syntax tree node.
+.Pp
+The first paragraph shows meta data found in the
+.Xr mdoc 7
+prologue, on the
+.Xr man 7
+.Ic \&TH
+line, or the fallbacks used.
+.Pp
+In the tree dump, each output line shows one syntax tree node.
 Child nodes are indented with respect to their parent node.
 The columns are:
 .Pp
 .Bl -enum -compact
 .It
 For macro nodes, the macro name; for text and
 .Xr tbl 7
 nodes, the content.
 There is a special format for
 .Xr eqn 7
 nodes.
 .It
 Node type (text, elem, block, head, body, body-end, tail, tbl, eqn).
 .It
 Flags:
 .Bl -dash -compact
 .It
 An opening parenthesis if the node is an opening delimiter.
 .It
 An asterisk if the node starts a new input line.
 .It
 The input line number (starting at one).
 .It
 A colon.
 .It
 The input column number (starting at one).
 .It
 A closing parenthesis if the node is a closing delimiter.
 .It
 A full stop if the node ends a sentence.
+.It
+NOSRC if the node is not in the input file,
+but automatically generated from macros.
+.It
+NOPRT if the node is not supposed to generate output
+for any output format.
 .El
 .El
 .Sh ENVIRONMENT
 .Bl -tag -width MANPAGER
 .It Ev MANPAGER
 Any non-empty value of the environment variable
 .Ev MANPAGER
 will be used instead of the standard pagination program,
 .Xr more 1 .
 .It Ev PAGER
 Specifies the pagination program to use when
 .Ev MANPAGER
 is not defined.
 If neither PAGER nor MANPAGER is defined,
 .Xr more 1
 .Fl s
 will be used.
 .El
 .Sh EXIT STATUS
 The
 .Nm
 utility exits with one of the following values, controlled by the message
 .Ar level
 associated with the
 .Fl W
 option:
 .Pp
 .Bl -tag -width Ds -compact
 .It 0
 No warnings or errors occurred, or those that did were ignored because
 they were lower than the requested
 .Ar level .
 .It 2
 At least one warning occurred, but no error, and
 .Fl W Cm warning
 was specified.
 .It 3
 At least one parsing error occurred,
 but no unsupported feature was encountered, and
 .Fl W Cm error
 or
 .Fl W Cm warning
 was specified.
 .It 4
 At least one unsupported feature was encountered, and
 .Fl W Cm unsupp ,
 .Fl W Cm error
 or
 .Fl W Cm warning
 was specified.
 .It 5
 Invalid command line arguments were specified.
 No input files have been read.
 .It 6
 An operating system error occurred, for example exhaustion
 of memory, file descriptors, or process table entries.
 Such errors cause
 .Nm
 to exit at once, possibly in the middle of parsing or formatting a file.
 .El
 .Pp
 Note that selecting
 .Fl T Cm lint
 output mode implies
 .Fl W Cm warning .
 .Sh EXAMPLES
 To page manuals to the terminal:
 .Pp
 .Dl $ mandoc \-W all,stop mandoc.1 2\*(Gt&1 | less
 .Dl $ mandoc mandoc.1 mdoc.3 mdoc.7 | less
 .Pp
 To produce HTML manuals with
 .Pa mandoc.css
 as the style-sheet:
 .Pp
 .Dl $ mandoc \-T html -O style=mandoc.css mdoc.7 \*(Gt mdoc.7.html
 .Pp
 To check over a large set of manuals:
 .Pp
 .Dl $ mandoc \-T lint \(gafind /usr/src -name \e*\e.[1-9]\(ga
 .Pp
 To produce a series of PostScript manuals for A4 paper:
 .Pp
 .Dl $ mandoc \-T ps \-O paper=a4 mdoc.7 man.7 \*(Gt manuals.ps
 .Pp
 Convert a modern
 .Xr mdoc 7
 manual to the older
 .Xr man 7
 format, for use on systems lacking an
 .Xr mdoc 7
 parser:
 .Pp
 .Dl $ mandoc \-T man foo.mdoc \*(Gt foo.man
 .Sh DIAGNOSTICS
 Messages displayed by
 .Nm
 follow this format:
 .Pp
 .D1 Nm Ns : Ar file : Ns Ar line : Ns Ar column : level : message : macro args
 .Pp
 Line and column numbers start at 1.
 Both are omitted for messages referring to an input file as a whole.
 Macro names and arguments are omitted where meaningless.
 Fatal messages about invalid command line arguments
 or operating system errors, for example when memory is exhausted,
 may also omit the
 .Ar file
 and
 .Ar level
 fields.
 .Pp
 Message levels have the following meanings:
 .Bl -tag -width "warning"
 .It Cm unsupp
 An input file uses unsupported low-level
 .Xr roff 7
 features.
 The output may be incomplete and/or misformatted,
 so using GNU troff instead of
 .Nm
 to process the file may be preferable.
 .It Cm error
 An input file contains invalid syntax that cannot be safely interpreted.
 By discarding part of the input or inserting missing tokens,
 the parser is able to continue, and the error does not prevent
 generation of formatted output, but typically, preparing that
 output involves information loss, broken document structure
 or unintended formatting, no matter whether
 .Nm
 or GNU troff is used.
 In many cases, the output of
 .Nm
 and GNU troff is identical, but in some,
 .Nm
 is more resilient than GNU troff with respect to malformed input.
 .Pp
 Non-existent or unreadable input files are also reported on the
 .Cm error
 level.
 In that case, the parser cannot even be started and no output
 is produced from those input files.
 .It Cm warning
 An input file uses obsolete, discouraged or non-portable syntax.
 All the same, the meaning of the input is unambiguous and a correct
 rendering can be produced.
 Documents causing warnings may render poorly when using other
 formatting tools instead of
 .Nm .
 .El
 .Pp
 Messages of the
 .Cm warning ,
 .Cm error ,
 and
 .Cm unsupp
 levels except those about non-existent or unreadable input files
 are hidden unless their level, or a lower level, is requested using a
 .Fl W
 option or
 .Fl T Cm lint
 output mode.
 .Ss Warnings related to the document prologue
 .Bl -ohang
 .It Sy "missing manual title, using UNTITLED"
 .Pq mdoc
 A
 .Ic \&Dt
 macro has no arguments, or there is no
 .Ic \&Dt
 macro before the first non-prologue macro.
 .It Sy "missing manual title, using \(dq\(dq"
 .Pq man
 There is no
 .Ic \&TH
 macro, or it has no arguments.
 .It Sy "lower case character in document title"
 .Pq mdoc , man
 The title is still used as given in the
 .Ic \&Dt
 or
 .Ic \&TH
 macro.
 .It Sy "missing manual section, using \(dq\(dq"
 .Pq mdoc , man
 A
 .Ic \&Dt
 or
 .Ic \&TH
 macro lacks the mandatory section argument.
 .It Sy "unknown manual section"
 .Pq mdoc
 The section number in a
 .Ic \&Dt
 line is invalid, but still used.
 .It Sy "missing date, using today's date"
 .Pq mdoc, man
 The document was parsed as
 .Xr mdoc 7
 and it has no
 .Ic \&Dd
 macro, or the
 .Ic \&Dd
 macro has no arguments or only empty arguments;
 or the document was parsed as
 .Xr man 7
 and it has no
 .Ic \&TH
 macro, or the
 .Ic \&TH
 macro has less than three arguments or its third argument is empty.
 .It Sy "cannot parse date, using it verbatim"
 .Pq mdoc , man
 The date given in a
 .Ic \&Dd
 or
 .Ic \&TH
 macro does not follow the conventional format.
 .It Sy "missing Os macro, using \(dq\(dq"
 .Pq mdoc
 The default or current system is not shown in this case.
 .It Sy "duplicate prologue macro"
 .Pq mdoc
 One of the prologue macros occurs more than once.
 The last instance overrides all previous ones.
 .It Sy "late prologue macro"
 .Pq mdoc
 A
 .Ic \&Dd
 or
 .Ic \&Os
 macro occurs after some non-prologue macro, but still takes effect.
 .It Sy "skipping late title macro"
 .Pq mdoc
 The
 .Ic \&Dt
 macro appears after the first non-prologue macro.
 Traditional formatters cannot handle this because
 they write the page header before parsing the document body.
 Even though this technical restriction does not apply to
 .Nm ,
 traditional semantics is preserved.
 The late macro is discarded including its arguments.
 .It Sy "prologue macros out of order"
 .Pq mdoc
 The prologue macros are not given in the conventional order
 .Ic \&Dd ,
 .Ic \&Dt ,
 .Ic \&Os .
 All three macros are used even when given in another order.
 .El
 .Ss Warnings regarding document structure
 .Bl -ohang
 .It Sy ".so is fragile, better use ln(1)"
 .Pq roff
 Including files only works when the parser program runs with the correct
 current working directory.
 .It Sy "no document body"
 .Pq mdoc , man
 The document body contains neither text nor macros.
 An empty document is shown, consisting only of a header and a footer line.
 .It Sy "content before first section header"
 .Pq mdoc , man
 Some macros or text precede the first
 .Ic \&Sh
 or
 .Ic \&SH
 section header.
 The offending macros and text are parsed and added to the top level
 of the syntax tree, outside any section block.
 .It Sy "first section is not NAME"
 .Pq mdoc
 The argument of the first
 .Ic \&Sh
 macro is not
 .Sq NAME .
 This may confuse
 .Xr makewhatis 8
 and
 .Xr apropos 1 .
-.It Sy "NAME section without name"
+.It Sy "NAME section without Nm before Nd"
 .Pq mdoc
 The NAME section does not contain any
 .Ic \&Nm
-child macro.
+child macro before the first
+.Ic \&Nd
+macro.
 .It Sy "NAME section without description"
 .Pq mdoc
 The NAME section lacks the mandatory
 .Ic \&Nd
 child macro.
 .It Sy "description not at the end of NAME"
 .Pq mdoc
 The NAME section does contain an
 .Ic \&Nd
 child macro, but other content follows it.
 .It Sy "bad NAME section content"
 .Pq mdoc
 The NAME section contains plain text or macros other than
 .Ic \&Nm
 and
 .Ic \&Nd .
+.It Sy "missing comma before name"
+.Pq mdoc
+The NAME section contains an
+.Ic \&Nm
+macro that is neither the first one nor preceded by a comma.
 .It Sy "missing description line, using \(dq\(dq"
 .Pq mdoc
 The
 .Ic \&Nd
 macro lacks the required argument.
 The title line of the manual will end after the dash.
 .It Sy "sections out of conventional order"
 .Pq mdoc
 A standard section occurs after another section it usually precedes.
 All section titles are used as given,
 and the order of sections is not changed.
 .It Sy "duplicate section title"
 .Pq mdoc
 The same standard section title occurs more than once.
 .It Sy "unexpected section"
 .Pq mdoc
 A standard section header occurs in a section of the manual
 where it normally isn't useful.
 .It Sy "unusual Xr order"
 .Pq mdoc
 In the SEE ALSO section, an
 .Ic \&Xr
 macro with a lower section number follows one with a higher number,
 or two
 .Ic \&Xr
 macros referring to the same section are out of alphabetical order.
 .It Sy "unusual Xr punctuation"
 .Pq mdoc
 In the SEE ALSO section, punctuation between two
 .Ic \&Xr
 macros differs from a single comma, or there is trailing punctuation
 after the last
 .Ic \&Xr
 macro.
 .It Sy "AUTHORS section without An macro"
 .Pq mdoc
 An AUTHORS sections contains no
 .Ic \&An
 macros, or only empty ones.
 Probably, there are author names lacking markup.
 .El
 .Ss "Warnings related to macros and nesting"
 .Bl -ohang
 .It Sy "obsolete macro"
 .Pq mdoc
 See the
 .Xr mdoc 7
 manual for replacements.
 .It Sy "macro neither callable nor escaped"
 .Pq mdoc
 The name of a macro that is not callable appears on a macro line.
 It is printed verbatim.
 If the intention is to call it, move it to its own input line;
 otherwise, escape it by prepending
 .Sq \e& .
 .It Sy "skipping paragraph macro"
 In
 .Xr mdoc 7
 documents, this happens
 .Bl -dash -compact
 .It
 at the beginning and end of sections and subsections
 .It
 right before non-compact lists and displays
 .It
 at the end of items in non-column, non-compact lists
 .It
 and for multiple consecutive paragraph macros.
 .El
 In
 .Xr man 7
 documents, it happens
 .Bl -dash -compact
 .It
 for empty
 .Ic \&P ,
 .Ic \&PP ,
 and
 .Ic \&LP
 macros
 .It
 for
 .Ic \&IP
 macros having neither head nor body arguments
 .It
 for
 .Ic \&br
 or
 .Ic \&sp
 right after
 .Ic \&SH
 or
 .Ic \&SS
 .El
 .It Sy "moving paragraph macro out of list"
 .Pq mdoc
 A list item in a
 .Ic \&Bl
 list contains a trailing paragraph macro.
 The paragraph macro is moved after the end of the list.
 .It Sy "skipping no-space macro"
 .Pq mdoc
 An input line begins with an
 .Ic \&Ns
 macro.
 The macro is ignored.
 .It Sy "blocks badly nested"
 .Pq mdoc
 If two blocks intersect, one should completely contain the other.
 Otherwise, rendered output is likely to look strange in any output
 format, and rendering in SGML-based output formats is likely to be
 outright wrong because such languages do not support badly nested
 blocks at all.
 Typical examples of badly nested blocks are
 .Qq Ic \&Ao \&Bo \&Ac \&Bc
 and
 .Qq Ic \&Ao \&Bq \&Ac .
 In these examples,
 .Ic \&Ac
 breaks
 .Ic \&Bo
 and
 .Ic \&Bq ,
 respectively.
 .It Sy "nested displays are not portable"
 .Pq mdoc
 A
 .Ic \&Bd ,
 .Ic \&D1 ,
 or
 .Ic \&Dl
 display occurs nested inside another
 .Ic \&Bd
 display.
 This works with
 .Nm ,
 but fails with most other implementations.
 .It Sy "moving content out of list"
 .Pq mdoc
 A
 .Ic \&Bl
 list block contains text or macros before the first
 .Ic \&It
 macro.
 The offending children are moved before the beginning of the list.
 .It Sy "fill mode already enabled, skipping"
 .Pq man
 A
 .Ic \&fi
 request occurs even though the document is still in fill mode,
 or already switched back to fill mode.
 It has no effect.
 .It Sy "fill mode already disabled, skipping"
 .Pq man
 An
 .Ic \&nf
 request occurs even though the document already switched to no-fill mode
 and did not switch back to fill mode yet.
 It has no effect.
 .It Sy "line scope broken"
 .Pq man
 While parsing the next-line scope of the previous macro,
 another macro is found that prematurely terminates the previous one.
 The previous, interrupted macro is deleted from the parse tree.
 .El
 .Ss "Warnings related to missing arguments"
 .Bl -ohang
 .It Sy "skipping empty request"
 .Pq roff , eqn
 The macro name is missing from a macro definition request,
 or an
 .Xr eqn 7
 control statement or operation keyword lacks its required argument.
 .It Sy "conditional request controls empty scope"
 .Pq roff
 A conditional request is only useful if any of the following
 follows it on the same logical input line:
 .Bl -dash -compact
 .It
 The
 .Sq \e{
 keyword to open a multi-line scope.
 .It
 A request or macro or some text, resulting in a single-line scope.
 .It
 The immediate end of the logical line without any intervening whitespace,
 resulting in next-line scope.
 .El
 Here, a conditional request is followed by trailing whitespace only,
 and there is no other content on its logical input line.
 Note that it doesn't matter whether the logical input line is split
 across multiple physical input lines using
 .Sq \e
 line continuation characters.
 This is one of the rare cases
 where trailing whitespace is syntactically significant.
 The conditional request controls a scope containing whitespace only,
 so it is unlikely to have a significant effect,
 except that it may control a following
 .Ic \&el
 clause.
 .It Sy "skipping empty macro"
 .Pq mdoc
 The indicated macro has no arguments and hence no effect.
 .It Sy "empty block"
 .Pq mdoc , man
 A
 .Ic \&Bd ,
 .Ic \&Bk ,
 .Ic \&Bl ,
 .Ic \&D1 ,
 .Ic \&Dl ,
 .Ic \&RS ,
 or
 .Ic \&UR
 block contains nothing in its body and will produce no output.
 .It Sy "empty argument, using 0n"
 .Pq mdoc
 The required width is missing after
 .Ic \&Bd
 or
 .Ic \&Bl
 .Fl offset
 or
 .Fl width.
 .It Sy "missing display type, using -ragged"
 .Pq mdoc
 The
 .Ic \&Bd
 macro is invoked without the required display type.
 .It Sy "list type is not the first argument"
 .Pq mdoc
 In a
 .Ic \&Bl
 macro, at least one other argument precedes the type argument.
 The
 .Nm
 utility copes with any argument order, but some other
 .Xr mdoc 7
 implementations do not.
 .It Sy "missing -width in -tag list, using 8n"
 .Pq mdoc
 Every
 .Ic \&Bl
 macro having the
 .Fl tag
 argument requires
 .Fl width ,
 too.
 .It Sy "missing utility name, using \(dq\(dq"
 .Pq mdoc
 The
 .Ic \&Ex Fl std
 macro is called without an argument before
 .Ic \&Nm
 has first been called with an argument.
 .It Sy "missing function name, using \(dq\(dq"
 .Pq mdoc
 The
 .Ic \&Fo
 macro is called without an argument.
 No function name is printed.
 .It Sy "empty head in list item"
 .Pq mdoc
 In a
 .Ic \&Bl
 .Fl diag ,
 .Fl hang ,
 .Fl inset ,
 .Fl ohang ,
 or
 .Fl tag
 list, an
 .Ic \&It
 macro lacks the required argument.
 The item head is left empty.
 .It Sy "empty list item"
 .Pq mdoc
 In a
 .Ic \&Bl
 .Fl bullet ,
 .Fl dash ,
 .Fl enum ,
 or
 .Fl hyphen
 list, an
 .Ic \&It
 block is empty.
 An empty list item is shown.
 .It Sy "missing font type, using \efR"
 .Pq mdoc
 A
 .Ic \&Bf
 macro has no argument.
 It switches to the default font.
 .It Sy "unknown font type, using \efR"
 .Pq mdoc
 The
 .Ic \&Bf
 argument is invalid.
 The default font is used instead.
 .It Sy "nothing follows prefix"
 .Pq mdoc
 A
 .Ic \&Pf
 macro has no argument, or only one argument and no macro follows
 on the same input line.
 This defeats its purpose; in particular, spacing is not suppressed
 before the text or macros following on the next input line.
 .It Sy "empty reference block"
 .Pq mdoc
 An
 .Ic \&Rs
 macro is immediately followed by an
 .Ic \&Re
 macro on the next input line.
 Such an empty block does not produce any output.
+.It Sy "missing section argument"
+.Pq mdoc
+An
+.Ic \&Xr
+macro lacks its second, section number argument.
+The first argument, i.e. the name, is printed, but without subsequent
+parentheses.
 .It Sy "missing -std argument, adding it"
 .Pq mdoc
 An
 .Ic \&Ex
 or
 .Ic \&Rv
 macro lacks the required
 .Fl std
 argument.
 The
 .Nm
 utility assumes
 .Fl std
 even when it is not specified, but other implementations may not.
 .It Sy "missing option string, using \(dq\(dq"
 .Pq man
 The
 .Ic \&OP
 macro is invoked without any argument.
 An empty pair of square brackets is shown.
 .It Sy "missing resource identifier, using \(dq\(dq"
 .Pq man
 The
 .Ic \&UR
 macro is invoked without any argument.
 An empty pair of angle brackets is shown.
 .It Sy "missing eqn box, using \(dq\(dq"
 .Pq eqn
 A diacritic mark or a binary operator is found,
 but there is nothing to the left of it.
 An empty box is inserted.
 .El
 .Ss "Warnings related to bad macro arguments"
 .Bl -ohang
 .It Sy "unterminated quoted argument"
 .Pq roff
 Macro arguments can be enclosed in double quote characters
 such that space characters and macro names contained in the quoted
 argument need not be escaped.
 The closing quote of the last argument of a macro can be omitted.
 However, omitting it is not recommended because it makes the code
 harder to read.
 .It Sy "duplicate argument"
 .Pq mdoc
 A
 .Ic \&Bd
 or
 .Ic \&Bl
 macro has more than one
 .Fl compact ,
 more than one
 .Fl offset ,
 or more than one
 .Fl width
 argument.
 All but the last instances of these arguments are ignored.
 .It Sy "skipping duplicate argument"
 .Pq mdoc
 An
 .Ic \&An
 macro has more than one
 .Fl split
 or
 .Fl nosplit
 argument.
 All but the first of these arguments are ignored.
 .It Sy "skipping duplicate display type"
 .Pq mdoc
 A
 .Ic \&Bd
 macro has more than one type argument; the first one is used.
 .It Sy "skipping duplicate list type"
 .Pq mdoc
 A
 .Ic \&Bl
 macro has more than one type argument; the first one is used.
 .It Sy "skipping -width argument"
 .Pq mdoc
 A
 .Ic \&Bl
 .Fl column ,
 .Fl diag ,
 .Fl ohang ,
 .Fl inset ,
 or
 .Fl item
 list has a
 .Fl width
 argument.
 That has no effect.
 .It Sy "wrong number of cells"
 In a line of a
 .Ic \&Bl Fl column
 list, the number of tabs or
 .Ic \&Ta
 macros is less than the number expected from the list header line
 or exceeds the expected number by more than one.
 Missing cells remain empty, and all cells exceeding the number of
 columns are joined into one single cell.
 .It Sy "unknown AT&T UNIX version"
 .Pq mdoc
 An
 .Ic \&At
 macro has an invalid argument.
 It is used verbatim, with
 .Qq "AT&T UNIX "
 prefixed to it.
 .It Sy "comma in function argument"
 .Pq mdoc
 An argument of an
 .Ic \&Fa
 or
 .Ic \&Fn
 macro contains a comma; it should probably be split into two arguments.
 .It Sy "parenthesis in function name"
 .Pq mdoc
 The first argument of an
 .Ic \&Fc
 or
 .Ic \&Fn
 macro contains an opening or closing parenthesis; that's probably wrong,
 parentheses are added automatically.
 .It Sy "invalid content in Rs block"
 .Pq mdoc
 An
 .Ic \&Rs
 block contains plain text or non-% macros.
 The bogus content is left in the syntax tree.
 Formatting may be poor.
 .It Sy "invalid Boolean argument"
 .Pq mdoc
 An
 .Ic \&Sm
 macro has an argument other than
 .Cm on
 or
 .Cm off .
 The invalid argument is moved out of the macro, which leaves the macro
 empty, causing it to toggle the spacing mode.
 .It Sy "unknown font, skipping request"
 .Pq man , tbl
 A
 .Xr roff 7
 .Ic \&ft
 request or a
 .Xr tbl 7
 .Ic \&f
 layout modifier has an unknown
 .Ar font
 argument.
 .It Sy "odd number of characters in request"
 .Pq roff
 A
 .Ic \&tr
 request contains an odd number of characters.
 The last character is mapped to the blank character.
 .El
 .Ss "Warnings related to plain text"
 .Bl -ohang
 .It Sy "blank line in fill mode, using .sp"
 .Pq mdoc
 The meaning of blank input lines is only well-defined in non-fill mode:
 In fill mode, line breaks of text input lines are not supposed to be
 significant.
 However, for compatibility with groff, blank lines in fill mode
 are replaced with
 .Ic \&sp
 requests.
 .It Sy "tab in filled text"
 .Pq mdoc , man
 The meaning of tab characters is only well-defined in non-fill mode:
 In fill mode, whitespace is not supposed to be significant
 on text input lines.
 As an implementation dependent choice, tab characters on text lines
 are passed through to the formatters in any case.
 Given that the text before the tab character will be filled,
 it is hard to predict which tab stop position the tab will advance to.
 .It Sy "whitespace at end of input line"
 .Pq mdoc , man , roff
 Whitespace at the end of input lines is almost never semantically
 significant \(em but in the odd case where it might be, it is
 extremely confusing when reviewing and maintaining documents.
 .It Sy "bad comment style"
 .Pq roff
 Comment lines start with a dot, a backslash, and a double-quote character.
 The
 .Nm
 utility treats the line as a comment line even without the backslash,
 but leaving out the backslash might not be portable.
 .It Sy "invalid escape sequence"
 .Pq roff
 An escape sequence has an invalid opening argument delimiter, lacks the
 closing argument delimiter, or the argument has too few characters.
 If the argument is incomplete,
 .Ic \e*
 and
 .Ic \en
 expand to an empty string,
 .Ic \eB
 to the digit
 .Sq 0 ,
 and
 .Ic \ew
 to the length of the incomplete argument.
 All other invalid escape sequences are ignored.
 .It Sy "undefined string, using \(dq\(dq"
 .Pq roff
 If a string is used without being defined before,
 its value is implicitly set to the empty string.
 However, defining strings explicitly before use
 keeps the code more readable.
 .El
 .Ss "Warnings related to tables"
 .Bl -ohang
 .It Sy "tbl line starts with span"
 .Pq tbl
 The first cell in a table layout line is a horizontal span
 .Pq Sq Cm s .
 Data provided for this cell is ignored, and nothing is printed in the cell.
 .It Sy "tbl column starts with span"
 .Pq tbl
 The first line of a table layout specification
 requests a vertical span
 .Pq Sq Cm ^ .
 Data provided for this cell is ignored, and nothing is printed in the cell.
 .It Sy "skipping vertical bar in tbl layout"
 .Pq tbl
 A table layout specification contains more than two consecutive vertical bars.
 A double bar is printed, all additional bars are discarded.
 .El
 .Ss "Errors related to tables"
 .Bl -ohang
 .It Sy "non-alphabetic character in tbl options"
 .Pq tbl
 The table options line contains a character other than a letter,
 blank, or comma where the beginning of an option name is expected.
 The character is ignored.
 .It Sy "skipping unknown tbl option"
 .Pq tbl
 The table options line contains a string of letters that does not
 match any known option name.
 The word is ignored.
 .It Sy "missing tbl option argument"
 .Pq tbl
 A table option that requires an argument is not followed by an
 opening parenthesis, or the opening parenthesis is immediately
 followed by a closing parenthesis.
 The option is ignored.
 .It Sy "wrong tbl option argument size"
 .Pq tbl
 A table option argument contains an invalid number of characters.
 Both the option and the argument are ignored.
 .It Sy "empty tbl layout"
 .Pq tbl
 A table layout specification is completely empty,
 specifying zero lines and zero columns.
 As a fallback, a single left-justified column is used.
 .It Sy "invalid character in tbl layout"
 .Pq tbl
 A table layout specification contains a character that can neither
 be interpreted as a layout key character nor as a layout modifier,
 or a modifier precedes the first key.
 The invalid character is discarded.
 .It Sy "unmatched parenthesis in tbl layout"
 .Pq tbl
 A table layout specification contains an opening parenthesis,
 but no matching closing parenthesis.
 The rest of the input line, starting from the parenthesis, has no effect.
 .It Sy "tbl without any data cells"
 .Pq tbl
 A table does not contain any data cells.
 It will probably produce no output.
 .It Sy "ignoring data in spanned tbl cell"
 .Pq tbl
 A table cell is marked as a horizontal span
 .Pq Sq Cm s
 or vertical span
 .Pq Sq Cm ^
 in the table layout, but it contains data.
 The data is ignored.
 .It Sy "ignoring extra tbl data cells"
 .Pq tbl
 A data line contains more cells than the corresponding layout line.
 The data in the extra cells is ignored.
 .It Sy "data block open at end of tbl"
 .Pq tbl
 A data block is opened with
 .Cm T{ ,
 but never closed with a matching
 .Cm T} .
 The remaining data lines of the table are all put into one cell,
 and any remaining cells stay empty.
 .El
 .Ss "Errors related to roff, mdoc, and man code"
 .Bl -ohang
 .It Sy "input stack limit exceeded, infinite loop?"
 .Pq roff
 Explicit recursion limits are implemented for the following features,
 in order to prevent infinite loops:
 .Bl -dash -compact
 .It
 expansion of nested escape sequences
 including expansion of strings and number registers,
 .It
 expansion of nested user-defined macros,
 .It
 and
 .Ic \&so
 file inclusion.
 .El
 When a limit is hit, the output is incorrect, typically losing
 some content, but the parser can continue.
 .It Sy "skipping bad character"
 .Pq mdoc , man , roff
 The input file contains a byte that is not a printable
 .Xr ascii 7
 character.
 The message mentions the character number.
 The offending byte is replaced with a question mark
 .Pq Sq \&? .
 Consider editing the input file to replace the byte with an ASCII
 transliteration of the intended character.
 .It Sy "skipping unknown macro"
 .Pq mdoc , man , roff
 The first identifier on a request or macro line is neither recognized as a
 .Xr roff 7
 request, nor as a user-defined macro, nor, respectively, as an
 .Xr mdoc 7
 or
 .Xr man 7
 macro.
 It may be mistyped or unsupported.
 The request or macro is discarded including its arguments.
 .It Sy "skipping insecure request"
 .Pq roff
 An input file attempted to run a shell command
 or to read or write an external file.
 Such attempts are denied for security reasons.
 .It Sy "skipping item outside list"
 .Pq mdoc , eqn
 An
 .Ic \&It
 macro occurs outside any
 .Ic \&Bl
 list, or an
 .Xr eqn 7
 .Ic above
 delimiter occurs outside any pile.
 It is discarded including its arguments.
 .It Sy "skipping column outside column list"
 .Pq mdoc
 A
 .Ic \&Ta
 macro occurs outside any
 .Ic \&Bl Fl column
 block.
 It is discarded including its arguments.
 .It Sy "skipping end of block that is not open"
 .Pq mdoc , man , eqn , tbl , roff
 Various syntax elements can only be used to explicitly close blocks
 that have previously been opened.
 An
 .Xr mdoc 7
 block closing macro, a
 .Xr man 7
 .Ic \&RE
 or
 .Ic \&UE
 macro, an
 .Xr eqn 7
 right delimiter or closing brace, or the end of an equation, table, or
 .Xr roff 7
 conditional request is encountered but no matching block is open.
 The offending request or macro is discarded.
 .It Sy "fewer RS blocks open, skipping"
 .Pq man
 The
 .Ic \&RE
 macro is invoked with an argument, but less than the specified number of
 .Ic \&RS
 blocks is open.
 The
 .Ic \&RE
 macro is discarded.
 .It Sy "inserting missing end of block"
 .Pq mdoc , tbl
 Various
 .Xr mdoc 7
 macros as well as tables require explicit closing by dedicated macros.
 A block that doesn't support bad nesting
 ends before all of its children are properly closed.
 The open child nodes are closed implicitly.
 .It Sy "appending missing end of block"
 .Pq mdoc , man , eqn , tbl , roff
 At the end of the document, an explicit
 .Xr mdoc 7
 block, a
 .Xr man 7
 next-line scope or
 .Ic \&RS
 or
 .Ic \&UR
 block, an equation, table, or
 .Xr roff 7
 conditional or ignore block is still open.
 The open block is closed implicitly.
 .It Sy "escaped character not allowed in a name"
 .Pq roff
 Macro, string and register identifiers consist of printable,
 non-whitespace ASCII characters.
 Escape sequences and characters and strings expressed in terms of them
 cannot form part of a name.
 The first argument of an
 .Ic \&am ,
 .Ic \&as ,
 .Ic \&de ,
 .Ic \&ds ,
 .Ic \&nr ,
 or
 .Ic \&rr
 request, or any argument of an
 .Ic \&rm
 request, or the name of a request or user defined macro being called,
 is terminated by an escape sequence.
 In the cases of
 .Ic \&as ,
 .Ic \&ds ,
 and
 .Ic \&nr ,
 the request has no effect at all.
 In the cases of
 .Ic \&am ,
 .Ic \&de ,
 .Ic \&rr ,
 and
 .Ic \&rm ,
 what was parsed up to this point is used as the arguments to the request,
 and the rest of the input line is discarded including the escape sequence.
 When parsing for a request or a user-defined macro name to be called,
 only the escape sequence is discarded.
 The characters preceding it are used as the request or macro name,
 the characters following it are used as the arguments to the request or macro.
 .It Sy "NOT IMPLEMENTED: Bd -file"
 .Pq mdoc
 For security reasons, the
 .Ic \&Bd
 macro does not support the
 .Fl file
 argument.
 By requesting the inclusion of a sensitive file, a malicious document
 might otherwise trick a privileged user into inadvertently displaying
 the file on the screen, revealing the file content to bystanders.
 The argument is ignored including the file name following it.
 .It Sy "skipping display without arguments"
 .Pq mdoc
 A
 .Ic \&Bd
 block macro does not have any arguments.
 The block is discarded, and the block content is displayed in
 whatever mode was active before the block.
 .It Sy "missing list type, using -item"
 .Pq mdoc
 A
 .Ic \&Bl
 macro fails to specify the list type.
 .It Sy "missing manual name, using \(dq\(dq"
 .Pq mdoc
 The first call to
-.Ic \&Nm
-lacks the required argument.
+.Ic \&Nm ,
+or any call in the NAME section, lacks the required argument.
 .It Sy "uname(3) system call failed, using UNKNOWN"
 .Pq mdoc
 The
 .Ic \&Os
 macro is called without arguments, and the
 .Xr uname 3
 system call failed.
 As a workaround,
 .Nm
 can be compiled with
 .Sm off
 .Fl D Cm OSNAME=\(dq\e\(dq Ar string Cm \e\(dq\(dq .
 .Sm on
 .It Sy "unknown standard specifier"
 .Pq mdoc
 An
 .Ic \&St
 macro has an unknown argument and is discarded.
 .It Sy "skipping request without numeric argument"
 .Pq roff , eqn
 An
 .Ic \&it
 request or an
 .Xr eqn 7
 .Ic \&size
 or
 .Ic \&gsize
 statement has a non-numeric or negative argument or no argument at all.
 The invalid request or statement is ignored.
 .It Sy "NOT IMPLEMENTED: .so with absolute path or \(dq..\(dq"
 .Pq roff
 For security reasons,
 .Nm
 allows
 .Ic \&so
 file inclusion requests only with relative paths
 and only without ascending to any parent directory.
 By requesting the inclusion of a sensitive file, a malicious document
 might otherwise trick a privileged user into inadvertently displaying
 the file on the screen, revealing the file content to bystanders.
 .Nm
 only shows the path as it appears behind
 .Ic \&so .
 .It Sy ".so request failed"
 .Pq roff
 Servicing a
 .Ic \&so
 request requires reading an external file, but the file could not be
 opened.
 .Nm
 only shows the path as it appears behind
 .Ic \&so .
 .It Sy "skipping all arguments"
 .Pq mdoc , man , eqn , roff
 An
 .Xr mdoc 7
 .Ic \&Bt ,
 .Ic \&Ed ,
 .Ic \&Ef ,
 .Ic \&Ek ,
 .Ic \&El ,
 .Ic \&Lp ,
 .Ic \&Pp ,
 .Ic \&Re ,
 .Ic \&Rs ,
 or
 .Ic \&Ud
 macro, an
 .Ic \&It
 macro in a list that don't support item heads, a
 .Xr man 7
 .Ic \&LP ,
 .Ic \&P ,
 or
 .Ic \&PP
 macro, an
 .Xr eqn 7
 .Ic \&EQ
 or
 .Ic \&EN
 macro, or a
 .Xr roff 7
 .Ic \&br ,
 .Ic \&fi ,
 or
 .Ic \&nf
 request or
 .Sq \&..
 block closing request is invoked with at least one argument.
 All arguments are ignored.
 .It Sy "skipping excess arguments"
 .Pq mdoc , man , roff
 A macro or request is invoked with too many arguments:
 .Bl -dash -offset 2n -width 2n -compact
 .It
 .Ic \&Fo ,
 .Ic \&PD ,
 .Ic \&RS ,
 .Ic \&UR ,
 .Ic \&ft ,
 or
 .Ic \&sp
 with more than one argument
 .It
 .Ic \&An
 with another argument after
 .Fl split
 or
 .Fl nosplit
 .It
 .Ic \&RE
 with more than one argument or with a non-integer argument
 .It
 .Ic \&OP
 or a request of the
 .Ic \&de
 family with more than two arguments
 .It
 .Ic \&Dt
 with more than three arguments
 .It
 .Ic \&TH
 with more than five arguments
 .It
 .Ic \&Bd ,
 .Ic \&Bk ,
 or
 .Ic \&Bl
 with invalid arguments
 .El
 The excess arguments are ignored.
 .El
 .Ss Unsupported features
 .Bl -ohang
 .It Sy "input too large"
 .Pq mdoc , man
 Currently,
 .Nm
 cannot handle input files larger than its arbitrary size limit
 of 2^31 bytes (2 Gigabytes).
 Since useful manuals are always small, this is not a problem in practice.
 Parsing is aborted as soon as the condition is detected.
 .It Sy "unsupported control character"
 .Pq roff
 An ASCII control character supported by other
 .Xr roff 7
 implementations but not by
 .Nm
 was found in an input file.
 It is replaced by a question mark.
 .It Sy "unsupported roff request"
 .Pq roff
 An input file contains a
 .Xr roff 7
 request supported by GNU troff or Heirloom troff but not by
 .Nm ,
 and it is likely that this will cause information loss
 or considerable misformatting.
 .It Sy "eqn delim option in tbl"
 .Pq eqn , tbl
 The options line of a table defines equation delimiters.
 Any equation source code contained in the table will be printed unformatted.
 .It Sy "unsupported table layout modifier"
 .Pq tbl
 A table layout specification contains an
 .Sq Cm m
 modifier.
 The modifier is discarded.
 .It Sy "ignoring macro in table"
 .Pq tbl , mdoc , man
 A table contains an invocation of an
 .Xr mdoc 7
 or
 .Xr man 7
 macro or of an undefined macro.
 The macro is ignored, and its arguments are handled
 as if they were a text line.
 .El
 .Sh SEE ALSO
 .Xr apropos 1 ,
 .Xr man 1 ,
 .Xr eqn 7 ,
 .Xr man 7 ,
 .Xr mandoc_char 7 ,
 .Xr mdoc 7 ,
 .Xr roff 7 ,
 .Xr tbl 7
 .Sh AUTHORS
 .An -nosplit
 The
 .Nm
 utility was written by
 .An Kristaps Dzonsons Aq Mt kristaps@bsd.lv
 and is maintained by
 .An Ingo Schwarze Aq Mt schwarze@openbsd.org .
-.Sh BUGS
-In
-.Fl T Cm html ,
-the maximum size of an element attribute is determined by
-.Dv BUFSIZ ,
-which is usually 1024 bytes.
-Be aware of this when setting long link
-formats such as
-.Fl O Cm style Ns = Ns Ar really/long/link .
Index: stable/11/contrib/mdocml/mandoc.3
===================================================================
--- stable/11/contrib/mdocml/mandoc.3	(revision 316419)
+++ stable/11/contrib/mdocml/mandoc.3	(revision 316420)
@@ -1,677 +1,702 @@
-.\"	$Id: mandoc.3,v 1.37 2016/07/07 19:19:01 schwarze Exp $
+.\"	$Id: mandoc.3,v 1.38 2017/01/09 01:37:03 schwarze Exp $
 .\"
 .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons 
-.\" Copyright (c) 2010-2016 Ingo Schwarze 
+.\" Copyright (c) 2010-2017 Ingo Schwarze 
 .\"
 .\" 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.
 .\"
-.Dd $Mdocdate: July 7 2016 $
+.Dd $Mdocdate: January 9 2017 $
 .Dt MANDOC 3
 .Os
 .Sh NAME
 .Nm mandoc ,
 .Nm deroff ,
 .Nm mandocmsg ,
 .Nm man_mparse ,
 .Nm man_validate ,
 .Nm mdoc_validate ,
 .Nm mparse_alloc ,
 .Nm mparse_free ,
 .Nm mparse_getkeep ,
 .Nm mparse_keep ,
 .Nm mparse_open ,
 .Nm mparse_readfd ,
 .Nm mparse_reset ,
 .Nm mparse_result ,
 .Nm mparse_strerror ,
-.Nm mparse_strlevel
+.Nm mparse_strlevel ,
+.Nm mparse_updaterc 
 .Nd mandoc macro compiler library
 .Sh SYNOPSIS
 .In sys/types.h
 .In mandoc.h
 .Pp
 .Fd "#define ASCII_NBRSP"
 .Fd "#define ASCII_HYPH"
 .Fd "#define ASCII_BREAK"
 .Ft struct mparse *
 .Fo mparse_alloc
 .Fa "int options"
 .Fa "enum mandoclevel wlevel"
 .Fa "mandocmsg mmsg"
 .Fa "char *defos"
 .Fc
 .Ft void
 .Fo (*mandocmsg)
 .Fa "enum mandocerr errtype"
 .Fa "enum mandoclevel level"
 .Fa "const char *file"
 .Fa "int line"
 .Fa "int col"
 .Fa "const char *msg"
 .Fc
 .Ft void
 .Fo mparse_free
 .Fa "struct mparse *parse"
 .Fc
 .Ft const char *
 .Fo mparse_getkeep
 .Fa "const struct mparse *parse"
 .Fc
 .Ft void
 .Fo mparse_keep
 .Fa "struct mparse *parse"
 .Fc
 .Ft int
 .Fo mparse_open
 .Fa "struct mparse *parse"
 .Fa "const char *fname"
 .Fc
 .Ft "enum mandoclevel"
 .Fo mparse_readfd
 .Fa "struct mparse *parse"
 .Fa "int fd"
 .Fa "const char *fname"
 .Fc
 .Ft void
 .Fo mparse_reset
 .Fa "struct mparse *parse"
 .Fc
 .Ft void
 .Fo mparse_result
 .Fa "struct mparse *parse"
 .Fa "struct roff_man **man"
 .Fa "char **sodest"
 .Fc
 .Ft "const char *"
 .Fo mparse_strerror
 .Fa "enum mandocerr"
 .Fc
 .Ft "const char *"
 .Fo mparse_strlevel
 .Fa "enum mandoclevel"
 .Fc
+.Ft void
+.Fo mparse_updaterc
+.Fa "struct mparse *parse"
+.Fa "enum mandoclevel *rc"
+.Fc
 .In roff.h
 .Ft void
 .Fo deroff
 .Fa "char **dest"
 .Fa "const struct roff_node *node"
 .Fc
 .In sys/types.h
 .In mandoc.h
 .In mdoc.h
 .Vt extern const char * const * mdoc_argnames;
 .Vt extern const char * const * mdoc_macronames;
 .Ft void
 .Fo mdoc_validate
 .Fa "struct roff_man *mdoc"
 .Fc
 .In sys/types.h
 .In mandoc.h
 .In man.h
 .Vt extern const char * const * man_macronames;
 .Ft "const struct mparse *"
 .Fo man_mparse
 .Fa "const struct roff_man *man"
 .Fc
 .Ft void
 .Fo man_validate
 .Fa "struct roff_man *man"
 .Fc
 .Sh DESCRIPTION
 The
 .Nm mandoc
 library parses a
 .Ux
 manual into an abstract syntax tree (AST).
 .Ux
 manuals are composed of
 .Xr mdoc 7
 or
 .Xr man 7 ,
 and may be mixed with
 .Xr roff 7 ,
 .Xr tbl 7 ,
 and
 .Xr eqn 7
 invocations.
 .Pp
 The following describes a general parse sequence:
 .Bl -enum
 .It
 initiate a parsing sequence with
 .Xr mchars_alloc 3
 and
 .Fn mparse_alloc ;
 .It
 open a file with
 .Xr open 2
 or
 .Fn mparse_open ;
 .It
 parse it with
 .Fn mparse_readfd ;
 .It
 close it with
 .Xr close 2 ;
 .It
 retrieve the syntax tree with
 .Fn mparse_result ;
 .It
 depending on whether the
 .Fa macroset
 member of the returned
 .Vt struct roff_man
 is
 .Dv MACROSET_MDOC
 or
 .Dv MACROSET_MAN ,
 validate it with
 .Fn mdoc_validate
 or
 .Fn man_validate ,
 respectively;
 .It
+if information about the validity of the input is needed, fetch it with
+.Fn mparse_updaterc ;
+.It
 iterate over parse nodes with starting from the
 .Fa first
 member of the returned
 .Vt struct roff_man ;
 .It
 free all allocated memory with
 .Fn mparse_free
 and
 .Xr mchars_free 3 ,
 or invoke
 .Fn mparse_reset
 and go back to step 2 to parse new files.
 .El
 .Sh REFERENCE
 This section documents the functions, types, and variables available
 via
 .In mandoc.h ,
 with the exception of those documented in
 .Xr mandoc_escape 3
 and
 .Xr mchars_alloc 3 .
 .Ss Types
 .Bl -ohang
 .It Vt "enum mandocerr"
 An error or warning message during parsing.
 .It Vt "enum mandoclevel"
 A classification of an
 .Vt "enum mandocerr"
 as regards system operation.
 See the DIAGNOSTICS section in
 .Xr mandoc 1
 regarding the meanings of the levels.
 .It Vt "struct mparse"
 An opaque pointer to a running parse sequence.
 Created with
 .Fn mparse_alloc
 and freed with
 .Fn mparse_free .
 This may be used across parsed input if
 .Fn mparse_reset
 is called between parses.
 .It Vt "mandocmsg"
 A prototype for a function to handle error and warning
 messages emitted by the parser.
 .El
 .Ss Functions
 .Bl -ohang
 .It Fn deroff
 Obtain a text-only representation of a
 .Vt struct roff_node ,
 including text contained in its child nodes.
 To be used on children of the
 .Fa first
 member of
 .Vt struct roff_man .
 When it is no longer needed, the pointer returned from
 .Fn deroff
 can be passed to
 .Xr free 3 .
 .It Fn man_mparse
 Get the parser used for the current output.
 Declared in
 .In man.h ,
 implemented in
 .Pa man.c .
 .It Fn man_validate
 Validate the
 .Dv MACROSET_MAN
 parse tree obtained with
 .Fn mparse_result .
 Declared in
 .In man.h ,
 implemented in
 .Pa man.c .
 .It Fn mdoc_validate
 Validate the
 .Dv MACROSET_MDOC
 parse tree obtained with
 .Fn mparse_result .
 Declared in
 .In mdoc.h ,
 implemented in
 .Pa mdoc.c .
 .It Fn mparse_alloc
 Allocate a parser.
 The arguments have the following effect:
 .Bl -tag -offset 5n -width inttype
 .It Ar options
 When the
 .Dv MPARSE_MDOC
 or
 .Dv MPARSE_MAN
 bit is set, only that parser is used.
 Otherwise, the document type is automatically detected.
 .Pp
 When the
 .Dv MPARSE_SO
 bit is set,
 .Xr roff 7
 .Ic \&so
 file inclusion requests are always honoured.
 Otherwise, if the request is the only content in an input file,
 only the file name is remembered, to be returned in the
 .Fa sodest
 argument of
 .Fn mparse_result .
 .Pp
 When the
 .Dv MPARSE_QUICK
 bit is set, parsing is aborted after the NAME section.
 This is for example useful in
 .Xr makewhatis 8
 .Fl Q
 to quickly build minimal databases.
 .It Ar wlevel
 Can be set to
 .Dv MANDOCLEVEL_BADARG ,
 .Dv MANDOCLEVEL_ERROR ,
 or
 .Dv MANDOCLEVEL_WARNING .
 Messages below the selected level will be suppressed.
 .It Ar mmsg
 A callback function to handle errors and warnings.
 See
 .Pa main.c
 for an example.
 If printing of error messages is not desired,
 .Dv NULL
 may be passed.
 .It Ar defos
 A default string for the
 .Xr mdoc 7
 .Sq \&Os
 macro, overriding the
 .Dv OSNAME
 preprocessor definition and the results of
 .Xr uname 3 .
 Passing
 .Dv NULL
 sets no default.
 .El
 .Pp
 The same parser may be used for multiple files so long as
 .Fn mparse_reset
 is called between parses.
 .Fn mparse_free
 must be called to free the memory allocated by this function.
 Declared in
 .In mandoc.h ,
 implemented in
 .Pa read.c .
 .It Fn mparse_free
 Free all memory allocated by
 .Fn mparse_alloc .
 Declared in
 .In mandoc.h ,
 implemented in
 .Pa read.c .
 .It Fn mparse_getkeep
 Acquire the keep buffer.
 Must follow a call of
 .Fn mparse_keep .
 Declared in
 .In mandoc.h ,
 implemented in
 .Pa read.c .
 .It Fn mparse_keep
 Instruct the parser to retain a copy of its parsed input.
 This can be acquired with subsequent
 .Fn mparse_getkeep
 calls.
 Declared in
 .In mandoc.h ,
 implemented in
 .Pa read.c .
 .It Fn mparse_open
 Open the file for reading.
 If that fails and
 .Fa fname
 does not already end in
 .Ql .gz ,
 try again after appending
 .Ql .gz .
 Save the information whether the file is zipped or not.
 Return a file descriptor open for reading or -1 on failure.
 It can be passed to
 .Fn mparse_readfd
 or used directly.
 Declared in
 .In mandoc.h ,
 implemented in
 .Pa read.c .
 .It Fn mparse_readfd
 Parse a file descriptor opened with
 .Xr open 2
 or
 .Fn mparse_open .
 Pass the associated filename in
 .Va fname .
 This function may be called multiple times with different parameters; however,
 .Xr close 2
 and
 .Fn mparse_reset
 should be invoked between parses.
 Declared in
 .In mandoc.h ,
 implemented in
 .Pa read.c .
 .It Fn mparse_reset
 Reset a parser so that
 .Fn mparse_readfd
 may be used again.
 Declared in
 .In mandoc.h ,
 implemented in
 .Pa read.c .
 .It Fn mparse_result
 Obtain the result of a parse.
 One of the two pointers will be filled in.
 Declared in
 .In mandoc.h ,
 implemented in
 .Pa read.c .
 .It Fn mparse_strerror
 Return a statically-allocated string representation of an error code.
 Declared in
 .In mandoc.h ,
 implemented in
 .Pa read.c .
 .It Fn mparse_strlevel
 Return a statically-allocated string representation of a level code.
+Declared in
+.In mandoc.h ,
+implemented in
+.Pa read.c .
+.It Fn mparse_updaterc
+If the highest warning or error level that occurred during the current
+.Fa parse
+is higher than
+.Pf * Fa rc ,
+update
+.Pf * Fa rc
+accordingly.
+This is useful after calling
+.Fn mdoc_validate
+or
+.Fn man_validate .
 Declared in
 .In mandoc.h ,
 implemented in
 .Pa read.c .
 .El
 .Ss Variables
 .Bl -ohang
 .It Va man_macronames
 The string representation of a
 .Xr man 7
 macro as indexed by
 .Vt "enum mant" .
 .It Va mdoc_argnames
 The string representation of an
 .Xr mdoc 7
 macro argument as indexed by
 .Vt "enum mdocargt" .
 .It Va mdoc_macronames
 The string representation of an
 .Xr mdoc 7
 macro as indexed by
 .Vt "enum mdoct" .
 .El
 .Sh IMPLEMENTATION NOTES
 This section consists of structural documentation for
 .Xr mdoc 7
 and
 .Xr man 7
 syntax trees and strings.
 .Ss Man and Mdoc Strings
 Strings may be extracted from mdoc and man meta-data, or from text
 nodes (MDOC_TEXT and MAN_TEXT, respectively).
 These strings have special non-printing formatting cues embedded in the
 text itself, as well as
 .Xr roff 7
 escapes preserved from input.
 Implementing systems will need to handle both situations to produce
 human-readable text.
 In general, strings may be assumed to consist of 7-bit ASCII characters.
 .Pp
 The following non-printing characters may be embedded in text strings:
 .Bl -tag -width Ds
 .It Dv ASCII_NBRSP
 A non-breaking space character.
 .It Dv ASCII_HYPH
 A soft hyphen.
 .It Dv ASCII_BREAK
 A breakable zero-width space.
 .El
 .Pp
 Escape characters are also passed verbatim into text strings.
 An escape character is a sequence of characters beginning with the
 backslash
 .Pq Sq \e .
 To construct human-readable text, these should be intercepted with
 .Xr mandoc_escape 3
 and converted with one the functions described in
 .Xr mchars_alloc 3 .
 .Ss Man Abstract Syntax Tree
 This AST is governed by the ontological rules dictated in
 .Xr man 7
 and derives its terminology accordingly.
 .Pp
 The AST is composed of
 .Vt struct roff_node
 nodes with element, root and text types as declared by the
 .Va type
 field.
 Each node also provides its parse point (the
 .Va line ,
 .Va pos ,
 and
 .Va sec
 fields), its position in the tree (the
 .Va parent ,
 .Va child ,
 .Va next
 and
 .Va prev
 fields) and some type-specific data.
 .Pp
 The tree itself is arranged according to the following normal form,
 where capitalised non-terminals represent nodes.
 .Pp
 .Bl -tag -width "ELEMENTXX" -compact
 .It ROOT
 \(<- mnode+
 .It mnode
 \(<- ELEMENT | TEXT | BLOCK
 .It BLOCK
 \(<- HEAD BODY
 .It HEAD
 \(<- mnode*
 .It BODY
 \(<- mnode*
 .It ELEMENT
 \(<- ELEMENT | TEXT*
 .It TEXT
 \(<- [[:ascii:]]*
 .El
 .Pp
 The only elements capable of nesting other elements are those with
 next-line scope as documented in
 .Xr man 7 .
 .Ss Mdoc Abstract Syntax Tree
 This AST is governed by the ontological
 rules dictated in
 .Xr mdoc 7
 and derives its terminology accordingly.
 .Qq In-line
 elements described in
 .Xr mdoc 7
 are described simply as
 .Qq elements .
 .Pp
 The AST is composed of
 .Vt struct roff_node
 nodes with block, head, body, element, root and text types as declared
 by the
 .Va type
 field.
 Each node also provides its parse point (the
 .Va line ,
 .Va pos ,
 and
 .Va sec
 fields), its position in the tree (the
 .Va parent ,
 .Va child ,
 .Va last ,
 .Va next
 and
 .Va prev
 fields) and some type-specific data, in particular, for nodes generated
 from macros, the generating macro in the
 .Va tok
 field.
 .Pp
 The tree itself is arranged according to the following normal form,
 where capitalised non-terminals represent nodes.
 .Pp
 .Bl -tag -width "ELEMENTXX" -compact
 .It ROOT
 \(<- mnode+
 .It mnode
 \(<- BLOCK | ELEMENT | TEXT
 .It BLOCK
 \(<- HEAD [TEXT] (BODY [TEXT])+ [TAIL [TEXT]]
 .It ELEMENT
 \(<- TEXT*
 .It HEAD
 \(<- mnode*
 .It BODY
 \(<- mnode* [ENDBODY mnode*]
 .It TAIL
 \(<- mnode*
 .It TEXT
 \(<- [[:ascii:]]*
 .El
 .Pp
 Of note are the TEXT nodes following the HEAD, BODY and TAIL nodes of
 the BLOCK production: these refer to punctuation marks.
 Furthermore, although a TEXT node will generally have a non-zero-length
 string, in the specific case of
 .Sq \&.Bd \-literal ,
 an empty line will produce a zero-length string.
 Multiple body parts are only found in invocations of
 .Sq \&Bl \-column ,
 where a new body introduces a new phrase.
 .Pp
 The
 .Xr mdoc 7
 syntax tree accommodates for broken block structures as well.
 The ENDBODY node is available to end the formatting associated
 with a given block before the physical end of that block.
 It has a non-null
 .Va end
 field, is of the BODY
 .Va type ,
 has the same
 .Va tok
 as the BLOCK it is ending, and has a
 .Va pending
 field pointing to that BLOCK's BODY node.
 It is an indirect child of that BODY node
 and has no children of its own.
 .Pp
 An ENDBODY node is generated when a block ends while one of its child
 blocks is still open, like in the following example:
 .Bd -literal -offset indent
 \&.Ao ao
 \&.Bo bo ac
 \&.Ac bc
 \&.Bc end
 .Ed
 .Pp
 This example results in the following block structure:
 .Bd -literal -offset indent
 BLOCK Ao
     HEAD Ao
     BODY Ao
         TEXT ao
         BLOCK Bo, pending -> Ao
             HEAD Bo
             BODY Bo
                 TEXT bo
                 TEXT ac
                 ENDBODY Ao, pending -> Ao
                 TEXT bc
 TEXT end
 .Ed
 .Pp
 Here, the formatting of the
 .Sq \&Ao
 block extends from TEXT ao to TEXT ac,
 while the formatting of the
 .Sq \&Bo
 block extends from TEXT bo to TEXT bc.
 It renders as follows in
 .Fl T Ns Cm ascii
 mode:
 .Pp
 .Dl  bc] end
 .Pp
 Support for badly-nested blocks is only provided for backward
 compatibility with some older
 .Xr mdoc 7
 implementations.
 Using badly-nested blocks is
 .Em strongly discouraged ;
 for example, the
 .Fl T Ns Cm html
 and
 .Fl T Ns Cm xhtml
 front-ends to
 .Xr mandoc 1
 are unable to render them in any meaningful way.
 Furthermore, behaviour when encountering badly-nested blocks is not
 consistent across troff implementations, especially when using multiple
 levels of badly-nested blocks.
 .Sh SEE ALSO
 .Xr mandoc 1 ,
 .Xr man.cgi 3 ,
 .Xr mandoc_escape 3 ,
 .Xr mandoc_headers 3 ,
 .Xr mandoc_malloc 3 ,
 .Xr mansearch 3 ,
 .Xr mchars_alloc 3 ,
 .Xr tbl 3 ,
 .Xr eqn 7 ,
 .Xr man 7 ,
 .Xr mandoc_char 7 ,
 .Xr mdoc 7 ,
 .Xr roff 7 ,
 .Xr tbl 7
 .Sh AUTHORS
 .An -nosplit
 The
 .Nm
 library was written by
 .An Kristaps Dzonsons Aq Mt kristaps@bsd.lv
 and is maintained by
 .An Ingo Schwarze Aq Mt schwarze@openbsd.org .
Index: stable/11/contrib/mdocml/mandoc.css
===================================================================
--- stable/11/contrib/mdocml/mandoc.css	(revision 316419)
+++ stable/11/contrib/mdocml/mandoc.css	(revision 316420)
@@ -1,159 +1,173 @@
-/* $Id: mandoc.css,v 1.2 2016/04/13 10:19:23 schwarze Exp $ */
-
+/* $Id: mandoc.css,v 1.13 2017/01/21 02:29:57 schwarze Exp $ */
 /*
- * This is an example style-sheet provided for mandoc(1) and the -Thtml
- * or -Txhtml output mode.
- *
- * It mimics the appearance of the traditional cvsweb output.
- *
- * See mdoc(7) and man(7) for macro explanations.
+ * Standard style sheet for mandoc(1) -Thtml and man.cgi(8).
  */
 
-html		{ max-width: 880px; margin-left: 1em; }
-body		{ font-size: smaller; font-family: Helvetica,Arial,sans-serif; }
-body > div			{ padding-left: 2em;
-				  padding-top: 1em; }
-body > div.mandoc,
-body > div#mancgi		{ padding-left: 0em;
-				  padding-top: 0em; }
-body > div.results		{ font-size: smaller; }
-#mancgi fieldset		{ text-align: center;
-				  border: thin solid silver;
-				  border-radius: 1em;
-			  	  font-size: small; }
-#mancgi input[name=expr] 	{ width: 25%; }
-.results td.title		{ vertical-align: top;
-				  padding-right: 1em; }
-h1		{ margin-bottom: 1ex; font-size: 110% } 
-div.section > h1 { margin-left: -4ex; } /* Section header (Sh, SH). */
-h2		{ margin-bottom: 1ex; font-size: 105%; margin-left: -2ex; } /* Sub-section header (Ss, SS). */
-table		{ width: 100%; margin-top: 0ex; margin-bottom: 0ex; } /* All tables. */
-td		{ vertical-align: top; } /* All table cells. */
-p		{ } /* Paragraph: Pp, Lp. */
-blockquote	{ margin-left: 5ex; margin-top: 0ex; margin-bottom: 0ex; } /* D1. */
-div.section	{ margin-bottom: 2ex; margin-left: 5ex; } /* Sections (Sh, SH). */
-div.subsection	{ } /* Sub-sections (Ss, SS). */
-table.synopsis	{ } /* SYNOPSIS section table. */
-div.spacer	{ margin: 1em 0; }
+/* Global defaults. */
 
-/* Preamble structure. */
+html {		max-width: 100ex; }
+body {		font-family: Helvetica,Arial,sans-serif; }
+table {		margin-top: 0em;
+		margin-bottom: 0em; }
+td {		vertical-align: top; }
+ul, ol, dl {	margin-top: 0em;
+		margin-bottom: 0em; }
+li, dt {	margin-top: 1em; }
 
-table.foot	{ font-size: smaller; margin-top: 1em; border-top: 1px dotted #dddddd; } /* Document footer. */
-td.foot-date	{ width: 50%; } /* Document footer: date. */
-td.foot-os	{ width: 50%; } /* Document footer: OS/source. */
-table.head	{ font-size: smaller; margin-bottom: 1em; border-bottom: 1px dotted #dddddd; } /* Document header. */
-td.head-ltitle	{ width: 10%; } /* Document header: left-title. */
-td.head-vol	{ width: 80%; } /* Document header: volume. */
-td.head-rtitle	{ width: 10%; } /* Document header: right-title. */
+/* Search form and search results. */
 
-/* General font modes. */
+fieldset {	border: thin solid silver;
+		border-radius: 1em;
+		text-align: center; }
+input[name=expr] {
+		width: 25%; }
 
-i		{ } /* Italic: BI, IB, I, (implicit). */
-.emph		{ font-style: italic; font-weight: normal; } /* Emphasis: Em, Bl -emphasis. */
-b		{ } /* Bold: SB, BI, IB, BR, RB, B, (implicit). */
-.symb		{ font-style: normal; font-weight: bold; } /* Symbolic: Sy, Ms, Bf -symbolic. */
-small		{ } /* Small: SB, SM. */
-.lit		{ font-style: normal; font-weight: normal; font-family: monospace; } /* Literal: Dl, Li, Ql, Bf -literal, Bl -literal, Bl -unfilled. */
+table.results {	margin-top: 1em;
+		margin-left: 2em;
+		font-size: smaller; }
 
-/* Block modes. */
+/* Header and footer lines. */
 
-.display	{ } /* Top of all Bd, D1, Dl. */
-.list		{ } /* Top of all Bl. */
+table.head {	width: 100%;
+		border-bottom: 1px dotted #808080;
+		margin-bottom: 1em;
+		font-size: smaller; }
+td.head-vol {	text-align: center; }
+td.head-rtitle {
+		text-align: right; }
+span.Nd { }
 
-/* Context-specific modes. */
+table.foot {	width: 100%;
+		border-top: 1px dotted #808080;
+		margin-top: 1em;
+		font-size: smaller; }
+td.foot-os {	text-align: right; }
 
-i.addr		{ font-weight: normal; } /* Address (Ad). */
-i.arg		{ font-weight: normal; } /* Command argument (Ar). */
-span.author	{ } /* Author name (An). */
-b.cmd		{ font-style: normal; } /* Command (Cm). */
-b.config	{ font-style: normal; } /* Config statement (Cd). */
-span.define	{ } /* Defines (Dv). */
-span.desc	{ } /* Nd.  After em-dash. */
-b.diag		{ font-style: normal; } /* Diagnostic (Bl -diag). */
-span.env	{ } /* Environment variables (Ev). */
-span.errno	{ } /* Error string (Er). */
-i.farg		{ font-weight: normal; } /* Function argument (Fa, Fn). */
-i.file		{ font-weight: normal; } /* File (Pa). */
-b.flag		{ font-style: normal; } /* Flag (Fl, Cm). */
-b.fname		{ font-style: normal; } /* Function name (Fa, Fn, Rv). */
-i.ftype		{ font-weight: normal; } /* Function types (Ft, Fn). */
-b.includes	{ font-style: normal; } /* Header includes (In). */
-span.lib	{ } /* Library (Lb). */
-i.link-sec	{ font-weight: normal; } /* Section links (Sx). */
-b.macro		{ font-style: normal; } /* Macro-ish thing (Fd). */
-b.name		{ font-style: normal; } /* Name of utility (Nm). */
-span.opt	{ } /* Options (Op, Oo/Oc). */
-span.ref	{ } /* Citations (Rs). */
-span.ref-auth	{ } /* Reference author (%A). */
-i.ref-book	{ font-weight: normal; } /* Reference book (%B). */
-span.ref-city	{ } /* Reference city (%C). */
-span.ref-date	{ } /* Reference date (%D). */
-i.ref-issue	{ font-weight: normal; } /* Reference issuer/publisher (%I). */
-i.ref-jrnl	{ font-weight: normal; } /* Reference journal (%J). */
-span.ref-num	{ } /* Reference number (%N). */
-span.ref-opt	{ } /* Reference optionals (%O). */
-span.ref-page	{ } /* Reference page (%P). */
-span.ref-corp	{ } /* Reference corporate/foreign author (%Q). */
-span.ref-rep	{ } /* Reference report (%R). */
-span.ref-title	{ text-decoration: underline; } /* Reference title (%T). */
-span.ref-vol	{ } /* Reference volume (%V). */
-span.type	{ font-style: italic; font-weight: normal; } /* Variable types (Vt). */
-span.unix	{ } /* Unices (Ux, Ox, Nx, Fx, Bx, Bsx, Dx). */
-b.utility	{ font-style: normal; } /* Name of utility (Ex). */
-b.var		{ font-style: normal; } /* Variables (Rv). */
+/* Sections and paragraphs. */
 
-a.link-ext	{ } /* Off-site link (Lk). */
-a.link-includes	{ } /* Include-file link (In). */
-a.link-mail	{ } /* Mailto links (Mt). */
-a.link-man	{ } /* Manual links (Xr). */
-a.link-ref	{ } /* Reference section links (%Q). */
-a.link-sec	{ } /* Section links (Sx). */
+div.manual-text {
+		margin-left: 5ex; }
+h1.Sh {		margin-top: 2ex;
+		margin-bottom: 1ex;
+		margin-left: -4ex;
+		font-size: 110%; }
+h2.Ss {		margin-top: 2ex;
+		margin-bottom: 1ex;
+		margin-left: -2ex;
+		font-size: 105%; }
+div.Pp {	margin: 1ex 0ex; }
+a.Sx { }
+a.Xr { }
 
-/* Formatting for lists.  See mdoc(7). */
+/* Displays and lists. */
 
-dl.list-diag	{ }
-dt.list-diag	{ }
-dd.list-diag	{ }
+div.Bd { }
+div.D1 {	margin-left: 5ex; }
 
-dl.list-hang	{ }
-dt.list-hang	{ }
-dd.list-hang	{ }
+ul.Bl-bullet {	list-style-type: disc;
+		padding-left: 1em; }
+li.It-bullet { }
+ul.Bl-dash {	list-style-type: none;
+		padding-left: 0em; }
+li.It-dash:before {
+		content: "\2014  "; }
+ul.Bl-item {	list-style-type: none;
+		padding-left: 0em; }
+li.It-item { }
 
-dl.list-inset	{ }
-dt.list-inset	{ }
-dd.list-inset	{ }
+ol.Bl-enum {	padding-left: 2em; }
+li.It-enum { }
 
-dl.list-ohang	{ }
-dt.list-ohang	{ }
-dd.list-ohang	{ margin-left: 0ex; }
+dl.Bl-diag { }
+dt.It-diag { }
+dd.It-diag { }
+b.It-diag {	font-style: normal; }
+dl.Bl-hang { }
+dt.It-hang { }
+dd.It-hang { }
+dl.Bl-inset { }
+dt.It-inset { }
+dd.It-inset { }
+dl.Bl-ohang { }
+dt.It-ohang { }
+dd.It-ohang {	margin-left: 0ex; }
+dl.Bl-tag { }
+dt.It-tag { }
+dd.It-tag { }
 
-dl.list-tag	{ }
-dt.list-tag	{ }
-dd.list-tag	{ }
+table.Bl-column { }
+tr.It-column { }
+td.It-column {	margin-top: 1em; }
 
-table.list-col	{ }
-tr.list-col	{ }
-td.list-col	{ }
+span.Rs	{ }
+span.RsA { }
+i.RsB {		font-weight: normal; }
+span.RsC { }
+span.RsD { }
+i.RsI {		font-weight: normal; }
+i.RsJ {		font-weight: normal; }
+span.RsN { }
+span.RsO { }
+span.RsP { }
+span.RsQ { }
+span.RsR { }
+span.RsT {	text-decoration: underline; }
+a.RsU { }
+span.RsV { }
 
-ul.list-bul	{ list-style-type: disc; padding-left: 1em; }
-li.list-bul	{ }
+span.eqn { }
+table.tbl { }
 
-ul.list-dash	{ list-style-type: none; padding-left: 0em; }
-li.list-dash:before { content: "\2014  "; }
+/* Semantic markup for command line utilities. */
 
-ul.list-hyph	{ list-style-type: none; padding-left: 0em; }
-li.list-hyph:before { content: "\2013  "; }
+table.Nm { }
+b.Nm {		font-style: normal; }
+b.Fl {		font-style: normal; }
+b.Cm {		font-style: normal; }
+i.Ar {		font-weight: normal; }
+span.Op { }
+b.Ic {		font-style: normal; }
+code.Ev {	font-style: normal;
+		font-weight: normal;
+		font-family: monospace; }
+i.Pa {		font-weight: normal; }
 
-ul.list-item	{ list-style-type: none; padding-left: 0em; }
-li.list-item	{ }
+/* Semantic markup for function libraries. */
 
-ol.list-enum	{ padding-left: 2em; }
-li.list-enum	{ }
+span.Lb { }
+b.In {		font-style: normal; }
+a.In { }
+b.Fd {		font-style: normal; }
+i.Ft {		font-weight: normal; }
+b.Fn {		font-style: normal; }
+i.Fa {		font-weight: normal; }
+i.Vt {		font-weight: normal; }
+i.Va {		font-weight: normal; }
+code.Dv {	font-style: normal;
+		font-weight: normal;
+		font-family: monospace; }
+code.Er {	font-style: normal;
+		font-weight: normal;
+		font-family: monospace; }
 
-/* Equation modes.  See eqn(7). */
+/* Various semantic markup. */
 
-span.eqn	{ }
+span.An { }
+a.Lk { }
+a.Mt { }
+b.Cd {		font-style: normal; }
+i.Ad {		font-weight: normal; }
+b.Ms {		font-style: normal; }
+a.Ux { }
 
-/* Table modes.  See tbl(7). */
+/* Physical markup. */
 
-table.tbl	{ }
+.No {		font-style: normal;
+		font-weight: normal; }
+.Em {		font-style: italic;
+		font-weight: normal; }
+.Sy {		font-style: normal;
+		font-weight: bold; }
+.Li {		font-style: normal;
+		font-weight: normal;
+		font-family: monospace; }
Index: stable/11/contrib/mdocml/mandoc.db.5
===================================================================
--- stable/11/contrib/mdocml/mandoc.db.5	(revision 316419)
+++ stable/11/contrib/mdocml/mandoc.db.5	(revision 316420)
@@ -1,156 +1,228 @@
-.\"	$Id: mandoc.db.5,v 1.4 2016/07/07 14:35:48 schwarze Exp $
+.\"	$Id: mandoc.db.5,v 1.5 2016/08/01 12:27:15 schwarze Exp $
 .\"
-.\" Copyright (c) 2014 Ingo Schwarze 
+.\" Copyright (c) 2014, 2016 Ingo Schwarze 
 .\"
 .\" 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.
 .\"
-.Dd $Mdocdate: July 7 2016 $
+.Dd $Mdocdate: August 1 2016 $
 .Dt MANDOC.DB 5
 .Os
 .Sh NAME
 .Nm mandoc.db
 .Nd manual page database
 .Sh DESCRIPTION
 The
 .Nm
-SQLite3 file format is used to store information about installed manual
+file format is used to store information about installed manual
 pages to facilitate semantic searching for manuals.
 Each manual page tree contains its own
 .Nm
 file; see
 .Sx FILES
 for examples.
 .Pp
 Such database files are generated by
 .Xr makewhatis 8
 and used by
+.Xr man 1 ,
 .Xr apropos 1
 and
 .Xr whatis 1 .
 .Pp
-One line in the following tables describes:
-.Bl -tag -width Ds
-.It Sy mpages
-One physical manual page file, no matter how many times and under which
-names it may appear in the file system.
-.It Sy mlinks
-One entry in the file system, no matter which content it points to.
-.It Sy names
-One manual page name, no matter whether it appears in a page header,
-in a NAME or SYNOPSIS section, or as a file name.
-.It Sy keys
-One chunk of text from some macro invocation.
+The file format uses three datatypes:
+.Pp
+.Bl -dash -compact -offset 2n -width 1n
+.It
+32-bit signed integer numbers in big endian (network) byte ordering
+.It
+NUL-terminated strings
+.It
+lists of NUL-terminated strings, terminated by a second NUL character
 .El
 .Pp
-Each record in the latter three tables uses its
-.Va pageid
-column to point to a record in the
-.Sy mpages
-table.
+Numbers are aligned to four-byte boundaries; where they follow
+strings or lists of strings, padding with additional NUL characters
+occurs.
+Some, but not all, numbers point to positions in the file.
+These pointers are measured in bytes, and the first byte of the
+file is considered to be byte 0.
 .Pp
-The other columns are as follows; unless stated otherwise, they are
-of type
-.Vt TEXT .
-.Bl -tag -width mpages.desc
-.It Sy mpages.desc
-The description line
-.Pq Sq \&Nd
-of the page.
-.It Sy mpages.form
-An
-.Vt INTEGER
-bit field.
-If bit
-.Dv FORM_GZ
-is set, the page is compressed and requires
-.Xr gunzip 1
-for display.
-If bit
-.Dv FORM_SRC
-is set, the page is unformatted, that is in
+Each file consists of:
+.Pp
+.Bl -dash -compact -offset 2n -width 1n
+.It
+One magic number, 0x3a7d0cdb.
+.It
+One version number, currently 1.
+.It
+One pointer to the macros table.
+.It
+One pointer to the final magic number.
+.It
+The pages table (variable length).
+.It
+The macros table (variable length).
+.It
+The magic number once again, 0x3a7d0cdb.
+.El
+.Pp
+The pages table contains one entry for each physical manual page
+file, no matter how many hard and soft links it may have in the
+file system.
+The pages table consists of:
+.Pp
+.Bl -dash -compact -offset 2n -width 1n
+.It
+The number of pages in the database.
+.It
+For each page:
+.Bl -dash -compact -offset 2n -width 1n
+.It
+One pointer to the list of names.
+.It
+One pointer to the list of sections.
+.It
+One pointer to the list of architectures
+or 0 if the page is machine-independent.
+.It
+One pointer to the one-line description string.
+.It
+One pointer to the list of filenames.
+.El
+.It
+For each page, the list of names.
+Each name is preceded by a single byte indicating the sources of the name.
+The meaning of the bits is:
+.Bl -dash -compact -offset 2n -width 1n
+.It
+0x10: The name appears in a filename.
+.It
+0x08: The name appears in a header line, i.e. in a .Dt or .TH macro.
+.It
+0x04: The name is the first one in the title line, i.e. it appears
+in the first .Nm macro in the NAME section.
+.It
+0x02: The name appears in any .Nm macro in the NAME section.
+.It
+0x01: The name appears in an .Nm block in the SYNOPSIS section.
+.El
+.It
+For each page, the list of sections.
+Each section is given as a string, not as a number.
+.It
+For each architecture-dependent page, the list of architectures.
+.It
+For each page, the one-line description string taken from the .Nd macro.
+.It
+For each page, the list of filenames relative to the root of the
+respective manpath.
+This list includes hard links, soft links, and links simulated
+with .so
+.Xr roff 7
+requests.
+The first filename is preceded by a single byte
+having the following significance:
+.Bl -dash -compact -offset 2n -width 1n
+.It
+.Dv FORM_SRC No = 0x01 :
+The file format is
 .Xr mdoc 7
 or
-.Xr man 7
-format, and requires
-.Xr mandoc 1
-for display.
-If bit
-.Dv FORM_SRC
-is not set, the page is formatted, i.e. a
-.Sq cat
-page.
-.It Sy mlinks.sec
-The manual section as found in the subdirectory name.
-.It Sy mlinks.arch
-The manual architecture as found in the subdirectory name, or
-.Qq any .
-.It Sy mlinks.name
-The manual name as found in the file name.
-.It Sy names.bits
-An
-.Vt INTEGER
-bit mask telling whether the name came from a header line, from the
-NAME or SYNOPSIS section, or from a file name.
-Bits are defined in
-.In mansearch.h .
-.It Sy names.name
-The name itself.
-.It Sy keys.bits
-An
-.Vt INTEGER
-bit mask telling which semantic contexts the key was found in;
-defined in
-.In mansearch.h ,
-documented in
+.Xr man 7 .
+.It
+.Dv FORM_CAT No = 0x02 :
+The manual page is preformatted.
+.El
+.It
+Zero to three NUL bytes for padding.
+.El
+.Pp
+The macros table consists of:
+.Pp
+.Bl -dash -compact -offset 2n -width 1n
+.It
+The number of different macro keys, currently 36.
+The ordering of macros is defined in
+.In mansearch.h
+and the significance of the macro keys is documented in
 .Xr apropos 1 .
-.It Sy keys.key
-The string found in those contexts.
+.It
+For each macro key, one pointer to the respective macro table.
+.It
+For each macro key, the macro table (variable length).
 .El
+.Pp
+Each macro table consists of:
+.Pp
+.Bl -dash -compact -offset 2n -width 1n
+.It
+The number of entries in the table.
+.It
+For each entry:
+.Bl -dash -compact -offset 2n -width 1n
+.It
+One pointer to the value of the macro key.
+Each value is a string of text taken from some macro invocation.
+.It
+One pointer to the list of pages.
+.El
+.It
+For each entry, the value of the macro key.
+.It
+Zero to three NUL bytes for padding.
+.It
+For each entry, one or more pointers to pages in the pages table,
+pointing to the pointer to the list of names,
+followed by the number 0.
+.El
 .Sh FILES
 .Bl -tag -width /usr/share/man/mandoc.db -compact
 .It Pa /usr/share/man/mandoc.db
 The manual page database for the base system.
 .It Pa /usr/X11R6/man/mandoc.db
 The same for the
 .Xr X 7
 Window System.
 .It Pa /usr/local/man/mandoc.db
 The same for
 .Xr packages 7 .
 .El
+.Pp
+A program to dump
+.Nm
+files in a human-readable format suitable for
+.Xr diff 1
+is provided in the directory
+.Pa /usr/src/regress/usr.bin/mandoc/db/dbm_dump/ .
 .Sh SEE ALSO
 .Xr apropos 1 ,
 .Xr man 1 ,
-.Xr sqlite3 1 ,
 .Xr whatis 1 ,
 .Xr makewhatis 8
 .Sh HISTORY
 A manual page database
 .Pa /usr/lib/whatis
 first appeared in
 .Bx 2 .
 The present format first appeared in
-.Ox 5.6 .
+.Ox 6.1 .
 .Sh AUTHORS
 .An -nosplit
 The original version of
 .Xr makewhatis 8
 was written by
 .An Bill Joy
 in 1979.
-An SQLite3 version was first implemented by
-.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv
-in 2012.
 The present database format was designed by
 .An Ingo Schwarze Aq Mt schwarze@openbsd.org
-in 2014.
+in 2016.
Index: stable/11/contrib/mdocml/mandoc.h
===================================================================
--- stable/11/contrib/mdocml/mandoc.h	(revision 316419)
+++ stable/11/contrib/mdocml/mandoc.h	(revision 316420)
@@ -1,435 +1,438 @@
-/*	$Id: mandoc.h,v 1.209 2016/01/08 02:53:13 schwarze Exp $ */
+/*	$Id: mandoc.h,v 1.213 2017/01/09 01:37:03 schwarze Exp $ */
 /*
  * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons 
- * Copyright (c) 2010-2016 Ingo Schwarze 
+ * Copyright (c) 2010-2017 Ingo Schwarze 
  *
  * 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 AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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.
  */
 
 #define ASCII_NBRSP	 31  /* non-breaking space */
 #define	ASCII_HYPH	 30  /* breakable hyphen */
 #define	ASCII_BREAK	 29  /* breakable zero-width space */
 
 /*
  * Status level.  This refers to both internal status (i.e., whilst
  * running, when warnings/errors are reported) and an indicator of a
  * threshold of when to halt (when said internal state exceeds the
  * threshold).
  */
 enum	mandoclevel {
 	MANDOCLEVEL_OK = 0,
 	MANDOCLEVEL_RESERVED,
 	MANDOCLEVEL_WARNING, /* warnings: syntax, whitespace, etc. */
 	MANDOCLEVEL_ERROR, /* input has been thrown away */
 	MANDOCLEVEL_UNSUPP, /* input needs unimplemented features */
 	MANDOCLEVEL_BADARG, /* bad argument in invocation */
 	MANDOCLEVEL_SYSERR, /* system error */
 	MANDOCLEVEL_MAX
 };
 
 /*
  * All possible things that can go wrong within a parse, be it libroff,
  * libmdoc, or libman.
  */
 enum	mandocerr {
 	MANDOCERR_OK,
 
 	MANDOCERR_WARNING, /* ===== start of warnings ===== */
 
 	/* related to the prologue */
 	MANDOCERR_DT_NOTITLE, /* missing manual title, using UNTITLED: line */
 	MANDOCERR_TH_NOTITLE, /* missing manual title, using "": [macro] */
 	MANDOCERR_TITLE_CASE, /* lower case character in document title */
 	MANDOCERR_MSEC_MISSING, /* missing manual section, using "": macro */
 	MANDOCERR_MSEC_BAD, /* unknown manual section: Dt ... section */
 	MANDOCERR_DATE_MISSING, /* missing date, using today's date */
 	MANDOCERR_DATE_BAD, /* cannot parse date, using it verbatim: date */
 	MANDOCERR_OS_MISSING, /* missing Os macro, using "" */
 	MANDOCERR_PROLOG_REP, /* duplicate prologue macro: macro */
 	MANDOCERR_PROLOG_LATE, /* late prologue macro: macro */
 	MANDOCERR_DT_LATE, /* skipping late title macro: Dt args */
 	MANDOCERR_PROLOG_ORDER, /* prologue macros out of order: macros */
 
 	/* related to document structure */
 	MANDOCERR_SO, /* .so is fragile, better use ln(1): so path */
 	MANDOCERR_DOC_EMPTY, /* no document body */
 	MANDOCERR_SEC_BEFORE, /* content before first section header: macro */
 	MANDOCERR_NAMESEC_FIRST, /* first section is not NAME: Sh title */
-	MANDOCERR_NAMESEC_NONM, /* NAME section without name */
+	MANDOCERR_NAMESEC_NONM, /* NAME section without Nm before Nd */
 	MANDOCERR_NAMESEC_NOND, /* NAME section without description */
 	MANDOCERR_NAMESEC_ND, /* description not at the end of NAME */
 	MANDOCERR_NAMESEC_BAD, /* bad NAME section content: macro */
+	MANDOCERR_NAMESEC_PUNCT, /* missing comma before name: Nm name */
 	MANDOCERR_ND_EMPTY, /* missing description line, using "" */
 	MANDOCERR_SEC_ORDER, /* sections out of conventional order: Sh title */
 	MANDOCERR_SEC_REP, /* duplicate section title: Sh title */
 	MANDOCERR_SEC_MSEC, /* unexpected section: Sh title for ... only */
 	MANDOCERR_XR_ORDER, /* unusual Xr order: ... after ... */
 	MANDOCERR_XR_PUNCT, /* unusual Xr punctuation: ... after ... */
 	MANDOCERR_AN_MISSING, /* AUTHORS section without An macro */
 
 	/* related to macros and nesting */
 	MANDOCERR_MACRO_OBS, /* obsolete macro: macro */
 	MANDOCERR_MACRO_CALL, /* macro neither callable nor escaped: macro */
 	MANDOCERR_PAR_SKIP, /* skipping paragraph macro: macro ... */
 	MANDOCERR_PAR_MOVE, /* moving paragraph macro out of list: macro */
 	MANDOCERR_NS_SKIP, /* skipping no-space macro */
 	MANDOCERR_BLK_NEST, /* blocks badly nested: macro ... */
 	MANDOCERR_BD_NEST, /* nested displays are not portable: macro ... */
 	MANDOCERR_BL_MOVE, /* moving content out of list: macro */
 	MANDOCERR_FI_SKIP, /* fill mode already enabled, skipping: fi */
 	MANDOCERR_NF_SKIP, /* fill mode already disabled, skipping: nf */
 	MANDOCERR_BLK_LINE, /* line scope broken: macro breaks macro */
 
 	/* related to missing arguments */
 	MANDOCERR_REQ_EMPTY, /* skipping empty request: request */
 	MANDOCERR_COND_EMPTY, /* conditional request controls empty scope */
 	MANDOCERR_MACRO_EMPTY, /* skipping empty macro: macro */
 	MANDOCERR_BLK_EMPTY, /* empty block: macro */
 	MANDOCERR_ARG_EMPTY, /* empty argument, using 0n: macro arg */
 	MANDOCERR_BD_NOTYPE, /* missing display type, using -ragged: Bd */
 	MANDOCERR_BL_LATETYPE, /* list type is not the first argument: Bl arg */
-	MANDOCERR_BL_NOWIDTH, /* missing -width in -tag list, using 8n */
+	MANDOCERR_BL_NOWIDTH, /* missing -width in -tag list, using 6n */
 	MANDOCERR_EX_NONAME, /* missing utility name, using "": Ex */
 	MANDOCERR_FO_NOHEAD, /* missing function name, using "": Fo */
 	MANDOCERR_IT_NOHEAD, /* empty head in list item: Bl -type It */
 	MANDOCERR_IT_NOBODY, /* empty list item: Bl -type It */
 	MANDOCERR_BF_NOFONT, /* missing font type, using \fR: Bf */
 	MANDOCERR_BF_BADFONT, /* unknown font type, using \fR: Bf font */
 	MANDOCERR_PF_SKIP, /* nothing follows prefix: Pf arg */
 	MANDOCERR_RS_EMPTY, /* empty reference block: Rs */
+	MANDOCERR_XR_NOSEC, /* missing section argument: Xr arg */
 	MANDOCERR_ARG_STD, /* missing -std argument, adding it: macro */
 	MANDOCERR_OP_EMPTY, /* missing option string, using "": OP */
 	MANDOCERR_UR_NOHEAD, /* missing resource identifier, using "": UR */
 	MANDOCERR_EQN_NOBOX, /* missing eqn box, using "": op */
 
 	/* related to bad arguments */
 	MANDOCERR_ARG_QUOTE, /* unterminated quoted argument */
 	MANDOCERR_ARG_REP, /* duplicate argument: macro arg */
 	MANDOCERR_AN_REP, /* skipping duplicate argument: An -arg */
 	MANDOCERR_BD_REP, /* skipping duplicate display type: Bd -type */
 	MANDOCERR_BL_REP, /* skipping duplicate list type: Bl -type */
 	MANDOCERR_BL_SKIPW, /* skipping -width argument: Bl -type */
 	MANDOCERR_BL_COL, /* wrong number of cells */
 	MANDOCERR_AT_BAD, /* unknown AT&T UNIX version: At version */
 	MANDOCERR_FA_COMMA, /* comma in function argument: arg */
 	MANDOCERR_FN_PAREN, /* parenthesis in function name: arg */
 	MANDOCERR_RS_BAD, /* invalid content in Rs block: macro */
 	MANDOCERR_SM_BAD, /* invalid Boolean argument: macro arg */
 	MANDOCERR_FT_BAD, /* unknown font, skipping request: ft font */
 	MANDOCERR_TR_ODD, /* odd number of characters in request: tr char */
 
 	/* related to plain text */
 	MANDOCERR_FI_BLANK, /* blank line in fill mode, using .sp */
 	MANDOCERR_FI_TAB, /* tab in filled text */
 	MANDOCERR_SPACE_EOL, /* whitespace at end of input line */
 	MANDOCERR_COMMENT_BAD, /* bad comment style */
 	MANDOCERR_ESC_BAD, /* invalid escape sequence: esc */
 	MANDOCERR_STR_UNDEF, /* undefined string, using "": name */
 
 	/* related to tables */
 	MANDOCERR_TBLLAYOUT_SPAN, /* tbl line starts with span */
 	MANDOCERR_TBLLAYOUT_DOWN, /* tbl column starts with span */
 	MANDOCERR_TBLLAYOUT_VERT, /* skipping vertical bar in tbl layout */
 
 	MANDOCERR_ERROR, /* ===== start of errors ===== */
 
 	/* related to tables */
 	MANDOCERR_TBLOPT_ALPHA, /* non-alphabetic character in tbl options */
 	MANDOCERR_TBLOPT_BAD, /* skipping unknown tbl option: option */
 	MANDOCERR_TBLOPT_NOARG, /* missing tbl option argument: option */
 	MANDOCERR_TBLOPT_ARGSZ, /* wrong tbl option argument size: option */
 	MANDOCERR_TBLLAYOUT_NONE, /* empty tbl layout */
 	MANDOCERR_TBLLAYOUT_CHAR, /* invalid character in tbl layout: char */
 	MANDOCERR_TBLLAYOUT_PAR, /* unmatched parenthesis in tbl layout */
 	MANDOCERR_TBLDATA_NONE, /* tbl without any data cells */
 	MANDOCERR_TBLDATA_SPAN, /* ignoring data in spanned tbl cell: data */
 	MANDOCERR_TBLDATA_EXTRA, /* ignoring extra tbl data cells: data */
 	MANDOCERR_TBLDATA_BLK, /* data block open at end of tbl: macro */
 
 	/* related to document structure and macros */
 	MANDOCERR_FILE, /* cannot open file */
 	MANDOCERR_ROFFLOOP, /* input stack limit exceeded, infinite loop? */
 	MANDOCERR_CHAR_BAD, /* skipping bad character: number */
 	MANDOCERR_MACRO, /* skipping unknown macro: macro */
 	MANDOCERR_REQ_INSEC, /* skipping insecure request: request */
 	MANDOCERR_IT_STRAY, /* skipping item outside list: It ... */
 	MANDOCERR_TA_STRAY, /* skipping column outside column list: Ta */
 	MANDOCERR_BLK_NOTOPEN, /* skipping end of block that is not open */
 	MANDOCERR_RE_NOTOPEN, /* fewer RS blocks open, skipping: RE arg */
 	MANDOCERR_BLK_BROKEN, /* inserting missing end of block: macro ... */
 	MANDOCERR_BLK_NOEND, /* appending missing end of block: macro */
 
 	/* related to request and macro arguments */
 	MANDOCERR_NAMESC, /* escaped character not allowed in a name: name */
 	MANDOCERR_BD_FILE, /* NOT IMPLEMENTED: Bd -file */
 	MANDOCERR_BD_NOARG, /* skipping display without arguments: Bd */
 	MANDOCERR_BL_NOTYPE, /* missing list type, using -item: Bl */
 	MANDOCERR_NM_NONAME, /* missing manual name, using "": Nm */
 	MANDOCERR_OS_UNAME, /* uname(3) system call failed, using UNKNOWN */
 	MANDOCERR_ST_BAD, /* unknown standard specifier: St standard */
 	MANDOCERR_IT_NONUM, /* skipping request without numeric argument */
 	MANDOCERR_SO_PATH, /* NOT IMPLEMENTED: .so with absolute path or ".." */
 	MANDOCERR_SO_FAIL, /* .so request failed */
 	MANDOCERR_ARG_SKIP, /* skipping all arguments: macro args */
 	MANDOCERR_ARG_EXCESS, /* skipping excess arguments: macro ... args */
 	MANDOCERR_DIVZERO, /* divide by zero */
 
 	MANDOCERR_UNSUPP, /* ===== start of unsupported features ===== */
 
 	MANDOCERR_TOOLARGE, /* input too large */
 	MANDOCERR_CHAR_UNSUPP, /* unsupported control character: number */
 	MANDOCERR_REQ_UNSUPP, /* unsupported roff request: request */
 	MANDOCERR_TBLOPT_EQN, /* eqn delim option in tbl: arg */
 	MANDOCERR_TBLLAYOUT_MOD, /* unsupported tbl layout modifier: m */
 	MANDOCERR_TBLMACRO, /* ignoring macro in table: macro */
 
 	MANDOCERR_MAX
 };
 
 struct	tbl_opts {
 	char		  tab; /* cell-separator */
 	char		  decimal; /* decimal point */
 	int		  opts;
 #define	TBL_OPT_CENTRE	 (1 << 0)
 #define	TBL_OPT_EXPAND	 (1 << 1)
 #define	TBL_OPT_BOX	 (1 << 2)
 #define	TBL_OPT_DBOX	 (1 << 3)
 #define	TBL_OPT_ALLBOX	 (1 << 4)
 #define	TBL_OPT_NOKEEP	 (1 << 5)
 #define	TBL_OPT_NOSPACE	 (1 << 6)
 #define	TBL_OPT_NOWARN	 (1 << 7)
 	int		  cols; /* number of columns */
 	int		  lvert; /* width of left vertical line */
 	int		  rvert; /* width of right vertical line */
 };
 
 enum	tbl_cellt {
 	TBL_CELL_CENTRE, /* c, C */
 	TBL_CELL_RIGHT, /* r, R */
 	TBL_CELL_LEFT, /* l, L */
 	TBL_CELL_NUMBER, /* n, N */
 	TBL_CELL_SPAN, /* s, S */
 	TBL_CELL_LONG, /* a, A */
 	TBL_CELL_DOWN, /* ^ */
 	TBL_CELL_HORIZ, /* _, - */
 	TBL_CELL_DHORIZ, /* = */
 	TBL_CELL_MAX
 };
 
 /*
  * A cell in a layout row.
  */
 struct	tbl_cell {
 	struct tbl_cell	 *next;
 	int		  vert; /* width of subsequent vertical line */
 	enum tbl_cellt	  pos;
 	size_t		  spacing;
 	int		  col; /* column number, starting from 0 */
 	int		  flags;
 #define	TBL_CELL_TALIGN	 (1 << 0) /* t, T */
 #define	TBL_CELL_BALIGN	 (1 << 1) /* d, D */
 #define	TBL_CELL_BOLD	 (1 << 2) /* fB, B, b */
 #define	TBL_CELL_ITALIC	 (1 << 3) /* fI, I, i */
 #define	TBL_CELL_EQUAL	 (1 << 4) /* e, E */
 #define	TBL_CELL_UP	 (1 << 5) /* u, U */
 #define	TBL_CELL_WIGN	 (1 << 6) /* z, Z */
 #define	TBL_CELL_WMAX	 (1 << 7) /* x, X */
 };
 
 /*
  * A layout row.
  */
 struct	tbl_row {
 	struct tbl_row	 *next;
 	struct tbl_cell	 *first;
 	struct tbl_cell	 *last;
 	int		  vert; /* width of left vertical line */
 };
 
 enum	tbl_datt {
 	TBL_DATA_NONE, /* has no data */
 	TBL_DATA_DATA, /* consists of data/string */
 	TBL_DATA_HORIZ, /* horizontal line */
 	TBL_DATA_DHORIZ, /* double-horizontal line */
 	TBL_DATA_NHORIZ, /* squeezed horizontal line */
 	TBL_DATA_NDHORIZ /* squeezed double-horizontal line */
 };
 
 /*
  * A cell within a row of data.  The "string" field contains the actual
  * string value that's in the cell.  The rest is layout.
  */
 struct	tbl_dat {
 	struct tbl_cell	 *layout; /* layout cell */
 	int		  spans; /* how many spans follow */
 	struct tbl_dat	 *next;
 	char		 *string; /* data (NULL if not TBL_DATA_DATA) */
 	enum tbl_datt	  pos;
 };
 
 enum	tbl_spant {
 	TBL_SPAN_DATA, /* span consists of data */
 	TBL_SPAN_HORIZ, /* span is horizontal line */
 	TBL_SPAN_DHORIZ /* span is double horizontal line */
 };
 
 /*
  * A row of data in a table.
  */
 struct	tbl_span {
 	struct tbl_opts	 *opts;
 	struct tbl_row	 *layout; /* layout row */
 	struct tbl_dat	 *first;
 	struct tbl_dat	 *last;
 	struct tbl_span	 *prev;
 	struct tbl_span	 *next;
 	int		  line; /* parse line */
 	enum tbl_spant	  pos;
 };
 
 enum	eqn_boxt {
 	EQN_ROOT, /* root of parse tree */
 	EQN_TEXT, /* text (number, variable, whatever) */
 	EQN_SUBEXPR, /* nested `eqn' subexpression */
 	EQN_LIST, /* list (braces, etc.) */
 	EQN_LISTONE, /* singleton list */
 	EQN_PILE, /* vertical pile */
 	EQN_MATRIX /* pile of piles */
 };
 
 enum	eqn_fontt {
 	EQNFONT_NONE = 0,
 	EQNFONT_ROMAN,
 	EQNFONT_BOLD,
 	EQNFONT_FAT,
 	EQNFONT_ITALIC,
 	EQNFONT__MAX
 };
 
 enum	eqn_post {
 	EQNPOS_NONE = 0,
 	EQNPOS_SUP,
 	EQNPOS_SUBSUP,
 	EQNPOS_SUB,
 	EQNPOS_TO,
 	EQNPOS_FROM,
 	EQNPOS_FROMTO,
 	EQNPOS_OVER,
 	EQNPOS_SQRT,
 	EQNPOS__MAX
 };
 
 enum	eqn_pilet {
 	EQNPILE_NONE = 0,
 	EQNPILE_PILE,
 	EQNPILE_CPILE,
 	EQNPILE_RPILE,
 	EQNPILE_LPILE,
 	EQNPILE_COL,
 	EQNPILE_CCOL,
 	EQNPILE_RCOL,
 	EQNPILE_LCOL,
 	EQNPILE__MAX
 };
 
  /*
  * A "box" is a parsed mathematical expression as defined by the eqn.7
  * grammar.
  */
 struct	eqn_box {
 	int		  size; /* font size of expression */
 #define	EQN_DEFSIZE	  INT_MIN
 	enum eqn_boxt	  type; /* type of node */
 	struct eqn_box	 *first; /* first child node */
 	struct eqn_box	 *last; /* last child node */
 	struct eqn_box	 *next; /* node sibling */
 	struct eqn_box	 *prev; /* node sibling */
 	struct eqn_box	 *parent; /* node sibling */
 	char		 *text; /* text (or NULL) */
 	char		 *left; /* fence left-hand */
 	char		 *right; /* fence right-hand */
 	char		 *top; /* expression over-symbol */
 	char		 *bottom; /* expression under-symbol */
 	size_t		  args; /* arguments in parent */
 	size_t		  expectargs; /* max arguments in parent */
 	enum eqn_post	  pos; /* position of next box */
 	enum eqn_fontt	  font; /* font of box */
 	enum eqn_pilet	  pile; /* equation piling */
 };
 
 /*
  * An equation consists of a tree of expressions starting at a given
  * line and position.
  */
 struct	eqn {
 	char		 *name; /* identifier (or NULL) */
 	struct eqn_box	 *root; /* root mathematical expression */
 	int		  ln; /* invocation line */
 	int		  pos; /* invocation position */
 };
 
 /*
  * Parse options.
  */
 #define	MPARSE_MDOC	1  /* assume -mdoc */
 #define	MPARSE_MAN	2  /* assume -man */
 #define	MPARSE_SO	4  /* honour .so requests */
 #define	MPARSE_QUICK	8  /* abort the parse early */
 #define	MPARSE_UTF8	16 /* accept UTF-8 input */
 #define	MPARSE_LATIN1	32 /* accept ISO-LATIN-1 input */
 
 enum	mandoc_esc {
 	ESCAPE_ERROR = 0, /* bail! unparsable escape */
 	ESCAPE_IGNORE, /* escape to be ignored */
 	ESCAPE_SPECIAL, /* a regular special character */
 	ESCAPE_FONT, /* a generic font mode */
 	ESCAPE_FONTBOLD, /* bold font mode */
 	ESCAPE_FONTITALIC, /* italic font mode */
 	ESCAPE_FONTBI, /* bold italic font mode */
 	ESCAPE_FONTROMAN, /* roman font mode */
 	ESCAPE_FONTPREV, /* previous font mode */
 	ESCAPE_NUMBERED, /* a numbered glyph */
 	ESCAPE_UNICODE, /* a unicode codepoint */
 	ESCAPE_NOSPACE, /* suppress space if the last on a line */
 	ESCAPE_SKIPCHAR, /* skip the next character */
 	ESCAPE_OVERSTRIKE /* overstrike all chars in the argument */
 };
 
 typedef	void	(*mandocmsg)(enum mandocerr, enum mandoclevel,
 			const char *, int, int, const char *);
 
 
 struct	mparse;
 struct	roff_man;
 
 enum mandoc_esc	  mandoc_escape(const char **, const char **, int *);
 void		  mchars_alloc(void);
 void		  mchars_free(void);
 int		  mchars_num2char(const char *, size_t);
 const char	 *mchars_uc2str(int);
 int		  mchars_num2uc(const char *, size_t);
 int		  mchars_spec2cp(const char *, size_t);
 const char	 *mchars_spec2str(const char *, size_t, size_t *);
 struct mparse	 *mparse_alloc(int, enum mandoclevel, mandocmsg, const char *);
 void		  mparse_free(struct mparse *);
 void		  mparse_keep(struct mparse *);
 int		  mparse_open(struct mparse *, const char *);
 enum mandoclevel  mparse_readfd(struct mparse *, int, const char *);
 enum mandoclevel  mparse_readmem(struct mparse *, void *, size_t,
 			const char *);
 void		  mparse_reset(struct mparse *);
 void		  mparse_result(struct mparse *,
 			struct roff_man **, char **);
 const char	 *mparse_getkeep(const struct mparse *);
 const char	 *mparse_strerror(enum mandocerr);
 const char	 *mparse_strlevel(enum mandoclevel);
+void		  mparse_updaterc(struct mparse *, enum mandoclevel *);
Index: stable/11/contrib/mdocml/mandoc_aux.h
===================================================================
--- stable/11/contrib/mdocml/mandoc_aux.h	(revision 316419)
+++ stable/11/contrib/mdocml/mandoc_aux.h	(revision 316420)
@@ -1,25 +1,26 @@
-/*	$Id: mandoc_aux.h,v 1.4 2015/11/07 14:01:16 schwarze Exp $ */
+/*	$Id: mandoc_aux.h,v 1.5 2016/07/19 13:36:13 schwarze Exp $ */
 /*
  * Copyright (c) 2009, 2011 Kristaps Dzonsons 
  * Copyright (c) 2014 Ingo Schwarze 
  *
  * 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.
  */
 
-int		  mandoc_asprintf(char **, const char *, ...);
+int		  mandoc_asprintf(char **, const char *, ...)
+			__attribute__((__format__ (printf, 2, 3)));
 void		 *mandoc_calloc(size_t, size_t);
 void		 *mandoc_malloc(size_t);
 void		 *mandoc_realloc(void *, size_t);
 void		 *mandoc_reallocarray(void *, size_t, size_t);
 char		 *mandoc_strdup(const char *);
 char		 *mandoc_strndup(const char *, size_t);
Index: stable/11/contrib/mdocml/mandoc_html.3
===================================================================
--- stable/11/contrib/mdocml/mandoc_html.3	(revision 316419)
+++ stable/11/contrib/mdocml/mandoc_html.3	(revision 316420)
@@ -1,249 +1,340 @@
-.\"	$Id: mandoc_html.3,v 1.1 2014/07/23 18:13:09 schwarze Exp $
+.\"	$Id: mandoc_html.3,v 1.3 2017/01/17 15:32:44 schwarze Exp $
 .\"
-.\" Copyright (c) 2014 Ingo Schwarze 
+.\" Copyright (c) 2014, 2017 Ingo Schwarze 
 .\"
 .\" 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.
 .\"
-.Dd $Mdocdate: July 23 2014 $
+.Dd $Mdocdate: January 17 2017 $
 .Dt MANDOC_HTML 3
 .Os
 .Sh NAME
 .Nm mandoc_html
 .Nd internals of the mandoc HTML formatter
 .Sh SYNOPSIS
 .In "html.h"
 .Ft void
 .Fn print_gen_decls "struct html *h"
 .Ft void
 .Fn print_gen_head "struct html *h"
 .Ft struct tag *
 .Fo print_otag
 .Fa "struct html *h"
 .Fa "enum htmltag tag"
-.Fa "int sz"
-.Fa "const struct htmlpair *p"
+.Fa "const char *fmt"
+.Fa ...
 .Fc
 .Ft void
 .Fo print_tagq
 .Fa "struct html *h"
 .Fa "const struct tag *until"
 .Fc
 .Ft void
 .Fo print_stagq
 .Fa "struct html *h"
 .Fa "const struct tag *suntil"
 .Fc
 .Ft void
 .Fo print_text
 .Fa "struct html *h"
 .Fa "const char *word"
 .Fc
 .Sh DESCRIPTION
 The mandoc HTML formatter is not a formal library.
 However, as it is compiled into more than one program, in particular
 .Xr mandoc 1
 and
 .Xr man.cgi 8 ,
 and because it may be security-critical in some contexts,
 some documentation is useful to help to use it correctly and
 to prevent XSS vulnerabilities.
 .Pp
 The formatter produces HTML output on the standard output.
 Since proper escaping is usually required and best taken care of
 at one central place, the language-specific formatters
 .Po
 .Pa *_html.c ,
 see
 .Sx FILES
 .Pc
 are not supposed to print directly to
 .Dv stdout
 using functions like
 .Xr printf 3 ,
 .Xr putc 3 ,
 .Xr puts 3 ,
 or
 .Xr write 2 .
 Instead, they are expected to use the output functions declared in
 .Pa html.h
 and implemented as part of the main HTML formatting engine in
 .Pa html.c .
 .Ss Data structures
 These structures are declared in
 .Pa html.h .
 .Bl -tag -width Ds
 .It Vt struct html
 Internal state of the HTML formatter.
-.It Vt struct htmlpair
-Holds one HTML attribute.
-Members are
-.Fa "enum htmlattr key"
-and
-.Fa "const char *val" .
-Helper macros
-.Fn PAIR_*
-are provided to support initialization of such structures.
 .It Vt struct tag
 One entry for the LIFO stack of HTML elements.
 Members are
 .Fa "enum htmltag tag"
 and
 .Fa "struct tag *next" .
 .El
 .Ss Private interface functions
 The function
 .Fn print_gen_decls
 prints the opening
 .Ao Pf \&? Ic xml ? Ac
 and
 .Aq Pf \&! Ic DOCTYPE
 declarations required for the current document type.
 .Pp
 The function
 .Fn print_gen_head
 prints the opening
 .Aq Ic META
 and
 .Aq Ic LINK
 elements for the document
 .Aq Ic HEAD ,
 using the
 .Fa style
 member of
 .Fa h
 unless that is
 .Dv NULL .
 It uses
 .Fn print_otag
 which takes care of properly encoding attributes,
 which is relevant for the
 .Fa style
 link in particular.
 .Pp
 The function
 .Fn print_otag
 prints the start tag of an HTML element with the name
 .Fa tag ,
-including the
-.Fa sz
-attributes that can optionally be provided in the
-.Fa p
-array.
-It uses the private function
-.Fn print_attr
-which in turn uses the private function
+optionally including the attributes specified by
+.Fa fmt .
+If
+.Fa fmt
+is the empty string, no attributes are written.
+Each letter of
+.Fa fmt
+specifies one attribute to write.
+Most attributes require one
+.Va char *
+argument which becomes the value of the attribute.
+The arguments have to be given in the same order as the attribute letters.
+.Bl -tag -width 1n -offset indent
+.It Cm c
+Print a
+.Cm class
+attribute.
+.It Cm h
+Print a
+.Cm href
+attribute.
+This attribute letter can optionally be followed by a modifier letter.
+If followed by
+.Cm R ,
+it formats the link as a local one by prefixing a
+.Sq #
+character.
+If followed by
+.Cm I ,
+it interpretes the argument as a header file name
+and generates a link using the
+.Xr mandoc 1
+.Fl O Cm includes
+option.
+If followed by
+.Cm M ,
+it takes two arguments instead of one, a manual page name and
+section, and formats them as a link to a manual page using the
+.Xr mandoc 1
+.Fl O Cm man
+option.
+.It Cm i
+Print an
+.Cm id
+attribute.
+.It Cm \&?
+Print an arbitrary attribute.
+This format letter requires two
+.Vt char *
+arguments, the attribute name and the value.
+.It Cm s
+Print a
+.Cm style
+attribute.
+If present, it must be the last format letter.
+In contrast to the other format letters, this one does not yet
+print the value and does not require an argument.
+Instead, the rest of the format string consists of pairs of
+argument type letters and style name letters.
+.El
+.Pp
+Argument type letters each require on argument as follows:
+.Bl -tag -width 1n -offset indent
+.It Cm h
+Requires one
+.Vt int
+argument, interpreted as a horizontal length in units of
+.Dv SCALE_EN .
+.It Cm s
+Requires one
+.Vt char *
+argument, used as a style value.
+.It Cm u
+Requires one
+.Vt struct roffsu *
+argument, used as a length.
+.It Cm v
+Requires one
+.Vt int
+argument, interpreted as a vertical length in units of
+.Dv SCALE_VS .
+.It Cm w
+Requires one
+.Vt char *
+argument, interpreted as an
+.Xr mdoc 7 Ns -style
+width specifier.
+.El
+.Pp
+Style name letters decide what to do with the preceding argument:
+.Bl -tag -width 1n -offset indent
+.It Cm b
+Set
+.Cm margin-bottom
+to the given length.
+.It Cm h
+Set
+.Cm height
+to the given length.
+.It Cm i
+Set
+.Cm text-indent
+to the given length.
+.It Cm l
+Set
+.Cm margin-left
+to the given length.
+.It Cm t
+Set
+.Cm margin-top
+to the given length.
+.It Cm w
+Set
+.Cm width
+to the given length.
+.It Cm W
+Set
+.Cm min-width
+to the given length.
+.It Cm \&?
+The special pair
+.Cm s?
+requires two
+.Vt char *
+arguments.
+The first is the style name, the second its value.
+.El
+.Pp
+.Fn print_otag
+uses the private function
 .Fn print_encode
 to take care of HTML encoding.
 If required by the element type, it remembers in
 .Fa h
 that the element is open.
 The function
 .Fn print_tagq
 is used to close out all open elements up to and including
 .Fa until ;
 .Fn print_stagq
 is a variant to close out all open elements up to but excluding
 .Fa suntil .
 .Pp
 The function
 .Fn print_text
 prints HTML element content.
 It uses the private function
 .Fn print_encode
 to take care of HTML encoding.
 If the document has requested a non-standard font, for example using a
 .Xr roff 7
 .Ic \ef
 font escape sequence,
 .Fn print_text
 wraps
 .Fa word
 in an HTML font selection element using the
 .Fn print_otag
 and
 .Fn print_tagq
 functions.
-.Pp
-The functions
-.Fn bufinit ,
-.Fn bufcat* ,
-and
-.Fn buffmt*
-do not directly produce output but buffer text in the
-.Fa buf
-member of
-.Fa h .
-They are not used internally by
-.Pa html.c
-but intended for use by the language-specific formatters
-to ease preparation of strings for the
-.Fa p
-argument of
-.Fn print_otag
-and for the
-.Fa word
-argument of
-.Fn print_text .
-Consequently, these functions do not do any HTML encoding.
 .Pp
 The functions
 .Fn html_strlen ,
 .Fn print_eqn ,
 .Fn print_tbl ,
 and
 .Fn print_tblclose
 are not yet documented.
 .Sh FILES
 .Bl -tag -width mandoc_aux.c -compact
 .It Pa main.h
 declarations of public functions for use by the main program,
 not yet documented
 .It Pa html.h
 declarations of data types and private functions
 for use by language-specific HTML formatters
 .It Pa html.c
 main HTML formatting engine and utility functions
 .It Pa mdoc_html.c
 .Xr mdoc 7
 HTML formatter
 .It Pa man_html.c
 .Xr man 7
 HTML formatter
 .It Pa tbl_html.c
 .Xr tbl 7
 HTML formatter
 .It Pa eqn_html.c
 .Xr eqn 7
 HTML formatter
 .It Pa out.h
 declarations of data types and private functions
 for shared use by all mandoc formatters,
 not yet documented
 .It Pa out.c
 private functions for shared use by all mandoc formatters
 .It Pa mandoc_aux.h
 declarations of common mandoc utility functions, see
 .Xr mandoc 3
 .It Pa mandoc_aux.c
 implementation of common mandoc utility functions
 .El
 .Sh SEE ALSO
 .Xr mandoc 1 ,
 .Xr mandoc 3 ,
 .Xr man.cgi 8
 .Sh AUTHORS
 .An -nosplit
 The mandoc HTML formatter was written by
 .An Kristaps Dzonsons Aq Mt kristaps@bsd.lv .
 This manual was written by
 .An Ingo Schwarze Aq Mt schwarze@openbsd.org .
Index: stable/11/contrib/mdocml/mandocdb.c
===================================================================
--- stable/11/contrib/mdocml/mandocdb.c	(revision 316419)
+++ stable/11/contrib/mdocml/mandocdb.c	(revision 316420)
@@ -1,2552 +1,2274 @@
-/*	$Id: mandocdb.c,v 1.218 2016/07/12 05:18:38 kristaps Exp $ */
+/*	$Id: mandocdb.c,v 1.237 2017/01/11 17:39:53 schwarze Exp $ */
 /*
  * Copyright (c) 2011, 2012 Kristaps Dzonsons 
- * Copyright (c) 2011-2016 Ingo Schwarze 
+ * Copyright (c) 2011-2017 Ingo Schwarze 
+ * Copyright (c) 2016 Ed Maste 
  *
  * 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 AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h"
 
 #include 
 #include 
 #include 
 
 #include 
 #include 
 #if HAVE_ERR
 #include 
 #endif
 #include 
 #include 
 #if HAVE_FTS
 #include 
 #else
 #include "compat_fts.h"
 #endif
 #include 
 #if HAVE_SANDBOX_INIT
 #include 
 #endif
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 
-#include 
-
 #include "mandoc_aux.h"
 #include "mandoc_ohash.h"
 #include "mandoc.h"
 #include "roff.h"
 #include "mdoc.h"
 #include "man.h"
 #include "manconf.h"
 #include "mansearch.h"
+#include "dba_array.h"
+#include "dba.h"
 
-extern int mansearch_keymax;
 extern const char *const mansearch_keynames[];
 
-#define	SQL_EXEC(_v) \
-	if (SQLITE_OK != sqlite3_exec(db, (_v), NULL, NULL, NULL)) \
-		say("", "%s: %s", (_v), sqlite3_errmsg(db))
-#define	SQL_BIND_TEXT(_s, _i, _v) \
-	if (SQLITE_OK != sqlite3_bind_text \
-		((_s), (_i)++, (_v), -1, SQLITE_STATIC)) \
-		say(mlink->file, "%s", sqlite3_errmsg(db))
-#define	SQL_BIND_INT(_s, _i, _v) \
-	if (SQLITE_OK != sqlite3_bind_int \
-		((_s), (_i)++, (_v))) \
-		say(mlink->file, "%s", sqlite3_errmsg(db))
-#define	SQL_BIND_INT64(_s, _i, _v) \
-	if (SQLITE_OK != sqlite3_bind_int64 \
-		((_s), (_i)++, (_v))) \
-		say(mlink->file, "%s", sqlite3_errmsg(db))
-#define SQL_STEP(_s) \
-	if (SQLITE_DONE != sqlite3_step((_s))) \
-		say(mlink->file, "%s", sqlite3_errmsg(db))
-
 enum	op {
 	OP_DEFAULT = 0, /* new dbs from dir list or default config */
 	OP_CONFFILE, /* new databases from custom config file */
 	OP_UPDATE, /* delete/add entries in existing database */
 	OP_DELETE, /* delete entries from existing database */
 	OP_TEST /* change no databases, report potential problems */
 };
 
 struct	str {
 	const struct mpage *mpage; /* if set, the owning parse */
 	uint64_t	 mask; /* bitmask in sequence */
 	char		 key[]; /* rendered text */
 };
 
 struct	inodev {
 	ino_t		 st_ino;
 	dev_t		 st_dev;
 };
 
 struct	mpage {
 	struct inodev	 inodev;  /* used for hashing routine */
-	int64_t		 pageid;  /* pageid in mpages SQL table */
+	struct dba_array *dba;
 	char		*sec;     /* section from file content */
 	char		*arch;    /* architecture from file content */
 	char		*title;   /* title from file content */
 	char		*desc;    /* description from file content */
 	struct mpage	*next;    /* singly linked list */
 	struct mlink	*mlinks;  /* singly linked list */
-	int		 form;    /* format from file content */
 	int		 name_head_done;
+	enum form	 form;    /* format from file content */
 };
 
 struct	mlink {
 	char		 file[PATH_MAX]; /* filename rel. to manpath */
 	char		*dsec;    /* section from directory */
 	char		*arch;    /* architecture from directory */
 	char		*name;    /* name from file name (not empty) */
 	char		*fsec;    /* section from file name suffix */
 	struct mlink	*next;    /* singly linked list */
 	struct mpage	*mpage;   /* parent */
-	int		 dform;   /* format from directory */
-	int		 fform;   /* format from file name suffix */
 	int		 gzip;	  /* filename has a .gz suffix */
+	enum form	 dform;   /* format from directory */
+	enum form	 fform;   /* format from file name suffix */
 };
 
-enum	stmt {
-	STMT_DELETE_PAGE = 0,	/* delete mpage */
-	STMT_INSERT_PAGE,	/* insert mpage */
-	STMT_INSERT_LINK,	/* insert mlink */
-	STMT_INSERT_NAME,	/* insert name */
-	STMT_SELECT_NAME,	/* retrieve existing name flags */
-	STMT_INSERT_KEY,	/* insert parsed key */
-	STMT__MAX
-};
-
 typedef	int (*mdoc_fp)(struct mpage *, const struct roff_meta *,
 			const struct roff_node *);
 
 struct	mdoc_handler {
 	mdoc_fp		 fp; /* optional handler */
 	uint64_t	 mask;  /* set unless handler returns 0 */
+	int		 taboo;  /* node flags that must not be set */
 };
 
-static	void	 dbclose(int);
-static	void	 dbadd(struct mpage *);
+
+int		 mandocdb(int, char *[]);
+
+static	void	 dbadd(struct dba *, struct mpage *);
 static	void	 dbadd_mlink(const struct mlink *mlink);
-static	void	 dbadd_mlink_name(const struct mlink *mlink);
-static	int	 dbopen(int);
-static	void	 dbprune(void);
+static	void	 dbprune(struct dba *);
+static	void	 dbwrite(struct dba *);
 static	void	 filescan(const char *);
+#if HAVE_FTS_COMPARE_CONST
 static	int	 fts_compare(const FTSENT *const *, const FTSENT *const *);
+#else
+static	int	 fts_compare(const FTSENT **, const FTSENT **);
+#endif
 static	void	 mlink_add(struct mlink *, const struct stat *);
 static	void	 mlink_check(struct mpage *, struct mlink *);
 static	void	 mlink_free(struct mlink *);
 static	void	 mlinks_undupe(struct mpage *);
 static	void	 mpages_free(void);
-static	void	 mpages_merge(struct mparse *);
-static	void	 names_check(void);
+static	void	 mpages_merge(struct dba *, struct mparse *);
 static	void	 parse_cat(struct mpage *, int);
 static	void	 parse_man(struct mpage *, const struct roff_meta *,
 			const struct roff_node *);
 static	void	 parse_mdoc(struct mpage *, const struct roff_meta *,
 			const struct roff_node *);
 static	int	 parse_mdoc_head(struct mpage *, const struct roff_meta *,
 			const struct roff_node *);
 static	int	 parse_mdoc_Fd(struct mpage *, const struct roff_meta *,
 			const struct roff_node *);
 static	void	 parse_mdoc_fname(struct mpage *, const struct roff_node *);
 static	int	 parse_mdoc_Fn(struct mpage *, const struct roff_meta *,
 			const struct roff_node *);
 static	int	 parse_mdoc_Fo(struct mpage *, const struct roff_meta *,
 			const struct roff_node *);
 static	int	 parse_mdoc_Nd(struct mpage *, const struct roff_meta *,
 			const struct roff_node *);
 static	int	 parse_mdoc_Nm(struct mpage *, const struct roff_meta *,
 			const struct roff_node *);
 static	int	 parse_mdoc_Sh(struct mpage *, const struct roff_meta *,
 			const struct roff_node *);
 static	int	 parse_mdoc_Va(struct mpage *, const struct roff_meta *,
 			const struct roff_node *);
 static	int	 parse_mdoc_Xr(struct mpage *, const struct roff_meta *,
 			const struct roff_node *);
 static	void	 putkey(const struct mpage *, char *, uint64_t);
 static	void	 putkeys(const struct mpage *, char *, size_t, uint64_t);
 static	void	 putmdockey(const struct mpage *,
-			const struct roff_node *, uint64_t);
+			const struct roff_node *, uint64_t, int);
 static	int	 render_string(char **, size_t *);
-static	void	 say(const char *, const char *, ...);
+static	void	 say(const char *, const char *, ...)
+			__attribute__((__format__ (printf, 2, 3)));
 static	int	 set_basedir(const char *, int);
 static	int	 treescan(void);
 static	size_t	 utf8(unsigned int, char [7]);
 
-static	char		 tempfilename[32];
 static	int		 nodb; /* no database changes */
 static	int		 mparse_options; /* abort the parse early */
 static	int		 use_all; /* use all found files */
 static	int		 debug; /* print what we're doing */
 static	int		 warnings; /* warn about crap */
 static	int		 write_utf8; /* write UTF-8 output; else ASCII */
 static	int		 exitcode; /* to be returned by main */
 static	enum op		 op; /* operational mode */
 static	char		 basedir[PATH_MAX]; /* current base directory */
+static	struct mpage	*mpage_head; /* list of distinct manual pages */
 static	struct ohash	 mpages; /* table of distinct manual pages */
 static	struct ohash	 mlinks; /* table of directory entries */
 static	struct ohash	 names; /* table of all names */
 static	struct ohash	 strings; /* table of all strings */
-static	sqlite3		*db = NULL; /* current database */
-static	sqlite3_stmt	*stmts[STMT__MAX]; /* current statements */
 static	uint64_t	 name_mask;
-static	struct mpage	*mpage_head;
 
 static	const struct mdoc_handler mdocs[MDOC_MAX] = {
-	{ NULL, 0 },  /* Ap */
-	{ NULL, 0 },  /* Dd */
-	{ NULL, 0 },  /* Dt */
-	{ NULL, 0 },  /* Os */
-	{ parse_mdoc_Sh, TYPE_Sh }, /* Sh */
-	{ parse_mdoc_head, TYPE_Ss }, /* Ss */
-	{ NULL, 0 },  /* Pp */
-	{ NULL, 0 },  /* D1 */
-	{ NULL, 0 },  /* Dl */
-	{ NULL, 0 },  /* Bd */
-	{ NULL, 0 },  /* Ed */
-	{ NULL, 0 },  /* Bl */
-	{ NULL, 0 },  /* El */
-	{ NULL, 0 },  /* It */
-	{ NULL, 0 },  /* Ad */
-	{ NULL, TYPE_An },  /* An */
-	{ NULL, TYPE_Ar },  /* Ar */
-	{ NULL, TYPE_Cd },  /* Cd */
-	{ NULL, TYPE_Cm },  /* Cm */
-	{ NULL, TYPE_Dv },  /* Dv */
-	{ NULL, TYPE_Er },  /* Er */
-	{ NULL, TYPE_Ev },  /* Ev */
-	{ NULL, 0 },  /* Ex */
-	{ NULL, TYPE_Fa },  /* Fa */
-	{ parse_mdoc_Fd, 0 },  /* Fd */
-	{ NULL, TYPE_Fl },  /* Fl */
-	{ parse_mdoc_Fn, 0 },  /* Fn */
-	{ NULL, TYPE_Ft },  /* Ft */
-	{ NULL, TYPE_Ic },  /* Ic */
-	{ NULL, TYPE_In },  /* In */
-	{ NULL, TYPE_Li },  /* Li */
-	{ parse_mdoc_Nd, 0 },  /* Nd */
-	{ parse_mdoc_Nm, 0 },  /* Nm */
-	{ NULL, 0 },  /* Op */
-	{ NULL, 0 },  /* Ot */
-	{ NULL, TYPE_Pa },  /* Pa */
-	{ NULL, 0 },  /* Rv */
-	{ NULL, TYPE_St },  /* St */
-	{ parse_mdoc_Va, TYPE_Va },  /* Va */
-	{ parse_mdoc_Va, TYPE_Vt },  /* Vt */
-	{ parse_mdoc_Xr, 0 },  /* Xr */
-	{ NULL, 0 },  /* %A */
-	{ NULL, 0 },  /* %B */
-	{ NULL, 0 },  /* %D */
-	{ NULL, 0 },  /* %I */
-	{ NULL, 0 },  /* %J */
-	{ NULL, 0 },  /* %N */
-	{ NULL, 0 },  /* %O */
-	{ NULL, 0 },  /* %P */
-	{ NULL, 0 },  /* %R */
-	{ NULL, 0 },  /* %T */
-	{ NULL, 0 },  /* %V */
-	{ NULL, 0 },  /* Ac */
-	{ NULL, 0 },  /* Ao */
-	{ NULL, 0 },  /* Aq */
-	{ NULL, TYPE_At },  /* At */
-	{ NULL, 0 },  /* Bc */
-	{ NULL, 0 },  /* Bf */
-	{ NULL, 0 },  /* Bo */
-	{ NULL, 0 },  /* Bq */
-	{ NULL, TYPE_Bsx },  /* Bsx */
-	{ NULL, TYPE_Bx },  /* Bx */
-	{ NULL, 0 },  /* Db */
-	{ NULL, 0 },  /* Dc */
-	{ NULL, 0 },  /* Do */
-	{ NULL, 0 },  /* Dq */
-	{ NULL, 0 },  /* Ec */
-	{ NULL, 0 },  /* Ef */
-	{ NULL, TYPE_Em },  /* Em */
-	{ NULL, 0 },  /* Eo */
-	{ NULL, TYPE_Fx },  /* Fx */
-	{ NULL, TYPE_Ms },  /* Ms */
-	{ NULL, 0 },  /* No */
-	{ NULL, 0 },  /* Ns */
-	{ NULL, TYPE_Nx },  /* Nx */
-	{ NULL, TYPE_Ox },  /* Ox */
-	{ NULL, 0 },  /* Pc */
-	{ NULL, 0 },  /* Pf */
-	{ NULL, 0 },  /* Po */
-	{ NULL, 0 },  /* Pq */
-	{ NULL, 0 },  /* Qc */
-	{ NULL, 0 },  /* Ql */
-	{ NULL, 0 },  /* Qo */
-	{ NULL, 0 },  /* Qq */
-	{ NULL, 0 },  /* Re */
-	{ NULL, 0 },  /* Rs */
-	{ NULL, 0 },  /* Sc */
-	{ NULL, 0 },  /* So */
-	{ NULL, 0 },  /* Sq */
-	{ NULL, 0 },  /* Sm */
-	{ NULL, 0 },  /* Sx */
-	{ NULL, TYPE_Sy },  /* Sy */
-	{ NULL, TYPE_Tn },  /* Tn */
-	{ NULL, 0 },  /* Ux */
-	{ NULL, 0 },  /* Xc */
-	{ NULL, 0 },  /* Xo */
-	{ parse_mdoc_Fo, 0 },  /* Fo */
-	{ NULL, 0 },  /* Fc */
-	{ NULL, 0 },  /* Oo */
-	{ NULL, 0 },  /* Oc */
-	{ NULL, 0 },  /* Bk */
-	{ NULL, 0 },  /* Ek */
-	{ NULL, 0 },  /* Bt */
-	{ NULL, 0 },  /* Hf */
-	{ NULL, 0 },  /* Fr */
-	{ NULL, 0 },  /* Ud */
-	{ NULL, TYPE_Lb },  /* Lb */
-	{ NULL, 0 },  /* Lp */
-	{ NULL, TYPE_Lk },  /* Lk */
-	{ NULL, TYPE_Mt },  /* Mt */
-	{ NULL, 0 },  /* Brq */
-	{ NULL, 0 },  /* Bro */
-	{ NULL, 0 },  /* Brc */
-	{ NULL, 0 },  /* %C */
-	{ NULL, 0 },  /* Es */
-	{ NULL, 0 },  /* En */
-	{ NULL, TYPE_Dx },  /* Dx */
-	{ NULL, 0 },  /* %Q */
-	{ NULL, 0 },  /* br */
-	{ NULL, 0 },  /* sp */
-	{ NULL, 0 },  /* %U */
-	{ NULL, 0 },  /* Ta */
-	{ NULL, 0 },  /* ll */
+	{ NULL, 0, 0 },  /* Ap */
+	{ NULL, 0, NODE_NOPRT },  /* Dd */
+	{ NULL, 0, NODE_NOPRT },  /* Dt */
+	{ NULL, 0, NODE_NOPRT },  /* Os */
+	{ parse_mdoc_Sh, TYPE_Sh, 0 }, /* Sh */
+	{ parse_mdoc_head, TYPE_Ss, 0 }, /* Ss */
+	{ NULL, 0, 0 },  /* Pp */
+	{ NULL, 0, 0 },  /* D1 */
+	{ NULL, 0, 0 },  /* Dl */
+	{ NULL, 0, 0 },  /* Bd */
+	{ NULL, 0, 0 },  /* Ed */
+	{ NULL, 0, 0 },  /* Bl */
+	{ NULL, 0, 0 },  /* El */
+	{ NULL, 0, 0 },  /* It */
+	{ NULL, 0, 0 },  /* Ad */
+	{ NULL, TYPE_An, 0 },  /* An */
+	{ NULL, TYPE_Ar, 0 },  /* Ar */
+	{ NULL, TYPE_Cd, 0 },  /* Cd */
+	{ NULL, TYPE_Cm, 0 },  /* Cm */
+	{ NULL, TYPE_Dv, 0 },  /* Dv */
+	{ NULL, TYPE_Er, 0 },  /* Er */
+	{ NULL, TYPE_Ev, 0 },  /* Ev */
+	{ NULL, 0, 0 },  /* Ex */
+	{ NULL, TYPE_Fa, 0 },  /* Fa */
+	{ parse_mdoc_Fd, 0, 0 },  /* Fd */
+	{ NULL, TYPE_Fl, 0 },  /* Fl */
+	{ parse_mdoc_Fn, 0, 0 },  /* Fn */
+	{ NULL, TYPE_Ft, 0 },  /* Ft */
+	{ NULL, TYPE_Ic, 0 },  /* Ic */
+	{ NULL, TYPE_In, 0 },  /* In */
+	{ NULL, TYPE_Li, 0 },  /* Li */
+	{ parse_mdoc_Nd, 0, 0 },  /* Nd */
+	{ parse_mdoc_Nm, 0, 0 },  /* Nm */
+	{ NULL, 0, 0 },  /* Op */
+	{ NULL, 0, 0 },  /* Ot */
+	{ NULL, TYPE_Pa, NODE_NOSRC },  /* Pa */
+	{ NULL, 0, 0 },  /* Rv */
+	{ NULL, TYPE_St, 0 },  /* St */
+	{ parse_mdoc_Va, TYPE_Va, 0 },  /* Va */
+	{ parse_mdoc_Va, TYPE_Vt, 0 },  /* Vt */
+	{ parse_mdoc_Xr, 0, 0 },  /* Xr */
+	{ NULL, 0, 0 },  /* %A */
+	{ NULL, 0, 0 },  /* %B */
+	{ NULL, 0, 0 },  /* %D */
+	{ NULL, 0, 0 },  /* %I */
+	{ NULL, 0, 0 },  /* %J */
+	{ NULL, 0, 0 },  /* %N */
+	{ NULL, 0, 0 },  /* %O */
+	{ NULL, 0, 0 },  /* %P */
+	{ NULL, 0, 0 },  /* %R */
+	{ NULL, 0, 0 },  /* %T */
+	{ NULL, 0, 0 },  /* %V */
+	{ NULL, 0, 0 },  /* Ac */
+	{ NULL, 0, 0 },  /* Ao */
+	{ NULL, 0, 0 },  /* Aq */
+	{ NULL, TYPE_At, 0 },  /* At */
+	{ NULL, 0, 0 },  /* Bc */
+	{ NULL, 0, 0 },  /* Bf */
+	{ NULL, 0, 0 },  /* Bo */
+	{ NULL, 0, 0 },  /* Bq */
+	{ NULL, TYPE_Bsx, NODE_NOSRC },  /* Bsx */
+	{ NULL, TYPE_Bx, NODE_NOSRC },  /* Bx */
+	{ NULL, 0, 0 },  /* Db */
+	{ NULL, 0, 0 },  /* Dc */
+	{ NULL, 0, 0 },  /* Do */
+	{ NULL, 0, 0 },  /* Dq */
+	{ NULL, 0, 0 },  /* Ec */
+	{ NULL, 0, 0 },  /* Ef */
+	{ NULL, TYPE_Em, 0 },  /* Em */
+	{ NULL, 0, 0 },  /* Eo */
+	{ NULL, TYPE_Fx, NODE_NOSRC },  /* Fx */
+	{ NULL, TYPE_Ms, 0 },  /* Ms */
+	{ NULL, 0, 0 },  /* No */
+	{ NULL, 0, 0 },  /* Ns */
+	{ NULL, TYPE_Nx, NODE_NOSRC },  /* Nx */
+	{ NULL, TYPE_Ox, NODE_NOSRC },  /* Ox */
+	{ NULL, 0, 0 },  /* Pc */
+	{ NULL, 0, 0 },  /* Pf */
+	{ NULL, 0, 0 },  /* Po */
+	{ NULL, 0, 0 },  /* Pq */
+	{ NULL, 0, 0 },  /* Qc */
+	{ NULL, 0, 0 },  /* Ql */
+	{ NULL, 0, 0 },  /* Qo */
+	{ NULL, 0, 0 },  /* Qq */
+	{ NULL, 0, 0 },  /* Re */
+	{ NULL, 0, 0 },  /* Rs */
+	{ NULL, 0, 0 },  /* Sc */
+	{ NULL, 0, 0 },  /* So */
+	{ NULL, 0, 0 },  /* Sq */
+	{ NULL, 0, 0 },  /* Sm */
+	{ NULL, 0, 0 },  /* Sx */
+	{ NULL, TYPE_Sy, 0 },  /* Sy */
+	{ NULL, TYPE_Tn, 0 },  /* Tn */
+	{ NULL, 0, NODE_NOSRC },  /* Ux */
+	{ NULL, 0, 0 },  /* Xc */
+	{ NULL, 0, 0 },  /* Xo */
+	{ parse_mdoc_Fo, 0, 0 },  /* Fo */
+	{ NULL, 0, 0 },  /* Fc */
+	{ NULL, 0, 0 },  /* Oo */
+	{ NULL, 0, 0 },  /* Oc */
+	{ NULL, 0, 0 },  /* Bk */
+	{ NULL, 0, 0 },  /* Ek */
+	{ NULL, 0, 0 },  /* Bt */
+	{ NULL, 0, 0 },  /* Hf */
+	{ NULL, 0, 0 },  /* Fr */
+	{ NULL, 0, 0 },  /* Ud */
+	{ NULL, TYPE_Lb, NODE_NOSRC },  /* Lb */
+	{ NULL, 0, 0 },  /* Lp */
+	{ NULL, TYPE_Lk, 0 },  /* Lk */
+	{ NULL, TYPE_Mt, NODE_NOSRC },  /* Mt */
+	{ NULL, 0, 0 },  /* Brq */
+	{ NULL, 0, 0 },  /* Bro */
+	{ NULL, 0, 0 },  /* Brc */
+	{ NULL, 0, 0 },  /* %C */
+	{ NULL, 0, 0 },  /* Es */
+	{ NULL, 0, 0 },  /* En */
+	{ NULL, TYPE_Dx, NODE_NOSRC },  /* Dx */
+	{ NULL, 0, 0 },  /* %Q */
+	{ NULL, 0, 0 },  /* br */
+	{ NULL, 0, 0 },  /* sp */
+	{ NULL, 0, 0 },  /* %U */
+	{ NULL, 0, 0 },  /* Ta */
+	{ NULL, 0, 0 },  /* ll */
 };
 
 
 int
 mandocdb(int argc, char *argv[])
 {
 	struct manconf	  conf;
 	struct mparse	 *mp;
+	struct dba	 *dba;
 	const char	 *path_arg, *progname;
 	size_t		  j, sz;
 	int		  ch, i;
 
 #if HAVE_PLEDGE
 	if (pledge("stdio rpath wpath cpath fattr flock proc exec", NULL) == -1) {
 		warn("pledge");
 		return (int)MANDOCLEVEL_SYSERR;
 	}
 #endif
 
 #if HAVE_SANDBOX_INIT
 	if (sandbox_init(kSBXProfileNoInternet, SANDBOX_NAMED, NULL) == -1) {
 		warnx("sandbox_init");
 		return (int)MANDOCLEVEL_SYSERR;
 	}
 #endif
 
 	memset(&conf, 0, sizeof(conf));
-	memset(stmts, 0, STMT__MAX * sizeof(sqlite3_stmt *));
 
 	/*
 	 * We accept a few different invocations.
 	 * The CHECKOP macro makes sure that invocation styles don't
 	 * clobber each other.
 	 */
 #define	CHECKOP(_op, _ch) do \
 	if (OP_DEFAULT != (_op)) { \
 		warnx("-%c: Conflicting option", (_ch)); \
 		goto usage; \
 	} while (/*CONSTCOND*/0)
 
 	path_arg = NULL;
 	op = OP_DEFAULT;
 
 	while (-1 != (ch = getopt(argc, argv, "aC:Dd:npQT:tu:v")))
 		switch (ch) {
 		case 'a':
 			use_all = 1;
 			break;
 		case 'C':
 			CHECKOP(op, ch);
 			path_arg = optarg;
 			op = OP_CONFFILE;
 			break;
 		case 'D':
 			debug++;
 			break;
 		case 'd':
 			CHECKOP(op, ch);
 			path_arg = optarg;
 			op = OP_UPDATE;
 			break;
 		case 'n':
 			nodb = 1;
 			break;
 		case 'p':
 			warnings = 1;
 			break;
 		case 'Q':
 			mparse_options |= MPARSE_QUICK;
 			break;
 		case 'T':
 			if (strcmp(optarg, "utf8")) {
 				warnx("-T%s: Unsupported output format",
 				    optarg);
 				goto usage;
 			}
 			write_utf8 = 1;
 			break;
 		case 't':
 			CHECKOP(op, ch);
 			dup2(STDOUT_FILENO, STDERR_FILENO);
 			op = OP_TEST;
 			nodb = warnings = 1;
 			break;
 		case 'u':
 			CHECKOP(op, ch);
 			path_arg = optarg;
 			op = OP_DELETE;
 			break;
 		case 'v':
 			/* Compatibility with espie@'s makewhatis. */
 			break;
 		default:
 			goto usage;
 		}
 
 	argc -= optind;
 	argv += optind;
 
 #if HAVE_PLEDGE
 	if (nodb) {
 		if (pledge("stdio rpath", NULL) == -1) {
 			warn("pledge");
 			return (int)MANDOCLEVEL_SYSERR;
 		}
 	}
 #endif
 
 	if (OP_CONFFILE == op && argc > 0) {
 		warnx("-C: Too many arguments");
 		goto usage;
 	}
 
 	exitcode = (int)MANDOCLEVEL_OK;
 	mchars_alloc();
 	mp = mparse_alloc(mparse_options, MANDOCLEVEL_BADARG, NULL, NULL);
 	mandoc_ohash_init(&mpages, 6, offsetof(struct mpage, inodev));
 	mandoc_ohash_init(&mlinks, 6, offsetof(struct mlink, file));
 
 	if (OP_UPDATE == op || OP_DELETE == op || OP_TEST == op) {
 
 		/*
 		 * Most of these deal with a specific directory.
 		 * Jump into that directory first.
 		 */
 		if (OP_TEST != op && 0 == set_basedir(path_arg, 1))
 			goto out;
 
-		if (dbopen(1)) {
+		dba = nodb ? dba_new(128) : dba_read(MANDOC_DB);
+		if (dba != NULL) {
 			/*
 			 * The existing database is usable.  Process
 			 * all files specified on the command-line.
 			 */
 #if HAVE_PLEDGE
 			if (!nodb) {
 				if (pledge("stdio rpath wpath cpath fattr flock", NULL) == -1) {
 					warn("pledge");
 					exitcode = (int)MANDOCLEVEL_SYSERR;
 					goto out;
 				}
 			}
 #endif
 			use_all = 1;
 			for (i = 0; i < argc; i++)
 				filescan(argv[i]);
-			if (OP_TEST != op)
-				dbprune();
+			if (nodb == 0)
+				dbprune(dba);
 		} else {
-			/*
-			 * Database missing or corrupt.
-			 * Recreate from scratch.
-			 */
+			/* Database missing or corrupt. */
+			if (op != OP_UPDATE || errno != ENOENT)
+				say(MANDOC_DB, "%s: Automatically recreating"
+				    " from scratch", strerror(errno));
 			exitcode = (int)MANDOCLEVEL_OK;
 			op = OP_DEFAULT;
 			if (0 == treescan())
 				goto out;
-			if (0 == dbopen(0))
-				goto out;
+			dba = dba_new(128);
 		}
 		if (OP_DELETE != op)
-			mpages_merge(mp);
-		dbclose(OP_DEFAULT == op ? 0 : 1);
+			mpages_merge(dba, mp);
+		if (nodb == 0)
+			dbwrite(dba);
+		dba_free(dba);
 	} else {
 		/*
 		 * If we have arguments, use them as our manpaths.
-		 * If we don't, grok from manpath(1) or however else
-		 * manconf_parse() wants to do it.
+		 * If we don't, use man.conf(5).
 		 */
 		if (argc > 0) {
 			conf.manpath.paths = mandoc_reallocarray(NULL,
 			    argc, sizeof(char *));
 			conf.manpath.sz = (size_t)argc;
 			for (i = 0; i < argc; i++)
 				conf.manpath.paths[i] = mandoc_strdup(argv[i]);
 		} else
 			manconf_parse(&conf, path_arg, NULL, NULL);
 
 		if (conf.manpath.sz == 0) {
 			exitcode = (int)MANDOCLEVEL_BADARG;
 			say("", "Empty manpath");
 		}
 
 		/*
 		 * First scan the tree rooted at a base directory, then
 		 * build a new database and finally move it into place.
 		 * Ignore zero-length directories and strip trailing
 		 * slashes.
 		 */
 		for (j = 0; j < conf.manpath.sz; j++) {
 			sz = strlen(conf.manpath.paths[j]);
 			if (sz && conf.manpath.paths[j][sz - 1] == '/')
 				conf.manpath.paths[j][--sz] = '\0';
 			if (0 == sz)
 				continue;
 
 			if (j) {
 				mandoc_ohash_init(&mpages, 6,
 				    offsetof(struct mpage, inodev));
 				mandoc_ohash_init(&mlinks, 6,
 				    offsetof(struct mlink, file));
 			}
 
 			if ( ! set_basedir(conf.manpath.paths[j], argc > 0))
 				continue;
 			if (0 == treescan())
 				continue;
-			if (0 == dbopen(0))
-				continue;
+			dba = dba_new(128);
+			mpages_merge(dba, mp);
+			if (nodb == 0)
+				dbwrite(dba);
+			dba_free(dba);
 
-			mpages_merge(mp);
-			if (warnings && !nodb &&
-			    ! (MPARSE_QUICK & mparse_options))
-				names_check();
-			dbclose(0);
-
 			if (j + 1 < conf.manpath.sz) {
 				mpages_free();
 				ohash_delete(&mpages);
 				ohash_delete(&mlinks);
 			}
 		}
 	}
 out:
 	manconf_free(&conf);
 	mparse_free(mp);
 	mchars_free();
 	mpages_free();
 	ohash_delete(&mpages);
 	ohash_delete(&mlinks);
 	return exitcode;
 usage:
 	progname = getprogname();
 	fprintf(stderr, "usage: %s [-aDnpQ] [-C file] [-Tutf8]\n"
 			"       %s [-aDnpQ] [-Tutf8] dir ...\n"
 			"       %s [-DnpQ] [-Tutf8] -d dir [file ...]\n"
 			"       %s [-Dnp] -u dir [file ...]\n"
 			"       %s [-Q] -t file ...\n",
 		        progname, progname, progname, progname, progname);
 
 	return (int)MANDOCLEVEL_BADARG;
 }
 
+/*
+ * To get a singly linked list in alpha order while inserting entries
+ * at the beginning, process directory entries in reverse alpha order.
+ */
 static int
+#if HAVE_FTS_COMPARE_CONST
 fts_compare(const FTSENT *const *a, const FTSENT *const *b)
+#else
+fts_compare(const FTSENT **a, const FTSENT **b)
+#endif
 {
-
-	/*
-	 * The mpage list is processed in the opposite order to which pages are
-	 * added, so traverse the hierarchy in reverse alpha order, resulting
-	 * in database inserts in alpha order. This is not required for correct
-	 * operation, but is helpful when inspecting the database during
-	 * development.
-	 */
 	return -strcmp((*a)->fts_name, (*b)->fts_name);
 }
 
 /*
  * Scan a directory tree rooted at "basedir" for manpages.
  * We use fts(), scanning directory parts along the way for clues to our
  * section and architecture.
  *
  * If use_all has been specified, grok all files.
  * If not, sanitise paths to the following:
  *
  *   [./]man*[/]/.
* or * [./]cat
[/]/.0 * * TODO: accommodate for multi-language directories. */ static int treescan(void) { char buf[PATH_MAX]; FTS *f; FTSENT *ff; struct mlink *mlink; - int dform, gzip; + int gzip; + enum form dform; char *dsec, *arch, *fsec, *cp; const char *path; const char *argv[2]; argv[0] = "."; argv[1] = (char *)NULL; f = fts_open((char * const *)argv, FTS_PHYSICAL | FTS_NOCHDIR, fts_compare); if (f == NULL) { exitcode = (int)MANDOCLEVEL_SYSERR; say("", "&fts_open"); return 0; } dsec = arch = NULL; dform = FORM_NONE; while ((ff = fts_read(f)) != NULL) { path = ff->fts_path + 2; switch (ff->fts_info) { /* * Symbolic links require various sanity checks, * then get handled just like regular files. */ case FTS_SL: if (realpath(path, buf) == NULL) { if (warnings) say(path, "&realpath"); continue; } if (strstr(buf, basedir) != buf #ifdef HOMEBREWDIR && strstr(buf, HOMEBREWDIR) != buf #endif ) { if (warnings) say("", "%s: outside base directory", buf); continue; } /* Use logical inode to avoid mpages dupe. */ if (stat(path, ff->fts_statp) == -1) { if (warnings) say(path, "&stat"); continue; } /* FALLTHROUGH */ /* * If we're a regular file, add an mlink by using the * stored directory data and handling the filename. */ case FTS_F: if ( ! strcmp(path, MANDOC_DB)) continue; if ( ! use_all && ff->fts_level < 2) { if (warnings) say(path, "Extraneous file"); continue; } gzip = 0; fsec = NULL; while (fsec == NULL) { fsec = strrchr(ff->fts_name, '.'); if (fsec == NULL || strcmp(fsec+1, "gz")) break; gzip = 1; *fsec = '\0'; fsec = NULL; } if (fsec == NULL) { if ( ! use_all) { if (warnings) say(path, "No filename suffix"); continue; } } else if ( ! strcmp(++fsec, "html")) { if (warnings) say(path, "Skip html"); continue; } else if ( ! strcmp(fsec, "ps")) { if (warnings) say(path, "Skip ps"); continue; } else if ( ! strcmp(fsec, "pdf")) { if (warnings) say(path, "Skip pdf"); continue; } else if ( ! use_all && ((dform == FORM_SRC && strncmp(fsec, dsec, strlen(dsec))) || (dform == FORM_CAT && strcmp(fsec, "0")))) { if (warnings) say(path, "Wrong filename suffix"); continue; } else fsec[-1] = '\0'; mlink = mandoc_calloc(1, sizeof(struct mlink)); if (strlcpy(mlink->file, path, sizeof(mlink->file)) >= sizeof(mlink->file)) { say(path, "Filename too long"); free(mlink); continue; } mlink->dform = dform; mlink->dsec = dsec; mlink->arch = arch; mlink->name = ff->fts_name; mlink->fsec = fsec; mlink->gzip = gzip; mlink_add(mlink, ff->fts_statp); continue; case FTS_D: case FTS_DP: break; default: if (warnings) say(path, "Not a regular file"); continue; } switch (ff->fts_level) { case 0: /* Ignore the root directory. */ break; case 1: /* * This might contain manX/ or catX/. * Try to infer this from the name. * If we're not in use_all, enforce it. */ cp = ff->fts_name; if (ff->fts_info == FTS_DP) { dform = FORM_NONE; dsec = NULL; break; } if ( ! strncmp(cp, "man", 3)) { dform = FORM_SRC; dsec = cp + 3; } else if ( ! strncmp(cp, "cat", 3)) { dform = FORM_CAT; dsec = cp + 3; } else { dform = FORM_NONE; dsec = NULL; } if (dsec != NULL || use_all) break; if (warnings) say(path, "Unknown directory part"); fts_set(f, ff, FTS_SKIP); break; case 2: /* * Possibly our architecture. * If we're descending, keep tabs on it. */ if (ff->fts_info != FTS_DP && dsec != NULL) arch = ff->fts_name; else arch = NULL; break; default: if (ff->fts_info == FTS_DP || use_all) break; if (warnings) say(path, "Extraneous directory part"); fts_set(f, ff, FTS_SKIP); break; } } fts_close(f); return 1; } /* * Add a file to the mlinks table. * Do not verify that it's a "valid" looking manpage (we'll do that * later). * * Try to infer the manual section, architecture, and page name from the * path, assuming it looks like * * [./]man*[/]/.
* or * [./]cat
[/]/.0 * * See treescan() for the fts(3) version of this. */ static void filescan(const char *file) { char buf[PATH_MAX]; struct stat st; struct mlink *mlink; char *p, *start; assert(use_all); if (0 == strncmp(file, "./", 2)) file += 2; /* * We have to do lstat(2) before realpath(3) loses * the information whether this is a symbolic link. * We need to know that because for symbolic links, * we want to use the orginal file name, while for * regular files, we want to use the real path. */ if (-1 == lstat(file, &st)) { exitcode = (int)MANDOCLEVEL_BADARG; say(file, "&lstat"); return; } else if (0 == ((S_IFREG | S_IFLNK) & st.st_mode)) { exitcode = (int)MANDOCLEVEL_BADARG; say(file, "Not a regular file"); return; } /* * We have to resolve the file name to the real path * in any case for the base directory check. */ if (NULL == realpath(file, buf)) { exitcode = (int)MANDOCLEVEL_BADARG; say(file, "&realpath"); return; } if (OP_TEST == op) start = buf; else if (strstr(buf, basedir) == buf) start = buf + strlen(basedir); #ifdef HOMEBREWDIR else if (strstr(buf, HOMEBREWDIR) == buf) start = buf; #endif else { exitcode = (int)MANDOCLEVEL_BADARG; say("", "%s: outside base directory", buf); return; } /* * Now we are sure the file is inside our tree. * If it is a symbolic link, ignore the real path * and use the original name. * This implies passing stuff like "cat1/../man1/foo.1" * on the command line won't work. So don't do that. * Note the stat(2) can still fail if the link target * doesn't exist. */ if (S_IFLNK & st.st_mode) { if (-1 == stat(buf, &st)) { exitcode = (int)MANDOCLEVEL_BADARG; say(file, "&stat"); return; } if (strlcpy(buf, file, sizeof(buf)) >= sizeof(buf)) { say(file, "Filename too long"); return; } start = buf; if (OP_TEST != op && strstr(buf, basedir) == buf) start += strlen(basedir); } mlink = mandoc_calloc(1, sizeof(struct mlink)); mlink->dform = FORM_NONE; if (strlcpy(mlink->file, start, sizeof(mlink->file)) >= sizeof(mlink->file)) { say(start, "Filename too long"); free(mlink); return; } /* * First try to guess our directory structure. * If we find a separator, try to look for man* or cat*. * If we find one of these and what's underneath is a directory, * assume it's an architecture. */ if (NULL != (p = strchr(start, '/'))) { *p++ = '\0'; if (0 == strncmp(start, "man", 3)) { mlink->dform = FORM_SRC; mlink->dsec = start + 3; } else if (0 == strncmp(start, "cat", 3)) { mlink->dform = FORM_CAT; mlink->dsec = start + 3; } start = p; if (NULL != mlink->dsec && NULL != (p = strchr(start, '/'))) { *p++ = '\0'; mlink->arch = start; start = p; } } /* * Now check the file suffix. * Suffix of `.0' indicates a catpage, `.1-9' is a manpage. */ p = strrchr(start, '\0'); while (p-- > start && '/' != *p && '.' != *p) /* Loop. */ ; if ('.' == *p) { *p++ = '\0'; mlink->fsec = p; } /* * Now try to parse the name. * Use the filename portion of the path. */ mlink->name = start; if (NULL != (p = strrchr(start, '/'))) { mlink->name = p + 1; *p = '\0'; } mlink_add(mlink, &st); } static void mlink_add(struct mlink *mlink, const struct stat *st) { struct inodev inodev; struct mpage *mpage; unsigned int slot; assert(NULL != mlink->file); mlink->dsec = mandoc_strdup(mlink->dsec ? mlink->dsec : ""); mlink->arch = mandoc_strdup(mlink->arch ? mlink->arch : ""); mlink->name = mandoc_strdup(mlink->name ? mlink->name : ""); mlink->fsec = mandoc_strdup(mlink->fsec ? mlink->fsec : ""); if ('0' == *mlink->fsec) { free(mlink->fsec); mlink->fsec = mandoc_strdup(mlink->dsec); mlink->fform = FORM_CAT; } else if ('1' <= *mlink->fsec && '9' >= *mlink->fsec) mlink->fform = FORM_SRC; else mlink->fform = FORM_NONE; slot = ohash_qlookup(&mlinks, mlink->file); assert(NULL == ohash_find(&mlinks, slot)); ohash_insert(&mlinks, slot, mlink); memset(&inodev, 0, sizeof(inodev)); /* Clear padding. */ inodev.st_ino = st->st_ino; inodev.st_dev = st->st_dev; slot = ohash_lookup_memory(&mpages, (char *)&inodev, sizeof(struct inodev), inodev.st_ino); mpage = ohash_find(&mpages, slot); if (NULL == mpage) { mpage = mandoc_calloc(1, sizeof(struct mpage)); mpage->inodev.st_ino = inodev.st_ino; mpage->inodev.st_dev = inodev.st_dev; + mpage->form = FORM_NONE; mpage->next = mpage_head; mpage_head = mpage; ohash_insert(&mpages, slot, mpage); } else mlink->next = mpage->mlinks; mpage->mlinks = mlink; mlink->mpage = mpage; } static void mlink_free(struct mlink *mlink) { free(mlink->dsec); free(mlink->arch); free(mlink->name); free(mlink->fsec); free(mlink); } static void mpages_free(void) { struct mpage *mpage; struct mlink *mlink; - while (NULL != (mpage = mpage_head)) { - while (NULL != (mlink = mpage->mlinks)) { + while ((mpage = mpage_head) != NULL) { + while ((mlink = mpage->mlinks) != NULL) { mpage->mlinks = mlink->next; mlink_free(mlink); } mpage_head = mpage->next; free(mpage->sec); free(mpage->arch); free(mpage->title); free(mpage->desc); free(mpage); } } /* * For each mlink to the mpage, check whether the path looks like * it is formatted, and if it does, check whether a source manual * exists by the same name, ignoring the suffix. * If both conditions hold, drop the mlink. */ static void mlinks_undupe(struct mpage *mpage) { char buf[PATH_MAX]; struct mlink **prev; struct mlink *mlink; char *bufp; mpage->form = FORM_CAT; prev = &mpage->mlinks; while (NULL != (mlink = *prev)) { if (FORM_CAT != mlink->dform) { mpage->form = FORM_NONE; goto nextlink; } (void)strlcpy(buf, mlink->file, sizeof(buf)); bufp = strstr(buf, "cat"); assert(NULL != bufp); memcpy(bufp, "man", 3); if (NULL != (bufp = strrchr(buf, '.'))) *++bufp = '\0'; (void)strlcat(buf, mlink->dsec, sizeof(buf)); if (NULL == ohash_find(&mlinks, ohash_qlookup(&mlinks, buf))) goto nextlink; if (warnings) say(mlink->file, "Man source exists: %s", buf); if (use_all) goto nextlink; *prev = mlink->next; mlink_free(mlink); continue; nextlink: prev = &(*prev)->next; } } static void mlink_check(struct mpage *mpage, struct mlink *mlink) { struct str *str; unsigned int slot; /* * Check whether the manual section given in a file * agrees with the directory where the file is located. * Some manuals have suffixes like (3p) on their * section number either inside the file or in the * directory name, some are linked into more than one * section, like encrypt(1) = makekey(8). */ if (FORM_SRC == mpage->form && strcasecmp(mpage->sec, mlink->dsec)) say(mlink->file, "Section \"%s\" manual in %s directory", mpage->sec, mlink->dsec); /* * Manual page directories exist for each kernel * architecture as returned by machine(1). * However, many manuals only depend on the * application architecture as returned by arch(1). * For example, some (2/ARM) manuals are shared * across the "armish" and "zaurus" kernel * architectures. * A few manuals are even shared across completely * different architectures, for example fdformat(1) - * on amd64, i386, sparc, and sparc64. + * on amd64, i386, and sparc64. */ if (strcasecmp(mpage->arch, mlink->arch)) say(mlink->file, "Architecture \"%s\" manual in " "\"%s\" directory", mpage->arch, mlink->arch); /* * XXX * parse_cat() doesn't set NAME_TITLE yet. */ if (FORM_CAT == mpage->form) return; /* * Check whether this mlink * appears as a name in the NAME section. */ slot = ohash_qlookup(&names, mlink->name); str = ohash_find(&names, slot); assert(NULL != str); if ( ! (NAME_TITLE & str->mask)) say(mlink->file, "Name missing in NAME section"); } /* * Run through the files in the global vector "mpages" * and add them to the database specified in "basedir". * * This handles the parsing scheme itself, using the cues of directory * and filename to determine whether the file is parsable or not. */ static void -mpages_merge(struct mparse *mp) +mpages_merge(struct dba *dba, struct mparse *mp) { - char any[] = "any"; struct mpage *mpage, *mpage_dest; struct mlink *mlink, *mlink_dest; struct roff_man *man; char *sodest; char *cp; int fd; - if ( ! nodb) - SQL_EXEC("BEGIN TRANSACTION"); - for (mpage = mpage_head; mpage != NULL; mpage = mpage->next) { mlinks_undupe(mpage); if ((mlink = mpage->mlinks) == NULL) continue; name_mask = NAME_MASK; mandoc_ohash_init(&names, 4, offsetof(struct str, key)); mandoc_ohash_init(&strings, 6, offsetof(struct str, key)); mparse_reset(mp); man = NULL; sodest = NULL; if ((fd = mparse_open(mp, mlink->file)) == -1) { say(mlink->file, "&open"); goto nextpage; } /* * Interpret the file as mdoc(7) or man(7) source * code, unless it is known to be formatted. */ if (mlink->dform != FORM_CAT || mlink->fform != FORM_CAT) { mparse_readfd(mp, fd, mlink->file); close(fd); mparse_result(mp, &man, &sodest); } if (sodest != NULL) { mlink_dest = ohash_find(&mlinks, ohash_qlookup(&mlinks, sodest)); if (mlink_dest == NULL) { mandoc_asprintf(&cp, "%s.gz", sodest); mlink_dest = ohash_find(&mlinks, ohash_qlookup(&mlinks, cp)); free(cp); } if (mlink_dest != NULL) { /* The .so target exists. */ mpage_dest = mlink_dest->mpage; while (1) { mlink->mpage = mpage_dest; /* * If the target was already * processed, add the links * to the database now. * Otherwise, this will * happen when we come * to the target. */ - if (mpage_dest->pageid) - dbadd_mlink_name(mlink); + if (mpage_dest->dba != NULL) + dbadd_mlink(mlink); if (mlink->next == NULL) break; mlink = mlink->next; } /* Move all links to the target. */ mlink->next = mlink_dest->next; mlink_dest->next = mpage->mlinks; mpage->mlinks = NULL; } goto nextpage; } else if (man != NULL && man->macroset == MACROSET_MDOC) { mdoc_validate(man); mpage->form = FORM_SRC; mpage->sec = man->meta.msec; mpage->sec = mandoc_strdup( mpage->sec == NULL ? "" : mpage->sec); mpage->arch = man->meta.arch; mpage->arch = mandoc_strdup( mpage->arch == NULL ? "" : mpage->arch); mpage->title = mandoc_strdup(man->meta.title); } else if (man != NULL && man->macroset == MACROSET_MAN) { man_validate(man); mpage->form = FORM_SRC; mpage->sec = mandoc_strdup(man->meta.msec); mpage->arch = mandoc_strdup(mlink->arch); mpage->title = mandoc_strdup(man->meta.title); } else { mpage->form = FORM_CAT; mpage->sec = mandoc_strdup(mlink->dsec); mpage->arch = mandoc_strdup(mlink->arch); mpage->title = mandoc_strdup(mlink->name); } - putkey(mpage, mpage->sec, TYPE_sec); - if (*mpage->arch != '\0') - putkey(mpage, mpage->arch, TYPE_arch); - for ( ; mlink != NULL; mlink = mlink->next) { - if ('\0' != *mlink->dsec) - putkey(mpage, mlink->dsec, TYPE_sec); - if ('\0' != *mlink->fsec) - putkey(mpage, mlink->fsec, TYPE_sec); - putkey(mpage, '\0' == *mlink->arch ? - any : mlink->arch, TYPE_arch); - putkey(mpage, mlink->name, NAME_FILE); - } - assert(mpage->desc == NULL); if (man != NULL && man->macroset == MACROSET_MDOC) parse_mdoc(mpage, &man->meta, man->first); else if (man != NULL) parse_man(mpage, &man->meta, man->first); else parse_cat(mpage, fd); if (mpage->desc == NULL) mpage->desc = mandoc_strdup(mpage->mlinks->name); if (warnings && !use_all) for (mlink = mpage->mlinks; mlink; mlink = mlink->next) mlink_check(mpage, mlink); - dbadd(mpage); + dbadd(dba, mpage); mlink = mpage->mlinks; nextpage: ohash_delete(&strings); ohash_delete(&names); } - - if (0 == nodb) - SQL_EXEC("END TRANSACTION"); } static void -names_check(void) -{ - sqlite3_stmt *stmt; - const char *name, *sec, *arch, *key; - - sqlite3_prepare_v2(db, - "SELECT name, sec, arch, key FROM (" - "SELECT name AS key, pageid FROM names " - "WHERE bits & ? AND NOT EXISTS (" - "SELECT pageid FROM mlinks " - "WHERE mlinks.pageid == names.pageid " - "AND mlinks.name == names.name" - ")" - ") JOIN (" - "SELECT sec, arch, name, pageid FROM mlinks " - "GROUP BY pageid" - ") USING (pageid);", - -1, &stmt, NULL); - - if (sqlite3_bind_int64(stmt, 1, NAME_TITLE) != SQLITE_OK) - say("", "%s", sqlite3_errmsg(db)); - - while (sqlite3_step(stmt) == SQLITE_ROW) { - name = (const char *)sqlite3_column_text(stmt, 0); - sec = (const char *)sqlite3_column_text(stmt, 1); - arch = (const char *)sqlite3_column_text(stmt, 2); - key = (const char *)sqlite3_column_text(stmt, 3); - say("", "%s(%s%s%s) lacks mlink \"%s\"", name, sec, - '\0' == *arch ? "" : "/", - '\0' == *arch ? "" : arch, key); - } - sqlite3_finalize(stmt); -} - -static void parse_cat(struct mpage *mpage, int fd) { FILE *stream; char *line, *p, *title; size_t linesz, plen, titlesz; ssize_t len; int offs; stream = (-1 == fd) ? fopen(mpage->mlinks->file, "r") : fdopen(fd, "r"); if (NULL == stream) { if (-1 != fd) close(fd); if (warnings) say(mpage->mlinks->file, "&fopen"); return; } line = NULL; linesz = 0; /* Skip to first blank line. */ while (getline(&line, &linesz, stream) != -1) if (*line == '\n') break; /* * Assume the first line that is not indented * is the first section header. Skip to it. */ while (getline(&line, &linesz, stream) != -1) if (*line != '\n' && *line != ' ') break; /* * Read up until the next section into a buffer. * Strip the leading and trailing newline from each read line, * appending a trailing space. * Ignore empty (whitespace-only) lines. */ titlesz = 0; title = NULL; while ((len = getline(&line, &linesz, stream)) != -1) { if (*line != ' ') break; offs = 0; while (isspace((unsigned char)line[offs])) offs++; if (line[offs] == '\0') continue; title = mandoc_realloc(title, titlesz + len - offs); memcpy(title + titlesz, line + offs, len - offs); titlesz += len - offs; title[titlesz - 1] = ' '; } free(line); /* * If no page content can be found, or the input line * is already the next section header, or there is no * trailing newline, reuse the page title as the page * description. */ if (NULL == title || '\0' == *title) { if (warnings) say(mpage->mlinks->file, "Cannot find NAME section"); fclose(stream); free(title); return; } title[titlesz - 1] = '\0'; /* * Skip to the first dash. * Use the remaining line as the description (no more than 70 * bytes). */ if (NULL != (p = strstr(title, "- "))) { for (p += 2; ' ' == *p || '\b' == *p; p++) /* Skip to next word. */ ; } else { if (warnings) say(mpage->mlinks->file, "No dash in title line"); p = title; } plen = strlen(p); /* Strip backspace-encoding from line. */ while (NULL != (line = memchr(p, '\b', plen))) { len = line - p; if (0 == len) { memmove(line, line + 1, plen--); continue; } memmove(line - 1, line + 1, plen - len); plen -= 2; } mpage->desc = mandoc_strdup(p); fclose(stream); free(title); } /* * Put a type/word pair into the word database for this particular file. */ static void putkey(const struct mpage *mpage, char *value, uint64_t type) { - char *cp; - - assert(NULL != value); - if (TYPE_arch == type) - for (cp = value; *cp; cp++) - if (isupper((unsigned char)*cp)) - *cp = _tolower((unsigned char)*cp); putkeys(mpage, value, strlen(value), type); } /* * Grok all nodes at or below a certain mdoc node into putkey(). */ static void putmdockey(const struct mpage *mpage, - const struct roff_node *n, uint64_t m) + const struct roff_node *n, uint64_t m, int taboo) { for ( ; NULL != n; n = n->next) { + if (n->flags & taboo) + continue; if (NULL != n->child) - putmdockey(mpage, n->child, m); + putmdockey(mpage, n->child, m, taboo); if (n->type == ROFFT_TEXT) putkey(mpage, n->string, m); } } static void parse_man(struct mpage *mpage, const struct roff_meta *meta, const struct roff_node *n) { const struct roff_node *head, *body; char *start, *title; char byte; size_t sz; if (n == NULL) return; /* * We're only searching for one thing: the first text child in * the BODY of a NAME section. Since we don't keep track of * sections in -man, run some hoops to find out whether we're in * the correct section or not. */ if (n->type == ROFFT_BODY && n->tok == MAN_SH) { body = n; if ((head = body->parent->head) != NULL && (head = head->child) != NULL && head->next == NULL && head->type == ROFFT_TEXT && strcmp(head->string, "NAME") == 0 && body->child != NULL) { /* * Suck the entire NAME section into memory. * Yes, we might run away. * But too many manuals have big, spread-out * NAME sections over many lines. */ title = NULL; deroff(&title, body); if (NULL == title) return; /* * Go through a special heuristic dance here. * Conventionally, one or more manual names are * comma-specified prior to a whitespace, then a * dash, then a description. Try to puzzle out * the name parts here. */ start = title; for ( ;; ) { sz = strcspn(start, " ,"); if ('\0' == start[sz]) break; byte = start[sz]; start[sz] = '\0'; /* * Assume a stray trailing comma in the * name list if a name begins with a dash. */ if ('-' == start[0] || ('\\' == start[0] && '-' == start[1])) break; putkey(mpage, start, NAME_TITLE); if ( ! (mpage->name_head_done || strcasecmp(start, meta->title))) { putkey(mpage, start, NAME_HEAD); mpage->name_head_done = 1; } if (' ' == byte) { start += sz + 1; break; } assert(',' == byte); start += sz + 1; while (' ' == *start) start++; } if (start == title) { putkey(mpage, start, NAME_TITLE); if ( ! (mpage->name_head_done || strcasecmp(start, meta->title))) { putkey(mpage, start, NAME_HEAD); mpage->name_head_done = 1; } free(title); return; } while (isspace((unsigned char)*start)) start++; if (0 == strncmp(start, "-", 1)) start += 1; else if (0 == strncmp(start, "\\-\\-", 4)) start += 4; else if (0 == strncmp(start, "\\-", 2)) start += 2; else if (0 == strncmp(start, "\\(en", 4)) start += 4; else if (0 == strncmp(start, "\\(em", 4)) start += 4; while (' ' == *start) start++; mpage->desc = mandoc_strdup(start); free(title); return; } } for (n = n->child; n; n = n->next) { if (NULL != mpage->desc) break; parse_man(mpage, meta, n); } } static void parse_mdoc(struct mpage *mpage, const struct roff_meta *meta, const struct roff_node *n) { assert(NULL != n); for (n = n->child; NULL != n; n = n->next) { + if (n->flags & mdocs[n->tok].taboo) + continue; switch (n->type) { case ROFFT_ELEM: case ROFFT_BLOCK: case ROFFT_HEAD: case ROFFT_BODY: case ROFFT_TAIL: if (NULL != mdocs[n->tok].fp) if (0 == (*mdocs[n->tok].fp)(mpage, meta, n)) break; if (mdocs[n->tok].mask) putmdockey(mpage, n->child, - mdocs[n->tok].mask); + mdocs[n->tok].mask, mdocs[n->tok].taboo); break; default: assert(n->type != ROFFT_ROOT); continue; } if (NULL != n->child) parse_mdoc(mpage, meta, n); } } static int parse_mdoc_Fd(struct mpage *mpage, const struct roff_meta *meta, const struct roff_node *n) { char *start, *end; size_t sz; if (SEC_SYNOPSIS != n->sec || NULL == (n = n->child) || n->type != ROFFT_TEXT) return 0; /* * Only consider those `Fd' macro fields that begin with an * "inclusion" token (versus, e.g., #define). */ if (strcmp("#include", n->string)) return 0; if ((n = n->next) == NULL || n->type != ROFFT_TEXT) return 0; /* * Strip away the enclosing angle brackets and make sure we're * not zero-length. */ start = n->string; if ('<' == *start || '"' == *start) start++; if (0 == (sz = strlen(start))) return 0; end = &start[(int)sz - 1]; if ('>' == *end || '"' == *end) end--; if (end > start) putkeys(mpage, start, end - start + 1, TYPE_In); return 0; } static void parse_mdoc_fname(struct mpage *mpage, const struct roff_node *n) { char *cp; size_t sz; if (n->type != ROFFT_TEXT) return; /* Skip function pointer punctuation. */ cp = n->string; while (*cp == '(' || *cp == '*') cp++; sz = strcspn(cp, "()"); putkeys(mpage, cp, sz, TYPE_Fn); if (n->sec == SEC_SYNOPSIS) putkeys(mpage, cp, sz, NAME_SYN); } static int parse_mdoc_Fn(struct mpage *mpage, const struct roff_meta *meta, const struct roff_node *n) { if (n->child == NULL) return 0; parse_mdoc_fname(mpage, n->child); for (n = n->child->next; n != NULL; n = n->next) if (n->type == ROFFT_TEXT) putkey(mpage, n->string, TYPE_Fa); return 0; } static int parse_mdoc_Fo(struct mpage *mpage, const struct roff_meta *meta, const struct roff_node *n) { if (n->type != ROFFT_HEAD) return 1; if (n->child != NULL) parse_mdoc_fname(mpage, n->child); return 0; } static int parse_mdoc_Va(struct mpage *mpage, const struct roff_meta *meta, const struct roff_node *n) { char *cp; if (n->type != ROFFT_ELEM && n->type != ROFFT_BODY) return 0; if (n->child != NULL && n->child->next == NULL && n->child->type == ROFFT_TEXT) return 1; cp = NULL; deroff(&cp, n); if (cp != NULL) { putkey(mpage, cp, TYPE_Vt | (n->tok == MDOC_Va || n->type == ROFFT_BODY ? TYPE_Va : 0)); free(cp); } return 0; } static int parse_mdoc_Xr(struct mpage *mpage, const struct roff_meta *meta, const struct roff_node *n) { char *cp; if (NULL == (n = n->child)) return 0; if (NULL == n->next) { putkey(mpage, n->string, TYPE_Xr); return 0; } mandoc_asprintf(&cp, "%s(%s)", n->string, n->next->string); putkey(mpage, cp, TYPE_Xr); free(cp); return 0; } static int parse_mdoc_Nd(struct mpage *mpage, const struct roff_meta *meta, const struct roff_node *n) { if (n->type == ROFFT_BODY) deroff(&mpage->desc, n); return 0; } static int parse_mdoc_Nm(struct mpage *mpage, const struct roff_meta *meta, const struct roff_node *n) { if (SEC_NAME == n->sec) - putmdockey(mpage, n->child, NAME_TITLE); + putmdockey(mpage, n->child, NAME_TITLE, 0); else if (n->sec == SEC_SYNOPSIS && n->type == ROFFT_HEAD) { if (n->child == NULL) putkey(mpage, meta->name, NAME_SYN); else - putmdockey(mpage, n->child, NAME_SYN); + putmdockey(mpage, n->child, NAME_SYN, 0); } if ( ! (mpage->name_head_done || n->child == NULL || n->child->string == NULL || strcasecmp(n->child->string, meta->title))) { - putkey(mpage, n->child->string, ROFFT_HEAD); + putkey(mpage, n->child->string, NAME_HEAD); mpage->name_head_done = 1; } return 0; } static int parse_mdoc_Sh(struct mpage *mpage, const struct roff_meta *meta, const struct roff_node *n) { return n->sec == SEC_CUSTOM && n->type == ROFFT_HEAD; } static int parse_mdoc_head(struct mpage *mpage, const struct roff_meta *meta, const struct roff_node *n) { return n->type == ROFFT_HEAD; } /* * Add a string to the hash table for the current manual. * Each string has a bitmask telling which macros it belongs to. * When we finish the manual, we'll dump the table. */ static void putkeys(const struct mpage *mpage, char *cp, size_t sz, uint64_t v) { struct ohash *htab; struct str *s; const char *end; unsigned int slot; int i, mustfree; if (0 == sz) return; mustfree = render_string(&cp, &sz); if (TYPE_Nm & v) { htab = &names; v &= name_mask; if (v & NAME_FIRST) name_mask &= ~NAME_FIRST; if (debug > 1) say(mpage->mlinks->file, - "Adding name %*s, bits=%d", sz, cp, v); + "Adding name %*s, bits=0x%llx", (int)sz, cp, + (unsigned long long)v); } else { htab = &strings; if (debug > 1) - for (i = 0; i < mansearch_keymax; i++) + for (i = 0; i < KEY_MAX; i++) if ((uint64_t)1 << i & v) say(mpage->mlinks->file, "Adding key %s=%*s", - mansearch_keynames[i], sz, cp); + mansearch_keynames[i], (int)sz, cp); } end = cp + sz; slot = ohash_qlookupi(htab, cp, &end); s = ohash_find(htab, slot); if (NULL != s && mpage == s->mpage) { s->mask |= v; return; } else if (NULL == s) { s = mandoc_calloc(1, sizeof(struct str) + sz + 1); memcpy(s->key, cp, sz); ohash_insert(htab, slot, s); } s->mpage = mpage; s->mask = v; if (mustfree) free(cp); } /* * Take a Unicode codepoint and produce its UTF-8 encoding. * This isn't the best way to do this, but it works. * The magic numbers are from the UTF-8 packaging. * They're not as scary as they seem: read the UTF-8 spec for details. */ static size_t utf8(unsigned int cp, char out[7]) { size_t rc; rc = 0; if (cp <= 0x0000007F) { rc = 1; out[0] = (char)cp; } else if (cp <= 0x000007FF) { rc = 2; out[0] = (cp >> 6 & 31) | 192; out[1] = (cp & 63) | 128; } else if (cp <= 0x0000FFFF) { rc = 3; out[0] = (cp >> 12 & 15) | 224; out[1] = (cp >> 6 & 63) | 128; out[2] = (cp & 63) | 128; } else if (cp <= 0x001FFFFF) { rc = 4; out[0] = (cp >> 18 & 7) | 240; out[1] = (cp >> 12 & 63) | 128; out[2] = (cp >> 6 & 63) | 128; out[3] = (cp & 63) | 128; } else if (cp <= 0x03FFFFFF) { rc = 5; out[0] = (cp >> 24 & 3) | 248; out[1] = (cp >> 18 & 63) | 128; out[2] = (cp >> 12 & 63) | 128; out[3] = (cp >> 6 & 63) | 128; out[4] = (cp & 63) | 128; } else if (cp <= 0x7FFFFFFF) { rc = 6; out[0] = (cp >> 30 & 1) | 252; out[1] = (cp >> 24 & 63) | 128; out[2] = (cp >> 18 & 63) | 128; out[3] = (cp >> 12 & 63) | 128; out[4] = (cp >> 6 & 63) | 128; out[5] = (cp & 63) | 128; } else return 0; out[rc] = '\0'; return rc; } /* * If the string contains escape sequences, * replace it with an allocated rendering and return 1, * such that the caller can free it after use. * Otherwise, do nothing and return 0. */ static int render_string(char **public, size_t *psz) { const char *src, *scp, *addcp, *seq; char *dst; size_t ssz, dsz, addsz; char utfbuf[7], res[6]; int seqlen, unicode; res[0] = '\\'; res[1] = '\t'; res[2] = ASCII_NBRSP; res[3] = ASCII_HYPH; res[4] = ASCII_BREAK; res[5] = '\0'; src = scp = *public; ssz = *psz; dst = NULL; dsz = 0; while (scp < src + *psz) { /* Leave normal characters unchanged. */ if (strchr(res, *scp) == NULL) { if (dst != NULL) dst[dsz++] = *scp; scp++; continue; } /* * Found something that requires replacing, * make sure we have a destination buffer. */ if (dst == NULL) { dst = mandoc_malloc(ssz + 1); dsz = scp - src; memcpy(dst, src, dsz); } /* Handle single-char special characters. */ switch (*scp) { case '\\': break; case '\t': case ASCII_NBRSP: dst[dsz++] = ' '; scp++; continue; case ASCII_HYPH: dst[dsz++] = '-'; /* FALLTHROUGH */ case ASCII_BREAK: scp++; continue; default: abort(); } /* * Found an escape sequence. * Read past the slash, then parse it. * Ignore everything except characters. */ scp++; if (mandoc_escape(&scp, &seq, &seqlen) != ESCAPE_SPECIAL) continue; /* * Render the special character * as either UTF-8 or ASCII. */ if (write_utf8) { unicode = mchars_spec2cp(seq, seqlen); if (unicode <= 0) continue; addsz = utf8(unicode, utfbuf); if (addsz == 0) continue; addcp = utfbuf; } else { addcp = mchars_spec2str(seq, seqlen, &addsz); if (addcp == NULL) continue; if (*addcp == ASCII_NBRSP) { addcp = " "; addsz = 1; } } /* Copy the rendered glyph into the stream. */ ssz += addsz; dst = mandoc_realloc(dst, ssz + 1); memcpy(dst + dsz, addcp, addsz); dsz += addsz; } if (dst != NULL) { *public = dst; *psz = dsz; } /* Trim trailing whitespace and NUL-terminate. */ while (*psz > 0 && (*public)[*psz - 1] == ' ') --*psz; if (dst != NULL) { (*public)[*psz] = '\0'; return 1; } else return 0; } static void dbadd_mlink(const struct mlink *mlink) { - size_t i; - - i = 1; - SQL_BIND_TEXT(stmts[STMT_INSERT_LINK], i, mlink->dsec); - SQL_BIND_TEXT(stmts[STMT_INSERT_LINK], i, mlink->arch); - SQL_BIND_TEXT(stmts[STMT_INSERT_LINK], i, mlink->name); - SQL_BIND_INT64(stmts[STMT_INSERT_LINK], i, mlink->mpage->pageid); - SQL_STEP(stmts[STMT_INSERT_LINK]); - sqlite3_reset(stmts[STMT_INSERT_LINK]); + dba_page_alias(mlink->mpage->dba, mlink->name, NAME_FILE); + dba_page_add(mlink->mpage->dba, DBP_SECT, mlink->dsec); + dba_page_add(mlink->mpage->dba, DBP_SECT, mlink->fsec); + dba_page_add(mlink->mpage->dba, DBP_ARCH, mlink->arch); + dba_page_add(mlink->mpage->dba, DBP_FILE, mlink->file); } -static void -dbadd_mlink_name(const struct mlink *mlink) -{ - uint64_t bits; - size_t i; - - dbadd_mlink(mlink); - - i = 1; - SQL_BIND_INT64(stmts[STMT_SELECT_NAME], i, mlink->mpage->pageid); - bits = NAME_FILE & NAME_MASK; - if (sqlite3_step(stmts[STMT_SELECT_NAME]) == SQLITE_ROW) { - bits |= sqlite3_column_int64(stmts[STMT_SELECT_NAME], 0); - sqlite3_reset(stmts[STMT_SELECT_NAME]); - } - - i = 1; - SQL_BIND_INT64(stmts[STMT_INSERT_NAME], i, bits); - SQL_BIND_TEXT(stmts[STMT_INSERT_NAME], i, mlink->name); - SQL_BIND_INT64(stmts[STMT_INSERT_NAME], i, mlink->mpage->pageid); - SQL_STEP(stmts[STMT_INSERT_NAME]); - sqlite3_reset(stmts[STMT_INSERT_NAME]); -} - /* * Flush the current page's terms (and their bits) into the database. - * Wrap the entire set of additions in a transaction to make sqlite be a - * little faster. * Also, handle escape sequences at the last possible moment. */ static void -dbadd(struct mpage *mpage) +dbadd(struct dba *dba, struct mpage *mpage) { struct mlink *mlink; struct str *key; char *cp; + uint64_t mask; size_t i; unsigned int slot; int mustfree; mlink = mpage->mlinks; if (nodb) { for (key = ohash_first(&names, &slot); NULL != key; key = ohash_next(&names, &slot)) free(key); for (key = ohash_first(&strings, &slot); NULL != key; key = ohash_next(&strings, &slot)) free(key); if (0 == debug) return; while (NULL != mlink) { fputs(mlink->name, stdout); if (NULL == mlink->next || strcmp(mlink->dsec, mlink->next->dsec) || strcmp(mlink->fsec, mlink->next->fsec) || strcmp(mlink->arch, mlink->next->arch)) { putchar('('); if ('\0' == *mlink->dsec) fputs(mlink->fsec, stdout); else fputs(mlink->dsec, stdout); if ('\0' != *mlink->arch) printf("/%s", mlink->arch); putchar(')'); } mlink = mlink->next; if (NULL != mlink) fputs(", ", stdout); } printf(" - %s\n", mpage->desc); return; } if (debug) say(mlink->file, "Adding to database"); cp = mpage->desc; i = strlen(cp); mustfree = render_string(&cp, &i); - i = 1; - SQL_BIND_TEXT(stmts[STMT_INSERT_PAGE], i, cp); - SQL_BIND_INT(stmts[STMT_INSERT_PAGE], i, mpage->form); - SQL_STEP(stmts[STMT_INSERT_PAGE]); - mpage->pageid = sqlite3_last_insert_rowid(db); - sqlite3_reset(stmts[STMT_INSERT_PAGE]); + mpage->dba = dba_page_new(dba->pages, + *mpage->arch == '\0' ? mlink->arch : mpage->arch, + cp, mlink->file, mpage->form); if (mustfree) free(cp); + dba_page_add(mpage->dba, DBP_SECT, mpage->sec); - while (NULL != mlink) { + while (mlink != NULL) { dbadd_mlink(mlink); mlink = mlink->next; } - mlink = mpage->mlinks; for (key = ohash_first(&names, &slot); NULL != key; key = ohash_next(&names, &slot)) { assert(key->mpage == mpage); - i = 1; - SQL_BIND_INT64(stmts[STMT_INSERT_NAME], i, key->mask); - SQL_BIND_TEXT(stmts[STMT_INSERT_NAME], i, key->key); - SQL_BIND_INT64(stmts[STMT_INSERT_NAME], i, mpage->pageid); - SQL_STEP(stmts[STMT_INSERT_NAME]); - sqlite3_reset(stmts[STMT_INSERT_NAME]); + dba_page_alias(mpage->dba, key->key, key->mask); free(key); } for (key = ohash_first(&strings, &slot); NULL != key; key = ohash_next(&strings, &slot)) { assert(key->mpage == mpage); - i = 1; - SQL_BIND_INT64(stmts[STMT_INSERT_KEY], i, key->mask); - SQL_BIND_TEXT(stmts[STMT_INSERT_KEY], i, key->key); - SQL_BIND_INT64(stmts[STMT_INSERT_KEY], i, mpage->pageid); - SQL_STEP(stmts[STMT_INSERT_KEY]); - sqlite3_reset(stmts[STMT_INSERT_KEY]); + i = 0; + for (mask = TYPE_Xr; mask <= TYPE_Lb; mask *= 2) { + if (key->mask & mask) + dba_macro_add(dba->macros, i, + key->key, mpage->dba); + i++; + } free(key); } } static void -dbprune(void) +dbprune(struct dba *dba) { - struct mpage *mpage; - struct mlink *mlink; - size_t i; - unsigned int slot; + struct dba_array *page, *files; + char *file; - if (0 == nodb) - SQL_EXEC("BEGIN TRANSACTION"); - - for (mpage = ohash_first(&mpages, &slot); NULL != mpage; - mpage = ohash_next(&mpages, &slot)) { - mlink = mpage->mlinks; - if (debug) - say(mlink->file, "Deleting from database"); - if (nodb) - continue; - for ( ; NULL != mlink; mlink = mlink->next) { - i = 1; - SQL_BIND_TEXT(stmts[STMT_DELETE_PAGE], - i, mlink->dsec); - SQL_BIND_TEXT(stmts[STMT_DELETE_PAGE], - i, mlink->arch); - SQL_BIND_TEXT(stmts[STMT_DELETE_PAGE], - i, mlink->name); - SQL_STEP(stmts[STMT_DELETE_PAGE]); - sqlite3_reset(stmts[STMT_DELETE_PAGE]); + dba_array_FOREACH(dba->pages, page) { + files = dba_array_get(page, DBP_FILE); + dba_array_FOREACH(files, file) { + if (*file < ' ') + file++; + if (ohash_find(&mlinks, ohash_qlookup(&mlinks, + file)) != NULL) { + if (debug) + say(file, "Deleting from database"); + dba_array_del(dba->pages); + break; + } } } - - if (0 == nodb) - SQL_EXEC("END TRANSACTION"); } /* - * Close an existing database and its prepared statements. - * If "real" is not set, rename the temporary file into the real one. + * Write the database from memory to disk. */ static void -dbclose(int real) +dbwrite(struct dba *dba) { - size_t i; + char tfn[32]; int status; pid_t child; - if (nodb) + if (dba_write(MANDOC_DB "~", dba) != -1) { + if (rename(MANDOC_DB "~", MANDOC_DB) == -1) { + exitcode = (int)MANDOCLEVEL_SYSERR; + say(MANDOC_DB, "&rename"); + unlink(MANDOC_DB "~"); + } return; - - for (i = 0; i < STMT__MAX; i++) { - sqlite3_finalize(stmts[i]); - stmts[i] = NULL; } - sqlite3_close(db); - db = NULL; - - if (real) + (void)strlcpy(tfn, "/tmp/mandocdb.XXXXXXXX", sizeof(tfn)); + if (mkdtemp(tfn) == NULL) { + exitcode = (int)MANDOCLEVEL_SYSERR; + say("", "&%s", tfn); return; + } - if ('\0' == *tempfilename) { - if (-1 == rename(MANDOC_DB "~", MANDOC_DB)) { - exitcode = (int)MANDOCLEVEL_SYSERR; - say(MANDOC_DB, "&rename"); - } - return; + (void)strlcat(tfn, "/" MANDOC_DB, sizeof(tfn)); + if (dba_write(tfn, dba) == -1) { + exitcode = (int)MANDOCLEVEL_SYSERR; + say(tfn, "&dba_write"); + goto out; } switch (child = fork()) { case -1: exitcode = (int)MANDOCLEVEL_SYSERR; say("", "&fork cmp"); return; case 0: - execlp("cmp", "cmp", "-s", - tempfilename, MANDOC_DB, (char *)NULL); + execlp("cmp", "cmp", "-s", tfn, MANDOC_DB, (char *)NULL); say("", "&exec cmp"); exit(0); default: break; } - if (-1 == waitpid(child, &status, 0)) { + if (waitpid(child, &status, 0) == -1) { exitcode = (int)MANDOCLEVEL_SYSERR; say("", "&wait cmp"); } else if (WIFSIGNALED(status)) { exitcode = (int)MANDOCLEVEL_SYSERR; say("", "cmp died from signal %d", WTERMSIG(status)); } else if (WEXITSTATUS(status)) { exitcode = (int)MANDOCLEVEL_SYSERR; say(MANDOC_DB, "Data changed, but cannot replace database"); } - *strrchr(tempfilename, '/') = '\0'; +out: + *strrchr(tfn, '/') = '\0'; switch (child = fork()) { case -1: exitcode = (int)MANDOCLEVEL_SYSERR; say("", "&fork rm"); return; case 0: - execlp("rm", "rm", "-rf", tempfilename, (char *)NULL); + execlp("rm", "rm", "-rf", tfn, (char *)NULL); say("", "&exec rm"); exit((int)MANDOCLEVEL_SYSERR); default: break; } - if (-1 == waitpid(child, &status, 0)) { + if (waitpid(child, &status, 0) == -1) { exitcode = (int)MANDOCLEVEL_SYSERR; say("", "&wait rm"); } else if (WIFSIGNALED(status) || WEXITSTATUS(status)) { exitcode = (int)MANDOCLEVEL_SYSERR; - say("", "%s: Cannot remove temporary directory", - tempfilename); + say("", "%s: Cannot remove temporary directory", tfn); } -} - -/* - * This is straightforward stuff. - * Open a database connection to a "temporary" database, then open a set - * of prepared statements we'll use over and over again. - * If "real" is set, we use the existing database; if not, we truncate a - * temporary one. - * Must be matched by dbclose(). - */ -static int -dbopen(int real) -{ - const char *sql; - int rc, ofl; - - if (nodb) - return 1; - - *tempfilename = '\0'; - ofl = SQLITE_OPEN_READWRITE; - - if (real) { - rc = sqlite3_open_v2(MANDOC_DB, &db, ofl, NULL); - if (SQLITE_OK != rc) { - exitcode = (int)MANDOCLEVEL_SYSERR; - if (SQLITE_CANTOPEN != rc) - say(MANDOC_DB, "%s", sqlite3_errstr(rc)); - return 0; - } - goto prepare_statements; - } - - ofl |= SQLITE_OPEN_CREATE | SQLITE_OPEN_EXCLUSIVE; - - remove(MANDOC_DB "~"); - rc = sqlite3_open_v2(MANDOC_DB "~", &db, ofl, NULL); - if (SQLITE_OK == rc) - goto create_tables; - if (MPARSE_QUICK & mparse_options) { - exitcode = (int)MANDOCLEVEL_SYSERR; - say(MANDOC_DB "~", "%s", sqlite3_errstr(rc)); - return 0; - } - - (void)strlcpy(tempfilename, "/tmp/mandocdb.XXXXXX", - sizeof(tempfilename)); - if (NULL == mkdtemp(tempfilename)) { - exitcode = (int)MANDOCLEVEL_SYSERR; - say("", "&%s", tempfilename); - return 0; - } - (void)strlcat(tempfilename, "/" MANDOC_DB, - sizeof(tempfilename)); - rc = sqlite3_open_v2(tempfilename, &db, ofl, NULL); - if (SQLITE_OK != rc) { - exitcode = (int)MANDOCLEVEL_SYSERR; - say("", "%s: %s", tempfilename, sqlite3_errstr(rc)); - return 0; - } - -create_tables: - sql = "CREATE TABLE \"mpages\" (\n" - " \"desc\" TEXT NOT NULL,\n" - " \"form\" INTEGER NOT NULL,\n" - " \"pageid\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL\n" - ");\n" - "\n" - "CREATE TABLE \"mlinks\" (\n" - " \"sec\" TEXT NOT NULL,\n" - " \"arch\" TEXT NOT NULL,\n" - " \"name\" TEXT NOT NULL,\n" - " \"pageid\" INTEGER NOT NULL REFERENCES mpages(pageid) " - "ON DELETE CASCADE\n" - ");\n" - "CREATE INDEX mlinks_pageid_idx ON mlinks (pageid);\n" - "\n" - "CREATE TABLE \"names\" (\n" - " \"bits\" INTEGER NOT NULL,\n" - " \"name\" TEXT NOT NULL,\n" - " \"pageid\" INTEGER NOT NULL REFERENCES mpages(pageid) " - "ON DELETE CASCADE,\n" - " UNIQUE (\"name\", \"pageid\") ON CONFLICT REPLACE\n" - ");\n" - "\n" - "CREATE TABLE \"keys\" (\n" - " \"bits\" INTEGER NOT NULL,\n" - " \"key\" TEXT NOT NULL,\n" - " \"pageid\" INTEGER NOT NULL REFERENCES mpages(pageid) " - "ON DELETE CASCADE\n" - ");\n" - "CREATE INDEX keys_pageid_idx ON keys (pageid);\n"; - - if (SQLITE_OK != sqlite3_exec(db, sql, NULL, NULL, NULL)) { - exitcode = (int)MANDOCLEVEL_SYSERR; - say(MANDOC_DB, "%s", sqlite3_errmsg(db)); - sqlite3_close(db); - return 0; - } - -prepare_statements: - if (SQLITE_OK != sqlite3_exec(db, - "PRAGMA foreign_keys = ON", NULL, NULL, NULL)) { - exitcode = (int)MANDOCLEVEL_SYSERR; - say(MANDOC_DB, "PRAGMA foreign_keys: %s", - sqlite3_errmsg(db)); - sqlite3_close(db); - return 0; - } - - sql = "DELETE FROM mpages WHERE pageid IN " - "(SELECT pageid FROM mlinks WHERE " - "sec=? AND arch=? AND name=?)"; - sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_DELETE_PAGE], NULL); - sql = "INSERT INTO mpages " - "(desc,form) VALUES (?,?)"; - sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_INSERT_PAGE], NULL); - sql = "INSERT INTO mlinks " - "(sec,arch,name,pageid) VALUES (?,?,?,?)"; - sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_INSERT_LINK], NULL); - sql = "SELECT bits FROM names where pageid = ?"; - sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_SELECT_NAME], NULL); - sql = "INSERT INTO names " - "(bits,name,pageid) VALUES (?,?,?)"; - sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_INSERT_NAME], NULL); - sql = "INSERT INTO keys " - "(bits,key,pageid) VALUES (?,?,?)"; - sqlite3_prepare_v2(db, sql, -1, &stmts[STMT_INSERT_KEY], NULL); - -#ifndef __APPLE__ - /* - * When opening a new database, we can turn off - * synchronous mode for much better performance. - */ - - if (real && SQLITE_OK != sqlite3_exec(db, - "PRAGMA synchronous = OFF", NULL, NULL, NULL)) { - exitcode = (int)MANDOCLEVEL_SYSERR; - say(MANDOC_DB, "PRAGMA synchronous: %s", - sqlite3_errmsg(db)); - sqlite3_close(db); - return 0; - } -#endif - - return 1; } static int set_basedir(const char *targetdir, int report_baddir) { static char startdir[PATH_MAX]; static int getcwd_status; /* 1 = ok, 2 = failure */ static int chdir_status; /* 1 = changed directory */ char *cp; /* * Remember the original working directory, if possible. * This will be needed if the second or a later directory * on the command line is given as a relative path. * Do not error out if the current directory is not * searchable: Maybe it won't be needed after all. */ if (0 == getcwd_status) { if (NULL == getcwd(startdir, sizeof(startdir))) { getcwd_status = 2; (void)strlcpy(startdir, strerror(errno), sizeof(startdir)); } else getcwd_status = 1; } /* * We are leaving the old base directory. * Do not use it any longer, not even for messages. */ *basedir = '\0'; /* * If and only if the directory was changed earlier and * the next directory to process is given as a relative path, * first go back, or bail out if that is impossible. */ if (chdir_status && '/' != *targetdir) { if (2 == getcwd_status) { exitcode = (int)MANDOCLEVEL_SYSERR; say("", "getcwd: %s", startdir); return 0; } if (-1 == chdir(startdir)) { exitcode = (int)MANDOCLEVEL_SYSERR; say("", "&chdir %s", startdir); return 0; } } /* * Always resolve basedir to the canonicalized absolute * pathname and append a trailing slash, such that * we can reliably check whether files are inside. */ if (NULL == realpath(targetdir, basedir)) { if (report_baddir || errno != ENOENT) { exitcode = (int)MANDOCLEVEL_BADARG; say("", "&%s: realpath", targetdir); } return 0; } else if (-1 == chdir(basedir)) { if (report_baddir || errno != ENOENT) { exitcode = (int)MANDOCLEVEL_BADARG; say("", "&chdir"); } return 0; } chdir_status = 1; cp = strchr(basedir, '\0'); if ('/' != cp[-1]) { if (cp - basedir >= PATH_MAX - 1) { exitcode = (int)MANDOCLEVEL_SYSERR; say("", "Filename too long"); return 0; } *cp++ = '/'; *cp = '\0'; } return 1; } static void say(const char *file, const char *format, ...) { va_list ap; int use_errno; if ('\0' != *basedir) fprintf(stderr, "%s", basedir); if ('\0' != *basedir && '\0' != *file) fputc('/', stderr); if ('\0' != *file) fprintf(stderr, "%s", file); use_errno = 1; if (NULL != format) { switch (*format) { case '&': format++; break; case '\0': format = NULL; break; default: use_errno = 0; break; } } if (NULL != format) { if ('\0' != *basedir || '\0' != *file) fputs(": ", stderr); va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap); } if (use_errno) { if ('\0' != *basedir || '\0' != *file || NULL != format) fputs(": ", stderr); perror(NULL); } else fputc('\n', stderr); } Index: stable/11/contrib/mdocml/manpath.c =================================================================== --- stable/11/contrib/mdocml/manpath.c (revision 316419) +++ stable/11/contrib/mdocml/manpath.c (revision 316420) @@ -1,335 +1,284 @@ -/* $Id: manpath.c,v 1.30 2016/05/28 13:44:13 schwarze Exp $ */ +/* $Id: manpath.c,v 1.31 2016/07/19 22:40:33 schwarze Exp $ */ /* * Copyright (c) 2011, 2014, 2015 Ingo Schwarze * Copyright (c) 2011 Kristaps Dzonsons * * 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 AUTHORS DISCLAIM ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h" #include #include #include #if HAVE_ERR #include #endif #include #include #include #include #include "mandoc_aux.h" #include "manconf.h" -#if !HAVE_MANPATH static void manconf_file(struct manconf *, const char *); -#endif static void manpath_add(struct manpaths *, const char *, int); static void manpath_parseline(struct manpaths *, char *, int); void manconf_parse(struct manconf *conf, const char *file, char *defp, char *auxp) { -#if HAVE_MANPATH - char cmd[(PATH_MAX * 3) + 20]; - FILE *stream; - char *buf; - size_t sz, bsz; - - strlcpy(cmd, "manpath", sizeof(cmd)); - if (file) { - strlcat(cmd, " -C ", sizeof(cmd)); - strlcat(cmd, file, sizeof(cmd)); - } - if (auxp) { - strlcat(cmd, " -m ", sizeof(cmd)); - strlcat(cmd, auxp, sizeof(cmd)); - } - if (defp) { - strlcat(cmd, " -M ", sizeof(cmd)); - strlcat(cmd, defp, sizeof(cmd)); - } - - /* Open manpath(1). Ignore errors. */ - - stream = popen(cmd, "r"); - if (NULL == stream) - return; - - buf = NULL; - bsz = 0; - - /* Read in as much output as we can. */ - - do { - buf = mandoc_realloc(buf, bsz + 1024); - sz = fread(buf + bsz, 1, 1024, stream); - bsz += sz; - } while (sz > 0); - - if ( ! ferror(stream) && feof(stream) && - bsz && '\n' == buf[bsz - 1]) { - buf[bsz - 1] = '\0'; - manpath_parseline(&conf->manpath, buf, 1); - } - - free(buf); - pclose(stream); -#else char *insert; /* Always prepend -m. */ manpath_parseline(&conf->manpath, auxp, 1); /* If -M is given, it overrides everything else. */ if (NULL != defp) { manpath_parseline(&conf->manpath, defp, 1); return; } /* MANPATH and man.conf(5) cooperate. */ defp = getenv("MANPATH"); if (NULL == file) file = MAN_CONF_FILE; /* No MANPATH; use man.conf(5) only. */ if (NULL == defp || '\0' == defp[0]) { manconf_file(conf, file); return; } /* Prepend man.conf(5) to MANPATH. */ if (':' == defp[0]) { manconf_file(conf, file); manpath_parseline(&conf->manpath, defp, 0); return; } /* Append man.conf(5) to MANPATH. */ if (':' == defp[strlen(defp) - 1]) { manpath_parseline(&conf->manpath, defp, 0); manconf_file(conf, file); return; } /* Insert man.conf(5) into MANPATH. */ insert = strstr(defp, "::"); if (NULL != insert) { *insert++ = '\0'; manpath_parseline(&conf->manpath, defp, 0); manconf_file(conf, file); manpath_parseline(&conf->manpath, insert + 1, 0); return; } /* MANPATH overrides man.conf(5) completely. */ manpath_parseline(&conf->manpath, defp, 0); -#endif } /* * Parse a FULL pathname from a colon-separated list of arrays. */ static void manpath_parseline(struct manpaths *dirs, char *path, int complain) { char *dir; if (NULL == path) return; for (dir = strtok(path, ":"); dir; dir = strtok(NULL, ":")) manpath_add(dirs, dir, complain); } /* * Add a directory to the array, ignoring bad directories. * Grow the array one-by-one for simplicity's sake. */ static void manpath_add(struct manpaths *dirs, const char *dir, int complain) { char buf[PATH_MAX]; struct stat sb; char *cp; size_t i; if (NULL == (cp = realpath(dir, buf))) { if (complain) warn("manpath: %s", dir); return; } for (i = 0; i < dirs->sz; i++) if (0 == strcmp(dirs->paths[i], dir)) return; if (stat(cp, &sb) == -1) { if (complain) warn("manpath: %s", dir); return; } dirs->paths = mandoc_reallocarray(dirs->paths, dirs->sz + 1, sizeof(char *)); dirs->paths[dirs->sz++] = mandoc_strdup(cp); } void manconf_free(struct manconf *conf) { size_t i; for (i = 0; i < conf->manpath.sz; i++) free(conf->manpath.paths[i]); free(conf->manpath.paths); free(conf->output.includes); free(conf->output.man); free(conf->output.paper); free(conf->output.style); } -#if !HAVE_MANPATH static void manconf_file(struct manconf *conf, const char *file) { const char *const toks[] = { "manpath", "output", "_whatdb" }; char manpath_default[] = MANPATH_DEFAULT; FILE *stream; char *line, *cp, *ep; size_t linesz, tok, toklen; ssize_t linelen; if ((stream = fopen(file, "r")) == NULL) goto out; line = NULL; linesz = 0; while ((linelen = getline(&line, &linesz, stream)) != -1) { cp = line; ep = cp + linelen - 1; while (ep > cp && isspace((unsigned char)*ep)) *ep-- = '\0'; while (isspace((unsigned char)*cp)) cp++; if (cp == ep || *cp == '#') continue; for (tok = 0; tok < sizeof(toks)/sizeof(toks[0]); tok++) { toklen = strlen(toks[tok]); if (cp + toklen < ep && isspace((unsigned char)cp[toklen]) && strncmp(cp, toks[tok], toklen) == 0) { cp += toklen; while (isspace((unsigned char)*cp)) cp++; break; } } switch (tok) { case 2: /* _whatdb */ while (ep > cp && ep[-1] != '/') ep--; if (ep == cp) continue; *ep = '\0'; /* FALLTHROUGH */ case 0: /* manpath */ manpath_add(&conf->manpath, cp, 0); *manpath_default = '\0'; break; case 1: /* output */ manconf_output(&conf->output, cp); break; default: break; } } free(line); fclose(stream); out: if (*manpath_default != '\0') manpath_parseline(&conf->manpath, manpath_default, 0); } -#endif void manconf_output(struct manoutput *conf, const char *cp) { const char *const toks[] = { "includes", "man", "paper", "style", "indent", "width", "fragment", "mdoc" }; size_t len, tok; for (tok = 0; tok < sizeof(toks)/sizeof(toks[0]); tok++) { len = strlen(toks[tok]); if ( ! strncmp(cp, toks[tok], len) && strchr(" = ", cp[len]) != NULL) { cp += len; if (*cp == '=') cp++; while (isspace((unsigned char)*cp)) cp++; break; } } if (tok < 6 && *cp == '\0') return; switch (tok) { case 0: if (conf->includes == NULL) conf->includes = mandoc_strdup(cp); break; case 1: if (conf->man == NULL) conf->man = mandoc_strdup(cp); break; case 2: if (conf->paper == NULL) conf->paper = mandoc_strdup(cp); break; case 3: if (conf->style == NULL) conf->style = mandoc_strdup(cp); break; case 4: if (conf->indent == 0) conf->indent = strtonum(cp, 0, 1000, NULL); break; case 5: if (conf->width == 0) conf->width = strtonum(cp, 58, 1000, NULL); break; case 6: conf->fragment = 1; break; case 7: conf->mdoc = 1; break; default: break; } } Index: stable/11/contrib/mdocml/mansearch.c =================================================================== --- stable/11/contrib/mdocml/mansearch.c (revision 316419) +++ stable/11/contrib/mdocml/mansearch.c (revision 316420) @@ -1,852 +1,751 @@ -/* $Id: mansearch.c,v 1.65 2016/07/09 15:24:19 schwarze Exp $ */ +/* $OpenBSD: mansearch.c,v 1.50 2016/07/09 15:23:36 schwarze Exp $ */ /* * Copyright (c) 2012 Kristaps Dzonsons - * Copyright (c) 2013, 2014, 2015 Ingo Schwarze + * Copyright (c) 2013, 2014, 2015, 2016 Ingo Schwarze * * 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 AUTHORS DISCLAIM ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h" #include #include #include #if HAVE_ERR #include #endif #include #include #include #include #include #include #include #include #include #include #include -#include -#ifndef SQLITE_DETERMINISTIC -#define SQLITE_DETERMINISTIC 0 -#endif - #include "mandoc.h" #include "mandoc_aux.h" #include "mandoc_ohash.h" #include "manconf.h" #include "mansearch.h" +#include "dbm.h" -extern int mansearch_keymax; -extern const char *const mansearch_keynames[]; - -#define SQL_BIND_TEXT(_db, _s, _i, _v) \ - do { if (SQLITE_OK != sqlite3_bind_text \ - ((_s), (_i)++, (_v), -1, SQLITE_STATIC)) \ - errx((int)MANDOCLEVEL_SYSERR, "%s", sqlite3_errmsg((_db))); \ - } while (0) -#define SQL_BIND_INT64(_db, _s, _i, _v) \ - do { if (SQLITE_OK != sqlite3_bind_int64 \ - ((_s), (_i)++, (_v))) \ - errx((int)MANDOCLEVEL_SYSERR, "%s", sqlite3_errmsg((_db))); \ - } while (0) -#define SQL_BIND_BLOB(_db, _s, _i, _v) \ - do { if (SQLITE_OK != sqlite3_bind_blob \ - ((_s), (_i)++, (&_v), sizeof(_v), SQLITE_STATIC)) \ - errx((int)MANDOCLEVEL_SYSERR, "%s", sqlite3_errmsg((_db))); \ - } while (0) - struct expr { - regex_t regexp; /* compiled regexp, if applicable */ - const char *substr; /* to search for, if applicable */ - struct expr *next; /* next in sequence */ - uint64_t bits; /* type-mask */ - int equal; /* equality, not subsring match */ - int open; /* opening parentheses before */ - int and; /* logical AND before */ - int close; /* closing parentheses after */ + /* Used for terms: */ + struct dbm_match match; /* Match type and expression. */ + uint64_t bits; /* Type mask. */ + /* Used for OR and AND groups: */ + struct expr *next; /* Next child in the parent group. */ + struct expr *child; /* First child in this group. */ + enum { EXPR_TERM, EXPR_OR, EXPR_AND } type; }; -struct match { - uint64_t pageid; /* identifier in database */ - uint64_t bits; /* name type mask */ - char *desc; /* manual page description */ - int form; /* bit field: formatted, zipped? */ +const char *const mansearch_keynames[KEY_MAX] = { + "arch", "sec", "Xr", "Ar", "Fa", "Fl", "Dv", "Fn", + "Ic", "Pa", "Cm", "Li", "Em", "Cd", "Va", "Ft", + "Tn", "Er", "Ev", "Sy", "Sh", "In", "Ss", "Ox", + "An", "Mt", "St", "Bx", "At", "Nx", "Fx", "Lk", + "Ms", "Bsx", "Dx", "Rs", "Vt", "Lb", "Nm", "Nd" }; -static void buildnames(const struct mansearch *, - struct manpage *, sqlite3 *, - sqlite3_stmt *, uint64_t, - const char *, int form); -static char *buildoutput(sqlite3 *, sqlite3_stmt *, - uint64_t, uint64_t); + +static struct ohash *manmerge(struct expr *, struct ohash *); +static struct ohash *manmerge_term(struct expr *, struct ohash *); +static struct ohash *manmerge_or(struct expr *, struct ohash *); +static struct ohash *manmerge_and(struct expr *, struct ohash *); +static char *buildnames(const struct dbm_page *); +static char *buildoutput(size_t, int32_t); +static size_t lstlen(const char *); +static void lstcat(char *, size_t *, const char *); +static int lstmatch(const char *, const char *); static struct expr *exprcomp(const struct mansearch *, - int, char *[]); + int, char *[], int *); +static struct expr *expr_and(const struct mansearch *, + int, char *[], int *); +static struct expr *exprterm(const struct mansearch *, + int, char *[], int *); static void exprfree(struct expr *); -static struct expr *exprterm(const struct mansearch *, char *, int); static int manpage_compare(const void *, const void *); -static void sql_append(char **sql, size_t *sz, - const char *newstr, int count); -static void sql_match(sqlite3_context *context, - int argc, sqlite3_value **argv); -static void sql_regexp(sqlite3_context *context, - int argc, sqlite3_value **argv); -static char *sql_statement(const struct expr *); int -mansearch_setup(int start) -{ - static void *pagecache; - int c; - -#define PC_PAGESIZE 1280 -#define PC_NUMPAGES 256 - - if (start) { - if (NULL != pagecache) { - warnx("pagecache already enabled"); - return (int)MANDOCLEVEL_BADARG; - } - - pagecache = mmap(NULL, PC_PAGESIZE * PC_NUMPAGES, - PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANON, -1, 0); - - if (MAP_FAILED == pagecache) { - warn("mmap"); - pagecache = NULL; - return (int)MANDOCLEVEL_SYSERR; - } - - c = sqlite3_config(SQLITE_CONFIG_PAGECACHE, - pagecache, PC_PAGESIZE, PC_NUMPAGES); - - if (SQLITE_OK == c) - return (int)MANDOCLEVEL_OK; - - warnx("pagecache: %s", sqlite3_errstr(c)); - - } else if (NULL == pagecache) { - warnx("pagecache missing"); - return (int)MANDOCLEVEL_BADARG; - } - - if (-1 == munmap(pagecache, PC_PAGESIZE * PC_NUMPAGES)) { - warn("munmap"); - pagecache = NULL; - return (int)MANDOCLEVEL_SYSERR; - } - - pagecache = NULL; - return (int)MANDOCLEVEL_OK; -} - -int mansearch(const struct mansearch *search, const struct manpaths *paths, int argc, char *argv[], struct manpage **res, size_t *sz) { - int64_t pageid; - uint64_t outbit, iterbit; char buf[PATH_MAX]; - char *sql; + struct dbm_res *rp; + struct expr *e; + struct dbm_page *page; struct manpage *mpage; - struct expr *e, *ep; - sqlite3 *db; - sqlite3_stmt *s, *s2; - struct match *mp; - struct ohash htab; - unsigned int idx; - size_t i, j, cur, maxres; - int c, chdir_status, getcwd_status, indexbit; + struct ohash *htab; + size_t cur, i, maxres, outkey; + unsigned int slot; + int argi, chdir_status, getcwd_status, im; - if (argc == 0 || (e = exprcomp(search, argc, argv)) == NULL) { + argi = 0; + if ((e = exprcomp(search, argc, argv, &argi)) == NULL) { *sz = 0; return 0; } cur = maxres = 0; *res = NULL; - if (NULL != search->outkey) { - outbit = TYPE_Nd; - for (indexbit = 0, iterbit = 1; - indexbit < mansearch_keymax; - indexbit++, iterbit <<= 1) { + outkey = KEY_Nd; + if (search->outkey != NULL) + for (im = 0; im < KEY_MAX; im++) if (0 == strcasecmp(search->outkey, - mansearch_keynames[indexbit])) { - outbit = iterbit; + mansearch_keynames[im])) { + outkey = im; break; } - } - } else - outbit = 0; /* * Remember the original working directory, if possible. * This will be needed if the second or a later directory * is given as a relative path. * Do not error out if the current directory is not * searchable: Maybe it won't be needed after all. */ if (getcwd(buf, PATH_MAX) == NULL) { getcwd_status = 0; (void)strlcpy(buf, strerror(errno), sizeof(buf)); } else getcwd_status = 1; - sql = sql_statement(e); - /* * Loop over the directories (containing databases) for us to * search. * Don't let missing/bad databases/directories phase us. * In each, try to open the resident database and, if it opens, * scan it for our match expression. */ chdir_status = 0; for (i = 0; i < paths->sz; i++) { if (chdir_status && paths->paths[i][0] != '/') { if ( ! getcwd_status) { warnx("%s: getcwd: %s", paths->paths[i], buf); continue; } else if (chdir(buf) == -1) { warn("%s", buf); continue; } } if (chdir(paths->paths[i]) == -1) { warn("%s", paths->paths[i]); continue; } chdir_status = 1; - c = sqlite3_open_v2(MANDOC_DB, &db, - SQLITE_OPEN_READONLY, NULL); - - if (SQLITE_OK != c) { + if (dbm_open(MANDOC_DB) == -1) { warn("%s/%s", paths->paths[i], MANDOC_DB); - sqlite3_close(db); continue; } - /* - * Define the SQL functions for substring - * and regular expression matching. - */ - - c = sqlite3_create_function(db, "match", 2, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, - NULL, sql_match, NULL, NULL); - assert(SQLITE_OK == c); - c = sqlite3_create_function(db, "regexp", 2, - SQLITE_UTF8 | SQLITE_DETERMINISTIC, - NULL, sql_regexp, NULL, NULL); - assert(SQLITE_OK == c); - - j = 1; - c = sqlite3_prepare_v2(db, sql, -1, &s, NULL); - if (SQLITE_OK != c) - errx((int)MANDOCLEVEL_SYSERR, - "%s", sqlite3_errmsg(db)); - - for (ep = e; NULL != ep; ep = ep->next) { - if (NULL == ep->substr) { - SQL_BIND_BLOB(db, s, j, ep->regexp); - } else - SQL_BIND_TEXT(db, s, j, ep->substr); - if (0 == ((TYPE_Nd | TYPE_Nm) & ep->bits)) - SQL_BIND_INT64(db, s, j, ep->bits); + if ((htab = manmerge(e, NULL)) == NULL) { + dbm_close(); + continue; } - mandoc_ohash_init(&htab, 4, offsetof(struct match, pageid)); + for (rp = ohash_first(htab, &slot); rp != NULL; + rp = ohash_next(htab, &slot)) { + page = dbm_page_get(rp->page); - /* - * Hash each entry on its [unique] document identifier. - * This is a uint64_t. - * Instead of using a hash function, simply convert the - * uint64_t to a uint32_t, the hash value's type. - * This gives good performance and preserves the - * distribution of buckets in the table. - */ - while (SQLITE_ROW == (c = sqlite3_step(s))) { - pageid = sqlite3_column_int64(s, 2); - idx = ohash_lookup_memory(&htab, - (char *)&pageid, sizeof(uint64_t), - (uint32_t)pageid); - - if (NULL != ohash_find(&htab, idx)) + if (lstmatch(search->sec, page->sect) == 0 || + lstmatch(search->arch, page->arch) == 0) continue; - mp = mandoc_calloc(1, sizeof(struct match)); - mp->pageid = pageid; - mp->form = sqlite3_column_int(s, 1); - mp->bits = sqlite3_column_int64(s, 3); - if (TYPE_Nd == outbit) - mp->desc = mandoc_strdup((const char *) - sqlite3_column_text(s, 0)); - ohash_insert(&htab, idx, mp); - } - - if (SQLITE_DONE != c) - warnx("%s", sqlite3_errmsg(db)); - - sqlite3_finalize(s); - - c = sqlite3_prepare_v2(db, - "SELECT sec, arch, name, pageid FROM mlinks " - "WHERE pageid=? ORDER BY sec, arch, name", - -1, &s, NULL); - if (SQLITE_OK != c) - errx((int)MANDOCLEVEL_SYSERR, - "%s", sqlite3_errmsg(db)); - - c = sqlite3_prepare_v2(db, - "SELECT bits, key, pageid FROM keys " - "WHERE pageid=? AND bits & ?", - -1, &s2, NULL); - if (SQLITE_OK != c) - errx((int)MANDOCLEVEL_SYSERR, - "%s", sqlite3_errmsg(db)); - - for (mp = ohash_first(&htab, &idx); - NULL != mp; - mp = ohash_next(&htab, &idx)) { if (cur + 1 > maxres) { maxres += 1024; *res = mandoc_reallocarray(*res, - maxres, sizeof(struct manpage)); + maxres, sizeof(**res)); } mpage = *res + cur; + mandoc_asprintf(&mpage->file, "%s/%s", + paths->paths[i], page->file + 1); + mpage->names = buildnames(page); + mpage->output = (int)outkey == KEY_Nd ? + mandoc_strdup(page->desc) : + buildoutput(outkey, page->addr); mpage->ipath = i; - mpage->bits = mp->bits; - mpage->sec = 10; - mpage->form = mp->form; - buildnames(search, mpage, db, s, mp->pageid, - paths->paths[i], mp->form); - if (mpage->names != NULL) { - mpage->output = TYPE_Nd & outbit ? - mp->desc : outbit ? - buildoutput(db, s2, mp->pageid, outbit) : - NULL; - cur++; - } - free(mp); + mpage->bits = rp->bits; + mpage->sec = *page->sect - '0'; + if (mpage->sec < 0 || mpage->sec > 9) + mpage->sec = 10; + mpage->form = *page->file; + free(rp); + cur++; } + ohash_delete(htab); + free(htab); + dbm_close(); - sqlite3_finalize(s); - sqlite3_finalize(s2); - sqlite3_close(db); - ohash_delete(&htab); - /* * In man(1) mode, prefer matches in earlier trees * over matches in later trees. */ if (cur && search->firstmatch) break; } qsort(*res, cur, sizeof(struct manpage), manpage_compare); if (chdir_status && getcwd_status && chdir(buf) == -1) warn("%s", buf); exprfree(e); - free(sql); *sz = cur; return 1; } -void -mansearch_free(struct manpage *res, size_t sz) +/* + * Merge the results for the expression tree rooted at e + * into the the result list htab. + */ +static struct ohash * +manmerge(struct expr *e, struct ohash *htab) { - size_t i; - - for (i = 0; i < sz; i++) { - free(res[i].file); - free(res[i].names); - free(res[i].output); + switch (e->type) { + case EXPR_TERM: + return manmerge_term(e, htab); + case EXPR_OR: + return manmerge_or(e->child, htab); + case EXPR_AND: + return manmerge_and(e->child, htab); + default: + abort(); } - free(res); } -static int -manpage_compare(const void *vp1, const void *vp2) +static struct ohash * +manmerge_term(struct expr *e, struct ohash *htab) { - const struct manpage *mp1, *mp2; - int diff; + struct dbm_res res, *rp; + uint64_t ib; + unsigned int slot; + int im; - mp1 = vp1; - mp2 = vp2; - return (diff = mp2->bits - mp1->bits) ? diff : - (diff = mp1->sec - mp2->sec) ? diff : - strcasecmp(mp1->names, mp2->names); -} + if (htab == NULL) { + htab = mandoc_malloc(sizeof(*htab)); + mandoc_ohash_init(htab, 4, offsetof(struct dbm_res, page)); + } -static void -buildnames(const struct mansearch *search, struct manpage *mpage, - sqlite3 *db, sqlite3_stmt *s, - uint64_t pageid, const char *path, int form) -{ - glob_t globinfo; - char *firstname, *newnames, *prevsec, *prevarch; - const char *oldnames, *sep1, *name, *sec, *sep2, *arch, *fsec; - size_t i; - int c, globres; + for (im = 0, ib = 1; im < KEY_MAX; im++, ib <<= 1) { + if ((e->bits & ib) == 0) + continue; - mpage->file = NULL; - mpage->names = NULL; - firstname = prevsec = prevarch = NULL; - i = 1; - SQL_BIND_INT64(db, s, i, pageid); - while (SQLITE_ROW == (c = sqlite3_step(s))) { + switch (ib) { + case TYPE_arch: + dbm_page_byarch(&e->match); + break; + case TYPE_sec: + dbm_page_bysect(&e->match); + break; + case TYPE_Nm: + dbm_page_byname(&e->match); + break; + case TYPE_Nd: + dbm_page_bydesc(&e->match); + break; + default: + dbm_page_bymacro(im - 2, &e->match); + break; + } - /* Decide whether we already have some names. */ + /* + * When hashing for deduplication, use the unique + * page ID itself instead of a hash function; + * that is quite efficient. + */ - if (NULL == mpage->names) { - oldnames = ""; - sep1 = ""; - } else { - oldnames = mpage->names; - sep1 = ", "; + for (;;) { + res = dbm_page_next(); + if (res.page == -1) + break; + slot = ohash_lookup_memory(htab, + (char *)&res, sizeof(res.page), res.page); + if ((rp = ohash_find(htab, slot)) != NULL) { + rp->bits |= res.bits; + continue; + } + rp = mandoc_malloc(sizeof(*rp)); + *rp = res; + ohash_insert(htab, slot, rp); } + } + return htab; +} - /* Fetch the next name, rejecting sec/arch mismatches. */ +static struct ohash * +manmerge_or(struct expr *e, struct ohash *htab) +{ + while (e != NULL) { + htab = manmerge(e, htab); + e = e->next; + } + return htab; +} - sec = (const char *)sqlite3_column_text(s, 0); - if (search->sec != NULL && strcasecmp(sec, search->sec)) - continue; - arch = (const char *)sqlite3_column_text(s, 1); - if (search->arch != NULL && *arch != '\0' && - strcasecmp(arch, search->arch)) - continue; - name = (const char *)sqlite3_column_text(s, 2); +static struct ohash * +manmerge_and(struct expr *e, struct ohash *htab) +{ + struct ohash *hand, *h1, *h2; + struct dbm_res *res; + unsigned int slot1, slot2; - /* Remember the first section found. */ + /* Evaluate the first term of the AND clause. */ - if (9 < mpage->sec && '1' <= *sec && '9' >= *sec) - mpage->sec = (*sec - '1') + 1; + hand = manmerge(e, NULL); - /* If the section changed, append the old one. */ + while ((e = e->next) != NULL) { - if (NULL != prevsec && - (strcmp(sec, prevsec) || - strcmp(arch, prevarch))) { - sep2 = '\0' == *prevarch ? "" : "/"; - mandoc_asprintf(&newnames, "%s(%s%s%s)", - oldnames, prevsec, sep2, prevarch); - free(mpage->names); - oldnames = mpage->names = newnames; - free(prevsec); - free(prevarch); - prevsec = prevarch = NULL; - } + /* Evaluate the next term and prepare for ANDing. */ - /* Save the new section, to append it later. */ + h2 = manmerge(e, NULL); + if (ohash_entries(h2) < ohash_entries(hand)) { + h1 = h2; + h2 = hand; + } else + h1 = hand; + hand = mandoc_malloc(sizeof(*hand)); + mandoc_ohash_init(hand, 4, offsetof(struct dbm_res, page)); - if (NULL == prevsec) { - prevsec = mandoc_strdup(sec); - prevarch = mandoc_strdup(arch); + /* Keep all pages that are in both result sets. */ + + for (res = ohash_first(h1, &slot1); res != NULL; + res = ohash_next(h1, &slot1)) { + if (ohash_find(h2, ohash_lookup_memory(h2, + (char *)res, sizeof(res->page), + res->page)) == NULL) + free(res); + else + ohash_insert(hand, ohash_lookup_memory(hand, + (char *)res, sizeof(res->page), + res->page), res); } - /* Append the new name. */ + /* Discard the merged results. */ - mandoc_asprintf(&newnames, "%s%s%s", - oldnames, sep1, name); - free(mpage->names); - mpage->names = newnames; + for (res = ohash_first(h2, &slot2); res != NULL; + res = ohash_next(h2, &slot2)) + free(res); + ohash_delete(h2); + free(h2); + ohash_delete(h1); + free(h1); + } - /* Also save the first file name encountered. */ + /* Merge the result of the AND into htab. */ - if (mpage->file != NULL) - continue; + if (htab == NULL) + return hand; - if (form & FORM_SRC) { - sep1 = "man"; - fsec = sec; - } else { - sep1 = "cat"; - fsec = "0"; - } - sep2 = *arch == '\0' ? "" : "/"; - mandoc_asprintf(&mpage->file, "%s/%s%s%s%s/%s.%s", - path, sep1, sec, sep2, arch, name, fsec); - if (access(mpage->file, R_OK) != -1) - continue; - - /* Handle unusual file name extensions. */ - - if (firstname == NULL) - firstname = mpage->file; + for (res = ohash_first(hand, &slot1); res != NULL; + res = ohash_next(hand, &slot1)) { + slot2 = ohash_lookup_memory(htab, + (char *)res, sizeof(res->page), res->page); + if (ohash_find(htab, slot2) == NULL) + ohash_insert(htab, slot2, res); else - free(mpage->file); - mandoc_asprintf(&mpage->file, "%s/%s%s%s%s/%s.*", - path, sep1, sec, sep2, arch, name); - globres = glob(mpage->file, 0, NULL, &globinfo); - free(mpage->file); - mpage->file = globres ? NULL : - mandoc_strdup(*globinfo.gl_pathv); - globfree(&globinfo); + free(res); } - if (c != SQLITE_DONE) - warnx("%s", sqlite3_errmsg(db)); - sqlite3_reset(s); - /* If none of the files is usable, use the first name. */ + /* Discard the merged result. */ - if (mpage->file == NULL) - mpage->file = firstname; - else if (mpage->file != firstname) - free(firstname); + ohash_delete(hand); + free(hand); + return htab; +} - /* Append one final section to the names. */ +void +mansearch_free(struct manpage *res, size_t sz) +{ + size_t i; - if (prevsec != NULL) { - sep2 = *prevarch == '\0' ? "" : "/"; - mandoc_asprintf(&newnames, "%s(%s%s%s)", - mpage->names, prevsec, sep2, prevarch); - free(mpage->names); - mpage->names = newnames; - free(prevsec); - free(prevarch); + for (i = 0; i < sz; i++) { + free(res[i].file); + free(res[i].names); + free(res[i].output); } + free(res); } +static int +manpage_compare(const void *vp1, const void *vp2) +{ + const struct manpage *mp1, *mp2; + int diff; + + mp1 = vp1; + mp2 = vp2; + return (diff = mp2->bits - mp1->bits) ? diff : + (diff = mp1->sec - mp2->sec) ? diff : + strcasecmp(mp1->names, mp2->names); +} + static char * -buildoutput(sqlite3 *db, sqlite3_stmt *s, uint64_t pageid, uint64_t outbit) +buildnames(const struct dbm_page *page) { - char *output, *newoutput; - const char *oldoutput, *sep1, *data; - size_t i; - int c; + char *buf; + size_t i, sz; - output = NULL; - i = 1; - SQL_BIND_INT64(db, s, i, pageid); - SQL_BIND_INT64(db, s, i, outbit); - while (SQLITE_ROW == (c = sqlite3_step(s))) { - if (NULL == output) { - oldoutput = ""; - sep1 = ""; - } else { - oldoutput = output; - sep1 = " # "; - } - data = (const char *)sqlite3_column_text(s, 1); - mandoc_asprintf(&newoutput, "%s%s%s", - oldoutput, sep1, data); - free(output); - output = newoutput; + sz = lstlen(page->name) + 1 + lstlen(page->sect) + + (page->arch == NULL ? 0 : 1 + lstlen(page->arch)) + 2; + buf = mandoc_malloc(sz); + i = 0; + lstcat(buf, &i, page->name); + buf[i++] = '('; + lstcat(buf, &i, page->sect); + if (page->arch != NULL) { + buf[i++] = '/'; + lstcat(buf, &i, page->arch); } - if (SQLITE_DONE != c) - warnx("%s", sqlite3_errmsg(db)); - sqlite3_reset(s); - return output; + buf[i++] = ')'; + buf[i++] = '\0'; + assert(i == sz); + return buf; } /* - * Implement substring match as an application-defined SQL function. - * Using the SQL LIKE or GLOB operators instead would be a bad idea - * because that would require escaping metacharacters in the string - * being searched for. + * Count the buffer space needed to print the NUL-terminated + * list of NUL-terminated strings, when printing two separator + * characters between strings. */ -static void -sql_match(sqlite3_context *context, int argc, sqlite3_value **argv) +static size_t +lstlen(const char *cp) { + size_t sz; - assert(2 == argc); - sqlite3_result_int(context, NULL != strcasestr( - (const char *)sqlite3_value_text(argv[1]), - (const char *)sqlite3_value_text(argv[0]))); + for (sz = 0;; sz++) { + if (cp[0] == '\0') { + if (cp[1] == '\0') + break; + sz++; + } else if (cp[0] < ' ') + sz--; + cp++; + } + return sz; } /* - * Implement regular expression match - * as an application-defined SQL function. + * Print the NUL-terminated list of NUL-terminated strings + * into the buffer, seperating strings with a comma and a blank. */ static void -sql_regexp(sqlite3_context *context, int argc, sqlite3_value **argv) +lstcat(char *buf, size_t *i, const char *cp) { - - assert(2 == argc); - sqlite3_result_int(context, !regexec( - (regex_t *)sqlite3_value_blob(argv[0]), - (const char *)sqlite3_value_text(argv[1]), - 0, NULL, 0)); + for (;;) { + if (cp[0] == '\0') { + if (cp[1] == '\0') + break; + buf[(*i)++] = ','; + buf[(*i)++] = ' '; + } else if (cp[0] >= ' ') + buf[(*i)++] = cp[0]; + cp++; + } } -static void -sql_append(char **sql, size_t *sz, const char *newstr, int count) +/* + * Return 1 if the string *want occurs in any of the strings + * in the NUL-terminated string list *have, or 0 otherwise. + * If either argument is NULL or empty, assume no filtering + * is desired and return 1. + */ +static int +lstmatch(const char *want, const char *have) { - size_t newsz; - - newsz = 1 < count ? (size_t)count : strlen(newstr); - *sql = mandoc_realloc(*sql, *sz + newsz + 1); - if (1 < count) - memset(*sql + *sz, *newstr, (size_t)count); - else - memcpy(*sql + *sz, newstr, newsz); - *sz += newsz; - (*sql)[*sz] = '\0'; + if (want == NULL || have == NULL || *have == '\0') + return 1; + while (*have != '\0') { + if (strcasestr(have, want) != NULL) + return 1; + have = strchr(have, '\0') + 1; + } + return 0; } /* - * Prepare the search SQL statement. + * Build a list of values taken by the macro im + * in the manual page with big-endian address addr. */ static char * -sql_statement(const struct expr *e) +buildoutput(size_t im, int32_t addr) { - char *sql; - size_t sz; - int needop; + const char *oldoutput, *sep; + char *output, *newoutput, *value; - sql = mandoc_strdup(e->equal ? - "SELECT desc, form, pageid, bits " - "FROM mpages NATURAL JOIN names WHERE " : - "SELECT desc, form, pageid, 0 FROM mpages WHERE "); - sz = strlen(sql); - - for (needop = 0; NULL != e; e = e->next) { - if (e->and) - sql_append(&sql, &sz, " AND ", 1); - else if (needop) - sql_append(&sql, &sz, " OR ", 1); - if (e->open) - sql_append(&sql, &sz, "(", e->open); - sql_append(&sql, &sz, - TYPE_Nd & e->bits - ? (NULL == e->substr - ? "desc REGEXP ?" - : "desc MATCH ?") - : TYPE_Nm == e->bits - ? (NULL == e->substr - ? "pageid IN (SELECT pageid FROM names " - "WHERE name REGEXP ?)" - : e->equal - ? "name = ? " - : "pageid IN (SELECT pageid FROM names " - "WHERE name MATCH ?)") - : (NULL == e->substr - ? "pageid IN (SELECT pageid FROM keys " - "WHERE key REGEXP ? AND bits & ?)" - : "pageid IN (SELECT pageid FROM keys " - "WHERE key MATCH ? AND bits & ?)"), 1); - if (e->close) - sql_append(&sql, &sz, ")", e->close); - needop = 1; + output = NULL; + dbm_macro_bypage(im - 2, addr); + while ((value = dbm_macro_next()) != NULL) { + if (output == NULL) { + oldoutput = ""; + sep = ""; + } else { + oldoutput = output; + sep = " # "; + } + mandoc_asprintf(&newoutput, "%s%s%s", oldoutput, sep, value); + free(output); + output = newoutput; } - - return sql; + return output; } /* * Compile a set of string tokens into an expression. * Tokens in "argv" are assumed to be individual expression atoms (e.g., * "(", "foo=bar", etc.). */ static struct expr * -exprcomp(const struct mansearch *search, int argc, char *argv[]) +exprcomp(const struct mansearch *search, int argc, char *argv[], int *argi) { - uint64_t mask; - int i, toopen, logic, igncase, toclose; - struct expr *first, *prev, *cur, *next; + struct expr *parent, *child; + int needterm, nested; - first = cur = NULL; - logic = igncase = toopen = toclose = 0; - - for (i = 0; i < argc; i++) { - if (0 == strcmp("(", argv[i])) { - if (igncase) - goto fail; - toopen++; - toclose++; + if ((nested = *argi) == argc) + return NULL; + needterm = 1; + parent = child = NULL; + while (*argi < argc) { + if (strcmp(")", argv[*argi]) == 0) { + if (needterm) + warnx("missing term " + "before closing parenthesis"); + needterm = 0; + if (nested) + break; + warnx("ignoring unmatched right parenthesis"); + ++*argi; continue; - } else if (0 == strcmp(")", argv[i])) { - if (toopen || logic || igncase || NULL == cur) - goto fail; - cur->close++; - if (0 > --toclose) - goto fail; + } + if (strcmp("-o", argv[*argi]) == 0) { + if (needterm) { + if (*argi > 0) + warnx("ignoring -o after %s", + argv[*argi - 1]); + else + warnx("ignoring initial -o"); + } + needterm = 1; + ++*argi; continue; - } else if (0 == strcmp("-a", argv[i])) { - if (toopen || logic || igncase || NULL == cur) - goto fail; - logic = 1; + } + needterm = 0; + if (child == NULL) { + child = expr_and(search, argc, argv, argi); continue; - } else if (0 == strcmp("-o", argv[i])) { - if (toopen || logic || igncase || NULL == cur) - goto fail; - logic = 2; - continue; - } else if (0 == strcmp("-i", argv[i])) { - if (igncase) - goto fail; - igncase = 1; - continue; } - next = exprterm(search, argv[i], !igncase); - if (NULL == next) - goto fail; - if (NULL == first) - first = next; - else - cur->next = next; - prev = cur = next; + if (parent == NULL) { + parent = mandoc_calloc(1, sizeof(*parent)); + parent->type = EXPR_OR; + parent->next = NULL; + parent->child = child; + } + child->next = expr_and(search, argc, argv, argi); + child = child->next; + } + if (needterm && *argi) + warnx("ignoring trailing %s", argv[*argi - 1]); + return parent == NULL ? child : parent; +} - /* - * Searching for descriptions must be split out - * because they are stored in the mpages table, - * not in the keys table. - */ +static struct expr * +expr_and(const struct mansearch *search, int argc, char *argv[], int *argi) +{ + struct expr *parent, *child; + int needterm; - for (mask = TYPE_Nm; mask <= TYPE_Nd; mask <<= 1) { - if (mask & cur->bits && ~mask & cur->bits) { - next = mandoc_calloc(1, - sizeof(struct expr)); - memcpy(next, cur, sizeof(struct expr)); - prev->open = 1; - cur->bits = mask; - cur->next = next; - cur = next; - cur->bits &= ~mask; + needterm = 1; + parent = child = NULL; + while (*argi < argc) { + if (strcmp(")", argv[*argi]) == 0) { + if (needterm) + warnx("missing term " + "before closing parenthesis"); + needterm = 0; + break; + } + if (strcmp("-o", argv[*argi]) == 0) + break; + if (strcmp("-a", argv[*argi]) == 0) { + if (needterm) { + if (*argi > 0) + warnx("ignoring -a after %s", + argv[*argi - 1]); + else + warnx("ignoring initial -a"); } + needterm = 1; + ++*argi; + continue; } - prev->and = (1 == logic); - prev->open += toopen; - if (cur != prev) - cur->close = 1; - - toopen = logic = igncase = 0; + if (needterm == 0) + break; + if (child == NULL) { + child = exprterm(search, argc, argv, argi); + if (child != NULL) + needterm = 0; + continue; + } + needterm = 0; + if (parent == NULL) { + parent = mandoc_calloc(1, sizeof(*parent)); + parent->type = EXPR_AND; + parent->next = NULL; + parent->child = child; + } + child->next = exprterm(search, argc, argv, argi); + if (child->next != NULL) { + child = child->next; + needterm = 0; + } } - if ( ! (toopen || logic || igncase || toclose)) - return first; - -fail: - if (NULL != first) - exprfree(first); - return NULL; + if (needterm && *argi) + warnx("ignoring trailing %s", argv[*argi - 1]); + return parent == NULL ? child : parent; } static struct expr * -exprterm(const struct mansearch *search, char *buf, int cs) +exprterm(const struct mansearch *search, int argc, char *argv[], int *argi) { char errbuf[BUFSIZ]; struct expr *e; char *key, *val; uint64_t iterbit; - int i, irc; + int cs, i, irc; - if ('\0' == *buf) - return NULL; + if (strcmp("(", argv[*argi]) == 0) { + ++*argi; + e = exprcomp(search, argc, argv, argi); + if (*argi < argc) { + assert(strcmp(")", argv[*argi]) == 0); + ++*argi; + } else + warnx("unclosed parenthesis"); + return e; + } - e = mandoc_calloc(1, sizeof(struct expr)); + e = mandoc_calloc(1, sizeof(*e)); + e->type = EXPR_TERM; + e->bits = 0; + e->next = NULL; + e->child = NULL; if (search->argmode == ARG_NAME) { e->bits = TYPE_Nm; - e->substr = buf; - e->equal = 1; + e->match.type = DBM_EXACT; + e->match.str = argv[(*argi)++]; return e; } /* * Separate macro keys from search string. - * If needed, request regular expression handling - * by setting e->substr to NULL. + * If needed, request regular expression handling. */ if (search->argmode == ARG_WORD) { e->bits = TYPE_Nm; - e->substr = NULL; + e->match.type = DBM_REGEX; #if HAVE_REWB_BSD - mandoc_asprintf(&val, "[[:<:]]%s[[:>:]]", buf); + mandoc_asprintf(&val, "[[:<:]]%s[[:>:]]", argv[*argi]); #elif HAVE_REWB_SYSV - mandoc_asprintf(&val, "\\<%s\\>", buf); + mandoc_asprintf(&val, "\\<%s\\>", argv[*argi]); #else mandoc_asprintf(&val, - "(^|[^a-zA-Z01-9_])%s([^a-zA-Z01-9_]|$)", buf); + "(^|[^a-zA-Z01-9_])%s([^a-zA-Z01-9_]|$)", argv[*argi]); #endif cs = 0; - } else if ((val = strpbrk(buf, "=~")) == NULL) { + } else if ((val = strpbrk(argv[*argi], "=~")) == NULL) { e->bits = TYPE_Nm | TYPE_Nd; - e->substr = buf; + e->match.type = DBM_SUB; + e->match.str = argv[*argi]; } else { - if (val == buf) + if (val == argv[*argi]) e->bits = TYPE_Nm | TYPE_Nd; - if ('=' == *val) - e->substr = val + 1; + if (*val == '=') { + e->match.type = DBM_SUB; + e->match.str = val + 1; + } else + e->match.type = DBM_REGEX; *val++ = '\0'; - if (NULL != strstr(buf, "arch")) + if (strstr(argv[*argi], "arch") != NULL) cs = 0; } /* Compile regular expressions. */ - if (NULL == e->substr) { - irc = regcomp(&e->regexp, val, + if (e->match.type == DBM_REGEX) { + e->match.re = mandoc_malloc(sizeof(*e->match.re)); + irc = regcomp(e->match.re, val, REG_EXTENDED | REG_NOSUB | (cs ? 0 : REG_ICASE)); + if (irc) { + regerror(irc, e->match.re, errbuf, sizeof(errbuf)); + warnx("regcomp /%s/: %s", val, errbuf); + } if (search->argmode == ARG_WORD) free(val); if (irc) { - regerror(irc, &e->regexp, errbuf, sizeof(errbuf)); - warnx("regcomp: %s", errbuf); + free(e->match.re); free(e); + ++*argi; return NULL; } } - if (e->bits) + if (e->bits) { + ++*argi; return e; + } /* * Parse out all possible fields. * If the field doesn't resolve, bail. */ - while (NULL != (key = strsep(&buf, ","))) { + while (NULL != (key = strsep(&argv[*argi], ","))) { if ('\0' == *key) continue; - for (i = 0, iterbit = 1; - i < mansearch_keymax; - i++, iterbit <<= 1) { - if (0 == strcasecmp(key, - mansearch_keynames[i])) { + for (i = 0, iterbit = 1; i < KEY_MAX; i++, iterbit <<= 1) { + if (0 == strcasecmp(key, mansearch_keynames[i])) { e->bits |= iterbit; break; } } - if (i == mansearch_keymax) { - if (strcasecmp(key, "any")) { - free(e); - return NULL; - } + if (i == KEY_MAX) { + if (strcasecmp(key, "any")) + warnx("treating unknown key " + "\"%s\" as \"any\"", key); e->bits |= ~0ULL; } } + ++*argi; return e; } static void -exprfree(struct expr *p) +exprfree(struct expr *e) { - struct expr *pp; - - while (NULL != p) { - pp = p->next; - free(p); - p = pp; - } + if (e->next != NULL) + exprfree(e->next); + if (e->child != NULL) + exprfree(e->child); + free(e); } Index: stable/11/contrib/mdocml/mansearch.h =================================================================== --- stable/11/contrib/mdocml/mansearch.h (revision 316419) +++ stable/11/contrib/mdocml/mansearch.h (revision 316420) @@ -1,108 +1,115 @@ -/* $Id: mansearch.h,v 1.24 2015/11/07 14:01:16 schwarze Exp $ */ +/* $Id: mansearch.h,v 1.27 2016/08/01 12:31:00 schwarze Exp $ */ /* * Copyright (c) 2012 Kristaps Dzonsons - * Copyright (c) 2013, 2014 Ingo Schwarze + * Copyright (c) 2013, 2014, 2016 Ingo Schwarze * * 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. */ #define MANDOC_DB "mandoc.db" +#define MANDOCDB_MAGIC 0x3a7d0cdb +#define MANDOCDB_VERSION 1 +#define MACRO_MAX 36 +#define KEY_Nd 39 +#define KEY_MAX 40 + #define TYPE_arch 0x0000000000000001ULL #define TYPE_sec 0x0000000000000002ULL #define TYPE_Xr 0x0000000000000004ULL #define TYPE_Ar 0x0000000000000008ULL #define TYPE_Fa 0x0000000000000010ULL #define TYPE_Fl 0x0000000000000020ULL #define TYPE_Dv 0x0000000000000040ULL #define TYPE_Fn 0x0000000000000080ULL #define TYPE_Ic 0x0000000000000100ULL #define TYPE_Pa 0x0000000000000200ULL #define TYPE_Cm 0x0000000000000400ULL #define TYPE_Li 0x0000000000000800ULL #define TYPE_Em 0x0000000000001000ULL #define TYPE_Cd 0x0000000000002000ULL #define TYPE_Va 0x0000000000004000ULL #define TYPE_Ft 0x0000000000008000ULL #define TYPE_Tn 0x0000000000010000ULL #define TYPE_Er 0x0000000000020000ULL #define TYPE_Ev 0x0000000000040000ULL #define TYPE_Sy 0x0000000000080000ULL #define TYPE_Sh 0x0000000000100000ULL #define TYPE_In 0x0000000000200000ULL #define TYPE_Ss 0x0000000000400000ULL #define TYPE_Ox 0x0000000000800000ULL #define TYPE_An 0x0000000001000000ULL #define TYPE_Mt 0x0000000002000000ULL #define TYPE_St 0x0000000004000000ULL #define TYPE_Bx 0x0000000008000000ULL #define TYPE_At 0x0000000010000000ULL #define TYPE_Nx 0x0000000020000000ULL #define TYPE_Fx 0x0000000040000000ULL #define TYPE_Lk 0x0000000080000000ULL #define TYPE_Ms 0x0000000100000000ULL #define TYPE_Bsx 0x0000000200000000ULL #define TYPE_Dx 0x0000000400000000ULL #define TYPE_Rs 0x0000000800000000ULL #define TYPE_Vt 0x0000001000000000ULL #define TYPE_Lb 0x0000002000000000ULL #define TYPE_Nm 0x0000004000000000ULL #define TYPE_Nd 0x0000008000000000ULL #define NAME_SYN 0x0000004000000001ULL #define NAME_FIRST 0x0000004000000004ULL #define NAME_TITLE 0x0000004000000006ULL #define NAME_HEAD 0x0000004000000008ULL #define NAME_FILE 0x0000004000000010ULL #define NAME_MASK 0x000000000000001fULL -#define FORM_CAT 0 /* manual page is preformatted */ -#define FORM_SRC 1 /* format is mdoc(7) or man(7) */ -#define FORM_NONE 4 /* format is unknown */ +enum form { + FORM_SRC = 1, /* Format is mdoc(7) or man(7). */ + FORM_CAT, /* Manual page is preformatted. */ + FORM_NONE /* Format is unknown. */ +}; enum argmode { ARG_FILE = 0, ARG_NAME, ARG_WORD, ARG_EXPR }; struct manpage { char *file; /* to be prefixed by manpath */ char *names; /* a list of names with sections */ char *output; /* user-defined additional output */ size_t ipath; /* number of the manpath */ uint64_t bits; /* name type mask */ int sec; /* section number, 10 means invalid */ - int form; /* 0 == catpage */ + enum form form; }; struct mansearch { const char *arch; /* architecture/NULL */ const char *sec; /* mansection/NULL */ const char *outkey; /* show content of this macro */ enum argmode argmode; /* interpretation of arguments */ int firstmatch; /* first matching database only */ }; struct manpaths; -int mansearch_setup(int); int mansearch(const struct mansearch *cfg, /* options */ const struct manpaths *paths, /* manpaths */ int argc, /* size of argv */ char *argv[], /* search terms */ struct manpage **res, /* results */ size_t *ressz); /* results returned */ void mansearch_free(struct manpage *, size_t); Index: stable/11/contrib/mdocml/mdoc.7 =================================================================== --- stable/11/contrib/mdocml/mdoc.7 (revision 316419) +++ stable/11/contrib/mdocml/mdoc.7 (revision 316420) @@ -1,3235 +1,3252 @@ -.\" $Id: mdoc.7,v 1.257 2015/11/05 12:06:45 schwarze Exp $ +.\" $Id: mdoc.7,v 1.260 2017/01/09 14:10:53 schwarze Exp $ .\" .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons -.\" Copyright (c) 2010, 2011, 2013 Ingo Schwarze +.\" Copyright (c) 2010, 2011, 2013-2017 Ingo Schwarze .\" .\" 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. .\" -.Dd $Mdocdate: November 5 2015 $ +.Dd $Mdocdate: January 9 2017 $ .Dt MDOC 7 .Os .Sh NAME .Nm mdoc .Nd semantic markup language for formatting manual pages .Sh DESCRIPTION The .Nm mdoc language supports authoring of manual pages for the .Xr man 1 utility by allowing semantic annotations of words, phrases, page sections and complete manual pages. Such annotations are used by formatting tools to achieve a uniform presentation across all manuals written in .Nm , and to support hyperlinking if supported by the output medium. .Pp This reference document describes the structure of manual pages and the syntax and usage of the .Nm language. The reference implementation of a parsing and formatting tool is .Xr mandoc 1 ; the .Sx COMPATIBILITY section describes compatibility with other implementations. .Pp In an .Nm document, lines beginning with the control character .Sq \&. are called .Dq macro lines . The first word is the macro name. It consists of two or three letters. Most macro names begin with a capital letter. For a list of available macros, see .Sx MACRO OVERVIEW . The words following the macro name are arguments to the macro, optionally including the names of other, callable macros; see .Sx MACRO SYNTAX for details. .Pp Lines not beginning with the control character are called .Dq text lines . They provide free-form text to be printed; the formatting of the text depends on the respective processing context: .Bd -literal -offset indent \&.Sh Macro lines change control state. Text lines are interpreted within the current state. .Ed .Pp Many aspects of the basic syntax of the .Nm language are based on the .Xr roff 7 language; see the .Em LANGUAGE SYNTAX and .Em MACRO SYNTAX sections in the .Xr roff 7 manual for details, in particular regarding comments, escape sequences, whitespace, and quoting. However, using .Xr roff 7 requests in .Nm documents is discouraged; .Xr mandoc 1 supports some of them merely for backward compatibility. .Sh MANUAL STRUCTURE A well-formed .Nm document consists of a document prologue followed by one or more sections. .Pp The prologue, which consists of the .Sx \&Dd , .Sx \&Dt , and .Sx \&Os macros in that order, is required for every document. .Pp The first section (sections are denoted by .Sx \&Sh ) must be the NAME section, consisting of at least one .Sx \&Nm followed by .Sx \&Nd . .Pp Following that, convention dictates specifying at least the .Em SYNOPSIS and .Em DESCRIPTION sections, although this varies between manual sections. .Pp The following is a well-formed skeleton .Nm file for a utility .Qq progname : .Bd -literal -offset indent \&.Dd $\&Mdocdate$ \&.Dt PROGNAME section \&.Os \&.Sh NAME \&.Nm progname \&.Nd one line about what it does \&.\e\(dq .Sh LIBRARY \&.\e\(dq For sections 2, 3, and 9 only. \&.\e\(dq Not used in OpenBSD. \&.Sh SYNOPSIS \&.Nm progname \&.Op Fl options \&.Ar \&.Sh DESCRIPTION The \&.Nm utility processes files ... \&.\e\(dq .Sh CONTEXT \&.\e\(dq For section 9 functions only. \&.\e\(dq .Sh IMPLEMENTATION NOTES \&.\e\(dq Not used in OpenBSD. \&.\e\(dq .Sh RETURN VALUES \&.\e\(dq For sections 2, 3, and 9 function return values only. \&.\e\(dq .Sh ENVIRONMENT \&.\e\(dq For sections 1, 6, 7, and 8 only. \&.\e\(dq .Sh FILES \&.\e\(dq .Sh EXIT STATUS \&.\e\(dq For sections 1, 6, and 8 only. \&.\e\(dq .Sh EXAMPLES \&.\e\(dq .Sh DIAGNOSTICS \&.\e\(dq For sections 1, 4, 6, 7, 8, and 9 printf/stderr messages only. \&.\e\(dq .Sh ERRORS \&.\e\(dq For sections 2, 3, 4, and 9 errno settings only. \&.\e\(dq .Sh SEE ALSO \&.\e\(dq .Xr foobar 1 \&.\e\(dq .Sh STANDARDS \&.\e\(dq .Sh HISTORY \&.\e\(dq .Sh AUTHORS \&.\e\(dq .Sh CAVEATS \&.\e\(dq .Sh BUGS \&.\e\(dq .Sh SECURITY CONSIDERATIONS \&.\e\(dq Not used in OpenBSD. .Ed .Pp The sections in an .Nm document are conventionally ordered as they appear above. Sections should be composed as follows: .Bl -ohang -offset Ds .It Em NAME The name(s) and a one line description of the documented material. The syntax for this as follows: .Bd -literal -offset indent \&.Nm name0 , \&.Nm name1 , \&.Nm name2 \&.Nd a one line description .Ed .Pp Multiple .Sq \&Nm names should be separated by commas. .Pp The .Sx \&Nm macro(s) must precede the .Sx \&Nd macro. .Pp See .Sx \&Nm and .Sx \&Nd . .It Em LIBRARY The name of the library containing the documented material, which is assumed to be a function in a section 2, 3, or 9 manual. The syntax for this is as follows: .Bd -literal -offset indent \&.Lb libarm .Ed .Pp See .Sx \&Lb . .It Em SYNOPSIS Documents the utility invocation syntax, function call syntax, or device configuration. .Pp For the first, utilities (sections 1, 6, and 8), this is generally structured as follows: .Bd -literal -offset indent \&.Nm bar \&.Op Fl v \&.Op Fl o Ar file \&.Op Ar \&.Nm foo \&.Op Fl v \&.Op Fl o Ar file \&.Op Ar .Ed .Pp Commands should be ordered alphabetically. .Pp For the second, function calls (sections 2, 3, 9): .Bd -literal -offset indent \&.In header.h \&.Vt extern const char *global; \&.Ft "char *" \&.Fn foo "const char *src" \&.Ft "char *" \&.Fn bar "const char *src" .Ed .Pp Ordering of .Sx \&In , .Sx \&Vt , .Sx \&Fn , and .Sx \&Fo macros should follow C header-file conventions. .Pp And for the third, configurations (section 4): .Bd -literal -offset indent \&.Cd \(dqit* at isa? port 0x2e\(dq \&.Cd \(dqit* at isa? port 0x4e\(dq .Ed .Pp Manuals not in these sections generally don't need a .Em SYNOPSIS . .Pp Some macros are displayed differently in the .Em SYNOPSIS section, particularly .Sx \&Nm , .Sx \&Cd , .Sx \&Fd , .Sx \&Fn , .Sx \&Fo , .Sx \&In , .Sx \&Vt , and .Sx \&Ft . All of these macros are output on their own line. If two such dissimilar macros are pairwise invoked (except for .Sx \&Ft before .Sx \&Fo or .Sx \&Fn ) , they are separated by a vertical space, unless in the case of .Sx \&Fo , .Sx \&Fn , and .Sx \&Ft , which are always separated by vertical space. .Pp When text and macros following an .Sx \&Nm macro starting an input line span multiple output lines, all output lines but the first will be indented to align with the text immediately following the .Sx \&Nm macro, up to the next .Sx \&Nm , .Sx \&Sh , or .Sx \&Ss macro or the end of an enclosing block, whichever comes first. .It Em DESCRIPTION This begins with an expansion of the brief, one line description in .Em NAME : .Bd -literal -offset indent The \&.Nm utility does this, that, and the other. .Ed .Pp It usually follows with a breakdown of the options (if documenting a command), such as: .Bd -literal -offset indent The arguments are as follows: \&.Bl \-tag \-width Ds \&.It Fl v Print verbose information. \&.El .Ed .Pp List the options in alphabetical order, uppercase before lowercase for each letter and with no regard to whether an option takes an argument. Put digits in ascending order before all letter options. .Pp Manuals not documenting a command won't include the above fragment. .Pp Since the .Em DESCRIPTION section usually contains most of the text of a manual, longer manuals often use the .Sx \&Ss macro to form subsections. In very long manuals, the .Em DESCRIPTION may be split into multiple sections, each started by an .Sx \&Sh macro followed by a non-standard section name, and each having several subsections, like in the present .Nm manual. .It Em CONTEXT This section lists the contexts in which functions can be called in section 9. The contexts are autoconf, process, or interrupt. .It Em IMPLEMENTATION NOTES Implementation-specific notes should be kept here. This is useful when implementing standard functions that may have side effects or notable algorithmic implications. .It Em RETURN VALUES This section documents the return values of functions in sections 2, 3, and 9. .Pp See .Sx \&Rv . .It Em ENVIRONMENT Lists the environment variables used by the utility, and explains the syntax and semantics of their values. The .Xr environ 7 manual provides examples of typical content and formatting. .Pp See .Sx \&Ev . .It Em FILES Documents files used. It's helpful to document both the file name and a short description of how the file is used (created, modified, etc.). .Pp See .Sx \&Pa . .It Em EXIT STATUS This section documents the command exit status for section 1, 6, and 8 utilities. Historically, this information was described in .Em DIAGNOSTICS , a practise that is now discouraged. .Pp See .Sx \&Ex . .It Em EXAMPLES Example usages. This often contains snippets of well-formed, well-tested invocations. Make sure that examples work properly! .It Em DIAGNOSTICS Documents error messages. In section 4 and 9 manuals, these are usually messages printed by the kernel to the console and to the kernel log. In section 1, 6, 7, and 8, these are usually messages printed by userland programs to the standard error output. .Pp Historically, this section was used in place of .Em EXIT STATUS for manuals in sections 1, 6, and 8; however, this practise is discouraged. .Pp See .Sx \&Bl .Fl diag . .It Em ERRORS Documents .Xr errno 2 settings in sections 2, 3, 4, and 9. .Pp See .Sx \&Er . .It Em SEE ALSO References other manuals with related topics. This section should exist for most manuals. Cross-references should conventionally be ordered first by section, then alphabetically (ignoring case). .Pp References to other documentation concerning the topic of the manual page, for example authoritative books or journal articles, may also be provided in this section. .Pp See .Sx \&Rs and .Sx \&Xr . .It Em STANDARDS References any standards implemented or used. If not adhering to any standards, the .Em HISTORY section should be used instead. .Pp See .Sx \&St . .It Em HISTORY A brief history of the subject, including where it was first implemented, and when it was ported to or reimplemented for the operating system at hand. .It Em AUTHORS Credits to the person or persons who wrote the code and/or documentation. Authors should generally be noted by both name and email address. .Pp See .Sx \&An . .It Em CAVEATS Common misuses and misunderstandings should be explained in this section. .It Em BUGS Known bugs, limitations, and work-arounds should be described in this section. .It Em SECURITY CONSIDERATIONS Documents any security precautions that operators should consider. .El .Sh MACRO OVERVIEW This overview is sorted such that macros of similar purpose are listed together, to help find the best macro for any given purpose. Deprecated macros are not included in the overview, but can be found below in the alphabetical .Sx MACRO REFERENCE . .Ss Document preamble and NAME section macros .Bl -column "Brq, Bro, Brc" description .It Sx \&Dd Ta document date: Cm $\&Mdocdate$ | Ar month day , year .It Sx \&Dt Ta document title: Ar TITLE section Op Ar arch .It Sx \&Os Ta operating system version: Op Ar system Op Ar version .It Sx \&Nm Ta document name (one argument) .It Sx \&Nd Ta document description (one line) .El .Ss Sections and cross references .Bl -column "Brq, Bro, Brc" description .It Sx \&Sh Ta section header (one line) .It Sx \&Ss Ta subsection header (one line) .It Sx \&Sx Ta internal cross reference to a section or subsection .It Sx \&Xr Ta cross reference to another manual page: Ar name section .It Sx \&Pp , \&Lp Ta start a text paragraph (no arguments) .El .Ss Displays and lists .Bl -column "Brq, Bro, Brc" description .It Sx \&Bd , \&Ed Ta display block: .Fl Ar type .Op Fl offset Ar width .Op Fl compact .It Sx \&D1 Ta indented display (one line) .It Sx \&Dl Ta indented literal display (one line) .It Sx \&Ql Ta in-line literal display: Ql text .It Sx \&Bl , \&El Ta list block: .Fl Ar type .Op Fl width Ar val .Op Fl offset Ar val .Op Fl compact .It Sx \&It Ta list item (syntax depends on Fl Ar type ) .It Sx \&Ta Ta table cell separator in Sx \&Bl Fl column No lists .It Sx \&Rs , \&%* , \&Re Ta bibliographic block (references) .El .Ss Spacing control .Bl -column "Brq, Bro, Brc" description .It Sx \&Pf Ta prefix, no following horizontal space (one argument) .It Sx \&Ns Ta roman font, no preceding horizontal space (no arguments) .It Sx \&Ap Ta apostrophe without surrounding whitespace (no arguments) .It Sx \&Sm Ta switch horizontal spacing mode: Op Cm on | off .It Sx \&Bk , \&Ek Ta keep block: Fl words .It Sx \&br Ta force output line break in text mode (no arguments) .It Sx \&sp Ta force vertical space: Op Ar height .El .Ss Semantic markup for command line utilities: .Bl -column "Brq, Bro, Brc" description .It Sx \&Nm Ta start a SYNOPSIS block with the name of a utility .It Sx \&Fl Ta command line options (flags) (>=0 arguments) .It Sx \&Cm Ta command modifier (>0 arguments) .It Sx \&Ar Ta command arguments (>=0 arguments) .It Sx \&Op , \&Oo , \&Oc Ta optional syntax elements (enclosure) .It Sx \&Ic Ta internal or interactive command (>0 arguments) .It Sx \&Ev Ta environmental variable (>0 arguments) .It Sx \&Pa Ta file system path (>=0 arguments) .El .Ss Semantic markup for function libraries: .Bl -column "Brq, Bro, Brc" description .It Sx \&Lb Ta function library (one argument) .It Sx \&In Ta include file (one argument) .It Sx \&Fd Ta other preprocessor directive (>0 arguments) .It Sx \&Ft Ta function type (>0 arguments) .It Sx \&Fo , \&Fc Ta function block: Ar funcname .It Sx \&Fn Ta function name: .Op Ar functype .Ar funcname .Oo .Op Ar argtype .Ar argname .Oc .It Sx \&Fa Ta function argument (>0 arguments) .It Sx \&Vt Ta variable type (>0 arguments) .It Sx \&Va Ta variable name (>0 arguments) .It Sx \&Dv Ta defined variable or preprocessor constant (>0 arguments) .It Sx \&Er Ta error constant (>0 arguments) .It Sx \&Ev Ta environmental variable (>0 arguments) .El .Ss Various semantic markup: .Bl -column "Brq, Bro, Brc" description .It Sx \&An Ta author name (>0 arguments) .It Sx \&Lk Ta hyperlink: Ar uri Op Ar name .It Sx \&Mt Ta Do mailto Dc hyperlink: Ar address .It Sx \&Cd Ta kernel configuration declaration (>0 arguments) .It Sx \&Ad Ta memory address (>0 arguments) .It Sx \&Ms Ta mathematical symbol (>0 arguments) .El .Ss Physical markup .Bl -column "Brq, Bro, Brc" description .It Sx \&Em Ta italic font or underline (emphasis) (>0 arguments) .It Sx \&Sy Ta boldface font (symbolic) (>0 arguments) .It Sx \&Li Ta typewriter font (literal) (>0 arguments) .It Sx \&No Ta return to roman font (normal) (no arguments) .It Sx \&Bf , \&Ef Ta font block: .Op Fl Ar type | Cm \&Em | \&Li | \&Sy .El .Ss Physical enclosures .Bl -column "Brq, Bro, Brc" description .It Sx \&Dq , \&Do , \&Dc Ta enclose in typographic double quotes: Dq text .It Sx \&Qq , \&Qo , \&Qc Ta enclose in typewriter double quotes: Qq text .It Sx \&Sq , \&So , \&Sc Ta enclose in single quotes: Sq text .It Sx \&Pq , \&Po , \&Pc Ta enclose in parentheses: Pq text .It Sx \&Bq , \&Bo , \&Bc Ta enclose in square brackets: Bq text .It Sx \&Brq , \&Bro , \&Brc Ta enclose in curly braces: Brq text .It Sx \&Aq , \&Ao , \&Ac Ta enclose in angle brackets: Aq text .It Sx \&Eo , \&Ec Ta generic enclosure .El .Ss Text production .Bl -column "Brq, Bro, Brc" description .It Sx \&Ex Fl std Ta standard command exit values: Op Ar utility ... .It Sx \&Rv Fl std Ta standard function return values: Op Ar function ... .It Sx \&St Ta reference to a standards document (one argument) .It Sx \&At Ta At .It Sx \&Bx Ta Bx .It Sx \&Bsx Ta Bsx .It Sx \&Nx Ta Nx .It Sx \&Fx Ta Fx .It Sx \&Ox Ta Ox .It Sx \&Dx Ta Dx .El .Sh MACRO REFERENCE This section is a canonical reference of all macros, arranged alphabetically. For the scoping of individual macros, see .Sx MACRO SYNTAX . .Ss \&%A Author name of an .Sx \&Rs block. Multiple authors should each be accorded their own .Sx \%%A line. Author names should be ordered with full or abbreviated forename(s) first, then full surname. .Ss \&%B Book title of an .Sx \&Rs block. This macro may also be used in a non-bibliographic context when referring to book titles. .Ss \&%C Publication city or location of an .Sx \&Rs block. .Ss \&%D Publication date of an .Sx \&Rs block. Recommended formats of arguments are .Ar month day , year or just .Ar year . .Ss \&%I Publisher or issuer name of an .Sx \&Rs block. .Ss \&%J Journal name of an .Sx \&Rs block. .Ss \&%N Issue number (usually for journals) of an .Sx \&Rs block. .Ss \&%O Optional information of an .Sx \&Rs block. .Ss \&%P Book or journal page number of an .Sx \&Rs block. .Ss \&%Q Institutional author (school, government, etc.) of an .Sx \&Rs block. Multiple institutional authors should each be accorded their own .Sx \&%Q line. .Ss \&%R Technical report name of an .Sx \&Rs block. .Ss \&%T Article title of an .Sx \&Rs block. This macro may also be used in a non-bibliographical context when referring to article titles. .Ss \&%U URI of reference document. .Ss \&%V Volume number of an .Sx \&Rs block. .Ss \&Ac Close an .Sx \&Ao block. Does not have any tail arguments. .Ss \&Ad Memory address. Do not use this for postal addresses. .Pp Examples: .Dl \&.Ad [0,$] .Dl \&.Ad 0x00000000 .Ss \&An Author name. Can be used both for the authors of the program, function, or driver documented in the manual, or for the authors of the manual itself. Requires either the name of an author or one of the following arguments: .Pp .Bl -tag -width "-nosplitX" -offset indent -compact .It Fl split Start a new output line before each subsequent invocation of .Sx \&An . .It Fl nosplit The opposite of .Fl split . .El .Pp The default is .Fl nosplit . The effect of selecting either of the .Fl split modes ends at the beginning of the .Em AUTHORS section. In the .Em AUTHORS section, the default is .Fl nosplit for the first author listing and .Fl split for all other author listings. .Pp Examples: .Dl \&.An -nosplit .Dl \&.An Kristaps Dzonsons \&Aq \&Mt kristaps@bsd.lv .Ss \&Ao Begin a block enclosed by angle brackets. Does not have any head arguments. .Pp Examples: .Dl \&.Fl -key= \&Ns \&Ao \&Ar val \&Ac .Pp See also .Sx \&Aq . .Ss \&Ap Inserts an apostrophe without any surrounding whitespace. This is generally used as a grammatical device when referring to the verb form of a function. .Pp Examples: .Dl \&.Fn execve \&Ap d .Ss \&Aq Encloses its arguments in angle brackets. .Pp Examples: .Dl \&.Fl -key= \&Ns \&Aq \&Ar val .Pp .Em Remarks : this macro is often abused for rendering URIs, which should instead use .Sx \&Lk or .Sx \&Mt , or to note pre-processor .Dq Li #include statements, which should use .Sx \&In . .Pp See also .Sx \&Ao . .Ss \&Ar Command arguments. If an argument is not provided, the string .Dq file ...\& is used as a default. .Pp Examples: .Dl ".Fl o Ar file" .Dl ".Ar" .Dl ".Ar arg1 , arg2 ." .Pp The arguments to the .Sx \&Ar macro are names and placeholders for command arguments; for fixed strings to be passed verbatim as arguments, use .Sx \&Fl or .Sx \&Cm . .Ss \&At Formats an .At version. Accepts one optional argument: .Pp .Bl -tag -width "v[1-7] | 32vX" -offset indent -compact .It Cm v[1-7] | 32v A version of .At . .It Cm III .At III . .It Cm V[.[1-4]]? A version of .At V . .El .Pp Note that these arguments do not begin with a hyphen. .Pp Examples: .Dl \&.At .Dl \&.At III .Dl \&.At V.1 .Pp See also .Sx \&Bsx , .Sx \&Bx , .Sx \&Dx , .Sx \&Fx , .Sx \&Nx , and .Sx \&Ox . .Ss \&Bc Close a .Sx \&Bo block. Does not have any tail arguments. .Ss \&Bd Begin a display block. Its syntax is as follows: .Bd -ragged -offset indent .Pf \. Sx \&Bd .Fl Ns Ar type .Op Fl offset Ar width .Op Fl compact .Ed .Pp Display blocks are used to select a different indentation and justification than the one used by the surrounding text. They may contain both macro lines and text lines. By default, a display block is preceded by a vertical space. .Pp The .Ar type must be one of the following: .Bl -tag -width 13n -offset indent .It Fl centered Produce one output line from each input line, and center-justify each line. Using this display type is not recommended; many .Nm implementations render it poorly. .It Fl filled Change the positions of line breaks to fill each line, and left- and right-justify the resulting block. .It Fl literal Produce one output line from each input line, and do not justify the block at all. Preserve white space as it appears in the input. Always use a constant-width font. Use this for displaying source code. .It Fl ragged Change the positions of line breaks to fill each line, and left-justify the resulting block. .It Fl unfilled The same as .Fl literal , but using the same font as for normal text, which is a variable width font if supported by the output device. .El .Pp The .Ar type must be provided first. Additional arguments may follow: .Bl -tag -width 13n -offset indent .It Fl offset Ar width Indent the display by the .Ar width , which may be one of the following: .Bl -item .It One of the pre-defined strings .Cm indent , the width of a standard indentation (six constant width characters); .Cm indent-two , twice .Cm indent ; .Cm left , which has no effect; .Cm right , which justifies to the right margin; or .Cm center , which aligns around an imagined center axis. .It A macro invocation, which selects a predefined width associated with that macro. The most popular is the imaginary macro .Ar \&Ds , which resolves to .Sy 6n . .It A scaling width as described in .Xr roff 7 . .It An arbitrary string, which indents by the length of this string. .El .Pp When the argument is missing, .Fl offset is ignored. .It Fl compact Do not assert vertical space before the display. .El .Pp Examples: .Bd -literal -offset indent \&.Bd \-literal \-offset indent \-compact Hello world. \&.Ed .Ed .Pp See also .Sx \&D1 and .Sx \&Dl . .Ss \&Bf Change the font mode for a scoped block of text. Its syntax is as follows: .Bd -ragged -offset indent .Pf \. Sx \&Bf .Oo .Fl emphasis | literal | symbolic | .Cm \&Em | \&Li | \&Sy .Oc .Ed .Pp The .Fl emphasis and .Cm \&Em argument are equivalent, as are .Fl symbolic and .Cm \&Sy , and .Fl literal and .Cm \&Li . Without an argument, this macro does nothing. The font mode continues until broken by a new font mode in a nested scope or .Sx \&Ef is encountered. .Pp See also .Sx \&Li , .Sx \&Ef , .Sx \&Em , and .Sx \&Sy . .Ss \&Bk For each macro, keep its output together on the same output line, until the end of the macro or the end of the input line is reached, whichever comes first. Line breaks in text lines are unaffected. The syntax is as follows: .Pp .D1 Pf \. Sx \&Bk Fl words .Pp The .Fl words argument is required; additional arguments are ignored. .Pp The following example will not break within each .Sx \&Op macro line: .Bd -literal -offset indent \&.Bk \-words \&.Op Fl f Ar flags \&.Op Fl o Ar output \&.Ek .Ed .Pp Be careful in using over-long lines within a keep block! Doing so will clobber the right margin. .Ss \&Bl Begin a list. Lists consist of items specified using the .Sx \&It macro, containing a head or a body or both. The list syntax is as follows: .Bd -ragged -offset indent .Pf \. Sx \&Bl .Fl Ns Ar type .Op Fl width Ar val .Op Fl offset Ar val .Op Fl compact .Op HEAD ... .Ed .Pp The list .Ar type is mandatory and must be specified first. The .Fl width and .Fl offset arguments accept macro names as described for .Sx \&Bd .Fl offset , scaling widths as described in .Xr roff 7 , or use the length of the given string. The .Fl offset is a global indentation for the whole list, affecting both item heads and bodies. For those list types supporting it, the .Fl width argument requests an additional indentation of item bodies, to be added to the .Fl offset . Unless the .Fl compact argument is specified, list entries are separated by vertical space. .Pp A list must specify one of the following list types: .Bl -tag -width 12n -offset indent .It Fl bullet No item heads can be specified, but a bullet will be printed at the head of each item. Item bodies start on the same output line as the bullet and are indented according to the .Fl width argument. .It Fl column A columnated list. The .Fl width argument has no effect; instead, each argument specifies the width of one column, using either the scaling width syntax described in .Xr roff 7 or the string length of the argument. If the first line of the body of a .Fl column list is not an .Sx \&It macro line, .Sx \&It contexts spanning one input line each are implied until an .Sx \&It macro line is encountered, at which point items start being interpreted as described in the .Sx \&It documentation. .It Fl dash Like .Fl bullet , except that dashes are used in place of bullets. .It Fl diag Like .Fl inset , except that item heads are not parsed for macro invocations. Most often used in the .Em DIAGNOSTICS section with error constants in the item heads. .It Fl enum A numbered list. No item heads can be specified. Formatted like .Fl bullet , except that cardinal numbers are used in place of bullets, starting at 1. .It Fl hang Like .Fl tag , except that the first lines of item bodies are not indented, but follow the item heads like in .Fl inset lists. .It Fl hyphen Synonym for .Fl dash . .It Fl inset Item bodies follow items heads on the same line, using normal inter-word spacing. Bodies are not indented, and the .Fl width argument is ignored. .It Fl item No item heads can be specified, and none are printed. Bodies are not indented, and the .Fl width argument is ignored. .It Fl ohang Item bodies start on the line following item heads and are not indented. The .Fl width argument is ignored. .It Fl tag Item bodies are indented according to the .Fl width argument. When an item head fits inside the indentation, the item body follows this head on the same output line. Otherwise, the body starts on the output line following the head. .El .Pp Lists may be nested within lists and displays. Nesting of .Fl column and .Fl enum lists may not be portable. .Pp See also .Sx \&El and .Sx \&It . .Ss \&Bo Begin a block enclosed by square brackets. Does not have any head arguments. .Pp Examples: .Bd -literal -offset indent -compact \&.Bo 1 , \&.Dv BUFSIZ \&Bc .Ed .Pp See also .Sx \&Bq . .Ss \&Bq Encloses its arguments in square brackets. .Pp Examples: .Dl \&.Bq 1 , \&Dv BUFSIZ .Pp .Em Remarks : this macro is sometimes abused to emulate optional arguments for commands; the correct macros to use for this purpose are .Sx \&Op , .Sx \&Oo , and .Sx \&Oc . .Pp See also .Sx \&Bo . .Ss \&Brc Close a .Sx \&Bro block. Does not have any tail arguments. .Ss \&Bro Begin a block enclosed by curly braces. Does not have any head arguments. .Pp Examples: .Bd -literal -offset indent -compact \&.Bro 1 , ... , \&.Va n \&Brc .Ed .Pp See also .Sx \&Brq . .Ss \&Brq Encloses its arguments in curly braces. .Pp Examples: .Dl \&.Brq 1 , ... , \&Va n .Pp See also .Sx \&Bro . .Ss \&Bsx Format the .Bsx version provided as an argument, or a default value if no argument is provided. .Pp Examples: .Dl \&.Bsx 1.0 .Dl \&.Bsx .Pp See also .Sx \&At , .Sx \&Bx , .Sx \&Dx , .Sx \&Fx , .Sx \&Nx , and .Sx \&Ox . .Ss \&Bt Supported only for compatibility, do not use this in new manuals. Prints .Dq is currently in beta test. .Ss \&Bx Format the .Bx version provided as an argument, or a default value if no argument is provided. .Pp Examples: .Dl \&.Bx 4.3 Tahoe .Dl \&.Bx 4.4 .Dl \&.Bx .Pp See also .Sx \&At , .Sx \&Bsx , .Sx \&Dx , .Sx \&Fx , .Sx \&Nx , and .Sx \&Ox . .Ss \&Cd Kernel configuration declaration. This denotes strings accepted by .Xr config 8 . It is most often used in section 4 manual pages. .Pp Examples: .Dl \&.Cd device le0 at scode? .Pp .Em Remarks : this macro is commonly abused by using quoted literals to retain whitespace and align consecutive .Sx \&Cd declarations. This practise is discouraged. .Ss \&Cm Command modifiers. Typically used for fixed strings passed as arguments, unless .Sx \&Fl is more appropriate. Also useful when specifying configuration options or keys. .Pp Examples: .Dl ".Nm mt Fl f Ar device Cm rewind" .Dl ".Nm ps Fl o Cm pid , Ns Cm command" .Dl ".Nm dd Cm if= Ns Ar file1 Cm of= Ns Ar file2" .Dl ".Cm IdentityFile Pa ~/.ssh/id_rsa" .Dl ".Cm LogLevel Dv DEBUG" .Ss \&D1 One-line indented display. This is formatted by the default rules and is useful for simple indented statements. It is followed by a newline. .Pp Examples: .Dl \&.D1 \&Fl abcdefgh .Pp See also .Sx \&Bd and .Sx \&Dl . .Ss \&Db This macro is obsolete. No replacement is needed. It is ignored by .Xr mandoc 1 and groff including its arguments. It was formerly used to toggle a debugging mode. .Ss \&Dc Close a .Sx \&Do block. Does not have any tail arguments. .Ss \&Dd Document date for display in the page footer. This is the mandatory first macro of any .Nm manual. Its syntax is as follows: .Pp .D1 Pf \. Sx \&Dd Ar month day , year .Pp The .Ar month is the full English month name, the .Ar day is an optionally zero-padded numeral, and the .Ar year is the full four-digit year. .Pp Other arguments are not portable; the .Xr mandoc 1 utility handles them as follows: .Bl -dash -offset 3n -compact .It To have the date automatically filled in by the .Ox version of .Xr cvs 1 , the special string .Dq $\&Mdocdate$ can be given as an argument. .It The traditional, purely numeric .Xr man 7 format .Ar year Ns \(en Ns Ar month Ns \(en Ns Ar day is accepted, too. .It If a date string cannot be parsed, it is used verbatim. .It If no date string is given, the current date is used. .El .Pp Examples: .Dl \&.Dd $\&Mdocdate$ .Dl \&.Dd $\&Mdocdate: July 21 2007$ .Dl \&.Dd July 21, 2007 .Pp See also .Sx \&Dt and .Sx \&Os . .Ss \&Dl One-line indented display. This is formatted as literal text and is useful for commands and invocations. It is followed by a newline. .Pp Examples: .Dl \&.Dl % mandoc mdoc.7 \e(ba less .Pp See also .Sx \&Ql , .Sx \&Bd .Fl literal , and .Sx \&D1 . .Ss \&Do Begin a block enclosed by double quotes. Does not have any head arguments. .Pp Examples: .Bd -literal -offset indent -compact \&.Do April is the cruellest month \&.Dc \e(em T.S. Eliot .Ed .Pp See also .Sx \&Dq . .Ss \&Dq Encloses its arguments in .Dq typographic double-quotes. .Pp Examples: .Bd -literal -offset indent -compact \&.Dq April is the cruellest month \e(em T.S. Eliot .Ed .Pp See also .Sx \&Qq , .Sx \&Sq , and .Sx \&Do . .Ss \&Dt Document title for display in the page header. This is the mandatory second macro of any .Nm file. Its syntax is as follows: .Bd -ragged -offset indent .Pf \. Sx \&Dt .Ar TITLE .Ar section .Op Ar arch .Ed .Pp Its arguments are as follows: .Bl -tag -width section -offset 2n .It Ar TITLE The document's title (name), defaulting to .Dq UNTITLED if unspecified. To achieve a uniform appearance of page header lines, it should by convention be all caps. .It Ar section The manual section. This may be one of .Cm 1 .Pq General Commands , .Cm 2 .Pq System Calls , .Cm 3 .Pq Library Functions , .Cm 3p .Pq Perl Library , .Cm 4 .Pq Device Drivers , .Cm 5 .Pq File Formats , .Cm 6 .Pq Games , .Cm 7 .Pq Miscellaneous Information , .Cm 8 .Pq System Manager's Manual , or .Cm 9 .Pq Kernel Developer's Manual . It should correspond to the manual's filename suffix and defaults to the empty string if unspecified. .It Ar arch This specifies the machine architecture a manual page applies to, where relevant, for example .Cm alpha , .Cm amd64 , .Cm i386 , or .Cm sparc64 . The list of valid architectures varies by operating system. .El .Pp Examples: .Dl \&.Dt FOO 1 .Dl \&.Dt FOO 9 i386 .Pp See also .Sx \&Dd and .Sx \&Os . .Ss \&Dv Defined variables such as preprocessor constants, constant symbols, enumeration values, and so on. .Pp Examples: .Dl \&.Dv NULL .Dl \&.Dv BUFSIZ .Dl \&.Dv STDOUT_FILENO .Pp See also .Sx \&Er and .Sx \&Ev for special-purpose constants, .Sx \&Va for variable symbols, and .Sx \&Fd for listing preprocessor variable definitions in the .Em SYNOPSIS . .Ss \&Dx Format the .Dx version provided as an argument, or a default value if no argument is provided. .Pp Examples: .Dl \&.Dx 2.4.1 .Dl \&.Dx .Pp See also .Sx \&At , .Sx \&Bsx , .Sx \&Bx , .Sx \&Fx , .Sx \&Nx , and .Sx \&Ox . .Ss \&Ec Close a scope started by .Sx \&Eo . Its syntax is as follows: .Pp .D1 Pf \. Sx \&Ec Op Ar TERM .Pp The .Ar TERM argument is used as the enclosure tail, for example, specifying \e(rq will emulate .Sx \&Dc . .Ss \&Ed End a display context started by .Sx \&Bd . .Ss \&Ef End a font mode context started by .Sx \&Bf . .Ss \&Ek End a keep context started by .Sx \&Bk . .Ss \&El End a list context started by .Sx \&Bl . .Pp See also .Sx \&Bl and .Sx \&It . .Ss \&Em Request an italic font. If the output device does not provide that, underline. .Pp This is most often used for stress emphasis (not to be confused with importance, see .Sx \&Sy ) . In the rare cases where none of the semantic markup macros fit, it can also be used for technical terms and placeholders, except that for syntax elements, .Sx \&Sy and .Sx \&Ar are preferred, respectively. .Pp Examples: .Bd -literal -compact -offset indent Selected lines are those \&.Em not matching any of the specified patterns. Some of the functions use a \&.Em hold space to save the pattern space for subsequent retrieval. .Ed .Pp See also .Sx \&Bf , .Sx \&Li , .Sx \&No , and .Sx \&Sy . .Ss \&En This macro is obsolete. Use .Sx \&Eo or any of the other enclosure macros. .Pp It encloses its argument in the delimiters specified by the last .Sx \&Es macro. .Ss \&Eo An arbitrary enclosure. Its syntax is as follows: .Pp .D1 Pf \. Sx \&Eo Op Ar TERM .Pp The .Ar TERM argument is used as the enclosure head, for example, specifying \e(lq will emulate .Sx \&Do . .Ss \&Er Error constants for definitions of the .Va errno libc global variable. This is most often used in section 2 and 3 manual pages. .Pp Examples: .Dl \&.Er EPERM .Dl \&.Er ENOENT .Pp See also .Sx \&Dv for general constants. .Ss \&Es This macro is obsolete. Use .Sx \&Eo or any of the other enclosure macros. .Pp It takes two arguments, defining the delimiters to be used by subsequent .Sx \&En macros. .Ss \&Ev Environmental variables such as those specified in .Xr environ 7 . .Pp Examples: .Dl \&.Ev DISPLAY .Dl \&.Ev PATH .Pp See also .Sx \&Dv for general constants. .Ss \&Ex Insert a standard sentence regarding command exit values of 0 on success and >0 on failure. This is most often used in section 1, 6, and 8 manual pages. Its syntax is as follows: .Pp .D1 Pf \. Sx \&Ex Fl std Op Ar utility ... .Pp If .Ar utility is not specified, the document's name set by .Sx \&Nm is used. Multiple .Ar utility arguments are treated as separate utilities. .Pp See also .Sx \&Rv . .Ss \&Fa Function argument or parameter. Its syntax is as follows: .Bd -ragged -offset indent .Pf \. Sx \&Fa .Qo .Op Ar argtype .Op Ar argname .Qc Ar \&... .Ed .Pp Each argument may be a name and a type (recommended for the .Em SYNOPSIS section), a name alone (for function invocations), or a type alone (for function prototypes). If both a type and a name are given or if the type consists of multiple words, all words belonging to the same function argument have to be given in a single argument to the .Sx \&Fa macro. .Pp This macro is also used to specify the field name of a structure. .Pp Most often, the .Sx \&Fa macro is used in the .Em SYNOPSIS within .Sx \&Fo blocks when documenting multi-line function prototypes. If invoked with multiple arguments, the arguments are separated by a comma. Furthermore, if the following macro is another .Sx \&Fa , the last argument will also have a trailing comma. .Pp Examples: .Dl \&.Fa \(dqconst char *p\(dq .Dl \&.Fa \(dqint a\(dq \(dqint b\(dq \(dqint c\(dq .Dl \&.Fa \(dqchar *\(dq size_t .Pp See also .Sx \&Fo . .Ss \&Fc End a function context started by .Sx \&Fo . .Ss \&Fd Preprocessor directive, in particular for listing it in the .Em SYNOPSIS . Historically, it was also used to document include files. The latter usage has been deprecated in favour of .Sx \&In . .Pp Its syntax is as follows: .Bd -ragged -offset indent .Pf \. Sx \&Fd .Li # Ns Ar directive .Op Ar argument ... .Ed .Pp Examples: .Dl \&.Fd #define sa_handler __sigaction_u.__sa_handler .Dl \&.Fd #define SIO_MAXNFDS .Dl \&.Fd #ifdef FS_DEBUG .Dl \&.Ft void .Dl \&.Fn dbg_open \(dqconst char *\(dq .Dl \&.Fd #endif .Pp See also .Sx MANUAL STRUCTURE , .Sx \&In , and .Sx \&Dv . .Ss \&Fl Command-line flag or option. Used when listing arguments to command-line utilities. Prints a fixed-width hyphen .Sq \- directly followed by each argument. If no arguments are provided, a hyphen is printed followed by a space. If the argument is a macro, a hyphen is prefixed to the subsequent macro output. .Pp Examples: .Dl ".Fl R Op Fl H | L | P" .Dl ".Op Fl 1AaCcdFfgHhikLlmnopqRrSsTtux" .Dl ".Fl type Cm d Fl name Pa CVS" .Dl ".Fl Ar signal_number" .Dl ".Fl o Fl" .Pp See also .Sx \&Cm . .Ss \&Fn A function name. Its syntax is as follows: .Bd -ragged -offset indent .Pf . Sx \&Fn .Op Ar functype .Ar funcname .Op Oo Ar argtype Oc Ar argname .Ed .Pp Function arguments are surrounded in parenthesis and are delimited by commas. If no arguments are specified, blank parenthesis are output. In the .Em SYNOPSIS section, this macro starts a new output line, and a blank line is automatically inserted between function definitions. .Pp Examples: .Dl \&.Fn \(dqint funcname\(dq \(dqint arg0\(dq \(dqint arg1\(dq .Dl \&.Fn funcname \(dqint arg0\(dq .Dl \&.Fn funcname arg0 .Pp .Bd -literal -offset indent -compact \&.Ft functype \&.Fn funcname .Ed .Pp When referring to a function documented in another manual page, use .Sx \&Xr instead. See also .Sx MANUAL STRUCTURE , .Sx \&Fo , and .Sx \&Ft . .Ss \&Fo Begin a function block. This is a multi-line version of .Sx \&Fn . Its syntax is as follows: .Pp .D1 Pf \. Sx \&Fo Ar funcname .Pp Invocations usually occur in the following context: .Bd -ragged -offset indent .Pf \. Sx \&Ft Ar functype .br .Pf \. Sx \&Fo Ar funcname .br .Pf \. Sx \&Fa Qq Ar argtype Ar argname .br \&.\.\. .br .Pf \. Sx \&Fc .Ed .Pp A .Sx \&Fo scope is closed by .Sx \&Fc . .Pp See also .Sx MANUAL STRUCTURE , .Sx \&Fa , .Sx \&Fc , and .Sx \&Ft . .Ss \&Fr This macro is obsolete. No replacement markup is needed. .Pp It was used to show numerical function return values in an italic font. .Ss \&Ft A function type. Its syntax is as follows: .Pp .D1 Pf \. Sx \&Ft Ar functype .Pp In the .Em SYNOPSIS section, a new output line is started after this macro. .Pp Examples: .Dl \&.Ft int .Bd -literal -offset indent -compact \&.Ft functype \&.Fn funcname .Ed .Pp See also .Sx MANUAL STRUCTURE , .Sx \&Fn , and .Sx \&Fo . .Ss \&Fx Format the .Fx version provided as an argument, or a default value if no argument is provided. .Pp Examples: .Dl \&.Fx 7.1 .Dl \&.Fx .Pp See also .Sx \&At , .Sx \&Bsx , .Sx \&Bx , .Sx \&Dx , .Sx \&Nx , and .Sx \&Ox . .Ss \&Hf This macro is not implemented in .Xr mandoc 1 . .Pp It was used to include the contents of a (header) file literally. The syntax was: .Pp .Dl Pf . Sx \&Hf Ar filename .Ss \&Ic Designate an internal or interactive command. This is similar to .Sx \&Cm but used for instructions rather than values. .Pp Examples: .Dl \&.Ic :wq .Dl \&.Ic hash .Dl \&.Ic alias .Pp Note that using .Sx \&Bd Fl literal or .Sx \&D1 is preferred for displaying code; the .Sx \&Ic macro is used when referring to specific instructions. .Ss \&In The name of an include file. This macro is most often used in section 2, 3, and 9 manual pages. .Pp When invoked as the first macro on an input line in the .Em SYNOPSIS section, the argument is displayed in angle brackets and preceded by .Qq #include , and a blank line is inserted in front if there is a preceding function declaration. In other sections, it only encloses its argument in angle brackets and causes no line break. .Pp Examples: .Dl \&.In sys/types.h .Pp See also .Sx MANUAL STRUCTURE . .Ss \&It A list item. The syntax of this macro depends on the list type. .Pp Lists of type .Fl hang , .Fl ohang , .Fl inset , and .Fl diag have the following syntax: .Pp .D1 Pf \. Sx \&It Ar args .Pp Lists of type .Fl bullet , .Fl dash , .Fl enum , .Fl hyphen and .Fl item have the following syntax: .Pp .D1 Pf \. Sx \&It .Pp with subsequent lines interpreted within the scope of the .Sx \&It until either a closing .Sx \&El or another .Sx \&It . .Pp The .Fl tag list has the following syntax: .Pp .D1 Pf \. Sx \&It Op Cm args .Pp Subsequent lines are interpreted as with .Fl bullet and family. The line arguments correspond to the list's left-hand side; body arguments correspond to the list's contents. .Pp The .Fl column list is the most complicated. Its syntax is as follows: .Pp -.D1 Pf \. Sx \&It Ar cell Op Ar cell ... .D1 Pf \. Sx \&It Ar cell Op Sx \&Ta Ar cell ... +.D1 Pf \. Sx \&It Ar cell Op Ar cell ... .Pp The arguments consist of one or more lines of text and macros representing a complete table line. -Cells within the line are delimited by tabs or by the special +Cells within the line are delimited by the special .Sx \&Ta -block macro. +block macro or by literal tab characters. +.Pp +Using literal tabs is strongly discouraged because they are very +hard to use correctly and +.Nm +code using them is very hard to read. +In particular, a blank character is syntactically significant +before and after the literal tab character. +If a word precedes or follows the tab without an intervening blank, +that word is never interpreted as a macro call, but always output +literally. +.Pp The tab cell delimiter may only be used within the .Sx \&It line itself; on following lines, only the .Sx \&Ta macro can be used to delimit cells, and .Sx \&Ta is only recognised as a macro when called by other macros, not as the first macro on a line. .Pp Note that quoted strings may span tab-delimited cells on an .Sx \&It line. For example, .Pp -.Dl .It \(dqcol1 ; col2 ;\(dq \&; +.Dl .It \(dqcol1 ,\& col2 ,\(dq \&; .Pp -will preserve the semicolon whitespace except for the last. +will preserve the whitespace before both commas, +but not the whitespace before the semicolon. .Pp See also .Sx \&Bl . .Ss \&Lb Specify a library. The syntax is as follows: .Pp .D1 Pf \. Sx \&Lb Ar library .Pp The .Ar library parameter may be a system library, such as .Cm libz or .Cm libpam , in which case a small library description is printed next to the linker invocation; or a custom library, in which case the library name is printed in quotes. This is most commonly used in the .Em SYNOPSIS section as described in .Sx MANUAL STRUCTURE . .Pp Examples: .Dl \&.Lb libz .Dl \&.Lb libmandoc .Ss \&Li Denotes text that should be in a .Li literal font mode. Note that this is a presentation term and should not be used for stylistically decorating technical terms. .Pp On terminal output devices, this is often indistinguishable from normal text. .Pp See also .Sx \&Bf , .Sx \&Em , .Sx \&No , and .Sx \&Sy . .Ss \&Lk Format a hyperlink. Its syntax is as follows: .Pp .D1 Pf \. Sx \&Lk Ar uri Op Ar name .Pp Examples: .Dl \&.Lk http://bsd.lv \(dqThe BSD.lv Project\(dq .Dl \&.Lk http://bsd.lv .Pp See also .Sx \&Mt . .Ss \&Lp Synonym for .Sx \&Pp . .Ss \&Ms Display a mathematical symbol. Its syntax is as follows: .Pp .D1 Pf \. Sx \&Ms Ar symbol .Pp Examples: .Dl \&.Ms sigma .Dl \&.Ms aleph .Ss \&Mt Format a .Dq mailto: hyperlink. Its syntax is as follows: .Pp .D1 Pf \. Sx \&Mt Ar address .Pp Examples: .Dl \&.Mt discuss@manpages.bsd.lv .Dl \&.An Kristaps Dzonsons \&Aq \&Mt kristaps@bsd.lv .Ss \&Nd A one line description of the manual's content. This is the mandatory last macro of the .Em NAME section and not appropriate for other sections. .Pp Examples: .Dl Pf . Sx \&Nd mdoc language reference .Dl Pf . Sx \&Nd format and display UNIX manuals .Pp The .Sx \&Nd macro technically accepts child macros and terminates with a subsequent .Sx \&Sh invocation. Do not assume this behaviour: some .Xr whatis 1 database generators are not smart enough to parse more than the line arguments and will display macros verbatim. .Pp See also .Sx \&Nm . .Ss \&Nm The name of the manual page, or \(em in particular in section 1, 6, and 8 pages \(em of an additional command or feature documented in the manual page. When first invoked, the .Sx \&Nm macro expects a single argument, the name of the manual page. Usually, the first invocation happens in the .Em NAME section of the page. The specified name will be remembered and used whenever the macro is called again without arguments later in the page. The .Sx \&Nm macro uses .Sx Block full-implicit semantics when invoked as the first macro on an input line in the .Em SYNOPSIS section; otherwise, it uses ordinary .Sx In-line semantics. .Pp Examples: .Bd -literal -offset indent \&.Sh SYNOPSIS \&.Nm cat \&.Op Fl benstuv \&.Op Ar .Ed .Pp In the .Em SYNOPSIS of section 2, 3 and 9 manual pages, use the .Sx \&Fn macro rather than .Sx \&Nm to mark up the name of the manual page. .Ss \&No Normal text. Closes the scope of any preceding in-line macro. When used after physical formatting macros like .Sx \&Em or .Sx \&Sy , switches back to the standard font face and weight. Can also be used to embed plain text strings in macro lines using semantic annotation macros. .Pp Examples: .Dl ".Em italic , Sy bold , No and roman" .Pp .Bd -literal -offset indent -compact \&.Sm off \&.Cm :C No / Ar pattern No / Ar replacement No / \&.Sm on .Ed .Pp See also .Sx \&Em , .Sx \&Li , and .Sx \&Sy . .Ss \&Ns Suppress a space between the output of the preceding macro and the following text or macro. Following invocation, input is interpreted as normal text just like after an .Sx \&No macro. .Pp This has no effect when invoked at the start of a macro line. .Pp Examples: .Dl ".Ar name Ns = Ns Ar value" .Dl ".Cm :M Ns Ar pattern" .Dl ".Fl o Ns Ar output" .Pp See also .Sx \&No and .Sx \&Sm . .Ss \&Nx Format the .Nx version provided as an argument, or a default value if no argument is provided. .Pp Examples: .Dl \&.Nx 5.01 .Dl \&.Nx .Pp See also .Sx \&At , .Sx \&Bsx , .Sx \&Bx , .Sx \&Dx , .Sx \&Fx , and .Sx \&Ox . .Ss \&Oc Close multi-line .Sx \&Oo context. .Ss \&Oo Multi-line version of .Sx \&Op . .Pp Examples: .Bd -literal -offset indent -compact \&.Oo \&.Op Fl flag Ns Ar value \&.Oc .Ed .Ss \&Op Optional part of a command line. Prints the argument(s) in brackets. This is most often used in the .Em SYNOPSIS section of section 1 and 8 manual pages. .Pp Examples: .Dl \&.Op \&Fl a \&Ar b .Dl \&.Op \&Ar a | b .Pp See also .Sx \&Oo . .Ss \&Os Operating system version for display in the page footer. This is the mandatory third macro of any .Nm file. Its syntax is as follows: .Pp .D1 Pf \. Sx \&Os Op Ar system Op Ar version .Pp The optional .Ar system parameter specifies the relevant operating system or environment. It is suggested to leave it unspecified, in which case .Xr mandoc 1 uses its .Fl Ios argument or, if that isn't specified either, .Fa sysname and .Fa release as returned by .Xr uname 3 . .Pp Examples: .Dl \&.Os .Dl \&.Os KTH/CSC/TCS .Dl \&.Os BSD 4.3 .Pp See also .Sx \&Dd and .Sx \&Dt . .Ss \&Ot This macro is obsolete. Use .Sx \&Ft instead; with .Xr mandoc 1 , both have the same effect. .Pp Historical .Nm packages described it as .Dq "old function type (FORTRAN)" . .Ss \&Ox Format the .Ox version provided as an argument, or a default value if no argument is provided. .Pp Examples: .Dl \&.Ox 4.5 .Dl \&.Ox .Pp See also .Sx \&At , .Sx \&Bsx , .Sx \&Bx , .Sx \&Dx , .Sx \&Fx , and .Sx \&Nx . .Ss \&Pa An absolute or relative file system path, or a file or directory name. If an argument is not provided, the character .Sq \(ti is used as a default. .Pp Examples: .Dl \&.Pa /usr/bin/mandoc .Dl \&.Pa /usr/share/man/man7/mdoc.7 .Pp See also .Sx \&Lk . .Ss \&Pc Close parenthesised context opened by .Sx \&Po . .Ss \&Pf Removes the space between its argument and the following macro. Its syntax is as follows: .Pp .D1 .Pf Ar prefix macro arguments ... .Pp This is equivalent to: .Pp .D1 .No \e& Ns Ar prefix No \&Ns Ar macro arguments ... .Pp The .Ar prefix argument is not parsed for macro names or delimiters, but used verbatim as if it were escaped. .Pp Examples: .Dl ".Pf $ Ar variable_name" .Dl ".Pf . Ar macro_name" .Dl ".Pf 0x Ar hex_digits" .Pp See also .Sx \&Ns and .Sx \&Sm . .Ss \&Po Multi-line version of .Sx \&Pq . .Ss \&Pp Break a paragraph. This will assert vertical space between prior and subsequent macros and/or text. .Pp Paragraph breaks are not needed before or after .Sx \&Sh or .Sx \&Ss macros or before displays .Pq Sx \&Bd or lists .Pq Sx \&Bl unless the .Fl compact flag is given. .Ss \&Pq Parenthesised enclosure. .Pp See also .Sx \&Po . .Ss \&Qc Close quoted context opened by .Sx \&Qo . .Ss \&Ql In-line literal display. This can for example be used for complete command invocations and for multi-word code fragments when more specific markup is not appropriate and an indented display is not desired. While .Xr mandoc 1 always encloses the arguments in single quotes, other formatters usually omit the quotes on non-terminal output devices when the arguments have three or more characters. .Pp See also .Sx \&Dl and .Sx \&Bd .Fl literal . .Ss \&Qo Multi-line version of .Sx \&Qq . .Ss \&Qq Encloses its arguments in .Qq typewriter double-quotes. Consider using .Sx \&Dq . .Pp See also .Sx \&Dq , .Sx \&Sq , and .Sx \&Qo . .Ss \&Re Close an .Sx \&Rs block. Does not have any tail arguments. .Ss \&Rs Begin a bibliographic .Pq Dq reference block. Does not have any head arguments. The block macro may only contain .Sx \&%A , .Sx \&%B , .Sx \&%C , .Sx \&%D , .Sx \&%I , .Sx \&%J , .Sx \&%N , .Sx \&%O , .Sx \&%P , .Sx \&%Q , .Sx \&%R , .Sx \&%T , .Sx \&%U , and .Sx \&%V child macros (at least one must be specified). .Pp Examples: .Bd -literal -offset indent -compact \&.Rs \&.%A J. E. Hopcroft \&.%A J. D. Ullman \&.%B Introduction to Automata Theory, Languages, and Computation \&.%I Addison-Wesley \&.%C Reading, Massachusetts \&.%D 1979 \&.Re .Ed .Pp If an .Sx \&Rs block is used within a SEE ALSO section, a vertical space is asserted before the rendered output, else the block continues on the current line. .Ss \&Rv Insert a standard sentence regarding a function call's return value of 0 on success and \-1 on error, with the .Va errno libc global variable set on error. Its syntax is as follows: .Pp .D1 Pf \. Sx \&Rv Fl std Op Ar function ... .Pp If .Ar function is not specified, the document's name set by .Sx \&Nm is used. Multiple .Ar function arguments are treated as separate functions. .Pp See also .Sx \&Ex . .Ss \&Sc Close single-quoted context opened by .Sx \&So . .Ss \&Sh Begin a new section. For a list of conventional manual sections, see .Sx MANUAL STRUCTURE . These sections should be used unless it's absolutely necessary that custom sections be used. .Pp Section names should be unique so that they may be keyed by .Sx \&Sx . Although this macro is parsed, it should not consist of child node or it may not be linked with .Sx \&Sx . .Pp See also .Sx \&Pp , .Sx \&Ss , and .Sx \&Sx . .Ss \&Sm Switches the spacing mode for output generated from macros. Its syntax is as follows: .Pp .D1 Pf \. Sx \&Sm Op Cm on | off .Pp By default, spacing is .Cm on . When switched .Cm off , no white space is inserted between macro arguments and between the output generated from adjacent macros, but text lines still get normal spacing between words and sentences. .Pp When called without an argument, the .Sx \&Sm macro toggles the spacing mode. Using this is not recommended because it makes the code harder to read. .Ss \&So Multi-line version of .Sx \&Sq . .Ss \&Sq Encloses its arguments in .Sq typewriter single-quotes. .Pp See also .Sx \&Dq , .Sx \&Qq , and .Sx \&So . .Ss \&Ss Begin a new subsection. Unlike with .Sx \&Sh , there is no convention for the naming of subsections. Except .Em DESCRIPTION , the conventional sections described in .Sx MANUAL STRUCTURE rarely have subsections. .Pp Sub-section names should be unique so that they may be keyed by .Sx \&Sx . Although this macro is parsed, it should not consist of child node or it may not be linked with .Sx \&Sx . .Pp See also .Sx \&Pp , .Sx \&Sh , and .Sx \&Sx . .Ss \&St Replace an abbreviation for a standard with the full form. The following standards are recognised. Where multiple lines are given without a blank line in between, they all refer to the same standard, and using the first form is recommended. .Bl -tag -width 1n .It C language standards .Pp .Bl -tag -width "-p1003.1g-2000" -compact .It \-ansiC .St -ansiC .It \-ansiC-89 .St -ansiC-89 .It \-isoC .St -isoC .It \-isoC-90 .St -isoC-90 .br The original C standard. .Pp .It \-isoC-amd1 .St -isoC-amd1 .Pp .It \-isoC-tcor1 .St -isoC-tcor1 .Pp .It \-isoC-tcor2 .St -isoC-tcor2 .Pp .It \-isoC-99 .St -isoC-99 .br The second major version of the C language standard. .Pp .It \-isoC-2011 .St -isoC-2011 .br The third major version of the C language standard. .El .It POSIX.1 before the Single UNIX Specification .Pp .Bl -tag -width "-p1003.1g-2000" -compact .It \-p1003.1-88 .St -p1003.1-88 .It \-p1003.1 .St -p1003.1 .br The original POSIX standard, based on ANSI C. .Pp .It \-p1003.1-90 .St -p1003.1-90 .It \-iso9945-1-90 .St -iso9945-1-90 .br The first update of POSIX.1. .Pp .It \-p1003.1b-93 .St -p1003.1b-93 .It \-p1003.1b .St -p1003.1b .br Real-time extensions. .Pp .It \-p1003.1c-95 .St -p1003.1c-95 .br POSIX thread interfaces. .Pp .It \-p1003.1i-95 .St -p1003.1i-95 .br Technical Corrigendum. .Pp .It \-p1003.1-96 .St -p1003.1-96 .It \-iso9945-1-96 .St -iso9945-1-96 .br Includes POSIX.1-1990, 1b, 1c, and 1i. .El .It X/Open Portability Guide version 4 and related standards .Pp .Bl -tag -width "-p1003.1g-2000" -compact .It \-xpg3 .St -xpg3 .br An XPG4 precursor, published in 1989. .Pp .It \-p1003.2 .St -p1003.2 .It \-p1003.2-92 .St -p1003.2-92 .It \-iso9945-2-93 .St -iso9945-2-93 .br An XCU4 precursor. .Pp .It \-p1003.2a-92 .St -p1003.2a-92 .br Updates to POSIX.2. .Pp .It \-xpg4 .St -xpg4 .br Based on POSIX.1 and POSIX.2, published in 1992. .El .It Single UNIX Specification version 1 and related standards .Pp .Bl -tag -width "-p1003.1g-2000" -compact .It \-susv1 .St -susv1 .It \-xpg4.2 .St -xpg4.2 .br This standard was published in 1994. It was used as the basis for UNIX 95 certification. The following three refer to parts of it. .Pp .It \-xsh4.2 .St -xsh4.2 .Pp .It \-xcurses4.2 .St -xcurses4.2 .Pp .It \-p1003.1g-2000 .St -p1003.1g-2000 .br Networking APIs, including sockets. .Pp .It \-svid4 .St -svid4 , .br Published in 1995. .El .It Single UNIX Specification version 2 and related standards .Pp .Bl -tag -width "-p1003.1g-2000" -compact .It \-susv2 .St -susv2 This Standard was published in 1997 and is also called X/Open Portability Guide version 5. It was used as the basis for UNIX 98 certification. The following refer to parts of it. .Pp .It \-xbd5 .St -xbd5 .Pp .It \-xsh5 .St -xsh5 .Pp .It \-xcu5 .St -xcu5 .Pp .It \-xns5 .St -xns5 .It \-xns5.2 .St -xns5.2 .El .It Single UNIX Specification version 3 .Pp .Bl -tag -width "-p1003.1-2001" -compact .It \-p1003.1-2001 .St -p1003.1-2001 .It \-susv3 .St -susv3 .br This standard is based on C99, SUSv2, POSIX.1-1996, 1d, and 1j. It is also called X/Open Portability Guide version 6. It is used as the basis for UNIX 03 certification. .Pp .It \-p1003.1-2004 .St -p1003.1-2004 .br The second and last Technical Corrigendum. .El .It Single UNIX Specification version 4 .Pp .Bl -tag -width "-p1003.1g-2000" -compact .It \-p1003.1-2008 .St -p1003.1-2008 .It \-susv4 .St -susv4 .br This standard is also called X/Open Portability Guide version 7. .Pp .It \-p1003.1-2013 .St -p1003.1-2013 .br This is the first Technical Corrigendum. .El .It Other standards .Pp .Bl -tag -width "-p1003.1g-2000" -compact .It \-ieee754 .St -ieee754 .br Floating-point arithmetic. .Pp .It \-iso8601 .St -iso8601 .br Representation of dates and times, published in 1988. .Pp .It \-iso8802-3 .St -iso8802-3 .br Ethernet local area networks. .Pp .It \-ieee1275-94 .St -ieee1275-94 .El .El .Ss \&Sx Reference a section or subsection in the same manual page. The referenced section or subsection name must be identical to the enclosed argument, including whitespace. .Pp Examples: .Dl \&.Sx MANUAL STRUCTURE .Pp See also .Sx \&Sh and .Sx \&Ss . .Ss \&Sy Request a boldface font. .Pp This is most often used to indicate importance or seriousness (not to be confused with stress emphasis, see .Sx \&Em ) . When none of the semantic macros fit, it is also adequate for syntax elements that have to be given or that appear verbatim. .Pp Examples: .Bd -literal -compact -offset indent \&.Sy Warning : If \&.Sy s appears in the owner permissions, set-user-ID mode is set. This utility replaces the former \&.Sy dumpdir program. .Ed .Pp See also .Sx \&Bf , .Sx \&Em , .Sx \&Li , and .Sx \&No . .Ss \&Ta Table cell separator in .Sx \&Bl Fl column lists; can only be used below .Sx \&It . .Ss \&Tn Supported only for compatibility, do not use this in new manuals. Even though the macro name .Pq Dq tradename suggests a semantic function, historic usage is inconsistent, mostly using it as a presentation-level macro to request a small caps font. .Ss \&Ud Supported only for compatibility, do not use this in new manuals. Prints out .Dq currently under development. .Ss \&Ux Supported only for compatibility, do not use this in new manuals. Prints out .Dq Ux . .Ss \&Va A variable name. .Pp Examples: .Dl \&.Va foo .Dl \&.Va const char *bar ; .Pp For function arguments and parameters, use .Sx \&Fa instead. For declarations of global variables in the .Em SYNOPSIS section, use .Sx \&Vt . .Ss \&Vt A variable type. .Pp This is also used for indicating global variables in the .Em SYNOPSIS section, in which case a variable name is also specified. Note that it accepts .Sx Block partial-implicit syntax when invoked as the first macro on an input line in the .Em SYNOPSIS section, else it accepts ordinary .Sx In-line syntax. In the former case, this macro starts a new output line, and a blank line is inserted in front if there is a preceding function definition or include directive. .Pp Examples: .Dl \&.Vt unsigned char .Dl \&.Vt extern const char * const sys_signame[] \&; .Pp For parameters in function prototypes, use .Sx \&Fa instead, for function return types .Sx \&Ft , and for variable names outside the .Em SYNOPSIS section .Sx \&Va , even when including a type with the name. See also .Sx MANUAL STRUCTURE . .Ss \&Xc Close a scope opened by .Sx \&Xo . .Ss \&Xo Extend the header of an .Sx \&It macro or the body of a partial-implicit block macro beyond the end of the input line. This macro originally existed to work around the 9-argument limit of historic .Xr roff 7 . .Ss \&Xr Link to another manual .Pq Qq cross-reference . Its syntax is as follows: .Pp -.D1 Pf \. Sx \&Xr Ar name Op section +.D1 Pf \. Sx \&Xr Ar name section .Pp Cross reference the .Ar name and .Ar section -number of another man page; -omitting the section number is rarely useful. +number of another man page. .Pp Examples: .Dl \&.Xr mandoc 1 .Dl \&.Xr mandoc 1 \&; .Dl \&.Xr mandoc 1 \&Ns s behaviour .Ss \&br Emits a line-break. This macro should not be used; it is implemented for compatibility with historical manuals. .Pp Consider using .Sx \&Pp in the event of natural paragraph breaks. .Ss \&sp Emits vertical space. This macro should not be used; it is implemented for compatibility with historical manuals. Its syntax is as follows: .Pp .D1 Pf \. Sx \&sp Op Ar height .Pp The .Ar height argument is a scaling width as described in .Xr roff 7 . If unspecified, .Sx \&sp asserts a single vertical space. .Sh MACRO SYNTAX The syntax of a macro depends on its classification. In this section, .Sq \-arg refers to macro arguments, which may be followed by zero or more .Sq parm parameters; .Sq \&Yo opens the scope of a macro; and if specified, .Sq \&Yc closes it out. .Pp The .Em Callable column indicates that the macro may also be called by passing its name as an argument to another macro. For example, .Sq \&.Op \&Fl O \&Ar file produces .Sq Op Fl O Ar file . To prevent a macro call and render the macro name literally, escape it by prepending a zero-width space, .Sq \e& . For example, .Sq \&Op \e&Fl O produces .Sq Op \&Fl O . If a macro is not callable but its name appears as an argument to another macro, it is interpreted as opaque text. For example, .Sq \&.Fl \&Sh produces .Sq Fl \&Sh . .Pp The .Em Parsed column indicates whether the macro may call other macros by receiving their names as arguments. If a macro is not parsed but the name of another macro appears as an argument, it is interpreted as opaque text. .Pp The .Em Scope column, if applicable, describes closure rules. .Ss Block full-explicit Multi-line scope closed by an explicit closing macro. All macros contains bodies; only .Sx \&Bf and .Pq optionally .Sx \&Bl contain a head. .Bd -literal -offset indent \&.Yo \(lB\-arg \(lBparm...\(rB\(rB \(lBhead...\(rB \(lBbody...\(rB \&.Yc .Ed .Bl -column "MacroX" "CallableX" "ParsedX" "closed by XXX" -offset indent .It Em Macro Ta Em Callable Ta Em Parsed Ta Em Scope .It Sx \&Bd Ta \&No Ta \&No Ta closed by Sx \&Ed .It Sx \&Bf Ta \&No Ta \&No Ta closed by Sx \&Ef .It Sx \&Bk Ta \&No Ta \&No Ta closed by Sx \&Ek .It Sx \&Bl Ta \&No Ta \&No Ta closed by Sx \&El .It Sx \&Ed Ta \&No Ta \&No Ta opened by Sx \&Bd .It Sx \&Ef Ta \&No Ta \&No Ta opened by Sx \&Bf .It Sx \&Ek Ta \&No Ta \&No Ta opened by Sx \&Bk .It Sx \&El Ta \&No Ta \&No Ta opened by Sx \&Bl .El .Ss Block full-implicit Multi-line scope closed by end-of-file or implicitly by another macro. All macros have bodies; some .Po .Sx \&It Fl bullet , .Fl hyphen , .Fl dash , .Fl enum , .Fl item .Pc don't have heads; only one .Po .Sx \&It in .Sx \&Bl Fl column .Pc has multiple heads. .Bd -literal -offset indent \&.Yo \(lB\-arg \(lBparm...\(rB\(rB \(lBhead... \(lBTa head...\(rB\(rB \(lBbody...\(rB .Ed .Bl -column "MacroX" "CallableX" "ParsedX" "closed by XXXXXXXXXXX" -offset indent .It Em Macro Ta Em Callable Ta Em Parsed Ta Em Scope .It Sx \&It Ta \&No Ta Yes Ta closed by Sx \&It , Sx \&El .It Sx \&Nd Ta \&No Ta \&No Ta closed by Sx \&Sh .It Sx \&Nm Ta \&No Ta Yes Ta closed by Sx \&Nm , Sx \&Sh , Sx \&Ss .It Sx \&Sh Ta \&No Ta Yes Ta closed by Sx \&Sh .It Sx \&Ss Ta \&No Ta Yes Ta closed by Sx \&Sh , Sx \&Ss .El .Pp Note that the .Sx \&Nm macro is a .Sx Block full-implicit macro only when invoked as the first macro in a .Em SYNOPSIS section line, else it is .Sx In-line . .Ss Block partial-explicit Like block full-explicit, but also with single-line scope. Each has at least a body and, in limited circumstances, a head .Po .Sx \&Fo , .Sx \&Eo .Pc and/or tail .Pq Sx \&Ec . .Bd -literal -offset indent \&.Yo \(lB\-arg \(lBparm...\(rB\(rB \(lBhead...\(rB \(lBbody...\(rB \&.Yc \(lBtail...\(rB \&.Yo \(lB\-arg \(lBparm...\(rB\(rB \(lBhead...\(rB \ \(lBbody...\(rB \&Yc \(lBtail...\(rB .Ed .Bl -column "MacroX" "CallableX" "ParsedX" "closed by XXXX" -offset indent .It Em Macro Ta Em Callable Ta Em Parsed Ta Em Scope .It Sx \&Ac Ta Yes Ta Yes Ta opened by Sx \&Ao .It Sx \&Ao Ta Yes Ta Yes Ta closed by Sx \&Ac .It Sx \&Bc Ta Yes Ta Yes Ta closed by Sx \&Bo .It Sx \&Bo Ta Yes Ta Yes Ta opened by Sx \&Bc .It Sx \&Brc Ta Yes Ta Yes Ta opened by Sx \&Bro .It Sx \&Bro Ta Yes Ta Yes Ta closed by Sx \&Brc .It Sx \&Dc Ta Yes Ta Yes Ta opened by Sx \&Do .It Sx \&Do Ta Yes Ta Yes Ta closed by Sx \&Dc .It Sx \&Ec Ta Yes Ta Yes Ta opened by Sx \&Eo .It Sx \&Eo Ta Yes Ta Yes Ta closed by Sx \&Ec .It Sx \&Fc Ta Yes Ta Yes Ta opened by Sx \&Fo .It Sx \&Fo Ta \&No Ta \&No Ta closed by Sx \&Fc .It Sx \&Oc Ta Yes Ta Yes Ta closed by Sx \&Oo .It Sx \&Oo Ta Yes Ta Yes Ta opened by Sx \&Oc .It Sx \&Pc Ta Yes Ta Yes Ta closed by Sx \&Po .It Sx \&Po Ta Yes Ta Yes Ta opened by Sx \&Pc .It Sx \&Qc Ta Yes Ta Yes Ta opened by Sx \&Oo .It Sx \&Qo Ta Yes Ta Yes Ta closed by Sx \&Oc .It Sx \&Re Ta \&No Ta \&No Ta opened by Sx \&Rs .It Sx \&Rs Ta \&No Ta \&No Ta closed by Sx \&Re .It Sx \&Sc Ta Yes Ta Yes Ta opened by Sx \&So .It Sx \&So Ta Yes Ta Yes Ta closed by Sx \&Sc .It Sx \&Xc Ta Yes Ta Yes Ta opened by Sx \&Xo .It Sx \&Xo Ta Yes Ta Yes Ta closed by Sx \&Xc .El .Ss Block partial-implicit Like block full-implicit, but with single-line scope closed by the end of the line. .Bd -literal -offset indent \&.Yo \(lB\-arg \(lBval...\(rB\(rB \(lBbody...\(rB \(lBres...\(rB .Ed .Bl -column "MacroX" "CallableX" "ParsedX" -offset indent .It Em Macro Ta Em Callable Ta Em Parsed .It Sx \&Aq Ta Yes Ta Yes .It Sx \&Bq Ta Yes Ta Yes .It Sx \&Brq Ta Yes Ta Yes .It Sx \&D1 Ta \&No Ta \&Yes .It Sx \&Dl Ta \&No Ta Yes .It Sx \&Dq Ta Yes Ta Yes .It Sx \&En Ta Yes Ta Yes .It Sx \&Op Ta Yes Ta Yes .It Sx \&Pq Ta Yes Ta Yes .It Sx \&Ql Ta Yes Ta Yes .It Sx \&Qq Ta Yes Ta Yes .It Sx \&Sq Ta Yes Ta Yes .It Sx \&Vt Ta Yes Ta Yes .El .Pp Note that the .Sx \&Vt macro is a .Sx Block partial-implicit only when invoked as the first macro in a .Em SYNOPSIS section line, else it is .Sx In-line . .Ss Special block macro The .Sx \&Ta macro can only be used below .Sx \&It in .Sx \&Bl Fl column lists. It delimits blocks representing table cells; these blocks have bodies, but no heads. .Bl -column "MacroX" "CallableX" "ParsedX" "closed by XXXX" -offset indent .It Em Macro Ta Em Callable Ta Em Parsed Ta Em Scope .It Sx \&Ta Ta Yes Ta Yes Ta closed by Sx \&Ta , Sx \&It .El .Ss In-line Closed by the end of the line, fixed argument lengths, and/or subsequent macros. In-line macros have only text children. If a number (or inequality) of arguments is .Pq n , then the macro accepts an arbitrary number of arguments. .Bd -literal -offset indent \&.Yo \(lB\-arg \(lBval...\(rB\(rB \(lBargs...\(rB \(lBres...\(rB \&.Yo \(lB\-arg \(lBval...\(rB\(rB \(lBargs...\(rB Yc... \&.Yo \(lB\-arg \(lBval...\(rB\(rB arg0 arg1 argN .Ed .Bl -column "MacroX" "CallableX" "ParsedX" "Arguments" -offset indent .It Em Macro Ta Em Callable Ta Em Parsed Ta Em Arguments .It Sx \&%A Ta \&No Ta \&No Ta >0 .It Sx \&%B Ta \&No Ta \&No Ta >0 .It Sx \&%C Ta \&No Ta \&No Ta >0 .It Sx \&%D Ta \&No Ta \&No Ta >0 .It Sx \&%I Ta \&No Ta \&No Ta >0 .It Sx \&%J Ta \&No Ta \&No Ta >0 .It Sx \&%N Ta \&No Ta \&No Ta >0 .It Sx \&%O Ta \&No Ta \&No Ta >0 .It Sx \&%P Ta \&No Ta \&No Ta >0 .It Sx \&%Q Ta \&No Ta \&No Ta >0 .It Sx \&%R Ta \&No Ta \&No Ta >0 .It Sx \&%T Ta \&No Ta \&No Ta >0 .It Sx \&%U Ta \&No Ta \&No Ta >0 .It Sx \&%V Ta \&No Ta \&No Ta >0 .It Sx \&Ad Ta Yes Ta Yes Ta >0 .It Sx \&An Ta Yes Ta Yes Ta >0 .It Sx \&Ap Ta Yes Ta Yes Ta 0 .It Sx \&Ar Ta Yes Ta Yes Ta n .It Sx \&At Ta Yes Ta Yes Ta 1 .It Sx \&Bsx Ta Yes Ta Yes Ta n .It Sx \&Bt Ta \&No Ta \&No Ta 0 .It Sx \&Bx Ta Yes Ta Yes Ta n .It Sx \&Cd Ta Yes Ta Yes Ta >0 .It Sx \&Cm Ta Yes Ta Yes Ta >0 .It Sx \&Db Ta \&No Ta \&No Ta 1 .It Sx \&Dd Ta \&No Ta \&No Ta n .It Sx \&Dt Ta \&No Ta \&No Ta n .It Sx \&Dv Ta Yes Ta Yes Ta >0 .It Sx \&Dx Ta Yes Ta Yes Ta n .It Sx \&Em Ta Yes Ta Yes Ta >0 .It Sx \&Er Ta Yes Ta Yes Ta >0 .It Sx \&Es Ta Yes Ta Yes Ta 2 .It Sx \&Ev Ta Yes Ta Yes Ta >0 .It Sx \&Ex Ta \&No Ta \&No Ta n .It Sx \&Fa Ta Yes Ta Yes Ta >0 .It Sx \&Fd Ta \&No Ta \&No Ta >0 .It Sx \&Fl Ta Yes Ta Yes Ta n .It Sx \&Fn Ta Yes Ta Yes Ta >0 .It Sx \&Fr Ta Yes Ta Yes Ta >0 .It Sx \&Ft Ta Yes Ta Yes Ta >0 .It Sx \&Fx Ta Yes Ta Yes Ta n .It Sx \&Hf Ta \&No Ta \&No Ta n .It Sx \&Ic Ta Yes Ta Yes Ta >0 .It Sx \&In Ta \&No Ta \&No Ta 1 .It Sx \&Lb Ta \&No Ta \&No Ta 1 .It Sx \&Li Ta Yes Ta Yes Ta >0 .It Sx \&Lk Ta Yes Ta Yes Ta >0 .It Sx \&Lp Ta \&No Ta \&No Ta 0 .It Sx \&Ms Ta Yes Ta Yes Ta >0 .It Sx \&Mt Ta Yes Ta Yes Ta >0 .It Sx \&Nm Ta Yes Ta Yes Ta n .It Sx \&No Ta Yes Ta Yes Ta 0 .It Sx \&Ns Ta Yes Ta Yes Ta 0 .It Sx \&Nx Ta Yes Ta Yes Ta n .It Sx \&Os Ta \&No Ta \&No Ta n .It Sx \&Ot Ta Yes Ta Yes Ta >0 .It Sx \&Ox Ta Yes Ta Yes Ta n .It Sx \&Pa Ta Yes Ta Yes Ta n .It Sx \&Pf Ta Yes Ta Yes Ta 1 .It Sx \&Pp Ta \&No Ta \&No Ta 0 .It Sx \&Rv Ta \&No Ta \&No Ta n .It Sx \&Sm Ta \&No Ta \&No Ta <2 .It Sx \&St Ta \&No Ta Yes Ta 1 .It Sx \&Sx Ta Yes Ta Yes Ta >0 .It Sx \&Sy Ta Yes Ta Yes Ta >0 .It Sx \&Tn Ta Yes Ta Yes Ta >0 .It Sx \&Ud Ta \&No Ta \&No Ta 0 .It Sx \&Ux Ta Yes Ta Yes Ta n .It Sx \&Va Ta Yes Ta Yes Ta n .It Sx \&Vt Ta Yes Ta Yes Ta >0 -.It Sx \&Xr Ta Yes Ta Yes Ta >0 +.It Sx \&Xr Ta Yes Ta Yes Ta 2 .It Sx \&br Ta \&No Ta \&No Ta 0 .It Sx \&sp Ta \&No Ta \&No Ta 1 .El .Ss Delimiters When a macro argument consists of one single input character considered as a delimiter, the argument gets special handling. This does not apply when delimiters appear in arguments containing more than one character. Consequently, to prevent special handling and just handle it like any other argument, a delimiter can be escaped by prepending a zero-width space .Pq Sq \e& . In text lines, delimiters never need escaping, but may be used as normal punctuation. .Pp For many macros, when the leading arguments are opening delimiters, these delimiters are put before the macro scope, and when the trailing arguments are closing delimiters, these delimiters are put after the macro scope. For example, .Pp .D1 Pf \. \&Aq "( [ word ] ) ." .Pp renders as: .Pp .D1 Aq ( [ word ] ) . .Pp Opening delimiters are: .Pp .Bl -tag -width Ds -offset indent -compact .It \&( left parenthesis .It \&[ left bracket .El .Pp Closing delimiters are: .Pp .Bl -tag -width Ds -offset indent -compact .It \&. period .It \&, comma .It \&: colon .It \&; semicolon .It \&) right parenthesis .It \&] right bracket .It \&? question mark .It \&! exclamation mark .El .Pp Note that even a period preceded by a backslash .Pq Sq \e.\& gets this special handling; use .Sq \e&. to prevent that. .Pp Many in-line macros interrupt their scope when they encounter delimiters, and resume their scope when more arguments follow that are not delimiters. For example, .Pp .D1 Pf \. \&Fl "a ( b | c \e*(Ba d ) e" .Pp renders as: .Pp .D1 Fl a ( b | c \*(Ba d ) e .Pp This applies to both opening and closing delimiters, and also to the middle delimiter: .Pp .Bl -tag -width Ds -offset indent -compact .It \&| vertical bar .El .Pp As a special case, the predefined string \e*(Ba is handled and rendered in the same way as a plain .Sq \&| character. Using this predefined string is not recommended in new manuals. .Ss Font handling In .Nm documents, usage of semantic markup is recommended in order to have proper fonts automatically selected; only when no fitting semantic markup is available, consider falling back to .Sx Physical markup macros. Whenever any .Nm macro switches the .Xr roff 7 font mode, it will automatically restore the previous font when exiting its scope. Manually switching the font using the .Xr roff 7 .Ql \ef font escape sequences is never required. .Sh COMPATIBILITY This section provides an incomplete list of compatibility issues between mandoc and GNU troff .Pq Qq groff . .Pp The following problematic behaviour is found in groff: .Pp .Bl -dash -compact .It .Sx \&Dd with non-standard arguments behaves very strangely. When there are three arguments, they are printed verbatim. Any other number of arguments is replaced by the current date, but without any arguments the string .Dq Epoch is printed. .It .Sx \&Lk only accepts a single link-name argument; the remainder is misformatted. .It .Sx \&Pa does not format its arguments when used in the FILES section under certain list types. .It .Sx \&Ta can only be called by other macros, but not at the beginning of a line. .It .Sx \&%C is not implemented (up to and including groff-1.22.2). .It .Sq \ef .Pq font face and .Sq \eF .Pq font family face .Sx Text Decoration escapes behave irregularly when specified within line-macro scopes. .It Negative scaling units return to prior lines. Instead, mandoc truncates them to zero. .El .Pp The following features are unimplemented in mandoc: .Pp .Bl -dash -compact .It .Sx \&Bd .Fl file Ar file is unsupported for security reasons. .It .Sx \&Bd .Fl filled does not adjust the right margin, but is an alias for .Sx \&Bd .Fl ragged . .It .Sx \&Bd .Fl literal does not use a literal font, but is an alias for .Sx \&Bd .Fl unfilled . .It .Sx \&Bd .Fl offset Cm center and .Fl offset Cm right don't work. Groff does not implement centered and flush-right rendering either, but produces large indentations. .El .Sh SEE ALSO .Xr man 1 , .Xr mandoc 1 , .Xr eqn 7 , .Xr man 7 , .Xr mandoc_char 7 , .Xr roff 7 , .Xr tbl 7 +.Pp +The web page +.Lk http://mdocml.bsd.lv/mdoc/ "extended documentation for the mdoc language" +provides a few tutorial-style pages for beginners, an extensive style +guide for advanced authors, and an alphabetic index helping to choose +the best macros for various kinds of content. .Sh HISTORY The .Nm language first appeared as a troff macro package in .Bx 4.4 . It was later significantly updated by Werner Lemberg and Ruslan Ermilov in groff-1.17. The standalone implementation that is part of the .Xr mandoc 1 utility written by Kristaps Dzonsons appeared in .Ox 4.6 . .Sh AUTHORS The .Nm reference was written by .An Kristaps Dzonsons Aq Mt kristaps@bsd.lv . Index: stable/11/contrib/mdocml/mdoc.c =================================================================== --- stable/11/contrib/mdocml/mdoc.c (revision 316419) +++ stable/11/contrib/mdocml/mdoc.c (revision 316420) @@ -1,489 +1,466 @@ -/* $Id: mdoc.c,v 1.256 2015/10/30 19:04:16 schwarze Exp $ */ +/* $Id: mdoc.c,v 1.258 2017/01/10 13:47:00 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010, 2012-2015 Ingo Schwarze + * Copyright (c) 2010, 2012-2016 Ingo Schwarze * * 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 AUTHORS DISCLAIM ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h" #include #include #include #include #include #include #include #include #include "mandoc_aux.h" #include "mandoc.h" #include "roff.h" #include "mdoc.h" #include "libmandoc.h" #include "roff_int.h" #include "libmdoc.h" const char *const __mdoc_macronames[MDOC_MAX + 1] = { "text", "Ap", "Dd", "Dt", "Os", "Sh", "Ss", "Pp", "D1", "Dl", "Bd", "Ed", "Bl", "El", "It", "Ad", "An", "Ar", "Cd", "Cm", "Dv", "Er", "Ev", "Ex", "Fa", "Fd", "Fl", "Fn", "Ft", "Ic", "In", "Li", "Nd", "Nm", "Op", "Ot", "Pa", "Rv", "St", "Va", "Vt", "Xr", "%A", "%B", "%D", "%I", "%J", "%N", "%O", "%P", "%R", "%T", "%V", "Ac", "Ao", "Aq", "At", "Bc", "Bf", "Bo", "Bq", "Bsx", "Bx", "Db", "Dc", "Do", "Dq", "Ec", "Ef", "Em", "Eo", "Fx", "Ms", "No", "Ns", "Nx", "Ox", "Pc", "Pf", "Po", "Pq", "Qc", "Ql", "Qo", "Qq", "Re", "Rs", "Sc", "So", "Sq", "Sm", "Sx", "Sy", "Tn", "Ux", "Xc", "Xo", "Fo", "Fc", "Oo", "Oc", "Bk", "Ek", "Bt", "Hf", "Fr", "Ud", "Lb", "Lp", "Lk", "Mt", "Brq", "Bro", "Brc", "%C", "Es", "En", "Dx", "%Q", "br", "sp", "%U", "Ta", "ll", }; const char *const __mdoc_argnames[MDOC_ARG_MAX] = { "split", "nosplit", "ragged", "unfilled", "literal", "file", "offset", "bullet", "dash", "hyphen", "item", "enum", "tag", "diag", "hang", "ohang", "inset", "column", "width", "compact", "std", "filled", "words", "emphasis", "symbolic", "nested", "centered" }; const char * const *mdoc_macronames = __mdoc_macronames + 1; const char * const *mdoc_argnames = __mdoc_argnames; static int mdoc_ptext(struct roff_man *, int, char *, int); static int mdoc_pmacro(struct roff_man *, int, char *, int); /* * Main parse routine. Parses a single line -- really just hands off to * the macro (mdoc_pmacro()) or text parser (mdoc_ptext()). */ int mdoc_parseln(struct roff_man *mdoc, int ln, char *buf, int offs) { if (mdoc->last->type != ROFFT_EQN || ln > mdoc->last->line) mdoc->flags |= MDOC_NEWLINE; /* * Let the roff nS register switch SYNOPSIS mode early, * such that the parser knows at all times * whether this mode is on or off. * Note that this mode is also switched by the Sh macro. */ if (roff_getreg(mdoc->roff, "nS")) mdoc->flags |= MDOC_SYNOPSIS; else mdoc->flags &= ~MDOC_SYNOPSIS; return roff_getcontrol(mdoc->roff, buf, &offs) ? mdoc_pmacro(mdoc, ln, buf, offs) : mdoc_ptext(mdoc, ln, buf, offs); } void mdoc_macro(MACRO_PROT_ARGS) { assert(tok > TOKEN_NONE && tok < MDOC_MAX); (*mdoc_macros[tok].fp)(mdoc, tok, line, ppos, pos, buf); } void mdoc_tail_alloc(struct roff_man *mdoc, int line, int pos, int tok) { struct roff_node *p; p = roff_node_alloc(mdoc, line, pos, ROFFT_TAIL, tok); roff_node_append(mdoc, p); mdoc->next = ROFF_NEXT_CHILD; } struct roff_node * mdoc_endbody_alloc(struct roff_man *mdoc, int line, int pos, int tok, struct roff_node *body, enum mdoc_endbody end) { struct roff_node *p; - body->flags |= MDOC_ENDED; - body->parent->flags |= MDOC_ENDED; + body->flags |= NODE_ENDED; + body->parent->flags |= NODE_ENDED; p = roff_node_alloc(mdoc, line, pos, ROFFT_BODY, tok); p->body = body; p->norm = body->norm; p->end = end; roff_node_append(mdoc, p); mdoc->next = ROFF_NEXT_SIBLING; return p; } struct roff_node * mdoc_block_alloc(struct roff_man *mdoc, int line, int pos, int tok, struct mdoc_arg *args) { struct roff_node *p; p = roff_node_alloc(mdoc, line, pos, ROFFT_BLOCK, tok); p->args = args; if (p->args) (args->refcnt)++; switch (tok) { case MDOC_Bd: case MDOC_Bf: case MDOC_Bl: case MDOC_En: case MDOC_Rs: p->norm = mandoc_calloc(1, sizeof(union mdoc_data)); break; default: break; } roff_node_append(mdoc, p); mdoc->next = ROFF_NEXT_CHILD; return p; } void mdoc_elem_alloc(struct roff_man *mdoc, int line, int pos, int tok, struct mdoc_arg *args) { struct roff_node *p; p = roff_node_alloc(mdoc, line, pos, ROFFT_ELEM, tok); p->args = args; if (p->args) (args->refcnt)++; switch (tok) { case MDOC_An: p->norm = mandoc_calloc(1, sizeof(union mdoc_data)); break; default: break; } roff_node_append(mdoc, p); mdoc->next = ROFF_NEXT_CHILD; } void mdoc_node_relink(struct roff_man *mdoc, struct roff_node *p) { roff_node_unlink(mdoc, p); p->prev = p->next = NULL; roff_node_append(mdoc, p); } /* * Parse free-form text, that is, a line that does not begin with the * control character. */ static int mdoc_ptext(struct roff_man *mdoc, int line, char *buf, int offs) { struct roff_node *n; char *c, *ws, *end; - assert(mdoc->last); n = mdoc->last; /* - * Divert directly to list processing if we're encountering a - * columnar ROFFT_BLOCK with or without a prior ROFFT_BLOCK entry - * (a ROFFT_BODY means it's already open, in which case we should - * process within its context in the normal way). + * If a column list contains plain text, assume an implicit item + * macro. This can happen one or more times at the beginning + * of such a list, intermixed with non-It mdoc macros and with + * nodes generated on the roff level, for example by tbl. */ - if (n->tok == MDOC_Bl && n->type == ROFFT_BODY && - n->end == ENDBODY_NOT && n->norm->Bl.type == LIST_column) { - /* `Bl' is open without any children. */ + if ((n->tok == MDOC_Bl && n->type == ROFFT_BODY && + n->end == ENDBODY_NOT && n->norm->Bl.type == LIST_column) || + (n->parent != NULL && n->parent->tok == MDOC_Bl && + n->parent->norm->Bl.type == LIST_column)) { mdoc->flags |= MDOC_FREECOL; mdoc_macro(mdoc, MDOC_It, line, offs, &offs, buf); return 1; } - if (n->tok == MDOC_It && n->type == ROFFT_BLOCK && - NULL != n->parent && - MDOC_Bl == n->parent->tok && - LIST_column == n->parent->norm->Bl.type) { - /* `Bl' has block-level `It' children. */ - mdoc->flags |= MDOC_FREECOL; - mdoc_macro(mdoc, MDOC_It, line, offs, &offs, buf); - return 1; - } - /* * Search for the beginning of unescaped trailing whitespace (ws) * and for the first character not to be output (end). */ /* FIXME: replace with strcspn(). */ ws = NULL; for (c = end = buf + offs; *c; c++) { switch (*c) { case ' ': if (NULL == ws) ws = c; continue; case '\t': /* * Always warn about trailing tabs, * even outside literal context, * where they should be put on the next line. */ if (NULL == ws) ws = c; /* * Strip trailing tabs in literal context only; * outside, they affect the next line. */ if (MDOC_LITERAL & mdoc->flags) continue; break; case '\\': /* Skip the escaped character, too, if any. */ if (c[1]) c++; /* FALLTHROUGH */ default: ws = NULL; break; } end = c + 1; } *end = '\0'; if (ws) mandoc_msg(MANDOCERR_SPACE_EOL, mdoc->parse, line, (int)(ws-buf), NULL); if (buf[offs] == '\0' && ! (mdoc->flags & MDOC_LITERAL)) { mandoc_msg(MANDOCERR_FI_BLANK, mdoc->parse, line, (int)(c - buf), NULL); /* * Insert a `sp' in the case of a blank line. Technically, * blank lines aren't allowed, but enough manuals assume this * behaviour that we want to work around it. */ roff_elem_alloc(mdoc, line, offs, MDOC_sp); - mdoc->last->flags |= MDOC_VALID | MDOC_ENDED; + mdoc->last->flags |= NODE_VALID | NODE_ENDED; mdoc->next = ROFF_NEXT_SIBLING; return 1; } roff_word_alloc(mdoc, line, offs, buf+offs); if (mdoc->flags & MDOC_LITERAL) return 1; /* * End-of-sentence check. If the last character is an unescaped * EOS character, then flag the node as being the end of a * sentence. The front-end will know how to interpret this. */ assert(buf < end); if (mandoc_eos(buf+offs, (size_t)(end-buf-offs))) - mdoc->last->flags |= MDOC_EOS; + mdoc->last->flags |= NODE_EOS; return 1; } /* * Parse a macro line, that is, a line beginning with the control * character. */ static int mdoc_pmacro(struct roff_man *mdoc, int ln, char *buf, int offs) { struct roff_node *n; const char *cp; int tok; int i, sv; char mac[5]; sv = offs; /* * Copy the first word into a nil-terminated buffer. * Stop when a space, tab, escape, or eoln is encountered. */ i = 0; while (i < 4 && strchr(" \t\\", buf[offs]) == NULL) mac[i++] = buf[offs++]; mac[i] = '\0'; tok = (i > 1 && i < 4) ? mdoc_hash_find(mac) : TOKEN_NONE; if (tok == TOKEN_NONE) { mandoc_msg(MANDOCERR_MACRO, mdoc->parse, ln, sv, buf + sv - 1); return 1; } /* Skip a leading escape sequence or tab. */ switch (buf[offs]) { case '\\': cp = buf + offs + 1; mandoc_escape(&cp, NULL, NULL); offs = cp - buf; break; case '\t': offs++; break; default: break; } /* Jump to the next non-whitespace word. */ while (buf[offs] && ' ' == buf[offs]) offs++; /* * Trailing whitespace. Note that tabs are allowed to be passed * into the parser as "text", so we only warn about spaces here. */ if ('\0' == buf[offs] && ' ' == buf[offs - 1]) mandoc_msg(MANDOCERR_SPACE_EOL, mdoc->parse, ln, offs - 1, NULL); /* * If an initial macro or a list invocation, divert directly * into macro processing. */ - if (NULL == mdoc->last || MDOC_It == tok || MDOC_El == tok) { + n = mdoc->last; + if (n == NULL || tok == MDOC_It || tok == MDOC_El) { mdoc_macro(mdoc, tok, ln, sv, &offs, buf); return 1; } - n = mdoc->last; - assert(mdoc->last); - /* - * If the first macro of a `Bl -column', open an `It' block - * context around the parsed macro. + * If a column list contains a non-It macro, assume an implicit + * item macro. This can happen one or more times at the + * beginning of such a list, intermixed with text lines and + * with nodes generated on the roff level, for example by tbl. */ - if (n->tok == MDOC_Bl && n->type == ROFFT_BODY && - n->end == ENDBODY_NOT && n->norm->Bl.type == LIST_column) { - mdoc->flags |= MDOC_FREECOL; - mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf); - return 1; - } - - /* - * If we're following a block-level `It' within a `Bl -column' - * context (perhaps opened in the above block or in ptext()), - * then open an `It' block context around the parsed macro. - */ - - if (n->tok == MDOC_It && n->type == ROFFT_BLOCK && - NULL != n->parent && - MDOC_Bl == n->parent->tok && - LIST_column == n->parent->norm->Bl.type) { + if ((n->tok == MDOC_Bl && n->type == ROFFT_BODY && + n->end == ENDBODY_NOT && n->norm->Bl.type == LIST_column) || + (n->parent != NULL && n->parent->tok == MDOC_Bl && + n->parent->norm->Bl.type == LIST_column)) { mdoc->flags |= MDOC_FREECOL; mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf); return 1; } /* Normal processing of a macro. */ mdoc_macro(mdoc, tok, ln, sv, &offs, buf); /* In quick mode (for mandocdb), abort after the NAME section. */ if (mdoc->quick && MDOC_Sh == tok && SEC_NAME != mdoc->last->sec) return 2; return 1; } enum mdelim mdoc_isdelim(const char *p) { if ('\0' == p[0]) return DELIM_NONE; if ('\0' == p[1]) switch (p[0]) { case '(': case '[': return DELIM_OPEN; case '|': return DELIM_MIDDLE; case '.': case ',': case ';': case ':': case '?': case '!': case ')': case ']': return DELIM_CLOSE; default: return DELIM_NONE; } if ('\\' != p[0]) return DELIM_NONE; if (0 == strcmp(p + 1, ".")) return DELIM_CLOSE; if (0 == strcmp(p + 1, "fR|\\fP")) return DELIM_MIDDLE; return DELIM_NONE; } void mdoc_validate(struct roff_man *mdoc) { mdoc->last = mdoc->first; mdoc_node_validate(mdoc); mdoc_state_reset(mdoc); } Index: stable/11/contrib/mdocml/mdoc_argv.c =================================================================== --- stable/11/contrib/mdocml/mdoc_argv.c (revision 316419) +++ stable/11/contrib/mdocml/mdoc_argv.c (revision 316420) @@ -1,677 +1,678 @@ -/* $Id: mdoc_argv.c,v 1.107 2015/10/17 00:21:07 schwarze Exp $ */ +/* $Id: mdoc_argv.c,v 1.109 2016/08/28 16:15:12 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2012, 2014, 2015 Ingo Schwarze * * 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 AUTHORS DISCLAIM ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h" #include #include #include #include #include #include "mandoc_aux.h" #include "mandoc.h" #include "roff.h" #include "mdoc.h" #include "libmandoc.h" +#include "roff_int.h" #include "libmdoc.h" #define MULTI_STEP 5 /* pre-allocate argument values */ #define DELIMSZ 6 /* max possible size of a delimiter */ enum argsflag { ARGSFL_NONE = 0, ARGSFL_DELIM, /* handle delimiters of [[::delim::][ ]+]+ */ ARGSFL_TABSEP /* handle tab/`Ta' separated phrases */ }; enum argvflag { ARGV_NONE, /* no args to flag (e.g., -split) */ ARGV_SINGLE, /* one arg to flag (e.g., -file xxx) */ ARGV_MULTI /* multiple args (e.g., -column xxx yyy) */ }; struct mdocarg { enum argsflag flags; const enum mdocargt *argvs; }; static void argn_free(struct mdoc_arg *, int); static enum margserr args(struct roff_man *, int, int *, char *, enum argsflag, char **); static int args_checkpunct(const char *, int); static void argv_multi(struct roff_man *, int, struct mdoc_argv *, int *, char *); static void argv_single(struct roff_man *, int, struct mdoc_argv *, int *, char *); static const enum argvflag argvflags[MDOC_ARG_MAX] = { ARGV_NONE, /* MDOC_Split */ ARGV_NONE, /* MDOC_Nosplit */ ARGV_NONE, /* MDOC_Ragged */ ARGV_NONE, /* MDOC_Unfilled */ ARGV_NONE, /* MDOC_Literal */ ARGV_SINGLE, /* MDOC_File */ ARGV_SINGLE, /* MDOC_Offset */ ARGV_NONE, /* MDOC_Bullet */ ARGV_NONE, /* MDOC_Dash */ ARGV_NONE, /* MDOC_Hyphen */ ARGV_NONE, /* MDOC_Item */ ARGV_NONE, /* MDOC_Enum */ ARGV_NONE, /* MDOC_Tag */ ARGV_NONE, /* MDOC_Diag */ ARGV_NONE, /* MDOC_Hang */ ARGV_NONE, /* MDOC_Ohang */ ARGV_NONE, /* MDOC_Inset */ ARGV_MULTI, /* MDOC_Column */ ARGV_SINGLE, /* MDOC_Width */ ARGV_NONE, /* MDOC_Compact */ ARGV_NONE, /* MDOC_Std */ ARGV_NONE, /* MDOC_Filled */ ARGV_NONE, /* MDOC_Words */ ARGV_NONE, /* MDOC_Emphasis */ ARGV_NONE, /* MDOC_Symbolic */ ARGV_NONE /* MDOC_Symbolic */ }; static const enum mdocargt args_Ex[] = { MDOC_Std, MDOC_ARG_MAX }; static const enum mdocargt args_An[] = { MDOC_Split, MDOC_Nosplit, MDOC_ARG_MAX }; static const enum mdocargt args_Bd[] = { MDOC_Ragged, MDOC_Unfilled, MDOC_Filled, MDOC_Literal, MDOC_File, MDOC_Offset, MDOC_Compact, MDOC_Centred, MDOC_ARG_MAX }; static const enum mdocargt args_Bf[] = { MDOC_Emphasis, MDOC_Literal, MDOC_Symbolic, MDOC_ARG_MAX }; static const enum mdocargt args_Bk[] = { MDOC_Words, MDOC_ARG_MAX }; static const enum mdocargt args_Bl[] = { MDOC_Bullet, MDOC_Dash, MDOC_Hyphen, MDOC_Item, MDOC_Enum, MDOC_Tag, MDOC_Diag, MDOC_Hang, MDOC_Ohang, MDOC_Inset, MDOC_Column, MDOC_Width, MDOC_Offset, MDOC_Compact, MDOC_Nested, MDOC_ARG_MAX }; static const struct mdocarg mdocargs[MDOC_MAX] = { { ARGSFL_DELIM, NULL }, /* Ap */ { ARGSFL_NONE, NULL }, /* Dd */ { ARGSFL_NONE, NULL }, /* Dt */ { ARGSFL_NONE, NULL }, /* Os */ { ARGSFL_NONE, NULL }, /* Sh */ { ARGSFL_NONE, NULL }, /* Ss */ { ARGSFL_NONE, NULL }, /* Pp */ { ARGSFL_DELIM, NULL }, /* D1 */ { ARGSFL_DELIM, NULL }, /* Dl */ { ARGSFL_NONE, args_Bd }, /* Bd */ { ARGSFL_NONE, NULL }, /* Ed */ { ARGSFL_NONE, args_Bl }, /* Bl */ { ARGSFL_NONE, NULL }, /* El */ { ARGSFL_NONE, NULL }, /* It */ { ARGSFL_DELIM, NULL }, /* Ad */ { ARGSFL_DELIM, args_An }, /* An */ { ARGSFL_DELIM, NULL }, /* Ar */ { ARGSFL_DELIM, NULL }, /* Cd */ { ARGSFL_DELIM, NULL }, /* Cm */ { ARGSFL_DELIM, NULL }, /* Dv */ { ARGSFL_DELIM, NULL }, /* Er */ { ARGSFL_DELIM, NULL }, /* Ev */ { ARGSFL_NONE, args_Ex }, /* Ex */ { ARGSFL_DELIM, NULL }, /* Fa */ { ARGSFL_NONE, NULL }, /* Fd */ { ARGSFL_DELIM, NULL }, /* Fl */ { ARGSFL_DELIM, NULL }, /* Fn */ { ARGSFL_DELIM, NULL }, /* Ft */ { ARGSFL_DELIM, NULL }, /* Ic */ { ARGSFL_DELIM, NULL }, /* In */ { ARGSFL_DELIM, NULL }, /* Li */ { ARGSFL_NONE, NULL }, /* Nd */ { ARGSFL_DELIM, NULL }, /* Nm */ { ARGSFL_DELIM, NULL }, /* Op */ { ARGSFL_DELIM, NULL }, /* Ot */ { ARGSFL_DELIM, NULL }, /* Pa */ { ARGSFL_NONE, args_Ex }, /* Rv */ { ARGSFL_DELIM, NULL }, /* St */ { ARGSFL_DELIM, NULL }, /* Va */ { ARGSFL_DELIM, NULL }, /* Vt */ { ARGSFL_DELIM, NULL }, /* Xr */ { ARGSFL_NONE, NULL }, /* %A */ { ARGSFL_NONE, NULL }, /* %B */ { ARGSFL_NONE, NULL }, /* %D */ { ARGSFL_NONE, NULL }, /* %I */ { ARGSFL_NONE, NULL }, /* %J */ { ARGSFL_NONE, NULL }, /* %N */ { ARGSFL_NONE, NULL }, /* %O */ { ARGSFL_NONE, NULL }, /* %P */ { ARGSFL_NONE, NULL }, /* %R */ { ARGSFL_NONE, NULL }, /* %T */ { ARGSFL_NONE, NULL }, /* %V */ { ARGSFL_DELIM, NULL }, /* Ac */ { ARGSFL_NONE, NULL }, /* Ao */ { ARGSFL_DELIM, NULL }, /* Aq */ { ARGSFL_DELIM, NULL }, /* At */ { ARGSFL_DELIM, NULL }, /* Bc */ { ARGSFL_NONE, args_Bf }, /* Bf */ { ARGSFL_NONE, NULL }, /* Bo */ { ARGSFL_DELIM, NULL }, /* Bq */ { ARGSFL_DELIM, NULL }, /* Bsx */ { ARGSFL_DELIM, NULL }, /* Bx */ { ARGSFL_NONE, NULL }, /* Db */ { ARGSFL_DELIM, NULL }, /* Dc */ { ARGSFL_NONE, NULL }, /* Do */ { ARGSFL_DELIM, NULL }, /* Dq */ { ARGSFL_DELIM, NULL }, /* Ec */ { ARGSFL_NONE, NULL }, /* Ef */ { ARGSFL_DELIM, NULL }, /* Em */ { ARGSFL_NONE, NULL }, /* Eo */ { ARGSFL_DELIM, NULL }, /* Fx */ { ARGSFL_DELIM, NULL }, /* Ms */ { ARGSFL_DELIM, NULL }, /* No */ { ARGSFL_DELIM, NULL }, /* Ns */ { ARGSFL_DELIM, NULL }, /* Nx */ { ARGSFL_DELIM, NULL }, /* Ox */ { ARGSFL_DELIM, NULL }, /* Pc */ { ARGSFL_DELIM, NULL }, /* Pf */ { ARGSFL_NONE, NULL }, /* Po */ { ARGSFL_DELIM, NULL }, /* Pq */ { ARGSFL_DELIM, NULL }, /* Qc */ { ARGSFL_DELIM, NULL }, /* Ql */ { ARGSFL_NONE, NULL }, /* Qo */ { ARGSFL_DELIM, NULL }, /* Qq */ { ARGSFL_NONE, NULL }, /* Re */ { ARGSFL_NONE, NULL }, /* Rs */ { ARGSFL_DELIM, NULL }, /* Sc */ { ARGSFL_NONE, NULL }, /* So */ { ARGSFL_DELIM, NULL }, /* Sq */ { ARGSFL_NONE, NULL }, /* Sm */ { ARGSFL_DELIM, NULL }, /* Sx */ { ARGSFL_DELIM, NULL }, /* Sy */ { ARGSFL_DELIM, NULL }, /* Tn */ { ARGSFL_DELIM, NULL }, /* Ux */ { ARGSFL_DELIM, NULL }, /* Xc */ { ARGSFL_NONE, NULL }, /* Xo */ { ARGSFL_NONE, NULL }, /* Fo */ { ARGSFL_DELIM, NULL }, /* Fc */ { ARGSFL_NONE, NULL }, /* Oo */ { ARGSFL_DELIM, NULL }, /* Oc */ { ARGSFL_NONE, args_Bk }, /* Bk */ { ARGSFL_NONE, NULL }, /* Ek */ { ARGSFL_NONE, NULL }, /* Bt */ { ARGSFL_NONE, NULL }, /* Hf */ { ARGSFL_DELIM, NULL }, /* Fr */ { ARGSFL_NONE, NULL }, /* Ud */ { ARGSFL_DELIM, NULL }, /* Lb */ { ARGSFL_NONE, NULL }, /* Lp */ { ARGSFL_DELIM, NULL }, /* Lk */ { ARGSFL_DELIM, NULL }, /* Mt */ { ARGSFL_DELIM, NULL }, /* Brq */ { ARGSFL_NONE, NULL }, /* Bro */ { ARGSFL_DELIM, NULL }, /* Brc */ { ARGSFL_NONE, NULL }, /* %C */ { ARGSFL_NONE, NULL }, /* Es */ { ARGSFL_DELIM, NULL }, /* En */ { ARGSFL_DELIM, NULL }, /* Dx */ { ARGSFL_NONE, NULL }, /* %Q */ { ARGSFL_NONE, NULL }, /* br */ { ARGSFL_NONE, NULL }, /* sp */ { ARGSFL_NONE, NULL }, /* %U */ { ARGSFL_NONE, NULL }, /* Ta */ { ARGSFL_NONE, NULL }, /* ll */ }; /* * Parse flags and their arguments from the input line. * These come in the form -flag [argument ...]. * Some flags take no argument, some one, some multiple. */ void mdoc_argv(struct roff_man *mdoc, int line, int tok, struct mdoc_arg **reta, int *pos, char *buf) { struct mdoc_argv tmpv; struct mdoc_argv **retv; const enum mdocargt *argtable; char *argname; int ipos, retc; char savechar; *reta = NULL; /* Which flags does this macro support? */ argtable = mdocargs[tok].argvs; if (argtable == NULL) return; /* Loop over the flags on the input line. */ ipos = *pos; while (buf[ipos] == '-') { /* Seek to the first unescaped space. */ for (argname = buf + ++ipos; buf[ipos] != '\0'; ipos++) if (buf[ipos] == ' ' && buf[ipos - 1] != '\\') break; /* * We want to nil-terminate the word to look it up. * But we may not have a flag, in which case we need * to restore the line as-is. So keep around the * stray byte, which we'll reset upon exiting. */ if ((savechar = buf[ipos]) != '\0') buf[ipos++] = '\0'; /* * Now look up the word as a flag. Use temporary * storage that we'll copy into the node's flags. */ while ((tmpv.arg = *argtable++) != MDOC_ARG_MAX) if ( ! strcmp(argname, mdoc_argnames[tmpv.arg])) break; /* If it isn't a flag, restore the saved byte. */ if (tmpv.arg == MDOC_ARG_MAX) { if (savechar != '\0') buf[ipos - 1] = savechar; break; } /* Read to the next word (the first argument). */ while (buf[ipos] == ' ') ipos++; /* Parse the arguments of the flag. */ tmpv.line = line; tmpv.pos = *pos; tmpv.sz = 0; tmpv.value = NULL; switch (argvflags[tmpv.arg]) { case ARGV_SINGLE: argv_single(mdoc, line, &tmpv, &ipos, buf); break; case ARGV_MULTI: argv_multi(mdoc, line, &tmpv, &ipos, buf); break; case ARGV_NONE: break; } /* Append to the return values. */ if (*reta == NULL) *reta = mandoc_calloc(1, sizeof(**reta)); retc = ++(*reta)->argc; retv = &(*reta)->argv; *retv = mandoc_reallocarray(*retv, retc, sizeof(**retv)); memcpy(*retv + retc - 1, &tmpv, sizeof(**retv)); /* Prepare for parsing the next flag. */ *pos = ipos; argtable = mdocargs[tok].argvs; } } void mdoc_argv_free(struct mdoc_arg *p) { int i; if (NULL == p) return; if (p->refcnt) { --(p->refcnt); if (p->refcnt) return; } assert(p->argc); for (i = (int)p->argc - 1; i >= 0; i--) argn_free(p, i); free(p->argv); free(p); } static void argn_free(struct mdoc_arg *p, int iarg) { struct mdoc_argv *arg; int j; arg = &p->argv[iarg]; if (arg->sz && arg->value) { for (j = (int)arg->sz - 1; j >= 0; j--) free(arg->value[j]); free(arg->value); } for (--p->argc; iarg < (int)p->argc; iarg++) p->argv[iarg] = p->argv[iarg+1]; } enum margserr mdoc_args(struct roff_man *mdoc, int line, int *pos, char *buf, int tok, char **v) { struct roff_node *n; char *v_local; enum argsflag fl; if (v == NULL) v = &v_local; fl = tok == TOKEN_NONE ? ARGSFL_NONE : mdocargs[tok].flags; if (tok != MDOC_It) return args(mdoc, line, pos, buf, fl, v); /* * We know that we're in an `It', so it's reasonable to expect * us to be sitting in a `Bl'. Someday this may not be the case * (if we allow random `It's sitting out there), so provide a * safe fall-back into the default behaviour. */ for (n = mdoc->last; n; n = n->parent) if (MDOC_Bl == n->tok) if (LIST_column == n->norm->Bl.type) { fl = ARGSFL_TABSEP; break; } return args(mdoc, line, pos, buf, fl, v); } static enum margserr args(struct roff_man *mdoc, int line, int *pos, char *buf, enum argsflag fl, char **v) { char *p; int pairs; if (buf[*pos] == '\0') { if (mdoc->flags & MDOC_PHRASELIT && ! (mdoc->flags & MDOC_PHRASE)) { mandoc_msg(MANDOCERR_ARG_QUOTE, mdoc->parse, line, *pos, NULL); mdoc->flags &= ~MDOC_PHRASELIT; } return ARGS_EOLN; } *v = buf + *pos; if (fl == ARGSFL_DELIM && args_checkpunct(buf, *pos)) return ARGS_PUNCT; /* * Tabs in `It' lines in `Bl -column' can't be escaped. * Phrases are reparsed for `Ta' and other macros later. */ if (fl == ARGSFL_TABSEP) { if ((p = strchr(*v, '\t')) != NULL) { /* * Words right before and right after * tab characters are not parsed, * unless there is a blank in between. */ - if (p[-1] != ' ') + if (p > buf && p[-1] != ' ') mdoc->flags |= MDOC_PHRASEQL; if (p[1] != ' ') mdoc->flags |= MDOC_PHRASEQN; /* * One or more blanks after a tab cause * one leading blank in the next column. * So skip all but one of them. */ *pos += (int)(p - *v) + 1; while (buf[*pos] == ' ' && buf[*pos + 1] == ' ') (*pos)++; /* * A tab at the end of an input line * switches to the next column. */ if (buf[*pos] == '\0' || buf[*pos + 1] == '\0') mdoc->flags |= MDOC_PHRASEQN; } else { p = strchr(*v, '\0'); if (p[-1] == ' ') mandoc_msg(MANDOCERR_SPACE_EOL, mdoc->parse, line, *pos, NULL); *pos += (int)(p - *v); } /* Skip any trailing blank characters. */ while (p > *v && p[-1] == ' ' && (p - 1 == *v || p[-2] != '\\')) p--; *p = '\0'; return ARGS_PHRASE; } /* * Process a quoted literal. A quote begins with a double-quote * and ends with a double-quote NOT preceded by a double-quote. * NUL-terminate the literal in place. * Collapse pairs of quotes inside quoted literals. * Whitespace is NOT involved in literal termination. */ if (mdoc->flags & MDOC_PHRASELIT || buf[*pos] == '\"') { if ( ! (mdoc->flags & MDOC_PHRASELIT)) *v = &buf[++(*pos)]; if (mdoc->flags & MDOC_PHRASE) mdoc->flags |= MDOC_PHRASELIT; pairs = 0; for ( ; buf[*pos]; (*pos)++) { /* Move following text left after quoted quotes. */ if (pairs) buf[*pos - pairs] = buf[*pos]; if ('\"' != buf[*pos]) continue; /* Unquoted quotes end quoted args. */ if ('\"' != buf[*pos + 1]) break; /* Quoted quotes collapse. */ pairs++; (*pos)++; } if (pairs) buf[*pos - pairs] = '\0'; if (buf[*pos] == '\0') { if ( ! (mdoc->flags & MDOC_PHRASE)) mandoc_msg(MANDOCERR_ARG_QUOTE, mdoc->parse, line, *pos, NULL); return ARGS_QWORD; } mdoc->flags &= ~MDOC_PHRASELIT; buf[(*pos)++] = '\0'; if ('\0' == buf[*pos]) return ARGS_QWORD; while (' ' == buf[*pos]) (*pos)++; if ('\0' == buf[*pos]) mandoc_msg(MANDOCERR_SPACE_EOL, mdoc->parse, line, *pos, NULL); return ARGS_QWORD; } p = &buf[*pos]; *v = mandoc_getarg(mdoc->parse, &p, line, pos); /* * After parsing the last word in this phrase, * tell lookup() whether or not to interpret it. */ if (*p == '\0' && mdoc->flags & MDOC_PHRASEQL) { mdoc->flags &= ~MDOC_PHRASEQL; mdoc->flags |= MDOC_PHRASEQF; } return ARGS_WORD; } /* * Check if the string consists only of space-separated closing * delimiters. This is a bit of a dance: the first must be a close * delimiter, but it may be followed by middle delimiters. Arbitrary * whitespace may separate these tokens. */ static int args_checkpunct(const char *buf, int i) { int j; char dbuf[DELIMSZ]; enum mdelim d; /* First token must be a close-delimiter. */ for (j = 0; buf[i] && ' ' != buf[i] && j < DELIMSZ; j++, i++) dbuf[j] = buf[i]; if (DELIMSZ == j) return 0; dbuf[j] = '\0'; if (DELIM_CLOSE != mdoc_isdelim(dbuf)) return 0; while (' ' == buf[i]) i++; /* Remaining must NOT be open/none. */ while (buf[i]) { j = 0; while (buf[i] && ' ' != buf[i] && j < DELIMSZ) dbuf[j++] = buf[i++]; if (DELIMSZ == j) return 0; dbuf[j] = '\0'; d = mdoc_isdelim(dbuf); if (DELIM_NONE == d || DELIM_OPEN == d) return 0; while (' ' == buf[i]) i++; } return '\0' == buf[i]; } static void argv_multi(struct roff_man *mdoc, int line, struct mdoc_argv *v, int *pos, char *buf) { enum margserr ac; char *p; for (v->sz = 0; ; v->sz++) { if (buf[*pos] == '-') break; ac = args(mdoc, line, pos, buf, ARGSFL_NONE, &p); if (ac == ARGS_EOLN) break; if (v->sz % MULTI_STEP == 0) v->value = mandoc_reallocarray(v->value, v->sz + MULTI_STEP, sizeof(char *)); v->value[(int)v->sz] = mandoc_strdup(p); } } static void argv_single(struct roff_man *mdoc, int line, struct mdoc_argv *v, int *pos, char *buf) { enum margserr ac; char *p; ac = args(mdoc, line, pos, buf, ARGSFL_NONE, &p); if (ac == ARGS_EOLN) return; v->sz = 1; v->value = mandoc_malloc(sizeof(char *)); v->value[0] = mandoc_strdup(p); } Index: stable/11/contrib/mdocml/mdoc_hash.c =================================================================== --- stable/11/contrib/mdocml/mdoc_hash.c (revision 316419) +++ stable/11/contrib/mdocml/mdoc_hash.c (revision 316420) @@ -1,93 +1,95 @@ -/* $Id: mdoc_hash.c,v 1.26 2015/10/06 18:32:19 schwarze Exp $ */ +/* $Id: mdoc_hash.c,v 1.27 2016/07/15 18:03:45 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * Copyright (c) 2015 Ingo Schwarze * * 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 "config.h" #include #include #include #include #include #include #include +#include "mandoc.h" #include "roff.h" #include "mdoc.h" +#include "libmandoc.h" #include "libmdoc.h" static unsigned char table[27 * 12]; void mdoc_hash_init(void) { int i, j, major; const char *p; if (*table != '\0') return; memset(table, UCHAR_MAX, sizeof(table)); for (i = 0; i < (int)MDOC_MAX; i++) { p = mdoc_macronames[i]; if (isalpha((unsigned char)p[1])) major = 12 * (tolower((unsigned char)p[1]) - 97); else major = 12 * 26; for (j = 0; j < 12; j++) if (UCHAR_MAX == table[major + j]) { table[major + j] = (unsigned char)i; break; } assert(j < 12); } } int mdoc_hash_find(const char *p) { int major, i, j; if (0 == p[0]) return TOKEN_NONE; if ( ! isalpha((unsigned char)p[0]) && '%' != p[0]) return TOKEN_NONE; if (isalpha((unsigned char)p[1])) major = 12 * (tolower((unsigned char)p[1]) - 97); else if ('1' == p[1]) major = 12 * 26; else return TOKEN_NONE; if (p[2] && p[3]) return TOKEN_NONE; for (j = 0; j < 12; j++) { if (UCHAR_MAX == (i = table[major + j])) break; if (0 == strcmp(p, mdoc_macronames[i])) return i; } return TOKEN_NONE; } Index: stable/11/contrib/mdocml/mdoc_html.c =================================================================== --- stable/11/contrib/mdocml/mdoc_html.c (revision 316419) +++ stable/11/contrib/mdocml/mdoc_html.c (revision 316420) @@ -1,2178 +1,1793 @@ -/* $Id: mdoc_html.c,v 1.240 2016/01/08 17:48:09 schwarze Exp $ */ +/* $Id: mdoc_html.c,v 1.260 2017/01/21 02:09:51 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons - * Copyright (c) 2014, 2015, 2016 Ingo Schwarze + * Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze * * 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 AUTHORS DISCLAIM ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h" #include #include #include #include #include #include #include #include "mandoc_aux.h" #include "roff.h" #include "mdoc.h" #include "out.h" #include "html.h" #include "main.h" #define INDENT 5 #define MDOC_ARGS const struct roff_meta *meta, \ struct roff_node *n, \ struct html *h #ifndef MIN #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b)) #endif struct htmlmdoc { int (*pre)(MDOC_ARGS); void (*post)(MDOC_ARGS); }; +static char *make_id(const struct roff_node *); static void print_mdoc_head(MDOC_ARGS); static void print_mdoc_node(MDOC_ARGS); static void print_mdoc_nodelist(MDOC_ARGS); static void synopsis_pre(struct html *, const struct roff_node *); -static void a2width(const char *, struct roffsu *); - static void mdoc_root_post(MDOC_ARGS); static int mdoc_root_pre(MDOC_ARGS); static void mdoc__x_post(MDOC_ARGS); static int mdoc__x_pre(MDOC_ARGS); static int mdoc_ad_pre(MDOC_ARGS); static int mdoc_an_pre(MDOC_ARGS); static int mdoc_ap_pre(MDOC_ARGS); static int mdoc_ar_pre(MDOC_ARGS); static int mdoc_bd_pre(MDOC_ARGS); static int mdoc_bf_pre(MDOC_ARGS); static void mdoc_bk_post(MDOC_ARGS); static int mdoc_bk_pre(MDOC_ARGS); static int mdoc_bl_pre(MDOC_ARGS); -static int mdoc_bt_pre(MDOC_ARGS); -static int mdoc_bx_pre(MDOC_ARGS); static int mdoc_cd_pre(MDOC_ARGS); +static int mdoc_cm_pre(MDOC_ARGS); static int mdoc_d1_pre(MDOC_ARGS); static int mdoc_dv_pre(MDOC_ARGS); static int mdoc_fa_pre(MDOC_ARGS); static int mdoc_fd_pre(MDOC_ARGS); static int mdoc_fl_pre(MDOC_ARGS); static int mdoc_fn_pre(MDOC_ARGS); static int mdoc_ft_pre(MDOC_ARGS); static int mdoc_em_pre(MDOC_ARGS); static void mdoc_eo_post(MDOC_ARGS); static int mdoc_eo_pre(MDOC_ARGS); static int mdoc_er_pre(MDOC_ARGS); static int mdoc_ev_pre(MDOC_ARGS); static int mdoc_ex_pre(MDOC_ARGS); static void mdoc_fo_post(MDOC_ARGS); static int mdoc_fo_pre(MDOC_ARGS); static int mdoc_ic_pre(MDOC_ARGS); static int mdoc_igndelim_pre(MDOC_ARGS); static int mdoc_in_pre(MDOC_ARGS); static int mdoc_it_pre(MDOC_ARGS); static int mdoc_lb_pre(MDOC_ARGS); static int mdoc_li_pre(MDOC_ARGS); static int mdoc_lk_pre(MDOC_ARGS); static int mdoc_mt_pre(MDOC_ARGS); static int mdoc_ms_pre(MDOC_ARGS); static int mdoc_nd_pre(MDOC_ARGS); static int mdoc_nm_pre(MDOC_ARGS); static int mdoc_no_pre(MDOC_ARGS); static int mdoc_ns_pre(MDOC_ARGS); static int mdoc_pa_pre(MDOC_ARGS); static void mdoc_pf_post(MDOC_ARGS); static int mdoc_pp_pre(MDOC_ARGS); static void mdoc_quote_post(MDOC_ARGS); static int mdoc_quote_pre(MDOC_ARGS); static int mdoc_rs_pre(MDOC_ARGS); -static int mdoc_rv_pre(MDOC_ARGS); static int mdoc_sh_pre(MDOC_ARGS); static int mdoc_skip_pre(MDOC_ARGS); static int mdoc_sm_pre(MDOC_ARGS); static int mdoc_sp_pre(MDOC_ARGS); static int mdoc_ss_pre(MDOC_ARGS); static int mdoc_sx_pre(MDOC_ARGS); static int mdoc_sy_pre(MDOC_ARGS); -static int mdoc_ud_pre(MDOC_ARGS); static int mdoc_va_pre(MDOC_ARGS); static int mdoc_vt_pre(MDOC_ARGS); static int mdoc_xr_pre(MDOC_ARGS); static int mdoc_xx_pre(MDOC_ARGS); static const struct htmlmdoc mdocs[MDOC_MAX] = { {mdoc_ap_pre, NULL}, /* Ap */ {NULL, NULL}, /* Dd */ {NULL, NULL}, /* Dt */ {NULL, NULL}, /* Os */ {mdoc_sh_pre, NULL }, /* Sh */ {mdoc_ss_pre, NULL }, /* Ss */ {mdoc_pp_pre, NULL}, /* Pp */ {mdoc_d1_pre, NULL}, /* D1 */ {mdoc_d1_pre, NULL}, /* Dl */ {mdoc_bd_pre, NULL}, /* Bd */ {NULL, NULL}, /* Ed */ {mdoc_bl_pre, NULL}, /* Bl */ {NULL, NULL}, /* El */ {mdoc_it_pre, NULL}, /* It */ {mdoc_ad_pre, NULL}, /* Ad */ {mdoc_an_pre, NULL}, /* An */ {mdoc_ar_pre, NULL}, /* Ar */ {mdoc_cd_pre, NULL}, /* Cd */ - {mdoc_fl_pre, NULL}, /* Cm */ + {mdoc_cm_pre, NULL}, /* Cm */ {mdoc_dv_pre, NULL}, /* Dv */ {mdoc_er_pre, NULL}, /* Er */ {mdoc_ev_pre, NULL}, /* Ev */ {mdoc_ex_pre, NULL}, /* Ex */ {mdoc_fa_pre, NULL}, /* Fa */ {mdoc_fd_pre, NULL}, /* Fd */ {mdoc_fl_pre, NULL}, /* Fl */ {mdoc_fn_pre, NULL}, /* Fn */ {mdoc_ft_pre, NULL}, /* Ft */ {mdoc_ic_pre, NULL}, /* Ic */ {mdoc_in_pre, NULL}, /* In */ {mdoc_li_pre, NULL}, /* Li */ {mdoc_nd_pre, NULL}, /* Nd */ {mdoc_nm_pre, NULL}, /* Nm */ {mdoc_quote_pre, mdoc_quote_post}, /* Op */ {mdoc_ft_pre, NULL}, /* Ot */ {mdoc_pa_pre, NULL}, /* Pa */ - {mdoc_rv_pre, NULL}, /* Rv */ + {mdoc_ex_pre, NULL}, /* Rv */ {NULL, NULL}, /* St */ {mdoc_va_pre, NULL}, /* Va */ {mdoc_vt_pre, NULL}, /* Vt */ {mdoc_xr_pre, NULL}, /* Xr */ {mdoc__x_pre, mdoc__x_post}, /* %A */ {mdoc__x_pre, mdoc__x_post}, /* %B */ {mdoc__x_pre, mdoc__x_post}, /* %D */ {mdoc__x_pre, mdoc__x_post}, /* %I */ {mdoc__x_pre, mdoc__x_post}, /* %J */ {mdoc__x_pre, mdoc__x_post}, /* %N */ {mdoc__x_pre, mdoc__x_post}, /* %O */ {mdoc__x_pre, mdoc__x_post}, /* %P */ {mdoc__x_pre, mdoc__x_post}, /* %R */ {mdoc__x_pre, mdoc__x_post}, /* %T */ {mdoc__x_pre, mdoc__x_post}, /* %V */ {NULL, NULL}, /* Ac */ {mdoc_quote_pre, mdoc_quote_post}, /* Ao */ {mdoc_quote_pre, mdoc_quote_post}, /* Aq */ {NULL, NULL}, /* At */ {NULL, NULL}, /* Bc */ {mdoc_bf_pre, NULL}, /* Bf */ {mdoc_quote_pre, mdoc_quote_post}, /* Bo */ {mdoc_quote_pre, mdoc_quote_post}, /* Bq */ {mdoc_xx_pre, NULL}, /* Bsx */ - {mdoc_bx_pre, NULL}, /* Bx */ + {mdoc_xx_pre, NULL}, /* Bx */ {mdoc_skip_pre, NULL}, /* Db */ {NULL, NULL}, /* Dc */ {mdoc_quote_pre, mdoc_quote_post}, /* Do */ {mdoc_quote_pre, mdoc_quote_post}, /* Dq */ {NULL, NULL}, /* Ec */ /* FIXME: no space */ {NULL, NULL}, /* Ef */ {mdoc_em_pre, NULL}, /* Em */ {mdoc_eo_pre, mdoc_eo_post}, /* Eo */ {mdoc_xx_pre, NULL}, /* Fx */ {mdoc_ms_pre, NULL}, /* Ms */ {mdoc_no_pre, NULL}, /* No */ {mdoc_ns_pre, NULL}, /* Ns */ {mdoc_xx_pre, NULL}, /* Nx */ {mdoc_xx_pre, NULL}, /* Ox */ {NULL, NULL}, /* Pc */ {mdoc_igndelim_pre, mdoc_pf_post}, /* Pf */ {mdoc_quote_pre, mdoc_quote_post}, /* Po */ {mdoc_quote_pre, mdoc_quote_post}, /* Pq */ {NULL, NULL}, /* Qc */ {mdoc_quote_pre, mdoc_quote_post}, /* Ql */ {mdoc_quote_pre, mdoc_quote_post}, /* Qo */ {mdoc_quote_pre, mdoc_quote_post}, /* Qq */ {NULL, NULL}, /* Re */ {mdoc_rs_pre, NULL}, /* Rs */ {NULL, NULL}, /* Sc */ {mdoc_quote_pre, mdoc_quote_post}, /* So */ {mdoc_quote_pre, mdoc_quote_post}, /* Sq */ {mdoc_sm_pre, NULL}, /* Sm */ {mdoc_sx_pre, NULL}, /* Sx */ {mdoc_sy_pre, NULL}, /* Sy */ {NULL, NULL}, /* Tn */ {mdoc_xx_pre, NULL}, /* Ux */ {NULL, NULL}, /* Xc */ {NULL, NULL}, /* Xo */ {mdoc_fo_pre, mdoc_fo_post}, /* Fo */ {NULL, NULL}, /* Fc */ {mdoc_quote_pre, mdoc_quote_post}, /* Oo */ {NULL, NULL}, /* Oc */ {mdoc_bk_pre, mdoc_bk_post}, /* Bk */ {NULL, NULL}, /* Ek */ - {mdoc_bt_pre, NULL}, /* Bt */ + {NULL, NULL}, /* Bt */ {NULL, NULL}, /* Hf */ {mdoc_em_pre, NULL}, /* Fr */ - {mdoc_ud_pre, NULL}, /* Ud */ + {NULL, NULL}, /* Ud */ {mdoc_lb_pre, NULL}, /* Lb */ {mdoc_pp_pre, NULL}, /* Lp */ {mdoc_lk_pre, NULL}, /* Lk */ {mdoc_mt_pre, NULL}, /* Mt */ {mdoc_quote_pre, mdoc_quote_post}, /* Brq */ {mdoc_quote_pre, mdoc_quote_post}, /* Bro */ {NULL, NULL}, /* Brc */ {mdoc__x_pre, mdoc__x_post}, /* %C */ {mdoc_skip_pre, NULL}, /* Es */ {mdoc_quote_pre, mdoc_quote_post}, /* En */ {mdoc_xx_pre, NULL}, /* Dx */ {mdoc__x_pre, mdoc__x_post}, /* %Q */ {mdoc_sp_pre, NULL}, /* br */ {mdoc_sp_pre, NULL}, /* sp */ {mdoc__x_pre, mdoc__x_post}, /* %U */ {NULL, NULL}, /* Ta */ {mdoc_skip_pre, NULL}, /* ll */ }; -static const char * const lists[LIST_MAX] = { - NULL, - "list-bul", - "list-col", - "list-dash", - "list-diag", - "list-enum", - "list-hang", - "list-hyph", - "list-inset", - "list-item", - "list-ohang", - "list-tag" -}; - /* - * Calculate the scaling unit passed in a `-width' argument. This uses - * either a native scaling unit (e.g., 1i, 2m) or the string length of - * the value. - */ -static void -a2width(const char *p, struct roffsu *su) -{ - - if (a2roffsu(p, su, SCALE_MAX) < 2) { - su->unit = SCALE_EN; - su->scale = html_strlen(p); - } else if (su->scale < 0.0) - su->scale = 0.0; -} - -/* * See the same function in mdoc_term.c for documentation. */ static void synopsis_pre(struct html *h, const struct roff_node *n) { - if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags)) + if (NULL == n->prev || ! (NODE_SYNPRETTY & n->flags)) return; if (n->prev->tok == n->tok && MDOC_Fo != n->tok && MDOC_Ft != n->tok && MDOC_Fn != n->tok) { - print_otag(h, TAG_BR, 0, NULL); + print_otag(h, TAG_BR, ""); return; } switch (n->prev->tok) { case MDOC_Fd: case MDOC_Fn: case MDOC_Fo: case MDOC_In: case MDOC_Vt: print_paragraph(h); break; case MDOC_Ft: if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) { print_paragraph(h); break; } /* FALLTHROUGH */ default: - print_otag(h, TAG_BR, 0, NULL); + print_otag(h, TAG_BR, ""); break; } } void html_mdoc(void *arg, const struct roff_man *mdoc) { - struct htmlpair tag; struct html *h; - struct tag *t, *tt; + struct tag *t; - PAIR_CLASS_INIT(&tag, "mandoc"); h = (struct html *)arg; - if ( ! (HTML_FRAGMENT & h->oflags)) { + if ((h->oflags & HTML_FRAGMENT) == 0) { print_gen_decls(h); - t = print_otag(h, TAG_HTML, 0, NULL); - tt = print_otag(h, TAG_HEAD, 0, NULL); + print_otag(h, TAG_HTML, ""); + t = print_otag(h, TAG_HEAD, ""); print_mdoc_head(&mdoc->meta, mdoc->first->child, h); - print_tagq(h, tt); - print_otag(h, TAG_BODY, 0, NULL); - print_otag(h, TAG_DIV, 1, &tag); - } else - t = print_otag(h, TAG_DIV, 1, &tag); + print_tagq(h, t); + print_otag(h, TAG_BODY, ""); + } mdoc_root_pre(&mdoc->meta, mdoc->first->child, h); + t = print_otag(h, TAG_DIV, "c", "manual-text"); print_mdoc_nodelist(&mdoc->meta, mdoc->first->child, h); - mdoc_root_post(&mdoc->meta, mdoc->first->child, h); print_tagq(h, t); - putchar('\n'); + mdoc_root_post(&mdoc->meta, mdoc->first->child, h); + print_tagq(h, NULL); } static void print_mdoc_head(MDOC_ARGS) { + char *cp; print_gen_head(h); - bufinit(h); - bufcat(h, meta->title); - if (meta->msec) - bufcat_fmt(h, "(%s)", meta->msec); - if (meta->arch) - bufcat_fmt(h, " (%s)", meta->arch); - print_otag(h, TAG_TITLE, 0, NULL); - print_text(h, h->buf); + if (meta->arch != NULL && meta->msec != NULL) + mandoc_asprintf(&cp, "%s(%s) (%s)", meta->title, + meta->msec, meta->arch); + else if (meta->msec != NULL) + mandoc_asprintf(&cp, "%s(%s)", meta->title, meta->msec); + else if (meta->arch != NULL) + mandoc_asprintf(&cp, "%s (%s)", meta->title, meta->arch); + else + cp = mandoc_strdup(meta->title); + + print_otag(h, TAG_TITLE, ""); + print_text(h, cp); + free(cp); } static void print_mdoc_nodelist(MDOC_ARGS) { while (n != NULL) { print_mdoc_node(meta, n, h); n = n->next; } } static void print_mdoc_node(MDOC_ARGS) { int child; struct tag *t; + if (n->flags & NODE_NOPRT) + return; + child = 1; t = h->tags.head; - n->flags &= ~MDOC_ENDED; + n->flags &= ~NODE_ENDED; switch (n->type) { case ROFFT_TEXT: /* No tables in this mode... */ assert(NULL == h->tblt); /* * Make sure that if we're in a literal mode already * (i.e., within a
) don't print the newline.
 		 */
-		if (' ' == *n->string && MDOC_LINE & n->flags)
+		if (' ' == *n->string && NODE_LINE & n->flags)
 			if ( ! (HTML_LITERAL & h->flags))
-				print_otag(h, TAG_BR, 0, NULL);
-		if (MDOC_DELIMC & n->flags)
+				print_otag(h, TAG_BR, "");
+		if (NODE_DELIMC & n->flags)
 			h->flags |= HTML_NOSPACE;
 		print_text(h, n->string);
-		if (MDOC_DELIMO & n->flags)
+		if (NODE_DELIMO & n->flags)
 			h->flags |= HTML_NOSPACE;
 		return;
 	case ROFFT_EQN:
-		if (n->flags & MDOC_LINE)
-			putchar('\n');
 		print_eqn(h, n->eqn);
 		break;
 	case ROFFT_TBL:
 		/*
 		 * This will take care of initialising all of the table
 		 * state data for the first table, then tearing it down
 		 * for the last one.
 		 */
 		print_tbl(h, n->span);
 		return;
 	default:
 		/*
 		 * Close out the current table, if it's open, and unset
 		 * the "meta" table state.  This will be reopened on the
 		 * next table element.
 		 */
 		if (h->tblt != NULL) {
 			print_tblclose(h);
 			t = h->tags.head;
 		}
 		assert(h->tblt == NULL);
 		if (mdocs[n->tok].pre && (n->end == ENDBODY_NOT || n->child))
 			child = (*mdocs[n->tok].pre)(meta, n, h);
 		break;
 	}
 
-	if (h->flags & HTML_KEEP && n->flags & MDOC_LINE) {
+	if (h->flags & HTML_KEEP && n->flags & NODE_LINE) {
 		h->flags &= ~HTML_KEEP;
 		h->flags |= HTML_PREKEEP;
 	}
 
 	if (child && n->child)
 		print_mdoc_nodelist(meta, n->child, h);
 
 	print_stagq(h, t);
 
 	switch (n->type) {
 	case ROFFT_EQN:
 		break;
 	default:
-		if ( ! mdocs[n->tok].post || n->flags & MDOC_ENDED)
+		if ( ! mdocs[n->tok].post || n->flags & NODE_ENDED)
 			break;
 		(*mdocs[n->tok].post)(meta, n, h);
 		if (n->end != ENDBODY_NOT)
-			n->body->flags |= MDOC_ENDED;
+			n->body->flags |= NODE_ENDED;
 		if (n->end == ENDBODY_NOSPACE)
 			h->flags |= HTML_NOSPACE;
 		break;
 	}
 }
 
 static void
 mdoc_root_post(MDOC_ARGS)
 {
-	struct htmlpair	 tag;
 	struct tag	*t, *tt;
 
-	PAIR_CLASS_INIT(&tag, "foot");
-	t = print_otag(h, TAG_TABLE, 1, &tag);
+	t = print_otag(h, TAG_TABLE, "c", "foot");
+	print_otag(h, TAG_TBODY, "");
+	tt = print_otag(h, TAG_TR, "");
 
-	print_otag(h, TAG_TBODY, 0, NULL);
-
-	tt = print_otag(h, TAG_TR, 0, NULL);
-
-	PAIR_CLASS_INIT(&tag, "foot-date");
-	print_otag(h, TAG_TD, 1, &tag);
+	print_otag(h, TAG_TD, "c", "foot-date");
 	print_text(h, meta->date);
 	print_stagq(h, tt);
 
-	PAIR_CLASS_INIT(&tag, "foot-os");
-	print_otag(h, TAG_TD, 1, &tag);
+	print_otag(h, TAG_TD, "c", "foot-os");
 	print_text(h, meta->os);
 	print_tagq(h, t);
 }
 
 static int
 mdoc_root_pre(MDOC_ARGS)
 {
-	struct htmlpair	 tag;
 	struct tag	*t, *tt;
 	char		*volume, *title;
 
 	if (NULL == meta->arch)
 		volume = mandoc_strdup(meta->vol);
 	else
 		mandoc_asprintf(&volume, "%s (%s)",
 		    meta->vol, meta->arch);
 
 	if (NULL == meta->msec)
 		title = mandoc_strdup(meta->title);
 	else
 		mandoc_asprintf(&title, "%s(%s)",
 		    meta->title, meta->msec);
 
-	PAIR_CLASS_INIT(&tag, "head");
-	t = print_otag(h, TAG_TABLE, 1, &tag);
+	t = print_otag(h, TAG_TABLE, "c", "head");
+	print_otag(h, TAG_TBODY, "");
+	tt = print_otag(h, TAG_TR, "");
 
-	print_otag(h, TAG_TBODY, 0, NULL);
-
-	tt = print_otag(h, TAG_TR, 0, NULL);
-
-	PAIR_CLASS_INIT(&tag, "head-ltitle");
-	print_otag(h, TAG_TD, 1, &tag);
+	print_otag(h, TAG_TD, "c", "head-ltitle");
 	print_text(h, title);
 	print_stagq(h, tt);
 
-	PAIR_CLASS_INIT(&tag, "head-vol");
-	print_otag(h, TAG_TD, 1, &tag);
+	print_otag(h, TAG_TD, "c", "head-vol");
 	print_text(h, volume);
 	print_stagq(h, tt);
 
-	PAIR_CLASS_INIT(&tag, "head-rtitle");
-	print_otag(h, TAG_TD, 1, &tag);
+	print_otag(h, TAG_TD, "c", "head-rtitle");
 	print_text(h, title);
 	print_tagq(h, t);
 
 	free(title);
 	free(volume);
 	return 1;
 }
 
+static char *
+make_id(const struct roff_node *n)
+{
+	const struct roff_node	*nch;
+	char			*buf, *cp;
+
+	for (nch = n->child; nch != NULL; nch = nch->next)
+		if (nch->type != ROFFT_TEXT)
+			return NULL;
+
+	buf = NULL;
+	deroff(&buf, n);
+
+	/* http://www.w3.org/TR/html5/dom.html#the-id-attribute */
+
+	for (cp = buf; *cp != '\0'; cp++)
+		if (*cp == ' ')
+			*cp = '_';
+
+	return buf;
+}
+
 static int
 mdoc_sh_pre(MDOC_ARGS)
 {
-	struct htmlpair	 tag;
+	char	*id;
 
 	switch (n->type) {
 	case ROFFT_BLOCK:
-		PAIR_CLASS_INIT(&tag, "section");
-		print_otag(h, TAG_DIV, 1, &tag);
 		return 1;
 	case ROFFT_BODY:
 		if (n->sec == SEC_AUTHORS)
 			h->flags &= ~(HTML_SPLIT|HTML_NOSPLIT);
 		return 1;
 	default:
 		break;
 	}
 
-	bufinit(h);
-
-	for (n = n->child; n != NULL && n->type == ROFFT_TEXT; ) {
-		bufcat_id(h, n->string);
-		if (NULL != (n = n->next))
-			bufcat_id(h, " ");
-	}
-
-	if (NULL == n) {
-		PAIR_ID_INIT(&tag, h->buf);
-		print_otag(h, TAG_H1, 1, &tag);
+	if ((id = make_id(n)) != NULL) {
+		print_otag(h, TAG_H1, "ci", "Sh", id);
+		free(id);
 	} else
-		print_otag(h, TAG_H1, 0, NULL);
+		print_otag(h, TAG_H1, "c", "Sh");
 
 	return 1;
 }
 
 static int
 mdoc_ss_pre(MDOC_ARGS)
 {
-	struct htmlpair	 tag;
+	char	*id;
 
-	if (n->type == ROFFT_BLOCK) {
-		PAIR_CLASS_INIT(&tag, "subsection");
-		print_otag(h, TAG_DIV, 1, &tag);
+	if (n->type != ROFFT_HEAD)
 		return 1;
-	} else if (n->type == ROFFT_BODY)
-		return 1;
 
-	bufinit(h);
-
-	for (n = n->child; n != NULL && n->type == ROFFT_TEXT; ) {
-		bufcat_id(h, n->string);
-		if (NULL != (n = n->next))
-			bufcat_id(h, " ");
-	}
-
-	if (NULL == n) {
-		PAIR_ID_INIT(&tag, h->buf);
-		print_otag(h, TAG_H2, 1, &tag);
+	if ((id = make_id(n)) != NULL) {
+		print_otag(h, TAG_H2, "ci", "Ss", id);
+		free(id);
 	} else
-		print_otag(h, TAG_H2, 0, NULL);
+		print_otag(h, TAG_H2, "c", "Ss");
 
 	return 1;
 }
 
 static int
 mdoc_fl_pre(MDOC_ARGS)
 {
-	struct htmlpair	 tag;
-
-	PAIR_CLASS_INIT(&tag, "flag");
-	print_otag(h, TAG_B, 1, &tag);
-
-	/* `Cm' has no leading hyphen. */
-
-	if (MDOC_Cm == n->tok)
-		return 1;
-
+	print_otag(h, TAG_B, "c", "Fl");
 	print_text(h, "\\-");
 
 	if (!(n->child == NULL &&
 	    (n->next == NULL ||
 	     n->next->type == ROFFT_TEXT ||
-	     n->next->flags & MDOC_LINE)))
+	     n->next->flags & NODE_LINE)))
 		h->flags |= HTML_NOSPACE;
 
 	return 1;
 }
 
 static int
-mdoc_nd_pre(MDOC_ARGS)
+mdoc_cm_pre(MDOC_ARGS)
 {
-	struct htmlpair	 tag;
+	print_otag(h, TAG_B, "c", "Cm");
+	return 1;
+}
 
+static int
+mdoc_nd_pre(MDOC_ARGS)
+{
 	if (n->type != ROFFT_BODY)
 		return 1;
 
 	/* XXX: this tag in theory can contain block elements. */
 
 	print_text(h, "\\(em");
-	PAIR_CLASS_INIT(&tag, "desc");
-	print_otag(h, TAG_SPAN, 1, &tag);
+	print_otag(h, TAG_SPAN, "c", "Nd");
 	return 1;
 }
 
 static int
 mdoc_nm_pre(MDOC_ARGS)
 {
-	struct htmlpair	 tag;
-	struct roffsu	 su;
 	int		 len;
 
 	switch (n->type) {
 	case ROFFT_HEAD:
-		print_otag(h, TAG_TD, 0, NULL);
+		print_otag(h, TAG_TD, "");
 		/* FALLTHROUGH */
 	case ROFFT_ELEM:
-		PAIR_CLASS_INIT(&tag, "name");
-		print_otag(h, TAG_B, 1, &tag);
+		print_otag(h, TAG_B, "c", "Nm");
 		if (n->child == NULL && meta->name != NULL)
 			print_text(h, meta->name);
 		return 1;
 	case ROFFT_BODY:
-		print_otag(h, TAG_TD, 0, NULL);
+		print_otag(h, TAG_TD, "");
 		return 1;
 	default:
 		break;
 	}
 
 	synopsis_pre(h, n);
-	PAIR_CLASS_INIT(&tag, "synopsis");
-	print_otag(h, TAG_TABLE, 1, &tag);
+	print_otag(h, TAG_TABLE, "c", "Nm");
 
 	for (len = 0, n = n->head->child; n; n = n->next)
 		if (n->type == ROFFT_TEXT)
 			len += html_strlen(n->string);
 
 	if (len == 0 && meta->name != NULL)
 		len = html_strlen(meta->name);
 
-	SCALE_HS_INIT(&su, len);
-	bufinit(h);
-	bufcat_su(h, "width", &su);
-	PAIR_STYLE_INIT(&tag, h);
-	print_otag(h, TAG_COL, 1, &tag);
-	print_otag(h, TAG_COL, 0, NULL);
-	print_otag(h, TAG_TBODY, 0, NULL);
-	print_otag(h, TAG_TR, 0, NULL);
+	print_otag(h, TAG_COL, "shw", len);
+	print_otag(h, TAG_COL, "");
+	print_otag(h, TAG_TBODY, "");
+	print_otag(h, TAG_TR, "");
 	return 1;
 }
 
 static int
 mdoc_xr_pre(MDOC_ARGS)
 {
-	struct htmlpair	 tag[2];
-
 	if (NULL == n->child)
 		return 0;
 
-	PAIR_CLASS_INIT(&tag[0], "link-man");
+	if (h->base_man)
+		print_otag(h, TAG_A, "chM", "Xr",
+		    n->child->string, n->child->next == NULL ?
+		    NULL : n->child->next->string);
+	else
+		print_otag(h, TAG_A, "c", "Xr");
 
-	if (h->base_man) {
-		buffmt_man(h, n->child->string,
-		    n->child->next ?
-		    n->child->next->string : NULL);
-		PAIR_HREF_INIT(&tag[1], h->buf);
-		print_otag(h, TAG_A, 2, tag);
-	} else
-		print_otag(h, TAG_A, 1, tag);
-
 	n = n->child;
 	print_text(h, n->string);
 
 	if (NULL == (n = n->next))
 		return 0;
 
 	h->flags |= HTML_NOSPACE;
 	print_text(h, "(");
 	h->flags |= HTML_NOSPACE;
 	print_text(h, n->string);
 	h->flags |= HTML_NOSPACE;
 	print_text(h, ")");
 	return 0;
 }
 
 static int
 mdoc_ns_pre(MDOC_ARGS)
 {
 
-	if ( ! (MDOC_LINE & n->flags))
+	if ( ! (NODE_LINE & n->flags))
 		h->flags |= HTML_NOSPACE;
 	return 1;
 }
 
 static int
 mdoc_ar_pre(MDOC_ARGS)
 {
-	struct htmlpair tag;
-
-	PAIR_CLASS_INIT(&tag, "arg");
-	print_otag(h, TAG_I, 1, &tag);
+	print_otag(h, TAG_I, "c", "Ar");
 	return 1;
 }
 
 static int
 mdoc_xx_pre(MDOC_ARGS)
 {
-	const char	*pp;
-	struct htmlpair	 tag;
-	int		 flags;
-
-	switch (n->tok) {
-	case MDOC_Bsx:
-		pp = "BSD/OS";
-		break;
-	case MDOC_Dx:
-		pp = "DragonFly";
-		break;
-	case MDOC_Fx:
-		pp = "FreeBSD";
-		break;
-	case MDOC_Nx:
-		pp = "NetBSD";
-		break;
-	case MDOC_Ox:
-		pp = "OpenBSD";
-		break;
-	case MDOC_Ux:
-		pp = "UNIX";
-		break;
-	default:
-		return 1;
-	}
-
-	PAIR_CLASS_INIT(&tag, "unix");
-	print_otag(h, TAG_SPAN, 1, &tag);
-
-	print_text(h, pp);
-	if (n->child) {
-		flags = h->flags;
-		h->flags |= HTML_KEEP;
-		print_text(h, n->child->string);
-		h->flags = flags;
-	}
-	return 0;
+	print_otag(h, TAG_SPAN, "c", "Ux");
+	return 1;
 }
 
 static int
-mdoc_bx_pre(MDOC_ARGS)
-{
-	struct htmlpair	 tag;
-
-	PAIR_CLASS_INIT(&tag, "unix");
-	print_otag(h, TAG_SPAN, 1, &tag);
-
-	if (NULL != (n = n->child)) {
-		print_text(h, n->string);
-		h->flags |= HTML_NOSPACE;
-		print_text(h, "BSD");
-	} else {
-		print_text(h, "BSD");
-		return 0;
-	}
-
-	if (NULL != (n = n->next)) {
-		h->flags |= HTML_NOSPACE;
-		print_text(h, "-");
-		h->flags |= HTML_NOSPACE;
-		print_text(h, n->string);
-	}
-
-	return 0;
-}
-
-static int
 mdoc_it_pre(MDOC_ARGS)
 {
-	struct roffsu	 su;
-	enum mdoc_list	 type;
-	struct htmlpair	 tag[2];
-	const struct roff_node *bl;
+	const struct roff_node	*bl;
+	const char		*cattr;
+	enum mdoc_list		 type;
 
 	bl = n->parent;
-	while (bl && MDOC_Bl != bl->tok)
+	while (bl != NULL && bl->tok != MDOC_Bl)
 		bl = bl->parent;
-
-	assert(bl);
-
 	type = bl->norm->Bl.type;
 
-	assert(lists[type]);
-	PAIR_CLASS_INIT(&tag[0], lists[type]);
+	switch (type) {
+	case LIST_bullet:
+		cattr = "It-bullet";
+		break;
+	case LIST_dash:
+	case LIST_hyphen:
+		cattr = "It-dash";
+		break;
+	case LIST_item:
+		cattr = "It-item";
+		break;
+	case LIST_enum:
+		cattr = "It-enum";
+		break;
+	case LIST_diag:
+		cattr = "It-diag";
+		break;
+	case LIST_hang:
+		cattr = "It-hang";
+		break;
+	case LIST_inset:
+		cattr = "It-inset";
+		break;
+	case LIST_ohang:
+		cattr = "It-ohang";
+		break;
+	case LIST_tag:
+		cattr = "It-tag";
+		break;
+	case LIST_column:
+		cattr = "It-column";
+		break;
+	default:
+		break;
+	}
 
-	bufinit(h);
-
-	if (n->type == ROFFT_HEAD) {
-		switch (type) {
-		case LIST_bullet:
-		case LIST_dash:
-		case LIST_item:
-		case LIST_hyphen:
-		case LIST_enum:
+	switch (type) {
+	case LIST_bullet:
+	case LIST_dash:
+	case LIST_hyphen:
+	case LIST_item:
+	case LIST_enum:
+		switch (n->type) {
+		case ROFFT_HEAD:
 			return 0;
-		case LIST_diag:
-		case LIST_hang:
-		case LIST_inset:
-		case LIST_ohang:
-		case LIST_tag:
-			SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
-			bufcat_su(h, "margin-top", &su);
-			PAIR_STYLE_INIT(&tag[1], h);
-			print_otag(h, TAG_DT, 2, tag);
-			if (LIST_diag != type)
-				break;
-			PAIR_CLASS_INIT(&tag[0], "diag");
-			print_otag(h, TAG_B, 1, tag);
+		case ROFFT_BODY:
+			if (bl->norm->Bl.comp)
+				print_otag(h, TAG_LI, "csvt", cattr, 0);
+			else
+				print_otag(h, TAG_LI, "c", cattr);
 			break;
-		case LIST_column:
-			break;
 		default:
 			break;
 		}
-	} else if (n->type == ROFFT_BODY) {
-		switch (type) {
-		case LIST_bullet:
-		case LIST_hyphen:
-		case LIST_dash:
-		case LIST_enum:
-		case LIST_item:
-			SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
-			bufcat_su(h, "margin-top", &su);
-			PAIR_STYLE_INIT(&tag[1], h);
-			print_otag(h, TAG_LI, 2, tag);
+		break;
+	case LIST_diag:
+	case LIST_hang:
+	case LIST_inset:
+	case LIST_ohang:
+	case LIST_tag:
+		switch (n->type) {
+		case ROFFT_HEAD:
+			if (bl->norm->Bl.comp)
+				print_otag(h, TAG_DT, "csvt", cattr, 0);
+			else
+				print_otag(h, TAG_DT, "c", cattr);
+			if (type == LIST_diag)
+				print_otag(h, TAG_B, "c", cattr);
 			break;
-		case LIST_diag:
-		case LIST_hang:
-		case LIST_inset:
-		case LIST_ohang:
-		case LIST_tag:
-			if (NULL == bl->norm->Bl.width) {
-				print_otag(h, TAG_DD, 1, tag);
-				break;
-			}
-			a2width(bl->norm->Bl.width, &su);
-			bufcat_su(h, "margin-left", &su);
-			PAIR_STYLE_INIT(&tag[1], h);
-			print_otag(h, TAG_DD, 2, tag);
+		case ROFFT_BODY:
+			if (bl->norm->Bl.width == NULL)
+				print_otag(h, TAG_DD, "c", cattr);
+			else
+				print_otag(h, TAG_DD, "cswl", cattr,
+				    bl->norm->Bl.width);
 			break;
-		case LIST_column:
-			SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
-			bufcat_su(h, "margin-top", &su);
-			PAIR_STYLE_INIT(&tag[1], h);
-			print_otag(h, TAG_TD, 2, tag);
-			break;
 		default:
 			break;
 		}
-	} else {
-		switch (type) {
-		case LIST_column:
-			print_otag(h, TAG_TR, 1, tag);
+		break;
+	case LIST_column:
+		switch (n->type) {
+		case ROFFT_HEAD:
 			break;
-		default:
+		case ROFFT_BODY:
+			if (bl->norm->Bl.comp)
+				print_otag(h, TAG_TD, "csvt", cattr, 0);
+			else
+				print_otag(h, TAG_TD, "c", cattr);
 			break;
+		default:
+			print_otag(h, TAG_TR, "c", cattr);
 		}
+	default:
+		break;
 	}
 
 	return 1;
 }
 
 static int
 mdoc_bl_pre(MDOC_ARGS)
 {
+	const char	*cattr;
 	int		 i;
-	struct htmlpair	 tag[3];
-	struct roffsu	 su;
-	char		 buf[BUFSIZ];
+	enum htmltag	 elemtype;
 
 	if (n->type == ROFFT_BODY) {
 		if (LIST_column == n->norm->Bl.type)
-			print_otag(h, TAG_TBODY, 0, NULL);
+			print_otag(h, TAG_TBODY, "");
 		return 1;
 	}
 
 	if (n->type == ROFFT_HEAD) {
 		if (LIST_column != n->norm->Bl.type)
 			return 0;
 
 		/*
 		 * For each column, print out the  tag with our
 		 * suggested width.  The last column gets min-width, as
 		 * in terminal mode it auto-sizes to the width of the
 		 * screen and we want to preserve that behaviour.
 		 */
 
-		for (i = 0; i < (int)n->norm->Bl.ncols; i++) {
-			bufinit(h);
-			a2width(n->norm->Bl.cols[i], &su);
-			if (i < (int)n->norm->Bl.ncols - 1)
-				bufcat_su(h, "width", &su);
-			else
-				bufcat_su(h, "min-width", &su);
-			PAIR_STYLE_INIT(&tag[0], h);
-			print_otag(h, TAG_COL, 1, tag);
-		}
+		for (i = 0; i < (int)n->norm->Bl.ncols - 1; i++)
+			print_otag(h, TAG_COL, "sww", n->norm->Bl.cols[i]);
+		print_otag(h, TAG_COL, "swW", n->norm->Bl.cols[i]);
 
 		return 0;
 	}
 
-	SCALE_VS_INIT(&su, 0);
-	bufinit(h);
-	bufcat_su(h, "margin-top", &su);
-	bufcat_su(h, "margin-bottom", &su);
-	PAIR_STYLE_INIT(&tag[0], h);
-
-	assert(lists[n->norm->Bl.type]);
-	(void)strlcpy(buf, "list ", BUFSIZ);
-	(void)strlcat(buf, lists[n->norm->Bl.type], BUFSIZ);
-	PAIR_INIT(&tag[1], ATTR_CLASS, buf);
-
-	/* Set the block's left-hand margin. */
-
-	if (n->norm->Bl.offs) {
-		a2width(n->norm->Bl.offs, &su);
-		bufcat_su(h, "margin-left", &su);
-	}
-
 	switch (n->norm->Bl.type) {
 	case LIST_bullet:
+		elemtype = TAG_UL;
+		cattr = "Bl-bullet";
+		break;
 	case LIST_dash:
 	case LIST_hyphen:
+		elemtype = TAG_UL;
+		cattr = "Bl-dash";
+		break;
 	case LIST_item:
-		print_otag(h, TAG_UL, 2, tag);
+		elemtype = TAG_UL;
+		cattr = "Bl-item";
 		break;
 	case LIST_enum:
-		print_otag(h, TAG_OL, 2, tag);
+		elemtype = TAG_OL;
+		cattr = "Bl-enum";
 		break;
 	case LIST_diag:
+		elemtype = TAG_DL;
+		cattr = "Bl-diag";
+		break;
 	case LIST_hang:
+		elemtype = TAG_DL;
+		cattr = "Bl-hang";
+		break;
 	case LIST_inset:
+		elemtype = TAG_DL;
+		cattr = "Bl-inset";
+		break;
 	case LIST_ohang:
+		elemtype = TAG_DL;
+		cattr = "Bl-ohang";
+		break;
 	case LIST_tag:
-		print_otag(h, TAG_DL, 2, tag);
+		elemtype = TAG_DL;
+		cattr = "Bl-tag";
 		break;
 	case LIST_column:
-		print_otag(h, TAG_TABLE, 2, tag);
+		elemtype = TAG_TABLE;
+		cattr = "Bl-column";
 		break;
 	default:
 		abort();
 	}
 
+	if (n->norm->Bl.offs)
+		print_otag(h, elemtype, "cswl", cattr, n->norm->Bl.offs);
+	else
+		print_otag(h, elemtype, "c", cattr);
+
 	return 1;
 }
 
 static int
 mdoc_ex_pre(MDOC_ARGS)
 {
-	struct htmlpair	  tag;
-	struct tag	 *t;
-	struct roff_node *nch;
-
 	if (n->prev)
-		print_otag(h, TAG_BR, 0, NULL);
-
-	PAIR_CLASS_INIT(&tag, "utility");
-
-	print_text(h, "The");
-
-	for (nch = n->child; nch != NULL; nch = nch->next) {
-		assert(nch->type == ROFFT_TEXT);
-
-		t = print_otag(h, TAG_B, 1, &tag);
-		print_text(h, nch->string);
-		print_tagq(h, t);
-
-		if (nch->next == NULL)
-			continue;
-
-		if (nch->prev != NULL || nch->next->next != NULL) {
-			h->flags |= HTML_NOSPACE;
-			print_text(h, ",");
-		}
-
-		if (nch->next->next == NULL)
-			print_text(h, "and");
-	}
-
-	if (n->child != NULL && n->child->next != NULL)
-		print_text(h, "utilities exit\\~0");
-	else
-		print_text(h, "utility exits\\~0");
-
-	print_text(h, "on success, and\\~>0 if an error occurs.");
-	return 0;
+		print_otag(h, TAG_BR, "");
+	return 1;
 }
 
 static int
 mdoc_em_pre(MDOC_ARGS)
 {
-	struct htmlpair	tag;
-
-	PAIR_CLASS_INIT(&tag, "emph");
-	print_otag(h, TAG_SPAN, 1, &tag);
+	print_otag(h, TAG_I, "c", "Em");
 	return 1;
 }
 
 static int
 mdoc_d1_pre(MDOC_ARGS)
 {
-	struct htmlpair	 tag[2];
-	struct roffsu	 su;
-
 	if (n->type != ROFFT_BLOCK)
 		return 1;
 
-	SCALE_VS_INIT(&su, 0);
-	bufinit(h);
-	bufcat_su(h, "margin-top", &su);
-	bufcat_su(h, "margin-bottom", &su);
-	PAIR_STYLE_INIT(&tag[0], h);
-	print_otag(h, TAG_BLOCKQUOTE, 1, tag);
+	print_otag(h, TAG_DIV, "c", "D1");
 
-	/* BLOCKQUOTE needs a block body. */
+	if (n->tok == MDOC_Dl)
+		print_otag(h, TAG_CODE, "c", "Li");
 
-	PAIR_CLASS_INIT(&tag[0], "display");
-	print_otag(h, TAG_DIV, 1, tag);
-
-	if (MDOC_Dl == n->tok) {
-		PAIR_CLASS_INIT(&tag[0], "lit");
-		print_otag(h, TAG_CODE, 1, tag);
-	}
-
 	return 1;
 }
 
 static int
 mdoc_sx_pre(MDOC_ARGS)
 {
-	struct htmlpair	 tag[2];
+	char	*id;
 
-	bufinit(h);
-	bufcat(h, "#");
+	if ((id = make_id(n)) != NULL) {
+		print_otag(h, TAG_A, "chR", "Sx", id);
+		free(id);
+	} else
+		print_otag(h, TAG_A, "c", "Sx");
 
-	for (n = n->child; n; ) {
-		bufcat_id(h, n->string);
-		if (NULL != (n = n->next))
-			bufcat_id(h, " ");
-	}
-
-	PAIR_CLASS_INIT(&tag[0], "link-sec");
-	PAIR_HREF_INIT(&tag[1], h->buf);
-
-	print_otag(h, TAG_I, 1, tag);
-	print_otag(h, TAG_A, 2, tag);
 	return 1;
 }
 
 static int
 mdoc_bd_pre(MDOC_ARGS)
 {
-	struct htmlpair		 tag[2];
-	int			 comp, sv;
+	int			 comp, offs, sv;
 	struct roff_node	*nn;
-	struct roffsu		 su;
 
 	if (n->type == ROFFT_HEAD)
 		return 0;
 
 	if (n->type == ROFFT_BLOCK) {
 		comp = n->norm->Bd.comp;
 		for (nn = n; nn && ! comp; nn = nn->parent) {
 			if (nn->type != ROFFT_BLOCK)
 				continue;
 			if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
 				comp = 1;
 			if (nn->prev)
 				break;
 		}
 		if ( ! comp)
 			print_paragraph(h);
 		return 1;
 	}
 
 	/* Handle the -offset argument. */
 
 	if (n->norm->Bd.offs == NULL ||
 	    ! strcmp(n->norm->Bd.offs, "left"))
-		SCALE_HS_INIT(&su, 0);
+		offs = 0;
 	else if ( ! strcmp(n->norm->Bd.offs, "indent"))
-		SCALE_HS_INIT(&su, INDENT);
+		offs = INDENT;
 	else if ( ! strcmp(n->norm->Bd.offs, "indent-two"))
-		SCALE_HS_INIT(&su, INDENT * 2);
+		offs = INDENT * 2;
 	else
-		a2width(n->norm->Bd.offs, &su);
+		offs = -1;
 
-	bufinit(h);
-	bufcat_su(h, "margin-left", &su);
-	PAIR_STYLE_INIT(&tag[0], h);
+	if (offs == -1)
+		print_otag(h, TAG_DIV, "cswl", "Bd", n->norm->Bd.offs);
+	else
+		print_otag(h, TAG_DIV, "cshl", "Bd", offs);
 
-	if (DISP_unfilled != n->norm->Bd.type &&
-	    DISP_literal != n->norm->Bd.type) {
-		PAIR_CLASS_INIT(&tag[1], "display");
-		print_otag(h, TAG_DIV, 2, tag);
+	if (n->norm->Bd.type != DISP_unfilled &&
+	    n->norm->Bd.type != DISP_literal)
 		return 1;
-	}
 
-	PAIR_CLASS_INIT(&tag[1], "lit display");
-	print_otag(h, TAG_PRE, 2, tag);
+	print_otag(h, TAG_PRE, "c", "Li");
 
 	/* This can be recursive: save & set our literal state. */
 
 	sv = h->flags & HTML_LITERAL;
 	h->flags |= HTML_LITERAL;
 
 	for (nn = n->child; nn; nn = nn->next) {
 		print_mdoc_node(meta, nn, h);
 		/*
 		 * If the printed node flushes its own line, then we
 		 * needn't do it here as well.  This is hacky, but the
 		 * notion of selective eoln whitespace is pretty dumb
 		 * anyway, so don't sweat it.
 		 */
 		switch (nn->tok) {
 		case MDOC_Sm:
 		case MDOC_br:
 		case MDOC_sp:
 		case MDOC_Bl:
 		case MDOC_D1:
 		case MDOC_Dl:
 		case MDOC_Lp:
 		case MDOC_Pp:
 			continue;
 		default:
 			break;
 		}
 		if (h->flags & HTML_NONEWLINE ||
-		    (nn->next && ! (nn->next->flags & MDOC_LINE)))
+		    (nn->next && ! (nn->next->flags & NODE_LINE)))
 			continue;
 		else if (nn->next)
 			print_text(h, "\n");
 
 		h->flags |= HTML_NOSPACE;
 	}
 
 	if (0 == sv)
 		h->flags &= ~HTML_LITERAL;
 
 	return 0;
 }
 
 static int
 mdoc_pa_pre(MDOC_ARGS)
 {
-	struct htmlpair	tag;
-
-	PAIR_CLASS_INIT(&tag, "file");
-	print_otag(h, TAG_I, 1, &tag);
+	print_otag(h, TAG_I, "c", "Pa");
 	return 1;
 }
 
 static int
 mdoc_ad_pre(MDOC_ARGS)
 {
-	struct htmlpair	tag;
-
-	PAIR_CLASS_INIT(&tag, "addr");
-	print_otag(h, TAG_I, 1, &tag);
+	print_otag(h, TAG_I, "c", "Ad");
 	return 1;
 }
 
 static int
 mdoc_an_pre(MDOC_ARGS)
 {
-	struct htmlpair	tag;
-
 	if (n->norm->An.auth == AUTH_split) {
 		h->flags &= ~HTML_NOSPLIT;
 		h->flags |= HTML_SPLIT;
 		return 0;
 	}
 	if (n->norm->An.auth == AUTH_nosplit) {
 		h->flags &= ~HTML_SPLIT;
 		h->flags |= HTML_NOSPLIT;
 		return 0;
 	}
 
 	if (h->flags & HTML_SPLIT)
-		print_otag(h, TAG_BR, 0, NULL);
+		print_otag(h, TAG_BR, "");
 
 	if (n->sec == SEC_AUTHORS && ! (h->flags & HTML_NOSPLIT))
 		h->flags |= HTML_SPLIT;
 
-	PAIR_CLASS_INIT(&tag, "author");
-	print_otag(h, TAG_SPAN, 1, &tag);
+	print_otag(h, TAG_SPAN, "c", "An");
 	return 1;
 }
 
 static int
 mdoc_cd_pre(MDOC_ARGS)
 {
-	struct htmlpair	tag;
-
 	synopsis_pre(h, n);
-	PAIR_CLASS_INIT(&tag, "config");
-	print_otag(h, TAG_B, 1, &tag);
+	print_otag(h, TAG_B, "c", "Cd");
 	return 1;
 }
 
 static int
 mdoc_dv_pre(MDOC_ARGS)
 {
-	struct htmlpair	tag;
-
-	PAIR_CLASS_INIT(&tag, "define");
-	print_otag(h, TAG_SPAN, 1, &tag);
+	print_otag(h, TAG_CODE, "c", "Dv");
 	return 1;
 }
 
 static int
 mdoc_ev_pre(MDOC_ARGS)
 {
-	struct htmlpair	tag;
-
-	PAIR_CLASS_INIT(&tag, "env");
-	print_otag(h, TAG_SPAN, 1, &tag);
+	print_otag(h, TAG_CODE, "c", "Ev");
 	return 1;
 }
 
 static int
 mdoc_er_pre(MDOC_ARGS)
 {
-	struct htmlpair	tag;
-
-	PAIR_CLASS_INIT(&tag, "errno");
-	print_otag(h, TAG_SPAN, 1, &tag);
+	print_otag(h, TAG_CODE, "c", "Er");
 	return 1;
 }
 
 static int
 mdoc_fa_pre(MDOC_ARGS)
 {
 	const struct roff_node	*nn;
-	struct htmlpair		 tag;
 	struct tag		*t;
 
-	PAIR_CLASS_INIT(&tag, "farg");
 	if (n->parent->tok != MDOC_Fo) {
-		print_otag(h, TAG_I, 1, &tag);
+		print_otag(h, TAG_I, "c", "Fa");
 		return 1;
 	}
 
 	for (nn = n->child; nn; nn = nn->next) {
-		t = print_otag(h, TAG_I, 1, &tag);
+		t = print_otag(h, TAG_I, "c", "Fa");
 		print_text(h, nn->string);
 		print_tagq(h, t);
 		if (nn->next) {
 			h->flags |= HTML_NOSPACE;
 			print_text(h, ",");
 		}
 	}
 
 	if (n->child && n->next && n->next->tok == MDOC_Fa) {
 		h->flags |= HTML_NOSPACE;
 		print_text(h, ",");
 	}
 
 	return 0;
 }
 
 static int
 mdoc_fd_pre(MDOC_ARGS)
 {
-	struct htmlpair	 tag[2];
-	char		 buf[BUFSIZ];
-	size_t		 sz;
-	int		 i;
 	struct tag	*t;
+	char		*buf, *cp;
 
 	synopsis_pre(h, n);
 
 	if (NULL == (n = n->child))
 		return 0;
 
 	assert(n->type == ROFFT_TEXT);
 
 	if (strcmp(n->string, "#include")) {
-		PAIR_CLASS_INIT(&tag[0], "macro");
-		print_otag(h, TAG_B, 1, tag);
+		print_otag(h, TAG_B, "c", "Fd");
 		return 1;
 	}
 
-	PAIR_CLASS_INIT(&tag[0], "includes");
-	print_otag(h, TAG_B, 1, tag);
+	print_otag(h, TAG_B, "c", "In");
 	print_text(h, n->string);
 
 	if (NULL != (n = n->next)) {
 		assert(n->type == ROFFT_TEXT);
 
-		/*
-		 * XXX This is broken and not easy to fix.
-		 * When using -Oincludes, truncation may occur.
-		 * Dynamic allocation wouldn't help because
-		 * passing long strings to buffmt_includes()
-		 * does not work either.
-		 */
-
-		strlcpy(buf, '<' == *n->string || '"' == *n->string ?
-		    n->string + 1 : n->string, BUFSIZ);
-
-		sz = strlen(buf);
-		if (sz && ('>' == buf[sz - 1] || '"' == buf[sz - 1]))
-			buf[sz - 1] = '\0';
-
-		PAIR_CLASS_INIT(&tag[0], "link-includes");
-
-		i = 1;
 		if (h->base_includes) {
-			buffmt_includes(h, buf);
-			PAIR_HREF_INIT(&tag[i], h->buf);
-			i++;
-		}
+			cp = n->string;
+			if (*cp == '<' || *cp == '"')
+				cp++;
+			buf = mandoc_strdup(cp);
+			cp = strchr(buf, '\0') - 1;
+			if (cp >= buf && (*cp == '>' || *cp == '"'))
+				*cp = '\0';
+			t = print_otag(h, TAG_A, "chI", "In", buf);
+			free(buf);
+		} else
+			t = print_otag(h, TAG_A, "c", "In");
 
-		t = print_otag(h, TAG_A, i, tag);
 		print_text(h, n->string);
 		print_tagq(h, t);
 
 		n = n->next;
 	}
 
 	for ( ; n; n = n->next) {
 		assert(n->type == ROFFT_TEXT);
 		print_text(h, n->string);
 	}
 
 	return 0;
 }
 
 static int
 mdoc_vt_pre(MDOC_ARGS)
 {
-	struct htmlpair	 tag;
-
 	if (n->type == ROFFT_BLOCK) {
 		synopsis_pre(h, n);
 		return 1;
 	} else if (n->type == ROFFT_ELEM) {
 		synopsis_pre(h, n);
 	} else if (n->type == ROFFT_HEAD)
 		return 0;
 
-	PAIR_CLASS_INIT(&tag, "type");
-	print_otag(h, TAG_SPAN, 1, &tag);
+	print_otag(h, TAG_I, "c", "Vt");
 	return 1;
 }
 
 static int
 mdoc_ft_pre(MDOC_ARGS)
 {
-	struct htmlpair	 tag;
-
 	synopsis_pre(h, n);
-	PAIR_CLASS_INIT(&tag, "ftype");
-	print_otag(h, TAG_I, 1, &tag);
+	print_otag(h, TAG_I, "c", "Ft");
 	return 1;
 }
 
 static int
 mdoc_fn_pre(MDOC_ARGS)
 {
 	struct tag	*t;
-	struct htmlpair	 tag[2];
 	char		 nbuf[BUFSIZ];
 	const char	*sp, *ep;
-	int		 sz, i, pretty;
+	int		 sz, pretty;
 
-	pretty = MDOC_SYNPRETTY & n->flags;
+	pretty = NODE_SYNPRETTY & n->flags;
 	synopsis_pre(h, n);
 
 	/* Split apart into type and name. */
 	assert(n->child->string);
 	sp = n->child->string;
 
 	ep = strchr(sp, ' ');
 	if (NULL != ep) {
-		PAIR_CLASS_INIT(&tag[0], "ftype");
-		t = print_otag(h, TAG_I, 1, tag);
+		t = print_otag(h, TAG_I, "c", "Ft");
 
 		while (ep) {
 			sz = MIN((int)(ep - sp), BUFSIZ - 1);
 			(void)memcpy(nbuf, sp, (size_t)sz);
 			nbuf[sz] = '\0';
 			print_text(h, nbuf);
 			sp = ++ep;
 			ep = strchr(sp, ' ');
 		}
 		print_tagq(h, t);
 	}
 
-	PAIR_CLASS_INIT(&tag[0], "fname");
+	t = print_otag(h, TAG_B, "c", "Fn");
 
-	/*
-	 * FIXME: only refer to IDs that we know exist.
-	 */
-
-#if 0
-	if (MDOC_SYNPRETTY & n->flags) {
-		nbuf[0] = '\0';
-		html_idcat(nbuf, sp, BUFSIZ);
-		PAIR_ID_INIT(&tag[1], nbuf);
-	} else {
-		strlcpy(nbuf, "#", BUFSIZ);
-		html_idcat(nbuf, sp, BUFSIZ);
-		PAIR_HREF_INIT(&tag[1], nbuf);
-	}
-#endif
-
-	t = print_otag(h, TAG_B, 1, tag);
-
 	if (sp)
 		print_text(h, sp);
 
 	print_tagq(h, t);
 
 	h->flags |= HTML_NOSPACE;
 	print_text(h, "(");
 	h->flags |= HTML_NOSPACE;
 
-	PAIR_CLASS_INIT(&tag[0], "farg");
-	bufinit(h);
-	bufcat_style(h, "white-space", "nowrap");
-	PAIR_STYLE_INIT(&tag[1], h);
-
 	for (n = n->child->next; n; n = n->next) {
-		i = 1;
-		if (MDOC_SYNPRETTY & n->flags)
-			i = 2;
-		t = print_otag(h, TAG_I, i, tag);
+		if (NODE_SYNPRETTY & n->flags)
+			t = print_otag(h, TAG_I, "css?", "Fa",
+			    "white-space", "nowrap");
+		else
+			t = print_otag(h, TAG_I, "c", "Fa");
 		print_text(h, n->string);
 		print_tagq(h, t);
 		if (n->next) {
 			h->flags |= HTML_NOSPACE;
 			print_text(h, ",");
 		}
 	}
 
 	h->flags |= HTML_NOSPACE;
 	print_text(h, ")");
 
 	if (pretty) {
 		h->flags |= HTML_NOSPACE;
 		print_text(h, ";");
 	}
 
 	return 0;
 }
 
 static int
 mdoc_sm_pre(MDOC_ARGS)
 {
 
 	if (NULL == n->child)
 		h->flags ^= HTML_NONOSPACE;
 	else if (0 == strcmp("on", n->child->string))
 		h->flags &= ~HTML_NONOSPACE;
 	else
 		h->flags |= HTML_NONOSPACE;
 
 	if ( ! (HTML_NONOSPACE & h->flags))
 		h->flags &= ~HTML_NOSPACE;
 
 	return 0;
 }
 
 static int
 mdoc_skip_pre(MDOC_ARGS)
 {
 
 	return 0;
 }
 
 static int
 mdoc_pp_pre(MDOC_ARGS)
 {
 
 	print_paragraph(h);
 	return 0;
 }
 
 static int
 mdoc_sp_pre(MDOC_ARGS)
 {
 	struct roffsu	 su;
-	struct htmlpair	 tag;
 
 	SCALE_VS_INIT(&su, 1);
 
 	if (MDOC_sp == n->tok) {
 		if (NULL != (n = n->child)) {
 			if ( ! a2roffsu(n->string, &su, SCALE_VS))
 				su.scale = 1.0;
 			else if (su.scale < 0.0)
 				su.scale = 0.0;
 		}
 	} else
 		su.scale = 0.0;
 
-	bufinit(h);
-	bufcat_su(h, "height", &su);
-	PAIR_STYLE_INIT(&tag, h);
-	print_otag(h, TAG_DIV, 1, &tag);
+	print_otag(h, TAG_DIV, "suh", &su);
 
 	/* So the div isn't empty: */
 	print_text(h, "\\~");
 
 	return 0;
 
 }
 
 static int
 mdoc_lk_pre(MDOC_ARGS)
 {
-	struct htmlpair	 tag[2];
-
 	if (NULL == (n = n->child))
 		return 0;
 
 	assert(n->type == ROFFT_TEXT);
 
-	PAIR_CLASS_INIT(&tag[0], "link-ext");
-	PAIR_HREF_INIT(&tag[1], n->string);
+	print_otag(h, TAG_A, "ch", "Lk", n->string);
 
-	print_otag(h, TAG_A, 2, tag);
-
 	if (NULL == n->next)
 		print_text(h, n->string);
 
 	for (n = n->next; n; n = n->next)
 		print_text(h, n->string);
 
 	return 0;
 }
 
 static int
 mdoc_mt_pre(MDOC_ARGS)
 {
-	struct htmlpair	 tag[2];
 	struct tag	*t;
+	char		*cp;
 
-	PAIR_CLASS_INIT(&tag[0], "link-mail");
-
 	for (n = n->child; n; n = n->next) {
 		assert(n->type == ROFFT_TEXT);
 
-		bufinit(h);
-		bufcat(h, "mailto:");
-		bufcat(h, n->string);
-
-		PAIR_HREF_INIT(&tag[1], h->buf);
-		t = print_otag(h, TAG_A, 2, tag);
+		mandoc_asprintf(&cp, "mailto:%s", n->string);
+		t = print_otag(h, TAG_A, "ch", "Mt", cp);
 		print_text(h, n->string);
 		print_tagq(h, t);
+		free(cp);
 	}
 
 	return 0;
 }
 
 static int
 mdoc_fo_pre(MDOC_ARGS)
 {
-	struct htmlpair	 tag;
 	struct tag	*t;
 
 	if (n->type == ROFFT_BODY) {
 		h->flags |= HTML_NOSPACE;
 		print_text(h, "(");
 		h->flags |= HTML_NOSPACE;
 		return 1;
 	} else if (n->type == ROFFT_BLOCK) {
 		synopsis_pre(h, n);
 		return 1;
 	}
 
 	if (n->child == NULL)
 		return 0;
 
 	assert(n->child->string);
-	PAIR_CLASS_INIT(&tag, "fname");
-	t = print_otag(h, TAG_B, 1, &tag);
+	t = print_otag(h, TAG_B, "c", "Fn");
 	print_text(h, n->child->string);
 	print_tagq(h, t);
 	return 0;
 }
 
 static void
 mdoc_fo_post(MDOC_ARGS)
 {
 
 	if (n->type != ROFFT_BODY)
 		return;
 	h->flags |= HTML_NOSPACE;
 	print_text(h, ")");
 	h->flags |= HTML_NOSPACE;
 	print_text(h, ";");
 }
 
 static int
 mdoc_in_pre(MDOC_ARGS)
 {
 	struct tag	*t;
-	struct htmlpair	 tag[2];
-	int		 i;
 
 	synopsis_pre(h, n);
+	print_otag(h, TAG_B, "c", "In");
 
-	PAIR_CLASS_INIT(&tag[0], "includes");
-	print_otag(h, TAG_B, 1, tag);
-
 	/*
 	 * The first argument of the `In' gets special treatment as
 	 * being a linked value.  Subsequent values are printed
 	 * afterward.  groff does similarly.  This also handles the case
 	 * of no children.
 	 */
 
-	if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags)
+	if (NODE_SYNPRETTY & n->flags && NODE_LINE & n->flags)
 		print_text(h, "#include");
 
 	print_text(h, "<");
 	h->flags |= HTML_NOSPACE;
 
 	if (NULL != (n = n->child)) {
 		assert(n->type == ROFFT_TEXT);
 
-		PAIR_CLASS_INIT(&tag[0], "link-includes");
-
-		i = 1;
-		if (h->base_includes) {
-			buffmt_includes(h, n->string);
-			PAIR_HREF_INIT(&tag[i], h->buf);
-			i++;
-		}
-
-		t = print_otag(h, TAG_A, i, tag);
+		if (h->base_includes)
+			t = print_otag(h, TAG_A, "chI", "In", n->string);
+		else
+			t = print_otag(h, TAG_A, "c", "In");
 		print_text(h, n->string);
 		print_tagq(h, t);
 
 		n = n->next;
 	}
 
 	h->flags |= HTML_NOSPACE;
 	print_text(h, ">");
 
 	for ( ; n; n = n->next) {
 		assert(n->type == ROFFT_TEXT);
 		print_text(h, n->string);
 	}
 
 	return 0;
 }
 
 static int
 mdoc_ic_pre(MDOC_ARGS)
 {
-	struct htmlpair	tag;
-
-	PAIR_CLASS_INIT(&tag, "cmd");
-	print_otag(h, TAG_B, 1, &tag);
+	print_otag(h, TAG_B, "c", "Ic");
 	return 1;
 }
 
 static int
-mdoc_rv_pre(MDOC_ARGS)
-{
-	struct htmlpair	 tag;
-	struct tag	*t;
-	struct roff_node *nch;
-
-	if (n->prev)
-		print_otag(h, TAG_BR, 0, NULL);
-
-	PAIR_CLASS_INIT(&tag, "fname");
-
-	if (n->child != NULL) {
-		print_text(h, "The");
-
-		for (nch = n->child; nch != NULL; nch = nch->next) {
-			t = print_otag(h, TAG_B, 1, &tag);
-			print_text(h, nch->string);
-			print_tagq(h, t);
-
-			h->flags |= HTML_NOSPACE;
-			print_text(h, "()");
-
-			if (nch->next == NULL)
-				continue;
-
-			if (nch->prev != NULL || nch->next->next != NULL) {
-				h->flags |= HTML_NOSPACE;
-				print_text(h, ",");
-			}
-			if (nch->next->next == NULL)
-				print_text(h, "and");
-		}
-
-		if (n->child != NULL && n->child->next != NULL)
-			print_text(h, "functions return");
-		else
-			print_text(h, "function returns");
-
-		print_text(h, "the value\\~0 if successful;");
-	} else
-		print_text(h, "Upon successful completion,"
-                    " the value\\~0 is returned;");
-
-	print_text(h, "otherwise the value\\~\\-1 is returned"
-	   " and the global variable");
-
-	PAIR_CLASS_INIT(&tag, "var");
-	t = print_otag(h, TAG_B, 1, &tag);
-	print_text(h, "errno");
-	print_tagq(h, t);
-	print_text(h, "is set to indicate the error.");
-	return 0;
-}
-
-static int
 mdoc_va_pre(MDOC_ARGS)
 {
-	struct htmlpair	tag;
-
-	PAIR_CLASS_INIT(&tag, "var");
-	print_otag(h, TAG_B, 1, &tag);
+	print_otag(h, TAG_I, "c", "Va");
 	return 1;
 }
 
 static int
 mdoc_ap_pre(MDOC_ARGS)
 {
 
 	h->flags |= HTML_NOSPACE;
 	print_text(h, "\\(aq");
 	h->flags |= HTML_NOSPACE;
 	return 1;
 }
 
 static int
 mdoc_bf_pre(MDOC_ARGS)
 {
-	struct htmlpair	 tag[2];
-	struct roffsu	 su;
+	const char	*cattr;
 
 	if (n->type == ROFFT_HEAD)
 		return 0;
 	else if (n->type != ROFFT_BODY)
 		return 1;
 
 	if (FONT_Em == n->norm->Bf.font)
-		PAIR_CLASS_INIT(&tag[0], "emph");
+		cattr = "Em";
 	else if (FONT_Sy == n->norm->Bf.font)
-		PAIR_CLASS_INIT(&tag[0], "symb");
+		cattr = "Sy";
 	else if (FONT_Li == n->norm->Bf.font)
-		PAIR_CLASS_INIT(&tag[0], "lit");
+		cattr = "Li";
 	else
-		PAIR_CLASS_INIT(&tag[0], "none");
+		cattr = "none";
 
 	/*
 	 * We want this to be inline-formatted, but needs to be div to
 	 * accept block children.
 	 */
-	bufinit(h);
-	bufcat_style(h, "display", "inline");
-	SCALE_HS_INIT(&su, 1);
-	/* Needs a left-margin for spacing. */
-	bufcat_su(h, "margin-left", &su);
-	PAIR_STYLE_INIT(&tag[1], h);
-	print_otag(h, TAG_DIV, 2, tag);
+
+	print_otag(h, TAG_DIV, "css?hl", cattr, "display", "inline", 1);
 	return 1;
 }
 
 static int
 mdoc_ms_pre(MDOC_ARGS)
 {
-	struct htmlpair	tag;
-
-	PAIR_CLASS_INIT(&tag, "symb");
-	print_otag(h, TAG_SPAN, 1, &tag);
+	print_otag(h, TAG_B, "c", "Ms");
 	return 1;
 }
 
 static int
 mdoc_igndelim_pre(MDOC_ARGS)
 {
 
 	h->flags |= HTML_IGNDELIM;
 	return 1;
 }
 
 static void
 mdoc_pf_post(MDOC_ARGS)
 {
 
-	if ( ! (n->next == NULL || n->next->flags & MDOC_LINE))
+	if ( ! (n->next == NULL || n->next->flags & NODE_LINE))
 		h->flags |= HTML_NOSPACE;
 }
 
 static int
 mdoc_rs_pre(MDOC_ARGS)
 {
-	struct htmlpair	 tag;
-
 	if (n->type != ROFFT_BLOCK)
 		return 1;
 
 	if (n->prev && SEC_SEE_ALSO == n->sec)
 		print_paragraph(h);
 
-	PAIR_CLASS_INIT(&tag, "ref");
-	print_otag(h, TAG_SPAN, 1, &tag);
+	print_otag(h, TAG_SPAN, "c", "Rs");
 	return 1;
 }
 
 static int
 mdoc_no_pre(MDOC_ARGS)
 {
-	struct htmlpair	tag;
-
-	PAIR_CLASS_INIT(&tag, "none");
-	print_otag(h, TAG_CODE, 1, &tag);
+	print_otag(h, TAG_SPAN, "c", "No");
 	return 1;
 }
 
 static int
 mdoc_li_pre(MDOC_ARGS)
 {
-	struct htmlpair	tag;
-
-	PAIR_CLASS_INIT(&tag, "lit");
-	print_otag(h, TAG_CODE, 1, &tag);
+	print_otag(h, TAG_CODE, "c", "Li");
 	return 1;
 }
 
 static int
 mdoc_sy_pre(MDOC_ARGS)
 {
-	struct htmlpair	tag;
-
-	PAIR_CLASS_INIT(&tag, "symb");
-	print_otag(h, TAG_SPAN, 1, &tag);
+	print_otag(h, TAG_B, "c", "Sy");
 	return 1;
 }
 
 static int
-mdoc_bt_pre(MDOC_ARGS)
-{
-
-	print_text(h, "is currently in beta test.");
-	return 0;
-}
-
-static int
-mdoc_ud_pre(MDOC_ARGS)
-{
-
-	print_text(h, "currently under development.");
-	return 0;
-}
-
-static int
 mdoc_lb_pre(MDOC_ARGS)
 {
-	struct htmlpair	tag;
+	if (SEC_LIBRARY == n->sec && NODE_LINE & n->flags && n->prev)
+		print_otag(h, TAG_BR, "");
 
-	if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags && n->prev)
-		print_otag(h, TAG_BR, 0, NULL);
-
-	PAIR_CLASS_INIT(&tag, "lib");
-	print_otag(h, TAG_SPAN, 1, &tag);
+	print_otag(h, TAG_SPAN, "c", "Lb");
 	return 1;
 }
 
 static int
 mdoc__x_pre(MDOC_ARGS)
 {
-	struct htmlpair	tag[2];
-	enum htmltag	t;
+	const char	*cattr;
+	enum htmltag	 t;
 
 	t = TAG_SPAN;
 
 	switch (n->tok) {
 	case MDOC__A:
-		PAIR_CLASS_INIT(&tag[0], "ref-auth");
+		cattr = "RsA";
 		if (n->prev && MDOC__A == n->prev->tok)
 			if (NULL == n->next || MDOC__A != n->next->tok)
 				print_text(h, "and");
 		break;
 	case MDOC__B:
-		PAIR_CLASS_INIT(&tag[0], "ref-book");
 		t = TAG_I;
+		cattr = "RsB";
 		break;
 	case MDOC__C:
-		PAIR_CLASS_INIT(&tag[0], "ref-city");
+		cattr = "RsC";
 		break;
 	case MDOC__D:
-		PAIR_CLASS_INIT(&tag[0], "ref-date");
+		cattr = "RsD";
 		break;
 	case MDOC__I:
-		PAIR_CLASS_INIT(&tag[0], "ref-issue");
 		t = TAG_I;
+		cattr = "RsI";
 		break;
 	case MDOC__J:
-		PAIR_CLASS_INIT(&tag[0], "ref-jrnl");
 		t = TAG_I;
+		cattr = "RsJ";
 		break;
 	case MDOC__N:
-		PAIR_CLASS_INIT(&tag[0], "ref-num");
+		cattr = "RsN";
 		break;
 	case MDOC__O:
-		PAIR_CLASS_INIT(&tag[0], "ref-opt");
+		cattr = "RsO";
 		break;
 	case MDOC__P:
-		PAIR_CLASS_INIT(&tag[0], "ref-page");
+		cattr = "RsP";
 		break;
 	case MDOC__Q:
-		PAIR_CLASS_INIT(&tag[0], "ref-corp");
+		cattr = "RsQ";
 		break;
 	case MDOC__R:
-		PAIR_CLASS_INIT(&tag[0], "ref-rep");
+		cattr = "RsR";
 		break;
 	case MDOC__T:
-		PAIR_CLASS_INIT(&tag[0], "ref-title");
+		cattr = "RsT";
 		break;
 	case MDOC__U:
-		PAIR_CLASS_INIT(&tag[0], "link-ref");
-		break;
+		print_otag(h, TAG_A, "ch", "RsU", n->child->string);
+		return 1;
 	case MDOC__V:
-		PAIR_CLASS_INIT(&tag[0], "ref-vol");
+		cattr = "RsV";
 		break;
 	default:
 		abort();
 	}
 
-	if (MDOC__U != n->tok) {
-		print_otag(h, t, 1, tag);
-		return 1;
-	}
-
-	PAIR_HREF_INIT(&tag[1], n->child->string);
-	print_otag(h, TAG_A, 2, tag);
-
+	print_otag(h, t, "c", cattr);
 	return 1;
 }
 
 static void
 mdoc__x_post(MDOC_ARGS)
 {
 
 	if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
 		if (NULL == n->next->next || MDOC__A != n->next->next->tok)
 			if (NULL == n->prev || MDOC__A != n->prev->tok)
 				return;
 
 	/* TODO: %U */
 
 	if (NULL == n->parent || MDOC_Rs != n->parent->tok)
 		return;
 
 	h->flags |= HTML_NOSPACE;
 	print_text(h, n->next ? "," : ".");
 }
 
 static int
 mdoc_bk_pre(MDOC_ARGS)
 {
 
 	switch (n->type) {
 	case ROFFT_BLOCK:
 		break;
 	case ROFFT_HEAD:
 		return 0;
 	case ROFFT_BODY:
 		if (n->parent->args != NULL || n->prev->child == NULL)
 			h->flags |= HTML_PREKEEP;
 		break;
 	default:
 		abort();
 	}
 
 	return 1;
 }
 
 static void
 mdoc_bk_post(MDOC_ARGS)
 {
 
 	if (n->type == ROFFT_BODY)
 		h->flags &= ~(HTML_KEEP | HTML_PREKEEP);
 }
 
 static int
 mdoc_quote_pre(MDOC_ARGS)
 {
-	struct htmlpair	tag;
-
 	if (n->type != ROFFT_BODY)
 		return 1;
 
 	switch (n->tok) {
 	case MDOC_Ao:
 	case MDOC_Aq:
 		print_text(h, n->child != NULL && n->child->next == NULL &&
 		    n->child->tok == MDOC_Mt ?  "<" : "\\(la");
 		break;
 	case MDOC_Bro:
 	case MDOC_Brq:
 		print_text(h, "\\(lC");
 		break;
 	case MDOC_Bo:
 	case MDOC_Bq:
 		print_text(h, "\\(lB");
 		break;
 	case MDOC_Oo:
 	case MDOC_Op:
 		print_text(h, "\\(lB");
 		h->flags |= HTML_NOSPACE;
-		PAIR_CLASS_INIT(&tag, "opt");
-		print_otag(h, TAG_SPAN, 1, &tag);
+		print_otag(h, TAG_SPAN, "c", "Op");
 		break;
 	case MDOC_En:
 		if (NULL == n->norm->Es ||
 		    NULL == n->norm->Es->child)
 			return 1;
 		print_text(h, n->norm->Es->child->string);
 		break;
 	case MDOC_Do:
 	case MDOC_Dq:
 	case MDOC_Qo:
 	case MDOC_Qq:
 		print_text(h, "\\(lq");
 		break;
 	case MDOC_Po:
 	case MDOC_Pq:
 		print_text(h, "(");
 		break;
 	case MDOC_Ql:
 		print_text(h, "\\(oq");
 		h->flags |= HTML_NOSPACE;
-		PAIR_CLASS_INIT(&tag, "lit");
-		print_otag(h, TAG_CODE, 1, &tag);
+		print_otag(h, TAG_CODE, "c", "Li");
 		break;
 	case MDOC_So:
 	case MDOC_Sq:
 		print_text(h, "\\(oq");
 		break;
 	default:
 		abort();
 	}
 
 	h->flags |= HTML_NOSPACE;
 	return 1;
 }
 
 static void
 mdoc_quote_post(MDOC_ARGS)
 {
 
 	if (n->type != ROFFT_BODY && n->type != ROFFT_ELEM)
 		return;
 
 	h->flags |= HTML_NOSPACE;
 
 	switch (n->tok) {
 	case MDOC_Ao:
 	case MDOC_Aq:
 		print_text(h, n->child != NULL && n->child->next == NULL &&
 		    n->child->tok == MDOC_Mt ?  ">" : "\\(ra");
 		break;
 	case MDOC_Bro:
 	case MDOC_Brq:
 		print_text(h, "\\(rC");
 		break;
 	case MDOC_Oo:
 	case MDOC_Op:
 	case MDOC_Bo:
 	case MDOC_Bq:
 		print_text(h, "\\(rB");
 		break;
 	case MDOC_En:
 		if (n->norm->Es == NULL ||
 		    n->norm->Es->child == NULL ||
 		    n->norm->Es->child->next == NULL)
 			h->flags &= ~HTML_NOSPACE;
 		else
 			print_text(h, n->norm->Es->child->next->string);
 		break;
 	case MDOC_Qo:
 	case MDOC_Qq:
 	case MDOC_Do:
 	case MDOC_Dq:
 		print_text(h, "\\(rq");
 		break;
 	case MDOC_Po:
 	case MDOC_Pq:
 		print_text(h, ")");
 		break;
 	case MDOC_Ql:
 	case MDOC_So:
 	case MDOC_Sq:
 		print_text(h, "\\(cq");
 		break;
 	default:
 		abort();
 	}
 }
 
 static int
 mdoc_eo_pre(MDOC_ARGS)
 {
 
 	if (n->type != ROFFT_BODY)
 		return 1;
 
 	if (n->end == ENDBODY_NOT &&
 	    n->parent->head->child == NULL &&
 	    n->child != NULL &&
 	    n->child->end != ENDBODY_NOT)
 		print_text(h, "\\&");
 	else if (n->end != ENDBODY_NOT ? n->child != NULL :
 	    n->parent->head->child != NULL && (n->child != NULL ||
 	    (n->parent->tail != NULL && n->parent->tail->child != NULL)))
 		h->flags |= HTML_NOSPACE;
 	return 1;
 }
 
 static void
 mdoc_eo_post(MDOC_ARGS)
 {
 	int	 body, tail;
 
 	if (n->type != ROFFT_BODY)
 		return;
 
 	if (n->end != ENDBODY_NOT) {
 		h->flags &= ~HTML_NOSPACE;
 		return;
 	}
 
 	body = n->child != NULL || n->parent->head->child != NULL;
 	tail = n->parent->tail != NULL && n->parent->tail->child != NULL;
 
 	if (body && tail)
 		h->flags |= HTML_NOSPACE;
 	else if ( ! tail)
 		h->flags &= ~HTML_NOSPACE;
 }
Index: stable/11/contrib/mdocml/mdoc_macro.c
===================================================================
--- stable/11/contrib/mdocml/mdoc_macro.c	(revision 316419)
+++ stable/11/contrib/mdocml/mdoc_macro.c	(revision 316420)
@@ -1,1477 +1,1486 @@
-/*	$Id: mdoc_macro.c,v 1.206 2015/10/20 02:01:32 schwarze Exp $ */
+/*	$Id: mdoc_macro.c,v 1.210 2017/01/10 13:47:00 schwarze Exp $ */
 /*
  * Copyright (c) 2008-2012 Kristaps Dzonsons 
- * Copyright (c) 2010, 2012-2015 Ingo Schwarze 
+ * Copyright (c) 2010, 2012-2016 Ingo Schwarze 
  *
  * 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 AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h"
 
 #include 
 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 
 #include "mandoc.h"
 #include "roff.h"
 #include "mdoc.h"
 #include "libmandoc.h"
 #include "roff_int.h"
 #include "libmdoc.h"
 
 static	void		blk_full(MACRO_PROT_ARGS);
 static	void		blk_exp_close(MACRO_PROT_ARGS);
 static	void		blk_part_exp(MACRO_PROT_ARGS);
 static	void		blk_part_imp(MACRO_PROT_ARGS);
 static	void		ctx_synopsis(MACRO_PROT_ARGS);
 static	void		in_line_eoln(MACRO_PROT_ARGS);
 static	void		in_line_argn(MACRO_PROT_ARGS);
 static	void		in_line(MACRO_PROT_ARGS);
 static	void		phrase_ta(MACRO_PROT_ARGS);
 
 static	void		append_delims(struct roff_man *, int, int *, char *);
 static	void		dword(struct roff_man *, int, int, const char *,
 				enum mdelim, int);
 static	int		find_pending(struct roff_man *, int, int, int,
 				struct roff_node *);
 static	int		lookup(struct roff_man *, int, int, int, const char *);
 static	int		macro_or_word(MACRO_PROT_ARGS, int);
 static	int		parse_rest(struct roff_man *, int, int, int *, char *);
 static	int		rew_alt(int);
 static	void		rew_elem(struct roff_man *, int);
 static	void		rew_last(struct roff_man *, const struct roff_node *);
 static	void		rew_pending(struct roff_man *,
 				const struct roff_node *);
 
 const	struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
 	{ in_line_argn, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Ap */
 	{ in_line_eoln, MDOC_PROLOGUE }, /* Dd */
 	{ in_line_eoln, MDOC_PROLOGUE }, /* Dt */
 	{ in_line_eoln, MDOC_PROLOGUE }, /* Os */
 	{ blk_full, MDOC_PARSED | MDOC_JOIN }, /* Sh */
 	{ blk_full, MDOC_PARSED | MDOC_JOIN }, /* Ss */
 	{ in_line_eoln, 0 }, /* Pp */
 	{ blk_part_imp, MDOC_PARSED | MDOC_JOIN }, /* D1 */
 	{ blk_part_imp, MDOC_PARSED | MDOC_JOIN }, /* Dl */
 	{ blk_full, MDOC_EXPLICIT }, /* Bd */
 	{ blk_exp_close, MDOC_EXPLICIT | MDOC_JOIN }, /* Ed */
 	{ blk_full, MDOC_EXPLICIT }, /* Bl */
 	{ blk_exp_close, MDOC_EXPLICIT | MDOC_JOIN }, /* El */
 	{ blk_full, MDOC_PARSED | MDOC_JOIN }, /* It */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Ad */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* An */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Ar */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Cd */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Cm */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Dv */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Er */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Ev */
 	{ in_line_eoln, 0 }, /* Ex */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Fa */
 	{ in_line_eoln, 0 }, /* Fd */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Fl */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Fn */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Ft */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Ic */
 	{ in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* In */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Li */
 	{ blk_full, MDOC_JOIN }, /* Nd */
 	{ ctx_synopsis, MDOC_CALLABLE | MDOC_PARSED }, /* Nm */
 	{ blk_part_imp, MDOC_CALLABLE | MDOC_PARSED }, /* Op */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Ot */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Pa */
 	{ in_line_eoln, 0 }, /* Rv */
 	{ in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* St */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Va */
 	{ ctx_synopsis, MDOC_CALLABLE | MDOC_PARSED }, /* Vt */
 	{ in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* Xr */
 	{ in_line_eoln, MDOC_JOIN }, /* %A */
 	{ in_line_eoln, MDOC_JOIN }, /* %B */
 	{ in_line_eoln, MDOC_JOIN }, /* %D */
 	{ in_line_eoln, MDOC_JOIN }, /* %I */
 	{ in_line_eoln, MDOC_JOIN }, /* %J */
 	{ in_line_eoln, 0 }, /* %N */
 	{ in_line_eoln, MDOC_JOIN }, /* %O */
 	{ in_line_eoln, 0 }, /* %P */
 	{ in_line_eoln, MDOC_JOIN }, /* %R */
 	{ in_line_eoln, MDOC_JOIN }, /* %T */
 	{ in_line_eoln, 0 }, /* %V */
 	{ blk_exp_close, MDOC_CALLABLE | MDOC_PARSED |
 			 MDOC_EXPLICIT | MDOC_JOIN }, /* Ac */
 	{ blk_part_exp, MDOC_CALLABLE | MDOC_PARSED |
 			MDOC_EXPLICIT | MDOC_JOIN }, /* Ao */
 	{ blk_part_imp, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Aq */
 	{ in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* At */
 	{ blk_exp_close, MDOC_CALLABLE | MDOC_PARSED |
 			 MDOC_EXPLICIT | MDOC_JOIN }, /* Bc */
 	{ blk_full, MDOC_EXPLICIT }, /* Bf */
 	{ blk_part_exp, MDOC_CALLABLE | MDOC_PARSED |
 			MDOC_EXPLICIT | MDOC_JOIN }, /* Bo */
 	{ blk_part_imp, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Bq */
 	{ in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* Bsx */
 	{ in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* Bx */
 	{ in_line_eoln, 0 }, /* Db */
 	{ blk_exp_close, MDOC_CALLABLE | MDOC_PARSED |
 			 MDOC_EXPLICIT | MDOC_JOIN }, /* Dc */
 	{ blk_part_exp, MDOC_CALLABLE | MDOC_PARSED |
 			MDOC_EXPLICIT | MDOC_JOIN }, /* Do */
 	{ blk_part_imp, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Dq */
 	{ blk_exp_close, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Ec */
 	{ blk_exp_close, MDOC_EXPLICIT | MDOC_JOIN }, /* Ef */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Em */
 	{ blk_part_exp, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Eo */
 	{ in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* Fx */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Ms */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* No */
 	{ in_line_argn, MDOC_CALLABLE | MDOC_PARSED |
 			MDOC_IGNDELIM | MDOC_JOIN }, /* Ns */
 	{ in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* Nx */
 	{ in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* Ox */
 	{ blk_exp_close, MDOC_CALLABLE | MDOC_PARSED |
 			 MDOC_EXPLICIT | MDOC_JOIN }, /* Pc */
 	{ in_line_argn, MDOC_CALLABLE | MDOC_PARSED | MDOC_IGNDELIM }, /* Pf */
 	{ blk_part_exp, MDOC_CALLABLE | MDOC_PARSED |
 			MDOC_EXPLICIT | MDOC_JOIN }, /* Po */
 	{ blk_part_imp, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Pq */
 	{ blk_exp_close, MDOC_CALLABLE | MDOC_PARSED |
 			 MDOC_EXPLICIT | MDOC_JOIN }, /* Qc */
 	{ blk_part_imp, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Ql */
 	{ blk_part_exp, MDOC_CALLABLE | MDOC_PARSED |
 			MDOC_EXPLICIT | MDOC_JOIN }, /* Qo */
 	{ blk_part_imp, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Qq */
 	{ blk_exp_close, MDOC_EXPLICIT | MDOC_JOIN }, /* Re */
 	{ blk_full, MDOC_EXPLICIT }, /* Rs */
 	{ blk_exp_close, MDOC_CALLABLE | MDOC_PARSED |
 			 MDOC_EXPLICIT | MDOC_JOIN }, /* Sc */
 	{ blk_part_exp, MDOC_CALLABLE | MDOC_PARSED |
 			MDOC_EXPLICIT | MDOC_JOIN }, /* So */
 	{ blk_part_imp, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Sq */
 	{ in_line_argn, 0 }, /* Sm */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Sx */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Sy */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Tn */
 	{ in_line_argn, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Ux */
 	{ blk_exp_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Xc */
 	{ blk_part_exp, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Xo */
 	{ blk_full, MDOC_EXPLICIT | MDOC_CALLABLE }, /* Fo */
 	{ blk_exp_close, MDOC_CALLABLE | MDOC_PARSED |
 			 MDOC_EXPLICIT | MDOC_JOIN }, /* Fc */
 	{ blk_part_exp, MDOC_CALLABLE | MDOC_PARSED |
 			MDOC_EXPLICIT | MDOC_JOIN }, /* Oo */
 	{ blk_exp_close, MDOC_CALLABLE | MDOC_PARSED |
 			 MDOC_EXPLICIT | MDOC_JOIN }, /* Oc */
 	{ blk_full, MDOC_EXPLICIT }, /* Bk */
 	{ blk_exp_close, MDOC_EXPLICIT | MDOC_JOIN }, /* Ek */
 	{ in_line_eoln, 0 }, /* Bt */
 	{ in_line_eoln, 0 }, /* Hf */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Fr */
 	{ in_line_eoln, 0 }, /* Ud */
 	{ in_line, 0 }, /* Lb */
 	{ in_line_eoln, 0 }, /* Lp */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Lk */
 	{ in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Mt */
 	{ blk_part_imp, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Brq */
 	{ blk_part_exp, MDOC_CALLABLE | MDOC_PARSED |
 			MDOC_EXPLICIT | MDOC_JOIN }, /* Bro */
 	{ blk_exp_close, MDOC_CALLABLE | MDOC_PARSED |
 			 MDOC_EXPLICIT | MDOC_JOIN }, /* Brc */
 	{ in_line_eoln, MDOC_JOIN }, /* %C */
 	{ in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* Es */
 	{ blk_part_imp, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* En */
 	{ in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* Dx */
 	{ in_line_eoln, MDOC_JOIN }, /* %Q */
 	{ in_line_eoln, 0 }, /* br */
 	{ in_line_eoln, 0 }, /* sp */
 	{ in_line_eoln, 0 }, /* %U */
 	{ phrase_ta, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Ta */
 	{ in_line_eoln, MDOC_PROLOGUE }, /* ll */
 };
 
 const	struct mdoc_macro * const mdoc_macros = __mdoc_macros;
 
 
 /*
  * This is called at the end of parsing.  It must traverse up the tree,
  * closing out open [implicit] scopes.  Obviously, open explicit scopes
  * are errors.
  */
 void
 mdoc_endparse(struct roff_man *mdoc)
 {
 	struct roff_node *n;
 
 	/* Scan for open explicit scopes. */
 
-	n = mdoc->last->flags & MDOC_VALID ?
+	n = mdoc->last->flags & NODE_VALID ?
 	    mdoc->last->parent : mdoc->last;
 
 	for ( ; n; n = n->parent)
 		if (n->type == ROFFT_BLOCK &&
 		    mdoc_macros[n->tok].flags & MDOC_EXPLICIT)
 			mandoc_msg(MANDOCERR_BLK_NOEND, mdoc->parse,
 			    n->line, n->pos, mdoc_macronames[n->tok]);
 
 	/* Rewind to the first. */
 
 	rew_last(mdoc, mdoc->first);
 	mdoc_state_reset(mdoc);
 }
 
 /*
  * Look up the macro at *p called by "from",
  * or as a line macro if from == TOKEN_NONE.
  */
 static int
 lookup(struct roff_man *mdoc, int from, int line, int ppos, const char *p)
 {
 	int	 res;
 
 	if (mdoc->flags & MDOC_PHRASEQF) {
 		mdoc->flags &= ~MDOC_PHRASEQF;
 		return TOKEN_NONE;
 	}
 	if (from == TOKEN_NONE || mdoc_macros[from].flags & MDOC_PARSED) {
 		res = mdoc_hash_find(p);
 		if (res != TOKEN_NONE) {
 			if (mdoc_macros[res].flags & MDOC_CALLABLE)
 				return res;
 			if (res != MDOC_br && res != MDOC_sp && res != MDOC_ll)
 				mandoc_msg(MANDOCERR_MACRO_CALL,
 				    mdoc->parse, line, ppos, p);
 		}
 	}
 	return TOKEN_NONE;
 }
 
 /*
  * Rewind up to and including a specific node.
  */
 static void
 rew_last(struct roff_man *mdoc, const struct roff_node *to)
 {
 
-	if (to->flags & MDOC_VALID)
+	if (to->flags & NODE_VALID)
 		return;
 
 	while (mdoc->last != to) {
 		mdoc_state(mdoc, mdoc->last);
-		mdoc->last->flags |= MDOC_VALID | MDOC_ENDED;
+		mdoc->last->flags |= NODE_VALID | NODE_ENDED;
 		mdoc->last = mdoc->last->parent;
 	}
 	mdoc_state(mdoc, mdoc->last);
-	mdoc->last->flags |= MDOC_VALID | MDOC_ENDED;
+	mdoc->last->flags |= NODE_VALID | NODE_ENDED;
 	mdoc->next = ROFF_NEXT_SIBLING;
 }
 
 /*
  * Rewind up to a specific block, including all blocks that broke it.
  */
 static void
 rew_pending(struct roff_man *mdoc, const struct roff_node *n)
 {
 
 	for (;;) {
 		rew_last(mdoc, n);
 
 		if (mdoc->last == n) {
 			switch (n->type) {
 			case ROFFT_HEAD:
 				roff_body_alloc(mdoc, n->line, n->pos,
 				    n->tok);
-				return;
+				break;
 			case ROFFT_BLOCK:
 				break;
 			default:
 				return;
 			}
-			if ( ! (n->flags & MDOC_BROKEN))
+			if ( ! (n->flags & NODE_BROKEN))
 				return;
 		} else
 			n = mdoc->last;
 
 		for (;;) {
 			if ((n = n->parent) == NULL)
 				return;
 
 			if (n->type == ROFFT_BLOCK ||
 			    n->type == ROFFT_HEAD) {
-				if (n->flags & MDOC_ENDED)
+				if (n->flags & NODE_ENDED)
 					break;
 				else
 					return;
 			}
 		}
 	}
 }
 
 /*
  * For a block closing macro, return the corresponding opening one.
  * Otherwise, return the macro itself.
  */
 static int
 rew_alt(int tok)
 {
 	switch (tok) {
 	case MDOC_Ac:
 		return MDOC_Ao;
 	case MDOC_Bc:
 		return MDOC_Bo;
 	case MDOC_Brc:
 		return MDOC_Bro;
 	case MDOC_Dc:
 		return MDOC_Do;
 	case MDOC_Ec:
 		return MDOC_Eo;
 	case MDOC_Ed:
 		return MDOC_Bd;
 	case MDOC_Ef:
 		return MDOC_Bf;
 	case MDOC_Ek:
 		return MDOC_Bk;
 	case MDOC_El:
 		return MDOC_Bl;
 	case MDOC_Fc:
 		return MDOC_Fo;
 	case MDOC_Oc:
 		return MDOC_Oo;
 	case MDOC_Pc:
 		return MDOC_Po;
 	case MDOC_Qc:
 		return MDOC_Qo;
 	case MDOC_Re:
 		return MDOC_Rs;
 	case MDOC_Sc:
 		return MDOC_So;
 	case MDOC_Xc:
 		return MDOC_Xo;
 	default:
 		return tok;
 	}
 }
 
 static void
 rew_elem(struct roff_man *mdoc, int tok)
 {
 	struct roff_node *n;
 
 	n = mdoc->last;
 	if (n->type != ROFFT_ELEM)
 		n = n->parent;
 	assert(n->type == ROFFT_ELEM);
 	assert(tok == n->tok);
 	rew_last(mdoc, n);
 }
 
 /*
  * If there is an open sub-block of the target requiring
  * explicit close-out, postpone closing out the target until
  * the rew_pending() call closing out the sub-block.
  */
 static int
 find_pending(struct roff_man *mdoc, int tok, int line, int ppos,
 	struct roff_node *target)
 {
 	struct roff_node	*n;
 	int			 irc;
 
 	irc = 0;
 	for (n = mdoc->last; n != NULL && n != target; n = n->parent) {
-		if (n->flags & MDOC_ENDED) {
-			if ( ! (n->flags & MDOC_VALID))
-				n->flags |= MDOC_BROKEN;
+		if (n->flags & NODE_ENDED) {
+			if ( ! (n->flags & NODE_VALID))
+				n->flags |= NODE_BROKEN;
 			continue;
 		}
 		if (n->type == ROFFT_BLOCK &&
 		    mdoc_macros[n->tok].flags & MDOC_EXPLICIT) {
 			irc = 1;
-			n->flags = MDOC_BROKEN;
+			n->flags = NODE_BROKEN;
 			if (target->type == ROFFT_HEAD)
-				target->flags = MDOC_ENDED;
-			else if ( ! (target->flags & MDOC_ENDED)) {
+				target->flags = NODE_ENDED;
+			else if ( ! (target->flags & NODE_ENDED)) {
 				mandoc_vmsg(MANDOCERR_BLK_NEST,
 				    mdoc->parse, line, ppos,
 				    "%s breaks %s", mdoc_macronames[tok],
 				    mdoc_macronames[n->tok]);
 				mdoc_endbody_alloc(mdoc, line, ppos,
 				    tok, target, ENDBODY_NOSPACE);
 			}
 		}
 	}
 	return irc;
 }
 
 /*
  * Allocate a word and check whether it's punctuation or not.
  * Punctuation consists of those tokens found in mdoc_isdelim().
  */
 static void
 dword(struct roff_man *mdoc, int line, int col, const char *p,
 		enum mdelim d, int may_append)
 {
 
 	if (d == DELIM_MAX)
 		d = mdoc_isdelim(p);
 
 	if (may_append &&
 	    ! (mdoc->flags & (MDOC_SYNOPSIS | MDOC_KEEP | MDOC_SMOFF)) &&
 	    d == DELIM_NONE && mdoc->last->type == ROFFT_TEXT &&
 	    mdoc_isdelim(mdoc->last->string) == DELIM_NONE) {
 		roff_word_append(mdoc, p);
 		return;
 	}
 
 	roff_word_alloc(mdoc, line, col, p);
 
 	/*
 	 * If the word consists of a bare delimiter,
 	 * flag the new node accordingly,
 	 * unless doing so was vetoed by the invoking macro.
 	 * Always clear the veto, it is only valid for one word.
 	 */
 
 	if (d == DELIM_OPEN)
-		mdoc->last->flags |= MDOC_DELIMO;
+		mdoc->last->flags |= NODE_DELIMO;
 	else if (d == DELIM_CLOSE &&
 	    ! (mdoc->flags & MDOC_NODELIMC) &&
 	    mdoc->last->parent->tok != MDOC_Fd)
-		mdoc->last->flags |= MDOC_DELIMC;
+		mdoc->last->flags |= NODE_DELIMC;
 	mdoc->flags &= ~MDOC_NODELIMC;
 }
 
 static void
 append_delims(struct roff_man *mdoc, int line, int *pos, char *buf)
 {
 	char		*p;
 	int		 la;
 
 	if (buf[*pos] == '\0')
 		return;
 
 	for (;;) {
 		la = *pos;
 		if (mdoc_args(mdoc, line, pos, buf, TOKEN_NONE, &p) ==
 		    ARGS_EOLN)
 			break;
 		dword(mdoc, line, la, p, DELIM_MAX, 1);
 
 		/*
 		 * If we encounter end-of-sentence symbols, then trigger
 		 * the double-space.
 		 *
 		 * XXX: it's easy to allow this to propagate outward to
 		 * the last symbol, such that `. )' will cause the
 		 * correct double-spacing.  However, (1) groff isn't
 		 * smart enough to do this and (2) it would require
 		 * knowing which symbols break this behaviour, for
 		 * example, `.  ;' shouldn't propagate the double-space.
 		 */
 
 		if (mandoc_eos(p, strlen(p)))
-			mdoc->last->flags |= MDOC_EOS;
+			mdoc->last->flags |= NODE_EOS;
 	}
 }
 
 /*
  * Parse one word.
  * If it is a macro, call it and return 1.
  * Otherwise, allocate it and return 0.
  */
 static int
 macro_or_word(MACRO_PROT_ARGS, int parsed)
 {
 	char		*p;
 	int		 ntok;
 
 	p = buf + ppos;
 	ntok = TOKEN_NONE;
 	if (*p == '"')
 		p++;
 	else if (parsed && ! (mdoc->flags & MDOC_PHRASELIT))
 		ntok = lookup(mdoc, tok, line, ppos, p);
 
 	if (ntok == TOKEN_NONE) {
 		dword(mdoc, line, ppos, p, DELIM_MAX, tok == TOKEN_NONE ||
 		    mdoc_macros[tok].flags & MDOC_JOIN);
 		return 0;
 	} else {
 		if (mdoc_macros[tok].fp == in_line_eoln)
 			rew_elem(mdoc, tok);
 		mdoc_macro(mdoc, ntok, line, ppos, pos, buf);
 		if (tok == TOKEN_NONE)
 			append_delims(mdoc, line, pos, buf);
 		return 1;
 	}
 }
 
 /*
  * Close out block partial/full explicit.
  */
 static void
 blk_exp_close(MACRO_PROT_ARGS)
 {
 	struct roff_node *body;		/* Our own body. */
 	struct roff_node *endbody;	/* Our own end marker. */
 	struct roff_node *itblk;	/* An It block starting later. */
 	struct roff_node *later;	/* A sub-block starting later. */
 	struct roff_node *n;		/* Search back to our block. */
 	struct roff_node *target;	/* For find_pending(). */
 
 	int		 j, lastarg, maxargs, nl, pending;
 	enum margserr	 ac;
 	int		 atok, ntok;
 	char		*p;
 
 	nl = MDOC_NEWLINE & mdoc->flags;
 
 	switch (tok) {
 	case MDOC_Ec:
 		maxargs = 1;
 		break;
 	case MDOC_Ek:
 		mdoc->flags &= ~MDOC_KEEP;
 		/* FALLTHROUGH */
 	default:
 		maxargs = 0;
 		break;
 	}
 
+	/* Search backwards for the beginning of our own body. */
+
+	atok = rew_alt(tok);
+	body = NULL;
+	for (n = mdoc->last; n; n = n->parent) {
+		if (n->flags & NODE_ENDED || n->tok != atok ||
+		    n->type != ROFFT_BODY || n->end != ENDBODY_NOT)
+			continue;
+		body = n;
+		break;
+	}
+
 	/*
 	 * Search backwards for beginnings of blocks,
 	 * both of our own and of pending sub-blocks.
 	 */
 
-	atok = rew_alt(tok);
-	body = endbody = itblk = later = NULL;
+	endbody = itblk = later = NULL;
 	for (n = mdoc->last; n; n = n->parent) {
-		if (n->flags & MDOC_ENDED) {
-			if ( ! (n->flags & MDOC_VALID))
-				n->flags |= MDOC_BROKEN;
+		if (n->flags & NODE_ENDED) {
+			if ( ! (n->flags & NODE_VALID))
+				n->flags |= NODE_BROKEN;
 			continue;
 		}
 
-		/* Remember the start of our own body. */
+		/*
+		 * Mismatching end macros can never break anything,
+		 * SYNOPSIS name blocks can never be broken,
+		 * and we only care about the breaking of BLOCKs.
+		 */
 
-		if (n->type == ROFFT_BODY && atok == n->tok) {
-			if (n->end == ENDBODY_NOT)
-				body = n;
+		if (body == NULL ||
+		    n->tok == MDOC_Nm ||
+		    n->type != ROFFT_BLOCK)
 			continue;
-		}
 
-		if (n->type != ROFFT_BLOCK || n->tok == MDOC_Nm)
-			continue;
-
 		if (n->tok == MDOC_It) {
 			itblk = n;
 			continue;
 		}
 
 		if (atok == n->tok) {
 			assert(body);
 
 			/*
 			 * Found the start of our own block.
 			 * When there is no pending sub block,
 			 * just proceed to closing out.
 			 */
 
 			if (later == NULL ||
 			    (tok == MDOC_El && itblk == NULL))
 				break;
 
 			/*
 			 * When there is a pending sub block, postpone
 			 * closing out the current block until the
 			 * rew_pending() closing out the sub-block.
 			 * Mark the place where the formatting - but not
 			 * the scope - of the current block ends.
 			 */
 
 			mandoc_vmsg(MANDOCERR_BLK_NEST, mdoc->parse,
 			    line, ppos, "%s breaks %s",
 			    mdoc_macronames[atok],
 			    mdoc_macronames[later->tok]);
 
 			endbody = mdoc_endbody_alloc(mdoc, line, ppos,
 			    atok, body, ENDBODY_SPACE);
 
 			if (tok == MDOC_El)
-				itblk->flags |= MDOC_ENDED | MDOC_BROKEN;
+				itblk->flags |= NODE_ENDED | NODE_BROKEN;
 
 			/*
 			 * If a block closing macro taking arguments
 			 * breaks another block, put the arguments
 			 * into the end marker.
 			 */
 
 			if (maxargs)
 				mdoc->next = ROFF_NEXT_CHILD;
 			break;
 		}
 
 		/* Explicit blocks close out description lines. */
 
 		if (n->tok == MDOC_Nd) {
 			rew_last(mdoc, n);
 			continue;
 		}
 
 		/* Breaking an open sub block. */
 
-		n->flags |= MDOC_BROKEN;
+		n->flags |= NODE_BROKEN;
 		if (later == NULL)
 			later = n;
 	}
 
 	if (body == NULL) {
 		mandoc_msg(MANDOCERR_BLK_NOTOPEN, mdoc->parse,
 		    line, ppos, mdoc_macronames[tok]);
-		if (later != NULL)
-			later->flags &= ~MDOC_BROKEN;
 		if (maxargs && endbody == NULL) {
 			/*
 			 * Stray .Ec without previous .Eo:
 			 * Break the output line, keep the arguments.
 			 */
 			roff_elem_alloc(mdoc, line, ppos, MDOC_br);
 			rew_elem(mdoc, MDOC_br);
 		}
 	} else if (endbody == NULL) {
 		rew_last(mdoc, body);
 		if (maxargs)
 			mdoc_tail_alloc(mdoc, line, ppos, atok);
 	}
 
 	if ( ! (mdoc_macros[tok].flags & MDOC_PARSED)) {
 		if (buf[*pos] != '\0')
 			mandoc_vmsg(MANDOCERR_ARG_SKIP,
 			    mdoc->parse, line, ppos,
 			    "%s %s", mdoc_macronames[tok],
 			    buf + *pos);
 		if (endbody == NULL && n != NULL)
 			rew_pending(mdoc, n);
 		return;
 	}
 
 	if (endbody != NULL)
 		n = endbody;
 
 	ntok = TOKEN_NONE;
 	for (j = 0; ; j++) {
 		lastarg = *pos;
 
 		if (j == maxargs && n != NULL)
 			rew_last(mdoc, n);
 
 		ac = mdoc_args(mdoc, line, pos, buf, tok, &p);
 		if (ac == ARGS_PUNCT || ac == ARGS_EOLN)
 			break;
 
 		ntok = ac == ARGS_QWORD ? TOKEN_NONE :
 		    lookup(mdoc, tok, line, lastarg, p);
 
 		if (ntok == TOKEN_NONE) {
 			dword(mdoc, line, lastarg, p, DELIM_MAX,
 			    MDOC_JOIN & mdoc_macros[tok].flags);
 			continue;
 		}
 
 		if (n != NULL)
 			rew_last(mdoc, n);
 		mdoc->flags &= ~MDOC_NEWLINE;
 		mdoc_macro(mdoc, ntok, line, lastarg, pos, buf);
 		break;
 	}
 
 	if (n != NULL) {
-		if (ntok != TOKEN_NONE && n->flags & MDOC_BROKEN) {
+		if (ntok != TOKEN_NONE && n->flags & NODE_BROKEN) {
 			target = n;
 			do
 				target = target->parent;
-			while ( ! (target->flags & MDOC_ENDED));
+			while ( ! (target->flags & NODE_ENDED));
 			pending = find_pending(mdoc, ntok, line, ppos,
 			    target);
 		} else
 			pending = 0;
 		if ( ! pending)
 			rew_pending(mdoc, n);
 	}
 	if (nl)
 		append_delims(mdoc, line, pos, buf);
 }
 
 static void
 in_line(MACRO_PROT_ARGS)
 {
 	int		 la, scope, cnt, firstarg, mayopen, nc, nl;
 	int		 ntok;
 	enum margserr	 ac;
 	enum mdelim	 d;
 	struct mdoc_arg	*arg;
 	char		*p;
 
 	nl = MDOC_NEWLINE & mdoc->flags;
 
 	/*
 	 * Whether we allow ignored elements (those without content,
 	 * usually because of reserved words) to squeak by.
 	 */
 
 	switch (tok) {
 	case MDOC_An:
 	case MDOC_Ar:
 	case MDOC_Fl:
 	case MDOC_Mt:
 	case MDOC_Nm:
 	case MDOC_Pa:
 		nc = 1;
 		break;
 	default:
 		nc = 0;
 		break;
 	}
 
 	mdoc_argv(mdoc, line, tok, &arg, pos, buf);
 
 	d = DELIM_NONE;
 	firstarg = 1;
 	mayopen = 1;
 	for (cnt = scope = 0;; ) {
 		la = *pos;
 		ac = mdoc_args(mdoc, line, pos, buf, tok, &p);
 
 		/*
 		 * At the end of a macro line,
 		 * opening delimiters do not suppress spacing.
 		 */
 
 		if (ac == ARGS_EOLN) {
 			if (d == DELIM_OPEN)
-				mdoc->last->flags &= ~MDOC_DELIMO;
+				mdoc->last->flags &= ~NODE_DELIMO;
 			break;
 		}
 
 		/*
 		 * The rest of the macro line is only punctuation,
 		 * to be handled by append_delims().
 		 * If there were no other arguments,
 		 * do not allow the first one to suppress spacing,
 		 * even if it turns out to be a closing one.
 		 */
 
 		if (ac == ARGS_PUNCT) {
 			if (cnt == 0 && (nc == 0 || tok == MDOC_An))
 				mdoc->flags |= MDOC_NODELIMC;
 			break;
 		}
 
 		ntok = (ac == ARGS_QWORD || (tok == MDOC_Fn && !cnt)) ?
 		    TOKEN_NONE : lookup(mdoc, tok, line, la, p);
 
 		/*
 		 * In this case, we've located a submacro and must
 		 * execute it.  Close out scope, if open.  If no
 		 * elements have been generated, either create one (nc)
 		 * or raise a warning.
 		 */
 
 		if (ntok != TOKEN_NONE) {
 			if (scope)
 				rew_elem(mdoc, tok);
 			if (nc && ! cnt) {
 				mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
 				rew_last(mdoc, mdoc->last);
 			} else if ( ! nc && ! cnt) {
 				mdoc_argv_free(arg);
 				mandoc_msg(MANDOCERR_MACRO_EMPTY,
 				    mdoc->parse, line, ppos,
 				    mdoc_macronames[tok]);
 			}
 			mdoc_macro(mdoc, ntok, line, la, pos, buf);
 			if (nl)
 				append_delims(mdoc, line, pos, buf);
 			return;
 		}
 
 		/*
 		 * Non-quote-enclosed punctuation.  Set up our scope, if
 		 * a word; rewind the scope, if a delimiter; then append
 		 * the word.
 		 */
 
 		d = ac == ARGS_QWORD ? DELIM_NONE : mdoc_isdelim(p);
 
 		if (DELIM_NONE != d) {
 			/*
 			 * If we encounter closing punctuation, no word
 			 * has been emitted, no scope is open, and we're
 			 * allowed to have an empty element, then start
 			 * a new scope.
 			 */
 			if ((d == DELIM_CLOSE ||
 			     (d == DELIM_MIDDLE && tok == MDOC_Fl)) &&
 			    !cnt && !scope && nc && mayopen) {
 				mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
 				scope = 1;
 				cnt++;
 				if (tok == MDOC_Nm)
 					mayopen = 0;
 			}
 			/*
 			 * Close out our scope, if one is open, before
 			 * any punctuation.
 			 */
 			if (scope)
 				rew_elem(mdoc, tok);
 			scope = 0;
 			if (tok == MDOC_Fn)
 				mayopen = 0;
 		} else if (mayopen && !scope) {
 			mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
 			scope = 1;
 			cnt++;
 		}
 
 		dword(mdoc, line, la, p, d,
 		    MDOC_JOIN & mdoc_macros[tok].flags);
 
 		/*
 		 * If the first argument is a closing delimiter,
 		 * do not suppress spacing before it.
 		 */
 
 		if (firstarg && d == DELIM_CLOSE && !nc)
-			mdoc->last->flags &= ~MDOC_DELIMC;
+			mdoc->last->flags &= ~NODE_DELIMC;
 		firstarg = 0;
 
 		/*
 		 * `Fl' macros have their scope re-opened with each new
 		 * word so that the `-' can be added to each one without
 		 * having to parse out spaces.
 		 */
 		if (scope && tok == MDOC_Fl) {
 			rew_elem(mdoc, tok);
 			scope = 0;
 		}
 	}
 
 	if (scope)
 		rew_elem(mdoc, tok);
 
 	/*
 	 * If no elements have been collected and we're allowed to have
 	 * empties (nc), open a scope and close it out.  Otherwise,
 	 * raise a warning.
 	 */
 
 	if ( ! cnt) {
 		if (nc) {
 			mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
 			rew_last(mdoc, mdoc->last);
 		} else {
 			mdoc_argv_free(arg);
 			mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse,
 			    line, ppos, mdoc_macronames[tok]);
 		}
 	}
 	if (nl)
 		append_delims(mdoc, line, pos, buf);
 }
 
 static void
 blk_full(MACRO_PROT_ARGS)
 {
 	int		  la, nl, parsed;
 	struct mdoc_arg	 *arg;
 	struct roff_node *blk; /* Our own or a broken block. */
 	struct roff_node *head; /* Our own head. */
 	struct roff_node *body; /* Our own body. */
 	struct roff_node *n;
 	enum margserr	  ac, lac;
 	char		 *p;
 
 	nl = MDOC_NEWLINE & mdoc->flags;
 
 	if (buf[*pos] == '\0' && (tok == MDOC_Sh || tok == MDOC_Ss)) {
 		mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse,
 		    line, ppos, mdoc_macronames[tok]);
 		return;
 	}
 
 	if ( ! (mdoc_macros[tok].flags & MDOC_EXPLICIT)) {
 
 		/* Here, tok is one of Sh Ss Nm Nd It. */
 
 		blk = NULL;
 		for (n = mdoc->last; n != NULL; n = n->parent) {
-			if (n->flags & MDOC_ENDED) {
-				if ( ! (n->flags & MDOC_VALID))
-					n->flags |= MDOC_BROKEN;
+			if (n->flags & NODE_ENDED) {
+				if ( ! (n->flags & NODE_VALID))
+					n->flags |= NODE_BROKEN;
 				continue;
 			}
 			if (n->type != ROFFT_BLOCK)
 				continue;
 
 			if (tok == MDOC_It && n->tok == MDOC_Bl) {
 				if (blk != NULL) {
 					mandoc_vmsg(MANDOCERR_BLK_BROKEN,
 					    mdoc->parse, line, ppos,
 					    "It breaks %s",
 					    mdoc_macronames[blk->tok]);
 					rew_pending(mdoc, blk);
 				}
 				break;
 			}
 
 			if (mdoc_macros[n->tok].flags & MDOC_EXPLICIT) {
 				switch (tok) {
 				case MDOC_Sh:
 				case MDOC_Ss:
 					mandoc_vmsg(MANDOCERR_BLK_BROKEN,
 					    mdoc->parse, line, ppos,
 					    "%s breaks %s",
 					    mdoc_macronames[tok],
 					    mdoc_macronames[n->tok]);
 					rew_pending(mdoc, n);
 					n = mdoc->last;
 					continue;
 				case MDOC_It:
 					/* Delay in case it's astray. */
 					blk = n;
 					continue;
 				default:
 					break;
 				}
 				break;
 			}
 
 			/* Here, n is one of Sh Ss Nm Nd It. */
 
 			if (tok != MDOC_Sh && (n->tok == MDOC_Sh ||
 			    (tok != MDOC_Ss && (n->tok == MDOC_Ss ||
 			     (tok != MDOC_It && n->tok == MDOC_It)))))
 				break;
 
 			/* Item breaking an explicit block. */
 
 			if (blk != NULL) {
 				mandoc_vmsg(MANDOCERR_BLK_BROKEN,
 				    mdoc->parse, line, ppos,
 				    "It breaks %s",
 				    mdoc_macronames[blk->tok]);
 				rew_pending(mdoc, blk);
 				blk = NULL;
 			}
 
 			/* Close out prior implicit scopes. */
 
 			rew_last(mdoc, n);
 		}
 
 		/* Skip items outside lists. */
 
 		if (tok == MDOC_It && (n == NULL || n->tok != MDOC_Bl)) {
 			mandoc_vmsg(MANDOCERR_IT_STRAY, mdoc->parse,
 			    line, ppos, "It %s", buf + *pos);
 			roff_elem_alloc(mdoc, line, ppos, MDOC_br);
 			rew_elem(mdoc, MDOC_br);
 			return;
 		}
 	}
 
 	/*
 	 * This routine accommodates implicitly- and explicitly-scoped
 	 * macro openings.  Implicit ones first close out prior scope
 	 * (seen above).  Delay opening the head until necessary to
 	 * allow leading punctuation to print.  Special consideration
 	 * for `It -column', which has phrase-part syntax instead of
 	 * regular child nodes.
 	 */
 
 	mdoc_argv(mdoc, line, tok, &arg, pos, buf);
 	blk = mdoc_block_alloc(mdoc, line, ppos, tok, arg);
 	head = body = NULL;
 
 	/*
 	 * Exception: Heads of `It' macros in `-diag' lists are not
 	 * parsed, even though `It' macros in general are parsed.
 	 */
 
 	parsed = tok != MDOC_It ||
 	    mdoc->last->parent->tok != MDOC_Bl ||
 	    mdoc->last->parent->norm->Bl.type != LIST_diag;
 
 	/*
 	 * The `Nd' macro has all arguments in its body: it's a hybrid
 	 * of block partial-explicit and full-implicit.  Stupid.
 	 */
 
 	if (tok == MDOC_Nd) {
 		head = roff_head_alloc(mdoc, line, ppos, tok);
 		rew_last(mdoc, head);
 		body = roff_body_alloc(mdoc, line, ppos, tok);
 	}
 
 	if (tok == MDOC_Bk)
 		mdoc->flags |= MDOC_KEEP;
 
 	ac = ARGS_EOLN;
 	for (;;) {
 
 		/*
 		 * If we are right after a tab character,
 		 * do not parse the first word for macros.
 		 */
 
 		if (mdoc->flags & MDOC_PHRASEQN) {
 			mdoc->flags &= ~MDOC_PHRASEQN;
 			mdoc->flags |= MDOC_PHRASEQF;
 		}
 
 		la = *pos;
 		lac = ac;
 		ac = mdoc_args(mdoc, line, pos, buf, tok, &p);
 		if (ac == ARGS_EOLN) {
 			if (lac != ARGS_PHRASE ||
 			    ! (mdoc->flags & MDOC_PHRASEQF))
 				break;
 
 			/*
 			 * This line ends in a tab; start the next
 			 * column now, with a leading blank.
 			 */
 
 			if (body != NULL)
 				rew_last(mdoc, body);
 			body = roff_body_alloc(mdoc, line, ppos, tok);
 			roff_word_alloc(mdoc, line, ppos, "\\&");
 			break;
 		}
 
 		if (tok == MDOC_Bd || tok == MDOC_Bk) {
 			mandoc_vmsg(MANDOCERR_ARG_EXCESS,
 			    mdoc->parse, line, la, "%s ... %s",
 			    mdoc_macronames[tok], buf + la);
 			break;
 		}
 		if (tok == MDOC_Rs) {
 			mandoc_vmsg(MANDOCERR_ARG_SKIP, mdoc->parse,
 			    line, la, "Rs %s", buf + la);
 			break;
 		}
 		if (ac == ARGS_PUNCT)
 			break;
 
 		/*
 		 * Emit leading punctuation (i.e., punctuation before
 		 * the ROFFT_HEAD) for non-phrase types.
 		 */
 
 		if (head == NULL &&
 		    ac != ARGS_PHRASE &&
 		    ac != ARGS_QWORD &&
 		    mdoc_isdelim(p) == DELIM_OPEN) {
 			dword(mdoc, line, la, p, DELIM_OPEN, 0);
 			continue;
 		}
 
 		/* Open a head if one hasn't been opened. */
 
 		if (head == NULL)
 			head = roff_head_alloc(mdoc, line, ppos, tok);
 
 		if (ac == ARGS_PHRASE) {
 
 			/*
 			 * If we haven't opened a body yet, rewind the
 			 * head; if we have, rewind that instead.
 			 */
 
 			rew_last(mdoc, body == NULL ? head : body);
 			body = roff_body_alloc(mdoc, line, ppos, tok);
 
 			/* Process to the tab or to the end of the line. */
 
 			mdoc->flags |= MDOC_PHRASE;
 			parse_rest(mdoc, TOKEN_NONE, line, &la, buf);
 			mdoc->flags &= ~MDOC_PHRASE;
 
 			/* There may have been `Ta' macros. */
 
 			while (body->next != NULL)
 				body = body->next;
 			continue;
 		}
 
 		if (macro_or_word(mdoc, tok, line, la, pos, buf, parsed))
 			break;
 	}
 
-	if (blk->flags & MDOC_VALID)
+	if (blk->flags & NODE_VALID)
 		return;
 	if (head == NULL)
 		head = roff_head_alloc(mdoc, line, ppos, tok);
 	if (nl && tok != MDOC_Bd && tok != MDOC_Bl && tok != MDOC_Rs)
 		append_delims(mdoc, line, pos, buf);
 	if (body != NULL)
 		goto out;
 	if (find_pending(mdoc, tok, line, ppos, head))
 		return;
 
 	/* Close out scopes to remain in a consistent state. */
 
 	rew_last(mdoc, head);
 	body = roff_body_alloc(mdoc, line, ppos, tok);
 out:
 	if (mdoc->flags & MDOC_FREECOL) {
 		rew_last(mdoc, body);
 		rew_last(mdoc, blk);
 		mdoc->flags &= ~MDOC_FREECOL;
 	}
 }
 
 static void
 blk_part_imp(MACRO_PROT_ARGS)
 {
 	int		  la, nl;
 	enum margserr	  ac;
 	char		 *p;
 	struct roff_node *blk; /* saved block context */
 	struct roff_node *body; /* saved body context */
 	struct roff_node *n;
 
 	nl = MDOC_NEWLINE & mdoc->flags;
 
 	/*
 	 * A macro that spans to the end of the line.  This is generally
 	 * (but not necessarily) called as the first macro.  The block
 	 * has a head as the immediate child, which is always empty,
 	 * followed by zero or more opening punctuation nodes, then the
 	 * body (which may be empty, depending on the macro), then zero
 	 * or more closing punctuation nodes.
 	 */
 
 	blk = mdoc_block_alloc(mdoc, line, ppos, tok, NULL);
 	rew_last(mdoc, roff_head_alloc(mdoc, line, ppos, tok));
 
 	/*
 	 * Open the body scope "on-demand", that is, after we've
 	 * processed all our the leading delimiters (open parenthesis,
 	 * etc.).
 	 */
 
 	for (body = NULL; ; ) {
 		la = *pos;
 		ac = mdoc_args(mdoc, line, pos, buf, tok, &p);
 		if (ac == ARGS_EOLN || ac == ARGS_PUNCT)
 			break;
 
 		if (body == NULL && ac != ARGS_QWORD &&
 		    mdoc_isdelim(p) == DELIM_OPEN) {
 			dword(mdoc, line, la, p, DELIM_OPEN, 0);
 			continue;
 		}
 
 		if (body == NULL)
 			body = roff_body_alloc(mdoc, line, ppos, tok);
 
 		if (macro_or_word(mdoc, tok, line, la, pos, buf, 1))
 			break;
 	}
 	if (body == NULL)
 		body = roff_body_alloc(mdoc, line, ppos, tok);
 
 	if (find_pending(mdoc, tok, line, ppos, body))
 		return;
 
 	rew_last(mdoc, body);
 	if (nl)
 		append_delims(mdoc, line, pos, buf);
 	rew_pending(mdoc, blk);
 
 	/* Move trailing .Ns out of scope. */
 
 	for (n = body->child; n && n->next; n = n->next)
 		/* Do nothing. */ ;
 	if (n && n->tok == MDOC_Ns)
 		mdoc_node_relink(mdoc, n);
 }
 
 static void
 blk_part_exp(MACRO_PROT_ARGS)
 {
 	int		  la, nl;
 	enum margserr	  ac;
 	struct roff_node *head; /* keep track of head */
 	char		 *p;
 
 	nl = MDOC_NEWLINE & mdoc->flags;
 
 	/*
 	 * The opening of an explicit macro having zero or more leading
 	 * punctuation nodes; a head with optional single element (the
 	 * case of `Eo'); and a body that may be empty.
 	 */
 
 	roff_block_alloc(mdoc, line, ppos, tok);
 	head = NULL;
 	for (;;) {
 		la = *pos;
 		ac = mdoc_args(mdoc, line, pos, buf, tok, &p);
 		if (ac == ARGS_PUNCT || ac == ARGS_EOLN)
 			break;
 
 		/* Flush out leading punctuation. */
 
 		if (head == NULL && ac != ARGS_QWORD &&
 		    mdoc_isdelim(p) == DELIM_OPEN) {
 			dword(mdoc, line, la, p, DELIM_OPEN, 0);
 			continue;
 		}
 
 		if (head == NULL) {
 			head = roff_head_alloc(mdoc, line, ppos, tok);
 			if (tok == MDOC_Eo)  /* Not parsed. */
 				dword(mdoc, line, la, p, DELIM_MAX, 0);
 			rew_last(mdoc, head);
 			roff_body_alloc(mdoc, line, ppos, tok);
 			if (tok == MDOC_Eo)
 				continue;
 		}
 
 		if (macro_or_word(mdoc, tok, line, la, pos, buf, 1))
 			break;
 	}
 
 	/* Clean-up to leave in a consistent state. */
 
 	if (head == NULL) {
 		rew_last(mdoc, roff_head_alloc(mdoc, line, ppos, tok));
 		roff_body_alloc(mdoc, line, ppos, tok);
 	}
 	if (nl)
 		append_delims(mdoc, line, pos, buf);
 }
 
 static void
 in_line_argn(MACRO_PROT_ARGS)
 {
 	struct mdoc_arg	*arg;
 	char		*p;
 	enum margserr	 ac;
 	int		 ntok;
 	int		 state; /* arg#; -1: not yet open; -2: closed */
 	int		 la, maxargs, nl;
 
 	nl = mdoc->flags & MDOC_NEWLINE;
 
 	/*
 	 * A line macro that has a fixed number of arguments (maxargs).
 	 * Only open the scope once the first non-leading-punctuation is
 	 * found (unless MDOC_IGNDELIM is noted, like in `Pf'), then
 	 * keep it open until the maximum number of arguments are
 	 * exhausted.
 	 */
 
 	switch (tok) {
 	case MDOC_Ap:
 	case MDOC_Ns:
 	case MDOC_Ux:
 		maxargs = 0;
 		break;
 	case MDOC_Bx:
 	case MDOC_Es:
 	case MDOC_Xr:
 		maxargs = 2;
 		break;
 	default:
 		maxargs = 1;
 		break;
 	}
 
 	mdoc_argv(mdoc, line, tok, &arg, pos, buf);
 
 	state = -1;
 	p = NULL;
 	for (;;) {
 		la = *pos;
 		ac = mdoc_args(mdoc, line, pos, buf, tok, &p);
 
 		if (ac == ARGS_WORD && state == -1 &&
 		    ! (mdoc_macros[tok].flags & MDOC_IGNDELIM) &&
 		    mdoc_isdelim(p) == DELIM_OPEN) {
 			dword(mdoc, line, la, p, DELIM_OPEN, 0);
 			continue;
 		}
 
 		if (state == -1 && tok != MDOC_In &&
 		    tok != MDOC_St && tok != MDOC_Xr) {
 			mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
 			state = 0;
 		}
 
 		if (ac == ARGS_PUNCT || ac == ARGS_EOLN) {
 			if (abs(state) < 2 && tok == MDOC_Pf)
 				mandoc_vmsg(MANDOCERR_PF_SKIP,
 				    mdoc->parse, line, ppos, "Pf %s",
 				    p == NULL ? "at eol" : p);
 			break;
 		}
 
 		if (state == maxargs) {
 			rew_elem(mdoc, tok);
 			state = -2;
 		}
 
 		ntok = (ac == ARGS_QWORD || (tok == MDOC_Pf && state == 0)) ?
 		    TOKEN_NONE : lookup(mdoc, tok, line, la, p);
 
 		if (ntok != TOKEN_NONE) {
 			if (state >= 0) {
 				rew_elem(mdoc, tok);
 				state = -2;
 			}
 			mdoc_macro(mdoc, ntok, line, la, pos, buf);
 			break;
 		}
 
 		if (ac == ARGS_QWORD ||
 		    mdoc_macros[tok].flags & MDOC_IGNDELIM ||
 		    mdoc_isdelim(p) == DELIM_NONE) {
 			if (state == -1) {
 				mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
 				state = 1;
 			} else if (state >= 0)
 				state++;
 		} else if (state >= 0) {
 			rew_elem(mdoc, tok);
 			state = -2;
 		}
 
 		dword(mdoc, line, la, p, DELIM_MAX,
 		    MDOC_JOIN & mdoc_macros[tok].flags);
 	}
 
 	if (state == -1) {
 		mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse,
 		    line, ppos, mdoc_macronames[tok]);
 		return;
 	}
 
 	if (state == 0 && tok == MDOC_Pf)
 		append_delims(mdoc, line, pos, buf);
 	if (state >= 0)
 		rew_elem(mdoc, tok);
 	if (nl)
 		append_delims(mdoc, line, pos, buf);
 }
 
 static void
 in_line_eoln(MACRO_PROT_ARGS)
 {
 	struct roff_node	*n;
 	struct mdoc_arg		*arg;
 
 	if ((tok == MDOC_Pp || tok == MDOC_Lp) &&
 	    ! (mdoc->flags & MDOC_SYNOPSIS)) {
 		n = mdoc->last;
 		if (mdoc->next == ROFF_NEXT_SIBLING)
 			n = n->parent;
 		if (n->tok == MDOC_Nm)
 			rew_last(mdoc, n->parent);
 	}
 
 	if (buf[*pos] == '\0' &&
 	    (tok == MDOC_Fd || mdoc_macronames[tok][0] == '%')) {
 		mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse,
 		    line, ppos, mdoc_macronames[tok]);
 		return;
 	}
 
 	mdoc_argv(mdoc, line, tok, &arg, pos, buf);
 	mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
 	if (parse_rest(mdoc, tok, line, pos, buf))
 		return;
 	rew_elem(mdoc, tok);
 }
 
 /*
  * The simplest argument parser available: Parse the remaining
  * words until the end of the phrase or line and return 0
  * or until the next macro, call that macro, and return 1.
  */
 static int
 parse_rest(struct roff_man *mdoc, int tok, int line, int *pos, char *buf)
 {
 	int		 la;
 
 	for (;;) {
 		la = *pos;
 		if (mdoc_args(mdoc, line, pos, buf, tok, NULL) == ARGS_EOLN)
 			return 0;
 		if (macro_or_word(mdoc, tok, line, la, pos, buf, 1))
 			return 1;
 	}
 }
 
 static void
 ctx_synopsis(MACRO_PROT_ARGS)
 {
 
 	if (~mdoc->flags & (MDOC_SYNOPSIS | MDOC_NEWLINE))
 		in_line(mdoc, tok, line, ppos, pos, buf);
 	else if (tok == MDOC_Nm)
 		blk_full(mdoc, tok, line, ppos, pos, buf);
 	else {
 		assert(tok == MDOC_Vt);
 		blk_part_imp(mdoc, tok, line, ppos, pos, buf);
 	}
 }
 
 /*
  * Phrases occur within `Bl -column' entries, separated by `Ta' or tabs.
  * They're unusual because they're basically free-form text until a
  * macro is encountered.
  */
 static void
 phrase_ta(MACRO_PROT_ARGS)
 {
 	struct roff_node *body, *n;
 
 	/* Make sure we are in a column list or ignore this macro. */
 
 	body = NULL;
 	for (n = mdoc->last; n != NULL; n = n->parent) {
-		if (n->flags & MDOC_ENDED)
+		if (n->flags & NODE_ENDED)
 			continue;
 		if (n->tok == MDOC_It && n->type == ROFFT_BODY)
 			body = n;
-		if (n->tok == MDOC_Bl)
+		if (n->tok == MDOC_Bl && n->end == ENDBODY_NOT)
 			break;
 	}
 
 	if (n == NULL || n->norm->Bl.type != LIST_column) {
 		mandoc_msg(MANDOCERR_TA_STRAY, mdoc->parse,
 		    line, ppos, "Ta");
 		return;
 	}
 
 	/* Advance to the next column. */
 
 	rew_last(mdoc, body);
 	roff_body_alloc(mdoc, line, ppos, MDOC_It);
 	parse_rest(mdoc, TOKEN_NONE, line, pos, buf);
 }
Index: stable/11/contrib/mdocml/mdoc_man.c
===================================================================
--- stable/11/contrib/mdocml/mdoc_man.c	(revision 316419)
+++ stable/11/contrib/mdocml/mdoc_man.c	(revision 316420)
@@ -1,1804 +1,1696 @@
-/*	$Id: mdoc_man.c,v 1.96 2016/01/08 17:48:09 schwarze Exp $ */
+/*	$Id: mdoc_man.c,v 1.101 2017/01/11 17:39:53 schwarze Exp $ */
 /*
- * Copyright (c) 2011-2016 Ingo Schwarze 
+ * Copyright (c) 2011-2017 Ingo Schwarze 
  *
  * 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 "config.h"
 
 #include 
 
 #include 
 #include 
 #include 
 
 #include "mandoc_aux.h"
 #include "mandoc.h"
 #include "roff.h"
 #include "mdoc.h"
 #include "man.h"
 #include "out.h"
 #include "main.h"
 
 #define	DECL_ARGS const struct roff_meta *meta, struct roff_node *n
 
 struct	manact {
 	int		(*cond)(DECL_ARGS); /* DON'T run actions */
 	int		(*pre)(DECL_ARGS); /* pre-node action */
 	void		(*post)(DECL_ARGS); /* post-node action */
 	const char	 *prefix; /* pre-node string constant */
 	const char	 *suffix; /* post-node string constant */
 };
 
 static	int	  cond_body(DECL_ARGS);
 static	int	  cond_head(DECL_ARGS);
 static  void	  font_push(char);
 static	void	  font_pop(void);
 static	void	  mid_it(void);
 static	void	  post__t(DECL_ARGS);
 static	void	  post_aq(DECL_ARGS);
 static	void	  post_bd(DECL_ARGS);
 static	void	  post_bf(DECL_ARGS);
 static	void	  post_bk(DECL_ARGS);
 static	void	  post_bl(DECL_ARGS);
 static	void	  post_dl(DECL_ARGS);
 static	void	  post_en(DECL_ARGS);
 static	void	  post_enc(DECL_ARGS);
 static	void	  post_eo(DECL_ARGS);
 static	void	  post_fa(DECL_ARGS);
 static	void	  post_fd(DECL_ARGS);
 static	void	  post_fl(DECL_ARGS);
 static	void	  post_fn(DECL_ARGS);
 static	void	  post_fo(DECL_ARGS);
 static	void	  post_font(DECL_ARGS);
 static	void	  post_in(DECL_ARGS);
 static	void	  post_it(DECL_ARGS);
 static	void	  post_lb(DECL_ARGS);
 static	void	  post_nm(DECL_ARGS);
 static	void	  post_percent(DECL_ARGS);
 static	void	  post_pf(DECL_ARGS);
 static	void	  post_sect(DECL_ARGS);
 static	void	  post_sp(DECL_ARGS);
 static	void	  post_vt(DECL_ARGS);
 static	int	  pre__t(DECL_ARGS);
 static	int	  pre_an(DECL_ARGS);
 static	int	  pre_ap(DECL_ARGS);
 static	int	  pre_aq(DECL_ARGS);
 static	int	  pre_bd(DECL_ARGS);
 static	int	  pre_bf(DECL_ARGS);
 static	int	  pre_bk(DECL_ARGS);
 static	int	  pre_bl(DECL_ARGS);
 static	int	  pre_br(DECL_ARGS);
-static	int	  pre_bx(DECL_ARGS);
 static	int	  pre_dl(DECL_ARGS);
 static	int	  pre_en(DECL_ARGS);
 static	int	  pre_enc(DECL_ARGS);
 static	int	  pre_em(DECL_ARGS);
 static	int	  pre_skip(DECL_ARGS);
 static	int	  pre_eo(DECL_ARGS);
 static	int	  pre_ex(DECL_ARGS);
 static	int	  pre_fa(DECL_ARGS);
 static	int	  pre_fd(DECL_ARGS);
 static	int	  pre_fl(DECL_ARGS);
 static	int	  pre_fn(DECL_ARGS);
 static	int	  pre_fo(DECL_ARGS);
 static	int	  pre_ft(DECL_ARGS);
 static	int	  pre_in(DECL_ARGS);
 static	int	  pre_it(DECL_ARGS);
 static	int	  pre_lk(DECL_ARGS);
 static	int	  pre_li(DECL_ARGS);
 static	int	  pre_ll(DECL_ARGS);
 static	int	  pre_nm(DECL_ARGS);
 static	int	  pre_no(DECL_ARGS);
 static	int	  pre_ns(DECL_ARGS);
 static	int	  pre_pp(DECL_ARGS);
 static	int	  pre_rs(DECL_ARGS);
-static	int	  pre_rv(DECL_ARGS);
 static	int	  pre_sm(DECL_ARGS);
 static	int	  pre_sp(DECL_ARGS);
 static	int	  pre_sect(DECL_ARGS);
 static	int	  pre_sy(DECL_ARGS);
 static	void	  pre_syn(const struct roff_node *);
 static	int	  pre_vt(DECL_ARGS);
-static	int	  pre_ux(DECL_ARGS);
 static	int	  pre_xr(DECL_ARGS);
 static	void	  print_word(const char *);
 static	void	  print_line(const char *, int);
 static	void	  print_block(const char *, int);
 static	void	  print_offs(const char *, int);
 static	void	  print_width(const struct mdoc_bl *,
 			const struct roff_node *);
 static	void	  print_count(int *);
 static	void	  print_node(DECL_ARGS);
 
 static	const struct manact manacts[MDOC_MAX + 1] = {
 	{ NULL, pre_ap, NULL, NULL, NULL }, /* Ap */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Dd */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Dt */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Os */
 	{ NULL, pre_sect, post_sect, ".SH", NULL }, /* Sh */
 	{ NULL, pre_sect, post_sect, ".SS", NULL }, /* Ss */
 	{ NULL, pre_pp, NULL, NULL, NULL }, /* Pp */
 	{ cond_body, pre_dl, post_dl, NULL, NULL }, /* D1 */
 	{ cond_body, pre_dl, post_dl, NULL, NULL }, /* Dl */
 	{ cond_body, pre_bd, post_bd, NULL, NULL }, /* Bd */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Ed */
 	{ cond_body, pre_bl, post_bl, NULL, NULL }, /* Bl */
 	{ NULL, NULL, NULL, NULL, NULL }, /* El */
 	{ NULL, pre_it, post_it, NULL, NULL }, /* It */
 	{ NULL, pre_em, post_font, NULL, NULL }, /* Ad */
 	{ NULL, pre_an, NULL, NULL, NULL }, /* An */
 	{ NULL, pre_em, post_font, NULL, NULL }, /* Ar */
 	{ NULL, pre_sy, post_font, NULL, NULL }, /* Cd */
 	{ NULL, pre_sy, post_font, NULL, NULL }, /* Cm */
 	{ NULL, pre_li, post_font, NULL, NULL }, /* Dv */
 	{ NULL, pre_li, post_font, NULL, NULL }, /* Er */
 	{ NULL, pre_li, post_font, NULL, NULL }, /* Ev */
 	{ NULL, pre_ex, NULL, NULL, NULL }, /* Ex */
 	{ NULL, pre_fa, post_fa, NULL, NULL }, /* Fa */
 	{ NULL, pre_fd, post_fd, NULL, NULL }, /* Fd */
 	{ NULL, pre_fl, post_fl, NULL, NULL }, /* Fl */
 	{ NULL, pre_fn, post_fn, NULL, NULL }, /* Fn */
 	{ NULL, pre_ft, post_font, NULL, NULL }, /* Ft */
 	{ NULL, pre_sy, post_font, NULL, NULL }, /* Ic */
 	{ NULL, pre_in, post_in, NULL, NULL }, /* In */
 	{ NULL, pre_li, post_font, NULL, NULL }, /* Li */
 	{ cond_head, pre_enc, NULL, "\\- ", NULL }, /* Nd */
 	{ NULL, pre_nm, post_nm, NULL, NULL }, /* Nm */
 	{ cond_body, pre_enc, post_enc, "[", "]" }, /* Op */
 	{ NULL, pre_ft, post_font, NULL, NULL }, /* Ot */
 	{ NULL, pre_em, post_font, NULL, NULL }, /* Pa */
-	{ NULL, pre_rv, NULL, NULL, NULL }, /* Rv */
+	{ NULL, pre_ex, NULL, NULL, NULL }, /* Rv */
 	{ NULL, NULL, NULL, NULL, NULL }, /* St */
 	{ NULL, pre_em, post_font, NULL, NULL }, /* Va */
 	{ NULL, pre_vt, post_vt, NULL, NULL }, /* Vt */
 	{ NULL, pre_xr, NULL, NULL, NULL }, /* Xr */
 	{ NULL, NULL, post_percent, NULL, NULL }, /* %A */
 	{ NULL, pre_em, post_percent, NULL, NULL }, /* %B */
 	{ NULL, NULL, post_percent, NULL, NULL }, /* %D */
 	{ NULL, pre_em, post_percent, NULL, NULL }, /* %I */
 	{ NULL, pre_em, post_percent, NULL, NULL }, /* %J */
 	{ NULL, NULL, post_percent, NULL, NULL }, /* %N */
 	{ NULL, NULL, post_percent, NULL, NULL }, /* %O */
 	{ NULL, NULL, post_percent, NULL, NULL }, /* %P */
 	{ NULL, NULL, post_percent, NULL, NULL }, /* %R */
 	{ NULL, pre__t, post__t, NULL, NULL }, /* %T */
 	{ NULL, NULL, post_percent, NULL, NULL }, /* %V */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Ac */
 	{ cond_body, pre_aq, post_aq, NULL, NULL }, /* Ao */
 	{ cond_body, pre_aq, post_aq, NULL, NULL }, /* Aq */
 	{ NULL, NULL, NULL, NULL, NULL }, /* At */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Bc */
 	{ NULL, pre_bf, post_bf, NULL, NULL }, /* Bf */
 	{ cond_body, pre_enc, post_enc, "[", "]" }, /* Bo */
 	{ cond_body, pre_enc, post_enc, "[", "]" }, /* Bq */
-	{ NULL, pre_ux, NULL, "BSD/OS", NULL }, /* Bsx */
-	{ NULL, pre_bx, NULL, NULL, NULL }, /* Bx */
+	{ NULL, NULL, NULL, NULL, NULL }, /* Bsx */
+	{ NULL, NULL, NULL, NULL, NULL }, /* Bx */
 	{ NULL, pre_skip, NULL, NULL, NULL }, /* Db */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Dc */
 	{ cond_body, pre_enc, post_enc, "\\(Lq", "\\(Rq" }, /* Do */
 	{ cond_body, pre_enc, post_enc, "\\(Lq", "\\(Rq" }, /* Dq */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Ec */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Ef */
 	{ NULL, pre_em, post_font, NULL, NULL }, /* Em */
 	{ cond_body, pre_eo, post_eo, NULL, NULL }, /* Eo */
-	{ NULL, pre_ux, NULL, "FreeBSD", NULL }, /* Fx */
+	{ NULL, NULL, NULL, NULL, NULL }, /* Fx */
 	{ NULL, pre_sy, post_font, NULL, NULL }, /* Ms */
 	{ NULL, pre_no, NULL, NULL, NULL }, /* No */
 	{ NULL, pre_ns, NULL, NULL, NULL }, /* Ns */
-	{ NULL, pre_ux, NULL, "NetBSD", NULL }, /* Nx */
-	{ NULL, pre_ux, NULL, "OpenBSD", NULL }, /* Ox */
+	{ NULL, NULL, NULL, NULL, NULL }, /* Nx */
+	{ NULL, NULL, NULL, NULL, NULL }, /* Ox */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Pc */
 	{ NULL, NULL, post_pf, NULL, NULL }, /* Pf */
 	{ cond_body, pre_enc, post_enc, "(", ")" }, /* Po */
 	{ cond_body, pre_enc, post_enc, "(", ")" }, /* Pq */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Qc */
 	{ cond_body, pre_enc, post_enc, "\\(oq", "\\(cq" }, /* Ql */
 	{ cond_body, pre_enc, post_enc, "\"", "\"" }, /* Qo */
 	{ cond_body, pre_enc, post_enc, "\"", "\"" }, /* Qq */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Re */
 	{ cond_body, pre_rs, NULL, NULL, NULL }, /* Rs */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Sc */
 	{ cond_body, pre_enc, post_enc, "\\(oq", "\\(cq" }, /* So */
 	{ cond_body, pre_enc, post_enc, "\\(oq", "\\(cq" }, /* Sq */
 	{ NULL, pre_sm, NULL, NULL, NULL }, /* Sm */
 	{ NULL, pre_em, post_font, NULL, NULL }, /* Sx */
 	{ NULL, pre_sy, post_font, NULL, NULL }, /* Sy */
 	{ NULL, pre_li, post_font, NULL, NULL }, /* Tn */
-	{ NULL, pre_ux, NULL, "UNIX", NULL }, /* Ux */
+	{ NULL, NULL, NULL, NULL, NULL }, /* Ux */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Xc */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Xo */
 	{ NULL, pre_fo, post_fo, NULL, NULL }, /* Fo */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Fc */
 	{ cond_body, pre_enc, post_enc, "[", "]" }, /* Oo */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Oc */
 	{ NULL, pre_bk, post_bk, NULL, NULL }, /* Bk */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Ek */
-	{ NULL, pre_ux, NULL, "is currently in beta test.", NULL }, /* Bt */
+	{ NULL, NULL, NULL, NULL, NULL }, /* Bt */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Hf */
 	{ NULL, pre_em, post_font, NULL, NULL }, /* Fr */
-	{ NULL, pre_ux, NULL, "currently under development.", NULL }, /* Ud */
+	{ NULL, NULL, NULL, NULL, NULL }, /* Ud */
 	{ NULL, NULL, post_lb, NULL, NULL }, /* Lb */
 	{ NULL, pre_pp, NULL, NULL, NULL }, /* Lp */
 	{ NULL, pre_lk, NULL, NULL, NULL }, /* Lk */
 	{ NULL, pre_em, post_font, NULL, NULL }, /* Mt */
 	{ cond_body, pre_enc, post_enc, "{", "}" }, /* Brq */
 	{ cond_body, pre_enc, post_enc, "{", "}" }, /* Bro */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Brc */
 	{ NULL, NULL, post_percent, NULL, NULL }, /* %C */
 	{ NULL, pre_skip, NULL, NULL, NULL }, /* Es */
 	{ cond_body, pre_en, post_en, NULL, NULL }, /* En */
-	{ NULL, pre_ux, NULL, "DragonFly", NULL }, /* Dx */
+	{ NULL, NULL, NULL, NULL, NULL }, /* Dx */
 	{ NULL, NULL, post_percent, NULL, NULL }, /* %Q */
 	{ NULL, pre_br, NULL, NULL, NULL }, /* br */
 	{ NULL, pre_sp, post_sp, NULL, NULL }, /* sp */
 	{ NULL, NULL, post_percent, NULL, NULL }, /* %U */
 	{ NULL, NULL, NULL, NULL, NULL }, /* Ta */
 	{ NULL, pre_ll, post_sp, NULL, NULL }, /* ll */
 	{ NULL, NULL, NULL, NULL, NULL }, /* ROOT */
 };
 
 static	int		outflags;
 #define	MMAN_spc	(1 << 0)  /* blank character before next word */
 #define	MMAN_spc_force	(1 << 1)  /* even before trailing punctuation */
 #define	MMAN_nl		(1 << 2)  /* break man(7) code line */
 #define	MMAN_br		(1 << 3)  /* break output line */
 #define	MMAN_sp		(1 << 4)  /* insert a blank output line */
 #define	MMAN_PP		(1 << 5)  /* reset indentation etc. */
 #define	MMAN_Sm		(1 << 6)  /* horizontal spacing mode */
 #define	MMAN_Bk		(1 << 7)  /* word keep mode */
 #define	MMAN_Bk_susp	(1 << 8)  /* suspend this (after a macro) */
 #define	MMAN_An_split	(1 << 9)  /* author mode is "split" */
 #define	MMAN_An_nosplit	(1 << 10) /* author mode is "nosplit" */
 #define	MMAN_PD		(1 << 11) /* inter-paragraph spacing disabled */
 #define	MMAN_nbrword	(1 << 12) /* do not break the next word */
 
 #define	BL_STACK_MAX	32
 
 static	int		Bl_stack[BL_STACK_MAX];  /* offsets [chars] */
 static	int		Bl_stack_post[BL_STACK_MAX];  /* add final .RE */
 static	int		Bl_stack_len;  /* number of nested Bl blocks */
 static	int		TPremain;  /* characters before tag is full */
 
 static	struct {
 	char	*head;
 	char	*tail;
 	size_t	 size;
 }	fontqueue;
 
 
 static void
 font_push(char newfont)
 {
 
 	if (fontqueue.head + fontqueue.size <= ++fontqueue.tail) {
 		fontqueue.size += 8;
 		fontqueue.head = mandoc_realloc(fontqueue.head,
 		    fontqueue.size);
 	}
 	*fontqueue.tail = newfont;
 	print_word("");
 	printf("\\f");
 	putchar(newfont);
 	outflags &= ~MMAN_spc;
 }
 
 static void
 font_pop(void)
 {
 
 	if (fontqueue.tail > fontqueue.head)
 		fontqueue.tail--;
 	outflags &= ~MMAN_spc;
 	print_word("");
 	printf("\\f");
 	putchar(*fontqueue.tail);
 }
 
 static void
 print_word(const char *s)
 {
 
 	if ((MMAN_PP | MMAN_sp | MMAN_br | MMAN_nl) & outflags) {
 		/*
 		 * If we need a newline, print it now and start afresh.
 		 */
 		if (MMAN_PP & outflags) {
 			if (MMAN_sp & outflags) {
 				if (MMAN_PD & outflags) {
 					printf("\n.PD");
 					outflags &= ~MMAN_PD;
 				}
 			} else if ( ! (MMAN_PD & outflags)) {
 				printf("\n.PD 0");
 				outflags |= MMAN_PD;
 			}
 			printf("\n.PP\n");
 		} else if (MMAN_sp & outflags)
 			printf("\n.sp\n");
 		else if (MMAN_br & outflags)
 			printf("\n.br\n");
 		else if (MMAN_nl & outflags)
 			putchar('\n');
 		outflags &= ~(MMAN_PP|MMAN_sp|MMAN_br|MMAN_nl|MMAN_spc);
 		if (1 == TPremain)
 			printf(".br\n");
 		TPremain = 0;
 	} else if (MMAN_spc & outflags) {
 		/*
 		 * If we need a space, only print it if
 		 * (1) it is forced by `No' or
 		 * (2) what follows is not terminating punctuation or
 		 * (3) what follows is longer than one character.
 		 */
 		if (MMAN_spc_force & outflags || '\0' == s[0] ||
 		    NULL == strchr(".,:;)]?!", s[0]) || '\0' != s[1]) {
 			if (MMAN_Bk & outflags &&
 			    ! (MMAN_Bk_susp & outflags))
 				putchar('\\');
 			putchar(' ');
 			if (TPremain)
 				TPremain--;
 		}
 	}
 
 	/*
 	 * Reassign needing space if we're not following opening
 	 * punctuation.
 	 */
 	if (MMAN_Sm & outflags && ('\0' == s[0] ||
 	    (('(' != s[0] && '[' != s[0]) || '\0' != s[1])))
 		outflags |= MMAN_spc;
 	else
 		outflags &= ~MMAN_spc;
 	outflags &= ~(MMAN_spc_force | MMAN_Bk_susp);
 
 	for ( ; *s; s++) {
 		switch (*s) {
 		case ASCII_NBRSP:
 			printf("\\ ");
 			break;
 		case ASCII_HYPH:
 			putchar('-');
 			break;
 		case ASCII_BREAK:
 			printf("\\:");
 			break;
 		case ' ':
 			if (MMAN_nbrword & outflags) {
 				printf("\\ ");
 				break;
 			}
 			/* FALLTHROUGH */
 		default:
 			putchar((unsigned char)*s);
 			break;
 		}
 		if (TPremain)
 			TPremain--;
 	}
 	outflags &= ~MMAN_nbrword;
 }
 
 static void
 print_line(const char *s, int newflags)
 {
 
 	outflags &= ~MMAN_br;
 	outflags |= MMAN_nl;
 	print_word(s);
 	outflags |= newflags;
 }
 
 static void
 print_block(const char *s, int newflags)
 {
 
 	outflags &= ~MMAN_PP;
 	if (MMAN_sp & outflags) {
 		outflags &= ~(MMAN_sp | MMAN_br);
 		if (MMAN_PD & outflags) {
 			print_line(".PD", 0);
 			outflags &= ~MMAN_PD;
 		}
 	} else if (! (MMAN_PD & outflags))
 		print_line(".PD 0", MMAN_PD);
 	outflags |= MMAN_nl;
 	print_word(s);
 	outflags |= MMAN_Bk_susp | newflags;
 }
 
 static void
 print_offs(const char *v, int keywords)
 {
 	char		  buf[24];
 	struct roffsu	  su;
 	int		  sz;
 
 	print_line(".RS", MMAN_Bk_susp);
 
 	/* Convert v into a number (of characters). */
 	if (NULL == v || '\0' == *v || (keywords && !strcmp(v, "left")))
 		sz = 0;
 	else if (keywords && !strcmp(v, "indent"))
 		sz = 6;
 	else if (keywords && !strcmp(v, "indent-two"))
 		sz = 12;
 	else if (a2roffsu(v, &su, SCALE_EN) > 1) {
 		if (SCALE_EN == su.unit)
 			sz = su.scale;
 		else {
 			/*
 			 * XXX
 			 * If we are inside an enclosing list,
 			 * there is no easy way to add the two
 			 * indentations because they are provided
 			 * in terms of different units.
 			 */
 			print_word(v);
 			outflags |= MMAN_nl;
 			return;
 		}
 	} else
 		sz = strlen(v);
 
 	/*
 	 * We are inside an enclosing list.
 	 * Add the two indentations.
 	 */
 	if (Bl_stack_len)
 		sz += Bl_stack[Bl_stack_len - 1];
 
 	(void)snprintf(buf, sizeof(buf), "%dn", sz);
 	print_word(buf);
 	outflags |= MMAN_nl;
 }
 
 /*
  * Set up the indentation for a list item; used from pre_it().
  */
 static void
 print_width(const struct mdoc_bl *bl, const struct roff_node *child)
 {
 	char		  buf[24];
 	struct roffsu	  su;
 	int		  numeric, remain, sz, chsz;
 
 	numeric = 1;
 	remain = 0;
 
 	/* Convert the width into a number (of characters). */
 	if (bl->width == NULL)
 		sz = (bl->type == LIST_hang) ? 6 : 0;
 	else if (a2roffsu(bl->width, &su, SCALE_MAX) > 1) {
 		if (SCALE_EN == su.unit)
 			sz = su.scale;
 		else {
 			sz = 0;
 			numeric = 0;
 		}
 	} else
 		sz = strlen(bl->width);
 
 	/* XXX Rough estimation, might have multiple parts. */
 	if (bl->type == LIST_enum)
 		chsz = (bl->count > 8) + 1;
 	else if (child != NULL && child->type == ROFFT_TEXT)
 		chsz = strlen(child->string);
 	else
 		chsz = 0;
 
 	/* Maybe we are inside an enclosing list? */
 	mid_it();
 
 	/*
 	 * Save our own indentation,
 	 * such that child lists can use it.
 	 */
 	Bl_stack[Bl_stack_len++] = sz + 2;
 
 	/* Set up the current list. */
 	if (chsz > sz && bl->type != LIST_tag)
 		print_block(".HP", 0);
 	else {
 		print_block(".TP", 0);
 		remain = sz + 2;
 	}
 	if (numeric) {
 		(void)snprintf(buf, sizeof(buf), "%dn", sz + 2);
 		print_word(buf);
 	} else
 		print_word(bl->width);
 	TPremain = remain;
 }
 
 static void
 print_count(int *count)
 {
 	char		  buf[24];
 
 	(void)snprintf(buf, sizeof(buf), "%d.\\&", ++*count);
 	print_word(buf);
 }
 
 void
 man_man(void *arg, const struct roff_man *man)
 {
 
 	/*
 	 * Dump the keep buffer.
 	 * We're guaranteed by now that this exists (is non-NULL).
 	 * Flush stdout afterward, just in case.
 	 */
 	fputs(mparse_getkeep(man_mparse(man)), stdout);
 	fflush(stdout);
 }
 
 void
 man_mdoc(void *arg, const struct roff_man *mdoc)
 {
 	struct roff_node *n;
 
 	printf(".TH \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n",
 	    mdoc->meta.title,
 	    (mdoc->meta.msec == NULL ? "" : mdoc->meta.msec),
 	    mdoc->meta.date, mdoc->meta.os, mdoc->meta.vol);
 
 	/* Disable hyphenation and if nroff, disable justification. */
 	printf(".nh\n.if n .ad l");
 
 	outflags = MMAN_nl | MMAN_Sm;
 	if (0 == fontqueue.size) {
 		fontqueue.size = 8;
 		fontqueue.head = fontqueue.tail = mandoc_malloc(8);
 		*fontqueue.tail = 'R';
 	}
 	for (n = mdoc->first->child; n != NULL; n = n->next)
 		print_node(&mdoc->meta, n);
 	putchar('\n');
 }
 
 static void
 print_node(DECL_ARGS)
 {
 	const struct manact	*act;
 	struct roff_node	*sub;
 	int			 cond, do_sub;
 
+	if (n->flags & NODE_NOPRT)
+		return;
+
 	/*
 	 * Break the line if we were parsed subsequent the current node.
 	 * This makes the page structure be more consistent.
 	 */
-	if (MMAN_spc & outflags && MDOC_LINE & n->flags)
+	if (MMAN_spc & outflags && NODE_LINE & n->flags)
 		outflags |= MMAN_nl;
 
 	act = NULL;
 	cond = 0;
 	do_sub = 1;
-	n->flags &= ~MDOC_ENDED;
+	n->flags &= ~NODE_ENDED;
 
 	if (n->type == ROFFT_TEXT) {
 		/*
 		 * Make sure that we don't happen to start with a
 		 * control character at the start of a line.
 		 */
 		if (MMAN_nl & outflags &&
 		    ('.' == *n->string || '\'' == *n->string)) {
 			print_word("");
 			printf("\\&");
 			outflags &= ~MMAN_spc;
 		}
-		if (outflags & MMAN_Sm && ! (n->flags & MDOC_DELIMC))
+		if (n->flags & NODE_DELIMC)
+			outflags &= ~(MMAN_spc | MMAN_spc_force);
+		else if (outflags & MMAN_Sm)
 			outflags |= MMAN_spc_force;
 		print_word(n->string);
-		if (outflags & MMAN_Sm && ! (n->flags & MDOC_DELIMO))
+		if (n->flags & NODE_DELIMO)
+			outflags &= ~(MMAN_spc | MMAN_spc_force);
+		else if (outflags & MMAN_Sm)
 			outflags |= MMAN_spc;
 	} else {
 		/*
 		 * Conditionally run the pre-node action handler for a
 		 * node.
 		 */
 		act = manacts + n->tok;
 		cond = act->cond == NULL || (*act->cond)(meta, n);
 		if (cond && act->pre != NULL &&
 		    (n->end == ENDBODY_NOT || n->child != NULL))
 			do_sub = (*act->pre)(meta, n);
 	}
 
 	/*
 	 * Conditionally run all child nodes.
 	 * Note that this iterates over children instead of using
 	 * recursion.  This prevents unnecessary depth in the stack.
 	 */
 	if (do_sub)
 		for (sub = n->child; sub; sub = sub->next)
 			print_node(meta, sub);
 
 	/*
 	 * Lastly, conditionally run the post-node handler.
 	 */
-	if (MDOC_ENDED & n->flags)
+	if (NODE_ENDED & n->flags)
 		return;
 
 	if (cond && act->post)
 		(*act->post)(meta, n);
 
 	if (ENDBODY_NOT != n->end)
-		n->body->flags |= MDOC_ENDED;
+		n->body->flags |= NODE_ENDED;
 
 	if (ENDBODY_NOSPACE == n->end)
 		outflags &= ~(MMAN_spc | MMAN_nl);
 }
 
 static int
 cond_head(DECL_ARGS)
 {
 
 	return n->type == ROFFT_HEAD;
 }
 
 static int
 cond_body(DECL_ARGS)
 {
 
 	return n->type == ROFFT_BODY;
 }
 
 static int
 pre_enc(DECL_ARGS)
 {
 	const char	*prefix;
 
 	prefix = manacts[n->tok].prefix;
 	if (NULL == prefix)
 		return 1;
 	print_word(prefix);
 	outflags &= ~MMAN_spc;
 	return 1;
 }
 
 static void
 post_enc(DECL_ARGS)
 {
 	const char *suffix;
 
 	suffix = manacts[n->tok].suffix;
 	if (NULL == suffix)
 		return;
 	outflags &= ~(MMAN_spc | MMAN_nl);
 	print_word(suffix);
 }
 
 static int
 pre_ex(DECL_ARGS)
 {
-	struct roff_node *nch;
-
 	outflags |= MMAN_br | MMAN_nl;
-
-	print_word("The");
-
-	for (nch = n->child; nch != NULL; nch = nch->next) {
-		font_push('B');
-		print_word(nch->string);
-		font_pop();
-
-		if (nch->next == NULL)
-			continue;
-
-		if (nch->prev != NULL || nch->next->next != NULL) {
-			outflags &= ~MMAN_spc;
-			print_word(",");
-		}
-		if (nch->next->next == NULL)
-			print_word("and");
-	}
-
-	if (n->child != NULL && n->child->next != NULL)
-		print_word("utilities exit\\~0");
-	else
-		print_word("utility exits\\~0");
-
-	print_word("on success, and\\~>0 if an error occurs.");
-	outflags |= MMAN_nl;
-	return 0;
+	return 1;
 }
 
 static void
 post_font(DECL_ARGS)
 {
 
 	font_pop();
 }
 
 static void
 post_percent(DECL_ARGS)
 {
 
 	if (pre_em == manacts[n->tok].pre)
 		font_pop();
 	if (n->next) {
 		print_word(",");
 		if (n->prev &&	n->prev->tok == n->tok &&
 				n->next->tok == n->tok)
 			print_word("and");
 	} else {
 		print_word(".");
 		outflags |= MMAN_nl;
 	}
 }
 
 static int
 pre__t(DECL_ARGS)
 {
 
 	if (n->parent && MDOC_Rs == n->parent->tok &&
 	    n->parent->norm->Rs.quote_T) {
 		print_word("");
 		putchar('\"');
 		outflags &= ~MMAN_spc;
 	} else
 		font_push('I');
 	return 1;
 }
 
 static void
 post__t(DECL_ARGS)
 {
 
 	if (n->parent && MDOC_Rs == n->parent->tok &&
 	    n->parent->norm->Rs.quote_T) {
 		outflags &= ~MMAN_spc;
 		print_word("");
 		putchar('\"');
 	} else
 		font_pop();
 	post_percent(meta, n);
 }
 
 /*
  * Print before a section header.
  */
 static int
 pre_sect(DECL_ARGS)
 {
 
 	if (n->type == ROFFT_HEAD) {
 		outflags |= MMAN_sp;
 		print_block(manacts[n->tok].prefix, 0);
 		print_word("");
 		putchar('\"');
 		outflags &= ~MMAN_spc;
 	}
 	return 1;
 }
 
 /*
  * Print subsequent a section header.
  */
 static void
 post_sect(DECL_ARGS)
 {
 
 	if (n->type != ROFFT_HEAD)
 		return;
 	outflags &= ~MMAN_spc;
 	print_word("");
 	putchar('\"');
 	outflags |= MMAN_nl;
 	if (MDOC_Sh == n->tok && SEC_AUTHORS == n->sec)
 		outflags &= ~(MMAN_An_split | MMAN_An_nosplit);
 }
 
 /* See mdoc_term.c, synopsis_pre() for comments. */
 static void
 pre_syn(const struct roff_node *n)
 {
 
-	if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags))
+	if (NULL == n->prev || ! (NODE_SYNPRETTY & n->flags))
 		return;
 
 	if (n->prev->tok == n->tok &&
 	    MDOC_Ft != n->tok &&
 	    MDOC_Fo != n->tok &&
 	    MDOC_Fn != n->tok) {
 		outflags |= MMAN_br;
 		return;
 	}
 
 	switch (n->prev->tok) {
 	case MDOC_Fd:
 	case MDOC_Fn:
 	case MDOC_Fo:
 	case MDOC_In:
 	case MDOC_Vt:
 		outflags |= MMAN_sp;
 		break;
 	case MDOC_Ft:
 		if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
 			outflags |= MMAN_sp;
 			break;
 		}
 		/* FALLTHROUGH */
 	default:
 		outflags |= MMAN_br;
 		break;
 	}
 }
 
 static int
 pre_an(DECL_ARGS)
 {
 
 	switch (n->norm->An.auth) {
 	case AUTH_split:
 		outflags &= ~MMAN_An_nosplit;
 		outflags |= MMAN_An_split;
 		return 0;
 	case AUTH_nosplit:
 		outflags &= ~MMAN_An_split;
 		outflags |= MMAN_An_nosplit;
 		return 0;
 	default:
 		if (MMAN_An_split & outflags)
 			outflags |= MMAN_br;
 		else if (SEC_AUTHORS == n->sec &&
 		    ! (MMAN_An_nosplit & outflags))
 			outflags |= MMAN_An_split;
 		return 1;
 	}
 }
 
 static int
 pre_ap(DECL_ARGS)
 {
 
 	outflags &= ~MMAN_spc;
 	print_word("'");
 	outflags &= ~MMAN_spc;
 	return 0;
 }
 
 static int
 pre_aq(DECL_ARGS)
 {
 
 	print_word(n->child != NULL && n->child->next == NULL &&
 	    n->child->tok == MDOC_Mt ?  "<" : "\\(la");
 	outflags &= ~MMAN_spc;
 	return 1;
 }
 
 static void
 post_aq(DECL_ARGS)
 {
 
 	outflags &= ~(MMAN_spc | MMAN_nl);
 	print_word(n->child != NULL && n->child->next == NULL &&
 	    n->child->tok == MDOC_Mt ?  ">" : "\\(ra");
 }
 
 static int
 pre_bd(DECL_ARGS)
 {
 
 	outflags &= ~(MMAN_PP | MMAN_sp | MMAN_br);
 
 	if (DISP_unfilled == n->norm->Bd.type ||
 	    DISP_literal  == n->norm->Bd.type)
 		print_line(".nf", 0);
 	if (0 == n->norm->Bd.comp && NULL != n->parent->prev)
 		outflags |= MMAN_sp;
 	print_offs(n->norm->Bd.offs, 1);
 	return 1;
 }
 
 static void
 post_bd(DECL_ARGS)
 {
 
 	/* Close out this display. */
 	print_line(".RE", MMAN_nl);
 	if (DISP_unfilled == n->norm->Bd.type ||
 	    DISP_literal  == n->norm->Bd.type)
 		print_line(".fi", MMAN_nl);
 
 	/* Maybe we are inside an enclosing list? */
 	if (NULL != n->parent->next)
 		mid_it();
 }
 
 static int
 pre_bf(DECL_ARGS)
 {
 
 	switch (n->type) {
 	case ROFFT_BLOCK:
 		return 1;
 	case ROFFT_BODY:
 		break;
 	default:
 		return 0;
 	}
 	switch (n->norm->Bf.font) {
 	case FONT_Em:
 		font_push('I');
 		break;
 	case FONT_Sy:
 		font_push('B');
 		break;
 	default:
 		font_push('R');
 		break;
 	}
 	return 1;
 }
 
 static void
 post_bf(DECL_ARGS)
 {
 
 	if (n->type == ROFFT_BODY)
 		font_pop();
 }
 
 static int
 pre_bk(DECL_ARGS)
 {
 
 	switch (n->type) {
 	case ROFFT_BLOCK:
 		return 1;
 	case ROFFT_BODY:
 		outflags |= MMAN_Bk;
 		return 1;
 	default:
 		return 0;
 	}
 }
 
 static void
 post_bk(DECL_ARGS)
 {
 
 	if (n->type == ROFFT_BODY)
 		outflags &= ~MMAN_Bk;
 }
 
 static int
 pre_bl(DECL_ARGS)
 {
 	size_t		 icol;
 
 	/*
 	 * print_offs() will increase the -offset to account for
 	 * a possible enclosing .It, but any enclosed .It blocks
 	 * just nest and do not add up their indentation.
 	 */
 	if (n->norm->Bl.offs) {
 		print_offs(n->norm->Bl.offs, 0);
 		Bl_stack[Bl_stack_len++] = 0;
 	}
 
 	switch (n->norm->Bl.type) {
 	case LIST_enum:
 		n->norm->Bl.count = 0;
 		return 1;
 	case LIST_column:
 		break;
 	default:
 		return 1;
 	}
 
 	if (n->child != NULL) {
 		print_line(".TS", MMAN_nl);
 		for (icol = 0; icol < n->norm->Bl.ncols; icol++)
 			print_word("l");
 		print_word(".");
 	}
 	outflags |= MMAN_nl;
 	return 1;
 }
 
 static void
 post_bl(DECL_ARGS)
 {
 
 	switch (n->norm->Bl.type) {
 	case LIST_column:
 		if (n->child != NULL)
 			print_line(".TE", 0);
 		break;
 	case LIST_enum:
 		n->norm->Bl.count = 0;
 		break;
 	default:
 		break;
 	}
 
 	if (n->norm->Bl.offs) {
 		print_line(".RE", MMAN_nl);
 		assert(Bl_stack_len);
 		Bl_stack_len--;
 		assert(0 == Bl_stack[Bl_stack_len]);
 	} else {
 		outflags |= MMAN_PP | MMAN_nl;
 		outflags &= ~(MMAN_sp | MMAN_br);
 	}
 
 	/* Maybe we are inside an enclosing list? */
 	if (NULL != n->parent->next)
 		mid_it();
 
 }
 
 static int
 pre_br(DECL_ARGS)
 {
 
 	outflags |= MMAN_br;
 	return 0;
 }
 
 static int
-pre_bx(DECL_ARGS)
-{
-
-	n = n->child;
-	if (n) {
-		print_word(n->string);
-		outflags &= ~MMAN_spc;
-		n = n->next;
-	}
-	print_word("BSD");
-	if (NULL == n)
-		return 0;
-	outflags &= ~MMAN_spc;
-	print_word("-");
-	outflags &= ~MMAN_spc;
-	print_word(n->string);
-	return 0;
-}
-
-static int
 pre_dl(DECL_ARGS)
 {
 
 	print_offs("6n", 0);
 	return 1;
 }
 
 static void
 post_dl(DECL_ARGS)
 {
 
 	print_line(".RE", MMAN_nl);
 
 	/* Maybe we are inside an enclosing list? */
 	if (NULL != n->parent->next)
 		mid_it();
 }
 
 static int
 pre_em(DECL_ARGS)
 {
 
 	font_push('I');
 	return 1;
 }
 
 static int
 pre_en(DECL_ARGS)
 {
 
 	if (NULL == n->norm->Es ||
 	    NULL == n->norm->Es->child)
 		return 1;
 
 	print_word(n->norm->Es->child->string);
 	outflags &= ~MMAN_spc;
 	return 1;
 }
 
 static void
 post_en(DECL_ARGS)
 {
 
 	if (NULL == n->norm->Es ||
 	    NULL == n->norm->Es->child ||
 	    NULL == n->norm->Es->child->next)
 		return;
 
 	outflags &= ~MMAN_spc;
 	print_word(n->norm->Es->child->next->string);
 	return;
 }
 
 static int
 pre_eo(DECL_ARGS)
 {
 
 	if (n->end == ENDBODY_NOT &&
 	    n->parent->head->child == NULL &&
 	    n->child != NULL &&
 	    n->child->end != ENDBODY_NOT)
 		print_word("\\&");
 	else if (n->end != ENDBODY_NOT ? n->child != NULL :
 	    n->parent->head->child != NULL && (n->child != NULL ||
 	    (n->parent->tail != NULL && n->parent->tail->child != NULL)))
 		outflags &= ~(MMAN_spc | MMAN_nl);
 	return 1;
 }
 
 static void
 post_eo(DECL_ARGS)
 {
 	int	 body, tail;
 
 	if (n->end != ENDBODY_NOT) {
 		outflags |= MMAN_spc;
 		return;
 	}
 
 	body = n->child != NULL || n->parent->head->child != NULL;
 	tail = n->parent->tail != NULL && n->parent->tail->child != NULL;
 
 	if (body && tail)
 		outflags &= ~MMAN_spc;
 	else if ( ! (body || tail))
 		print_word("\\&");
 	else if ( ! tail)
 		outflags |= MMAN_spc;
 }
 
 static int
 pre_fa(DECL_ARGS)
 {
 	int	 am_Fa;
 
 	am_Fa = MDOC_Fa == n->tok;
 
 	if (am_Fa)
 		n = n->child;
 
 	while (NULL != n) {
 		font_push('I');
-		if (am_Fa || MDOC_SYNPRETTY & n->flags)
+		if (am_Fa || NODE_SYNPRETTY & n->flags)
 			outflags |= MMAN_nbrword;
 		print_node(meta, n);
 		font_pop();
 		if (NULL != (n = n->next))
 			print_word(",");
 	}
 	return 0;
 }
 
 static void
 post_fa(DECL_ARGS)
 {
 
 	if (NULL != n->next && MDOC_Fa == n->next->tok)
 		print_word(",");
 }
 
 static int
 pre_fd(DECL_ARGS)
 {
 
 	pre_syn(n);
 	font_push('B');
 	return 1;
 }
 
 static void
 post_fd(DECL_ARGS)
 {
 
 	font_pop();
 	outflags |= MMAN_br;
 }
 
 static int
 pre_fl(DECL_ARGS)
 {
 
 	font_push('B');
 	print_word("\\-");
 	if (n->child != NULL)
 		outflags &= ~MMAN_spc;
 	return 1;
 }
 
 static void
 post_fl(DECL_ARGS)
 {
 
 	font_pop();
 	if (!(n->child != NULL ||
 	    n->next == NULL ||
 	    n->next->type == ROFFT_TEXT ||
-	    n->next->flags & MDOC_LINE))
+	    n->next->flags & NODE_LINE))
 		outflags &= ~MMAN_spc;
 }
 
 static int
 pre_fn(DECL_ARGS)
 {
 
 	pre_syn(n);
 
 	n = n->child;
 	if (NULL == n)
 		return 0;
 
-	if (MDOC_SYNPRETTY & n->flags)
+	if (NODE_SYNPRETTY & n->flags)
 		print_block(".HP 4n", MMAN_nl);
 
 	font_push('B');
 	print_node(meta, n);
 	font_pop();
 	outflags &= ~MMAN_spc;
 	print_word("(");
 	outflags &= ~MMAN_spc;
 
 	n = n->next;
 	if (NULL != n)
 		pre_fa(meta, n);
 	return 0;
 }
 
 static void
 post_fn(DECL_ARGS)
 {
 
 	print_word(")");
-	if (MDOC_SYNPRETTY & n->flags) {
+	if (NODE_SYNPRETTY & n->flags) {
 		print_word(";");
 		outflags |= MMAN_PP;
 	}
 }
 
 static int
 pre_fo(DECL_ARGS)
 {
 
 	switch (n->type) {
 	case ROFFT_BLOCK:
 		pre_syn(n);
 		break;
 	case ROFFT_HEAD:
 		if (n->child == NULL)
 			return 0;
-		if (MDOC_SYNPRETTY & n->flags)
+		if (NODE_SYNPRETTY & n->flags)
 			print_block(".HP 4n", MMAN_nl);
 		font_push('B');
 		break;
 	case ROFFT_BODY:
 		outflags &= ~(MMAN_spc | MMAN_nl);
 		print_word("(");
 		outflags &= ~MMAN_spc;
 		break;
 	default:
 		break;
 	}
 	return 1;
 }
 
 static void
 post_fo(DECL_ARGS)
 {
 
 	switch (n->type) {
 	case ROFFT_HEAD:
 		if (n->child != NULL)
 			font_pop();
 		break;
 	case ROFFT_BODY:
 		post_fn(meta, n);
 		break;
 	default:
 		break;
 	}
 }
 
 static int
 pre_ft(DECL_ARGS)
 {
 
 	pre_syn(n);
 	font_push('I');
 	return 1;
 }
 
 static int
 pre_in(DECL_ARGS)
 {
 
-	if (MDOC_SYNPRETTY & n->flags) {
+	if (NODE_SYNPRETTY & n->flags) {
 		pre_syn(n);
 		font_push('B');
 		print_word("#include <");
 		outflags &= ~MMAN_spc;
 	} else {
 		print_word("<");
 		outflags &= ~MMAN_spc;
 		font_push('I');
 	}
 	return 1;
 }
 
 static void
 post_in(DECL_ARGS)
 {
 
-	if (MDOC_SYNPRETTY & n->flags) {
+	if (NODE_SYNPRETTY & n->flags) {
 		outflags &= ~MMAN_spc;
 		print_word(">");
 		font_pop();
 		outflags |= MMAN_br;
 	} else {
 		font_pop();
 		outflags &= ~MMAN_spc;
 		print_word(">");
 	}
 }
 
 static int
 pre_it(DECL_ARGS)
 {
 	const struct roff_node *bln;
 
 	switch (n->type) {
 	case ROFFT_HEAD:
 		outflags |= MMAN_PP | MMAN_nl;
 		bln = n->parent->parent;
 		if (0 == bln->norm->Bl.comp ||
 		    (NULL == n->parent->prev &&
 		     NULL == bln->parent->prev))
 			outflags |= MMAN_sp;
 		outflags &= ~MMAN_br;
 		switch (bln->norm->Bl.type) {
 		case LIST_item:
 			return 0;
 		case LIST_inset:
 		case LIST_diag:
 		case LIST_ohang:
 			if (bln->norm->Bl.type == LIST_diag)
 				print_line(".B \"", 0);
 			else
 				print_line(".R \"", 0);
 			outflags &= ~MMAN_spc;
 			return 1;
 		case LIST_bullet:
 		case LIST_dash:
 		case LIST_hyphen:
 			print_width(&bln->norm->Bl, NULL);
 			TPremain = 0;
 			outflags |= MMAN_nl;
 			font_push('B');
 			if (LIST_bullet == bln->norm->Bl.type)
 				print_word("\\(bu");
 			else
 				print_word("-");
 			font_pop();
 			outflags |= MMAN_nl;
 			return 0;
 		case LIST_enum:
 			print_width(&bln->norm->Bl, NULL);
 			TPremain = 0;
 			outflags |= MMAN_nl;
 			print_count(&bln->norm->Bl.count);
 			outflags |= MMAN_nl;
 			return 0;
 		case LIST_hang:
 			print_width(&bln->norm->Bl, n->child);
 			TPremain = 0;
 			outflags |= MMAN_nl;
 			return 1;
 		case LIST_tag:
 			print_width(&bln->norm->Bl, n->child);
 			putchar('\n');
 			outflags &= ~MMAN_spc;
 			return 1;
 		default:
 			return 1;
 		}
 	default:
 		break;
 	}
 	return 1;
 }
 
 /*
  * This function is called after closing out an indented block.
  * If we are inside an enclosing list, restore its indentation.
  */
 static void
 mid_it(void)
 {
 	char		 buf[24];
 
 	/* Nothing to do outside a list. */
 	if (0 == Bl_stack_len || 0 == Bl_stack[Bl_stack_len - 1])
 		return;
 
 	/* The indentation has already been set up. */
 	if (Bl_stack_post[Bl_stack_len - 1])
 		return;
 
 	/* Restore the indentation of the enclosing list. */
 	print_line(".RS", MMAN_Bk_susp);
 	(void)snprintf(buf, sizeof(buf), "%dn",
 	    Bl_stack[Bl_stack_len - 1]);
 	print_word(buf);
 
 	/* Remeber to close out this .RS block later. */
 	Bl_stack_post[Bl_stack_len - 1] = 1;
 }
 
 static void
 post_it(DECL_ARGS)
 {
 	const struct roff_node *bln;
 
 	bln = n->parent->parent;
 
 	switch (n->type) {
 	case ROFFT_HEAD:
 		switch (bln->norm->Bl.type) {
 		case LIST_diag:
 			outflags &= ~MMAN_spc;
 			print_word("\\ ");
 			break;
 		case LIST_ohang:
 			outflags |= MMAN_br;
 			break;
 		default:
 			break;
 		}
 		break;
 	case ROFFT_BODY:
 		switch (bln->norm->Bl.type) {
 		case LIST_bullet:
 		case LIST_dash:
 		case LIST_hyphen:
 		case LIST_enum:
 		case LIST_hang:
 		case LIST_tag:
 			assert(Bl_stack_len);
 			Bl_stack[--Bl_stack_len] = 0;
 
 			/*
 			 * Our indentation had to be restored
 			 * after a child display or child list.
 			 * Close out that indentation block now.
 			 */
 			if (Bl_stack_post[Bl_stack_len]) {
 				print_line(".RE", MMAN_nl);
 				Bl_stack_post[Bl_stack_len] = 0;
 			}
 			break;
 		case LIST_column:
 			if (NULL != n->next) {
 				putchar('\t');
 				outflags &= ~MMAN_spc;
 			}
 			break;
 		default:
 			break;
 		}
 		break;
 	default:
 		break;
 	}
 }
 
 static void
 post_lb(DECL_ARGS)
 {
 
 	if (SEC_LIBRARY == n->sec)
 		outflags |= MMAN_br;
 }
 
 static int
 pre_lk(DECL_ARGS)
 {
 	const struct roff_node *link, *descr;
 
 	if (NULL == (link = n->child))
 		return 0;
 
 	if (NULL != (descr = link->next)) {
 		font_push('I');
 		while (NULL != descr) {
 			print_word(descr->string);
 			descr = descr->next;
 		}
 		print_word(":");
 		font_pop();
 	}
 
 	font_push('B');
 	print_word(link->string);
 	font_pop();
 	return 0;
 }
 
 static int
 pre_ll(DECL_ARGS)
 {
 
 	print_line(".ll", 0);
 	return 1;
 }
 
 static int
 pre_li(DECL_ARGS)
 {
 
 	font_push('R');
 	return 1;
 }
 
 static int
 pre_nm(DECL_ARGS)
 {
 	char	*name;
 
 	if (n->type == ROFFT_BLOCK) {
 		outflags |= MMAN_Bk;
 		pre_syn(n);
 	}
 	if (n->type != ROFFT_ELEM && n->type != ROFFT_HEAD)
 		return 1;
 	name = n->child ? n->child->string : meta->name;
 	if (NULL == name)
 		return 0;
 	if (n->type == ROFFT_HEAD) {
 		if (NULL == n->parent->prev)
 			outflags |= MMAN_sp;
 		print_block(".HP", 0);
 		printf(" %zun", strlen(name) + 1);
 		outflags |= MMAN_nl;
 	}
 	font_push('B');
 	if (NULL == n->child)
 		print_word(meta->name);
 	return 1;
 }
 
 static void
 post_nm(DECL_ARGS)
 {
 
 	switch (n->type) {
 	case ROFFT_BLOCK:
 		outflags &= ~MMAN_Bk;
 		break;
 	case ROFFT_HEAD:
 	case ROFFT_ELEM:
 		if (n->child != NULL || meta->name != NULL)
 			font_pop();
 		break;
 	default:
 		break;
 	}
 }
 
 static int
 pre_no(DECL_ARGS)
 {
 
 	outflags |= MMAN_spc_force;
 	return 1;
 }
 
 static int
 pre_ns(DECL_ARGS)
 {
 
 	outflags &= ~MMAN_spc;
 	return 0;
 }
 
 static void
 post_pf(DECL_ARGS)
 {
 
-	if ( ! (n->next == NULL || n->next->flags & MDOC_LINE))
+	if ( ! (n->next == NULL || n->next->flags & NODE_LINE))
 		outflags &= ~MMAN_spc;
 }
 
 static int
 pre_pp(DECL_ARGS)
 {
 
 	if (MDOC_It != n->parent->tok)
 		outflags |= MMAN_PP;
 	outflags |= MMAN_sp | MMAN_nl;
 	outflags &= ~MMAN_br;
 	return 0;
 }
 
 static int
 pre_rs(DECL_ARGS)
 {
 
 	if (SEC_SEE_ALSO == n->sec) {
 		outflags |= MMAN_PP | MMAN_sp | MMAN_nl;
 		outflags &= ~MMAN_br;
 	}
 	return 1;
 }
 
 static int
-pre_rv(DECL_ARGS)
-{
-	struct roff_node *nch;
-
-	outflags |= MMAN_br | MMAN_nl;
-
-	if (n->child != NULL) {
-		print_word("The");
-
-		for (nch = n->child; nch != NULL; nch = nch->next) {
-			font_push('B');
-			print_word(nch->string);
-			font_pop();
-
-			outflags &= ~MMAN_spc;
-			print_word("()");
-
-			if (nch->next == NULL)
-				continue;
-
-			if (nch->prev != NULL || nch->next->next != NULL) {
-				outflags &= ~MMAN_spc;
-				print_word(",");
-			}
-			if (nch->next->next == NULL)
-				print_word("and");
-		}
-
-		if (n->child != NULL && n->child->next != NULL)
-			print_word("functions return");
-		else
-			print_word("function returns");
-
-		print_word("the value\\~0 if successful;");
-	} else
-		print_word("Upon successful completion, "
-		    "the value\\~0 is returned;");
-
-	print_word("otherwise the value\\~\\-1 is returned"
-	    " and the global variable");
-
-	font_push('I');
-	print_word("errno");
-	font_pop();
-
-	print_word("is set to indicate the error.");
-	outflags |= MMAN_nl;
-	return 0;
-}
-
-static int
 pre_skip(DECL_ARGS)
 {
 
 	return 0;
 }
 
 static int
 pre_sm(DECL_ARGS)
 {
 
 	if (NULL == n->child)
 		outflags ^= MMAN_Sm;
 	else if (0 == strcmp("on", n->child->string))
 		outflags |= MMAN_Sm;
 	else
 		outflags &= ~MMAN_Sm;
 
 	if (MMAN_Sm & outflags)
 		outflags |= MMAN_spc;
 
 	return 0;
 }
 
 static int
 pre_sp(DECL_ARGS)
 {
 
 	if (MMAN_PP & outflags) {
 		outflags &= ~MMAN_PP;
 		print_line(".PP", 0);
 	} else
 		print_line(".sp", 0);
 	return 1;
 }
 
 static void
 post_sp(DECL_ARGS)
 {
 
 	outflags |= MMAN_nl;
 }
 
 static int
 pre_sy(DECL_ARGS)
 {
 
 	font_push('B');
 	return 1;
 }
 
 static int
 pre_vt(DECL_ARGS)
 {
 
-	if (MDOC_SYNPRETTY & n->flags) {
+	if (NODE_SYNPRETTY & n->flags) {
 		switch (n->type) {
 		case ROFFT_BLOCK:
 			pre_syn(n);
 			return 1;
 		case ROFFT_BODY:
 			break;
 		default:
 			return 0;
 		}
 	}
 	font_push('I');
 	return 1;
 }
 
 static void
 post_vt(DECL_ARGS)
 {
 
-	if (n->flags & MDOC_SYNPRETTY && n->type != ROFFT_BODY)
+	if (n->flags & NODE_SYNPRETTY && n->type != ROFFT_BODY)
 		return;
 	font_pop();
 }
 
 static int
 pre_xr(DECL_ARGS)
 {
 
 	n = n->child;
 	if (NULL == n)
 		return 0;
 	print_node(meta, n);
 	n = n->next;
 	if (NULL == n)
 		return 0;
 	outflags &= ~MMAN_spc;
 	print_word("(");
 	print_node(meta, n);
 	print_word(")");
 	return 0;
-}
-
-static int
-pre_ux(DECL_ARGS)
-{
-
-	print_word(manacts[n->tok].prefix);
-	if (NULL == n->child)
-		return 0;
-	outflags &= ~MMAN_spc;
-	print_word("\\ ");
-	outflags &= ~MMAN_spc;
-	return 1;
 }
Index: stable/11/contrib/mdocml/mdoc_state.c
===================================================================
--- stable/11/contrib/mdocml/mdoc_state.c	(revision 316419)
+++ stable/11/contrib/mdocml/mdoc_state.c	(revision 316420)
@@ -1,292 +1,292 @@
-/*	$Id: mdoc_state.c,v 1.3 2015/10/30 18:53:54 schwarze Exp $ */
+/*	$Id: mdoc_state.c,v 1.4 2017/01/10 13:47:00 schwarze Exp $ */
 /*
  * Copyright (c) 2014, 2015 Ingo Schwarze 
  *
  * 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 
 
 #include 
 #include 
 
 #include "mandoc.h"
 #include "roff.h"
 #include "mdoc.h"
 #include "libmandoc.h"
 #include "libmdoc.h"
 
 #define STATE_ARGS  struct roff_man *mdoc, struct roff_node *n
 
 typedef	void	(*state_handler)(STATE_ARGS);
 
 static	void	 state_bd(STATE_ARGS);
 static	void	 state_bl(STATE_ARGS);
 static	void	 state_dl(STATE_ARGS);
 static	void	 state_sh(STATE_ARGS);
 static	void	 state_sm(STATE_ARGS);
 
 static	const state_handler state_handlers[MDOC_MAX] = {
 	NULL,		/* Ap */
 	NULL,		/* Dd */
 	NULL,		/* Dt */
 	NULL,		/* Os */
 	state_sh,	/* Sh */
 	NULL,		/* Ss */
 	NULL,		/* Pp */
 	NULL,		/* D1 */
 	state_dl,	/* Dl */
 	state_bd,	/* Bd */
 	NULL,		/* Ed */
 	state_bl,	/* Bl */
 	NULL,		/* El */
 	NULL,		/* It */
 	NULL,		/* Ad */
 	NULL,		/* An */
 	NULL,		/* Ar */
 	NULL,		/* Cd */
 	NULL,		/* Cm */
 	NULL,		/* Dv */
 	NULL,		/* Er */
 	NULL,		/* Ev */
 	NULL,		/* Ex */
 	NULL,		/* Fa */
 	NULL,		/* Fd */
 	NULL,		/* Fl */
 	NULL,		/* Fn */
 	NULL,		/* Ft */
 	NULL,		/* Ic */
 	NULL,		/* In */
 	NULL,		/* Li */
 	NULL,		/* Nd */
 	NULL,		/* Nm */
 	NULL,		/* Op */
 	NULL,		/* Ot */
 	NULL,		/* Pa */
 	NULL,		/* Rv */
 	NULL,		/* St */
 	NULL,		/* Va */
 	NULL,		/* Vt */
 	NULL,		/* Xr */
 	NULL,		/* %A */
 	NULL,		/* %B */
 	NULL,		/* %D */
 	NULL,		/* %I */
 	NULL,		/* %J */
 	NULL,		/* %N */
 	NULL,		/* %O */
 	NULL,		/* %P */
 	NULL,		/* %R */
 	NULL,		/* %T */
 	NULL,		/* %V */
 	NULL,		/* Ac */
 	NULL,		/* Ao */
 	NULL,		/* Aq */
 	NULL,		/* At */
 	NULL,		/* Bc */
 	NULL,		/* Bf */
 	NULL,		/* Bo */
 	NULL,		/* Bq */
 	NULL,		/* Bsx */
 	NULL,		/* Bx */
 	NULL,		/* Db */
 	NULL,		/* Dc */
 	NULL,		/* Do */
 	NULL,		/* Dq */
 	NULL,		/* Ec */
 	NULL,		/* Ef */
 	NULL,		/* Em */
 	NULL,		/* Eo */
 	NULL,		/* Fx */
 	NULL,		/* Ms */
 	NULL,		/* No */
 	NULL,		/* Ns */
 	NULL,		/* Nx */
 	NULL,		/* Ox */
 	NULL,		/* Pc */
 	NULL,		/* Pf */
 	NULL,		/* Po */
 	NULL,		/* Pq */
 	NULL,		/* Qc */
 	NULL,		/* Ql */
 	NULL,		/* Qo */
 	NULL,		/* Qq */
 	NULL,		/* Re */
 	NULL,		/* Rs */
 	NULL,		/* Sc */
 	NULL,		/* So */
 	NULL,		/* Sq */
 	state_sm,	/* Sm */
 	NULL,		/* Sx */
 	NULL,		/* Sy */
 	NULL,		/* Tn */
 	NULL,		/* Ux */
 	NULL,		/* Xc */
 	NULL,		/* Xo */
 	NULL,		/* Fo */
 	NULL,		/* Fc */
 	NULL,		/* Oo */
 	NULL,		/* Oc */
 	NULL,		/* Bk */
 	NULL,		/* Ek */
 	NULL,		/* Bt */
 	NULL,		/* Hf */
 	NULL,		/* Fr */
 	NULL,		/* Ud */
 	NULL,		/* Lb */
 	NULL,		/* Lp */
 	NULL,		/* Lk */
 	NULL,		/* Mt */
 	NULL,		/* Brq */
 	NULL,		/* Bro */
 	NULL,		/* Brc */
 	NULL,		/* %C */
 	NULL,		/* Es */
 	NULL,		/* En */
 	NULL,		/* Dx */
 	NULL,		/* %Q */
 	NULL,		/* br */
 	NULL,		/* sp */
 	NULL,		/* %U */
 	NULL,		/* Ta */
 	NULL,		/* ll */
 };
 
 
 void
 mdoc_state(struct roff_man *mdoc, struct roff_node *n)
 {
 	state_handler handler;
 
 	if (n->tok == TOKEN_NONE)
 		return;
 
 	if ( ! (mdoc_macros[n->tok].flags & MDOC_PROLOGUE))
 		mdoc->flags |= MDOC_PBODY;
 
 	handler = state_handlers[n->tok];
 	if (*handler)
 		(*handler)(mdoc, n);
 }
 
 void
 mdoc_state_reset(struct roff_man *mdoc)
 {
 
 	roff_setreg(mdoc->roff, "nS", 0, '=');
 	mdoc->flags = 0;
 }
 
 static void
 state_bd(STATE_ARGS)
 {
 	enum mdocargt arg;
 
 	if (n->type != ROFFT_HEAD &&
 	    (n->type != ROFFT_BODY || n->end != ENDBODY_NOT))
 		return;
 
 	if (n->parent->args == NULL)
 		return;
 
 	arg = n->parent->args->argv[0].arg;
 	if (arg != MDOC_Literal && arg != MDOC_Unfilled)
 		return;
 
 	state_dl(mdoc, n);
 }
 
 static void
 state_bl(STATE_ARGS)
 {
 
 	if (n->type != ROFFT_HEAD || n->parent->args == NULL)
 		return;
 
 	switch(n->parent->args->argv[0].arg) {
 	case MDOC_Diag:
 		n->norm->Bl.type = LIST_diag;
 		break;
 	case MDOC_Column:
 		n->norm->Bl.type = LIST_column;
 		break;
 	default:
 		break;
 	}
 }
 
 static void
 state_dl(STATE_ARGS)
 {
 
 	switch (n->type) {
 	case ROFFT_HEAD:
 		mdoc->flags |= MDOC_LITERAL;
 		break;
 	case ROFFT_BODY:
 		mdoc->flags &= ~MDOC_LITERAL;
 		break;
 	default:
 		break;
 	}
 }
 
 static void
 state_sh(STATE_ARGS)
 {
 	struct roff_node *nch;
 	char		 *secname;
 
 	if (n->type != ROFFT_HEAD)
 		return;
 
-	if ( ! (n->flags & MDOC_VALID)) {
+	if ( ! (n->flags & NODE_VALID)) {
 		secname = NULL;
 		deroff(&secname, n);
 
 		/*
 		 * Set the section attribute for the BLOCK, HEAD,
 		 * and HEAD children; the latter can only be TEXT
 		 * nodes, so no recursion is needed.  For other
 		 * nodes, including the .Sh BODY, this is done
 		 * when allocating the node data structures, but
 		 * for .Sh BLOCK and HEAD, the section is still
 		 * unknown at that time.
 		 */
 
 		n->sec = n->parent->sec = secname == NULL ?
 		    SEC_CUSTOM : mdoc_a2sec(secname);
 		for (nch = n->child; nch != NULL; nch = nch->next)
 			nch->sec = n->sec;
 		free(secname);
 	}
 
 	if ((mdoc->lastsec = n->sec) == SEC_SYNOPSIS) {
 		roff_setreg(mdoc->roff, "nS", 1, '=');
 		mdoc->flags |= MDOC_SYNOPSIS;
 	} else {
 		roff_setreg(mdoc->roff, "nS", 0, '=');
 		mdoc->flags &= ~MDOC_SYNOPSIS;
 	}
 }
 
 static void
 state_sm(STATE_ARGS)
 {
 
 	if (n->child == NULL)
 		mdoc->flags ^= MDOC_SMOFF;
 	else if ( ! strcmp(n->child->string, "on"))
 		mdoc->flags &= ~MDOC_SMOFF;
 	else if ( ! strcmp(n->child->string, "off"))
 		mdoc->flags |= MDOC_SMOFF;
 }
Index: stable/11/contrib/mdocml/mdoc_term.c
===================================================================
--- stable/11/contrib/mdocml/mdoc_term.c	(revision 316419)
+++ stable/11/contrib/mdocml/mdoc_term.c	(revision 316420)
@@ -1,2245 +1,2131 @@
-/*	$Id: mdoc_term.c,v 1.331 2016/01/08 17:48:09 schwarze Exp $ */
+/*	$Id: mdoc_term.c,v 1.341 2017/01/11 17:39:53 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons 
- * Copyright (c) 2010, 2012-2016 Ingo Schwarze 
+ * Copyright (c) 2010, 2012-2017 Ingo Schwarze 
  * Copyright (c) 2013 Franco Fichtner 
  *
  * 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 AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h"
 
 #include 
 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 
 #include "mandoc_aux.h"
 #include "mandoc.h"
 #include "roff.h"
 #include "mdoc.h"
 #include "out.h"
 #include "term.h"
 #include "tag.h"
 #include "main.h"
 
 struct	termpair {
 	struct termpair	 *ppair;
 	int		  count;
 };
 
 #define	DECL_ARGS struct termp *p, \
 		  struct termpair *pair, \
 		  const struct roff_meta *meta, \
 		  struct roff_node *n
 
 struct	termact {
 	int	(*pre)(DECL_ARGS);
 	void	(*post)(DECL_ARGS);
 };
 
 static	int	  a2width(const struct termp *, const char *);
 
 static	void	  print_bvspace(struct termp *,
 			const struct roff_node *,
 			const struct roff_node *);
 static	void	  print_mdoc_node(DECL_ARGS);
 static	void	  print_mdoc_nodelist(DECL_ARGS);
 static	void	  print_mdoc_head(struct termp *, const struct roff_meta *);
 static	void	  print_mdoc_foot(struct termp *, const struct roff_meta *);
 static	void	  synopsis_pre(struct termp *,
 			const struct roff_node *);
 
 static	void	  termp____post(DECL_ARGS);
 static	void	  termp__t_post(DECL_ARGS);
 static	void	  termp_bd_post(DECL_ARGS);
 static	void	  termp_bk_post(DECL_ARGS);
 static	void	  termp_bl_post(DECL_ARGS);
 static	void	  termp_eo_post(DECL_ARGS);
 static	void	  termp_fd_post(DECL_ARGS);
 static	void	  termp_fo_post(DECL_ARGS);
 static	void	  termp_in_post(DECL_ARGS);
 static	void	  termp_it_post(DECL_ARGS);
 static	void	  termp_lb_post(DECL_ARGS);
 static	void	  termp_nm_post(DECL_ARGS);
 static	void	  termp_pf_post(DECL_ARGS);
 static	void	  termp_quote_post(DECL_ARGS);
 static	void	  termp_sh_post(DECL_ARGS);
 static	void	  termp_ss_post(DECL_ARGS);
+static	void	  termp_xx_post(DECL_ARGS);
 
 static	int	  termp__a_pre(DECL_ARGS);
 static	int	  termp__t_pre(DECL_ARGS);
 static	int	  termp_an_pre(DECL_ARGS);
 static	int	  termp_ap_pre(DECL_ARGS);
 static	int	  termp_bd_pre(DECL_ARGS);
 static	int	  termp_bf_pre(DECL_ARGS);
 static	int	  termp_bk_pre(DECL_ARGS);
 static	int	  termp_bl_pre(DECL_ARGS);
 static	int	  termp_bold_pre(DECL_ARGS);
-static	int	  termp_bt_pre(DECL_ARGS);
-static	int	  termp_bx_pre(DECL_ARGS);
 static	int	  termp_cd_pre(DECL_ARGS);
 static	int	  termp_d1_pre(DECL_ARGS);
 static	int	  termp_eo_pre(DECL_ARGS);
+static	int	  termp_em_pre(DECL_ARGS);
 static	int	  termp_er_pre(DECL_ARGS);
 static	int	  termp_ex_pre(DECL_ARGS);
 static	int	  termp_fa_pre(DECL_ARGS);
 static	int	  termp_fd_pre(DECL_ARGS);
 static	int	  termp_fl_pre(DECL_ARGS);
 static	int	  termp_fn_pre(DECL_ARGS);
 static	int	  termp_fo_pre(DECL_ARGS);
 static	int	  termp_ft_pre(DECL_ARGS);
 static	int	  termp_in_pre(DECL_ARGS);
 static	int	  termp_it_pre(DECL_ARGS);
 static	int	  termp_li_pre(DECL_ARGS);
 static	int	  termp_ll_pre(DECL_ARGS);
 static	int	  termp_lk_pre(DECL_ARGS);
 static	int	  termp_nd_pre(DECL_ARGS);
 static	int	  termp_nm_pre(DECL_ARGS);
 static	int	  termp_ns_pre(DECL_ARGS);
 static	int	  termp_quote_pre(DECL_ARGS);
 static	int	  termp_rs_pre(DECL_ARGS);
-static	int	  termp_rv_pre(DECL_ARGS);
 static	int	  termp_sh_pre(DECL_ARGS);
 static	int	  termp_skip_pre(DECL_ARGS);
 static	int	  termp_sm_pre(DECL_ARGS);
 static	int	  termp_sp_pre(DECL_ARGS);
 static	int	  termp_ss_pre(DECL_ARGS);
+static	int	  termp_sy_pre(DECL_ARGS);
 static	int	  termp_tag_pre(DECL_ARGS);
 static	int	  termp_under_pre(DECL_ARGS);
-static	int	  termp_ud_pre(DECL_ARGS);
 static	int	  termp_vt_pre(DECL_ARGS);
 static	int	  termp_xr_pre(DECL_ARGS);
 static	int	  termp_xx_pre(DECL_ARGS);
 
 static	const struct termact termacts[MDOC_MAX] = {
 	{ termp_ap_pre, NULL }, /* Ap */
 	{ NULL, NULL }, /* Dd */
 	{ NULL, NULL }, /* Dt */
 	{ NULL, NULL }, /* Os */
 	{ termp_sh_pre, termp_sh_post }, /* Sh */
 	{ termp_ss_pre, termp_ss_post }, /* Ss */
 	{ termp_sp_pre, NULL }, /* Pp */
 	{ termp_d1_pre, termp_bl_post }, /* D1 */
 	{ termp_d1_pre, termp_bl_post }, /* Dl */
 	{ termp_bd_pre, termp_bd_post }, /* Bd */
 	{ NULL, NULL }, /* Ed */
 	{ termp_bl_pre, termp_bl_post }, /* Bl */
 	{ NULL, NULL }, /* El */
 	{ termp_it_pre, termp_it_post }, /* It */
 	{ termp_under_pre, NULL }, /* Ad */
 	{ termp_an_pre, NULL }, /* An */
 	{ termp_under_pre, NULL }, /* Ar */
 	{ termp_cd_pre, NULL }, /* Cd */
 	{ termp_bold_pre, NULL }, /* Cm */
 	{ termp_li_pre, NULL }, /* Dv */
 	{ termp_er_pre, NULL }, /* Er */
 	{ termp_tag_pre, NULL }, /* Ev */
 	{ termp_ex_pre, NULL }, /* Ex */
 	{ termp_fa_pre, NULL }, /* Fa */
 	{ termp_fd_pre, termp_fd_post }, /* Fd */
 	{ termp_fl_pre, NULL }, /* Fl */
 	{ termp_fn_pre, NULL }, /* Fn */
 	{ termp_ft_pre, NULL }, /* Ft */
 	{ termp_bold_pre, NULL }, /* Ic */
 	{ termp_in_pre, termp_in_post }, /* In */
 	{ termp_li_pre, NULL }, /* Li */
 	{ termp_nd_pre, NULL }, /* Nd */
 	{ termp_nm_pre, termp_nm_post }, /* Nm */
 	{ termp_quote_pre, termp_quote_post }, /* Op */
 	{ termp_ft_pre, NULL }, /* Ot */
 	{ termp_under_pre, NULL }, /* Pa */
-	{ termp_rv_pre, NULL }, /* Rv */
+	{ termp_ex_pre, NULL }, /* Rv */
 	{ NULL, NULL }, /* St */
 	{ termp_under_pre, NULL }, /* Va */
 	{ termp_vt_pre, NULL }, /* Vt */
 	{ termp_xr_pre, NULL }, /* Xr */
 	{ termp__a_pre, termp____post }, /* %A */
 	{ termp_under_pre, termp____post }, /* %B */
 	{ NULL, termp____post }, /* %D */
 	{ termp_under_pre, termp____post }, /* %I */
 	{ termp_under_pre, termp____post }, /* %J */
 	{ NULL, termp____post }, /* %N */
 	{ NULL, termp____post }, /* %O */
 	{ NULL, termp____post }, /* %P */
 	{ NULL, termp____post }, /* %R */
 	{ termp__t_pre, termp__t_post }, /* %T */
 	{ NULL, termp____post }, /* %V */
 	{ NULL, NULL }, /* Ac */
 	{ termp_quote_pre, termp_quote_post }, /* Ao */
 	{ termp_quote_pre, termp_quote_post }, /* Aq */
 	{ NULL, NULL }, /* At */
 	{ NULL, NULL }, /* Bc */
 	{ termp_bf_pre, NULL }, /* Bf */
 	{ termp_quote_pre, termp_quote_post }, /* Bo */
 	{ termp_quote_pre, termp_quote_post }, /* Bq */
-	{ termp_xx_pre, NULL }, /* Bsx */
-	{ termp_bx_pre, NULL }, /* Bx */
+	{ termp_xx_pre, termp_xx_post }, /* Bsx */
+	{ NULL, NULL }, /* Bx */
 	{ termp_skip_pre, NULL }, /* Db */
 	{ NULL, NULL }, /* Dc */
 	{ termp_quote_pre, termp_quote_post }, /* Do */
 	{ termp_quote_pre, termp_quote_post }, /* Dq */
 	{ NULL, NULL }, /* Ec */ /* FIXME: no space */
 	{ NULL, NULL }, /* Ef */
-	{ termp_under_pre, NULL }, /* Em */
+	{ termp_em_pre, NULL }, /* Em */
 	{ termp_eo_pre, termp_eo_post }, /* Eo */
-	{ termp_xx_pre, NULL }, /* Fx */
+	{ termp_xx_pre, termp_xx_post }, /* Fx */
 	{ termp_bold_pre, NULL }, /* Ms */
 	{ termp_li_pre, NULL }, /* No */
 	{ termp_ns_pre, NULL }, /* Ns */
-	{ termp_xx_pre, NULL }, /* Nx */
-	{ termp_xx_pre, NULL }, /* Ox */
+	{ termp_xx_pre, termp_xx_post }, /* Nx */
+	{ termp_xx_pre, termp_xx_post }, /* Ox */
 	{ NULL, NULL }, /* Pc */
 	{ NULL, termp_pf_post }, /* Pf */
 	{ termp_quote_pre, termp_quote_post }, /* Po */
 	{ termp_quote_pre, termp_quote_post }, /* Pq */
 	{ NULL, NULL }, /* Qc */
 	{ termp_quote_pre, termp_quote_post }, /* Ql */
 	{ termp_quote_pre, termp_quote_post }, /* Qo */
 	{ termp_quote_pre, termp_quote_post }, /* Qq */
 	{ NULL, NULL }, /* Re */
 	{ termp_rs_pre, NULL }, /* Rs */
 	{ NULL, NULL }, /* Sc */
 	{ termp_quote_pre, termp_quote_post }, /* So */
 	{ termp_quote_pre, termp_quote_post }, /* Sq */
 	{ termp_sm_pre, NULL }, /* Sm */
 	{ termp_under_pre, NULL }, /* Sx */
-	{ termp_bold_pre, NULL }, /* Sy */
+	{ termp_sy_pre, NULL }, /* Sy */
 	{ NULL, NULL }, /* Tn */
-	{ termp_xx_pre, NULL }, /* Ux */
+	{ termp_xx_pre, termp_xx_post }, /* Ux */
 	{ NULL, NULL }, /* Xc */
 	{ NULL, NULL }, /* Xo */
 	{ termp_fo_pre, termp_fo_post }, /* Fo */
 	{ NULL, NULL }, /* Fc */
 	{ termp_quote_pre, termp_quote_post }, /* Oo */
 	{ NULL, NULL }, /* Oc */
 	{ termp_bk_pre, termp_bk_post }, /* Bk */
 	{ NULL, NULL }, /* Ek */
-	{ termp_bt_pre, NULL }, /* Bt */
+	{ NULL, NULL }, /* Bt */
 	{ NULL, NULL }, /* Hf */
 	{ termp_under_pre, NULL }, /* Fr */
-	{ termp_ud_pre, NULL }, /* Ud */
+	{ NULL, NULL }, /* Ud */
 	{ NULL, termp_lb_post }, /* Lb */
 	{ termp_sp_pre, NULL }, /* Lp */
 	{ termp_lk_pre, NULL }, /* Lk */
 	{ termp_under_pre, NULL }, /* Mt */
 	{ termp_quote_pre, termp_quote_post }, /* Brq */
 	{ termp_quote_pre, termp_quote_post }, /* Bro */
 	{ NULL, NULL }, /* Brc */
 	{ NULL, termp____post }, /* %C */
 	{ termp_skip_pre, NULL }, /* Es */
 	{ termp_quote_pre, termp_quote_post }, /* En */
-	{ termp_xx_pre, NULL }, /* Dx */
+	{ termp_xx_pre, termp_xx_post }, /* Dx */
 	{ NULL, termp____post }, /* %Q */
 	{ termp_sp_pre, NULL }, /* br */
 	{ termp_sp_pre, NULL }, /* sp */
 	{ NULL, termp____post }, /* %U */
 	{ NULL, NULL }, /* Ta */
 	{ termp_ll_pre, NULL }, /* ll */
 };
 
 static	int	 fn_prio;
 
 void
 terminal_mdoc(void *arg, const struct roff_man *mdoc)
 {
 	struct roff_node	*n;
 	struct termp		*p;
 
 	p = (struct termp *)arg;
 	p->overstep = 0;
 	p->rmargin = p->maxrmargin = p->defrmargin;
 	p->tabwidth = term_len(p, 5);
 
 	n = mdoc->first->child;
 	if (p->synopsisonly) {
 		while (n != NULL) {
 			if (n->tok == MDOC_Sh && n->sec == SEC_SYNOPSIS) {
 				if (n->child->next->child != NULL)
 					print_mdoc_nodelist(p, NULL,
 					    &mdoc->meta,
 					    n->child->next->child);
 				term_newln(p);
 				break;
 			}
 			n = n->next;
 		}
 	} else {
 		if (p->defindent == 0)
 			p->defindent = 5;
 		term_begin(p, print_mdoc_head, print_mdoc_foot,
 		    &mdoc->meta);
+		while (n != NULL && n->flags & NODE_NOPRT)
+			n = n->next;
 		if (n != NULL) {
 			if (n->tok != MDOC_Sh)
 				term_vspace(p);
 			print_mdoc_nodelist(p, NULL, &mdoc->meta, n);
 		}
 		term_end(p);
 	}
 }
 
 static void
 print_mdoc_nodelist(DECL_ARGS)
 {
 
 	while (n != NULL) {
 		print_mdoc_node(p, pair, meta, n);
 		n = n->next;
 	}
 }
 
 static void
 print_mdoc_node(DECL_ARGS)
 {
 	int		 chld;
 	struct termpair	 npair;
 	size_t		 offset, rmargin;
 
+	if (n->flags & NODE_NOPRT)
+		return;
+
 	chld = 1;
 	offset = p->offset;
 	rmargin = p->rmargin;
-	n->flags &= ~MDOC_ENDED;
+	n->flags &= ~NODE_ENDED;
 	n->prev_font = p->fonti;
 
 	memset(&npair, 0, sizeof(struct termpair));
 	npair.ppair = pair;
 
 	/*
 	 * Keeps only work until the end of a line.  If a keep was
 	 * invoked in a prior line, revert it to PREKEEP.
 	 */
 
-	if (p->flags & TERMP_KEEP && n->flags & MDOC_LINE) {
+	if (p->flags & TERMP_KEEP && n->flags & NODE_LINE) {
 		p->flags &= ~TERMP_KEEP;
 		p->flags |= TERMP_PREKEEP;
 	}
 
 	/*
 	 * After the keep flags have been set up, we may now
 	 * produce output.  Note that some pre-handlers do so.
 	 */
 
 	switch (n->type) {
 	case ROFFT_TEXT:
-		if (' ' == *n->string && MDOC_LINE & n->flags)
+		if (' ' == *n->string && NODE_LINE & n->flags)
 			term_newln(p);
-		if (MDOC_DELIMC & n->flags)
+		if (NODE_DELIMC & n->flags)
 			p->flags |= TERMP_NOSPACE;
 		term_word(p, n->string);
-		if (MDOC_DELIMO & n->flags)
+		if (NODE_DELIMO & n->flags)
 			p->flags |= TERMP_NOSPACE;
 		break;
 	case ROFFT_EQN:
-		if ( ! (n->flags & MDOC_LINE))
+		if ( ! (n->flags & NODE_LINE))
 			p->flags |= TERMP_NOSPACE;
 		term_eqn(p, n->eqn);
-		if (n->next != NULL && ! (n->next->flags & MDOC_LINE))
+		if (n->next != NULL && ! (n->next->flags & NODE_LINE))
 			p->flags |= TERMP_NOSPACE;
 		break;
 	case ROFFT_TBL:
 		if (p->tbl.cols == NULL)
 			term_newln(p);
 		term_tbl(p, n->span);
 		break;
 	default:
 		if (termacts[n->tok].pre &&
 		    (n->end == ENDBODY_NOT || n->child != NULL))
 			chld = (*termacts[n->tok].pre)
 				(p, &npair, meta, n);
 		break;
 	}
 
 	if (chld && n->child)
 		print_mdoc_nodelist(p, &npair, meta, n->child);
 
 	term_fontpopq(p,
 	    (ENDBODY_NOT == n->end ? n : n->body)->prev_font);
 
 	switch (n->type) {
 	case ROFFT_TEXT:
 		break;
 	case ROFFT_TBL:
 		break;
 	case ROFFT_EQN:
 		break;
 	default:
-		if ( ! termacts[n->tok].post || MDOC_ENDED & n->flags)
+		if ( ! termacts[n->tok].post || NODE_ENDED & n->flags)
 			break;
 		(void)(*termacts[n->tok].post)(p, &npair, meta, n);
 
 		/*
 		 * Explicit end tokens not only call the post
 		 * handler, but also tell the respective block
 		 * that it must not call the post handler again.
 		 */
 		if (ENDBODY_NOT != n->end)
-			n->body->flags |= MDOC_ENDED;
+			n->body->flags |= NODE_ENDED;
 
 		/*
 		 * End of line terminating an implicit block
 		 * while an explicit block is still open.
 		 * Continue the explicit block without spacing.
 		 */
 		if (ENDBODY_NOSPACE == n->end)
 			p->flags |= TERMP_NOSPACE;
 		break;
 	}
 
-	if (MDOC_EOS & n->flags)
+	if (NODE_EOS & n->flags)
 		p->flags |= TERMP_SENTENCE;
 
 	if (MDOC_ll != n->tok) {
 		p->offset = offset;
 		p->rmargin = rmargin;
 	}
 }
 
 static void
 print_mdoc_foot(struct termp *p, const struct roff_meta *meta)
 {
 	size_t sz;
 
 	term_fontrepl(p, TERMFONT_NONE);
 
 	/*
 	 * Output the footer in new-groff style, that is, three columns
 	 * with the middle being the manual date and flanking columns
 	 * being the operating system:
 	 *
 	 * SYSTEM                  DATE                    SYSTEM
 	 */
 
 	term_vspace(p);
 
 	p->offset = 0;
 	sz = term_strlen(p, meta->date);
 	p->rmargin = p->maxrmargin > sz ?
 	    (p->maxrmargin + term_len(p, 1) - sz) / 2 : 0;
 	p->trailspace = 1;
 	p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
 
 	term_word(p, meta->os);
 	term_flushln(p);
 
 	p->offset = p->rmargin;
 	sz = term_strlen(p, meta->os);
 	p->rmargin = p->maxrmargin > sz ? p->maxrmargin - sz : 0;
 	p->flags |= TERMP_NOSPACE;
 
 	term_word(p, meta->date);
 	term_flushln(p);
 
 	p->offset = p->rmargin;
 	p->rmargin = p->maxrmargin;
 	p->trailspace = 0;
 	p->flags &= ~TERMP_NOBREAK;
 	p->flags |= TERMP_NOSPACE;
 
 	term_word(p, meta->os);
 	term_flushln(p);
 
 	p->offset = 0;
 	p->rmargin = p->maxrmargin;
 	p->flags = 0;
 }
 
 static void
 print_mdoc_head(struct termp *p, const struct roff_meta *meta)
 {
 	char			*volume, *title;
 	size_t			 vollen, titlen;
 
 	/*
 	 * The header is strange.  It has three components, which are
 	 * really two with the first duplicated.  It goes like this:
 	 *
 	 * IDENTIFIER              TITLE                   IDENTIFIER
 	 *
 	 * The IDENTIFIER is NAME(SECTION), which is the command-name
 	 * (if given, or "unknown" if not) followed by the manual page
 	 * section.  These are given in `Dt'.  The TITLE is a free-form
 	 * string depending on the manual volume.  If not specified, it
 	 * switches on the manual section.
 	 */
 
 	assert(meta->vol);
 	if (NULL == meta->arch)
 		volume = mandoc_strdup(meta->vol);
 	else
 		mandoc_asprintf(&volume, "%s (%s)",
 		    meta->vol, meta->arch);
 	vollen = term_strlen(p, volume);
 
 	if (NULL == meta->msec)
 		title = mandoc_strdup(meta->title);
 	else
 		mandoc_asprintf(&title, "%s(%s)",
 		    meta->title, meta->msec);
 	titlen = term_strlen(p, title);
 
 	p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
 	p->trailspace = 1;
 	p->offset = 0;
 	p->rmargin = 2 * (titlen+1) + vollen < p->maxrmargin ?
 	    (p->maxrmargin - vollen + term_len(p, 1)) / 2 :
 	    vollen < p->maxrmargin ?  p->maxrmargin - vollen : 0;
 
 	term_word(p, title);
 	term_flushln(p);
 
 	p->flags |= TERMP_NOSPACE;
 	p->offset = p->rmargin;
 	p->rmargin = p->offset + vollen + titlen < p->maxrmargin ?
 	    p->maxrmargin - titlen : p->maxrmargin;
 
 	term_word(p, volume);
 	term_flushln(p);
 
 	p->flags &= ~TERMP_NOBREAK;
 	p->trailspace = 0;
 	if (p->rmargin + titlen <= p->maxrmargin) {
 		p->flags |= TERMP_NOSPACE;
 		p->offset = p->rmargin;
 		p->rmargin = p->maxrmargin;
 		term_word(p, title);
 		term_flushln(p);
 	}
 
 	p->flags &= ~TERMP_NOSPACE;
 	p->offset = 0;
 	p->rmargin = p->maxrmargin;
 	free(title);
 	free(volume);
 }
 
 static int
 a2width(const struct termp *p, const char *v)
 {
 	struct roffsu	 su;
 
 	if (a2roffsu(v, &su, SCALE_MAX) < 2) {
 		SCALE_HS_INIT(&su, term_strlen(p, v));
 		su.scale /= term_strlen(p, "0");
 	}
 	return term_hspan(p, &su) / 24;
 }
 
 /*
  * Determine how much space to print out before block elements of `It'
  * (and thus `Bl') and `Bd'.  And then go ahead and print that space,
  * too.
  */
 static void
 print_bvspace(struct termp *p,
 	const struct roff_node *bl,
 	const struct roff_node *n)
 {
 	const struct roff_node	*nn;
 
 	assert(n);
 
 	term_newln(p);
 
 	if (MDOC_Bd == bl->tok && bl->norm->Bd.comp)
 		return;
 	if (MDOC_Bl == bl->tok && bl->norm->Bl.comp)
 		return;
 
 	/* Do not vspace directly after Ss/Sh. */
 
 	nn = n;
+	while (nn->prev != NULL && nn->prev->flags & NODE_NOPRT)
+		nn = nn->prev;
 	while (nn->prev == NULL) {
 		do {
 			nn = nn->parent;
 			if (nn->type == ROFFT_ROOT)
 				return;
 		} while (nn->type != ROFFT_BLOCK);
 		if (nn->tok == MDOC_Sh || nn->tok == MDOC_Ss)
 			return;
 		if (nn->tok == MDOC_It &&
 		    nn->parent->parent->norm->Bl.type != LIST_item)
 			break;
 	}
 
 	/* A `-column' does not assert vspace within the list. */
 
 	if (MDOC_Bl == bl->tok && LIST_column == bl->norm->Bl.type)
 		if (n->prev && MDOC_It == n->prev->tok)
 			return;
 
 	/* A `-diag' without body does not vspace. */
 
 	if (MDOC_Bl == bl->tok && LIST_diag == bl->norm->Bl.type)
 		if (n->prev && MDOC_It == n->prev->tok) {
 			assert(n->prev->body);
 			if (NULL == n->prev->body->child)
 				return;
 		}
 
 	term_vspace(p);
 }
 
 
 static int
 termp_ll_pre(DECL_ARGS)
 {
 
 	term_setwidth(p, n->child != NULL ? n->child->string : NULL);
 	return 0;
 }
 
 static int
 termp_it_pre(DECL_ARGS)
 {
 	char			buf[24];
 	const struct roff_node *bl, *nn;
 	size_t			ncols, dcol;
 	int			i, offset, width;
 	enum mdoc_list		type;
 
 	if (n->type == ROFFT_BLOCK) {
 		print_bvspace(p, n->parent->parent, n);
 		return 1;
 	}
 
 	bl = n->parent->parent->parent;
 	type = bl->norm->Bl.type;
 
 	/*
 	 * Defaults for specific list types.
 	 */
 
 	switch (type) {
 	case LIST_bullet:
 	case LIST_dash:
 	case LIST_hyphen:
 	case LIST_enum:
 		width = term_len(p, 2);
 		break;
 	case LIST_hang:
+	case LIST_tag:
 		width = term_len(p, 8);
 		break;
 	case LIST_column:
-	case LIST_tag:
 		width = term_len(p, 10);
 		break;
 	default:
 		width = 0;
 		break;
 	}
 	offset = 0;
 
 	/*
 	 * First calculate width and offset.  This is pretty easy unless
 	 * we're a -column list, in which case all prior columns must
 	 * be accounted for.
 	 */
 
 	if (bl->norm->Bl.offs != NULL) {
 		offset = a2width(p, bl->norm->Bl.offs);
 		if (offset < 0 && (size_t)(-offset) > p->offset)
 			offset = -p->offset;
 		else if (offset > SHRT_MAX)
 			offset = 0;
 	}
 
 	switch (type) {
 	case LIST_column:
 		if (n->type == ROFFT_HEAD)
 			break;
 
 		/*
 		 * Imitate groff's column handling:
 		 * - For each earlier column, add its width.
 		 * - For less than 5 columns, add four more blanks per
 		 *   column.
 		 * - For exactly 5 columns, add three more blank per
 		 *   column.
 		 * - For more than 5 columns, add only one column.
 		 */
 		ncols = bl->norm->Bl.ncols;
 		dcol = ncols < 5 ? term_len(p, 4) :
 		    ncols == 5 ? term_len(p, 3) : term_len(p, 1);
 
 		/*
 		 * Calculate the offset by applying all prior ROFFT_BODY,
 		 * so we stop at the ROFFT_HEAD (nn->prev == NULL).
 		 */
 
 		for (i = 0, nn = n->prev;
 		    nn->prev && i < (int)ncols;
 		    nn = nn->prev, i++)
 			offset += dcol + a2width(p,
 			    bl->norm->Bl.cols[i]);
 
 		/*
 		 * When exceeding the declared number of columns, leave
 		 * the remaining widths at 0.  This will later be
 		 * adjusted to the default width of 10, or, for the last
 		 * column, stretched to the right margin.
 		 */
 		if (i >= (int)ncols)
 			break;
 
 		/*
 		 * Use the declared column widths, extended as explained
 		 * in the preceding paragraph.
 		 */
 		width = a2width(p, bl->norm->Bl.cols[i]) + dcol;
 		break;
 	default:
 		if (NULL == bl->norm->Bl.width)
 			break;
 
 		/*
 		 * Note: buffer the width by 2, which is groff's magic
 		 * number for buffering single arguments.  See the above
 		 * handling for column for how this changes.
 		 */
 		width = a2width(p, bl->norm->Bl.width) + term_len(p, 2);
 		if (width < 0 && (size_t)(-width) > p->offset)
 			width = -p->offset;
 		else if (width > SHRT_MAX)
 			width = 0;
 		break;
 	}
 
 	/*
 	 * Whitespace control.  Inset bodies need an initial space,
 	 * while diagonal bodies need two.
 	 */
 
 	p->flags |= TERMP_NOSPACE;
 
 	switch (type) {
 	case LIST_diag:
 		if (n->type == ROFFT_BODY)
 			term_word(p, "\\ \\ ");
 		break;
 	case LIST_inset:
 		if (n->type == ROFFT_BODY && n->parent->head->child != NULL)
 			term_word(p, "\\ ");
 		break;
 	default:
 		break;
 	}
 
 	p->flags |= TERMP_NOSPACE;
 
 	switch (type) {
 	case LIST_diag:
 		if (n->type == ROFFT_HEAD)
 			term_fontpush(p, TERMFONT_BOLD);
 		break;
 	default:
 		break;
 	}
 
 	/*
 	 * Pad and break control.  This is the tricky part.  These flags
 	 * are documented in term_flushln() in term.c.  Note that we're
 	 * going to unset all of these flags in termp_it_post() when we
 	 * exit.
 	 */
 
 	switch (type) {
 	case LIST_enum:
 	case LIST_bullet:
 	case LIST_dash:
 	case LIST_hyphen:
 		/*
 		 * Weird special case.
 		 * Some very narrow lists actually hang.
 		 */
 		if (width <= (int)term_len(p, 2))
 			p->flags |= TERMP_HANG;
 		if (n->type != ROFFT_HEAD)
 			break;
 		p->flags |= TERMP_NOBREAK;
 		p->trailspace = 1;
 		break;
 	case LIST_hang:
 		if (n->type != ROFFT_HEAD)
 			break;
 
 		/*
 		 * This is ugly.  If `-hang' is specified and the body
 		 * is a `Bl' or `Bd', then we want basically to nullify
 		 * the "overstep" effect in term_flushln() and treat
 		 * this as a `-ohang' list instead.
 		 */
 		if (NULL != n->next &&
 		    NULL != n->next->child &&
 		    (MDOC_Bl == n->next->child->tok ||
 		     MDOC_Bd == n->next->child->tok))
 			break;
 
 		p->flags |= TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG;
 		p->trailspace = 1;
 		break;
 	case LIST_tag:
 		if (n->type != ROFFT_HEAD)
 			break;
 
 		p->flags |= TERMP_NOBREAK | TERMP_BRTRSP | TERMP_BRIND;
 		p->trailspace = 2;
 
 		if (NULL == n->next || NULL == n->next->child)
 			p->flags |= TERMP_DANGLE;
 		break;
 	case LIST_column:
 		if (n->type == ROFFT_HEAD)
 			break;
 
 		if (NULL == n->next) {
 			p->flags &= ~TERMP_NOBREAK;
 			p->trailspace = 0;
 		} else {
 			p->flags |= TERMP_NOBREAK;
 			p->trailspace = 1;
 		}
 
 		break;
 	case LIST_diag:
 		if (n->type != ROFFT_HEAD)
 			break;
 		p->flags |= TERMP_NOBREAK | TERMP_BRIND;
 		p->trailspace = 1;
 		break;
 	default:
 		break;
 	}
 
 	/*
 	 * Margin control.  Set-head-width lists have their right
 	 * margins shortened.  The body for these lists has the offset
 	 * necessarily lengthened.  Everybody gets the offset.
 	 */
 
 	p->offset += offset;
 
 	switch (type) {
 	case LIST_hang:
 		/*
 		 * Same stipulation as above, regarding `-hang'.  We
 		 * don't want to recalculate rmargin and offsets when
 		 * using `Bd' or `Bl' within `-hang' overstep lists.
 		 */
 		if (n->type == ROFFT_HEAD &&
 		    NULL != n->next &&
 		    NULL != n->next->child &&
 		    (MDOC_Bl == n->next->child->tok ||
 		     MDOC_Bd == n->next->child->tok))
 			break;
 		/* FALLTHROUGH */
 	case LIST_bullet:
 	case LIST_dash:
 	case LIST_enum:
 	case LIST_hyphen:
 	case LIST_tag:
 		if (n->type == ROFFT_HEAD)
 			p->rmargin = p->offset + width;
 		else
 			p->offset += width;
 		break;
 	case LIST_column:
 		assert(width);
 		p->rmargin = p->offset + width;
 		/*
 		 * XXX - this behaviour is not documented: the
 		 * right-most column is filled to the right margin.
 		 */
 		if (n->type == ROFFT_HEAD)
 			break;
 		if (NULL == n->next && p->rmargin < p->maxrmargin)
 			p->rmargin = p->maxrmargin;
 		break;
 	default:
 		break;
 	}
 
 	/*
 	 * The dash, hyphen, bullet and enum lists all have a special
 	 * HEAD character (temporarily bold, in some cases).
 	 */
 
 	if (n->type == ROFFT_HEAD)
 		switch (type) {
 		case LIST_bullet:
 			term_fontpush(p, TERMFONT_BOLD);
 			term_word(p, "\\[bu]");
 			term_fontpop(p);
 			break;
 		case LIST_dash:
 		case LIST_hyphen:
 			term_fontpush(p, TERMFONT_BOLD);
 			term_word(p, "-");
 			term_fontpop(p);
 			break;
 		case LIST_enum:
 			(pair->ppair->ppair->count)++;
 			(void)snprintf(buf, sizeof(buf), "%d.",
 			    pair->ppair->ppair->count);
 			term_word(p, buf);
 			break;
 		default:
 			break;
 		}
 
 	/*
 	 * If we're not going to process our children, indicate so here.
 	 */
 
 	switch (type) {
 	case LIST_bullet:
 	case LIST_item:
 	case LIST_dash:
 	case LIST_hyphen:
 	case LIST_enum:
 		if (n->type == ROFFT_HEAD)
 			return 0;
 		break;
 	case LIST_column:
 		if (n->type == ROFFT_HEAD)
 			return 0;
 		break;
 	default:
 		break;
 	}
 
 	return 1;
 }
 
 static void
 termp_it_post(DECL_ARGS)
 {
 	enum mdoc_list	   type;
 
 	if (n->type == ROFFT_BLOCK)
 		return;
 
 	type = n->parent->parent->parent->norm->Bl.type;
 
 	switch (type) {
 	case LIST_item:
 	case LIST_diag:
 	case LIST_inset:
 		if (n->type == ROFFT_BODY)
 			term_newln(p);
 		break;
 	case LIST_column:
 		if (n->type == ROFFT_BODY)
 			term_flushln(p);
 		break;
 	default:
 		term_newln(p);
 		break;
 	}
 
 	/*
 	 * Now that our output is flushed, we can reset our tags.  Since
 	 * only `It' sets these flags, we're free to assume that nobody
 	 * has munged them in the meanwhile.
 	 */
 
 	p->flags &= ~(TERMP_NOBREAK | TERMP_BRTRSP | TERMP_BRIND |
 			TERMP_DANGLE | TERMP_HANG);
 	p->trailspace = 0;
 }
 
 static int
 termp_nm_pre(DECL_ARGS)
 {
 	const char	*cp;
 
 	if (n->type == ROFFT_BLOCK) {
 		p->flags |= TERMP_PREKEEP;
 		return 1;
 	}
 
 	if (n->type == ROFFT_BODY) {
 		if (NULL == n->child)
 			return 0;
 		p->flags |= TERMP_NOSPACE;
 		cp = NULL;
 		if (n->prev->child != NULL)
 		    cp = n->prev->child->string;
 		if (cp == NULL)
 			cp = meta->name;
 		if (cp == NULL)
 			p->offset += term_len(p, 6);
 		else
 			p->offset += term_len(p, 1) + term_strlen(p, cp);
 		return 1;
 	}
 
 	if (NULL == n->child && NULL == meta->name)
 		return 0;
 
 	if (n->type == ROFFT_HEAD)
 		synopsis_pre(p, n->parent);
 
 	if (n->type == ROFFT_HEAD &&
 	    NULL != n->next && NULL != n->next->child) {
 		p->flags |= TERMP_NOSPACE | TERMP_NOBREAK | TERMP_BRIND;
 		p->trailspace = 1;
 		p->rmargin = p->offset + term_len(p, 1);
 		if (NULL == n->child) {
 			p->rmargin += term_strlen(p, meta->name);
 		} else if (n->child->type == ROFFT_TEXT) {
 			p->rmargin += term_strlen(p, n->child->string);
 			if (n->child->next)
 				p->flags |= TERMP_HANG;
 		} else {
 			p->rmargin += term_len(p, 5);
 			p->flags |= TERMP_HANG;
 		}
 	}
 
 	term_fontpush(p, TERMFONT_BOLD);
 	if (NULL == n->child)
 		term_word(p, meta->name);
 	return 1;
 }
 
 static void
 termp_nm_post(DECL_ARGS)
 {
 
 	if (n->type == ROFFT_BLOCK) {
 		p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
 	} else if (n->type == ROFFT_HEAD &&
 	    NULL != n->next && NULL != n->next->child) {
 		term_flushln(p);
 		p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG);
 		p->trailspace = 0;
 	} else if (n->type == ROFFT_BODY && n->child != NULL)
 		term_flushln(p);
 }
 
 static int
 termp_fl_pre(DECL_ARGS)
 {
 
 	termp_tag_pre(p, pair, meta, n);
 	term_fontpush(p, TERMFONT_BOLD);
 	term_word(p, "\\-");
 
 	if (!(n->child == NULL &&
 	    (n->next == NULL ||
 	     n->next->type == ROFFT_TEXT ||
-	     n->next->flags & MDOC_LINE)))
+	     n->next->flags & NODE_LINE)))
 		p->flags |= TERMP_NOSPACE;
 
 	return 1;
 }
 
 static int
 termp__a_pre(DECL_ARGS)
 {
 
 	if (n->prev && MDOC__A == n->prev->tok)
 		if (NULL == n->next || MDOC__A != n->next->tok)
 			term_word(p, "and");
 
 	return 1;
 }
 
 static int
 termp_an_pre(DECL_ARGS)
 {
 
 	if (n->norm->An.auth == AUTH_split) {
 		p->flags &= ~TERMP_NOSPLIT;
 		p->flags |= TERMP_SPLIT;
 		return 0;
 	}
 	if (n->norm->An.auth == AUTH_nosplit) {
 		p->flags &= ~TERMP_SPLIT;
 		p->flags |= TERMP_NOSPLIT;
 		return 0;
 	}
 
 	if (p->flags & TERMP_SPLIT)
 		term_newln(p);
 
 	if (n->sec == SEC_AUTHORS && ! (p->flags & TERMP_NOSPLIT))
 		p->flags |= TERMP_SPLIT;
 
 	return 1;
 }
 
 static int
 termp_ns_pre(DECL_ARGS)
 {
 
-	if ( ! (MDOC_LINE & n->flags))
+	if ( ! (NODE_LINE & n->flags))
 		p->flags |= TERMP_NOSPACE;
 	return 1;
 }
 
 static int
 termp_rs_pre(DECL_ARGS)
 {
 
 	if (SEC_SEE_ALSO != n->sec)
 		return 1;
 	if (n->type == ROFFT_BLOCK && n->prev != NULL)
 		term_vspace(p);
 	return 1;
 }
 
 static int
-termp_rv_pre(DECL_ARGS)
-{
-	struct roff_node *nch;
-
-	term_newln(p);
-
-	if (n->child != NULL) {
-		term_word(p, "The");
-
-		for (nch = n->child; nch != NULL; nch = nch->next) {
-			term_fontpush(p, TERMFONT_BOLD);
-			term_word(p, nch->string);
-			term_fontpop(p);
-
-			p->flags |= TERMP_NOSPACE;
-			term_word(p, "()");
-
-			if (nch->next == NULL)
-				continue;
-
-			if (nch->prev != NULL || nch->next->next != NULL) {
-				p->flags |= TERMP_NOSPACE;
-				term_word(p, ",");
-			}
-			if (nch->next->next == NULL)
-				term_word(p, "and");
-		}
-
-		if (n->child != NULL && n->child->next != NULL)
-			term_word(p, "functions return");
-		else
-			term_word(p, "function returns");
-
-		term_word(p, "the value\\~0 if successful;");
-	} else
-		term_word(p, "Upon successful completion,"
-		    " the value\\~0 is returned;");
-
-	term_word(p, "otherwise the value\\~\\-1 is returned"
-	    " and the global variable");
-
-	term_fontpush(p, TERMFONT_UNDER);
-	term_word(p, "errno");
-	term_fontpop(p);
-
-	term_word(p, "is set to indicate the error.");
-	p->flags |= TERMP_SENTENCE;
-
-	return 0;
-}
-
-static int
 termp_ex_pre(DECL_ARGS)
 {
-	struct roff_node *nch;
-
 	term_newln(p);
-	term_word(p, "The");
-
-	for (nch = n->child; nch != NULL; nch = nch->next) {
-		term_fontpush(p, TERMFONT_BOLD);
-		term_word(p, nch->string);
-		term_fontpop(p);
-
-		if (nch->next == NULL)
-			continue;
-
-		if (nch->prev != NULL || nch->next->next != NULL) {
-			p->flags |= TERMP_NOSPACE;
-			term_word(p, ",");
-		}
-
-		if (nch->next->next == NULL)
-			term_word(p, "and");
-	}
-
-	if (n->child != NULL && n->child->next != NULL)
-		term_word(p, "utilities exit\\~0");
-	else
-		term_word(p, "utility exits\\~0");
-
-	term_word(p, "on success, and\\~>0 if an error occurs.");
-
-	p->flags |= TERMP_SENTENCE;
-	return 0;
+	return 1;
 }
 
 static int
 termp_nd_pre(DECL_ARGS)
 {
 
 	if (n->type == ROFFT_BODY)
 		term_word(p, "\\(en");
 	return 1;
 }
 
 static int
 termp_bl_pre(DECL_ARGS)
 {
 
 	return n->type != ROFFT_HEAD;
 }
 
 static void
 termp_bl_post(DECL_ARGS)
 {
 
 	if (n->type == ROFFT_BLOCK)
 		term_newln(p);
 }
 
 static int
 termp_xr_pre(DECL_ARGS)
 {
 
 	if (NULL == (n = n->child))
 		return 0;
 
 	assert(n->type == ROFFT_TEXT);
 	term_word(p, n->string);
 
 	if (NULL == (n = n->next))
 		return 0;
 
 	p->flags |= TERMP_NOSPACE;
 	term_word(p, "(");
 	p->flags |= TERMP_NOSPACE;
 
 	assert(n->type == ROFFT_TEXT);
 	term_word(p, n->string);
 
 	p->flags |= TERMP_NOSPACE;
 	term_word(p, ")");
 
 	return 0;
 }
 
 /*
  * This decides how to assert whitespace before any of the SYNOPSIS set
  * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
  * macro combos).
  */
 static void
 synopsis_pre(struct termp *p, const struct roff_node *n)
 {
 	/*
 	 * Obviously, if we're not in a SYNOPSIS or no prior macros
 	 * exist, do nothing.
 	 */
-	if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags))
+	if (NULL == n->prev || ! (NODE_SYNPRETTY & n->flags))
 		return;
 
 	/*
 	 * If we're the second in a pair of like elements, emit our
 	 * newline and return.  UNLESS we're `Fo', `Fn', `Fn', in which
 	 * case we soldier on.
 	 */
 	if (n->prev->tok == n->tok &&
 	    MDOC_Ft != n->tok &&
 	    MDOC_Fo != n->tok &&
 	    MDOC_Fn != n->tok) {
 		term_newln(p);
 		return;
 	}
 
 	/*
 	 * If we're one of the SYNOPSIS set and non-like pair-wise after
 	 * another (or Fn/Fo, which we've let slip through) then assert
 	 * vertical space, else only newline and move on.
 	 */
 	switch (n->prev->tok) {
 	case MDOC_Fd:
 	case MDOC_Fn:
 	case MDOC_Fo:
 	case MDOC_In:
 	case MDOC_Vt:
 		term_vspace(p);
 		break;
 	case MDOC_Ft:
 		if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
 			term_vspace(p);
 			break;
 		}
 		/* FALLTHROUGH */
 	default:
 		term_newln(p);
 		break;
 	}
 }
 
 static int
 termp_vt_pre(DECL_ARGS)
 {
 
 	if (n->type == ROFFT_ELEM) {
 		synopsis_pre(p, n);
 		return termp_under_pre(p, pair, meta, n);
 	} else if (n->type == ROFFT_BLOCK) {
 		synopsis_pre(p, n);
 		return 1;
 	} else if (n->type == ROFFT_HEAD)
 		return 0;
 
 	return termp_under_pre(p, pair, meta, n);
 }
 
 static int
 termp_bold_pre(DECL_ARGS)
 {
 
 	termp_tag_pre(p, pair, meta, n);
 	term_fontpush(p, TERMFONT_BOLD);
 	return 1;
 }
 
 static int
 termp_fd_pre(DECL_ARGS)
 {
 
 	synopsis_pre(p, n);
 	return termp_bold_pre(p, pair, meta, n);
 }
 
 static void
 termp_fd_post(DECL_ARGS)
 {
 
 	term_newln(p);
 }
 
 static int
 termp_sh_pre(DECL_ARGS)
 {
 
 	switch (n->type) {
 	case ROFFT_BLOCK:
 		/*
 		 * Vertical space before sections, except
 		 * when the previous section was empty.
 		 */
 		if (n->prev == NULL ||
 		    n->prev->tok != MDOC_Sh ||
 		    (n->prev->body != NULL &&
 		     n->prev->body->child != NULL))
 			term_vspace(p);
 		break;
 	case ROFFT_HEAD:
 		term_fontpush(p, TERMFONT_BOLD);
 		break;
 	case ROFFT_BODY:
 		p->offset = term_len(p, p->defindent);
 		switch (n->sec) {
 		case SEC_DESCRIPTION:
 			fn_prio = 0;
 			break;
 		case SEC_AUTHORS:
 			p->flags &= ~(TERMP_SPLIT|TERMP_NOSPLIT);
 			break;
 		default:
 			break;
 		}
 		break;
 	default:
 		break;
 	}
 	return 1;
 }
 
 static void
 termp_sh_post(DECL_ARGS)
 {
 
 	switch (n->type) {
 	case ROFFT_HEAD:
 		term_newln(p);
 		break;
 	case ROFFT_BODY:
 		term_newln(p);
 		p->offset = 0;
 		break;
 	default:
 		break;
 	}
 }
 
-static int
-termp_bt_pre(DECL_ARGS)
-{
-
-	term_word(p, "is currently in beta test.");
-	p->flags |= TERMP_SENTENCE;
-	return 0;
-}
-
 static void
 termp_lb_post(DECL_ARGS)
 {
 
-	if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags)
+	if (SEC_LIBRARY == n->sec && NODE_LINE & n->flags)
 		term_newln(p);
 }
 
 static int
-termp_ud_pre(DECL_ARGS)
-{
-
-	term_word(p, "currently under development.");
-	p->flags |= TERMP_SENTENCE;
-	return 0;
-}
-
-static int
 termp_d1_pre(DECL_ARGS)
 {
 
 	if (n->type != ROFFT_BLOCK)
 		return 1;
 	term_newln(p);
 	p->offset += term_len(p, p->defindent + 1);
 	return 1;
 }
 
 static int
 termp_ft_pre(DECL_ARGS)
 {
 
-	/* NB: MDOC_LINE does not effect this! */
+	/* NB: NODE_LINE does not effect this! */
 	synopsis_pre(p, n);
 	term_fontpush(p, TERMFONT_UNDER);
 	return 1;
 }
 
 static int
 termp_fn_pre(DECL_ARGS)
 {
 	size_t		 rmargin = 0;
 	int		 pretty;
 
-	pretty = MDOC_SYNPRETTY & n->flags;
+	pretty = NODE_SYNPRETTY & n->flags;
 
 	synopsis_pre(p, n);
 
 	if (NULL == (n = n->child))
 		return 0;
 
 	if (pretty) {
 		rmargin = p->rmargin;
 		p->rmargin = p->offset + term_len(p, 4);
 		p->flags |= TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG;
 	}
 
 	assert(n->type == ROFFT_TEXT);
 	term_fontpush(p, TERMFONT_BOLD);
 	term_word(p, n->string);
 	term_fontpop(p);
 
-	if (n->sec == SEC_DESCRIPTION)
+	if (n->sec == SEC_DESCRIPTION || n->sec == SEC_CUSTOM)
 		tag_put(n->string, ++fn_prio, p->line);
 
 	if (pretty) {
 		term_flushln(p);
 		p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG);
 		p->offset = p->rmargin;
 		p->rmargin = rmargin;
 	}
 
 	p->flags |= TERMP_NOSPACE;
 	term_word(p, "(");
 	p->flags |= TERMP_NOSPACE;
 
 	for (n = n->next; n; n = n->next) {
 		assert(n->type == ROFFT_TEXT);
 		term_fontpush(p, TERMFONT_UNDER);
 		if (pretty)
 			p->flags |= TERMP_NBRWORD;
 		term_word(p, n->string);
 		term_fontpop(p);
 
 		if (n->next) {
 			p->flags |= TERMP_NOSPACE;
 			term_word(p, ",");
 		}
 	}
 
 	p->flags |= TERMP_NOSPACE;
 	term_word(p, ")");
 
 	if (pretty) {
 		p->flags |= TERMP_NOSPACE;
 		term_word(p, ";");
 		term_flushln(p);
 	}
 
 	return 0;
 }
 
 static int
 termp_fa_pre(DECL_ARGS)
 {
 	const struct roff_node	*nn;
 
 	if (n->parent->tok != MDOC_Fo) {
 		term_fontpush(p, TERMFONT_UNDER);
 		return 1;
 	}
 
 	for (nn = n->child; nn; nn = nn->next) {
 		term_fontpush(p, TERMFONT_UNDER);
 		p->flags |= TERMP_NBRWORD;
 		term_word(p, nn->string);
 		term_fontpop(p);
 
 		if (nn->next || (n->next && n->next->tok == MDOC_Fa)) {
 			p->flags |= TERMP_NOSPACE;
 			term_word(p, ",");
 		}
 	}
 
 	return 0;
 }
 
 static int
 termp_bd_pre(DECL_ARGS)
 {
 	size_t			 tabwidth, lm, len, rm, rmax;
 	struct roff_node	*nn;
 	int			 offset;
 
 	if (n->type == ROFFT_BLOCK) {
 		print_bvspace(p, n, n);
 		return 1;
 	} else if (n->type == ROFFT_HEAD)
 		return 0;
 
 	/* Handle the -offset argument. */
 
 	if (n->norm->Bd.offs == NULL ||
 	    ! strcmp(n->norm->Bd.offs, "left"))
 		/* nothing */;
 	else if ( ! strcmp(n->norm->Bd.offs, "indent"))
 		p->offset += term_len(p, p->defindent + 1);
 	else if ( ! strcmp(n->norm->Bd.offs, "indent-two"))
 		p->offset += term_len(p, (p->defindent + 1) * 2);
 	else {
 		offset = a2width(p, n->norm->Bd.offs);
 		if (offset < 0 && (size_t)(-offset) > p->offset)
 			p->offset = 0;
 		else if (offset < SHRT_MAX)
 			p->offset += offset;
 	}
 
 	/*
 	 * If -ragged or -filled are specified, the block does nothing
 	 * but change the indentation.  If -unfilled or -literal are
 	 * specified, text is printed exactly as entered in the display:
 	 * for macro lines, a newline is appended to the line.  Blank
 	 * lines are allowed.
 	 */
 
 	if (DISP_literal != n->norm->Bd.type &&
 	    DISP_unfilled != n->norm->Bd.type &&
 	    DISP_centered != n->norm->Bd.type)
 		return 1;
 
 	tabwidth = p->tabwidth;
 	if (DISP_literal == n->norm->Bd.type)
 		p->tabwidth = term_len(p, 8);
 
 	lm = p->offset;
 	rm = p->rmargin;
 	rmax = p->maxrmargin;
 	p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
 
 	for (nn = n->child; nn; nn = nn->next) {
 		if (DISP_centered == n->norm->Bd.type) {
 			if (nn->type == ROFFT_TEXT) {
 				len = term_strlen(p, nn->string);
 				p->offset = len >= rm ? 0 :
 				    lm + len >= rm ? rm - len :
 				    (lm + rm - len) / 2;
 			} else
 				p->offset = lm;
 		}
 		print_mdoc_node(p, pair, meta, nn);
 		/*
 		 * If the printed node flushes its own line, then we
 		 * needn't do it here as well.  This is hacky, but the
 		 * notion of selective eoln whitespace is pretty dumb
 		 * anyway, so don't sweat it.
 		 */
 		switch (nn->tok) {
 		case MDOC_Sm:
 		case MDOC_br:
 		case MDOC_sp:
 		case MDOC_Bl:
 		case MDOC_D1:
 		case MDOC_Dl:
 		case MDOC_Lp:
 		case MDOC_Pp:
 			continue;
 		default:
 			break;
 		}
 		if (p->flags & TERMP_NONEWLINE ||
-		    (nn->next && ! (nn->next->flags & MDOC_LINE)))
+		    (nn->next && ! (nn->next->flags & NODE_LINE)))
 			continue;
 		term_flushln(p);
 		p->flags |= TERMP_NOSPACE;
 	}
 
 	p->tabwidth = tabwidth;
 	p->rmargin = rm;
 	p->maxrmargin = rmax;
 	return 0;
 }
 
 static void
 termp_bd_post(DECL_ARGS)
 {
 	size_t		 rm, rmax;
 
 	if (n->type != ROFFT_BODY)
 		return;
 
 	rm = p->rmargin;
 	rmax = p->maxrmargin;
 
 	if (DISP_literal == n->norm->Bd.type ||
 	    DISP_unfilled == n->norm->Bd.type)
 		p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
 
 	p->flags |= TERMP_NOSPACE;
 	term_newln(p);
 
 	p->rmargin = rm;
 	p->maxrmargin = rmax;
 }
 
 static int
-termp_bx_pre(DECL_ARGS)
+termp_xx_pre(DECL_ARGS)
 {
-
-	if (NULL != (n = n->child)) {
-		term_word(p, n->string);
-		p->flags |= TERMP_NOSPACE;
-		term_word(p, "BSD");
-	} else {
-		term_word(p, "BSD");
-		return 0;
-	}
-
-	if (NULL != (n = n->next)) {
-		p->flags |= TERMP_NOSPACE;
-		term_word(p, "-");
-		p->flags |= TERMP_NOSPACE;
-		term_word(p, n->string);
-	}
-
-	return 0;
+	if ((n->aux = p->flags & TERMP_PREKEEP) == 0)
+		p->flags |= TERMP_PREKEEP;
+	return 1;
 }
 
-static int
-termp_xx_pre(DECL_ARGS)
+static void
+termp_xx_post(DECL_ARGS)
 {
-	const char	*pp;
-	int		 flags;
-
-	pp = NULL;
-	switch (n->tok) {
-	case MDOC_Bsx:
-		pp = "BSD/OS";
-		break;
-	case MDOC_Dx:
-		pp = "DragonFly";
-		break;
-	case MDOC_Fx:
-		pp = "FreeBSD";
-		break;
-	case MDOC_Nx:
-		pp = "NetBSD";
-		break;
-	case MDOC_Ox:
-		pp = "OpenBSD";
-		break;
-	case MDOC_Ux:
-		pp = "UNIX";
-		break;
-	default:
-		abort();
-	}
-
-	term_word(p, pp);
-	if (n->child) {
-		flags = p->flags;
-		p->flags |= TERMP_KEEP;
-		term_word(p, n->child->string);
-		p->flags = flags;
-	}
-	return 0;
+	if (n->aux == 0)
+		p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
 }
 
 static void
 termp_pf_post(DECL_ARGS)
 {
 
-	if ( ! (n->next == NULL || n->next->flags & MDOC_LINE))
+	if ( ! (n->next == NULL || n->next->flags & NODE_LINE))
 		p->flags |= TERMP_NOSPACE;
 }
 
 static int
 termp_ss_pre(DECL_ARGS)
 {
+	struct roff_node *nn;
 
 	switch (n->type) {
 	case ROFFT_BLOCK:
 		term_newln(p);
-		if (n->prev)
+		for (nn = n->prev; nn != NULL; nn = nn->prev)
+			if ((nn->flags & NODE_NOPRT) == 0)
+				break;
+		if (nn != NULL)
 			term_vspace(p);
 		break;
 	case ROFFT_HEAD:
 		term_fontpush(p, TERMFONT_BOLD);
 		p->offset = term_len(p, (p->defindent+1)/2);
 		break;
 	case ROFFT_BODY:
 		p->offset = term_len(p, p->defindent);
 		break;
 	default:
 		break;
 	}
 
 	return 1;
 }
 
 static void
 termp_ss_post(DECL_ARGS)
 {
 
 	if (n->type == ROFFT_HEAD || n->type == ROFFT_BODY)
 		term_newln(p);
 }
 
 static int
 termp_cd_pre(DECL_ARGS)
 {
 
 	synopsis_pre(p, n);
 	term_fontpush(p, TERMFONT_BOLD);
 	return 1;
 }
 
 static int
 termp_in_pre(DECL_ARGS)
 {
 
 	synopsis_pre(p, n);
 
-	if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags) {
+	if (NODE_SYNPRETTY & n->flags && NODE_LINE & n->flags) {
 		term_fontpush(p, TERMFONT_BOLD);
 		term_word(p, "#include");
 		term_word(p, "<");
 	} else {
 		term_word(p, "<");
 		term_fontpush(p, TERMFONT_UNDER);
 	}
 
 	p->flags |= TERMP_NOSPACE;
 	return 1;
 }
 
 static void
 termp_in_post(DECL_ARGS)
 {
 
-	if (MDOC_SYNPRETTY & n->flags)
+	if (NODE_SYNPRETTY & n->flags)
 		term_fontpush(p, TERMFONT_BOLD);
 
 	p->flags |= TERMP_NOSPACE;
 	term_word(p, ">");
 
-	if (MDOC_SYNPRETTY & n->flags)
+	if (NODE_SYNPRETTY & n->flags)
 		term_fontpop(p);
 }
 
 static int
 termp_sp_pre(DECL_ARGS)
 {
 	struct roffsu	 su;
 	int		 i, len;
 
 	switch (n->tok) {
 	case MDOC_sp:
 		if (n->child) {
 			if ( ! a2roffsu(n->child->string, &su, SCALE_VS))
 				su.scale = 1.0;
 			len = term_vspan(p, &su);
 		} else
 			len = 1;
 		break;
 	case MDOC_br:
 		len = 0;
 		break;
 	default:
 		len = 1;
 		fn_prio = 0;
 		break;
 	}
 
 	if (0 == len)
 		term_newln(p);
 	else if (len < 0)
 		p->skipvsp -= len;
 	else
 		for (i = 0; i < len; i++)
 			term_vspace(p);
 
 	return 0;
 }
 
 static int
 termp_skip_pre(DECL_ARGS)
 {
 
 	return 0;
 }
 
 static int
 termp_quote_pre(DECL_ARGS)
 {
 
 	if (n->type != ROFFT_BODY && n->type != ROFFT_ELEM)
 		return 1;
 
 	switch (n->tok) {
 	case MDOC_Ao:
 	case MDOC_Aq:
 		term_word(p, n->child != NULL && n->child->next == NULL &&
 		    n->child->tok == MDOC_Mt ? "<" : "\\(la");
 		break;
 	case MDOC_Bro:
 	case MDOC_Brq:
 		term_word(p, "{");
 		break;
 	case MDOC_Oo:
 	case MDOC_Op:
 	case MDOC_Bo:
 	case MDOC_Bq:
 		term_word(p, "[");
 		break;
 	case MDOC_Do:
 	case MDOC_Dq:
 		term_word(p, "\\(Lq");
 		break;
 	case MDOC_En:
 		if (NULL == n->norm->Es ||
 		    NULL == n->norm->Es->child)
 			return 1;
 		term_word(p, n->norm->Es->child->string);
 		break;
 	case MDOC_Po:
 	case MDOC_Pq:
 		term_word(p, "(");
 		break;
 	case MDOC__T:
 	case MDOC_Qo:
 	case MDOC_Qq:
 		term_word(p, "\"");
 		break;
 	case MDOC_Ql:
 	case MDOC_So:
 	case MDOC_Sq:
 		term_word(p, "\\(oq");
 		break;
 	default:
 		abort();
 	}
 
 	p->flags |= TERMP_NOSPACE;
 	return 1;
 }
 
 static void
 termp_quote_post(DECL_ARGS)
 {
 
 	if (n->type != ROFFT_BODY && n->type != ROFFT_ELEM)
 		return;
 
 	p->flags |= TERMP_NOSPACE;
 
 	switch (n->tok) {
 	case MDOC_Ao:
 	case MDOC_Aq:
 		term_word(p, n->child != NULL && n->child->next == NULL &&
 		    n->child->tok == MDOC_Mt ? ">" : "\\(ra");
 		break;
 	case MDOC_Bro:
 	case MDOC_Brq:
 		term_word(p, "}");
 		break;
 	case MDOC_Oo:
 	case MDOC_Op:
 	case MDOC_Bo:
 	case MDOC_Bq:
 		term_word(p, "]");
 		break;
 	case MDOC_Do:
 	case MDOC_Dq:
 		term_word(p, "\\(Rq");
 		break;
 	case MDOC_En:
 		if (n->norm->Es == NULL ||
 		    n->norm->Es->child == NULL ||
 		    n->norm->Es->child->next == NULL)
 			p->flags &= ~TERMP_NOSPACE;
 		else
 			term_word(p, n->norm->Es->child->next->string);
 		break;
 	case MDOC_Po:
 	case MDOC_Pq:
 		term_word(p, ")");
 		break;
 	case MDOC__T:
 	case MDOC_Qo:
 	case MDOC_Qq:
 		term_word(p, "\"");
 		break;
 	case MDOC_Ql:
 	case MDOC_So:
 	case MDOC_Sq:
 		term_word(p, "\\(cq");
 		break;
 	default:
 		abort();
 	}
 }
 
 static int
 termp_eo_pre(DECL_ARGS)
 {
 
 	if (n->type != ROFFT_BODY)
 		return 1;
 
 	if (n->end == ENDBODY_NOT &&
 	    n->parent->head->child == NULL &&
 	    n->child != NULL &&
 	    n->child->end != ENDBODY_NOT)
 		term_word(p, "\\&");
 	else if (n->end != ENDBODY_NOT ? n->child != NULL :
 	     n->parent->head->child != NULL && (n->child != NULL ||
 	     (n->parent->tail != NULL && n->parent->tail->child != NULL)))
 		p->flags |= TERMP_NOSPACE;
 
 	return 1;
 }
 
 static void
 termp_eo_post(DECL_ARGS)
 {
 	int	 body, tail;
 
 	if (n->type != ROFFT_BODY)
 		return;
 
 	if (n->end != ENDBODY_NOT) {
 		p->flags &= ~TERMP_NOSPACE;
 		return;
 	}
 
 	body = n->child != NULL || n->parent->head->child != NULL;
 	tail = n->parent->tail != NULL && n->parent->tail->child != NULL;
 
 	if (body && tail)
 		p->flags |= TERMP_NOSPACE;
 	else if ( ! (body || tail))
 		term_word(p, "\\&");
 	else if ( ! tail)
 		p->flags &= ~TERMP_NOSPACE;
 }
 
 static int
 termp_fo_pre(DECL_ARGS)
 {
 	size_t		 rmargin = 0;
 	int		 pretty;
 
-	pretty = MDOC_SYNPRETTY & n->flags;
+	pretty = NODE_SYNPRETTY & n->flags;
 
 	if (n->type == ROFFT_BLOCK) {
 		synopsis_pre(p, n);
 		return 1;
 	} else if (n->type == ROFFT_BODY) {
 		if (pretty) {
 			rmargin = p->rmargin;
 			p->rmargin = p->offset + term_len(p, 4);
 			p->flags |= TERMP_NOBREAK | TERMP_BRIND |
 					TERMP_HANG;
 		}
 		p->flags |= TERMP_NOSPACE;
 		term_word(p, "(");
 		p->flags |= TERMP_NOSPACE;
 		if (pretty) {
 			term_flushln(p);
 			p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND |
 					TERMP_HANG);
 			p->offset = p->rmargin;
 			p->rmargin = rmargin;
 		}
 		return 1;
 	}
 
 	if (NULL == n->child)
 		return 0;
 
 	/* XXX: we drop non-initial arguments as per groff. */
 
 	assert(n->child->string);
 	term_fontpush(p, TERMFONT_BOLD);
 	term_word(p, n->child->string);
 	return 0;
 }
 
 static void
 termp_fo_post(DECL_ARGS)
 {
 
 	if (n->type != ROFFT_BODY)
 		return;
 
 	p->flags |= TERMP_NOSPACE;
 	term_word(p, ")");
 
-	if (MDOC_SYNPRETTY & n->flags) {
+	if (NODE_SYNPRETTY & n->flags) {
 		p->flags |= TERMP_NOSPACE;
 		term_word(p, ";");
 		term_flushln(p);
 	}
 }
 
 static int
 termp_bf_pre(DECL_ARGS)
 {
 
 	if (n->type == ROFFT_HEAD)
 		return 0;
 	else if (n->type != ROFFT_BODY)
 		return 1;
 
 	if (FONT_Em == n->norm->Bf.font)
 		term_fontpush(p, TERMFONT_UNDER);
 	else if (FONT_Sy == n->norm->Bf.font)
 		term_fontpush(p, TERMFONT_BOLD);
 	else
 		term_fontpush(p, TERMFONT_NONE);
 
 	return 1;
 }
 
 static int
 termp_sm_pre(DECL_ARGS)
 {
 
 	if (NULL == n->child)
 		p->flags ^= TERMP_NONOSPACE;
 	else if (0 == strcmp("on", n->child->string))
 		p->flags &= ~TERMP_NONOSPACE;
 	else
 		p->flags |= TERMP_NONOSPACE;
 
 	if (p->col && ! (TERMP_NONOSPACE & p->flags))
 		p->flags &= ~TERMP_NOSPACE;
 
 	return 0;
 }
 
 static int
 termp_ap_pre(DECL_ARGS)
 {
 
 	p->flags |= TERMP_NOSPACE;
 	term_word(p, "'");
 	p->flags |= TERMP_NOSPACE;
 	return 1;
 }
 
 static void
 termp____post(DECL_ARGS)
 {
 
 	/*
 	 * Handle lists of authors.  In general, print each followed by
 	 * a comma.  Don't print the comma if there are only two
 	 * authors.
 	 */
 	if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
 		if (NULL == n->next->next || MDOC__A != n->next->next->tok)
 			if (NULL == n->prev || MDOC__A != n->prev->tok)
 				return;
 
 	/* TODO: %U. */
 
 	if (NULL == n->parent || MDOC_Rs != n->parent->tok)
 		return;
 
 	p->flags |= TERMP_NOSPACE;
 	if (NULL == n->next) {
 		term_word(p, ".");
 		p->flags |= TERMP_SENTENCE;
 	} else
 		term_word(p, ",");
 }
 
 static int
 termp_li_pre(DECL_ARGS)
 {
 
+	termp_tag_pre(p, pair, meta, n);
 	term_fontpush(p, TERMFONT_NONE);
 	return 1;
 }
 
 static int
 termp_lk_pre(DECL_ARGS)
 {
 	const struct roff_node *link, *descr;
 
 	if (NULL == (link = n->child))
 		return 0;
 
 	if (NULL != (descr = link->next)) {
 		term_fontpush(p, TERMFONT_UNDER);
 		while (NULL != descr) {
 			term_word(p, descr->string);
 			descr = descr->next;
 		}
 		p->flags |= TERMP_NOSPACE;
 		term_word(p, ":");
 		term_fontpop(p);
 	}
 
 	term_fontpush(p, TERMFONT_BOLD);
 	term_word(p, link->string);
 	term_fontpop(p);
 
 	return 0;
 }
 
 static int
 termp_bk_pre(DECL_ARGS)
 {
 
 	switch (n->type) {
 	case ROFFT_BLOCK:
 		break;
 	case ROFFT_HEAD:
 		return 0;
 	case ROFFT_BODY:
 		if (n->parent->args != NULL || n->prev->child == NULL)
 			p->flags |= TERMP_PREKEEP;
 		break;
 	default:
 		abort();
 	}
 
 	return 1;
 }
 
 static void
 termp_bk_post(DECL_ARGS)
 {
 
 	if (n->type == ROFFT_BODY)
 		p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
 }
 
 static void
 termp__t_post(DECL_ARGS)
 {
 
 	/*
 	 * If we're in an `Rs' and there's a journal present, then quote
 	 * us instead of underlining us (for disambiguation).
 	 */
 	if (n->parent && MDOC_Rs == n->parent->tok &&
 	    n->parent->norm->Rs.quote_T)
 		termp_quote_post(p, pair, meta, n);
 
 	termp____post(p, pair, meta, n);
 }
 
 static int
 termp__t_pre(DECL_ARGS)
 {
 
 	/*
 	 * If we're in an `Rs' and there's a journal present, then quote
 	 * us instead of underlining us (for disambiguation).
 	 */
 	if (n->parent && MDOC_Rs == n->parent->tok &&
 	    n->parent->norm->Rs.quote_T)
 		return termp_quote_pre(p, pair, meta, n);
 
 	term_fontpush(p, TERMFONT_UNDER);
 	return 1;
 }
 
 static int
 termp_under_pre(DECL_ARGS)
 {
 
 	term_fontpush(p, TERMFONT_UNDER);
 	return 1;
 }
 
 static int
+termp_em_pre(DECL_ARGS)
+{
+	if (n->child != NULL &&
+	    n->child->type == ROFFT_TEXT)
+		tag_put(n->child->string, 0, p->line);
+	term_fontpush(p, TERMFONT_UNDER);
+	return 1;
+}
+
+static int
+termp_sy_pre(DECL_ARGS)
+{
+	if (n->child != NULL &&
+	    n->child->type == ROFFT_TEXT)
+		tag_put(n->child->string, 0, p->line);
+	term_fontpush(p, TERMFONT_BOLD);
+	return 1;
+}
+
+static int
 termp_er_pre(DECL_ARGS)
 {
 
 	if (n->sec == SEC_ERRORS &&
 	    (n->parent->tok == MDOC_It ||
 	     (n->parent->tok == MDOC_Bq &&
 	      n->parent->parent->parent->tok == MDOC_It)))
 		tag_put(n->child->string, 1, p->line);
 	return 1;
 }
 
 static int
 termp_tag_pre(DECL_ARGS)
 {
 
 	if (n->child != NULL &&
 	    n->child->type == ROFFT_TEXT &&
-	    n->prev == NULL &&
+	    (n->prev == NULL ||
+	     (n->prev->type == ROFFT_TEXT &&
+	      strcmp(n->prev->string, "|") == 0)) &&
 	    (n->parent->tok == MDOC_It ||
 	     (n->parent->tok == MDOC_Xo &&
 	      n->parent->parent->prev == NULL &&
 	      n->parent->parent->parent->tok == MDOC_It)))
 		tag_put(n->child->string, 1, p->line);
 	return 1;
 }
Index: stable/11/contrib/mdocml/mdoc_validate.c
===================================================================
--- stable/11/contrib/mdocml/mdoc_validate.c	(revision 316419)
+++ stable/11/contrib/mdocml/mdoc_validate.c	(revision 316420)
@@ -1,2294 +1,2441 @@
-/*	$Id: mdoc_validate.c,v 1.301 2016/01/08 17:48:09 schwarze Exp $ */
+/*	$Id: mdoc_validate.c,v 1.317 2017/01/11 17:39:53 schwarze Exp $ */
 /*
  * Copyright (c) 2008-2012 Kristaps Dzonsons 
- * Copyright (c) 2010-2016 Ingo Schwarze 
+ * Copyright (c) 2010-2017 Ingo Schwarze 
  * Copyright (c) 2010 Joerg Sonnenberger 
  *
  * 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 AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h"
 
 #include 
 #ifndef OSNAME
 #include 
 #endif
 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 
 #include "mandoc_aux.h"
 #include "mandoc.h"
 #include "roff.h"
 #include "mdoc.h"
 #include "libmandoc.h"
 #include "roff_int.h"
 #include "libmdoc.h"
 
 /* FIXME: .Bl -diag can't have non-text children in HEAD. */
 
 #define	POST_ARGS struct roff_man *mdoc
 
 enum	check_ineq {
 	CHECK_LT,
 	CHECK_GT,
 	CHECK_EQ
 };
 
 typedef	void	(*v_post)(POST_ARGS);
 
+static	int	 build_list(struct roff_man *, int);
 static	void	 check_text(struct roff_man *, int, int, char *);
 static	void	 check_argv(struct roff_man *,
 			struct roff_node *, struct mdoc_argv *);
 static	void	 check_args(struct roff_man *, struct roff_node *);
 static	int	 child_an(const struct roff_node *);
 static	size_t		macro2len(int);
 static	void	 rewrite_macro2len(char **);
 
 static	void	 post_an(POST_ARGS);
 static	void	 post_an_norm(POST_ARGS);
 static	void	 post_at(POST_ARGS);
 static	void	 post_bd(POST_ARGS);
 static	void	 post_bf(POST_ARGS);
 static	void	 post_bk(POST_ARGS);
 static	void	 post_bl(POST_ARGS);
 static	void	 post_bl_block(POST_ARGS);
-static	void	 post_bl_block_tag(POST_ARGS);
 static	void	 post_bl_head(POST_ARGS);
 static	void	 post_bl_norm(POST_ARGS);
 static	void	 post_bx(POST_ARGS);
 static	void	 post_defaults(POST_ARGS);
 static	void	 post_display(POST_ARGS);
 static	void	 post_dd(POST_ARGS);
 static	void	 post_dt(POST_ARGS);
 static	void	 post_en(POST_ARGS);
 static	void	 post_es(POST_ARGS);
 static	void	 post_eoln(POST_ARGS);
 static	void	 post_ex(POST_ARGS);
 static	void	 post_fa(POST_ARGS);
 static	void	 post_fn(POST_ARGS);
 static	void	 post_fname(POST_ARGS);
 static	void	 post_fo(POST_ARGS);
 static	void	 post_hyph(POST_ARGS);
 static	void	 post_ignpar(POST_ARGS);
 static	void	 post_it(POST_ARGS);
 static	void	 post_lb(POST_ARGS);
 static	void	 post_nd(POST_ARGS);
 static	void	 post_nm(POST_ARGS);
 static	void	 post_ns(POST_ARGS);
 static	void	 post_obsolete(POST_ARGS);
 static	void	 post_os(POST_ARGS);
 static	void	 post_par(POST_ARGS);
 static	void	 post_prevpar(POST_ARGS);
 static	void	 post_root(POST_ARGS);
 static	void	 post_rs(POST_ARGS);
+static	void	 post_rv(POST_ARGS);
 static	void	 post_sh(POST_ARGS);
 static	void	 post_sh_head(POST_ARGS);
 static	void	 post_sh_name(POST_ARGS);
 static	void	 post_sh_see_also(POST_ARGS);
 static	void	 post_sh_authors(POST_ARGS);
 static	void	 post_sm(POST_ARGS);
 static	void	 post_st(POST_ARGS);
 static	void	 post_std(POST_ARGS);
+static	void	 post_xr(POST_ARGS);
+static	void	 post_xx(POST_ARGS);
 
 static	v_post mdoc_valids[MDOC_MAX] = {
 	NULL,		/* Ap */
 	post_dd,	/* Dd */
 	post_dt,	/* Dt */
 	post_os,	/* Os */
 	post_sh,	/* Sh */
 	post_ignpar,	/* Ss */
 	post_par,	/* Pp */
 	post_display,	/* D1 */
 	post_display,	/* Dl */
 	post_display,	/* Bd */
 	NULL,		/* Ed */
 	post_bl,	/* Bl */
 	NULL,		/* El */
 	post_it,	/* It */
 	NULL,		/* Ad */
 	post_an,	/* An */
 	post_defaults,	/* Ar */
 	NULL,		/* Cd */
 	NULL,		/* Cm */
 	NULL,		/* Dv */
 	NULL,		/* Er */
 	NULL,		/* Ev */
 	post_ex,	/* Ex */
 	post_fa,	/* Fa */
 	NULL,		/* Fd */
 	NULL,		/* Fl */
 	post_fn,	/* Fn */
 	NULL,		/* Ft */
 	NULL,		/* Ic */
 	NULL,		/* In */
 	post_defaults,	/* Li */
 	post_nd,	/* Nd */
 	post_nm,	/* Nm */
 	NULL,		/* Op */
 	post_obsolete,	/* Ot */
 	post_defaults,	/* Pa */
-	post_std,	/* Rv */
+	post_rv,	/* Rv */
 	post_st,	/* St */
 	NULL,		/* Va */
 	NULL,		/* Vt */
-	NULL,		/* Xr */
+	post_xr,	/* Xr */
 	NULL,		/* %A */
 	post_hyph,	/* %B */ /* FIXME: can be used outside Rs/Re. */
 	NULL,		/* %D */
 	NULL,		/* %I */
 	NULL,		/* %J */
 	post_hyph,	/* %N */
 	post_hyph,	/* %O */
 	NULL,		/* %P */
 	post_hyph,	/* %R */
 	post_hyph,	/* %T */ /* FIXME: can be used outside Rs/Re. */
 	NULL,		/* %V */
 	NULL,		/* Ac */
 	NULL,		/* Ao */
 	NULL,		/* Aq */
 	post_at,	/* At */
 	NULL,		/* Bc */
 	post_bf,	/* Bf */
 	NULL,		/* Bo */
 	NULL,		/* Bq */
-	NULL,		/* Bsx */
+	post_xx,	/* Bsx */
 	post_bx,	/* Bx */
 	post_obsolete,	/* Db */
 	NULL,		/* Dc */
 	NULL,		/* Do */
 	NULL,		/* Dq */
 	NULL,		/* Ec */
 	NULL,		/* Ef */
 	NULL,		/* Em */
 	NULL,		/* Eo */
-	NULL,		/* Fx */
+	post_xx,	/* Fx */
 	NULL,		/* Ms */
 	NULL,		/* No */
 	post_ns,	/* Ns */
-	NULL,		/* Nx */
-	NULL,		/* Ox */
+	post_xx,	/* Nx */
+	post_xx,	/* Ox */
 	NULL,		/* Pc */
 	NULL,		/* Pf */
 	NULL,		/* Po */
 	NULL,		/* Pq */
 	NULL,		/* Qc */
 	NULL,		/* Ql */
 	NULL,		/* Qo */
 	NULL,		/* Qq */
 	NULL,		/* Re */
 	post_rs,	/* Rs */
 	NULL,		/* Sc */
 	NULL,		/* So */
 	NULL,		/* Sq */
 	post_sm,	/* Sm */
 	post_hyph,	/* Sx */
 	NULL,		/* Sy */
 	NULL,		/* Tn */
-	NULL,		/* Ux */
+	post_xx,	/* Ux */
 	NULL,		/* Xc */
 	NULL,		/* Xo */
 	post_fo,	/* Fo */
 	NULL,		/* Fc */
 	NULL,		/* Oo */
 	NULL,		/* Oc */
 	post_bk,	/* Bk */
 	NULL,		/* Ek */
 	post_eoln,	/* Bt */
 	NULL,		/* Hf */
 	post_obsolete,	/* Fr */
 	post_eoln,	/* Ud */
 	post_lb,	/* Lb */
 	post_par,	/* Lp */
 	NULL,		/* Lk */
 	post_defaults,	/* Mt */
 	NULL,		/* Brq */
 	NULL,		/* Bro */
 	NULL,		/* Brc */
 	NULL,		/* %C */
 	post_es,	/* Es */
 	post_en,	/* En */
-	NULL,		/* Dx */
+	post_xx,	/* Dx */
 	NULL,		/* %Q */
 	post_par,	/* br */
 	post_par,	/* sp */
 	NULL,		/* %U */
 	NULL,		/* Ta */
 	NULL,		/* ll */
 };
 
 #define	RSORD_MAX 14 /* Number of `Rs' blocks. */
 
 static	const int rsord[RSORD_MAX] = {
 	MDOC__A,
 	MDOC__T,
 	MDOC__B,
 	MDOC__I,
 	MDOC__J,
 	MDOC__R,
 	MDOC__N,
 	MDOC__V,
 	MDOC__U,
 	MDOC__P,
 	MDOC__Q,
 	MDOC__C,
 	MDOC__D,
 	MDOC__O
 };
 
 static	const char * const secnames[SEC__MAX] = {
 	NULL,
 	"NAME",
 	"LIBRARY",
 	"SYNOPSIS",
 	"DESCRIPTION",
 	"CONTEXT",
 	"IMPLEMENTATION NOTES",
 	"RETURN VALUES",
 	"ENVIRONMENT",
 	"FILES",
 	"EXIT STATUS",
 	"EXAMPLES",
 	"DIAGNOSTICS",
 	"COMPATIBILITY",
 	"ERRORS",
 	"SEE ALSO",
 	"STANDARDS",
 	"HISTORY",
 	"AUTHORS",
 	"CAVEATS",
 	"BUGS",
 	"SECURITY CONSIDERATIONS",
 	NULL
 };
 
 
 void
 mdoc_node_validate(struct roff_man *mdoc)
 {
 	struct roff_node *n;
 	v_post *p;
 
 	n = mdoc->last;
 	mdoc->last = mdoc->last->child;
 	while (mdoc->last != NULL) {
 		mdoc_node_validate(mdoc);
 		if (mdoc->last == n)
 			mdoc->last = mdoc->last->child;
 		else
 			mdoc->last = mdoc->last->next;
 	}
 
 	mdoc->last = n;
 	mdoc->next = ROFF_NEXT_SIBLING;
 	switch (n->type) {
 	case ROFFT_TEXT:
-		if (n->sec != SEC_SYNOPSIS || n->parent->tok != MDOC_Fd)
+		if (n->sec != SEC_SYNOPSIS ||
+		    (n->parent->tok != MDOC_Cd && n->parent->tok != MDOC_Fd))
 			check_text(mdoc, n->line, n->pos, n->string);
 		break;
 	case ROFFT_EQN:
 	case ROFFT_TBL:
 		break;
 	case ROFFT_ROOT:
 		post_root(mdoc);
 		break;
 	default:
 		check_args(mdoc, mdoc->last);
 
 		/*
 		 * Closing delimiters are not special at the
 		 * beginning of a block, opening delimiters
 		 * are not special at the end.
 		 */
 
 		if (n->child != NULL)
-			n->child->flags &= ~MDOC_DELIMC;
+			n->child->flags &= ~NODE_DELIMC;
 		if (n->last != NULL)
-			n->last->flags &= ~MDOC_DELIMO;
+			n->last->flags &= ~NODE_DELIMO;
 
 		/* Call the macro's postprocessor. */
 
 		p = mdoc_valids + n->tok;
 		if (*p)
 			(*p)(mdoc);
 		if (mdoc->last == n)
 			mdoc_state(mdoc, n);
 		break;
 	}
 }
 
 static void
 check_args(struct roff_man *mdoc, struct roff_node *n)
 {
 	int		 i;
 
 	if (NULL == n->args)
 		return;
 
 	assert(n->args->argc);
 	for (i = 0; i < (int)n->args->argc; i++)
 		check_argv(mdoc, n, &n->args->argv[i]);
 }
 
 static void
 check_argv(struct roff_man *mdoc, struct roff_node *n, struct mdoc_argv *v)
 {
 	int		 i;
 
 	for (i = 0; i < (int)v->sz; i++)
 		check_text(mdoc, v->line, v->pos, v->value[i]);
 }
 
 static void
 check_text(struct roff_man *mdoc, int ln, int pos, char *p)
 {
 	char		*cp;
 
 	if (MDOC_LITERAL & mdoc->flags)
 		return;
 
 	for (cp = p; NULL != (p = strchr(p, '\t')); p++)
 		mandoc_msg(MANDOCERR_FI_TAB, mdoc->parse,
 		    ln, pos + (int)(p - cp), NULL);
 }
 
 static void
 post_bl_norm(POST_ARGS)
 {
 	struct roff_node *n;
 	struct mdoc_argv *argv, *wa;
 	int		  i;
 	enum mdocargt	  mdoclt;
 	enum mdoc_list	  lt;
 
 	n = mdoc->last->parent;
 	n->norm->Bl.type = LIST__NONE;
 
 	/*
 	 * First figure out which kind of list to use: bind ourselves to
 	 * the first mentioned list type and warn about any remaining
 	 * ones.  If we find no list type, we default to LIST_item.
 	 */
 
 	wa = (n->args == NULL) ? NULL : n->args->argv;
 	mdoclt = MDOC_ARG_MAX;
 	for (i = 0; n->args && i < (int)n->args->argc; i++) {
 		argv = n->args->argv + i;
 		lt = LIST__NONE;
 		switch (argv->arg) {
 		/* Set list types. */
 		case MDOC_Bullet:
 			lt = LIST_bullet;
 			break;
 		case MDOC_Dash:
 			lt = LIST_dash;
 			break;
 		case MDOC_Enum:
 			lt = LIST_enum;
 			break;
 		case MDOC_Hyphen:
 			lt = LIST_hyphen;
 			break;
 		case MDOC_Item:
 			lt = LIST_item;
 			break;
 		case MDOC_Tag:
 			lt = LIST_tag;
 			break;
 		case MDOC_Diag:
 			lt = LIST_diag;
 			break;
 		case MDOC_Hang:
 			lt = LIST_hang;
 			break;
 		case MDOC_Ohang:
 			lt = LIST_ohang;
 			break;
 		case MDOC_Inset:
 			lt = LIST_inset;
 			break;
 		case MDOC_Column:
 			lt = LIST_column;
 			break;
 		/* Set list arguments. */
 		case MDOC_Compact:
 			if (n->norm->Bl.comp)
 				mandoc_msg(MANDOCERR_ARG_REP,
 				    mdoc->parse, argv->line,
 				    argv->pos, "Bl -compact");
 			n->norm->Bl.comp = 1;
 			break;
 		case MDOC_Width:
 			wa = argv;
 			if (0 == argv->sz) {
 				mandoc_msg(MANDOCERR_ARG_EMPTY,
 				    mdoc->parse, argv->line,
 				    argv->pos, "Bl -width");
 				n->norm->Bl.width = "0n";
 				break;
 			}
 			if (NULL != n->norm->Bl.width)
 				mandoc_vmsg(MANDOCERR_ARG_REP,
 				    mdoc->parse, argv->line,
 				    argv->pos, "Bl -width %s",
 				    argv->value[0]);
 			rewrite_macro2len(argv->value);
 			n->norm->Bl.width = argv->value[0];
 			break;
 		case MDOC_Offset:
 			if (0 == argv->sz) {
 				mandoc_msg(MANDOCERR_ARG_EMPTY,
 				    mdoc->parse, argv->line,
 				    argv->pos, "Bl -offset");
 				break;
 			}
 			if (NULL != n->norm->Bl.offs)
 				mandoc_vmsg(MANDOCERR_ARG_REP,
 				    mdoc->parse, argv->line,
 				    argv->pos, "Bl -offset %s",
 				    argv->value[0]);
 			rewrite_macro2len(argv->value);
 			n->norm->Bl.offs = argv->value[0];
 			break;
 		default:
 			continue;
 		}
 		if (LIST__NONE == lt)
 			continue;
 		mdoclt = argv->arg;
 
 		/* Check: multiple list types. */
 
 		if (LIST__NONE != n->norm->Bl.type) {
 			mandoc_vmsg(MANDOCERR_BL_REP,
 			    mdoc->parse, n->line, n->pos,
 			    "Bl -%s", mdoc_argnames[argv->arg]);
 			continue;
 		}
 
 		/* The list type should come first. */
 
 		if (n->norm->Bl.width ||
 		    n->norm->Bl.offs ||
 		    n->norm->Bl.comp)
 			mandoc_vmsg(MANDOCERR_BL_LATETYPE,
 			    mdoc->parse, n->line, n->pos, "Bl -%s",
 			    mdoc_argnames[n->args->argv[0].arg]);
 
 		n->norm->Bl.type = lt;
 		if (LIST_column == lt) {
 			n->norm->Bl.ncols = argv->sz;
 			n->norm->Bl.cols = (void *)argv->value;
 		}
 	}
 
 	/* Allow lists to default to LIST_item. */
 
 	if (LIST__NONE == n->norm->Bl.type) {
 		mandoc_msg(MANDOCERR_BL_NOTYPE, mdoc->parse,
 		    n->line, n->pos, "Bl");
 		n->norm->Bl.type = LIST_item;
+		mdoclt = MDOC_Item;
 	}
 
 	/*
 	 * Validate the width field.  Some list types don't need width
 	 * types and should be warned about them.  Others should have it
 	 * and must also be warned.  Yet others have a default and need
 	 * no warning.
 	 */
 
 	switch (n->norm->Bl.type) {
 	case LIST_tag:
 		if (NULL == n->norm->Bl.width)
 			mandoc_msg(MANDOCERR_BL_NOWIDTH, mdoc->parse,
 			    n->line, n->pos, "Bl -tag");
 		break;
 	case LIST_column:
 	case LIST_diag:
 	case LIST_ohang:
 	case LIST_inset:
 	case LIST_item:
 		if (n->norm->Bl.width)
 			mandoc_vmsg(MANDOCERR_BL_SKIPW, mdoc->parse,
 			    wa->line, wa->pos, "Bl -%s",
 			    mdoc_argnames[mdoclt]);
 		break;
 	case LIST_bullet:
 	case LIST_dash:
 	case LIST_hyphen:
 		if (NULL == n->norm->Bl.width)
 			n->norm->Bl.width = "2n";
 		break;
 	case LIST_enum:
 		if (NULL == n->norm->Bl.width)
 			n->norm->Bl.width = "3n";
 		break;
 	default:
 		break;
 	}
 }
 
 static void
 post_bd(POST_ARGS)
 {
 	struct roff_node *n;
 	struct mdoc_argv *argv;
 	int		  i;
 	enum mdoc_disp	  dt;
 
 	n = mdoc->last;
 	for (i = 0; n->args && i < (int)n->args->argc; i++) {
 		argv = n->args->argv + i;
 		dt = DISP__NONE;
 
 		switch (argv->arg) {
 		case MDOC_Centred:
 			dt = DISP_centered;
 			break;
 		case MDOC_Ragged:
 			dt = DISP_ragged;
 			break;
 		case MDOC_Unfilled:
 			dt = DISP_unfilled;
 			break;
 		case MDOC_Filled:
 			dt = DISP_filled;
 			break;
 		case MDOC_Literal:
 			dt = DISP_literal;
 			break;
 		case MDOC_File:
 			mandoc_msg(MANDOCERR_BD_FILE, mdoc->parse,
 			    n->line, n->pos, NULL);
 			break;
 		case MDOC_Offset:
 			if (0 == argv->sz) {
 				mandoc_msg(MANDOCERR_ARG_EMPTY,
 				    mdoc->parse, argv->line,
 				    argv->pos, "Bd -offset");
 				break;
 			}
 			if (NULL != n->norm->Bd.offs)
 				mandoc_vmsg(MANDOCERR_ARG_REP,
 				    mdoc->parse, argv->line,
 				    argv->pos, "Bd -offset %s",
 				    argv->value[0]);
 			rewrite_macro2len(argv->value);
 			n->norm->Bd.offs = argv->value[0];
 			break;
 		case MDOC_Compact:
 			if (n->norm->Bd.comp)
 				mandoc_msg(MANDOCERR_ARG_REP,
 				    mdoc->parse, argv->line,
 				    argv->pos, "Bd -compact");
 			n->norm->Bd.comp = 1;
 			break;
 		default:
 			abort();
 		}
 		if (DISP__NONE == dt)
 			continue;
 
 		if (DISP__NONE == n->norm->Bd.type)
 			n->norm->Bd.type = dt;
 		else
 			mandoc_vmsg(MANDOCERR_BD_REP,
 			    mdoc->parse, n->line, n->pos,
 			    "Bd -%s", mdoc_argnames[argv->arg]);
 	}
 
 	if (DISP__NONE == n->norm->Bd.type) {
 		mandoc_msg(MANDOCERR_BD_NOTYPE, mdoc->parse,
 		    n->line, n->pos, "Bd");
 		n->norm->Bd.type = DISP_ragged;
 	}
 }
 
+/*
+ * Stand-alone line macros.
+ */
+
 static void
 post_an_norm(POST_ARGS)
 {
 	struct roff_node *n;
 	struct mdoc_argv *argv;
 	size_t	 i;
 
 	n = mdoc->last;
 	if (n->args == NULL)
 		return;
 
 	for (i = 1; i < n->args->argc; i++) {
 		argv = n->args->argv + i;
 		mandoc_vmsg(MANDOCERR_AN_REP,
 		    mdoc->parse, argv->line, argv->pos,
 		    "An -%s", mdoc_argnames[argv->arg]);
 	}
 
 	argv = n->args->argv;
 	if (argv->arg == MDOC_Split)
 		n->norm->An.auth = AUTH_split;
 	else if (argv->arg == MDOC_Nosplit)
 		n->norm->An.auth = AUTH_nosplit;
 	else
 		abort();
 }
 
 static void
+post_eoln(POST_ARGS)
+{
+	struct roff_node	*n;
+
+	n = mdoc->last;
+	if (n->child != NULL)
+		mandoc_vmsg(MANDOCERR_ARG_SKIP, mdoc->parse,
+		    n->line, n->pos, "%s %s",
+		    mdoc_macronames[n->tok], n->child->string);
+
+	while (n->child != NULL)
+		roff_node_delete(mdoc, n->child);
+
+	roff_word_alloc(mdoc, n->line, n->pos, n->tok == MDOC_Bt ?
+	    "is currently in beta test." : "currently under development.");
+	mdoc->last->flags |= NODE_EOS | NODE_NOSRC;
+	mdoc->last = n;
+}
+
+static int
+build_list(struct roff_man *mdoc, int tok)
+{
+	struct roff_node	*n;
+	int			 ic;
+
+	n = mdoc->last->next;
+	for (ic = 1;; ic++) {
+		roff_elem_alloc(mdoc, n->line, n->pos, tok);
+		mdoc->last->flags |= NODE_NOSRC;
+		mdoc_node_relink(mdoc, n);
+		n = mdoc->last = mdoc->last->parent;
+		mdoc->next = ROFF_NEXT_SIBLING;
+		if (n->next == NULL)
+			return ic;
+		if (ic > 1 || n->next->next != NULL) {
+			roff_word_alloc(mdoc, n->line, n->pos, ",");
+			mdoc->last->flags |= NODE_DELIMC | NODE_NOSRC;
+		}
+		n = mdoc->last->next;
+		if (n->next == NULL) {
+			roff_word_alloc(mdoc, n->line, n->pos, "and");
+			mdoc->last->flags |= NODE_NOSRC;
+		}
+	}
+}
+
+static void
+post_ex(POST_ARGS)
+{
+	struct roff_node	*n;
+	int			 ic;
+
+	post_std(mdoc);
+
+	n = mdoc->last;
+	mdoc->next = ROFF_NEXT_CHILD;
+	roff_word_alloc(mdoc, n->line, n->pos, "The");
+	mdoc->last->flags |= NODE_NOSRC;
+
+	if (mdoc->last->next != NULL)
+		ic = build_list(mdoc, MDOC_Nm);
+	else if (mdoc->meta.name != NULL) {
+		roff_elem_alloc(mdoc, n->line, n->pos, MDOC_Nm);
+		mdoc->last->flags |= NODE_NOSRC;
+		roff_word_alloc(mdoc, n->line, n->pos, mdoc->meta.name);
+		mdoc->last->flags |= NODE_NOSRC;
+		mdoc->last = mdoc->last->parent;
+		mdoc->next = ROFF_NEXT_SIBLING;
+		ic = 1;
+	} else {
+		mandoc_msg(MANDOCERR_EX_NONAME, mdoc->parse,
+		    n->line, n->pos, "Ex");
+		ic = 0;
+	}
+
+	roff_word_alloc(mdoc, n->line, n->pos,
+	    ic > 1 ? "utilities exit\\~0" : "utility exits\\~0");
+	mdoc->last->flags |= NODE_NOSRC;
+	roff_word_alloc(mdoc, n->line, n->pos,
+	    "on success, and\\~>0 if an error occurs.");
+	mdoc->last->flags |= NODE_EOS | NODE_NOSRC;
+	mdoc->last = n;
+}
+
+static void
+post_lb(POST_ARGS)
+{
+	struct roff_node	*n;
+	const char		*p;
+
+	n = mdoc->last;
+	assert(n->child->type == ROFFT_TEXT);
+	mdoc->next = ROFF_NEXT_CHILD;
+
+	if ((p = mdoc_a2lib(n->child->string)) != NULL) {
+		n->child->flags |= NODE_NOPRT;
+		roff_word_alloc(mdoc, n->line, n->pos, p);
+		mdoc->last->flags = NODE_NOSRC;
+		mdoc->last = n;
+		return;
+	}
+
+	roff_word_alloc(mdoc, n->line, n->pos, "library");
+	mdoc->last->flags = NODE_NOSRC;
+	roff_word_alloc(mdoc, n->line, n->pos, "\\(Lq");
+	mdoc->last->flags = NODE_DELIMO | NODE_NOSRC;
+	mdoc->last = mdoc->last->next;
+	roff_word_alloc(mdoc, n->line, n->pos, "\\(Rq");
+	mdoc->last->flags = NODE_DELIMC | NODE_NOSRC;
+	mdoc->last = n;
+}
+
+static void
+post_rv(POST_ARGS)
+{
+	struct roff_node	*n;
+	int			 ic;
+
+	post_std(mdoc);
+
+	n = mdoc->last;
+	mdoc->next = ROFF_NEXT_CHILD;
+	if (n->child != NULL) {
+		roff_word_alloc(mdoc, n->line, n->pos, "The");
+		mdoc->last->flags |= NODE_NOSRC;
+		ic = build_list(mdoc, MDOC_Fn);
+		roff_word_alloc(mdoc, n->line, n->pos,
+		    ic > 1 ? "functions return" : "function returns");
+		mdoc->last->flags |= NODE_NOSRC;
+		roff_word_alloc(mdoc, n->line, n->pos,
+		    "the value\\~0 if successful;");
+	} else
+		roff_word_alloc(mdoc, n->line, n->pos, "Upon successful "
+		    "completion, the value\\~0 is returned;");
+	mdoc->last->flags |= NODE_NOSRC;
+
+	roff_word_alloc(mdoc, n->line, n->pos, "otherwise "
+	    "the value\\~\\-1 is returned and the global variable");
+	mdoc->last->flags |= NODE_NOSRC;
+	roff_elem_alloc(mdoc, n->line, n->pos, MDOC_Va);
+	mdoc->last->flags |= NODE_NOSRC;
+	roff_word_alloc(mdoc, n->line, n->pos, "errno");
+	mdoc->last->flags |= NODE_NOSRC;
+	mdoc->last = mdoc->last->parent;
+	mdoc->next = ROFF_NEXT_SIBLING;
+	roff_word_alloc(mdoc, n->line, n->pos,
+	    "is set to indicate the error.");
+	mdoc->last->flags |= NODE_EOS | NODE_NOSRC;
+	mdoc->last = n;
+}
+
+static void
 post_std(POST_ARGS)
 {
 	struct roff_node *n;
 
 	n = mdoc->last;
 	if (n->args && n->args->argc == 1)
 		if (n->args->argv[0].arg == MDOC_Std)
 			return;
 
 	mandoc_msg(MANDOCERR_ARG_STD, mdoc->parse,
 	    n->line, n->pos, mdoc_macronames[n->tok]);
 }
 
 static void
+post_st(POST_ARGS)
+{
+	struct roff_node	 *n, *nch;
+	const char		 *p;
+
+	n = mdoc->last;
+	nch = n->child;
+	assert(nch->type == ROFFT_TEXT);
+
+	if ((p = mdoc_a2st(nch->string)) == NULL) {
+		mandoc_vmsg(MANDOCERR_ST_BAD, mdoc->parse,
+		    nch->line, nch->pos, "St %s", nch->string);
+		roff_node_delete(mdoc, n);
+		return;
+	}
+
+	nch->flags |= NODE_NOPRT;
+	mdoc->next = ROFF_NEXT_CHILD;
+	roff_word_alloc(mdoc, nch->line, nch->pos, p);
+	mdoc->last->flags |= NODE_NOSRC;
+	mdoc->last= n;
+}
+
+static void
 post_obsolete(POST_ARGS)
 {
 	struct roff_node *n;
 
 	n = mdoc->last;
 	if (n->type == ROFFT_ELEM || n->type == ROFFT_BLOCK)
 		mandoc_msg(MANDOCERR_MACRO_OBS, mdoc->parse,
 		    n->line, n->pos, mdoc_macronames[n->tok]);
 }
 
+/*
+ * Block macros.
+ */
+
 static void
 post_bf(POST_ARGS)
 {
 	struct roff_node *np, *nch;
 
 	/*
 	 * Unlike other data pointers, these are "housed" by the HEAD
 	 * element, which contains the goods.
 	 */
 
 	np = mdoc->last;
 	if (np->type != ROFFT_HEAD)
 		return;
 
 	assert(np->parent->type == ROFFT_BLOCK);
 	assert(np->parent->tok == MDOC_Bf);
 
 	/* Check the number of arguments. */
 
 	nch = np->child;
 	if (np->parent->args == NULL) {
 		if (nch == NULL) {
 			mandoc_msg(MANDOCERR_BF_NOFONT, mdoc->parse,
 			    np->line, np->pos, "Bf");
 			return;
 		}
 		nch = nch->next;
 	}
 	if (nch != NULL)
 		mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse,
 		    nch->line, nch->pos, "Bf ... %s", nch->string);
 
 	/* Extract argument into data. */
 
 	if (np->parent->args != NULL) {
 		switch (np->parent->args->argv[0].arg) {
 		case MDOC_Emphasis:
 			np->norm->Bf.font = FONT_Em;
 			break;
 		case MDOC_Literal:
 			np->norm->Bf.font = FONT_Li;
 			break;
 		case MDOC_Symbolic:
 			np->norm->Bf.font = FONT_Sy;
 			break;
 		default:
 			abort();
 		}
 		return;
 	}
 
 	/* Extract parameter into data. */
 
 	if ( ! strcmp(np->child->string, "Em"))
 		np->norm->Bf.font = FONT_Em;
 	else if ( ! strcmp(np->child->string, "Li"))
 		np->norm->Bf.font = FONT_Li;
 	else if ( ! strcmp(np->child->string, "Sy"))
 		np->norm->Bf.font = FONT_Sy;
 	else
 		mandoc_vmsg(MANDOCERR_BF_BADFONT, mdoc->parse,
 		    np->child->line, np->child->pos,
 		    "Bf %s", np->child->string);
 }
 
 static void
-post_lb(POST_ARGS)
-{
-	struct roff_node	*n;
-	const char		*stdlibname;
-	char			*libname;
-
-	n = mdoc->last->child;
-	assert(n->type == ROFFT_TEXT);
-
-	if (NULL == (stdlibname = mdoc_a2lib(n->string)))
-		mandoc_asprintf(&libname,
-		    "library \\(Lq%s\\(Rq", n->string);
-	else
-		libname = mandoc_strdup(stdlibname);
-
-	free(n->string);
-	n->string = libname;
-}
-
-static void
-post_eoln(POST_ARGS)
-{
-	const struct roff_node *n;
-
-	n = mdoc->last;
-	if (n->child != NULL)
-		mandoc_vmsg(MANDOCERR_ARG_SKIP,
-		    mdoc->parse, n->line, n->pos,
-		    "%s %s", mdoc_macronames[n->tok],
-		    n->child->string);
-}
-
-static void
 post_fname(POST_ARGS)
 {
 	const struct roff_node	*n;
 	const char		*cp;
 	size_t			 pos;
 
 	n = mdoc->last->child;
 	pos = strcspn(n->string, "()");
 	cp = n->string + pos;
 	if ( ! (cp[0] == '\0' || (cp[0] == '(' && cp[1] == '*')))
 		mandoc_msg(MANDOCERR_FN_PAREN, mdoc->parse,
 		    n->line, n->pos + pos, n->string);
 }
 
 static void
 post_fn(POST_ARGS)
 {
 
 	post_fname(mdoc);
 	post_fa(mdoc);
 }
 
 static void
 post_fo(POST_ARGS)
 {
 	const struct roff_node	*n;
 
 	n = mdoc->last;
 
 	if (n->type != ROFFT_HEAD)
 		return;
 
 	if (n->child == NULL) {
 		mandoc_msg(MANDOCERR_FO_NOHEAD, mdoc->parse,
 		    n->line, n->pos, "Fo");
 		return;
 	}
 	if (n->child != n->last) {
 		mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse,
 		    n->child->next->line, n->child->next->pos,
 		    "Fo ... %s", n->child->next->string);
 		while (n->child != n->last)
 			roff_node_delete(mdoc, n->last);
 	}
 
 	post_fname(mdoc);
 }
 
 static void
 post_fa(POST_ARGS)
 {
 	const struct roff_node *n;
 	const char *cp;
 
 	for (n = mdoc->last->child; n != NULL; n = n->next) {
 		for (cp = n->string; *cp != '\0'; cp++) {
 			/* Ignore callbacks and alterations. */
 			if (*cp == '(' || *cp == '{')
 				break;
 			if (*cp != ',')
 				continue;
 			mandoc_msg(MANDOCERR_FA_COMMA, mdoc->parse,
 			    n->line, n->pos + (cp - n->string),
 			    n->string);
 			break;
 		}
 	}
 }
 
 static void
 post_nm(POST_ARGS)
 {
 	struct roff_node	*n;
 
 	n = mdoc->last;
 
 	if (n->last != NULL &&
 	    (n->last->tok == MDOC_Pp ||
 	     n->last->tok == MDOC_Lp))
 		mdoc_node_relink(mdoc, n->last);
 
-	if (mdoc->meta.name != NULL)
-		return;
-
-	deroff(&mdoc->meta.name, n);
-
 	if (mdoc->meta.name == NULL)
+		deroff(&mdoc->meta.name, n);
+
+	if (mdoc->meta.name == NULL ||
+	    (mdoc->lastsec == SEC_NAME && n->child == NULL))
 		mandoc_msg(MANDOCERR_NM_NONAME, mdoc->parse,
 		    n->line, n->pos, "Nm");
 }
 
 static void
 post_nd(POST_ARGS)
 {
 	struct roff_node	*n;
 
 	n = mdoc->last;
 
 	if (n->type != ROFFT_BODY)
 		return;
 
 	if (n->child == NULL)
 		mandoc_msg(MANDOCERR_ND_EMPTY, mdoc->parse,
 		    n->line, n->pos, "Nd");
 
 	post_hyph(mdoc);
 }
 
 static void
 post_display(POST_ARGS)
 {
 	struct roff_node *n, *np;
 
 	n = mdoc->last;
 	switch (n->type) {
 	case ROFFT_BODY:
-		if (n->end != ENDBODY_NOT)
-			break;
-		if (n->child == NULL)
+		if (n->end != ENDBODY_NOT) {
+			if (n->tok == MDOC_Bd &&
+			    n->body->parent->args == NULL)
+				roff_node_delete(mdoc, n);
+		} else if (n->child == NULL)
 			mandoc_msg(MANDOCERR_BLK_EMPTY, mdoc->parse,
 			    n->line, n->pos, mdoc_macronames[n->tok]);
 		else if (n->tok == MDOC_D1)
 			post_hyph(mdoc);
 		break;
 	case ROFFT_BLOCK:
 		if (n->tok == MDOC_Bd) {
 			if (n->args == NULL) {
 				mandoc_msg(MANDOCERR_BD_NOARG,
 				    mdoc->parse, n->line, n->pos, "Bd");
 				mdoc->next = ROFF_NEXT_SIBLING;
 				while (n->body->child != NULL)
 					mdoc_node_relink(mdoc,
 					    n->body->child);
 				roff_node_delete(mdoc, n);
 				break;
 			}
 			post_bd(mdoc);
 			post_prevpar(mdoc);
 		}
 		for (np = n->parent; np != NULL; np = np->parent) {
 			if (np->type == ROFFT_BLOCK && np->tok == MDOC_Bd) {
 				mandoc_vmsg(MANDOCERR_BD_NEST,
 				    mdoc->parse, n->line, n->pos,
 				    "%s in Bd", mdoc_macronames[n->tok]);
 				break;
 			}
 		}
 		break;
 	default:
 		break;
 	}
 }
 
 static void
 post_defaults(POST_ARGS)
 {
 	struct roff_node *nn;
 
 	/*
 	 * The `Ar' defaults to "file ..." if no value is provided as an
 	 * argument; the `Mt' and `Pa' macros use "~"; the `Li' just
 	 * gets an empty string.
 	 */
 
 	if (mdoc->last->child != NULL)
 		return;
 
 	nn = mdoc->last;
 
 	switch (nn->tok) {
 	case MDOC_Ar:
 		mdoc->next = ROFF_NEXT_CHILD;
 		roff_word_alloc(mdoc, nn->line, nn->pos, "file");
+		mdoc->last->flags |= NODE_NOSRC;
 		roff_word_alloc(mdoc, nn->line, nn->pos, "...");
+		mdoc->last->flags |= NODE_NOSRC;
 		break;
 	case MDOC_Pa:
 	case MDOC_Mt:
 		mdoc->next = ROFF_NEXT_CHILD;
 		roff_word_alloc(mdoc, nn->line, nn->pos, "~");
+		mdoc->last->flags |= NODE_NOSRC;
 		break;
 	default:
 		abort();
 	}
 	mdoc->last = nn;
 }
 
 static void
 post_at(POST_ARGS)
 {
-	struct roff_node	*n;
-	const char		*std_att;
-	char			*att;
+	struct roff_node	*n, *nch;
+	const char		*att;
 
 	n = mdoc->last;
-	if (n->child == NULL) {
-		mdoc->next = ROFF_NEXT_CHILD;
-		roff_word_alloc(mdoc, n->line, n->pos, "AT&T UNIX");
-		mdoc->last = n;
-		return;
-	}
+	nch = n->child;
 
 	/*
 	 * If we have a child, look it up in the standard keys.  If a
 	 * key exist, use that instead of the child; if it doesn't,
 	 * prefix "AT&T UNIX " to the existing data.
 	 */
 
-	n = n->child;
-	assert(n->type == ROFFT_TEXT);
-	if ((std_att = mdoc_a2att(n->string)) == NULL) {
+	att = NULL;
+	if (nch != NULL && ((att = mdoc_a2att(nch->string)) == NULL))
 		mandoc_vmsg(MANDOCERR_AT_BAD, mdoc->parse,
-		    n->line, n->pos, "At %s", n->string);
-		mandoc_asprintf(&att, "AT&T UNIX %s", n->string);
-	} else
-		att = mandoc_strdup(std_att);
+		    nch->line, nch->pos, "At %s", nch->string);
 
-	free(n->string);
-	n->string = att;
+	mdoc->next = ROFF_NEXT_CHILD;
+	if (att != NULL) {
+		roff_word_alloc(mdoc, nch->line, nch->pos, att);
+		nch->flags |= NODE_NOPRT;
+	} else
+		roff_word_alloc(mdoc, n->line, n->pos, "AT&T UNIX");
+	mdoc->last->flags |= NODE_NOSRC;
+	mdoc->last = n;
 }
 
 static void
 post_an(POST_ARGS)
 {
 	struct roff_node *np, *nch;
 
 	post_an_norm(mdoc);
 
 	np = mdoc->last;
 	nch = np->child;
 	if (np->norm->An.auth == AUTH__NONE) {
 		if (nch == NULL)
 			mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse,
 			    np->line, np->pos, "An");
 	} else if (nch != NULL)
 		mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse,
 		    nch->line, nch->pos, "An ... %s", nch->string);
 }
 
 static void
 post_en(POST_ARGS)
 {
 
 	post_obsolete(mdoc);
 	if (mdoc->last->type == ROFFT_BLOCK)
 		mdoc->last->norm->Es = mdoc->last_es;
 }
 
 static void
 post_es(POST_ARGS)
 {
 
 	post_obsolete(mdoc);
 	mdoc->last_es = mdoc->last;
 }
 
 static void
+post_xx(POST_ARGS)
+{
+	struct roff_node	*n;
+	const char		*os;
+
+	n = mdoc->last;
+	switch (n->tok) {
+	case MDOC_Bsx:
+		os = "BSD/OS";
+		break;
+	case MDOC_Dx:
+		os = "DragonFly";
+		break;
+	case MDOC_Fx:
+		os = "FreeBSD";
+		break;
+	case MDOC_Nx:
+		os = "NetBSD";
+		break;
+	case MDOC_Ox:
+		os = "OpenBSD";
+		break;
+	case MDOC_Ux:
+		os = "UNIX";
+		break;
+	default:
+		abort();
+	}
+	mdoc->next = ROFF_NEXT_CHILD;
+	roff_word_alloc(mdoc, n->line, n->pos, os);
+	mdoc->last->flags |= NODE_NOSRC;
+	mdoc->last = n;
+}
+
+static void
 post_it(POST_ARGS)
 {
 	struct roff_node *nbl, *nit, *nch;
 	int		  i, cols;
 	enum mdoc_list	  lt;
 
 	post_prevpar(mdoc);
 
 	nit = mdoc->last;
 	if (nit->type != ROFFT_BLOCK)
 		return;
 
 	nbl = nit->parent->parent;
 	lt = nbl->norm->Bl.type;
 
 	switch (lt) {
 	case LIST_tag:
 	case LIST_hang:
 	case LIST_ohang:
 	case LIST_inset:
 	case LIST_diag:
 		if (nit->head->child == NULL)
 			mandoc_vmsg(MANDOCERR_IT_NOHEAD,
 			    mdoc->parse, nit->line, nit->pos,
 			    "Bl -%s It",
 			    mdoc_argnames[nbl->args->argv[0].arg]);
 		break;
 	case LIST_bullet:
 	case LIST_dash:
 	case LIST_enum:
 	case LIST_hyphen:
 		if (nit->body == NULL || nit->body->child == NULL)
 			mandoc_vmsg(MANDOCERR_IT_NOBODY,
 			    mdoc->parse, nit->line, nit->pos,
 			    "Bl -%s It",
 			    mdoc_argnames[nbl->args->argv[0].arg]);
 		/* FALLTHROUGH */
 	case LIST_item:
-		if (nit->head->child != NULL)
+		if ((nch = nit->head->child) != NULL)
 			mandoc_vmsg(MANDOCERR_ARG_SKIP,
 			    mdoc->parse, nit->line, nit->pos,
-			    "It %s", nit->head->child->string);
+			    "It %s", nch->string == NULL ?
+			    mdoc_macronames[nch->tok] : nch->string);
 		break;
 	case LIST_column:
 		cols = (int)nbl->norm->Bl.ncols;
 
 		assert(nit->head->child == NULL);
 
 		i = 0;
 		for (nch = nit->child; nch != NULL; nch = nch->next)
 			if (nch->type == ROFFT_BODY)
 				i++;
 
 		if (i < cols || i > cols + 1)
 			mandoc_vmsg(MANDOCERR_BL_COL,
 			    mdoc->parse, nit->line, nit->pos,
 			    "%d columns, %d cells", cols, i);
 		break;
 	default:
 		abort();
 	}
 }
 
 static void
 post_bl_block(POST_ARGS)
 {
 	struct roff_node *n, *ni, *nc;
 
 	post_prevpar(mdoc);
 
-	/*
-	 * These are fairly complicated, so we've broken them into two
-	 * functions.  post_bl_block_tag() is called when a -tag is
-	 * specified, but no -width (it must be guessed).  The second
-	 * when a -width is specified (macro indicators must be
-	 * rewritten into real lengths).
-	 */
-
 	n = mdoc->last;
-
-	if (n->norm->Bl.type == LIST_tag &&
-	    n->norm->Bl.width == NULL) {
-		post_bl_block_tag(mdoc);
-		assert(n->norm->Bl.width != NULL);
-	}
-
 	for (ni = n->body->child; ni != NULL; ni = ni->next) {
 		if (ni->body == NULL)
 			continue;
 		nc = ni->body->last;
 		while (nc != NULL) {
 			switch (nc->tok) {
 			case MDOC_Pp:
 			case MDOC_Lp:
 			case MDOC_br:
 				break;
 			default:
 				nc = NULL;
 				continue;
 			}
 			if (ni->next == NULL) {
 				mandoc_msg(MANDOCERR_PAR_MOVE,
 				    mdoc->parse, nc->line, nc->pos,
 				    mdoc_macronames[nc->tok]);
 				mdoc_node_relink(mdoc, nc);
 			} else if (n->norm->Bl.comp == 0 &&
 			    n->norm->Bl.type != LIST_column) {
 				mandoc_vmsg(MANDOCERR_PAR_SKIP,
 				    mdoc->parse, nc->line, nc->pos,
 				    "%s before It",
 				    mdoc_macronames[nc->tok]);
 				roff_node_delete(mdoc, nc);
 			} else
 				break;
 			nc = ni->body->last;
 		}
 	}
 }
 
 /*
  * If the argument of -offset or -width is a macro,
  * replace it with the associated default width.
  */
 void
 rewrite_macro2len(char **arg)
 {
 	size_t		  width;
 	int		  tok;
 
 	if (*arg == NULL)
 		return;
 	else if ( ! strcmp(*arg, "Ds"))
 		width = 6;
 	else if ((tok = mdoc_hash_find(*arg)) == TOKEN_NONE)
 		return;
 	else
 		width = macro2len(tok);
 
 	free(*arg);
 	mandoc_asprintf(arg, "%zun", width);
 }
 
 static void
-post_bl_block_tag(POST_ARGS)
-{
-	struct roff_node *n, *nn;
-	size_t		  sz, ssz;
-	int		  i;
-	char		  buf[24];
-
-	/*
-	 * Calculate the -width for a `Bl -tag' list if it hasn't been
-	 * provided.  Uses the first head macro.  NOTE AGAIN: this is
-	 * ONLY if the -width argument has NOT been provided.  See
-	 * rewrite_macro2len() for converting the -width string.
-	 */
-
-	sz = 10;
-	n = mdoc->last;
-
-	for (nn = n->body->child; nn != NULL; nn = nn->next) {
-		if (nn->tok != MDOC_It)
-			continue;
-
-		assert(nn->type == ROFFT_BLOCK);
-		nn = nn->head->child;
-
-		if (nn == NULL)
-			break;
-
-		if (nn->type == ROFFT_TEXT) {
-			sz = strlen(nn->string) + 1;
-			break;
-		}
-
-		if (0 != (ssz = macro2len(nn->tok)))
-			sz = ssz;
-
-		break;
-	}
-
-	/* Defaults to ten ens. */
-
-	(void)snprintf(buf, sizeof(buf), "%un", (unsigned int)sz);
-
-	/*
-	 * We have to dynamically add this to the macro's argument list.
-	 * We're guaranteed that a MDOC_Width doesn't already exist.
-	 */
-
-	assert(n->args != NULL);
-	i = (int)(n->args->argc)++;
-
-	n->args->argv = mandoc_reallocarray(n->args->argv,
-	    n->args->argc, sizeof(struct mdoc_argv));
-
-	n->args->argv[i].arg = MDOC_Width;
-	n->args->argv[i].line = n->line;
-	n->args->argv[i].pos = n->pos;
-	n->args->argv[i].sz = 1;
-	n->args->argv[i].value = mandoc_malloc(sizeof(char *));
-	n->args->argv[i].value[0] = mandoc_strdup(buf);
-
-	/* Set our width! */
-	n->norm->Bl.width = n->args->argv[i].value[0];
-}
-
-static void
 post_bl_head(POST_ARGS)
 {
 	struct roff_node *nbl, *nh, *nch, *nnext;
 	struct mdoc_argv *argv;
 	int		  i, j;
 
 	post_bl_norm(mdoc);
 
 	nh = mdoc->last;
 	if (nh->norm->Bl.type != LIST_column) {
 		if ((nch = nh->child) == NULL)
 			return;
 		mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse,
 		    nch->line, nch->pos, "Bl ... %s", nch->string);
 		while (nch != NULL) {
 			roff_node_delete(mdoc, nch);
 			nch = nh->child;
 		}
 		return;
 	}
 
 	/*
 	 * Append old-style lists, where the column width specifiers
 	 * trail as macro parameters, to the new-style ("normal-form")
 	 * lists where they're argument values following -column.
 	 */
 
 	if (nh->child == NULL)
 		return;
 
 	nbl = nh->parent;
 	for (j = 0; j < (int)nbl->args->argc; j++)
 		if (nbl->args->argv[j].arg == MDOC_Column)
 			break;
 
 	assert(j < (int)nbl->args->argc);
 
 	/*
 	 * Accommodate for new-style groff column syntax.  Shuffle the
 	 * child nodes, all of which must be TEXT, as arguments for the
 	 * column field.  Then, delete the head children.
 	 */
 
 	argv = nbl->args->argv + j;
 	i = argv->sz;
 	for (nch = nh->child; nch != NULL; nch = nch->next)
 		argv->sz++;
 	argv->value = mandoc_reallocarray(argv->value,
 	    argv->sz, sizeof(char *));
 
 	nh->norm->Bl.ncols = argv->sz;
 	nh->norm->Bl.cols = (void *)argv->value;
 
 	for (nch = nh->child; nch != NULL; nch = nnext) {
 		argv->value[i++] = nch->string;
 		nch->string = NULL;
 		nnext = nch->next;
 		roff_node_delete(NULL, nch);
 	}
 	nh->child = NULL;
 }
 
 static void
 post_bl(POST_ARGS)
 {
 	struct roff_node	*nparent, *nprev; /* of the Bl block */
 	struct roff_node	*nblock, *nbody;  /* of the Bl */
 	struct roff_node	*nchild, *nnext;  /* of the Bl body */
 
 	nbody = mdoc->last;
 	switch (nbody->type) {
 	case ROFFT_BLOCK:
 		post_bl_block(mdoc);
 		return;
 	case ROFFT_HEAD:
 		post_bl_head(mdoc);
 		return;
 	case ROFFT_BODY:
 		break;
 	default:
 		return;
 	}
 	if (nbody->end != ENDBODY_NOT)
 		return;
 
 	nchild = nbody->child;
 	if (nchild == NULL) {
 		mandoc_msg(MANDOCERR_BLK_EMPTY, mdoc->parse,
 		    nbody->line, nbody->pos, "Bl");
 		return;
 	}
 	while (nchild != NULL) {
+		nnext = nchild->next;
 		if (nchild->tok == MDOC_It ||
 		    (nchild->tok == MDOC_Sm &&
-		     nchild->next != NULL &&
-		     nchild->next->tok == MDOC_It)) {
-			nchild = nchild->next;
+		     nnext != NULL && nnext->tok == MDOC_It)) {
+			nchild = nnext;
 			continue;
 		}
 
+		/*
+		 * In .Bl -column, the first rows may be implicit,
+		 * that is, they may not start with .It macros.
+		 * Such rows may be followed by nodes generated on the
+		 * roff level, for example .TS, which cannot be moved
+		 * out of the list.  In that case, wrap such roff nodes
+		 * into an implicit row.
+		 */
+
+		if (nchild->prev != NULL) {
+			mdoc->last = nchild;
+			mdoc->next = ROFF_NEXT_SIBLING;
+			roff_block_alloc(mdoc, nchild->line,
+			    nchild->pos, MDOC_It);
+			roff_head_alloc(mdoc, nchild->line,
+			    nchild->pos, MDOC_It);
+			mdoc->next = ROFF_NEXT_SIBLING;
+			roff_body_alloc(mdoc, nchild->line,
+			    nchild->pos, MDOC_It);
+			while (nchild->tok != MDOC_It) {
+				mdoc_node_relink(mdoc, nchild);
+				if ((nchild = nnext) == NULL)
+					break;
+				nnext = nchild->next;
+				mdoc->next = ROFF_NEXT_SIBLING;
+			}
+			mdoc->last = nbody;
+			continue;
+		}
+
 		mandoc_msg(MANDOCERR_BL_MOVE, mdoc->parse,
 		    nchild->line, nchild->pos,
 		    mdoc_macronames[nchild->tok]);
 
 		/*
 		 * Move the node out of the Bl block.
 		 * First, collect all required node pointers.
 		 */
 
 		nblock  = nbody->parent;
 		nprev   = nblock->prev;
 		nparent = nblock->parent;
-		nnext   = nchild->next;
 
 		/*
 		 * Unlink this child.
 		 */
 
-		assert(nchild->prev == NULL);
 		nbody->child = nnext;
 		if (nnext == NULL)
 			nbody->last  = NULL;
 		else
 			nnext->prev = NULL;
 
 		/*
 		 * Relink this child.
 		 */
 
 		nchild->parent = nparent;
 		nchild->prev   = nprev;
 		nchild->next   = nblock;
 
 		nblock->prev = nchild;
 		if (nprev == NULL)
 			nparent->child = nchild;
 		else
 			nprev->next = nchild;
 
 		nchild = nnext;
 	}
 }
 
 static void
 post_bk(POST_ARGS)
 {
 	struct roff_node	*n;
 
 	n = mdoc->last;
 
 	if (n->type == ROFFT_BLOCK && n->body->child == NULL) {
 		mandoc_msg(MANDOCERR_BLK_EMPTY,
 		    mdoc->parse, n->line, n->pos, "Bk");
 		roff_node_delete(mdoc, n);
 	}
 }
 
 static void
 post_sm(POST_ARGS)
 {
 	struct roff_node	*nch;
 
 	nch = mdoc->last->child;
 
 	if (nch == NULL) {
 		mdoc->flags ^= MDOC_SMOFF;
 		return;
 	}
 
 	assert(nch->type == ROFFT_TEXT);
 
 	if ( ! strcmp(nch->string, "on")) {
 		mdoc->flags &= ~MDOC_SMOFF;
 		return;
 	}
 	if ( ! strcmp(nch->string, "off")) {
 		mdoc->flags |= MDOC_SMOFF;
 		return;
 	}
 
 	mandoc_vmsg(MANDOCERR_SM_BAD,
 	    mdoc->parse, nch->line, nch->pos,
 	    "%s %s", mdoc_macronames[mdoc->last->tok], nch->string);
 	mdoc_node_relink(mdoc, nch);
 	return;
 }
 
 static void
 post_root(POST_ARGS)
 {
 	struct roff_node *n;
 
 	/* Add missing prologue data. */
 
 	if (mdoc->meta.date == NULL)
 		mdoc->meta.date = mdoc->quick ?
 		    mandoc_strdup("") :
 		    mandoc_normdate(mdoc->parse, NULL, 0, 0);
 
 	if (mdoc->meta.title == NULL) {
 		mandoc_msg(MANDOCERR_DT_NOTITLE,
 		    mdoc->parse, 0, 0, "EOF");
 		mdoc->meta.title = mandoc_strdup("UNTITLED");
 	}
 
 	if (mdoc->meta.vol == NULL)
 		mdoc->meta.vol = mandoc_strdup("LOCAL");
 
 	if (mdoc->meta.os == NULL) {
 		mandoc_msg(MANDOCERR_OS_MISSING,
 		    mdoc->parse, 0, 0, NULL);
 		mdoc->meta.os = mandoc_strdup("");
 	}
 
 	/* Check that we begin with a proper `Sh'. */
 
 	n = mdoc->first->child;
 	while (n != NULL && n->tok != TOKEN_NONE &&
 	    mdoc_macros[n->tok].flags & MDOC_PROLOGUE)
 		n = n->next;
 
 	if (n == NULL)
 		mandoc_msg(MANDOCERR_DOC_EMPTY, mdoc->parse, 0, 0, NULL);
 	else if (n->tok != MDOC_Sh)
 		mandoc_msg(MANDOCERR_SEC_BEFORE, mdoc->parse,
 		    n->line, n->pos, mdoc_macronames[n->tok]);
 }
 
 static void
-post_st(POST_ARGS)
-{
-	struct roff_node	 *n, *nch;
-	const char		 *p;
-
-	n = mdoc->last;
-	nch = n->child;
-
-	assert(nch->type == ROFFT_TEXT);
-
-	if ((p = mdoc_a2st(nch->string)) == NULL) {
-		mandoc_vmsg(MANDOCERR_ST_BAD, mdoc->parse,
-		    nch->line, nch->pos, "St %s", nch->string);
-		roff_node_delete(mdoc, n);
-	} else {
-		free(nch->string);
-		nch->string = mandoc_strdup(p);
-	}
-}
-
-static void
 post_rs(POST_ARGS)
 {
 	struct roff_node *np, *nch, *next, *prev;
 	int		  i, j;
 
 	np = mdoc->last;
 
 	if (np->type != ROFFT_BODY)
 		return;
 
 	if (np->child == NULL) {
 		mandoc_msg(MANDOCERR_RS_EMPTY, mdoc->parse,
 		    np->line, np->pos, "Rs");
 		return;
 	}
 
 	/*
 	 * The full `Rs' block needs special handling to order the
 	 * sub-elements according to `rsord'.  Pick through each element
 	 * and correctly order it.  This is an insertion sort.
 	 */
 
 	next = NULL;
 	for (nch = np->child->next; nch != NULL; nch = next) {
 		/* Determine order number of this child. */
 		for (i = 0; i < RSORD_MAX; i++)
 			if (rsord[i] == nch->tok)
 				break;
 
 		if (i == RSORD_MAX) {
 			mandoc_msg(MANDOCERR_RS_BAD,
 			    mdoc->parse, nch->line, nch->pos,
 			    mdoc_macronames[nch->tok]);
 			i = -1;
 		} else if (nch->tok == MDOC__J || nch->tok == MDOC__B)
 			np->norm->Rs.quote_T++;
 
 		/*
 		 * Remove this child from the chain.  This somewhat
 		 * repeats roff_node_unlink(), but since we're
 		 * just re-ordering, there's no need for the
 		 * full unlink process.
 		 */
 
 		if ((next = nch->next) != NULL)
 			next->prev = nch->prev;
 
 		if ((prev = nch->prev) != NULL)
 			prev->next = nch->next;
 
 		nch->prev = nch->next = NULL;
 
 		/*
 		 * Scan back until we reach a node that's
 		 * to be ordered before this child.
 		 */
 
 		for ( ; prev ; prev = prev->prev) {
 			/* Determine order of `prev'. */
 			for (j = 0; j < RSORD_MAX; j++)
 				if (rsord[j] == prev->tok)
 					break;
 			if (j == RSORD_MAX)
 				j = -1;
 
 			if (j <= i)
 				break;
 		}
 
 		/*
 		 * Set this child back into its correct place
 		 * in front of the `prev' node.
 		 */
 
 		nch->prev = prev;
 
 		if (prev == NULL) {
 			np->child->prev = nch;
 			nch->next = np->child;
 			np->child = nch;
 		} else {
 			if (prev->next)
 				prev->next->prev = nch;
 			nch->next = prev->next;
 			prev->next = nch;
 		}
 	}
 }
 
 /*
  * For some arguments of some macros,
  * convert all breakable hyphens into ASCII_HYPH.
  */
 static void
 post_hyph(POST_ARGS)
 {
 	struct roff_node	*nch;
 	char			*cp;
 
 	for (nch = mdoc->last->child; nch != NULL; nch = nch->next) {
 		if (nch->type != ROFFT_TEXT)
 			continue;
 		cp = nch->string;
 		if (*cp == '\0')
 			continue;
 		while (*(++cp) != '\0')
 			if (*cp == '-' &&
 			    isalpha((unsigned char)cp[-1]) &&
 			    isalpha((unsigned char)cp[1]))
 				*cp = ASCII_HYPH;
 	}
 }
 
 static void
 post_ns(POST_ARGS)
 {
 
-	if (mdoc->last->flags & MDOC_LINE)
+	if (mdoc->last->flags & NODE_LINE)
 		mandoc_msg(MANDOCERR_NS_SKIP, mdoc->parse,
 		    mdoc->last->line, mdoc->last->pos, NULL);
 }
 
 static void
 post_sh(POST_ARGS)
 {
 
 	post_ignpar(mdoc);
 
 	switch (mdoc->last->type) {
 	case ROFFT_HEAD:
 		post_sh_head(mdoc);
 		break;
 	case ROFFT_BODY:
 		switch (mdoc->lastsec)  {
 		case SEC_NAME:
 			post_sh_name(mdoc);
 			break;
 		case SEC_SEE_ALSO:
 			post_sh_see_also(mdoc);
 			break;
 		case SEC_AUTHORS:
 			post_sh_authors(mdoc);
 			break;
 		default:
 			break;
 		}
 		break;
 	default:
 		break;
 	}
 }
 
 static void
 post_sh_name(POST_ARGS)
 {
 	struct roff_node *n;
 	int hasnm, hasnd;
 
 	hasnm = hasnd = 0;
 
 	for (n = mdoc->last->child; n != NULL; n = n->next) {
 		switch (n->tok) {
 		case MDOC_Nm:
+			if (hasnm && n->child != NULL)
+				mandoc_vmsg(MANDOCERR_NAMESEC_PUNCT,
+				    mdoc->parse, n->line, n->pos,
+				    "Nm %s", n->child->string);
 			hasnm = 1;
-			break;
+			continue;
 		case MDOC_Nd:
 			hasnd = 1;
 			if (n->next != NULL)
 				mandoc_msg(MANDOCERR_NAMESEC_ND,
 				    mdoc->parse, n->line, n->pos, NULL);
 			break;
 		case TOKEN_NONE:
-			if (hasnm)
-				break;
+			if (n->type == ROFFT_TEXT &&
+			    n->string[0] == ',' && n->string[1] == '\0' &&
+			    n->next != NULL && n->next->tok == MDOC_Nm) {
+				n = n->next;
+				continue;
+			}
 			/* FALLTHROUGH */
 		default:
 			mandoc_msg(MANDOCERR_NAMESEC_BAD, mdoc->parse,
 			    n->line, n->pos, mdoc_macronames[n->tok]);
-			break;
+			continue;
 		}
+		break;
 	}
 
 	if ( ! hasnm)
 		mandoc_msg(MANDOCERR_NAMESEC_NONM, mdoc->parse,
 		    mdoc->last->line, mdoc->last->pos, NULL);
 	if ( ! hasnd)
 		mandoc_msg(MANDOCERR_NAMESEC_NOND, mdoc->parse,
 		    mdoc->last->line, mdoc->last->pos, NULL);
 }
 
 static void
 post_sh_see_also(POST_ARGS)
 {
 	const struct roff_node	*n;
 	const char		*name, *sec;
 	const char		*lastname, *lastsec, *lastpunct;
 	int			 cmp;
 
 	n = mdoc->last->child;
 	lastname = lastsec = lastpunct = NULL;
 	while (n != NULL) {
 		if (n->tok != MDOC_Xr ||
 		    n->child == NULL ||
 		    n->child->next == NULL)
 			break;
 
 		/* Process one .Xr node. */
 
 		name = n->child->string;
 		sec = n->child->next->string;
 		if (lastsec != NULL) {
 			if (lastpunct[0] != ',' || lastpunct[1] != '\0')
 				mandoc_vmsg(MANDOCERR_XR_PUNCT,
 				    mdoc->parse, n->line, n->pos,
 				    "%s before %s(%s)", lastpunct,
 				    name, sec);
 			cmp = strcmp(lastsec, sec);
 			if (cmp > 0)
 				mandoc_vmsg(MANDOCERR_XR_ORDER,
 				    mdoc->parse, n->line, n->pos,
 				    "%s(%s) after %s(%s)", name,
 				    sec, lastname, lastsec);
 			else if (cmp == 0 &&
 			    strcasecmp(lastname, name) > 0)
 				mandoc_vmsg(MANDOCERR_XR_ORDER,
 				    mdoc->parse, n->line, n->pos,
 				    "%s after %s", name, lastname);
 		}
 		lastname = name;
 		lastsec = sec;
 
 		/* Process the following node. */
 
 		n = n->next;
 		if (n == NULL)
 			break;
 		if (n->tok == MDOC_Xr) {
 			lastpunct = "none";
 			continue;
 		}
 		if (n->type != ROFFT_TEXT)
 			break;
 		for (name = n->string; *name != '\0'; name++)
 			if (isalpha((const unsigned char)*name))
 				return;
 		lastpunct = n->string;
 		if (n->next == NULL)
 			mandoc_vmsg(MANDOCERR_XR_PUNCT, mdoc->parse,
 			    n->line, n->pos, "%s after %s(%s)",
 			    lastpunct, lastname, lastsec);
 		n = n->next;
 	}
 }
 
 static int
 child_an(const struct roff_node *n)
 {
 
 	for (n = n->child; n != NULL; n = n->next)
 		if ((n->tok == MDOC_An && n->child != NULL) || child_an(n))
 			return 1;
 	return 0;
 }
 
 static void
 post_sh_authors(POST_ARGS)
 {
 
 	if ( ! child_an(mdoc->last))
 		mandoc_msg(MANDOCERR_AN_MISSING, mdoc->parse,
 		    mdoc->last->line, mdoc->last->pos, NULL);
 }
 
 static void
 post_sh_head(POST_ARGS)
 {
-	const char	*goodsec;
-	enum roff_sec	 sec;
+	struct roff_node	*nch;
+	const char		*goodsec;
+	enum roff_sec		 sec;
 
 	/*
 	 * Process a new section.  Sections are either "named" or
 	 * "custom".  Custom sections are user-defined, while named ones
 	 * follow a conventional order and may only appear in certain
 	 * manual sections.
 	 */
 
 	sec = mdoc->last->sec;
 
 	/* The NAME should be first. */
 
-	if (SEC_NAME != sec && SEC_NONE == mdoc->lastnamed)
+	if (sec != SEC_NAME && mdoc->lastnamed == SEC_NONE)
 		mandoc_vmsg(MANDOCERR_NAMESEC_FIRST, mdoc->parse,
-		    mdoc->last->line, mdoc->last->pos,
-		    "Sh %s", secnames[sec]);
+		    mdoc->last->line, mdoc->last->pos, "Sh %s",
+		    sec != SEC_CUSTOM ? secnames[sec] :
+		    (nch = mdoc->last->child) == NULL ? "" :
+		    nch->type == ROFFT_TEXT ? nch->string :
+		    mdoc_macronames[nch->tok]);
 
 	/* The SYNOPSIS gets special attention in other areas. */
 
 	if (sec == SEC_SYNOPSIS) {
 		roff_setreg(mdoc->roff, "nS", 1, '=');
 		mdoc->flags |= MDOC_SYNOPSIS;
 	} else {
 		roff_setreg(mdoc->roff, "nS", 0, '=');
 		mdoc->flags &= ~MDOC_SYNOPSIS;
 	}
 
 	/* Mark our last section. */
 
 	mdoc->lastsec = sec;
 
 	/* We don't care about custom sections after this. */
 
 	if (sec == SEC_CUSTOM)
 		return;
 
 	/*
 	 * Check whether our non-custom section is being repeated or is
 	 * out of order.
 	 */
 
 	if (sec == mdoc->lastnamed)
 		mandoc_vmsg(MANDOCERR_SEC_REP, mdoc->parse,
 		    mdoc->last->line, mdoc->last->pos,
 		    "Sh %s", secnames[sec]);
 
 	if (sec < mdoc->lastnamed)
 		mandoc_vmsg(MANDOCERR_SEC_ORDER, mdoc->parse,
 		    mdoc->last->line, mdoc->last->pos,
 		    "Sh %s", secnames[sec]);
 
 	/* Mark the last named section. */
 
 	mdoc->lastnamed = sec;
 
 	/* Check particular section/manual conventions. */
 
 	if (mdoc->meta.msec == NULL)
 		return;
 
 	goodsec = NULL;
 	switch (sec) {
 	case SEC_ERRORS:
 		if (*mdoc->meta.msec == '4')
 			break;
 		goodsec = "2, 3, 4, 9";
 		/* FALLTHROUGH */
 	case SEC_RETURN_VALUES:
 	case SEC_LIBRARY:
 		if (*mdoc->meta.msec == '2')
 			break;
 		if (*mdoc->meta.msec == '3')
 			break;
 		if (NULL == goodsec)
 			goodsec = "2, 3, 9";
 		/* FALLTHROUGH */
 	case SEC_CONTEXT:
 		if (*mdoc->meta.msec == '9')
 			break;
 		if (NULL == goodsec)
 			goodsec = "9";
 		mandoc_vmsg(MANDOCERR_SEC_MSEC, mdoc->parse,
 		    mdoc->last->line, mdoc->last->pos,
 		    "Sh %s for %s only", secnames[sec], goodsec);
 		break;
 	default:
 		break;
 	}
 }
 
 static void
+post_xr(POST_ARGS)
+{
+	struct roff_node *n, *nch;
+
+	n = mdoc->last;
+	nch = n->child;
+	if (nch->next == NULL) {
+		mandoc_vmsg(MANDOCERR_XR_NOSEC, mdoc->parse,
+		    n->line, n->pos, "Xr %s", nch->string);
+		return;
+	}
+	assert(nch->next == n->last);
+}
+
+static void
 post_ignpar(POST_ARGS)
 {
 	struct roff_node *np;
 
 	switch (mdoc->last->type) {
 	case ROFFT_HEAD:
 		post_hyph(mdoc);
 		return;
 	case ROFFT_BODY:
 		break;
 	default:
 		return;
 	}
 
 	if ((np = mdoc->last->child) != NULL)
 		if (np->tok == MDOC_Pp || np->tok == MDOC_Lp) {
 			mandoc_vmsg(MANDOCERR_PAR_SKIP,
 			    mdoc->parse, np->line, np->pos,
 			    "%s after %s", mdoc_macronames[np->tok],
 			    mdoc_macronames[mdoc->last->tok]);
 			roff_node_delete(mdoc, np);
 		}
 
 	if ((np = mdoc->last->last) != NULL)
 		if (np->tok == MDOC_Pp || np->tok == MDOC_Lp) {
 			mandoc_vmsg(MANDOCERR_PAR_SKIP, mdoc->parse,
 			    np->line, np->pos, "%s at the end of %s",
 			    mdoc_macronames[np->tok],
 			    mdoc_macronames[mdoc->last->tok]);
 			roff_node_delete(mdoc, np);
 		}
 }
 
 static void
 post_prevpar(POST_ARGS)
 {
 	struct roff_node *n;
 
 	n = mdoc->last;
 	if (NULL == n->prev)
 		return;
 	if (n->type != ROFFT_ELEM && n->type != ROFFT_BLOCK)
 		return;
 
 	/*
 	 * Don't allow prior `Lp' or `Pp' prior to a paragraph-type
 	 * block:  `Lp', `Pp', or non-compact `Bd' or `Bl'.
 	 */
 
 	if (n->prev->tok != MDOC_Pp &&
 	    n->prev->tok != MDOC_Lp &&
 	    n->prev->tok != MDOC_br)
 		return;
 	if (n->tok == MDOC_Bl && n->norm->Bl.comp)
 		return;
 	if (n->tok == MDOC_Bd && n->norm->Bd.comp)
 		return;
 	if (n->tok == MDOC_It && n->parent->norm->Bl.comp)
 		return;
 
 	mandoc_vmsg(MANDOCERR_PAR_SKIP, mdoc->parse,
 	    n->prev->line, n->prev->pos,
 	    "%s before %s", mdoc_macronames[n->prev->tok],
 	    mdoc_macronames[n->tok]);
 	roff_node_delete(mdoc, n->prev);
 }
 
 static void
 post_par(POST_ARGS)
 {
 	struct roff_node *np;
 
 	np = mdoc->last;
 	if (np->tok != MDOC_br && np->tok != MDOC_sp)
 		post_prevpar(mdoc);
 
 	if (np->tok == MDOC_sp) {
 		if (np->child != NULL && np->child->next != NULL)
 			mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse,
 			    np->child->next->line, np->child->next->pos,
 			    "sp ... %s", np->child->next->string);
 	} else if (np->child != NULL)
 		mandoc_vmsg(MANDOCERR_ARG_SKIP,
 		    mdoc->parse, np->line, np->pos, "%s %s",
 		    mdoc_macronames[np->tok], np->child->string);
 
 	if ((np = mdoc->last->prev) == NULL) {
 		np = mdoc->last->parent;
 		if (np->tok != MDOC_Sh && np->tok != MDOC_Ss)
 			return;
 	} else if (np->tok != MDOC_Pp && np->tok != MDOC_Lp &&
 	    (mdoc->last->tok != MDOC_br ||
 	     (np->tok != MDOC_sp && np->tok != MDOC_br)))
 		return;
 
 	mandoc_vmsg(MANDOCERR_PAR_SKIP, mdoc->parse,
 	    mdoc->last->line, mdoc->last->pos,
 	    "%s after %s", mdoc_macronames[mdoc->last->tok],
 	    mdoc_macronames[np->tok]);
 	roff_node_delete(mdoc, mdoc->last);
 }
 
 static void
 post_dd(POST_ARGS)
 {
 	struct roff_node *n;
 	char		 *datestr;
 
 	n = mdoc->last;
+	n->flags |= NODE_NOPRT;
+
 	if (mdoc->meta.date != NULL) {
 		mandoc_msg(MANDOCERR_PROLOG_REP, mdoc->parse,
 		    n->line, n->pos, "Dd");
 		free(mdoc->meta.date);
 	} else if (mdoc->flags & MDOC_PBODY)
 		mandoc_msg(MANDOCERR_PROLOG_LATE, mdoc->parse,
 		    n->line, n->pos, "Dd");
 	else if (mdoc->meta.title != NULL)
 		mandoc_msg(MANDOCERR_PROLOG_ORDER, mdoc->parse,
 		    n->line, n->pos, "Dd after Dt");
 	else if (mdoc->meta.os != NULL)
 		mandoc_msg(MANDOCERR_PROLOG_ORDER, mdoc->parse,
 		    n->line, n->pos, "Dd after Os");
 
 	if (n->child == NULL || n->child->string[0] == '\0') {
 		mdoc->meta.date = mdoc->quick ? mandoc_strdup("") :
 		    mandoc_normdate(mdoc->parse, NULL, n->line, n->pos);
-		goto out;
+		return;
 	}
 
 	datestr = NULL;
 	deroff(&datestr, n);
 	if (mdoc->quick)
 		mdoc->meta.date = datestr;
 	else {
 		mdoc->meta.date = mandoc_normdate(mdoc->parse,
 		    datestr, n->line, n->pos);
 		free(datestr);
 	}
-out:
-	roff_node_delete(mdoc, n);
 }
 
 static void
 post_dt(POST_ARGS)
 {
 	struct roff_node *nn, *n;
 	const char	 *cp;
 	char		 *p;
 
 	n = mdoc->last;
+	n->flags |= NODE_NOPRT;
+
 	if (mdoc->flags & MDOC_PBODY) {
 		mandoc_msg(MANDOCERR_DT_LATE, mdoc->parse,
 		    n->line, n->pos, "Dt");
-		goto out;
+		return;
 	}
 
 	if (mdoc->meta.title != NULL)
 		mandoc_msg(MANDOCERR_PROLOG_REP, mdoc->parse,
 		    n->line, n->pos, "Dt");
 	else if (mdoc->meta.os != NULL)
 		mandoc_msg(MANDOCERR_PROLOG_ORDER, mdoc->parse,
 		    n->line, n->pos, "Dt after Os");
 
 	free(mdoc->meta.title);
 	free(mdoc->meta.msec);
 	free(mdoc->meta.vol);
 	free(mdoc->meta.arch);
 
 	mdoc->meta.title = NULL;
 	mdoc->meta.msec = NULL;
 	mdoc->meta.vol = NULL;
 	mdoc->meta.arch = NULL;
 
 	/* Mandatory first argument: title. */
 
 	nn = n->child;
 	if (nn == NULL || *nn->string == '\0') {
 		mandoc_msg(MANDOCERR_DT_NOTITLE,
 		    mdoc->parse, n->line, n->pos, "Dt");
 		mdoc->meta.title = mandoc_strdup("UNTITLED");
 	} else {
 		mdoc->meta.title = mandoc_strdup(nn->string);
 
 		/* Check that all characters are uppercase. */
 
 		for (p = nn->string; *p != '\0'; p++)
 			if (islower((unsigned char)*p)) {
 				mandoc_vmsg(MANDOCERR_TITLE_CASE,
 				    mdoc->parse, nn->line,
 				    nn->pos + (p - nn->string),
 				    "Dt %s", nn->string);
 				break;
 			}
 	}
 
-	/* Mandatory second argument: section. */
+	/* Mandatory second argument: section. */
 
 	if (nn != NULL)
 		nn = nn->next;
 
 	if (nn == NULL) {
 		mandoc_vmsg(MANDOCERR_MSEC_MISSING,
 		    mdoc->parse, n->line, n->pos,
 		    "Dt %s", mdoc->meta.title);
 		mdoc->meta.vol = mandoc_strdup("LOCAL");
-		goto out;  /* msec and arch remain NULL. */
+		return;  /* msec and arch remain NULL. */
 	}
 
 	mdoc->meta.msec = mandoc_strdup(nn->string);
 
 	/* Infer volume title from section number. */
 
 	cp = mandoc_a2msec(nn->string);
 	if (cp == NULL) {
 		mandoc_vmsg(MANDOCERR_MSEC_BAD, mdoc->parse,
 		    nn->line, nn->pos, "Dt ... %s", nn->string);
 		mdoc->meta.vol = mandoc_strdup(nn->string);
 	} else
 		mdoc->meta.vol = mandoc_strdup(cp);
 
 	/* Optional third argument: architecture. */
 
 	if ((nn = nn->next) == NULL)
-		goto out;
+		return;
 
 	for (p = nn->string; *p != '\0'; p++)
 		*p = tolower((unsigned char)*p);
 	mdoc->meta.arch = mandoc_strdup(nn->string);
 
 	/* Ignore fourth and later arguments. */
 
 	if ((nn = nn->next) != NULL)
 		mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse,
 		    nn->line, nn->pos, "Dt ... %s", nn->string);
-
-out:
-	roff_node_delete(mdoc, n);
 }
 
 static void
 post_bx(POST_ARGS)
 {
-	struct roff_node	*n;
+	struct roff_node	*n, *nch;
 
+	n = mdoc->last;
+	nch = n->child;
+
+	if (nch != NULL) {
+		mdoc->last = nch;
+		nch = nch->next;
+		mdoc->next = ROFF_NEXT_SIBLING;
+		roff_elem_alloc(mdoc, n->line, n->pos, MDOC_Ns);
+		mdoc->last->flags |= NODE_NOSRC;
+		mdoc->next = ROFF_NEXT_SIBLING;
+	} else
+		mdoc->next = ROFF_NEXT_CHILD;
+	roff_word_alloc(mdoc, n->line, n->pos, "BSD");
+	mdoc->last->flags |= NODE_NOSRC;
+
+	if (nch == NULL) {
+		mdoc->last = n;
+		return;
+	}
+
+	roff_elem_alloc(mdoc, n->line, n->pos, MDOC_Ns);
+	mdoc->last->flags |= NODE_NOSRC;
+	mdoc->next = ROFF_NEXT_SIBLING;
+	roff_word_alloc(mdoc, n->line, n->pos, "-");
+	mdoc->last->flags |= NODE_NOSRC;
+	roff_elem_alloc(mdoc, n->line, n->pos, MDOC_Ns);
+	mdoc->last->flags |= NODE_NOSRC;
+	mdoc->last = n;
+
 	/*
 	 * Make `Bx's second argument always start with an uppercase
 	 * letter.  Groff checks if it's an "accepted" term, but we just
 	 * uppercase blindly.
 	 */
 
-	if ((n = mdoc->last->child) != NULL && (n = n->next) != NULL)
-		*n->string = (char)toupper((unsigned char)*n->string);
+	*nch->string = (char)toupper((unsigned char)*nch->string);
 }
 
 static void
 post_os(POST_ARGS)
 {
 #ifndef OSNAME
 	struct utsname	  utsname;
 	static char	 *defbuf;
 #endif
 	struct roff_node *n;
 
 	n = mdoc->last;
+	n->flags |= NODE_NOPRT;
+
 	if (mdoc->meta.os != NULL)
 		mandoc_msg(MANDOCERR_PROLOG_REP, mdoc->parse,
 		    n->line, n->pos, "Os");
 	else if (mdoc->flags & MDOC_PBODY)
 		mandoc_msg(MANDOCERR_PROLOG_LATE, mdoc->parse,
 		    n->line, n->pos, "Os");
 
 	/*
 	 * Set the operating system by way of the `Os' macro.
 	 * The order of precedence is:
 	 * 1. the argument of the `Os' macro, unless empty
 	 * 2. the -Ios=foo command line argument, if provided
 	 * 3. -DOSNAME="\"foo\"", if provided during compilation
 	 * 4. "sysname release" from uname(3)
 	 */
 
 	free(mdoc->meta.os);
 	mdoc->meta.os = NULL;
 	deroff(&mdoc->meta.os, n);
 	if (mdoc->meta.os)
-		goto out;
+		return;
 
 	if (mdoc->defos) {
 		mdoc->meta.os = mandoc_strdup(mdoc->defos);
-		goto out;
+		return;
 	}
 
 #ifdef OSNAME
 	mdoc->meta.os = mandoc_strdup(OSNAME);
 #else /*!OSNAME */
 	if (defbuf == NULL) {
 		if (uname(&utsname) == -1) {
 			mandoc_msg(MANDOCERR_OS_UNAME, mdoc->parse,
 			    n->line, n->pos, "Os");
 			defbuf = mandoc_strdup("UNKNOWN");
 		} else
 			mandoc_asprintf(&defbuf, "%s %s",
 			    utsname.sysname, utsname.release);
 	}
 	mdoc->meta.os = mandoc_strdup(defbuf);
 #endif /*!OSNAME*/
-
-out:
-	roff_node_delete(mdoc, n);
-}
-
-/*
- * If no argument is provided,
- * fill in the name of the current manual page.
- */
-static void
-post_ex(POST_ARGS)
-{
-	struct roff_node *n;
-
-	post_std(mdoc);
-
-	n = mdoc->last;
-	if (n->child != NULL)
-		return;
-
-	if (mdoc->meta.name == NULL) {
-		mandoc_msg(MANDOCERR_EX_NONAME, mdoc->parse,
-		    n->line, n->pos, "Ex");
-		return;
-	}
-
-	mdoc->next = ROFF_NEXT_CHILD;
-	roff_word_alloc(mdoc, n->line, n->pos, mdoc->meta.name);
-	mdoc->last = n;
 }
 
 enum roff_sec
 mdoc_a2sec(const char *p)
 {
 	int		 i;
 
 	for (i = 0; i < (int)SEC__MAX; i++)
 		if (secnames[i] && 0 == strcmp(p, secnames[i]))
 			return (enum roff_sec)i;
 
 	return SEC_CUSTOM;
 }
 
 static size_t
 macro2len(int macro)
 {
 
 	switch (macro) {
 	case MDOC_Ad:
 		return 12;
 	case MDOC_Ao:
 		return 12;
 	case MDOC_An:
 		return 12;
 	case MDOC_Aq:
 		return 12;
 	case MDOC_Ar:
 		return 12;
 	case MDOC_Bo:
 		return 12;
 	case MDOC_Bq:
 		return 12;
 	case MDOC_Cd:
 		return 12;
 	case MDOC_Cm:
 		return 10;
 	case MDOC_Do:
 		return 10;
 	case MDOC_Dq:
 		return 12;
 	case MDOC_Dv:
 		return 12;
 	case MDOC_Eo:
 		return 12;
 	case MDOC_Em:
 		return 10;
 	case MDOC_Er:
 		return 17;
 	case MDOC_Ev:
 		return 15;
 	case MDOC_Fa:
 		return 12;
 	case MDOC_Fl:
 		return 10;
 	case MDOC_Fo:
 		return 16;
 	case MDOC_Fn:
 		return 16;
 	case MDOC_Ic:
 		return 10;
 	case MDOC_Li:
 		return 16;
 	case MDOC_Ms:
 		return 6;
 	case MDOC_Nm:
 		return 10;
 	case MDOC_No:
 		return 12;
 	case MDOC_Oo:
 		return 10;
 	case MDOC_Op:
 		return 14;
 	case MDOC_Pa:
 		return 32;
 	case MDOC_Pf:
 		return 12;
 	case MDOC_Po:
 		return 12;
 	case MDOC_Pq:
 		return 12;
 	case MDOC_Ql:
 		return 16;
 	case MDOC_Qo:
 		return 12;
 	case MDOC_So:
 		return 12;
 	case MDOC_Sq:
 		return 12;
 	case MDOC_Sy:
 		return 6;
 	case MDOC_Sx:
 		return 16;
 	case MDOC_Tn:
 		return 10;
 	case MDOC_Va:
 		return 12;
 	case MDOC_Vt:
 		return 12;
 	case MDOC_Xr:
 		return 10;
 	default:
 		break;
 	};
 	return 0;
 }
Index: stable/11/contrib/mdocml/read.c
===================================================================
--- stable/11/contrib/mdocml/read.c	(revision 316419)
+++ stable/11/contrib/mdocml/read.c	(revision 316420)
@@ -1,948 +1,937 @@
-/*	$Id: read.c,v 1.149 2016/07/10 13:34:30 schwarze Exp $ */
+/*	$Id: read.c,v 1.157 2017/01/09 01:37:03 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons 
- * Copyright (c) 2010-2016 Ingo Schwarze 
+ * Copyright (c) 2010-2017 Ingo Schwarze 
  * Copyright (c) 2010, 2012 Joerg Sonnenberger 
  *
  * 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 AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h"
 
 #include 
-#if HAVE_MMAP
 #include 
 #include 
-#endif
 
 #include 
 #include 
 #if HAVE_ERR
 #include 
 #endif
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 
 #include "mandoc_aux.h"
 #include "mandoc.h"
 #include "roff.h"
 #include "mdoc.h"
 #include "man.h"
 #include "libmandoc.h"
 #include "roff_int.h"
 
 #define	REPARSE_LIMIT	1000
 
 struct	mparse {
 	struct roff_man	 *man; /* man parser */
 	struct roff	 *roff; /* roff parser (!NULL) */
 	char		 *sodest; /* filename pointed to by .so */
 	const char	 *file; /* filename of current input file */
 	struct buf	 *primary; /* buffer currently being parsed */
 	struct buf	 *secondary; /* preprocessed copy of input */
 	const char	 *defos; /* default operating system */
 	mandocmsg	  mmsg; /* warning/error message handler */
 	enum mandoclevel  file_status; /* status of current parse */
 	enum mandoclevel  wlevel; /* ignore messages below this */
 	int		  options; /* parser options */
 	int		  gzip; /* current input file is gzipped */
 	int		  filenc; /* encoding of the current file */
 	int		  reparse_count; /* finite interp. stack */
 	int		  line; /* line number in the file */
 };
 
 static	void	  choose_parser(struct mparse *);
 static	void	  resize_buf(struct buf *, size_t);
 static	void	  mparse_buf_r(struct mparse *, struct buf, size_t, int);
 static	int	  read_whole_file(struct mparse *, const char *, int,
 				struct buf *, int *);
 static	void	  mparse_end(struct mparse *);
 static	void	  mparse_parse_buffer(struct mparse *, struct buf,
 			const char *);
 
 static	const enum mandocerr	mandoclimits[MANDOCLEVEL_MAX] = {
 	MANDOCERR_OK,
 	MANDOCERR_WARNING,
 	MANDOCERR_WARNING,
 	MANDOCERR_ERROR,
 	MANDOCERR_UNSUPP,
 	MANDOCERR_MAX,
 	MANDOCERR_MAX
 };
 
 static	const char * const	mandocerrs[MANDOCERR_MAX] = {
 	"ok",
 
 	"generic warning",
 
 	/* related to the prologue */
 	"missing manual title, using UNTITLED",
 	"missing manual title, using \"\"",
 	"lower case character in document title",
 	"missing manual section, using \"\"",
 	"unknown manual section",
 	"missing date, using today's date",
 	"cannot parse date, using it verbatim",
 	"missing Os macro, using \"\"",
 	"duplicate prologue macro",
 	"late prologue macro",
 	"skipping late title macro",
 	"prologue macros out of order",
 
 	/* related to document structure */
 	".so is fragile, better use ln(1)",
 	"no document body",
 	"content before first section header",
 	"first section is not \"NAME\"",
-	"NAME section without name",
+	"NAME section without Nm before Nd",
 	"NAME section without description",
 	"description not at the end of NAME",
 	"bad NAME section content",
+	"missing comma before name",
 	"missing description line, using \"\"",
 	"sections out of conventional order",
 	"duplicate section title",
 	"unexpected section",
 	"unusual Xr order",
 	"unusual Xr punctuation",
 	"AUTHORS section without An macro",
 
 	/* related to macros and nesting */
 	"obsolete macro",
 	"macro neither callable nor escaped",
 	"skipping paragraph macro",
 	"moving paragraph macro out of list",
 	"skipping no-space macro",
 	"blocks badly nested",
 	"nested displays are not portable",
 	"moving content out of list",
 	"fill mode already enabled, skipping",
 	"fill mode already disabled, skipping",
 	"line scope broken",
 
 	/* related to missing macro arguments */
 	"skipping empty request",
 	"conditional request controls empty scope",
 	"skipping empty macro",
 	"empty block",
 	"empty argument, using 0n",
 	"missing display type, using -ragged",
 	"list type is not the first argument",
-	"missing -width in -tag list, using 8n",
+	"missing -width in -tag list, using 6n",
 	"missing utility name, using \"\"",
 	"missing function name, using \"\"",
 	"empty head in list item",
 	"empty list item",
 	"missing font type, using \\fR",
 	"unknown font type, using \\fR",
 	"nothing follows prefix",
 	"empty reference block",
+	"missing section argument",
 	"missing -std argument, adding it",
 	"missing option string, using \"\"",
 	"missing resource identifier, using \"\"",
 	"missing eqn box, using \"\"",
 
 	/* related to bad macro arguments */
 	"unterminated quoted argument",
 	"duplicate argument",
 	"skipping duplicate argument",
 	"skipping duplicate display type",
 	"skipping duplicate list type",
 	"skipping -width argument",
 	"wrong number of cells",
 	"unknown AT&T UNIX version",
 	"comma in function argument",
 	"parenthesis in function name",
 	"invalid content in Rs block",
 	"invalid Boolean argument",
 	"unknown font, skipping request",
 	"odd number of characters in request",
 
 	/* related to plain text */
 	"blank line in fill mode, using .sp",
 	"tab in filled text",
 	"whitespace at end of input line",
 	"bad comment style",
 	"invalid escape sequence",
 	"undefined string, using \"\"",
 
 	/* related to tables */
 	"tbl line starts with span",
 	"tbl column starts with span",
 	"skipping vertical bar in tbl layout",
 
 	"generic error",
 
 	/* related to tables */
 	"non-alphabetic character in tbl options",
 	"skipping unknown tbl option",
 	"missing tbl option argument",
 	"wrong tbl option argument size",
 	"empty tbl layout",
 	"invalid character in tbl layout",
 	"unmatched parenthesis in tbl layout",
 	"tbl without any data cells",
 	"ignoring data in spanned tbl cell",
 	"ignoring extra tbl data cells",
 	"data block open at end of tbl",
 
 	/* related to document structure and macros */
 	NULL,
 	"input stack limit exceeded, infinite loop?",
 	"skipping bad character",
 	"skipping unknown macro",
 	"skipping insecure request",
 	"skipping item outside list",
 	"skipping column outside column list",
 	"skipping end of block that is not open",
 	"fewer RS blocks open, skipping",
 	"inserting missing end of block",
 	"appending missing end of block",
 
 	/* related to request and macro arguments */
 	"escaped character not allowed in a name",
 	"NOT IMPLEMENTED: Bd -file",
 	"skipping display without arguments",
 	"missing list type, using -item",
 	"missing manual name, using \"\"",
 	"uname(3) system call failed, using UNKNOWN",
 	"unknown standard specifier",
 	"skipping request without numeric argument",
 	"NOT IMPLEMENTED: .so with absolute path or \"..\"",
 	".so request failed",
 	"skipping all arguments",
 	"skipping excess arguments",
 	"divide by zero",
 
 	"unsupported feature",
 	"input too large",
 	"unsupported control character",
 	"unsupported roff request",
 	"eqn delim option in tbl",
 	"unsupported tbl layout modifier",
 	"ignoring macro in table",
 };
 
 static	const char * const	mandoclevels[MANDOCLEVEL_MAX] = {
 	"SUCCESS",
 	"RESERVED",
 	"WARNING",
 	"ERROR",
 	"UNSUPP",
 	"BADARG",
 	"SYSERR"
 };
 
 
 static void
 resize_buf(struct buf *buf, size_t initial)
 {
 
 	buf->sz = buf->sz > initial/2 ? 2 * buf->sz : initial;
 	buf->buf = mandoc_realloc(buf->buf, buf->sz);
 }
 
 static void
 choose_parser(struct mparse *curp)
 {
 	char		*cp, *ep;
 	int		 format;
 
 	/*
 	 * If neither command line arguments -mdoc or -man select
 	 * a parser nor the roff parser found a .Dd or .TH macro
 	 * yet, look ahead in the main input buffer.
 	 */
 
 	if ((format = roff_getformat(curp->roff)) == 0) {
 		cp = curp->primary->buf;
 		ep = cp + curp->primary->sz;
 		while (cp < ep) {
 			if (*cp == '.' || *cp == '\'') {
 				cp++;
 				if (cp[0] == 'D' && cp[1] == 'd') {
 					format = MPARSE_MDOC;
 					break;
 				}
 				if (cp[0] == 'T' && cp[1] == 'H') {
 					format = MPARSE_MAN;
 					break;
 				}
 			}
 			cp = memchr(cp, '\n', ep - cp);
 			if (cp == NULL)
 				break;
 			cp++;
 		}
 	}
 
-	if (curp->man == NULL) {
-		curp->man = roff_man_alloc(curp->roff, curp, curp->defos,
-		    curp->options & MPARSE_QUICK ? 1 : 0);
-		curp->man->macroset = MACROSET_MAN;
-		curp->man->first->tok = TOKEN_NONE;
-	}
-
 	if (format == MPARSE_MDOC) {
 		mdoc_hash_init();
 		curp->man->macroset = MACROSET_MDOC;
 		curp->man->first->tok = TOKEN_NONE;
 	} else {
 		man_hash_init();
 		curp->man->macroset = MACROSET_MAN;
 		curp->man->first->tok = TOKEN_NONE;
 	}
 }
 
 /*
  * Main parse routine for a buffer.
  * It assumes encoding and line numbering are already set up.
  * It can recurse directly (for invocations of user-defined
  * macros, inline equations, and input line traps)
  * and indirectly (for .so file inclusion).
  */
 static void
 mparse_buf_r(struct mparse *curp, struct buf blk, size_t i, int start)
 {
 	const struct tbl_span	*span;
 	struct buf	 ln;
 	const char	*save_file;
 	char		*cp;
 	size_t		 pos; /* byte number in the ln buffer */
+	size_t		 j;  /* auxiliary byte number in the blk buffer */
 	enum rofferr	 rr;
 	int		 of;
 	int		 lnn; /* line number in the real file */
 	int		 fd;
 	unsigned char	 c;
 
 	memset(&ln, 0, sizeof(ln));
 
 	lnn = curp->line;
 	pos = 0;
 
 	while (i < blk.sz) {
 		if (0 == pos && '\0' == blk.buf[i])
 			break;
 
 		if (start) {
 			curp->line = lnn;
 			curp->reparse_count = 0;
 
 			if (lnn < 3 &&
 			    curp->filenc & MPARSE_UTF8 &&
 			    curp->filenc & MPARSE_LATIN1)
 				curp->filenc = preconv_cue(&blk, i);
 		}
 
 		while (i < blk.sz && (start || blk.buf[i] != '\0')) {
 
 			/*
 			 * When finding an unescaped newline character,
 			 * leave the character loop to process the line.
 			 * Skip a preceding carriage return, if any.
 			 */
 
 			if ('\r' == blk.buf[i] && i + 1 < blk.sz &&
 			    '\n' == blk.buf[i + 1])
 				++i;
 			if ('\n' == blk.buf[i]) {
 				++i;
 				++lnn;
 				break;
 			}
 
 			/*
 			 * Make sure we have space for the worst
 			 * case of 11 bytes: "\\[u10ffff]\0"
 			 */
 
 			if (pos + 11 > ln.sz)
 				resize_buf(&ln, 256);
 
 			/*
 			 * Encode 8-bit input.
 			 */
 
 			c = blk.buf[i];
 			if (c & 0x80) {
 				if ( ! (curp->filenc && preconv_encode(
 				    &blk, &i, &ln, &pos, &curp->filenc))) {
 					mandoc_vmsg(MANDOCERR_CHAR_BAD, curp,
 					    curp->line, pos, "0x%x", c);
 					ln.buf[pos++] = '?';
 					i++;
 				}
 				continue;
 			}
 
 			/*
 			 * Exclude control characters.
 			 */
 
 			if (c == 0x7f || (c < 0x20 && c != 0x09)) {
 				mandoc_vmsg(c == 0x00 || c == 0x04 ||
 				    c > 0x0a ? MANDOCERR_CHAR_BAD :
 				    MANDOCERR_CHAR_UNSUPP,
 				    curp, curp->line, pos, "0x%x", c);
 				i++;
 				if (c != '\r')
 					ln.buf[pos++] = '?';
 				continue;
 			}
 
 			/* Trailing backslash = a plain char. */
 
 			if (blk.buf[i] != '\\' || i + 1 == blk.sz) {
 				ln.buf[pos++] = blk.buf[i++];
 				continue;
 			}
 
 			/*
 			 * Found escape and at least one other character.
 			 * When it's a newline character, skip it.
 			 * When there is a carriage return in between,
 			 * skip that one as well.
 			 */
 
 			if ('\r' == blk.buf[i + 1] && i + 2 < blk.sz &&
 			    '\n' == blk.buf[i + 2])
 				++i;
 			if ('\n' == blk.buf[i + 1]) {
 				i += 2;
 				++lnn;
 				continue;
 			}
 
 			if ('"' == blk.buf[i + 1] || '#' == blk.buf[i + 1]) {
+				j = i;
 				i += 2;
 				/* Comment, skip to end of line */
 				for (; i < blk.sz; ++i) {
-					if ('\n' == blk.buf[i]) {
-						++i;
-						++lnn;
-						break;
-					}
+					if (blk.buf[i] != '\n')
+						continue;
+					if (blk.buf[i - 1] == ' ' ||
+					    blk.buf[i - 1] == '\t')
+						mandoc_msg(
+						    MANDOCERR_SPACE_EOL,
+						    curp, curp->line,
+						    pos + i-1 - j, NULL);
+					++i;
+					++lnn;
+					break;
 				}
 
 				/* Backout trailing whitespaces */
 				for (; pos > 0; --pos) {
 					if (ln.buf[pos - 1] != ' ')
 						break;
 					if (pos > 2 && ln.buf[pos - 2] == '\\')
 						break;
 				}
 				break;
 			}
 
 			/* Catch escaped bogus characters. */
 
 			c = (unsigned char) blk.buf[i+1];
 
 			if ( ! (isascii(c) &&
 			    (isgraph(c) || isblank(c)))) {
 				mandoc_vmsg(MANDOCERR_CHAR_BAD, curp,
 				    curp->line, pos, "0x%x", c);
 				i += 2;
 				ln.buf[pos++] = '?';
 				continue;
 			}
 
 			/* Some other escape sequence, copy & cont. */
 
 			ln.buf[pos++] = blk.buf[i++];
 			ln.buf[pos++] = blk.buf[i++];
 		}
 
 		if (pos >= ln.sz)
 			resize_buf(&ln, 256);
 
 		ln.buf[pos] = '\0';
 
 		/*
 		 * A significant amount of complexity is contained by
 		 * the roff preprocessor.  It's line-oriented but can be
 		 * expressed on one line, so we need at times to
 		 * readjust our starting point and re-run it.  The roff
 		 * preprocessor can also readjust the buffers with new
 		 * data, so we pass them in wholesale.
 		 */
 
 		of = 0;
 
 		/*
 		 * Maintain a lookaside buffer of all parsed lines.  We
 		 * only do this if mparse_keep() has been invoked (the
 		 * buffer may be accessed with mparse_getkeep()).
 		 */
 
 		if (curp->secondary) {
 			curp->secondary->buf = mandoc_realloc(
 			    curp->secondary->buf,
 			    curp->secondary->sz + pos + 2);
 			memcpy(curp->secondary->buf +
 			    curp->secondary->sz,
 			    ln.buf, pos);
 			curp->secondary->sz += pos;
 			curp->secondary->buf
 				[curp->secondary->sz] = '\n';
 			curp->secondary->sz++;
 			curp->secondary->buf
 				[curp->secondary->sz] = '\0';
 		}
 rerun:
 		rr = roff_parseln(curp->roff, curp->line, &ln, &of);
 
 		switch (rr) {
 		case ROFF_REPARSE:
 			if (REPARSE_LIMIT >= ++curp->reparse_count)
 				mparse_buf_r(curp, ln, of, 0);
 			else
 				mandoc_msg(MANDOCERR_ROFFLOOP, curp,
 				    curp->line, pos, NULL);
 			pos = 0;
 			continue;
 		case ROFF_APPEND:
 			pos = strlen(ln.buf);
 			continue;
 		case ROFF_RERUN:
 			goto rerun;
 		case ROFF_IGN:
 			pos = 0;
 			continue;
 		case ROFF_SO:
 			if ( ! (curp->options & MPARSE_SO) &&
 			    (i >= blk.sz || blk.buf[i] == '\0')) {
 				curp->sodest = mandoc_strdup(ln.buf + of);
 				free(ln.buf);
 				return;
 			}
 			/*
 			 * We remove `so' clauses from our lookaside
 			 * buffer because we're going to descend into
 			 * the file recursively.
 			 */
 			if (curp->secondary)
 				curp->secondary->sz -= pos + 1;
 			save_file = curp->file;
 			if ((fd = mparse_open(curp, ln.buf + of)) != -1) {
 				mparse_readfd(curp, fd, ln.buf + of);
 				close(fd);
 				curp->file = save_file;
 			} else {
 				curp->file = save_file;
 				mandoc_vmsg(MANDOCERR_SO_FAIL,
 				    curp, curp->line, pos,
 				    ".so %s", ln.buf + of);
 				ln.sz = mandoc_asprintf(&cp,
 				    ".sp\nSee the file %s.\n.sp",
 				    ln.buf + of);
 				free(ln.buf);
 				ln.buf = cp;
 				of = 0;
 				mparse_buf_r(curp, ln, of, 0);
 			}
 			pos = 0;
 			continue;
 		default:
 			break;
 		}
 
-		/*
-		 * If input parsers have not been allocated, do so now.
-		 * We keep these instanced between parsers, but set them
-		 * locally per parse routine since we can use different
-		 * parsers with each one.
-		 */
-
-		if (curp->man == NULL ||
-		    curp->man->macroset == MACROSET_NONE)
+		if (curp->man->macroset == MACROSET_NONE)
 			choose_parser(curp);
 
 		/*
 		 * Lastly, push down into the parsers themselves.
 		 * If libroff returns ROFF_TBL, then add it to the
 		 * currently open parse.  Since we only get here if
 		 * there does exist data (see tbl_data.c), we're
 		 * guaranteed that something's been allocated.
 		 * Do the same for ROFF_EQN.
 		 */
 
 		if (rr == ROFF_TBL)
 			while ((span = roff_span(curp->roff)) != NULL)
 				roff_addtbl(curp->man, span);
 		else if (rr == ROFF_EQN)
 			roff_addeqn(curp->man, roff_eqn(curp->roff));
 		else if ((curp->man->macroset == MACROSET_MDOC ?
 		    mdoc_parseln(curp->man, curp->line, ln.buf, of) :
 		    man_parseln(curp->man, curp->line, ln.buf, of)) == 2)
 				break;
 
 		/* Temporary buffers typically are not full. */
 
 		if (0 == start && '\0' == blk.buf[i])
 			break;
 
 		/* Start the next input line. */
 
 		pos = 0;
 	}
 
 	free(ln.buf);
 }
 
 static int
 read_whole_file(struct mparse *curp, const char *file, int fd,
 		struct buf *fb, int *with_mmap)
 {
 	gzFile		 gz;
 	size_t		 off;
 	ssize_t		 ssz;
 
-#if HAVE_MMAP
 	struct stat	 st;
 
 	if (fstat(fd, &st) == -1)
 		err((int)MANDOCLEVEL_SYSERR, "%s", file);
 
 	/*
 	 * If we're a regular file, try just reading in the whole entry
 	 * via mmap().  This is faster than reading it into blocks, and
 	 * since each file is only a few bytes to begin with, I'm not
 	 * concerned that this is going to tank any machines.
 	 */
 
 	if (curp->gzip == 0 && S_ISREG(st.st_mode)) {
 		if (st.st_size > 0x7fffffff) {
 			mandoc_msg(MANDOCERR_TOOLARGE, curp, 0, 0, NULL);
 			return 0;
 		}
 		*with_mmap = 1;
 		fb->sz = (size_t)st.st_size;
 		fb->buf = mmap(NULL, fb->sz, PROT_READ, MAP_SHARED, fd, 0);
 		if (fb->buf != MAP_FAILED)
 			return 1;
 	}
-#endif
 
 	if (curp->gzip) {
 		if ((gz = gzdopen(fd, "rb")) == NULL)
 			err((int)MANDOCLEVEL_SYSERR, "%s", file);
 	} else
 		gz = NULL;
 
 	/*
 	 * If this isn't a regular file (like, say, stdin), then we must
 	 * go the old way and just read things in bit by bit.
 	 */
 
 	*with_mmap = 0;
 	off = 0;
 	fb->sz = 0;
 	fb->buf = NULL;
 	for (;;) {
 		if (off == fb->sz) {
 			if (fb->sz == (1U << 31)) {
 				mandoc_msg(MANDOCERR_TOOLARGE, curp,
 				    0, 0, NULL);
 				break;
 			}
 			resize_buf(fb, 65536);
 		}
 		ssz = curp->gzip ?
 		    gzread(gz, fb->buf + (int)off, fb->sz - off) :
 		    read(fd, fb->buf + (int)off, fb->sz - off);
 		if (ssz == 0) {
 			fb->sz = off;
 			return 1;
 		}
 		if (ssz == -1)
 			err((int)MANDOCLEVEL_SYSERR, "%s", file);
 		off += (size_t)ssz;
 	}
 
 	free(fb->buf);
 	fb->buf = NULL;
 	return 0;
 }
 
 static void
 mparse_end(struct mparse *curp)
 {
-
-	if (curp->man == NULL && curp->sodest == NULL)
-		curp->man = roff_man_alloc(curp->roff, curp, curp->defos,
-		    curp->options & MPARSE_QUICK ? 1 : 0);
 	if (curp->man->macroset == MACROSET_NONE)
 		curp->man->macroset = MACROSET_MAN;
 	if (curp->man->macroset == MACROSET_MDOC)
 		mdoc_endparse(curp->man);
 	else
 		man_endparse(curp->man);
 	roff_endparse(curp->roff);
 }
 
 static void
 mparse_parse_buffer(struct mparse *curp, struct buf blk, const char *file)
 {
 	struct buf	*svprimary;
 	const char	*svfile;
 	size_t		 offset;
 	static int	 recursion_depth;
 
 	if (64 < recursion_depth) {
 		mandoc_msg(MANDOCERR_ROFFLOOP, curp, curp->line, 0, NULL);
 		return;
 	}
 
 	/* Line number is per-file. */
 	svfile = curp->file;
 	curp->file = file;
 	svprimary = curp->primary;
 	curp->primary = &blk;
 	curp->line = 1;
 	recursion_depth++;
 
 	/* Skip an UTF-8 byte order mark. */
 	if (curp->filenc & MPARSE_UTF8 && blk.sz > 2 &&
 	    (unsigned char)blk.buf[0] == 0xef &&
 	    (unsigned char)blk.buf[1] == 0xbb &&
 	    (unsigned char)blk.buf[2] == 0xbf) {
 		offset = 3;
 		curp->filenc &= ~MPARSE_LATIN1;
 	} else
 		offset = 0;
 
 	mparse_buf_r(curp, blk, offset, 1);
 
 	if (--recursion_depth == 0)
 		mparse_end(curp);
 
 	curp->primary = svprimary;
 	curp->file = svfile;
 }
 
 enum mandoclevel
 mparse_readmem(struct mparse *curp, void *buf, size_t len,
 		const char *file)
 {
 	struct buf blk;
 
 	blk.buf = buf;
 	blk.sz = len;
 
 	mparse_parse_buffer(curp, blk, file);
 	return curp->file_status;
 }
 
 /*
  * Read the whole file into memory and call the parsers.
  * Called recursively when an .so request is encountered.
  */
 enum mandoclevel
 mparse_readfd(struct mparse *curp, int fd, const char *file)
 {
 	struct buf	 blk;
 	int		 with_mmap;
 	int		 save_filenc;
 
 	if (read_whole_file(curp, file, fd, &blk, &with_mmap)) {
 		save_filenc = curp->filenc;
 		curp->filenc = curp->options &
 		    (MPARSE_UTF8 | MPARSE_LATIN1);
 		mparse_parse_buffer(curp, blk, file);
 		curp->filenc = save_filenc;
-#if HAVE_MMAP
 		if (with_mmap)
 			munmap(blk.buf, blk.sz);
 		else
-#endif
 			free(blk.buf);
 	}
 	return curp->file_status;
 }
 
 int
 mparse_open(struct mparse *curp, const char *file)
 {
 	char		 *cp;
 	int		  fd;
 
 	curp->file = file;
 	cp = strrchr(file, '.');
 	curp->gzip = (cp != NULL && ! strcmp(cp + 1, "gz"));
 
 	/* First try to use the filename as it is. */
 
 	if ((fd = open(file, O_RDONLY)) != -1)
 		return fd;
 
 	/*
 	 * If that doesn't work and the filename doesn't
 	 * already  end in .gz, try appending .gz.
 	 */
 
 	if ( ! curp->gzip) {
 		mandoc_asprintf(&cp, "%s.gz", file);
 		fd = open(cp, O_RDONLY);
 		free(cp);
 		if (fd != -1) {
 			curp->gzip = 1;
 			return fd;
 		}
 	}
 
 	/* Neither worked, give up. */
 
 	mandoc_msg(MANDOCERR_FILE, curp, 0, 0, strerror(errno));
 	return -1;
 }
 
 struct mparse *
 mparse_alloc(int options, enum mandoclevel wlevel, mandocmsg mmsg,
     const char *defos)
 {
 	struct mparse	*curp;
 
 	curp = mandoc_calloc(1, sizeof(struct mparse));
 
 	curp->options = options;
 	curp->wlevel = wlevel;
 	curp->mmsg = mmsg;
 	curp->defos = defos;
 
 	curp->roff = roff_alloc(curp, options);
 	curp->man = roff_man_alloc( curp->roff, curp, curp->defos,
 		curp->options & MPARSE_QUICK ? 1 : 0);
 	if (curp->options & MPARSE_MDOC) {
 		mdoc_hash_init();
 		curp->man->macroset = MACROSET_MDOC;
 	} else if (curp->options & MPARSE_MAN) {
 		man_hash_init();
 		curp->man->macroset = MACROSET_MAN;
 	}
 	curp->man->first->tok = TOKEN_NONE;
 	return curp;
 }
 
 void
 mparse_reset(struct mparse *curp)
 {
-
 	roff_reset(curp->roff);
-
-	if (curp->man != NULL)
-		roff_man_reset(curp->man);
+	roff_man_reset(curp->man);
 	if (curp->secondary)
 		curp->secondary->sz = 0;
 
 	curp->file_status = MANDOCLEVEL_OK;
 
 	free(curp->sodest);
 	curp->sodest = NULL;
 }
 
 void
 mparse_free(struct mparse *curp)
 {
 
 	roff_man_free(curp->man);
 	if (curp->roff)
 		roff_free(curp->roff);
 	if (curp->secondary)
 		free(curp->secondary->buf);
 
 	free(curp->secondary);
 	free(curp->sodest);
 	free(curp);
 }
 
 void
 mparse_result(struct mparse *curp, struct roff_man **man,
 	char **sodest)
 {
 
 	if (sodest && NULL != (*sodest = curp->sodest)) {
 		*man = NULL;
 		return;
 	}
 	if (man)
 		*man = curp->man;
+}
+
+void
+mparse_updaterc(struct mparse *curp, enum mandoclevel *rc)
+{
+	if (curp->file_status > *rc)
+		*rc = curp->file_status;
 }
 
 void
 mandoc_vmsg(enum mandocerr t, struct mparse *m,
 		int ln, int pos, const char *fmt, ...)
 {
 	char		 buf[256];
 	va_list		 ap;
 
 	va_start(ap, fmt);
 	(void)vsnprintf(buf, sizeof(buf), fmt, ap);
 	va_end(ap);
 
 	mandoc_msg(t, m, ln, pos, buf);
 }
 
 void
 mandoc_msg(enum mandocerr er, struct mparse *m,
 		int ln, int col, const char *msg)
 {
 	enum mandoclevel level;
 
 	level = MANDOCLEVEL_UNSUPP;
 	while (er < mandoclimits[level])
 		level--;
 
 	if (level < m->wlevel && er != MANDOCERR_FILE)
 		return;
 
 	if (m->mmsg)
 		(*m->mmsg)(er, level, m->file, ln, col, msg);
 
 	if (m->file_status < level)
 		m->file_status = level;
 }
 
 const char *
 mparse_strerror(enum mandocerr er)
 {
 
 	return mandocerrs[er];
 }
 
 const char *
 mparse_strlevel(enum mandoclevel lvl)
 {
 	return mandoclevels[lvl];
 }
 
 void
 mparse_keep(struct mparse *p)
 {
 
 	assert(NULL == p->secondary);
 	p->secondary = mandoc_calloc(1, sizeof(struct buf));
 }
 
 const char *
 mparse_getkeep(const struct mparse *p)
 {
 
 	assert(p->secondary);
 	return p->secondary->sz ? p->secondary->buf : NULL;
 }
Index: stable/11/contrib/mdocml/roff.c
===================================================================
--- stable/11/contrib/mdocml/roff.c	(revision 316419)
+++ stable/11/contrib/mdocml/roff.c	(revision 316420)
@@ -1,3468 +1,3462 @@
-/*	$Id: roff.c,v 1.284 2016/01/08 17:48:10 schwarze Exp $ */
+/*	$Id: roff.c,v 1.288 2017/01/12 18:02:20 schwarze Exp $ */
 /*
  * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons 
- * Copyright (c) 2010-2015 Ingo Schwarze 
+ * Copyright (c) 2010-2015, 2017 Ingo Schwarze 
  *
  * 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 AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h"
 
 #include 
 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 
 #include "mandoc.h"
 #include "mandoc_aux.h"
 #include "roff.h"
 #include "libmandoc.h"
 #include "roff_int.h"
 #include "libroff.h"
 
 /* Maximum number of string expansions per line, to break infinite loops. */
 #define	EXPAND_LIMIT	1000
 
 /* --- data types --------------------------------------------------------- */
 
 enum	rofft {
 	ROFF_ab,
 	ROFF_ad,
 	ROFF_af,
 	ROFF_aln,
 	ROFF_als,
 	ROFF_am,
 	ROFF_am1,
 	ROFF_ami,
 	ROFF_ami1,
 	ROFF_as,
 	ROFF_as1,
 	ROFF_asciify,
 	ROFF_backtrace,
 	ROFF_bd,
 	ROFF_bleedat,
 	ROFF_blm,
 	ROFF_box,
 	ROFF_boxa,
 	ROFF_bp,
 	ROFF_BP,
 	/* MAN_br, MDOC_br */
 	ROFF_break,
 	ROFF_breakchar,
 	ROFF_brnl,
 	ROFF_brp,
 	ROFF_brpnl,
 	ROFF_c2,
 	ROFF_cc,
 	ROFF_ce,
 	ROFF_cf,
 	ROFF_cflags,
 	ROFF_ch,
 	ROFF_char,
 	ROFF_chop,
 	ROFF_class,
 	ROFF_close,
 	ROFF_CL,
 	ROFF_color,
 	ROFF_composite,
 	ROFF_continue,
 	ROFF_cp,
 	ROFF_cropat,
 	ROFF_cs,
 	ROFF_cu,
 	ROFF_da,
 	ROFF_dch,
 	ROFF_Dd,
 	ROFF_de,
 	ROFF_de1,
 	ROFF_defcolor,
 	ROFF_dei,
 	ROFF_dei1,
 	ROFF_device,
 	ROFF_devicem,
 	ROFF_di,
 	ROFF_do,
 	ROFF_ds,
 	ROFF_ds1,
 	ROFF_dwh,
 	ROFF_dt,
 	ROFF_ec,
 	ROFF_ecr,
 	ROFF_ecs,
 	ROFF_el,
 	ROFF_em,
 	ROFF_EN,
 	ROFF_eo,
 	ROFF_EP,
 	ROFF_EQ,
 	ROFF_errprint,
 	ROFF_ev,
 	ROFF_evc,
 	ROFF_ex,
 	ROFF_fallback,
 	ROFF_fam,
 	ROFF_fc,
 	ROFF_fchar,
 	ROFF_fcolor,
 	ROFF_fdeferlig,
 	ROFF_feature,
 	/* MAN_fi; ignored in mdoc(7) */
 	ROFF_fkern,
 	ROFF_fl,
 	ROFF_flig,
 	ROFF_fp,
 	ROFF_fps,
 	ROFF_fschar,
 	ROFF_fspacewidth,
 	ROFF_fspecial,
 	/* MAN_ft; ignored in mdoc(7) */
 	ROFF_ftr,
 	ROFF_fzoom,
 	ROFF_gcolor,
 	ROFF_hc,
 	ROFF_hcode,
 	ROFF_hidechar,
 	ROFF_hla,
 	ROFF_hlm,
 	ROFF_hpf,
 	ROFF_hpfa,
 	ROFF_hpfcode,
 	ROFF_hw,
 	ROFF_hy,
 	ROFF_hylang,
 	ROFF_hylen,
 	ROFF_hym,
 	ROFF_hypp,
 	ROFF_hys,
 	ROFF_ie,
 	ROFF_if,
 	ROFF_ig,
 	/* MAN_in; ignored in mdoc(7) */
 	ROFF_index,
 	ROFF_it,
 	ROFF_itc,
 	ROFF_IX,
 	ROFF_kern,
 	ROFF_kernafter,
 	ROFF_kernbefore,
 	ROFF_kernpair,
 	ROFF_lc,
 	ROFF_lc_ctype,
 	ROFF_lds,
 	ROFF_length,
 	ROFF_letadj,
 	ROFF_lf,
 	ROFF_lg,
 	ROFF_lhang,
 	ROFF_linetabs,
 	/* MAN_ll, MDOC_ll */
 	ROFF_lnr,
 	ROFF_lnrf,
 	ROFF_lpfx,
 	ROFF_ls,
 	ROFF_lsm,
 	ROFF_lt,
 	ROFF_mc,
 	ROFF_mediasize,
 	ROFF_minss,
 	ROFF_mk,
 	ROFF_mso,
 	ROFF_na,
 	ROFF_ne,
 	/* MAN_nf; ignored in mdoc(7) */
 	ROFF_nh,
 	ROFF_nhychar,
 	ROFF_nm,
 	ROFF_nn,
 	ROFF_nop,
 	ROFF_nr,
 	ROFF_nrf,
 	ROFF_nroff,
 	ROFF_ns,
 	ROFF_nx,
 	ROFF_open,
 	ROFF_opena,
 	ROFF_os,
 	ROFF_output,
 	ROFF_padj,
 	ROFF_papersize,
 	ROFF_pc,
 	ROFF_pev,
 	ROFF_pi,
 	ROFF_PI,
 	ROFF_pl,
 	ROFF_pm,
 	ROFF_pn,
 	ROFF_pnr,
 	ROFF_po,
 	ROFF_ps,
 	ROFF_psbb,
 	ROFF_pshape,
 	ROFF_pso,
 	ROFF_ptr,
 	ROFF_pvs,
 	ROFF_rchar,
 	ROFF_rd,
 	ROFF_recursionlimit,
 	ROFF_return,
 	ROFF_rfschar,
 	ROFF_rhang,
 	ROFF_rj,
 	ROFF_rm,
 	ROFF_rn,
 	ROFF_rnn,
 	ROFF_rr,
 	ROFF_rs,
 	ROFF_rt,
 	ROFF_schar,
 	ROFF_sentchar,
 	ROFF_shc,
 	ROFF_shift,
 	ROFF_sizes,
 	ROFF_so,
 	/* MAN_sp, MDOC_sp */
 	ROFF_spacewidth,
 	ROFF_special,
 	ROFF_spreadwarn,
 	ROFF_ss,
 	ROFF_sty,
 	ROFF_substring,
 	ROFF_sv,
 	ROFF_sy,
 	ROFF_T_,
 	ROFF_ta,
 	ROFF_tc,
 	ROFF_TE,
 	ROFF_TH,
 	ROFF_ti,
 	ROFF_tkf,
 	ROFF_tl,
 	ROFF_tm,
 	ROFF_tm1,
 	ROFF_tmc,
 	ROFF_tr,
 	ROFF_track,
 	ROFF_transchar,
 	ROFF_trf,
 	ROFF_trimat,
 	ROFF_trin,
 	ROFF_trnt,
 	ROFF_troff,
 	ROFF_TS,
 	ROFF_uf,
 	ROFF_ul,
 	ROFF_unformat,
 	ROFF_unwatch,
 	ROFF_unwatchn,
 	ROFF_vpt,
 	ROFF_vs,
 	ROFF_warn,
 	ROFF_warnscale,
 	ROFF_watch,
 	ROFF_watchlength,
 	ROFF_watchn,
 	ROFF_wh,
 	ROFF_while,
 	ROFF_write,
 	ROFF_writec,
 	ROFF_writem,
 	ROFF_xflag,
 	ROFF_cblock,
 	ROFF_USERDEF,
 	ROFF_MAX
 };
 
 /*
  * An incredibly-simple string buffer.
  */
 struct	roffstr {
 	char		*p; /* nil-terminated buffer */
 	size_t		 sz; /* saved strlen(p) */
 };
 
 /*
  * A key-value roffstr pair as part of a singly-linked list.
  */
 struct	roffkv {
 	struct roffstr	 key;
 	struct roffstr	 val;
 	struct roffkv	*next; /* next in list */
 };
 
 /*
  * A single number register as part of a singly-linked list.
  */
 struct	roffreg {
 	struct roffstr	 key;
 	int		 val;
 	struct roffreg	*next;
 };
 
 struct	roff {
 	struct mparse	*parse; /* parse point */
 	struct roffnode	*last; /* leaf of stack */
 	int		*rstack; /* stack of inverted `ie' values */
 	struct roffreg	*regtab; /* number registers */
 	struct roffkv	*strtab; /* user-defined strings & macros */
 	struct roffkv	*xmbtab; /* multi-byte trans table (`tr') */
 	struct roffstr	*xtab; /* single-byte trans table (`tr') */
 	const char	*current_string; /* value of last called user macro */
 	struct tbl_node	*first_tbl; /* first table parsed */
 	struct tbl_node	*last_tbl; /* last table parsed */
 	struct tbl_node	*tbl; /* current table being parsed */
 	struct eqn_node	*last_eqn; /* last equation parsed */
 	struct eqn_node	*first_eqn; /* first equation parsed */
 	struct eqn_node	*eqn; /* current equation being parsed */
 	int		 eqn_inline; /* current equation is inline */
 	int		 options; /* parse options */
 	int		 rstacksz; /* current size limit of rstack */
 	int		 rstackpos; /* position in rstack */
 	int		 format; /* current file in mdoc or man format */
 	int		 argc; /* number of args of the last macro */
 	char		 control; /* control character */
 };
 
 struct	roffnode {
 	enum rofft	 tok; /* type of node */
 	struct roffnode	*parent; /* up one in stack */
 	int		 line; /* parse line */
 	int		 col; /* parse col */
 	char		*name; /* node name, e.g. macro name */
 	char		*end; /* end-rules: custom token */
 	int		 endspan; /* end-rules: next-line or infty */
 	int		 rule; /* current evaluation rule */
 };
 
 #define	ROFF_ARGS	 struct roff *r, /* parse ctx */ \
 			 enum rofft tok, /* tok of macro */ \
 			 struct buf *buf, /* input buffer */ \
 			 int ln, /* parse line */ \
 			 int ppos, /* original pos in buffer */ \
 			 int pos, /* current pos in buffer */ \
 			 int *offs /* reset offset of buffer data */
 
 typedef	enum rofferr (*roffproc)(ROFF_ARGS);
 
 struct	roffmac {
 	const char	*name; /* macro name */
 	roffproc	 proc; /* process new macro */
 	roffproc	 text; /* process as child text of macro */
 	roffproc	 sub; /* process as child of macro */
 	int		 flags;
 #define	ROFFMAC_STRUCT	(1 << 0) /* always interpret */
 	struct roffmac	*next;
 };
 
 struct	predef {
 	const char	*name; /* predefined input name */
 	const char	*str; /* replacement symbol */
 };
 
 #define	PREDEF(__name, __str) \
 	{ (__name), (__str) },
 
 /* --- function prototypes ------------------------------------------------ */
 
 static	enum rofft	 roffhash_find(const char *, size_t);
 static	void		 roffhash_init(void);
 static	void		 roffnode_cleanscope(struct roff *);
 static	void		 roffnode_pop(struct roff *);
 static	void		 roffnode_push(struct roff *, enum rofft,
 				const char *, int, int);
 static	enum rofferr	 roff_block(ROFF_ARGS);
 static	enum rofferr	 roff_block_text(ROFF_ARGS);
 static	enum rofferr	 roff_block_sub(ROFF_ARGS);
 static	enum rofferr	 roff_brp(ROFF_ARGS);
 static	enum rofferr	 roff_cblock(ROFF_ARGS);
 static	enum rofferr	 roff_cc(ROFF_ARGS);
 static	void		 roff_ccond(struct roff *, int, int);
 static	enum rofferr	 roff_cond(ROFF_ARGS);
 static	enum rofferr	 roff_cond_text(ROFF_ARGS);
 static	enum rofferr	 roff_cond_sub(ROFF_ARGS);
 static	enum rofferr	 roff_ds(ROFF_ARGS);
 static	enum rofferr	 roff_eqndelim(struct roff *, struct buf *, int);
 static	int		 roff_evalcond(struct roff *r, int, char *, int *);
 static	int		 roff_evalnum(struct roff *, int,
 				const char *, int *, int *, int);
 static	int		 roff_evalpar(struct roff *, int,
 				const char *, int *, int *, int);
 static	int		 roff_evalstrcond(const char *, int *);
 static	void		 roff_free1(struct roff *);
 static	void		 roff_freereg(struct roffreg *);
 static	void		 roff_freestr(struct roffkv *);
 static	size_t		 roff_getname(struct roff *, char **, int, int);
 static	int		 roff_getnum(const char *, int *, int *, int);
 static	int		 roff_getop(const char *, int *, char *);
 static	int		 roff_getregn(const struct roff *,
 				const char *, size_t);
 static	int		 roff_getregro(const struct roff *,
 				const char *name);
 static	const char	*roff_getstrn(const struct roff *,
 				const char *, size_t);
 static	int		 roff_hasregn(const struct roff *,
 				const char *, size_t);
 static	enum rofferr	 roff_insec(ROFF_ARGS);
 static	enum rofferr	 roff_it(ROFF_ARGS);
 static	enum rofferr	 roff_line_ignore(ROFF_ARGS);
 static	void		 roff_man_alloc1(struct roff_man *);
 static	void		 roff_man_free1(struct roff_man *);
 static	enum rofferr	 roff_nr(ROFF_ARGS);
 static	enum rofft	 roff_parse(struct roff *, char *, int *,
 				int, int);
 static	enum rofferr	 roff_parsetext(struct buf *, int, int *);
 static	enum rofferr	 roff_res(struct roff *, struct buf *, int, int);
 static	enum rofferr	 roff_rm(ROFF_ARGS);
 static	enum rofferr	 roff_rr(ROFF_ARGS);
 static	void		 roff_setstr(struct roff *,
 				const char *, const char *, int);
 static	void		 roff_setstrn(struct roffkv **, const char *,
 				size_t, const char *, size_t, int);
 static	enum rofferr	 roff_so(ROFF_ARGS);
 static	enum rofferr	 roff_tr(ROFF_ARGS);
 static	enum rofferr	 roff_Dd(ROFF_ARGS);
 static	enum rofferr	 roff_TH(ROFF_ARGS);
 static	enum rofferr	 roff_TE(ROFF_ARGS);
 static	enum rofferr	 roff_TS(ROFF_ARGS);
 static	enum rofferr	 roff_EQ(ROFF_ARGS);
 static	enum rofferr	 roff_EN(ROFF_ARGS);
 static	enum rofferr	 roff_T_(ROFF_ARGS);
 static	enum rofferr	 roff_unsupp(ROFF_ARGS);
 static	enum rofferr	 roff_userdef(ROFF_ARGS);
 
 /* --- constant data ------------------------------------------------------ */
 
 /* See roffhash_find() */
 
 #define	ASCII_HI	 126
 #define	ASCII_LO	 33
 #define	HASHWIDTH	(ASCII_HI - ASCII_LO + 1)
 
 #define	ROFFNUM_SCALE	(1 << 0)  /* Honour scaling in roff_getnum(). */
 #define	ROFFNUM_WHITE	(1 << 1)  /* Skip whitespace in roff_evalnum(). */
 
 static	struct roffmac	*hash[HASHWIDTH];
 
 static	struct roffmac	 roffs[ROFF_MAX] = {
 	{ "ab", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "ad", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "af", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "aln", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "als", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "am", roff_block, roff_block_text, roff_block_sub, 0, NULL },
 	{ "am1", roff_block, roff_block_text, roff_block_sub, 0, NULL },
 	{ "ami", roff_block, roff_block_text, roff_block_sub, 0, NULL },
 	{ "ami1", roff_block, roff_block_text, roff_block_sub, 0, NULL },
 	{ "as", roff_ds, NULL, NULL, 0, NULL },
 	{ "as1", roff_ds, NULL, NULL, 0, NULL },
 	{ "asciify", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "backtrace", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "bd", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "bleedat", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "blm", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "box", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "boxa", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "bp", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "BP", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "break", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "breakchar", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "brnl", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "brp", roff_brp, NULL, NULL, 0, NULL },
 	{ "brpnl", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "c2", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "cc", roff_cc, NULL, NULL, 0, NULL },
 	{ "ce", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "cf", roff_insec, NULL, NULL, 0, NULL },
 	{ "cflags", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "ch", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "char", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "chop", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "class", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "close", roff_insec, NULL, NULL, 0, NULL },
 	{ "CL", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "color", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "composite", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "continue", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "cp", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "cropat", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "cs", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "cu", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "da", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "dch", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "Dd", roff_Dd, NULL, NULL, 0, NULL },
 	{ "de", roff_block, roff_block_text, roff_block_sub, 0, NULL },
 	{ "de1", roff_block, roff_block_text, roff_block_sub, 0, NULL },
 	{ "defcolor", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "dei", roff_block, roff_block_text, roff_block_sub, 0, NULL },
 	{ "dei1", roff_block, roff_block_text, roff_block_sub, 0, NULL },
 	{ "device", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "devicem", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "di", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "do", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "ds", roff_ds, NULL, NULL, 0, NULL },
 	{ "ds1", roff_ds, NULL, NULL, 0, NULL },
 	{ "dwh", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "dt", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "ec", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "ecr", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "ecs", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "el", roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT, NULL },
 	{ "em", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "EN", roff_EN, NULL, NULL, 0, NULL },
 	{ "eo", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "EP", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "EQ", roff_EQ, NULL, NULL, 0, NULL },
 	{ "errprint", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "ev", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "evc", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "ex", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "fallback", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "fam", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "fc", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "fchar", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "fcolor", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "fdeferlig", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "feature", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "fkern", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "fl", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "flig", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "fp", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "fps", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "fschar", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "fspacewidth", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "fspecial", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "ftr", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "fzoom", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "gcolor", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "hc", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "hcode", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "hidechar", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "hla", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "hlm", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "hpf", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "hpfa", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "hpfcode", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "hw", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "hy", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "hylang", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "hylen", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "hym", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "hypp", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "hys", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "ie", roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT, NULL },
 	{ "if", roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT, NULL },
 	{ "ig", roff_block, roff_block_text, roff_block_sub, 0, NULL },
 	{ "index", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "it", roff_it, NULL, NULL, 0, NULL },
 	{ "itc", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "IX", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "kern", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "kernafter", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "kernbefore", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "kernpair", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "lc", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "lc_ctype", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "lds", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "length", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "letadj", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "lf", roff_insec, NULL, NULL, 0, NULL },
 	{ "lg", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "lhang", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "linetabs", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "lnr", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "lnrf", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "lpfx", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "ls", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "lsm", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "lt", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "mc", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "mediasize", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "minss", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "mk", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "mso", roff_insec, NULL, NULL, 0, NULL },
 	{ "na", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "ne", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "nh", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "nhychar", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "nm", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "nn", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "nop", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "nr", roff_nr, NULL, NULL, 0, NULL },
 	{ "nrf", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "nroff", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "ns", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "nx", roff_insec, NULL, NULL, 0, NULL },
 	{ "open", roff_insec, NULL, NULL, 0, NULL },
 	{ "opena", roff_insec, NULL, NULL, 0, NULL },
 	{ "os", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "output", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "padj", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "papersize", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "pc", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "pev", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "pi", roff_insec, NULL, NULL, 0, NULL },
 	{ "PI", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "pl", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "pm", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "pn", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "pnr", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "po", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "ps", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "psbb", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "pshape", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "pso", roff_insec, NULL, NULL, 0, NULL },
 	{ "ptr", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "pvs", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "rchar", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "rd", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "recursionlimit", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "return", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "rfschar", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "rhang", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "rj", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "rm", roff_rm, NULL, NULL, 0, NULL },
 	{ "rn", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "rnn", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "rr", roff_rr, NULL, NULL, 0, NULL },
 	{ "rs", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "rt", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "schar", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "sentchar", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "shc", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "shift", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "sizes", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "so", roff_so, NULL, NULL, 0, NULL },
 	{ "spacewidth", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "special", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "spreadwarn", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "ss", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "sty", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "substring", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "sv", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "sy", roff_insec, NULL, NULL, 0, NULL },
 	{ "T&", roff_T_, NULL, NULL, 0, NULL },
 	{ "ta", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "tc", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "TE", roff_TE, NULL, NULL, 0, NULL },
 	{ "TH", roff_TH, NULL, NULL, 0, NULL },
 	{ "ti", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "tkf", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "tl", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "tm", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "tm1", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "tmc", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "tr", roff_tr, NULL, NULL, 0, NULL },
 	{ "track", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "transchar", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "trf", roff_insec, NULL, NULL, 0, NULL },
 	{ "trimat", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "trin", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "trnt", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "troff", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "TS", roff_TS, NULL, NULL, 0, NULL },
 	{ "uf", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "ul", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "unformat", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "unwatch", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "unwatchn", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "vpt", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "vs", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "warn", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "warnscale", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "watch", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "watchlength", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "watchn", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ "wh", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "while", roff_unsupp, NULL, NULL, 0, NULL },
 	{ "write", roff_insec, NULL, NULL, 0, NULL },
 	{ "writec", roff_insec, NULL, NULL, 0, NULL },
 	{ "writem", roff_insec, NULL, NULL, 0, NULL },
 	{ "xflag", roff_line_ignore, NULL, NULL, 0, NULL },
 	{ ".", roff_cblock, NULL, NULL, 0, NULL },
 	{ NULL, roff_userdef, NULL, NULL, 0, NULL },
 };
 
 /* not currently implemented: Ds em Eq LP Me PP pp Or Rd Sf SH */
 const	char *const __mdoc_reserved[] = {
 	"Ac", "Ad", "An", "Ao", "Ap", "Aq", "Ar", "At",
 	"Bc", "Bd", "Bf", "Bk", "Bl", "Bo", "Bq",
 	"Brc", "Bro", "Brq", "Bsx", "Bt", "Bx",
 	"Cd", "Cm", "Db", "Dc", "Dd", "Dl", "Do", "Dq",
 	"Dt", "Dv", "Dx", "D1",
 	"Ec", "Ed", "Ef", "Ek", "El", "Em",
 	"En", "Eo", "Er", "Es", "Ev", "Ex",
 	"Fa", "Fc", "Fd", "Fl", "Fn", "Fo", "Fr", "Ft", "Fx",
 	"Hf", "Ic", "In", "It", "Lb", "Li", "Lk", "Lp",
 	"Ms", "Mt", "Nd", "Nm", "No", "Ns", "Nx",
 	"Oc", "Oo", "Op", "Os", "Ot", "Ox",
 	"Pa", "Pc", "Pf", "Po", "Pp", "Pq",
 	"Qc", "Ql", "Qo", "Qq", "Re", "Rs", "Rv",
 	"Sc", "Sh", "Sm", "So", "Sq",
 	"Ss", "St", "Sx", "Sy",
 	"Ta", "Tn", "Ud", "Ux", "Va", "Vt", "Xc", "Xo", "Xr",
 	"%A", "%B", "%C", "%D", "%I", "%J", "%N", "%O",
 	"%P", "%Q", "%R", "%T", "%U", "%V",
 	NULL
 };
 
 /* not currently implemented: BT DE DS ME MT PT SY TQ YS */
 const	char *const __man_reserved[] = {
 	"AT", "B", "BI", "BR", "DT",
 	"EE", "EN", "EQ", "EX", "HP", "I", "IB", "IP", "IR",
 	"LP", "OP", "P", "PD", "PP",
 	"R", "RB", "RE", "RI", "RS", "SB", "SH", "SM", "SS",
 	"TE", "TH", "TP", "TS", "T&", "UC", "UE", "UR",
 	NULL
 };
 
 /* Array of injected predefined strings. */
 #define	PREDEFS_MAX	 38
 static	const struct predef predefs[PREDEFS_MAX] = {
 #include "predefs.in"
 };
 
 /* See roffhash_find() */
 #define	ROFF_HASH(p)	(p[0] - ASCII_LO)
 
 static	int	 roffit_lines;  /* number of lines to delay */
 static	char	*roffit_macro;  /* nil-terminated macro line */
 
 
 /* --- request table ------------------------------------------------------ */
 
 static void
 roffhash_init(void)
 {
 	struct roffmac	 *n;
 	int		  buc, i;
 
 	for (i = 0; i < (int)ROFF_USERDEF; i++) {
 		assert(roffs[i].name[0] >= ASCII_LO);
 		assert(roffs[i].name[0] <= ASCII_HI);
 
 		buc = ROFF_HASH(roffs[i].name);
 
 		if (NULL != (n = hash[buc])) {
 			for ( ; n->next; n = n->next)
 				/* Do nothing. */ ;
 			n->next = &roffs[i];
 		} else
 			hash[buc] = &roffs[i];
 	}
 }
 
 /*
  * Look up a roff token by its name.  Returns ROFF_MAX if no macro by
  * the nil-terminated string name could be found.
  */
 static enum rofft
 roffhash_find(const char *p, size_t s)
 {
 	int		 buc;
 	struct roffmac	*n;
 
 	/*
 	 * libroff has an extremely simple hashtable, for the time
 	 * being, which simply keys on the first character, which must
 	 * be printable, then walks a chain.  It works well enough until
 	 * optimised.
 	 */
 
 	if (p[0] < ASCII_LO || p[0] > ASCII_HI)
 		return ROFF_MAX;
 
 	buc = ROFF_HASH(p);
 
 	if (NULL == (n = hash[buc]))
 		return ROFF_MAX;
 	for ( ; n; n = n->next)
 		if (0 == strncmp(n->name, p, s) && '\0' == n->name[(int)s])
 			return (enum rofft)(n - roffs);
 
 	return ROFF_MAX;
 }
 
 /* --- stack of request blocks -------------------------------------------- */
 
 /*
  * Pop the current node off of the stack of roff instructions currently
  * pending.
  */
 static void
 roffnode_pop(struct roff *r)
 {
 	struct roffnode	*p;
 
 	assert(r->last);
 	p = r->last;
 
 	r->last = r->last->parent;
 	free(p->name);
 	free(p->end);
 	free(p);
 }
 
 /*
  * Push a roff node onto the instruction stack.  This must later be
  * removed with roffnode_pop().
  */
 static void
 roffnode_push(struct roff *r, enum rofft tok, const char *name,
 		int line, int col)
 {
 	struct roffnode	*p;
 
 	p = mandoc_calloc(1, sizeof(struct roffnode));
 	p->tok = tok;
 	if (name)
 		p->name = mandoc_strdup(name);
 	p->parent = r->last;
 	p->line = line;
 	p->col = col;
 	p->rule = p->parent ? p->parent->rule : 0;
 
 	r->last = p;
 }
 
 /* --- roff parser state data management ---------------------------------- */
 
 static void
 roff_free1(struct roff *r)
 {
 	struct tbl_node	*tbl;
 	struct eqn_node	*e;
 	int		 i;
 
 	while (NULL != (tbl = r->first_tbl)) {
 		r->first_tbl = tbl->next;
 		tbl_free(tbl);
 	}
 	r->first_tbl = r->last_tbl = r->tbl = NULL;
 
 	while (NULL != (e = r->first_eqn)) {
 		r->first_eqn = e->next;
 		eqn_free(e);
 	}
 	r->first_eqn = r->last_eqn = r->eqn = NULL;
 
 	while (r->last)
 		roffnode_pop(r);
 
 	free (r->rstack);
 	r->rstack = NULL;
 	r->rstacksz = 0;
 	r->rstackpos = -1;
 
 	roff_freereg(r->regtab);
 	r->regtab = NULL;
 
 	roff_freestr(r->strtab);
 	roff_freestr(r->xmbtab);
 	r->strtab = r->xmbtab = NULL;
 
 	if (r->xtab)
 		for (i = 0; i < 128; i++)
 			free(r->xtab[i].p);
 	free(r->xtab);
 	r->xtab = NULL;
 }
 
 void
 roff_reset(struct roff *r)
 {
 
 	roff_free1(r);
 	r->format = r->options & (MPARSE_MDOC | MPARSE_MAN);
 	r->control = 0;
 }
 
 void
 roff_free(struct roff *r)
 {
 
 	roff_free1(r);
 	free(r);
 }
 
 struct roff *
 roff_alloc(struct mparse *parse, int options)
 {
 	struct roff	*r;
 
 	r = mandoc_calloc(1, sizeof(struct roff));
 	r->parse = parse;
 	r->options = options;
 	r->format = options & (MPARSE_MDOC | MPARSE_MAN);
 	r->rstackpos = -1;
 
 	roffhash_init();
 
 	return r;
 }
 
 /* --- syntax tree state data management ---------------------------------- */
 
 static void
 roff_man_free1(struct roff_man *man)
 {
 
 	if (man->first != NULL)
 		roff_node_delete(man, man->first);
 	free(man->meta.msec);
 	free(man->meta.vol);
 	free(man->meta.os);
 	free(man->meta.arch);
 	free(man->meta.title);
 	free(man->meta.name);
 	free(man->meta.date);
 }
 
 static void
 roff_man_alloc1(struct roff_man *man)
 {
 
 	memset(&man->meta, 0, sizeof(man->meta));
 	man->first = mandoc_calloc(1, sizeof(*man->first));
 	man->first->type = ROFFT_ROOT;
 	man->last = man->first;
 	man->last_es = NULL;
 	man->flags = 0;
 	man->macroset = MACROSET_NONE;
 	man->lastsec = man->lastnamed = SEC_NONE;
 	man->next = ROFF_NEXT_CHILD;
 }
 
 void
 roff_man_reset(struct roff_man *man)
 {
 
 	roff_man_free1(man);
 	roff_man_alloc1(man);
 }
 
 void
 roff_man_free(struct roff_man *man)
 {
 
 	roff_man_free1(man);
 	free(man);
 }
 
 struct roff_man *
 roff_man_alloc(struct roff *roff, struct mparse *parse,
 	const char *defos, int quick)
 {
 	struct roff_man *man;
 
 	man = mandoc_calloc(1, sizeof(*man));
 	man->parse = parse;
 	man->roff = roff;
 	man->defos = defos;
 	man->quick = quick;
 	roff_man_alloc1(man);
 	return man;
 }
 
 /* --- syntax tree handling ----------------------------------------------- */
 
 struct roff_node *
 roff_node_alloc(struct roff_man *man, int line, int pos,
 	enum roff_type type, int tok)
 {
 	struct roff_node	*n;
 
 	n = mandoc_calloc(1, sizeof(*n));
 	n->line = line;
 	n->pos = pos;
 	n->tok = tok;
 	n->type = type;
 	n->sec = man->lastsec;
 
 	if (man->flags & MDOC_SYNOPSIS)
-		n->flags |= MDOC_SYNPRETTY;
+		n->flags |= NODE_SYNPRETTY;
 	else
-		n->flags &= ~MDOC_SYNPRETTY;
+		n->flags &= ~NODE_SYNPRETTY;
 	if (man->flags & MDOC_NEWLINE)
-		n->flags |= MDOC_LINE;
+		n->flags |= NODE_LINE;
 	man->flags &= ~MDOC_NEWLINE;
 
 	return n;
 }
 
 void
 roff_node_append(struct roff_man *man, struct roff_node *n)
 {
 
 	switch (man->next) {
 	case ROFF_NEXT_SIBLING:
 		if (man->last->next != NULL) {
 			n->next = man->last->next;
 			man->last->next->prev = n;
 		} else
 			man->last->parent->last = n;
 		man->last->next = n;
 		n->prev = man->last;
 		n->parent = man->last->parent;
 		break;
 	case ROFF_NEXT_CHILD:
+		if (man->last->child != NULL) {
+			n->next = man->last->child;
+			man->last->child->prev = n;
+		} else
+			man->last->last = n;
 		man->last->child = n;
 		n->parent = man->last;
-		n->parent->last = n;
 		break;
 	default:
 		abort();
 	}
 	man->last = n;
 
 	switch (n->type) {
 	case ROFFT_HEAD:
 		n->parent->head = n;
 		break;
 	case ROFFT_BODY:
 		if (n->end != ENDBODY_NOT)
 			return;
 		n->parent->body = n;
 		break;
 	case ROFFT_TAIL:
 		n->parent->tail = n;
 		break;
 	default:
 		return;
 	}
 
 	/*
 	 * Copy over the normalised-data pointer of our parent.  Not
 	 * everybody has one, but copying a null pointer is fine.
 	 */
 
 	n->norm = n->parent->norm;
 	assert(n->parent->type == ROFFT_BLOCK);
 }
 
 void
 roff_word_alloc(struct roff_man *man, int line, int pos, const char *word)
 {
 	struct roff_node	*n;
 
 	n = roff_node_alloc(man, line, pos, ROFFT_TEXT, TOKEN_NONE);
 	n->string = roff_strdup(man->roff, word);
 	roff_node_append(man, n);
-	if (man->macroset == MACROSET_MDOC)
-		n->flags |= MDOC_VALID | MDOC_ENDED;
-	else
-		n->flags |= MAN_VALID;
+	n->flags |= NODE_VALID | NODE_ENDED;
 	man->next = ROFF_NEXT_SIBLING;
 }
 
 void
 roff_word_append(struct roff_man *man, const char *word)
 {
 	struct roff_node	*n;
 	char			*addstr, *newstr;
 
 	n = man->last;
 	addstr = roff_strdup(man->roff, word);
 	mandoc_asprintf(&newstr, "%s %s", n->string, addstr);
 	free(addstr);
 	free(n->string);
 	n->string = newstr;
 	man->next = ROFF_NEXT_SIBLING;
 }
 
 void
 roff_elem_alloc(struct roff_man *man, int line, int pos, int tok)
 {
 	struct roff_node	*n;
 
 	n = roff_node_alloc(man, line, pos, ROFFT_ELEM, tok);
 	roff_node_append(man, n);
 	man->next = ROFF_NEXT_CHILD;
 }
 
 struct roff_node *
 roff_block_alloc(struct roff_man *man, int line, int pos, int tok)
 {
 	struct roff_node	*n;
 
 	n = roff_node_alloc(man, line, pos, ROFFT_BLOCK, tok);
 	roff_node_append(man, n);
 	man->next = ROFF_NEXT_CHILD;
 	return n;
 }
 
 struct roff_node *
 roff_head_alloc(struct roff_man *man, int line, int pos, int tok)
 {
 	struct roff_node	*n;
 
 	n = roff_node_alloc(man, line, pos, ROFFT_HEAD, tok);
 	roff_node_append(man, n);
 	man->next = ROFF_NEXT_CHILD;
 	return n;
 }
 
 struct roff_node *
 roff_body_alloc(struct roff_man *man, int line, int pos, int tok)
 {
 	struct roff_node	*n;
 
 	n = roff_node_alloc(man, line, pos, ROFFT_BODY, tok);
 	roff_node_append(man, n);
 	man->next = ROFF_NEXT_CHILD;
 	return n;
 }
 
 void
 roff_addeqn(struct roff_man *man, const struct eqn *eqn)
 {
 	struct roff_node	*n;
 
 	n = roff_node_alloc(man, eqn->ln, eqn->pos, ROFFT_EQN, TOKEN_NONE);
 	n->eqn = eqn;
 	if (eqn->ln > man->last->line)
-		n->flags |= MDOC_LINE;
+		n->flags |= NODE_LINE;
 	roff_node_append(man, n);
 	man->next = ROFF_NEXT_SIBLING;
 }
 
 void
 roff_addtbl(struct roff_man *man, const struct tbl_span *tbl)
 {
 	struct roff_node	*n;
 
 	if (man->macroset == MACROSET_MAN)
 		man_breakscope(man, TOKEN_NONE);
 	n = roff_node_alloc(man, tbl->line, 0, ROFFT_TBL, TOKEN_NONE);
 	n->span = tbl;
 	roff_node_append(man, n);
-	if (man->macroset == MACROSET_MDOC)
-		n->flags |= MDOC_VALID | MDOC_ENDED;
-	else
-		n->flags |= MAN_VALID;
+	n->flags |= NODE_VALID | NODE_ENDED;
 	man->next = ROFF_NEXT_SIBLING;
 }
 
 void
 roff_node_unlink(struct roff_man *man, struct roff_node *n)
 {
 
 	/* Adjust siblings. */
 
 	if (n->prev)
 		n->prev->next = n->next;
 	if (n->next)
 		n->next->prev = n->prev;
 
 	/* Adjust parent. */
 
 	if (n->parent != NULL) {
 		if (n->parent->child == n)
 			n->parent->child = n->next;
 		if (n->parent->last == n)
 			n->parent->last = n->prev;
 	}
 
 	/* Adjust parse point. */
 
 	if (man == NULL)
 		return;
 	if (man->last == n) {
 		if (n->prev == NULL) {
 			man->last = n->parent;
 			man->next = ROFF_NEXT_CHILD;
 		} else {
 			man->last = n->prev;
 			man->next = ROFF_NEXT_SIBLING;
 		}
 	}
 	if (man->first == n)
 		man->first = NULL;
 }
 
 void
 roff_node_free(struct roff_node *n)
 {
 
 	if (n->args != NULL)
 		mdoc_argv_free(n->args);
 	if (n->type == ROFFT_BLOCK || n->type == ROFFT_ELEM)
 		free(n->norm);
 	free(n->string);
 	free(n);
 }
 
 void
 roff_node_delete(struct roff_man *man, struct roff_node *n)
 {
 
 	while (n->child != NULL)
 		roff_node_delete(man, n->child);
 	roff_node_unlink(man, n);
 	roff_node_free(n);
 }
 
 void
 deroff(char **dest, const struct roff_node *n)
 {
 	char	*cp;
 	size_t	 sz;
 
 	if (n->type != ROFFT_TEXT) {
 		for (n = n->child; n != NULL; n = n->next)
 			deroff(dest, n);
 		return;
 	}
 
-	/* Skip leading whitespace and escape sequences. */
+	/* Skip leading whitespace. */
 
-	cp = n->string;
-	while (*cp != '\0') {
-		if ('\\' == *cp) {
+	for (cp = n->string; *cp != '\0'; cp++) {
+		if (cp[0] == '\\' && strchr(" %&0^|~", cp[1]) != NULL)
 			cp++;
-			mandoc_escape((const char **)&cp, NULL, NULL);
-		} else if (isspace((unsigned char)*cp))
-			cp++;
-		else
+		else if ( ! isspace((unsigned char)*cp))
 			break;
 	}
 
 	/* Skip trailing whitespace. */
 
 	for (sz = strlen(cp); sz; sz--)
 		if ( ! isspace((unsigned char)cp[sz-1]))
 			break;
 
 	/* Skip empty strings. */
 
 	if (sz == 0)
 		return;
 
 	if (*dest == NULL) {
 		*dest = mandoc_strndup(cp, sz);
 		return;
 	}
 
 	mandoc_asprintf(&cp, "%s %*s", *dest, (int)sz, cp);
 	free(*dest);
 	*dest = cp;
 }
 
 /* --- main functions of the roff parser ---------------------------------- */
 
 /*
  * In the current line, expand escape sequences that tend to get
  * used in numerical expressions and conditional requests.
  * Also check the syntax of the remaining escape sequences.
  */
 static enum rofferr
 roff_res(struct roff *r, struct buf *buf, int ln, int pos)
 {
 	char		 ubuf[24]; /* buffer to print the number */
 	const char	*start;	/* start of the string to process */
 	char		*stesc;	/* start of an escape sequence ('\\') */
 	const char	*stnam;	/* start of the name, after "[(*" */
 	const char	*cp;	/* end of the name, e.g. before ']' */
 	const char	*res;	/* the string to be substituted */
 	char		*nbuf;	/* new buffer to copy buf->buf to */
 	size_t		 maxl;  /* expected length of the escape name */
 	size_t		 naml;	/* actual length of the escape name */
 	enum mandoc_esc	 esc;	/* type of the escape sequence */
 	int		 inaml;	/* length returned from mandoc_escape() */
 	int		 expand_count;	/* to avoid infinite loops */
 	int		 npos;	/* position in numeric expression */
 	int		 arg_complete; /* argument not interrupted by eol */
 	char		 term;	/* character terminating the escape */
 
 	expand_count = 0;
 	start = buf->buf + pos;
 	stesc = strchr(start, '\0') - 1;
 	while (stesc-- > start) {
 
 		/* Search backwards for the next backslash. */
 
 		if (*stesc != '\\')
 			continue;
 
 		/* If it is escaped, skip it. */
 
 		for (cp = stesc - 1; cp >= start; cp--)
 			if (*cp != '\\')
 				break;
 
 		if ((stesc - cp) % 2 == 0) {
 			stesc = (char *)cp;
 			continue;
 		}
 
 		/* Decide whether to expand or to check only. */
 
 		term = '\0';
 		cp = stesc + 1;
 		switch (*cp) {
 		case '*':
 			res = NULL;
 			break;
 		case 'B':
 		case 'w':
 			term = cp[1];
 			/* FALLTHROUGH */
 		case 'n':
 			res = ubuf;
 			break;
 		default:
 			esc = mandoc_escape(&cp, &stnam, &inaml);
 			if (esc == ESCAPE_ERROR ||
 			    (esc == ESCAPE_SPECIAL &&
 			     mchars_spec2cp(stnam, inaml) < 0))
 				mandoc_vmsg(MANDOCERR_ESC_BAD,
 				    r->parse, ln, (int)(stesc - buf->buf),
 				    "%.*s", (int)(cp - stesc), stesc);
 			continue;
 		}
 
 		if (EXPAND_LIMIT < ++expand_count) {
 			mandoc_msg(MANDOCERR_ROFFLOOP, r->parse,
 			    ln, (int)(stesc - buf->buf), NULL);
 			return ROFF_IGN;
 		}
 
 		/*
 		 * The third character decides the length
 		 * of the name of the string or register.
 		 * Save a pointer to the name.
 		 */
 
 		if (term == '\0') {
 			switch (*++cp) {
 			case '\0':
 				maxl = 0;
 				break;
 			case '(':
 				cp++;
 				maxl = 2;
 				break;
 			case '[':
 				cp++;
 				term = ']';
 				maxl = 0;
 				break;
 			default:
 				maxl = 1;
 				break;
 			}
 		} else {
 			cp += 2;
 			maxl = 0;
 		}
 		stnam = cp;
 
 		/* Advance to the end of the name. */
 
 		naml = 0;
 		arg_complete = 1;
 		while (maxl == 0 || naml < maxl) {
 			if (*cp == '\0') {
 				mandoc_msg(MANDOCERR_ESC_BAD, r->parse,
 				    ln, (int)(stesc - buf->buf), stesc);
 				arg_complete = 0;
 				break;
 			}
 			if (maxl == 0 && *cp == term) {
 				cp++;
 				break;
 			}
 			if (*cp++ != '\\' || stesc[1] != 'w') {
 				naml++;
 				continue;
 			}
 			switch (mandoc_escape(&cp, NULL, NULL)) {
 			case ESCAPE_SPECIAL:
 			case ESCAPE_UNICODE:
 			case ESCAPE_NUMBERED:
 			case ESCAPE_OVERSTRIKE:
 				naml++;
 				break;
 			default:
 				break;
 			}
 		}
 
 		/*
 		 * Retrieve the replacement string; if it is
 		 * undefined, resume searching for escapes.
 		 */
 
 		switch (stesc[1]) {
 		case '*':
 			if (arg_complete)
 				res = roff_getstrn(r, stnam, naml);
 			break;
 		case 'B':
 			npos = 0;
 			ubuf[0] = arg_complete &&
 			    roff_evalnum(r, ln, stnam, &npos,
 			      NULL, ROFFNUM_SCALE) &&
 			    stnam + npos + 1 == cp ? '1' : '0';
 			ubuf[1] = '\0';
 			break;
 		case 'n':
 			if (arg_complete)
 				(void)snprintf(ubuf, sizeof(ubuf), "%d",
 				    roff_getregn(r, stnam, naml));
 			else
 				ubuf[0] = '\0';
 			break;
 		case 'w':
 			/* use even incomplete args */
 			(void)snprintf(ubuf, sizeof(ubuf), "%d",
 			    24 * (int)naml);
 			break;
 		}
 
 		if (res == NULL) {
 			mandoc_vmsg(MANDOCERR_STR_UNDEF,
 			    r->parse, ln, (int)(stesc - buf->buf),
 			    "%.*s", (int)naml, stnam);
 			res = "";
 		} else if (buf->sz + strlen(res) > SHRT_MAX) {
 			mandoc_msg(MANDOCERR_ROFFLOOP, r->parse,
 			    ln, (int)(stesc - buf->buf), NULL);
 			return ROFF_IGN;
 		}
 
 		/* Replace the escape sequence by the string. */
 
 		*stesc = '\0';
 		buf->sz = mandoc_asprintf(&nbuf, "%s%s%s",
 		    buf->buf, res, cp) + 1;
 
 		/* Prepare for the next replacement. */
 
 		start = nbuf + pos;
 		stesc = nbuf + (stesc - buf->buf) + strlen(res);
 		free(buf->buf);
 		buf->buf = nbuf;
 	}
 	return ROFF_CONT;
 }
 
 /*
  * Process text streams.
  */
 static enum rofferr
 roff_parsetext(struct buf *buf, int pos, int *offs)
 {
 	size_t		 sz;
 	const char	*start;
 	char		*p;
 	int		 isz;
 	enum mandoc_esc	 esc;
 
 	/* Spring the input line trap. */
 
 	if (roffit_lines == 1) {
 		isz = mandoc_asprintf(&p, "%s\n.%s", buf->buf, roffit_macro);
 		free(buf->buf);
 		buf->buf = p;
 		buf->sz = isz + 1;
 		*offs = 0;
 		free(roffit_macro);
 		roffit_lines = 0;
 		return ROFF_REPARSE;
 	} else if (roffit_lines > 1)
 		--roffit_lines;
 
 	/* Convert all breakable hyphens into ASCII_HYPH. */
 
 	start = p = buf->buf + pos;
 
 	while (*p != '\0') {
 		sz = strcspn(p, "-\\");
 		p += sz;
 
 		if (*p == '\0')
 			break;
 
 		if (*p == '\\') {
 			/* Skip over escapes. */
 			p++;
 			esc = mandoc_escape((const char **)&p, NULL, NULL);
 			if (esc == ESCAPE_ERROR)
 				break;
 			while (*p == '-')
 				p++;
 			continue;
 		} else if (p == start) {
 			p++;
 			continue;
 		}
 
 		if (isalpha((unsigned char)p[-1]) &&
 		    isalpha((unsigned char)p[1]))
 			*p = ASCII_HYPH;
 		p++;
 	}
 	return ROFF_CONT;
 }
 
 enum rofferr
 roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs)
 {
 	enum rofft	 t;
 	enum rofferr	 e;
 	int		 pos;	/* parse point */
 	int		 spos;	/* saved parse point for messages */
 	int		 ppos;	/* original offset in buf->buf */
 	int		 ctl;	/* macro line (boolean) */
 
 	ppos = pos = *offs;
 
 	/* Handle in-line equation delimiters. */
 
 	if (r->tbl == NULL &&
 	    r->last_eqn != NULL && r->last_eqn->delim &&
 	    (r->eqn == NULL || r->eqn_inline)) {
 		e = roff_eqndelim(r, buf, pos);
 		if (e == ROFF_REPARSE)
 			return e;
 		assert(e == ROFF_CONT);
 	}
 
 	/* Expand some escape sequences. */
 
 	e = roff_res(r, buf, ln, pos);
 	if (e == ROFF_IGN)
 		return e;
 	assert(e == ROFF_CONT);
 
 	ctl = roff_getcontrol(r, buf->buf, &pos);
 
 	/*
 	 * First, if a scope is open and we're not a macro, pass the
 	 * text through the macro's filter.
 	 * Equations process all content themselves.
 	 * Tables process almost all content themselves, but we want
 	 * to warn about macros before passing it there.
 	 */
 
 	if (r->last != NULL && ! ctl) {
 		t = r->last->tok;
 		assert(roffs[t].text);
 		e = (*roffs[t].text)(r, t, buf, ln, pos, pos, offs);
 		assert(e == ROFF_IGN || e == ROFF_CONT);
 		if (e != ROFF_CONT)
 			return e;
 	}
 	if (r->eqn != NULL)
 		return eqn_read(&r->eqn, ln, buf->buf, ppos, offs);
 	if (r->tbl != NULL && ( ! ctl || buf->buf[pos] == '\0'))
 		return tbl_read(r->tbl, ln, buf->buf, ppos);
 	if ( ! ctl)
 		return roff_parsetext(buf, pos, offs);
 
 	/* Skip empty request lines. */
 
 	if (buf->buf[pos] == '"') {
 		mandoc_msg(MANDOCERR_COMMENT_BAD, r->parse,
 		    ln, pos, NULL);
 		return ROFF_IGN;
 	} else if (buf->buf[pos] == '\0')
 		return ROFF_IGN;
 
 	/*
 	 * If a scope is open, go to the child handler for that macro,
 	 * as it may want to preprocess before doing anything with it.
 	 * Don't do so if an equation is open.
 	 */
 
 	if (r->last) {
 		t = r->last->tok;
 		assert(roffs[t].sub);
 		return (*roffs[t].sub)(r, t, buf, ln, ppos, pos, offs);
 	}
 
 	/* No scope is open.  This is a new request or macro. */
 
 	spos = pos;
 	t = roff_parse(r, buf->buf, &pos, ln, ppos);
 
 	/* Tables ignore most macros. */
 
 	if (r->tbl != NULL && (t == ROFF_MAX || t == ROFF_TS)) {
 		mandoc_msg(MANDOCERR_TBLMACRO, r->parse,
 		    ln, pos, buf->buf + spos);
 		if (t == ROFF_TS)
 			return ROFF_IGN;
 		while (buf->buf[pos] != '\0' && buf->buf[pos] != ' ')
 			pos++;
 		while (buf->buf[pos] != '\0' && buf->buf[pos] == ' ')
 			pos++;
 		return tbl_read(r->tbl, ln, buf->buf, pos);
 	}
 
 	/*
 	 * This is neither a roff request nor a user-defined macro.
 	 * Let the standard macro set parsers handle it.
 	 */
 
 	if (t == ROFF_MAX)
 		return ROFF_CONT;
 
 	/* Execute a roff request or a user defined macro. */
 
 	assert(roffs[t].proc);
 	return (*roffs[t].proc)(r, t, buf, ln, ppos, pos, offs);
 }
 
 void
 roff_endparse(struct roff *r)
 {
 
 	if (r->last)
 		mandoc_msg(MANDOCERR_BLK_NOEND, r->parse,
 		    r->last->line, r->last->col,
 		    roffs[r->last->tok].name);
 
 	if (r->eqn) {
 		mandoc_msg(MANDOCERR_BLK_NOEND, r->parse,
 		    r->eqn->eqn.ln, r->eqn->eqn.pos, "EQ");
 		eqn_end(&r->eqn);
 	}
 
 	if (r->tbl) {
 		mandoc_msg(MANDOCERR_BLK_NOEND, r->parse,
 		    r->tbl->line, r->tbl->pos, "TS");
 		tbl_end(&r->tbl);
 	}
 }
 
 /*
  * Parse a roff node's type from the input buffer.  This must be in the
  * form of ".foo xxx" in the usual way.
  */
 static enum rofft
 roff_parse(struct roff *r, char *buf, int *pos, int ln, int ppos)
 {
 	char		*cp;
 	const char	*mac;
 	size_t		 maclen;
 	enum rofft	 t;
 
 	cp = buf + *pos;
 
 	if ('\0' == *cp || '"' == *cp || '\t' == *cp || ' ' == *cp)
 		return ROFF_MAX;
 
 	mac = cp;
 	maclen = roff_getname(r, &cp, ln, ppos);
 
 	t = (r->current_string = roff_getstrn(r, mac, maclen))
 	    ? ROFF_USERDEF : roffhash_find(mac, maclen);
 
 	if (ROFF_MAX != t)
 		*pos = cp - buf;
 
 	return t;
 }
 
 /* --- handling of request blocks ----------------------------------------- */
 
 static enum rofferr
 roff_cblock(ROFF_ARGS)
 {
 
 	/*
 	 * A block-close `..' should only be invoked as a child of an
 	 * ignore macro, otherwise raise a warning and just ignore it.
 	 */
 
 	if (r->last == NULL) {
 		mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse,
 		    ln, ppos, "..");
 		return ROFF_IGN;
 	}
 
 	switch (r->last->tok) {
 	case ROFF_am:
 		/* ROFF_am1 is remapped to ROFF_am in roff_block(). */
 	case ROFF_ami:
 	case ROFF_de:
 		/* ROFF_de1 is remapped to ROFF_de in roff_block(). */
 	case ROFF_dei:
 	case ROFF_ig:
 		break;
 	default:
 		mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse,
 		    ln, ppos, "..");
 		return ROFF_IGN;
 	}
 
 	if (buf->buf[pos] != '\0')
 		mandoc_vmsg(MANDOCERR_ARG_SKIP, r->parse, ln, pos,
 		    ".. %s", buf->buf + pos);
 
 	roffnode_pop(r);
 	roffnode_cleanscope(r);
 	return ROFF_IGN;
 
 }
 
 static void
 roffnode_cleanscope(struct roff *r)
 {
 
 	while (r->last) {
 		if (--r->last->endspan != 0)
 			break;
 		roffnode_pop(r);
 	}
 }
 
 static void
 roff_ccond(struct roff *r, int ln, int ppos)
 {
 
 	if (NULL == r->last) {
 		mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse,
 		    ln, ppos, "\\}");
 		return;
 	}
 
 	switch (r->last->tok) {
 	case ROFF_el:
 	case ROFF_ie:
 	case ROFF_if:
 		break;
 	default:
 		mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse,
 		    ln, ppos, "\\}");
 		return;
 	}
 
 	if (r->last->endspan > -1) {
 		mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse,
 		    ln, ppos, "\\}");
 		return;
 	}
 
 	roffnode_pop(r);
 	roffnode_cleanscope(r);
 	return;
 }
 
 static enum rofferr
 roff_block(ROFF_ARGS)
 {
 	const char	*name;
 	char		*iname, *cp;
 	size_t		 namesz;
 
 	/* Ignore groff compatibility mode for now. */
 
 	if (tok == ROFF_de1)
 		tok = ROFF_de;
 	else if (tok == ROFF_dei1)
 		tok = ROFF_dei;
 	else if (tok == ROFF_am1)
 		tok = ROFF_am;
 	else if (tok == ROFF_ami1)
 		tok = ROFF_ami;
 
 	/* Parse the macro name argument. */
 
 	cp = buf->buf + pos;
 	if (tok == ROFF_ig) {
 		iname = NULL;
 		namesz = 0;
 	} else {
 		iname = cp;
 		namesz = roff_getname(r, &cp, ln, ppos);
 		iname[namesz] = '\0';
 	}
 
 	/* Resolve the macro name argument if it is indirect. */
 
 	if (namesz && (tok == ROFF_dei || tok == ROFF_ami)) {
 		if ((name = roff_getstrn(r, iname, namesz)) == NULL) {
 			mandoc_vmsg(MANDOCERR_STR_UNDEF,
 			    r->parse, ln, (int)(iname - buf->buf),
 			    "%.*s", (int)namesz, iname);
 			namesz = 0;
 		} else
 			namesz = strlen(name);
 	} else
 		name = iname;
 
 	if (namesz == 0 && tok != ROFF_ig) {
 		mandoc_msg(MANDOCERR_REQ_EMPTY, r->parse,
 		    ln, ppos, roffs[tok].name);
 		return ROFF_IGN;
 	}
 
 	roffnode_push(r, tok, name, ln, ppos);
 
 	/*
 	 * At the beginning of a `de' macro, clear the existing string
 	 * with the same name, if there is one.  New content will be
 	 * appended from roff_block_text() in multiline mode.
 	 */
 
 	if (tok == ROFF_de || tok == ROFF_dei)
 		roff_setstrn(&r->strtab, name, namesz, "", 0, 0);
 
 	if (*cp == '\0')
 		return ROFF_IGN;
 
 	/* Get the custom end marker. */
 
 	iname = cp;
 	namesz = roff_getname(r, &cp, ln, ppos);
 
 	/* Resolve the end marker if it is indirect. */
 
 	if (namesz && (tok == ROFF_dei || tok == ROFF_ami)) {
 		if ((name = roff_getstrn(r, iname, namesz)) == NULL) {
 			mandoc_vmsg(MANDOCERR_STR_UNDEF,
 			    r->parse, ln, (int)(iname - buf->buf),
 			    "%.*s", (int)namesz, iname);
 			namesz = 0;
 		} else
 			namesz = strlen(name);
 	} else
 		name = iname;
 
 	if (namesz)
 		r->last->end = mandoc_strndup(name, namesz);
 
 	if (*cp != '\0')
 		mandoc_vmsg(MANDOCERR_ARG_EXCESS, r->parse,
 		    ln, pos, ".%s ... %s", roffs[tok].name, cp);
 
 	return ROFF_IGN;
 }
 
 static enum rofferr
 roff_block_sub(ROFF_ARGS)
 {
 	enum rofft	t;
 	int		i, j;
 
 	/*
 	 * First check whether a custom macro exists at this level.  If
 	 * it does, then check against it.  This is some of groff's
 	 * stranger behaviours.  If we encountered a custom end-scope
 	 * tag and that tag also happens to be a "real" macro, then we
 	 * need to try interpreting it again as a real macro.  If it's
 	 * not, then return ignore.  Else continue.
 	 */
 
 	if (r->last->end) {
 		for (i = pos, j = 0; r->last->end[j]; j++, i++)
 			if (buf->buf[i] != r->last->end[j])
 				break;
 
 		if (r->last->end[j] == '\0' &&
 		    (buf->buf[i] == '\0' ||
 		     buf->buf[i] == ' ' ||
 		     buf->buf[i] == '\t')) {
 			roffnode_pop(r);
 			roffnode_cleanscope(r);
 
 			while (buf->buf[i] == ' ' || buf->buf[i] == '\t')
 				i++;
 
 			pos = i;
 			if (roff_parse(r, buf->buf, &pos, ln, ppos) !=
 			    ROFF_MAX)
 				return ROFF_RERUN;
 			return ROFF_IGN;
 		}
 	}
 
 	/*
 	 * If we have no custom end-query or lookup failed, then try
 	 * pulling it out of the hashtable.
 	 */
 
 	t = roff_parse(r, buf->buf, &pos, ln, ppos);
 
 	if (t != ROFF_cblock) {
 		if (tok != ROFF_ig)
 			roff_setstr(r, r->last->name, buf->buf + ppos, 2);
 		return ROFF_IGN;
 	}
 
 	assert(roffs[t].proc);
 	return (*roffs[t].proc)(r, t, buf, ln, ppos, pos, offs);
 }
 
 static enum rofferr
 roff_block_text(ROFF_ARGS)
 {
 
 	if (tok != ROFF_ig)
 		roff_setstr(r, r->last->name, buf->buf + pos, 2);
 
 	return ROFF_IGN;
 }
 
 static enum rofferr
 roff_cond_sub(ROFF_ARGS)
 {
 	enum rofft	 t;
 	char		*ep;
 	int		 rr;
 
 	rr = r->last->rule;
 	roffnode_cleanscope(r);
 	t = roff_parse(r, buf->buf, &pos, ln, ppos);
 
 	/*
 	 * Fully handle known macros when they are structurally
 	 * required or when the conditional evaluated to true.
 	 */
 
 	if ((t != ROFF_MAX) &&
 	    (rr || roffs[t].flags & ROFFMAC_STRUCT)) {
 		assert(roffs[t].proc);
 		return (*roffs[t].proc)(r, t, buf, ln, ppos, pos, offs);
 	}
 
 	/*
 	 * If `\}' occurs on a macro line without a preceding macro,
 	 * drop the line completely.
 	 */
 
 	ep = buf->buf + pos;
 	if (ep[0] == '\\' && ep[1] == '}')
 		rr = 0;
 
 	/* Always check for the closing delimiter `\}'. */
 
 	while ((ep = strchr(ep, '\\')) != NULL) {
 		if (*(++ep) == '}') {
 			*ep = '&';
 			roff_ccond(r, ln, ep - buf->buf - 1);
 		}
 		if (*ep != '\0')
 			++ep;
 	}
 	return rr ? ROFF_CONT : ROFF_IGN;
 }
 
 static enum rofferr
 roff_cond_text(ROFF_ARGS)
 {
 	char		*ep;
 	int		 rr;
 
 	rr = r->last->rule;
 	roffnode_cleanscope(r);
 
 	ep = buf->buf + pos;
 	while ((ep = strchr(ep, '\\')) != NULL) {
 		if (*(++ep) == '}') {
 			*ep = '&';
 			roff_ccond(r, ln, ep - buf->buf - 1);
 		}
 		if (*ep != '\0')
 			++ep;
 	}
 	return rr ? ROFF_CONT : ROFF_IGN;
 }
 
 /* --- handling of numeric and conditional expressions -------------------- */
 
 /*
  * Parse a single signed integer number.  Stop at the first non-digit.
  * If there is at least one digit, return success and advance the
  * parse point, else return failure and let the parse point unchanged.
  * Ignore overflows, treat them just like the C language.
  */
 static int
 roff_getnum(const char *v, int *pos, int *res, int flags)
 {
 	int	 myres, scaled, n, p;
 
 	if (NULL == res)
 		res = &myres;
 
 	p = *pos;
 	n = v[p] == '-';
 	if (n || v[p] == '+')
 		p++;
 
 	if (flags & ROFFNUM_WHITE)
 		while (isspace((unsigned char)v[p]))
 			p++;
 
 	for (*res = 0; isdigit((unsigned char)v[p]); p++)
 		*res = 10 * *res + v[p] - '0';
 	if (p == *pos + n)
 		return 0;
 
 	if (n)
 		*res = -*res;
 
 	/* Each number may be followed by one optional scaling unit. */
 
 	switch (v[p]) {
 	case 'f':
 		scaled = *res * 65536;
 		break;
 	case 'i':
 		scaled = *res * 240;
 		break;
 	case 'c':
 		scaled = *res * 240 / 2.54;
 		break;
 	case 'v':
 	case 'P':
 		scaled = *res * 40;
 		break;
 	case 'm':
 	case 'n':
 		scaled = *res * 24;
 		break;
 	case 'p':
 		scaled = *res * 10 / 3;
 		break;
 	case 'u':
 		scaled = *res;
 		break;
 	case 'M':
 		scaled = *res * 6 / 25;
 		break;
 	default:
 		scaled = *res;
 		p--;
 		break;
 	}
 	if (flags & ROFFNUM_SCALE)
 		*res = scaled;
 
 	*pos = p + 1;
 	return 1;
 }
 
 /*
  * Evaluate a string comparison condition.
  * The first character is the delimiter.
  * Succeed if the string up to its second occurrence
  * matches the string up to its third occurence.
  * Advance the cursor after the third occurrence
  * or lacking that, to the end of the line.
  */
 static int
 roff_evalstrcond(const char *v, int *pos)
 {
 	const char	*s1, *s2, *s3;
 	int		 match;
 
 	match = 0;
 	s1 = v + *pos;		/* initial delimiter */
 	s2 = s1 + 1;		/* for scanning the first string */
 	s3 = strchr(s2, *s1);	/* for scanning the second string */
 
 	if (NULL == s3)		/* found no middle delimiter */
 		goto out;
 
 	while ('\0' != *++s3) {
 		if (*s2 != *s3) {  /* mismatch */
 			s3 = strchr(s3, *s1);
 			break;
 		}
 		if (*s3 == *s1) {  /* found the final delimiter */
 			match = 1;
 			break;
 		}
 		s2++;
 	}
 
 out:
 	if (NULL == s3)
 		s3 = strchr(s2, '\0');
 	else if (*s3 != '\0')
 		s3++;
 	*pos = s3 - v;
 	return match;
 }
 
 /*
  * Evaluate an optionally negated single character, numerical,
  * or string condition.
  */
 static int
 roff_evalcond(struct roff *r, int ln, char *v, int *pos)
 {
 	char	*cp, *name;
 	size_t	 sz;
 	int	 number, savepos, wanttrue;
 
 	if ('!' == v[*pos]) {
 		wanttrue = 0;
 		(*pos)++;
 	} else
 		wanttrue = 1;
 
 	switch (v[*pos]) {
 	case '\0':
 		return 0;
 	case 'n':
 	case 'o':
 		(*pos)++;
 		return wanttrue;
 	case 'c':
 	case 'd':
 	case 'e':
 	case 't':
 	case 'v':
 		(*pos)++;
 		return !wanttrue;
 	case 'r':
 		cp = name = v + ++*pos;
 		sz = roff_getname(r, &cp, ln, *pos);
 		*pos = cp - v;
 		return (sz && roff_hasregn(r, name, sz)) == wanttrue;
 	default:
 		break;
 	}
 
 	savepos = *pos;
 	if (roff_evalnum(r, ln, v, pos, &number, ROFFNUM_SCALE))
 		return (number > 0) == wanttrue;
 	else if (*pos == savepos)
 		return roff_evalstrcond(v, pos) == wanttrue;
 	else
 		return 0;
 }
 
 static enum rofferr
 roff_line_ignore(ROFF_ARGS)
 {
 
 	return ROFF_IGN;
 }
 
 static enum rofferr
 roff_insec(ROFF_ARGS)
 {
 
 	mandoc_msg(MANDOCERR_REQ_INSEC, r->parse,
 	    ln, ppos, roffs[tok].name);
 	return ROFF_IGN;
 }
 
 static enum rofferr
 roff_unsupp(ROFF_ARGS)
 {
 
 	mandoc_msg(MANDOCERR_REQ_UNSUPP, r->parse,
 	    ln, ppos, roffs[tok].name);
 	return ROFF_IGN;
 }
 
 static enum rofferr
 roff_cond(ROFF_ARGS)
 {
 
 	roffnode_push(r, tok, NULL, ln, ppos);
 
 	/*
 	 * An `.el' has no conditional body: it will consume the value
 	 * of the current rstack entry set in prior `ie' calls or
 	 * defaults to DENY.
 	 *
 	 * If we're not an `el', however, then evaluate the conditional.
 	 */
 
 	r->last->rule = tok == ROFF_el ?
 	    (r->rstackpos < 0 ? 0 : r->rstack[r->rstackpos--]) :
 	    roff_evalcond(r, ln, buf->buf, &pos);
 
 	/*
 	 * An if-else will put the NEGATION of the current evaluated
 	 * conditional into the stack of rules.
 	 */
 
 	if (tok == ROFF_ie) {
 		if (r->rstackpos + 1 == r->rstacksz) {
 			r->rstacksz += 16;
 			r->rstack = mandoc_reallocarray(r->rstack,
 			    r->rstacksz, sizeof(int));
 		}
 		r->rstack[++r->rstackpos] = !r->last->rule;
 	}
 
 	/* If the parent has false as its rule, then so do we. */
 
 	if (r->last->parent && !r->last->parent->rule)
 		r->last->rule = 0;
 
 	/*
 	 * Determine scope.
 	 * If there is nothing on the line after the conditional,
 	 * not even whitespace, use next-line scope.
 	 */
 
 	if (buf->buf[pos] == '\0') {
 		r->last->endspan = 2;
 		goto out;
 	}
 
 	while (buf->buf[pos] == ' ')
 		pos++;
 
 	/* An opening brace requests multiline scope. */
 
 	if (buf->buf[pos] == '\\' && buf->buf[pos + 1] == '{') {
 		r->last->endspan = -1;
 		pos += 2;
 		while (buf->buf[pos] == ' ')
 			pos++;
 		goto out;
 	}
 
 	/*
 	 * Anything else following the conditional causes
 	 * single-line scope.  Warn if the scope contains
 	 * nothing but trailing whitespace.
 	 */
 
 	if (buf->buf[pos] == '\0')
 		mandoc_msg(MANDOCERR_COND_EMPTY, r->parse,
 		    ln, ppos, roffs[tok].name);
 
 	r->last->endspan = 1;
 
 out:
 	*offs = pos;
 	return ROFF_RERUN;
 }
 
 static enum rofferr
 roff_ds(ROFF_ARGS)
 {
 	char		*string;
 	const char	*name;
 	size_t		 namesz;
 
 	/* Ignore groff compatibility mode for now. */
 
 	if (tok == ROFF_ds1)
 		tok = ROFF_ds;
 	else if (tok == ROFF_as1)
 		tok = ROFF_as;
 
 	/*
 	 * The first word is the name of the string.
 	 * If it is empty or terminated by an escape sequence,
 	 * abort the `ds' request without defining anything.
 	 */
 
 	name = string = buf->buf + pos;
 	if (*name == '\0')
 		return ROFF_IGN;
 
 	namesz = roff_getname(r, &string, ln, pos);
 	if (name[namesz] == '\\')
 		return ROFF_IGN;
 
 	/* Read past the initial double-quote, if any. */
 	if (*string == '"')
 		string++;
 
 	/* The rest is the value. */
 	roff_setstrn(&r->strtab, name, namesz, string, strlen(string),
 	    ROFF_as == tok);
 	return ROFF_IGN;
 }
 
 /*
  * Parse a single operator, one or two characters long.
  * If the operator is recognized, return success and advance the
  * parse point, else return failure and let the parse point unchanged.
  */
 static int
 roff_getop(const char *v, int *pos, char *res)
 {
 
 	*res = v[*pos];
 
 	switch (*res) {
 	case '+':
 	case '-':
 	case '*':
 	case '/':
 	case '%':
 	case '&':
 	case ':':
 		break;
 	case '<':
 		switch (v[*pos + 1]) {
 		case '=':
 			*res = 'l';
 			(*pos)++;
 			break;
 		case '>':
 			*res = '!';
 			(*pos)++;
 			break;
 		case '?':
 			*res = 'i';
 			(*pos)++;
 			break;
 		default:
 			break;
 		}
 		break;
 	case '>':
 		switch (v[*pos + 1]) {
 		case '=':
 			*res = 'g';
 			(*pos)++;
 			break;
 		case '?':
 			*res = 'a';
 			(*pos)++;
 			break;
 		default:
 			break;
 		}
 		break;
 	case '=':
 		if ('=' == v[*pos + 1])
 			(*pos)++;
 		break;
 	default:
 		return 0;
 	}
 	(*pos)++;
 
 	return *res;
 }
 
 /*
  * Evaluate either a parenthesized numeric expression
  * or a single signed integer number.
  */
 static int
 roff_evalpar(struct roff *r, int ln,
 	const char *v, int *pos, int *res, int flags)
 {
 
 	if ('(' != v[*pos])
 		return roff_getnum(v, pos, res, flags);
 
 	(*pos)++;
 	if ( ! roff_evalnum(r, ln, v, pos, res, flags | ROFFNUM_WHITE))
 		return 0;
 
 	/*
 	 * Omission of the closing parenthesis
 	 * is an error in validation mode,
 	 * but ignored in evaluation mode.
 	 */
 
 	if (')' == v[*pos])
 		(*pos)++;
 	else if (NULL == res)
 		return 0;
 
 	return 1;
 }
 
 /*
  * Evaluate a complete numeric expression.
  * Proceed left to right, there is no concept of precedence.
  */
 static int
 roff_evalnum(struct roff *r, int ln, const char *v,
 	int *pos, int *res, int flags)
 {
 	int		 mypos, operand2;
 	char		 operator;
 
 	if (NULL == pos) {
 		mypos = 0;
 		pos = &mypos;
 	}
 
 	if (flags & ROFFNUM_WHITE)
 		while (isspace((unsigned char)v[*pos]))
 			(*pos)++;
 
 	if ( ! roff_evalpar(r, ln, v, pos, res, flags))
 		return 0;
 
 	while (1) {
 		if (flags & ROFFNUM_WHITE)
 			while (isspace((unsigned char)v[*pos]))
 				(*pos)++;
 
 		if ( ! roff_getop(v, pos, &operator))
 			break;
 
 		if (flags & ROFFNUM_WHITE)
 			while (isspace((unsigned char)v[*pos]))
 				(*pos)++;
 
 		if ( ! roff_evalpar(r, ln, v, pos, &operand2, flags))
 			return 0;
 
 		if (flags & ROFFNUM_WHITE)
 			while (isspace((unsigned char)v[*pos]))
 				(*pos)++;
 
 		if (NULL == res)
 			continue;
 
 		switch (operator) {
 		case '+':
 			*res += operand2;
 			break;
 		case '-':
 			*res -= operand2;
 			break;
 		case '*':
 			*res *= operand2;
 			break;
 		case '/':
 			if (operand2 == 0) {
 				mandoc_msg(MANDOCERR_DIVZERO,
 					r->parse, ln, *pos, v);
 				*res = 0;
 				break;
 			}
 			*res /= operand2;
 			break;
 		case '%':
 			if (operand2 == 0) {
 				mandoc_msg(MANDOCERR_DIVZERO,
 					r->parse, ln, *pos, v);
 				*res = 0;
 				break;
 			}
 			*res %= operand2;
 			break;
 		case '<':
 			*res = *res < operand2;
 			break;
 		case '>':
 			*res = *res > operand2;
 			break;
 		case 'l':
 			*res = *res <= operand2;
 			break;
 		case 'g':
 			*res = *res >= operand2;
 			break;
 		case '=':
 			*res = *res == operand2;
 			break;
 		case '!':
 			*res = *res != operand2;
 			break;
 		case '&':
 			*res = *res && operand2;
 			break;
 		case ':':
 			*res = *res || operand2;
 			break;
 		case 'i':
 			if (operand2 < *res)
 				*res = operand2;
 			break;
 		case 'a':
 			if (operand2 > *res)
 				*res = operand2;
 			break;
 		default:
 			abort();
 		}
 	}
 	return 1;
 }
 
 /* --- register management ------------------------------------------------ */
 
 void
 roff_setreg(struct roff *r, const char *name, int val, char sign)
 {
 	struct roffreg	*reg;
 
 	/* Search for an existing register with the same name. */
 	reg = r->regtab;
 
 	while (reg && strcmp(name, reg->key.p))
 		reg = reg->next;
 
 	if (NULL == reg) {
 		/* Create a new register. */
 		reg = mandoc_malloc(sizeof(struct roffreg));
 		reg->key.p = mandoc_strdup(name);
 		reg->key.sz = strlen(name);
 		reg->val = 0;
 		reg->next = r->regtab;
 		r->regtab = reg;
 	}
 
 	if ('+' == sign)
 		reg->val += val;
 	else if ('-' == sign)
 		reg->val -= val;
 	else
 		reg->val = val;
 }
 
 /*
  * Handle some predefined read-only number registers.
  * For now, return -1 if the requested register is not predefined;
  * in case a predefined read-only register having the value -1
  * were to turn up, another special value would have to be chosen.
  */
 static int
 roff_getregro(const struct roff *r, const char *name)
 {
 
 	switch (*name) {
 	case '$':  /* Number of arguments of the last macro evaluated. */
 		return r->argc;
 	case 'A':  /* ASCII approximation mode is always off. */
 		return 0;
 	case 'g':  /* Groff compatibility mode is always on. */
 		return 1;
 	case 'H':  /* Fixed horizontal resolution. */
 		return 24;
 	case 'j':  /* Always adjust left margin only. */
 		return 0;
 	case 'T':  /* Some output device is always defined. */
 		return 1;
 	case 'V':  /* Fixed vertical resolution. */
 		return 40;
 	default:
 		return -1;
 	}
 }
 
 int
 roff_getreg(const struct roff *r, const char *name)
 {
 	struct roffreg	*reg;
 	int		 val;
 
 	if ('.' == name[0] && '\0' != name[1] && '\0' == name[2]) {
 		val = roff_getregro(r, name + 1);
 		if (-1 != val)
 			return val;
 	}
 
 	for (reg = r->regtab; reg; reg = reg->next)
 		if (0 == strcmp(name, reg->key.p))
 			return reg->val;
 
 	return 0;
 }
 
 static int
 roff_getregn(const struct roff *r, const char *name, size_t len)
 {
 	struct roffreg	*reg;
 	int		 val;
 
 	if ('.' == name[0] && 2 == len) {
 		val = roff_getregro(r, name + 1);
 		if (-1 != val)
 			return val;
 	}
 
 	for (reg = r->regtab; reg; reg = reg->next)
 		if (len == reg->key.sz &&
 		    0 == strncmp(name, reg->key.p, len))
 			return reg->val;
 
 	return 0;
 }
 
 static int
 roff_hasregn(const struct roff *r, const char *name, size_t len)
 {
 	struct roffreg	*reg;
 	int		 val;
 
 	if ('.' == name[0] && 2 == len) {
 		val = roff_getregro(r, name + 1);
 		if (-1 != val)
 			return 1;
 	}
 
 	for (reg = r->regtab; reg; reg = reg->next)
 		if (len == reg->key.sz &&
 		    0 == strncmp(name, reg->key.p, len))
 			return 1;
 
 	return 0;
 }
 
 static void
 roff_freereg(struct roffreg *reg)
 {
 	struct roffreg	*old_reg;
 
 	while (NULL != reg) {
 		free(reg->key.p);
 		old_reg = reg;
 		reg = reg->next;
 		free(old_reg);
 	}
 }
 
 static enum rofferr
 roff_nr(ROFF_ARGS)
 {
 	char		*key, *val;
 	size_t		 keysz;
 	int		 iv;
 	char		 sign;
 
 	key = val = buf->buf + pos;
 	if (*key == '\0')
 		return ROFF_IGN;
 
 	keysz = roff_getname(r, &val, ln, pos);
 	if (key[keysz] == '\\')
 		return ROFF_IGN;
 	key[keysz] = '\0';
 
 	sign = *val;
 	if (sign == '+' || sign == '-')
 		val++;
 
 	if (roff_evalnum(r, ln, val, NULL, &iv, ROFFNUM_SCALE))
 		roff_setreg(r, key, iv, sign);
 
 	return ROFF_IGN;
 }
 
 static enum rofferr
 roff_rr(ROFF_ARGS)
 {
 	struct roffreg	*reg, **prev;
 	char		*name, *cp;
 	size_t		 namesz;
 
 	name = cp = buf->buf + pos;
 	if (*name == '\0')
 		return ROFF_IGN;
 	namesz = roff_getname(r, &cp, ln, pos);
 	name[namesz] = '\0';
 
 	prev = &r->regtab;
 	while (1) {
 		reg = *prev;
 		if (reg == NULL || !strcmp(name, reg->key.p))
 			break;
 		prev = ®->next;
 	}
 	if (reg != NULL) {
 		*prev = reg->next;
 		free(reg->key.p);
 		free(reg);
 	}
 	return ROFF_IGN;
 }
 
 /* --- handler functions for roff requests -------------------------------- */
 
 static enum rofferr
 roff_rm(ROFF_ARGS)
 {
 	const char	 *name;
 	char		 *cp;
 	size_t		  namesz;
 
 	cp = buf->buf + pos;
 	while (*cp != '\0') {
 		name = cp;
 		namesz = roff_getname(r, &cp, ln, (int)(cp - buf->buf));
 		roff_setstrn(&r->strtab, name, namesz, NULL, 0, 0);
 		if (name[namesz] == '\\')
 			break;
 	}
 	return ROFF_IGN;
 }
 
 static enum rofferr
 roff_it(ROFF_ARGS)
 {
 	int		 iv;
 
 	/* Parse the number of lines. */
 
 	if ( ! roff_evalnum(r, ln, buf->buf, &pos, &iv, 0)) {
 		mandoc_msg(MANDOCERR_IT_NONUM, r->parse,
 		    ln, ppos, buf->buf + 1);
 		return ROFF_IGN;
 	}
 
 	while (isspace((unsigned char)buf->buf[pos]))
 		pos++;
 
 	/*
 	 * Arm the input line trap.
 	 * Special-casing "an-trap" is an ugly workaround to cope
 	 * with DocBook stupidly fiddling with man(7) internals.
 	 */
 
 	roffit_lines = iv;
 	roffit_macro = mandoc_strdup(iv != 1 ||
 	    strcmp(buf->buf + pos, "an-trap") ?
 	    buf->buf + pos : "br");
 	return ROFF_IGN;
 }
 
 static enum rofferr
 roff_Dd(ROFF_ARGS)
 {
 	const char *const	*cp;
 
 	if ((r->options & (MPARSE_MDOC | MPARSE_QUICK)) == 0)
 		for (cp = __mdoc_reserved; *cp; cp++)
 			roff_setstr(r, *cp, NULL, 0);
 
 	if (r->format == 0)
 		r->format = MPARSE_MDOC;
 
 	return ROFF_CONT;
 }
 
 static enum rofferr
 roff_TH(ROFF_ARGS)
 {
 	const char *const	*cp;
 
 	if ((r->options & MPARSE_QUICK) == 0)
 		for (cp = __man_reserved; *cp; cp++)
 			roff_setstr(r, *cp, NULL, 0);
 
 	if (r->format == 0)
 		r->format = MPARSE_MAN;
 
 	return ROFF_CONT;
 }
 
 static enum rofferr
 roff_TE(ROFF_ARGS)
 {
 
 	if (NULL == r->tbl)
 		mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse,
 		    ln, ppos, "TE");
 	else if ( ! tbl_end(&r->tbl)) {
 		free(buf->buf);
 		buf->buf = mandoc_strdup(".sp");
 		buf->sz = 4;
 		return ROFF_REPARSE;
 	}
 	return ROFF_IGN;
 }
 
 static enum rofferr
 roff_T_(ROFF_ARGS)
 {
 
 	if (NULL == r->tbl)
 		mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse,
 		    ln, ppos, "T&");
 	else
 		tbl_restart(ppos, ln, r->tbl);
 
 	return ROFF_IGN;
 }
 
 /*
  * Handle in-line equation delimiters.
  */
 static enum rofferr
 roff_eqndelim(struct roff *r, struct buf *buf, int pos)
 {
 	char		*cp1, *cp2;
 	const char	*bef_pr, *bef_nl, *mac, *aft_nl, *aft_pr;
 
 	/*
 	 * Outside equations, look for an opening delimiter.
 	 * If we are inside an equation, we already know it is
 	 * in-line, or this function wouldn't have been called;
 	 * so look for a closing delimiter.
 	 */
 
 	cp1 = buf->buf + pos;
 	cp2 = strchr(cp1, r->eqn == NULL ?
 	    r->last_eqn->odelim : r->last_eqn->cdelim);
 	if (cp2 == NULL)
 		return ROFF_CONT;
 
 	*cp2++ = '\0';
 	bef_pr = bef_nl = aft_nl = aft_pr = "";
 
 	/* Handle preceding text, protecting whitespace. */
 
 	if (*buf->buf != '\0') {
 		if (r->eqn == NULL)
 			bef_pr = "\\&";
 		bef_nl = "\n";
 	}
 
 	/*
 	 * Prepare replacing the delimiter with an equation macro
 	 * and drop leading white space from the equation.
 	 */
 
 	if (r->eqn == NULL) {
 		while (*cp2 == ' ')
 			cp2++;
 		mac = ".EQ";
 	} else
 		mac = ".EN";
 
 	/* Handle following text, protecting whitespace. */
 
 	if (*cp2 != '\0') {
 		aft_nl = "\n";
 		if (r->eqn != NULL)
 			aft_pr = "\\&";
 	}
 
 	/* Do the actual replacement. */
 
 	buf->sz = mandoc_asprintf(&cp1, "%s%s%s%s%s%s%s", buf->buf,
 	    bef_pr, bef_nl, mac, aft_nl, aft_pr, cp2) + 1;
 	free(buf->buf);
 	buf->buf = cp1;
 
 	/* Toggle the in-line state of the eqn subsystem. */
 
 	r->eqn_inline = r->eqn == NULL;
 	return ROFF_REPARSE;
 }
 
 static enum rofferr
 roff_EQ(ROFF_ARGS)
 {
 	struct eqn_node *e;
 
 	assert(r->eqn == NULL);
 	e = eqn_alloc(ppos, ln, r->parse);
 
 	if (r->last_eqn) {
 		r->last_eqn->next = e;
 		e->delim = r->last_eqn->delim;
 		e->odelim = r->last_eqn->odelim;
 		e->cdelim = r->last_eqn->cdelim;
 	} else
 		r->first_eqn = r->last_eqn = e;
 
 	r->eqn = r->last_eqn = e;
 
 	if (buf->buf[pos] != '\0')
 		mandoc_vmsg(MANDOCERR_ARG_SKIP, r->parse, ln, pos,
 		    ".EQ %s", buf->buf + pos);
 
 	return ROFF_IGN;
 }
 
 static enum rofferr
 roff_EN(ROFF_ARGS)
 {
 
 	mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse, ln, ppos, "EN");
 	return ROFF_IGN;
 }
 
 static enum rofferr
 roff_TS(ROFF_ARGS)
 {
 	struct tbl_node	*tbl;
 
 	if (r->tbl) {
 		mandoc_msg(MANDOCERR_BLK_BROKEN, r->parse,
 		    ln, ppos, "TS breaks TS");
 		tbl_end(&r->tbl);
 	}
 
 	tbl = tbl_alloc(ppos, ln, r->parse);
 
 	if (r->last_tbl)
 		r->last_tbl->next = tbl;
 	else
 		r->first_tbl = r->last_tbl = tbl;
 
 	r->tbl = r->last_tbl = tbl;
 	return ROFF_IGN;
 }
 
 static enum rofferr
 roff_brp(ROFF_ARGS)
 {
 
 	buf->buf[pos - 1] = '\0';
 	return ROFF_CONT;
 }
 
 static enum rofferr
 roff_cc(ROFF_ARGS)
 {
 	const char	*p;
 
 	p = buf->buf + pos;
 
 	if (*p == '\0' || (r->control = *p++) == '.')
 		r->control = 0;
 
 	if (*p != '\0')
 		mandoc_vmsg(MANDOCERR_ARG_EXCESS, r->parse,
 		    ln, p - buf->buf, "cc ... %s", p);
 
 	return ROFF_IGN;
 }
 
 static enum rofferr
 roff_tr(ROFF_ARGS)
 {
 	const char	*p, *first, *second;
 	size_t		 fsz, ssz;
 	enum mandoc_esc	 esc;
 
 	p = buf->buf + pos;
 
 	if (*p == '\0') {
 		mandoc_msg(MANDOCERR_REQ_EMPTY, r->parse, ln, ppos, "tr");
 		return ROFF_IGN;
 	}
 
 	while (*p != '\0') {
 		fsz = ssz = 1;
 
 		first = p++;
 		if (*first == '\\') {
 			esc = mandoc_escape(&p, NULL, NULL);
 			if (esc == ESCAPE_ERROR) {
 				mandoc_msg(MANDOCERR_ESC_BAD, r->parse,
 				    ln, (int)(p - buf->buf), first);
 				return ROFF_IGN;
 			}
 			fsz = (size_t)(p - first);
 		}
 
 		second = p++;
 		if (*second == '\\') {
 			esc = mandoc_escape(&p, NULL, NULL);
 			if (esc == ESCAPE_ERROR) {
 				mandoc_msg(MANDOCERR_ESC_BAD, r->parse,
 				    ln, (int)(p - buf->buf), second);
 				return ROFF_IGN;
 			}
 			ssz = (size_t)(p - second);
 		} else if (*second == '\0') {
 			mandoc_vmsg(MANDOCERR_TR_ODD, r->parse,
 			    ln, first - buf->buf, "tr %s", first);
 			second = " ";
 			p--;
 		}
 
 		if (fsz > 1) {
 			roff_setstrn(&r->xmbtab, first, fsz,
 			    second, ssz, 0);
 			continue;
 		}
 
 		if (r->xtab == NULL)
 			r->xtab = mandoc_calloc(128,
 			    sizeof(struct roffstr));
 
 		free(r->xtab[(int)*first].p);
 		r->xtab[(int)*first].p = mandoc_strndup(second, ssz);
 		r->xtab[(int)*first].sz = ssz;
 	}
 
 	return ROFF_IGN;
 }
 
 static enum rofferr
 roff_so(ROFF_ARGS)
 {
 	char *name, *cp;
 
 	name = buf->buf + pos;
 	mandoc_vmsg(MANDOCERR_SO, r->parse, ln, ppos, "so %s", name);
 
 	/*
 	 * Handle `so'.  Be EXTREMELY careful, as we shouldn't be
 	 * opening anything that's not in our cwd or anything beneath
 	 * it.  Thus, explicitly disallow traversing up the file-system
 	 * or using absolute paths.
 	 */
 
 	if (*name == '/' || strstr(name, "../") || strstr(name, "/..")) {
 		mandoc_vmsg(MANDOCERR_SO_PATH, r->parse, ln, ppos,
 		    ".so %s", name);
 		buf->sz = mandoc_asprintf(&cp,
 		    ".sp\nSee the file %s.\n.sp", name) + 1;
 		free(buf->buf);
 		buf->buf = cp;
 		*offs = 0;
 		return ROFF_REPARSE;
 	}
 
 	*offs = pos;
 	return ROFF_SO;
 }
 
 /* --- user defined strings and macros ------------------------------------ */
 
 static enum rofferr
 roff_userdef(ROFF_ARGS)
 {
 	const char	 *arg[9], *ap;
 	char		 *cp, *n1, *n2;
 	int		  i, ib, ie;
 	size_t		  asz, rsz;
 
 	/*
 	 * Collect pointers to macro argument strings
 	 * and NUL-terminate them.
 	 */
 
 	r->argc = 0;
 	cp = buf->buf + pos;
 	for (i = 0; i < 9; i++) {
 		if (*cp == '\0')
 			arg[i] = "";
 		else {
 			arg[i] = mandoc_getarg(r->parse, &cp, ln, &pos);
 			r->argc = i + 1;
 		}
 	}
 
 	/*
 	 * Expand macro arguments.
 	 */
 
 	buf->sz = strlen(r->current_string) + 1;
 	n1 = cp = mandoc_malloc(buf->sz);
 	memcpy(n1, r->current_string, buf->sz);
 	while (*cp != '\0') {
 
 		/* Scan ahead for the next argument invocation. */
 
 		if (*cp++ != '\\')
 			continue;
 		if (*cp++ != '$')
 			continue;
 		if (*cp == '*') {  /* \\$* inserts all arguments */
 			ib = 0;
 			ie = r->argc - 1;
 		} else {  /* \\$1 .. \\$9 insert one argument */
 			ib = ie = *cp - '1';
 			if (ib < 0 || ib > 8)
 				continue;
 		}
 		cp -= 2;
 
 		/*
 		 * Determine the size of the expanded argument,
 		 * taking escaping of quotes into account.
 		 */
 
 		asz = ie > ib ? ie - ib : 0;  /* for blanks */
 		for (i = ib; i <= ie; i++) {
 			for (ap = arg[i]; *ap != '\0'; ap++) {
 				asz++;
 				if (*ap == '"')
 					asz += 3;
 			}
 		}
 		if (asz != 3) {
 
 			/*
 			 * Determine the size of the rest of the
 			 * unexpanded macro, including the NUL.
 			 */
 
 			rsz = buf->sz - (cp - n1) - 3;
 
 			/*
 			 * When shrinking, move before
 			 * releasing the storage.
 			 */
 
 			if (asz < 3)
 				memmove(cp + asz, cp + 3, rsz);
 
 			/*
 			 * Resize the storage for the macro
 			 * and readjust the parse pointer.
 			 */
 
 			buf->sz += asz - 3;
 			n2 = mandoc_realloc(n1, buf->sz);
 			cp = n2 + (cp - n1);
 			n1 = n2;
 
 			/*
 			 * When growing, make room
 			 * for the expanded argument.
 			 */
 
 			if (asz > 3)
 				memmove(cp + asz, cp + 3, rsz);
 		}
 
 		/* Copy the expanded argument, escaping quotes. */
 
 		n2 = cp;
 		for (i = ib; i <= ie; i++) {
 			for (ap = arg[i]; *ap != '\0'; ap++) {
 				if (*ap == '"') {
 					memcpy(n2, "\\(dq", 4);
 					n2 += 4;
 				} else
 					*n2++ = *ap;
 			}
 			if (i < ie)
 				*n2++ = ' ';
 		}
 	}
 
 	/*
 	 * Replace the macro invocation
 	 * by the expanded macro.
 	 */
 
 	free(buf->buf);
 	buf->buf = n1;
 	*offs = 0;
 
 	return buf->sz > 1 && buf->buf[buf->sz - 2] == '\n' ?
 	   ROFF_REPARSE : ROFF_APPEND;
 }
 
 static size_t
 roff_getname(struct roff *r, char **cpp, int ln, int pos)
 {
 	char	 *name, *cp;
 	size_t	  namesz;
 
 	name = *cpp;
 	if ('\0' == *name)
 		return 0;
 
 	/* Read until end of name and terminate it with NUL. */
 	for (cp = name; 1; cp++) {
 		if ('\0' == *cp || ' ' == *cp) {
 			namesz = cp - name;
 			break;
 		}
 		if ('\\' != *cp)
 			continue;
 		namesz = cp - name;
 		if ('{' == cp[1] || '}' == cp[1])
 			break;
 		cp++;
 		if ('\\' == *cp)
 			continue;
 		mandoc_vmsg(MANDOCERR_NAMESC, r->parse, ln, pos,
 		    "%.*s", (int)(cp - name + 1), name);
 		mandoc_escape((const char **)&cp, NULL, NULL);
 		break;
 	}
 
 	/* Read past spaces. */
 	while (' ' == *cp)
 		cp++;
 
 	*cpp = cp;
 	return namesz;
 }
 
 /*
  * Store *string into the user-defined string called *name.
  * To clear an existing entry, call with (*r, *name, NULL, 0).
  * append == 0: replace mode
  * append == 1: single-line append mode
  * append == 2: multiline append mode, append '\n' after each call
  */
 static void
 roff_setstr(struct roff *r, const char *name, const char *string,
 	int append)
 {
 
 	roff_setstrn(&r->strtab, name, strlen(name), string,
 	    string ? strlen(string) : 0, append);
 }
 
 static void
 roff_setstrn(struct roffkv **r, const char *name, size_t namesz,
 		const char *string, size_t stringsz, int append)
 {
 	struct roffkv	*n;
 	char		*c;
 	int		 i;
 	size_t		 oldch, newch;
 
 	/* Search for an existing string with the same name. */
 	n = *r;
 
 	while (n && (namesz != n->key.sz ||
 			strncmp(n->key.p, name, namesz)))
 		n = n->next;
 
 	if (NULL == n) {
 		/* Create a new string table entry. */
 		n = mandoc_malloc(sizeof(struct roffkv));
 		n->key.p = mandoc_strndup(name, namesz);
 		n->key.sz = namesz;
 		n->val.p = NULL;
 		n->val.sz = 0;
 		n->next = *r;
 		*r = n;
 	} else if (0 == append) {
 		free(n->val.p);
 		n->val.p = NULL;
 		n->val.sz = 0;
 	}
 
 	if (NULL == string)
 		return;
 
 	/*
 	 * One additional byte for the '\n' in multiline mode,
 	 * and one for the terminating '\0'.
 	 */
 	newch = stringsz + (1 < append ? 2u : 1u);
 
 	if (NULL == n->val.p) {
 		n->val.p = mandoc_malloc(newch);
 		*n->val.p = '\0';
 		oldch = 0;
 	} else {
 		oldch = n->val.sz;
 		n->val.p = mandoc_realloc(n->val.p, oldch + newch);
 	}
 
 	/* Skip existing content in the destination buffer. */
 	c = n->val.p + (int)oldch;
 
 	/* Append new content to the destination buffer. */
 	i = 0;
 	while (i < (int)stringsz) {
 		/*
 		 * Rudimentary roff copy mode:
 		 * Handle escaped backslashes.
 		 */
 		if ('\\' == string[i] && '\\' == string[i + 1])
 			i++;
 		*c++ = string[i++];
 	}
 
 	/* Append terminating bytes. */
 	if (1 < append)
 		*c++ = '\n';
 
 	*c = '\0';
 	n->val.sz = (int)(c - n->val.p);
 }
 
 static const char *
 roff_getstrn(const struct roff *r, const char *name, size_t len)
 {
 	const struct roffkv *n;
 	int i;
 
 	for (n = r->strtab; n; n = n->next)
 		if (0 == strncmp(name, n->key.p, len) &&
 		    '\0' == n->key.p[(int)len])
 			return n->val.p;
 
 	for (i = 0; i < PREDEFS_MAX; i++)
 		if (0 == strncmp(name, predefs[i].name, len) &&
 				'\0' == predefs[i].name[(int)len])
 			return predefs[i].str;
 
 	return NULL;
 }
 
 static void
 roff_freestr(struct roffkv *r)
 {
 	struct roffkv	 *n, *nn;
 
 	for (n = r; n; n = nn) {
 		free(n->key.p);
 		free(n->val.p);
 		nn = n->next;
 		free(n);
 	}
 }
 
 /* --- accessors and utility functions ------------------------------------ */
 
 const struct tbl_span *
 roff_span(const struct roff *r)
 {
 
 	return r->tbl ? tbl_span(r->tbl) : NULL;
 }
 
 const struct eqn *
 roff_eqn(const struct roff *r)
 {
 
 	return r->last_eqn ? &r->last_eqn->eqn : NULL;
 }
 
 /*
  * Duplicate an input string, making the appropriate character
  * conversations (as stipulated by `tr') along the way.
  * Returns a heap-allocated string with all the replacements made.
  */
 char *
 roff_strdup(const struct roff *r, const char *p)
 {
 	const struct roffkv *cp;
 	char		*res;
 	const char	*pp;
 	size_t		 ssz, sz;
 	enum mandoc_esc	 esc;
 
 	if (NULL == r->xmbtab && NULL == r->xtab)
 		return mandoc_strdup(p);
 	else if ('\0' == *p)
 		return mandoc_strdup("");
 
 	/*
 	 * Step through each character looking for term matches
 	 * (remember that a `tr' can be invoked with an escape, which is
 	 * a glyph but the escape is multi-character).
 	 * We only do this if the character hash has been initialised
 	 * and the string is >0 length.
 	 */
 
 	res = NULL;
 	ssz = 0;
 
 	while ('\0' != *p) {
 		if ('\\' != *p && r->xtab && r->xtab[(int)*p].p) {
 			sz = r->xtab[(int)*p].sz;
 			res = mandoc_realloc(res, ssz + sz + 1);
 			memcpy(res + ssz, r->xtab[(int)*p].p, sz);
 			ssz += sz;
 			p++;
 			continue;
 		} else if ('\\' != *p) {
 			res = mandoc_realloc(res, ssz + 2);
 			res[ssz++] = *p++;
 			continue;
 		}
 
 		/* Search for term matches. */
 		for (cp = r->xmbtab; cp; cp = cp->next)
 			if (0 == strncmp(p, cp->key.p, cp->key.sz))
 				break;
 
 		if (NULL != cp) {
 			/*
 			 * A match has been found.
 			 * Append the match to the array and move
 			 * forward by its keysize.
 			 */
 			res = mandoc_realloc(res,
 			    ssz + cp->val.sz + 1);
 			memcpy(res + ssz, cp->val.p, cp->val.sz);
 			ssz += cp->val.sz;
 			p += (int)cp->key.sz;
 			continue;
 		}
 
 		/*
 		 * Handle escapes carefully: we need to copy
 		 * over just the escape itself, or else we might
 		 * do replacements within the escape itself.
 		 * Make sure to pass along the bogus string.
 		 */
 		pp = p++;
 		esc = mandoc_escape(&p, NULL, NULL);
 		if (ESCAPE_ERROR == esc) {
 			sz = strlen(pp);
 			res = mandoc_realloc(res, ssz + sz + 1);
 			memcpy(res + ssz, pp, sz);
 			break;
 		}
 		/*
 		 * We bail out on bad escapes.
 		 * No need to warn: we already did so when
 		 * roff_res() was called.
 		 */
 		sz = (int)(p - pp);
 		res = mandoc_realloc(res, ssz + sz + 1);
 		memcpy(res + ssz, pp, sz);
 		ssz += sz;
 	}
 
 	res[(int)ssz] = '\0';
 	return res;
 }
 
 int
 roff_getformat(const struct roff *r)
 {
 
 	return r->format;
 }
 
 /*
  * Find out whether a line is a macro line or not.
  * If it is, adjust the current position and return one; if it isn't,
  * return zero and don't change the current position.
  * If the control character has been set with `.cc', then let that grain
  * precedence.
  * This is slighly contrary to groff, where using the non-breaking
  * control character when `cc' has been invoked will cause the
  * non-breaking macro contents to be printed verbatim.
  */
 int
 roff_getcontrol(const struct roff *r, const char *cp, int *ppos)
 {
 	int		pos;
 
 	pos = *ppos;
 
 	if (0 != r->control && cp[pos] == r->control)
 		pos++;
 	else if (0 != r->control)
 		return 0;
 	else if ('\\' == cp[pos] && '.' == cp[pos + 1])
 		pos += 2;
 	else if ('.' == cp[pos] || '\'' == cp[pos])
 		pos++;
 	else
 		return 0;
 
 	while (' ' == cp[pos] || '\t' == cp[pos])
 		pos++;
 
 	*ppos = pos;
 	return 1;
 }
Index: stable/11/contrib/mdocml/roff.h
===================================================================
--- stable/11/contrib/mdocml/roff.h	(revision 316419)
+++ stable/11/contrib/mdocml/roff.h	(revision 316420)
@@ -1,164 +1,163 @@
-/*	$OpenBSD$	*/
+/*	$Id: roff.h,v 1.39 2017/01/10 13:47:00 schwarze Exp $	*/
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons 
- * Copyright (c) 2013, 2014, 2015 Ingo Schwarze 
+ * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze 
  *
  * 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 AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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.
  */
 
 struct	mdoc_arg;
 union	mdoc_data;
 
 enum	roff_macroset {
 	MACROSET_NONE = 0,
 	MACROSET_MDOC,
 	MACROSET_MAN
 };
 
 enum	roff_sec {
 	SEC_NONE = 0,
 	SEC_NAME,
 	SEC_LIBRARY,
 	SEC_SYNOPSIS,
 	SEC_DESCRIPTION,
 	SEC_CONTEXT,
 	SEC_IMPLEMENTATION,	/* IMPLEMENTATION NOTES */
 	SEC_RETURN_VALUES,
 	SEC_ENVIRONMENT,
 	SEC_FILES,
 	SEC_EXIT_STATUS,
 	SEC_EXAMPLES,
 	SEC_DIAGNOSTICS,
 	SEC_COMPATIBILITY,
 	SEC_ERRORS,
 	SEC_SEE_ALSO,
 	SEC_STANDARDS,
 	SEC_HISTORY,
 	SEC_AUTHORS,
 	SEC_CAVEATS,
 	SEC_BUGS,
 	SEC_SECURITY,
 	SEC_CUSTOM,
 	SEC__MAX
 };
 
 enum	roff_type {
 	ROFFT_ROOT,
 	ROFFT_BLOCK,
 	ROFFT_HEAD,
 	ROFFT_BODY,
 	ROFFT_TAIL,
 	ROFFT_ELEM,
 	ROFFT_TEXT,
 	ROFFT_TBL,
 	ROFFT_EQN
 };
 
 enum	roff_next {
 	ROFF_NEXT_SIBLING = 0,
 	ROFF_NEXT_CHILD
 };
 
 /*
  * Indicates that a BODY's formatting has ended, but
  * the scope is still open.  Used for badly nested blocks.
  */
 enum	mdoc_endbody {
 	ENDBODY_NOT = 0,
 	ENDBODY_SPACE,	/* Is broken: append a space. */
 	ENDBODY_NOSPACE	/* Is broken: don't append a space. */
 };
 
 struct	roff_node {
 	struct roff_node *parent;  /* Parent AST node. */
 	struct roff_node *child;   /* First child AST node. */
 	struct roff_node *last;    /* Last child AST node. */
 	struct roff_node *next;    /* Sibling AST node. */
 	struct roff_node *prev;    /* Prior sibling AST node. */
 	struct roff_node *head;    /* BLOCK */
 	struct roff_node *body;    /* BLOCK/ENDBODY */
 	struct roff_node *tail;    /* BLOCK */
 	struct mdoc_arg	 *args;    /* BLOCK/ELEM */
 	union mdoc_data	 *norm;    /* Normalized arguments. */
 	char		 *string;  /* TEXT */
 	const struct tbl_span *span; /* TBL */
 	const struct eqn *eqn;	   /* EQN */
 	int		  line;    /* Input file line number. */
 	int		  pos;     /* Input file column number. */
 	int		  tok;     /* Request or macro ID. */
 #define	TOKEN_NONE	 (-1)	   /* No request or macro. */
 	int		  flags;
-#define	MDOC_VALID	 (1 << 0)  /* Has been validated. */
-#define	MDOC_ENDED	 (1 << 1)  /* Gone past body end mark. */
-#define MDOC_EOS	 (1 << 2)  /* At sentence boundary. */
-#define	MDOC_LINE	 (1 << 3)  /* First macro/text on line. */
-#define MDOC_SYNPRETTY	 (1 << 4)  /* SYNOPSIS-style formatting. */
-#define MDOC_BROKEN	 (1 << 5)  /* Must validate parent when ending. */
-#define	MDOC_DELIMO	 (1 << 6)
-#define	MDOC_DELIMC	 (1 << 7)
-#define	MAN_VALID	  MDOC_VALID
-#define	MAN_EOS		  MDOC_EOS
-#define	MAN_LINE	  MDOC_LINE
+#define	NODE_VALID	 (1 << 0)  /* Has been validated. */
+#define	NODE_ENDED	 (1 << 1)  /* Gone past body end mark. */
+#define	NODE_EOS	 (1 << 2)  /* At sentence boundary. */
+#define	NODE_LINE	 (1 << 3)  /* First macro/text on line. */
+#define	NODE_SYNPRETTY	 (1 << 4)  /* SYNOPSIS-style formatting. */
+#define	NODE_BROKEN	 (1 << 5)  /* Must validate parent when ending. */
+#define	NODE_DELIMO	 (1 << 6)
+#define	NODE_DELIMC	 (1 << 7)
+#define	NODE_NOSRC	 (1 << 8)  /* Generated node, not in input file. */
+#define	NODE_NOPRT	 (1 << 9)  /* Shall not print anything. */
 	int		  prev_font; /* Before entering this node. */
 	int		  aux;     /* Decoded node data, type-dependent. */
 	enum roff_type	  type;    /* AST node type. */
 	enum roff_sec	  sec;     /* Current named section. */
 	enum mdoc_endbody end;     /* BODY */
 };
 
 struct	roff_meta {
 	char		 *msec;    /* Manual section, usually a digit. */
 	char		 *vol;     /* Manual volume title. */
 	char		 *os;      /* Operating system. */
 	char		 *arch;    /* Machine architecture. */
 	char		 *title;   /* Manual title, usually CAPS. */
 	char		 *name;    /* Leading manual name. */
 	char		 *date;    /* Normalized date. */
 	int		  hasbody; /* Document is not empty. */
 };
 
 struct	roff_man {
 	struct roff_meta  meta;    /* Document meta-data. */
 	struct mparse	 *parse;   /* Parse pointer. */
 	struct roff	 *roff;    /* Roff parser state data. */
 	const char	 *defos;   /* Default operating system. */
 	struct roff_node *first;   /* The first node parsed. */
 	struct roff_node *last;    /* The last node parsed. */
 	struct roff_node *last_es; /* The most recent Es node. */
 	int		  quick;   /* Abort parse early. */
 	int		  flags;   /* Parse flags. */
 #define	MDOC_LITERAL	 (1 << 1)  /* In a literal scope. */
 #define	MDOC_PBODY	 (1 << 2)  /* In the document body. */
 #define	MDOC_NEWLINE	 (1 << 3)  /* First macro/text in a line. */
 #define	MDOC_PHRASE	 (1 << 4)  /* In a Bl -column phrase. */
 #define	MDOC_PHRASELIT	 (1 << 5)  /* Literal within a phrase. */
 #define	MDOC_FREECOL	 (1 << 6)  /* `It' invocation should close. */
 #define	MDOC_SYNOPSIS	 (1 << 7)  /* SYNOPSIS-style formatting. */
 #define	MDOC_KEEP	 (1 << 8)  /* In a word keep. */
 #define	MDOC_SMOFF	 (1 << 9)  /* Spacing is off. */
 #define	MDOC_NODELIMC	 (1 << 10) /* Disable closing delimiter handling. */
 #define	MAN_ELINE	 (1 << 11) /* Next-line element scope. */
 #define	MAN_BLINE	 (1 << 12) /* Next-line block scope. */
 #define	MDOC_PHRASEQF	 (1 << 13) /* Quote first word encountered. */
 #define	MDOC_PHRASEQL	 (1 << 14) /* Quote last word of this phrase. */
 #define	MDOC_PHRASEQN	 (1 << 15) /* Quote first word of the next phrase. */
 #define	MAN_LITERAL	  MDOC_LITERAL
 #define	MAN_NEWLINE	  MDOC_NEWLINE
 	enum roff_macroset macroset; /* Kind of high-level macros used. */
 	enum roff_sec	  lastsec; /* Last section seen. */
 	enum roff_sec	  lastnamed; /* Last standard section seen. */
 	enum roff_next	  next;    /* Where to put the next node. */
 };
 
 
 void		 deroff(char **, const struct roff_node *);
Index: stable/11/contrib/mdocml/tag.c
===================================================================
--- stable/11/contrib/mdocml/tag.c	(revision 316419)
+++ stable/11/contrib/mdocml/tag.c	(revision 316420)
@@ -1,204 +1,249 @@
-/*      $Id: tag.c,v 1.12 2016/07/08 20:42:15 schwarze Exp $    */
+/*	$Id: tag.c,v 1.17 2017/01/09 17:49:58 schwarze Exp $ */
 /*
- * Copyright (c) 2015 Ingo Schwarze 
+ * Copyright (c) 2015, 2016 Ingo Schwarze 
  *
  * 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 "config.h"
 
 #include 
 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 
 #include "mandoc_aux.h"
 #include "mandoc_ohash.h"
 #include "tag.h"
 
 struct tag_entry {
-	size_t	 line;
+	size_t	*lines;
+	size_t	 maxlines;
+	size_t	 nlines;
 	int	 prio;
 	char	 s[];
 };
 
-static	void	 tag_signal(int);
+static	void	 tag_signal(int) __attribute__((noreturn));
 
 static struct ohash	 tag_data;
 static struct tag_files	 tag_files;
 
 
 /*
  * Prepare for using a pager.
  * Not all pagers are capable of using a tag file,
  * but for simplicity, create it anyway.
  */
 struct tag_files *
 tag_init(void)
 {
 	struct sigaction	 sa;
 	int			 ofd;
 
 	ofd = -1;
 	tag_files.tfd = -1;
 	tag_files.tcpgid = -1;
 
 	/* Clean up when dying from a signal. */
 
 	memset(&sa, 0, sizeof(sa));
 	sigfillset(&sa.sa_mask);
 	sa.sa_handler = tag_signal;
 	sigaction(SIGHUP, &sa, NULL);
 	sigaction(SIGINT, &sa, NULL);
 	sigaction(SIGTERM, &sa, NULL);
 
 	/*
 	 * POSIX requires that a process calling tcsetpgrp(3)
 	 * from the background gets a SIGTTOU signal.
 	 * In that case, do not stop.
 	 */
 
 	sa.sa_handler = SIG_IGN;
 	sigaction(SIGTTOU, &sa, NULL);
 
 	/* Save the original standard output for use by the pager. */
 
 	if ((tag_files.ofd = dup(STDOUT_FILENO)) == -1)
 		goto fail;
 
 	/* Create both temporary output files. */
 
 	(void)strlcpy(tag_files.ofn, "/tmp/man.XXXXXXXXXX",
 	    sizeof(tag_files.ofn));
 	(void)strlcpy(tag_files.tfn, "/tmp/man.XXXXXXXXXX",
 	    sizeof(tag_files.tfn));
 	if ((ofd = mkstemp(tag_files.ofn)) == -1)
 		goto fail;
 	if ((tag_files.tfd = mkstemp(tag_files.tfn)) == -1)
 		goto fail;
 	if (dup2(ofd, STDOUT_FILENO) == -1)
 		goto fail;
 	close(ofd);
 
 	/*
 	 * Set up the ohash table to collect output line numbers
 	 * where various marked-up terms are documented.
 	 */
 
 	mandoc_ohash_init(&tag_data, 4, offsetof(struct tag_entry, s));
 	return &tag_files;
 
 fail:
 	tag_unlink();
 	if (ofd != -1)
 		close(ofd);
 	if (tag_files.ofd != -1)
 		close(tag_files.ofd);
 	if (tag_files.tfd != -1)
 		close(tag_files.tfd);
 	*tag_files.ofn = '\0';
 	*tag_files.tfn = '\0';
 	tag_files.ofd = -1;
 	tag_files.tfd = -1;
 	return NULL;
 }
 
 /*
  * Set the line number where a term is defined,
  * unless it is already defined at a higher priority.
  */
 void
 tag_put(const char *s, int prio, size_t line)
 {
 	struct tag_entry	*entry;
 	size_t			 len;
 	unsigned int		 slot;
 
-	if (tag_files.tfd <= 0 || strchr(s, ' ') != NULL)
+	/* Sanity checks. */
+
+	if (tag_files.tfd <= 0)
 		return;
+	if (s[0] == '\\' && (s[1] == '&' || s[1] == 'e'))
+		s += 2;
+	if (*s == '\0' || strchr(s, ' ') != NULL)
+		return;
+
 	slot = ohash_qlookup(&tag_data, s);
 	entry = ohash_find(&tag_data, slot);
+
 	if (entry == NULL) {
+
+		/* Build a new entry. */
+
 		len = strlen(s) + 1;
 		entry = mandoc_malloc(sizeof(*entry) + len);
 		memcpy(entry->s, s, len);
+		entry->lines = NULL;
+		entry->maxlines = entry->nlines = 0;
 		ohash_insert(&tag_data, slot, entry);
-	} else if (entry->prio <= prio)
-		return;
-	entry->line = line;
+
+	} else {
+
+		/* Handle priority 0 entries. */
+
+		if (prio == 0) {
+			if (entry->prio == 0)
+				entry->prio = -1;
+			return;
+		}
+
+		/* A better entry is already present, ignore the new one. */
+
+		if (entry->prio > 0 && entry->prio < prio)
+			return;
+
+		/* The existing entry is worse, clear it. */
+
+		if (entry->prio < 1 || entry->prio > prio)
+			entry->nlines = 0;
+	}
+
+	/* Remember the new line. */
+
+	if (entry->maxlines == entry->nlines) {
+		entry->maxlines += 4;
+		entry->lines = mandoc_reallocarray(entry->lines,
+		    entry->maxlines, sizeof(*entry->lines));
+	}
+	entry->lines[entry->nlines++] = line;
 	entry->prio = prio;
 }
 
 /*
  * Write out the tags file using the previously collected
  * information and clear the ohash table while going along.
  */
 void
 tag_write(void)
 {
 	FILE			*stream;
 	struct tag_entry	*entry;
+	size_t			 i;
 	unsigned int		 slot;
 
 	if (tag_files.tfd <= 0)
 		return;
 	stream = fdopen(tag_files.tfd, "w");
 	entry = ohash_first(&tag_data, &slot);
 	while (entry != NULL) {
-		if (stream != NULL)
-			fprintf(stream, "%s %s %zu\n",
-			    entry->s, tag_files.ofn, entry->line);
+		if (stream != NULL && entry->prio >= 0)
+			for (i = 0; i < entry->nlines; i++)
+				fprintf(stream, "%s %s %zu\n",
+				    entry->s, tag_files.ofn, entry->lines[i]);
+		free(entry->lines);
 		free(entry);
 		entry = ohash_next(&tag_data, &slot);
 	}
 	ohash_delete(&tag_data);
 	if (stream != NULL)
 		fclose(stream);
 }
 
 void
 tag_unlink(void)
 {
 	pid_t	 tc_pgid;
 
 	if (tag_files.tcpgid != -1) {
-		tc_pgid = tcgetpgrp(STDIN_FILENO);
+		tc_pgid = tcgetpgrp(tag_files.ofd);
 		if (tc_pgid == tag_files.pager_pid ||
 		    tc_pgid == getpgid(0) ||
 		    getpgid(tc_pgid) == -1)
-			(void)tcsetpgrp(STDIN_FILENO, tag_files.tcpgid);
+			(void)tcsetpgrp(tag_files.ofd, tag_files.tcpgid);
 	}
 	if (*tag_files.ofn != '\0')
 		unlink(tag_files.ofn);
 	if (*tag_files.tfn != '\0')
 		unlink(tag_files.tfn);
 }
 
 static void
 tag_signal(int signum)
 {
 	struct sigaction	 sa;
 
 	tag_unlink();
 	memset(&sa, 0, sizeof(sa));
 	sigemptyset(&sa.sa_mask);
 	sa.sa_handler = SIG_DFL;
 	sigaction(signum, &sa, NULL);
 	kill(getpid(), signum);
 	/* NOTREACHED */
 	_exit(1);
 }
Index: stable/11/contrib/mdocml/tbl_html.c
===================================================================
--- stable/11/contrib/mdocml/tbl_html.c	(revision 316419)
+++ stable/11/contrib/mdocml/tbl_html.c	(revision 316420)
@@ -1,142 +1,130 @@
-/*	$Id: tbl_html.c,v 1.18 2015/10/12 00:08:16 schwarze Exp $ */
+/*	$Id: tbl_html.c,v 1.19 2017/01/17 01:47:51 schwarze Exp $ */
 /*
  * Copyright (c) 2011 Kristaps Dzonsons 
- * Copyright (c) 2014, 2015 Ingo Schwarze 
+ * Copyright (c) 2014, 2015, 2017 Ingo Schwarze 
  *
  * 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 "config.h"
 
 #include 
 
 #include 
 #include 
 #include 
 #include 
 
 #include "mandoc.h"
 #include "out.h"
 #include "html.h"
 
 static	void	 html_tblopen(struct html *, const struct tbl_span *);
 static	size_t	 html_tbl_len(size_t, void *);
 static	size_t	 html_tbl_strlen(const char *, void *);
 
 
 static size_t
 html_tbl_len(size_t sz, void *arg)
 {
 
 	return sz;
 }
 
 static size_t
 html_tbl_strlen(const char *p, void *arg)
 {
 
 	return strlen(p);
 }
 
 static void
 html_tblopen(struct html *h, const struct tbl_span *sp)
 {
-	struct htmlpair	 tag;
-	struct roffsu	 su;
-	struct roffcol	*col;
 	int		 ic;
 
 	if (h->tbl.cols == NULL) {
 		h->tbl.len = html_tbl_len;
 		h->tbl.slen = html_tbl_strlen;
 		tblcalc(&h->tbl, sp, 0);
 	}
 
 	assert(NULL == h->tblt);
-	PAIR_CLASS_INIT(&tag, "tbl");
-	h->tblt = print_otag(h, TAG_TABLE, 1, &tag);
+	h->tblt = print_otag(h, TAG_TABLE, "c", "tbl");
 
-	for (ic = 0; ic < sp->opts->cols; ic++) {
-		bufinit(h);
-		col = h->tbl.cols + ic;
-		SCALE_HS_INIT(&su, col->width);
-		bufcat_su(h, "width", &su);
-		PAIR_STYLE_INIT(&tag, h);
-		print_otag(h, TAG_COL, 1, &tag);
-	}
+	for (ic = 0; ic < sp->opts->cols; ic++)
+		print_otag(h, TAG_COL, "shw", h->tbl.cols[ic].width);
 
-	print_otag(h, TAG_TBODY, 0, NULL);
+	print_otag(h, TAG_TBODY, "");
 }
 
 void
 print_tblclose(struct html *h)
 {
 
 	assert(h->tblt);
 	print_tagq(h, h->tblt);
 	h->tblt = NULL;
 }
 
 void
 print_tbl(struct html *h, const struct tbl_span *sp)
 {
 	const struct tbl_dat *dp;
-	struct htmlpair	 tag;
 	struct tag	*tt;
 	int		 ic;
 
 	/* Inhibit printing of spaces: we do padding ourselves. */
 
 	if (h->tblt == NULL)
 		html_tblopen(h, sp);
 
 	assert(h->tblt);
 
 	h->flags |= HTML_NONOSPACE;
 	h->flags |= HTML_NOSPACE;
 
-	tt = print_otag(h, TAG_TR, 0, NULL);
+	tt = print_otag(h, TAG_TR, "");
 
 	switch (sp->pos) {
 	case TBL_SPAN_HORIZ:
 	case TBL_SPAN_DHORIZ:
-		PAIR_INIT(&tag, ATTR_COLSPAN, "0");
-		print_otag(h, TAG_TD, 1, &tag);
+		print_otag(h, TAG_TD, "?", "colspan", "0");
 		break;
 	default:
 		dp = sp->first;
 		for (ic = 0; ic < sp->opts->cols; ic++) {
 			print_stagq(h, tt);
-			print_otag(h, TAG_TD, 0, NULL);
+			print_otag(h, TAG_TD, "");
 
 			if (dp == NULL || dp->layout->col > ic)
 				continue;
 			if (dp->layout->pos != TBL_CELL_DOWN)
 				if (dp->string != NULL)
 					print_text(h, dp->string);
 			dp = dp->next;
 		}
 		break;
 	}
 
 	print_tagq(h, tt);
 
 	h->flags &= ~HTML_NONOSPACE;
 
 	if (sp->next == NULL) {
 		assert(h->tbl.cols);
 		free(h->tbl.cols);
 		h->tbl.cols = NULL;
 		print_tblclose(h);
 	}
 
 }
Index: stable/11/contrib/mdocml/term.c
===================================================================
--- stable/11/contrib/mdocml/term.c	(revision 316419)
+++ stable/11/contrib/mdocml/term.c	(revision 316420)
@@ -1,829 +1,843 @@
-/*	$Id: term.c,v 1.257 2016/04/12 15:30:00 schwarze Exp $ */
+/*	$Id: term.c,v 1.259 2017/01/08 18:16:58 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons 
- * Copyright (c) 2010-2015 Ingo Schwarze 
+ * Copyright (c) 2010-2017 Ingo Schwarze 
  *
  * 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 AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h"
 
 #include 
 
 #include 
 #include 
 #include 
 #include 
 #include 
 
 #include "mandoc.h"
 #include "mandoc_aux.h"
 #include "out.h"
 #include "term.h"
 #include "main.h"
 
 static	size_t		 cond_width(const struct termp *, int, int *);
 static	void		 adjbuf(struct termp *p, size_t);
 static	void		 bufferc(struct termp *, char);
 static	void		 encode(struct termp *, const char *, size_t);
 static	void		 encode1(struct termp *, int);
 
 
 void
 term_free(struct termp *p)
 {
 
 	free(p->buf);
 	free(p->fontq);
 	free(p);
 }
 
 void
 term_begin(struct termp *p, term_margin head,
 		term_margin foot, const struct roff_meta *arg)
 {
 
 	p->headf = head;
 	p->footf = foot;
 	p->argf = arg;
 	(*p->begin)(p);
 }
 
 void
 term_end(struct termp *p)
 {
 
 	(*p->end)(p);
 }
 
 /*
  * Flush a chunk of text.  By default, break the output line each time
  * the right margin is reached, and continue output on the next line
  * at the same offset as the chunk itself.  By default, also break the
  * output line at the end of the chunk.
  * The following flags may be specified:
  *
  *  - TERMP_NOBREAK: Do not break the output line at the right margin,
  *    but only at the max right margin.  Also, do not break the output
  *    line at the end of the chunk, such that the next call can pad to
  *    the next column.  However, if less than p->trailspace blanks,
  *    which can be 0, 1, or 2, remain to the right margin, the line
  *    will be broken.
  *  - TERMP_BRTRSP: Consider trailing whitespace significant
  *    when deciding whether the chunk fits or not.
  *  - TERMP_BRIND: If the chunk does not fit and the output line has
  *    to be broken, start the next line at the right margin instead
  *    of at the offset.  Used together with TERMP_NOBREAK for the tags
  *    in various kinds of tagged lists.
  *  - TERMP_DANGLE: Do not break the output line at the right margin,
  *    append the next chunk after it even if this one is too long.
  *    To be used together with TERMP_NOBREAK.
  *  - TERMP_HANG: Like TERMP_DANGLE, and also suppress padding before
  *    the next chunk if this column is not full.
  */
 void
 term_flushln(struct termp *p)
 {
 	size_t		 i;     /* current input position in p->buf */
 	int		 ntab;	/* number of tabs to prepend */
 	size_t		 vis;   /* current visual position on output */
 	size_t		 vbl;   /* number of blanks to prepend to output */
 	size_t		 vend;	/* end of word visual position on output */
 	size_t		 bp;    /* visual right border position */
 	size_t		 dv;    /* temporary for visual pos calculations */
 	size_t		 j;     /* temporary loop index for p->buf */
 	size_t		 jhy;	/* last hyph before overflow w/r/t j */
 	size_t		 maxvis; /* output position of visible boundary */
 
 	/*
 	 * First, establish the maximum columns of "visible" content.
 	 * This is usually the difference between the right-margin and
 	 * an indentation, but can be, for tagged lists or columns, a
 	 * small set of values.
 	 *
 	 * The following unsigned-signed subtractions look strange,
 	 * but they are actually correct.  If the int p->overstep
 	 * is negative, it gets sign extended.  Subtracting that
 	 * very large size_t effectively adds a small number to dv.
 	 */
 	dv = p->rmargin > p->offset ? p->rmargin - p->offset : 0;
 	maxvis = (int)dv > p->overstep ? dv - (size_t)p->overstep : 0;
 
 	if (p->flags & TERMP_NOBREAK) {
 		dv = p->maxrmargin > p->offset ?
 		     p->maxrmargin - p->offset : 0;
 		bp = (int)dv > p->overstep ?
 		     dv - (size_t)p->overstep : 0;
 	} else
 		bp = maxvis;
 
 	/*
 	 * Calculate the required amount of padding.
 	 */
 	vbl = p->offset + p->overstep > p->viscol ?
 	      p->offset + p->overstep - p->viscol : 0;
 
 	vis = vend = 0;
 	i = 0;
 
 	while (i < p->col) {
 		/*
 		 * Handle literal tab characters: collapse all
 		 * subsequent tabs into a single huge set of spaces.
 		 */
 		ntab = 0;
 		while (i < p->col && '\t' == p->buf[i]) {
 			vend = (vis / p->tabwidth + 1) * p->tabwidth;
 			vbl += vend - vis;
 			vis = vend;
 			ntab++;
 			i++;
 		}
 
 		/*
 		 * Count up visible word characters.  Control sequences
 		 * (starting with the CSI) aren't counted.  A space
 		 * generates a non-printing word, which is valid (the
 		 * space is printed according to regular spacing rules).
 		 */
 
 		for (j = i, jhy = 0; j < p->col; j++) {
 			if (' ' == p->buf[j] || '\t' == p->buf[j])
 				break;
 
 			/* Back over the last printed character. */
 			if (8 == p->buf[j]) {
 				assert(j);
 				vend -= (*p->width)(p, p->buf[j - 1]);
 				continue;
 			}
 
 			/* Regular word. */
 			/* Break at the hyphen point if we overrun. */
 			if (vend > vis && vend < bp &&
 			    (ASCII_HYPH == p->buf[j] ||
 			     ASCII_BREAK == p->buf[j]))
 				jhy = j;
 
 			/*
 			 * Hyphenation now decided, put back a real
 			 * hyphen such that we get the correct width.
 			 */
 			if (ASCII_HYPH == p->buf[j])
 				p->buf[j] = '-';
 
 			vend += (*p->width)(p, p->buf[j]);
 		}
 
 		/*
 		 * Find out whether we would exceed the right margin.
 		 * If so, break to the next line.
 		 */
 		if (vend > bp && 0 == jhy && vis > 0) {
 			vend -= vis;
 			(*p->endline)(p);
 			p->viscol = 0;
 			if (TERMP_BRIND & p->flags) {
 				vbl = p->rmargin;
 				vend += p->rmargin;
 				vend -= p->offset;
 			} else
 				vbl = p->offset;
 
 			/* use pending tabs on the new line */
 
 			if (0 < ntab)
 				vbl += ntab * p->tabwidth;
 
 			/*
 			 * Remove the p->overstep width.
 			 * Again, if p->overstep is negative,
 			 * sign extension does the right thing.
 			 */
 
 			bp += (size_t)p->overstep;
 			p->overstep = 0;
 		}
 
 		/* Write out the [remaining] word. */
 		for ( ; i < p->col; i++) {
 			if (vend > bp && jhy > 0 && i > jhy)
 				break;
 			if ('\t' == p->buf[i])
 				break;
 			if (' ' == p->buf[i]) {
 				j = i;
 				while (i < p->col && ' ' == p->buf[i])
 					i++;
 				dv = (i - j) * (*p->width)(p, ' ');
 				vbl += dv;
 				vend += dv;
 				break;
 			}
 			if (ASCII_NBRSP == p->buf[i]) {
 				vbl += (*p->width)(p, ' ');
 				continue;
 			}
 			if (ASCII_BREAK == p->buf[i])
 				continue;
 
 			/*
 			 * Now we definitely know there will be
 			 * printable characters to output,
 			 * so write preceding white space now.
 			 */
 			if (vbl) {
 				(*p->advance)(p, vbl);
 				p->viscol += vbl;
 				vbl = 0;
 			}
 
 			(*p->letter)(p, p->buf[i]);
 			if (8 == p->buf[i])
 				p->viscol -= (*p->width)(p, p->buf[i-1]);
 			else
 				p->viscol += (*p->width)(p, p->buf[i]);
 		}
 		vis = vend;
 	}
 
 	/*
 	 * If there was trailing white space, it was not printed;
 	 * so reset the cursor position accordingly.
 	 */
 	if (vis > vbl)
 		vis -= vbl;
 	else
 		vis = 0;
 
 	p->col = 0;
 	p->overstep = 0;
 	p->flags &= ~(TERMP_BACKAFTER | TERMP_BACKBEFORE);
 
 	if ( ! (TERMP_NOBREAK & p->flags)) {
 		p->viscol = 0;
 		(*p->endline)(p);
 		return;
 	}
 
 	if (TERMP_HANG & p->flags) {
 		p->overstep += (int)(p->offset + vis - p->rmargin +
 		    p->trailspace * (*p->width)(p, ' '));
 
 		/*
 		 * If we have overstepped the margin, temporarily move
 		 * it to the right and flag the rest of the line to be
 		 * shorter.
 		 * If there is a request to keep the columns together,
 		 * allow negative overstep when the column is not full.
 		 */
 		if (p->trailspace && p->overstep < 0)
 			p->overstep = 0;
 		return;
 
 	} else if (TERMP_DANGLE & p->flags)
 		return;
 
 	/* Trailing whitespace is significant in some columns. */
 	if (vis && vbl && (TERMP_BRTRSP & p->flags))
 		vis += vbl;
 
 	/* If the column was overrun, break the line. */
 	if (maxvis < vis + p->trailspace * (*p->width)(p, ' ')) {
 		(*p->endline)(p);
 		p->viscol = 0;
 	}
 }
 
 /*
  * A newline only breaks an existing line; it won't assert vertical
  * space.  All data in the output buffer is flushed prior to the newline
  * assertion.
  */
 void
 term_newln(struct termp *p)
 {
 
 	p->flags |= TERMP_NOSPACE;
 	if (p->col || p->viscol)
 		term_flushln(p);
 }
 
 /*
  * Asserts a vertical space (a full, empty line-break between lines).
  * Note that if used twice, this will cause two blank spaces and so on.
  * All data in the output buffer is flushed prior to the newline
  * assertion.
  */
 void
 term_vspace(struct termp *p)
 {
 
 	term_newln(p);
 	p->viscol = 0;
 	if (0 < p->skipvsp)
 		p->skipvsp--;
 	else
 		(*p->endline)(p);
 }
 
 /* Swap current and previous font; for \fP and .ft P */
 void
 term_fontlast(struct termp *p)
 {
 	enum termfont	 f;
 
 	f = p->fontl;
 	p->fontl = p->fontq[p->fonti];
 	p->fontq[p->fonti] = f;
 }
 
 /* Set font, save current, discard previous; for \f, .ft, .B etc. */
 void
 term_fontrepl(struct termp *p, enum termfont f)
 {
 
 	p->fontl = p->fontq[p->fonti];
 	p->fontq[p->fonti] = f;
 }
 
 /* Set font, save previous. */
 void
 term_fontpush(struct termp *p, enum termfont f)
 {
 
 	p->fontl = p->fontq[p->fonti];
 	if (++p->fonti == p->fontsz) {
 		p->fontsz += 8;
 		p->fontq = mandoc_reallocarray(p->fontq,
 		    p->fontsz, sizeof(*p->fontq));
 	}
 	p->fontq[p->fonti] = f;
 }
 
 /* Flush to make the saved pointer current again. */
 void
 term_fontpopq(struct termp *p, int i)
 {
 
 	assert(i >= 0);
 	if (p->fonti > i)
 		p->fonti = i;
 }
 
 /* Pop one font off the stack. */
 void
 term_fontpop(struct termp *p)
 {
 
 	assert(p->fonti);
 	p->fonti--;
 }
 
 /*
  * Handle pwords, partial words, which may be either a single word or a
  * phrase that cannot be broken down (such as a literal string).  This
  * handles word styling.
  */
 void
 term_word(struct termp *p, const char *word)
 {
 	const char	 nbrsp[2] = { ASCII_NBRSP, 0 };
 	const char	*seq, *cp;
 	int		 sz, uc;
 	size_t		 ssz;
 	enum mandoc_esc	 esc;
 
 	if ( ! (TERMP_NOSPACE & p->flags)) {
 		if ( ! (TERMP_KEEP & p->flags)) {
 			bufferc(p, ' ');
 			if (TERMP_SENTENCE & p->flags)
 				bufferc(p, ' ');
 		} else
 			bufferc(p, ASCII_NBRSP);
 	}
 	if (TERMP_PREKEEP & p->flags)
 		p->flags |= TERMP_KEEP;
 
 	if ( ! (p->flags & TERMP_NONOSPACE))
 		p->flags &= ~TERMP_NOSPACE;
 	else
 		p->flags |= TERMP_NOSPACE;
 
 	p->flags &= ~(TERMP_SENTENCE | TERMP_NONEWLINE);
 	p->skipvsp = 0;
 
 	while ('\0' != *word) {
 		if ('\\' != *word) {
 			if (TERMP_NBRWORD & p->flags) {
 				if (' ' == *word) {
 					encode(p, nbrsp, 1);
 					word++;
 					continue;
 				}
 				ssz = strcspn(word, "\\ ");
 			} else
 				ssz = strcspn(word, "\\");
 			encode(p, word, ssz);
 			word += (int)ssz;
 			continue;
 		}
 
 		word++;
 		esc = mandoc_escape(&word, &seq, &sz);
 		if (ESCAPE_ERROR == esc)
 			continue;
 
 		switch (esc) {
 		case ESCAPE_UNICODE:
 			uc = mchars_num2uc(seq + 1, sz - 1);
 			break;
 		case ESCAPE_NUMBERED:
 			uc = mchars_num2char(seq, sz);
 			if (uc < 0)
 				continue;
 			break;
 		case ESCAPE_SPECIAL:
 			if (p->enc == TERMENC_ASCII) {
 				cp = mchars_spec2str(seq, sz, &ssz);
 				if (cp != NULL)
 					encode(p, cp, ssz);
 			} else {
 				uc = mchars_spec2cp(seq, sz);
 				if (uc > 0)
 					encode1(p, uc);
 			}
 			continue;
 		case ESCAPE_FONTBOLD:
 			term_fontrepl(p, TERMFONT_BOLD);
 			continue;
 		case ESCAPE_FONTITALIC:
 			term_fontrepl(p, TERMFONT_UNDER);
 			continue;
 		case ESCAPE_FONTBI:
 			term_fontrepl(p, TERMFONT_BI);
 			continue;
 		case ESCAPE_FONT:
 		case ESCAPE_FONTROMAN:
 			term_fontrepl(p, TERMFONT_NONE);
 			continue;
 		case ESCAPE_FONTPREV:
 			term_fontlast(p);
 			continue;
 		case ESCAPE_NOSPACE:
 			if (p->flags & TERMP_BACKAFTER)
 				p->flags &= ~TERMP_BACKAFTER;
 			else if (*word == '\0')
 				p->flags |= (TERMP_NOSPACE | TERMP_NONEWLINE);
 			continue;
 		case ESCAPE_SKIPCHAR:
 			p->flags |= TERMP_BACKAFTER;
 			continue;
 		case ESCAPE_OVERSTRIKE:
 			cp = seq + sz;
 			while (seq < cp) {
 				if (*seq == '\\') {
 					mandoc_escape(&seq, NULL, NULL);
 					continue;
 				}
 				encode1(p, *seq++);
 				if (seq < cp) {
 					if (p->flags & TERMP_BACKBEFORE)
 						p->flags |= TERMP_BACKAFTER;
 					else
 						p->flags |= TERMP_BACKBEFORE;
 				}
 			}
 			/* Trim trailing backspace/blank pair. */
-			if (p->col > 2 && p->buf[p->col - 1] == ' ')
+			if (p->col > 2 &&
+			    (p->buf[p->col - 1] == ' ' ||
+			     p->buf[p->col - 1] == '\t'))
 				p->col -= 2;
 			continue;
 		default:
 			continue;
 		}
 
 		/*
 		 * Common handling for Unicode and numbered
 		 * character escape sequences.
 		 */
 
 		if (p->enc == TERMENC_ASCII) {
 			cp = ascii_uc2str(uc);
 			encode(p, cp, strlen(cp));
 		} else {
 			if ((uc < 0x20 && uc != 0x09) ||
 			    (uc > 0x7E && uc < 0xA0))
 				uc = 0xFFFD;
 			encode1(p, uc);
 		}
 	}
 	p->flags &= ~TERMP_NBRWORD;
 }
 
 static void
 adjbuf(struct termp *p, size_t sz)
 {
 
 	if (0 == p->maxcols)
 		p->maxcols = 1024;
 	while (sz >= p->maxcols)
 		p->maxcols <<= 2;
 
 	p->buf = mandoc_reallocarray(p->buf, p->maxcols, sizeof(int));
 }
 
 static void
 bufferc(struct termp *p, char c)
 {
 
 	if (p->col + 1 >= p->maxcols)
 		adjbuf(p, p->col + 1);
 
 	p->buf[p->col++] = c;
 }
 
 /*
  * See encode().
  * Do this for a single (probably unicode) value.
  * Does not check for non-decorated glyphs.
  */
 static void
 encode1(struct termp *p, int c)
 {
 	enum termfont	  f;
 
 	if (p->col + 7 >= p->maxcols)
 		adjbuf(p, p->col + 7);
 
 	f = (c == ASCII_HYPH || c > 127 || isgraph(c)) ?
 	    p->fontq[p->fonti] : TERMFONT_NONE;
 
 	if (p->flags & TERMP_BACKBEFORE) {
-		if (p->buf[p->col - 1] == ' ')
+		if (p->buf[p->col - 1] == ' ' || p->buf[p->col - 1] == '\t')
 			p->col--;
 		else
 			p->buf[p->col++] = 8;
 		p->flags &= ~TERMP_BACKBEFORE;
 	}
 	if (TERMFONT_UNDER == f || TERMFONT_BI == f) {
 		p->buf[p->col++] = '_';
 		p->buf[p->col++] = 8;
 	}
 	if (TERMFONT_BOLD == f || TERMFONT_BI == f) {
 		if (ASCII_HYPH == c)
 			p->buf[p->col++] = '-';
 		else
 			p->buf[p->col++] = c;
 		p->buf[p->col++] = 8;
 	}
 	p->buf[p->col++] = c;
 	if (p->flags & TERMP_BACKAFTER) {
 		p->flags |= TERMP_BACKBEFORE;
 		p->flags &= ~TERMP_BACKAFTER;
 	}
 }
 
 static void
 encode(struct termp *p, const char *word, size_t sz)
 {
 	size_t		  i;
 
 	if (p->col + 2 + (sz * 5) >= p->maxcols)
 		adjbuf(p, p->col + 2 + (sz * 5));
 
 	for (i = 0; i < sz; i++) {
 		if (ASCII_HYPH == word[i] ||
 		    isgraph((unsigned char)word[i]))
 			encode1(p, word[i]);
-		else
+		else {
 			p->buf[p->col++] = word[i];
+
+			/*
+			 * Postpone the effect of \z while handling
+			 * an overstrike sequence from ascii_uc2str().
+			 */
+
+			if (word[i] == '\b' &&
+			    (p->flags & TERMP_BACKBEFORE)) {
+				p->flags &= ~TERMP_BACKBEFORE;
+				p->flags |= TERMP_BACKAFTER;
+			}
+		}
 	}
 }
 
 void
 term_setwidth(struct termp *p, const char *wstr)
 {
 	struct roffsu	 su;
 	int		 iop, width;
 
 	iop = 0;
 	width = 0;
 	if (NULL != wstr) {
 		switch (*wstr) {
 		case '+':
 			iop = 1;
 			wstr++;
 			break;
 		case '-':
 			iop = -1;
 			wstr++;
 			break;
 		default:
 			break;
 		}
 		if (a2roffsu(wstr, &su, SCALE_MAX))
 			width = term_hspan(p, &su);
 		else
 			iop = 0;
 	}
 	(*p->setwidth)(p, iop, width);
 }
 
 size_t
 term_len(const struct termp *p, size_t sz)
 {
 
 	return (*p->width)(p, ' ') * sz;
 }
 
 static size_t
 cond_width(const struct termp *p, int c, int *skip)
 {
 
 	if (*skip) {
 		(*skip) = 0;
 		return 0;
 	} else
 		return (*p->width)(p, c);
 }
 
 size_t
 term_strlen(const struct termp *p, const char *cp)
 {
 	size_t		 sz, rsz, i;
 	int		 ssz, skip, uc;
 	const char	*seq, *rhs;
 	enum mandoc_esc	 esc;
 	static const char rej[] = { '\\', ASCII_NBRSP, ASCII_HYPH,
 			ASCII_BREAK, '\0' };
 
 	/*
 	 * Account for escaped sequences within string length
 	 * calculations.  This follows the logic in term_word() as we
 	 * must calculate the width of produced strings.
 	 */
 
 	sz = 0;
 	skip = 0;
 	while ('\0' != *cp) {
 		rsz = strcspn(cp, rej);
 		for (i = 0; i < rsz; i++)
 			sz += cond_width(p, *cp++, &skip);
 
 		switch (*cp) {
 		case '\\':
 			cp++;
 			esc = mandoc_escape(&cp, &seq, &ssz);
 			if (ESCAPE_ERROR == esc)
 				continue;
 
 			rhs = NULL;
 
 			switch (esc) {
 			case ESCAPE_UNICODE:
 				uc = mchars_num2uc(seq + 1, ssz - 1);
 				break;
 			case ESCAPE_NUMBERED:
 				uc = mchars_num2char(seq, ssz);
 				if (uc < 0)
 					continue;
 				break;
 			case ESCAPE_SPECIAL:
 				if (p->enc == TERMENC_ASCII) {
 					rhs = mchars_spec2str(seq, ssz, &rsz);
 					if (rhs != NULL)
 						break;
 				} else {
 					uc = mchars_spec2cp(seq, ssz);
 					if (uc > 0)
 						sz += cond_width(p, uc, &skip);
 				}
 				continue;
 			case ESCAPE_SKIPCHAR:
 				skip = 1;
 				continue;
 			case ESCAPE_OVERSTRIKE:
 				rsz = 0;
 				rhs = seq + ssz;
 				while (seq < rhs) {
 					if (*seq == '\\') {
 						mandoc_escape(&seq, NULL, NULL);
 						continue;
 					}
 					i = (*p->width)(p, *seq++);
 					if (rsz < i)
 						rsz = i;
 				}
 				sz += rsz;
 				continue;
 			default:
 				continue;
 			}
 
 			/*
 			 * Common handling for Unicode and numbered
 			 * character escape sequences.
 			 */
 
 			if (rhs == NULL) {
 				if (p->enc == TERMENC_ASCII) {
 					rhs = ascii_uc2str(uc);
 					rsz = strlen(rhs);
 				} else {
 					if ((uc < 0x20 && uc != 0x09) ||
 					    (uc > 0x7E && uc < 0xA0))
 						uc = 0xFFFD;
 					sz += cond_width(p, uc, &skip);
 					continue;
 				}
 			}
 
 			if (skip) {
 				skip = 0;
 				break;
 			}
 
 			/*
 			 * Common handling for all escape sequences
 			 * printing more than one character.
 			 */
 
 			for (i = 0; i < rsz; i++)
 				sz += (*p->width)(p, *rhs++);
 			break;
 		case ASCII_NBRSP:
 			sz += cond_width(p, ' ', &skip);
 			cp++;
 			break;
 		case ASCII_HYPH:
 			sz += cond_width(p, '-', &skip);
 			cp++;
 			break;
 		default:
 			break;
 		}
 	}
 
 	return sz;
 }
 
 int
 term_vspan(const struct termp *p, const struct roffsu *su)
 {
 	double		 r;
 	int		 ri;
 
 	switch (su->unit) {
 	case SCALE_BU:
 		r = su->scale / 40.0;
 		break;
 	case SCALE_CM:
 		r = su->scale * 6.0 / 2.54;
 		break;
 	case SCALE_FS:
 		r = su->scale * 65536.0 / 40.0;
 		break;
 	case SCALE_IN:
 		r = su->scale * 6.0;
 		break;
 	case SCALE_MM:
 		r = su->scale * 0.006;
 		break;
 	case SCALE_PC:
 		r = su->scale;
 		break;
 	case SCALE_PT:
 		r = su->scale / 12.0;
 		break;
 	case SCALE_EN:
 	case SCALE_EM:
 		r = su->scale * 0.6;
 		break;
 	case SCALE_VS:
 		r = su->scale;
 		break;
 	default:
 		abort();
 	}
 	ri = r > 0.0 ? r + 0.4995 : r - 0.4995;
 	return ri < 66 ? ri : 1;
 }
 
 /*
  * Convert a scaling width to basic units, rounding down.
  */
 int
 term_hspan(const struct termp *p, const struct roffsu *su)
 {
 
 	return (*p->hspan)(p, su);
 }
Index: stable/11/contrib/mdocml/term_ascii.c
===================================================================
--- stable/11/contrib/mdocml/term_ascii.c	(revision 316419)
+++ stable/11/contrib/mdocml/term_ascii.c	(revision 316420)
@@ -1,382 +1,382 @@
-/*	$Id: term_ascii.c,v 1.53 2016/07/08 22:29:05 schwarze Exp $ */
+/*	$Id: term_ascii.c,v 1.54 2016/07/31 09:29:13 schwarze Exp $ */
 /*
  * Copyright (c) 2010, 2011 Kristaps Dzonsons 
  * Copyright (c) 2014, 2015 Ingo Schwarze 
  *
  * 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 AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h"
 
 #include 
 
 #include 
 #if HAVE_WCHAR
 #include 
 #endif
 #include 
 #include 
 #include 
 #include 
 #if HAVE_WCHAR
 #include 
 #endif
 
 #include "mandoc.h"
 #include "mandoc_aux.h"
 #include "out.h"
 #include "term.h"
 #include "manconf.h"
 #include "main.h"
 
 static	struct termp	 *ascii_init(enum termenc, const struct manoutput *);
 static	int		  ascii_hspan(const struct termp *,
 				const struct roffsu *);
 static	size_t		  ascii_width(const struct termp *, int);
 static	void		  ascii_advance(struct termp *, size_t);
 static	void		  ascii_begin(struct termp *);
 static	void		  ascii_end(struct termp *);
 static	void		  ascii_endline(struct termp *);
 static	void		  ascii_letter(struct termp *, int);
 static	void		  ascii_setwidth(struct termp *, int, int);
 
 #if HAVE_WCHAR
 static	void		  locale_advance(struct termp *, size_t);
 static	void		  locale_endline(struct termp *);
 static	void		  locale_letter(struct termp *, int);
 static	size_t		  locale_width(const struct termp *, int);
 #endif
 
 
 static struct termp *
 ascii_init(enum termenc enc, const struct manoutput *outopts)
 {
 #if HAVE_WCHAR
 	char		*v;
 #endif
 	struct termp	*p;
 
 	p = mandoc_calloc(1, sizeof(struct termp));
 
 	p->line = 1;
 	p->tabwidth = 5;
 	p->defrmargin = p->lastrmargin = 78;
 	p->fontq = mandoc_reallocarray(NULL,
 	     (p->fontsz = 8), sizeof(enum termfont));
 	p->fontq[0] = p->fontl = TERMFONT_NONE;
 
 	p->begin = ascii_begin;
 	p->end = ascii_end;
 	p->hspan = ascii_hspan;
 	p->type = TERMTYPE_CHAR;
 
 	p->enc = TERMENC_ASCII;
 	p->advance = ascii_advance;
 	p->endline = ascii_endline;
 	p->letter = ascii_letter;
 	p->setwidth = ascii_setwidth;
 	p->width = ascii_width;
 
 #if HAVE_WCHAR
 	if (TERMENC_ASCII != enc) {
 
 		/*
 		 * Do not change any of this to LC_ALL.  It might break
 		 * the formatting by subtly changing the behaviour of
 		 * various functions, for example strftime(3).  As a
 		 * worst case, it might even cause buffer overflows.
 		 */
 
 		v = TERMENC_LOCALE == enc ?
 		    setlocale(LC_CTYPE, "") :
-		    setlocale(LC_CTYPE, "en_US.UTF-8");
+		    setlocale(LC_CTYPE, UTF8_LOCALE);
 		if (NULL != v && MB_CUR_MAX > 1) {
 			p->enc = enc;
 			p->advance = locale_advance;
 			p->endline = locale_endline;
 			p->letter = locale_letter;
 			p->width = locale_width;
 		}
 	}
 #endif
 
 	if (outopts->mdoc) {
 		p->mdocstyle = 1;
 		p->defindent = 5;
 	}
 	if (outopts->indent)
 		p->defindent = outopts->indent;
 	if (outopts->width)
 		p->defrmargin = outopts->width;
 	if (outopts->synopsisonly)
 		p->synopsisonly = 1;
 
 	return p;
 }
 
 void *
 ascii_alloc(const struct manoutput *outopts)
 {
 
 	return ascii_init(TERMENC_ASCII, outopts);
 }
 
 void *
 utf8_alloc(const struct manoutput *outopts)
 {
 
 	return ascii_init(TERMENC_UTF8, outopts);
 }
 
 void *
 locale_alloc(const struct manoutput *outopts)
 {
 
 	return ascii_init(TERMENC_LOCALE, outopts);
 }
 
 static void
 ascii_setwidth(struct termp *p, int iop, int width)
 {
 
 	width /= 24;
 	p->rmargin = p->defrmargin;
 	if (iop > 0)
 		p->defrmargin += width;
 	else if (iop == 0)
 		p->defrmargin = width ? (size_t)width : p->lastrmargin;
 	else if (p->defrmargin > (size_t)width)
 		p->defrmargin -= width;
 	else
 		p->defrmargin = 0;
 	p->lastrmargin = p->rmargin;
 	p->rmargin = p->maxrmargin = p->defrmargin;
 }
 
 void
 terminal_sepline(void *arg)
 {
 	struct termp	*p;
 	size_t		 i;
 
 	p = (struct termp *)arg;
 	(*p->endline)(p);
 	for (i = 0; i < p->defrmargin; i++)
 		(*p->letter)(p, '-');
 	(*p->endline)(p);
 	(*p->endline)(p);
 }
 
 static size_t
 ascii_width(const struct termp *p, int c)
 {
 
 	return 1;
 }
 
 void
 ascii_free(void *arg)
 {
 
 	term_free((struct termp *)arg);
 }
 
 static void
 ascii_letter(struct termp *p, int c)
 {
 
 	putchar(c);
 }
 
 static void
 ascii_begin(struct termp *p)
 {
 
 	(*p->headf)(p, p->argf);
 }
 
 static void
 ascii_end(struct termp *p)
 {
 
 	(*p->footf)(p, p->argf);
 }
 
 static void
 ascii_endline(struct termp *p)
 {
 
 	p->line++;
 	putchar('\n');
 }
 
 static void
 ascii_advance(struct termp *p, size_t len)
 {
 	size_t		i;
 
 	for (i = 0; i < len; i++)
 		putchar(' ');
 }
 
 static int
 ascii_hspan(const struct termp *p, const struct roffsu *su)
 {
 	double		 r;
 
 	switch (su->unit) {
 	case SCALE_BU:
 		r = su->scale;
 		break;
 	case SCALE_CM:
 		r = su->scale * 240.0 / 2.54;
 		break;
 	case SCALE_FS:
 		r = su->scale * 65536.0;
 		break;
 	case SCALE_IN:
 		r = su->scale * 240.0;
 		break;
 	case SCALE_MM:
 		r = su->scale * 0.24;
 		break;
 	case SCALE_VS:
 	case SCALE_PC:
 		r = su->scale * 40.0;
 		break;
 	case SCALE_PT:
 		r = su->scale * 10.0 / 3.0;
 		break;
 	case SCALE_EN:
 	case SCALE_EM:
 		r = su->scale * 24.0;
 		break;
 	default:
 		abort();
 	}
 	return r > 0.0 ? r + 0.01 : r - 0.01;
 }
 
 const char *
 ascii_uc2str(int uc)
 {
 	static const char nbrsp[2] = { ASCII_NBRSP, '\0' };
 	static const char *tab[] = {
 	"","","","","","","","",
 	"",	"\t",	"",	"",	"",	"",	"",	"",
 	"","","","","","","","",
 	"","",	"","","",	"",	"",	"",
 	" ",	"!",	"\"",	"#",	"$",	"%",	"&",	"'",
 	"(",	")",	"*",	"+",	",",	"-",	".",	"/",
 	"0",	"1",	"2",	"3",	"4",	"5",	"6",	"7",
 	"8",	"9",	":",	";",	"<",	"=",	">",	"?",
 	"@",	"A",	"B",	"C",	"D",	"E",	"F",	"G",
 	"H",	"I",	"J",	"K",	"L",	"M",	"N",	"O",
 	"P",	"Q",	"R",	"S",	"T",	"U",	"V",	"W",
 	"X",	"Y",	"Z",	"[",	"\\",	"]",	"^",	"_",
 	"`",	"a",	"b",	"c",	"d",	"e",	"f",	"g",
 	"h",	"i",	"j",	"k",	"l",	"m",	"n",	"o",
 	"p",	"q",	"r",	"s",	"t",	"u",	"v",	"w",
 	"x",	"y",	"z",	"{",	"|",	"}",	"~",	"",
 	"<80>",	"<81>",	"<82>",	"<83>",	"<84>",	"<85>",	"<86>",	"<87>",
 	"<88>",	"<89>",	"<8A>",	"<8B>",	"<8C>",	"<8D>",	"<8E>",	"<8F>",
 	"<90>",	"<91>",	"<92>",	"<93>",	"<94>",	"<95>",	"<96>",	"<97>",
 	"<99>",	"<99>",	"<9A>",	"<9B>",	"<9C>",	"<9D>",	"<9E>",	"<9F>",
 	nbrsp,	"!",	"/\bc",	"GBP",	"o\bx",	"=\bY",	"|",	"",
 	"\"",	"(C)",	"_\ba",	"<<",	"~",	"",	"(R)",	"-",
 	"","+-",	"2",	"3",	"'",	",\bu",	"",".",
 	",",	"1",	"_\bo",	">>",	"1/4",	"1/2",	"3/4",	"?",
 	"`\bA",	"'\bA",	"^\bA",	"~\bA",	"\"\bA","o\bA",	"AE",	",\bC",
 	"`\bE",	"'\bE",	"^\bE",	"\"\bE","`\bI",	"'\bI",	"^\bI",	"\"\bI",
 	"-\bD",	"~\bN",	"`\bO",	"'\bO",	"^\bO",	"~\bO",	"\"\bO","x",
 	"/\bO",	"`\bU",	"'\bU",	"^\bU",	"\"\bU","'\bY",	"Th",	"ss",
 	"`\ba",	"'\ba",	"^\ba",	"~\ba",	"\"\ba","o\ba",	"ae",	",\bc",
 	"`\be",	"'\be",	"^\be",	"\"\be","`\bi",	"'\bi",	"^\bi",	"\"\bi",
 	"d",	"~\bn",	"`\bo",	"'\bo",	"^\bo",	"~\bo",	"\"\bo","-:-",
 	"/\bo",	"`\bu",	"'\bu",	"^\bu",	"\"\bu","'\by",	"th",	"\"\by",
 	"A",	"a",	"A",	"a",	"A",	"a",	"'\bC",	"'\bc",
 	"^\bC",	"^\bc",	"C",	"c",	"C",	"c",	"D",	"d",
 	"/\bD",	"/\bd",	"E",	"e",	"E",	"e",	"E",	"e",
 	"E",	"e",	"E",	"e",	"^\bG",	"^\bg",	"G",	"g",
 	"G",	"g",	",\bG",	",\bg",	"^\bH",	"^\bh",	"/\bH",	"/\bh",
 	"~\bI",	"~\bi",	"I",	"i",	"I",	"i",	"I",	"i",
 	"I",	"i",	"IJ",	"ij",	"^\bJ",	"^\bj",	",\bK",	",\bk",
 	"q",	"'\bL",	"'\bl",	",\bL",	",\bl",	"L",	"l",	"L",
 	"l",	"/\bL",	"/\bl",	"'\bN",	"'\bn",	",\bN",	",\bn",	"N",
 	"n",	"'n",	"Ng",	"ng",	"O",	"o",	"O",	"o",
 	"O",	"o",	"OE",	"oe",	"'\bR",	"'\br",	",\bR",	",\br",
 	"R",	"r",	"'\bS",	"'\bs",	"^\bS",	"^\bs",	",\bS",	",\bs",
 	"S",	"s",	",\bT",	",\bt",	"T",	"t",	"/\bT",	"/\bt",
 	"~\bU",	"~\bu",	"U",	"u",	"U",	"u",	"U",	"u",
 	"U",	"u",	"U",	"u",	"^\bW",	"^\bw",	"^\bY",	"^\by",
 	"\"\bY","'\bZ",	"'\bz",	"Z",	"z",	"Z",	"z",	"s",
 	"b",	"B",	"B",	"b",	"6",	"6",	"O",	"C",
 	"c",	"D",	"D",	"D",	"d",	"d",	"3",	"@",
 	"E",	"F",	",\bf",	"G",	"G",	"hv",	"I",	"/\bI",
 	"K",	"k",	"/\bl",	"l",	"W",	"N",	"n",	"~\bO",
 	"O",	"o",	"OI",	"oi",	"P",	"p",	"YR",	"2",
 	"2",	"SH",	"sh",	"t",	"T",	"t",	"T",	"U",
 	"u",	"Y",	"V",	"Y",	"y",	"/\bZ",	"/\bz",	"ZH",
 	"ZH",	"zh",	"zh",	"/\b2",	"5",	"5",	"ts",	"w",
 	"|",	"||",	"|=",	"!",	"DZ",	"Dz",	"dz",	"LJ",
 	"Lj",	"lj",	"NJ",	"Nj",	"nj",	"A",	"a",	"I",
 	"i",	"O",	"o",	"U",	"u",	"U",	"u",	"U",
 	"u",	"U",	"u",	"U",	"u",	"@",	"A",	"a",
 	"A",	"a",	"AE",	"ae",	"/\bG",	"/\bg",	"G",	"g",
 	"K",	"k",	"O",	"o",	"O",	"o",	"ZH",	"zh",
 	"j",	"DZ",	"Dz",	"dz",	"'\bG",	"'\bg",	"HV",	"W",
 	"`\bN",	"`\bn",	"A",	"a",	"'\bAE","'\bae","O",	"o"};
 
 	assert(uc >= 0);
 	if ((size_t)uc < sizeof(tab)/sizeof(tab[0]))
 		return tab[uc];
 	return mchars_uc2str(uc);
 }
 
 #if HAVE_WCHAR
 static size_t
 locale_width(const struct termp *p, int c)
 {
 	int		rc;
 
 	if (c == ASCII_NBRSP)
 		c = ' ';
 	rc = wcwidth(c);
 	if (rc < 0)
 		rc = 0;
 	return rc;
 }
 
 static void
 locale_advance(struct termp *p, size_t len)
 {
 	size_t		i;
 
 	for (i = 0; i < len; i++)
 		putwchar(L' ');
 }
 
 static void
 locale_endline(struct termp *p)
 {
 
 	p->line++;
 	putwchar(L'\n');
 }
 
 static void
 locale_letter(struct termp *p, int c)
 {
 
 	putwchar(c);
 }
 #endif
Index: stable/11/contrib/mdocml/term_ps.c
===================================================================
--- stable/11/contrib/mdocml/term_ps.c	(revision 316419)
+++ stable/11/contrib/mdocml/term_ps.c	(revision 316420)
@@ -1,1339 +1,1325 @@
-/*	$Id: term_ps.c,v 1.80 2015/12/23 20:50:13 schwarze Exp $ */
+/*	$Id: term_ps.c,v 1.82 2016/08/10 11:03:43 schwarze Exp $ */
 /*
  * Copyright (c) 2010, 2011 Kristaps Dzonsons 
- * Copyright (c) 2014, 2015 Ingo Schwarze 
+ * Copyright (c) 2014, 2015, 2016 Ingo Schwarze 
  *
  * 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 AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h"
 
 #include 
 
 #include 
 #if HAVE_ERR
 #include 
 #endif
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 
 #include "mandoc_aux.h"
 #include "out.h"
 #include "term.h"
 #include "manconf.h"
 #include "main.h"
 
 /* These work the buffer used by the header and footer. */
 #define	PS_BUFSLOP	  128
 
 /* Convert PostScript point "x" to an AFM unit. */
 #define	PNT2AFM(p, x) \
 	(size_t)((double)(x) * (1000.0 / (double)(p)->ps->scale))
 
 /* Convert an AFM unit "x" to a PostScript points */
 #define	AFM2PNT(p, x) \
 	((double)(x) / (1000.0 / (double)(p)->ps->scale))
 
 struct	glyph {
 	unsigned short	  wx; /* WX in AFM */
 };
 
 struct	font {
 	const char	 *name; /* FontName in AFM */
 #define	MAXCHAR		  95 /* total characters we can handle */
 	struct glyph	  gly[MAXCHAR]; /* glyph metrics */
 };
 
 struct	termp_ps {
 	int		  flags;
 #define	PS_INLINE	 (1 << 0)	/* we're in a word */
 #define	PS_MARGINS	 (1 << 1)	/* we're in the margins */
 #define	PS_NEWPAGE	 (1 << 2)	/* new page, no words yet */
 #define	PS_BACKSP	 (1 << 3)	/* last character was backspace */
 	size_t		  pscol;	/* visible column (AFM units) */
 	size_t		  pscolnext;	/* used for overstrike */
 	size_t		  psrow;	/* visible row (AFM units) */
 	char		 *psmarg;	/* margin buf */
 	size_t		  psmargsz;	/* margin buf size */
 	size_t		  psmargcur;	/* cur index in margin buf */
 	char		  last;		/* last non-backspace seen */
 	enum termfont	  lastf;	/* last set font */
 	enum termfont	  nextf;	/* building next font here */
 	size_t		  scale;	/* font scaling factor */
 	size_t		  pages;	/* number of pages shown */
 	size_t		  lineheight;	/* line height (AFM units) */
 	size_t		  top;		/* body top (AFM units) */
 	size_t		  bottom;	/* body bottom (AFM units) */
 	size_t		  height;	/* page height (AFM units */
 	size_t		  width;	/* page width (AFM units) */
 	size_t		  lastwidth;	/* page width before last ll */
 	size_t		  left;		/* body left (AFM units) */
 	size_t		  header;	/* header pos (AFM units) */
 	size_t		  footer;	/* footer pos (AFM units) */
 	size_t		  pdfbytes;	/* current output byte */
 	size_t		  pdflastpg;	/* byte of last page mark */
 	size_t		  pdfbody;	/* start of body object */
 	size_t		 *pdfobjs;	/* table of object offsets */
 	size_t		  pdfobjsz;	/* size of pdfobjs */
 };
 
 static	int		  ps_hspan(const struct termp *,
 				const struct roffsu *);
 static	size_t		  ps_width(const struct termp *, int);
 static	void		  ps_advance(struct termp *, size_t);
 static	void		  ps_begin(struct termp *);
 static	void		  ps_closepage(struct termp *);
 static	void		  ps_end(struct termp *);
 static	void		  ps_endline(struct termp *);
-static	void		  ps_fclose(struct termp *);
 static	void		  ps_growbuf(struct termp *, size_t);
 static	void		  ps_letter(struct termp *, int);
 static	void		  ps_pclose(struct termp *);
+static	void		  ps_plast(struct termp *);
 static	void		  ps_pletter(struct termp *, int);
-#if __GNUC__ - 0 >= 4
-__attribute__((__format__ (__printf__, 2, 3)))
-#endif
-static	void		  ps_printf(struct termp *, const char *, ...);
+static	void		  ps_printf(struct termp *, const char *, ...)
+				__attribute__((__format__ (printf, 2, 3)));
 static	void		  ps_putchar(struct termp *, char);
 static	void		  ps_setfont(struct termp *, enum termfont);
 static	void		  ps_setwidth(struct termp *, int, int);
 static	struct termp	 *pspdf_alloc(const struct manoutput *);
 static	void		  pdf_obj(struct termp *, size_t);
 
 /*
  * We define, for the time being, three fonts: bold, oblique/italic, and
  * normal (roman).  The following table hard-codes the font metrics for
  * ASCII, i.e., 32--127.
  */
 
 static	const struct font fonts[TERMFONT__MAX] = {
 	{ "Times-Roman", {
 		{ 250 },
 		{ 333 },
 		{ 408 },
 		{ 500 },
 		{ 500 },
 		{ 833 },
 		{ 778 },
 		{ 333 },
 		{ 333 },
 		{ 333 },
 		{ 500 },
 		{ 564 },
 		{ 250 },
 		{ 333 },
 		{ 250 },
 		{ 278 },
 		{ 500 },
 		{ 500 },
 		{ 500 },
 		{ 500 },
 		{ 500 },
 		{ 500 },
 		{ 500 },
 		{ 500 },
 		{ 500 },
 		{ 500 },
 		{ 278 },
 		{ 278 },
 		{ 564 },
 		{ 564 },
 		{ 564 },
 		{ 444 },
 		{ 921 },
 		{ 722 },
 		{ 667 },
 		{ 667 },
 		{ 722 },
 		{ 611 },
 		{ 556 },
 		{ 722 },
 		{ 722 },
 		{ 333 },
 		{ 389 },
 		{ 722 },
 		{ 611 },
 		{ 889 },
 		{ 722 },
 		{ 722 },
 		{ 556 },
 		{ 722 },
 		{ 667 },
 		{ 556 },
 		{ 611 },
 		{ 722 },
 		{ 722 },
 		{ 944 },
 		{ 722 },
 		{ 722 },
 		{ 611 },
 		{ 333 },
 		{ 278 },
 		{ 333 },
 		{ 469 },
 		{ 500 },
 		{ 333 },
 		{ 444 },
 		{ 500 },
 		{ 444 },
 		{  500},
 		{  444},
 		{  333},
 		{  500},
 		{  500},
 		{  278},
 		{  278},
 		{  500},
 		{  278},
 		{  778},
 		{  500},
 		{  500},
 		{  500},
 		{  500},
 		{  333},
 		{  389},
 		{  278},
 		{  500},
 		{  500},
 		{  722},
 		{  500},
 		{  500},
 		{  444},
 		{  480},
 		{  200},
 		{  480},
 		{  541},
 	} },
 	{ "Times-Bold", {
 		{ 250  },
 		{ 333  },
 		{ 555  },
 		{ 500  },
 		{ 500  },
 		{ 1000 },
 		{ 833  },
 		{ 333  },
 		{ 333  },
 		{ 333  },
 		{ 500  },
 		{ 570  },
 		{ 250  },
 		{ 333  },
 		{ 250  },
 		{ 278  },
 		{ 500  },
 		{ 500  },
 		{ 500  },
 		{ 500  },
 		{ 500  },
 		{ 500  },
 		{ 500  },
 		{ 500  },
 		{ 500  },
 		{ 500  },
 		{ 333  },
 		{ 333  },
 		{ 570  },
 		{ 570  },
 		{ 570  },
 		{ 500  },
 		{ 930  },
 		{ 722  },
 		{ 667  },
 		{ 722  },
 		{ 722  },
 		{ 667  },
 		{ 611  },
 		{ 778  },
 		{ 778  },
 		{ 389  },
 		{ 500  },
 		{ 778  },
 		{ 667  },
 		{ 944  },
 		{ 722  },
 		{ 778  },
 		{ 611  },
 		{ 778  },
 		{ 722  },
 		{ 556  },
 		{ 667  },
 		{ 722  },
 		{ 722  },
 		{ 1000 },
 		{ 722  },
 		{ 722  },
 		{ 667  },
 		{ 333  },
 		{ 278  },
 		{ 333  },
 		{ 581  },
 		{ 500  },
 		{ 333  },
 		{ 500  },
 		{ 556  },
 		{ 444  },
 		{  556 },
 		{  444 },
 		{  333 },
 		{  500 },
 		{  556 },
 		{  278 },
 		{  333 },
 		{  556 },
 		{  278 },
 		{  833 },
 		{  556 },
 		{  500 },
 		{  556 },
 		{  556 },
 		{  444 },
 		{  389 },
 		{  333 },
 		{  556 },
 		{  500 },
 		{  722 },
 		{  500 },
 		{  500 },
 		{  444 },
 		{  394 },
 		{  220 },
 		{  394 },
 		{  520 },
 	} },
 	{ "Times-Italic", {
 		{ 250  },
 		{ 333  },
 		{ 420  },
 		{ 500  },
 		{ 500  },
 		{ 833  },
 		{ 778  },
 		{ 333  },
 		{ 333  },
 		{ 333  },
 		{ 500  },
 		{ 675  },
 		{ 250  },
 		{ 333  },
 		{ 250  },
 		{ 278  },
 		{ 500  },
 		{ 500  },
 		{ 500  },
 		{ 500  },
 		{ 500  },
 		{ 500  },
 		{ 500  },
 		{ 500  },
 		{ 500  },
 		{ 500  },
 		{ 333  },
 		{ 333  },
 		{ 675  },
 		{ 675  },
 		{ 675  },
 		{ 500  },
 		{ 920  },
 		{ 611  },
 		{ 611  },
 		{ 667  },
 		{ 722  },
 		{ 611  },
 		{ 611  },
 		{ 722  },
 		{ 722  },
 		{ 333  },
 		{ 444  },
 		{ 667  },
 		{ 556  },
 		{ 833  },
 		{ 667  },
 		{ 722  },
 		{ 611  },
 		{ 722  },
 		{ 611  },
 		{ 500  },
 		{ 556  },
 		{ 722  },
 		{ 611  },
 		{ 833  },
 		{ 611  },
 		{ 556  },
 		{ 556  },
 		{ 389  },
 		{ 278  },
 		{ 389  },
 		{ 422  },
 		{ 500  },
 		{ 333  },
 		{ 500  },
 		{ 500  },
 		{ 444  },
 		{  500 },
 		{  444 },
 		{  278 },
 		{  500 },
 		{  500 },
 		{  278 },
 		{  278 },
 		{  444 },
 		{  278 },
 		{  722 },
 		{  500 },
 		{  500 },
 		{  500 },
 		{  500 },
 		{  389 },
 		{  389 },
 		{  278 },
 		{  500 },
 		{  444 },
 		{  667 },
 		{  444 },
 		{  444 },
 		{  389 },
 		{  400 },
 		{  275 },
 		{  400 },
 		{  541 },
 	} },
 	{ "Times-BoldItalic", {
 		{  250 },
 		{  389 },
 		{  555 },
 		{  500 },
 		{  500 },
 		{  833 },
 		{  778 },
 		{  333 },
 		{  333 },
 		{  333 },
 		{  500 },
 		{  570 },
 		{  250 },
 		{  333 },
 		{  250 },
 		{  278 },
 		{  500 },
 		{  500 },
 		{  500 },
 		{  500 },
 		{  500 },
 		{  500 },
 		{  500 },
 		{  500 },
 		{  500 },
 		{  500 },
 		{  333 },
 		{  333 },
 		{  570 },
 		{  570 },
 		{  570 },
 		{  500 },
 		{  832 },
 		{  667 },
 		{  667 },
 		{  667 },
 		{  722 },
 		{  667 },
 		{  667 },
 		{  722 },
 		{  778 },
 		{  389 },
 		{  500 },
 		{  667 },
 		{  611 },
 		{  889 },
 		{  722 },
 		{  722 },
 		{  611 },
 		{  722 },
 		{  667 },
 		{  556 },
 		{  611 },
 		{  722 },
 		{  667 },
 		{  889 },
 		{  667 },
 		{  611 },
 		{  611 },
 		{  333 },
 		{  278 },
 		{  333 },
 		{  570 },
 		{  500 },
 		{  333 },
 		{  500 },
 		{  500 },
 		{  444 },
 		{  500 },
 		{  444 },
 		{  333 },
 		{  500 },
 		{  556 },
 		{  278 },
 		{  278 },
 		{  500 },
 		{  278 },
 		{  778 },
 		{  556 },
 		{  500 },
 		{  500 },
 		{  500 },
 		{  389 },
 		{  389 },
 		{  278 },
 		{  556 },
 		{  444 },
 		{  667 },
 		{  500 },
 		{  444 },
 		{  389 },
 		{  348 },
 		{  220 },
 		{  348 },
 		{  570 },
 	} },
 };
 
 void *
 pdf_alloc(const struct manoutput *outopts)
 {
 	struct termp	*p;
 
 	if (NULL != (p = pspdf_alloc(outopts)))
 		p->type = TERMTYPE_PDF;
 
 	return p;
 }
 
 void *
 ps_alloc(const struct manoutput *outopts)
 {
 	struct termp	*p;
 
 	if (NULL != (p = pspdf_alloc(outopts)))
 		p->type = TERMTYPE_PS;
 
 	return p;
 }
 
 static struct termp *
 pspdf_alloc(const struct manoutput *outopts)
 {
 	struct termp	*p;
 	unsigned int	 pagex, pagey;
 	size_t		 marginx, marginy, lineheight;
 	const char	*pp;
 
 	p = mandoc_calloc(1, sizeof(struct termp));
 	p->enc = TERMENC_ASCII;
 	p->fontq = mandoc_reallocarray(NULL,
 	    (p->fontsz = 8), sizeof(enum termfont));
 	p->fontq[0] = p->fontl = TERMFONT_NONE;
 	p->ps = mandoc_calloc(1, sizeof(struct termp_ps));
 
 	p->advance = ps_advance;
 	p->begin = ps_begin;
 	p->end = ps_end;
 	p->endline = ps_endline;
 	p->hspan = ps_hspan;
 	p->letter = ps_letter;
 	p->setwidth = ps_setwidth;
 	p->width = ps_width;
 
 	/* Default to US letter (millimetres). */
 
 	pagex = 216;
 	pagey = 279;
 
 	/*
 	 * The ISO-269 paper sizes can be calculated automatically, but
 	 * it would require bringing in -lm for pow() and I'd rather not
 	 * do that.  So just do it the easy way for now.  Since this
 	 * only happens once, I'm not terribly concerned.
 	 */
 
 	pp = outopts->paper;
 	if (pp && strcasecmp(pp, "letter")) {
 		if (0 == strcasecmp(pp, "a3")) {
 			pagex = 297;
 			pagey = 420;
 		} else if (0 == strcasecmp(pp, "a4")) {
 			pagex = 210;
 			pagey = 297;
 		} else if (0 == strcasecmp(pp, "a5")) {
 			pagex = 148;
 			pagey = 210;
 		} else if (0 == strcasecmp(pp, "legal")) {
 			pagex = 216;
 			pagey = 356;
 		} else if (2 != sscanf(pp, "%ux%u", &pagex, &pagey))
 			warnx("%s: Unknown paper", pp);
 	}
 
 	/*
 	 * This MUST be defined before any PNT2AFM or AFM2PNT
 	 * calculations occur.
 	 */
 
 	p->ps->scale = 11;
 
 	/* Remember millimetres -> AFM units. */
 
 	pagex = PNT2AFM(p, ((double)pagex * 2.834));
 	pagey = PNT2AFM(p, ((double)pagey * 2.834));
 
 	/* Margins are 1/9 the page x and y. */
 
 	marginx = (size_t)((double)pagex / 9.0);
 	marginy = (size_t)((double)pagey / 9.0);
 
 	/* Line-height is 1.4em. */
 
 	lineheight = PNT2AFM(p, ((double)p->ps->scale * 1.4));
 
 	p->ps->width = p->ps->lastwidth = (size_t)pagex;
 	p->ps->height = (size_t)pagey;
 	p->ps->header = pagey - (marginy / 2) - (lineheight / 2);
 	p->ps->top = pagey - marginy;
 	p->ps->footer = (marginy / 2) - (lineheight / 2);
 	p->ps->bottom = marginy;
 	p->ps->left = marginx;
 	p->ps->lineheight = lineheight;
 
 	p->defrmargin = pagex - (marginx * 2);
 	return p;
 }
 
 static void
 ps_setwidth(struct termp *p, int iop, int width)
 {
 	size_t	 lastwidth;
 
 	lastwidth = p->ps->width;
 	if (iop > 0)
 		p->ps->width += width;
 	else if (iop == 0)
 		p->ps->width = width ? (size_t)width : p->ps->lastwidth;
 	else if (p->ps->width > (size_t)width)
 		p->ps->width -= width;
 	else
 		p->ps->width = 0;
 	p->ps->lastwidth = lastwidth;
 }
 
 void
 pspdf_free(void *arg)
 {
 	struct termp	*p;
 
 	p = (struct termp *)arg;
 
 	free(p->ps->psmarg);
 	free(p->ps->pdfobjs);
 
 	free(p->ps);
 	term_free(p);
 }
 
 static void
 ps_printf(struct termp *p, const char *fmt, ...)
 {
 	va_list		 ap;
 	int		 pos, len;
 
 	va_start(ap, fmt);
 
 	/*
 	 * If we're running in regular mode, then pipe directly into
 	 * vprintf().  If we're processing margins, then push the data
 	 * into our growable margin buffer.
 	 */
 
 	if ( ! (PS_MARGINS & p->ps->flags)) {
 		len = vprintf(fmt, ap);
 		va_end(ap);
 		p->ps->pdfbytes += len < 0 ? 0 : (size_t)len;
 		return;
 	}
 
 	/*
 	 * XXX: I assume that the in-margin print won't exceed
 	 * PS_BUFSLOP (128 bytes), which is reasonable but still an
 	 * assumption that will cause pukeage if it's not the case.
 	 */
 
 	ps_growbuf(p, PS_BUFSLOP);
 
 	pos = (int)p->ps->psmargcur;
 	vsnprintf(&p->ps->psmarg[pos], PS_BUFSLOP, fmt, ap);
 
 	va_end(ap);
 
 	p->ps->psmargcur = strlen(p->ps->psmarg);
 }
 
 static void
 ps_putchar(struct termp *p, char c)
 {
 	int		 pos;
 
 	/* See ps_printf(). */
 
 	if ( ! (PS_MARGINS & p->ps->flags)) {
 		putchar(c);
 		p->ps->pdfbytes++;
 		return;
 	}
 
 	ps_growbuf(p, 2);
 
 	pos = (int)p->ps->psmargcur++;
 	p->ps->psmarg[pos++] = c;
 	p->ps->psmarg[pos] = '\0';
 }
 
 static void
 pdf_obj(struct termp *p, size_t obj)
 {
 
 	assert(obj > 0);
 
 	if ((obj - 1) >= p->ps->pdfobjsz) {
 		p->ps->pdfobjsz = obj + 128;
 		p->ps->pdfobjs = mandoc_reallocarray(p->ps->pdfobjs,
 		    p->ps->pdfobjsz, sizeof(size_t));
 	}
 
 	p->ps->pdfobjs[(int)obj - 1] = p->ps->pdfbytes;
 	ps_printf(p, "%zu 0 obj\n", obj);
 }
 
 static void
 ps_closepage(struct termp *p)
 {
 	int		 i;
 	size_t		 len, base;
 
 	/*
 	 * Close out a page that we've already flushed to output.  In
 	 * PostScript, we simply note that the page must be showed.  In
 	 * PDF, we must now create the Length, Resource, and Page node
 	 * for the page contents.
 	 */
 
 	assert(p->ps->psmarg && p->ps->psmarg[0]);
 	ps_printf(p, "%s", p->ps->psmarg);
 
 	if (TERMTYPE_PS != p->type) {
 		ps_printf(p, "ET\n");
 
 		len = p->ps->pdfbytes - p->ps->pdflastpg;
 		base = p->ps->pages * 4 + p->ps->pdfbody;
 
 		ps_printf(p, "endstream\nendobj\n");
 
 		/* Length of content. */
 		pdf_obj(p, base + 1);
 		ps_printf(p, "%zu\nendobj\n", len);
 
 		/* Resource for content. */
 		pdf_obj(p, base + 2);
 		ps_printf(p, "<<\n/ProcSet [/PDF /Text]\n");
 		ps_printf(p, "/Font <<\n");
 		for (i = 0; i < (int)TERMFONT__MAX; i++)
 			ps_printf(p, "/F%d %d 0 R\n", i, 3 + i);
 		ps_printf(p, ">>\n>>\n");
 
 		/* Page node. */
 		pdf_obj(p, base + 3);
 		ps_printf(p, "<<\n");
 		ps_printf(p, "/Type /Page\n");
 		ps_printf(p, "/Parent 2 0 R\n");
 		ps_printf(p, "/Resources %zu 0 R\n", base + 2);
 		ps_printf(p, "/Contents %zu 0 R\n", base);
 		ps_printf(p, ">>\nendobj\n");
 	} else
 		ps_printf(p, "showpage\n");
 
 	p->ps->pages++;
 	p->ps->psrow = p->ps->top;
 	assert( ! (PS_NEWPAGE & p->ps->flags));
 	p->ps->flags |= PS_NEWPAGE;
 }
 
 static void
 ps_end(struct termp *p)
 {
 	size_t		 i, xref, base;
 
+	ps_plast(p);
+	ps_pclose(p);
+
 	/*
 	 * At the end of the file, do one last showpage.  This is the
 	 * same behaviour as groff(1) and works for multiple pages as
 	 * well as just one.
 	 */
 
 	if ( ! (PS_NEWPAGE & p->ps->flags)) {
 		assert(0 == p->ps->flags);
 		assert('\0' == p->ps->last);
 		ps_closepage(p);
 	}
 
 	if (TERMTYPE_PS == p->type) {
 		ps_printf(p, "%%%%Trailer\n");
 		ps_printf(p, "%%%%Pages: %zu\n", p->ps->pages);
 		ps_printf(p, "%%%%EOF\n");
 		return;
 	}
 
 	pdf_obj(p, 2);
 	ps_printf(p, "<<\n/Type /Pages\n");
 	ps_printf(p, "/MediaBox [0 0 %zu %zu]\n",
 			(size_t)AFM2PNT(p, p->ps->width),
 			(size_t)AFM2PNT(p, p->ps->height));
 
 	ps_printf(p, "/Count %zu\n", p->ps->pages);
 	ps_printf(p, "/Kids [");
 
 	for (i = 0; i < p->ps->pages; i++)
 		ps_printf(p, " %zu 0 R", i * 4 + p->ps->pdfbody + 3);
 
 	base = (p->ps->pages - 1) * 4 + p->ps->pdfbody + 4;
 
 	ps_printf(p, "]\n>>\nendobj\n");
 	pdf_obj(p, base);
 	ps_printf(p, "<<\n");
 	ps_printf(p, "/Type /Catalog\n");
 	ps_printf(p, "/Pages 2 0 R\n");
 	ps_printf(p, ">>\n");
 	xref = p->ps->pdfbytes;
 	ps_printf(p, "xref\n");
 	ps_printf(p, "0 %zu\n", base + 1);
 	ps_printf(p, "0000000000 65535 f \n");
 
 	for (i = 0; i < base; i++)
 		ps_printf(p, "%.10zu 00000 n \n",
 		    p->ps->pdfobjs[(int)i]);
 
 	ps_printf(p, "trailer\n");
 	ps_printf(p, "<<\n");
 	ps_printf(p, "/Size %zu\n", base + 1);
 	ps_printf(p, "/Root %zu 0 R\n", base);
 	ps_printf(p, "/Info 1 0 R\n");
 	ps_printf(p, ">>\n");
 	ps_printf(p, "startxref\n");
 	ps_printf(p, "%zu\n", xref);
 	ps_printf(p, "%%%%EOF\n");
 }
 
 static void
 ps_begin(struct termp *p)
 {
 	int		 i;
 
 	/*
 	 * Print margins into margin buffer.  Nothing gets output to the
 	 * screen yet, so we don't need to initialise the primary state.
 	 */
 
 	if (p->ps->psmarg) {
 		assert(p->ps->psmargsz);
 		p->ps->psmarg[0] = '\0';
 	}
 
 	/*p->ps->pdfbytes = 0;*/
 	p->ps->psmargcur = 0;
 	p->ps->flags = PS_MARGINS;
 	p->ps->pscol = p->ps->left;
 	p->ps->psrow = p->ps->header;
 
 	ps_setfont(p, TERMFONT_NONE);
 
 	(*p->headf)(p, p->argf);
 	(*p->endline)(p);
 
 	p->ps->pscol = p->ps->left;
 	p->ps->psrow = p->ps->footer;
 
 	(*p->footf)(p, p->argf);
 	(*p->endline)(p);
 
 	p->ps->flags &= ~PS_MARGINS;
 
 	assert(0 == p->ps->flags);
 	assert(p->ps->psmarg);
 	assert('\0' != p->ps->psmarg[0]);
 
 	/*
 	 * Print header and initialise page state.  Following this,
 	 * stuff gets printed to the screen, so make sure we're sane.
 	 */
 
 	if (TERMTYPE_PS == p->type) {
 		ps_printf(p, "%%!PS-Adobe-3.0\n");
 		ps_printf(p, "%%%%DocumentData: Clean7Bit\n");
 		ps_printf(p, "%%%%Orientation: Portrait\n");
 		ps_printf(p, "%%%%Pages: (atend)\n");
 		ps_printf(p, "%%%%PageOrder: Ascend\n");
 		ps_printf(p, "%%%%DocumentMedia: "
 		    "Default %zu %zu 0 () ()\n",
 		    (size_t)AFM2PNT(p, p->ps->width),
 		    (size_t)AFM2PNT(p, p->ps->height));
 		ps_printf(p, "%%%%DocumentNeededResources: font");
 
 		for (i = 0; i < (int)TERMFONT__MAX; i++)
 			ps_printf(p, " %s", fonts[i].name);
 
 		ps_printf(p, "\n%%%%EndComments\n");
 	} else {
 		ps_printf(p, "%%PDF-1.1\n");
 		pdf_obj(p, 1);
 		ps_printf(p, "<<\n");
 		ps_printf(p, ">>\n");
 		ps_printf(p, "endobj\n");
 
 		for (i = 0; i < (int)TERMFONT__MAX; i++) {
 			pdf_obj(p, (size_t)i + 3);
 			ps_printf(p, "<<\n");
 			ps_printf(p, "/Type /Font\n");
 			ps_printf(p, "/Subtype /Type1\n");
 			ps_printf(p, "/Name /F%d\n", i);
 			ps_printf(p, "/BaseFont /%s\n", fonts[i].name);
 			ps_printf(p, ">>\n");
 		}
 	}
 
 	p->ps->pdfbody = (size_t)TERMFONT__MAX + 3;
 	p->ps->pscol = p->ps->left;
 	p->ps->psrow = p->ps->top;
 	p->ps->flags |= PS_NEWPAGE;
 	ps_setfont(p, TERMFONT_NONE);
 }
 
 static void
 ps_pletter(struct termp *p, int c)
 {
 	int		 f;
 
 	/*
 	 * If we haven't opened a page context, then output that we're
 	 * in a new page and make sure the font is correctly set.
 	 */
 
 	if (PS_NEWPAGE & p->ps->flags) {
 		if (TERMTYPE_PS == p->type) {
 			ps_printf(p, "%%%%Page: %zu %zu\n",
 			    p->ps->pages + 1, p->ps->pages + 1);
 			ps_printf(p, "/%s %zu selectfont\n",
 			    fonts[(int)p->ps->lastf].name,
 			    p->ps->scale);
 		} else {
 			pdf_obj(p, p->ps->pdfbody +
 			    p->ps->pages * 4);
 			ps_printf(p, "<<\n");
 			ps_printf(p, "/Length %zu 0 R\n",
 			    p->ps->pdfbody + 1 + p->ps->pages * 4);
 			ps_printf(p, ">>\nstream\n");
 		}
 		p->ps->pdflastpg = p->ps->pdfbytes;
 		p->ps->flags &= ~PS_NEWPAGE;
 	}
 
 	/*
 	 * If we're not in a PostScript "word" context, then open one
 	 * now at the current cursor.
 	 */
 
 	if ( ! (PS_INLINE & p->ps->flags)) {
 		if (TERMTYPE_PS != p->type) {
 			ps_printf(p, "BT\n/F%d %zu Tf\n",
 			    (int)p->ps->lastf, p->ps->scale);
 			ps_printf(p, "%.3f %.3f Td\n(",
 			    AFM2PNT(p, p->ps->pscol),
 			    AFM2PNT(p, p->ps->psrow));
 		} else
 			ps_printf(p, "%.3f %.3f moveto\n(",
 			    AFM2PNT(p, p->ps->pscol),
 			    AFM2PNT(p, p->ps->psrow));
 		p->ps->flags |= PS_INLINE;
 	}
 
 	assert( ! (PS_NEWPAGE & p->ps->flags));
 
 	/*
 	 * We need to escape these characters as per the PostScript
 	 * specification.  We would also escape non-graphable characters
 	 * (like tabs), but none of them would get to this point and
 	 * it's superfluous to abort() on them.
 	 */
 
 	switch (c) {
 	case '(':
 	case ')':
 	case '\\':
 		ps_putchar(p, '\\');
 		break;
 	default:
 		break;
 	}
 
 	/* Write the character and adjust where we are on the page. */
 
 	f = (int)p->ps->lastf;
 
 	if (c <= 32 || c - 32 >= MAXCHAR)
 		c = 32;
 
 	ps_putchar(p, (char)c);
 	c -= 32;
 	p->ps->pscol += (size_t)fonts[f].gly[c].wx;
 }
 
 static void
 ps_pclose(struct termp *p)
 {
 
 	/*
 	 * Spit out that we're exiting a word context (this is a
 	 * "partial close" because we don't check the last-char buffer
 	 * or anything).
 	 */
 
 	if ( ! (PS_INLINE & p->ps->flags))
 		return;
 
 	if (TERMTYPE_PS != p->type) {
 		ps_printf(p, ") Tj\nET\n");
 	} else
 		ps_printf(p, ") show\n");
 
 	p->ps->flags &= ~PS_INLINE;
 }
 
+/* If we have a `last' char that wasn't printed yet, print it now. */
 static void
-ps_fclose(struct termp *p)
+ps_plast(struct termp *p)
 {
+	size_t	 wx;
 
+	if (p->ps->last == '\0')
+		return;
+
+	/* Check the font mode; open a new scope if it doesn't match. */
+
+	if (p->ps->nextf != p->ps->lastf) {
+		ps_pclose(p);
+		ps_setfont(p, p->ps->nextf);
+	}
+	p->ps->nextf = TERMFONT_NONE;
+
 	/*
-	 * Strong closure: if we have a last-char, spit it out after
-	 * checking that we're in the right font mode.  This will of
-	 * course open a new scope, if applicable.
-	 *
-	 * Following this, close out any scope that's open.
+	 * For an overstrike, if a previous character
+	 * was wider, advance to center the new one.
 	 */
 
-	if (p->ps->last != '\0') {
-		assert( ! (p->ps->flags & PS_BACKSP));
-		if (p->ps->nextf != p->ps->lastf) {
-			ps_pclose(p);
-			ps_setfont(p, p->ps->nextf);
-		}
-		p->ps->nextf = TERMFONT_NONE;
-		ps_pletter(p, p->ps->last);
-		p->ps->last = '\0';
+	if (p->ps->pscolnext) {
+		wx = fonts[p->ps->lastf].gly[(int)p->ps->last-32].wx;
+		if (p->ps->pscol + wx < p->ps->pscolnext)
+			p->ps->pscol = (p->ps->pscol +
+			    p->ps->pscolnext - wx) / 2;
 	}
 
-	if ( ! (PS_INLINE & p->ps->flags))
-		return;
+	ps_pletter(p, p->ps->last);
+	p->ps->last = '\0';
 
-	ps_pclose(p);
+	/*
+	 * For an overstrike, if a previous character
+	 * was wider, advance to the end of the old one.
+	 */
+
+	if (p->ps->pscol < p->ps->pscolnext) {
+		ps_pclose(p);
+		p->ps->pscol = p->ps->pscolnext;
+	}
 }
 
 static void
 ps_letter(struct termp *p, int arg)
 {
-	size_t		savecol, wx;
+	size_t		savecol;
 	char		c;
 
 	c = arg >= 128 || arg <= 0 ? '?' : arg;
 
 	/*
 	 * When receiving a backspace, merely flag it.
 	 * We don't know yet whether it is
 	 * a font instruction or an overstrike.
 	 */
 
 	if (c == '\b') {
 		assert(p->ps->last != '\0');
 		assert( ! (p->ps->flags & PS_BACKSP));
 		p->ps->flags |= PS_BACKSP;
 		return;
 	}
 
 	/*
 	 * Decode font instructions.
 	 */
 
 	if (p->ps->flags & PS_BACKSP) {
 		if (p->ps->last == '_') {
 			switch (p->ps->nextf) {
 			case TERMFONT_BI:
 				break;
 			case TERMFONT_BOLD:
 				p->ps->nextf = TERMFONT_BI;
 				break;
 			default:
 				p->ps->nextf = TERMFONT_UNDER;
 			}
 			p->ps->last = c;
 			p->ps->flags &= ~PS_BACKSP;
 			return;
 		}
 		if (p->ps->last == c) {
 			switch (p->ps->nextf) {
 			case TERMFONT_BI:
 				break;
 			case TERMFONT_UNDER:
 				p->ps->nextf = TERMFONT_BI;
 				break;
 			default:
 				p->ps->nextf = TERMFONT_BOLD;
 			}
 			p->ps->flags &= ~PS_BACKSP;
 			return;
 		}
 
 		/*
 		 * This is not a font instruction, but rather
 		 * the next character.  Prepare for overstrike.
 		 */
 
 		savecol = p->ps->pscol;
 	} else
 		savecol = SIZE_MAX;
 
 	/*
 	 * We found the next character, so the font instructions
 	 * for the previous one are complete.
 	 * Use them and print it.
 	 */
 
-	if (p->ps->last != '\0') {
-		if (p->ps->nextf != p->ps->lastf) {
-			ps_pclose(p);
-			ps_setfont(p, p->ps->nextf);
-		}
-		p->ps->nextf = TERMFONT_NONE;
+	ps_plast(p);
 
-		/*
-		 * For an overstrike, if a previous character
-		 * was wider, advance to center the new one.
-		 */
-
-		if (p->ps->pscolnext) {
-			wx = fonts[p->ps->lastf].gly[(int)p->ps->last-32].wx;
-			if (p->ps->pscol + wx < p->ps->pscolnext)
-				p->ps->pscol = (p->ps->pscol +
-				    p->ps->pscolnext - wx) / 2;
-		}
-
-		ps_pletter(p, p->ps->last);
-
-		/*
-		 * For an overstrike, if a previous character
-		 * was wider, advance to the end of the old one.
-		 */
-
-		if (p->ps->pscol < p->ps->pscolnext) {
-			ps_pclose(p);
-			p->ps->pscol = p->ps->pscolnext;
-		}
-	}
-
 	/*
 	 * Do not print the current character yet because font
-	 * instructions might follow; only remember it.
-	 * For the first character, nothing else is done.
-	 * The final character will get printed from ps_fclose().
+	 * instructions might follow; only remember the character.
+	 * It will get printed later from ps_plast().
 	 */
 
 	p->ps->last = c;
 
 	/*
 	 * For an overstrike, back up to the previous position.
 	 * If the previous character is wider than any it overstrikes,
 	 * remember the current position, because it might also be
 	 * wider than all that will overstrike it.
 	 */
 
 	if (savecol != SIZE_MAX) {
 		if (p->ps->pscolnext < p->ps->pscol)
 			p->ps->pscolnext = p->ps->pscol;
 		ps_pclose(p);
 		p->ps->pscol = savecol;
 		p->ps->flags &= ~PS_BACKSP;
 	} else
 		p->ps->pscolnext = 0;
 }
 
 static void
 ps_advance(struct termp *p, size_t len)
 {
 
 	/*
 	 * Advance some spaces.  This can probably be made smarter,
 	 * i.e., to have multiple space-separated words in the same
 	 * scope, but this is easier:  just close out the current scope
 	 * and readjust our column settings.
 	 */
 
-	ps_fclose(p);
+	ps_plast(p);
+	ps_pclose(p);
 	p->ps->pscol += len;
 }
 
 static void
 ps_endline(struct termp *p)
 {
 
 	/* Close out any scopes we have open: we're at eoln. */
 
-	ps_fclose(p);
+	ps_plast(p);
+	ps_pclose(p);
 
 	/*
 	 * If we're in the margin, don't try to recalculate our current
 	 * row.  XXX: if the column tries to be fancy with multiple
 	 * lines, we'll do nasty stuff.
 	 */
 
 	if (PS_MARGINS & p->ps->flags)
 		return;
 
 	/* Left-justify. */
 
 	p->ps->pscol = p->ps->left;
 
 	/* If we haven't printed anything, return. */
 
 	if (PS_NEWPAGE & p->ps->flags)
 		return;
 
 	/*
 	 * Put us down a line.  If we're at the page bottom, spit out a
 	 * showpage and restart our row.
 	 */
 
 	if (p->ps->psrow >= p->ps->lineheight + p->ps->bottom) {
 		p->ps->psrow -= p->ps->lineheight;
 		return;
 	}
 
 	ps_closepage(p);
 }
 
 static void
 ps_setfont(struct termp *p, enum termfont f)
 {
 
 	assert(f < TERMFONT__MAX);
 	p->ps->lastf = f;
 
 	/*
 	 * If we're still at the top of the page, let the font-setting
 	 * be delayed until we actually have stuff to print.
 	 */
 
 	if (PS_NEWPAGE & p->ps->flags)
 		return;
 
 	if (TERMTYPE_PS == p->type)
 		ps_printf(p, "/%s %zu selectfont\n",
 		    fonts[(int)f].name, p->ps->scale);
 	else
 		ps_printf(p, "/F%d %zu Tf\n",
 		    (int)f, p->ps->scale);
 }
 
 static size_t
 ps_width(const struct termp *p, int c)
 {
 
 	if (c <= 32 || c - 32 >= MAXCHAR)
 		c = 0;
 	else
 		c -= 32;
 
 	return (size_t)fonts[(int)TERMFONT_NONE].gly[c].wx;
 }
 
 static int
 ps_hspan(const struct termp *p, const struct roffsu *su)
 {
 	double		 r;
 
 	/*
 	 * All of these measurements are derived by converting from the
 	 * native measurement to AFM units.
 	 */
 	switch (su->unit) {
 	case SCALE_BU:
 		/*
 		 * Traditionally, the default unit is fixed to the
 		 * output media.  So this would refer to the point.  In
 		 * mandoc(1), however, we stick to the default terminal
 		 * scaling unit so that output is the same regardless
 		 * the media.
 		 */
 		r = PNT2AFM(p, su->scale * 72.0 / 240.0);
 		break;
 	case SCALE_CM:
 		r = PNT2AFM(p, su->scale * 72.0 / 2.54);
 		break;
 	case SCALE_EM:
 		r = su->scale *
 		    fonts[(int)TERMFONT_NONE].gly[109 - 32].wx;
 		break;
 	case SCALE_EN:
 		r = su->scale *
 		    fonts[(int)TERMFONT_NONE].gly[110 - 32].wx;
 		break;
 	case SCALE_IN:
 		r = PNT2AFM(p, su->scale * 72.0);
 		break;
 	case SCALE_MM:
 		r = su->scale *
 		    fonts[(int)TERMFONT_NONE].gly[109 - 32].wx / 100.0;
 		break;
 	case SCALE_PC:
 		r = PNT2AFM(p, su->scale * 12.0);
 		break;
 	case SCALE_PT:
 		r = PNT2AFM(p, su->scale * 1.0);
 		break;
 	case SCALE_VS:
 		r = su->scale * p->ps->lineheight;
 		break;
 	default:
 		r = su->scale;
 		break;
 	}
 
 	return r * 24.0;
 }
 
 static void
 ps_growbuf(struct termp *p, size_t sz)
 {
 	if (p->ps->psmargcur + sz <= p->ps->psmargsz)
 		return;
 
 	if (sz < PS_BUFSLOP)
 		sz = PS_BUFSLOP;
 
 	p->ps->psmargsz += sz;
 	p->ps->psmarg = mandoc_realloc(p->ps->psmarg, p->ps->psmargsz);
 }
Index: stable/11/contrib/mdocml/test-EFTYPE.c
===================================================================
--- stable/11/contrib/mdocml/test-EFTYPE.c	(nonexistent)
+++ stable/11/contrib/mdocml/test-EFTYPE.c	(revision 316420)
@@ -0,0 +1,7 @@
+#include 
+
+int
+main(void)
+{
+	return !EFTYPE;
+}

Property changes on: stable/11/contrib/mdocml/test-EFTYPE.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: stable/11/contrib/mdocml/test-PATH_MAX.c
===================================================================
--- stable/11/contrib/mdocml/test-PATH_MAX.c	(nonexistent)
+++ stable/11/contrib/mdocml/test-PATH_MAX.c	(revision 316420)
@@ -0,0 +1,30 @@
+/*
+ * POSIX allows PATH_MAX to not be defined, see
+ * http://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html;
+ * the GNU Hurd is an example of a system not having it.
+ *
+ * Arguably, it would be better to test sysconf(_SC_PATH_MAX),
+ * but since the individual *.c files include "config.h" before
+ * , overriding an excessive value of PATH_MAX from
+ * "config.h" is impossible anyway, so for now, the simplest
+ * fix is to provide a value only on systems not having any.
+ * So far, we encountered no system defining PATH_MAX to an
+ * impractically large value, even though POSIX explicitly
+ * allows that.
+ *
+ * The real fix would be to replace all static buffers of size
+ * PATH_MAX by dynamically allocated buffers.  But that is
+ * somewhat intrusive because it touches several files and
+ * because it requires changing struct mlink in mandocdb.c.
+ * So i'm postponing that for now.
+ */
+
+#include 
+#include 
+
+int
+main(void)
+{
+	printf("PATH_MAX is defined to be %ld\n", (long)PATH_MAX);
+	return 0;
+}

Property changes on: stable/11/contrib/mdocml/test-PATH_MAX.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: stable/11/contrib/mdocml/test-be32toh.c
===================================================================
--- stable/11/contrib/mdocml/test-be32toh.c	(nonexistent)
+++ stable/11/contrib/mdocml/test-be32toh.c	(revision 316420)
@@ -0,0 +1,11 @@
+#ifdef SYS_ENDIAN
+#include 
+#else
+#include 
+#endif
+
+int
+main(void)
+{
+	return htobe32(be32toh(0x3a7d0cdb)) != 0x3a7d0cdb;
+}

Property changes on: stable/11/contrib/mdocml/test-be32toh.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: stable/11/contrib/mdocml/test-fts.c
===================================================================
--- stable/11/contrib/mdocml/test-fts.c	(revision 316419)
+++ stable/11/contrib/mdocml/test-fts.c	(revision 316420)
@@ -1,42 +1,59 @@
 #include 
 #include 
 #include 
 #include 
+#include 
 
+#ifdef FTS_COMPARE_CONST
+int fts_compare(const FTSENT *const *, const FTSENT *const *);
+#else
+int fts_compare(const FTSENT **, const FTSENT **);
+#endif
+
 int
 main(void)
 {
 	const char	*argv[2];
 	FTS		*ftsp;
 	FTSENT		*entry;
 
 	argv[0] = ".";
 	argv[1] = (char *)NULL;
 
 	ftsp = fts_open((char * const *)argv,
-	    FTS_PHYSICAL | FTS_NOCHDIR, NULL);
+	    FTS_PHYSICAL | FTS_NOCHDIR, fts_compare);
 
 	if (ftsp == NULL) {
 		perror("fts_open");
 		return 1;
 	}
 
 	entry = fts_read(ftsp);
 
 	if (entry == NULL) {
 		perror("fts_read");
 		return 1;
 	}
 
 	if (fts_set(ftsp, entry, FTS_SKIP) != 0) {
 		perror("fts_set");
 		return 1;
 	}
 
 	if (fts_close(ftsp) != 0) {
 		perror("fts_close");
 		return 1;
 	}
 
 	return 0;
+}
+
+int
+#ifdef FTS_COMPARE_CONST
+fts_compare(const FTSENT *const *a, const FTSENT *const *b)
+#else
+fts_compare(const FTSENT **a, const FTSENT **b)
+#endif
+{
+	return strcmp((*a)->fts_name, (*b)->fts_name);
 }
Index: stable/11/contrib/mdocml/test-nanosleep.c
===================================================================
--- stable/11/contrib/mdocml/test-nanosleep.c	(nonexistent)
+++ stable/11/contrib/mdocml/test-nanosleep.c	(revision 316420)
@@ -0,0 +1,17 @@
+#include 
+#include 
+
+int
+main(void)
+{
+	struct timespec	 timeout;
+
+	timeout.tv_sec = 0;
+	timeout.tv_nsec = 100000000;	/* 0.1 seconds */
+	
+	if (nanosleep(&timeout, NULL)) {
+		perror("nanosleep");
+		return 1;
+	}
+	return 0;
+}

Property changes on: stable/11/contrib/mdocml/test-nanosleep.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: stable/11/contrib/mdocml/test-ntohl.c
===================================================================
--- stable/11/contrib/mdocml/test-ntohl.c	(nonexistent)
+++ stable/11/contrib/mdocml/test-ntohl.c	(revision 316420)
@@ -0,0 +1,7 @@
+#include 
+
+int
+main(void)
+{
+	return htonl(ntohl(0x3a7d0cdb)) != 0x3a7d0cdb;
+}

Property changes on: stable/11/contrib/mdocml/test-ntohl.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: stable/11/contrib/mdocml/test-ohash.c
===================================================================
--- stable/11/contrib/mdocml/test-ohash.c	(revision 316419)
+++ stable/11/contrib/mdocml/test-ohash.c	(revision 316420)
@@ -1,21 +1,39 @@
 #include 
 #include 
 #include 
 #include 
 
-void *xmalloc(size_t sz, void *arg) { return calloc(1,sz); }
-void *xcalloc(size_t nmemb, size_t sz, void *arg) { return calloc(nmemb,sz); }
-void xfree(void *p, void *arg) { free(p); }
+static void	*xmalloc(size_t, void *);
+static void	*xcalloc(size_t, size_t, void *);
+static void	 xfree(void *, void *);
+
+
+static void *
+xmalloc(size_t sz, void *arg) {
+	return calloc(1,sz);
+}
+
+static void *
+xcalloc(size_t nmemb, size_t sz, void *arg)
+{
+	return calloc(nmemb,sz);
+}
+
+static void
+xfree(void *p, void *arg)
+{
+	free(p);
+}
 
 int
 main(void)
 {
 	struct ohash h;
 	struct ohash_info i;
 	i.alloc = xmalloc;
 	i.calloc = xcalloc;
 	i.free = xfree;
 	ohash_init(&h, 2, &i);
 	ohash_delete(&h);
 	return 0;
 }
Index: stable/11/contrib/mdocml/test-sandbox_init.c
===================================================================
--- stable/11/contrib/mdocml/test-sandbox_init.c	(nonexistent)
+++ stable/11/contrib/mdocml/test-sandbox_init.c	(revision 316420)
@@ -0,0 +1,13 @@
+#include 
+
+int
+main(void)
+{
+	char	*ep;
+	int	 rc;
+
+	rc = sandbox_init(kSBXProfileNoInternet, SANDBOX_NAMED, &ep);
+	if (-1 == rc)
+		sandbox_free_error(ep);
+	return(-1 == rc);
+}

Property changes on: stable/11/contrib/mdocml/test-sandbox_init.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+FreeBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: stable/11/contrib/mdocml/test-vasprintf.c
===================================================================
--- stable/11/contrib/mdocml/test-vasprintf.c	(revision 316419)
+++ stable/11/contrib/mdocml/test-vasprintf.c	(revision 316420)
@@ -1,49 +1,52 @@
-/*	$Id: test-vasprintf.c,v 1.3 2015/10/06 18:32:20 schwarze Exp $	*/
+/*	$Id: test-vasprintf.c,v 1.4 2016/07/18 18:35:05 schwarze Exp $	*/
 /*
  * Copyright (c) 2015 Ingo Schwarze 
  *
  * 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.
  */
 
 #if defined(__linux__) || defined(__MINT__)
 #define _GNU_SOURCE /* vasprintf() */
 #endif
 
 #include 
 #include 
 #include 
 
-int
+static int	 testfunc(char **, const char *, ...);
+
+
+static int
 testfunc(char **ret, const char *format, ...)
 {
 	va_list	 ap;
 	int	 irc;
 
 	va_start(ap, format);
 	irc = vasprintf(ret, format, ap);
 	va_end(ap);
 
 	return irc;
 }
 
 int
 main(void)
 {
 	char	*ret;
 
 	if (testfunc(&ret, "%s.", "Text") != 5)
 		return 1;
 	if (strcmp(ret, "Text."))
 		return 2;
 	return 0;
 }
Index: stable/11/contrib/mdocml/test-wchar.c
===================================================================
--- stable/11/contrib/mdocml/test-wchar.c	(revision 316419)
+++ stable/11/contrib/mdocml/test-wchar.c	(revision 316420)
@@ -1,63 +1,63 @@
-/*	$Id: test-wchar.c,v 1.3 2015/10/06 18:32:20 schwarze Exp $	*/
+/*	$Id: test-wchar.c,v 1.4 2016/07/31 09:29:13 schwarze Exp $	*/
 /*
  * Copyright (c) 2014 Ingo Schwarze 
  *
  * 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.
  */
 
 #if defined(__linux__) || defined(__MINT__)
 #define _GNU_SOURCE /* wcwidth() */
 #endif
 
 #include 
 #include 
 #include 
 #include 
 
 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);
+	if (setlocale(LC_CTYPE, UTF8_LOCALE) == NULL) {
+		fprintf(stderr, "setlocale(LC_CTYPE, \"%s\") failed\n",
+		    UTF8_LOCALE);
 		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) != (wint_t)wc) {
 		fputs("bad putwchar return value\n", stderr);
 		return 1;
 	}
 
 	return 0;
 }
Index: stable/11/contrib/mdocml/tree.c
===================================================================
--- stable/11/contrib/mdocml/tree.c	(revision 316419)
+++ stable/11/contrib/mdocml/tree.c	(revision 316420)
@@ -1,377 +1,405 @@
-/*	$Id: tree.c,v 1.69 2015/10/12 00:08:16 schwarze Exp $ */
+/*	$Id: tree.c,v 1.72 2017/01/12 17:29:33 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons 
- * Copyright (c) 2013, 2014, 2015 Ingo Schwarze 
+ * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze 
  *
  * 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 AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 "config.h"
 
 #include 
 
 #include 
 #include 
 #include 
 #include 
 #include 
 
 #include "mandoc.h"
 #include "roff.h"
 #include "mdoc.h"
 #include "man.h"
 #include "main.h"
 
 static	void	print_box(const struct eqn_box *, int);
 static	void	print_man(const struct roff_node *, int);
+static	void	print_meta(const struct roff_meta *);
 static	void	print_mdoc(const struct roff_node *, int);
 static	void	print_span(const struct tbl_span *, int);
 
 
 void
 tree_mdoc(void *arg, const struct roff_man *mdoc)
 {
-
+	print_meta(&mdoc->meta);
+	putchar('\n');
 	print_mdoc(mdoc->first->child, 0);
 }
 
 void
 tree_man(void *arg, const struct roff_man *man)
 {
-
+	print_meta(&man->meta);
+	if (man->meta.hasbody == 0)
+		puts("body  = empty");
+	putchar('\n');
 	print_man(man->first->child, 0);
 }
 
 static void
+print_meta(const struct roff_meta *meta)
+{
+	if (meta->title != NULL)
+		printf("title = \"%s\"\n", meta->title);
+	if (meta->name != NULL)
+		printf("name  = \"%s\"\n", meta->name);
+	if (meta->msec != NULL)
+		printf("sec   = \"%s\"\n", meta->msec);
+	if (meta->vol != NULL)
+		printf("vol   = \"%s\"\n", meta->vol);
+	if (meta->arch != NULL)
+		printf("arch  = \"%s\"\n", meta->arch);
+	if (meta->os != NULL)
+		printf("os    = \"%s\"\n", meta->os);
+	if (meta->date != NULL)
+		printf("date  = \"%s\"\n", meta->date);
+}
+
+static void
 print_mdoc(const struct roff_node *n, int indent)
 {
 	const char	 *p, *t;
 	int		  i, j;
 	size_t		  argc;
 	struct mdoc_argv *argv;
 
 	if (n == NULL)
 		return;
 
 	argv = NULL;
 	argc = 0;
 	t = p = NULL;
 
 	switch (n->type) {
 	case ROFFT_ROOT:
 		t = "root";
 		break;
 	case ROFFT_BLOCK:
 		t = "block";
 		break;
 	case ROFFT_HEAD:
 		t = "head";
 		break;
 	case ROFFT_BODY:
 		if (n->end)
 			t = "body-end";
 		else
 			t = "body";
 		break;
 	case ROFFT_TAIL:
 		t = "tail";
 		break;
 	case ROFFT_ELEM:
 		t = "elem";
 		break;
 	case ROFFT_TEXT:
 		t = "text";
 		break;
 	case ROFFT_TBL:
 		break;
 	case ROFFT_EQN:
 		t = "eqn";
 		break;
 	default:
 		abort();
 	}
 
 	switch (n->type) {
 	case ROFFT_TEXT:
 		p = n->string;
 		break;
 	case ROFFT_BODY:
 		p = mdoc_macronames[n->tok];
 		break;
 	case ROFFT_HEAD:
 		p = mdoc_macronames[n->tok];
 		break;
 	case ROFFT_TAIL:
 		p = mdoc_macronames[n->tok];
 		break;
 	case ROFFT_ELEM:
 		p = mdoc_macronames[n->tok];
 		if (n->args) {
 			argv = n->args->argv;
 			argc = n->args->argc;
 		}
 		break;
 	case ROFFT_BLOCK:
 		p = mdoc_macronames[n->tok];
 		if (n->args) {
 			argv = n->args->argv;
 			argc = n->args->argc;
 		}
 		break;
 	case ROFFT_TBL:
 		break;
 	case ROFFT_EQN:
 		p = "EQ";
 		break;
 	case ROFFT_ROOT:
 		p = "root";
 		break;
 	default:
 		abort();
 	}
 
 	if (n->span) {
 		assert(NULL == p && NULL == t);
 		print_span(n->span, indent);
 	} else {
 		for (i = 0; i < indent; i++)
 			putchar(' ');
 
 		printf("%s (%s)", p, t);
 
 		for (i = 0; i < (int)argc; i++) {
 			printf(" -%s", mdoc_argnames[argv[i].arg]);
 			if (argv[i].sz > 0)
 				printf(" [");
 			for (j = 0; j < (int)argv[i].sz; j++)
 				printf(" [%s]", argv[i].value[j]);
 			if (argv[i].sz > 0)
 				printf(" ]");
 		}
 
 		putchar(' ');
-		if (MDOC_DELIMO & n->flags)
+		if (NODE_DELIMO & n->flags)
 			putchar('(');
-		if (MDOC_LINE & n->flags)
+		if (NODE_LINE & n->flags)
 			putchar('*');
 		printf("%d:%d", n->line, n->pos + 1);
-		if (MDOC_DELIMC & n->flags)
+		if (NODE_DELIMC & n->flags)
 			putchar(')');
-		if (MDOC_EOS & n->flags)
+		if (NODE_EOS & n->flags)
 			putchar('.');
+		if (NODE_NOSRC & n->flags)
+			printf(" NOSRC");
+		if (NODE_NOPRT & n->flags)
+			printf(" NOPRT");
 		putchar('\n');
 	}
 
 	if (n->eqn)
 		print_box(n->eqn->root->first, indent + 4);
 	if (n->child)
 		print_mdoc(n->child, indent +
 		    (n->type == ROFFT_BLOCK ? 2 : 4));
 	if (n->next)
 		print_mdoc(n->next, indent);
 }
 
 static void
 print_man(const struct roff_node *n, int indent)
 {
 	const char	 *p, *t;
 	int		  i;
 
 	if (n == NULL)
 		return;
 
 	t = p = NULL;
 
 	switch (n->type) {
 	case ROFFT_ROOT:
 		t = "root";
 		break;
 	case ROFFT_ELEM:
 		t = "elem";
 		break;
 	case ROFFT_TEXT:
 		t = "text";
 		break;
 	case ROFFT_BLOCK:
 		t = "block";
 		break;
 	case ROFFT_HEAD:
 		t = "head";
 		break;
 	case ROFFT_BODY:
 		t = "body";
 		break;
 	case ROFFT_TBL:
 		break;
 	case ROFFT_EQN:
 		t = "eqn";
 		break;
 	default:
 		abort();
 	}
 
 	switch (n->type) {
 	case ROFFT_TEXT:
 		p = n->string;
 		break;
 	case ROFFT_ELEM:
 	case ROFFT_BLOCK:
 	case ROFFT_HEAD:
 	case ROFFT_BODY:
 		p = man_macronames[n->tok];
 		break;
 	case ROFFT_ROOT:
 		p = "root";
 		break;
 	case ROFFT_TBL:
 		break;
 	case ROFFT_EQN:
 		p = "EQ";
 		break;
 	default:
 		abort();
 	}
 
 	if (n->span) {
 		assert(NULL == p && NULL == t);
 		print_span(n->span, indent);
 	} else {
 		for (i = 0; i < indent; i++)
 			putchar(' ');
 		printf("%s (%s) ", p, t);
-		if (MAN_LINE & n->flags)
+		if (NODE_LINE & n->flags)
 			putchar('*');
 		printf("%d:%d", n->line, n->pos + 1);
-		if (MAN_EOS & n->flags)
+		if (NODE_EOS & n->flags)
 			putchar('.');
 		putchar('\n');
 	}
 
 	if (n->eqn)
 		print_box(n->eqn->root->first, indent + 4);
 	if (n->child)
 		print_man(n->child, indent +
 		    (n->type == ROFFT_BLOCK ? 2 : 4));
 	if (n->next)
 		print_man(n->next, indent);
 }
 
 static void
 print_box(const struct eqn_box *ep, int indent)
 {
 	int		 i;
 	const char	*t;
 
 	static const char *posnames[] = {
 	    NULL, "sup", "subsup", "sub",
 	    "to", "from", "fromto",
 	    "over", "sqrt", NULL };
 
 	if (NULL == ep)
 		return;
 	for (i = 0; i < indent; i++)
 		putchar(' ');
 
 	t = NULL;
 	switch (ep->type) {
 	case EQN_ROOT:
 		t = "eqn-root";
 		break;
 	case EQN_LISTONE:
 	case EQN_LIST:
 		t = "eqn-list";
 		break;
 	case EQN_SUBEXPR:
 		t = "eqn-expr";
 		break;
 	case EQN_TEXT:
 		t = "eqn-text";
 		break;
 	case EQN_PILE:
 		t = "eqn-pile";
 		break;
 	case EQN_MATRIX:
 		t = "eqn-matrix";
 		break;
 	}
 
 	fputs(t, stdout);
 	if (ep->pos)
 		printf(" pos=%s", posnames[ep->pos]);
 	if (ep->left)
 		printf(" left=\"%s\"", ep->left);
 	if (ep->right)
 		printf(" right=\"%s\"", ep->right);
 	if (ep->top)
 		printf(" top=\"%s\"", ep->top);
 	if (ep->bottom)
 		printf(" bottom=\"%s\"", ep->bottom);
 	if (ep->text)
 		printf(" text=\"%s\"", ep->text);
 	if (ep->font)
 		printf(" font=%d", ep->font);
 	if (ep->size != EQN_DEFSIZE)
 		printf(" size=%d", ep->size);
 	if (ep->expectargs != UINT_MAX && ep->expectargs != ep->args)
 		printf(" badargs=%zu(%zu)", ep->args, ep->expectargs);
 	else if (ep->args)
 		printf(" args=%zu", ep->args);
 	putchar('\n');
 
 	print_box(ep->first, indent + 4);
 	print_box(ep->next, indent);
 }
 
 static void
 print_span(const struct tbl_span *sp, int indent)
 {
 	const struct tbl_dat *dp;
 	int		 i;
 
 	for (i = 0; i < indent; i++)
 		putchar(' ');
 
 	switch (sp->pos) {
 	case TBL_SPAN_HORIZ:
 		putchar('-');
 		return;
 	case TBL_SPAN_DHORIZ:
 		putchar('=');
 		return;
 	default:
 		break;
 	}
 
 	for (dp = sp->first; dp; dp = dp->next) {
 		switch (dp->pos) {
 		case TBL_DATA_HORIZ:
 		case TBL_DATA_NHORIZ:
 			putchar('-');
 			continue;
 		case TBL_DATA_DHORIZ:
 		case TBL_DATA_NDHORIZ:
 			putchar('=');
 			continue;
 		default:
 			break;
 		}
 		printf("[\"%s\"", dp->string ? dp->string : "");
 		if (dp->spans)
 			printf("(%d)", dp->spans);
 		if (NULL == dp->layout)
 			putchar('*');
 		putchar(']');
 		putchar(' ');
 	}
 
 	printf("(tbl) %d:1\n", sp->line);
 }
Index: stable/11/usr.bin/mandoc/Makefile
===================================================================
--- stable/11/usr.bin/mandoc/Makefile	(revision 316419)
+++ stable/11/usr.bin/mandoc/Makefile	(revision 316420)
@@ -1,91 +1,96 @@
 # $FreeBSD$
 
 .include 
 
 MDOCMLDIR=	${.CURDIR}/../../contrib/mdocml
 .PATH: ${MDOCMLDIR}
 
 PROG=	mandoc
 MAN=	mandoc.1 eqn.7 mandoc_char.7 tbl.7 man.7 mdoc.7 # roff.7
 MLINKS=	mandoc.1 mdocml.1
 .if ${MK_MANDOCDB} != no
 MAN+=	apropos.1 makewhatis.8
 MLINKS+=	apropos.1 whatis.1
 LINKS=	${BINDIR}/mandoc ${BINDIR}/whatis \
 	${BINDIR}/mandoc ${BINDIR}/makewhatis \
 	${BINDIR}/mandoc ${BINDIR}/apropos
 .endif
 
 LIBMAN_SRCS=	man.c \
 		man_hash.c \
 		man_macro.c \
 		man_validate.c
 
 LIBMDOC_SRCS=	att.c \
 		lib.c \
 		mdoc.c \
 		mdoc_argv.c \
 		mdoc_hash.c \
 		mdoc_macro.c \
 		mdoc_state.c \
 		mdoc_validate.c \
 		st.c \
 
 LIBROFF_SRCS=	eqn.c \
 		roff.c \
 		tbl.c \
 		tbl_data.c \
 		tbl_layout.c \
 		tbl_opts.c \
 
 LIB_SRCS=	${LIBMAN_SRCS} \
 		${LIBMDOC_SRCS} \
 		${LIBROFF_SRCS} \
 		chars.c \
 		mandoc.c \
 		mandoc_aux.c \
 		mandoc_ohash.c \
 		msec.c \
 		preconv.c \
 		read.c
 
 HTML_SRCS=	eqn_html.c \
 		html.c \
 		man_html.c \
 		mdoc_html.c \
 		tbl_html.c
 
 MAN_SRCS=	mdoc_man.c
 
 TERM_SRCS=	eqn_term.c \
 		man_term.c \
 		mdoc_term.c \
 		term.c \
 		term_ascii.c \
 		term_ps.c \
 		tbl_term.c
 
-DB_SRCS=	mandocdb.c \
-		mansearch.c \
-		mansearch_const.c \
-		tag.c \
-		manpath.c
+DBM_SRCS=	dbm.c \
+		dbm_map.c \
+		mansearch.c
 
+DBA_SRCS=	dba.c \
+		dba_array.c \
+		dba_read.c \
+		dba_write.c \
+		mandocdb.c
+
 SRCS=		${LIB_SRCS} \
 		${HTML_SRCS} \
 		${MAN_SRCS} \
 		${TERM_SRCS} \
+		${DBM_SRCS} \
+		${DBA_SRCS} \
 		main.c \
+		manpath.c \
 		out.c \
+		tag.c \
 		tree.c
 
-SRCS+=	${DB_SRCS}
-
-WARNS?=	2
+WARNS?=	3
 CFLAGS+= -DHAVE_CONFIG_H \
 	 -D_WITH_GETLINE \
-	 -I${.CURDIR}/../../lib/libopenbsd/ \
-	 -I${.CURDIR}/../../contrib/sqlite3
-LIBADD=	openbsd sqlite3 z
+	 -I${.CURDIR}/../../lib/libopenbsd/
+LIBADD=	openbsd z
 
 .include 
Index: stable/11/usr.bin/mandoc/Makefile.depend
===================================================================
--- stable/11/usr.bin/mandoc/Makefile.depend	(revision 316419)
+++ stable/11/usr.bin/mandoc/Makefile.depend	(revision 316420)
@@ -1,22 +1,20 @@
 # $FreeBSD$
 # Autogenerated - do NOT edit!
 
 DIRDEPS = \
 	gnu/lib/csu \
 	gnu/lib/libgcc \
 	include \
 	include/xlocale \
 	lib/${CSU_DIR} \
 	lib/libc \
 	lib/libcompiler_rt \
 	lib/libopenbsd \
-	lib/libsqlite3 \
-	lib/libthr \
 	lib/libz \
 
 
 .include 
 
 .if ${DEP_RELDIR} == ${_DEP_RELDIR}
 # local dependencies - needed for -jN in clean tree
 .endif
Index: stable/11
===================================================================
--- stable/11	(revision 316419)
+++ stable/11	(revision 316420)

Property changes on: stable/11
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /head:r312593