Crossfire Server, Branches 1.12
R18729
|
#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) |
sstring | add_string (const char *str) |
int | buf_overflow (const char *buf1, const char *buf2, size_t bufsize) |
sstring | find_string (const char *str) |
void | free_string (sstring str) |
static unsigned long | hashstr (const char *str) |
void | init_hash_table (void) |
static shared_string * | new_shared_string (const char *str) |
int | query_refcount (sstring str) |
void | ss_dump_statistics (char *buf, size_t size) |
char * | ss_dump_table (int what, char *buf, size_t size) |
Variables | |
static shared_string * | hash_table [TABLESIZE] |
This is a simple shared strings package with a simple interface.
Author: Kjetil T. Homme, Oslo 1992.
Definition in file shstr.c.
This will increase the refcount of the string str.
str | string which *must *have been returned from a previous add_string(). |
Definition at line 202 of file shstr.c.
Referenced by add_abilities(), adjust_sign_msg(), animate_bomb(), attack_ob_simple(), cast_bless(), cast_change_ability(), cast_curse(), cast_invisible(), cone_drop(), copy_object(), do_symptoms(), explode_bullet(), fire_bolt(), fire_bow(), fire_bullet(), fix_object(), hit_with_arrow(), identify(), infect_object(), init_skills(), move_monster(), poison_living(), receive_play_again(), set_ob_key_value_s(), set_spell_skill(), and START_TEST().
sstring add_string | ( | const char * | str | ) |
This will add 'str' to the hash table. If there's no entry for this string, a copy will be allocated, and a pointer to that is returned.
str | string to share. |
Definition at line 116 of file shstr.c.
References _shared_string::array, GATHER, hashstr(), new_shared_string(), _shared_string::next, _shared_string::previous, _shared_string::refcount, _shared_string::string, TOPBIT, and _shared_string::u.
Referenced by add_author(), add_book_to_list(), add_god_to_list(), add_to_racelist(), adjust_sign_msg(), alchemy_failure_effect(), animate_weapon(), become_follower(), cast_bless(), cast_create_town_portal(), cast_word_of_recall(), cctk_set_object_strings(), cfapi_system_add_string(), change_abil(), change_book(), change_treasure(), check_output_buffers(), command_follow(), command_goto(), command_reset(), command_summon(), command_teleport(), confuse_living(), create_singularity(), determine_god(), do_symptoms(), do_throw(), enter_player_savebed(), enter_random_map(), find_archetype_by_object_name(), find_object_name(), find_or_create_connection_for_map(), fire_bow(), fix_container_multipart(), fix_generated_item(), fix_multipart_object(), fix_stopped_arrow(), get_jail_exit(), get_player(), give_artifact_abilities(), god_enchants_weapon(), grant_immunity(), init_anim(), init_artifacts(), init_book_archive(), init_formulae(), init_globals(), init_msgfile(), init_races(), init_skills(), key_change_class(), keyplace(), kill_player(), load_materials(), load_treasure(), load_treasures(), local_check_loaded_object(), lock_and_hide_doors(), main(), make_formula_book(), move_marker(), new_text_name(), place_chest(), place_exits(), place_fountain_with_specials(), place_special_exit(), receive_play_again(), set_materialname(), set_ob_key_value(), set_ob_key_value_s(), START_TEST(), stringbuffer_finish_shared(), summon_golem(), tailor_god_spell(), tailor_readable_ob(), write_mark(), write_note(), and write_rune().
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 393 of file shstr.c.
Referenced by book_overflow(), init_msgfile(), and START_TEST().
sstring find_string | ( | const char * | str | ) |
Searches a string in the shared strings.
str | string to search for. |
Definition at line 228 of file shstr.c.
References GATHER, hashstr(), _shared_string::next, and _shared_string::string.
Referenced by cfapi_system_find_string(), find_treasurelist(), get_ob_key_value(), set_ob_key_value(), and START_TEST().
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 272 of file shstr.c.
References _shared_string::array, GATHER, _shared_string::next, _shared_string::previous, _shared_string::refcount, SS, TOPBIT, and _shared_string::u.
Referenced by add_abilities(), adjust_sign_msg(), alchemy_failure_effect(), animate_bomb(), animate_weapon(), attack_ob_simple(), become_follower(), cast_bless(), cast_change_ability(), cast_create_town_portal(), cast_curse(), cfapi_system_remove_string(), change_abil(), change_book(), change_treasure(), check_output_buffers(), cone_drop(), confuse_living(), copy_object(), do_symptoms(), do_throw(), enter_player_savebed(), find_archetype_by_object_name(), find_object_name(), fire_bow(), fix_container_multipart(), fix_multipart_object(), fix_object(), flush_output_element(), free_all_anim(), free_all_god(), free_all_readable(), free_all_recipes(), free_all_treasures(), free_arch(), free_artifact(), free_races(), give_artifact_abilities(), hit_with_arrow(), identify(), infect_object(), init_races(), key_change_class(), keyplace(), kill_player(), local_check_loaded_object(), make_formula_book(), move_monster(), new_text_name(), poison_living(), set_ob_key_value(), START_TEST(), summon_golem(), tailor_god_spell(), tailor_readable_ob(), and write_note().
|
static |
Hashing-function used by the shared string library.
str | string to hash. |
Definition at line 62 of file shstr.c.
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 47 of file shstr.c.
References hash_table, and TABLESIZE.
Referenced by cctk_init_std_archetypes(), init_library(), and setup().
|
static |
Allocates and initialises a new shared_string structure, containing the string str.
str | string to store. |
Definition at line 90 of file shstr.c.
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(). |
Definition at line 216 of file shstr.c.
Referenced by START_TEST().
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 315 of file shstr.c.
References snprintf().
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 346 of file shstr.c.
References llevDebug, LOG(), _shared_string::next, _shared_string::refcount, snprintf(), 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 42 of file shstr.c.
Referenced by init_hash_table(), and init_ptr_assoc_table().