Esempio n. 1
0
/*
 * set_var_value: Given the variable structure and the string representation
 * of the value, this sets the value in the most verbose and error checking
 * of manors.  It displays the results of the set and executes the function
 * defined in the var structure 
 */
int 	set_variable (const char *name, IrcVariable *var, const char *orig_value, int noisy)
{
	char	*rest;
	int	changed = 0;
	unsigned char	*value;
	int	retval = 0;

	if (orig_value)
		value = LOCAL_COPY(orig_value);
	else
		value = NULL;

	switch (var->type)
	{
	    case BOOL_VAR:
	    {
		if (value && *value && (value = next_arg(value, &rest)))
		{
			if (do_boolean(value, &(var->data->integer))) {
			    say("Value must be either ON, OFF, or TOGGLE");
			    retval = -1;
			}
			else
			    changed = 1;
		}
		break;
	    }

	    case CHAR_VAR:
	    {
		int	codepoint;

		if (!value || !*value)
		{
			var->data->integer = ' ';
			changed = 1;
			break;
		}

		if ((codepoint = next_code_point((const unsigned char **)&value, 0)) == -1)
		{
			say("New value of %s could not be determined", name);
			retval = -1;
			break;
		}

		if (codepoint_numcolumns(codepoint) != 1)
		{
			say("New value of %s must be exactly 1 column wide", name);
			retval = -1;
			break;
		}

		var->data->integer = codepoint;
		changed = 1;
		break;
	    }

	    case INT_VAR:
	    {
		if (value && *value && (value = next_arg(value, &rest)))
		{
			int	val;

			if (!is_number(value)) {
			    say("Value of %s must be numeric!", name);
			    retval = -1;
			} else if ((val = my_atol(value)) < 0) {
			    say("Value of %s must be a non-negative number", 
					name);
			    retval = -1;
			} else {
			    var->data->integer = val;
			    changed = 1;
			}
		}
		break;
	    }

	    case STR_VAR:
	    {
		if (!value)
		{
			new_free(&(var->data->string));
			changed = 1;
		}
		else if (*value)
		{
			malloc_strcpy(&(var->data->string), value);
			changed = 1;
		}
	    }
	}

	if (changed)
	{
	    if ((var->func || var->script) && !(var->flags & VIF_PENDING))
	    {
		var->flags |= VIF_PENDING;
		if (var->func)
		    (var->func)(var->data);
		if (var->script)
		{
		    char *s;
		    int owd = window_display;

		    s = make_string_var_bydata(var->type, (void *)var->data);
		    window_display = 0;
		    call_lambda_command("SET", var->script, s);
		    window_display = owd;
		    new_free(&s);
		}
		var->flags &= ~VIF_PENDING;
	    }
	}

	if (noisy)
	    show_var_value(name, var, changed);

	return retval;
}
Esempio n. 2
0
void parse_note( CHAR_DATA *ch, char *argument, int type )
{
	char arg[MAX_INPUT_LENGTH];
	NOTE_DATA *pnote;
	NOTE_DATA **list;
	char *list_name;
	int vnum = 0;
	int anum = 0;

	if ( IS_NPC(ch) )
		return;

	switch(type)
	{
		default:
		return;
		case NOTE_NOTE:
		list = &note_list;
		list_name = "notes";
		break;
		case NOTE_IDEA:
		list = &idea_list;
		list_name = "ideas";
		break;
		case NOTE_PENALTY:
		list = &penalty_list;
		list_name = "penalties";
		break;
		case NOTE_NEWS:
		list = &news_list;
		list_name = "news";
		break;
		case NOTE_CHANGES:
		list = &changes_list;
		list_name = "changes";
		break;
	}

	argument = one_argument( argument, arg );
	smash_tilde( argument );

	if ( arg[0] == '\0' || !str_prefix( arg, "read" ) )
	{
		bool fAll;

		if ( !str_cmp( argument, "all" ) )
		{
			fAll = TRUE;
			anum = 0;
		}

		else if ( argument[0] == '\0' || !str_prefix(argument, "next"))
		/* read next unread note */
		{
			vnum = 0;
			for ( pnote = *list; pnote != NULL; pnote = pnote->next)
			{
				if (!hide_note(ch,pnote))
				{
					send_to_char( Format("[%3d] %s: %s\n\r%s\n\rTo: %s\n\r",
						vnum,
						pnote->sender,
						pnote->subject,
						pnote->date,
						pnote->to_list), ch );
					page_to_char( pnote->text, ch );
					update_read(ch,pnote);
					return;
				}
				else if (is_note_to(ch,pnote))
					vnum++;
			}
			send_to_char( Format("You have no unread %s.\n\r",list_name),ch);
			return;
		}

		else if ( is_number( argument ) )
		{
			fAll = FALSE;
			anum = atoi( argument );
		}
		else
		{
			send_to_char( "Read which number?\n\r", ch );
			return;
		}

		vnum = 0;
		for ( pnote = *list; pnote != NULL; pnote = pnote->next )
		{
			if ( is_note_to( ch, pnote ) && ( vnum++ == anum || fAll ) )
			{
				send_to_char( Format("[%3d] %s: %s\n\r%s\n\rTo: %s\n\r",
					vnum - 1,
					pnote->sender,
					pnote->subject,
					pnote->date,
					pnote->to_list), ch );
				page_to_char( pnote->text, ch );
				update_read(ch,pnote);
				return;
			}
		}

		send_to_char( Format("There aren't that many %s.\n\r",list_name),ch);
		return;
	}

	if ( !str_prefix( arg, "list" ) )
	{
		vnum = 0;
		for ( pnote = *list; pnote != NULL; pnote = pnote->next )
		{
			if ( is_note_to( ch, pnote ) )
			{
				send_to_char( Format("[%3d%s] %s: %s\n\r",
					vnum, hide_note(ch,pnote) ? " " : "N", 
					pnote->sender, pnote->subject), ch );
				vnum++;
			}
		}
		if (!vnum)
		{
			switch(type)
			{
				case NOTE_NOTE:	
				send_to_char("There are no notes for you.\n\r",ch);
				break;
				case NOTE_IDEA:
				send_to_char("There are no ideas for you.\n\r",ch);
				break;
				case NOTE_PENALTY:
				send_to_char("There are no penalties for you.\n\r",ch);
				break;
				case NOTE_NEWS:
				send_to_char("There is no news for you.\n\r",ch);
				break;
				case NOTE_CHANGES:
				send_to_char("There are no changes for you.\n\r",ch);
				break;
			}
		}
		return;
	}

	if ( !str_prefix( arg, "remove" ) )
	{
		if ( !is_number( argument ) )
		{
			send_to_char( "Note remove which number?\n\r", ch );
			return;
		}

		anum = atoi( argument );
		vnum = 0;
		for ( pnote = *list; pnote != NULL; pnote = pnote->next )
		{
			if ( is_note_to( ch, pnote ) && vnum++ == anum )
			{
				note_remove( ch, pnote, FALSE );
				send_to_char( "Ok.\n\r", ch );
				return;
			}
		}

		send_to_char( Format("There aren't that many %s.",list_name),ch);
		return;
	}

	if ( !str_prefix( arg, "delete" ) && get_trust(ch) >= MAX_LEVEL - 1)
	{
		if ( !is_number( argument ) )
		{
			send_to_char( "Note delete which number?\n\r", ch );
			return;
		}

		anum = atoi( argument );
		vnum = 0;
		for ( pnote = *list; pnote != NULL; pnote = pnote->next )
		{
			if ( is_note_to( ch, pnote ) && vnum++ == anum )
			{
				note_remove( ch, pnote,TRUE );
				send_to_char( "Ok.\n\r", ch );
				return;
			}
		}

		send_to_char( Format("There aren't that many %s.",list_name),ch);
		return;
	}

	if (!str_prefix(arg,"catchup"))
	{
		switch(type)
		{
			case NOTE_NOTE:	
			ch->pcdata->last_note = current_time;
			break;
			case NOTE_IDEA:
			ch->pcdata->last_idea = current_time;
			break;
			case NOTE_PENALTY:
			ch->pcdata->last_penalty = current_time;
			break;
			case NOTE_NEWS:
			ch->pcdata->last_news = current_time;
			break;
			case NOTE_CHANGES:
			ch->pcdata->last_changes = current_time;
			break;
		}
		return;
	}

	/* below this point only certain people can edit notes */
	if ((type == NOTE_NEWS && !IS_TRUSTED(ch,ANGEL))
		||  (type == NOTE_CHANGES && !IS_TRUSTED(ch,CREATOR)))
	{
		send_to_char( Format("You aren't high enough level to write %s.",list_name),ch);
		return;
	}

	if ( !str_cmp ( arg, "new" ) || !str_cmp ( arg, "write" ) ) {
		note_attach ( ch, type );
		if ( ch->pnote->type != type ) {
			send_to_char ( "You already have a different note in progress.\n\r", ch );
			return;
		}
		ch->desc->connected = CON_NOTE_TO;
		send_to_char ( "Address this message to whom: (all, staff, <name>) ", ch );
		return;
	}

	send_to_char( "You can't do that.\n\r", ch );
	return;
}
Esempio n. 3
0
int board_remove_msg(int board_type, struct char_data *ch, char *arg, struct obj_data *board)
{
  int ind, msg, slot_num;
  char number[MAX_INPUT_LENGTH], buf[MAX_INPUT_LENGTH];
  struct descriptor_data *d;

  one_argument(arg, number);

  if (!*number || !is_number(number))
    return (0);
  if (!(msg = atoi(number)))
    return (0);

  if (!num_of_msgs[board_type]) {
    send_to_char(ch, "The board is empty!\r\n");
    return (1);
  }
  if (msg < 1 || msg > num_of_msgs[board_type]) {
    send_to_char(ch, "That message exists only in your imagination.\r\n");
    return (1);
  }
#if NEWEST_AT_TOP
  ind = num_of_msgs[board_type] - msg;
#else
  ind = msg - 1;
#endif
  if (!MSG_HEADING(board_type, ind)) {
    send_to_char(ch, "That message appears to be screwed up.\r\n");
    return (1);
  }
  snprintf(buf, sizeof(buf), "(%s)", GET_NAME(ch));
  if (GET_LEVEL(ch) < REMOVE_LVL(board_type) &&
      !(strstr(MSG_HEADING(board_type, ind), buf))) {
    send_to_char(ch, "You are not holy enough to remove other people's messages.\r\n");
    return (1);
  }
  if (GET_LEVEL(ch) < MSG_LEVEL(board_type, ind)) {
    send_to_char(ch, "You can't remove a message holier than yourself.\r\n");
    return (1);
  }
  slot_num = MSG_SLOTNUM(board_type, ind);
  if (slot_num < 0 || slot_num >= INDEX_SIZE) {
    send_to_char(ch, "That message is majorly screwed up.\r\n");
    log("SYSERR: The board is seriously screwed up. (Room #%d)", GET_ROOM_VNUM(IN_ROOM(ch)));
    return (1);
  }
  for (d = descriptor_list; d; d = d->next)
    if (STATE(d) == CON_PLAYING && d->str == &(msg_storage[slot_num])) {
      send_to_char(ch, "At least wait until the author is finished before removing it!\r\n");
      return (1);
    }
  if (msg_storage[slot_num])
    free(msg_storage[slot_num]);
  msg_storage[slot_num] = 0;
  msg_storage_taken[slot_num] = 0;
  if (MSG_HEADING(board_type, ind))
    free(MSG_HEADING(board_type, ind));

  for (; ind < num_of_msgs[board_type] - 1; ind++) {
    MSG_HEADING(board_type, ind) = MSG_HEADING(board_type, ind + 1);
    MSG_SLOTNUM(board_type, ind) = MSG_SLOTNUM(board_type, ind + 1);
    MSG_LEVEL(board_type, ind) = MSG_LEVEL(board_type, ind + 1);
  }
  num_of_msgs[board_type]--;

  send_to_char(ch, "Message removed.\r\n");
  snprintf(buf, sizeof(buf), "$n just removed message %d.", msg);
  act(buf, FALSE, ch, 0, 0, TO_ROOM);
  board_save_board(board_type);

  return (1);
}
Esempio n. 4
0
void do_dicethrow(CHAR_DATA *ch, char *argument )
{
	char arg1[MAX_STRING_LENGTH];
	char arg2[MAX_STRING_LENGTH];
	char arg3[MAX_STRING_LENGTH];
	char buffer[MAX_STRING_LENGTH];
	char buff[MAX_STRING_LENGTH];

	bool dch = FALSE ,dcl = FALSE, dce=FALSE;
	int sum=0,diceroll=0, numberofdice=0;
	int i = 0;

	if (argument[0] == '\0')
        {
	   numberofdice = 6;
	}
	else
        {
	   argument = one_argument(argument,arg1);
	   if (!is_number(arg1))
           {
		   send_to_char("Syntax: Dicethrow <number of dice>\r\n",ch);
		   return;
	   }
	   numberofdice = atoi(arg1);
	   if (numberofdice < 1 || numberofdice > 6)
           {
		send_to_char("dicethrow: You must specifiy 1 to 6 dice\r\n",ch);
		return;
	   }
	   if (argument[0] != '\0')
           {
	      argument = one_argument(argument,arg2);
	      if (!str_cmp(arg2,"ch"))
	      {
		dch = TRUE;
	      }
	      else if (!str_cmp(arg2,"cl"))
              {
		dcl = TRUE; 
	      }
	      else if (!str_cmp(arg2,"ce"))
              {
		argument=one_argument(argument,arg3);
		dce = TRUE;
              }
           }
	}
	
	sprintf(buffer,"<DICE GAME>$n rolls the dice: ");
	  
	   for (i = 0; i < numberofdice;i++)
           {
		diceroll=number_range(1,6);
		if (dch)
		{
		   if (diceroll < 5)
                   {
			diceroll += 2;
 	           }
		}	
		else if (dcl)
                {
		   if (diceroll > 2)
                   {
			diceroll -= 2;
 	           }
		}
		else if (dce)
                {
		   if (strlen(arg3) > i)
                   {
			diceroll = arg3[i] - '0';
                   }			
		}
		sum += diceroll;
		sprintf(buff,"%d ",diceroll);
		strcat(buffer,buff);		
           }
	   sprintf(buff,"\r\nFor a total of: %d\n\r",sum);
	   strcat(buffer,buff);
	   act(buffer,ch,NULL,NULL,TO_ROOM);
	   act(buffer,ch,NULL,NULL,TO_CHAR);
	   if (IS_RP(ch))
           {
	      char rp_buffer[MAX_STRING_LENGTH];
	      sprintf(rp_buffer,"%s: %s",ch->name,buffer);
	      log_rp_string(ch,rp_buffer);
	   }
}
Esempio n. 5
0
void game_even_odd( CHAR_DATA *ch, char *argument )
{
    char arg[MAX_INPUT_LENGTH];
    char arg2[MAX_INPUT_LENGTH];
    char buf[MAX_STRING_LENGTH];
    long amount;
    int roll;
    CHAR_DATA *gamemaster;

    argument = one_argument( argument, arg );
    argument = one_argument( argument, arg2 );

    buf[0] = '\0';

    if ( arg[0] == '\0' || arg2[0] == '\0' )
    {
        send_to_char( "Syntax: game even-odd <even|odd> <amount>\n\r", ch );
        return;
    }

    for ( gamemaster = ch->in_room->people; gamemaster != NULL; gamemaster = gamemaster->next_in_room )
    {
        if ( !IS_NPC( gamemaster ) )
            continue;
        if ( gamemaster->spec_fun == spec_lookup( "spec_gamemaster" ) )
            break;
    }

    if ( gamemaster == NULL || gamemaster->spec_fun != spec_lookup( "spec_gamemaster" ) )
    {
        send_to_char("You can't do that here.\n\r",ch);
        return;
    }

    if ( gamemaster->fighting != NULL)
    {
        send_to_char("Wait until the fighting stops.\n\r",ch);
        return;
    }

    if ( !is_number( arg2 ) )
    {
        send_to_char( "You must bet a number.\n\r", ch );
        return;
    }

    roll = dice( 2, 16 );

    amount = atol( arg2 );

    if ( amount < 1 )
    {
        send_to_char( "Bet SOMETHING, will you?\n\r", ch );
        return;
    }

    if (amount > ch->silver) {
        send_to_char( "We don't take credit here?\n\r", ch );
        return;
    }

	if (amount > 10000) {
		send_to_char( "100 gold or 10000 silver is the max bet here.\n\r",ch);
		return; 	
	}
    sprintf( buf, "%s rolls the dice.\n\rThe roll is %d.\n\r", gamemaster->short_descr, roll );
    send_to_char( buf, ch );
    
    if ( !str_cmp( arg, "odd" ) )
    {
        if ( roll %2 != 0 )     /* you win! */
            win( ch, amount );
        else
            lose( ch, amount );
        return;
    }
    else if ( !str_cmp( arg, "even" ) )
    {
        if ( roll %2 == 0 )
            win( ch, amount );
        else
            lose( ch, amount );
        return;
    }
    else
    {
        send_to_char( "Syntax: game even-odd <even|odd> <amount>\n\r", ch );
    }
    return;
}
Esempio n. 6
0
static char const *
parse_with_separator (char const *spec, char const *separator,
                      uid_t *uid, gid_t *gid,
                      char **username, char **groupname)
{
  static const char *E_invalid_user = N_("invalid user");
  static const char *E_invalid_group = N_("invalid group");
  static const char *E_bad_spec = N_("invalid spec");

  const char *error_msg;
  struct passwd *pwd;
  struct group *grp;
  char *u;
  char const *g;
  char *gname = NULL;
  uid_t unum = *uid;
  gid_t gnum = *gid;

  error_msg = NULL;
  *username = *groupname = NULL;

  /* Set U and G to nonzero length strings corresponding to user and
     group specifiers or to NULL.  If U is not NULL, it is a newly
     allocated string.  */

  u = NULL;
  if (separator == NULL)
    {
      if (*spec)
        u = xstrdup (spec);
    }
  else
    {
      size_t ulen = separator - spec;
      if (ulen != 0)
        {
          u = xmemdup (spec, ulen + 1);
          u[ulen] = '\0';
        }
    }

  g = (separator == NULL || *(separator + 1) == '\0'
       ? NULL
       : separator + 1);

#ifdef __DJGPP__
  /* Pretend that we are the user U whose group is G.  This makes
     pwd and grp functions ``know'' about the UID and GID of these.  */
  if (u && !is_number (u))
    setenv ("USER", u, 1);
  if (g && !is_number (g))
    setenv ("GROUP", g, 1);
#endif

  if (u != NULL)
    {
      /* If it starts with "+", skip the look-up.  */
      pwd = (*u == '+' ? NULL : getpwnam (u));
      if (pwd == NULL)
        {
          bool use_login_group = (separator != NULL && g == NULL);
          if (use_login_group)
            {
              /* If there is no group,
                 then there may not be a trailing ":", either.  */
              error_msg = E_bad_spec;
            }
          else
            {
              unsigned long int tmp;
              if (xstrtoul (u, NULL, 10, &tmp, "") == LONGINT_OK
                  && tmp <= MAXUID && (uid_t) tmp != (uid_t) -1)
                unum = tmp;
              else
                error_msg = E_invalid_user;
            }
        }
      else
        {
          unum = pwd->pw_uid;
          if (g == NULL && separator != NULL)
            {
              /* A separator was given, but a group was not specified,
                 so get the login group.  */
              char buf[INT_BUFSIZE_BOUND (uintmax_t)];
              gnum = pwd->pw_gid;
              grp = getgrgid (gnum);
              gname = xstrdup (grp ? grp->gr_name : umaxtostr (gnum, buf));
              endgrent ();
            }
        }
      endpwent ();
    }

  if (g != NULL && error_msg == NULL)
    {
      /* Explicit group.  */
      /* If it starts with "+", skip the look-up.  */
      grp = (*g == '+' ? NULL : getgrnam (g));
      if (grp == NULL)
        {
          unsigned long int tmp;
          if (xstrtoul (g, NULL, 10, &tmp, "") == LONGINT_OK
              && tmp <= MAXGID && (gid_t) tmp != (gid_t) -1)
            gnum = tmp;
          else
            error_msg = E_invalid_group;
        }
      else
        gnum = grp->gr_gid;
      endgrent ();              /* Save a file descriptor.  */
      gname = xstrdup (g);
    }

  if (error_msg == NULL)
    {
      *uid = unum;
      *gid = gnum;
      *username = u;
      *groupname = gname;
      u = NULL;
    }
  else
    free (gname);

  free (u);
  return _(error_msg);
}
Esempio n. 7
0
sb_token_t *lex_pull_token ( void ) {
  g_sb_token [ 0 ] = '\0';
  lex_mode_e mode = mode_seek_statement;

  while ( 1 ) {

    //printf ( "%c", *_cursor );

    switch ( mode ) {

    case mode_seek_statement:

      if ( is_whitespace ( *_cursor ) ) {
	// ignore
      } else if ( *_cursor == '#' ) {
	mode = mode_consume_comment;
      } else if ( *_cursor == '"' ) {
	mode = mode_consume_string;
      } else if ( is_number ( *_cursor ) ) {
	mode = mode_consume_constant;
	tokencat ( *_cursor );
      } else if ( is_operator ( *_cursor ) ) {
	mode = mode_consume_op;
	tokencat ( *_cursor );
      } else if ( is_eol ( *_cursor ) ) {
	_cursor++;
	sb_token_t *t = make_token();
	t -> type = sbt_eol;
	return ( t );
      } else if ( *_cursor == '\0' ) {
	_cursor++;
	sb_token_t *t = make_token();
	t -> type = sbt_eof;
	return ( t );
      } else if ( is_alpha ( *_cursor ) ) {
	mode = mode_consume_word;
	tokencat ( *_cursor );
      }

      break;

    case mode_consume_comment:

      if ( *_cursor == '\r' ) {
	break;
      } else if ( *_cursor == '\n' ) {
	// let top loop return a EOL
	_cursor--;
	mode = mode_seek_statement;
      } else if ( *_cursor == '\0' ) {
	// let top loop return a EOF
	_cursor--;
	mode = mode_seek_statement;
      }

      break;

    case mode_consume_constant:

      if ( is_eol ( *_cursor ) ||
	   *_cursor == '#' ||
	   is_whitespace ( *_cursor )
	 )
      {
	mode = mode_seek_statement;

	sb_token_t *t = make_token();
	t -> type = sbt_constant;
	t -> data.text = strdup ( g_sb_token );
	return ( t );

      } else {
	tokencat ( *_cursor );
	//_cursor++;
      }

      break;

    case mode_consume_string:

      if ( is_eol ( *_cursor ) ||
	   *_cursor == '"' )
      {

	if ( is_eol ( *_cursor ) ) {
	  printf ( "String terminator not found; assuming terminator at EOL\n" );
	} else {
	  _cursor++;
	}

	mode = mode_seek_statement;

	sb_token_t *t = make_token();
	t -> type = sbt_string;
	t -> data.text = strdup ( g_sb_token );
	return ( t );
      } else {
	rawcat ( *_cursor );
      }

      break;

    case mode_consume_op:

      if ( is_eol ( *_cursor ) ||
	   *_cursor == '#' ||
	   is_whitespace ( *_cursor )
	 )
      {
	mode = mode_seek_statement;
	_cursor++;

	sb_token_t *t = make_token();
	t -> type = sbt_op;
	t -> data.text = strdup ( g_sb_token );
	return ( t );

      } else {
	tokencat ( *_cursor );
      }

      break;

    case mode_consume_word:

      if ( is_eol ( *_cursor ) || *_cursor == '#' || is_whitespace ( *_cursor ) ) {

	// back up cursor, so when we come back into lexer it'll just
	// find the # or ' ' and start consuming comment or word..
	// no need to do it here.
	if ( *_cursor == '#' ) {
	  mode = mode_seek_statement; // consume comment and restart
	} else if ( is_whitespace ( *_cursor ) ) {
	  mode = mode_consume_word; // try to build another word
	} else if ( is_eol ( *_cursor ) ) {
	  mode = mode_seek_statement; // consume comment and restart
	}

	// do it
	if ( strcmp ( g_sb_token, "LET" ) == 0 ) {
	  sb_token_t *t = make_token();
	  t -> type = sbt_let;
	  return ( t );
	} else if ( strcmp ( g_sb_token, "EXIT" ) == 0 ) {
	  sb_token_t *t = make_token();
	  t -> type = sbt_exit;
	  return ( t );
	} else if ( strcmp ( g_sb_token, "PRINT" ) == 0 ) {
	  sb_token_t *t = make_token();
	  t -> type = sbt_print;
	  return ( t );
	} else if ( strcmp ( g_sb_token, "WHILE" ) == 0 ) {
	  sb_token_t *t = make_token();
	  t -> type = sbt_while;
	  return ( t );
	} else if ( strcmp ( g_sb_token, "GOSUB" ) == 0 ) {
	  sb_token_t *t = make_token();
	  t -> type = sbt_gosub;
	  return ( t );
	} else if ( strcmp ( g_sb_token, "SUBROUTINE" ) == 0 ) {
	  sb_token_t *t = make_token();
	  t -> type = sbt_proc;
	  return ( t );
	} else if ( ( strcmp ( g_sb_token, "ENDWHILE" ) == 0 ) ||
		    ( strcmp ( g_sb_token, "ENDIF" ) == 0 ) ||
		    ( strcmp ( g_sb_token, "ENDPROC" ) == 0 ) ||
		    ( strcmp ( g_sb_token, "ENDSUB" ) == 0 ) ||
		    ( strcmp ( g_sb_token, "END" ) == 0 )
		  )
	{
	  sb_token_t *t = make_token();
	  t -> type = sbt_end;
	  t -> data.text = strdup ( g_sb_token );
	  return ( t );
	} else if ( strcmp ( g_sb_token, "IF" ) == 0 ) {
	  sb_token_t *t = make_token();
	  t -> type = sbt_if;
	  return ( t );
	} else if ( strcmp ( g_sb_token, "ELSE" ) == 0 ) {
	  sb_token_t *t = make_token();
	  t -> type = sbt_else;
	  return ( t );
	} else {
	  sb_token_t *t = make_token();
	  t -> type = sbt_word;
	  t -> data.text = strdup ( g_sb_token );
	  return ( t );
	}

      } else if ( is_alpha ( *_cursor ) || is_number ( *_cursor ) || ( *_cursor == '_' ) ) {
	tokencat ( *_cursor );
      }

      break;

    } // switch on mode

    // we done here?
    if ( mode == mode_done ) {
      break;
    }

    _cursor++;
  } // while forever

  return NULL;
}
Esempio n. 8
0
/* Calendar code (c)The Alsherok Team*/
void do_setholiday( CHAR_DATA* ch, const char* argument)
{
   HOLIDAY_DATA *day, *newday;
   int count = 0;
   int x = 0;
   char arg1[MIL], arg2[MIL], arg3[MIL];

   argument = one_argument( argument, arg1 );
   argument = one_argument( argument, arg2 );
   argument = one_argument( argument, arg3 );

   if( arg1 == '\0' || !str_cmp( arg1, " " ) )
   {
      send_to_char( "Syntax : setholiday <name> <field> <argument>\r\n", ch );
      send_to_char( "Field can be : day name create announce save delete\r\n", ch );
      return;
   }

/* Save em all.. saves the work of saving individual 
   holidays when mass-creating or editing*/
   if( !str_cmp( arg1, "save" ) )
   {
      save_holidays(  );
      send_to_char( "Holiday chart saved.\r\n", ch );
      return;
   }

/* Create a new holiday by name arg1 */
   if( !str_cmp( arg2, "create" ) )
   {
      for( day = first_holiday; day; day = day->next )
         count++;
      for( day = first_holiday; day; day = day->next )
      {
         if( !str_cmp( arg1, day->name ) )
         {
            send_to_char( "A holiday with that name exists already!\r\n", ch );
            return;
         }
      }

      if( count >= sysdata.maxholiday )
      {
         send_to_char( "There are already too many holidays!\r\n", ch );
         return;
      }

      CREATE( newday, HOLIDAY_DATA, 1 );
      newday->name = str_dup( arg1 );
      newday->day = time_info.day;
      newday->month = time_info.month;
      newday->announce = str_dup( "Today is the holiday of when some moron forgot to set the announcement for this one!" );
      LINK( newday, first_holiday, last_holiday, next, prev );
      send_to_char( "Holiday created.\r\n", ch );
      return;
   }

/* Now... let's find that holiday */

   for( day = first_holiday; day; day = day->next )
   {
      if( !str_cmp( day->name, arg1 ) )
         break;
   }

/* Anything match? */
   if( !day )
   {
      send_to_char( "Which holiday was that?\r\n", ch );
      return;
   }

/* Set the day */

   if( !str_cmp( arg2, "day" ) )
   {
      if( arg3 == '\0' || !is_number( arg3 ) || atoi( arg3 ) > sysdata.dayspermonth || atoi( arg3 ) <= 1 )
      {
         ch_printf( ch, "You must specify a numeric value : %d - %d", 1, sysdata.dayspermonth );
         return;
      }

/* What day is it?... FRIDAY!.. oh... no... it's.. arg3? */
      day->day = atoi( arg3 );
      send_to_char( "Day changed.\r\n", ch );
      return;
   }

   if( !str_cmp( arg2, "month" ) )
   {
/* Go through the months and find arg3 */

      if( arg3 == '\0' || !is_number( arg3 ) || atoi( arg3 ) > sysdata.monthsperyear || atoi( arg3 ) <= 1 )
      {
         send_to_char( "You must specify a valid month number:\r\n", ch );

/* List all the months with a counter next to them*/
         count = 1;
         while( month_name[x] != '\0' && str_cmp(month_name[x], " ") && x < sysdata.monthsperyear)

         {
            ch_printf( ch, "&R(&W%d&R)&Y%s\r\n", count, month_name[x] );
            x++;
            count++;
         }
return;
      }


/* What's the month? */
      day->month = atoi( arg3 );
      send_to_char( "Month changed.\r\n", ch );
      return;
   }

   if( !str_cmp( arg2, "announce" ) )
   {
      if( arg3 == '\0' || !str_cmp( arg3, " " ) || is_number( arg3 ) )
      {
         send_to_char( "Set the annoucement to what?\r\n", ch );
         return;
      }

/* Set the announcement */
      DISPOSE( day->announce );
      day->announce = str_dup( arg3 );
      send_to_char( "Announcement changed.\r\n", ch );
      return;
   }

/* Change the name */
   if( !str_cmp( arg2, "name" ) )
   {
      if( arg3 == '\0' || !str_cmp( arg3, " " ) || is_number( arg3 ) )
      {
         send_to_char( "Set the name to what?\r\n", ch );
         return;
      }

/* Release the good...err... name */
      DISPOSE( day->name );
      day->name = str_dup( arg3 );
      send_to_char( "Name changed.\r\n", ch );
      return;
   }

   if( !str_cmp( arg2, "delete" ) )
   {
      if( str_cmp( arg3, "yes" ) )
      {
         send_to_char( "If you are sure, use 'delete yes'.\r\n", ch );
         return;
      }

      free_holiday( day );
      send_to_char( "&RHoliday deleted.\r\n", ch );
      return;
   }

   send_to_char( "Syntax: setholiday <name> <field> <argument>\r\n", ch );
   send_to_char( "Field can be: day name create announce save delete\r\n", ch );
   return;
}
symbolt &cpp_declarator_convertert::convert_new_symbol(
  const cpp_storage_spect &storage_spec,
  const cpp_member_spect &member_spec,
  cpp_declaratort &declarator)
{
  irep_idt pretty_name=get_pretty_name();

  symbolt symbol;

  symbol.name=final_identifier;
  symbol.base_name=base_name;
  symbol.value=declarator.value();
  symbol.location=declarator.name().source_location();
  symbol.mode=linkage_spec==ID_auto?ID_cpp:linkage_spec;
  symbol.module=cpp_typecheck.module;
  symbol.type=final_type;
  symbol.is_type=is_typedef;
  symbol.is_macro=is_typedef && !is_template_parameter;
  symbol.pretty_name=pretty_name;

  // Constant? These are propagated.
  if(symbol.type.get_bool(ID_C_constant) &&
     symbol.value.is_not_nil())
    symbol.is_macro=true;

  if(member_spec.is_inline())
    symbol.type.set(ID_C_inlined, true);

  if(!symbol.is_type)
  {
    if(is_code)
    {
      // it is a function
      if(storage_spec.is_static())
        symbol.is_file_local=true;
    }
    else
    {
      // it is a variable
      symbol.is_state_var=true;
      symbol.is_lvalue = !is_reference(symbol.type) &&
                         !(symbol.type.get_bool(ID_C_constant) &&
                         is_number(symbol.type) &&
                         symbol.value.id() == ID_constant);

      if(cpp_typecheck.cpp_scopes.current_scope().is_global_scope())
      {
        symbol.is_static_lifetime=true;

        if(storage_spec.is_extern())
          symbol.is_extern=true;
      }
      else
      {
        if(storage_spec.is_static())
        {
          symbol.is_static_lifetime=true;
          symbol.is_file_local=true;
        }
        else if(storage_spec.is_extern())
        {
          cpp_typecheck.error().source_location=storage_spec.location();
          cpp_typecheck.error() << "external storage not permitted here"
                                << messaget::eom;
          throw 0;
        }
      }
    }
  }

  if(symbol.is_static_lifetime)
    cpp_typecheck.dynamic_initializations.push_back(symbol.name);

  // move early, it must be visible before doing any value
  symbolt *new_symbol;

  if(cpp_typecheck.symbol_table.move(symbol, new_symbol))
  {
    cpp_typecheck.error().source_location=symbol.location;
    cpp_typecheck.error()
      << "cpp_typecheckt::convert_declarator: symbol_table.move() failed"
      << messaget::eom;
    throw 0;
  }

  if(!is_code)
  {
    cpp_scopest::id_sett id_set;

    cpp_typecheck.cpp_scopes.current_scope().lookup(
      base_name, cpp_scopet::SCOPE_ONLY, id_set);

    for(cpp_scopest::id_sett::const_iterator
        id_it=id_set.begin();
        id_it!=id_set.end();
        id_it++)
    {
      const cpp_idt &id=**id_it;
      // the name is already in the scope
      // this is ok if they belong to different categories

      if(!id.is_class() && !id.is_enum())
      {
        cpp_typecheck.error().source_location=new_symbol->location;
        cpp_typecheck.error() << "`" << base_name
                              << "' already in scope"
                              << messaget::eom;
        throw 0;
      }
    }
  }

  // put into scope
  cpp_idt &identifier=
    cpp_typecheck.cpp_scopes.put_into_scope(*new_symbol, *scope, is_friend);

  if(is_template)
    identifier.id_class=cpp_idt::id_classt::TEMPLATE;
  else if(is_template_parameter)
    identifier.id_class=cpp_idt::id_classt::TEMPLATE_PARAMETER;
  else if(is_typedef)
    identifier.id_class=cpp_idt::id_classt::TYPEDEF;
  else
    identifier.id_class=cpp_idt::id_classt::SYMBOL;

  // do the value
  if(!new_symbol->is_type)
  {
    if(is_code && declarator.type().id()!=ID_template)
      cpp_typecheck.add_method_body(new_symbol);

    if(!is_code)
      cpp_typecheck.convert_initializer(*new_symbol);
  }

  enforce_rules(*new_symbol);

  return *new_symbol;
}
Esempio n. 10
0
void do_pfiles( CHAR_DATA * ch, char *argument )
{
   char buf[MSL];
   char arg1[MIL];
   char x[3];


   if( IS_NPC( ch ) )
   {
      send_to_char( "Mobs cannot use this command!\n\r", ch );
      return;
   }


   if ( !argument || argument[0] == '\0' )
   {
        send_to_char( "&RSyntax: pfiles <scan/settime/count/letter/force>\n\r", ch);
        return;
   }

   if( !str_cmp( argument, "scan") )
   {
      /*
       * Makes a backup copy of existing pfiles just in case - Samson 
       */
      sprintf( buf, "tar -cf %spfiles.tar %s*", PLAYER_DIR, PLAYER_DIR );

      /*
       * GAH, the shell pipe won't process the command that gets pieced
       * together in the preceeding lines! God only knows why. - Samson 
       */
      system( buf );

      sprintf( log_buf, "Manual pfile cleanup started by %s.", ch->name );
      log_string( log_buf );
      pfile_scan( FALSE );

      return;
   }

   if( !str_cmp( argument, "settime" ) )
   {
      new_pfile_time_t = current_time + 86400;
      save_timedata(  );
      send_to_char( "New cleanup time set for 24 hrs from now.\n\r", ch );
      return;
   }

   if( !str_cmp( argument, "count" ) )
   {
      sprintf( log_buf, "Pfile count started by %s.", ch->name );
      log_string( log_buf );
      pfile_scan( TRUE );
      return;
   }

	argument = one_argument( argument, arg1);

   if ( !str_cmp( arg1, "letter" ) )
   {

	if ( (argument[0] == '\0') || !argument )
	{
		send_to_char("&RSyntax: pfiles letter (letter A-Z)\n\r", ch );
                return;
        }

        if( !is_number( argument ) || ( argument[1] != '\0' ) ) 
        { 
           snprintf( x, 2, argument ); 
           x[0] = tolower(x[0]); 
           show_pfiles( ch, x ); 
        } 
        else
        {
          send_to_char("You can only use a letter in this scan!\n\r",ch);
          return;
        }

        return;
     }   

    if ( !str_cmp( arg1, "forcers" ) )
	{
	   scan_forcers( ch );
	   return;
	}

   send_to_char( "Invalid argument.\n\r", ch );
   return;
}
Esempio n. 11
0
File: vars.c Progetto: jnbek/TekNap
void set_var_value(int var_index, char *value, IrcVariable *dll)
{
	char	*rest;
	IrcVariable *var;
	int	old;
	var = &(irc_variable[var_index]);
	switch (var->type)
	{
	case BOOL_TYPE_VAR:
		if (value && *value && (value = next_arg(value, &rest)))
		{
			old = var->integer;
			if (do_boolean(value, &(var->integer)))
			{
				say("Value must be either ON, OFF, or TOGGLE");
				break;
			}
			if (!(var->int_flags & VIF_CHANGED))
			{
				if (old != var->integer)
					var->int_flags |= VIF_CHANGED;
			}
			if (var->func)
				(var->func) (current_window, NULL, var->integer);
			say("Value of %s set to %s", var->name,
				var->integer ? var_settings[ON]
					     : var_settings[OFF]);
		}
		else
			say("Value of %s -> %s", var->name, var->integer?var_settings[ON] : var_settings[OFF]);
		break;
	case CHAR_TYPE_VAR:
		if (!value)
		{
			if (!(var->int_flags & VIF_CHANGED))
			{
				if (var->integer)
					var->int_flags |= VIF_CHANGED;
			}
			var->integer = ' ';
			if (var->func)
				(var->func) (current_window, NULL, var->integer);
			say("Value of %s set to '%c'", var->name, var->integer);
		}

		else if (value && *value && (value = next_arg(value, &rest)))
		{
			if (strlen(value) > 1)
				say("Value of %s must be a single character",
					var->name);
			else
			{
				if (!(var->int_flags & VIF_CHANGED))
				{
					if (var->integer != *value)
						var->int_flags |= VIF_CHANGED;
				}
				var->integer = *value;
				if (var->func)
					(var->func) (current_window, NULL, var->integer);
				say("Value of %s set to '%c'", var->name,
					var->integer);
			}
		}
		else
			say("Value of %s -> %c", var->name, var->integer);
		break;
	case INT_TYPE_VAR:
		if (value && *value && (value = next_arg(value, &rest)))
		{
			int	val;

			if (!is_number(value))
			{
				say("Value of %s must be numeric!", var->name);
				break;
			}
			if ((val = my_atol(value)) < 0)
			{
				say("Value of %s must be greater than 0", var->name);
				break;
			}
			if (!(var->int_flags & VIF_CHANGED))
			{
				if (var->integer != val)
					var->int_flags |= VIF_CHANGED;
			}
			var->integer = val;
			if (var->func)
				(var->func) (current_window, NULL, var->integer);
			say("Value of %s set to %d", var->name, var->integer);
		}
		else
			say("Value of %s -> %d", var->name, var->integer);
		break;
	case STR_TYPE_VAR:
		if (value)
		{
			if (*value)
			{
				char	*temp = NULL;

				if (var->flags & VF_EXPAND_PATH)
				{
					temp = expand_twiddle(value);
					if (temp)
						value = temp;
					else
						say("SET: no such user");
				}
				if ((!var->int_flags & VIF_CHANGED))
				{
					if ((var->string && ! value) ||
					    (! var->string && value) ||
					    my_stricmp(var->string, value))
						var->int_flags |= VIF_CHANGED;
				}
				malloc_strcpy(&(var->string), value);
				if (temp)
					new_free(&temp);
			}
			else
			{
				say("Value of %s -> %s", var->name, var->string ? var->string : "<null>");
				return;
			}
		}
		else
			new_free(&(var->string));
		if (var->func && !(var->int_flags & VIF_PENDING))
		{
			var->int_flags |= VIF_PENDING;
			(var->func) (current_window, var->string, 0);
			var->int_flags &= ~VIF_PENDING;
		}
		say("Value of %s set to %s", var->name, var->string ?
			var->string : "<EMPTY>");
		break;
	}
}
Esempio n. 12
0
void graph(FILE * fp)
{
   static char buf[BUFLNG], arg[BUFLNG / 2], xtype[16], ytype[16];
   static double xa, ya, xap, yap, xmin, xmax, ymin, ymax;
   static double xs = -NSCALE, ys = -NSCALE;
   int n, c;
   char *s, *p;
   double x, y, lpt, th, dt, lscale, rad;
   int is_grid, old_lbl = 0;
   char xory;

   h *= fct;
   w *= fct;

   for (n = 0; (s = fgets(buf, BUFLNG, fp));) {
      s = getarg(s, arg);
      if (s == NULL || *arg == '#');    /* comment line */
      else if ((!is_t && strcmp(arg, "x") == 0)
               || (is_t && strcmp(arg, "y") == 0)) {
         s = gettyp(s, xtype);
         if (sscanf(s, "%lf %lf %lf", &xmin, &xmax, &xa) != 3)
            xa = xmin;
         if (strncmp(xtype, "log", 3) == 0) {
            xmin = log10(xmin);
            xmax = log10(xmax);
            xa = log10(xa);
            is_xlog = (xtype[3] == '*') ? -1 : 1;
         }
         xfct = xl / (xmax - xmin);
         xap = (xa - xmin) * xfct;
         x00 = -xmin * xfct;
      } else if ((!is_t && strcmp(arg, "y") == 0)
                 || (is_t && strcmp(arg, "x") == 0)) {
         s = gettyp(s, ytype);
         if (sscanf(s, "%lf %lf %lf", &ymin, &ymax, &ya) != 3)
            ya = ymin;
         if (strncmp(ytype, "log", 3) == 0) {
            ymin = log10(ymin);
            ymax = log10(ymax);
            ya = log10(ya);
            is_ylog = (ytype[3] == '*') ? -1 : 1;
         }
         yfct = (yl) ? yl / (ymax - ymin) : 0;
         yap = (ya - ymin) * yfct;
         y00 = -ymin * yfct;
      } else if ((!is_t && strncmp(arg, "xscale", 6) == 0)
                 || (is_t && strncmp(arg, "yscale", 6) == 0)) {
         is_grid = *(arg + 6);
         if (type < 0 || (ya != ymin && ya != ymax)) {
            plot(0.0, yap, 3);
            plot(xl, yap, 2);
         }
         ys = yap - h - MSCALE;
         while ((s = getarg(s, p = arg)) != NULL) {
            if (*p != '"') {
               x = atof((is_number(*p)) ? p : p + 1);
               if (strncmp(xtype, "mel", 3) == 0)
                  x = argapf(x / nz(xmax, xmin),
                             atof(xtype + 3)) * nz(xmax, xmin);
               else if (is_xlog)
                  x = log10(x);
               x = (x - xmin) * xfct;
               lscale = (*p == 's') ? LSCALE / 2 : LSCALE;
               if (*p != '\\' && *p != '@') {
                  plot(x, yap, 3);
                  plot(x, yap + lscale, 2);
                  if (type > 0 && !is_grid && yap == 0) {
                     plot(x, yl, 3);
                     plot(x, yl - lscale, 2);
                  }
               } else if (*p == '\\')
                  ++p;
            }
            if (is_number(*p) || *p++ == '"')
               _symbol(x - sleng(p, h, w) / 2, ys - ysadj(), p, h, w, 0.0);
         }
      } else if ((!is_t && strncmp(arg, "yscale", 6) == 0)
                 || (is_t && strncmp(arg, "xscale", 6) == 0)) {
         is_grid = *(arg + 6);
         if (type < 0 || (xa != xmin && xa != xmax)) {
            plot(xap, 0.0, 3);
            plot(xap, yl, 2);
         }
         while ((s = getarg(s, p = arg)) != NULL) {
            if (*p != '"') {
               y = atof((is_number(*p)) ? p : p + 1);
               if (strncmp(ytype, "mel", 3) == 0)
                  y = argapf(y / nz(ymax, ymin),
                             atof(ytype + 3)) * nz(ymax, ymin);
               else if (is_ylog)
                  y = log10(y);
               y = (y - ymin) * yfct;
               lscale = (*p == 's') ? LSCALE / 2 : LSCALE;
               if (*p != '\\' && *p != '@') {
                  plot(xap, y, 3);
                  plot(xap + lscale, y, 2);
                  if (type > 0 && !is_grid && xap == 0) {
                     plot(xl, y, 3);
                     plot(xl - lscale, y, 2);
                  }
               } else if (*p == '\\')
                  ++p;
            }
            if (is_number(*p) || *p++ == '"') {
               x = xap - sleng(p, h, w) - MSCALE;
               if (x < xs)
                  xs = x;
               _symbol(x, y - h * 0.5, p, h, w, 0.0);
            }
         }
      } else if (strcmp(arg + 1, "grid") == 0) {
         draw_fig0(xbuf, ybuf, n, wf, hf, fct);
         if ((!is_t && (*arg == 'x')) || (is_t && (*arg == 'y'))) {
            ybuf[0] = 0;
            ybuf[1] = yl;
            while ((s = getarg(s, arg)) != NULL) {
               x = atof(arg);
               if (is_xlog)
                  x = log10(x);
               xbuf[0] = xbuf[1]
                   = (x - xmin) * xfct;
               draw_fig0(xbuf, ybuf, 2, wf, hf, fct);
            }
         } else {
            xbuf[0] = 0;
            xbuf[1] = xl;
            while ((s = getarg(s, arg)) != NULL) {
               y = atof(arg);
               if (is_ylog)
                  y = log10(y);
               ybuf[0] = ybuf[1]
                   = (y - ymin) * yfct;
               draw_fig0(xbuf, ybuf, 2, wf, hf, fct);
            }
         }
         n = 0;
      } else if (strcmp(arg + 1, "circle") == 0) {
         xory = *arg;
         s = getarg(s, arg);
         x = xt(atof(arg));
         s = getarg(s, arg);
         y = yt(atof(arg));
         swap(&x, &y);
         x = xfct * x + x00;
         y = yfct * y + y00;
         while ((s = getarg(s, arg)) != NULL) {
            if ((!is_t && xory == 'x') || (is_t && xory == 'y'))
               rad = xt(atof(arg)) * xfct;
            else
               rad = yt(atof(arg)) * yfct;
            pntstyl(ptyp);
            circle(x, y, rad, rad, 0., 360.);
         }
      } else if (strcmp(arg, "circle") == 0) {
         s = getarg(s, arg);
         x = xt(atof(arg));
         s = getarg(s, arg);
         y = yt(atof(arg));
         swap(&x, &y);
         x = xfct * x + x00;
         y = yfct * y + y00;
         while ((s = getarg(s, arg)) != NULL) {
            rad = atof(arg);
            pntstyl(ptyp);
            circle(x, y, rad, rad, 0., 360.);
         }
      } else if (strcmp(arg + 1, "name") == 0) {
         s = getname(s, p = arg + 1);
         if ((!is_t && *arg == 'x') || (is_t && *arg == 'y'))
            _symbol((xl - sleng(s, h, w)) / 2,
                    (*p) ? -atof(p) - h : ys - h - NSCALE, s, h, w, 0.0);
         else
            _symbol((*p) ? -atof(p) : xs - MSCALE,
                    (yl - sleng(s, h, w)) / 2, s, h, w, 90.0);
      } else if (strncmp(arg, "title", 5) == 0 || strncmp(arg, "print", 5) == 0) {
         sscanf(s, "%lf %lf", &x, &y);
         swap(&x, &y);
         if (*arg == 'p') {
            x = xfct * xt(x) + x00;
            y = yfct * yt(y) + y00;
         }
         s = gettxt_fig(s);
         th = getarg(s + strlen(s) + 1, arg) ? atof(arg) : 0;
         if (*(arg + 5)) {
            x -= rx(LADJ * h / 2, h / 2, th);
            y -= ry(LADJ * h / 2, h / 2, th);
         }
         _symbol(x, y, s, h, w, th);
      } else if (strcmp(arg, "eod") == 0 || strcmp(arg, "EOD") == 0) {
         draw_fig0(xbuf, ybuf, n, wf, hf, fct);
         n = 0;
      } else if (strcmp(arg, "pen") == 0) {
         n = flush(xbuf, ybuf, n, wf, hf, fct);
         pen(atoi(s));
      } else if (strcmp(arg, "join") == 0) {
         n = flush(xbuf, ybuf, n, wf, hf, fct);
         join(atoi(s));
      } else if (strcmp(arg, "csize") == 0) {
         if (sscanf(s, "%lf %lf", &h, &w) != 2)
            w = h;
      } else if (strcmp(arg, "hight") == 0) {
         if (sscanf(s, "%lf %lf", &mh, &mw) != 2)
            mw = mh;
      } else if (strcmp(arg, "line") == 0) {
         n = flush(xbuf, ybuf, n, wf, hf, fct);
         if (sscanf(s, "%d %lf", &ltype, &lpt) != 2) {
            if (ltype > 0)
               lpt = lpit[ltype - 1];
         }
         if (--ltype >= 0)
            mode(lmod[ltype], lpt);
      } else if (strcmp(arg, "italic") == 0)
         italic(atof(s));
      else if (strcmp(arg, "mark") == 0) {
         while (*s == ' ' || *s == '\t')
            ++s;
         if (*s == '\\' && *(s + 1) == '0')
            *label = '\0';
         else
            strcpy(label, s);
      } else if (strcmp(arg, "paint") == 0) {
         sscanf(s, "%d %lf %lf", &ptyp, &dhat, &that);
      } else if (strcmp(arg, "clip") == 0) {
         draw_fig0(xbuf, ybuf, n, wf, hf, fct);
         for (n = 0; (s = getarg(s, arg)) != NULL; ++n) {
            x = xt(atof(arg));
            if ((s = getarg(s, arg)) == NULL)
               break;
            y = yt(atof(arg));
            swap(&x, &y);
            xbuf[n] = xfct * x + x00;
            ybuf[n] = yfct * y + y00;
         }
         if (n == 0) {
            xclip0 = yclip0 = 0;
            xclip1 = xl;
            yclip1 = yl;
            swap(&xclip1, &yclip1);
         } else if (n == 2) {
            xclip0 = xbuf[0];
            yclip0 = ybuf[0];
            xclip1 = xbuf[1];
            yclip1 = ybuf[1];
         }
         n = 0;
      } else if (strcmp(arg, "box") == 0) {
         draw_fig0(xbuf, ybuf, n, wf, hf, fct);
         for (n = 0; (s = getarg(s, arg)) != NULL; ++n) {
            x = xt(atof(arg));
            if ((s = getarg(s, arg)) == NULL)
               break;
            y = yt(atof(arg));
            swap(&x, &y);
            xbuf[n] = xfct * x + x00;
            ybuf[n] = yfct * y + y00;
         }
         if (n == 2) {
            xbuf[2] = xbuf[1];
            ybuf[3] = ybuf[2] = ybuf[1];
            ybuf[1] = ybuf[0];
            xbuf[3] = xbuf[0];
            n = 4;
         }
         polyg(xbuf, ybuf, n, wf, hf, fct);
         n = 0;
      } else {
         x = xt(atof(arg));
         s = getarg(s, arg);
         y = yt(atof(arg));
         swap(&x, &y);
         xbuf[n] = x = xfct * x + x00;
         ybuf[n] = y = yfct * y + y00;
         if (is_in(x, y) && ((s = getarg(s, arg))
                             || *label || old_lbl > 0)) {
            c = 0;
            if (s || *label) {
               if (s == NULL)
                  s = getarg(label, arg);
               if (*arg == '\\' && (abs(c = atoi(arg + 1))) < 16)
                  mark(abs(c), &x, &y, 1, mh, 1);
               else if (abs(c) == 16) {
                  pntstyl(ptyp);
                  circle(x, y, mh / 2, mh / 2, 0., 360.);
               } else {
                  if (c) {
                     *arg = c;
                     *(arg + 1) = '\0';
                  }
                  _symbol(x - LADJ * h / 2, y - w / 2, arg, h, w, atof(s));
               }
            }
            if (c > 0)
               n = flush(xbuf, ybuf, n, wf, hf, fct);
            if ((c > 0 || old_lbl > 0) && n) {
               dt = atan2(y - ybuf[0], x - xbuf[0]);
               if (old_lbl > 0) {
                  xbuf[0] += MADJ * mh * cos(dt);
                  ybuf[0] += MADJ * mh * sin(dt);
               }
               if (c > 0) {
                  xbuf[1] -= MADJ * mh * cos(dt);
                  ybuf[1] -= MADJ * mh * sin(dt);
               }
               draw_fig0(xbuf, ybuf, 2, wf, hf, fct);
               xbuf[0] = x;
               ybuf[0] = y;
               n = 0;
            }
            old_lbl = c;
         }
         if (++n >= BUFLNG)
            n = flush(xbuf, ybuf, n, wf, hf, fct);
      }
   }
   draw_fig0(xbuf, ybuf, n, wf, hf, fct);
}
Esempio n. 13
0
bool get_money_obj( CHAR_DATA * ch, char *argument, OBJ_DATA * obj )
{
    MONEY_TYPE *transfer = new MONEY_TYPE;
    short looper;
    char m_number[MSL];
    char m_name[MSL];
    char outbuf[MSL];

    if ( !str_cmp( "all", argument ) )
    {
        for ( looper = 0; looper < MAX_CURRENCY; looper++ )
        {
            transfer->cash_unit[looper] = obj->money->cash_unit[looper];
            obj->money->cash_unit[looper] = 0;
        }
    }
    else
    {
        for ( looper = 0; looper < MAX_CURRENCY; looper++ )
        {
            transfer->cash_unit[looper] = 0;
        }
        for ( ;; )
        {
            short mn;
            argument = one_argument( argument, m_number );
            if ( m_number[0] == '\0' )
                break;
            argument = one_argument( argument, m_name );
            if ( m_name[0] == '\0' )
                break;
            if ( ( ( mn = money_lookup( m_name ) ) < 0 ) || ( !is_number( m_number ) ) )
            {
                snprintf( outbuf, MSL, "%s %s isn't a valid money type!\r\n", m_number, m_name );
                send_to_char( outbuf, ch );
                join_money( transfer, obj->money );
                return FALSE;
            }
            if ( obj->money->cash_unit[mn] < atoi( m_number ) )
            {
                /*        snprintf( outbuf, MSL, "There isn't that much %s in %s!\r\n", m_name, obj->short_descr );
                        send_to_char( outbuf, ch );  */
                join_money( transfer, obj->money );
                return FALSE;
            }
            obj->money->cash_unit[mn] -= atoi( m_number );
            transfer->cash_unit[mn] += atoi( m_number );
        }
    }
    if ( money_value( transfer ) <= 0 )
    {
        delete transfer;
        return FALSE;
    }

    if ( ( ch->carry_weight + money_weight( transfer ) ) > can_carry_w( ch ) )
    {
        snprintf( outbuf, MSL, "%s", "You cannot carry that much weight!\r\n" );
        send_to_char( outbuf, ch );
        join_money( transfer, obj->money );
        return FALSE;
    }

    ch->carry_weight += money_weight( transfer );
    if ( check_charm_aff(ch, CHARM_AFF_GOLD) )
        for ( looper = 0; looper < MAX_CURRENCY; looper++ )
            transfer->cash_unit[looper] *= ((100 + get_charm_bonus(ch, CHARM_AFF_GOLD)) / 100);
    snprintf( outbuf, MSL, "You take %s from %s.\r\n", money_string( transfer ), obj->short_descr );
    send_to_char( outbuf, ch );
    join_money( transfer, ch->money );
    return TRUE;
}
Esempio n. 14
0
bool get_money_room( CHAR_DATA * ch, char *argument )
{
    MONEY_TYPE *transfer = new MONEY_TYPE;
    short looper;
    char m_number[MSL];
    char m_name[MSL];
    char outbuf[MSL];

    if ( !str_cmp( "all", argument ) )
    {
        for ( looper = 0; looper < MAX_CURRENCY; looper++ )
        {
            transfer->cash_unit[looper] = ch->in_room->treasure->cash_unit[looper];
            ch->in_room->treasure->cash_unit[looper] = 0;
        }
    }
    else
    {
        for ( looper = 0; looper < MAX_CURRENCY; looper++ )
        {
            transfer->cash_unit[looper] = 0;
        }
        for ( ;; )
        {
            short mn;
            argument = one_argument( argument, m_number );
            if ( m_number[0] == '\0' )
                break;
            argument = one_argument( argument, m_name );
            if ( m_name[0] == '\0' )
                break;
            if ( ( ( mn = money_lookup( m_name ) ) < 0 ) || ( !is_number( m_number ) ) )
            {
                snprintf( outbuf, MSL, "%s %s isn't a valid money type!\r\n", m_number, m_name );
                send_to_char( outbuf, ch );
                join_money( transfer, ch->in_room->treasure );
                return FALSE;
            }
            if ( ch->in_room->treasure->cash_unit[mn] < atoi( m_number ) )
            {
                /*        snprintf( outbuf, MSL, "There isn't that much %s here!\r\n", m_name );
                        send_to_char( outbuf, ch );  */
                join_money( transfer, ch->in_room->treasure );
                return FALSE;
            }
            ch->in_room->treasure->cash_unit[mn] -= atoi( m_number );
            transfer->cash_unit[mn] += atoi( m_number );
        }
    }
    if ( ( ch->carry_weight + money_weight( transfer ) ) > can_carry_w( ch ) )
    {
        snprintf( outbuf, MSL, "%s", "You cannot carry that much weight!\r\n" );
        send_to_char( outbuf, ch );
        join_money( transfer, ch->in_room->treasure );
        return FALSE;
    }
    ch->carry_weight += money_weight( transfer );
    if ( money_value( transfer ) <= 0 )
        return FALSE;
    snprintf( outbuf, MSL, "You pick up %s.\r\n", money_string( transfer ) );
    send_to_char( outbuf, ch );
    join_money( transfer, ch->money );
    return TRUE;
}
Esempio n. 15
0
void do_comment( CHAR_DATA * ch, char *argument )
{
    char buf[MAX_STRING_LENGTH];
    char arg[MAX_INPUT_LENGTH];
    char arg1[MAX_INPUT_LENGTH];
    NOTE_DATA *pnote;
    CHAR_DATA *victim;
    int vnum;
    int anum;

    if( IS_NPC( ch ) )
    {
        send_to_char( "Mobs can't use the comment command.\n\r", ch );
        return;
    }

    if( !ch->desc )
    {
        bug( "do_comment: no descriptor", 0 );
        return;
    }

    /*
     * Put in to prevent crashing when someone issues a comment command
     * from within the editor. -Narn
     */
    if( ch->desc->connected == CON_EDITING )
    {
        send_to_char( "You can't use the comment command from within the editor.\n\r", ch );
        return;
    }

    switch ( ch->substate )
    {
    default:
        break;
    case SUB_WRITING_NOTE:
        if( !ch->pnote )
        {
            bug( "do_comment: note got lost?", 0 );
            send_to_char( "Your note got lost!\n\r", ch );
            stop_editing( ch );
            return;
        }
        if( ch->dest_buf != ch->pnote )
            bug( "do_comment: sub_writing_note: ch->dest_buf != ch->pnote", 0 );
        STRFREE( ch->pnote->text );
        ch->pnote->text = copy_buffer( ch );
        stop_editing( ch );
        return;
    }

    set_char_color( AT_NOTE, ch );
    argument = one_argument( argument, arg );
    smash_tilde( argument );

    if( !str_cmp( arg, "about" ) )
    {

        victim = get_char_world( ch, argument );
        if( !victim )
        {
            send_to_char( "They're not logged on!\n\r", ch );  /* maybe fix this? */
            return;
        }

        if( IS_NPC( victim ) )
        {
            send_to_char( "No comments about mobs\n\r", ch );
            return;
        }


    }


    if( !str_cmp( arg, "list" ) )
    {
        victim = get_char_world( ch, argument );
        if( !victim )
        {
            send_to_char( "They're not logged on!\n\r", ch );  /* maybe fix this? */
            return;
        }

        if( IS_NPC( victim ) )
        {
            send_to_char( "No comments about mobs\n\r", ch );
            return;
        }

        if( get_trust( victim ) >= get_trust( ch ) )
        {
            send_to_char( "You're not of the right caliber to do this...\n\r", ch );
            return;
        }

        if( !victim->comments )
        {
            send_to_char( "There are no relevant comments.\n\r", ch );
            return;
        }

        vnum = 0;
        for( pnote = victim->comments; pnote; pnote = pnote->next )
        {
            vnum++;
            sprintf( buf, "%2d) %-10s [%s] %s\n\r", vnum, pnote->sender, pnote->date, pnote->subject );
            /* Brittany added date to comment list and whois with above change */
            send_to_char( buf, ch );
        }

        /*
         * act( AT_ACTION, "$n glances over the notes.", ch, NULL, NULL, TO_ROOM );
         */
        return;
    }

    if( !str_cmp( arg, "read" ) )
    {
        bool fAll;

        argument = one_argument( argument, arg1 );
        victim = get_char_world( ch, arg1 );
        if( !victim )
        {
            send_to_char( "They're not logged on!\n\r", ch );  /* maybe fix this? */
            return;
        }

        if( IS_NPC( victim ) )
        {
            send_to_char( "No comments about mobs\n\r", ch );
            return;
        }

        if( get_trust( victim ) >= get_trust( ch ) )
        {
            send_to_char( "You're not of the right caliber to do this...\n\r", ch );
            return;
        }

        if( !victim->comments )
        {
            send_to_char( "There are no relevant comments.\n\r", ch );
            return;
        }



        if( !str_cmp( argument, "all" ) )
        {
            fAll = TRUE;
            anum = 0;
        }
        else if( is_number( argument ) )
        {
            fAll = FALSE;
            anum = atoi( argument );
        }
        else
        {
            send_to_char( "Note read which number?\n\r", ch );
            return;
        }

        vnum = 0;
        for( pnote = victim->comments; pnote; pnote = pnote->next )
        {
            vnum++;
            if( vnum == anum || fAll )
            {
                sprintf( buf, "[%3d] %s: %s\n\r%s\n\rTo: %s\n\r",
                         vnum, pnote->sender, pnote->subject, pnote->date, pnote->to_list );
                send_to_char( buf, ch );
                send_to_char( pnote->text, ch );
                /*
                 * act( AT_ACTION, "$n reads a note.", ch, NULL, NULL, TO_ROOM );
                 */
                return;
            }
        }

        send_to_char( "No such comment.\n\r", ch );
        return;
    }

    if( !str_cmp( arg, "write" ) )
    {
        note_attach( ch );
        ch->substate = SUB_WRITING_NOTE;
        ch->dest_buf = ch->pnote;
        start_editing( ch, ch->pnote->text );
        return;
    }

    if( !str_cmp( arg, "subject" ) )
    {
        note_attach( ch );
        STRFREE( ch->pnote->subject );
        ch->pnote->subject = STRALLOC( argument );
        send_to_char( "Ok.\n\r", ch );
        return;
    }

    if( !str_cmp( arg, "to" ) )
    {
        note_attach( ch );
        STRFREE( ch->pnote->to_list );
        ch->pnote->to_list = STRALLOC( argument );
        send_to_char( "Ok.\n\r", ch );
        return;
    }

    if( !str_cmp( arg, "clear" ) )
    {
        if( ch->pnote )
        {
            STRFREE( ch->pnote->text );
            STRFREE( ch->pnote->subject );
            STRFREE( ch->pnote->to_list );
            STRFREE( ch->pnote->date );
            STRFREE( ch->pnote->sender );
            DISPOSE( ch->pnote );
        }
        ch->pnote = NULL;

        send_to_char( "Ok.\n\r", ch );
        return;
    }

    if( !str_cmp( arg, "show" ) )
    {
        if( !ch->pnote )
        {
            send_to_char( "You have no comment in progress.\n\r", ch );
            return;
        }

        sprintf( buf, "%s: %s\n\rTo: %s\n\r", ch->pnote->sender, ch->pnote->subject, ch->pnote->to_list );
        send_to_char( buf, ch );
        send_to_char( ch->pnote->text, ch );
        return;
    }

    if( !str_cmp( arg, "post" ) )
    {
        char *strtime;

        if( !ch->pnote )
        {
            send_to_char( "You have no comment in progress.\n\r", ch );
            return;
        }

        argument = one_argument( argument, arg1 );
        victim = get_char_world( ch, arg1 );
        if( !victim )
        {
            send_to_char( "They're not logged on!\n\r", ch );  /* maybe fix this? */
            return;
        }

        if( IS_NPC( victim ) )
        {
            send_to_char( "No comments about mobs\n\r", ch );
            return;
        }

        if( get_trust( victim ) > get_trust( ch ) )
        {
            send_to_char( "You're not of the right caliber to do this...\n\r", ch );
            return;
        }

        /*
         * act( AT_ACTION, "$n posts a note.", ch, NULL, NULL, TO_ROOM );
         */

        strtime = ctime( &current_time );
        strtime[strlen( strtime ) - 1] = '\0';
        ch->pnote->date = STRALLOC( strtime );

        pnote = ch->pnote;
        ch->pnote = NULL;


        /*
         * LIFO to make life easier
         */
        pnote->next = victim->comments;
        if( victim->comments )
            victim->comments->prev = pnote;
        pnote->prev = NULL;
        victim->comments = pnote;

        save_char_obj( victim );


#ifdef NOTDEFD
        fclose( fpReserve );
        sprintf( notefile, "%s/%s", BOARD_DIR, board->note_file );
        if( ( fp = fopen( notefile, "a" ) ) == NULL )
        {
            perror( notefile );
        }
        else
        {
            fprintf( fp, "Sender  %s~\nDate    %s~\nTo      %s~\nSubject %s~\nText\n%s~\n\n",
                     pnote->sender, pnote->date, pnote->to_list, pnote->subject, pnote->text );
            fclose( fp );
        }
        fpReserve = fopen( NULL_FILE, "r" );
#endif

        send_to_char( "Ok.\n\r", ch );
        return;
    }

    if( !str_cmp( arg, "remove" ) )
    {
        argument = one_argument( argument, arg1 );
        victim = get_char_world( ch, arg1 );
        if( !victim )
        {
            send_to_char( "They're not logged on!\n\r", ch );  /* maybe fix this? */
            return;
        }

        if( IS_NPC( victim ) )
        {
            send_to_char( "No comments about mobs\n\r", ch );
            return;
        }

        if( ( get_trust( victim ) >= get_trust( ch ) ) || ( get_trust( ch ) < 58 ) )  /* switch to some LEVEL_ thingie */
        {
            send_to_char( "You're not of the right caliber to do this...\n\r", ch );
            return;
        }

        /*
         * argument = one_argument(argument, arg);
         */
        if( !is_number( argument ) )
        {
            send_to_char( "Comment remove which number?\n\r", ch );
            return;
        }

        anum = atoi( argument );
        vnum = 0;
        for( pnote = victim->comments; pnote; pnote = pnote->next )
        {
            vnum++;
            if( ( 58 <= get_trust( ch ) ) /* switch to some LEVEL_ thingie */
                    && ( vnum == anum ) )
            {
                comment_remove( ch, victim, pnote );
                send_to_char( "Ok.\n\r", ch );
                /*
                 * act( AT_ACTION, "$n removes a note.", ch, NULL, NULL, TO_ROOM );
                 */
                return;
            }
        }

        send_to_char( "No such comment.\n\r", ch );
        return;
    }

    send_to_char( "Huh?  Type 'help comment' for usage (i hope!).\n\r", ch );
    return;
}
Esempio n. 16
0
FGActuator::FGActuator(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
{
  double denom;

  // inputs are read from the base class constructor

  PreviousOutput = 0.0;
  PreviousHystOutput = 0.0;
  PreviousRateLimOutput = 0.0;
  PreviousLagInput = PreviousLagOutput = 0.0;
  bias = lag = hysteresis_width = deadband_width = 0.0;
  rate_limited = false;
  rate_limit = rate_limit_incr = rate_limit_decr = 0.0; // no limit
  rate_limit_incr_prop = rate_limit_decr_prop = 0;
  fail_zero = fail_hardover = fail_stuck = false;
  ca = cb = 0.0;
  initialized = 0;
  saturated = false;

  if ( element->FindElement("deadband_width") ) {
    deadband_width = element->FindElementValueAsNumber("deadband_width");
  }
  if ( element->FindElement("hysteresis_width") ) {
    hysteresis_width = element->FindElementValueAsNumber("hysteresis_width");
  }

  // There can be a single rate limit specified, or increasing and 
  // decreasing rate limits specified, and rate limits can be numeric, or
  // a property.
  Element* ratelim_el = element->FindElement("rate_limit");
  while ( ratelim_el ) {
    rate_limited = true;
    FGPropertyManager* rate_limit_prop=0;

    string rate_limit_str = ratelim_el->GetDataLine();
    trim(rate_limit_str);
    if (is_number(rate_limit_str)) {
    rate_limit = fabs(element->FindElementValueAsNumber("rate_limit"));
    } else {
      if (rate_limit_str[0] == '-') rate_limit_str.erase(0,1);
      rate_limit_prop = PropertyManager->GetNode(rate_limit_str, true);
      if (rate_limit_prop == 0)
        std::cerr << "No such property, " << rate_limit_str << " for rate limiting" << std::endl;
    }

    if (ratelim_el->HasAttribute("sense")) {
      string sense = ratelim_el->GetAttributeValue("sense");
      if (sense.substr(0,4) == "incr") {
        if (rate_limit_prop != 0) rate_limit_incr_prop = rate_limit_prop;
        else                      rate_limit_incr = rate_limit;
      } else if (sense.substr(0,4) == "decr") {
        if (rate_limit_prop != 0) rate_limit_decr_prop = rate_limit_prop;
        else                      rate_limit_decr = -rate_limit;
  }
    } else {
      rate_limit_incr =  rate_limit;
      rate_limit_decr = -rate_limit;
    }
    ratelim_el = element->FindNextElement("rate_limit");
  }

  if ( element->FindElement("bias") ) {
    bias = element->FindElementValueAsNumber("bias");
  }
  if ( element->FindElement("lag") ) {
    lag = element->FindElementValueAsNumber("lag");
    denom = 2.00 + dt*lag;
    ca = dt*lag / denom;
    cb = (2.00 - dt*lag) / denom;
  }

  FGFCSComponent::bind();
  bind();

  Debug(0);
}
Esempio n. 17
0
BOOL CALLBACK ConfigDialog::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
{
	LRESULT result;

	switch (Message)
	{
	case WM_INITDIALOG :
		{
			initializeOptions();
			goToCenter();

			Edit_LimitText(GetDlgItem(_hSelf, IDC_MAXDISPLAYFILES), 7);
			Edit_LimitText(GetDlgItem(_hSelf, IDC_MAXTRAVERSEFILES), 7);
			Edit_LimitText(GetDlgItem(_hSelf, IDC_SEARCHCONTEXTPATH), MAX_PATH);

			initTooltips();

			return TRUE;
		}

	case WM_COMMAND :
		{
			switch (LOWORD(wParam))
			{
			case IDC_RADIOSORTREMEMBER:
			case IDC_RADIOSORTINDEX:
			case IDC_RADIOSORTPATH:
			case IDC_RADIOSORTFILENAME:
				{
					enableOrDisableSortCheckBoxes();
					break;
				}
			case IDC_CHECKSORTDESCENDING :
			{
				_options->activeReversedSortOrder = (BST_CHECKED != ::SendDlgItemMessage(_hSelf, IDC_CHECKOVERRIDESORTWHENTABBING, BM_GETCHECK, 0, 0));
				break;
			}
			case IDC_CHECKDIALOGFORCTRLTAB :
				{
					bool checked = BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECKDIALOGFORCTRLTAB, BM_GETCHECK, 0, 0);
					EnableWindow(GetDlgItem(_hSelf, IDC_CHECKREVERTSORTORDERDURINGTABBING), checked);
					break;
				}
			case IDC_CHECKCONFIGURESEARCHCONTEXT:
				{
					bool isChecked = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECKCONFIGURESEARCHCONTEXT, BM_GETCHECK, 0, 0));
					EnableWindow(GetDlgItem(_hSelf, IDC_SEARCHCONTEXTPATH), isChecked);
					EnableWindow(GetDlgItem(_hSelf, IDC_MAXTRAVERSEFILES), isChecked);
					EnableWindow(GetDlgItem(_hSelf, IDC_MAXDISPLAYFILES), isChecked);
					EnableWindow(GetDlgItem(_hSelf, IDC_CHECKINCLUDEINDEX), !isChecked);
					EnableWindow(GetDlgItem(_hSelf, IDC_CHECKINCLUDEVIEW), !isChecked);
					EnableWindow(GetDlgItem(_hSelf, IDC_RADIOSORTINDEX), !isChecked);
					EnableWindow(GetDlgItem(_hSelf, IDC_CHECKONLYCURRENTVIEW), !isChecked);
					EnableWindow(GetDlgItem(_hSelf, IDC_CHECKSEPARATECOLUMNFORVIEW), !isChecked);

					if(BST_CHECKED && ::SendDlgItemMessage(_hSelf, IDC_RADIOSORTINDEX, BM_GETCHECK, 0, 0))
					{
						::SendDlgItemMessage(_hSelf, IDC_RADIOSORTFILENAME, BM_SETCHECK, BST_CHECKED, 0);
					}
					else if(!BST_CHECKED && ::SendDlgItemMessage(_hSelf, IDC_RADIOSORTINDEX, BM_GETCHECK, 0, 0))
					{
						::SendDlgItemMessage(_hSelf, IDC_RADIOSORTREMEMBER, BM_SETCHECK, BST_UNCHECKED, 0);
						::SendDlgItemMessage(_hSelf, IDC_RADIOSORTFILENAME, BM_SETCHECK, BST_UNCHECKED, 0);
						::SendDlgItemMessage(_hSelf, IDC_RADIOSORTPATH, BM_SETCHECK, BST_UNCHECKED, 0);
					}
					break;
				}
			case IDC_CHECKAUTOSIZECOLUMNS:
				{
					result = ::SendDlgItemMessage(_hSelf, IDC_CHECKAUTOSIZECOLUMNS, BM_GETCHECK, 0, 0);
					EnableWindow(GetDlgItem(_hSelf, IDC_CHECKAUTOSIZEWINDOW), BST_CHECKED == result);
					break;
				}
			case IDOK :
				{
					tstring error = _T("");
					_options->searchFlags = 0;

					result = ::SendDlgItemMessage(_hSelf, IDC_CHECKSTARTONLY, BM_GETCHECK, 0, 0);
					if (BST_CHECKED == result)
						_options->searchFlags |= SEARCHFLAG_STARTONLY;

					result = ::SendDlgItemMessage(_hSelf, IDC_CHECKCASE, BM_GETCHECK, 0, 0);
					if (BST_CHECKED == result)
						_options->searchFlags |= SEARCHFLAG_CASESENSITIVE;

					result = ::SendDlgItemMessage(_hSelf, IDC_CHECKINCLUDEPATH, BM_GETCHECK, 0, 0);
					if (BST_CHECKED == result)
						_options->searchFlags |= SEARCHFLAG_INCLUDEPATH;

					result = ::SendDlgItemMessage(_hSelf, IDC_CHECKINCLUDEFILENAME, BM_GETCHECK, 0, 0);
					if (BST_CHECKED == result)
						_options->searchFlags |= SEARCHFLAG_INCLUDEFILENAME;

					result = ::SendDlgItemMessage(_hSelf, IDC_CHECKINCLUDEINDEX, BM_GETCHECK, 0, 0);
					if (BST_CHECKED == result)
						_options->searchFlags |= SEARCHFLAG_INCLUDEINDEX;

					result = ::SendDlgItemMessage(_hSelf, IDC_CHECKINCLUDEVIEW, BM_GETCHECK, 0, 0);
					if (BST_CHECKED == result)
						_options->searchFlags |= SEARCHFLAG_INCLUDEVIEW;

					_options->hasConfiguredContext = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECKCONFIGURESEARCHCONTEXT, BM_GETCHECK, 0, 0));

					if(
						(
							!_options->hasConfiguredContext
							&& !(_options->searchFlags & SEARCHFLAG_INCLUDEPATH)
							&& !(_options->searchFlags & SEARCHFLAG_INCLUDEFILENAME)
							&& !(_options->searchFlags & SEARCHFLAG_INCLUDEINDEX)
							&& !(_options->searchFlags & SEARCHFLAG_INCLUDEVIEW)
						)
						|| (
							_options->hasConfiguredContext
							&& !(_options->searchFlags & SEARCHFLAG_INCLUDEPATH)
							&& !(_options->searchFlags & SEARCHFLAG_INCLUDEFILENAME)
						)
					){
						tstring tmpMsg = _T("- Must select at least one item to include in your search");
						error.length() > 0
							? error.append(_T("\r\n")).append(tmpMsg)
							: error.append(tmpMsg);
					}

					_options->disabledSelectedSortOrder = NONE;
					if (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_RADIOSORTREMEMBER, BM_GETCHECK, 0, 0))
					{
						if (IsWindowEnabled(GetDlgItem(_hSelf, IDC_RADIOSORTREMEMBER)))
							_options->defaultSortOrder = ALWAYSREMEMBER;
						else
							_options->disabledSelectedSortOrder = ALWAYSREMEMBER;
					}

					_options->reversedSortOrder = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECKSORTDESCENDING, BM_GETCHECK, 0, 0));
					_options->resetSortOrder = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECKRESETSORTORDER, BM_GETCHECK, 0, 0));

					if (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_RADIOSORTFILENAME, BM_GETCHECK, 0, 0))
					{
						if (IsWindowEnabled(GetDlgItem(_hSelf, IDC_RADIOSORTFILENAME)))
						{
							_options->activeSortOrder = FILENAME;
							_options->defaultSortOrder = FILENAME;
						}
						else
							_options->disabledSelectedSortOrder = FILENAME;
					}

					if (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_RADIOSORTPATH, BM_GETCHECK, 0, 0))
					{
						if (IsWindowEnabled(GetDlgItem(_hSelf, IDC_RADIOSORTPATH)))
						{
							_options->activeSortOrder = PATH;
							_options->defaultSortOrder = PATH;
						}
						else
							_options->disabledSelectedSortOrder = PATH;
					}

					if (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_RADIOSORTINDEX, BM_GETCHECK, 0, 0))
					{
						if (IsWindowEnabled(GetDlgItem(_hSelf, IDC_RADIOSORTINDEX)))
						{
							_options->activeSortOrder = INDEX;
							_options->defaultSortOrder = INDEX;
						}
						else
							_options->disabledSelectedSortOrder = INDEX;
					}

					_options->overrideSortWhenTabbing = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECKOVERRIDESORTWHENTABBING, BM_GETCHECK, 0, 0));

					_options->revertSortWhenTabbing = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECKREVERTSORTORDERDURINGTABBING, BM_GETCHECK, 0, 0));

					_options->onlyUseCurrentView = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECKONLYCURRENTVIEW, BM_GETCHECK, 0, 0));

					_options->autoSizeColumns = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECKAUTOSIZECOLUMNS, BM_GETCHECK, 0, 0));

					_options->autoSizeWindow = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECKAUTOSIZEWINDOW, BM_GETCHECK, 0, 0));

					_options->columnForView = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECKSEPARATECOLUMNFORVIEW, BM_GETCHECK, 0, 0));

					_options->showDialogForCtrlTab = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECKDIALOGFORCTRLTAB, BM_GETCHECK, 0, 0));

					_options->useHomeForEdit = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECKUSEHOMEFOREDIT, BM_GETCHECK, 0, 0));

					if(BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECKWILDCARD, BM_GETCHECK, 0, 0))
						_options->searchFlags |= SEARCHFLAG_INCLUDEWILDCARD;

					if (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECKCASE, BM_GETCHECK, 0, 0))
						_options->searchFlags |= SEARCHFLAG_CASESENSITIVE;

					bool isNumber = true;
					TCHAR bufMaxs[20];
					GetDlgItemText(_hSelf, IDC_MAXTRAVERSEFILES, bufMaxs, MAX_PATH);
					tstring tmpMaxs = bufMaxs;
					if(tmpMaxs.length() > 0 && is_number(tmpMaxs))
					{
						_options->maxTraverseFiles = _tstoi(tmpMaxs.c_str());
					}
					else
					{
						tstring tmpMsg = _T("- Maximum files traversed is not a valid number");
						error.length() > 0
							? error.append(_T("\r\n")).append(tmpMsg)
							: error.append(tmpMsg);
						isNumber = false;
					}

					GetDlgItemText(_hSelf, IDC_MAXDISPLAYFILES, bufMaxs, MAX_PATH);
					tmpMaxs = bufMaxs;
					if(tmpMaxs.length() > 0 && is_number(tmpMaxs))
					{
						_options->maxDisplayFiles = _tstoi(tmpMaxs.c_str());
					}
					else
					{
						tstring tmpMsg = _T("- Maximum files displayed is not a valid number");
						error.length() > 0
							? error.append(_T("\r\n")).append(tmpMsg)
							: error.append(tmpMsg);
						isNumber = false;
					}
					if(isNumber && _options->maxTraverseFiles < _options->maxDisplayFiles)
					{
						tstring tmpMsg = _T("- Max traverse files must be more than max display files.");
						error.length() > 0
							? error.append(_T("\r\n")).append(tmpMsg)
							: error.append(tmpMsg);
					}

					TCHAR tmpPath[MAX_PATH];
					result = ::GetDlgItemText(_hSelf, IDC_SEARCHCONTEXTPATH, tmpPath, MAX_PATH);
					tstring tstrPath = tmpPath;
					if(_options->hasConfiguredContext
						&& (tstrPath.length() > 0))
						_options->configuredContextPath = (tstrPath.back() == _T('\\')) ? tstrPath : tstrPath.append(_T("\\"));

					if(_options->hasConfiguredContext
						&& !(_options->ConfiguredContextPathIsValid())
						){
						tstring tmpMsg = _T("- Context path is invalid.  Please provide a valid context path.");
						error.length() > 0
							? error.append(_T("\r\n")).append(tmpMsg)
							: error.append(tmpMsg);
					}

					if(error.length() > 0)
					{
						MessageBox(_hSelf, error.c_str(), _T("Error"), MB_OK);
						return TRUE;
					}

					g_filesNeedToBeReloaded(
						(_tcscmp(contextPathOnInit.c_str(), _options->configuredContextPath.c_str()) != 0)
						|| (!contextConfiguredOnInit && _options->hasConfiguredContext));
					redisplaySwitchDialog();
				}
			case IDCANCEL :
				{
					if (_isModal)
						EndDialog(_hSelf, 0);
					else
						display(FALSE);

					redisplaySwitchDialog();
					return TRUE;
				}
			case IDABORT :
			case IDCLOSE :
				{
					redisplaySwitchDialog();
				}
			default :
				break;
			}
		}
	}
	return FALSE;
}
Esempio n. 18
0
static void prvInterpreterDaemon(void* pvParameters)
{
  char c;
  char buffer[32];
  char* cmd;
  int abort, size;
  vTaskDelay(1000);
  vUartPuts("\r\n");
  for (;;)
  {
    abort = 0;
    size = 0;

    vUartPuts(prompt);
    vUartPuts(" # ");

    buffer[0] = 0;
    while ((c = cUartGetc()))
    {
      if (size == 32)
      {
        abort = 1;
        vUartPuts("\r\nerror: command too long...\r\n");
        break;
      }

      if (c == '\r' || c == '\n')
      {
        vUartPuts("\r\n");
        buffer[size] = 0;
        break;
      }
      else if (c == 0x03)
      {
        abort = 1;
        vUartPuts("\r\n");
        buffer[size] = 0;
        vUartPuts(buffer);
        vUartPuts(": abort\r\n");
        break;
      }
      else if (c == 0x08 || c == 0x7f)
      {
        if (size > 0)
        {
          size--;
          vUartPutc(c);
          vUartPutc(' ');
          vUartPutc(c);
        }
        continue;
      }
      else if (!is_letter(c) && !is_number(c)
               && !is_space(c) && c != '-'
               && c != ':'     && c != '.')
        continue;

      vUartPutc(c);
      buffer[size++] = c;
    }

    if (abort)
      continue;

    cmd = trim_in_place(buffer);

    // Skip empty command
    if (cmd[0] == 0)
      continue;

    abort = 1;
    for (int i = 0; i < n_tokens; i++)
    {
      if (cmd[0] == tokens[i].command)
      {
        (*tokens[i].handler)(cmd + 1);
        abort = 0;
        vUartPuts("\r\n");
        break;
      }
    }

    if (abort)
    {
      vUartPuts("error: undefined command '");
      vUartPutc(cmd[0]);
      vUartPuts("\r\n");
    }
  }
}
Esempio n. 19
0
/* The main quest function */
void do_quest(CHAR_DATA * ch, char *argument)
{
	CHAR_DATA *questman;
	OBJ_DATA *obj = NULL, *obj_next;

	char buf[MAX_STRING_LENGTH];
	char result[MAX_STRING_LENGTH * 2];
	char arg1[MAX_INPUT_LENGTH];
	char arg2[MAX_INPUT_LENGTH];
	char arg3[MAX_INPUT_LENGTH];
	int amt = 0;

	argument = one_argument(argument, arg1);
	argument = one_argument(argument, arg2);
	argument = one_argument(argument, arg3);

	if (arg3[0] != '\0')
		amt = is_number(arg3) ? atoi(arg3) : 1;
	else
		amt = 1;

	if (!strcmp(arg1, "info")) {
		if (IS_SET(ch->act, PLR_QUESTOR)) {
			if ((!ch->questmob && !ch->questobj)
			    && ch->questgiver->short_descr != NULL) {
				sprintf(buf,
					"&YYour quest is ALMOST complete!\n\rGet back to %s before your time runs out!\n\r",
					ch->questgiver->short_descr);
				send_to_char(AT_YELLOW, buf, ch);
			} else if (ch->questobj) {
				sprintf(buf,
					"You are on a quest to find %s!\n\r",
					ch->questobj->short_descr);
				send_to_char(AT_WHITE, buf, ch);
				return;
			} else if (ch->questmob) {
				sprintf(buf,
					"You are on a quest to kill %s!\n\r",
					ch->questmob->short_descr);
				send_to_char(AT_WHITE, buf, ch);
				return;
			}
		} else
			send_to_char(AT_WHITE,
				     "You aren't currently on a quest.\n\r",
				     ch);
		return;
	}
/* Quest area: info on area only for object quests */

	if (!strcmp(arg1, "area")) {
		if (IS_SET(ch->act, PLR_QUESTOR)) {
			if (ch->questobj) {
				sprintf(buf, "AREA: %s\n\r", room->area->name);
				send_to_char(AT_WHITE, buf, ch);
			} else
				send_to_char(AT_WHITE,
					     "You aren't currently on an object quest.\n\r",
					     ch);
			return;
		} else
			send_to_char(AT_WHITE,
				     "You aren't currently on a quest.\n\r",
				     ch);
		return;
	}

	if (!strcmp(arg1, "points")) {
		sprintf(buf, "You have %d quest points.\n\r", ch->questpoints);
		send_to_char(AT_WHITE, buf, ch);
		return;
	} else if (!strcmp(arg1, "time")) {
		if (!IS_SET(ch->act, PLR_QUESTOR)) {
			send_to_char(AT_WHITE,
				     "You aren't currently on a quest.\n\r",
				     ch);

			if (ch->nextquest > 1) {
				sprintf(buf,
					"There are %d minutes remaining until you can go on another quest.\n\r",
					ch->nextquest);
				send_to_char(AT_WHITE, buf, ch);
			} else if (ch->nextquest == 1) {
				sprintf(buf,
					"There is less than a minute remaining until you can go on another quest.\n\r");
				send_to_char(AT_WHITE, buf, ch);
			}
		} else if (ch->countdown > 0) {
			sprintf(buf, "Time left for current quest: %d\n\r",
				ch->countdown);
			send_to_char(AT_WHITE, buf, ch);
		}
		return;
	}

/* Checks for a Questmaster in the room */

	for (questman = ch->in_room->people; questman;
	     questman = questman->next_in_room) {
		if (IS_NPC(questman) && IS_SET(questman->act, ACT_QUESTMASTER))
			break;
	}

	if (!questman) {
		send_to_char(AT_WHITE, "You can't do that here.\n\r", ch);
		return;
	}

	if (questman->fighting != NULL) {
		send_to_char(AT_WHITE, "Wait until the fighting stops.\n\r",
			     ch);
		return;
	}

/* Can have multiple questmasters, ch must report back to the one who gave quest */

	ch->questgiver = questman;

/* List displaying items one can buy with quest points */

	if (!strcmp(arg1, "list")) {
		act(AT_WHITE, "$n asks $N for a list of quest items.", ch, NULL,
		    questman, TO_ROOM);
		act(AT_WHITE, "You ask $N for a list of quest items.", ch, NULL,
		    questman, TO_CHAR);
		sprintf(result, "&W[&R%5s %10s&W] [&R%30s&W]\n\r", "Lvl",
			"Points", "Item");

		for (cnt = 0; quest_table[cnt].name[0] != '\0'; cnt++) {
			sprintf(buf, "[%5d %10d] [%*s]\n\r",
				quest_table[cnt].level,
				quest_table[cnt].qp,
				(int)(30 + strlen(quest_table[cnt].name) -
				      strlen_wo_col(quest_table[cnt].name)),
				quest_table[cnt].name);
			strcat(result, buf);
		}
		send_to_char(AT_WHITE, result, ch);
		return;
	}

	else if (!strcmp(arg1, "buy")) {
		if (arg2[0] == '\0') {
			send_to_char(AT_WHITE,
				     "To buy an item, type 'QUEST BUY <item> <amount>'.\n\rAmount is optional.\n\r",
				     ch);
			return;
		}

		for (cnt = 0; quest_table[cnt].name[0] != '\0'; cnt++) {
			if (is_name(ch, arg2, quest_table[cnt].name)) {
				if (ch->questpoints >=
				    quest_table[cnt].qp * amt) {
					if (quest_table[cnt].level <= ch->level) {
						ch->questpoints -=
						    quest_table[cnt].qp * amt;
						if (is_name
						    (ch, arg2,
						     "prac pracs practice practices"))
						{
							ch->practice += amt;
							if (amt > 1) {
								act(AT_WHITE,
								    "$N gives some practice sessions to $n.",
								    ch, NULL,
								    questman,
								    TO_ROOM);
								act(AT_WHITE,
								    "$N gives you some practice sessions.",
								    ch, NULL,
								    questman,
								    TO_CHAR);
							} else {
								act(AT_WHITE,
								    "$N gives a practice session to $n.",
								    ch, NULL,
								    questman,
								    TO_ROOM);
								act(AT_WHITE,
								    "$N gives you a practice session.",
								    ch, NULL,
								    questman,
								    TO_CHAR);
							}
						} else {
							while (amt > 0) {
								obj =
								    create_object
								    (get_obj_index
								     (quest_table
								      [cnt].
								      vnum),
								     quest_table
								     [cnt].
								     level);
								act(AT_WHITE,
								    "$N gives $p to $n.",
								    ch, obj,
								    questman,
								    TO_ROOM);
								act(AT_WHITE,
								    "$N gives you $p.",
								    ch, obj,
								    questman,
								    TO_CHAR);
								obj_to_char(obj,
									    ch);
								amt--;
							}
						}
					} else {
						sprintf(buf,
							"Sorry, %s, but you are too inexperienced to use that item.\n\r",
							ch->name);
						do_say(questman, buf);
						return;
					}
				} else {
					sprintf(buf,
						"Sorry, %s, but you don't have enough quest points for that.\n\r",
						ch->name);
					do_say(questman, buf);
					return;
				}
				break;
			}
		}

		if ((obj == NULL)
		    && !(is_name(ch, arg2, "prac pracs practice practices"))) {
			sprintf(buf, "I don't have that item, %s.\n\r",
				ch->name);
			do_say(questman, buf);
		}
		return;
	} else if (!strcmp(arg1, "request")) {
		act(AT_WHITE, "$n asks $N for a quest.", ch, NULL, questman,
		    TO_ROOM);
		act(AT_WHITE, "You ask $N for a quest.", ch, NULL, questman,
		    TO_CHAR);
		if (IS_SET(ch->act, PLR_QUESTOR)) {
			sprintf(buf, "But you're already on a quest!");
			do_say(questman, buf);
			return;
		}
		if (ch->nextquest > 0) {
			sprintf(buf,
				"You're very brave, %s, but let someone else have a chance.",
				ch->name);
			do_say(questman, buf);
			sprintf(buf, "Come back later.");
			do_say(questman, buf);
			return;
		}

		sprintf(buf, "Thank you, brave %s!", ch->name);
		do_say(questman, buf);

		generate_quest(ch, questman);

		if (ch->questmob || ch->questobj) {
			if (ch->questmob)
				ch->countdown = number_range(10, 30);	/* time to complete quest */

/* Allow longer chance for an object quest */

			if (ch->questobj)
				ch->countdown = number_range(20, 45);

			SET_BIT(ch->act, PLR_QUESTOR);
			sprintf(buf,
				"You have %d minutes to complete this quest.",
				ch->countdown);
			do_say(questman, buf);
			sprintf(buf, "May the gods go with you!");
			do_say(questman, buf);
		}
		return;
	} else if (!strcmp(arg1, "complete")) {
		act(AT_WHITE, "$n informs $N $e has completed $S quest.", ch,
		    NULL, questman, TO_ROOM);
		act(AT_WHITE, "You inform $N you have completed $S quest.", ch,
		    NULL, questman, TO_CHAR);

/* Check if ch returned to correct QuestMaster */
		if (ch->questgiver != questman) {
			sprintf(buf,
				"I never sent you on a quest! Perhaps you're thinking of someone else.");
			do_say(questman, buf);
			return;
		}

		if (IS_SET(ch->act, PLR_QUESTOR)) {
			if ((!ch->questmob && !ch->questobj)
			    && ch->countdown > 0) {
				int pointreward, pracreward;

				pointreward = number_range(10, 30);

				sprintf(buf,
					"Congratulations on completing your quest!");
				do_say(questman, buf);
				sprintf(buf,
					"As a reward, I am giving you %d quest points!",
					pointreward);
				do_say(questman, buf);

				/* 5% chance of getting between 1 and 6 practices :> */
				if (chance(5)) {
					pracreward = number_range(1, 6);
					sprintf(buf,
						"You gain %d practices!\n\r",
						pracreward);
					send_to_char(AT_WHITE, buf, ch);
					ch->practice += pracreward;
				}

				REMOVE_BIT(ch->act, PLR_QUESTOR);
				ch->questgiver = NULL;
				ch->countdown = 0;
				ch->questmob = NULL;
				ch->questobj = NULL;
				ch->nextquest = 30;	/* 30 */
				ch->questpoints += pointreward;

				return;
			}
/* Look to see if ch has quest obj in inventory */
			else if (ch->questobj && ch->countdown > 0) {
				bool obj_found = FALSE;

				for (obj = ch->carrying; obj != NULL;
				     obj = obj_next) {
					obj_next = obj->next_content;

					if (obj == ch->questobj) {
						obj_found = TRUE;
						break;
					}
				}
				/* If ch returned without quest obj... */
				if (!obj_found) {
					sprintf(buf,
						"You haven't completed the quest yet, but there is still time!");
					do_say(questman, buf);
					return;
				}
				{
					int pointreward, pracreward;

					/* Ch receives between 10 and 30 qp for completing quest :> */
					pointreward = number_range(10, 30);

					/* Player doesn't keep quest object */
					act(AT_WHITE, "You hand $p to $N.", ch,
					    obj, questman, TO_CHAR);
					act(AT_WHITE, "$n hands $p to $N.", ch,
					    obj, questman, TO_ROOM);

					sprintf(buf,
						"Congratulations on completing your quest!");
					do_say(questman, buf);
					sprintf(buf,
						"As a reward, I am giving you %d quest points!",
						pointreward);
					do_say(questman, buf);

					/* 5% chance to get pracs.. */
					if (chance(5)) {
						pracreward = number_range(1, 6);
						sprintf(buf,
							"You gain %d practices!\n\r",
							pracreward);
						send_to_char(AT_WHITE, buf, ch);
						ch->practice += pracreward;
					}

					REMOVE_BIT(ch->act, PLR_QUESTOR);
					ch->questgiver = NULL;
					ch->countdown = 0;
					ch->questmob = NULL;
					ch->questobj = NULL;
					ch->nextquest = 30;	/* 30 min till ch can quest again */
					ch->questpoints += pointreward;
					extract_obj(obj);
					return;
				}
			}
/* Quest not complete, but still time left */
			else if ((ch->questmob || ch->questobj)
				 && ch->countdown > 0) {
				sprintf(buf,
					"You haven't completed the quest yet, but there is still time!");
				do_say(questman, buf);
				return;
			}
		}
		if (ch->nextquest > 0)
			sprintf(buf,
				"But you didn't complete your quest in time!");
		else
			sprintf(buf, "You have to REQUEST a quest first, %s.",
				ch->name);
		do_say(questman, buf);
		return;
	}

	if (arg1[0] == '\0') {
		if (IS_SET(ch->act, PLR_QUESTOR)) {
			if (ch->questobj) {
				sprintf(buf,
					"You are on a quest to find %s!\n\r",
					ch->questobj->short_descr);
				send_to_char(AT_WHITE, buf, ch);
			} else if (ch->questmob) {
				sprintf(buf,
					"You are on a quest to kill %s!\n\r",
					ch->questmob->short_descr);
				send_to_char(AT_WHITE, buf, ch);
			}

			sprintf(buf, "You have %d quest points.\n\r",
				ch->questpoints);
			send_to_char(AT_WHITE, buf, ch);
			if (ch->countdown > 0) {
				sprintf(buf,
					"Time left for current quest: %d\n\r",
					ch->countdown);
				send_to_char(AT_WHITE, buf, ch);
			}
		}
		if (ch->nextquest > 1) {
			sprintf(buf,
				"There are %d minutes remaining until you can go on another quest.\n\r",
				ch->nextquest);
			send_to_char(AT_WHITE, buf, ch);
		} else if (ch->nextquest == 1) {
			sprintf(buf,
				"There is less than a minute remaining until you can go on another quest.\n\r");
			send_to_char(AT_WHITE, buf, ch);
		}

		send_to_char(AT_RED,
			     "QUEST commands: POINTS INFO TIME REQUEST COMPLETE LIST BUY AREA.\n\r",
			     ch);
		send_to_char(AT_WHITE,
			     "For more information, type 'HELP AUTOQUEST'.\n\r",
			     ch);
		return;
	}
}
Esempio n. 20
0
AbstractQoreNode *command::get_node(const CS_DATAFMT_EX& datafmt, const output_value_buffer& buffer, ExceptionSink* xsink) {
   if (buffer.indicator == -1) { // SQL NULL
      return null();
   }

   const QoreEncoding *encoding = m_conn.getEncoding();

   switch (datafmt.datatype) {
      case CS_LONGCHAR_TYPE:
      case CS_VARCHAR_TYPE:
      case CS_TEXT_TYPE: {
	 CS_CHAR* value = (CS_CHAR*)(buffer.value);

	 if (use_numbers(m_conn) && is_number(datafmt))
	    return new QoreNumberNode(value);

	 ReferenceHolder<QoreStringNode> s(new QoreStringNode(value, buffer.value_len - 1, encoding), xsink);

	 if (need_trim(datafmt))
	    s->trim_trailing(' ');
	 return s.release();
      }

      case CS_CHAR_TYPE: {
	 CS_CHAR* value = (CS_CHAR*)(buffer.value);
	 if (use_numbers(m_conn) && is_number(datafmt))
	    return new QoreNumberNode(value);

	 ReferenceHolder<QoreStringNode> s(new QoreStringNode(value, buffer.value_len, encoding), xsink);

	 if (need_trim(datafmt))
	    s->trim_trailing(' ');
	 return s.release();
      }

      case CS_VARBINARY_TYPE:
      case CS_BINARY_TYPE:
      case CS_LONGBINARY_TYPE:
      case CS_IMAGE_TYPE: {
	 CS_BINARY* value = (CS_BINARY*)(buffer.value);
	 int size = buffer.value_len;
	 void* block = malloc(size);
	 if (!block) {
	    xsink->outOfMemory();
	    return 0;
	 }
	 memcpy(block, value, size);
	 return new BinaryNode(block, size);
      }

      case CS_TINYINT_TYPE: {
	 CS_TINYINT* value = (CS_TINYINT*)(buffer.value);
	 return new QoreBigIntNode(*value);
      }

      case CS_SMALLINT_TYPE: {
	 CS_SMALLINT* value = (CS_SMALLINT*)(buffer.value);
	 return new QoreBigIntNode(*value);
      }

      case CS_INT_TYPE: {
	 CS_INT* value = (CS_INT*)(buffer.value);
	 return new QoreBigIntNode(*value);
      }

#ifdef CS_BIGINT_TYPE
      case CS_BIGINT_TYPE: {
	 int64 *value = (int64 *)(buffer.value);
	 return new QoreBigIntNode(*value);
      }
#endif

      case CS_REAL_TYPE: {
	 CS_REAL* value = (CS_REAL*)(buffer.value);
	 return new QoreFloatNode((double)*value);
      }

      case CS_FLOAT_TYPE: {
	 CS_FLOAT* value = (CS_FLOAT*)(buffer.value);
	 return new QoreFloatNode((double)*value);
      }

      case CS_BIT_TYPE: {
	 CS_BIT* value = (CS_BIT*)(buffer.value);
	 return get_bool_node(*value != 0);
      }

      case CS_DATETIME_TYPE: {
	 CS_DATETIME* value = (CS_DATETIME*)(buffer.value);

	 ss::Conversions conv;
	 // NOTE: can't find a USER_* define for 38!
	 if (datafmt.usertype == 38)
            return conv.TIME_to_DateTime(*value, m_conn.getTZ());

	 return conv.DATETIME_to_DateTime(*value, m_conn.getTZ());
      }
      case CS_DATETIME4_TYPE: {
	 ss::Conversions conv;
	 CS_DATETIME4* value = (CS_DATETIME4*)(buffer.value);
	 return conv.DATETIME4_to_DateTime(*value);
      }

      default:
	 xsink->raiseException("DBI-EXEC-EXCEPTION", "Unknown data type %d", (int)datafmt.datatype);
	 return 0;
   } // switch
}
Esempio n. 21
0
void game_higher_lower( CHAR_DATA *ch, char *argument )
{
    char arg[MAX_INPUT_LENGTH];
    char buf[MAX_STRING_LENGTH];
    long amount;
    int your_roll, his_roll;
    CHAR_DATA *gamemaster;

    argument = one_argument( argument, arg );

    buf[0] = '\0';

    if ( arg[0] == '\0' )
    {
        send_to_char( "Syntax: game higher-lower <amount>\n\r", ch );
        return;
    }

    for ( gamemaster = ch->in_room->people; gamemaster != NULL; gamemaster = gamemaster->next_in_room )
    {
        if ( !IS_NPC( gamemaster ) )
            continue;
        if ( gamemaster->spec_fun == spec_lookup( "spec_gamemaster" ) )
            break;
    }

    if ( gamemaster == NULL || gamemaster->spec_fun != spec_lookup( "spec_gamemaster" ) )
    {
        send_to_char("You can't do that here.\n\r",ch);
        return;
    }

    if ( gamemaster->fighting != NULL)
    {
        send_to_char("Wait until the fighting stops.\n\r",ch);
        return;
    }

    if ( !is_number( arg ) )
    {
        send_to_char( "You must bet a number.\n\r", ch );
        return;
    }

    your_roll = dice( 2, 4 );
    his_roll = dice( 2, 6 );

    amount = atol( arg );

    if ( amount < 1 )
    {
        send_to_char( "Bet SOMETHING, will you?\n\r", ch );
        return;
    }
    if (amount > ch->silver) {
        send_to_char( "We don't take credit here?\n\r", ch );
        return;
    }

	if (amount > 10000) {
		send_to_char( "100 gold or 10000 silver is the max bet here.\n\r",ch);
		return; 	
	}


    sprintf( buf, "%s rolls the dice and gets a %d.\n\rYour roll is %d.\n\r",                                gamemaster->short_descr, his_roll, your_roll );
    send_to_char( buf, ch );
    
    if ( your_roll > his_roll )     /* you win! */
        win( ch, amount * 2 );
    else
        lose( ch, amount );
    return;
}
Esempio n. 22
0
Cell *split(Node **a, int nnn)	/* split(a[0], a[1], a[2]); a[3] is type */
{
	Cell *x = 0, *y, *ap;
	char *s, *origs;
	int sep;
	char *t, temp, num[50], *fs = 0;
	int n, tempstat, arg3type;

	y = execute(a[0]);	/* source string */
	origs = s = strdup(getsval(y));
	arg3type = ptoi(a[3]);
	if (a[2] == 0)		/* fs string */
		fs = *FS;
	else if (arg3type == STRING) {	/* split(str,arr,"string") */
		x = execute(a[2]);
		fs = getsval(x);
	} else if (arg3type == REGEXPR)
		fs = "(regexpr)";	/* split(str,arr,/regexpr/) */
	else
		FATAL("illegal type of split");
	sep = *fs;
	ap = execute(a[1]);	/* array name */
	freesymtab(ap);
	   dprintf( ("split: s=|%s|, a=%s, sep=|%s|\n", s, NN(ap->nval), fs) );
	ap->tval &= ~STR;
	ap->tval |= ARR;
	ap->sval = (char *) makesymtab(NSYMTAB);

	n = 0;
        if (arg3type == REGEXPR && strlen((char*)((fa*)a[2])->restr) == 0) {
		/* split(s, a, //); have to arrange that it looks like empty sep */
		arg3type = 0;
		fs = "";
		sep = 0;
	}
	if (*s != '\0' && (strlen(fs) > 1 || arg3type == REGEXPR)) {	/* reg expr */
		fa *pfa;
		if (arg3type == REGEXPR) {	/* it's ready already */
			pfa = (fa *) a[2];
		} else {
			pfa = makedfa(fs, 1);
		}
		if (nematch(pfa,s)) {
			tempstat = pfa->initstat;
			pfa->initstat = 2;
			do {
				n++;
				sprintf(num, "%d", n);
				temp = *patbeg;
				*patbeg = '\0';
				if (is_number(s))
					setsymtab(num, s, atof(s), STR|NUM, (Array *) ap->sval);
				else
					setsymtab(num, s, 0.0, STR, (Array *) ap->sval);
				*patbeg = temp;
				s = patbeg + patlen;
				if (*(patbeg+patlen-1) == 0 || *s == 0) {
					n++;
					sprintf(num, "%d", n);
					setsymtab(num, "", 0.0, STR, (Array *) ap->sval);
					pfa->initstat = tempstat;
					goto spdone;
				}
			} while (nematch(pfa,s));
			pfa->initstat = tempstat; 	/* bwk: has to be here to reset */
							/* cf gsub and refldbld */
		}
		n++;
		sprintf(num, "%d", n);
		if (is_number(s))
			setsymtab(num, s, atof(s), STR|NUM, (Array *) ap->sval);
		else
			setsymtab(num, s, 0.0, STR, (Array *) ap->sval);
  spdone:
		pfa = NULL;
	} else if (sep == ' ') {
		for (n = 0; ; ) {
			while (*s == ' ' || *s == '\t' || *s == '\n')
				s++;
			if (*s == 0)
				break;
			n++;
			t = s;
			do
				s++;
			while (*s!=' ' && *s!='\t' && *s!='\n' && *s!='\0');
			temp = *s;
			*s = '\0';
			sprintf(num, "%d", n);
			if (is_number(t))
				setsymtab(num, t, atof(t), STR|NUM, (Array *) ap->sval);
			else
				setsymtab(num, t, 0.0, STR, (Array *) ap->sval);
			*s = temp;
			if (*s != 0)
				s++;
		}
	} else if (sep == 0) {	/* new: split(s, a, "") => 1 char/elem */
		for (n = 0; *s != 0; s++) {
			char buf[2];
			n++;
			sprintf(num, "%d", n);
			buf[0] = *s;
			buf[1] = 0;
			if (isdigit((uschar)buf[0]))
				setsymtab(num, buf, atof(buf), STR|NUM, (Array *) ap->sval);
			else
				setsymtab(num, buf, 0.0, STR, (Array *) ap->sval);
		}
	} else if (*s != 0) {
		for (;;) {
			n++;
			t = s;
			while (*s != sep && *s != '\n' && *s != '\0')
				s++;
			temp = *s;
			*s = '\0';
			sprintf(num, "%d", n);
			if (is_number(t))
				setsymtab(num, t, atof(t), STR|NUM, (Array *) ap->sval);
			else
				setsymtab(num, t, 0.0, STR, (Array *) ap->sval);
			*s = temp;
			if (*s++ == 0)
				break;
		}
	}
	tempfree(ap);
	tempfree(y);
	free(origs);
	if (a[2] != 0 && arg3type == STRING) {
		tempfree(x);
	}
	x = gettemp();
	x->tval = NUM;
	x->fval = n;
	return(x);
}
Esempio n. 23
0
//Multisided dice roll
void do_multidicethrow(CHAR_DATA *ch, char *argument )
{
	char arg1[MAX_STRING_LENGTH];
	char arg2[MAX_STRING_LENGTH];
	// char arg3[MAX_STRING_LENGTH];
	char buffer[MAX_STRING_LENGTH];
	char buff[MAX_STRING_LENGTH];

	int sum=0,diceroll=0, numberofdice=0, numberofsides=6;
	int i = 0;

	if (argument[0] == '\0')
        {
		   send_to_char("Syntax: Dicethrow <number of dice> <number of sides>\r\n",ch);
		   return;
	}
	
	argument = one_argument(argument,arg1);
	if (!is_number(arg1))
        {
		   send_to_char("Syntax: Dicethrow <number of dice> <number of sides>\r\n",ch);
		   return;
	}
        numberofdice = atoi(arg1);
        if (numberofdice < 1 || numberofdice > 10)
        {
		send_to_char("dicethrow: You must specifiy 1 to 10 dice\r\n",ch);
		return;
	}
	if (argument[0] == '\0')
        {
		   send_to_char("Syntax: Dicethrow <number of dice> <number of sides>\r\n",ch);
		   return;
	}
	else
        {
		argument = one_argument(argument,arg2);
		if (!is_number(arg2)) {
		   send_to_char("Syntax: Dicethrow <number of dice> <number of sides>\r\n",ch);
		   return;
		}
     		numberofsides = atoi(arg2); 
		if (numberofsides < 2 || numberofsides > 40) {
		   send_to_char("Please use more than 1 side and less than 40\r\n",ch);
		   return;

		}
        }
	
	sprintf(buffer,"<DICE GAME>$n rolls %d %d sided dice: ", numberofdice, numberofsides);
	  
	   for (i = 0; i < numberofdice;i++)
           {
		diceroll=number_range(1,numberofsides);
		sum += diceroll;
		sprintf(buff,"%d ",diceroll);
		strcat(buffer,buff);		
           }
	   sprintf(buff,"\r\nFor a total of: %d\n\r",sum);
	   strcat(buffer,buff);
	   act(buffer,ch,NULL,NULL,TO_ROOM);
	   act(buffer,ch,NULL,NULL,TO_CHAR);
	   if (IS_RP(ch))
           {
	      char rp_buffer[MAX_STRING_LENGTH];
	      sprintf(rp_buffer,"%s: %s",ch->name,buffer);
	      log_rp_string(ch,rp_buffer);
	   }
}
Esempio n. 24
0
void
parse_simplebox(void)
{
    InputBox *box;
    char *name;
    short int picked = 0;
    char *filename;
    TextNode *input_box = curr_node;

    gStringValueOk = 0;

    /* set the type and space fields  */
    input_box->type = SimpleBox;
    input_box->space = token.id[-1];

    /* IS it selected? */
    get_token();
    if (token.type == Lsquarebrace) {
        get_expected_token(Word);
        if (!is_number(token.id)) {
            fprintf(stderr,
                    "parse_simple_box: Expected a value not %s\n", token.id);
            print_page_and_filename();
            jump();
        }
        else if (!strcmp(token.id, "1"))
            picked = 1;
        else if (!strcmp(token.id, "0"))
            picked = 0;
        else {
            fprintf(stderr, "parse_simple_box: Unexpected Value %s\n", token.id);
            print_page_and_filename();
            jump();
        }
        get_expected_token(Rsquarebrace);
        get_token();
    }

    if (token.type != Lbrace) {
        token_name(token.type);
        fprintf(stderr, "parse_inputbox was expecting a { not a %s\n", ebuffer);
        print_page_and_filename();
        jump();
    }

    name = get_input_string();
    if (gPageBeingParsed->box_hash && hash_find(gPageBeingParsed->box_hash, name)) {
        fprintf(stderr, "Input box name %s is not unique \n", name);
        print_page_and_filename();
        jump();
    }

    box = alloc_inputbox();
    box->name = alloc_string(name);
    input_box->data.text = alloc_string(name);
    box->picked = picked;

    /* Get the filename for the selected and unselected bitmaps */
    get_expected_token(Lbrace);
    filename = get_input_string();
    if (!make_input_file)
        box->selected = insert_image_struct(filename);
    get_expected_token(Lbrace);
    filename = get_input_string();
    if (!make_input_file) {
        box->unselected = insert_image_struct(filename);
        /* set the width and height for the maximaum of the two */
        input_box->height = max(box->selected->height, box->unselected->height);
        input_box->width = max(box->selected->width, box->unselected->width);
        /* Make the window and stuff */
        input_box->link = make_box_window(box, SimpleBox);
        box->win = input_box->link->win;

        /* Now add the box to the box_has table for this window */
        if (gPageBeingParsed->box_hash == NULL) {
            gPageBeingParsed->box_hash = (HashTable *) halloc(sizeof(HashTable),
                                         "Box Hash");
            hash_init(
                gPageBeingParsed->box_hash,
                BoxHashSize,
                (EqualFunction) string_equal,
                (HashcodeFunction) string_hash);
        }
        hash_insert(gPageBeingParsed->box_hash, (char *)box, box->name);
    }

    /* reset the curr_node and then return */
    curr_node = input_box;
    gStringValueOk = 1;
    return;
}
Esempio n. 25
0
void do_wizlist(CHAR_DATA *ch, char *argument)
{
    char arg1[MAX_INPUT_LENGTH];
    char arg2[MAX_INPUT_LENGTH];
    char arg3[MAX_INPUT_LENGTH];
    char buf[MAX_STRING_LENGTH];
    char title[MAX_STRING_LENGTH];
    BUFFER *buffer;
    int level;
    WIZ_DATA *pwiz;
    int lngth;
    int amt;
    bool found;

    argument = one_argument( argument, arg1 );
    argument = one_argument( argument, arg2 );
    argument = one_argument( argument, arg3 );

/*
 * Uncomment the following to use the old method of having
 * a fixed wizlist in the rot.are file.
 */

/*
    do_help(ch,"wizlist");
    return;
*/

    if ((arg1[0] != '\0') && (ch->level == MAX_LEVEL))
    {
	if ( !str_prefix( arg1, "add" ) )
	{
	    if ( !is_number( arg2 ) || ( arg3[0] == '\0' ) )
	    {
		send_to_char( "Syntax: wizlist add <level> <name>\n\r", ch );
		return;
	    }
	    level = atoi(arg2);
	    change_wizlist( ch, TRUE, level, arg3 );
	    return;
	}
	if ( !str_prefix( arg1, "delete" ) )
	{
	    if ( arg2[0] == '\0' )
	    {
		send_to_char( "Syntax: wizlist delete <name>\n\r", ch );
		return;
	    }
	    change_wizlist( ch, FALSE, 0, arg2 );
	    return;
	}
	send_to_char( "Syntax:\n\r", ch );
	send_to_char( "       wizlist delete <name>\n\r", ch );
	send_to_char( "       wizlist add <level> <name>\n\r", ch );
	return;
    }

    if (wiz_list == NULL)
    {
	send_to_char("No immortals listed at this time.\n\r",ch);
	return;
    }
    buffer = new_buf();
    sprintf(title,"Realm of the Keepers Staff");
    sprintf(buf,"{x  ___________________________________________________________________________\n\r");
    add_buf(buffer,buf);
    sprintf(buf,"{x /\\_\\%70s\\_\\\n\r", " ");
    add_buf(buffer,buf);
    lngth = (70 - strlen(title))/2;
    for( ; lngth >= 0; lngth--)
    {
	strcat(title, " ");
    }
    sprintf(buf,"|/\\\\_\\{W%70s{x\\_\\\n\r", title);
    add_buf(buffer,buf);
    sprintf(buf,"{x\\_/_|_|%69s|_|\n\r", " ");
    add_buf(buffer,buf);
    for (level = IMPLEMENTOR; level > HERO; level--)
    {
	found = FALSE;
	amt = 0;
        for (pwiz = wiz_list;pwiz != NULL;pwiz = pwiz->next)
        {
	    if (pwiz->level == level)
	    {
		amt++;
		found = TRUE;
	    }
	}
	if (!found)
	{
	    if (level == HERO+1)
	    {
		sprintf(buf,"{x ___|_|%69s|_|\n\r", " ");
		add_buf(buffer,buf);
	    }
	    continue;
	}
	sprintf(buf,"{x    |_|{R%37s {B[%d]{x%26s|_|\n\r",
	    wiz_titles[IMPLEMENTOR-level], level, " ");
	add_buf(buffer,buf);
	sprintf(buf,"{x    |_|{Y%25s******************{x%26s|_|\n\r",
	    " ", " ");
	add_buf(buffer,buf);
	lngth = 0;
        for (pwiz = wiz_list;pwiz != NULL;pwiz = pwiz->next)
        {
	    if (pwiz->level == level)
	    {
		if (lngth == 0)
		{
		    if (amt > 2)
		    {
			sprintf(buf, "{x    |_|{%s%12s%-17s ",
			    level >= DEMI ? "G" : "C", " ",
			    pwiz->name);
			add_buf(buffer, buf);
			lngth = 1;
		    } else if (amt > 1)
		    {
			sprintf(buf, "{x    |_|{%s%21s%-17s ",
			    level >= DEMI ? "G" : "C", " ",
			    pwiz->name);
			add_buf(buffer, buf);
			lngth = 1;
		    } else
		    {
			sprintf(buf, "{x    |_|{%s%30s%-39s{x|_|\n\r",
			    level >= DEMI ? "G" : "C", " ",
			    pwiz->name);
			add_buf(buffer, buf);
			lngth = 0;
		    }
		} else if (lngth == 1)
		{
		    if (amt > 2)
		    {
			sprintf(buf, "%-17s ",
			    pwiz->name);
			add_buf(buffer, buf);
			lngth = 2;
		    } else
		    {
			sprintf(buf, "%-30s{x|_|\n\r",
			    pwiz->name);
			add_buf(buffer, buf);
			lngth = 0;
		    }
		} else
		{
		    sprintf(buf, "%-21s{x|_|\n\r",
			pwiz->name);
		    add_buf(buffer, buf);
		    lngth = 0;
		    amt -= 3;
		}
	    }
        }
	if (level == HERO+1)
	{
	    sprintf(buf,"{x ___|_|%69s|_|\n\r", " ");
	} else
	{
	    sprintf(buf,"{x    |_|%69s|_|\n\r", " ");
	}
	add_buf(buffer,buf);
    }
    sprintf(buf,"{x/ \\ |_|%69s|_|\n\r", " ");
    add_buf(buffer,buf);
    sprintf(buf,"{x|\\//_/%70s/_/\n\r", " ");
    add_buf(buffer,buf);
    sprintf(buf,"{x \\/_/______________________________________________________________________/_/\n\r");
    add_buf(buffer,buf);
    page_to_char( buf_string(buffer), ch );
    free_buf(buffer);
    return;
}
Esempio n. 26
0
void
parse_radiobox(void)
{
    InputBox *box;
    char *name;
    char *group_name;
    short int picked = 0;
    TextNode *input_box = curr_node;

    gStringValueOk = 0;

    /* set the type and space fields  */
    input_box->type = Radiobox;
    input_box->space = token.id[-1];

    /* IS it selected? */
    get_token();
    if (token.type == Lsquarebrace) {
        get_expected_token(Word);
        if (!is_number(token.id)) {
            fprintf(stderr,
                    "parse_simple_box: Expected a value not %s\n", token.id);
            print_page_and_filename();
            jump();
        }
        else if (!strcmp(token.id, "1"))
            picked = 1;
        else if (!strcmp(token.id, "0"))
            picked = 0;
        else {
            fprintf(stderr, "parse_simple_box: Unexpected Value %s\n", token.id);
            print_page_and_filename();
            jump();
        }
        get_expected_token(Rsquarebrace);
        get_token();
    }

    if (token.type != Lbrace) {
        token_name(token.type);
        fprintf(stderr, "parse_inputbox was expecting a { not a %s\n", ebuffer);
        print_page_and_filename();
        jump();
    }

    name = get_input_string();
    if (gPageBeingParsed->box_hash && hash_find(gPageBeingParsed->box_hash, name)) {
        fprintf(stderr, "Input box name %s is not unique \n", name);
        print_page_and_filename();
        jump();
    }

    box = alloc_inputbox();
    box->name = alloc_string(name);
    input_box->data.text = alloc_string(name);
    box->picked = picked;

    /* Now what I need to do is get the group name */
    get_token();
    if (token.type != Lbrace) {
        token_name(token.type);
        fprintf(stderr, "parse_inputbox was expecting a { not a %s\n", ebuffer);
        print_page_and_filename();
        jump();
    }
    group_name = get_input_string();

    /*
     * Now call a routine which searches the radio box list for the current
     * group name, and if found adds this box to it
     */
    add_box_to_rb_list(group_name, box);

    input_box->width = box->rbs->width;
    input_box->height = box->rbs->height;
    /* Make the window and stuff */
    input_box->link = make_box_window(box, Radiobox);
    if (!make_input_file)
        box->win = input_box->link->win;        /* TTT */


    /* Now add the box to the box_has table for this window */
    if (gPageBeingParsed->box_hash == NULL) {
        gPageBeingParsed->box_hash = (HashTable *) halloc(sizeof(HashTable),
                                     "Box Hash");
        hash_init(
            gPageBeingParsed->box_hash,
            BoxHashSize,
            (EqualFunction) string_equal,
            (HashcodeFunction) string_hash);
    }
    hash_insert(gPageBeingParsed->box_hash, (char *)box, box->name);

    /* reset the curr_node and then return */
    curr_node = input_box;
    gStringValueOk = 1;
    return;
}
Esempio n. 27
0
int enif_is_number(ErlNifEnv* env, ERL_NIF_TERM term)
{
    return is_number(term);
}
Esempio n. 28
0
/* ---------------------------------------------------------------------
 * CMD_EVAL
 * This monster evaluates an if/or/and statement
 * There are five kinds of statement:
 * 1) keyword and value (no $-code)	    if random 30
 * 2) keyword, comparison and value	    if people > 2
 * 3) keyword and actor		    	    if isnpc $n
 * 4) keyword, actor and value		    if carries $n sword
 * 5) keyword, actor, comparison and value  if level $n >= 10
 *
 *----------------------------------------------------------------------
 */
int cmd_eval( sh_int vnum, char *line, int check,
	CHAR_DATA *mob, CHAR_DATA *ch, 
	const void *arg1, const void *arg2, CHAR_DATA *rch )
{
    CHAR_DATA *lval_char = mob;
    CHAR_DATA *vch = (CHAR_DATA *) arg2;
    OBJ_DATA *obj1 = (OBJ_DATA  *) arg1;
    OBJ_DATA *obj2 = (OBJ_DATA  *) arg2;
    OBJ_DATA  *lval_obj = NULL;

    char *original, buf[MAX_INPUT_LENGTH], code;
    int lval = 0, oper = 0, rval = -1;

    original = line;
    line = one_argument( line, buf );
    if ( buf[0] == '\0' || mob == NULL )
	return FALSE;

    /*
     * If this mobile has no target, let's assume our victim is the one
     */
    if ( mob->mprog_target == NULL )
	mob->mprog_target = ch;

    switch ( check )
    {
	/*
	 * Case 1: keyword and value
	 */
	case CHK_RAND:
	    return( atoi( buf ) < number_percent() );
	case CHK_MOBHERE:
	    if ( is_number( buf ) )
		return( get_mob_vnum_room( mob, atoi(buf) ) );
	    else
		return( (bool) (get_char_room( mob, buf) != NULL) );
	case CHK_OBJHERE:
	    if ( is_number( buf ) )
		return( get_obj_vnum_room( mob, atoi(buf) ) );
	    else
		return( (bool) (get_obj_here( mob, buf) != NULL) );
        case CHK_MOBEXISTS:
	    return( (bool) (get_char_world( mob, buf) != NULL) );
	case CHK_OBJEXISTS:
	    return( (bool) (get_obj_world( mob, buf) != NULL) );
	/*
	 * Case 2 begins here: We sneakily use rval to indicate need
	 * 		       for numeric eval...
	 */
	case CHK_PEOPLE:
	    rval = count_people_room( mob, 0 ); break;
	case CHK_PLAYERS:
	    rval = count_people_room( mob, 1 ); break;
	case CHK_MOBS:
	    rval = count_people_room( mob, 2 ); break;
	case CHK_CLONES:
	    rval = count_people_room( mob, 3 ); break;
	case CHK_ORDER:
	    rval = get_order( mob ); break;
	case CHK_HOUR:
	    rval = time_info.hour; break;
	default:;
    }

    /*
     * Case 2 continued: evaluate expression
     */
    if ( rval >= 0 )
    {
	if ( (oper = keyword_lookup( fn_evals, buf )) < 0 )
	{
	    sprintf( buf, "Cmd_eval: prog %d syntax error(2) '%s'",
		vnum, original );
	    bug( buf, 0 );
	    return FALSE;
	}
	one_argument( line, buf );
	lval = rval;
	rval = atoi( buf );
	return( num_eval( lval, oper, rval ) );
    }

    /*
     * Case 3,4,5: Grab actors from $* codes
     */
    if ( buf[0] != '$' || buf[1] == '\0' )
    {
	sprintf( buf, "Cmd_eval: prog %d syntax error(3) '%s'",
		vnum, original );
	bug( buf, 0 );
        return FALSE;
    }
    else
        code = buf[1];
    switch( code )
    {
    	case 'i':
            lval_char = mob; break;
        case 'n':
            lval_char = ch; break;
        case 't':
            lval_char = vch; break;
        case 'r':
            lval_char = rch == NULL ? get_random_char( mob ) : rch ; break;
        case 'o':
            lval_obj = obj1; break;
        case 'p':
            lval_obj = obj2; break;
	case 'q':
	    lval_char = mob->mprog_target; break;
	default:
	    sprintf( buf, "Cmd_eval: prog %d syntax error(4) '%s'",
		vnum, original );
	    bug( buf, 0 );
	    return FALSE;
    }
    /*
     * From now on, we need an actor, so if none was found, bail out
     */
    if ( lval_char == NULL && lval_obj == NULL )
    	return FALSE;

    /*
     * Case 3: Keyword, comparison and value
     */
    switch( check )
    {
	case CHK_ISPC:
            return( lval_char != NULL && !IS_NPC( lval_char ) );
        case CHK_ISNPC:
            return( lval_char != NULL && IS_NPC( lval_char ) );
        case CHK_ISGOOD:
            return( lval_char != NULL && IS_GOOD( lval_char ) );
        case CHK_ISEVIL:
            return( lval_char != NULL && IS_EVIL( lval_char ) );
        case CHK_ISNEUTRAL:
            return( lval_char != NULL && IS_NEUTRAL( lval_char ) );
	case CHK_ISIMMORT:
            return( lval_char != NULL && IS_IMMORTAL( lval_char ) );
        case CHK_ISCHARM: /* A relic from MERC 2.2 MOBprograms */
            return( lval_char != NULL && IS_AFFECTED( lval_char, AFF_CHARM ) );
        case CHK_ISFOLLOW:
            return( lval_char != NULL && lval_char->master != NULL 
		 && lval_char->master->in_room == lval_char->in_room );
	case CHK_ISACTIVE:
	    return( lval_char != NULL && lval_char->position > POS_SLEEPING );
	case CHK_ISDELAY:
	    return( lval_char != NULL && lval_char->mprog_delay > 0 );
	case CHK_ISVISIBLE:
            switch( code )
            {
                default :
                case 'i':
                case 'n':
                case 't':
                case 'r':
		case 'q':
	    	    return( lval_char != NULL && can_see( mob, lval_char ) );
		case 'o':
		case 'p':
	    	    return( lval_obj != NULL && can_see_obj( mob, lval_obj ) );
	    }
	case CHK_HASTARGET:
	    return( lval_char != NULL && lval_char->mprog_target != NULL
		&&  lval_char->in_room == lval_char->mprog_target->in_room );
	case CHK_ISTARGET:
	    return( lval_char != NULL && mob->mprog_target == lval_char );
	default:;
     }

     /* 
      * Case 4: Keyword, actor and value
      */
     line = one_argument( line, buf );
     switch( check )
     {
	case CHK_AFFECTED:
	    return( lval_char != NULL 
		&&  IS_SET(lval_char->affected_by, flag_lookup(buf, affect_flags)) );
	case CHK_ACT:
	    return( lval_char != NULL 
		&&  IS_SET(lval_char->act, flag_lookup(buf, act_flags)) );
	case CHK_IMM:
	    return( lval_char != NULL 
		&&  IS_SET(lval_char->imm_flags, flag_lookup(buf, imm_flags)) );
	case CHK_OFF:
	    return( lval_char != NULL 
		&&  IS_SET(lval_char->off_flags, flag_lookup(buf, off_flags)) );
	case CHK_CARRIES:
	    if ( is_number( buf ) )
		return( lval_char != NULL && has_item( lval_char, atoi(buf), -1, FALSE ) );
	    else
		return( lval_char != NULL && (get_obj_carry( lval_char, buf ) != NULL) );
	case CHK_WEARS:
	    if ( is_number( buf ) )
		return( lval_char != NULL && has_item( lval_char, atoi(buf), -1, TRUE ) );
	    else
		return( lval_char != NULL && (get_obj_wear( lval_char, buf ) != NULL) );
	case CHK_HAS:
	    return( lval_char != NULL && has_item( lval_char, -1, item_lookup(buf), FALSE ) );
	case CHK_USES:
	    return( lval_char != NULL && has_item( lval_char, -1, item_lookup(buf), TRUE ) );
	case CHK_NAME:
            switch( code )
            {
                default :
                case 'i':
                case 'n':
                case 't':
                case 'r':
		case 'q':
		    return( lval_char != NULL && is_name( buf, lval_char->name ) );
		case 'o':
		case 'p':
		    return( lval_obj != NULL && is_name( buf, lval_obj->name ) );
	    }
	case CHK_POS:
	    return( lval_char != NULL && lval_char->position == position_lookup( buf ) );
	case CHK_CLAN:
	    return( lval_char != NULL && lval_char->clan == clan_lookup( buf ) );
	case CHK_RACE:
	    return( lval_char != NULL && lval_char->race == race_lookup( buf ) );
	case CHK_OBJTYPE:
	    return( lval_obj != NULL && lval_obj->item_type == item_lookup( buf ) );
	default:;
    }

    /*
     * Case 5: Keyword, actor, comparison and value
     */
    if ( (oper = keyword_lookup( fn_evals, buf )) < 0 )
    {
	sprintf( buf, "Cmd_eval: prog %d syntax error(5): '%s'",
		vnum, original );
	bug( buf, 0 );
	return FALSE;
    }
    one_argument( line, buf );
    rval = atoi( buf );

    switch( check )
    {
	case CHK_VNUM:
	    switch( code )
            {
                default :
                case 'i':
                case 'n':
                case 't':
                case 'r':
		case 'q':
                    if( lval_char != NULL && IS_NPC( lval_char ) )
                        lval = lval_char->pIndexData->vnum;
                    break;
                case 'o':
                case 'p':
                     if ( lval_obj != NULL )
                        lval = lval_obj->pIndexData->vnum;
            }
            break;
	case CHK_HPCNT:
	    if ( lval_char != NULL ) lval = (lval_char->hit * 100)/(UMAX(1,lval_char->max_hit)); break;
	case CHK_ROOM:
	    if ( lval_char != NULL && lval_char->in_room != NULL )
		lval = lval_char->in_room->vnum; break;
        case CHK_SEX:
	    if ( lval_char != NULL ) lval = lval_char->sex; break;
        case CHK_LEVEL:
            if ( lval_char != NULL ) lval = lval_char->level; break;
	case CHK_ALIGN:
            if ( lval_char != NULL ) lval = lval_char->alignment; break;
	case CHK_MONEY:  /* Money is converted to silver... */
	    if ( lval_char != NULL ) 
		lval = lval_char->gold + (lval_char->silver * 100); break;
	case CHK_OBJVAL0:
            if ( lval_obj != NULL ) lval = lval_obj->value[0]; break;
        case CHK_OBJVAL1:
            if ( lval_obj != NULL ) lval = lval_obj->value[1]; break;
        case CHK_OBJVAL2: 
            if ( lval_obj != NULL ) lval = lval_obj->value[2]; break;
        case CHK_OBJVAL3:
            if ( lval_obj != NULL ) lval = lval_obj->value[3]; break;
	case CHK_OBJVAL4:
	    if ( lval_obj != NULL ) lval = lval_obj->value[4]; break;
	case CHK_GRPSIZE:
	    if( lval_char != NULL ) lval = count_people_room( lval_char, 4 ); break;
	default:
            return FALSE;
    }
    return( num_eval( lval, oper, rval ) );
}
Esempio n. 29
0
int CmdLineParser::value_to_int(const char* key) {
	string strVal = value(key);
	if(strVal.length() == 0 || !is_number(strVal))
		return -1;
	return atoi(strVal.c_str());
}
Esempio n. 30
0
// split a string into individual tokens
void tokenise(const std::string &line, const std::string &filename, int line_num, const Options &opt,
    /*out*/ std::vector<Token> &tokens,
    bool test_is_raw_python = false   // whether --test input is raw python code (vs just a list of boolean expressions)
)
{
    size_t pos = 0;
    size_t len = line.length();
    bool found_assign_op = false;
    bool ids_can_be_keywords = opt.assign || (opt.test && !test_is_raw_python);

    while (pos < len)
    {
        size_t space_start = pos;

        // skip whitespace (and finish if end of line or comment)
        while (std::isspace(char_at(line, pos))) { ++pos; }
        if (pos >= len || line[pos] == '#') { break; }

        size_t num_spaces = pos - space_start;
        size_t tok_start = pos;
        char ch = line[pos];
        char next_ch = char_at(line, pos + 1);
        token_type type = t_undefined;
        std::string tok_str;

        if (opt.assign && found_assign_op)
        {
            type = t_string;
            pos = len;
            tok_str = trim_spaces(line.substr(tok_start, pos - tok_start));
            if (is_quoted(tok_str))
            {
                // make sure quotes are of the right type
                std::string unquoted_tok_str = tok_str.substr(1, tok_str.length() - 2);
                tok_str = quote(unquoted_tok_str, '\'');
            }
            else if (!is_number(tok_str)) { tok_str = quote(tok_str, '\''); }
        }
        else
        if (is_start_of_id(ch))
        {
            // TODO: maybe allow spaces around array indexes , e.g. "a/b[ 10 ]/c"
            while (is_id(char_at(line, pos))) { ++pos; }
            std::string id = line.substr(tok_start, pos - tok_start);
            check_transform_id(id);
            if (is_keyword(id) && !(ids_can_be_keywords && is_keyword_allowed_as_id(id))) { tok_str = id; type = t_keyword; }
            else if (id != kwd_expect && next_nonblank_char(line, pos) == '(') { tok_str = id; type = t_function; }
            else { tok_str = (opt.demangle ? demangle_id(id, true) : mangle_id(id)); type = t_id; }
        }
        else
        if (std::isdigit(ch) ||
            (ch == '.' && std::isdigit(next_ch)) ||
            (ch == '-' && (std::isdigit(next_ch) || next_ch == '.')))
        {
            bool any_digits = false;

            if (ch == '-') { ++pos; }
            while (std::isdigit(char_at(line, pos))) { ++pos; any_digits = true; }

            if (char_at(line, pos) == '.')
            {
                ++pos;
                while (std::isdigit(char_at(line, pos))) { ++pos; any_digits = true; }
            }

            // check for scientific notation
            // (TODO: merge common code with is_number function)
            if (any_digits && std::tolower(char_at(line, pos)) == 'e')
            {
                size_t pos2 = pos + 1;
                if (char_at(line, pos2) == '+' || char_at(line, pos2) == '-')
                {
                    ++pos2;
                    if (std::isdigit(char_at(line, pos2)))
                    { for (pos = pos2 + 1;std::isdigit(char_at(line, pos));++pos) { } }
                }
            }

            if (any_digits) { type = t_number; }
            else { type = t_operator; pos = tok_start + 1; }  // token is a single character ("-" or ".")

            tok_str = line.substr(tok_start, pos - tok_start);
        }
        else
        if (ch == '\"' || ch == '\'')
        {
            for (++pos;pos < len && line[pos] != ch;++pos)
            {
                // check for escape character
                if (line[pos] == '\\') { if (++pos >= len) break; }
            }
            if (pos < len) { ++pos; }
            tok_str = line.substr(tok_start, pos - tok_start);
            type = t_string;
        }
        else
        {
            pos += operator_length(line, pos);
            tok_str = line.substr(tok_start, pos - tok_start);
            type = t_operator;
            if (tok_str == "=")
            {
                found_assign_op = true;
                if (opt.test && (!test_is_raw_python || 
                    (tokens.size() > 0 && tokens[0].type == t_id && tokens[0].str == kwd_expect)))
                { tok_str = "=="; }
            }
        }

        tokens.push_back(Token(type, tok_str, num_spaces));

        if (!opt.command && tokens.size() == 1)
        {
            // Python will complain if the line is indented
            tokens[0].spaces_before = 0;
        }
    }

    transform_special_tokens(tokens, filename, line_num);

    if (opt.assign)
    {
        // transform var= into var=''
        if (tokens.size() == 2 && tokens[1].str == "=") { tokens.push_back(Token(t_string, "''", 0)); }
    }

    if (opt.test) { force_string_comparison_if_quoted(tokens); }

    if (opt.command)
    {
        // add any missing ":" at the end of the line
        if (tokens.size() > 0 && tokens[0].type == t_keyword)
        {
            // check if there is a ":" anywhere in the line
            if (find_token(tokens, t_operator, ":") == -1)
            {
                if (tokens[0].str == "if" || tokens[0].str == "else" || tokens[0].str == "elif" ||
                    tokens[0].str == "while" || tokens[0].str == "for" || tokens[0].str == "try" ||
                    tokens[0].str == "except" || tokens[0].str == "finally")
                { tokens.push_back(Token(t_operator, ":", 0)); }
            }
        }
    }
}