Freeciv-3.2
Loading...
Searching...
No Matches
fcintl.c
Go to the documentation of this file.
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.
7
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***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <string.h>
19
20#ifdef HAVE_UNISTD_H
21#include <unistd.h>
22#endif
23
24/* utility */
25#include "mem.h"
26
27#include "fcintl.h"
28
29static bool autocap = FALSE;
30
31/*******************************************************************/
48const char *skip_intl_qualifier_prefix(const char *str)
49{
50 const char *ptr;
51
52 if (*str != '?') {
53 return str;
54 } else if ((ptr = strchr(str, ':'))) {
55 return (ptr + 1);
56 } else {
57 return str; /* may be something wrong */
58 }
59}
60
61/*******************************************************************/
66char *capitalized_string(const char *str)
67{
68 int len = strlen(str);
69 char *result = fc_malloc(len + 1);
70
71 fc_strlcpy(result, str, len + 1);
72
73 if (autocap) {
74 if ((unsigned char) result[0] < 128) {
75 result[0] = fc_toupper(result[0]);
76 }
77 }
78
79 return result;
80}
81
82/*******************************************************************/
86{
87 FC_FREE(str);
88}
89
90/*******************************************************************/
94{
96}
97
98/*******************************************************************/
102{
103 return autocap;
104}
105
106/*******************************************************************/
111const char *get_locale_dir(void)
112{
113 static bool ldbuf_init = FALSE;
114 static char buf[4096];
115
116 if (!ldbuf_init) {
117 bool absolute = FALSE;
118
119 /* FIXME: On Windows, also something starting with the drive,
120 * e.g., "C:\", can be absolute path. Paths like that
121 * are never used with our currently supported setups.
122 *
123 * Can't check just against DIR_SEPARATOR_CHAR as the mingw
124 * layer may have converted path to use '/' even on Windows.
125 *
126 * Have to have these as two separate ifs instead of just one
127 * with || or &&, to avoid compiler warning about constants
128 * being used in such a condition.
129 */
130 if (LOCALEDIR[0] == '/') {
131 absolute = TRUE;
132 } else if (LOCALEDIR[0] == '\\') {
133 absolute = TRUE;
134 }
135
136 if (!absolute) {
137 char *cwdbuf;
138
139#ifdef HAVE_GETCWD
140 cwdbuf = getcwd(NULL, 0);
141#else
142 /* Can't help it. Must construct relative path. */
143 cwdbuf = fc_strdup(".");
144#endif
145
147
148 free(cwdbuf);
149 } else {
150 strncpy(buf, LOCALEDIR, sizeof(buf));
151 }
152
154 }
155
156 return buf;
157}
#define str
Definition astring.c:76
char * incite_cost
Definition comments.c:75
static bool autocap
Definition fcintl.c:29
char * capitalized_string(const char *str)
Definition fcintl.c:66
bool is_capitalization_enabled(void)
Definition fcintl.c:101
const char * get_locale_dir(void)
Definition fcintl.c:111
const char * skip_intl_qualifier_prefix(const char *str)
Definition fcintl.c:48
void free_capitalized(char *str)
Definition fcintl.c:85
void capitalization_opt_in(bool opt_in)
Definition fcintl.c:93
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
#define fc_malloc(sz)
Definition mem.h:34
int len
Definition packhand.c:127
#define DIR_SEPARATOR
Definition shared.h:127
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:791
char fc_toupper(char c)
Definition support.c:1276
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47