mux/src/functions.h File Reference

#include "copyright.h"

Include dependency graph for functions.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  tagFun
struct  ufun
struct  SEP

Defines

#define FN_NOEVAL   2
#define FN_PRIV   4
#define FN_PRES   8
#define FN_LIST   1
#define print_sep(ps, b, p)   safe_copy_buf((ps)->str,(ps)->n,(b),(p))
#define MAX_SEP_LEN   50
#define DELIM_DFLT   0x0000
#define DELIM_EVAL   0x0001
#define DELIM_NULL   0x0002
#define DELIM_CRLF   0x0004
#define DELIM_STRING   0x0008
#define DELIM_INIT   0x0010
#define FUNCTION(x)
#define OPTIONAL_DELIM(iSep, Sep, dflags)
#define XFUNCTION(x)

Typedefs

typedef tagFun FUN
typedef ufun UFUN

Functions

void init_functab (void)
void list_functable (dbref)
bool delim_check (char *buff, char **bufc, dbref executor, dbref caller, dbref enactor, char *fargs[], int nfargs, char *cargs[], int ncargs, int sep_arg, SEP *sep, int dflags)
void arr2list (char *arr[], int alen, char *list, char **bufc, SEP *psep)
int list2arr (char *arr[], int maxlen, char *list, SEP *psep)
char * trim_space_sep (char *str, SEP *psep)
char * trim_space_sep_LEN (char *str, int nStr, SEP *psep, int *nTrim)
char * next_token (char *str, SEP *psep)
char * split_token (char **sp, SEP *psep)
int countwords (char *str, SEP *psep)
void function_add (FUN *fp)
void functions_add (FUN funlist[])
 XFUNCTION (fun_channels)
 XFUNCTION (fun_comalias)
 XFUNCTION (fun_comtitle)
 XFUNCTION (fun_alphamax)
 XFUNCTION (fun_alphamin)
 XFUNCTION (fun_andflags)
 XFUNCTION (fun_ansi)
 XFUNCTION (fun_beep)
 XFUNCTION (fun_children)
 XFUNCTION (fun_columns)
 XFUNCTION (fun_cwho)
 XFUNCTION (fun_decrypt)
 XFUNCTION (fun_default)
 XFUNCTION (fun_die)
 XFUNCTION (fun_dumping)
 XFUNCTION (fun_edefault)
 XFUNCTION (fun_elements)
 XFUNCTION (fun_empty)
 XFUNCTION (fun_encrypt)
 XFUNCTION (fun_entrances)
 XFUNCTION (fun_fcount)
 XFUNCTION (fun_fdepth)
 XFUNCTION (fun_findable)
 XFUNCTION (fun_foreach)
 XFUNCTION (fun_grab)
 XFUNCTION (fun_graball)
 XFUNCTION (fun_grep)
 XFUNCTION (fun_grepi)
 XFUNCTION (fun_hasattr)
 XFUNCTION (fun_hasattrp)
 XFUNCTION (fun_hastype)
 XFUNCTION (fun_ifelse)
 XFUNCTION (fun_inzone)
 XFUNCTION (fun_isword)
 XFUNCTION (fun_items)
 XFUNCTION (fun_last)
 XFUNCTION (fun_lit)
 XFUNCTION (fun_localize)
 XFUNCTION (fun_lparent)
 XFUNCTION (fun_lrand)
 XFUNCTION (fun_lrooms)
 XFUNCTION (fun_lstack)
 XFUNCTION (fun_mail)
 XFUNCTION (fun_mailfrom)
 XFUNCTION (fun_matchall)
 XFUNCTION (fun_mix)
 XFUNCTION (fun_munge)
 XFUNCTION (fun_null)
 XFUNCTION (fun_objeval)
 XFUNCTION (fun_objmem)
 XFUNCTION (fun_orflags)
 XFUNCTION (fun_pack)
 XFUNCTION (fun_peek)
 XFUNCTION (fun_pickrand)
 XFUNCTION (fun_playmem)
 XFUNCTION (fun_pop)
 XFUNCTION (fun_ports)
 XFUNCTION (fun_push)
 XFUNCTION (fun_regmatch)
 XFUNCTION (fun_regmatchi)
 XFUNCTION (fun_regrab)
 XFUNCTION (fun_regraball)
 XFUNCTION (fun_regraballi)
 XFUNCTION (fun_regrabi)
 XFUNCTION (fun_scramble)
 XFUNCTION (fun_shuffle)
 XFUNCTION (fun_sortby)
 XFUNCTION (fun_squish)
 XFUNCTION (fun_strcat)
 XFUNCTION (fun_stripansi)
 XFUNCTION (fun_strtrunc)
 XFUNCTION (fun_table)
 XFUNCTION (fun_translate)
 XFUNCTION (fun_udefault)
 XFUNCTION (fun_unpack)
 XFUNCTION (fun_valid)
 XFUNCTION (fun_visible)
 XFUNCTION (fun_zfun)
 XFUNCTION (fun_zone)
 XFUNCTION (fun_zwho)
 XFUNCTION (fun_doing)
 XFUNCTION (fun_host)
 XFUNCTION (fun_motd)
 XFUNCTION (fun_poll)
 XFUNCTION (fun_hasquota)

Variables

UFUNufun_head
SEP sepSpace


Define Documentation

#define DELIM_CRLF   0x0004

Definition at line 62 of file functions.h.

Referenced by FUNCTION().

#define DELIM_DFLT   0x0000

Definition at line 59 of file functions.h.

Referenced by FUNCTION().

#define DELIM_EVAL   0x0001

Definition at line 60 of file functions.h.

Referenced by delim_check(), and FUNCTION().

#define DELIM_INIT   0x0010

Definition at line 64 of file functions.h.

Referenced by delim_check(), and FUNCTION().

#define DELIM_NULL   0x0002

Definition at line 61 of file functions.h.

Referenced by delim_check(), and FUNCTION().

#define DELIM_STRING   0x0008

Definition at line 63 of file functions.h.

Referenced by delim_check(), and FUNCTION().

#define FN_LIST   1

Definition at line 37 of file functions.h.

Referenced by do_function().

#define FN_NOEVAL   2

Definition at line 33 of file functions.h.

Referenced by mux_exec().

#define FN_PRES   8

Definition at line 35 of file functions.h.

Referenced by do_function(), and mux_exec().

#define FN_PRIV   4

Definition at line 34 of file functions.h.

Referenced by do_function(), and mux_exec().

#define FUNCTION (  ) 

Value:

void x(char *buff, char **bufc, dbref executor, dbref caller,     \
        dbref enactor, char *fargs[], int nfargs, char *cargs[],      \
        int ncargs)

Definition at line 85 of file functions.h.

#define MAX_SEP_LEN   50

Definition at line 48 of file functions.h.

Referenced by delim_check().

#define OPTIONAL_DELIM ( iSep,
Sep,
dflags   ) 

Value:

delim_check(buff, bufc, executor, caller, enactor,           \
        fargs, nfargs, cargs, ncargs, (iSep), &(Sep), (dflags))

Definition at line 92 of file functions.h.

Referenced by FUNCTION().

#define print_sep ( ps,
b,
 )     safe_copy_buf((ps)->str,(ps)->n,(b),(p))

Definition at line 46 of file functions.h.

Referenced by arr2list(), filter_handler(), FUNCTION(), handle_sets(), handle_vectors(), and real_regrab().

#define XFUNCTION (  ) 

Value:

void x(char *buff, char **bufc, dbref executor,    \
 dbref caller, dbref enactor, char *fargs[], int nfargs, char *cargs[],        \
 int ncargs)

Definition at line 96 of file functions.h.


Typedef Documentation

typedef struct tagFun FUN

typedef struct ufun UFUN


Function Documentation

void arr2list ( char *  arr[],
int  alen,
char *  list,
char **  bufc,
SEP psep 
)

Definition at line 392 of file functions.cpp.

References print_sep, and safe_str.

Referenced by FUNCTION().

00393 {
00394     int i;
00395     for (i = 0; i < alen-1; i++)
00396     {
00397         safe_str(arr[i], list, bufc);
00398         print_sep(psep, list, bufc);
00399     }
00400     if (alen)
00401     {
00402         safe_str(arr[i], list, bufc);
00403     }
00404 }

int countwords ( char *  str,
SEP psep 
)

Definition at line 540 of file functions.cpp.

References next_token(), and trim_space_sep().

Referenced by FUNCTION().

00541 {
00542     int n;
00543 
00544     str = trim_space_sep(str, psep);
00545     if (!*str)
00546     {
00547         return 0;
00548     }
00549     for (n = 0; str; str = next_token(str, psep), n++)
00550     {
00551         ; // Nothing.
00552     }
00553     return n;
00554 }

bool delim_check ( char *  buff,
char **  bufc,
dbref  executor,
dbref  caller,
dbref  enactor,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs,
int  sep_arg,
SEP sep,
int  dflags 
)

Definition at line 443 of file functions.cpp.

References alloc_lbuf, DELIM_EVAL, DELIM_INIT, DELIM_NULL, DELIM_STRING, EV_EVAL, EV_FCHECK, free_lbuf, MAX_SEP_LEN, mux_exec(), SEP::n, NULL_DELIM_VAR, safe_str, and SEP::str.

00450 {
00451     bool bSuccess = true;
00452     if (sep_arg <= nfargs)
00453     {
00454         // First, we decide whether to evalute fargs[sep_arg-1] or not.
00455         //
00456         char *tstr = fargs[sep_arg-1];
00457         int tlen = strlen(tstr);
00458 
00459         if (tlen <= 1)
00460         {
00461             dflags &= ~DELIM_EVAL;
00462         }
00463         if (dflags & DELIM_EVAL)
00464         {
00465             char *str = tstr;
00466             char *bp = tstr = alloc_lbuf("delim_check");
00467             mux_exec(tstr, &bp, executor, caller, enactor,
00468                      EV_EVAL | EV_FCHECK, &str, cargs, ncargs);
00469             *bp = '\0';
00470             tlen = bp - tstr;
00471         }
00472 
00473         // Regardless of evaulation or no, tstr contains what we need to
00474         // look at, and tlen is the length of this string.
00475         //
00476         if (tlen == 1)
00477         {
00478             sep->n      = 1;
00479             memcpy(sep->str, tstr, tlen+1);
00480         }
00481         else if (tlen == 0)
00482         {
00483             sep->n      = 1;
00484             memcpy(sep->str, " ", 2);
00485         }
00486         else if (  tlen == 2
00487                 && (dflags & DELIM_NULL)
00488                 && memcmp(tstr, NULL_DELIM_VAR, 2) == 0)
00489         {
00490             sep->n      = 0;
00491             sep->str[0] = '\0';
00492         }
00493         else if (  tlen == 2
00494                 && (dflags & DELIM_EVAL)
00495                 && memcmp(tstr, "\r\n", 2) == 0)
00496         {
00497             sep->n      = 2;
00498             memcpy(sep->str, "\r\n", 3);
00499         }
00500         else if (dflags & DELIM_STRING)
00501         {
00502             if (tlen <= MAX_SEP_LEN)
00503             {
00504                 sep->n = tlen;
00505                 memcpy(sep->str, tstr, tlen);
00506                 sep->str[sep->n] = '\0';
00507             }
00508             else
00509             {
00510                 safe_str("#-1 SEPARATOR IS TOO LARGE", buff, bufc);
00511                 bSuccess = false;
00512             }
00513         }
00514         else
00515         {
00516             safe_str("#-1 SEPARATOR MUST BE ONE CHARACTER", buff, bufc);
00517             bSuccess = false;
00518         }
00519 
00520         // Clean up the evaluation buffer.
00521         //
00522         if (dflags & DELIM_EVAL)
00523         {
00524             free_lbuf(tstr);
00525         }
00526     }
00527     else if (!(dflags & DELIM_INIT))
00528     {
00529         sep->n      = 1;
00530         memcpy(sep->str, " ", 2);
00531     }
00532     return bSuccess;
00533 }

void function_add ( FUN fp  ) 

Definition at line 8905 of file functions.cpp.

References alloc_sbuf, free_sbuf, statedata::func_htab, hashaddLEN(), mudstate, mux_strlwr(), tagFun::name, and safe_sb_str.

08906 {
08907     char *buff = alloc_sbuf("init_functab");
08908     char *bp = buff;
08909     safe_sb_str(fp->name, buff, &bp);
08910     *bp = '\0';
08911     mux_strlwr(buff);
08912     hashaddLEN(buff, strlen(buff), fp, &mudstate.func_htab);
08913     free_sbuf(buff);
08914 }

void functions_add ( FUN  funlist[]  ) 

Definition at line 8916 of file functions.cpp.

References alloc_sbuf, free_sbuf, statedata::func_htab, hashaddLEN(), mudstate, mux_strlwr(), tagFun::name, and safe_sb_str.

Referenced by init_functab(), and local_startup().

08917 {
08918     char *buff = alloc_sbuf("init_functab");
08919     for (FUN *fp = funlist; fp->name; fp++)
08920     {
08921         char *bp = buff;
08922         safe_sb_str(fp->name, buff, &bp);
08923         *bp = '\0';
08924         mux_strlwr(buff);
08925         hashaddLEN(buff, strlen(buff), fp, &mudstate.func_htab);
08926     }
08927     free_sbuf(buff);
08928 }

void init_functab ( void   ) 

Definition at line 8930 of file functions.cpp.

References builtin_function_list, functions_add(), and ufun_head.

Referenced by main().

08931 {
08932     functions_add(builtin_function_list);
08933     ufun_head = NULL;
08934 }

int list2arr ( char *  arr[],
int  maxlen,
char *  list,
SEP psep 
)

Definition at line 376 of file functions.cpp.

References split_token(), and trim_space_sep().

Referenced by FUNCTION(), handle_sets(), handle_vectors(), and real_regmatch().

00377 {
00378     list = trim_space_sep(list, psep);
00379     if (list[0] == '\0')
00380     {
00381         return 0;
00382     }
00383     char *p = split_token(&list, psep);
00384     int i;
00385     for (i = 0; p && i < maxlen; i++, p = split_token(&list, psep))
00386     {
00387         arr[i] = p;
00388     }
00389     return i;
00390 }

void list_functable ( dbref   ) 

Definition at line 9084 of file functions.cpp.

References alloc_lbuf, builtin_function_list, check_access(), LBUF_SIZE, tagFun::name, tagFun::perms, safe_chr, and safe_str.

Referenced by do_list().

09085 {
09086     char *buff = alloc_lbuf("list_functable");
09087     char *bp = buff;
09088 
09089     safe_str("Functions:", buff, &bp);
09090 
09091     FUN *fp;
09092     for (fp = builtin_function_list; fp->name && bp < buff + (LBUF_SIZE-1); fp++)
09093     {
09094         if (check_access(player, fp->perms))
09095         {
09096             safe_chr(' ', buff, &bp);
09097             safe_str(fp->name, buff, &bp);
09098         }
09099     }
09100     *bp = '\0';
09101     notify(player, buff);
09102 
09103     bp = buff;
09104     safe_str("User-Functions:", buff, &bp);
09105 
09106     UFUN *ufp;
09107     for (ufp = ufun_head; ufp && bp < buff + (LBUF_SIZE-1); ufp = ufp->next)
09108     {
09109         if (check_access(player, ufp->perms))
09110         {
09111             safe_chr(' ', buff, &bp);
09112             safe_str(ufp->name, buff, &bp);
09113         }
09114     }
09115     *bp = '\0';
09116     notify(player, buff);
09117     free_lbuf(buff);
09118 }

char* next_token ( char *  str,
SEP psep 
)

Definition at line 138 of file functions.cpp.

References SEP::n, and SEP::str.

Referenced by countwords(), and FUNCTION().

00139 {
00140     if (psep->n == 1)
00141     {
00142         while (  *str != '\0'
00143               && *str != psep->str[0])
00144         {
00145             str++;
00146         }
00147         if (!*str)
00148         {
00149             return NULL;
00150         }
00151         str++;
00152         if (psep->str[0] == ' ')
00153         {
00154             while (*str == ' ')
00155             {
00156                 str++;
00157             }
00158         }
00159     }
00160     else
00161     {
00162         char *p = strstr(str, psep->str);
00163         if (p)
00164         {
00165             str = p + psep->n;
00166         }
00167         else
00168         {
00169             return NULL;
00170         }
00171     }
00172     return str;
00173 }

char* split_token ( char **  sp,
SEP psep 
)

Definition at line 239 of file functions.cpp.

References SEP::n, and SEP::str.

Referenced by filter_handler(), FUNCTION(), list2arr(), and real_regrab().

00240 {
00241     char *str = *sp;
00242     char *save = str;
00243 
00244     if (!str)
00245     {
00246         *sp = NULL;
00247         return NULL;
00248     }
00249     if (psep->n == 1)
00250     {
00251         while (  *str
00252               && *str != psep->str[0])
00253         {
00254             str++;
00255         }
00256         if (*str)
00257         {
00258             *str++ = '\0';
00259             if (psep->str[0] == ' ')
00260             {
00261                 while (*str == ' ')
00262                 {
00263                     str++;
00264                 }
00265             }
00266         }
00267         else
00268         {
00269             str = NULL;
00270         }
00271     }
00272     else
00273     {
00274         char *p = strstr(str, psep->str);
00275         if (p)
00276         {
00277             *p = '\0';
00278             str = p + psep->n;
00279         }
00280         else
00281         {
00282             str = NULL;
00283         }
00284     }
00285     *sp = str;
00286     return save;
00287 }

char* trim_space_sep ( char *  str,
SEP psep 
)

Definition at line 67 of file functions.cpp.

References SEP::n, and SEP::str.

Referenced by countwords(), filter_handler(), FUNCTION(), list2arr(), and real_regrab().

00068 {
00069     if (  sep->n != 1
00070        || sep->str[0] != ' ')
00071     {
00072         return str;
00073     }
00074     while (*str == ' ')
00075     {
00076         str++;
00077     }
00078     char *p;
00079     for (p = str; *p; p++)
00080     {
00081         // Nothing.
00082     }
00083     for (p--; p > str && *p == ' '; p--)
00084     {
00085         // Nothing.
00086     }
00087     p++;
00088     *p = '\0';
00089     return str;
00090 }

char* trim_space_sep_LEN ( char *  str,
int  nStr,
SEP psep,
int *  nTrim 
)

Definition at line 33 of file functions.cpp.

References SEP::n, and SEP::str.

Referenced by do_itemfuns(), and FUNCTION().

00034 {
00035     if (  sep->n != 1
00036        || sep->str[0] != ' ')
00037     {
00038         *nTrim = nStr;
00039         return str;
00040     }
00041 
00042     // Advance over leading spaces.
00043     //
00044     char *pBegin = str;
00045     char *pEnd = str + nStr - 1;
00046     while (*pBegin == ' ')
00047     {
00048         pBegin++;
00049     }
00050 
00051     // Advance over trailing spaces.
00052     //
00053     for (; pEnd > pBegin && *pEnd == ' '; pEnd--)
00054     {
00055         // Nothing.
00056     }
00057     pEnd++;
00058 
00059     *pEnd = '\0';
00060     *nTrim = pEnd - pBegin;
00061     return pBegin;
00062 }

XFUNCTION ( fun_hasquota   ) 

XFUNCTION ( fun_poll   ) 

XFUNCTION ( fun_motd   ) 

XFUNCTION ( fun_host   ) 

XFUNCTION ( fun_doing   ) 

XFUNCTION ( fun_zwho   ) 

XFUNCTION ( fun_zone   ) 

XFUNCTION ( fun_zfun   ) 

XFUNCTION ( fun_visible   ) 

XFUNCTION ( fun_valid   ) 

XFUNCTION ( fun_unpack   ) 

XFUNCTION ( fun_udefault   ) 

XFUNCTION ( fun_translate   ) 

XFUNCTION ( fun_table   ) 

XFUNCTION ( fun_strtrunc   ) 

XFUNCTION ( fun_stripansi   ) 

XFUNCTION ( fun_strcat   ) 

XFUNCTION ( fun_squish   ) 

XFUNCTION ( fun_sortby   ) 

XFUNCTION ( fun_shuffle   ) 

XFUNCTION ( fun_scramble   ) 

XFUNCTION ( fun_regrabi   ) 

XFUNCTION ( fun_regraballi   ) 

XFUNCTION ( fun_regraball   ) 

XFUNCTION ( fun_regrab   ) 

XFUNCTION ( fun_regmatchi   ) 

XFUNCTION ( fun_regmatch   ) 

XFUNCTION ( fun_push   ) 

XFUNCTION ( fun_ports   ) 

XFUNCTION ( fun_pop   ) 

XFUNCTION ( fun_playmem   ) 

XFUNCTION ( fun_pickrand   ) 

XFUNCTION ( fun_peek   ) 

XFUNCTION ( fun_pack   ) 

XFUNCTION ( fun_orflags   ) 

XFUNCTION ( fun_objmem   ) 

XFUNCTION ( fun_objeval   ) 

XFUNCTION ( fun_null   ) 

XFUNCTION ( fun_munge   ) 

XFUNCTION ( fun_mix   ) 

XFUNCTION ( fun_matchall   ) 

XFUNCTION ( fun_mailfrom   ) 

XFUNCTION ( fun_mail   ) 

XFUNCTION ( fun_lstack   ) 

XFUNCTION ( fun_lrooms   ) 

XFUNCTION ( fun_lrand   ) 

XFUNCTION ( fun_lparent   ) 

XFUNCTION ( fun_localize   ) 

XFUNCTION ( fun_lit   ) 

XFUNCTION ( fun_last   ) 

XFUNCTION ( fun_items   ) 

XFUNCTION ( fun_isword   ) 

XFUNCTION ( fun_inzone   ) 

XFUNCTION ( fun_ifelse   ) 

XFUNCTION ( fun_hastype   ) 

XFUNCTION ( fun_hasattrp   ) 

XFUNCTION ( fun_hasattr   ) 

XFUNCTION ( fun_grepi   ) 

XFUNCTION ( fun_grep   ) 

XFUNCTION ( fun_graball   ) 

XFUNCTION ( fun_grab   ) 

XFUNCTION ( fun_foreach   ) 

XFUNCTION ( fun_findable   ) 

XFUNCTION ( fun_fdepth   ) 

XFUNCTION ( fun_fcount   ) 

XFUNCTION ( fun_entrances   ) 

XFUNCTION ( fun_encrypt   ) 

XFUNCTION ( fun_empty   ) 

XFUNCTION ( fun_elements   ) 

XFUNCTION ( fun_edefault   ) 

XFUNCTION ( fun_dumping   ) 

XFUNCTION ( fun_die   ) 

XFUNCTION ( fun_default   ) 

XFUNCTION ( fun_decrypt   ) 

XFUNCTION ( fun_cwho   ) 

XFUNCTION ( fun_columns   ) 

XFUNCTION ( fun_children   ) 

XFUNCTION ( fun_beep   ) 

XFUNCTION ( fun_ansi   ) 

XFUNCTION ( fun_andflags   ) 

XFUNCTION ( fun_alphamin   ) 

XFUNCTION ( fun_alphamax   ) 

XFUNCTION ( fun_comtitle   ) 

XFUNCTION ( fun_comalias   ) 

XFUNCTION ( fun_channels   ) 


Variable Documentation

SEP sepSpace

Definition at line 28 of file functions.cpp.

Referenced by FUNCTION().

UFUN* ufun_head

Definition at line 26 of file functions.cpp.

Referenced by dbclean_RenumberAttributes(), do_function(), and init_functab().


Generated on Mon May 28 04:40:18 2007 for MUX by  doxygen 1.4.7