Sun Feb 12 18:56:54 2017 UTC ()
Import verify-synopsis-1.0 as textproc/verify-synopsis.
This package contains a tool to verify that the functions in the
SYNOPSIS of a man page match the actual implementation.
(wiz)
diff -r0 -r1.1 pkgsrc/textproc/verify-synopsis/DESCR
diff -r0 -r1.1 pkgsrc/textproc/verify-synopsis/Makefile
diff -r0 -r1.1 pkgsrc/textproc/verify-synopsis/PLIST
diff -r0 -r1.1 pkgsrc/textproc/verify-synopsis/files/dmpsynopsis.awk
diff -r0 -r1.1 pkgsrc/textproc/verify-synopsis/files/verify-synopsis
diff -r0 -r1.1 pkgsrc/textproc/verify-synopsis/files/verify-synopsis.1
This package contains a tool to verify that the functions in the
SYNOPSIS of a man page match the actual implementation.
# $NetBSD: Makefile,v 1.1 2017/02/12 18:56:54 wiz Exp $
DISTNAME= verify-synopsis-1.0
CATEGORIES= textproc
MASTER_SITES= # none
DISTFILES= # none
OWNER= wiz@NetBSD.org
#HOMEPAGE= #
COMMENT= Tool for verifying man pages' SYNOPSIS
LICENSE= modified-bsd
INSTALLATION_DIRS= bin ${PKGMANDIR}/man1 libexec
WRKSRC= ${WRKDIR}
NO_BUILD= yes
USE_LANGUAGES= # none
.include "../../mk/bsd.prefs.mk"
.if ${OPSYS} != "NetBSD"
DEPENDS+= mdocml-[0-9]*:../../textproc/mdocml
.endif
SUBST_CLASSES+= prefix
SUBST_STAGE.prefix= post-extract
SUBST_VARS.prefix= PREFIX
SUBST_FILES.prefix= verify-synopsis
SUBST_MESSAGE.prefix= Fixing prefix.
do-extract:
cd ${FILESDIR} && cp d* v* ${WRKSRC}/
do-install:
${INSTALL_SCRIPT} ${WRKSRC}/verify-synopsis ${DESTDIR}${PREFIX}/bin
${INSTALL_DATA} ${WRKSRC}/dmpsynopsis.awk ${DESTDIR}${PREFIX}/libexec
${INSTALL_MAN} ${FILESDIR}/verify-synopsis.1 \
${DESTDIR}${PREFIX}/${PKGMANDIR}/man1
.include "../../mk/bsd.pkg.mk"
@comment $NetBSD: PLIST,v 1.1 2017/02/12 18:56:54 wiz Exp $
bin/verify-synopsis
libexec/dmpsynopsis.awk
man/man1/verify-synopsis.1
#
# Copyright (c) 2016 The DragonFly Project. All rights reserved.
#
# This code is derived from software contributed to The DragonFly Project
# by Sascha Wildner <swildner@dragonflybsd.org>
#
# 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 DragonFly Project 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 COPYRIGHT HOLDERS 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
# COPYRIGHT HOLDERS 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.
#
#
# Converts the output of mandoc -Ttree (run over a manual page
# with prototypes) into a small C program that can be used to
# check it.
#
($1 == "SYNOPSIS" && $2 == "(text)") {
getline;
if ($1 == "Sh" && ($2 == "(block-body)" || $2 == "(body)")) {
getline;
while ($1 != "Sh") {
if ($2 == "(elem)") {
if (elem == "Fn" ||
(elem == "Fa" && $1 != "Fa")) {
printf ");\n"
if (justtypedef == 0) {
printf "#ifndef %s\n",
function_name;
printf "man_%s test_%s = %s;\n",
function_name,
function_name,
function_name;
printf "#endif";
}
printf "\n";
justtypedef = 0;
function_type = "";
}
elem = $1; # elem is now from the current line
funcnamenext = 0;
if (elem == "In")
printf "#include ";
else if (elem == "Fn")
funcnamenext = 1;
else if (elem == "Ft")
firsttypenext = 1;
} else if ($2 == "(block)" && elem == "In" &&
$1 != "Fo") {
elem = "";
} else if (match($0, "(text)") != 0) {
if (elem == "In") {
printf "<%s>\n", $1;
} else if (elem == "Ft") { # function type
if ($1 == "typedef") {
justtypedef = 1;
firsttypenext = 0;
}
gsub("^[ ]*", "");
gsub(" [(]text[)].*", "");
gsub("\\\\", "");
if (justtypedef == 1) {
printf "\n";
}
if (firsttypenext == 1) {
firsttypenext = 0;
printf "\ntypedef ";
}
function_type = $0;
printf "%s ", function_type;
} else if (elem == "Fn") { # function name
if (funcnamenext == 1) {
function_name = $1;
if (justtypedef == 1) {
printf "%s(",
function_name;
} else {
if (function_type == "")
printf "\ntypedef void *****";
printf "(*man_%s)(",
function_name;
}
funcnamenext = 0;
firstargnext = 1;
} else { # function arguments
gsub("^[ ]*", "")
gsub(" [(]text[)].*", "");
gsub("\\\\\\\\[*][(]lp", "(");
gsub("\\\\\\\\[*][(]rp", ")");
if (firstargnext == 1)
firstargnext = 0;
else
printf ", ";
if (justtypedef == 0) {
printf("\n#ifdef %s\n", function_name);
if (index($0, " ") == 0 && $0 != "void")
printf("int\n");
printf("#endif\n");
}
printf "%s", $0;
}
} else if (elem == "Fa") {
gsub("^[ ]*", "")
gsub(" [(]text[)].*", "");
gsub("\\\\:", ""); # \: (see groff(7))
if (firstargnext == 1)
firstargnext = 0;
else
printf ", ";
if (justtypedef == 0) {
printf("\n#ifdef %s\n", function_name);
if (index($0, " ") == 0 && $0 != "void")
printf("int\n");
printf("#endif\n");
}
printf "%s", $0;
}
} else if ($1 == "Fo") {
getline; getline;
function_name = $1;
if (function_type == "")
printf "\ntypedef void *****";
printf "(*man_%s)(", function_name;
getline;
firstargnext = 1;
}
getline;
}
if (elem == "Fn" || elem == "Fa") {
printf ");\n";
if (justtypedef == 0) {
printf "#ifndef %s\n", function_name;
printf "man_%s test_%s = %s;\n",
function_name,
function_name,
function_name;
printf "#endif\n";
}
}
}
}
#!/bin/sh
TMPFILE=/tmp/verify-synopsis.$$.c
mandoc -Ttree "$@" | awk -f @PREFIX@/libexec/dmpsynopsis.awk > "$TMPFILE" && gcc -c -o /dev/null -Wall "$TMPFILE" 2>&1
rm -f "$TMPFILE"
.\" $NetBSD: verify-synopsis.1,v 1.1 2017/02/12 18:56:54 wiz Exp $
.\"
.\" Copyright (c) 2017 Thomas Klausner
.\" 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.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR, THOMAS KLAUSNER,
.\" ``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 FOUNDATION 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.
.\"
.Dd February 12, 2017
.Dt VERIFY-SYNOPSIS 1
.Os
.Sh NAME
.Nm verify-synopsis
.Nd man page verification of SYNOPSIS section
.Sh SYNOPSIS
.Nm
.Op Ar manpage
.Sh DESCRIPTION
.Nm
verifies the SYNOPSIS section of a man page by extracting it into
a C code snipped and compiling this.
The compiler warnings will indiciate missing headers or incorrect
prototypes.
.Sh EXAMPLES
.Dl verify-synopsis foo.3
.Sh SEE ALSO
.Xr mandoc 1 ,
.Xr mdoclint 1
.Sh AUTHORS
.An Sascha Wildner
.Aq Mt swildner@dragonflybsd.org
.Sh BUGS
Macros are not handled very well.