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

List functions. More...

#include "config.h"
#include "constants.h"
#include "typedefs.h"
#include "macros.h"
#include "externs.h"
#include "prototypes.h"
#include <ctype.h>
#include <string.h>
Include dependency graph for funlist.c:

Functions

int autodetect_list (char *ptrs[], int nitems)
 Auto-Detect what kind of list we are dealing with. More...
 
int get_list_type (char *fargs[], int nfargs, int type_pos, char *ptrs[], int nitems)
 Detect the list type. More...
 
int dbnum (char *dbr)
 Convert a DBref (db) to it's numerical value (db) More...
 
void fun_words (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Returns number of words in a string. More...
 
void fun_first (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Returns first word in a string. More...
 
void fun_rest (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Returns all but the first word in a string. More...
 
void fun_last (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Returns last word in a string. More...
 
void fun_match (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Match arg2 against each word of arg1, returning index of first match. More...
 
void fun_matchall (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Returns the index numbers of all words in the list which match pattern. More...
 
void fun_extract (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Extract words from string. More...
 
void fun_index (char *buff, char **bufc, dbref player __attribute__((unused)), dbref caller __attribute__((unused)), dbref cause __attribute__((unused)), char *fargs[], int nfargs __attribute__((unused)), char *cargs[] __attribute__((unused)), int ncargs __attribute__((unused)))
 like extract(), but it works with an arbitrary separator. More...
 
void do_itemfuns (char *buff, char **bufc, char *str, int el, char *word, const Delim *sep, int flag)
 Helper functionm for fun_ldelete, fun_replace and fun_insert. More...
 
void fun_ldelete (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Delete a word at position X of a list. More...
 
void fun_replace (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Replace a word at position X of a list. More...
 
void fun_insert (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Insert a word at position X of a list. More...
 
void fun_lreplace (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Replace item in list. More...
 
void fun_remove (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Remove a word from a string. More...
 
void fun_member (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Is a word in a string. More...
 
void fun_revwords (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Reverse the order of words in a list. More...
 
void fun_splice (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 given two lists and a word, merge the two lists by replacing words in list1 that are the same as the given word by the corresponding word in list2 (by position). The lists must have the same number of words. Compare to MERGE(). More...
 
int a_comp (const void *s1, const void *s2)
 qsort helper for string comparison (case sensitive) More...
 
int c_comp (const void *s1, const void *s2)
 qsort helper for string comparison (case insensitive) More...
 
int arec_comp (const void *s1, const void *s2)
 qsort helper for alphanumerical comparison (case sensitive) More...
 
int crec_comp (const void *s1, const void *s2)
 qsort helper for alphanumerical comparison (case insensitive) More...
 
int f_comp (const void *s1, const void *s2)
 qsort helper for floating point comparison More...
 
int i_comp (const void *s1, const void *s2)
 qsort helper for numerical comparison More...
 
int * do_asort (char *s[], int n, int sort_type, int listpos_only)
 Sort various type of lists. More...
 
void handle_sort (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Handle list sorting. More...
 
int u_comp (const void *s1, const void *s2, char *cbuff, dbref thing, dbref player, dbref cause)
 Helper function for sorting using a user-defined function. More...
 
void sane_qsort (void *array[], int left, int right, int(*compare)(const void *, const void *, char *, dbref, dbref, dbref), char *cbuff, dbref thing, dbref player, dbref cause)
 Andrew Molitor's qsort, which doesn't require transitivity between comparisons (essential for preventing crashes due to boneheads who write comparison functions where a > b doesn't mean b < a). More...
 
void fun_sortby (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Sort by user-define function. More...
 
void handle_sets (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Set management: SETUNION, SETDIFF, SETINTER. Also LUNION, LDIFF, LINTER: Same thing, but takes a sort type like sort() does. There's an unavoidable PennMUSH conflict, as setunion() and friends have a 4th-arg output delimiter in TM3, but the 4th arg is used for the sort type in PennMUSH. Also, adding the sort type as a fifth arg for setunion(), etc. would be confusing, since the last two args are, by convention, delimiters. So we add new funcs. More...
 
void fun_columns (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Format a list into columns. More...
 
void tables_helper (char *list, int *last_state, int n_cols, int col_widths[], char *lead_str, char *trail_str, const Delim *list_sep, const Delim *field_sep, const Delim *pad_char, char *buff, char **bufc, int just)
 Helper function for perform_tables. More...
 
void perform_tables (dbref player __attribute__((unused)), char *list, int n_cols, int col_widths[], char *lead_str, char *trail_str, const Delim *list_sep, const Delim *field_sep, const Delim *pad_char, char *buff, char **bufc, int just)
 Draw a table. More...
 
void process_tables (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Validate that we have everything to draw the table. More...
 
void fun_table (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Turn a list into a table. More...
 
void fun_elements (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 given a list of numbers, get corresponding elements from the list. More...
 
void fun_exclude (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Return the elements of a list EXCEPT the numbered items. More...
 
void fun_grab (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 a combination of extract() and match(), sortof. We grab the single element that we match. More...
 
void fun_graball (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Like grab with matchall() rather than match(). We grab all the elements that match, and we can take an output delimiter. More...
 
void swap (char **p, char **q)
 swaps two points to strings More...
 
void fun_shuffle (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 randomize order of words in a list. More...
 
void fun_ledit (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 If a <word> in

in <old words>, replace it with the corresponding word from <new words>. This is basically a mass-edit. This is an EXACT, not a case-insensitive or wildcarded, match. More...

 
void fun_itemize (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Turn a list into a punctuated list. More...
 
void fun_choose (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Weighted random choice from a list. More...
 
void fun_group (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Sort a list by numerical-size group, i.e., take every Nth element. Useful for passing to a column-type function where you want the list to go down rather than across, for instance. More...
 
void fun_tokens (char *buff, char **bufc, dbref player, dbref caller, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
 Take a string such as 'this "Joe Bloggs" John' and turn it into an output delim-separated list. More...
 

Detailed Description

List functions.

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

Function Documentation

◆ a_comp()

int a_comp ( const void *  s1,
const void *  s2 
)

qsort helper for string comparison (case sensitive)

Parameters
s1First string
s2Second String
Returns
int Comparison result

◆ arec_comp()

int arec_comp ( const void *  s1,
const void *  s2 
)

qsort helper for alphanumerical comparison (case sensitive)

Parameters
s1First list
s2Second list
Returns
int Comparison result

◆ autodetect_list()

int autodetect_list ( char *  ptrs[],
int  nitems 
)

Auto-Detect what kind of list we are dealing with.

List management utilities.

Parameters
ptrsList to check
nitemsNumber of items
Returns
int List type

If non-numeric, switch to alphanum sort. Exception: if this is the first element and it is a good dbref, switch to a dbref sort. We're a little looser than the normal 'good dbref' rules, any number following the #-sign is accepted.

◆ c_comp()

int c_comp ( const void *  s1,
const void *  s2 
)

qsort helper for string comparison (case insensitive)

Parameters
s1First string
s2Second String
Returns
int Comparison result

◆ crec_comp()

int crec_comp ( const void *  s1,
const void *  s2 
)

qsort helper for alphanumerical comparison (case insensitive)

Parameters
s1First list
s2Second list
Returns
int Comparison result

◆ dbnum()

int dbnum ( char *  dbr)

Convert a DBref (db) to it's numerical value (db)

Parameters
dbrText DBref value
Returns
int DBref numerical value

◆ do_asort()

int * do_asort ( char *  s[],
int  n,
int  sort_type,
int  listpos_only 
)

Sort various type of lists.

Parameters
sList
nNumber of arguments
sort_typeSorty type
listpos_onlyReturn position in list instead of modified list
Returns
int* Sorted list position

◆ do_itemfuns()

void do_itemfuns ( char *  buff,
char **  bufc,
char *  str,
int  el,
char *  word,
const Delim sep,
int  flag 
)

Helper functionm for fun_ldelete, fun_replace and fun_insert.

Parameters
buffOutput buffer
bufcOutput buffer tracker
strString to work on
elPosition
wordTarget word
sepString separator
flagFlags

If passed a null string return an empty string, except that we are allowed to append to a null string.

we can't fiddle with anything before the first position

Split the list up into 'before', 'target', and 'after' chunks pointed to by sptr, iptr, and eptr respectively.

No 'before' portion, just split off element 1

Break off 'before' portion

If we didn't make it to the target element, just return the string. Insert is allowed to continue if we are exactly at the end of the string, but replace and delete are not.

Split the 'target' word from the 'after' portion.

◆ f_comp()

int f_comp ( const void *  s1,
const void *  s2 
)

qsort helper for floating point comparison

Parameters
s1First list
s2Second list
Returns
int Comparison result

◆ fun_choose()

void fun_choose ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Weighted random choice from a list.

choose(<list of items>,<list of weights>,<input delim>)

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

Store the breakpoints, not the choose weights themselves.

◆ fun_columns()

void fun_columns ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Format a list into columns.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

unsigned int, always a positive number

Must check number separately, since number + indent can result in an integer overflow.

Start of ANSI code. Skip to end.

We only need spaces if we need to pad out. Sanitize the number of spaces, too.

◆ fun_elements()

void fun_elements ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

given a list of numbers, get corresponding elements from the list.

elements(ack bar eep foof yay,2 4) ==> bar foof The function takes a separator, but the separator only applies to the first list.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

Turn the first list into an array.

Go through the second list, grabbing the numbers and finding the corresponding elements.

Just a number. If negative, count back from end of list.

Support Python-style slicing syntax: <start>:<end>:<step> If start is empty, start from element 0. If start is positive, start from that number. If start is negative, start from that number back from the end (-1 is the last item, -2 is second to last, etc.) If end is empty, stop at the last element. If end is positive, stop there. If end is negative, skip the last end elements. Note that Python numbers arrays from 0, and we number word lists from 1, so the syntax isn't Python-identical!

r points to our start

Empty start

Empty end

Empty start, goes to the LAST element

Empty end

◆ fun_exclude()

void fun_exclude ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Return the elements of a list EXCEPT the numbered items.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

Turn the first list into an array.

Go through the second list, grabbing the numbers and mapping the corresponding elements.

Just a number. If negative, count back from end of list.

Slicing syntax

r points to our start

Empty start

Empty end

Empty start, goes to the LAST element

Empty end

◆ fun_extract()

void fun_extract ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Extract words from string.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

Skip to the start of the string to save

If we ran of the end of the string, return nothing

If our delimiter is the same, we have an easy task. Otherwise we have to go token by token.

Count off the words in the string to save

Chop off the rest of the string, if needed

◆ fun_first()

void fun_first ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Returns first word in a string.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

If we are passed an empty arglist return a null string

◆ fun_grab()

void fun_grab ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

a combination of extract() and match(), sortof. We grab the single element that we match.

grab(Test:1 Ack:2 Foof:3,*:2) => Ack:2 grab(Test-1+Ack-2+Foof-3,o,+) => Ack:2

fun_graball: Ditto, but like matchall() rather than match(). We grab all the elements that match, and we can take an output delimiter.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

Walk the wordstring, until we find the word we want.

◆ fun_graball()

void fun_graball ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Like grab with matchall() rather than match(). We grab all the elements that match, and we can take an output delimiter.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

◆ fun_group()

void fun_group ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Sort a list by numerical-size group, i.e., take every Nth element. Useful for passing to a column-type function where you want the list to go down rather than across, for instance.

group(<list>, <number of groups>, <idelim>, <odelim>, <gdelim>)

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

Separator checking is weird in this, since we can delimit by group, too, as well as the element delimiter. The group delimiter defaults to the output delimiter.

Go do it, unless the group size doesn't make sense.

◆ fun_index()

void fun_index ( char *  buff,
char **  bufc,
dbref player   __attribute__(unused),
dbref caller   __attribute__(unused),
dbref cause   __attribute__(unused),
char *  fargs[],
int nfargs   __attribute__(unused),
char *cargs[]  __attribute__(unused),
int ncargs   __attribute__(unused) 
)

like extract(), but it works with an arbitrary separator.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerNot used
callerNot used
causeNot used
fargsFunction's arguments
nfargsNot used
cargsNot used
ncargsNot used

move s to point to the start of the item we want

skip over just spaces

figure out where to end the string

if we've gotten this far, we've run off the end of the string

◆ fun_insert()

void fun_insert ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Insert a word at position X of a list.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

◆ fun_itemize()

void fun_itemize ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Turn a list into a punctuated list.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

◆ fun_last()

void fun_last ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Returns last word in a string.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

If we are passed an empty arglist return a null string

this is like next_token(), but tracking ansi

Walk backwards through the string to find the separator. Find the last character, and compare the previous characters, to find the separator. If we can't find the last character or we know we're going to fall off the string, return the original string.

◆ fun_ldelete()

void fun_ldelete ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Delete a word at position X of a list.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

◆ fun_ledit()

void fun_ledit ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

If a <word> in

in <old words>, replace it with the corresponding word from <new words>. This is basically a mass-edit. This is an EXACT, not a case-insensitive or wildcarded, match.

ledit(<list of words>,<old words>,<new words>[,<delim>[,<output delim>]])

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

Iterate through the words.

If we specify more old words than we have new words, we assume we want to just nullify.

◆ fun_lreplace()

void fun_lreplace ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Replace item in list.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

We're generous with the argument checking, in case the replacement list is blank, and/or the position list is blank.

If there are no positions to replace, then we just return the original list.

The number of elements we have in our replacement list must equal the number of elements in our position list.

Turn out lists into arrays for ease of manipulation.

The positions we have aren't necessarily sequential, so we can't just walk through the list. We have to replace position by position. If we get an invalid position number, just ignore it.

◆ fun_match()

void fun_match ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Match arg2 against each word of arg1, returning index of first match.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

Check each word individually, returning the word number of the first one that matches. If none match, return 0.

◆ fun_matchall()

void fun_matchall ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Returns the index numbers of all words in the list which match pattern.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

SPECIAL CASE: If there's no output delimiter specified, we use a space, NOT the delimiter given for the list!

Check each word individually, returning the word number of all that match (or don't match, in the case of unmatchall). If none, return a null string.

◆ fun_member()

void fun_member ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Is a word in a string.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

◆ fun_remove()

void fun_remove ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Remove a word from a string.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

Walk through the string copying words until (if ever) we get to one that matches the target word.

◆ fun_replace()

void fun_replace ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Replace a word at position X of a list.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

◆ fun_rest()

void fun_rest ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Returns all but the first word in a string.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

◆ fun_revwords()

void fun_revwords ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Reverse the order of words in a list.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

If we are passed an empty arglist return a null string

Nasty bounds checking

Chop it up into an array of words and reverse them.

◆ fun_shuffle()

void fun_shuffle ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

randomize order of words in a list.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

◆ fun_sortby()

void fun_sortby ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Sort by user-define function.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

pointless to sort less than 2 elements

◆ fun_splice()

void fun_splice ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

given two lists and a word, merge the two lists by replacing words in list1 that are the same as the given word by the corresponding word in list2 (by position). The lists must have the same number of words. Compare to MERGE().

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

length checks

loop through the two lists

< replace

< copy

◆ fun_table()

void fun_table ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Turn a list into a table.

table(<list>,<field width>,<line length>,<list delim>,<field sep>,<pad>) Only the

is mandatory. tables(<list>,<field widths>,<lead str>,<trail str>,<list delim>,<field sep str>,<pad>) Only the

<field widths> parameters are mandatory.

There are a couple of PennMUSH incompatibilities. The handling here is more complex and probably more desirable behavior. The issues are:

  • ANSI states are preserved even if a word is truncated. Thus, the next word will start with the correct color.
  • ANSI does not bleed into the padding or field separators.
  • Having a 'r' embedded in the list will start a new set of columns. This allows a series of r-separated lists to be table-ified correctly, and doesn't mess up the character count.
Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

Get line length and column width. All columns are the same width. Calculate what we need to.

◆ fun_tokens()

void fun_tokens ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Take a string such as 'this "Joe Bloggs" John' and turn it into an output delim-separated list.

tokens(<string>[,<obj>/<attr>][,<open>][,<close>][,<sep>][,<osep>])

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

Now we're inside quotes. Find the end quote, and copy the token inside of it. If we run off the end of the string, we ignore the literal opening marker that we've skipped.

We are at a bare word. Split it off.

Pass the token through the transformation function if we have one, or just copy it, if not.

Skip to start of next token, ignoring input separators.

◆ fun_words()

void fun_words ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Returns number of words in a string.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

◆ get_list_type()

int get_list_type ( char *  fargs[],
int  nfargs,
int  type_pos,
char *  ptrs[],
int  nitems 
)

Detect the list type.

Parameters
fargsFunction Arguments
nfargsNumber of arguments
type_posWhich argument hold the list type
ptrsList
nitemsNumber of items in the list
Returns
int List type

◆ handle_sets()

void handle_sets ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Set management: SETUNION, SETDIFF, SETINTER. Also LUNION, LDIFF, LINTER: Same thing, but takes a sort type like sort() does. There's an unavoidable PennMUSH conflict, as setunion() and friends have a 4th-arg output delimiter in TM3, but the 4th arg is used for the sort type in PennMUSH. Also, adding the sort type as a fifth arg for setunion(), etc. would be confusing, since the last two args are, by convention, delimiters. So we add new funcs.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

This conversion is inefficient, since it's already happened once in do_asort().

< Copy elements common to both lists

Handle case of two identical single-element lists

Process until one list is empty

Skip over duplicates

Compare and copy

Copy rest of remaining list, stripping duplicates

< Copy elements not in both lists

Got a match, copy it

< Copy elements unique to list1

Got a match, increment pointers

Item in list1 not in list2, copy

Item in list2 but not in list1, discard

Copy remainder of list1

◆ handle_sort()

void handle_sort ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Handle list sorting.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

If we are passed an empty arglist return a null string

Convert the list to an array

◆ i_comp()

int i_comp ( const void *  s1,
const void *  s2 
)

qsort helper for numerical comparison

Parameters
s1First list
s2Second list
Returns
int Comparison result

◆ perform_tables()

void perform_tables ( dbref player   __attribute__(unused),
char *  list,
int  n_cols,
int  col_widths[],
char *  lead_str,
char *  trail_str,
const Delim list_sep,
const Delim field_sep,
const Delim pad_char,
char *  buff,
char **  bufc,
int  just 
)

Draw a table.

Parameters
playerNot Used
listList to draw in table
n_colsNumber of column
col_widthsColumn width
lead_strLeading String
trail_strTrailing String
list_sepList Separator
field_sepField Separator
pad_charPadding char
buffOutput buffer
bufcOutput buffer tracker
justJustify table?

< must skip '
' too

◆ process_tables()

void process_tables ( char *  buff,
char **  bufc,
dbref  player,
dbref  caller,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Validate that we have everything to draw the table.

Parameters
buffOutput buffer
bufcOutput buffer tracker
playerDBref of player
callerDBref of caller
causeDBref of cause
fargsFunction's arguments
nfargsNumber of function's arguments
cargsCommand's arguments
ncargsNomber of command's arguments

◆ sane_qsort()

void sane_qsort ( void *  array[],
int  left,
int  right,
int(*)(const void *, const void *, char *, dbref, dbref, dbref)  compare,
char *  cbuff,
dbref  thing,
dbref  player,
dbref  cause 
)

Andrew Molitor's qsort, which doesn't require transitivity between comparisons (essential for preventing crashes due to boneheads who write comparison functions where a > b doesn't mean b < a).

Parameters
arrayArray to sort
leftLeft position of array
rightRight position of array
compareCompare function
cbuffUser-defined compare function
thingDBref of thing
playerDBref of player
causeDBref of cause

Pick something at random at swap it into the leftmost slot This is the pivot, we'll put it back in the right spot later

Walk the array, looking for stuff that's less than our pivot. If it is, swap it with the next thing along

Now we put the pivot back, it's now in the right spot, we never need to look at it again, trust me.

At this point everything underneath the 'last' index is < the entry at 'last' and everything above it is not < it.

◆ swap()

void swap ( char **  p,
char **  q 
)

swaps two points to strings

Parameters
pFirst points to strings
qSecond points to strings

◆ tables_helper()

void tables_helper ( char *  list,
int *  last_state,
int  n_cols,
int  col_widths[],
char *  lead_str,
char *  trail_str,
const Delim list_sep,
const Delim field_sep,
const Delim pad_char,
char *  buff,
char **  bufc,
int  just 
)

Helper function for perform_tables.

Parameters
listList
last_stateAnsi state
n_colsNumber of columns
col_widthsColumns width
lead_strLeading String
trail_strTrailing String
list_sepList separator
field_sepField Separator
pad_charPadding Char
buffOutput buffer
bufcOutput buffer tracker
justJustify?

Split apart the list. We need to find the length of each de-ansified word, as well as keep track of the state of each word. Overly-long words eventually get truncated, but the correct ANSI state is preserved nonetheless.

Beginning of new line. Insert newline if this isn't the first thing we're writing. Write left margin, if appropriate.

Do each column in the line.

Write leading padding if we need it.

If we had a previous state, we have to write it.

Copy in the word.

Bleah. We have a string that's too long. Truncate it. Write an ANSI normal at the end at the end if we need one (we'll restore the correct ANSI code with the next word, if need be).

Writing trailing padding if we need it.

Insert the field separator if this isn't the last column AND this is not the very last word in the list.

If we didn't get enough columns to fill out a line, and this is the last line, then we have to pad it out.

Write the right margin.

Save the ANSI state of the last word.

Clean up.

◆ u_comp()

int u_comp ( const void *  s1,
const void *  s2,
char *  cbuff,
dbref  thing,
dbref  player,
dbref  cause 
)

Helper function for sorting using a user-defined function.

Parameters
s1Element 1
s2Element 2
cbuffuser-defined function for sorting
thingDBref of thing
playerDBref of player
causeDBref oc cause
Returns
int Sort result

Note that this function is for use in conjunction with our own sane_qsort routine, NOT with the standard library qsort!