TinyMUSH 3.3
TinyMUSH Server
|
Helper functions for MUSH functions. More...
#include "config.h"
#include "constants.h"
#include "typedefs.h"
#include "macros.h"
#include "externs.h"
#include "prototypes.h"
#include <stdbool.h>
#include <string.h>
Functions | |
char * | trim_space_sep (char *str, const Delim *sep) |
Trim off leading and trailing spaces if the separator char is a space. More... | |
char * | next_token (char *str, const Delim *sep) |
Point at start of next token in string. More... | |
char * | split_token (char **sp, const Delim *sep) |
Get next token from string as null-term string. String is destructively modified. More... | |
char * | next_token_ansi (char *str, const Delim *sep, int *ansi_state_ptr) |
Point at start of next token, and tell what color it is. More... | |
int | countwords (char *str, const Delim *sep) |
Count the words in a delimiter-separated list. More... | |
int | list2arr (char ***arr, int maxtok, char *list, const Delim *sep) |
Convert lists to arrays. More... | |
void | print_separator (const Delim *sep, char *list, char **bufc) |
Print separator for arr2list. More... | |
void | arr2list (char **arr, int alen, char *list, char **bufc, const Delim *sep) |
Convert arrays to lists. More... | |
int | list2ansi (int *arr, int *prior_state, int maxlen, char *list, const Delim *sep) |
Find the ANSI states at the beginning and end of each word of a list. More... | |
dbref | match_thing (dbref player, char *name) |
Quick-matching for function purposes. More... | |
bool | fn_range_check (const char *fname, int nfargs, int minargs, int maxargs, char *result, char **bufc) |
Check # of args to a function with an optional argument for validity. More... | |
int | delim_check (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs, int sep_arg, Delim *sep, int dflags) |
Obtain delimiter. More... | |
bool | xlate (char *arg) |
void | do_reverse (char *from, char *to) |
Used by fun_reverse and fun_revwords to reverse things. More... | |
uint32_t | random_range (uint32_t low, uint32_t high) |
Generate random number between low and high. More... | |
void | pcg32_srandom_r (pcg32_random_t *rng, uint64_t initstate, uint64_t initseq) |
Seed the rng. Specified in two parts, state initializer and a sequence selection constant (a.k.a. stream id) More... | |
uint32_t | pcg32_random_r (pcg32_random_t *rng) |
Generate a uniformly distributed 32-bit random number. More... | |
uint32_t | pcg32_boundedrand_r (pcg32_random_t *rng, uint32_t bound) |
Generate a uniformly distributed number, r, where 0 <= r < bound. More... | |
Helper functions for MUSH functions.
void arr2list | ( | char ** | arr, |
int | alen, | ||
char * | list, | ||
char ** | bufc, | ||
const Delim * | sep | ||
) |
Convert arrays to lists.
arr | Array to convert |
alen | Array length |
list | List buffer |
bufc | Buffer |
sep | Separatpr |
int countwords | ( | char * | str, |
const Delim * | sep | ||
) |
Count the words in a delimiter-separated list.
str | String to count words |
sep | Word separators |
int delim_check | ( | char * | buff, |
char ** | bufc, | ||
dbref | player, | ||
dbref | caller, | ||
dbref | cause, | ||
char * | fargs[], | ||
int | nfargs, | ||
char * | cargs[], | ||
int | ncargs, | ||
int | sep_arg, | ||
Delim * | sep, | ||
int | dflags | ||
) |
Obtain delimiter.
buff | Buffer |
bufc | Buffer tracher |
player | DBref of player |
caller | DBref of caller |
cause | DBref oc cause |
fargs | Arguments for functions |
nfargs | Number of arguments for functions |
cargs | Arguments for commands |
ncargs | Number of arguments for commands |
sep_arg | Argument Separator |
sep | Separator |
dflags | Delimiter flags |
void do_reverse | ( | char * | from, |
char * | to | ||
) |
Used by fun_reverse and fun_revwords to reverse things.
from | Input |
to | Output |
bool fn_range_check | ( | const char * | fname, |
int | nfargs, | ||
int | minargs, | ||
int | maxargs, | ||
char * | result, | ||
char ** | bufc | ||
) |
Check # of args to a function with an optional argument for validity.
fname | Function name |
nfargs | Number of arguments |
minargs | Minimum number of arguments |
maxargs | Maximum number of arguments |
result | Result message if error |
bufc | Buffer |
int list2ansi | ( | int * | arr, |
int * | prior_state, | ||
int | maxlen, | ||
char * | list, | ||
const Delim * | sep | ||
) |
Find the ANSI states at the beginning and end of each word of a list.
arr | Array |
prior_state | Ansi State |
maxlen | Maximum length of array |
list | List to parse |
sep | Separator |
int list2arr | ( | char *** | arr, |
int | maxtok, | ||
char * | list, | ||
const Delim * | sep | ||
) |
Convert lists to arrays.
arr | Pointer to Array |
maxtok | Maximum number of token |
list | List to convert |
sep | List separator |
Mark token starting points in a 1k bitstring, then go back and collect them into an array of just the right number of pointers.
< So we don't try to XMALLOC(0).
Caller must free this array of pointers later. Validity of the pointers is dependent upon the original list string having not been freed yet.
There's at least one token starting in this byte of the bitstring, so we scan the bits.
dbref match_thing | ( | dbref | player, |
char * | name | ||
) |
Quick-matching for function purposes.
player | DBref of player |
name | Name for match |
char * next_token | ( | char * | str, |
const Delim * | sep | ||
) |
Point at start of next token in string.
str | String with tokens |
sep | Token separators |
char * next_token_ansi | ( | char * | str, |
const Delim * | sep, | ||
int * | ansi_state_ptr | ||
) |
Point at start of next token, and tell what color it is.
str | String with token |
sep | Token separator |
ansi_state_ptr | Current ansi state |
ansi tracking not supported yet in multichar delims
uint32_t pcg32_boundedrand_r | ( | pcg32_random_t * | rng, |
uint32_t | bound | ||
) |
Generate a uniformly distributed number, r, where 0 <= r < bound.
rng | Address of a pcg32_random_t value previously declared |
bound | Upper limit for the generated number |
uint32_t pcg32_random_r | ( | pcg32_random_t * | rng | ) |
Generate a uniformly distributed 32-bit random number.
rng | Address of a pcg32_random_t value previously declared |
void pcg32_srandom_r | ( | pcg32_random_t * | rng, |
uint64_t | initstate, | ||
uint64_t | initseq | ||
) |
Seed the rng. Specified in two parts, state initializer and a sequence selection constant (a.k.a. stream id)
rng | Address of a pcg32_random_t value previously declared |
initstate | Starting state for the RNG, you can pass any 64-bit value |
initseq | Selects the output sequence for the RNG, you can pass any 64-bit value, although only the low 63 bits are significant |
void print_separator | ( | const Delim * | sep, |
char * | list, | ||
char ** | bufc | ||
) |
Print separator for arr2list.
sep | Separator |
list | List |
bufc | Buffer where to write |
uint32_t random_range | ( | uint32_t | low, |
uint32_t | high | ||
) |
Generate random number between low and high.
low | Lowest value of random number |
high | Highest value of random number |
char * split_token | ( | char ** | sp, |
const Delim * | sep | ||
) |
Get next token from string as null-term string. String is destructively modified.
sp | String with tokens |
sep | Token separators |
char * trim_space_sep | ( | char * | str, |
const Delim * | sep | ||
) |
Trim off leading and trailing spaces if the separator char is a space.
str | String to trim |
sep | Separator char |
bool xlate | ( | char * | arg | ) |
arg | Boolean true/false check. |
Case of '#-1 <string>'