![]() |
Crossfire Server, Trunk
1.75.0
|
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <sys/types.h>
#include <limits.h>
#include <string.h>
#include <global.h>
#include <libproto.h>
#include <logger.h>
#include "shstr.h"
#include <autoconf.h>
Go to the source code of this file.
Macros | |
#define | SS_STATISTICS |
Functions | |
sstring | add_refcount (sstring str) |
Like add_string(), but the string is already a shared string. More... | |
sstring | add_string (const char *str) |
Share a string. More... | |
int | buf_overflow (const char *buf1, const char *buf2, size_t bufsize) |
We don't want to exceed the buffer size of buf1 by adding on buf2! More... | |
sstring | find_string (const char *str) |
Searches a string in the shared strings. More... | |
void | free_string (sstring str) |
This will reduce the refcount, and if it has reached 0, str will be freed. More... | |
static unsigned long | hashstr (const char *str) |
Hashing-function used by the shared string library. More... | |
void | init_hash_table (void) |
Initialises the hash-table used by the shared string library. More... | |
static shared_string * | new_shared_string (const char *str) |
Allocates and initialises a new shared_string structure, containing the string str. More... | |
int | query_refcount (sstring str) |
This will return the refcount of the string str. More... | |
void | ss_dump_statistics (char *buf, size_t size) |
A call to this function will cause the statistics to be dumped into specified buffer. More... | |
char * | ss_dump_table (int what, char *buf, size_t size) |
Dump the contents of the share string tables. More... | |
Variables | |
static shared_string * | hash_table [TABLESIZE] |
Hash table to store our string. More... | |
This is a simple shared strings package with a simple interface.
Author: Kjetil T. Homme, Oslo 1992.
To minimize memory use, Crossfire uses a shared string mechanism. This is intended to be used for strings whose contents is not expected to change during the server's life. Using shared strings saves memory and improved performance.
Those strings are used like regular const char*, but should not be changed via strcpy, snprintf or other means because it would affect all structures using the shared string. Internally, they use a counter to track at how many places they are used. When it reaches 0, string is freed.
To alter such a string, the right behaviour is:
Definition in file shstr.cpp.
Like add_string(), but the string is already a shared string.
This will increase the refcount of the string str.
str | string which *must *have been returned from a previous add_string(). |
Definition at line 224 of file shstr.cpp.
Referenced by add_abilities(), animate_bomb(), cast_bless(), cast_change_ability(), cast_curse(), cast_invisible(), cone_drop(), create_aura(), do_each_skill(), do_symptoms(), dragon_focus_type_apply(), explode_bullet(), fire_arch_from_position(), fire_bolt(), fire_bow(), fix_object(), get_or_create_quest(), get_or_create_state(), give_artifact_abilities(), hit_with_arrow(), i18n_init(), identify(), infect_object(), knowledge_get_or_create(), load_materials(), map2_add_label(), object_copy_no_speed(), object_set_value_s(), poison_living(), receive_play_again(), and set_spell_skill().
sstring add_string | ( | const char * | str | ) |
Share a string.
Looks for an existing string, and if it doesn't exist, copy and store it.
str | string to share. |
Definition at line 137 of file shstr.cpp.
References shared_string::array, GATHER, hash_table, hashstr(), new_shared_string(), shared_string::next, shared_string::previous, shared_string::refcount, shared_string::string, TOPBIT, and shared_string::u.
Referenced by account_char_add(), account_char_load(), account_char_load_from_file(), account_play_cmd(), add_author(), add_book_to_list(), add_exit_to_item(), add_force(), adjust_sign_msg(), alchemy_failure_effect(), animate_weapon(), apply_race_and_class(), asset_create(), become_follower(), cast_bless(), cast_create_town_portal(), cast_word_of_recall(), cfapi_system_add_string(), change_abil(), change_book(), change_treasure(), check_loaded_object(), check_login(), command_follow(), command_reset(), command_summon(), command_teleport(), command_unarmed_skill(), confuse_living(), create_singularity(), determine_god(), do_each_skill(), do_goto(), do_throw(), enter_player_savebed(), enter_random_map(), examine_monster(), find_or_create_connection_for_map(), fire_bow(), fix_container_multipart(), fix_generated_item(), fix_stopped_arrow(), generate_random_map(), get_jail_exit(), get_npc(), get_player(), give_artifact_abilities(), god_enchants_weapon(), grant_immunity(), i18n_init(), init_book_archive(), init_formulae(), init_globals(), key_change_class(), keyplace(), kill_player(), knowledge_add(), knowledge_read_player_data(), ArtifactLoader::load(), MessageLoader::load(), FaceLoader::load(), QuestLoader::load(), TreasureLoader::load(), load_map_header(), load_materials(), FaceLoader::loadAnimationBlock(), TreasureLoader::loadTreasure(), lock_and_hide_doors(), monster_do_talk_npc(), move_marker(), new_text_name(), object_find_by_name(), object_find_by_name_global(), object_fix_multipart(), object_set_msg(), object_set_value(), object_set_value_s(), pets_summon_golem(), place_chest(), place_exits(), place_special_exit(), player_start_repeat(), potion_type_apply(), process_map(), process_object(), quest_condition_from_string(), quest_create(), quest_read_player_data(), receive_play_again(), set_materialname(), stringbuffer_finish_shared(), tailor_god_spell(), town_portal_find_force(), while(), and write_mark().
int buf_overflow | ( | const char * | buf1, |
const char * | buf2, | ||
size_t | bufsize | ||
) |
We don't want to exceed the buffer size of buf1 by adding on buf2!
buf1 | |
buf2 | buffers we plan on concatening. Can be NULL. |
bufsize | size of buf1. Can be NULL. |
Definition at line 412 of file shstr.cpp.
Referenced by book_overflow(), and MessageLoader::load().
sstring find_string | ( | const char * | str | ) |
Searches a string in the shared strings.
str | string to search for. |
Definition at line 250 of file shstr.cpp.
References GATHER, hash_table, hashstr(), shared_string::next, and shared_string::string.
Referenced by cfapi_system_find_string(), find_artifact(), Archetypes::findByObjectName(), i18n(), object_get_value(), object_set_value(), and skill_throw().
void free_string | ( | sstring | str | ) |
This will reduce the refcount, and if it has reached 0, str will be freed.
str | string to release, which *must *have been returned from a previous add_string(). |
Definition at line 294 of file shstr.cpp.
References shared_string::array, GATHER, shared_string::next, shared_string::previous, shared_string::refcount, SS, TOPBIT, and shared_string::u.
Referenced by account_char_add(), account_char_free(), account_char_remove(), add_abilities(), adjust_sign_msg(), alchemy_failure_effect(), animate_bomb(), animate_weapon(), apply_race_and_class(), asset_destroy(), become_follower(), cast_bless(), cast_change_ability(), cast_curse(), cfapi_system_remove_string(), change_abil(), change_book(), change_treasure(), check_loaded_object(), command_unarmed_skill(), cone_drop(), confuse_living(), create_aura(), do_symptoms(), do_throw(), dragon_focus_type_apply(), enter_player_savebed(), examine_monster(), fire_bow(), fix_container_multipart(), fix_object(), free_all_readable(), free_all_recipes(), free_arch(), free_artifact(), free_knowledge_items(), free_knowledge_player(), free_quest(), free_state(), give_artifact_abilities(), hit_with_arrow(), i18n_free(), i18n_init(), identify(), infect_object(), key_change_class(), keyplace(), knowledge_god_add(), FaceLoader::load(), TreasureLoader::loadTreasure(), make_formula_book(), map2_add_label(), mon_info_msg(), monster_communicate(), new_text_name(), object_copy_no_speed(), object_find_by_name(), object_find_by_name_global(), object_fix_multipart(), object_set_msg(), object_set_value(), pets_summon_golem(), player_cancel_repeat(), player_start_repeat(), poison_living(), potion_type_apply(), process_object(), quest_clear(), quest_destroy_condition(), AllAnimations::replace(), tailor_god_spell(), town_portal_find_force(), and treasure_free().
|
static |
Hashing-function used by the shared string library.
str | string to hash. |
Definition at line 84 of file shstr.cpp.
References GATHER, MAXSTRING, and TABLESIZE.
Referenced by add_string(), and find_string().
void init_hash_table | ( | void | ) |
Initialises the hash-table used by the shared string library.
Definition at line 69 of file shstr.cpp.
References hash_table, and TABLESIZE.
Referenced by init_library().
|
static |
Allocates and initialises a new shared_string structure, containing the string str.
str | string to store. |
Definition at line 112 of file shstr.cpp.
References fatal(), shared_string::next, OUT_OF_MEMORY, PADDING, shared_string::previous, shared_string::refcount, shared_string::string, and shared_string::u.
Referenced by add_string().
int query_refcount | ( | sstring | str | ) |
This will return the refcount of the string str.
str | string which *must *have been returned from a previous add_string(). |
void ss_dump_statistics | ( | char * | buf, |
size_t | size | ||
) |
A call to this function will cause the statistics to be dumped into specified buffer.
The routines will gather statistics if SS_STATISTICS is defined.
buf | buffer which will contain dumped information. |
size | buf's size. |
Definition at line 337 of file shstr.cpp.
References buf, and is_valid_types_gen::line.
Referenced by command_strings().
char* ss_dump_table | ( | int | what, |
char * | buf, | ||
size_t | size | ||
) |
Dump the contents of the share string tables.
what | combination of flags:
|
buf | buffer that will contain total information if (what & SS_DUMP_TABLE). Left untouched else. |
size | buffer's size |
Definition at line 368 of file shstr.cpp.
References buf, hash_table, llevDebug, LOG(), shared_string::next, shared_string::refcount, SS_DUMP_TABLE, SS_DUMP_TOTALS, shared_string::string, TABLESIZE, and TOPBIT.
Referenced by command_ssdumptable(), and command_strings().
|
static |
Hash table to store our string.
Definition at line 64 of file shstr.cpp.
Referenced by add_string(), find_string(), init_hash_table(), and ss_dump_table().