コード例 #1
0
ファイル: slip.c プロジェクト: quixadhal/discworld
int slip(string str) {
  object *obs,
         *obs2,
         *fail,
         *t_p,
         *g_f,
         *from;
  int i, j, ret, skill, g_p;
  string s1;

  if (!str) {
    notify_fail("Syntax: slip <objects> to <objects>\n");
    return 0;
  }
  
  if (sscanf(str, "%s to %s", str, s1) != 2) {
    notify_fail("Syntax: slip <objects> to <objects>\n");
    return 0;
  }
  obs = find_match(s1, environment(this_player()));
  if (!sizeof(obs)) {
    notify_fail("Slip to who?\n");
    return 0;
  }

  skill = (int)this_player()->query_skill_bonus(SKILL);
  g_p = (int)this_player()->query_gp();

  for (i=0;i<sizeof(obs);i++) {
    t_p = fail = g_f = ({ });
    obs2 = find_match(str, this_player());
    for (j=0;j<sizeof(obs2);j++)
      if (obs2[j]->move(obs[i]))
        fail += ({ obs2[j] });
コード例 #2
0
int main()
{
	srand((unsigned) time(NULL));

	std::string sInput = "";
	std::string sResponse = "";
	std::string sPreviousResponse = "";

	while(1) {
		std::cout << ">";
		sPreviousResponse = sResponse;
		std::getline(std::cin, sInput);
		preprocess_input(sInput);
		vstring responses = find_match(sInput);
		if(sInput == "BYE") {
			std::cout << "IT WAS NICE TALKING TO YOU USER, SEE YOU NEXT TIME!" << std::endl;
			break;
		} else if(responses.size() == 0) {
			std::cout << "I'M NOT SURE IF I UNDERSTAND WHAT YOU ARE TALKING ABOUT." << std::endl;
		} else {
			int nSelection = rand() % MAX_RESP;
			sResponse = responses[nSelection];
			// avoids repeating the same response
			if(sResponse == sPreviousResponse) {
				responses.erase(responses.begin() + nSelection);
				nSelection = rand() % responses.size();
				sResponse = responses[nSelection];
			}
			std::cout << sResponse << std::endl;
		}
	}

	return 0;
}
コード例 #3
0
ファイル: instance.c プロジェクト: zeldin/libsigrokdecode
/**
 * Process available samples and check if they match the defined conditions.
 *
 * This function returns if there is an error, or when a match is found, or
 * when all samples have been processed (whether a match was found or not).
 *
 * @param di The decoder instance to use. Must not be NULL.
 * @param found_match Will be set to TRUE if at least one condition matched,
 *                    FALSE otherwise. Must not be NULL.
 *
 * @retval SRD_OK No errors occured, see found_match for the result.
 * @retval SRD_ERR_ARG Invalid arguments.
 *
 * @private
 */
SRD_PRIV int process_samples_until_condition_match(struct srd_decoder_inst *di, gboolean *found_match)
{
	if (!di || !found_match)
		return SRD_ERR_ARG;

	/* Check if any of the current condition(s) match. */
	while (TRUE) {
		/* Feed the (next chunk of the) buffer to find_match(). */
		*found_match = find_match(di);

		/* Did we handle all samples yet? */
		if (di->abs_cur_samplenum >= di->abs_end_samplenum) {
			srd_dbg("Done, handled all samples (abs cur %" PRIu64
				" / abs end %" PRIu64 ").",
				di->abs_cur_samplenum, di->abs_end_samplenum);
			return SRD_OK;
		}

		/* If we didn't find a match, continue looking. */
		if (!(*found_match))
			continue;

		/* At least one condition matched, return. */
		return SRD_OK;
	}

	return SRD_OK;
}
コード例 #4
0
ファイル: ftmenu.c プロジェクト: taq/ftmenu
static char* menu_title(char *menu_file, char *title){
	wordexp_t exp_result;

	if(find_match(menu_file,"^(\\[begin\\]) (\\()(.*)(\\).*)",3,title)==NULL)
		return NULL;
	return title;
}
コード例 #5
0
ファイル: raise.c プロジェクト: quixadhal/discworld
mixed raise(string str, int skill, int cast) {     
  mixed ob;

  if (!str || str == "")
    return "You try to raise nothing and fail miserably.\n";
  ob = find_match(str, environment(this_player()));
  if (sizeof(ob))
    ob = ob[0];
  else
    return "Who is " + capitalize(str) + "?\n";
  if (!living(ob))
    return (string)ob->query_cap_name() + " refuses to be brought to life.\n";
  if (!ob->query_property("dead"))
    return (string)ob->query_cap_name() + " is not dead ... yet.\n";
  if (ob->query_property("noregen"))
    return "Death tells you: HOLD ON, I'M NOT FINISHED WITH THEM YET.\n";
  if (cast && (int)this_player()->adjust_gp(-SP_COST) < 0)
    return "Too low on power.\n";
  write("You call upon the gods to restore " + (string)ob->query_cap_name() +
    " from " + (string)ob->query_possessive() + " immaterial state.\n");
  tell_object(ob, (string)this_player()->query_cap_name() +
    " summons the gods for you.\n");
  say((string)this_player()->query_cap_name() + " summons the gods to raise " +
    (string)ob->query_cap_name() + " from the dead.\n", ob);
  ob->remove_ghost();
  return 1;
}
コード例 #6
0
ファイル: fake_event.c プロジェクト: chigumaya/unbound
/**
 * Find the range that matches this pending message.
 * @param runtime: runtime with current moment, and range list.
 * @param entry: returns the pointer to entry that matches.
 * @param pend: the pending that the entry must match.
 * @return: true if a match is found.
 */
static int
pending_find_match(struct replay_runtime* runtime, struct entry** entry, 
	struct fake_pending* pend)
{
	int timenow = runtime->now->time_step;
	struct replay_range* p = runtime->scenario->range_list;
	while(p) {
		if(p->start_step <= timenow && timenow <= p->end_step &&
		  (p->addrlen == 0 || sockaddr_cmp(&p->addr, p->addrlen,
		  	&pend->addr, pend->addrlen) == 0) &&
		  (*entry = find_match(p->match, pend->pkt, pend->pkt_len,
		 	 pend->transport))) {
			log_info("matched query time %d in range [%d, %d] "
				"with entry line %d", timenow, 
				p->start_step, p->end_step, (*entry)->lineno);
			if(p->addrlen != 0)
				log_addr(0, "matched ip", &p->addr, p->addrlen);
			log_pkt("matched pkt: ",
				(*entry)->reply_list->reply_pkt,
				(*entry)->reply_list->reply_len);
			return 1;
		}
		p = p->next_range;
	}
	return 0;
}
コード例 #7
0
ファイル: gfx_lzw_enc.c プロジェクト: jasonkfirth/fbc
/*:::::*/
FBCALL int fb_hEncode(const unsigned char *in_buffer, int in_size, unsigned char *out_buffer, int *out_size)
{
	LZW_ENTRY *e;
	unsigned short string_code, next_code = 256;
	unsigned char bit = 0;
	int size;

	size = 0;
	fb_hMemSet(fb_lzw_entry, -1, sizeof(fb_lzw_entry));
	string_code = *in_buffer++;
	in_size--;
	while (in_size) {
		e = find_match(string_code, *in_buffer);
		if (e->code != -1)
			string_code = (unsigned short)e->code;
		else {
			if (next_code < MAX_CODE) {
				e->code = next_code++;
				e->prefix = string_code;
				e->value = *in_buffer;
			}
			OUTPUT_CODE(string_code);
			string_code = *in_buffer;
		}
		in_buffer++;
		in_size--;
	}
	OUTPUT_CODE(string_code);
	OUTPUT_CODE(MAX_CODE);
	if (bit)
		size++;
	*out_size = size;
	return 0;
}
コード例 #8
0
ファイル: LZW_Pick70.c プロジェクト: kaelfischer/lib_prrsv
int LZWsize(char* seq, int size) //    (FILE *input,FILE *output)
{
  unsigned int next_code;
  unsigned int character;
  unsigned int string_code;
  unsigned int index;
  int i =0,j=0;

  if (size == 0)
    return 0;
  
  code_value=malloc(TABLE_SIZE*sizeof(unsigned int));
  prefix_code=malloc(TABLE_SIZE*sizeof(unsigned int));
  append_character=malloc(TABLE_SIZE*sizeof(unsigned char));

  next_code=256;              /* Next code is the next available string code*/
  for (i=0;i<TABLE_SIZE;i++)  /* Clear out the string table before starting */
    code_value[i]=-1;

  string_code=seq[0];    /* Get the first code                         */
  i=1;
/*
** This is the main loop where it all happens.  This loop runs util all of
** the input has been exhausted.  Note that it stops adding codes to the
** table after all of the possible codes have been defined.
*/

  while (i<size)
  {
    character = seq[i];
    ++i;

    index=find_match(string_code,character);/* See if the string is in */
    if (code_value[index] != -1)            /* the table.  If it is,   */
      string_code=code_value[index];        /* get the code value.  If */
    else                                    /* the string is not in the*/
    {                                       /* table, try to add it.   */
      if (next_code <= MAX_CODE)
      {
        code_value[index]=next_code++;
        prefix_code[index]=string_code;
        append_character[index]=character;
      }
      // output_code(output,string_code);  /* When a string is found  */
      string_code=character;            /* that is not in the table*/
      ++j;
    }                                   /* I output the last string*/
  }                                     /* after adding the new one*/
/*
** End of the main loop.
*/

  //  output_code(output,string_code); /* Output the last code               */
  ++j;

  //  output_code(output,MAX_VALUE);   /* Output the end of buffer code      */
  //output_code(output,0);           /* This code flushes the output buffer*/
  return j;
}
コード例 #9
0
ファイル: ftmenu.c プロジェクト: taq/ftmenu
static char* icon_file(char *menu_file, char *icon){
	wordexp_t exp_result;

	if(find_match(menu_file,"^(.*\\[begin\\]) (.*) (<)(.+)(>)",4,icon)==NULL)
		return NULL;
	wordexp(icon,&exp_result,0);
	strcpy(icon,exp_result.we_wordv[0]);
	return icon;
}
コード例 #10
0
ファイル: parse_config.c プロジェクト: cehh/powertool
void parse_cleanup(char **rails_to_measure, int num_rails,
		   char **groups_to_measure, int num_groups)
{
	struct pm_bus *bus = root_pm_bus, *to_free_bus, *prev_bus = NULL;
	struct ina226_rail *rail, *to_free_rail, *prev_rail = NULL;

	while (bus) {
		rail = bus->rail;
		while (rail) {
			/* is this rail a matching rail? if yes, skip */
			if (find_match(rail->name, rails_to_measure, num_rails)
			    || find_match(rail->board_group_name,
					  groups_to_measure, num_groups)) {
				prev_rail = rail;
				rail = rail->next;
				continue;
			}

			to_free_rail = rail;
			rail = rail->next;
			/* unlink it */
			if (to_free_rail == bus->rail)
				bus->rail = rail;
			else
				prev_rail->next = rail;
			ina226_free(to_free_rail);
		}

		if (bus->rail) {
			prev_bus = bus;
			bus = bus->next;
			continue;
		}

		to_free_bus = bus;
		bus = bus->next;
		/* unlink it */
		if (to_free_bus == root_pm_bus)
			root_pm_bus = bus;
		else
			prev_bus->next = bus;
		pm_bus_free(to_free_bus);
	}
}
コード例 #11
0
void tab_group_t::display(const any_regular_t& new_value)
{
    assert(control_m);

    tab_set_t::iterator iter(find_match(items_m, new_value, compare_members(&tab_t::value_m, std::equal_to<any_regular_t>())));

    if (iter == items_m.end()) return;

    ::SendMessage(control_m, TCM_SETCURSEL, iter - items_m.begin(), 0);
}
コード例 #12
0
ファイル: findobj.c プロジェクト: sartak/Undertow
static int find_in_arm(CHAR_DATA *ch, char *args, OBJECT_DATA **exact, OBJECT_DATA **other)
{
  /* try to cut down on number of stack variables */
  /* started at 13, down to 4 after spawning off a function */
  OBJECT_DATA *obj;
  int mperc = 0, m, perc = 0;
  int i, is_eq;
  *exact = *other = 0;

  /* yes, nutty way to keep track of inv */
  for (obj = ch->obj; obj != 0; obj = obj->next_local)
  {
    is_eq = 0;
    for (i = 0; i < EQUIP_MAX; ++i)
    {
      if (i == EQUIP_LHAND || i == EQUIP_RHAND) /* todo: check if shields */
        continue;
      if (ch->equip[i] == obj)
      {
        is_eq = 1;
        break;
      }
    }
    if (!is_eq)
      continue;
    m = find_match(obj, args, &perc);
    if (m == 1) /* inexact match */
    {
      if (which == 0) /* find best matching */
      {
        if (perc > mperc)
        {
          mperc = perc;
          *other = obj;
        }
      }
      else if (which == cur)
      {
        *other = obj;
        return 1;
      }
        cur++;
    }
    else if (m == 2) /* exact match */
    {
      if (which == 0 || which == cur)
      {
        *exact = obj;
        return 2;
      }
      cur++;
    }
  }
  return (other != 0) ? 1 : 0;
}
コード例 #13
0
ファイル: ftmenu.c プロジェクト: taq/ftmenu
static char* fluxbox_menu_file(char* init_file, char *menu_file){
	wordexp_t exp_result;

	if(find_match(init_file,"^(session\\.menuFile:)(.*)$",2,menu_file)==NULL){
		g_error("Could not find the menu file on config in %s",init_file);
		return NULL;
	}
	wordexp(menu_file,&exp_result,0);
	strcpy(menu_file,exp_result.we_wordv[0]);
	return menu_file;
}
コード例 #14
0
ファイル: cure_disease.c プロジェクト: quixadhal/discworld
mixed cure_disease(string str, int skill, int cast) {
  mixed ob;
 
  if ((int)this_player()->query_spell_effect("spell")) 
    return "You are already casting a spell.\n";
  ob = filter_array(find_match(str, environment(this_player())), "check_liv",
                    this_object());
  if (!sizeof(ob))
    return "You must cast calm at someone.\n";
  this_player()->add_spell_effect(1, "spell", "Cure Disease",
    this_object(), "hb_cure_disease", ({ skill, ob, cast }));
コード例 #15
0
ファイル: platform_tab_group.cpp プロジェクト: Syntaf/GG
void tab_group_t::display(const any_regular_t& new_value)
{
    assert(control_m);

    tab_set_t::iterator it =
        find_match(items_m, new_value,
                   compare_members(&tab_t::value_m, std::equal_to<any_regular_t>()));

    if (it != items_m.end())
        tab_bar_m->SetCurrentTab(it - items_m.begin());
}
コード例 #16
0
ファイル: findobj.c プロジェクト: sartak/Undertow
static int find_in_inv(CHAR_DATA *ch, char *args, OBJECT_DATA **exact, OBJECT_DATA **other)
{
  /* try to cut down on number of stack variables */
  /* started at 13, down to 4 after spawning off a function */
  OBJECT_DATA *obj;
  int mperc = 0, m, perc = 0;
  int i, is_inv;
  *exact = *other = 0;

  /* yes, nutty way to keep track of inv */
  for (obj = ch->obj; obj != 0; obj = obj->next_local)
  {
    is_inv = 1;
    if (obj->container != NULL) /* we don't want contained items */
      continue;
    for (i = 0; i < EQUIP_MAX; ++i) /* we don't want weapons or armor */
      if (ch->equip[i] == obj)
      {
        is_inv = 0;
        break;
      }
    if (!is_inv)
      continue;
    m = find_match(obj, args, &perc);
    if (m == 1) /* inexact match */
    {
      if (which == 0) /* find best matching */
      {
        if (perc > mperc)
        {
          mperc = perc;
          *other = obj;
        }
      }
      else if (which == cur)
      {
        *other = obj;
        return 1;
      }
        cur++;
    }
    else if (m == 2) /* exact match */
    {
      if (which == 0 || which == cur)
      {
        *exact = obj;
        return 2;
      }
      cur++;
    }
  }
  return (other != 0) ? 1 : 0;
}
コード例 #17
0
ファイル: lz78.c プロジェクト: daemqn/Atari_ST_Sources
/*
	This is the compression routine.  The code should be a fairly close
	match to the algorithm accompanying the article.
*/
void compress(FILE * input,FILE * output) {
	unsigned int next_code;
	unsigned int character;
	unsigned int string_code;
	unsigned int index;
	int i;
	
	/* Write original file length */
	long int flen = filelength(fileno(input));
	putc((unsigned char)(flen >> 24),output);
	putc((unsigned char)(flen >> 16),output);
	putc((unsigned char)(flen >> 8),output);
	putc((unsigned char)flen,output);			

	next_code=256;              /* Next code is the next available string code*/
	for (i=0;i<TABLE_SIZE;i++)  /* Clear out the string table before starting */
    	code_value[i]=-1;

	i=0;
	string_code=getc(input);    /* Get the first code */
	
	/*
	   This is the main loop where it all happens.  This loop runs util all of
	   the input has been exhausted.  Note that it stops adding codes to the
	   table after all of the possible codes have been defined.
	*/
	while ((character=getc(input)) != (unsigned)EOF) {
    
		if (++i==1000) {
			i=0;
			printf("*");
		}
		
		index=find_match(string_code,character);	/* See if the string is in */
		if (code_value[index] != -1)				/* the table.  If it is,   */
			string_code=code_value[index];        	/* get the code value.  If */
		else                                    	/* the string is not in the*/
		{                                       	/* table, try to add it.   */
			if (next_code <= MAX_CODE) {
				code_value[index]=next_code++;
				prefix_code[index]=string_code;
				append_character[index]=character;
			}
			output_code(output,string_code);	/* When a string is found  */
			string_code=character;				/* that is not in the table*/
		}										/* I output the last string*/
	}											/* after adding the new one*/
	
	/* End of the main loop. */
	output_code(output,string_code); /* Output the last code */
	output_code(output,MAX_VALUE);   /* Output the end of buffer code */
	output_code(output,0);           /* This code flushes the output buffer */
}
コード例 #18
0
struct waiting_tcp* 
pending_tcp_query(struct outside_network* outnet, ldns_buffer* packet,
	struct sockaddr_storage* addr, socklen_t addrlen, int timeout,
	comm_point_callback_t* callback, void* callback_arg)
{
	struct replay_runtime* runtime = (struct replay_runtime*)outnet->base;
	struct fake_pending* pend = (struct fake_pending*)calloc(1,
		sizeof(struct fake_pending));
	ldns_status status;
	log_assert(pend);
	pend->buffer = ldns_buffer_new(ldns_buffer_capacity(packet));
	log_assert(pend->buffer);
	ldns_buffer_write(pend->buffer, ldns_buffer_begin(packet),
		ldns_buffer_limit(packet));
	ldns_buffer_flip(pend->buffer);
	memcpy(&pend->addr, addr, addrlen);
	pend->addrlen = addrlen;
	pend->callback = callback;
	pend->cb_arg = callback_arg;
	pend->timeout = timeout;
	pend->transport = transport_tcp;
	pend->pkt = NULL;
	pend->runtime = runtime;
	pend->serviced = 0;
	status = ldns_buffer2pkt_wire(&pend->pkt, packet);
	if(status != LDNS_STATUS_OK) {
		log_err("ldns error parsing tcp output packet: %s",
			ldns_get_errorstr_by_id(status));
		fatal_exit("Sending unparseable DNS packets to servers!");
	}
	log_pkt("pending tcp pkt: ", pend->pkt);

	/* see if it matches the current moment */
	if(runtime->now && runtime->now->evt_type == repevt_back_query &&
		(runtime->now->addrlen == 0 || sockaddr_cmp(
			&runtime->now->addr, runtime->now->addrlen,
			&pend->addr, pend->addrlen) == 0) &&
		find_match(runtime->now->match, pend->pkt, pend->transport)) {
		log_info("testbound: matched pending to event. "
			"advance time between events.");
		log_info("testbound: do STEP %d %s", runtime->now->time_step,
			repevt_string(runtime->now->evt_type));
		advance_moment(runtime);
		/* still create the pending, because we need it to callback */
	} 
	log_info("testbound: created fake pending");
	/* add to list */
	pend->next = runtime->pending_list;
	runtime->pending_list = pend;
	return (struct waiting_tcp*)pend;
}
コード例 #19
0
ファイル: findobj.c プロジェクト: sartak/Undertow
static int find_in_flr(CHAR_DATA *ch, char *args, OBJECT_DATA **exact, OBJECT_DATA **other, long limit)
{
  OBJECT_DATA *obj;
  int mperc = 0, m, perc = 0;
  int plane = 0, mud = 0, dist = 0;

  *exact = *other = 0;

  for (obj = objhead; obj; obj = obj->next)
  {
    if (limit < 0)
      plane = 1;
    if (limit == -2)
      mud = 1;
    dist = (obj->x - ch->x) * (obj->x - ch->x) + (obj->y - ch->y) * (obj->y - ch->y) <= limit * limit;
    if (obj->plane != ch->plane && !mud)
      continue;
    if (!dist && !plane)
      continue;
    if (obj->holder != NULL || obj->container != NULL)
      continue;
    m = find_match(obj, args, &perc);
    if (m == 1) /* inexact match */
    {
      if (which == 0) /* find best matching */
      {
        if (perc > mperc)
        {
          mperc = perc;
          *other = obj;
        }
      }
      else if (which == cur)
      {
        *other = obj;
        return 1;
      }
        cur++;
    }
    else if (m == 2) /* exact match */
    {
      if (which == 0 || which == cur)
      {
        *exact = obj;
        return 2;
      }
      cur++;
    }
  }
  return (other != 0) ? 1 : 0;
}
コード例 #20
0
ファイル: fake_event.c プロジェクト: chigumaya/unbound
struct waiting_tcp* 
pending_tcp_query(struct outside_network* outnet, sldns_buffer* packet,
	struct sockaddr_storage* addr, socklen_t addrlen, int timeout,
	comm_point_callback_t* callback, void* callback_arg,
	int ATTR_UNUSED(ssl_upstream))
{
	struct replay_runtime* runtime = (struct replay_runtime*)outnet->base;
	struct fake_pending* pend = (struct fake_pending*)calloc(1,
		sizeof(struct fake_pending));
	log_assert(pend);
	pend->buffer = sldns_buffer_new(sldns_buffer_capacity(packet));
	log_assert(pend->buffer);
	sldns_buffer_write(pend->buffer, sldns_buffer_begin(packet),
		sldns_buffer_limit(packet));
	sldns_buffer_flip(pend->buffer);
	memcpy(&pend->addr, addr, addrlen);
	pend->addrlen = addrlen;
	pend->callback = callback;
	pend->cb_arg = callback_arg;
	pend->timeout = timeout;
	pend->transport = transport_tcp;
	pend->pkt = NULL;
	pend->zone = NULL;
	pend->runtime = runtime;
	pend->serviced = 0;
	pend->pkt_len = sldns_buffer_limit(packet);
	pend->pkt = memdup(sldns_buffer_begin(packet), pend->pkt_len);
	if(!pend->pkt) fatal_exit("out of memory");
	log_pkt("pending tcp pkt: ", pend->pkt, pend->pkt_len);

	/* see if it matches the current moment */
	if(runtime->now && runtime->now->evt_type == repevt_back_query &&
		(runtime->now->addrlen == 0 || sockaddr_cmp(
			&runtime->now->addr, runtime->now->addrlen,
			&pend->addr, pend->addrlen) == 0) &&
		find_match(runtime->now->match, pend->pkt, pend->pkt_len,
			pend->transport)) {
		log_info("testbound: matched pending to event. "
			"advance time between events.");
		log_info("testbound: do STEP %d %s", runtime->now->time_step,
			repevt_string(runtime->now->evt_type));
		advance_moment(runtime);
		/* still create the pending, because we need it to callback */
	} 
	log_info("testbound: created fake pending");
	/* add to list */
	pend->next = runtime->pending_list;
	runtime->pending_list = pend;
	return (struct waiting_tcp*)pend;
}
コード例 #21
0
ファイル: hhash.c プロジェクト: gitter-badger/knot
int hhash_del(hhash_t* tbl, const char* key, uint16_t len)
{
	if (tbl == NULL) {
		return KNOT_EINVAL;
	}

	uint32_t idx = hash(key, len) % tbl->size;
	unsigned dist = find_match(tbl, idx, key, len);
	if (dist > HOP_LEN) {
		return KNOT_ENOENT;
	}

	return hhelem_free(tbl, idx, dist, NULL);
}
コード例 #22
0
int max_match()
{
	memset(match, -1, sizeof(match));
	for (int i = 0; i < x_num; i++)
	{
		memset(vis, 0, sizeof(vis));
		find_match(i);
	}
	int ans = 0;
	for (int i = 0; i < y_num; i++)
		if (match[i] != -1)
			ans++;
	return ans;
}
コード例 #23
0
int nearest_neighbour(User *user, User ** set, int langs)
{
    int i, k;
    double vote;
    Repo *repo, *candidates[WATCH_SIZE];
    Match *match;
    int votes = 0;
    int candidate_count;
    int matches;

    if(langs) get_langs(user);

    /* Each user in the set */
    for(i = 0; i < stats.filtered_user_count; i++) {
        if(user == set[i]) continue;

        matches = candidate_count = 0;

        /* Get number of matches, and store the rest in candidates[] */
        for(k = 0; k < set[i]->watch_count; k++) {
            repo = set[i]->watch[k];
            if(find(repo, user->watch, user->watch_count)) matches++;
            else candidates[candidate_count++] = repo;
        }

        /* If the watch-list is similar enough (lots of matches) */
        if(matches > (user->watch_count * REPO_MATCH_TRESHOLD)) {

            vote = normalize(matches, set[i]->watch_count, 100);

            /* Go through candidates, and add them to recommendations */
            for(k = 0; k < candidate_count; k++) {
                repo = candidates[k];

                if(langs) vote += match_langs(user->langs, repo->langs, user->lang_count, repo->lang_count);

                /* repo is already in recommendation list, add a vote */
                if(match = find_match(repo, user->recommend, votes)) match->weight += vote;
                else {
                    user->recommend[votes].repo = repo;
                    user->recommend[votes++].weight = vote
                                                      + normalize(repo->watchers, stats.max_watchers, 1);
                }
            }
        }
    }
    return votes;
}
コード例 #24
0
void CBot::handle_repetition()
{
	if(response_list.size() > 0)
	{
		response_list.erase(response_list.begin());
	}
	if(no_response())
	{
		save_input();
		set_input(m_sEvent);

		find_match();
		restore_input();
	}
	select_response();
}
コード例 #25
0
bool find_match(int a)
{
	for (int i = head[a]; ~i; i = edge[i].next)
	{
		int v = edge[i].v;
		if (vis[v])
			continue;
		vis[v] = true;
		if (match[v] == -1 || find_match(match[v]))
		{
			match[v] = a;
			return true;
		}
	}
	return false;
}
コード例 #26
0
void CBot::respond() 
{
	save_prev_response();
	set_event("BOT UNDERSTAND**");

	if(null_input())
	{
		handle_event("NULL INPUT**");
	}
	else if(null_input_repetition())
	{
		handle_event("NULL INPUT REPETITION**");
	}
	else if(user_repeat())
	{
		handle_user_repetition();
	}
	else
	{
		find_match();
	}

    
    if(user_want_to_quit())
	{
		m_bQuitProgram = 1;
	}

	if(!bot_understand())
	{
		handle_event("BOT DON'T UNDERSTAND**");
	}
	
	if(response_list.size() > 0) 
	{
		select_response();
		preprocess_response();

		if(bot_repeat())
		{
			handle_repetition();
		}
		print_response();
	}
}
コード例 #27
0
void CBot::handle_event(std::string str)
{
	save_prev_event();
	set_event(str);

	save_input();

	insert_space(str);

	set_input(str);

	if(!same_event()) 
	{
		find_match();
	}

	restore_input();
}
コード例 #28
0
ファイル: backstab.c プロジェクト: quixadhal/discworld
mixed do_backstab(string str, int skill, int cast, object wpn) {
  mixed ob;
/* now skill bonus... will range from about 1-250 or so...
 * make max damage 25 hp... ok skill/10.
 * no problems.
 * remember it will be random(dam) anyway ...
 * garanteeded of doing SOME damage.. ;)
 */
  if ((int)this_player()->query_spell_effect("attack")) 
/* used to add spells in the attack procedure. */
    return "You are already casting a spell.\n";
  ob = find_match(str, environment(this_player()));
  if (sizeof(ob))
    ob = ob[0];
   else
    return "Backstab whom?\n";
  this_player()->add_spell_effect(1, "attack", "Backstab", this_object(),
                         "heart_beat_backstab", ({ skill/10, ob, cast, wpn }));
コード例 #29
0
ファイル: cfg.c プロジェクト: gongheguoyingpai/cfg
void  start_cfg(array*  a)
{
	/* 只有当整个array中只有一个结点 也就是句子结点时才表示结束 */
	while (a->size != 1)
	{
	    int  pos = 0;
		
	    int  prop_pos = find_match(a, &pos);
		
		/* 只要句子合理一般是可以找到一个组合的 如果找不到则说明句式有问题 */
		if (prop_pos == 0)
		{
		    fprintf(stderr, "We think maybe the sentence is illegality!\n");
			exit(1);
		}
		else
		{
            word*  node = (word*)malloc(sizeof(word));
			check_malloc(node);
			
			property* p = (property*)malloc(sizeof(property));
			check_malloc(p);
			
			char*  s = (char*)malloc(strlen((props[prop_pos]).key) + 1);
			check_malloc(s);
			
			p->key = s;
			p->value = (props[prop_pos]).value;
			strcpy(p->key, (props[prop_pos]).key);
			
			node->value = NULL;
			node->prop = p;
			node->left = a->words[pos];
			node->right = a->words[pos+1];
			(a->words[pos])->parent = node;
			(a->words[pos+1])->parent = node;
			
			a->words[pos] = node;
			
			delete_node(a, pos+1);
        }
	}
}
コード例 #30
0
ファイル: ip6tables-save.c プロジェクト: ebichu/dd-wrt
static int print_match(const struct ip6t_entry_match *e,
			const struct ip6t_ip6 *ip)
{
	struct ip6tables_match *match
		= find_match(e->u.user.name, TRY_LOAD, NULL);

	if (match) {
		printf("-m %s ", e->u.user.name);

		/* some matches don't provide a save function */
		if (match->save)
			match->save(ip, e);
	} else {
		if (e->u.match_size) {
			fprintf(stderr,
				"Can't find library for match `%s'\n",
				e->u.user.name);
			exit(1);
		}
	}
	return 0;
}