Esempio n. 1
0
File: med_util.c Progetto: amnh/poy5
/* Copies a permutation, simultaneously representing the effect of the
   specified reversal */
void
copy_with_reversal ( int *dest, int *src, int n, Reversal * rev )
{
    assert(dest!=src); 
    int i, mid;
    int tmp[64];
    for(i=0 ; i<n ; i++)
        tmp[i]=src[i];
    if ( 1== check_repeat( src, n ))
    {
        fprintf(stdout," \n copy from repeated src,rev=(%d,%d): ",
                rev->start,rev->stop);
        for(i=0;i<n;i++)
            fprintf(stdout,"[%d]=%d,",i,src[i]);
        fprintf(stdout,"\n"); fflush(stdout);
        assert(0);
    }
   // src = tmp;

    for ( i = 0; i < rev->start; i++ )
        dest[i] = src[i];

    mid = ceil ( ( rev->stop - rev->start ) / 2.0 );
    for ( i = 0; i < mid; i++ )
    {
        dest[rev->start + i] = -1 * src[rev->stop - 1 - i];
        dest[rev->stop - 1 - i] = -1 * src[rev->start + i];
    }

    for ( i = rev->stop; i < n; i++ )
        dest[i] = src[i];

    if ( 1== check_repeat( dest, n ))
    {
        fprintf(stdout," \n copy from src: ");
        for(i=0;i<n;i++)
            fprintf(stdout,"[%d]=%d/%d,",i,src[i],tmp[i]);
        fprintf(stdout," \n to dest with rev:(%d,%d), has repeated items, dest = \n",
                rev->start,rev->stop);
        for(i=0;i<n;i++)
            fprintf(stdout,"[%d]=%d,",i,dest[i]);
        fprintf(stdout,"\n"); fflush(stdout);
        assert(0);
    }

    
}
Esempio n. 2
0
bool test_repeat() {
	Vertex c3[] = {Vertex(7), Vertex(6), Vertex(5), Vertex(3)};
	Vertex c4[] = {Vertex(4), Vertex(0), Vertex(2), Vertex(0)};
	Vertex* cycleList2[] = {c3, c4};
	int factor2[] = {4, 4};
	if(check_repeat(8, 2, factor2, cycleList2)) {
		return false;
	}
    return true;
}
Esempio n. 3
0
File: fopen.c Progetto: hxhlb/GridOS
/*
	@brief 为stdio_file设置具体的flags
 
	r	打开只读文件,该文件必须存在;
	r+	打开可读写文件,该文件必须存在;
	w	打开只写文件,若文件存在则清除文件内容,即文件长度为0,
		若文件不存在则创建文件;
	w+	打开可读写文件,若文件存在则清除文件内容,即文件长度为0,
		若文件不存在则创建文件;
	a	附加方式打开只写文件,若文件存在则写入数据只会追加至文件尾,文件原数据无法修改,
		若文件不存在则创建文件;
	a+	附加方式打开可读写文件,若文件存在则写入数据只会追加至文件尾,文件原数据无法修改,
		若文件不存在则创建文件。
 
	b	二进制流
 
	@return 成功返回true,失败则返回false
 */
static bool set_file_flags(struct stdio_file *file, const char *type)
{
	bool ret = true;
	int	access_modes, status_flags, count;
	
	if (strlen(type) > FLAG_LENGTH) return false;
	
	/* 检查flags中是否有重复设置 */
	if (check_repeat(type)) return false;
	
	/* r/w/a为第一个字符 */
	switch (type[0])
	{
		case 'r':
			access_modes = O_RDONLY;
			status_flags = 0;
			break;
		case 'w':
			access_modes = O_WRONLY;
			status_flags = O_CREAT | O_TRUNC;
			break;
		case 'a':
			access_modes = O_WRONLY;
			status_flags = O_CREAT | O_APPEND;
			break;
			
		default:
			return false;
	}
	
	/* 'b'和'+'位于/r/w/a后,其顺序可不受限制,如/r/w/ab+、/r/w/a+b等效 */
	for (type++; *type != '\0'; type++)
	{
		switch (*type)
		{
			case 'b':
				break;
			case '+':
				access_modes = O_RDWR;
				break;
			default:
				return false;
		}
	}
	
	file->flags = access_modes | status_flags;
	return ret;
}
Esempio n. 4
0
/*
 * msg_channel
 *
 * inputs	- flag privmsg or notice
 * 		- pointer to command "PRIVMSG" or "NOTICE"
 *		- pointer to client_p
 *		- pointer to source_p
 *		- pointer to channel
 * output	- NONE
 * side effects	- message given channel
 */
static void
msg_channel(int p_or_n, char *command,
            struct Client *client_p,
            struct Client *source_p, struct Channel *chptr, char *text)
{
  struct Channel *vchan = NULL;
  char *chname = NULL;
  int result;

  chname = RootChan(chptr)->chname;

#ifdef VCHANS
  if (HasVchans(chptr))
    vchan = map_vchan(chptr, source_p);
#endif
  
  if (!vchan)
    vchan = chptr;

  if (MyClient(source_p))
  {
    /* idle time shouldnt be reset by notices --fl */
    if ((p_or_n != NOTICE) && source_p->user)
      source_p->user->last = CurrentTime;
  }

  /* chanops and voiced can flood their own channel with impunity */
  if ((result = can_send(vchan, source_p)))
  {
    if (result == CAN_SEND_NOTREG)
	{
	  if (p_or_n != NOTICE)
	    sendto_one(source_p, form_str(source_p,ERR_CANNOTSENDNOTREG),
		       me.name, source_p->name, chname);
	  return;
	}
    if (result == CAN_SEND_OPV ||
        !flood_attack_channel(p_or_n, source_p, vchan, chname))
    {
		dlink_node *ptr;
		struct Ban *banptr;
		char strbuf[BUFSIZE+1], buf[TOPICLEN+1];
		char *word, *subst, *p = buf;
		int drop = 0;

		if (MyClient(source_p) && IsPerson(source_p))
		if (!is_chan_op(vchan, source_p) && NoRepeatChannel(vchan))
		if (check_repeat(source_p, vchan, text)) {
			sendto_one(source_p, form_str(source_p,ERR_NOREPEATING),
				me.name, source_p->name, chname);
			return;
		}

	  if (NoColorChannel(vchan)) 
	    /*strip_color(text);*/
	    text = strip_color(text, 0);

	  strncpy(strbuf, text, BUFSIZE)[BUFSIZE] = 0;

	  if (MyClient(source_p) && IsPerson(source_p))
	  if (!is_chan_op(vchan, source_p))
	  for (ptr = vchan->substlist.head; ptr; ptr = ptr->next, p = buf) {
		  banptr = ptr->data; 
		  strncpy(buf, banptr->banstr, TOPICLEN)[TOPICLEN] = 0;

		  while (*p) 
			  if (*p++ == '$')
				  *(p-1) = ' ';

		  subst = strchr(buf, '/'); if (subst) {
			  *subst++ = 0; word = buf;
			  if (strstr(strbuf, word) && !irccmp(subst, "&"))
			  	drop = 1;
			  replace(strbuf, word, subst, BUFSIZE);
			  strbuf[BUFSIZE] = 0;
		  }
	  }

      if (!drop) {
	  if (PaceChannel(vchan) && (vchan->msgs < MAX_PACEMSG))
	    add_pace_msg(vchan, client_p, source_p, command, strbuf);
	  else
      	sendto_channel_butone(client_p, source_p, vchan, command, ":%s", strbuf);
      }
    }
  }
  else
  {
    if (p_or_n != NOTICE)
      sendto_one(source_p, form_str(source_p,ERR_CANNOTSENDTOCHAN),
                 me.name, source_p->name, chname);
  }
}
Esempio n. 5
0
bool verify(int n, int numCycles, int* factor, Vertex** cycleList) {
	return check_repeat(n, numCycles, factor, cycleList) &&
			check_differences(n, numCycles, factor, cycleList);
}