TinyMUSH 3.3
TinyMUSH Server
|
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>
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... | |
List functions.
int a_comp | ( | const void * | s1, |
const void * | s2 | ||
) |
qsort helper for string comparison (case sensitive)
s1 | First string |
s2 | Second String |
int arec_comp | ( | const void * | s1, |
const void * | s2 | ||
) |
qsort helper for alphanumerical comparison (case sensitive)
s1 | First list |
s2 | Second list |
int autodetect_list | ( | char * | ptrs[], |
int | nitems | ||
) |
Auto-Detect what kind of list we are dealing with.
List management utilities.
ptrs | List to check |
nitems | Number of items |
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.
int c_comp | ( | const void * | s1, |
const void * | s2 | ||
) |
qsort helper for string comparison (case insensitive)
s1 | First string |
s2 | Second String |
int crec_comp | ( | const void * | s1, |
const void * | s2 | ||
) |
qsort helper for alphanumerical comparison (case insensitive)
s1 | First list |
s2 | Second list |
int dbnum | ( | char * | dbr | ) |
Convert a DBref (db) to it's numerical value (db)
dbr | Text DBref value |
int * do_asort | ( | char * | s[], |
int | n, | ||
int | sort_type, | ||
int | listpos_only | ||
) |
Sort various type of lists.
s | List |
n | Number of arguments |
sort_type | Sorty type |
listpos_only | Return position in list instead of modified list |
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.
buff | Output buffer |
bufc | Output buffer tracker |
str | String to work on |
el | Position |
word | Target word |
sep | String separator |
flag | Flags |
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.
int f_comp | ( | const void * | s1, |
const void * | s2 | ||
) |
qsort helper for floating point comparison
s1 | First list |
s2 | Second list |
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>)
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber of command's arguments |
Store the breakpoints, not the choose weights themselves.
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber 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.
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber 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
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber 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
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber 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
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber of command's arguments |
If we are passed an empty arglist return a null string
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber of command's arguments |
Walk the wordstring, until we find the word we want.
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber of command's arguments |
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>)
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber 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.
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | Not used |
caller | Not used |
cause | Not used |
fargs | Function's arguments |
nfargs | Not used |
cargs | Not used |
ncargs | Not 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
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber of command's arguments |
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber of command's arguments |
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber 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.
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber of command's arguments |
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>]])
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber 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.
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber 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.
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber of command's arguments |
Check each word individually, returning the word number of the first one that matches. If none match, return 0.
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber 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.
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber of command's arguments |
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber of command's arguments |
Walk through the string copying words until (if ever) we get to one that matches the target word.
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber of command's arguments |
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber of command's arguments |
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber 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.
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber of command's arguments |
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber of command's arguments |
pointless to sort less than 2 elements
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().
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber of command's arguments |
length checks
loop through the two lists
< replace
< copy
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:
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber of command's arguments |
Get line length and column width. All columns are the same width. Calculate what we need to.
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>])
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber 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.
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber of command's arguments |
int get_list_type | ( | char * | fargs[], |
int | nfargs, | ||
int | type_pos, | ||
char * | ptrs[], | ||
int | nitems | ||
) |
Detect the list type.
fargs | Function Arguments |
nfargs | Number of arguments |
type_pos | Which argument hold the list type |
ptrs | List |
nitems | Number of items in the list |
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber 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
void handle_sort | ( | char * | buff, |
char ** | bufc, | ||
dbref | player, | ||
dbref | caller, | ||
dbref | cause, | ||
char * | fargs[], | ||
int | nfargs, | ||
char * | cargs[], | ||
int | ncargs | ||
) |
Handle list sorting.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber of command's arguments |
If we are passed an empty arglist return a null string
Convert the list to an array
int i_comp | ( | const void * | s1, |
const void * | s2 | ||
) |
qsort helper for numerical comparison
s1 | First list |
s2 | Second list |
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.
player | Not Used |
list | List to draw in table |
n_cols | Number of column |
col_widths | Column width |
lead_str | Leading String |
trail_str | Trailing String |
list_sep | List Separator |
field_sep | Field Separator |
pad_char | Padding char |
buff | Output buffer |
bufc | Output buffer tracker |
just | Justify table? |
< must skip '
' too
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.
buff | Output buffer |
bufc | Output buffer tracker |
player | DBref of player |
caller | DBref of caller |
cause | DBref of cause |
fargs | Function's arguments |
nfargs | Number of function's arguments |
cargs | Command's arguments |
ncargs | Nomber of command's arguments |
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).
array | Array to sort |
left | Left position of array |
right | Right position of array |
compare | Compare function |
cbuff | User-defined compare function |
thing | DBref of thing |
player | DBref of player |
cause | DBref 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.
void swap | ( | char ** | p, |
char ** | q | ||
) |
swaps two points to strings
p | First points to strings |
q | Second points to strings |
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.
list | List |
last_state | Ansi state |
n_cols | Number of columns |
col_widths | Columns width |
lead_str | Leading String |
trail_str | Trailing String |
list_sep | List separator |
field_sep | Field Separator |
pad_char | Padding Char |
buff | Output buffer |
bufc | Output buffer tracker |
just | Justify? |
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.
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.
s1 | Element 1 |
s2 | Element 2 |
cbuff | user-defined function for sorting |
thing | DBref of thing |
player | DBref of player |
cause | DBref oc cause |
Note that this function is for use in conjunction with our own sane_qsort routine, NOT with the standard library qsort!