Angband
Macros | Functions | Variables
z-util.h File Reference

Low-level string handling and other utilities. More...

#include "h-basic.h"

Go to the source code of this file.

Macros

#define PLURAL(n)   ((n) == 1 ? "" : "s")
 

Available Functions


#define VERB_AGREEMENT(count, singular, plural)   (((count) == 1) ? (singular) : (plural))
 Return the verb form matching the given count.
#define streq(s, t)   (!strcmp(s, t))

Functions

int my_stricmp (const char *s1, const char *s2)
 Case insensitive comparison between two strings.
int my_strnicmp (const char *a, const char *b, int n)
 Case insensitive comparison between two strings, up to n characters long.
char * my_stristr (const char *string, const char *pattern)
 Case-insensitive strstr.
size_t my_strcpy (char *buf, const char *src, size_t bufsize)
 Copy up to 'bufsize'-1 characters from 'src' to 'buf' and NULL-terminate the result.
size_t my_strcat (char *buf, const char *src, size_t bufsize)
 Try to append a string to an existing NULL-terminated string, never writing more characters into the buffer than indicated by 'bufsize', and NULL-terminating the buffer.
void my_strcap (char *buf)
 Capitalise string 'buf'.
bool streq (const char *s, const char *t)
 Test equality, prefix, suffix.
bool prefix (const char *s, const char *t)
 Determine if string "t" is a prefix of string "s".
bool prefix_i (const char *s, const char *t)
 Determine if string "t" is a prefix of string "s" - case insensitive.
bool suffix (const char *s, const char *t)
 Determine if string "t" is a suffix of string "s".
void strskip (char *s, const char c)
 Skip occurrences of a characters.
void strescape (char *s, const char c)
 Rewrite string s in-place removing escape character c note that pairs of c will leave one instance of c in out.
bool contains_only_spaces (const char *s)
 Determines if a string is "empty".
bool is_a_vowel (int ch)
 Check if a char is a vowel.
size_t text_mbstowcs (wchar_t *dest, const char *src, int n)
 Allow override of the multi-byte to wide char conversion.
void plog (const char *str)
 Print an error message.
void quit (const char *str)
 Exit, with optional message.
void sort (void *array, size_t nmemb, size_t smemb, int(*comp)(const void *a, const void *b))
 Sorting functions.
int mean (int *nums, int size)
 Mathematical functions.
int variance (int *nums, int size)
 Variance of the first 'size' entries of the array 'nums'.

Variables

char * argv0
 

Available variables


size_t(* text_mbcs_hook )(wchar_t *dest, const char *src, int n)
 Aux functions.
void(* plog_aux )(const char *)
 Redefinable "plog" action.
void(* quit_aux )(const char *)
 Redefinable "quit" action.

Detailed Description

Low-level string handling and other utilities.

Copyright (c) 1997-2005 Ben Harrison, Robert Ruehlmann.

This work is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation, version 2, or

b) the "Angband licence": This software may be copied and distributed for educational, research, and not for profit purposes provided that this copyright and statement are included in all such copies. Other copyrights may also apply.

Macro Definition Documentation

#define PLURAL (   n)    ((n) == 1 ? "" : "s")


Available Functions

Return "s" (or not) depending on whether n is singular.

Referenced by lore_append_drop(), lore_append_exp(), monster_list_format_section(), obj_desc_charges(), object_list_format_section(), and spell_learn().

#define streq (   s,
 
)    (!strcmp(s, t))
#define VERB_AGREEMENT (   count,
  singular,
  plural 
)    (((count) == 1) ? (singular) : (plural))

Function Documentation

bool contains_only_spaces ( const char *  s)

Determines if a string is "empty".

References FALSE, and TRUE.

Referenced by show_file().

bool is_a_vowel ( int  ch)
int mean ( int nums,
int  size 
)

Mathematical functions.

References i, and size.

Referenced by store_base_power(), and variance().

void my_strcap ( char *  buf)
size_t my_strcat ( char *  buf,
const char *  src,
size_t  bufsize 
)

Try to append a string to an existing NULL-terminated string, never writing more characters into the buffer than indicated by 'bufsize', and NULL-terminating the buffer.

The 'buf' and 'src' strings may not overlap.

my_strcat() returns strlen(buf) + strlen(src). This makes checking for truncation easy. Example: if (my_strcat(buf, src, sizeof(buf)) >= sizeof(buf)) ...;

This function should be equivalent to the strlcat() function in BSD.

Try to append a string to an existing NULL-terminated string, never writing more characters into the buffer than indicated by 'bufsize', and NULL-terminating the buffer.

It never writes more characters into the buffer than indicated by 'bufsize' and NUL-terminates the buffer. The 'buf' and 'src' strings may not overlap.

my_strcat() returns strlen(buf) + strlen(src). This makes checking for truncation easy. Example: if (my_strcat(buf, src, sizeof(buf)) >= sizeof(buf)) ...;

This function should be equivalent to the strlcat() function in BSD.

References my_strcpy().

Referenced by describe_origin(), display_object(), display_scores_aux(), dump_history(), ego_item_name(), flush_monster_messages(), get_mon_name(), grab_index_and_int(), history_display(), ignore_drop(), init_names(), init_stuff(), int_to_roman(), look_mon_desc(), lore_append_exp(), monster_desc(), monster_list_format_section(), object_list_format_name(), player_pickup_gold(), plural_aux(), set_file_paths(), show_equip(), textui_get_item(), and write_flags().

size_t my_strcpy ( char *  buf,
const char *  src,
size_t  bufsize 
)

Copy up to 'bufsize'-1 characters from 'src' to 'buf' and NULL-terminate the result.

The 'buf' and 'src' strings may not overlap.

Returns: strlen(src). This makes checking for truncation easy. Example: if (my_strcpy(buf, src, sizeof(buf)) >= sizeof(buf)) ...;

This function should be equivalent to the strlcpy() function in BSD.

Copy up to 'bufsize'-1 characters from 'src' to 'buf' and NULL-terminate the result.

The 'buf' and 'src' strings may not overlap.

my_strcpy() returns strlen(src). This makes checking for truncation easy. Example: if (my_strcpy(buf, src, sizeof(buf)) >= sizeof(buf)) ...;

This function should be equivalent to the strlcpy() function in BSD.

References void().

Referenced by build_score(), cmd_get_string(), cmd_set_arg(), de_armour(), death_knowledge(), describe_origin(), dir_create(), display_message(), do_cmd_change_name(), do_cmd_choose_name(), do_cmd_note(), do_cmd_pref(), do_cmd_query_symbol(), do_cmd_suicide(), do_cmd_wiz_effect(), ego_item_name(), flavor_init(), flush_monster_messages(), get_chamber_monsters(), get_character_name(), get_file_backup(), get_file_text(), get_history_command(), get_mon_name(), grab_base_and_int(), grab_index_and_int(), grab_int_value(), grab_rand_value(), handle_signal_abort(), handle_signal_simple(), history_add_full(), ignore_drop(), improve_attack_modifier(), init_stuff(), look_mon_desc(), main(), make_ranged_shot(), make_ranged_throw(), monster_desc(), my_dread(), my_strcat(), next_blockheader(), object_kind_name(), parse_random(), parser_parse(), parser_setstate(), path_parse(), player_outfit(), player_pickup_gold(), player_safe_name(), process_character_pref_files(), prt_depth(), prt_state(), py_attack_real(), ranged_helper(), rd_player(), save_game(), savefile_get_description(), set_file_paths(), show_equip(), show_file(), show_inven(), show_obj_list(), show_quiver(), string_append(), string_make(), take_hit(), text_out_to_file(), try_save(), user_name(), vstrnfmt(), wiz_cheat_death(), write_dummy_object_record(), and write_flags().

int my_stricmp ( const char *  s1,
const char *  s2 
)
char* my_stristr ( const char *  string,
const char *  pattern 
)

Case-insensitive strstr.

Case-insensitive strstr.

In the public domain; found at: http://c.snippets.org/code/stristr.c

References start.

Referenced by do_cmd_messages(), lookup_artifact_name(), lookup_monster(), and lookup_trap().

int my_strnicmp ( const char *  a,
const char *  b,
int  n 
)

Case insensitive comparison between two strings, up to n characters long.

References s1, s2, z1, and z2.

void plog ( const char *  str)

Print an error message.

References argv0, and plog_aux.

Referenced by plog_fmt(), quit(), and textui_init().

bool prefix ( const char *  s,
const char *  t 
)

Determine if string "t" is a prefix of string "s".

References FALSE, and TRUE.

Referenced by ego_item_name(), grab_element_flag(), init_names(), object_desc(), path_build(), show_file(), and strip_ego_name().

bool prefix_i ( const char *  s,
const char *  t 
)

Determine if string "t" is a prefix of string "s" - case insensitive.

References FALSE, and TRUE.

void quit ( const char *  str)

Exit, with optional message.

Exit, with optional message.

If 'str' is NULL, do "exit(EXIT_SUCCESS)". Otherwise, plog() 'str' and exit with an error code of -1. But always use 'quit_aux', if set, before anything else.

References plog(), and quit_aux.

Referenced by choose_profile(), get_confirm_command(), get_history_command(), handle_signal_abort(), handle_signal_simple(), init_race_allocs(), main(), mem_alloc(), mem_realloc(), menu_question(), parse_file(), point_based_command(), quit_fmt(), roller_command(), run_template_parser(), safe_setuid_drop(), safe_setuid_grab(), start_game(), store_init(), textui_birth_quickstart(), and textui_init().

void sort ( void array,
size_t  nmemb,
size_t  smemb,
int(*)(const void *a, const void *b)  comp 
)

Sorting functions.

bool streq ( const char *  a,
const char *  b 
)

Test equality, prefix, suffix.

void strescape ( char *  s,
const char  c 
)

Rewrite string s in-place removing escape character c note that pairs of c will leave one instance of c in out.

References FALSE, and TRUE.

Referenced by show_file().

void strskip ( char *  s,
const char  c 
)

Skip occurrences of a characters.

Referenced by show_file().

bool suffix ( const char *  s,
const char *  t 
)

Determine if string "t" is a suffix of string "s".

References FALSE.

Referenced by grab_element_flag(), init_stuff(), player_safe_name(), and set_file_paths().

size_t text_mbstowcs ( wchar_t *  dest,
const char *  src,
int  n 
)
int variance ( int nums,
int  size 
)

Variance of the first 'size' entries of the array 'nums'.

References i, mean(), and size.

Referenced by store_base_power().

Variable Documentation

char* argv0


Available variables

The name of the program.

Referenced by main(), and plog().

void(* plog_aux)(const char *)

Redefinable "plog" action.

Referenced by main(), plog(), and setup_tests().

void(* quit_aux)(const char *)

Redefinable "quit" action.

Referenced by main(), and quit().

size_t(* text_mbcs_hook)(wchar_t *dest, const char *src, int n)

Aux functions.