示例#1
0
static EC_OBJ match_copy( EC_OBJ obj, EcCopyType type )
{
	ov_int *ovector;
	EcInt   ovecsize;
	EC_OBJ  regexp_copy, subject_copy;

	if (type == EcShallowCopyType)
	{
		regexp_copy  = EC_MATCH_REGEXP(obj);
		subject_copy = EC_MATCH_SUBJECT(obj);
	}
	else
	{
		regexp_copy = EcCopy( EC_MATCH_REGEXP(obj), EcDeepCopyType );
		if (EC_ERRORP(regexp_copy)) return regexp_copy;
		subject_copy = EcCopy( EC_MATCH_SUBJECT(obj), EcDeepCopyType );
		if (EC_ERRORP(subject_copy)) return subject_copy;
	}

	/* copy the ovector */
	ovecsize = EC_MATCH_OVECSIZE(obj);
	ovector = ec_malloc( sizeof(ov_int) * ovecsize );
	if (! ovector)
		return EcMemoryError();
	memcpy( ovector, EC_MATCH_OVECTOR(obj), sizeof(ov_int) * ovecsize );

	return make_match( regexp_copy, subject_copy, ovector, ovecsize, EC_MATCH_NSUB(obj) );
}
int Honor_Arena_Manager::tick(const Time_Value &now){
	check_fight_teams(now);

	match_tick_num_ += 1;
	check_rank_change_tick_ += 1;
	if(match_tick_num_ > 30){// 3秒匹配一次
		match_tick_num_ = 0;
		make_match();
	}
	if(check_rank_change_tick_ > 40){
		check_rank_change_tick_ = 0;
		check_rank_change();
	}
	return 0;
}
示例#3
0
文件: match.hpp 项目: BianJian/mmo
namespace gce
{
namespace adl
{
inline bool operator==(match const& lhs, match const& rhs)
{
  return lhs.val_ == rhs.val_;
}

inline bool operator==(match const& lhs, int rhs)
{
  return lhs.val_ == rhs;
}

inline bool operator!=(match const& lhs, match const& rhs)
{
  return !(lhs == rhs);
}

inline bool operator!=(match const& lhs, int rhs)
{
  return !(lhs == rhs);
}

inline bool operator<(match const& lhs, match const& rhs)
{
  return lhs.val_ < rhs.val_;
}
} /// namespace adl

inline std::string to_string(adl::match const& o)
{
  std::string str;
  str += "match<";
  str += boost::lexical_cast<intbuf_t>(o.val_).cbegin();
  str += ">";
  return str;
}

template <>
struct tostring<adl::match>
{
  static std::string convert(adl::match const& o)
  {
    return to_string(o);
  }
};

typedef adl::match match_t;

inline match_t make_match(uint64_t val)
{
  match_t rt;
  rt.val_ = val;
  return rt;
}

/// match nil value
static match_t const match_nil = make_match(u64_nil);
typedef std::vector<match_t> match_list_t;
}
示例#4
0
static EC_OBJ EcLibRe_Match( EC_OBJ stack, EcAny userdata )
{
	EC_OBJ      regexp;
	EC_OBJ      subject_obj;
	const char *subject;
	EcInt       length;
	EcInt       startoffset = 0;
	EC_OBJ      opts    = EC_NIL;
	int         options;
	pcre       *code  = NULL;
	pcre_extra *extra = NULL;
	EcBool      compiledhere = FALSE;
	ov_int     *ovector;
	EcInt       ovecsize;
	EcInt       ncapsub;
	int         exec_res;
	int         rc;
	EC_OBJ      res;

	res = EcParseStackFunction( "re.match", TRUE, stack, "OO!|iO",
								&regexp, tc_string, &subject_obj, &startoffset, opts );
	if (EC_ERRORP(res)) return res;

	if (!(EC_REGEXPP(regexp) || (EC_STRINGP(regexp))))
	{
		return EC_TYPEERROR_F( "re.match", 1, tc_none, regexp, "expected 'regexp' or 'string'" );
	}

	if (EC_STRINGP(regexp))
	{
		/* compile the pattern */

		const char *errptr  = NULL;
		int         erroffs = 0;

		code = pcre_compile( EC_STRDATA(regexp), 0,				/* we'll use options at matching time */
							 &errptr, &erroffs,
							 /* tableptr */ NULL );
		if (! code) return EcReError( errptr, erroffs );
		extra = NULL;
		compiledhere = TRUE;
	} else
	{
		code  = EC_PCRE(regexp);
		extra = EC_PCREXTRA(regexp);
		compiledhere = FALSE;
	}

	subject = EC_STRDATA(subject_obj);
	length  = EC_STRLEN(subject_obj);

	opts = obj2options( "re.match", 4, opts, &options );
	if (EC_ERRORP(opts)) return opts;

	rc = pcre_fullinfo( code, extra, PCRE_INFO_CAPTURECOUNT, &ncapsub );
	if (rc < 0)
		return EcReError( "internal error: pcre_fullinfo", -1 );

	ovecsize = (ncapsub + 1) * 3;
	ovector  = ec_malloc( sizeof(ov_int) * ovecsize );
	if (! ovector) return EcMemoryError();
	memset( ovector, 0x00, sizeof(ov_int) * ovecsize );

	exec_res = pcre_exec( code, extra,
						  subject, length, startoffset,
						  options, ovector, ovecsize );
	if (compiledhere)
	{
		if (code)  free( code );
		if (extra) free( extra );
	}
	switch (exec_res)
	{
	case PCRE_ERROR_NOMATCH:
		ec_free( ovector );
		return EC_NIL;
		break;
	case PCRE_ERROR_NULL:
		ec_free( ovector );
		return EcReError( "internal error: PCRE_ERROR_NULL", -1 );
		break;
	case PCRE_ERROR_BADOPTION:
		ec_free( ovector );
		return EcReError( "internal error: PCRE_ERROR_BADOPTION", -1 );
		break;
	case PCRE_ERROR_BADMAGIC:
		ec_free( ovector );
		return EcReError( "internal error: PCRE_ERROR_BADMAGIC", -1 );
		break;
	case PCRE_ERROR_UNKNOWN_NODE:
		ec_free( ovector );
		return EcReError( "internal error: PCRE_ERROR_UNKNOWN_MODE", -1 );
		break;
	case PCRE_ERROR_NOMEMORY:
		ec_free( ovector );
		return EcMemoryError();
		break;
	}
#if 0
	if (exec_res == 0)
	{
		ec_free( ovector );
		return EC_NIL;
		}
#endif
	ASSERT( exec_res >= 0 );
	return make_match( regexp, subject_obj, ovector, ovecsize, exec_res );
}