TinyMUSH 3.3
TinyMUSH Server
Loading...
Searching...
No Matches
Functions
fnhelper.c File Reference

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>
Include dependency graph for fnhelper.c:

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...
 

Detailed Description

Helper functions for MUSH functions.

Author
TinyMUSH development team (https://github.com/TinyMUSH)
Version
3.3
Date
2021-01-04

Function Documentation

◆ arr2list()

void arr2list ( char **  arr,
int  alen,
char *  list,
char **  bufc,
const Delim sep 
)

Convert arrays to lists.

Parameters
arrArray to convert
alenArray length
listList buffer
bufcBuffer
sepSeparatpr

◆ countwords()

int countwords ( char *  str,
const Delim sep 
)

Count the words in a delimiter-separated list.

Parameters
strString to count words
sepWord separators
Returns
int Number of words

◆ delim_check()

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.

Parameters
buffBuffer
bufcBuffer tracher
playerDBref of player
callerDBref of caller
causeDBref oc cause
fargsArguments for functions
nfargsNumber of arguments for functions
cargsArguments for commands
ncargsNumber of arguments for commands
sep_argArgument Separator
sepSeparator
dflagsDelimiter flags
Returns
int

◆ do_reverse()

void do_reverse ( char *  from,
char *  to 
)

Used by fun_reverse and fun_revwords to reverse things.

Parameters
fromInput
toOutput

◆ fn_range_check()

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.

Parameters
fnameFunction name
nfargsNumber of arguments
minargsMinimum number of arguments
maxargsMaximum number of arguments
resultResult message if error
bufcBuffer
Returns
bool

◆ list2ansi()

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.

Note
Needs one more array slot than list2arr (think fenceposts) but still takes the same maxlen and returns the same number of words.
Parameters
arrArray
prior_stateAnsi State
maxlenMaximum length of array
listList to parse
sepSeparator
Returns
int Ansi state

◆ list2arr()

int list2arr ( char ***  arr,
int  maxtok,
char *  list,
const Delim sep 
)

Convert lists to arrays.

Parameters
arrPointer to Array
maxtokMaximum number of token
listList to convert
sepList separator
Returns
int Number of token in array.

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.

◆ match_thing()

dbref match_thing ( dbref  player,
char *  name 
)

Quick-matching for function purposes.

Parameters
playerDBref of player
nameName for match
Returns
dbref Match

◆ next_token()

char * next_token ( char *  str,
const Delim sep 
)

Point at start of next token in string.

Parameters
strString with tokens
sepToken separators
Returns
char* Pointer to next token

◆ next_token_ansi()

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.

Parameters
strString with token
sepToken separator
ansi_state_ptrCurrent ansi state
Returns
char* Token

ansi tracking not supported yet in multichar delims

◆ pcg32_boundedrand_r()

uint32_t pcg32_boundedrand_r ( pcg32_random_t rng,
uint32_t  bound 
)

Generate a uniformly distributed number, r, where 0 <= r < bound.

Parameters
rngAddress of a pcg32_random_t value previously declared
boundUpper limit for the generated number
Returns
uint32_t Uniformly distributed 32-bit random number

◆ pcg32_random_r()

uint32_t pcg32_random_r ( pcg32_random_t rng)

Generate a uniformly distributed 32-bit random number.

Parameters
rngAddress of a pcg32_random_t value previously declared
Returns
uint32_t Uniformly distributed 32-bit random number

◆ pcg32_srandom_r()

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)

Parameters
rngAddress of a pcg32_random_t value previously declared
initstateStarting state for the RNG, you can pass any 64-bit value
initseqSelects the output sequence for the RNG, you can pass any 64-bit value, although only the low 63 bits are significant

◆ print_separator()

void print_separator ( const Delim sep,
char *  list,
char **  bufc 
)

Print separator for arr2list.

Parameters
sepSeparator
listList
bufcBuffer where to write

◆ random_range()

uint32_t random_range ( uint32_t  low,
uint32_t  high 
)

Generate random number between low and high.

Parameters
lowLowest value of random number
highHighest value of random number
Returns
uint32_t Random number

◆ split_token()

char * split_token ( char **  sp,
const Delim sep 
)

Get next token from string as null-term string. String is destructively modified.

Parameters
spString with tokens
sepToken separators
Returns
char* Token

◆ trim_space_sep()

char * trim_space_sep ( char *  str,
const Delim sep 
)

Trim off leading and trailing spaces if the separator char is a space.

Parameters
strString to trim
sepSeparator char
Returns
char* Trimmed string

◆ xlate()

bool xlate ( char *  arg)
Parameters
argBoolean true/false check.
Returns
true
false

Case of '#-1 <string>'