Convert NASettings to a private singleton
[nautilus-actions.git] / tools / check-headers.sh
blob6ef51b65561afd879bf49d1525bbcbeb4c0448a9
1 #!/bin/sh
2 # Nautilus-Actions
3 # A Nautilus extension which offers configurable context menu actions.
5 # Copyright (C) 2005 The GNOME Foundation
6 # Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
7 # Copyright (C) 2009, 2010, 2011 Pierre Wieser and others (see AUTHORS)
9 # This Program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation; either version 2 of
12 # the License, or (at your option) any later version.
14 # This Program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public
20 # License along with this Library; see the file COPYING. If not,
21 # write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307, USA.
24 # Authors:
25 # Frederic Ruaudel <grumz@grumz.net>
26 # Rodrigo Moya <rodrigo@gnome-db.org>
27 # Pierre Wieser <pwieser@trychlos.org>
28 # ... and many others (see AUTHORS)
30 errs=0 # will be the exit code of the script
31 my_cmd="${0}" # e.g. "./make-ks.sh"
32 my_parms="$*" # e.g. "-host toaster"
33 my_cmdline="${my_cmd} ${my_parms}"
34 me="${my_cmd##*/}" # e.g. "make-ks.sh"
35 # used in msg and msgerr functions
36 my_tmproot="/tmp/$(echo ${me} | sed 's?\..*$??').$$"
37 # e.g. "/tmp/make-ks.1978"
39 # These three functions must be defined using the name() syntax in order
40 # to share traps with the caller process (cf. man (1) ksh).
42 trap_exit()
44 clear_tmpfiles
45 [ "${opt_verbose}" = "yes" -o ${errs} -gt 0 ] && msg "exiting with code ${errs}"
46 exit ${errs}
49 trap_int()
51 msg "quitting on keyboard interrupt"
52 let errs+=1
53 exit
56 trap_term()
58 [ "${opt_verbose}" = "yes" ] && msg "quitting on TERM signal"
59 exit
62 # setup the different trap functions
63 trap 'trap_term' TERM
64 trap 'trap_int' INT
65 trap 'trap_exit' EXIT
67 function clear_tmpfiles
69 \rm -f ${my_tmproot}.*
72 function msg
74 typeset _eol="\n"
75 [ $# -ge 2 ] && _eol="${2}"
76 printf "[%s] %s${_eol}" ${me} "${1}"
77 return 0
80 function msgerr
82 msg "error: ${1}" 1>&2
83 return $?
86 function msgwarn
88 msg "warning: ${1}" 1>&2
89 return $?
92 function msg_help
94 msg_version
95 echo "
96 This script checks for header files consistency and completeness.
97 It ensures that each header files itself includes the set of prequisite
98 header files so that the tested header is auto-sufficent.
100 Usage: ${my_cmd} [options]
101 --[no]help print this message, and exit [${opt_help_def}]
102 --[no]version print script version, and exit [${opt_version_def}]
103 --[no]dummy dummy execution [${opt_dummy_def}]
104 --[no]verbose runs verbosely [${opt_verbose_def}]"
107 function msg_version
109 pck_name=$(grep '^PACKAGE_NAME' Makefile 2>/dev/null | awk '{ print $3 }')
110 pck_version=$(grep '^PACKAGE_VERSION' Makefile 2>/dev/null | awk '{ print $3 }')
111 echo "
112 ${pck_name} v ${pck_version}
113 Copyright (C) 2011 Pierre Wieser."
116 # initialize common command-line options
117 nbopt=$#
118 opt_help=
119 opt_help_def="no"
120 opt_dummy=
121 opt_dummy_def="yes"
122 opt_version=
123 opt_version_def="no"
124 opt_verbose=
125 opt_verbose_def="no"
127 # a first loop over command line arguments to detect verbose mode
128 while :
130 # break when all arguments have been read
131 case $# in
133 break
135 esac
137 # get and try to interpret the next argument
138 _option=$1
139 shift
141 # make all options have two hyphens
142 _orig_option=${_option}
143 case ${_option} in
144 --*)
147 _option=-${_option}
149 esac
151 # now process options and their argument
152 case ${_option} in
153 --noverb | --noverbo | --noverbos | --noverbose)
154 opt_verbose="no"
156 --verb | --verbo | --verbos | --verbose)
157 opt_verbose="yes"
159 esac
160 done
162 [ "${opt_verbose}" = "yes" ] && msg "setting opt_verbose to 'yes'"
164 # we have scanned all command-line arguments in order to detect an
165 # opt_verbose option;
166 # reset now arguments so that they can be scanned again in main script
167 set -- ${my_parms}
169 # interpreting command-line arguments
170 opt_potfile=
171 opt_potfile_def="po/POTFILES.in"
173 # loop over command line arguments
174 pos=0
175 while :
177 # break when all arguments have been read
178 case $# in
180 break
182 esac
184 # get and try to interpret the next argument
185 option=$1
186 shift
188 # make all options have two hyphens
189 orig_option=${option}
190 case ${option} in
191 --*)
194 option=-${option}
196 esac
198 # split and extract argument for options that take one
199 case ${option} in
200 --*=*)
201 optarg=$(echo ${option} | sed -e 's/^[^=]*=//')
202 option=$(echo ${option} | sed 's/=.*//')
204 # these options take a mandatory argument
205 # since, we didn't find it in 'option', so it should be
206 # next word in the command line
207 #--p | -po | -pot | -potf | -potfi | -potfil | -potfile)
208 # optarg=$1
209 # shift
210 # ;;
211 esac
213 # now process options and their argument
214 case ${option} in
215 --d | --du | --dum | --dumm | --dummy)
216 [ "${opt_verbose}" = "yes" ] && msg "setting opt_dummy to 'yes'"
217 opt_dummy="yes"
219 --h | --he | --hel | --help)
220 [ "${opt_verbose}" = "yes" ] && msg "setting opt_help to 'yes'"
221 opt_help="yes"
223 --nod | --nodu | --nodum | --nodumm | --nodummy)
224 [ "${opt_verbose}" = "yes" ] && msg "setting opt_dummy to 'no'"
225 opt_dummy="no"
227 --noh | --nohe | --nohel | --nohelp)
228 [ "${opt_verbose}" = "yes" ] && msg "setting opt_help to 'no'"
229 opt_help="no"
231 --noverb | --noverbo | --noverbos | --noverbose)
233 --novers | --noversi | --noversio | --noversion)
234 [ "${opt_verbose}" = "yes" ] && msg "setting opt_version to 'no'"
235 opt_version="no"
237 --verb | --verbo | --verbos | --verbose)
239 --vers | --versi | --versio | --version)
240 [ "${opt_verbose}" = "yes" ] && msg "setting opt_version to 'yes'"
241 opt_version="yes"
243 --*)
244 msgerr "unrecognized option: '${orig_option}'"
245 let errs+=1
247 # positional parameters
249 let pos+=1
250 #if [ ${pos} -eq 1 ]; then
251 # [ "${opt_verbose}" = "yes" ] && msg "setting opt_output to '${option}'"
252 # opt_output=${option}
253 #else
254 msgerr "unexpected positional parameter #${pos}: '${option}'"
255 let errs+=1
258 esac
259 done
261 # set option defaults
262 # does not work with /bin/sh ??
263 #set | grep -e '^opt_' | cut -d= -f1 | while read _name; do
264 # if [ "$(echo ${_name} | sed 's/.*\(_def\)/\1/')" != "_def" ]; then
265 # _value="$(eval echo "$"${_name})"
266 # if [ "${_value}" = "" ]; then
267 # eval ${_name}="$(eval echo "$"${_name}_def)"
268 # fi
269 # fi
270 #done
272 opt_help=${opt_help:-${opt_help_def}}
273 opt_dummy=${opt_dummy:-${opt_dummy_def}}
274 opt_verbose=${opt_verbose:-${opt_verbose_def}}
275 opt_version=${opt_version:-${opt_version_def}}
277 if [ "${opt_help}" = "yes" -o ${nbopt} -eq 0 ]; then
278 msg_help
279 echo ""
280 exit
283 if [ "${opt_version}" = "yes" ]; then
284 msg_version
285 echo ""
286 exit
289 if [ "$(basename $(pwd))" != "nautilus-actions" ]; then
290 msgerr "current directory is $(pwd)"
291 msg "you should change to nautilus-actions/"
292 let errs+=1
295 if [ ${errs} -gt 0 ]; then
296 msg "${errs} error(s) have been detected"
297 msg "try '${my_cmd} --help' for usage"
298 exit
301 # ---------------------------------------------------------------------
302 # MAIN CODE
304 for f in $(git ls-files src | grep '\.h$' | grep -v '^src/test'); do
305 msg "checking for $f..." " "
306 tmpc=tools/check-header.c
307 cat <<! >${tmpc}
308 #include <${f}>
309 int main( int argc, char **argv ){ return( 0 ); }
311 make -C tools check-header 1>/dev/null 2>&1 && tools/check-header 1>/dev/null 2>&1
312 [ $? -eq 0 ] && echo "OK" || { echo "NOT OK"; let errs+=1; }
313 done
315 exit