mirror of
https://github.com/tbamud/tbamud.git
synced 2026-01-22 00:46:09 +01:00
Addressed several compiler warnings.
This commit is contained in:
parent
08374524d0
commit
fc4c64c782
61 changed files with 163 additions and 395 deletions
105
src/utils.c
105
src/utils.c
|
|
@ -26,8 +26,7 @@
|
|||
|
||||
/** Aportable random number function.
|
||||
* @param from The lower bounds of the random number.
|
||||
* @param to The upper bounds of the random number.
|
||||
* @retval int The resulting randomly generated number. */
|
||||
* @param to The upper bounds of the random number. */
|
||||
int rand_number(int from, int to)
|
||||
{
|
||||
/* error checking in case people call this incorrectly */
|
||||
|
|
@ -50,8 +49,7 @@ int rand_number(int from, int to)
|
|||
/** Simulates a single dice roll from one to many of a certain sized die.
|
||||
* @param num The number of dice to roll.
|
||||
* @param size The number of sides each die has, and hence the number range
|
||||
* of the die.
|
||||
* @retval int The sum of all the dice rolled. A random number. */
|
||||
* of the die. */
|
||||
int dice(int num, int size)
|
||||
{
|
||||
int sum = 0;
|
||||
|
|
@ -67,8 +65,7 @@ int dice(int num, int size)
|
|||
|
||||
/** Return the smaller number. Original note: Be wary of sign issues with this.
|
||||
* @param a The first number.
|
||||
* @param b The second number.
|
||||
* @retval int The smaller of the two, a or b. */
|
||||
* @param b The second number. */
|
||||
int MIN(int a, int b)
|
||||
{
|
||||
return (a < b ? a : b);
|
||||
|
|
@ -76,16 +73,14 @@ int MIN(int a, int b)
|
|||
|
||||
/** Return the larger number. Original note: Be wary of sign issues with this.
|
||||
* @param a The first number.
|
||||
* @param b The second number.
|
||||
* @retval int The larger of the two, a or b. */
|
||||
* @param b The second number. */
|
||||
int MAX(int a, int b)
|
||||
{
|
||||
return (a > b ? a : b);
|
||||
}
|
||||
|
||||
/** Used to capitalize a string. Will not change any mud specific color codes.
|
||||
* @param txt The string to capitalize.
|
||||
* @retval char* Pointer to the capitalized string. */
|
||||
* @param txt The string to capitalize. */
|
||||
char *CAP(char *txt)
|
||||
{
|
||||
char *p = txt;
|
||||
|
|
@ -132,9 +127,9 @@ char *strdup(const char *source)
|
|||
}
|
||||
#endif
|
||||
|
||||
/** Strips "\r\n" from just the end of a string. Will not remove internal
|
||||
* "\r\n" values to the string.
|
||||
* @post Replaces any "\r\n" values at the end of the string with null.
|
||||
/** Strips "\\r\\n" from just the end of a string. Will not remove internal
|
||||
* "\\r\\n" values to the string.
|
||||
* @post Replaces any "\\r\\n" values at the end of the string with null.
|
||||
* @param txt The writable string to prune. */
|
||||
void prune_crlf(char *txt)
|
||||
{
|
||||
|
|
@ -153,7 +148,7 @@ int str_cmp(const char *arg1, const char *arg2)
|
|||
int chk, i;
|
||||
|
||||
if (arg1 == NULL || arg2 == NULL) {
|
||||
log("SYSERR: str_cmp() passed a NULL pointer, %p or %p.", arg1, arg2);
|
||||
log("SYSERR: str_cmp() passed a NULL pointer, %p or %p.", (void *)arg1, (void *)arg2);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
@ -174,7 +169,7 @@ int strn_cmp(const char *arg1, const char *arg2, int n)
|
|||
int chk, i;
|
||||
|
||||
if (arg1 == NULL || arg2 == NULL) {
|
||||
log("SYSERR: strn_cmp() passed a NULL pointer, %p or %p.", arg1, arg2);
|
||||
log("SYSERR: strn_cmp() passed a NULL pointer, %p or %p.", (void *)arg1, (void *)arg2);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
@ -233,9 +228,7 @@ void basic_mud_log(const char *format, ...)
|
|||
/** Essentially the touch command. Create an empty file or update the modified
|
||||
* time of a file.
|
||||
* @param path The filepath to "touch." This filepath is relative to the /lib
|
||||
* directory relative to the root of the mud distribution.
|
||||
* @retval int 0 on a success, -1 on a failure; standard system call exit
|
||||
* values. */
|
||||
* directory relative to the root of the mud distribution. */
|
||||
int touch(const char *path)
|
||||
{
|
||||
FILE *fl;
|
||||
|
|
@ -302,12 +295,12 @@ void mudlog(int type, int level, int file, const char *str, ...)
|
|||
/** Take a bitvector and return a human readable
|
||||
* description of which bits are set in it.
|
||||
* @pre The final element in the names array must contain a one character
|
||||
* string consisting of a single newline character "\n". Caller of function is
|
||||
* string consisting of a single newline character "\\n". Caller of function is
|
||||
* responsible for creating the memory buffer for the result string.
|
||||
* @param[in] bitvector The bitvector to test for set bits.
|
||||
* @param[in] names An array of human readable strings describing each possible
|
||||
* bit. The final element in this array must be a string made of a single
|
||||
* newline character (eg "\n").
|
||||
* newline character (eg "\\n").
|
||||
* If you don't have a 'const' array for the names param, cast it as such.
|
||||
* @param[out] result Holds the names of the set bits in bitvector. The bit
|
||||
* names will be delimited by a single space.
|
||||
|
|
@ -315,8 +308,7 @@ void mudlog(int type, int level, int file, const char *str, ...)
|
|||
* Will be set to "NOBITS" if no bits are set in bitvector (ie bitvector = 0).
|
||||
* @param[in] reslen The length of the available memory in the result buffer.
|
||||
* Ideally, results will be large enough to hold the description of every bit
|
||||
* that could possibly be set in bitvector.
|
||||
* @retval size_t The length of the string copied into result. */
|
||||
* that could possibly be set in bitvector. */
|
||||
size_t sprintbit(bitvector_t bitvector, const char *names[], char *result, size_t reslen)
|
||||
{
|
||||
size_t len = 0;
|
||||
|
|
@ -345,18 +337,17 @@ size_t sprintbit(bitvector_t bitvector, const char *names[], char *result, size_
|
|||
|
||||
/** Return the human readable name of a defined type.
|
||||
* @pre The final element in the names array must contain a one character
|
||||
* string consisting of a single newline character "\n". Caller of function is
|
||||
* string consisting of a single newline character "\\n". Caller of function is
|
||||
* responsible for creating the memory buffer for the result string.
|
||||
* @param[in] type The type number to be translated.
|
||||
* @param[in] names An array of human readable strings describing each possible
|
||||
* bit. The final element in this array must be a string made of a single
|
||||
* newline character (eg "\n").
|
||||
* newline character (eg "\\n").
|
||||
* @param[out] result Holds the translated name of the type.
|
||||
* Caller of sprintbit is responsible for creating the buffer for result.
|
||||
* Will be set to "UNDEFINED" if the type is greater than the number of names
|
||||
* available.
|
||||
* @param[in] reslen The length of the available memory in the result buffer.
|
||||
* @retval size_t The length of the string copied into result. */
|
||||
* @param[in] reslen The length of the available memory in the result buffer. */
|
||||
size_t sprinttype(int type, const char *names[], char *result, size_t reslen)
|
||||
{
|
||||
int nr = 0;
|
||||
|
|
@ -372,14 +363,14 @@ size_t sprinttype(int type, const char *names[], char *result, size_t reslen)
|
|||
/** Take a bitarray and return a human readable description of which bits are
|
||||
* set in it.
|
||||
* @pre The final element in the names array must contain a one character
|
||||
* string consisting of a single newline character "\n". Caller of function is
|
||||
* string consisting of a single newline character "\\n". Caller of function is
|
||||
* responsible for creating the memory buffer for the result string large enough
|
||||
* to hold all possible bit translations. There is no error checking for
|
||||
* possible array overflow for result.
|
||||
* @param[in] bitvector The bitarray in which to test for set bits.
|
||||
* @param[in] names An array of human readable strings describing each possible
|
||||
* bit. The final element in this array must be a string made of a single
|
||||
* newline character (eg "\n").
|
||||
* newline character (eg "\\n").
|
||||
* If you don't have a 'const' array for the names param, cast it as such.
|
||||
* @param[in] maxar The number of 'bytes' in the bitarray. This number will
|
||||
* usually be pre-defined for the particular bitarray you are using.
|
||||
|
|
@ -427,10 +418,7 @@ void sprintbitarray(int bitvector[], const char *names[], int maxar, char *resul
|
|||
* @todo Recommend making this function foresightedly useful by calculating
|
||||
* real months and years, too.
|
||||
* @param t2 The later time.
|
||||
* @param t1 The earlier time.
|
||||
* @retval time_info_data The real hours and days passed between t2 and t1. Only
|
||||
* the hours and days are returned, months and years are ignored and returned
|
||||
* as -1 values. */
|
||||
* @param t1 The earlier time. */
|
||||
struct time_info_data *real_time_passed(time_t t2, time_t t1)
|
||||
{
|
||||
long secs;
|
||||
|
|
@ -452,10 +440,7 @@ struct time_info_data *real_time_passed(time_t t2, time_t t1)
|
|||
|
||||
/** Calculate the MUD time passed between two time invervals.
|
||||
* @param t2 The later time.
|
||||
* @param t1 The earlier time.
|
||||
* @retval time_info_data A pointer to the mud hours, days, months and years
|
||||
* that have passed between the two time intervals. DO NOT FREE the structure
|
||||
* pointed to by the return value. */
|
||||
* @param t1 The earlier time. */
|
||||
struct time_info_data *mud_time_passed(time_t t2, time_t t1)
|
||||
{
|
||||
long secs;
|
||||
|
|
@ -478,9 +463,7 @@ struct time_info_data *mud_time_passed(time_t t2, time_t t1)
|
|||
}
|
||||
|
||||
/** Translate the current mud time to real seconds (in type time_t).
|
||||
* @param now The current mud time to translate into a real time unit.
|
||||
* @retval time_t The real time that would have had to have passed
|
||||
* to represent the mud time represented by the now parameter. */
|
||||
* @param now The current mud time to translate into a real time unit. */
|
||||
time_t mud_time_to_secs(struct time_info_data *now)
|
||||
{
|
||||
time_t when = 0;
|
||||
|
|
@ -495,9 +478,7 @@ time_t mud_time_to_secs(struct time_info_data *now)
|
|||
/** Calculate a player's MUD age.
|
||||
* @todo The minimum starting age of 17 is hardcoded in this function. Recommend
|
||||
* changing the minimum age to a property (variable) external to this function.
|
||||
* @param ch A valid player character.
|
||||
* @retval time_info_data A pointer to the mud age in years of the player
|
||||
* character. DO NOT FREE the structure pointed to by the return value. */
|
||||
* @param ch A valid player character. */
|
||||
struct time_info_data *age(struct char_data *ch)
|
||||
{
|
||||
static struct time_info_data player_age;
|
||||
|
|
@ -513,9 +494,7 @@ struct time_info_data *age(struct char_data *ch)
|
|||
* essence, this prevents someone from following a character in a group that
|
||||
* is already being lead by the character.
|
||||
* @param ch The character trying to follow.
|
||||
* @param victim The character being followed.
|
||||
* @retval bool TRUE if ch is already leading someone in victims group, FALSE
|
||||
* if it is okay for ch to follow victim. */
|
||||
* @param victim The character being followed. */
|
||||
bool circle_follow(struct char_data *ch, struct char_data *victim)
|
||||
{
|
||||
struct char_data *k;
|
||||
|
|
@ -578,7 +557,6 @@ void stop_follower(struct char_data *ch)
|
|||
/** Finds the number of follows that are following, and charmed by, the
|
||||
* character (PC or NPC).
|
||||
* @param ch The character to check for charmed followers.
|
||||
* @retval int The number of followers that are also charmed by the character.
|
||||
*/
|
||||
int num_followers_charmed(struct char_data *ch)
|
||||
{
|
||||
|
|
@ -649,8 +627,7 @@ void add_follower(struct char_data *ch, struct char_data *leader)
|
|||
* returned in buf.
|
||||
* @param[in] fl The file to be read from.
|
||||
* @param[out] buf The next non-blank line read from the file. Buffer given must
|
||||
* be at least READ_SIZE (256) characters large.
|
||||
* @retval int The number of lines advanced in the file. */
|
||||
* be at least READ_SIZE (256) characters large. */
|
||||
int get_line(FILE *fl, char *buf)
|
||||
{
|
||||
char temp[READ_SIZE];
|
||||
|
|
@ -685,8 +662,7 @@ int get_line(FILE *fl, char *buf)
|
|||
* @param[in] mode What type of files can be created. Currently, recognized
|
||||
* modes are CRASH_FILE, ETEXT_FILE, SCRIPT_VARS_FILE and PLR_FILE.
|
||||
* @param[in] orig_name The player name to create the filepath (of type mode)
|
||||
* for.
|
||||
* @retval int 0 if filename cannot be created, 1 if it can. */
|
||||
* for. */
|
||||
int get_filename(char *filename, size_t fbufsize, int mode, const char *orig_name)
|
||||
{
|
||||
const char *prefix, *middle, *suffix;
|
||||
|
|
@ -694,7 +670,7 @@ int get_filename(char *filename, size_t fbufsize, int mode, const char *orig_nam
|
|||
|
||||
if (orig_name == NULL || *orig_name == '\0' || filename == NULL) {
|
||||
log("SYSERR: NULL pointer or empty string passed to get_filename(), %p or %p.",
|
||||
orig_name, filename);
|
||||
(const void *)orig_name, (void *)filename);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
@ -796,8 +772,7 @@ void core_dump_real(const char *who, int line)
|
|||
|
||||
/** Count the number bytes taken up by color codes in a string that will be
|
||||
* empty space once the color codes are converted and made non-printable.
|
||||
* @param string The string in which to check for color codes.
|
||||
* @retval int the number of color codes found. */
|
||||
* @param string The string in which to check for color codes. */
|
||||
int count_color_chars(char *string)
|
||||
{
|
||||
int i, len;
|
||||
|
|
@ -855,8 +830,7 @@ int count_non_protocol_chars(char * str)
|
|||
* Inside and City rooms are always lit. Outside rooms are dark at sunset and
|
||||
* night.
|
||||
* @todo Make the return value a bool.
|
||||
* @param room The real room to test for.
|
||||
* @retval int FALSE if the room is lit, TRUE if the room is dark. */
|
||||
* @param room The real room to test for. */
|
||||
int room_is_dark(room_rnum room)
|
||||
{
|
||||
if (!VALID_ROOM_RNUM(room)) {
|
||||
|
|
@ -886,8 +860,7 @@ int room_is_dark(room_rnum room)
|
|||
* down the possible choices. For more information about Levenshtein distance,
|
||||
* recommend doing an internet or wikipedia search.
|
||||
* @param s1 The input string.
|
||||
* @param s2 The string to be compared to.
|
||||
* @retval int The Levenshtein distance between s1 and s2. */
|
||||
* @param s2 The string to be compared to. */
|
||||
int levenshtein_distance(const char *s1, const char *s2)
|
||||
{
|
||||
int **d, i, j;
|
||||
|
|
@ -1049,8 +1022,6 @@ void column_list(struct char_data *ch, int num_cols, const char **list, int list
|
|||
* @param flag_list An array of flag name strings. The final element must
|
||||
* be a string made up of a single newline.
|
||||
* @param flag_name The name to search in flag_list.
|
||||
* @retval int Returns the element number in flag_list of flag_name or
|
||||
* NOFLAG (-1) if no match.
|
||||
*/
|
||||
int get_flag_by_name(const char *flag_list[], char *flag_name)
|
||||
{
|
||||
|
|
@ -1078,10 +1049,6 @@ int get_flag_by_name(const char *flag_list[], char *flag_name)
|
|||
* @param[in] bufsize The total size of the buffer.
|
||||
* @param[in] lines_to_read The number of lines to be read from the front of
|
||||
* the file.
|
||||
* @retval int The number of lines actually read from the file. Can be used
|
||||
* the compare with the number of lines requested to be read to determine if the
|
||||
* entire file was read. If lines_to_read is <= 0, no processing occurs
|
||||
* and lines_to_read is returned.
|
||||
*/
|
||||
int file_head( FILE *file, char *buf, size_t bufsize, int lines_to_read )
|
||||
{
|
||||
|
|
@ -1159,10 +1126,6 @@ int file_head( FILE *file, char *buf, size_t bufsize, int lines_to_read )
|
|||
* @param[in] bufsize The total size of the buffer.
|
||||
* @param[in] lines_to_read The number of lines to be read from the back of
|
||||
* the file.
|
||||
* @retval int The number of lines actually read from the file. Can be used
|
||||
* the compare with the number of lines requested to be read to determine if the
|
||||
* entire file was read. If lines_to_read is <= 0, no processing occurs
|
||||
* and lines_to_read is returned.
|
||||
*/
|
||||
int file_tail( FILE *file, char *buf, size_t bufsize, int lines_to_read )
|
||||
{
|
||||
|
|
@ -1244,8 +1207,6 @@ int file_tail( FILE *file, char *buf, size_t bufsize, int lines_to_read )
|
|||
* @pre file parameter must already be opened.
|
||||
* @post file will be rewound.
|
||||
* @param file The file to determine the size of.
|
||||
* @retval size_t The byte size of the file (we assume no errors will be
|
||||
* encountered in this function).
|
||||
*/
|
||||
size_t file_sizeof( FILE *file )
|
||||
{
|
||||
|
|
@ -1269,14 +1230,12 @@ size_t file_sizeof( FILE *file )
|
|||
return numbytes;
|
||||
}
|
||||
|
||||
/** Returns the number of newlines '\n' in a file, which we equate to number of
|
||||
/** Returns the number of newlines "\\n" in a file, which we equate to number of
|
||||
* lines. We assume the int type more than adequate to count the number of lines
|
||||
* and do not make checks for overrunning INT_MAX.
|
||||
* @pre file parameter must already be opened.
|
||||
* @post file will be rewound.
|
||||
* @param file The file to determine the size of.
|
||||
* @retval size_t The byte size of the file (we assume no errors will be
|
||||
* encountered in this function).
|
||||
*/
|
||||
int file_numlines( FILE *file )
|
||||
{
|
||||
|
|
@ -1305,7 +1264,6 @@ int file_numlines( FILE *file )
|
|||
* @pre Assumes that NOWHERE, NOTHING, NOBODY, NOFLAG, etc are all equal.
|
||||
* @param str_to_conv A string of characters to attempt to convert to an
|
||||
* IDXTYPE number.
|
||||
* @retval IDXTYPE A valid index number, or NOWHERE if not valid.
|
||||
*/
|
||||
IDXTYPE atoidx( const char *str_to_conv )
|
||||
{
|
||||
|
|
@ -1456,7 +1414,6 @@ char *strfrmt(char *str, int w, int h, int justify, int hpad, int vpad)
|
|||
@param str1 The string to be displayed on the left.
|
||||
@param str2 The string to be displayed on the right.
|
||||
@param joiner ???.
|
||||
@retval char * Pointer to the output to be displayed?
|
||||
*/
|
||||
char *strpaste(char *str1, char *str2, char *joiner)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue