Blame manual/check-safety.sh

Packit 6c4009
#!/bin/sh
Packit 6c4009
Packit 6c4009
# Copyright 2014-2018 Free Software Foundation, Inc.
Packit 6c4009
# This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
# The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
# modify it under the terms of the GNU Lesser General Public
Packit 6c4009
# License as published by the Free Software Foundation; either
Packit 6c4009
# version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
# The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
# Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
# You should have received a copy of the GNU Lesser General Public
Packit 6c4009
# License along with the GNU C Library; if not, see
Packit 6c4009
# <http://www.gnu.org/licenses/>.
Packit 6c4009
Packit 6c4009
Packit 6c4009
# Check that the @safety notes are self-consistent, i.e., that they're
Packit 6c4009
# in proper order (mt then as then ac), that remarks appear within
Packit 6c4009
# corresponding sections (mt within mt, etc), that unsafety always has
Packit 6c4009
# an explicit reason and when there's a reason for unsafety it's not
Packit 6c4009
# safe, and that there aren't duplicates remarks.
Packit 6c4009
Packit 6c4009
Packit 6c4009
success=:
Packit 6c4009
Packit 6c4009
# If no arguments are given, take all *.texi files in the current directory.
Packit 6c4009
test $# != 0 || set *.texi
Packit 6c4009
Packit 6c4009
# FIXME: check that each @deftypefu?n is followed by a @safety note,
Packit 6c4009
# with nothing but @deftypefu?nx and comment lines in between.  (There
Packit 6c4009
# might be more stuff too).
Packit 6c4009
Packit 6c4009
Packit 6c4009
# Check that all safety remarks have entries for all of MT, AS and AC,
Packit 6c4009
# in this order, with an optional prelim note before them.
Packit 6c4009
grep -n '^@safety' "$@" |
Packit 6c4009
grep -v ':@safety{\(@prelim{}\)\?@mt\(un\)\?safe{.*}'\
Packit 6c4009
'@as\(un\)\?safe{.*}@ac\(un\)\?safe{.*}}' &&
Packit 6c4009
success=false
Packit 6c4009
Packit 6c4009
# Check that @mt-started notes appear within @mtsafe or @mtunsafe,
Packit 6c4009
# that @as-started notes appear within @assafe or @asunsafe, and that
Packit 6c4009
# @ac-started notes appear within @acsafe or @acunsafe.  Also check
Packit 6c4009
# that @mt, @as and @ac are followed by an s (for safe) or u (for
Packit 6c4009
# unsafe), but let @mt have as, ac or asc before [su], and let @as
Packit 6c4009
# have a c (for cancel) before [su].  Also make sure blanks separate
Packit 6c4009
# each of the annotations.
Packit 6c4009
grep -n '^@safety' "$@" |
Packit 6c4009
grep -v ':@safety{\(@prelim{}\)\?'\
Packit 6c4009
'@mt\(un\)\?safe{\(@mt\(asc\?\|ac\)\?[su][^ ]*}\)\?'\
Packit 6c4009
'\( @mt\(asc\?\|ac\)\?[su][^ ]*}\)*}'\
Packit 6c4009
'@as\(un\)\?safe{\(@asc\?[su][^ ]*}\)\?'\
Packit 6c4009
'\( @asc\?[su][^ ]*}\)*}'\
Packit 6c4009
'@ac\(un\)\?safe{\(@ac[su][^ ]*}\)\?'\
Packit 6c4009
'\( @ac[su][^ ]*}\)*}}' &&
Packit 6c4009
success=false
Packit 6c4009
Packit 6c4009
# Make sure safety lines marked as @mtsafe do not contain any
Packit 6c4009
# MT-Unsafe remark; that would be @mtu, but there could be as, ac or
Packit 6c4009
# asc between mt and u.
Packit 6c4009
grep -n '^@safety.*@mtsafe' "$@" |
Packit 6c4009
grep '@mt\(asc\?\|ac\)?u' "$@" &&
Packit 6c4009
success=false
Packit 6c4009
Packit 6c4009
# Make sure @mtunsafe lines contain at least one @mtu remark (with
Packit 6c4009
# optional as, ac or asc between mt and u).
Packit 6c4009
grep -n '^@safety.*@mtunsafe' "$@" |
Packit 6c4009
grep -v '@mtunsafe{.*@mt\(asc\?\|ac\)\?u' &&
Packit 6c4009
success=false
Packit 6c4009
Packit 6c4009
# Make sure safety lines marked as @assafe do not contain any AS-Unsafe
Packit 6c4009
# remark, which could be @asu or @mtasu note (with an optional c
Packit 6c4009
# between as and u in both cases).
Packit 6c4009
grep -n '^@safety.*@assafe' "$@" |
Packit 6c4009
grep '@\(mt\)\?asc\?u' &&
Packit 6c4009
success=false
Packit 6c4009
Packit 6c4009
# Make sure @asunsafe lines contain at least one @asu remark (which
Packit 6c4009
# could be @ascu, or @mtasu or even @mtascu).
Packit 6c4009
grep -n '^@safety.*@asunsafe' "$@" |
Packit 6c4009
grep -v '@mtasc\?u.*@asunsafe\|@asunsafe{.*@asc\?u' &&
Packit 6c4009
success=false
Packit 6c4009
Packit 6c4009
# Make sure safety lines marked as @acsafe do not contain any
Packit 6c4009
# AC-Unsafe remark, which could be @acu, @ascu or even @mtacu or
Packit 6c4009
# @mtascu.
Packit 6c4009
grep -n '^@safety.*@acsafe' "$@" |
Packit 6c4009
grep '@\(mt\)\?as\?cu' &&
Packit 6c4009
success=false
Packit 6c4009
Packit 6c4009
# Make sure @acunsafe lines contain at least one @acu remark (possibly
Packit 6c4009
# implied by @ascu, @mtacu or @mtascu).
Packit 6c4009
grep -n '^@safety.*@acunsafe' "$@" |
Packit 6c4009
grep -v '@\(mtas\?\|as\)cu.*@acunsafe\|@acunsafe{.*@acu' &&
Packit 6c4009
success=false
Packit 6c4009
Packit 6c4009
# Make sure there aren't duplicate remarks in the same safety note.
Packit 6c4009
grep -n '^@safety' "$@" |
Packit 6c4009
grep '[^:]\(@\(mt\|a[sc]\)[^ {]*{[^ ]*}\).*[^:]\1' &&
Packit 6c4009
success=false
Packit 6c4009
Packit 6c4009
# Check that comments containing safety remarks do not contain {}s,
Packit 6c4009
# that all @mt remarks appear before @as remarks, that in turn appear
Packit 6c4009
# before @ac remarks, all properly blank-separated, and that an
Packit 6c4009
# optional comment about exclusions is between []s at the end of the
Packit 6c4009
# line.
Packit 6c4009
grep -n '^@c \+[^@ ]\+\( dup\)\?'\
Packit 6c4009
'\( @\(mt\|a[sc]\)[^ ]*\)*\( \[.*\]\)\?$' "$@" |
Packit 6c4009
grep -v ':@c *[^@{}]*\( @mt[^ {}]*\)*'\
Packit 6c4009
'\( @as[^ {}]*\)*\( @ac[^ {}]*\)*\( \[.*\]\)\?$' &&
Packit 6c4009
success=false
Packit 6c4009
Packit 6c4009
# Check that comments containing safety remarks do not contain
Packit 6c4009
# duplicate remarks.
Packit 6c4009
grep -n '^@c \+[^@ ]\+\( dup\)\?'\
Packit 6c4009
'\( @\(mt\|a[sc]\)[^ ]*\)*\( \[.*\]\)\?$' "$@" |
Packit 6c4009
grep '[^:]\(@\(mt\|a[sc]\)[^ ]*\) \(.*[^:]\)\?\1\($\| \)' &&
Packit 6c4009
success=false
Packit 6c4009
Packit 6c4009
$success