Exemple #1
0
 void log_main_init() {
     NBDEBUG("log_main_init()\n\t"
             "nbuffers=%i version=%i\n", NUM_LOG_BUFFERS, LOG_VERSION);
     
     main_upstart = time(NULL);
     
     bzero(fio_start, sizeof(io_state_t) * NUM_LOG_BUFFERS);
     bzero(cio_start, sizeof(io_state_t) * NUM_LOG_BUFFERS);
     bzero(total, sizeof(io_state_t) * NUM_LOG_BUFFERS);
     
     bzero(nlog_assoc, sizeof(int) * NUM_LOG_BUFFERS);
     
     bzero(&log_main, sizeof(log_main_t));
     
     for (int i = 0; i < NUM_LOG_BUFFERS; ++i) {
         log_main.buffers[i].objects = (Log **) malloc(LOG_BUFFER_SIZES[i] * sizeof(Log *));
         bzero(log_main.buffers[i].objects, LOG_BUFFER_SIZES[i] * sizeof(Log *));
         
         pthread_mutex_init(&(log_main.buffers[i].lock), NULL);
     }
     
     sanity_checks();
     
     pthread_create(&(log_main.log_main_thread), NULL, &log_main_loop, NULL);
     pthread_detach(log_main.log_main_thread);
     //server thread is live...
     
     log_running = true;
     NBDEBUG("log_main thread running...\n");
 }
Exemple #2
0
u8 init_simulation(command* cmd, simulation* sim, timer* t, ocrGuid_t** list)
{
  sim->step = 0;
  sim->steps = cmd->steps;
  sim->period = cmd->period;
  sim->dt = cmd->dt;
  sim->e_potential = 0.0;
  sim->e_kinetic = 0.0;

  u8 insane = 0;
  if(cmd->doeam)
    insane = init_eam(cmd->pot_dir, cmd->pot_name, cmd->pot_type, &sim->pot, sim->dt);
  else
    init_lj(&sim->pot, sim->dt);
  if(insane) return insane;

  real_t lattice_const = cmd->lat;
  if(cmd->lat < 0.0)
    lattice_const = sim->pot.lat;
  insane = sanity_checks(cmd, sim->pot.cutoff, lattice_const, sim->pot.lattice_type);
  if(insane) return insane;

  ocrGuid_t box_tmp;
  box** box_ptr = init_lattice(sim, cmd, lattice_const, list, &box_tmp);

  profile_start(redistribute_timer,t);
  redistribute_atoms(sim, box_ptr, sim->bxs.boxes_num);
  profile_stop(redistribute_timer,t);

  ocrDbDestroy(box_tmp);

  return 0;
}
Exemple #3
0
 void log_main_init() {
     LOGDEBUG(1, "log_main_init()\n");
     
     /*
      stats and flags
      */
     bzero( (uint8_t *) nbsf::flags, nbsf::num_flags);
     nbsf::flags[nbsf::servio] = true;
     nbsf::flags[nbsf::STATS] = true;
     
     nbsf::main_upstart = time(NULL);
     nbsf::sio_upstart = time(NULL);
     
     bzero(nbsf::fio_start, sizeof(nbsf::io_state_t) * NUM_LOG_BUFFERS);
     bzero(nbsf::cio_start, sizeof(nbsf::io_state_t) * NUM_LOG_BUFFERS);
     bzero(nbsf::total, sizeof(nbsf::io_state_t) * NUM_LOG_BUFFERS);
     
     bzero(log_main, sizeof(log_main_t));
     
     for (int i = 0; i < NUM_LOG_BUFFERS; ++i) {
         size_t buffer_size = sizeof(log_buffer_t) + LOG_BUFFER_SIZES[i] * sizeof(log_object_t *);
         log_main->buffers[i] = (log_buffer_t *) malloc(buffer_size);
         
         bzero(log_main->buffers[i], buffer_size);
         pthread_mutex_init(&(log_main->buffers[i]->lock), NULL);
     }
     
     sanity_checks();
     
     pthread_create(&(log_main->log_main_thread), NULL, &log_main_loop, NULL);
     pthread_detach(log_main->log_main_thread);
     //server thread is live...
     LOGDEBUG(1, "log_main thread running...\n");
 }
Exemple #4
0
/* This is called after options have been parsed, and partially
   processed.  */
void
cpp_post_options (cpp_reader *pfile)
{
  sanity_checks (pfile);

  post_options (pfile);

  /* Mark named operators before handling command line macros.  */
  if (CPP_OPTION (pfile, cplusplus) && CPP_OPTION (pfile, operator_names))
    mark_named_operators (pfile);
}
AIHTTPTimeoutPolicy::AIHTTPTimeoutPolicy(char const* name,
										 U16 dns_lookup_grace, U16 subsequent_connects, U16 reply_delay,
										 U16 low_speed_time, U32 low_speed_limit,
										 U16 curl_transaction, U16 total_delay) :
	mName(name),
	mBase(NULL),
	mDNSLookupGrace(dns_lookup_grace),
	mMaximumConnectTime(subsequent_connects),
	mMaximumReplyDelay(reply_delay),
	mLowSpeedTime(low_speed_time),
	mLowSpeedLimit(low_speed_limit),
	mMaximumCurlTransaction(curl_transaction),
	mMaximumTotalDelay(total_delay)
{
  sanity_checks();
}
Exemple #6
0
/* This is called after options have been parsed, and partially
   processed.  */
void
cpp_post_options (cpp_reader *pfile)
{
  int flags;

  sanity_checks (pfile);

  post_options (pfile);

  /* Mark named operators before handling command line macros.  */
  flags = 0;
  if (CPP_OPTION (pfile, cplusplus) && CPP_OPTION (pfile, operator_names))
    flags |= NODE_OPERATOR;
  if (CPP_OPTION (pfile, warn_cxx_operator_names))
    flags |= NODE_DIAGNOSTIC | NODE_WARN_OPERATOR;
  if (flags != 0)
    mark_named_operators (pfile, flags);
}
static int
filesystem(void)
{
    int i;
    char *partname;

    debconf_get(debconf, "partconf/partitions");
    if (strcmp(debconf->value, "Finish") == 0) {
        if (!sanity_checks())
            return 1; // will back up
        finish();
    }
    if (strcmp(debconf->value, "Abort") == 0)
        return -1;
    partname = strdup(debconf->value);
    curr_part = NULL;
    for (i = 0; i < part_count; i++) {
        //fprintf(stderr, "pname='%s', pdesc='%s'\n", partname, parts[i]->description);
        if (streqcomma(parts[i]->description, partname)) {
//        if (strstr(partname, parts[i]->description) == partname) {
            curr_part = parts[i];
            break;
        }
    }
    if (curr_part == NULL)
        return -1;
    if (curr_part->fstype != NULL) {
        curr_q = "partconf/existing-filesystem";
        debconf_subst(debconf, curr_q, "FSTYPE", curr_part->fstype);
        debconf_set(debconf, curr_q, "Leave the file system intact");
    } else
        curr_q = "partconf/create-filesystem";
    debconf_subst(debconf, curr_q, "FSCHOICES", fschoices);
    debconf_subst(debconf, curr_q, "PARTITION", curr_part->path);
    debconf_input(debconf, "critical", curr_q);
    return 0;
}
Exemple #8
0
void load_conf(void)
{
   FILE *fc;
   char line[128];
   char *p, *q, **tmp;
   int lineno = 0;
   size_t tmplen;
   struct conf_entry *curr_section = NULL;
   void *value = NULL;

   /* initialize the structures */
   init_structures();
   
   DEBUG_MSG("load_conf");
  
   /* the user has specified an alternative config file */
   if (GBL_CONF->file) {
      DEBUG_MSG("load_conf: alternative config: %s", GBL_CONF->file);
      fc = fopen(GBL_CONF->file, FOPEN_READ_TEXT);
      ON_ERROR(fc, NULL, "Cannot open %s", GBL_CONF->file);
   } else {
      /* errors are handled by the function */
      fc = open_data("etc", ETTER_CONF, FOPEN_READ_TEXT);
      ON_ERROR(fc, NULL, "Cannot open %s", ETTER_CONF);
   }
  
   /* read the file */
   while (fgets(line, 128, fc) != 0) {
      
      /* update the line count */
      lineno++;
      
      /* trim out the comments */
      if ((p = strchr(line, '#')))
         *p = '\0';
      
      /* trim out the new line */
      if ((p = strchr(line, '\n')))
         *p = '\0';

      q = line;
      
      /* trim the initial spaces */
      while (q < line + sizeof(line) && *q == ' ')
         q++;
      
      /* skip empty lines */
      if (line[0] == '\0' || *q == '\0')
         continue;
      
      /* here starts a new section [...] */
      if (*q == '[') {
         
         /* remove the square brackets */
         if ((p = strchr(line, ']')))
            *p = '\0';
         else
            FATAL_ERROR("Missing ] in %s line %d", ETTER_CONF, lineno);
         
         p = q + 1;
         
         DEBUG_MSG("load_conf: SECTION: %s", p);

         /* get the pointer to the right structure */
         if ( (curr_section = search_section(p)) == NULL)
            FATAL_ERROR("Invalid section in %s line %d", ETTER_CONF, lineno);
         
         /* read the next line */
         continue;
      }
   
      /* variable outside a section */
      if (curr_section == NULL)
         FATAL_ERROR("Entry outside a section in %s line %d", ETTER_CONF, lineno);
      
      /* sanity check */
      if (!strchr(q, '='))
         FATAL_ERROR("Parse error %s line %d", ETTER_CONF, lineno);
      
      p = q;

      /* split the entry name from the value */
      do {
         if (*p == ' ' || *p == '='){
            *p = '\0';
            break;
         }
      } while (p++ < line + sizeof(line) );
      
      /* move p to the value */
      p++;
      do {
         if (*p != ' ' && *p != '=')
            break;
      } while (p++ < line + sizeof(line) );
      
      /* 
       * if it is the "dissector" section,
       * do it in a different way
       */
      if (curr_section == (struct conf_entry *)&dissectors) {
         set_dissector(q, p, lineno);
         continue;
      }
     
      /* search the entry name */
      if ( (value = search_entry(curr_section, q)) == NULL)
         FATAL_ERROR("Invalid entry in %s line %d", ETTER_CONF, lineno);
   
      /* strings must be handled in a different way */
      if (curr_section == (struct conf_entry *)&strings) {
         /* trim the quotes */
         if (*p == '"')
            p++;
         
         /* set the string value */ 
         tmp = (char **)value;
         *tmp = strdup(p);
         
         /* trim the ending quotes */
         p = *tmp;
         tmplen = strlen(*tmp);
         do {
            if (*p == '"') {
               *p = 0;
               break;
            }
         } while (p++ < *tmp + tmplen );
         
         DEBUG_MSG("load_conf: \tENTRY: %s  [%s]", q, *tmp);
      } else {
         /* set the integer value */ 
         *(int *)value = strtol(p, (char **)NULL, 10);
         DEBUG_MSG("load_conf: \tENTRY: %s  %d", q, *(int *)value);
      }
   }

   sanity_checks();
   fclose(fc);
}
Exemple #9
0
int main(int argc, char *argv[]) {
    FILE *output;

    /* TODO fix this so that we can accept a log file */
    output = stdout;

    /* Prepare environment */
    initialize_buffer();
    initialize_card_arrs();

    fprintf(output, "Commencing testing of: %s\n\n", PROG_VER);

    fprintf(output, "%s\n\n", ". indicates success\nF indicates failure");

    /* Sanity checks */
    fprintf(output, "%s\n", "==== Sanity Checks ==========================");
    sanity_checks(output);
    fprintf(output, "%s", "\n");

    /* Log file detection */
    fprintf(output, "%s\n", "==== Log File Tests =========================");
    run_test(output, SELF_LOG);
    fprintf(output, "%s", "\n\n");

    /* Image file detection */
    fprintf(output, "%s\n", "==== Image File Tests =======================");
    run_test(output, IMAGE);
    fprintf(output, "%s", "\n\n");

    /* Binary file detection */
    fprintf(output, "%s\n", "==== Binary File Tests ======================");
    run_test(output, BINARY);
    fprintf(output, "%s", "\n\n");

    /* Image file detection */
    fprintf(output, "%s\n", "==== Default Separator Tests ================");
    run_test(output, SKIPCHARS);
    fprintf(output, "%s", "\n\n");

    /* Compressed files */
    fprintf(output, "%s\n", "==== Compressed files =======================");
    run_test(output, ZIP);
    fprintf(output, "%s", "\n\n");

    /* PDF files */
    fprintf(output, "%s\n", "==== PDF files ==============================");
    run_test(output, PDF);
    fprintf(output, "%s", "\n\n");

    /* .xlsx files */
    fprintf(output, "%s\n", "==== .xlsx files ============================");
    run_test(output, MS_EXCELX);
    fprintf(output, "%s", "\n\n");

    /* .docx files */
    fprintf(output, "%s\n", "==== .docx files ============================");
    run_test(output, MS_WORDX);
    fprintf(output, "%s", "\n\n");

    /* ODS files */
    fprintf(output, "%s\n", "==== ODS files ==============================");
    run_test(output, ODS);
    fprintf(output, "%s", "\n\n");

    /* ODT files */
    fprintf(output, "%s\n", "==== ODT files ==============================");
    run_test(output, ODT);
    return 0;
}
void check_test_tsaheylu(struct test_tsaheylu_data *data, unsigned int check)
{
	sanity_checks(check);

	check_value[check](data);
}
Exemple #11
0
int main(int argc, char *argv[])
	{
	precompute();
#ifdef USE_HASH
	hash_init();
#endif
	// load_endgames();
//	load_bitbases();
	if (argc == 2 && !strcmp(argv[1], "nobook"))
		{
		printf("Skipping opening book\n");
		}
	else if (argc == 2 && !strcmp(argv[1], "makebook"))
		{
		load_opening_book(1);
		opening_book_grow(0);
		return 0;
		}
	else if (argc == 2 && !strcmp(argv[1], "showbook"))
		{
		load_opening_book(1);
		opening_book_grow(1);
		return 0;
		}
	else
		load_opening_book(2);
	new_game();

	int ply;

	int i, j, k;

	FILE * input;
	FILE * output;

	char command[80] = "";
	char buffer[4100] = "";


/*	if (argc == 2 && !strcmp(argv[1], "files"))
		{
		printf("Using files for I/O\n");
		input = fopen("input.txt", "r+");
		output = fopen("output.txt", "w");
		}
	else */
		{
		input = stdin;
		output = stdout;
		}

	if (argc == 2 && !strcmp(argv[1], "bitbases"))
		{
		bitbase_report();
		return 0;
		}

	if (argc == 7 && !strcmp(argv[1], "position"))
		{
		i = bitbase_test(
			atoi(argv[2])
			,atoi(argv[3])
			,atoi(argv[4])
			,atoi(argv[5])
			,atoi(argv[6])
			);
		printf("%s\n", i ? "is a win for black" : "not a win for black");

		int pieces[MAX_BDB_PIECES];
		int total_pieces = 0;

		for (i = 0; i < atoi(argv[2]); ++i) pieces[total_pieces++] = 0;
		for (i = 0; i < atoi(argv[3]); ++i) pieces[total_pieces++] = 1;
		for (i = 0; i < atoi(argv[4]); ++i) pieces[total_pieces++] = 2;
		for (i = 0; i < atoi(argv[5]); ++i) pieces[total_pieces++] = 3;

		position_decode(atoi(argv[6]), pieces, total_pieces);

		print_board(0);

		return 0;
		}

	if (argc == 2 && !strcmp(argv[1], "sanity"))
		{
		sanity_checks();
		memory_report();
		return 0;
		}

	if (argc == 2 && !strcmp(argv[1], "perft"))
		{
		iterative_performance_test();
#ifdef SORT_STATISTIC
	for (i = 0; i < 5; ++i)
		printf("Returns at sort level %d: %d\n"
			, i
			, sort_statistic[i]);
#endif
		return 0;
		}

	if (argc >= 4 && !strcmp(argv[1], "pdn"))
		{
		ply = 0;

		FILE * pdn;

		pdn = fopen(argv[3], "a+");
		if (!pdn)
			{
			printf("error: fopen \"%s\" for append/create\n", argv[3]);
			// printf("err: %d - %s\n", errno, strerror(errno));
			// getcwd(buffer, sizeof(buffer));
			// printf("pwd: %s\n", buffer);
			return 1;
			}
		while (!feof(pdn)) // fixme: this loader sux...
			{
			if (!fgets(buffer, 4096, pdn))
				break;

			//if (!buffer || feof(pdn))
			//	break;

			i = 0;
			while (j = load_move_from_pdn(buffer, command, &i))
				{
				generate_moves(0, 0);
				k = find_move(0, command);
				if (k < 0 || k >= move_counter[0])
					{
					fprintf(output, "error invalid move from pdn (%s)\n"
						, command);
					for (k = 0; k < move_counter[0]; ++k)
						{
						fprintf(output, "move %d ",k);
						print_move(&moves[0][k], 0);
						fprintf(output, "\n");
						}
					}
				else
					{
					++ply;
					//fprintf(output, "executing move at index %d: ", k);
					if (!strcmp(argv[2], "show") || !strcmp(argv[2], "step"))
						{
						if (ply % 2 == 1)
							printf("%3d. ", (ply+1) / 2);
						print_move(&moves[0][k], 0);
						if (ply % 2 == 0)
							{
							printf("\n");
							//print_board(0);
							}
						else
							printf(" ");
						if (!strcmp(argv[2], "step") && ply % 2 == 0)
							{
							print_board(0);
							getc(stdin);
							}
						}
					//fprintf(output, "\n");
					move_do(&moves[0][k], 0);
					move_list_push(&moves[0][k]);
					}
				}
			if (feof(pdn))
				break;
			}
		fclose(pdn);

		if (!strcmp(argv[2], "play"))
			{
			pdn = fopen(argv[3], "a");
			if (!pdn)
				{
				printf("error: fopen \"%s\" for append\n", argv[3]);
				return 1;
				}

			if (argc >= 5 && strcmp(argv[4], "hint") && strcmp(argv[4], "move"))
				{
				generate_moves(0, 0);
				i = find_move(0, argv[4]);
				if (i < 0 || i >= move_counter[0])
					{
					print_moves(0);
					i = -1;
					}
				else
					{
					move_do(&moves[0][i], 0);
					move_list_push(&moves[0][i]);
					fprintf(pdn, "%s ", argv[4]);
					if (moves[0][i].same_player_square != -1)
						i = -1;
					}
				}

			if (i != -1)
				{
				if (argc >= 6)
					strength = atoi(argv[5]);
				if (argc >= 7)
					thinking_time = atoi(argv[6]);

				if (strength == 1)
					thinking_time = 1;

				if (!strcmp(argv[4], "hint"))
					bestmove(0, 0);
				else
					while (bestmove(pdn, 1));
				}

			fclose(pdn);
			fprintf(output, "boardok ");
			for (i = 0; i < 64; ++i)
				fprintf(output, "%d", board[i]);
			fprintf(output, " %d", state.tactical_square);
			fprintf(output, " %d", state.side_to_move);
			fprintf(output, " %d", state.this_piece_must_take);
			fprintf(output, "\n");
			}
		else
			{
			print_board(0);
//debug_moves = 1;
			generate_moves(0, 0);
			if (!strcmp(argv[2], "show"))
				print_moves(0);
			}

		if (!strcmp(argv[2], "load"))
			{
			printf("PDN loaded\n");
			command[0] = 0;
			buffer[0] = 0;
			}
		else
			return 0;
		}

	for (;;)
		{
		fscanf(input, "%20s", command);

		if (parse(command, "quit"))
			break;
		else if (parse(command, "gnt"))
			fprintf(output, "id name GNTredux\nid author QuakePhil\ngntok\n");
		else if (parse(command, "new"))
			new_game();
		else if (parse(command, "flipside"))
			state.side_to_move ^= 1;
		else if (parse(command, "flipkings"))
			{
			for (i = 0; i < 64; ++i) if (initial_board[i] != 4)
				{
				if (initial_board[i] < 2)
					initial_board[i] += 2;
				else
					initial_board[i] -= 2;
				}
			new_game();
			}
		else if (parse(command, "flipboardonly"))
			{ // fixme: need to re-do materials here?
			int temp[64];
			int flip_piece[5] = {1,0,3,2,4};
			j = 64;
			for (i = 0; i < 64; ++i)
				temp[--j] = flip_piece[board[i]];
			for (i = 0; i < 64; ++i)
				board[i] = temp[i];
			state.side_to_move ^= 1;
			}
		else if (parse(command, "rand"))
			rand_board();
		else if (parse(command, "think"))
			{
			bestmove(0, 0);
			}
		else if (parse(command, "go"))
			{
			bestmove(0, 1);
			}
		else if (parse(command, "perft"))
			{
			iterative_performance_test();
			}
		else if (parse(command, "ping"))
			{
			fprintf(output, "pong %.6lf\n", timer());
			}
		else if (parse(command, "pboard"))
			print_board(0);
		else if (parse(command, "board"))
			{
			fprintf(output, "boardok ");
			for (i = 0; i < 64; ++i)
				fprintf(output, "%d", board[i]);
			fprintf(output, " %d", state.tactical_square);
			fprintf(output, " %d", state.side_to_move);
			fprintf(output, " %d", state.this_piece_must_take);
			fprintf(output, "\n");
			}
		else if (parse(command, "time"))
			{
			fscanf(input, "%d", &thinking_time);
			printf("Think time limit set to: %d seconds\n", thinking_time);
			}
		else if (parse(command, "pdn"))
			{
			fscanf(input, "%20s", buffer);
			generate_moves(0, 0);
			i = find_move(0, buffer);
			if (i < 0 || i >= move_counter[0])
				fprintf(output, "error invalid move\n");
			else
				{
				move_do(&moves[0][i], 0);
				move_list_push(&moves[0][i]);
				//fprintf(output, "executing move at index %d: ", i);
				//print_move(&moves[0][i], 0);
				//fprintf(output, "\n");
				fprintf(output, "done\n");
				}
			}
		else if (parse(command, "do") || parse(command, "toggle"))
			{
			fscanf(input, "%d", &i);
			fprintf(output, "executing move %d\n", i);
			generate_moves(0, 0);
			if (i < 0)
				fprintf(output, "error move can't be negative\n");
			else if (i >= move_counter[0])
				fprintf(output, "error no such move\n");
			else
				{
				move_do(&moves[0][i], 0);
				move_list_push(&moves[0][i]);

				if (parse(command, "toggle"))
					{
					print_board(0);
					fprintf(output, "undoing move %d\n", i);
					move_undo(&moves[0][i], 0);
					print_board(0);
					}
				}
			fprintf(output, "done\n");
			}
		else if (parse(command, "list"))
			{
			print_move_list();
			}
		else if (parse(command, "pbook"))
			{
			print_book();
			}
		else if (parse(command, "moves"))
			{
			generate_moves(0, 0);
			for (i = 0; i < move_counter[0]; ++i)
				{
				fprintf(output, "move %d ",i);
				print_move(&moves[0][i], 1);
				fprintf(output, "\n");
				}
			fprintf(output, "movesok\n");
			}
		else // if (!strcmp(command, "help"))
			{
			// fprintf(output, "?\n");
			}

		fflush(output);
		}

#ifdef HASH_STATISTIC
	printf("Hash saves:      %d\n", hash_saves);
	printf("Hash collisions: %d\n", hash_collisions);
	printf("Hash probes:     %d\n", hash_probes);
	printf("Hash hits:       %d\n", hash_hits);
#endif

#ifdef SORT_STATISTIC
	for (i = 0; i < 5; ++i)
		printf("Returns at sort level %d: %d\n"
			, i
			, sort_statistic[i]);
#endif

	fclose(output);
	fclose(input);

	return 0;
	}