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 charastr_buffer_get (size_t *alloc)
 
static charastr_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)
 
charastr_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 charastr_build_or_list (struct astring *astr, const char *const *items, size_t number)
 
const charastr_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 charastr_buffer = nullptr
 
static size_t astr_buffer_alloc = 0
 
static fc_mutex astr_mutex
 

Macro Definition Documentation

◆ 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,
  ... 
)

◆ astr_add_line()

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

◆ 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 
)

◆ 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)

◆ 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)

◆ 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,
  ... 
)

◆ 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().