Remove obsolete na-check-for-gtk.m4
[nautilus-actions.git] / maintainer / check-po.sh
blob3f4ad5270a0b0a0999d38e80149b605577600c9a
1 #!/bin/sh
2 # FileManager-Actions
3 # A file-manager extension which offers configurable context menu actions.
5 # Copyright (C) 2005 The GNOME Foundation
6 # Copyright (C) 2006-2008 Frederic Ruaudel and others (see AUTHORS)
7 # Copyright (C) 2009-2015 Pierre Wieser and others (see AUTHORS)
9 # FileManager-Actions 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 # FileManager-Actions 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 GNU
17 # General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with FileManager-Actions; see the file COPYING. If not, see
21 # <http://www.gnu.org/licenses/>.
23 # Authors:
24 # Frederic Ruaudel <grumz@grumz.net>
25 # Rodrigo Moya <rodrigo@gnome-db.org>
26 # Pierre Wieser <pwieser@trychlos.org>
27 # ... and many others (see AUTHORS)
29 errs=0 # will be the exit code of the script
30 my_cmd="${0}" # e.g. "./make-ks.sh"
31 my_parms="$*" # e.g. "-host toaster"
32 my_cmdline="${my_cmd} ${my_parms}"
33 me="${my_cmd##*/}" # e.g. "make-ks.sh"
34 # used in msg and msgerr functions
35 my_tmproot="/tmp/$(echo ${me} | sed 's?\..*$??').$$"
36 # e.g. "/tmp/make-ks.1978"
38 # These three functions must be defined using the name() syntax in order
39 # to share traps with the caller process (cf. man (1) ksh).
41 trap_exit()
43 clear_tmpfiles
44 [ "${opt_verbose}" = "yes" -o ${errs} -gt 0 ] && msg "exiting with code ${errs}"
45 exit ${errs}
48 trap_int()
50 msg "quitting on keyboard interrupt"
51 let errs+=1
52 exit
55 trap_term()
57 [ "${opt_verbose}" = "yes" ] && msg "quitting on TERM signal"
58 exit
61 # setup the different trap functions
62 trap 'trap_term' TERM
63 trap 'trap_int' INT
64 trap 'trap_exit' EXIT
66 function clear_tmpfiles
68 \rm -f ${my_tmproot}.*
71 function msg
73 typeset _eol="\n"
74 [ $# -ge 2 ] && _eol="${2}"
75 printf "[%s] %s${_eol}" ${me} "${1}"
76 return 0
79 function msgerr
81 msg "error: ${1}" 1>&2
82 return $?
85 function msgwarn
87 msg "warning: ${1}" 1>&2
88 return $?
91 function msg_help
93 msg_version
94 echo "
95 This script checks for POTFILES.in consistency and completeness.
97 Usage: ${my_cmd} [options]
98 --[no]help print this message, and exit [${opt_help_def}]
99 --[no]version print script version, and exit [${opt_version_def}]
100 --[no]dummy dummy execution [${opt_dummy_def}]
101 --[no]verbose runs verbosely [${opt_verbose_def}]
102 --potfile=filename POTFILES.in to be checked [${opt_potfile_def}]"
105 function msg_version
107 makefile="${top_srcdir}/_build/Makefile"
108 pck_name=$(grep '^PACKAGE_NAME' ${makefile} 2>/dev/null | awk '{ print $3 }')
109 pck_version=$(grep '^PACKAGE_VERSION' ${makefile} 2>/dev/null | awk '{ print $3 }')
110 echo "
111 ${pck_name} v ${pck_version}
112 Copyright (C) 2010, 2011, 2012, 2013 Pierre Wieser."
115 # initialize common command-line options
116 nbopt=$#
117 opt_help=
118 opt_help_def="no"
119 opt_dummy=
120 opt_dummy_def="yes"
121 opt_version=
122 opt_version_def="no"
123 opt_verbose=
124 opt_verbose_def="no"
126 # a first loop over command line arguments to detect verbose mode
127 while :
129 # break when all arguments have been read
130 case $# in
132 break
134 esac
136 # get and try to interpret the next argument
137 _option=$1
138 shift
140 # make all options have two hyphens
141 _orig_option=${_option}
142 case ${_option} in
143 --*)
146 _option=-${_option}
148 esac
150 # now process options and their argument
151 case ${_option} in
152 --noverb | --noverbo | --noverbos | --noverbose)
153 opt_verbose="no"
155 --verb | --verbo | --verbos | --verbose)
156 opt_verbose="yes"
158 esac
159 done
161 [ "${opt_verbose}" = "yes" ] && msg "setting opt_verbose to 'yes'"
163 # we have scanned all command-line arguments in order to detect an
164 # opt_verbose option;
165 # reset now arguments so that they can be scanned again in main script
166 set -- ${my_parms}
168 # interpreting command-line arguments
169 opt_potfile=
170 opt_potfile_def="po/POTFILES.in"
172 # loop over command line arguments
173 pos=0
174 while :
176 # break when all arguments have been read
177 case $# in
179 break
181 esac
183 # get and try to interpret the next argument
184 option=$1
185 shift
187 # make all options have two hyphens
188 orig_option=${option}
189 case ${option} in
190 --*)
193 option=-${option}
195 esac
197 # split and extract argument for options that take one
198 case ${option} in
199 --*=*)
200 optarg=$(echo ${option} | sed -e 's/^[^=]*=//')
201 option=$(echo ${option} | sed 's/=.*//')
203 # these options take a mandatory argument
204 # since, we didn't find it in 'option', so it should be
205 # next word in the command line
206 --p | -po | -pot | -potf | -potfi | -potfil | -potfile)
207 optarg=$1
208 shift
210 esac
212 # now process options and their argument
213 case ${option} in
214 --d | --du | --dum | --dumm | --dummy)
215 [ "${opt_verbose}" = "yes" ] && msg "setting opt_dummy to 'yes'"
216 opt_dummy="yes"
218 --h | --he | --hel | --help)
219 [ "${opt_verbose}" = "yes" ] && msg "setting opt_help to 'yes'"
220 opt_help="yes"
222 --nod | --nodu | --nodum | --nodumm | --nodummy)
223 [ "${opt_verbose}" = "yes" ] && msg "setting opt_dummy to 'no'"
224 opt_dummy="no"
226 --noh | --nohe | --nohel | --nohelp)
227 [ "${opt_verbose}" = "yes" ] && msg "setting opt_help to 'no'"
228 opt_help="no"
230 --noverb | --noverbo | --noverbos | --noverbose)
232 --novers | --noversi | --noversio | --noversion)
233 [ "${opt_verbose}" = "yes" ] && msg "setting opt_version to 'no'"
234 opt_version="no"
236 --p | -po | -pot | -potf | -potfi | -potfil | -potfile)
237 [ "${opt_verbose}" = "yes" ] && msg "setting opt_potfile to '${optarg}'"
238 opt_version="no"
240 --verb | --verbo | --verbos | --verbose)
242 --vers | --versi | --versio | --version)
243 [ "${opt_verbose}" = "yes" ] && msg "setting opt_version to 'yes'"
244 opt_version="yes"
246 --*)
247 msgerr "unrecognized option: '${orig_option}'"
248 let errs+=1
250 # positional parameters
252 let pos+=1
253 #if [ ${pos} -eq 1 ]; then
254 # [ "${opt_verbose}" = "yes" ] && msg "setting opt_output to '${option}'"
255 # opt_output=${option}
256 #else
257 msgerr "unexpected positional parameter #${pos}: '${option}'"
258 let errs+=1
261 esac
262 done
264 # set option defaults
265 # does not work with /bin/sh ??
266 #set | grep -e '^opt_' | cut -d= -f1 | while read _name; do
267 # if [ "$(echo ${_name} | sed 's/.*\(_def\)/\1/')" != "_def" ]; then
268 # _value="$(eval echo "$"${_name})"
269 # if [ "${_value}" = "" ]; then
270 # eval ${_name}="$(eval echo "$"${_name}_def)"
271 # fi
272 # fi
273 #done
275 opt_help=${opt_help:-${opt_help_def}}
276 opt_dummy=${opt_dummy:-${opt_dummy_def}}
277 opt_verbose=${opt_verbose:-${opt_verbose_def}}
278 opt_version=${opt_version:-${opt_version_def}}
280 opt_potfile=${opt_potfile:-${opt_potfile_def}}
282 # check that we are running from the top of srcdir
283 maintainer_dir=$(cd ${0%/*}; pwd)
284 top_srcdir="${maintainer_dir%/*}"
285 if [ ! -f "${top_srcdir}/configure.ac" ]; then
286 msgerr "this script is only meant to be run by the maintainer,"
287 msgerr "and current working directory should be the top source directory."
288 let errs+=1
289 exit
292 if [ "${opt_help}" = "yes" -o ${nbopt} -eq 0 ]; then
293 msg_help
294 echo ""
295 exit
298 if [ "${opt_version}" = "yes" ]; then
299 msg_version
300 echo ""
301 exit
304 if [ ! -r ${opt_potfile} ]; then
305 msgerr "${opt_potfile}: file not found or not readable"
306 let errs+=1
309 if [ ${errs} -gt 0 ]; then
310 msg "${errs} error(s) have been detected"
311 msg "try '${my_cmd} --help' for usage"
312 exit
315 # ---------------------------------------------------------------------
316 # MAIN CODE
318 totpass=5
319 nbpass=0
321 # first, check that all .ui are in po/POTFILE.in
322 nbfiles=0
323 nberrs=0
324 let nbpass+=1
325 msg "pass ${nbpass}/${totpass}: checking that all .ui are in ${opt_potfile}..."
326 for f in $(git ls-files *.ui); do
327 if [ "$(grep -xe "\[type:\s*gettext/glade]\s*${f}" ${opt_potfile})" = "" ]; then
328 msg " ${f} should be added to ${opt_potfile}"
329 let nberrs+=1
330 elif [ "${opt_verbose}" = "yes" ]; then
331 msg " ${f}: OK"
333 let nbfiles+=1
334 done
335 msg " nbfiles=${nbfiles} error(s)=${nberrs}"
336 let errs+=${nberrs}
338 # second, check that all .ui in PO exist
339 nbfiles=0
340 nberrs=0
341 let nbpass+=1
342 msg "pass ${nbpass}/${totpass}: checking that all .ui from ${opt_potfile} actually exist..."
343 for f in $(grep -e '\.ui$' ${opt_potfile} | sed 's,\[type:\s*gettext/glade]\s*,,'); do
344 if [ ! -r ${f} ]; then
345 msg " ${f} should be removed from ${opt_potfile}"
346 let nberrs+=1
347 elif [ "${opt_verbose}" = "yes" ]; then
348 msg " ${f}: OK"
350 let nbfiles+=1
351 done
352 msg " nbfiles=${nbfiles} error(s)=${nberrs}"
353 let errs+=${nberrs}
355 # third, check that all files which use _( construct are in PO
356 nbfiles=0
357 nberrs=0
358 let nbpass+=1
359 msg "pass ${nbpass}/${totpass}: checking that all translatable files are in ${opt_potfile}..."
360 for f in $(git grep -I '_(' src | cut -d: -f1 | sort -u); do
361 if [ "$(grep -x ${f} ${opt_potfile})" != "${f}" ]; then
362 msg " ${f} should be added to ${opt_potfile}"
363 let nberrs+=1
364 elif [ "${opt_verbose}" = "yes" ]; then
365 msg " ${f}: OK"
367 let nbfiles+=1
368 done
369 msg " nbfiles=${nbfiles} error(s)=${nberrs}"
370 let errs+=${nberrs}
372 # fourth, check that all files in PO actually use the _( construct
373 nbfiles=0
374 nberrs=0
375 let nbpass+=1
376 msg "pass ${nbpass}/${totpass}: checking that all files in ${opt_potfile} actually use the '_(' construct..."
377 for f in $(grep -E '^src/' ${opt_potfile} | grep -vE '\.ui$' | grep -vE '\.in$'); do
378 grep '_(' ${f} 1>/dev/null 2>&1
379 if [ $? -ne 0 ]; then
380 msg " ${f} should be removed from ${opt_potfile}"
381 let nberrs+=1
382 elif [ "${opt_verbose}" = "yes" ]; then
383 msg " ${f}: OK"
385 let nbfiles+=1
386 done
387 msg " nbfiles=${nbfiles} error(s)=${nberrs}"
388 let errs+=${nberrs}
390 # last, check that all files which include gi18n.h are relevant
391 nbfiles=0
392 nberrs=0
393 let nbpass+=1
394 msg "pass ${nbpass}/${totpass}: checking that all files have a good reason to include gi18n.h..."
395 for f in $(git grep '#include <glib/gi18n.h>' src | cut -d: -f1 | sort -u); do
396 grep '_(' ${f} 1>/dev/null 2>&1
397 if [ $? -ne 0 ]; then
398 msg " ${f} should not include <glib/gi18n.h>"
399 let nberrs+=1
400 elif [ "${opt_verbose}" = "yes" ]; then
401 msg " ${f}: OK"
403 let nbfiles+=1
404 done
405 msg " nbfiles=${nbfiles} error(s)=${nberrs}"
406 let errs+=${nberrs}
408 msg "total: ${errs} error(s)."
410 exit