webperimental: killstack decides stack protects.
[freeciv.git] / utility / fcintl.c
blobcb903cfda0a7590c13cb0dc4c82e3da54e5ce674
1 /***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 #include <string.h>
20 /* utility */
21 #include "mem.h"
23 #include "fcintl.h"
25 static bool autocap = FALSE;
27 /***********************************************************************
28 Some strings are ambiguous for translation. For example, "Game" is
29 something you play (like Freeciv!) or animals that can be hunted.
30 To distinguish strings for translation, we qualify them with a prefix
31 string of the form "?qualifier:". So, the above two cases might be:
32 "Game" -- when used as meaning something you play
33 "?animals:Game" -- when used as animals to be hunted
34 Notice that only the second is qualified; the first is processed in
35 the normal gettext() manner (as at most one ambiguous string can be).
37 This function tests for, and removes if found, the qualifier prefix part
38 of a string.
40 This function is called by the Q_() macro and specenum. If used in the
41 Q_() macro it should, if NLS is enabled, have called gettext() to get the
42 argument to pass to this function. Specenum use it untranslated.
43 ***********************************************************************/
44 const char *skip_intl_qualifier_prefix(const char *str)
46 const char *ptr;
48 if (*str != '?') {
49 return str;
50 } else if ((ptr = strchr(str, ':'))) {
51 return (ptr + 1);
52 } else {
53 return str; /* may be something wrong */
57 /**********************************************************************
58 This function tries to capitalize first letter of the string.
59 Currently this handles just single byte UTF-8 characters, since
60 those are same as ASCII.
61 ***********************************************************************/
62 char *capitalized_string(const char *str)
64 int len = strlen(str);
65 char *result = fc_malloc(len + 1);
67 fc_strlcpy(result, str, len + 1);
69 if (autocap) {
70 if ((unsigned char) result[0] < 128) {
71 result[0] = fc_toupper(result[0]);
75 return result;
78 /**********************************************************************
79 Free capitalized string.
80 ***********************************************************************/
81 void free_capitalized(char *str)
83 FC_FREE(str);
86 /**********************************************************************
87 Translation opts in to automatic capitalization features.
88 ***********************************************************************/
89 void capitalization_opt_in(bool opt_in)
91 autocap = opt_in;
94 /**********************************************************************
95 Automatic capitalization features requested.
96 ***********************************************************************/
97 bool is_capitalization_enabled(void)
99 return autocap;
102 /**********************************************************************
103 Return directory containing locales.
104 ***********************************************************************/
105 const char *get_locale_dir(void)
107 return LOCALEDIR;