Exemplo n.º 1
0
void do_shflag( char_data* ch, char* argument )
{
  shop_data*       shop;
  const char*  response;

  for( shop = shop_list; shop != NULL; shop = shop->next )
    if( ch->in_room == shop->room ) 
      break;  

  if( shop == NULL ) {
    send( ch, "This room has no shop entry.\r\n" );
    return;
    }

#define types 3

  const char*  title [types] = { "Basic", "Obj_Types", "Materials" };
  int            max [types] = { MAX_SHOP, MAX_ITEM, MAX_MATERIAL };

  const char** name1 [types] = { &shop_flags[0], &item_type_name[0],
    &material_name[0] };
  const char** name2 [types] = { &shop_flags[1], &item_type_name[1],
    &material_name[1] };

  int*    flag_value [types] = { &shop->flags, shop->buy_type,
    &shop->materials };
  int      uses_flag [types] = { 1, 1, 1 };

  response = flag_handler( title, name1, name2, flag_value, max,
    uses_flag, (const char*) NULL, ch, argument, types );

#undef types

  if( response == NULL ) 
    send( ch, "No such flag.\r\n" );
  else
    room_log( ch, ch->in_room->vnum, response );

  return;
}
/* PUBLIC */
Term read_commands(FILE *fin, FILE *fout, BOOL echo, int unknown_action)
{
  Term t = read_term(fin, fout);
  BOOL go = (t != NULL);

  while (go) {
    BOOL already_echoed = FALSE;
    /************************************************************ set, clear */
    if (is_term(t, "set", 1) || is_term(t, "clear", 1)) {
      if (echo) {
	fwrite_term_nl(fout, t);
	already_echoed = TRUE;
      }
      flag_handler(fout, t, unknown_action);
    }
    else if (is_term(t, "assign", 2)) {
      /************************************************************** assign */
      if (echo) {
	fwrite_term_nl(fout, t);
	already_echoed = TRUE;
      }
      parm_handler(fout, t, unknown_action);
    }
    else if (is_term(t, "assoc_comm", 1) ||
             is_term(t, "commutative", 1)) {
      /************************************************************ AC, etc. */
      Term f = ARG(t,0);
      if (!CONSTANT(f)) {
	bell(stderr);
	fwrite_term_nl(fout, t);
	fwrite_term_nl(stderr, t);
	fatal_error("argument must be symbol only");
      }
      else {
	if (is_term(t, "assoc_comm", 1))
	  set_assoc_comm(sn_to_str(SYMNUM(f)), TRUE);
	else
	  set_commutative(sn_to_str(SYMNUM(f)), TRUE);
      }
    }
    else if (is_term(t, "op", 3)) {
      /****************************************************************** op */
      /* e.g., op(300, infix, +); */
      Term prec_term = ARG(t,0);
      Term type_term = ARG(t,1);
      Term symb_term = ARG(t,2);
      int prec;
      BOOL ok = term_to_int(prec_term, &prec);
      if (!ok || prec < MIN_PRECEDENCE || prec > MAX_PRECEDENCE) {
	bell(stderr);
	fwrite_term_nl(fout, t);
	fwrite_term_nl(stderr, t);
	fatal_error("bad precedence in op command");
      }
      else if (proper_listterm(symb_term)) {
	while (cons_term(symb_term)) {
	  process_op(fout, t, prec, type_term, ARG(symb_term, 0));
	  symb_term = ARG(symb_term, 1);
	}
      }
      else
	process_op(fout, t, prec, type_term, symb_term);
    }
    else if (is_term(t, "lex", 1)) {
      /***************************************************************** lex */
      Plist p = listterm_to_tlist(ARG(t,0));
      if (p == NULL) {
	bell(stderr);
	fwrite_term_nl(fout, t);
	fwrite_term_nl(stderr, t);
	fatal_error("lex command must contain a proper list, e.g., [a,b,c]");
      }
      else {
	preliminary_precedence(p);
	zap_plist(p);
      }
    }
    else {
      /******************************************************** unrecognized */
      /* return this unknown term */
      go = FALSE;
    }

    if (go) {
      if (echo && !already_echoed)
	fwrite_term_nl(fout, t);
      zap_term(t);
      t = read_term(fin, fout);
      go = (t != NULL);
    }
  }
  return t;
}  /* read_commands */