Linus Walleij | 59765e8 | 2008-08-15 07:17:12 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file util.c |
| 3 | * A set of common utility functions found |
| 4 | * in all samples. |
| 5 | * |
| 6 | * Copyright (C) 2008 Linus Walleij <triad@df.lth.se> |
| 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Lesser General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public |
| 19 | * License along with this library; if not, write to the |
| 20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 21 | * Boston, MA 02111-1307, USA. |
| 22 | */ |
Catalin Patulea | a53c389 | 2012-07-17 22:25:10 -0400 | [diff] [blame] | 23 | #include "config.h" |
Linus Walleij | 59765e8 | 2008-08-15 07:17:12 +0000 | [diff] [blame] | 24 | #include "util.h" |
| 25 | #ifdef HAVE_LANGINFO_H |
| 26 | #include <langinfo.h> |
| 27 | #endif |
Linus Walleij | 8b8c850 | 2008-08-18 19:58:36 +0000 | [diff] [blame] | 28 | #ifdef HAVE_LOCALE_H |
| 29 | #include <locale.h> |
| 30 | #endif |
Linus Walleij | 59765e8 | 2008-08-15 07:17:12 +0000 | [diff] [blame] | 31 | #include <stdlib.h> |
| 32 | #include <stdio.h> |
| 33 | #include <string.h> |
Catalin Patulea | a53c389 | 2012-07-17 22:25:10 -0400 | [diff] [blame] | 34 | #include <strings.h> |
Linus Walleij | 59765e8 | 2008-08-15 07:17:12 +0000 | [diff] [blame] | 35 | |
| 36 | void checklang(void) |
| 37 | { |
Catalin Patulea | a53c389 | 2012-07-17 22:25:10 -0400 | [diff] [blame] | 38 | const char *langsuff = NULL; |
| 39 | const char *lang = getenv("LANG"); |
Linus Walleij | 59765e8 | 2008-08-15 07:17:12 +0000 | [diff] [blame] | 40 | |
Linus Walleij | 8b8c850 | 2008-08-18 19:58:36 +0000 | [diff] [blame] | 41 | #ifdef HAVE_LOCALE_H |
| 42 | // Set the locale in accordance with environment |
| 43 | setlocale(LC_ALL, ""); |
| 44 | #endif |
Linus Walleij | 59765e8 | 2008-08-15 07:17:12 +0000 | [diff] [blame] | 45 | #ifdef HAVE_LANGINFO_H |
| 46 | langsuff = nl_langinfo(CODESET); |
| 47 | #else |
| 48 | /* |
| 49 | * Check environment variables $LANG and $LC_CTYPE |
| 50 | * to see if we want to support UTF-8 unicode |
| 51 | */ |
| 52 | if (lang != NULL) { |
Catalin Patulea | a53c389 | 2012-07-17 22:25:10 -0400 | [diff] [blame] | 53 | const char *sep = strrchr(lang, '.'); |
| 54 | if (sep != NULL) { |
| 55 | langsuff = sep + 1; |
| 56 | } else { |
| 57 | langsuff = lang; |
Linus Walleij | 59765e8 | 2008-08-15 07:17:12 +0000 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | #endif |
Linus Walleij | d8a2fae | 2008-12-02 12:20:17 +0000 | [diff] [blame] | 61 | if (langsuff == NULL) { |
| 62 | printf("Could not determine language suffix for your system. Please check your setup!\n"); |
Catalin Patulea | a53c389 | 2012-07-17 22:25:10 -0400 | [diff] [blame] | 63 | } else if (strcasecmp(langsuff, "UTF-8") && strcasecmp(langsuff, "UTF8")) { |
Linus Walleij | 59765e8 | 2008-08-15 07:17:12 +0000 | [diff] [blame] | 64 | printf("Your system does not appear to have UTF-8 enabled ($LANG=\"%s\")\n", lang); |
| 65 | printf("If you want to have support for diacritics and Unicode characters,\n"); |
| 66 | printf("please switch your locale to an UTF-8 locale, e.g. \"en_US.UTF-8\".\n"); |
| 67 | } |
| 68 | } |