PennMUSH Community

Changeset 833

Show
Ignore:
Timestamp:
05/08/07 21:20:11 (2 years ago)
Author:
shawnw
Message:

expr: #7321: Use a ptab for command switches.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 1.8.3/branches/experimental/hdrs/game.h

    r832 r833  
    2020extern void init_flag_table(const char *ns);    /* flags.c */ 
    2121extern void init_pronouns(void);    /* funstr.c */ 
     22void init_switches(void); /* command.c */ 
    2223 
    2324/* From bsd.c */ 
  • 1.8.3/branches/experimental/src/command.c

    r803 r833  
    4040PTAB ptab_command;  /**< Prefix table for command names. */ 
    4141PTAB ptab_command_perms;    /**< Prefix table for command permissions */ 
     42PTAB ptab_switches; /**< Prefix table for command switches. */ 
    4243 
    4344HASHTAB htab_reserved_aliases;  /**< Hash table for reserved command aliases */ 
     
    367368#include "switchinc.c" 
    368369 
     370void 
     371init_switches(void) { 
     372  SWITCH_VALUE *v; 
     373   
     374  ptab_init(&ptab_switches); 
     375 
     376  ptab_start_inserts(&ptab_switches); 
     377  for (v = switch_list; v->name; v++) 
     378    ptab_insert(&ptab_switches,  v->name, v); 
     379  ptab_end_inserts(&ptab_switches); 
     380} 
     381 
    369382/** Table of command permissions/restrictions. */ 
    370383struct command_perms_t command_perms[] = { 
     
    404417  safe_str(from, buff, bp); 
    405418} 
     419 
    406420static int 
    407421switch_find(COMMAND_INFO *cmd, char *sw) 
    408422{ 
    409423  SWITCH_VALUE *sw_val; 
    410   int i = 0; 
    411   int len; 
     424 
    412425  if (!sw || !*sw) 
    413426    return 0; 
    414   len = strlen(sw); 
     427 
    415428  /* Special case, for init */ 
    416   sw_val = switch_list; 
    417429  if (!cmd) { 
    418     while (sw_val->name) { 
    419       if (strcmp(sw_val->name, sw) == 0) 
    420     return sw_val->value; 
    421       sw_val++; 
    422     } 
    423     return 0; 
     430    sw_val = ptab_find_exact(&ptab_switches, sw); 
     431    if (sw_val) 
     432      return sw_val->value; 
     433    else 
     434      return 0; 
    424435  } else { 
    425     while (sw_val->name) { 
    426       i++; 
    427       if (SW_ISSET(cmd->sw, i) && (strncmp(sw_val->name, sw, len) == 0)) 
    428     return i; 
    429       sw_val++; 
    430     } 
    431   } 
    432   return 0; 
     436    sw_val = ptab_find(&ptab_switches, sw); 
     437    if (sw_val && SW_ISSET(cmd->sw, sw_val->value)) 
     438      return sw_val->value; 
     439    else 
     440      return 0; 
     441  } 
    433442} 
    434443 
  • 1.8.3/branches/experimental/src/game.c

    r832 r833  
    733733  init_names(); 
    734734  init_pronouns(); 
     735  init_switches(); 
    735736 
    736737  memset(&current_state, 0, sizeof current_state); 
     
    23342335extern PTAB ptab_attrib; 
    23352336extern PTAB ptab_flag; 
     2337extern PTAB ptab_switches; 
    23362338 
    23372339/** Reports stats on various in-memory data structures. 
     
    23552357  ptab_stats(player, &ptab_command, "Commands"); 
    23562358  ptab_stats(player, &ptab_flag, "Flags"); 
     2359  ptab_stats(player, &ptab_switches, "Switches"); 
    23572360  notify(player, "String Trees:"); 
    23582361  st_stats_header(player);