Freeciv-3.3: /fast/freeciv/nightly/main/utility/astring.c File Reference

Freeciv-3.3

Loading...
Searching...
No Matches
Macros | Functions | Variables
astring.c File Reference
`#include "fc_prehdrs.h"`
`#include <stdarg.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include "fcintl.h"`
`#include "fcthread.h"`
`#include "log.h"`
`#include "mem.h"`
`#include "support.h"`
`#include "astring.h"`

Go to the source code of this file.

## Macros

#define | str _private_str_
#define | n _private_n_
#define | n_alloc _private_n_alloc_

## Functions

static char * | astr_buffer_get (size_t *alloc)
static char * | astr_buffer_grow (size_t request, size_t *alloc)
static void | astr_buffer_free (void)
void | astr_init (struct astring *astr)
void | astr_free (struct astring *astr)
char * | astr_to_str (struct astring *astr)
void | astr_reserve (struct astring *astr, size_t n)
void | astr_clear (struct astring *astr)
static void | astr_vadd_at (struct astring *astr, size_t at, const char *format, va_list ap)
void | astr_set (struct astring *astr, const char *format,...)
void | astr_vadd (struct astring *astr, const char *format, va_list ap)
void | astr_add (struct astring *astr, const char *format,...)
void | astr_add_line (struct astring *astr, const char *format,...)
void | astr_break_lines (struct astring *astr, size_t desired_len)
const char * | astr_build_or_list (struct astring *astr, const char *const *items, size_t number)
const char * | astr_build_and_list (struct astring *astr, const char *const *items, size_t number)
void | astr_copy (struct astring *dest, const struct astring *src)
void | fc_astr_init (void)
void | fc_astr_free (void)

## Variables

static const struct astring | zero_astr = ASTRING_INIT
static char * | astr_buffer = nullptr
static size_t | astr_buffer_alloc = 0
static fc_mutex | astr_mutex

## Macro Definition Documentation

## ◆ n

#define n _private_n_

Definition at line 77 of file astring.c.

## ◆ n_alloc

#define n_alloc _private_n_alloc_

Definition at line 78 of file astring.c.

## ◆ str

#define str _private_str_

Definition at line 76 of file astring.c.

## Function Documentation

## ◆ astr_add()

void astr_add | ( | struct astring * | astr,
|  | const char * | format,
|  |  | ...
| ) |  |

Add the text to the string.

Definition at line 271 of file astring.c.

Referenced by action_prepare_ui_name(), astr_build_and_list(), astr_build_or_list(), check_for_game_over(), client_start_server(), combat_odds_to_astr(), concat_tile_activity_text(), create_races_dialog(), fileinfoname(), format_duration(), get_nearest_city_text(), get_ping_time_text(), get_science_target_text(), get_score_text(), get_timeout_label_text(), get_token_value(), get_unit_info_label_text1(), luascript_report(), mapimg_help(), move_points_text_full(), popup_info_text(), science_dialog_text(), text_happiness_cities(), text_happiness_nationality(), unit_activity_astr(), unit_description(), and update_source_label().

## ◆ astr_add_line()

void astr_add_line | ( | struct astring * | astr,
|  | const char * | format,
|  |  | ...
| ) |  |

Add the text to the string in a new line.

Definition at line 283 of file astring.c.

Referenced by ai_level_help(), combat_odds_to_astr(), get_bulb_tooltip(), get_global_warming_tooltip(), get_government_tooltip(), get_info_label_text(), get_info_label_text_popup(), get_nuclear_winter_tooltip(), get_report_title(), get_science_goal_text(), get_spaceship_descr(), get_unit_info_label_text2(), luascript_report(), popup_info_text(), real_players_dialog_update(), science_dialog_text(), text_happiness_cities(), text_happiness_luxuries(), text_happiness_nationality(), text_happiness_units(), unit_activity_astr(), unit_description(), and unit_upkeep_astr().

## ◆ astr_break_lines()

void astr_break_lines | ( | struct astring * | astr,
|  | size_t | desired_len
| ) |  |

Replace the spaces by line breaks when the line length is over the desired one.

Definition at line 302 of file astring.c.

Referenced by popup_info_text(), text_happiness_buildings(), and text_happiness_wonders().

## ◆ astr_buffer_free()

static void astr_buffer_free | ( | void |  | ) |

static

Free the astring buffer.

Definition at line 131 of file astring.c.

Referenced by astr_buffer_get().

## ◆ astr_buffer_get()

static char * astr_buffer_get | ( | size_t * | alloc | ) |

inlinestatic

Returns the astring buffer. Create it if necessary.

Definition at line 93 of file astring.c.

Referenced by astr_vadd_at().

## ◆ astr_buffer_grow()

static char * astr_buffer_grow | ( | size_t | request,
|  | size_t * | alloc
| ) |  |

inlinestatic

Grow the astring buffer.

Definition at line 109 of file astring.c.

Referenced by astr_vadd_at().

## ◆ astr_build_and_list()

const char * astr_build_and_list | ( | struct astring * | astr,
|  | const char *const * | items,
|  | size_t | number
| ) |  |

Build a localized string with the given items. Items will be "and"-separated.

See also astr_build_or_list(), strvec_to_and_list().

Definition at line 351 of file astring.c.

Referenced by helptext_advance(), helptext_extra(), helptext_nation(), helptext_terrain(), helptext_unit(), popup_info_text(), role_units_translations(), setting_match_prefix(), strvec_to_and_list(), and update_source_label().

## ◆ astr_build_or_list()

const char * astr_build_or_list | ( | struct astring * | astr,
|  | const char *const * | items,
|  | size_t | number
| ) |  |

Build a localized string with the given items. Items will be "or"-separated.

See also astr_build_and_list(), strvec_to_or_list().

Definition at line 313 of file astring.c.

Referenced by cmdlevel_command(), explain_why_no_action_enabled(), helptext_unit(), illegal_action_msg(), req_text_insert(), role_units_translations(), and strvec_to_or_list().

## ◆ astr_clear()

void astr_clear | ( | struct astring * | astr | ) |

Sets the content to the empty string.

Definition at line 201 of file astring.c.

Referenced by action_prepare_ui_name(), action_prob_explain(), astr_copy(), astr_reserve(), concat_tile_activity_text(), fileinfoname(), format_duration(), get_bulb_tooltip(), get_global_warming_tooltip(), get_government_tooltip(), get_info_label_text(), get_info_label_text_popup(), get_nearest_city_text(), get_nuclear_winter_tooltip(), get_ping_time_text(), get_report_title(), get_science_goal_text(), get_science_target_text(), get_score_text(), get_spaceship_descr(), get_timeout_label_text(), get_token_eol(), get_token_value(), get_unit_info_label_text1(), get_unit_info_label_text2(), move_points_text_full(), popup_info_text(), read_a_line(), science_dialog_text(), text_happiness_cities(), text_happiness_luxuries(), text_happiness_nationality(), text_happiness_units(), and unit_description().

## ◆ astr_copy()

void astr_copy | ( | struct astring * | dest,
|  | const struct astring * | src
| ) |  |

Copy one astring in another.

Definition at line 386 of file astring.c.

## ◆ astr_free()

void astr_free | ( | struct astring * | astr | ) |

Free the memory associated with astr, and return astr to same state as after astr_init().

Definition at line 148 of file astring.c.

Referenced by action_prepare_ui_name(), actions_free(), ai_level_help(), check_for_game_over(), client_start_server(), cmdlevel_command(), create_advances_list(), create_improvements_list(), create_present_supported_units_widget_list(), create_races_dialog(), do_tech_parasite_effects(), effect_list_sanity_cb(), enabler_first_self_contradiction(), enabler_tile_tgt_local_diplrel_implies_claimed(), explain_why_no_action_enabled(), free_fileinfo_data(), get_bulb_tooltip(), get_science_goal_text(), get_unit_info_label_text2(), helptext_advance(), helptext_extra(), helptext_government(), helptext_nation(), helptext_terrain(), helptext_unit(), illegal_action_msg(), inf_close_partial(), insert_allows_single(), luascript_report(), mapimg_help(), notify_illegal_armistice_units(), units_select::paint(), popup_action_selection(), popup_advanced_terrain_dialog(), popup_info_text(), popup_sabotage_dialog(), popup_sabotage_dialog(), real_players_dialog_update(), redraw_unit_info_label(), req_text_insert(), req_vec_change_translation(), req_vec_get_first_contradiction(), req_vec_get_first_missing_univ(), req_vec_get_first_redundant_req(), request_unit_goto(), sanity_check_ruleset_data(), save_action_auto_uflag_block(), science_dialog_text(), secfile_from_input_file(), setting_bitwise_to_str(), setting_match_prefix(), spy_steal_popup_shared(), spy_steal_shared(), text_happiness_buildings(), text_happiness_wonders(), unit_select_dialog_popup(), and update_source_label().

## ◆ astr_init()

void astr_init | ( | struct astring * | astr | ) |

Initialize the struct.

Definition at line 139 of file astring.c.

Referenced by check_for_game_over(), do_tech_parasite_effects(), helptext_nation(), init_zeros(), mapimg_help(), req_to_fstring(), secfile_from_input_file(), and update_source_label().

## ◆ astr_reserve()

void astr_reserve | ( | struct astring * | astr,
|  | size_t | n
| ) |  |

Check that astr has enough size to hold n, and realloc to a bigger size if necessary. Here n must be big enough to include the trailing ascii-null if required. The requested n is stored in astr->n. The actual amount allocated may be larger than n, and is stored in astr->n_alloc.

Definition at line 179 of file astring.c.

Referenced by astr_build_and_list(), astr_build_or_list(), astr_clear(), astr_vadd_at(), get_token_value(), and read_a_line().

## ◆ astr_set()

void astr_set | ( | struct astring * | astr,
|  | const char * | format,
|  |  | ...
| ) |  |

Set the text to the string.

Definition at line 251 of file astring.c.

Referenced by action_prepare_ui_name(), action_prob_explain(), action_prob_to_text(), astr_build_and_list(), astr_build_or_list(), astr_copy(), create_advances_list(), create_improvements_list(), create_races_dialog(), delegate_player_str(), fileinfoname(), get_act_sel_action_custom_text(), get_airlift_text(), get_bulb_tooltip(), get_science_goal_text(), get_tile_output_text(), get_token_entry_name(), get_token_eol(), get_token_section_name(), get_token_value(), get_token_white_char(), helptext_government(), helptext_nation(), mapimg_help(), notify_illegal_armistice_units(), players_vision_callback(), players_vision_callback(), players_war_callback(), players_war_callback(), popup_action_selection(), popup_sabotage_dialog(), popup_sabotage_dialog(), req_to_fstring(), role_units_translations(), science_dialog_text(), secfile_from_input_file(), spy_steal_popup_shared(), spy_steal_shared(), ssetv_human_readable(), text_happiness_buildings(), text_happiness_wonders(), and update_source_label().

## ◆ astr_to_str()

char * astr_to_str | ( | struct astring * | astr | ) |

Return the raw string to the caller, and return astr to same state as after astr_init(). Freeing the string's storage becomes the caller's responsibility.

Definition at line 163 of file astring.c.

Referenced by ai_level_help(), fc__attribute(), fc__attribute(), players_vision_callback(), players_vision_callback(), players_war_callback(), and players_war_callback().

## ◆ astr_vadd()

void astr_vadd | ( | struct astring * | astr,
|  | const char * | format,
|  | va_list | ap
| ) |  |

Add the text to the string (varargs version).

Definition at line 263 of file astring.c.

Referenced by fc__attribute(), and fc__attribute().

## ◆ astr_vadd_at()

static void astr_vadd_at | ( | struct astring * | astr,
|  | size_t | at,
|  | const char * | format,
|  | va_list | ap
| ) |  |

inlinestatic

Helper: add the text to the specified place in the string.

Definition at line 214 of file astring.c.

Referenced by astr_add(), astr_add_line(), astr_set(), and astr_vadd().

## ◆ fc_astr_free()

void fc_astr_free | ( | void |  | ) |

Free astr handling API resources

Definition at line 406 of file astring.c.

Referenced by libfreeciv_free().

## ◆ fc_astr_init()

void fc_astr_init | ( | void |  | ) |

Initialize astr API

Definition at line 398 of file astring.c.

Referenced by libfreeciv_init().

## Variable Documentation

## ◆ astr_buffer

char* astr_buffer = nullptr

static

Definition at line 81 of file astring.c.

Referenced by astr_buffer_free(), astr_buffer_get(), and astr_buffer_grow().

## ◆ astr_buffer_alloc

size_t astr_buffer_alloc = 0

static

Definition at line 82 of file astring.c.

Referenced by astr_buffer_get(), and astr_buffer_grow().

## ◆ astr_mutex

fc_mutex astr_mutex

static

Definition at line 84 of file astring.c.

Referenced by astr_vadd_at(), fc_astr_free(), and fc_astr_init().

## ◆ zero_astr

const struct astring zero_astr = ASTRING_INIT

static

Definition at line 80 of file astring.c.

Referenced by astr_free(), astr_init(), and astr_to_str().