src/p.functions.h File Reference

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

Go to the source code of this file.

Functions

char * trim_space_sep (char *str, int sep)
char * next_token (char *str, int sep)
char * split_token (char **sp, int sep)
dbref match_thing (dbref player, char *name)
int list2arr (char *arr[], int maxlen, char *list, int sep)
void arr2list (char *arr[], int alen, char *list, char **bufc, int sep)
int nearby_or_control (dbref player, dbref thing)
int fn_range_check (const char *fname, int nfargs, int minargs, int maxargs, char *result, char **bufc)
int delim_check (char *fargs[], int nfargs, int sep_arg, char *sep, char *buff, char **bufc, int eval, dbref player, dbref cause, char *cargs[], int ncargs)
int countwords (char *str, int sep)
time_t mytime (dbref player)
int do_convtime (char *str, struct tm *ttm)
char * get_uptime_to_string (int uptime)
char * get_uptime_to_short_string (int uptime)
int check_read_perms (dbref player, dbref thing, ATTR *attr, int aowner, int aflags, char *buff, char **bufc)
int xlate (char *arg)
void init_functab (void)
void do_function (dbref player, dbref cause, int key, char *fname, char *target)
void list_functable (dbref player)
int cf_func_access (int *vp, char *str, long extra, dbref player, char *cmd)


Function Documentation

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

int cf_func_access ( int *  vp,
char *  str,
long  extra,
dbref  player,
char *  cmd 
)

Definition at line 5985 of file functions.c.

References cf_modify_bits(), flist, fun::name, fun::perms, and string_compare().

05986 {
05987         FUN *fp;
05988         UFUN *ufp;
05989         char *ap;
05990 
05991         for(ap = str; *ap && !isspace(*ap); ap++);
05992         if(*ap)
05993                 *ap++ = '\0';
05994 
05995         for(fp = flist; fp->name; fp++) {
05996                 if(!string_compare(fp->name, str)) {
05997                         return (cf_modify_bits(&fp->perms, ap, extra, player, cmd));
05998                 }
05999         }
06000         for(ufp = ufun_head; ufp; ufp = ufp->next) {
06001                 if(!string_compare(ufp->name, str)) {
06002                         return (cf_modify_bits(&ufp->perms, ap, extra, player, cmd));
06003                 }
06004         }
06005         cf_log_notfound(player, cmd, "Function", str);
06006         return -1;
06007 }

int check_read_perms ( dbref  player,
dbref  thing,
ATTR attr,
int  aowner,
int  aflags,
char *  buff,
char **  bufc 
)

Get attribute from object.

Definition at line 1030 of file functions.c.

References A_DESC, attr, Examinable, mudconf, nearby(), attr::number, confdata::read_rem_desc, safe_str, See_All, See_attr, and See_attr_explicit.

01032 {
01033         int see_it;
01034 
01035         /*
01036          * If we have explicit read permission to the attr, return it 
01037          */
01038 
01039         if(See_attr_explicit(player, thing, attr, aowner, aflags))
01040                 return 1;
01041 
01042         /*
01043          * If we are nearby or have examine privs to the attr and it is * * * 
01044          * 
01045          * * visible to us, return it. 
01046          */
01047 
01048         see_it = See_attr(player, thing, attr, aowner, aflags);
01049         if((Examinable(player, thing) || nearby(player, thing) ||
01050                 See_All(player)) && see_it)
01051                 return 1;
01052 
01053         /*
01054          * For any object, we can read its visible attributes, EXCEPT * for * 
01055          * 
01056          * *  * * descs, which are only visible if read_rem_desc is on. 
01057          */
01058 
01059         if(see_it) {
01060                 if(!mudconf.read_rem_desc && (attr->number == A_DESC)) {
01061                         safe_str("#-1 TOO FAR AWAY TO SEE", buff, bufc);
01062                         return 0;
01063                 } else {
01064                         return 1;
01065                 }
01066         }
01067         safe_str("#-1 PERMISSION DENIED", buff, bufc);
01068         return 0;
01069 }

int countwords ( char *  str,
int  sep 
)

int delim_check ( char *  fargs[],
int  nfargs,
int  sep_arg,
char *  sep,
char *  buff,
char **  bufc,
int  eval,
dbref  player,
dbref  cause,
char *  cargs[],
int  ncargs 
)

* delim_check: obtain delimiter

Definition at line 489 of file functions.c.

References alloc_lbuf, EV_EVAL, EV_FCHECK, exec(), free_lbuf, and safe_str.

00492 {
00493         char *tstr, *bp, *str;
00494         int tlen;
00495 
00496         if(nfargs >= sep_arg) {
00497                 tlen = strlen(fargs[sep_arg - 1]);
00498                 if(tlen <= 1)
00499                         eval = 0;
00500                 if(eval) {
00501                         tstr = bp = alloc_lbuf("delim_check");
00502                         str = fargs[sep_arg - 1];
00503                         exec(tstr, &bp, 0, player, cause, EV_EVAL | EV_FCHECK, &str,
00504                                  cargs, ncargs);
00505                         *bp = '\0';
00506                         tlen = strlen(tstr);
00507                         *sep = *tstr;
00508                         free_lbuf(tstr);
00509                 }
00510                 if(tlen == 0) {
00511                         *sep = ' ';
00512                 } else if(tlen != 1) {
00513                         safe_str("#-1 SEPARATOR MUST BE ONE CHARACTER", buff, bufc);
00514                         return 0;
00515                 } else if(!eval) {
00516                         *sep = *fargs[sep_arg - 1];
00517                 }
00518         } else {
00519                 *sep = ' ';
00520         }
00521         return 1;
00522 }

int do_convtime ( char *  str,
struct tm *  ttm 
)

Definition at line 732 of file functions.c.

References alloc_sbuf, daystab, free_sbuf, get_substr, LEAPYEAR_1900, monthtab, safe_sb_str, and string_compare().

Referenced by check_mail_expiration(), fun_convtime(), and mail_match().

00733 {
00734         char *buf, *p, *q;
00735         int i;
00736 
00737         if(!str || !ttm)
00738                 return 0;
00739         while (*str == ' ')
00740                 str++;
00741         buf = p = alloc_sbuf("do_convtime");    /*
00742                                                                                          * make a temp copy of arg 
00743                                                                                          */
00744         safe_sb_str(str, buf, &p);
00745         *p = '\0';
00746 
00747         get_substr(buf, p);                     /*
00748                                                                  * day-of-week or month 
00749                                                                  */
00750         if(!p || strlen(buf) != 3) {
00751                 free_sbuf(buf);
00752                 return 0;
00753         }
00754         for(i = 0; (i < 12) && string_compare(monthtab[i], p); i++);
00755         if(i == 12) {
00756                 get_substr(p, q);               /*
00757                                                                  * month 
00758                                                                  */
00759                 if(!q || strlen(p) != 3) {
00760                         free_sbuf(buf);
00761                         return 0;
00762                 }
00763                 for(i = 0; (i < 12) && string_compare(monthtab[i], p); i++);
00764                 if(i == 12) {
00765                         free_sbuf(buf);
00766                         return 0;
00767                 }
00768                 p = q;
00769         }
00770         ttm->tm_mon = i;
00771 
00772         get_substr(p, q);                       /*
00773                                                                  * day of month 
00774                                                                  */
00775         if(!q || (ttm->tm_mday = atoi(p)) < 1 || ttm->tm_mday > daystab[i]) {
00776                 free_sbuf(buf);
00777                 return 0;
00778         }
00779         p = (char *) index(q, ':');     /*
00780                                                                  * hours 
00781                                                                  */
00782         if(!p) {
00783                 free_sbuf(buf);
00784                 return 0;
00785         }
00786         *p++ = '\0';
00787         if((ttm->tm_hour = atoi(q)) > 23 || ttm->tm_hour < 0) {
00788                 free_sbuf(buf);
00789                 return 0;
00790         }
00791         if(ttm->tm_hour == 0) {
00792                 while (isspace(*q))
00793                         q++;
00794                 if(*q != '0') {
00795                         free_sbuf(buf);
00796                         return 0;
00797                 }
00798         }
00799         q = (char *) index(p, ':');     /*
00800                                                                  * minutes 
00801                                                                  */
00802         if(!q) {
00803                 free_sbuf(buf);
00804                 return 0;
00805         }
00806         *q++ = '\0';
00807         if((ttm->tm_min = atoi(p)) > 59 || ttm->tm_min < 0) {
00808                 free_sbuf(buf);
00809                 return 0;
00810         }
00811         if(ttm->tm_min == 0) {
00812                 while (isspace(*p))
00813                         p++;
00814                 if(*p != '0') {
00815                         free_sbuf(buf);
00816                         return 0;
00817                 }
00818         }
00819         get_substr(q, p);                       /*
00820                                                                  * seconds 
00821                                                                  */
00822         if(!p || (ttm->tm_sec = atoi(q)) > 59 || ttm->tm_sec < 0) {
00823                 free_sbuf(buf);
00824                 return 0;
00825         }
00826         if(ttm->tm_sec == 0) {
00827                 while (isspace(*q))
00828                         q++;
00829                 if(*q != '0') {
00830                         free_sbuf(buf);
00831                         return 0;
00832                 }
00833         }
00834         get_substr(p, q);                       /*
00835                                                                  * year 
00836                                                                  */
00837         if((ttm->tm_year = atoi(p)) == 0) {
00838                 while (isspace(*p))
00839                         p++;
00840                 if(*p != '0') {
00841                         free_sbuf(buf);
00842                         return 0;
00843                 }
00844         }
00845         free_sbuf(buf);
00846         if(ttm->tm_year > 100)
00847                 ttm->tm_year -= 1900;
00848         if(ttm->tm_year < 0) {
00849                 return 0;
00850         }
00851 #define LEAPYEAR_1900(yr) ((yr)%400==100||((yr)%100!=0&&(yr)%4==0))
00852         return (ttm->tm_mday != 29 || i != 1 || LEAPYEAR_1900(ttm->tm_year));
00853 #undef LEAPYEAR_1900
00854 }

void do_function ( dbref  player,
dbref  cause,
int  key,
char *  fname,
char *  target 
)

Definition at line 5831 of file functions.c.

References alloc_sbuf, free_sbuf, statedata::func_htab, hashfind(), mudstate, notify_quiet, safe_sb_str, and ToLower.

05833 {
05834         UFUN *ufp, *ufp2;
05835         ATTR *ap;
05836         char *np, *bp;
05837         int atr, aflags;
05838         dbref obj, aowner;
05839 
05840         /*
05841          * Make a local uppercase copy of the function name 
05842          */
05843 
05844         bp = np = alloc_sbuf("add_user_func");
05845         safe_sb_str(fname, np, &bp);
05846         *bp = '\0';
05847         for(bp = np; *bp; bp++)
05848                 *bp = ToLower(*bp);
05849 
05850         /*
05851          * Verify that the function doesn't exist in the builtin table 
05852          */
05853 
05854         if(hashfind(np, &mudstate.func_htab) != NULL) {
05855                 notify_quiet(player,
05856                                          "Function already defined in builtin function table.");
05857                 free_sbuf(np);
05858                 return;
05859         }
05860         /*
05861          * Make sure the target object exists 
05862          */
05863 
05864         if(!parse_attrib(player, target, &obj, &atr)) {
05865                 notify_quiet(player, "I don't see that here.");
05866                 free_sbuf(np);
05867                 return;
05868         }
05869         /*
05870          * Make sure the attribute exists 
05871          */
05872 
05873         if(atr == NOTHING) {
05874                 notify_quiet(player, "No such attribute.");
05875                 free_sbuf(np);
05876                 return;
05877         }
05878         /*
05879          * Make sure attribute is readably by me 
05880          */
05881 
05882         ap = atr_num(atr);
05883         if(!ap) {
05884                 notify_quiet(player, "No such attribute.");
05885                 free_sbuf(np);
05886                 return;
05887         }
05888         atr_get_info(obj, atr, &aowner, &aflags);
05889         if(!See_attr(player, obj, ap, aowner, aflags)) {
05890                 notify_quiet(player, "Permission denied.");
05891                 free_sbuf(np);
05892                 return;
05893         }
05894         /*
05895          * Privileged functions require you control the obj.  
05896          */
05897 
05898         if((key & FN_PRIV) && !Controls(player, obj)) {
05899                 notify_quiet(player, "Permission denied.");
05900                 free_sbuf(np);
05901                 return;
05902         }
05903         /*
05904          * See if function already exists.  If so, redefine it 
05905          */
05906 
05907         ufp = (UFUN *) hashfind(np, &mudstate.ufunc_htab);
05908 
05909         if(!ufp) {
05910                 ufp = (UFUN *) malloc(sizeof(UFUN));
05911                 ufp->name = strsave(np);
05912                 for(bp = (char *) ufp->name; *bp; bp++)
05913                         *bp = ToUpper(*bp);
05914                 ufp->obj = obj;
05915                 ufp->atr = atr;
05916                 ufp->perms = CA_PUBLIC;
05917                 ufp->next = NULL;
05918                 if(!ufun_head) {
05919                         ufun_head = ufp;
05920                 } else {
05921                         for(ufp2 = ufun_head; ufp2->next; ufp2 = ufp2->next);
05922                         ufp2->next = ufp;
05923                 }
05924                 hashadd(np, (int *) ufp, &mudstate.ufunc_htab);
05925         }
05926         ufp->obj = obj;
05927         ufp->atr = atr;
05928         ufp->flags = key;
05929         free_sbuf(np);
05930         if(!Quiet(player)) {
05931         char buffer[MBUF_SIZE];
05932         snprintf(buffer, MBUF_SIZE - 1, "Function %s defined.", fname);
05933         notify_quiet(player, buffer);
05934     }
05935 }

int fn_range_check ( const char *  fname,
int  nfargs,
int  minargs,
int  maxargs,
char *  result,
char **  bufc 
)

Check # of args to a function with an optional argument for validity.

Definition at line 469 of file functions.c.

References safe_tprintf_str().

00471 {
00472         if((nfargs >= minargs) && (nfargs <= maxargs))
00473                 return 1;
00474 
00475         if(maxargs == (minargs + 1))
00476                 safe_tprintf_str(result, bufc,
00477                                                  "#-1 FUNCTION (%s) EXPECTS %d OR %d ARGUMENTS",
00478                                                  fname, minargs, maxargs);
00479         else
00480                 safe_tprintf_str(result, bufc,
00481                                                  "#-1 FUNCTION (%s) EXPECTS BETWEEN %d AND %d ARGUMENTS",
00482                                                  fname, minargs, maxargs);
00483         return 0;
00484 }

char* get_uptime_to_short_string ( int  uptime  ) 

Definition at line 932 of file functions.c.

References alloc_sbuf, multip, sname, uptime_unit_table, and UPTIME_UNITS.

00933 {
00934         char *buf = alloc_sbuf("get_uptime_to_string");
00935         int units[UPTIME_UNITS];
00936         int taim = uptime;
00937         int ut = 0, uc = 0, foofaa;
00938 
00939         if(uptime <= 0) {
00940                 strcpy(buf, "#-1 INVALID VALUE");
00941                 return buf;
00942         }
00943         for(ut = 0; ut < UPTIME_UNITS; ut++)
00944                 units[ut] = 0;
00945         ut = 0;
00946         buf[0] = 0;
00947         while (taim > 0) {
00948                 if((foofaa = (taim / uptime_unit_table[ut].multip)) > 0) {
00949                         uc++;
00950                         units[ut] = foofaa;
00951                         taim -= uptime_unit_table[ut].multip * foofaa;
00952                 }
00953                 ut++;
00954         }
00955         /*
00956          * Now, we got it..
00957          */
00958         for(ut = 0; ut < UPTIME_UNITS; ut++) {
00959                 if(units[ut]) {
00960                         uc--;
00961                         if(units[ut] > 1)
00962                                 sprintf(buf + strlen(buf), "%d%s", units[ut],
00963                                                 uptime_unit_table[ut].sname);
00964                         else
00965                                 sprintf(buf + strlen(buf), "%d%s", units[ut],
00966                                                 uptime_unit_table[ut].sname);
00967                         if(uc > 0)
00968                                 strcat(buf, " ");
00969                 }
00970         }
00971         return buf;
00972 }

char* get_uptime_to_string ( int  uptime  ) 

Definition at line 888 of file functions.c.

References alloc_sbuf, multip, name, uptime_unit_table, and UPTIME_UNITS.

Referenced by do_comwho(), fun_convuptime(), and silly_get_uptime_to_string().

00889 {
00890         char *buf = alloc_sbuf("get_uptime_to_string");
00891         int units[UPTIME_UNITS];
00892         int taim = uptime;
00893         int ut = 0, uc = 0, foofaa;
00894 
00895         if(uptime <= 0) {
00896                 strcpy(buf, "#-1 INVALID VALUE");
00897                 return buf;
00898         }
00899         for(ut = 0; ut < UPTIME_UNITS; ut++)
00900                 units[ut] = 0;
00901         ut = 0;
00902         buf[0] = 0;
00903         while (taim > 0) {
00904                 if((foofaa = (taim / uptime_unit_table[ut].multip)) > 0) {
00905                         uc++;
00906                         units[ut] = foofaa;
00907                         taim -= uptime_unit_table[ut].multip * foofaa;
00908                 }
00909                 ut++;
00910         }
00911         /*
00912          * Now, we got it..
00913          */
00914         for(ut = 0; ut < UPTIME_UNITS; ut++) {
00915                 if(units[ut]) {
00916                         uc--;
00917                         if(units[ut] > 1)
00918                                 sprintf(buf + strlen(buf), "%d %ss", units[ut],
00919                                                 uptime_unit_table[ut].name);
00920                         else
00921                                 sprintf(buf + strlen(buf), "%d %s", units[ut],
00922                                                 uptime_unit_table[ut].name);
00923                         if(uc > 1)
00924                                 strcat(buf, ", ");
00925                         else if(uc > 0)
00926                                 strcat(buf, " and ");
00927                 }
00928         }
00929         return buf;
00930 }

void init_functab ( void   ) 

Definition at line 5808 of file functions.c.

References alloc_sbuf, flist, free_sbuf, statedata::func_htab, HASH_FACTOR, hashadd(), hashinit(), mudstate, fun::name, ToLower, ufun_head, and statedata::ufunc_htab.

Referenced by main().

05809 {
05810         FUN *fp;
05811         char *buff, *cp, *dp;
05812 
05813         buff = alloc_sbuf("init_functab");
05814         hashinit(&mudstate.func_htab, 100 * HASH_FACTOR);
05815         for(fp = flist; fp->name; fp++) {
05816                 cp = (char *) fp->name;
05817                 dp = buff;
05818                 while (*cp) {
05819                         *dp = ToLower(*cp);
05820                         cp++;
05821                         dp++;
05822                 }
05823                 *dp = '\0';
05824                 hashadd(buff, (int *) fp, &mudstate.func_htab);
05825         }
05826         free_sbuf(buff);
05827         ufun_head = NULL;
05828         hashinit(&mudstate.ufunc_htab, 11);
05829 }

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

void list_functable ( dbref  player  ) 

Definition at line 5942 of file functions.c.

References alloc_lbuf, check_access(), flist, fun::name, and fun::perms.

Referenced by do_list().

05943 {
05944         FUN *fp;
05945         UFUN *ufp;
05946         char *buf, *bp, *cp;
05947 
05948         buf = alloc_lbuf("list_functable");
05949         bp = buf;
05950 
05951         /* Hardcoded Functions */
05952         for(cp = (char *) "Functions:"; *cp; cp++)
05953                 *bp++ = *cp;
05954         for(fp = flist; fp->name; fp++) {
05955                 if(check_access(player, fp->perms)) {
05956                         *bp++ = ' ';
05957                         for(cp = (char *) (fp->name); *cp; cp++)
05958                                 *bp++ = *cp;
05959                 }
05960         }
05961         *bp = '\0';
05962         notify(player, buf);
05963 
05964         /* User-Defined functions (via @function) */
05965         bp = buf;
05966         safe_str("User-Functions:", buf, &bp);
05967 
05968         for(ufp = ufun_head; ufp; ufp = ufp->next) {
05969                 if(check_access(player, ufp->perms)) {
05970                         *bp++ = ' ';
05971                         for(cp = (char *) (ufp->name); *cp; cp++)
05972                                 *bp++ = *cp;
05973                 }
05974         }
05975         *bp = '\0';
05976         notify(player, buf);
05977         free_lbuf(buf);
05978 }

dbref match_thing ( dbref  player,
char *  name 
)

Definition at line 289 of file functions.c.

00290 {
00291         init_match(player, name, NOTYPE);
00292         match_everything(MAT_EXIT_PARENTS);
00293         return (noisy_match_result());
00294 }

time_t mytime ( dbref  player  ) 

Definition at line 625 of file functions.c.

References A_TZ, mudstate, statedata::now, and silly_atr_get().

00626 {
00627         struct timeval tv;
00628         struct timezone tz;
00629         char *tzstr;
00630         int hours, dst;
00631 
00632         tzstr = silly_atr_get(player, A_TZ);
00633         if(sscanf(tzstr, "%d:%d", &hours, &dst) < 2)
00634                 return mudstate.now;
00635         tz.tz_minuteswest = (0 - hours) * 60;
00636         tz.tz_dsttime = dst;
00637         gettimeofday(&tv, &tz);
00638         return tv.tv_sec;
00639 }

int nearby_or_control ( dbref  player,
dbref  thing 
)

Check if player is near or controls thing

Definition at line 421 of file functions.c.

References Controls, Good_obj, and nearby().

Referenced by fun_elock(), fun_fullname(), fun_name(), fun_nearby(), and process_sex().

00422 {
00423         if(!Good_obj(player) || !Good_obj(thing))
00424                 return 0;
00425         if(Controls(player, thing))
00426                 return 1;
00427         if(!nearby(player, thing))
00428                 return 0;
00429         return 1;
00430 }

char* next_token ( char *  str,
int  sep 
)

char* split_token ( char **  sp,
int  sep 
)

char* trim_space_sep ( char *  str,
int  sep 
)

int xlate ( char *  arg  ) 

Definition at line 2030 of file functions.c.

References is_integer(), and trim_space_sep().

02031 {
02032         int temp;
02033         char *temp2;
02034 
02035         if(arg[0] == '#') {
02036                 arg++;
02037                 /* #- anything is false */
02038                 if(arg[1] == '-') {
02039                         return 0;
02040                 }
02041                 if(is_integer(arg)) {
02042                         temp = atoi(arg);
02043                         if(temp == -1)
02044                                 temp = 0;
02045                         return temp;
02046                 }
02047                 return 0;
02048         }
02049         temp2 = trim_space_sep(arg, ' ');
02050         if(!*temp2)
02051                 return 0;
02052         if(is_integer(temp2))
02053                 return atoi(temp2);
02054         return 1;
02055 }


Generated on Mon May 28 04:25:47 2007 for BattletechMUX by  doxygen 1.4.7