Beispiel #1
0
/*!
 * @brief 様々な初期化設定を行う
 *
 * シグナルハンドラを設定し、画面を初期化する。<br>
 * また、ブロックを生成する。
 */
static void initialize(int sock) {
  uint i;

  sig_sock = sock;                   /* シグナルハンドラが参照できるように、グローバル変数にソケットを記憶 */
  signal(SIGINT, sig_handler);       /* シグナルハンドラの設定 */
  srand(gettimeofday_sec());         /* 乱数の種の設定 */
  initscr();                         /* 画面を初期化する */
  clear();
  cbreak();                          /* 入力をバッファに溜め込まないようにする */
  noecho();                          /* エコーバックを行わないようにする */
  fcntl(sock, F_SETFL, O_NONBLOCK);  /* sockからのread()をノンブロッキングに(リアルタイム処理を可能にする) */
  nodelay(stdscr, TRUE);             /* getch()をノンブロッキングに */
  print_labels();                    /* ラベルを描画する */

  /* 画面と壁を初期設定 */
  for (i = 0; i < STAGE_HEIGHT; i++) {
    uint j;
    for (j = 0; j < STAGE_WIDTH; j++) {
      if ((j == 0) || (j == STAGE_WIDTH - 1) || (i == STAGE_HEIGHT - 1)) {
        field[i][j] = stage[i][j] = WALL;
      } else {
        field[i][j] = stage[i][j] = SPACE;
      }
    }
  }
  create_block();                 /* 最初のブロック発生させる */
  show_field(field, MY_FIELD_X);  /* ゲーム直後の画面を描画 */
}
Beispiel #2
0
int main() {
  init_labels();
  init_sign_buffer(&sgn);
  init_congruence_table(&tbl, 1);

  build_composites();
  print_labels();
  print_composites(12);
  printf("\n");

  test_signatures(12);
  printf("\n");

  test_equalities(12);
  printf("\n");

  test_disjunctions(12);
  printf("\n");

  test_congruences(12);

  delete_composites(12);
  delete_congruence_table(&tbl);
  delete_sign_buffer(&sgn);

  return 0;
}
static  void    free_macro_entry_short( mac_entry * me )
{
    inp_line    *   ml;
    inp_line    *   mln;
    labelcb     *   cb;

    if( me != NULL ) {
        cb = me->label_cb;
        if( GlobalFlags.research ) {
            print_labels( cb, me->name );   // print label info
        }
        while( cb != NULL ) {
            me->label_cb = cb->prev;
            mem_free( cb );
            cb = me->label_cb;
        }
        ml = me->macline;
        while( ml != NULL ) {           // free all macro lines
            mln = ml->next;
            mem_free( ml );
            ml = mln;
        }
        mem_free( me );                 // now the entry itself
    }
    return;
}
Beispiel #4
0
void Grid::print_points() const {

	// check indexing:
	if (!check()) {
		print_labels();
		return;
	}

	for (unsigned int i = 0; i < gridSize(); i++) {

		// get index set:
		MultiIndexed::IndexSet is = i2x(i);

		// get Cartesian point:
		COORD_CART cp = getPoint(is);

		cout << "i = " << i << " --> ";
		for (unsigned int j = 0; j < cp.size(); j++) {
			cout << "x(" << j << ") = " << cp[j] << "  ";
		}

		cout << endl;
	}

}
Beispiel #5
0
void parse_args(int argc, char **argv)
{
	ckpt_op_num = num_labels - 1;
	ckpt_label = labels[ckpt_op_num];
	while (1) {
		int c;
		c = getopt_long(argc, argv, "f:LNhl:n:s:c:", long_options, NULL);
		if (c == -1)
			break;
		switch(c) {
			case 'f':
				freezer = optarg;
				break;
			case 'L':
				print_labels(stdout);
				exit(EXIT_SUCCESS);
				break;
			case 'N':
				printf("%d\n", num_labels - 1);
				exit(EXIT_SUCCESS);
				break;
			case 'h':
				usage(stdout);
				exit(EXIT_SUCCESS);
				break;
			case 'l':
				ckpt_label = optarg;
				break;
			case 'n':
				if ((sscanf(optarg, "%d", &ckpt_op_num) < 1) ||
				    (ckpt_op_num < 0) ||
				    (ckpt_op_num >= num_labels)) {
					fprintf(stderr, "Option -%c requires an argument in the range 0-%d. Got %d\n", c, num_labels - 1, ckpt_op_num);
					usage(stderr);
					exit(EXIT_FAILURE);
				}
				break;
			case 'c':
				if (sscanf(optarg, "%u", &num_efd) < 1) {
					fprintf(stderr, "Option -%c requires an argument in the range 1-INT_MAX. Got %d\n", c, num_efd);
					usage(stderr);
					exit(EXIT_FAILURE);
				}

				{
					/* rlimit restricts max fd */
					struct rlimit lim;
					getrlimit(RLIMIT_NOFILE, &lim);
					fprintf(stdout, "INFO: RLIMIT_NOFILE: soft (cur): %ld hard (max): %ld\n", lim.rlim_cur, lim.rlim_max);
					if ((unsigned int)num_efd >= lim.rlim_cur) {
						fprintf(stderr, "WARN: process is restricted from opening %d sockets. Opening %ld instead.\n", num_efd, lim.rlim_cur);
						num_efd = lim.rlim_cur;
					}
				}
				break;
			default: /* unknown option */
				break;
		}
	}
}
Beispiel #6
0
void
ofm_read_rest(void)
{
    retrieve_dimen_tables();
    if (verbose_option==TRUE) print_dimen_tables();
    retrieve_ligkern_table(ofm+(4*lig_kern_base), ofm+(4*kern_base));
    adjust_labels(FALSE);
    if (verbose_option==TRUE) print_labels();
    print_ligkern_table();
    retrieve_exten_table(ofm+(4*exten_base));
    if (verbose_option==TRUE) print_extens();
}
Beispiel #7
0
void parse_args(int argc, char **argv)
{
	ckpt_op_num = num_labels - 1;
	ckpt_label = labels[ckpt_op_num];
	while (1) {
		int c;
		c = getopt_long(argc, argv, "f:LNhl:n:c::", long_options, NULL);
		if (c == -1)
			break;
		switch(c) {
			case 'f':
				freezer = optarg;
				break;
			case 'L':
				print_labels(stdout);
				exit(EXIT_SUCCESS);
				break;
			case 'N':
				printf("%d\n", num_labels - 1);
				exit(EXIT_SUCCESS);
				break;
			case 'h':
				usage(stdout);
				exit(EXIT_SUCCESS);
				break;
			case 'l':
				ckpt_label = optarg;
				break;
			case 'n':
				if ((sscanf(optarg, "%d", &ckpt_op_num) < 1) ||
				    (ckpt_op_num < 0) ||
				    (ckpt_op_num >= num_labels)) {
					fprintf(stderr, "Option -n requires an argument in the range 0-%d. Got %d\n", num_labels - 1, ckpt_op_num);
					usage(stderr);
					exit(EXIT_FAILURE);
				}
				break;
			case 'c':
				if (optarg && (strlen(optarg) > 0))
					cgroup2 = strdup(optarg);
				else
					cgroup2 = "2";
				break;
			case '?':
				/* unkown option in optopt */
			default: /* unknown option */
				break;
		}
	}
}
Beispiel #8
0
void parse_args(int argc, char **argv)
{
	ckpt_op_num = num_labels - 1;
	ckpt_label = labels[ckpt_op_num];
	while (1) {
		char c;
		c = getopt_long(argc, argv, "LNhl:n:aiu", long_options, NULL);
		if (c == -1)
			break;
		switch(c) {
			case 'L':
				print_labels(stdout);
				exit(EXIT_SUCCESS);
				break;
			case 'N':
				printf("%d\n", num_labels - 1);
				exit(EXIT_SUCCESS);
				break;
			case 'h':
				usage(stdout, argv[0]);
				exit(EXIT_SUCCESS);
				break;
			case 'a':
				oflags |= O_APPEND;
				inode_flags |= FS_APPEND_FL;
				break;
			case 'i':
				inode_flags |= FS_IMMUTABLE_FL;
				break;
			case 'u':
				inode_flags |= FS_UNRM_FL;
				break;
			case 'l':
				ckpt_label = optarg;
				break;
			case 'n':
				if ((sscanf(optarg, "%d", &ckpt_op_num) < 1) ||
				    (ckpt_op_num < 0) ||
				    (ckpt_op_num >= num_labels)) {
					fprintf(stderr, "Option -n requires an argument in the range 0-%d. Got %d\n", num_labels - 1, ckpt_op_num);
					usage(stderr, argv[0]);
					exit(EXIT_FAILURE);
				}
				break;
			default: /* unknown option */
				break;
		}
	}
}
Beispiel #9
0
void usage(FILE *pout)
{
	fprintf(pout, "\nscm [-L] [-N] [-h|--help] [-l LABEL] [-n NUM]\n"
"Open a pipe and an epoll set. Pass them across a unix socket to an\n"
"'unrelated' task and test whether epoll retrieves events related to IO\n"
"on the pipe.\n"
"\t-L\tPrint the valid LABELs in order and exit.\n"
"\t-l\tWait for checkpoint at LABEL.\n"
"\t-N\tPrint the maximum label number and exit.\n"
"\t-n\tWait for checkpoint at NUM.\n"
"\n"
"You may only specify one LABEL or NUM and you may not specify both.\n"
"Label numbers are integers in the range 0-%d\n"
"Valid label numbers and their corresponding LABELs are:\n", num_labels - 1);
	print_labels(pout);
}
Beispiel #10
0
void usage(FILE *pout)
{
	fprintf(pout, "\ncycle [-L] [-N] [-h|--help] [-l LABEL] [-n NUM] [-c NUM]\n\n"
"Open several epoll sets and link them in a cycle.\n"
"This means that each successive epoll fd waits for events from another epoll\n"
"file descriptor. To test event propagation we also use a pipe in one epoll\n"
"set and do some IO with the pipe.\n"
"\n"
"\t-L\tPrint the valid LABELs in order and exit.\n"
"\t-l\tWait for checkpoint at LABEL.\n"
"\t-N\tPrint the maximum label number and exit.\n"
"\t-n\tWait for checkpoint at NUM.\n"
"\t-c\tCicumference of the epoll set cycle in NUM epoll fds.\n"
"\n"
"You may only specify one LABEL or NUM and you may not specify both.\n"
"Label numbers are integers in the range 0-%d\n"
"Valid label numbers and their corresponding LABELs are:\n", num_labels - 1);
	print_labels(pout);
}
Beispiel #11
0
void usage(FILE *pout, const char *prog)
{
	fprintf(pout, "\n%s [-L] [-N] [-h|--help] [-l LABEL] [-n NUM]\n"
"%s\n"
"\n"
"\t-L\tPrint the valid LABELs in order and exit.\n"
"\t-l\tWait for checkpoint at LABEL.\n"
"\t-N\tPrint the maximum label number and exit.\n"
"\t-n\tWait for checkpoint at NUM.\n"
"\t-a\tSet the append-only flag (extX filesystems, needs cap_linux_immutable).\n"
"\t-i\tSet the immutable flag (extX filesystems, needs cap_linux_immutable).\n"
"\t-u\tSet the undeleteable (recoverable) flag (extX filesystems).\n"
"\n"
"You may only specify one LABEL or NUM and you may not specify both.\n"
"Label numbers are integers in the range 0-%d\n"
"Valid label numbers and their corresponding LABELs are:\n", prog,
		descr, num_labels - 1);
	print_labels(pout);
}
Beispiel #12
0
void    free_macro_entry( mac_entry * * dict, mac_entry * me )
{
    inp_line    *   ml;
    inp_line    *   mln;
    mac_entry   *   wk;
    mac_entry   *   wkn;
    labelcb     *   cb;

    if( me != NULL ) {
        cb = me->label_cb;
        if( GlobalFlags.research ) {
            print_labels( cb, me->name );// print label info
        }
        while( cb != NULL ) {
            me->label_cb = cb->prev;
            mem_free( cb );
            cb = me->label_cb;
        }
        ml = me->macline;
        while( ml != NULL ) {           // free all macro lines
            mln = ml->next;
            mem_free( ml );
            ml = mln;
        }
        if( *dict == me ) {                // delete first entry
            *dict = me->next;
        } else {
            wk = *dict;
            while( wk != NULL ) {     // search the entry in macro dictionary
                wkn = wk->next;
                if( wkn == me ) {
                    wk->next = me->next;// chain update
                    break;
                }
                wk = wkn;
            }
        }
        mem_free( me );                 // now the entry itself
    }
    return;
}
Beispiel #13
0
void Grid::print_indices() const {

	// check indexing:
	if (!check()) {
		print_labels();
		return;
	}

	for (unsigned int i = 0; i < indexSize(); i++) {

		// get index set:
		MultiIndexed::IndexSet is = i2x(i);

		cout << "i = " << i << " --> ";
		for (unsigned int j = 0; j < is.size(); j++) {
			cout << "x(" << j << ") = " << is[j] << "  ";
		}
		cout << "---> i = " << x2i(is);
		cout << endl;
	}

}
Beispiel #14
0
void update_labels()
{
    if (verbose)
    {
        printf("About to update labels\n");
 
        print_S_T_sets();
        
        print_labels();
    }

    int x, y, delta = INF;             //init delta as infinity
    for (y = 0; y < n; y++)            //calculate delta using slack
    {
        if (!T[y])
        {
            //if (verbose)
            //    printf("delta = min(%d, %d) // doing y%d\n", delta, slack[y], y);
            
            delta = min(delta, slack[y]);
        }
    }

    if (verbose)
    {
        printf("New edges to be added will be to verts: { ");
        for (y = 0; y < n; y++)            //calculate delta using slack
        {
            if ((!T[y]) && (delta == slack[y]))
            {
                printf("y%d ", y);
            }
        }
        printf("}\n");


        // although delta is calculated efficiently using slack variables, 
        // it is just a calculation that satisfies:
        //  delta = min_{x,y} [ l(x) + l(y) - Cost(x,y) ] 
        //          where x \in S
        //          where y \in Y\T

        // We print this the long way

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if ((S[i]) && (!T[j]))
                {
                    printf("l(x%d) + l(y%d) - Cost(x%d, y%d) = %d + %d - %d = %d\n",
                                i, j, i, j, lx[i], ly[j], cost[i][j], lx[i] + ly[j] - cost[i][j]);
                }
            }
        }
        printf("min = %d\n", delta);
    }


    for (x = 0; x < n; x++)            //update X labels
        if (S[x]) lx[x] -= delta;
    for (y = 0; y < n; y++)            //update Y labels
        if (T[y]) ly[y] += delta;
    for (y = 0; y < n; y++)            //update slack array
        if (!T[y])
            slack[y] -= delta;

    if (verbose)
    {
        printf("Updated labels (delta = %d)\n", delta);



        print_labels();

        print_equality_subgraph();


    }
}