Freeciv-3.3
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions
shared.h File Reference
#include <freeciv_config.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "log.h"
#include "support.h"
#include "speclist.h"

Go to the source code of this file.

Data Structures

struct  fileinfo
 
struct  cf_sequence
 

Macros

#define MAX_LEN_ADDR   256 /* See also MAXHOSTNAMELEN and RFC 1123 2.1 */
 
#define MAX_LEN_PATH   4095
 
#define FC_INFINITY   (1000 * 1000 * 1000)
 
#define BAD_HEURISTIC_INIT(_ini_val_)   = _ini_val_
 
#define BOOL_TO_TRISTATE(tri)   ((tri) ? TRI_YES : TRI_NO)
 
#define MAX(x, y)   (((x)>(y))?(x):(y))
 
#define MIN(x, y)   (((x)<(y))?(x):(y))
 
#define CLIP(lower, current, upper)    ((current)<(lower)?(lower):(current)>(upper)?(upper):(current))
 
#define ABS(x)   (((x) >= 0) ? (x) : -(x))
 
#define FC_WRAP(value, range)
 
#define BOOL_VAL(x)   ((x) != 0)
 
#define XOR(p, q)   (BOOL_VAL(p) != BOOL_VAL(q))
 
#define EQ(p, q)   (BOOL_VAL(p) == BOOL_VAL(q))
 
#define DIVIDE(n, d)    ( (n) / (d) - (( (n) < 0 && (n) % (d) < 0 ) ? 1 : 0) )
 
#define MAX_UINT32   0xFFFFFFFF
 
#define MAX_UINT16   0xFFFF
 
#define MAX_UINT8   0xFF
 
#define ARRAY_SIZE(x)   (sizeof(x) / sizeof((x)[0]))
 
#define ADD_TO_POINTER(p, n)   ((void *)((char *)(p)+(n)))
 
#define FC_MEMBER(type, member)   (((type *) nullptr)->member)
 
#define FC_MEMBER_OFFSETOF(type, member)   ((size_t) &FC_MEMBER(type, member))
 
#define FC_MEMBER_SIZEOF(type, member)   sizeof(FC_MEMBER(type, member))
 
#define FC_MEMBER_ARRAY_SIZE(type, member)    ARRAY_SIZE(FC_MEMBER(type, member))
 
#define FC_INT_TO_PTR(i)   ((void *) (intptr_t) (i))
 
#define FC_PTR_TO_INT(p)   ((int) (intptr_t) (p))
 
#define INITIALIZE_ARRAY(array, size, value)
 
#define PATH_SEPARATOR   ":"
 
#define DIR_SEPARATOR_IS_DEFAULT
 
#define DIR_SEPARATOR   "/"
 
#define DIR_SEPARATOR_CHAR   '/'
 
#define PARENT_DIR_OPERATOR   ".."
 
#define sz_loud_strlcpy(buffer, str, errmsg)    loud_strlcpy(buffer, str, sizeof(buffer), errmsg)
 
#define SPECLIST_TAG   fileinfo
 
#define SPECLIST_TYPE   struct fileinfo
 
#define fileinfo_list_iterate(list, pnode)    TYPED_LIST_ITERATE(struct fileinfo, list, pnode)
 
#define fileinfo_list_iterate_end   LIST_ITERATE_END
 
#define DIRMODE_DEFAULT   (-1)
 

Typedefs

typedef const char *(* m_pre_accessor_fn_t) (int)
 
typedef int(* m_pre_strncmp_fn_t) (const char *, const char *, size_t n)
 
typedef size_t() m_strlen_fn_t(const char *str)
 

Enumerations

enum  fc_tristate { TRI_NO , TRI_YES , TRI_MAYBE }
 
enum  m_pre_result {
  M_PRE_EXACT , M_PRE_ONLY , M_PRE_AMBIGUOUS , M_PRE_EMPTY ,
  M_PRE_LONG , M_PRE_FAIL , M_PRE_LAST
}
 
enum  cf_type {
  CF_BOOLEAN , CF_TRANS_BOOLEAN , CF_CHARACTER , CF_INTEGER ,
  CF_HEXA , CF_FLOAT , CF_POINTER , CF_STRING ,
  CF_LAST = -1
}
 

Functions

enum fc_tristate fc_tristate_and (enum fc_tristate one, enum fc_tristate two)
 
enum fc_tristate fc_tristate_or (enum fc_tristate one, enum fc_tristate two)
 
const charbig_int_to_text (unsigned int mantissa, unsigned int exponent)
 
const charint_to_text (unsigned int number)
 
bool is_ascii_name (const char *name)
 
bool is_base64url (const char *s)
 
bool is_safe_filename (const char *name)
 
void randomize_base64url_string (char *s, size_t n)
 
int compare_strings (const void *first, const void *second)
 
int compare_strings_ptrs (const void *first, const void *second)
 
int compare_strings_strvec (const char *const *first, const char *const *second)
 
charskip_leading_spaces (char *s) fc__attribute((nonnull(1)))
 
void remove_leading_spaces (char *s) fc__attribute((nonnull(1)))
 
void remove_trailing_spaces (char *s) fc__attribute((nonnull(1)))
 
void remove_leading_trailing_spaces (char *s)
 
bool check_strlen (const char *str, size_t len, const char *errmsg)
 
size_t loud_strlcpy (char *buffer, const char *str, size_t len, const char *errmsg)
 
charend_of_strn (char *str, int *nleft)
 
bool str_to_int (const char *str, int *pint) fc__attribute((nonnull(1)))
 
bool str_to_uint (const char *str, unsigned int *pint) fc__attribute((nonnull(1)))
 
bool str_to_float (const char *str, float *pfloat) fc__attribute((nonnull(1)))
 
charuser_home_dir (void)
 
void free_user_home_dir (void)
 
charuser_username (char *buf, size_t bufsz)
 
charfreeciv_storage_dir (void)
 
void free_freeciv_storage_dir (void)
 
const struct strvecget_data_dirs (void)
 
const struct strvecget_save_dirs (void)
 
const struct strvecget_scenario_dirs (void)
 
void free_data_dir_names (void)
 
struct strvecfileinfolist (const struct strvec *dirs, const char *suffix)
 
struct fileinfo_listfileinfolist_infix (const struct strvec *dirs, const char *infix, bool nodups)
 
const charfileinfoname (const struct strvec *dirs, const char *filename)
 
void free_fileinfo_data (void)
 
void init_nls (void)
 
void free_nls (void)
 
const charsetup_langname (void)
 
void switch_lang (const char *lang)
 
void dont_run_as_root (const char *argv0, const char *fallback)
 
const charm_pre_description (enum m_pre_result result)
 
enum m_pre_result match_prefix (m_pre_accessor_fn_t accessor_fn, size_t n_names, size_t max_len_name, m_pre_strncmp_fn_t cmp_fn, m_strlen_fn_t len_fn, const char *prefix, int *ind_result)
 
enum m_pre_result match_prefix_full (m_pre_accessor_fn_t accessor_fn, size_t n_names, size_t max_len_name, m_pre_strncmp_fn_t cmp_fn, m_strlen_fn_t len_fn, const char *prefix, int *ind_result, int *matches, int max_matches, int *pnum_matches)
 
charget_multicast_group (bool ipv6_preferred)
 
void free_multicast_group (void)
 
void interpret_tilde (char *buf, size_t buf_size, const char *filename)
 
charinterpret_tilde_alloc (const char *filename)
 
charskip_to_basename (char *filepath)
 
bool make_dir (const char *pathname, int mode) fc__attribute((nonnull(1)))
 
bool make_dir_for_file (char *filename) fc__attribute((nonnull(1)))
 
bool path_is_absolute (const char *filename)
 
char scanin (const char **buf, char *delimiters, char *dest, int size)
 
void array_shuffle (int *array, int n)
 
void format_time_duration (time_t t, char *buf, int maxlen)
 
bool wildcard_fit_string (const char *pattern, const char *test)
 
int fc_snprintcf (char *buf, size_t buf_len, const char *format,...) fc__attribute((nonnull(1
 
int int fc_vsnprintcf (char *buf, size_t buf_len, const char *format, const struct cf_sequence *sequences, size_t sequences_num) fc__attribute((nonnull(1
 
int int static struct cf_sequence cf_bool_seq (char letter, bool value)
 
static struct cf_sequence cf_trans_bool_seq (char letter, bool value)
 
static struct cf_sequence cf_char_seq (char letter, char value)
 
static void cf_int_seq (char letter, int value, struct cf_sequence *out)
 
static struct cf_sequence cf_hexa_seq (char letter, int value)
 
static struct cf_sequence cf_float_seq (char letter, float value)
 
static struct cf_sequence cf_ptr_seq (char letter, const void *value)
 
static struct cf_sequence cf_str_seq (char letter, const char *value)
 
static struct cf_sequence cf_end (void)
 
bool formats_match (const char *format1, const char *format2)
 

Macro Definition Documentation

◆ ABS

#define ABS (   x)    (((x) >= 0) ? (x) : -(x))

Definition at line 61 of file shared.h.

◆ ADD_TO_POINTER

#define ADD_TO_POINTER (   p,
  n 
)    ((void *)((char *)(p)+(n)))

Definition at line 86 of file shared.h.

◆ ARRAY_SIZE

#define ARRAY_SIZE (   x)    (sizeof(x) / sizeof((x)[0]))

Definition at line 85 of file shared.h.

◆ BAD_HEURISTIC_INIT

#define BAD_HEURISTIC_INIT (   _ini_val_)    = _ini_val_

Definition at line 41 of file shared.h.

◆ BOOL_TO_TRISTATE

#define BOOL_TO_TRISTATE (   tri)    ((tri) ? TRI_YES : TRI_NO)

Definition at line 47 of file shared.h.

◆ BOOL_VAL

#define BOOL_VAL (   x)    ((x) != 0)

Definition at line 70 of file shared.h.

◆ CLIP

#define CLIP (   lower,
  current,
  upper 
)     ((current)<(lower)?(lower):(current)>(upper)?(upper):(current))

Definition at line 57 of file shared.h.

◆ DIR_SEPARATOR

#define DIR_SEPARATOR   "/"

Definition at line 127 of file shared.h.

◆ DIR_SEPARATOR_CHAR

#define DIR_SEPARATOR_CHAR   '/'

Definition at line 128 of file shared.h.

◆ DIR_SEPARATOR_IS_DEFAULT

#define DIR_SEPARATOR_IS_DEFAULT

Definition at line 126 of file shared.h.

◆ DIRMODE_DEFAULT

#define DIRMODE_DEFAULT   (-1)

Definition at line 258 of file shared.h.

◆ DIVIDE

#define DIVIDE (   n,
 
)     ( (n) / (d) - (( (n) < 0 && (n) % (d) < 0 ) ? 1 : 0) )

Definition at line 78 of file shared.h.

◆ EQ

#define EQ (   p,
  q 
)    (BOOL_VAL(p) == BOOL_VAL(q))

Definition at line 72 of file shared.h.

◆ FC_INFINITY

#define FC_INFINITY   (1000 * 1000 * 1000)

Definition at line 36 of file shared.h.

◆ FC_INT_TO_PTR

#define FC_INT_TO_PTR (   i)    ((void *) (intptr_t) (i))

Definition at line 94 of file shared.h.

◆ FC_MEMBER

#define FC_MEMBER (   type,
  member 
)    (((type *) nullptr)->member)

Definition at line 88 of file shared.h.

◆ FC_MEMBER_ARRAY_SIZE

#define FC_MEMBER_ARRAY_SIZE (   type,
  member 
)     ARRAY_SIZE(FC_MEMBER(type, member))

Definition at line 91 of file shared.h.

◆ FC_MEMBER_OFFSETOF

#define FC_MEMBER_OFFSETOF (   type,
  member 
)    ((size_t) &FC_MEMBER(type, member))

Definition at line 89 of file shared.h.

◆ FC_MEMBER_SIZEOF

#define FC_MEMBER_SIZEOF (   type,
  member 
)    sizeof(FC_MEMBER(type, member))

Definition at line 90 of file shared.h.

◆ FC_PTR_TO_INT

#define FC_PTR_TO_INT (   p)    ((int) (intptr_t) (p))

Definition at line 95 of file shared.h.

◆ FC_WRAP

#define FC_WRAP (   value,
  range 
)
Value:
((value) < 0 \
? ((value) % (range) != 0 ? (value) % (range) + (range) : 0) \
: ((value) >= (range) ? (value) % (range) : (value)))

Definition at line 65 of file shared.h.

◆ fileinfo_list_iterate

#define fileinfo_list_iterate (   list,
  pnode 
)     TYPED_LIST_ITERATE(struct fileinfo, list, pnode)

Definition at line 182 of file shared.h.

◆ fileinfo_list_iterate_end

#define fileinfo_list_iterate_end   LIST_ITERATE_END

Definition at line 184 of file shared.h.

◆ INITIALIZE_ARRAY

#define INITIALIZE_ARRAY (   array,
  size,
  value 
)
Value:
{ \
(array)[_ini_index] = (value); \
} \
}
char * incite_cost
Definition comments.c:76
size_t size
Definition specvec.h:72

Definition at line 101 of file shared.h.

◆ MAX

#define MAX (   x,
  y 
)    (((x)>(y))?(x):(y))

Definition at line 54 of file shared.h.

◆ MAX_LEN_ADDR

#define MAX_LEN_ADDR   256 /* See also MAXHOSTNAMELEN and RFC 1123 2.1 */

Definition at line 31 of file shared.h.

◆ MAX_LEN_PATH

#define MAX_LEN_PATH   4095

Definition at line 32 of file shared.h.

◆ MAX_UINT16

#define MAX_UINT16   0xFFFF

Definition at line 82 of file shared.h.

◆ MAX_UINT32

#define MAX_UINT32   0xFFFFFFFF

Definition at line 81 of file shared.h.

◆ MAX_UINT8

#define MAX_UINT8   0xFF

Definition at line 83 of file shared.h.

◆ MIN

#define MIN (   x,
  y 
)    (((x)<(y))?(x):(y))

Definition at line 55 of file shared.h.

◆ PARENT_DIR_OPERATOR

#define PARENT_DIR_OPERATOR   ".."

Definition at line 131 of file shared.h.

◆ PATH_SEPARATOR

#define PATH_SEPARATOR   ":"

Definition at line 116 of file shared.h.

◆ SPECLIST_TAG

#define SPECLIST_TAG   fileinfo

Definition at line 179 of file shared.h.

◆ SPECLIST_TYPE

#define SPECLIST_TYPE   struct fileinfo

Definition at line 180 of file shared.h.

◆ sz_loud_strlcpy

#define sz_loud_strlcpy (   buffer,
  str,
  errmsg 
)     loud_strlcpy(buffer, str, sizeof(buffer), errmsg)

Definition at line 158 of file shared.h.

◆ XOR

#define XOR (   p,
  q 
)    (BOOL_VAL(p) != BOOL_VAL(q))

Definition at line 71 of file shared.h.

Typedef Documentation

◆ m_pre_accessor_fn_t

typedef const char *(* m_pre_accessor_fn_t) (int)

Definition at line 226 of file shared.h.

◆ m_pre_strncmp_fn_t

typedef int(* m_pre_strncmp_fn_t) (const char *, const char *, size_t n)

Definition at line 229 of file shared.h.

◆ m_strlen_fn_t

typedef size_t() m_strlen_fn_t(const char *str)

Definition at line 232 of file shared.h.

Enumeration Type Documentation

◆ cf_type

Enumerator
CF_BOOLEAN 
CF_TRANS_BOOLEAN 
CF_CHARACTER 
CF_INTEGER 
CF_HEXA 
CF_FLOAT 
CF_POINTER 
CF_STRING 
CF_LAST 

Definition at line 295 of file shared.h.

◆ fc_tristate

Enumerator
TRI_NO 
TRI_YES 
TRI_MAYBE 

Definition at line 46 of file shared.h.

◆ m_pre_result

Enumerator
M_PRE_EXACT 
M_PRE_ONLY 
M_PRE_AMBIGUOUS 
M_PRE_EMPTY 
M_PRE_LONG 
M_PRE_FAIL 
M_PRE_LAST 

Definition at line 213 of file shared.h.

Function Documentation

◆ array_shuffle()

void array_shuffle ( int array,
int  n 
)

Randomize the elements of an array using the Fisher-Yates shuffle.

See: http://benpfaff.org/writings/clc/shuffle.html

Definition at line 2011 of file shared.c.

Referenced by trade_generator::calculate(), genlist_shuffle(), map_generate_fair_islands(), and shuffle_players().

◆ big_int_to_text()

const char * big_int_to_text ( unsigned int  mantissa,
unsigned int  exponent 
)

Returns a statically allocated string containing a nicely-formatted version of the given number according to the user's locale. (Only works for numbers >= zero.) The number is given in scientific notation as mantissa * 10^exponent.

Definition at line 162 of file shared.c.

Referenced by int_to_text(), and population_to_text().

◆ cf_bool_seq()

static struct cf_sequence cf_bool_seq ( char  letter,
bool  value 
)
inlinestatic

Build an argument for fc_snprintcf() of boolean type.

Definition at line 324 of file shared.h.

◆ cf_char_seq()

static struct cf_sequence cf_char_seq ( char  letter,
char  value 
)
inlinestatic

Build an argument for fc_snprintcf() of character type (c).

Definition at line 353 of file shared.h.

◆ cf_end()

static struct cf_sequence cf_end ( void  )
inlinestatic

Must finish the list of the arguments of fc_snprintcf().

Definition at line 433 of file shared.h.

Referenced by generate_save_name().

◆ cf_float_seq()

static struct cf_sequence cf_float_seq ( char  letter,
float  value 
)
inlinestatic

Build an argument for fc_snprintcf() of float type (f).

Definition at line 391 of file shared.h.

◆ cf_hexa_seq()

static struct cf_sequence cf_hexa_seq ( char  letter,
int  value 
)
inlinestatic

Build an argument for fc_snprintcf() of hexadecimal type (x).

Definition at line 377 of file shared.h.

◆ cf_int_seq()

static void cf_int_seq ( char  letter,
int  value,
struct cf_sequence out 
)
inlinestatic

Build an argument for fc_snprintcf() of integer type (d).

Definition at line 367 of file shared.h.

Referenced by generate_save_name().

◆ cf_ptr_seq()

static struct cf_sequence cf_ptr_seq ( char  letter,
const void value 
)
inlinestatic

Build an argument for fc_snprintcf() of pointer type (p).

Definition at line 405 of file shared.h.

◆ cf_str_seq()

static struct cf_sequence cf_str_seq ( char  letter,
const char value 
)
inlinestatic

Build an argument for fc_snprintcf() of string type (s).

Definition at line 419 of file shared.h.

Referenced by generate_save_name().

◆ cf_trans_bool_seq()

static struct cf_sequence cf_trans_bool_seq ( char  letter,
bool  value 
)
inlinestatic

Build an argument for fc_snprintcf() of boolean type (result will be translated).

Definition at line 339 of file shared.h.

◆ check_strlen()

bool check_strlen ( const char str,
size_t  len,
const char errmsg 
)

Check the length of the given string. If the string is too long, log errmsg, which should be a string in printf-format taking up to two arguments: the string and the length.

Definition at line 493 of file shared.c.

Referenced by load_ruleset_nations(), and loud_strlcpy().

◆ compare_strings()

int compare_strings ( const void first,
const void second 
)

Compares two strings, in the collating order of the current locale, given pointers to the two strings (i.e., given "char *"s). Case-sensitive. Designed to be called from qsort().

Definition at line 363 of file shared.c.

Referenced by help_item_compar().

◆ compare_strings_ptrs()

int compare_strings_ptrs ( const void first,
const void second 
)

Compares two strings, in the collating order of the current locale, given pointers to the two string pointers (i.e., given "char **"s). Case-sensitive. Designed to be called from qsort().

Definition at line 373 of file shared.c.

Referenced by packet_handlers_get().

◆ compare_strings_strvec()

int compare_strings_strvec ( const char *const first,
const char *const second 
)

Compares two strings, in the collating order of the current locale, given pointers to the two string pointers. Case-sensitive. Designed to be called from strvec_sort().

Definition at line 383 of file shared.c.

Referenced by fileinfolist(), and report_wonders_of_the_world_long().

◆ dont_run_as_root()

void dont_run_as_root ( const char argv0,
const char fallback 
)

If we have root privileges, die with an error. (Eg, for security reasons.) Param argv0 should be argv[0] or similar; fallback is used instead if argv0 is nullptr. But don't die on systems where the user is always root... (a general test for this would be better). Doesn't use log_*() because gets called before logging is setup.

Definition at line 1542 of file shared.c.

Referenced by client_main(), and main().

◆ end_of_strn()

char * end_of_strn ( char str,
int nleft 
)

Returns pointer to '\0' at end of string 'str', and decrements nleft by the length of 'str'. This is intended to be useful to allow strcat-ing without traversing the whole string each time, while still keeping track of the buffer length. Eg: char buf[128]; int n = sizeof(buf); char *p = buf;

fc_snprintf(p, n, "foo%p", p); p = end_of_strn(p, &n); fc_strlcpy(p, "yyy", n);

Definition at line 478 of file shared.c.

◆ fc_snprintcf()

int fc_snprintcf ( char buf,
size_t  buf_len,
const char format,
  ... 
)

◆ fc_tristate_and()

enum fc_tristate fc_tristate_and ( enum fc_tristate  one,
enum fc_tristate  two 
)

An AND function for fc_tristate.

Definition at line 127 of file shared.c.

Referenced by action_enabled_local(), and action_prob().

◆ fc_tristate_or()

enum fc_tristate fc_tristate_or ( enum fc_tristate  one,
enum fc_tristate  two 
)

An OR function for fc_tristate.

Definition at line 143 of file shared.c.

Referenced by is_diplrel_unitany_in_range().

◆ fc_vsnprintcf()

int int fc_vsnprintcf ( char buf,
size_t  buf_len,
const char format,
const struct cf_sequence sequences,
size_t  sequences_num 
)

◆ fileinfolist()

struct strvec * fileinfolist ( const struct strvec dirs,
const char suffix 
)

Returns a string vector storing the filenames in the data directories matching the given suffix.

The list is allocated when the function is called; it should either be stored permanently or destroyed (with strvec_destroy()).

The suffixes are removed from the filenames before the list is returned.

Definition at line 1020 of file shared.c.

Referenced by get_audio_speclist(), get_init_script_choices(), get_theme_list(), and themespec_try_read().

◆ fileinfolist_infix()

struct fileinfo_list * fileinfolist_infix ( const struct strvec dirs,
const char infix,
bool  nodups 
)

Search for filenames with the "infix" substring in the "subpath" subdirectory of the data path. "nodups" removes duplicate names. The returned list will be sorted by name first and modification time second. Returned "name"s will be truncated starting at the "infix" substring. The returned list must be freed with fileinfo_list_destroy().

Definition at line 1204 of file shared.c.

Referenced by get_modpacks_list(), popup_load_game_dialog(), save_dialog_mapimg_list(), save_dialog_savegame_list(), save_dialog_scenario_list(), show_scenarios(), update_load_page(), fc_client::update_load_page(), update_scenario_page(), and fc_client::update_scenarios_page().

◆ fileinfoname()

const char * fileinfoname ( const struct strvec dirs,
const char filename 
)

Returns a filename to access the specified file from a directory by searching all specified directories for the file.

If the specified 'filename' is nullptr, the returned string contains the effective path. (But this should probably only be used for debug output.)

Returns nullptr if the specified filename cannot be found in any of the data directories. (A file is considered "found" if it can be read-opened.) The returned pointer points to static memory, so this function can only supply one filename at a time. Don't free that pointer.

TODO: Make this re-entrant

Definition at line 1094 of file shared.c.

Referenced by audio_play_tag(), audiospec_fullname(), boot_help_texts(), comments_load(), datafilename(), fc_icons::get_icon(), fc_icons::get_path(), fc_icons::get_pixmap(), get_token_value(), get_ui_filename(), load_command(), load_gfx_file(), load_sdl2_gfx_file(), load_sdl3_gfx_file(), lua_command(), main(), read_init_script_real(), ruledit_main::ruledit_main(), set_rulesetdir(), sg_load_savefile(), srv_prepare(), theme_read_toplevel(), themespec_gfx_filename(), tileset_scan_single_list(), tilespec_fullname(), tilespec_gfx_filename(), and valid_ruleset_filename().

◆ format_time_duration()

void format_time_duration ( time_t  t,
char buf,
int  maxlen 
)

Convenience function to nicely format a time_t seconds value in to a string with hours, minutes, etc.

Definition at line 1968 of file shared.c.

Referenced by unit_can_do_action_now().

◆ formats_match()

bool formats_match ( const char format1,
const char format2 
)

Returns TRUE iff both formats are compatible (if 'format1' can be used instead 'format2' and reciprocally).

Definition at line 2446 of file shared.c.

Referenced by ruler_title_check(), and sanity_check_ruleset_data().

◆ free_data_dir_names()

void free_data_dir_names ( void  )

Free data dir name vectors.

Definition at line 859 of file shared.c.

Referenced by libfreeciv_free().

◆ free_fileinfo_data()

void free_fileinfo_data ( void  )

Free resources allocated for fileinfoname service

Definition at line 1151 of file shared.c.

Referenced by libfreeciv_free().

◆ free_freeciv_storage_dir()

void free_freeciv_storage_dir ( void  )

Free freeciv storage directory information

Definition at line 689 of file shared.c.

Referenced by libfreeciv_free().

◆ free_multicast_group()

void free_multicast_group ( void  )

Free multicast group resources

Definition at line 1698 of file shared.c.

Referenced by libfreeciv_free().

◆ free_nls()

void free_nls ( void  )

Free memory allocated by Native Language Support

Definition at line 1525 of file shared.c.

Referenced by libfreeciv_free().

◆ free_user_home_dir()

void free_user_home_dir ( void  )

Free user home directory information

Definition at line 658 of file shared.c.

Referenced by libfreeciv_free().

◆ freeciv_storage_dir()

char * freeciv_storage_dir ( void  )

Returns string which gives freeciv storage dir. Gets value once, and then caches result. Note the caller should not mess with the returned string.

Definition at line 671 of file shared.c.

Referenced by client_start_server(), fcmp_parse_cmdline(), get_challenge_fullname(), mr_menu::save_image(), send_client_wants_hack(), server_sniff_all_input(), and tab_misc::tab_misc().

◆ get_data_dirs()

const struct strvec * get_data_dirs ( void  )

Returns a list of data directory paths, in the order in which they should be searched. These paths are specified internally or may be set as the environment variable $FREECIV_DATA PATH (a separated list of directories, where the separator itself is specified internally, platform-dependent). '~' at the start of a component (provided followed by '/' or '\0') is expanded as $HOME.

The returned pointer is static and shouldn't be modified, nor destroyed by the user caller.

Definition at line 886 of file shared.c.

Referenced by audio_play_tag(), audiospec_fullname(), boot_help_texts(), comments_load(), datafilename(), get_audio_speclist(), get_gui_specific_themes_directories(), fc_icons::get_icon(), get_init_script_choices(), get_modpacks_list(), fc_icons::get_path(), fc_icons::get_pixmap(), get_theme_list(), get_token_value(), get_ui_filename(), load_gfx_file(), load_sdl2_gfx_file(), load_sdl3_gfx_file(), lua_command(), main(), qtg_get_gui_specific_themes_directories(), read_init_script_real(), ruledit_main::ruledit_main(), set_rulesetdir(), srv_prepare(), theme_read_toplevel(), themespec_gfx_filename(), themespec_try_read(), tileset_scan_single_list(), tilespec_fullname(), tilespec_gfx_filename(), and valid_ruleset_filename().

◆ get_multicast_group()

char * get_multicast_group ( bool  ipv6_preferred)

Returns string which gives the multicast group IP address for finding servers on the LAN, as specified by $FREECIV_MULTICAST_GROUP. Gets value once, and then caches result.

Definition at line 1667 of file shared.c.

Referenced by begin_lanserver_scan(), send_lanserver_response(), and server_open_socket().

◆ get_save_dirs()

const struct strvec * get_save_dirs ( void  )

Returns a list of save directory paths, in the order in which they should be searched. These paths are specified internally or may be set as the environment variable $FREECIV_SAVE_PATH (a separated list of directories, where the separator itself is specified internally, platform-dependent). '~' at the start of a component (provided followed by '/' or '\0') is expanded as $HOME.

The returned pointer is static and shouldn't be modified, nor destroyed by the user caller.

Definition at line 934 of file shared.c.

Referenced by load_command(), popup_load_game_dialog(), save_dialog_mapimg_list(), save_dialog_savegame_list(), mr_menu::save_game_as(), update_load_page(), and fc_client::update_load_page().

◆ get_scenario_dirs()

const struct strvec * get_scenario_dirs ( void  )

Returns a list of scenario directory paths, in the order in which they should be searched. These paths are specified internally or may be set as the environment variable $FREECIV_SCENARIO_PATH (a separated list of directories, where the separator itself is specified internally, platform-dependent). '~' at the start of a component (provided followed by '/' or '\0') is expanded as $HOME.

The returned pointer is static and shouldn't be modified, nor destroyed by the user caller.

Definition at line 971 of file shared.c.

Referenced by load_command(), save_dialog_scenario_list(), sg_load_savefile(), show_scenarios(), update_scenario_page(), and fc_client::update_scenarios_page().

◆ init_nls()

void init_nls ( void  )

Setup for Native Language Support, if configured to use it. (Call this only once, or it may leak memory.)

Definition at line 1463 of file shared.c.

Referenced by libfreeciv_init().

◆ int_to_text()

const char * int_to_text ( unsigned int  number)

Return a prettily formatted string containing the given number.

Definition at line 237 of file shared.c.

Referenced by value_units().

◆ interpret_tilde()

void interpret_tilde ( char buf,
size_t  buf_size,
const char filename 
)

Interpret ~/ in filename as home dir New path is returned in buf of size buf_size

This may fail if the path is too long. It is better to use interpret_tilde_alloc().

Definition at line 1713 of file shared.c.

Referenced by lua_command(), read_init_script_real(), secfile_load_section(), secfile_save(), and write_init_script().

◆ interpret_tilde_alloc()

char * interpret_tilde_alloc ( const char filename)

Interpret ~/ in filename as home dir

The new path is returned in buf, as a newly allocated buffer. The new path will always be allocated and written, even if there is no ~ present.

Definition at line 1730 of file shared.c.

Referenced by make_dir().

◆ is_ascii_name()

bool is_ascii_name ( const char name)

This is used in sundry places to make sure that names of cities, players etc. do not contain yucky characters of various sorts. Returns TRUE iff the name is acceptable. FIXME: Not internationalised.

Definition at line 286 of file shared.c.

Referenced by is_allowed_city_name(), is_good_password(), is_valid_username(), server_player_name_is_allowed(), and user_username().

◆ is_base64url()

bool is_base64url ( const char s)

Check for valid base64url.

Definition at line 321 of file shared.c.

Referenced by sg_load_sanitycheck(), and sg_load_sanitycheck().

◆ is_safe_filename()

bool is_safe_filename ( const char name)

Check if the name is safe security-wise. This is intended to be used to make sure an untrusted filename is safe to be used.

Definition at line 256 of file shared.c.

Referenced by api_server_save(), load_command(), lua_command(), read_init_script_real(), savename_validate(), scorefile_validate(), send_client_wants_hack(), and set_rulesetdir().

◆ loud_strlcpy()

size_t loud_strlcpy ( char buffer,
const char str,
size_t  len,
const char errmsg 
)

Call check_strlen() on str and then strlcpy() it into buffer.

Definition at line 503 of file shared.c.

◆ m_pre_description()

const char * m_pre_description ( enum m_pre_result  result)

Return a description string of the result. In English, form of description is suitable to substitute in, eg: prefix is (N.B.: The description is always in English, but they have all been marked for translation. If you want a localized version, use _() on the return.)

Definition at line 1564 of file shared.c.

Referenced by cmd_reply_no_such_conn(), and cmd_reply_no_such_player().

◆ make_dir()

bool make_dir ( const char pathname,
int  mode 
)

If the directory "pathname" does not exist, recursively create all directories until it does.

TODO: Make errno available after a failure, preferably via fc_get_errno(). Currently there's things potentially messing errno between failed mkdir() and the function return.

Parameters
pathnamedirectory path to create
modedirectory creation mode, or negative for default mode
Returns
success or not

Definition at line 1779 of file shared.c.

Referenced by create_mpdb(), img_save(), make_dir_for_file(), save_game(), save_ruleset(), send_client_wants_hack(), and server_sniff_all_input().

◆ make_dir_for_file()

bool make_dir_for_file ( char filename)

If the directory part of the "filename" does not exist, recursively create all directories until it does.

Definition at line 1862 of file shared.c.

Referenced by download_modpack_recursive().

◆ match_prefix()

enum m_pre_result match_prefix ( m_pre_accessor_fn_t  accessor_fn,
size_t  n_names,
size_t  max_len_name,
m_pre_strncmp_fn_t  cmp_fn,
m_strlen_fn_t  len_fn,
const char prefix,
int ind_result 
)

◆ match_prefix_full()

enum m_pre_result match_prefix_full ( m_pre_accessor_fn_t  accessor_fn,
size_t  n_names,
size_t  max_len_name,
m_pre_strncmp_fn_t  cmp_fn,
m_strlen_fn_t  len_fn,
const char prefix,
int ind_result,
int matches,
int  max_matches,
int pnum_matches 
)

Given n names, with maximum length max_len_name, accessed by accessor_fn(0) to accessor_fn(n-1), look for matching prefix according to given comparison function. Returns type of match or fail, and for return <= M_PRE_AMBIGUOUS sets *ind_result with matching index (or for ambiguous, first match). If max_len_name == 0, treat as no maximum. If the int array 'matches' is not nullptr, up to 'max_matches' ambiguous matching names indices will be inserted into it. If 'pnum_matches' is not nullptr, it will be set to the number of indices inserted into 'matches'.

Definition at line 1606 of file shared.c.

Referenced by check_player_or_user_name(), match_prefix(), and show_help().

◆ path_is_absolute()

bool path_is_absolute ( const char filename)

Returns TRUE if the filename's path is absolute.

Definition at line 1884 of file shared.c.

Referenced by img_save(), and save_game().

◆ randomize_base64url_string()

void randomize_base64url_string ( char s,
size_t  n 
)

Generate a random string meeting criteria such as is_ascii_name(), is_base64url(), and is_safe_filename().

Definition at line 343 of file shared.c.

Referenced by init_new_game(), sg_load_sanitycheck(), and sg_load_sanitycheck().

◆ remove_leading_spaces()

void remove_leading_spaces ( char s)

Removes leading spaces in string pointed to by 's'. Note 's' must point to writeable memory!

Definition at line 405 of file shared.c.

Referenced by handle_stdin_input_real(), and remove_leading_trailing_spaces().

◆ remove_leading_trailing_spaces()

void remove_leading_trailing_spaces ( char s)

◆ remove_trailing_spaces()

void remove_trailing_spaces ( char s)

Terminates string pointed to by 's' to remove trailing spaces; Note 's' must point to writeable memory!

Definition at line 422 of file shared.c.

Referenced by expand_dir(), handle_stdin_input_real(), and remove_leading_trailing_spaces().

◆ scanin()

char scanin ( const char **  buf,
char delimiters,
char dest,
int  size 
)

Scan in a word or set of words from start to but not including any of the given delimiters. The buf pointer will point past delimiter, or be set to nullptr if there is nothing there. Removes excess white space.

This function should be safe, and dest will contain "\0" and buf == nullptr on failure. We always fail gently.

Due to the way the scanning is performed, looking for a space will give you the first word even if it comes before multiple spaces.

Returns delimiter found.

Pass in nullptr for dest and -1 for size to just skip ahead. Note that if nothing is found, dest will contain the whole string, minus leading and trailing whitespace. You can scan for "" to conveniently grab the remainder of a string.

Definition at line 1923 of file shared.c.

Referenced by sg_load_map_altitude(), sg_load_map_owner(), sg_load_map_owner(), sg_load_map_worked(), sg_load_map_worked(), sg_load_player_vision(), and sg_load_player_vision().

◆ setup_langname()

const char * setup_langname ( void  )

Language environmental variable (with emulation).

Definition at line 1281 of file shared.c.

Referenced by init_nls(), and theme_read_toplevel().

◆ skip_leading_spaces()

char * skip_leading_spaces ( char s)

◆ skip_to_basename()

char * skip_to_basename ( char filepath)

Return a pointer to the start of the file basename in filepath. If the string contains no dir separator, it is returned itself.

Definition at line 1753 of file shared.c.

Referenced by scenario_list_callback().

◆ str_to_float()

bool str_to_float ( const char str,
float pfloat 
)

Convert 'str' to its float representation if possible. 'pfloat' can be nullptr, then it will only test 'str' only contains a floating point number.

Definition at line 579 of file shared.c.

Referenced by entry_from_token().

◆ str_to_int()

bool str_to_int ( const char str,
int pint 
)

◆ str_to_uint()

bool str_to_uint ( const char str,
unsigned int pint 
)

Convert 'str' to its unsigned int representation if possible. 'pint' can be nullptr, then it will only test 'str' only contains an unsigned integer number.

Definition at line 547 of file shared.c.

Referenced by log_parse_level_str(), and parse_options().

◆ switch_lang()

void switch_lang ( const char lang)

Switch to specified LANG

Definition at line 1434 of file shared.c.

◆ user_home_dir()

char * user_home_dir ( void  )

Returns string which gives users home dir, as specified by $HOME. Gets value once, and then caches result. If $HOME is not set, give a log message and returns nullptr. Note the caller should not mess with the returned string.

Definition at line 627 of file shared.c.

Referenced by expand_dir(), get_gui_specific_themes_directories(), interpret_tilde(), and interpret_tilde_alloc().

◆ user_username()

char * user_username ( char buf,
size_t  bufsz 
)

Returns string which gives user's username, as specified by $USER or as given in password file for this user's uid, or a made up name if we can't get either of the above. Gets value once, and then caches result. Note the caller should not mess with returned string.

Definition at line 704 of file shared.c.

Referenced by client_main().

◆ wildcard_fit_string()

bool wildcard_fit_string ( const char pattern,
const char test 
)

Returns TRUE if test fit the pattern. The pattern can contain special characters: '*': to specify a substitute for any zero or more characters. '?': to specify a substitute for any one character. '[...]': to specify a range of characters: '!': at the begenning of the range means that the matching result will be inverted 'A-Z': means any character between 'A' and 'Z'. 'agr': means 'a', 'g' or 'r'.

Definition at line 2156 of file shared.c.

Referenced by conn_pattern_match(), and wildcard_asterisk_fit().