Freeciv-3.1: /fast/freeciv/nightly/S3_1/utility/fcintl.c Source File

Freeciv-3.1

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
29 static bool autocap = FALSE;
30
31/*******************************************************************/
48 const 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/*******************************************************************/
66 char *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/*******************************************************************/
85 void free_capitalized(char *str)
86{
87 FC_FREE(str);
88}
89
90/*******************************************************************/
93 void capitalization_opt_in(bool opt_in)
94{
95 autocap = opt_in;
96}
97
98/*******************************************************************/
101 bool is_capitalization_enabled(void)
102{
103 return autocap;
104}
105
106/*******************************************************************/
111 const 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
146 fc_snprintf(buf, sizeof(buf), "%s" DIR_SEPARATOR LOCALEDIR, cwdbuf);
147
148 free(cwdbuf);
149 } else {
150 strncpy(buf, LOCALEDIR, sizeof(buf));
151 }
152
153 ldbuf_init = TRUE;
154 }
155
156 return buf;
157}
str
#define str
Definition astring.c:76
autocap
static bool autocap
Definition fcintl.c:29
capitalized_string
char * capitalized_string(const char *str)
Definition fcintl.c:66
is_capitalization_enabled
bool is_capitalization_enabled(void)
Definition fcintl.c:101
get_locale_dir
const char * get_locale_dir(void)
Definition fcintl.c:111
skip_intl_qualifier_prefix
const char * skip_intl_qualifier_prefix(const char *str)
Definition fcintl.c:48
free_capitalized
void free_capitalized(char *str)
Definition fcintl.c:85
capitalization_opt_in
void capitalization_opt_in(bool opt_in)
Definition fcintl.c:93
fcintl.h
mem.h
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
fc_strdup
#define fc_strdup(str)
Definition mem.h:43
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
len
int len
Definition packhand.c:125
DIR_SEPARATOR
#define DIR_SEPARATOR
Definition shared.h:127
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
fc_strlcpy
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:787
fc_toupper
char fc_toupper(char c)
Definition support.c:1271
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47