18 #include <QFileInfoList>
20 #include <QStringList>
27 #define MAX_LEN_ADDR 256
28 #define MAX_LEN_PATH 4095
32 #define FC_INFINITY (1000 * 1000 * 1000)
34 #ifndef FREECIV_TESTMATIC
37 #define BAD_HEURISTIC_INIT(_ini_val_) = _ini_val_
39 #define BAD_HEURISTIC_INIT(_ini_val_)
43 #define BOOL_TO_TRISTATE(tri) ((tri) ? TRI_YES : TRI_NO)
48 #define MAX(x, y) (((x) > (y)) ? (x) : (y))
49 #define MIN(x, y) (((x) < (y)) ? (x) : (y))
51 #define CLIP(lower, current, upper) \
52 ((current) < (lower) ? (lower) : (current) > (upper) ? (upper) : (current))
55 #define ABS(x) (((x) >= 0) ? (x) : -(x))
59 #define FC_WRAP(value, range) \
60 ((value) < 0 ? ((value) % (range) != 0 ? (value) % (range) + (range) : 0) \
61 : ((value) >= (range) ? (value) % (range) : (value)))
63 #define BOOL_VAL(x) ((x) != 0)
64 #define XOR(p, q) (BOOL_VAL(p) != BOOL_VAL(q))
65 #define EQ(p, q) (BOOL_VAL(p) == BOOL_VAL(q))
71 #define DIVIDE(n, d) ((n) / (d) - (((n) < 0 && (n) % (d) < 0) ? 1 : 0))
73 #define MAX_UINT32 0xFFFFFFFF
74 #define MAX_UINT16 0xFFFF
75 #define MAX_UINT8 0xFF
79 #define ARRAY_SIZE(x) (*(&(x) + 1) - (x))
80 #define ADD_TO_POINTER(p, n) ((void *) ((char *) (p) + (n)))
82 #define FC_MEMBER(type, member) (((type *) nullptr)->member)
83 #define FC_MEMBER_OFFSETOF(type, member) ((size_t) &FC_MEMBER(type, member))
84 #define FC_MEMBER_SIZEOF(type, member) sizeof(FC_MEMBER(type, member))
85 #define FC_MEMBER_ARRAY_SIZE(type, member) \
86 ARRAY_SIZE(FC_MEMBER(type, member))
88 #define FC_INT_TO_PTR(i) ((void *) (intptr_t)(i))
89 #define FC_PTR_TO_INT(p) ((int) (intptr_t)(p))
90 #define FC_UINT_TO_PTR(u) ((void *) (intptr_t)(u))
91 #define FC_PTR_TO_UINT(p) ((unsigned int) (intptr_t)(p))
92 #define FC_SIZE_TO_PTR(s) ((void *) (intptr_t)(s))
93 #define FC_PTR_TO_SIZE(p) ((size_t)(intptr_t)(p))
99 #define INITIALIZE_ARRAY(array, size, value) \
103 for (_ini_index = 0; _ini_index < (size); _ini_index++) { \
104 (array)[_ini_index] = (value); \
108 #define PARENT_DIR_OPERATOR ".."
110 const char *
big_int_to_text(
unsigned int mantissa,
unsigned int exponent);
127 #define sz_loud_strlcpy(buffer, str, errmsg) \
128 loud_strlcpy(buffer, str, sizeof(buffer), errmsg)
141 const QString &pattern,
bool nodups);
142 QString
fileinfoname(
const QStringList &dirs,
const QString &filename);
165 typedef const char *(*m_pre_accessor_fn_t)(int);
174 size_t n_names,
size_t max_len_name,
179 size_t n_names,
size_t max_len_name,
182 int *ind_result,
int *matches,
183 int max_matches,
int *pnum_matches);
190 bool make_dir(
const QString &pathname);
192 char scanin(
char **buf,
char *delimiters,
char *dest,
int size);
204 const struct cf_sequence *sequences,
size_t sequences_num)
258 sequence.str_value = value;
271 sequence.letter =
'\0';
272 sequence.bool_value =
false;
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,...
int(* m_pre_strncmp_fn_t)(const char *, const char *, size_t n)
char * skip_leading_spaces(char *s)
Returns 's' incremented to first non-space character.
enum fc_tristate fc_tristate_and(enum fc_tristate one, enum fc_tristate two)
An AND function for fc_tristate.
size_t() m_strlen_fn_t(const char *str)
void dont_run_as_root(const char *argv0, const char *fallback)
If we have root privileges, die with an error.
bool wildcard_fit_string(const char *pattern, const char *test)
Returns TRUE if test fit the pattern.
bool is_safe_filename(const QString &name)
Check if the name is safe security-wise.
const QStringList & get_data_dirs()
Returns a list of data directory paths, in the order in which they should be searched.
bool check_strlen(const char *str, size_t len, const char *errmsg)
Check the length of the given string.
const char * m_pre_description(enum m_pre_result result)
Return a description string of the result.
char * setup_langname()
Language environmental variable (with emulation).
void remove_trailing_spaces(char *s)
Terminates string pointed to by 's' to remove traling spaces; Note 's' must point to writeable memory...
const char * int_to_text(unsigned int number)
Return a prettily formatted string containing the given number.
bool str_to_int(const char *str, int *pint)
Convert 'str' to it's int reprentation if possible.
int static void cf_int_seq(char letter, int value, struct cf_sequence *out)
static struct cf_sequence cf_str_seq(char letter, const char *value)
const QStringList & get_save_dirs()
Returns a list of save directory paths, in the order in which they should be searched.
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 accor...
QString interpret_tilde(const QString &filename)
Interpret ~ in filename as home dir.
void free_nls()
Free memory allocated by Native Language Support.
char scanin(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.
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),...
void init_nls()
Setup for Native Language Support, if configured to use it.
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.
const char *(* m_pre_accessor_fn_t)(int)
char * get_multicast_group(bool ipv6_preferred)
Returns string which gives the multicast group IP address for finding servers on the LAN,...
bool is_base64url(const char *s)
Check for valid base64url.
void free_multicast_group()
Free multicast group resources.
QString fileinfoname(const QStringList &dirs, const QString &filename)
Returns a filename to access the specified file from a directory by searching all specified directori...
static struct cf_sequence cf_end()
bool formats_match(const char *format1, const char *format2)
Returns TRUE iff both formats are compatible (if 'format1' can be used instead 'format2' and reciproc...
QVector< QString > * fileinfolist(const QStringList &dirs, const char *suffix)
Returns a string vector storing the filenames in the data directories matching the given suffix.
void remove_leading_spaces(char *s)
Removes leading spaces in string pointed to by 's'.
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 th...
void array_shuffle(int *array, int n)
Randomize the elements of an array using the Fisher-Yates shuffle.
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)
See match_prefix_full().
bool is_ascii_name(const char *name)
This is used in sundry places to make sure that names of cities, players etc.
bool make_dir(const QString &pathname)
If the directory "pathname" does not exist, recursively create all directories until it does.
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
QFileInfoList find_files_in_path(const QStringList &path, const QString &pattern, bool nodups)
Search for file names matching the pattern in the provided list of directories.
void randomize_base64url_string(char *s, size_t n)
generate a random string meeting criteria such as is_ascii_name(), is_base64url(),...
QString freeciv_storage_dir()
Returns string which gives freeciv storage dir.
void remove_leading_trailing_spaces(char *s)
Removes leading and trailing spaces in string pointed to by 's'.
const QStringList & get_scenario_dirs()
Returns a list of scenario directory paths, in the order in which they should be searched.
int fc__attribute((nonnull(1, 3)))