localeck.c revision 90181
190181Sphantom/*- 290181Sphantom * Copyright (c) 2002 Alexey Zelkin <phantom@FreeBSD.org> 390181Sphantom * All rights reserved. 490181Sphantom * 590181Sphantom * Redistribution and use in source and binary forms, with or without 690181Sphantom * modification, are permitted provided that the following conditions 790181Sphantom * are met: 890181Sphantom * 1. Redistributions of source code must retain the above copyright 990181Sphantom * notice, this list of conditions and the following disclaimer. 1090181Sphantom * 2. Redistributions in binary form must reproduce the above copyright 1190181Sphantom * notice, this list of conditions and the following disclaimer in the 1290181Sphantom * documentation and/or other materials provided with the distribution. 1390181Sphantom * 1490181Sphantom * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1590181Sphantom * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1690181Sphantom * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1790181Sphantom * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1890181Sphantom * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1990181Sphantom * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2090181Sphantom * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2190181Sphantom * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2290181Sphantom * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2390181Sphantom * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2490181Sphantom * SUCH DAMAGE. 2590181Sphantom * 2690181Sphantom * $FreeBSD: head/tools/diag/localeck/localeck.c 90181 2002-02-04 13:59:16Z phantom $ 2790181Sphantom */ 2890181Sphantom 2990181Sphantom#include <locale.h> 3090181Sphantom#include <stdio.h> 3190181Sphantom 3290181Sphantom/* 3390181Sphantom * Try setlocale() for locale with given name 3490181Sphantom */ 3590181Sphantom 3690181Sphantomstruct locdef { 3790181Sphantom int catid; 3890181Sphantom char *catname; 3990181Sphantom} locales[_LC_LAST] = { 4090181Sphantom { LC_ALL, "LC_ALL" }, 4190181Sphantom { LC_COLLATE, "LC_COLLATE" }, 4290181Sphantom { LC_CTYPE, "LC_CTYPE" }, 4390181Sphantom { LC_MONETARY, "LC_MONETARY" }, 4490181Sphantom { LC_NUMERIC, "LC_NUMERIC" }, 4590181Sphantom { LC_TIME, "LC_TIME" }, 4690181Sphantom { LC_MESSAGES, "LC_MESSAGES" } 4790181Sphantom}; 4890181Sphantom 4990181Sphantomint 5090181Sphantommain(int argc, char **argv) { 5190181Sphantom 5290181Sphantom int i, result; 5390181Sphantom char *localename; 5490181Sphantom 5590181Sphantom if (argc != 2) { 5690181Sphantom fprintf(stderr, "Usage: localeck <locale_name>\n"); 5790181Sphantom exit(1); 5890181Sphantom } 5990181Sphantom 6090181Sphantom localename = argv[1]; 6190181Sphantom result = 0; 6290181Sphantom 6390181Sphantom for (i = 0; i < _LC_LAST; i++) { 6490181Sphantom if (setlocale(locales[i].catid, localename) == NULL) { 6590181Sphantom printf("setlocale(%s, %s) failed\n", locales[i].catname, 6690181Sphantom localename); 6790181Sphantom result++; 6890181Sphantom } 6990181Sphantom } 7090181Sphantom return (result); 7190181Sphantom} 72