Add simple diagnostic utility to checking for invalid/incomplete

locales
This commit is contained in:
Alexey Zelkin 2002-02-04 13:59:16 +00:00
parent f25125064b
commit ac6e0aed98
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=90181
3 changed files with 122 additions and 0 deletions

View File

@ -0,0 +1,11 @@
# $FreeBSD$
PROG= localeck
NOMAN= YES
LOCALEDIR?=/usr/share/locale
test: ${PROG}
/bin/sh docheck.sh ${LOCALEDIR}
.include <bsd.prog.mk>

View File

@ -0,0 +1,40 @@
#!/bin/sh
#
# Validate all locales installed in specified directory
# (by default check system locales)
#
# $FreeBSD$
#
LOCALEDIR=/usr/share/locale
if [ "$1" != "" ]; then
LOCALEDIR=$1
fi
if [ ! -x ./localeck ]; then
echo "ERROR: build test program first."
exit 1
fi
PATH_LOCALE=$LOCALEDIR
LOCALES=0
ERRORS=0
echo "Validating locales in $LOCALEDIR"
echo
for i in `ls -1 $LOCALEDIR`
do
LOCALES=`expr $LOCALES + 1`
./localeck $i
if [ $? != 0 ]; then
ERRORS=`expr $ERRORS + 1`
fi
done
echo
echo "Validation test complete."
echo "$LOCALES locale(s) were checked"
echo "$ERRORS invalid locale(s) were found"

View File

@ -0,0 +1,71 @@
/*-
* Copyright (c) 2002 Alexey Zelkin <phantom@FreeBSD.org>
* 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 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 AUTHOR 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.
*
* $FreeBSD$
*/
#include <locale.h>
#include <stdio.h>
/*
* Try setlocale() for locale with given name
*/
struct locdef {
int catid;
char *catname;
} locales[_LC_LAST] = {
{ LC_ALL, "LC_ALL" },
{ LC_COLLATE, "LC_COLLATE" },
{ LC_CTYPE, "LC_CTYPE" },
{ LC_MONETARY, "LC_MONETARY" },
{ LC_NUMERIC, "LC_NUMERIC" },
{ LC_TIME, "LC_TIME" },
{ LC_MESSAGES, "LC_MESSAGES" }
};
int
main(int argc, char **argv) {
int i, result;
char *localename;
if (argc != 2) {
fprintf(stderr, "Usage: localeck <locale_name>\n");
exit(1);
}
localename = argv[1];
result = 0;
for (i = 0; i < _LC_LAST; i++) {
if (setlocale(locales[i].catid, localename) == NULL) {
printf("setlocale(%s, %s) failed\n", locales[i].catname,
localename);
result++;
}
}
return (result);
}