Fixup fromcvs/togit conversion
[minix-pkgsrc.git] / mk / check / check-subr.sh
blob58e6eb706ab99031088b2a8a19f069b25005e28b
1 # $NetBSD: check-subr.sh,v 1.4 2006/11/11 23:08:00 rillig Exp $
3 # This file contains shell functions that are used by the various shell
4 # programs that check things in pkgsrc. All these programs must be
5 # called with the following environment variables set:
7 # SKIP_FILTER
8 # A shell expression of the form
10 # */pattern.*) continue;; *.txt) continue;;
12 # that can be passed to eval(1) in order to skip the files
13 # that are chosen by the respective *_SKIP variable in
14 # make(1).
17 # Implementation notes:
19 # 1. The SKIP_FILTER variable should only be used in the following
20 # pattern, usually inside a "for" or "while" loop.
22 # skip=no
23 # eval "case \"\$fname\" in $SKIP_FILTER *.orig) skip=yes;; esac"
24 # [ $skip = no ] || continue
26 # 2. The programs using this file are run with the tools wrapper
27 # directory in the PATH, so they call the utilities by their base names.
28 # They may also assume to be interpreted by a POSIX-conforming shell, in
29 # particular _not_ by the Solaris /bin/sh.
32 # All programs that check something are very strict.
33 set -eu
35 cs_exitcode=0
37 # usage: cs_setprogname "progname"
39 # This function sets the variable that will later be used in diagnostic
40 # messages to identify the program that generated the message.
41 cs_setprogname() {
42 cs_progname="${1##*/}"
45 # Each diagnostic message can be preceded by a heading to better identify
46 # messages that belong together. The heading will only be printed if it
47 # differs from the last one.
48 cs_last_heading=""
50 # usage: cs_error_heading "new heading"
51 cs_error_heading() {
52 if [ x"$1" != x"$cs_last_heading" ]; then
53 cs_last_heading="$1"
54 cs_error_msg "=> $1"
58 # usage: cs_warning_heading "new heading"
59 cs_warning_heading() {
60 if [ x"$1" != x"$cs_last_heading" ]; then
61 cs_last_heading="$1"
62 cs_warning_msg "=> $1"
66 # usage: cs_error_msg "error message"
67 cs_error_msg() {
68 echo "ERROR: [$cs_progname] $*" 1>&2
69 cs_exitcode=1
72 # usage: cs_warning_msg "warning message"
73 cs_warning_msg() {
74 echo "WARNING: [$cs_progname] $*" 1>&2
77 cs_hline=\
78 "==========================================================================="
80 # usage: cs_explain <<EOF
81 cs_explain() {
82 { echo ""
83 echo "Explanation:"
84 echo "$cs_hline"
85 cat
86 echo "$cs_hline"
87 echo ""
88 } 1>&2
91 # usage: cs_exit
93 # At the end of the program, cs_exit should be called to return the
94 # appropriate exit status to the calling process. It is non-zero when
95 # any error messages have been printed and zero otherwise.
96 cs_exit() {
97 exit "$cs_exitcode"