diff options
| author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2025-09-20 19:19:34 +0200 | 
|---|---|---|
| committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2025-09-20 19:19:34 +0200 | 
| commit | e7d20cf352688bf717a01f4e6d9e6f497c2bea4c (patch) | |
| tree | cfd2ef9b569f49af985a6f1ec44f2614f63c8e78 /app/bin/locale.c | |
| parent | a14a7a0ccc9de76aeab0b2e4bbf58f1a79deedc2 (diff) | |
New upstream version 5.3.1Beta2upstream/5.3.1Beta2
Diffstat (limited to 'app/bin/locale.c')
| -rw-r--r-- | app/bin/locale.c | 78 | 
1 files changed, 78 insertions, 0 deletions
diff --git a/app/bin/locale.c b/app/bin/locale.c new file mode 100644 index 0000000..257a975 --- /dev/null +++ b/app/bin/locale.c @@ -0,0 +1,78 @@ +/** + * \file   locale.c + * \brief  Locale handling + */ + +/*  XTrackCad - Model Railroad CAD + *  Copyright (C) 2005, 2024 Dave Bullis + * + *  This program is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 2 of the License, or + *  (at your option) any later version. + * + *  This program is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with this program; if not, write to the Free Software + *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "common.h" +#include <locale.h> + +/** + * SetCLocale is called before reading/writing any data files (.xtc, .xti, .xtq, .cus...). + * SetUserLocale is called after. + * Calls can be nested: C, C, User, User + */ + +static char* sUserLocale = NULL;	// current user locale +static long lCLocale = 0;		// locale state: > 0 C locale, <= 0 user locale +static long nCLocale = 0;		// total # of setlocals calls +static int log_locale = 0;		// logging + + +EXPORT void SetCLocale() +{ +	if (sUserLocale == NULL) { +		sUserLocale = MyStrdup(setlocale(LC_ALL, NULL)); +	} +	if (lCLocale == 0) { +		LOG(log_locale, 1, ("Set C Locale: %ld\n", ++nCLocale)); +		setlocale(LC_ALL, "C"); +#ifdef LC_MESSAGES +		setlocale(LC_MESSAGES, ""); +#endif +	} +	lCLocale++; +	if (lCLocale > 1) { +		LOG(log_locale, 3, ("SetClocale - C! %ld\n", nCLocale)); +	} else if (lCLocale < 1) { +		LOG(log_locale, 2, ("SetClocale - User! %ld\n", nCLocale)); +	} +} + +EXPORT void SetUserLocale() +{ +	if (lCLocale == 1) { +		LOG(log_locale, 1, ("Set %s Locale: %ld\n", sUserLocale, ++nCLocale)); +		setlocale(LC_ALL, sUserLocale); +	} +	lCLocale--; +	if (lCLocale < 0) { +		LOG(log_locale, 2, ("SetUserLocale - User! %ld\n", nCLocale)); +	} else if (lCLocale > 0) { +		LOG(log_locale, 3, ("SetUserLocale - C! %ld\n", nCLocale)); +	} +} + +void +LocaleInit() +{ +	log_locale = LogFindIndex("locale"); +} +  | 
