PennMUSH Community

Changeset 939

Show
Ignore:
Timestamp:
06/14/07 14:21:29 (1 year ago)
Author:
walker
Message:

Added cond() and friends.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 1.8.3/branches/devel/game/txt/hlp/pennfunc.hlp

    r934 r939  
    755755 
    756756See also: lcon(), next() 
     757& COND() 
     758& CONDALL() 
     759& NCOND() 
     760& NCONDALL() 
     761  cond(<cond1>, <expr1>, [<condN>, <exprN>], ...[<default>]) 
     762  condall(<cond1>, <expr1>, [<condN>, <exprN>], ...[<default>]) 
     763  ncond(<cond1>, <expr1>, [<condN>, <exprN>], ...[<default>]) 
     764  ncondall(<cond1>, <expr1>, [<condN>, <exprN>], ...[<default>]) 
     765 
     766  cond() evaluates <cond>s until one returns a boolean true value. Should 
     767  none return true, <default> is returned. 
     768 
     769  condall() returns all <expr>s for those <cond>s that evaluate to true. 
     770 
     771  ncond() and ncondall() are identical to cond(), except it returns <expr>s 
     772  for which <cond>s evaluate to false. 
     773 
     774  Examples: 
     775  > say cond(0,This is false,#-1,This is also false,#123,This is true) 
     776  You say, "This is true" 
     777 
     778  > say ncond(0,This is false,#-1,This is also false,#123,This is true) 
     779  You say, "This is false" 
     780   
     781  > say ncondall(0,This is false,#-1,This is also false,#123,This is true) 
     782  You say, "This is falseThis is also false" 
    757783& CONFIG() 
    758784  config() 
  • 1.8.3/branches/devel/src/function.c

    r909 r939  
    351351  {"COMP", fun_comp, 2, 3, FN_REG}, 
    352352  {"CON", fun_con, 1, 1, FN_REG}, 
     353  {"COND", fun_if, 2, INT_MAX, FN_NOPARSE}, 
     354  {"CONDALL", fun_if, 2, INT_MAX, FN_NOPARSE}, 
    353355  {"CONFIG", fun_config, 1, 1, FN_REG}, 
    354356  {"CONN", fun_conn, 1, 1, FN_REG}, 
     
    529531  {"NCHILDREN", fun_lsearch, 1, 1, FN_REG}, 
    530532  {"NCON", fun_dbwalker, 1, 1, FN_REG}, 
     533  {"NCOND", fun_if, 2, INT_MAX, FN_NOPARSE}, 
     534  {"NCONDALL", fun_if, 2, INT_MAX, FN_NOPARSE}, 
    531535  {"NEXITS", fun_dbwalker, 1, 1, FN_REG}, 
    532536  {"NPLAYERS", fun_dbwalker, 1, 1, FN_REG}, 
  • 1.8.3/branches/devel/src/funmisc.c

    r937 r939  
    508508  char tbuf[BUFFER_LEN], *tp; 
    509509  char const *sp; 
    510  
    511   tp = tbuf; 
    512   sp = args[0]; 
    513   process_expression(tbuf, &tp, &sp, executor, caller, enactor, 
    514                      PE_DEFAULT, PT_DEFAULT, pe_info); 
    515   *tp = '\0'; 
    516   if (parse_boolean(tbuf)) { 
    517     sp = args[1]; 
    518     process_expression(buff, bp, &sp, executor, caller, enactor, 
     510  /* Since this may be used as COND(), NCOND(), CONDALL() or NCONDALL, 
     511   * we check for that. */ 
     512  int findtrue = 1; 
     513  int findall = 0; 
     514  int found = 0; 
     515  int i; 
     516 
     517  if (called_as[0] == 'N') 
     518    findtrue = 0; 
     519 
     520  if (strstr(called_as,"ALL")) 
     521    findall = 1; 
     522  
     523  for (i = 0 ; i < nargs-1 ; i += 2) { 
     524    tp = tbuf; 
     525    sp = args[i]; 
     526    process_expression(tbuf, &tp, &sp, executor, caller, enactor, 
    519527                       PE_DEFAULT, PT_DEFAULT, pe_info); 
    520   } else if (nargs > 2) { 
    521     sp = args[2]; 
     528    *tp = '\0'; 
     529    if (parse_boolean(tbuf) == findtrue) { 
     530      sp = args[i+1]; 
     531      process_expression(buff, bp, &sp, executor, caller, enactor, 
     532                         PE_DEFAULT, PT_DEFAULT, pe_info); 
     533      if (!findall) return; 
     534      found = 1; 
     535    } 
     536  } 
     537  /* If we've found no true case, run the default if it exists. */ 
     538  if (!found && (nargs & 1)) { 
     539    sp = args[nargs - 1]; 
    522540    process_expression(buff, bp, &sp, executor, caller, enactor, 
    523541                       PE_DEFAULT, PT_DEFAULT, pe_info);