예제 #1
0
static void
get_options(int argc, char *argv[])
{
    int i;
    char *progname, *arg;

    progname = g_path_get_basename(argv[0]);

    for (i = 1; i < argc; i++) {
        arg = argv[i];

        if (strcmp(arg, "-v") == 0 ||
            strcmp(arg, "--version") == 0) {
            version(progname);
            exit(0);
        }
        else if (strcmp(arg, "-h") == 0 ||
                 strcmp(arg, "-?") == 0 ||
                 strcmp(arg, "--help") == 0) {
            usage(progname, TRUE, FALSE);
            exit(0);
        }
        else if (strcmp(arg, "--help-all") == 0) {
            usage(progname, TRUE, TRUE);
            exit(0);
        }
        else if (strcmp(arg, "--help-gtk") == 0) {
            usage(progname, FALSE, TRUE);
            exit(0);
        }
        else if (strcmp(arg, "-s") == 0 ||
            strcmp(arg, "--solve") == 0) {
            i++;
            if (i >= argc) {
                fprintf(stderr,
                        /* Error printed to stderr when user uses --solve argument without an equation */
                        _("Argument --solve requires an equation to solve"));
                fprintf(stderr, "\n");
                exit(1);
            }
            else
                solve(argv[i]);
        }
        else if (strcmp(arg, "-u") == 0 ||
            strcmp(arg, "--unittest") == 0) {
            unittest();
        }
        else {
            fprintf(stderr,
                    /* Error printed to stderr when user provides an unknown command-line argument */
                    _("Unknown argument '%s'"), arg);
            fprintf(stderr, "\n");
            usage(progname, TRUE, FALSE);
            exit(1);
        }
    }
}
예제 #2
0
파일: csp_main.c 프로젝트: kenkendk/dsmcbe
//This is the CommsTime CSP main function
int csp_thread_main()
{
	unsigned int pid;
	unsigned int processcount;

	unsigned int* tmp;

	CSP_SAFE_CALL("read processid", dsmcbe_csp_channel_read(PROCESS_COUNTER_GUID, NULL, (void**)&tmp));

	pid = (tmp[0])++;
	processcount = tmp[1];

	if (tmp[0] != tmp[1])
	{
		CSP_SAFE_CALL("write processid", dsmcbe_csp_channel_write(PROCESS_COUNTER_GUID, tmp));
	}
	else
	{
		CSP_SAFE_CALL("free processid", dsmcbe_csp_item_free(tmp));
	}

	unittest(pid);

	GUID readerChannel = CHANNEL_START_GUID + (pid % processcount);
	GUID writerChannel = CHANNEL_START_GUID + ((pid + 1) % processcount);

	CSP_SAFE_CALL("create start channel", dsmcbe_csp_channel_create(readerChannel, 0, CSP_CHANNEL_TYPE_ONE2ONE));

	int call_result;

	if (pid == 0)
		call_result = delta2(readerChannel, DELTA_CHANNEL, writerChannel);
	else if (pid == 1)
	{
		void* data;
		CSP_SAFE_CALL("create prefix value", dsmcbe_csp_item_create(&data, DATA_BLOCK_SIZE));
		call_result = prefix(readerChannel, writerChannel, data);
	}
	else
		call_result = delta1(readerChannel, writerChannel);

	if (call_result != CSP_CALL_POISON)
		printf("**** ERROR: poison is broken :(\n");

	CSP_SAFE_CALL("poison start channel", dsmcbe_csp_channel_poison(writerChannel));

	return CSP_CALL_SUCCESS;
}
예제 #3
0
int 
constants_test(void) {

  int passed = FALSE;

  if (unittest(tests)) {
     fprintf(stdout,"Passed constants_test\n");
     passed = TRUE;
  } else {
     fprintf(stdout,"Failed constants_test\n");
  }


  return passed;

}
예제 #4
0
파일: tests.cpp 프로젝트: hyp/arpha
void runTests(){
	//TODO
	const char* running = nullptr;

	unittest(Scope){
		auto scope = new Scope(0);

		assert(!scope->lookupPrefix("foo"));
		assert(!scope->lookupPrefix("bar"));
		assert(!scope->lookupInfix("bar"));
		assert(!scope->lookupInfix("foo"));
		assert(!scope->containsPrefix("foo"));
		assert(!scope->containsPrefix("bar"));
		assert(!scope->containsInfix("bar"));
		assert(!scope->containsInfix("foo"));

		delete scope;
	}

	unittest(_theEndDummy);
}
예제 #5
0
int main()
{
    //init();
#ifdef _DEBUG
    performance_test();
    unittest();
#endif

    int n = 0;
    printf("请输入要判断是否为素数的正整数:");
    scanf_s("%d", &n);

    int b = is_prime(n);
    if (b != 0)
    {
        printf("%d是素数\n", n);
    }
    else
    {
        printf("%d不是素数\n", n);
    }

    return 0;
}
예제 #6
0
파일: pachi.c 프로젝트: ChengDaHaI/pachi
int main(int argc, char *argv[])
{
	enum engine_id engine = E_UCT;
	struct time_info ti_default = { .period = TT_NULL };
	char *testfile = NULL;
	char *gtp_port = NULL;
	char *log_port = NULL;
	int gtp_sock = -1;
	char *chatfile = NULL;
	char *fbookfile = NULL;
	char *ruleset = NULL;

	seed = time(NULL) ^ getpid();

	int opt;
	while ((opt = getopt(argc, argv, "c:e:d:Df:g:l:r:s:t:u:")) != -1) {
		switch (opt) {
			case 'c':
				chatfile = strdup(optarg);
				break;
			case 'e':
				if (!strcasecmp(optarg, "random")) {
					engine = E_RANDOM;
				} else if (!strcasecmp(optarg, "replay")) {
					engine = E_REPLAY;
				} else if (!strcasecmp(optarg, "montecarlo")) {
					engine = E_MONTECARLO;
				} else if (!strcasecmp(optarg, "uct")) {
					engine = E_UCT;
				} else if (!strcasecmp(optarg, "distributed")) {
					engine = E_DISTRIBUTED;
				} else if (!strcasecmp(optarg, "patternscan")) {
					engine = E_PATTERNSCAN;
				} else if (!strcasecmp(optarg, "patternplay")) {
					engine = E_PATTERNPLAY;
				} else if (!strcasecmp(optarg, "joseki")) {
					engine = E_JOSEKI;
				} else {
					fprintf(stderr, "%s: Invalid -e argument %s\n", argv[0], optarg);
					exit(1);
				}
				break;
			case 'd':
				debug_level = atoi(optarg);
				break;
			case 'D':
				debug_boardprint = false;
				break;
			case 'f':
				fbookfile = strdup(optarg);
				break;
			case 'g':
				gtp_port = strdup(optarg);
				break;
			case 'l':
				log_port = strdup(optarg);
				break;
			case 'r':
				ruleset = strdup(optarg);
				break;
			case 's':
				seed = atoi(optarg);
				break;
			case 't':
				/* Time settings to follow; if specified,
				 * GTP time information is ignored. Useful
				 * e.g. when you want to force your bot to
				 * play weaker while giving the opponent
				 * reasonable time to play, or force play
				 * by number of simulations in timed games. */
				/* Please see timeinfo.h:time_parse()
				 * description for syntax details. */
				if (!time_parse(&ti_default, optarg)) {
					fprintf(stderr, "%s: Invalid -t argument %s\n", argv[0], optarg);
					exit(1);
				}
				ti_default.ignore_gtp = true;
				assert(ti_default.period != TT_NULL);
				break;
			case 'u':
				testfile = strdup(optarg);
				break;
			default: /* '?' */
				usage(argv[0]);
				exit(1);
		}
	}

	if (log_port)
		open_log_port(log_port);

	fast_srandom(seed);
	if (DEBUGL(0))
		fprintf(stderr, "Random seed: %d\n", seed);

	struct board *b = board_init(fbookfile);
	if (ruleset) {
		if (!board_set_rules(b, ruleset)) {
			fprintf(stderr, "Unknown ruleset: %s\n", ruleset);
			exit(1);
		}
	}

	struct time_info ti[S_MAX];
	ti[S_BLACK] = ti_default;
	ti[S_WHITE] = ti_default;

	chat_init(chatfile);

	char *e_arg = NULL;
	if (optind < argc)
		e_arg = argv[optind];
	struct engine *e = init_engine(engine, e_arg, b);

	if (testfile) {
		unittest(testfile);
		return 0;
	}

	if (gtp_port) {
		open_gtp_connection(&gtp_sock, gtp_port);
	}

	for (;;) {
		char buf[4096];
		while (fgets(buf, 4096, stdin)) {
			if (DEBUGL(1))
				fprintf(stderr, "IN: %s", buf);

			enum parse_code c = gtp_parse(b, e, ti, buf);
			if (c == P_ENGINE_RESET) {
				ti[S_BLACK] = ti_default;
				ti[S_WHITE] = ti_default;
				if (!e->keep_on_clear) {
					b->es = NULL;
					done_engine(e);
					e = init_engine(engine, e_arg, b);
				}
			} else if (c == P_UNKNOWN_COMMAND && gtp_port) {
				/* The gtp command is a weak identity check,
				 * close the connection with a wrong peer. */
				break;
			}
		}
		if (!gtp_port) break;
		open_gtp_connection(&gtp_sock, gtp_port);
	}
	done_engine(e);
	chat_done();
	free(testfile);
	free(gtp_port);
	free(log_port);
	free(chatfile);
	free(fbookfile);
	free(ruleset);
	return 0;
}