Пример #1
0
void vt100_echo(termstate_t *term, char c, l4_int8_t old)
{
    char buf[2];

    switch(c)
    {
    case '\b':
        if (IS_CTRL(old))
        {
            vt100_write( term,"\b \b", 3);
        }
        vt100_write(term, "\b \b", 3);
        break;
    case 13:  // RETURN is a ctrl-character but should not print as ^M
        vt100_write(term, "\n", 1);
        break;
    case 10:  // ^R is a ctrl-character but should print a LF additionally
        displaymap(c, buf);
        vt100_write(term, buf, 2);
        vt100_write(term, "\n", 1);
        break;
    default:
        if (IS_CTRL(c))
        {
            displaymap(c, buf);
            vt100_write(term, buf, 2);
        }
        else if (term->__ctrl)   // fixme: what is this used for???
        {
            displaymap(c, buf);
            vt100_write( term, buf, 2 );
        }
        else
        {
            vt100_write( term, &c, 1 );
        }
        break;
    }
}
Пример #2
0
int main(){
  int i,j,dx,dy,x,y,c,g,turn,cnt,a[8][8];
  char symbol[]={'X','-','O'};
  /* 初期化 */
  c = 1; /* 順番 */
  turn = 0; /* 総ターン数 */
  g = 0; /* 反転数 */
  cnt = 2; /* 先手の駒数 */  
  for(i=0;i<8;i++) /* マップの初期化 */
    for(j=0;j<8;j++)
      a[i][j] = 0;
  a[3][3]=a[4][4]=1; /* O の初期配置 */
  a[3][4]=a[4][3]=-1; /* X の初期配置 */
  
  while(turn <= 60){
    displaymap(a);	/* 表示 */
    printf("turn: %d (O:%d, X:%d)\n", turn, cnt, turn + 4 - cnt); /* 現在の状態 */
    printf("%c x y>",symbol[c+1]); /* 入力を促すメッセージの表示 */
    if(c==1)
      scanf("%d %d",&x,&y); /* 入力 */
    else{
      cput(a,c,&x,&y);
      printf("%d %d\n",x,y);
    }
    
    if(a[x][y]==0) /* なにもおいていなかったら */
      for(dx=-1;dx<=1;dx++) /* 反転 */
        for(dy=-1;dy<=1;dy++)
          reverse(a, c, x+dx, y+dy, dx, dy, &g);
    if(g!=0){ /* 反転数が0以外だったら */
      a[x][y] = c; /* 駒を置く */
      cnt += c * g;  /* 反転数を用いて先手の駒数を更新 */
      if(c==1)/* 先手だったら置いた分も追加 */
        cnt++; 
      g=0; /* 反転数初期化 */
      turn++; /* 総ターン数更新 */
      c*=-1; /* 順番更新 */
    } else
      printf("Can't put it here\n");
  }
  return 0;
}
Пример #3
0
int main(int argc, char *argv[])
{
	char *p;
	int option;
	struct timespec result;
	unsigned long bytes;
	double duration, mbytes;
	struct bitmask *from;
	struct bitmask *to;

	pagesize = getpagesize();

	/* Command line processing */
	opterr = 1;
	cmd = argv[0];

	while ((option = getopt(argc, argv, optstr)) != EOF)
	switch (option) {
	case 'h' :
	case '?' :
		usage();
		break;
	case 'v' :
		verbose++;
		break;
	case 'p' :
		pages = strtoul(optarg, &p, 0);
		if (p == optarg || *p)
			usage();
		break;
	}

	if (!argv[optind])
		usage();

	if (verbose > 1)
		printf("numa_max_node = %d\n", numa_max_node());

	numa_exit_on_error = 1;

	from = numa_parse_nodestring(argv[optind]);
	if (!from) {
                printf ("<%s> is invalid\n", argv[optind]);
		exit(1);
	}
	if (errno) {
		perror("from mask");
		exit(1);
	}

	if (verbose)
		printmask("From", from);

	if (!argv[optind+1])
		usage();

	to = numa_parse_nodestring(argv[optind+1]);
	if (!to) {
                printf ("<%s> is invalid\n", argv[optind+1]);
		exit(1);
	}
	if (errno) {
		perror("to mask");
		exit(1);
	}

	if (verbose)
		printmask("To", to);

	bytes = pages * pagesize;

	if (verbose)
		printf("Allocating %lu pages of %lu bytes of memory\n",
				pages, pagesize);

	memory = memalign(pagesize, bytes);

	if (!memory) {
		printf("Out of Memory\n");
		exit(2);
	}

	if (mbind(memory, bytes, MPOL_BIND, from->maskp, from->size, 0) < 0)
		numa_error("mbind");

	if (verbose)
		printf("Dirtying memory....\n");

	for (p = memory; p <= memory + bytes; p += pagesize)
		*p = 1;

	if (verbose)
		printf("Starting test\n");

	displaymap();
	clock_gettime(CLOCK_REALTIME, &start);

	if (mbind(memory, bytes, MPOL_BIND, to->maskp, to->size, MPOL_MF_MOVE) <0)
		numa_error("memory move");

	clock_gettime(CLOCK_REALTIME, &end);
	displaymap();

	result.tv_sec = end.tv_sec - start.tv_sec;
	result.tv_nsec = end.tv_nsec - start.tv_nsec;

	if (result.tv_nsec < 0) {
		result.tv_sec--;
		result.tv_nsec += 1000000000;
	}

	if (result.tv_nsec >= 1000000000) {
		result.tv_sec++;
		result.tv_nsec -= 1000000000;
	}

	duration = result.tv_sec + result.tv_nsec / 1000000000.0;
	mbytes = bytes / (1024*1024.0);

	printf("%1.1f Mbyte migrated in %1.2f secs. %3.1f Mbytes/second\n",
			mbytes,
			duration,
			mbytes / duration);
	return 0;
}