Example #1
0
//not used
container::container(char const *argv[])
{
	create_map();
	process_file(argv);
}
Example #2
0
config map_generator::create_scenario(const std::vector<std::string>& args)
{
	config res;
	res["map_data"] = create_map(args);
	return res;
}
Example #3
0
File: main.c Project: rzmz/GoSky
int main(int argc, char *argv[])
{

  int H,i;
  
  int para_R=0;
  int para_x=0;
  int para_y=0;
  int para_inte=0;
  char *fin=0;
  char *fout=0;
  char show_help=0;
  int isLoggingEnabled=0;

//Argumentide otsimine
  for(i=0; i<argc;i++){
	  if((strcmp(argv[i], "-R")==0) && ((i+1)<argc)){
  		  para_R=atoi(argv[i+1]);
  	  	  }
  	  else if((strcmp(argv[i], "-x")==0) && ((i+1)<argc)){
  		  para_x=atoi(argv[i+1]);
  	  	  }
  	  else if((strcmp(argv[i], "-y")==0) && ((i+1)<argc)){
  		  para_y=atoi(argv[i+1]);
  	  	  }
  	  else if((strcmp(argv[i], "-fin")==0) && ((i+1)<argc)){
  		fin=argv[i+1];
  	  	  }
  	  else if((strcmp(argv[i], "-fout")==0) && ((i+1)<argc)){
  		fout=argv[i+1];
  	  	  }
  	  else if((strcmp(argv[i], "-inte")==0) && ((i+1)<argc)){
  		para_inte=atoi(argv[i+1]);
  	  	  	  }
  	  else if((strcmp(argv[i], "-help")==0)){
  		show_help=1;
  	  	  }
  	  else if((strcmp(argv[i], "-log")==0)){
  		isLoggingEnabled=1;
  	  	  }
  	  else{
  		  //printf("Unknown parameter or missing argument: %s", argv[i]);
  	  	  }
  	  }

//Kui mõni argumentidest on olnud help, siis trüki see ja välju.
  if(show_help==1){
	  HELP();
	  return 0;
  	  }


//Kui Logimine on lubatud, siis tekitan logimise failid
  if(isLoggingEnabled){
  	init_error_log("ERROR.txt");
  	init_progress_log("PROGRESS.txt");
	}


/*
  printf("R %i\n", para_R);
  printf("x %i\n", para_x);
  printf("y %i\n", para_y);
  printf("intensity %i\n", para_inte);
  printf("Fin %s\n", fin);
  printf("Fout %s\n", fout);
*/

//Päris programm

  open_img(fin);
  
  //Antud funktsiooni sees toimub parameetrite korrigeerimine 
  DWPA_set_parameters(get_W(), get_H(), para_x, para_y, para_R, para_inte);
  //DWPA_set_parameters(get_W(), get_H(), para_R, 1 );
  H=DWPA_get_img_size();
  create_map(H, H);
  generate_image_from_map(fout);

  char str_msg[1024];
  sprintf(str_msg, "%s -> %s\n", fin, fout);
  write_progress_log(str_msg);

  close_error_log();
  close_progress_log();
  return 0;
}
Example #4
0
void union_comp_list_direct(comp_list_t *cl1, comp_list_t *cl2, unsigned short int n){
	char *map = create_map(cl1,n);
	union_comp_list(cl1,cl2,map);
	free(map);
}
Example #5
0
objVectorOop objVectorMap::create_objVector(slotList* slots) {
  objVectorOop ov;
  objVectorMap m1;
  (void)create_map(sizeof(objVectorMap), slots, &m1, (oop*)&ov);
  return ov;
}
Example #6
0
/* Size of the LRU map is 2*tgt_free
 * It is to test the active/inactive list rotation
 * Insert 1 to 2*tgt_free (+2*tgt_free keys)
 * Lookup key 1 to tgt_free*3/2
 * Add 1+2*tgt_free to tgt_free*5/2 (+tgt_free/2 keys)
 *  => key 1+tgt_free*3/2 to 2*tgt_free are removed from LRU
 */
static void test_lru_sanity3(int map_type, int map_flags, unsigned int tgt_free)
{
	unsigned long long key, end_key, value[nr_cpus];
	int lru_map_fd, expected_map_fd;
	unsigned int batch_size;
	unsigned int map_size;
	int next_cpu = 0;

	printf("%s (map_type:%d map_flags:0x%X): ", __func__, map_type,
	       map_flags);

	assert(sched_next_online(0, &next_cpu) != -1);

	batch_size = tgt_free / 2;
	assert(batch_size * 2 == tgt_free);

	map_size = tgt_free * 2;
	if (map_flags & BPF_F_NO_COMMON_LRU)
		lru_map_fd = create_map(map_type, map_flags,
					map_size * nr_cpus);
	else
		lru_map_fd = create_map(map_type, map_flags, map_size);
	assert(lru_map_fd != -1);

	expected_map_fd = create_map(BPF_MAP_TYPE_HASH, 0, map_size);
	assert(expected_map_fd != -1);

	value[0] = 1234;

	/* Insert 1 to 2*tgt_free (+2*tgt_free keys) */
	end_key = 1 + (2 * tgt_free);
	for (key = 1; key < end_key; key++)
		assert(!bpf_map_update_elem(lru_map_fd, &key, value,
					    BPF_NOEXIST));

	/* Lookup key 1 to tgt_free*3/2 */
	end_key = tgt_free + batch_size;
	for (key = 1; key < end_key; key++) {
		assert(!bpf_map_lookup_elem(lru_map_fd, &key, value));
		assert(!bpf_map_update_elem(expected_map_fd, &key, value,
				            BPF_NOEXIST));
	}

	/* Add 1+2*tgt_free to tgt_free*5/2
	 * (+tgt_free/2 keys)
	 */
	key = 2 * tgt_free + 1;
	end_key = key + batch_size;
	for (; key < end_key; key++) {
		assert(!bpf_map_update_elem(lru_map_fd, &key, value,
					    BPF_NOEXIST));
		assert(!bpf_map_update_elem(expected_map_fd, &key, value,
				            BPF_NOEXIST));
	}

	assert(map_equal(lru_map_fd, expected_map_fd));

	close(expected_map_fd);
	close(lru_map_fd);

	printf("Pass\n");
}
Example #7
0
int sp_map_rehash(map **incmap) {
   
   map *themap = *incmap;     /* another level of indirection */
	map *pnewmap = NULL;		      /* the bigger map */ 
	kvpair *curr=NULL,*prev=NULL;
	bucket *bucketptr=NULL;
   status code;
	long i=0;

#ifdef DEBUG
   printf("*********************************************************************************************\n");
	printf("DEBUG: enter sp_map_rehash - map size %lu, bucketsize %lu, bucketsused %lu\n",themap->size, themap->bucketsize,themap->bucketsused); 
#endif
   pnewmap = (map*)malloc(sizeof(map)); /* allocate memory for the new map */
	
   code = create_map(&pnewmap, themap->type, nextprobableprime((themap->bucketsize) * (themap->resize_factor)), themap->resize_factor, themap->load_factor);
	
	bucketptr = themap->start;

	for(i=0;i<themap->bucketsize;i++) {
		if((bucketptr->start) == NULL) {
			bucketptr++;
			continue; 	/* no kvpairs at this hashcode */

#ifdef DEBUG
			printf("DEBUG: sp_map_rehash - ** no kvpairs at this hashcode, continue **\n");
#endif

		}
		else {
			curr = bucketptr->start; /* set curr to the first kvpair */
			while(curr!=NULL) { /* now iterate through all kvpairs at this hashcode */

#ifdef DEBUG
	printf("DEBUG: putting key: %s value: %s into new map\n",(char*)curr->key,(char*)curr->value);
#endif

				kv_put(&pnewmap, (void*)curr->key, (void*)curr->value); /* put the key value pair into the new map */
				prev = curr;
				curr = curr->next;
				if((prev->key)!=NULL) 
			   	free((void*)prev->key);
				prev->key = NULL;
				
				if((prev->value)!=NULL)	
					free((void*)prev->value);
				prev->value = NULL;
				
            if(prev!=NULL)
               free((void*)prev);
            prev = NULL; /* old kvpair is free */

			}
		}
		bucketptr++;
	}
	
	if(themap->start!=NULL)
		free((void*)themap->start); /* free the buckets in the old map */
	themap->start = NULL;
 
   if(themap!=NULL) 
      free((void*)themap);    /* old map is now free */ 
   themap = NULL; 

   *incmap = pnewmap;         /* set the dereferenced map pointer passed in to the new map */

#ifdef DEBUG
   printf("DEBUG: leave sp_map_rehash - new map size: %lu, bucketsused: %lu, currentload: %f, loadfactor: %f bucketsize: %lu\n",(*incmap)->size,(*incmap)->bucketsused,(*incmap)->currentload,(*incmap)->load_factor,(*incmap)->bucketsize);
   printf("*******************************************************************************************************************\n");
#endif

   return SUCCESS;
}
Example #8
0
int main(int argc, char *argv[])
{
    const char *input, *source, *output;
    char *title;
    struct Cell_head cellhd;
    GDALDatasetH hDS;
    GDALRasterBandH hBand;
    struct GModule *module;
    struct {
	struct Option *input, *source, *output, *band, *title;
    } parm;
    struct {
	struct Flag *o, *f, *e, *h, *v, *t;
    } flag;
    int min_band, max_band, band;
    struct band_info info;
    int flip;
    struct Ref reference;

    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("raster"));
    G_add_keyword(_("import"));
    G_add_keyword(_("external"));
    module->description =
	_("Links GDAL supported raster data as a pseudo GRASS raster map.");

    parm.input = G_define_standard_option(G_OPT_F_INPUT);
    parm.input->description = _("Name of raster file to be linked");
    parm.input->required = NO;
    parm.input->guisection = _("Input");

    parm.source = G_define_option();
    parm.source->key = "source";
    parm.source->description = _("Name of non-file GDAL data source");
    parm.source->required = NO;
    parm.source->type = TYPE_STRING;
    parm.source->key_desc = "name";
    parm.source->guisection = _("Input");
    
    parm.output = G_define_standard_option(G_OPT_R_OUTPUT);
    
    parm.band = G_define_option();
    parm.band->key = "band";
    parm.band->type = TYPE_INTEGER;
    parm.band->required = NO;
    parm.band->description = _("Band to select (default is all bands)");
    parm.band->guisection = _("Input");

    parm.title = G_define_option();
    parm.title->key = "title";
    parm.title->key_desc = "phrase";
    parm.title->type = TYPE_STRING;
    parm.title->required = NO;
    parm.title->description = _("Title for resultant raster map");
    parm.title->guisection = _("Metadata");

    flag.f = G_define_flag();
    flag.f->key = 'f';
    flag.f->description = _("List supported formats and exit");
    flag.f->guisection = _("Print");
    flag.f->suppress_required = YES;

    flag.o = G_define_flag();
    flag.o->key = 'o';
    flag.o->label =
	_("Override projection check (use current location's projection)");
    flag.o->description =
	_("Assume that the dataset has same projection as the current location");

    flag.e = G_define_flag();
    flag.e->key = 'e';
    flag.e->label = _("Extend region extents based on new dataset");
    flag.e->description = _("Also updates the default region if in the PERMANENT mapset");

    flag.h = G_define_flag();
    flag.h->key = 'h';
    flag.h->description = _("Flip horizontally");

    flag.v = G_define_flag();
    flag.v->key = 'v';
    flag.v->description = _("Flip vertically");

    flag.t = G_define_flag();
    flag.t->key = 't';
    flag.t->label =
        _("List available bands including band type in dataset and exit");
    flag.t->description = _("Format: band number,type,projection check");
    flag.t->guisection = _("Print");
    flag.t->suppress_required = YES;

    if (G_parser(argc, argv))
	exit(EXIT_FAILURE);

    GDALAllRegister();

    if (flag.f->answer) {
	list_formats();
	exit(EXIT_SUCCESS);
    }

    input = parm.input->answer;
    source = parm.source->answer;
    output = parm.output->answer;

    flip = 0;
    if (flag.h->answer)
	flip |= FLIP_H;
    if (flag.v->answer)
	flip |= FLIP_V;

    if (parm.title->answer) {
	title = G_store(parm.title->answer);
	G_strip(title);
    }
    else
	title = NULL;

    if (!input && !source)
	G_fatal_error(_("%s= or %s= must be given"),
		      parm.input->key, parm.source->key);

    if (input && source)
	G_fatal_error(_("%s= and %s= are mutually exclusive"),
		      parm.input->key, parm.source->key);
    
    if (input && !G_is_absolute_path(input)) {
	char path[GPATH_MAX], *cwd;
	cwd = CPLGetCurrentDir();
	if (!cwd)
	    G_fatal_error(_("Unable to get current working directory"));
	
	G_snprintf(path, GPATH_MAX, "%s%c%s", cwd, HOST_DIRSEP, input);
	input = G_store(path);
	CPLFree(cwd);
    }

    if (!input)
	input = source;

    hDS = GDALOpen(input, GA_ReadOnly);
    if (hDS == NULL)
	return 1;

    setup_window(&cellhd, hDS, &flip);

    if (flag.t->answer) {
        list_bands(&cellhd, hDS);
        /* close the GDALDataset to avoid segfault in libgdal */
        GDALClose(hDS);
        exit(EXIT_SUCCESS);
    }

    check_projection(&cellhd, hDS, flag.o->answer);

    Rast_set_window(&cellhd);

    if (parm.band->answer)
	min_band = max_band = atoi(parm.band->answer);
    else
	min_band = 1, max_band = GDALGetRasterCount(hDS);

    G_verbose_message(_("Proceeding with import..."));

    if (max_band > min_band) {
	if (I_find_group(output) == 1)
	    G_warning(_("Imagery group <%s> already exists and will be overwritten."), output);
	I_init_group_ref(&reference);
    }

    for (band = min_band; band <= max_band; band++) {
	char *output2, *title2 = NULL;

	G_message(_("Reading band %d of %d..."),
		  band, GDALGetRasterCount( hDS ));

	hBand = GDALGetRasterBand(hDS, band);
	if (!hBand)
	    G_fatal_error(_("Selected band (%d) does not exist"), band);

	if (max_band > min_band) {
	    G_asprintf(&output2, "%s.%d", output, band);
	    if (title)
		G_asprintf(&title2, "%s (band %d)", title, band);
	    G_debug(1, "Adding raster map <%s> to group <%s>", output2, output);
	    I_add_file_to_group_ref(output2, G_mapset(), &reference);
	}
	else {
	    output2 = G_store(output);
	    if (title)
		title2 = G_store(title);
	}

	query_band(hBand, output2, &cellhd, &info);
	create_map(input, band, output2, &cellhd, &info, title, flip);

	G_free(output2);
	G_free(title2);
    }

    /* close the GDALDataset to avoid segfault in libgdal */
    GDALClose(hDS);

    if (flag.e->answer)
	update_default_window(&cellhd);

    /* Create the imagery group if multiple bands are imported */
    if (max_band > min_band) {
    	I_put_group_ref(output, &reference);
	I_put_group(output);
	G_message(_("Imagery group <%s> created"), output);
    }

    exit(EXIT_SUCCESS);
}
Example #9
0
config map_generator::create_scenario(boost::optional<boost::uint32_t> randomseed)
{
    config res;
    res["map_data"] = create_map(randomseed);
    return res;
}
Example #10
0
/**************************************************
*
*   FUNCTION:
*       init_symbol_table - "Initialize Symbol
*                            Table"
*
*   DESCRIPTION:
*       This initializes the symbol table.
*
*   ERRORS:
*       * Returns SYM_NO_ERROR if there were
*         no errors
*       * Returns SYM_ALREADY_INITIALIZED if
*         the symbol table has already been
*         initialized
*       * Returns SYM_INIT_ERROR if there was
*         an error encountered while either
*         creating or initializing the symbol
*         table
*       * Returns SYM_INIT_ADD_ERROR if there
*         was an error when adding the different
*         symbols to the table.
*
**************************************************/
sym_table_error_t8 init_symbol_table
(
    void
)
{
    /*---------------------------------
    Local variables
    ---------------------------------*/
    uint32  i;          /* a for-loop iterator      */
    sint    table_size; /* size of the table        */

    /*---------------------------------
    Check if the table is already
    initialized
    ---------------------------------*/
    if( NULL != __keyword_table )
    {
        return( SYM_ALREADY_INITIALIZED );
    }

    /*---------------------------------
    Create and initialize the keyword
    table
    ---------------------------------*/
    table_size = (sint)ceil( 0.5 * (double)( size( __keywords ) ) );
    __keyword_table = create_map();
    if( NULL == __keyword_table )
    {
        return( SYM_INIT_ERROR );
    }

    if( ERR_NO_ERROR != init_static_map( __keyword_table,
                                         table_size      ) )
    {
        return( SYM_INIT_ERROR );
    }

    /*---------------------------------
    Create and initialize the
    identifier table
    ---------------------------------*/
    __id_table = create_map();
    if( NULL == __id_table )
    {
        return( SYM_INIT_ERROR );
    }

    if( ERR_NO_ERROR != init_static_map( __id_table, 0 ) )
    {
        return( SYM_INIT_ERROR );
    }

    /*---------------------------------
    Add all of the keywords in the
    giant table somewhere above
    ---------------------------------*/
    for( i = 0; i < size( __keywords ); ++i )
    {
        if( 0 == add_map (  __keyword_table,
                            __keywords[ i ].word,
                           &__keywords[ i ].tok,
                            sizeof( struct token_type ) ) )
        {
            return( SYM_INIT_ADD_ERROR );
        }
    }

    return( SYM_NO_ERROR );

}   /* init_symbol_table() */
Example #11
0
	void VertexBest::localSearch(
		const std::vector<Graph> &graphs,
		Solution &solution
	) {
		size_t m = solution.alignment.size1();
		size_t n = solution.alignment.size2();

		// Create reverse alignment mapping
		std::vector<std::vector<size_t>> map;
		create_map(graphs, solution, map);

		// Count number of graphs each edge is covered in
		edge_count_matrix edges;
		count_edges(graphs, map, solution, edges);

		// Build neighbor lists
		std::vector<neighbor_list> neighbors;
		create_neighbor_lists(graphs, map, solution, neighbors);

		// Active index map
		std::vector<int> active(m, 0);

		int iteration = 0;
		bool repeat;

		do {
			repeat = false;

			for(size_t g = 0; g < n-1; ++g) {
				for(size_t i = 0; i < m; ++i) {
					int best_delta = 0;
					size_t best_j = 0;

					#pragma omp parallel
					{
						int prv_best_delta = 0;
						size_t prv_best_j = 0;

						#pragma omp for schedule(static)
						for(size_t j = i+1; j < m; ++j) {
							if(active[i] < iteration && active[j] < iteration) continue;

							int delta = get_delta(i, j, g, neighbors, edges);

							if(delta > prv_best_delta) {
								prv_best_delta = delta;
								prv_best_j = j;
							}
						}

						#pragma omp critical
						{
							if(prv_best_delta > best_delta) {
								best_delta = prv_best_delta;
								best_j = prv_best_j;
							}
						}
					}

					if(best_delta > 0) {
						repeat = true;
						swap(i, best_j, g, iteration, neighbors, edges, solution, active);
					}
				}
			}

			iteration++;
		} while(repeat);

		// Extract LCS and solution quality
		finalize(edges, solution);
	}
Example #12
0
void custom_map(char* mapz)
{
	int i, rez;
	int br, phase = 1, lastKey = 5;
	long int random_element_gen = 0;
	unsigned long int random_pup_gen = 0;
	unsigned short mm = 0, pp = 0;
	clock_t start_lvl_time = clock(), pw_shield_start, pw_clock_start, pw_shovel_start;
	Levels tank_struct;
	br = 0;
	HIGH_SCORE=0;
	lst->first = NULL;
	lst->curr = NULL;
	lst->last = NULL;
	lst->n = 0;
	Plst->first = NULL;
	Plst->last = NULL;
	init_powerups();
	create_map(mapz, 2);
	tank_struct.kind = -1;
	tank_struct.smart = 0;
	LVL = 0;
	//link_levels();
	print_border_side_menu(2, x1m, 25, x2m, 3); // bots left.
	print_bots_left(); // saljes tezinu izabranu u podesavanjima( Easy-0 medium-1 hard-2) LVL(koji je nivo).  NOVO!
	print_border_side_menu(47, x1m + 20, 56, x2m, 4);// high score counter. // changed coordinates-Andrija // sve spusteno za 21
	print_border_side_menu(58, x1m, 67, x2m, 4); // pw disclaimer.
	print_menu_pups(61);
	alloc_tank(0, tank_struct);
	attron(COLOR_PAIR(1));
	mvaddstr(68,40,"ESC TO PAUSE");
	attroff(COLOR_PAIR(1));
	while (1){
		time_now();
		print_high_score();
		random_element_gen++;
		if (random_element_gen == 280000) random_element_gen = 0, rand_gen();
		execute_powerups(&pw_shield_start, &pw_clock_start, &pw_shovel_start, &random_pup_gen);
		should_spawn_bot(&start_lvl_time, &rez, &br, LVL);
		if (_kbhit())
			execute_our_tank(&mm, &pp, &phase, &lastKey, start_lvl_time, br, 0);
		execute_bots(1);
		if (lst->n == 1 && br >= botsInLevel[BOT_DIF][LVL]) { 
			create_map("win.map",0);
			Sleep(2500); 
			clear();
			free_tank(lst->first);
			delete_powerup_list();
			demo_mode();
		return;
		}
		if ((!powerup.life) || (!strcmp(map_name, "gameover.map")) || (!strcmp(map_name, "gohardorgohome.map")) )
		{
			clear();
			delete_tank_list();
			delete_powerup_list();
			demo_mode();
			return;
		}
	}
}
Example #13
0
namespace dpen {


std::map<DPBlockDefinition::BlockCode,DPBlockDefinition> create_map()
{
    std::map<DPBlockDefinition::BlockCode,DPBlockDefinition> m;
    m[DPBlockDefinition::DP_BLOCK_LAYER_START]  = DPBlockDefinition(0xF1, 0x03, 0x80, true, DPBlockDefinition::DP_BLOCK_LAYER_START,    "Layer Start      :", false);
    m[DPBlockDefinition::DP_BLOCK_TRACE_START] = DPBlockDefinition(0xF1, 0x03, 0x01, true, DPBlockDefinition::DP_BLOCK_TRACE_START,   "Trace Start     :", false);
    m[DPBlockDefinition::DP_BLOCK_TRACE_END]   = DPBlockDefinition(0xF1, 0x03, 0x00, true, DPBlockDefinition::DP_BLOCK_TRACE_END,     "Stroke End       :", false);

    m[DPBlockDefinition::DP_BLOCK_PEN_POSITION] = DPBlockDefinition(0x61, 0x06, 0x00, false, DPBlockDefinition::DP_BLOCK_PEN_POSITION,  "Position         :", false);
    m[DPBlockDefinition::DP_BLOCK_PEN_TILT]     = DPBlockDefinition(0x65, 0x06, 0x00, false, DPBlockDefinition::DP_BLOCK_PEN_TILT,      "Tilt             :", false);
    m[DPBlockDefinition::DP_BLOCK_PEN_PRESSURE] = DPBlockDefinition(0x64, 0x06, 0x00, false, DPBlockDefinition::DP_BLOCK_PEN_PRESSURE,  "Pressure         :", false);

    m[DPBlockDefinition::DP_BLOCK_CLOCK_COUNTER] = DPBlockDefinition(0xC2, 0x06, 0x11, true, DPBlockDefinition::DP_BLOCK_CLOCK_COUNTER, "Clock Counter    :", false);
    m[DPBlockDefinition::DP_BLOCK_CLOCK_UNKNOWN] = DPBlockDefinition(0xC2, 0x06, 0x12, true, DPBlockDefinition::DP_BLOCK_CLOCK_UNKNOWN, "Clock (?)        :", false);
    m[DPBlockDefinition::DP_BLOCK_CLOCK_INIT]    = DPBlockDefinition(0xC2, 0x06, 0x00, true, DPBlockDefinition::DP_BLOCK_CLOCK_INIT,    "Clock Init (?)   :", false);

    m[DPBlockDefinition::DP_BLOCK_C5]    = DPBlockDefinition(0xC5, 0x13, 0x00, false, DPBlockDefinition::DP_BLOCK_C5,     "0xC5 (?)         :", false);

    m[DPBlockDefinition::DP_BLOCK_C7_INTERFERENCE] = DPBlockDefinition(0xC7, 0x0E, 0x00, false, DPBlockDefinition::DP_BLOCK_C7_INTERFERENCE,
                                                                       "Interference     :", false);
    m[DPBlockDefinition::DP_BLOCK_C7_1E] = DPBlockDefinition(0xC7, 0x1E, 0x00, false, DPBlockDefinition::DP_BLOCK_C7_1E,  "0xC7-0x1E (?)    :", true);
    m[DPBlockDefinition::DP_BLOCK_C7_1A] = DPBlockDefinition(0xC7, 0x1A, 0x00, false, DPBlockDefinition::DP_BLOCK_C7_1A,  "0xC7-0x1A (?)    :", false);
    m[DPBlockDefinition::DP_BLOCK_C7_16] = DPBlockDefinition(0xC7, 0x16, 0x00, false, DPBlockDefinition::DP_BLOCK_C7_16,  "0xC7-0x16 (?)    :", false);
    m[DPBlockDefinition::DP_BLOCK_C7_22] = DPBlockDefinition(0xC7, 0x22, 0x00, false, DPBlockDefinition::DP_BLOCK_C7_22,  "0xC7-0x22 (?)    :", false);
    return m;
}


std::map<DPBlockDefinition::BlockCode,DPBlockDefinition> DPBlockDefinition::blockEventMap = create_map();


bool DPBlockDefinition::dumpDebugCounts()
{
    std::map<DPBlockDefinition::BlockCode,DPBlockDefinition>::const_iterator iter = DPBlockDefinition::blockEventMap.begin();

    std::cout << "--------------DEBUG COUNTS--------------" << std::endl;
    while (iter != blockEventMap.end())
    {
        std::cout << (*iter).second.getName() << " " << (*iter).second.getCount() << std::endl;
        ++iter;
    }
}


bool DPBlockDefinition::resetDebugCounts()
{
    std::map<DPBlockDefinition::BlockCode,DPBlockDefinition>::iterator iter = DPBlockDefinition::blockEventMap.begin();

    while (iter != blockEventMap.end())
    {
        (*iter).second.resetCount();
        ++iter;
    }
}

bool DPBlockDefinition::matchEventBlock(std::vector<unsigned char>& buf,
                                        std::size_t i,
                                        DPBlockDefinition::BlockCode& blockCode)
{
    std::size_t bufRemaining = buf.size() - i;
    blockCode = DPBlockDefinition::DP_BLOCK_UNKNOWN;

    if (bufRemaining <= 0)
    {
        DPLogError("Trying to read, but buffer empty.");
        return false;
    }

    std::map<DPBlockDefinition::BlockCode,DPBlockDefinition>::const_iterator iter = blockEventMap.begin();

    for (;iter != blockEventMap.end();++iter)
    {
        if (buf[i] == (*iter).second.getBlockStart())
        {
            if (bufRemaining > 1 && buf[i+1] == (*iter).second.getBlockLength())
            {
                if (bufRemaining >= buf[i+1])
                {
                    if ((*iter).second.getBlockIdMustMatch())
                    {
                        if ((*iter).second.getBlockId() == buf[i+2])
                        {
                            // matched the blockid
                            blockCode = (*iter).second.getBlockCode();
                            return true;
                        }
                        else
                        {
                            continue; // no match
                        }
                    }
                    else
                    {
                        // didn't need to match the block id
                        blockCode = (*iter).second.getBlockCode();
                        return true;
                    }
                }
                else
                {
                    DPLogError("Trying to read, but there are not enough bytes left in the buffer to read this entire block.");
                    return false;
                }
            }
        }
    }

    return true;
}

bool DPBlockDefinition::hasBlockCode(const DPBlockDefinition::BlockCode& code)
{
    return blockEventMap.find(code) != DPBlockDefinition::blockEventMap.end();
}

bool DPBlockDefinition::getELIBlockDef(const DPBlockDefinition::BlockCode& code,
                                       DPBlockDefinition& def)
{
    std::map<DPBlockDefinition::BlockCode,DPBlockDefinition>::iterator iter = blockEventMap.find(code);

    if (iter != blockEventMap.end())
    {
        def = (*iter).second;
        
        return true;
    }
    else
    {
        return false;
    }
}


} // namespace dpen
{
	OutputDebugString( StdStringFormat("MtcOpcAdapter trans_func - Code = 0x%x\n",  
		pExp->ExceptionRecord->ExceptionCode).c_str() );
	throw std::exception();
}

static std::map<std::string, Condition::ELevels> create_map() 
{   
	std::map<std::string,Condition::ELevels> m;   
	m["UNAVAILABLE"] =  Condition::eUNAVAILABLE;
	m["NORMAL"] =  Condition::eNORMAL;
	m["WARNING"] =  Condition::eWARNING;
	m["FAULT"] =  Condition::eFAULT;
	return m; 
}  
std::map<std::string,Condition::ELevels> LevelMap = create_map(); 

//////////////////////////////////////////////////////////////////////////////////////////



MtcOpcAdapter::MtcOpcAdapter(int aPort)
: Adapter(aPort, 1000),
mAvailability("avail")
{
	addDatum(mAvailability);
	_bResetAtMidnight=false;	  
	_bRunning=false;
	_bOPCEnabled=false; 
}
Example #15
0
/* Size of the LRU map is 1.5*tgt_free
 * Insert 1 to tgt_free (+tgt_free keys)
 * Lookup 1 to tgt_free/2
 * Insert 1+tgt_free to 2*tgt_free (+tgt_free keys)
 * => 1+tgt_free/2 to LOCALFREE_TARGET will be removed by LRU
 */
static void test_lru_sanity1(int map_type, int map_flags, unsigned int tgt_free)
{
	unsigned long long key, end_key, value[nr_cpus];
	int lru_map_fd, expected_map_fd;
	unsigned int batch_size;
	unsigned int map_size;
	int next_cpu = 0;

	if (map_flags & BPF_F_NO_COMMON_LRU)
		/* Ther percpu lru list (i.e each cpu has its own LRU
		 * list) does not have a local free list.  Hence,
		 * it will only free old nodes till there is no free
		 * from the LRU list.  Hence, this test does not apply
		 * to BPF_F_NO_COMMON_LRU
		 */
		return;

	printf("%s (map_type:%d map_flags:0x%X): ", __func__, map_type,
	       map_flags);

	assert(sched_next_online(0, &next_cpu) != -1);

	batch_size = tgt_free / 2;
	assert(batch_size * 2 == tgt_free);

	map_size = tgt_free + batch_size;
	lru_map_fd = create_map(map_type, map_flags, map_size);
	assert(lru_map_fd != -1);

	expected_map_fd = create_map(BPF_MAP_TYPE_HASH, 0, map_size);
	assert(expected_map_fd != -1);

	value[0] = 1234;

	/* Insert 1 to tgt_free (+tgt_free keys) */
	end_key = 1 + tgt_free;
	for (key = 1; key < end_key; key++)
		assert(!bpf_map_update_elem(lru_map_fd, &key, value,
					    BPF_NOEXIST));

	/* Lookup 1 to tgt_free/2 */
	end_key = 1 + batch_size;
	for (key = 1; key < end_key; key++) {
		assert(!bpf_map_lookup_elem(lru_map_fd, &key, value));
		assert(!bpf_map_update_elem(expected_map_fd, &key, value,
				            BPF_NOEXIST));
	}

	/* Insert 1+tgt_free to 2*tgt_free
	 * => 1+tgt_free/2 to LOCALFREE_TARGET will be
	 * removed by LRU
	 */
	key = 1 + tgt_free;
	end_key = key + tgt_free;
	for (; key < end_key; key++) {
		assert(!bpf_map_update_elem(lru_map_fd, &key, value,
					    BPF_NOEXIST));
		assert(!bpf_map_update_elem(expected_map_fd, &key, value,
					    BPF_NOEXIST));
	}

	assert(map_equal(lru_map_fd, expected_map_fd));

	close(expected_map_fd);
	close(lru_map_fd);

	printf("Pass\n");
}
Example #16
0
VALUE bm_alloc(VALUE self) {
    Bitmapper* map;
    map = create_map();
    return Data_Wrap_Struct(self, 0, bm_free, map);
}
Example #17
0
/* Size of the LRU map 1.5 * tgt_free
 * Insert 1 to tgt_free (+tgt_free keys)
 * Update 1 to tgt_free/2
 *   => The original 1 to tgt_free/2 will be removed due to
 *      the LRU shrink process
 * Re-insert 1 to tgt_free/2 again and do a lookup immeidately
 * Insert 1+tgt_free to tgt_free*3/2
 * Insert 1+tgt_free*3/2 to tgt_free*5/2
 *   => Key 1+tgt_free to tgt_free*3/2
 *      will be removed from LRU because it has never
 *      been lookup and ref bit is not set
 */
static void test_lru_sanity2(int map_type, int map_flags, unsigned int tgt_free)
{
	unsigned long long key, value[nr_cpus];
	unsigned long long end_key;
	int lru_map_fd, expected_map_fd;
	unsigned int batch_size;
	unsigned int map_size;
	int next_cpu = 0;

	if (map_flags & BPF_F_NO_COMMON_LRU)
		/* Ther percpu lru list (i.e each cpu has its own LRU
		 * list) does not have a local free list.  Hence,
		 * it will only free old nodes till there is no free
		 * from the LRU list.  Hence, this test does not apply
		 * to BPF_F_NO_COMMON_LRU
		 */
		return;

	printf("%s (map_type:%d map_flags:0x%X): ", __func__, map_type,
	       map_flags);

	assert(sched_next_online(0, &next_cpu) != -1);

	batch_size = tgt_free / 2;
	assert(batch_size * 2 == tgt_free);

	map_size = tgt_free + batch_size;
	if (map_flags & BPF_F_NO_COMMON_LRU)
		lru_map_fd = create_map(map_type, map_flags,
					map_size * nr_cpus);
	else
		lru_map_fd = create_map(map_type, map_flags, map_size);
	assert(lru_map_fd != -1);

	expected_map_fd = create_map(BPF_MAP_TYPE_HASH, 0, map_size);
	assert(expected_map_fd != -1);

	value[0] = 1234;

	/* Insert 1 to tgt_free (+tgt_free keys) */
	end_key = 1 + tgt_free;
	for (key = 1; key < end_key; key++)
		assert(!bpf_map_update_elem(lru_map_fd, &key, value,
					    BPF_NOEXIST));

	/* Any bpf_map_update_elem will require to acquire a new node
	 * from LRU first.
	 *
	 * The local list is running out of free nodes.
	 * It gets from the global LRU list which tries to
	 * shrink the inactive list to get tgt_free
	 * number of free nodes.
	 *
	 * Hence, the oldest key 1 to tgt_free/2
	 * are removed from the LRU list.
	 */
	key = 1;
	if (map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH) {
		assert(!bpf_map_update_elem(lru_map_fd, &key, value,
					    BPF_NOEXIST));
		assert(!bpf_map_delete_elem(lru_map_fd, &key));
	} else {
		assert(bpf_map_update_elem(lru_map_fd, &key, value,
					   BPF_EXIST));
	}

	/* Re-insert 1 to tgt_free/2 again and do a lookup
	 * immeidately.
	 */
	end_key = 1 + batch_size;
	value[0] = 4321;
	for (key = 1; key < end_key; key++) {
		assert(bpf_map_lookup_elem(lru_map_fd, &key, value));
		assert(!bpf_map_update_elem(lru_map_fd, &key, value,
					    BPF_NOEXIST));
		assert(!bpf_map_lookup_elem(lru_map_fd, &key, value));
		assert(value[0] == 4321);
		assert(!bpf_map_update_elem(expected_map_fd, &key, value,
				            BPF_NOEXIST));
	}

	value[0] = 1234;

	/* Insert 1+tgt_free to tgt_free*3/2 */
	end_key = 1 + tgt_free + batch_size;
	for (key = 1 + tgt_free; key < end_key; key++)
		/* These newly added but not referenced keys will be
		 * gone during the next LRU shrink.
		 */
		assert(!bpf_map_update_elem(lru_map_fd, &key, value,
					    BPF_NOEXIST));

	/* Insert 1+tgt_free*3/2 to  tgt_free*5/2 */
	end_key = key + tgt_free;
	for (; key < end_key; key++) {
		assert(!bpf_map_update_elem(lru_map_fd, &key, value,
					    BPF_NOEXIST));
		assert(!bpf_map_update_elem(expected_map_fd, &key, value,
				            BPF_NOEXIST));
	}

	assert(map_equal(lru_map_fd, expected_map_fd));

	close(expected_map_fd);
	close(lru_map_fd);

	printf("Pass\n");
}
Example #18
0
int data_handling(SDL_Rect *pst, SDL_Rect *src, hero *tux, map_info *map, platform **first, platform **last){
	if(tux->move)
		tux->on_platform = 0;
	platform *runner = *first;
	while(runner != NULL){ // Check whether you are on any platform
		if(pst->x + tux->w > runner->x && 
		runner->x > pst->x - runner->width && 
		pst->y + tux->h >= runner->y - src->y &&
		map->backup <= runner->y - src->y && !tux->raising && tux->move){
			if(map->previous != runner->x + runner->y)
				tux->score += 10;
			map->previous = runner->x + runner->y;
			pst->y = runner->y - src->y - tux->h;

			tux->raising = 0;
			tux->in_jump = 0;
			tux->on_platform = 1;
			if(tux->state == 3)
				tux->state = 0;
		}
		runner = runner->next;
	}
	map->backup = pst->y + tux->h;
	if(!tux->on_platform){
		tux->in_jump = 1;
		pst->y += 6;
		tux->x_speed = gd->screen.width/NASOBIC_1;
	}
	else
		tux->x_speed = gd->screen.width/NASOBIC_2;
	if(tux->raising > 0)
		tux->x_speed = gd->screen.width/NASOBIC_2;
	if(tux->move == 1){
		src->y -= tux->level;
		pst->y += tux->level;
	}
	if(map->ch_count + 1 > map->limit){ // Check for new level
		map->next_level = 1;
		map->ch_count = 0;
	}

	if(tux->raising > 6){
		tux->raising--;
		pst->y -= tux->raising;
	}
	else
		tux->raising = 0;
	if(pst->y < 0)
		src->y += pst->y;
	while(src->y <= 0){
		if(map->next_level == 1){
			tux->level++;
			map->limit += LIMIT_ADD;
			tux->score += NEW_LEVEL*tux->level;
			map->next_level = 0;
		}
		if(!create_map(map, tux->level, first, last))
			return 0;
		src->y += BACK_Y;
		map->ch_count++;
	}
	if(pst->y > gd->screen.height - tux->h && tux->move == 1){ //If tux falls under the visible screen
		game_over(*tux);
		return 0;
	}
//	if(pst->y < gd->screen.width/2)
//		map->move = 1;

	return 1;
}
Example #19
0
/* Size of the LRU amp is 2
 * Add key=1 (+1 key)
 * Add key=2 (+1 key)
 * Lookup Key=1
 * Add Key=3
 *   => Key=2 will be removed by LRU
 * Iterate map.  Only found key=1 and key=3
 */
static void test_lru_sanity0(int map_type, int map_flags)
{
	unsigned long long key, value[nr_cpus];
	int lru_map_fd, expected_map_fd;
	int next_cpu = 0;

	printf("%s (map_type:%d map_flags:0x%X): ", __func__, map_type,
	       map_flags);

	assert(sched_next_online(0, &next_cpu) != -1);

	if (map_flags & BPF_F_NO_COMMON_LRU)
		lru_map_fd = create_map(map_type, map_flags, 2 * nr_cpus);
	else
		lru_map_fd = create_map(map_type, map_flags, 2);
	assert(lru_map_fd != -1);

	expected_map_fd = create_map(BPF_MAP_TYPE_HASH, 0, 2);
	assert(expected_map_fd != -1);

	value[0] = 1234;

	/* insert key=1 element */

	key = 1;
	assert(!bpf_map_update_elem(lru_map_fd, &key, value, BPF_NOEXIST));
	assert(!bpf_map_update_elem(expected_map_fd, &key, value,
				    BPF_NOEXIST));

	/* BPF_NOEXIST means: add new element if it doesn't exist */
	assert(bpf_map_update_elem(lru_map_fd, &key, value, BPF_NOEXIST) == -1
	       /* key=1 already exists */
	       && errno == EEXIST);

	assert(bpf_map_update_elem(lru_map_fd, &key, value, -1) == -1 &&
	       errno == EINVAL);

	/* insert key=2 element */

	/* check that key=2 is not found */
	key = 2;
	assert(bpf_map_lookup_elem(lru_map_fd, &key, value) == -1 &&
	       errno == ENOENT);

	/* BPF_EXIST means: update existing element */
	assert(bpf_map_update_elem(lru_map_fd, &key, value, BPF_EXIST) == -1 &&
	       /* key=2 is not there */
	       errno == ENOENT);

	assert(!bpf_map_update_elem(lru_map_fd, &key, value, BPF_NOEXIST));

	/* insert key=3 element */

	/* check that key=3 is not found */
	key = 3;
	assert(bpf_map_lookup_elem(lru_map_fd, &key, value) == -1 &&
	       errno == ENOENT);

	/* check that key=1 can be found and mark the ref bit to
	 * stop LRU from removing key=1
	 */
	key = 1;
	assert(!bpf_map_lookup_elem(lru_map_fd, &key, value));
	assert(value[0] == 1234);

	key = 3;
	assert(!bpf_map_update_elem(lru_map_fd, &key, value, BPF_NOEXIST));
	assert(!bpf_map_update_elem(expected_map_fd, &key, value,
				    BPF_NOEXIST));

	/* key=2 has been removed from the LRU */
	key = 2;
	assert(bpf_map_lookup_elem(lru_map_fd, &key, value) == -1);

	assert(map_equal(lru_map_fd, expected_map_fd));

	close(expected_map_fd);
	close(lru_map_fd);

	printf("Pass\n");
}
Example #20
0
int main(int argc, char* argv[]) {
	int c;
	char *dbname = (char *)DBNAME;
	char *dbinst = (char *)DBINST;
	char *hostname = (char *)HOSTNAME;
	char *datadir = NULL;
	char *verdesc = NULL;
	char *verstr = NULL;
	char *prefix = NULL;
	unsigned int version = 0;
	char *schemastr = NULL;
	unsigned short usage = 0;
	unsigned short dblist = 0;
	unsigned short schemalist = 0;
	unsigned short prefixlist = 0;
	unsigned short trusted = 1;
	unsigned char term = '\0';

	// source files
	char udd_sql3[BUFLEN] = NULLSTR;
	char cert_yaml[BUFLEN] = NULLSTR;
	char gfxids_yaml[BUFLEN] = NULLSTR;
	char iconids_yaml[BUFLEN] = NULLSTR;
	char typeids_yaml[BUFLEN] = NULLSTR;
	char blueprints_yaml[BUFLEN] = NULLSTR;

	// SQL things
	int db3_rc;
	SQLRETURN ret;
	SQLCHAR connStrOut[BUFLEN] = NULLSTR;
	SQLCHAR dsn[BUFLEN] = NULLSTR;
	SQLCHAR auth[BUFLEN] = NULLSTR;
	SQLCHAR usr[BUFLEN] = NULLSTR;
	SQLCHAR pwd[BUFLEN] = NULLSTR;
	SQLSMALLINT connStrLen;

	// set globals
	GZIP_FLAG = 1;
	JSONP_FLAG = 1;
	SCHEMA = 0;
	JSON_DIR = NULL;
	H_ENV = SQL_NULL_HENV;
	H_DBC = SQL_NULL_HDBC;
	H_DBC2 = SQL_NULL_HDBC;
	DB3_UD = NULL;

	while ((c = getopt(argc, argv, "i:o:d:u:p:n:N:s:x:hvXDSZP")) != -1) {
		switch (c) {
		case 'i':
			datadir = (char *)malloc(BUFLEN);
			strlcpy(datadir, optarg, BUFLEN);
			term = datadir[strlen(datadir) - 1];
			if (term != PATHSEP) {
				strlcat(datadir, SZPATHSEP, BUFLEN);
			}
			break;
		case 'o':
			JSON_DIR = (char *)malloc(BUFLEN);
			strlcpy(JSON_DIR, optarg, BUFLEN);
			term = JSON_DIR[strlen(JSON_DIR) - 1];
			if (term != PATHSEP) {
				strlcat(JSON_DIR, SZPATHSEP, BUFLEN);
			}
			break;
		case 'x':
			prefix = (char *)malloc(BUFLEN);
			strlcpy(prefix, optarg, BUFLEN);
			break;
		case 'd':
			dbname = (char *)malloc(BUFLEN);
			strlcpy(dbname, optarg, BUFLEN);
			break;
		case 'n':
			verstr = (char *)malloc(BUFLEN);
			strlcpy(verstr, optarg, BUFLEN);
			break;
		case 'N':
			verdesc = (char *)malloc(BUFLEN);
			strlcpy(verdesc, optarg, BUFLEN);
			break;
		case 's':
			schemastr = (char *)malloc(BUFLEN);
			strlcpy(schemastr, optarg, BUFLEN);
			break;
		case 'S':
			schemalist = 1;
			break;
		case 'v':
			printf("sdd2json version %d.%d.%d", SDD2JSON_V_MAJOR, SDD2JSON_V_MINOR, SDD2JSON_V_PATCH);
			return 0;
		case 'D':
			dblist = 1;
			break;
		case 'u':
			trusted = 0;
			strlcpy(usr, optarg, BUFLEN);
			break;
		case 'p':
			trusted = 0;
			strlcpy(pwd, optarg, BUFLEN);
			break;
		case 'P':
			JSONP_FLAG = 0;
			break;
		case 'Z':
			GZIP_FLAG = 0;
			break;
		case 'X':
			prefixlist = 1;
		case '?':
			printf("\n");
			usage = 1;
			break;
		}
	}

	if (1 == schemalist) {
		for (unsigned int i = 0; i < VERS_N; i++) {
			printf("%s:\tversion %d;\tschema %d\n", VERS[i].version_desc, VERS[i].version_id, VERS[i].schema_id);
		}
		return 0;
	}

	if (1 == prefixlist) {
		printf("\tcrp\n");
		printf("\tdgm\n");
		printf("\tinv\n");
		printf("\tmap\n");
		printf("\tram\n");
		printf("\tsta\n");
		return 0;
	}

	if (usage < 1 && datadir == NULL) {
		fprintf(stderr, "EVE static data dir path is required\n");
		usage = 1;
	}

	if (usage < 1 && verstr == NULL) {
		fprintf(stderr, "static data version ID is required\n");
		usage = 1;
	}

	if (usage > 0) return dump_usage();

	// parse version/schema from params and known values
	if (verstr != NULL) {
		version = atoi(verstr);
	}
	if (version == 0) {
		fprintf(stderr, "the static data version ID provided is invalid: %s\n", verstr);
		return 1;
	}
	unsigned int found_version = 0;
	for (unsigned int i = 0; i < VERS_N; i++) {
		if (VERS[i].version_id == version) {
			found_version = 1;
			SCHEMA = VERS[i].schema_id;
			if (NULL == verdesc) {
				verdesc = (char *)malloc(BUFLEN);
				strlcpy(verdesc, VERS[i].version_desc, BUFLEN);
			}
			break;
		}
	}
	if (1 != found_version) {
		fprintf(stderr, "warning: using unknown static data version ID: %d\n", version);
	}
	if (schemastr != NULL) {
		if (0 != SCHEMA) {
			fprintf(stderr, "warning: overriding known schema ID\n");
		}
		SCHEMA = atoi(schemastr);
	}
	if (0 == SCHEMA) {
		fprintf(stderr, "schema ID is required\n");
		return 1;
	}
	printf("static data: '%s', version %d, schema %d\n", verdesc, version, SCHEMA);

	// validate input/schema
	printf("checking input: %s - ", datadir);
	if (ACCESS(datadir, 0) != 0) {
		printf("err\n");
		fprintf(stderr, "could not access output path\n");
		return 1;
	}
		
	if (SCHEMA >= 100038) {
		strlcpy(cert_yaml, datadir, BUFLEN);
		strlcat(cert_yaml, "certificates.yaml", BUFLEN);
		if (ACCESS(cert_yaml, 0) != 0) {
			printf("err\n");
			fprintf(stderr, "could not access %s\n", cert_yaml);
			return 1;
		}
	}

	if (SCHEMA >= 100038) {
		strlcpy(gfxids_yaml, datadir, BUFLEN);
		strlcat(gfxids_yaml, "graphicIDs.yaml", BUFLEN);
		if (ACCESS(gfxids_yaml, 0) != 0) {
			printf("err\n");
			fprintf(stderr, "could not access %s\n", gfxids_yaml);
			return 1;
		}
	}

	if (SCHEMA >= 100038) {
		strlcpy(iconids_yaml, datadir, BUFLEN);
		strlcat(iconids_yaml, "iconIDs.yaml", BUFLEN);
		if (ACCESS(iconids_yaml, 0) != 0) {
			printf("err\n");
			fprintf(stderr, "could not access %s\n", iconids_yaml);
			return 1;
		}
	}

	if (SCHEMA >= 100038) {
		strlcpy(typeids_yaml, datadir, BUFLEN);
		strlcat(typeids_yaml, "typeIDs.yaml", BUFLEN);
		if (ACCESS(typeids_yaml, 0) != 0) {
			printf("err\n");
			fprintf(stderr, "could not access %s\n", typeids_yaml);
			return 1;
		}
	}

	if (SCHEMA >= 100038) {
		strlcpy(udd_sql3, datadir, BUFLEN);
		strlcat(udd_sql3, "universeDataDx.db", BUFLEN);
		if (ACCESS(udd_sql3, 0) != 0) {
			printf("err\n");
			fprintf(stderr, "could not access %s\n", udd_sql3);
			return 1;
		}
	}

	if (SCHEMA >= 100038) {
		strlcpy(blueprints_yaml, datadir, BUFLEN);
		strlcat(blueprints_yaml, "blueprints.yaml", BUFLEN);
		if (ACCESS(blueprints_yaml, 0) != 0) {
			printf("err\n");
			fprintf(stderr, "could not access %s\n", blueprints_yaml);
			return 1;
		}
	}

	printf("OK\n");

	// validate output
	if (JSON_DIR == NULL) {
		JSON_DIR = (char *)malloc(2 * BUFLEN);
		strlcpy(JSON_DIR, datadir, 2 * BUFLEN);
		strlcat(JSON_DIR, SDD, 2* BUFLEN);
		strlcat(JSON_DIR, SZPATHSEP, 2 * BUFLEN);
	}
	printf("checking output: %s - ", JSON_DIR);
	if (ACCESS(JSON_DIR, 0) != 0) {
		if (MKDIR(JSON_DIR) != 0) {
			printf("err\n");
			fprintf(stderr, "could not create output path\n");
			return 1;
		}
		if (ACCESS(JSON_DIR, 0) != 0) {
			printf("err\n");
			fprintf(stderr, "could not access output path\n");
			return 1;
		}
	}
	printf("OK\n");

	// connect to SQLLITE dbs
	printf("connecting to [%s] - ", udd_sql3);

	db3_rc = sqlite3_open(udd_sql3, &DB3_UD);
	if (SQLITE_OK != db3_rc) return dump_db3_error(DB3_UD, 1);
	printf("OK\n");

	// connect to SQL server
	if (0 != trusted) {
		SNPRINTF(auth, BUFLEN, "Trusted_Connection=yes");
	}
	else {
		SNPRINTF(auth, BUFLEN, "User ID=%s;Password=%s", usr, pwd);
	}
	printf("connecting to [%s\\%s] using [%s] - ", hostname, dbinst, auth);

	ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HENV, &H_ENV);
	if (!SQL_SUCCEEDED(ret)) return dump_sql_error(ret, SQL_HANDLE_ENV, H_ENV, 1);
	ret = SQLSetEnvAttr(H_ENV, SQL_ATTR_ODBC_VERSION, (void *)SQL_OV_ODBC3_80, 0);
	if (!SQL_SUCCEEDED(ret)) return dump_sql_error(ret, SQL_HANDLE_ENV, H_ENV, 1);

	if (dblist > 0) {
		printf("list drivers\n");
		unsigned short ret = check_drivers(1);
		close_handles();
		return ret;
	}

	if (0 != check_drivers(0)) {
		printf("err\n");
		fprintf(stderr, "SQL server driver not found\n");
		close_handles();
		return 1;
	}

	ret = SQLAllocHandle(SQL_HANDLE_DBC, H_ENV, &H_DBC);
	if (!SQL_SUCCEEDED(ret)) return dump_sql_error(ret, SQL_HANDLE_ENV, H_ENV, 1);
	ret = SQLAllocHandle(SQL_HANDLE_DBC, H_ENV, &H_DBC2);
	if (!SQL_SUCCEEDED(ret)) return dump_sql_error(ret, SQL_HANDLE_ENV, H_ENV, 1);

	SNPRINTF(dsn, BUFLEN, "Driver={%s};Server=%s\\%s;Database=%s;%s;", SQLDRV, hostname, dbinst, dbname, auth);
	ret = SQLDriverConnect(H_DBC, NULL, dsn, strnlen(dsn, BUFLEN), connStrOut, BUFLEN, &connStrLen, SQL_DRIVER_NOPROMPT);
	if (!SQL_SUCCEEDED(ret)) return dump_sql_error(ret, SQL_HANDLE_DBC, H_DBC, 1);
	ret = SQLDriverConnect(H_DBC2, NULL, dsn, strnlen(dsn, BUFLEN), connStrOut, BUFLEN, &connStrLen, SQL_DRIVER_NOPROMPT);
	if (!SQL_SUCCEEDED(ret)) return dump_sql_error(ret, SQL_HANDLE_DBC, H_DBC2, 1);

	printf("OK\n");

	// create metainfo file
	char metafile[BUFLEN] = NULLSTR;
	strlcpy(metafile, JSON_DIR, BUFLEN);
	strlcat(metafile, "metainf.json", BUFLEN);
	FILE *f = fopen(metafile, "w");
	if (f == NULL) {
		printf("err\n");
		fprintf(stderr, "error opening meta file: %s", metafile);
		close_handles();
		return 1;
	}
	printf("OK\n");
	fprintf(f, "{\n");
	fprintf(f, "\"formatID\":%d,\n", FORMAT_ID);
	fprintf(f, "\"schema\":%d,\n", SCHEMA);
	fprintf(f, "\"copy\":\"%s\",\n", CCPR);
	fprintf(f, "\"version\":%d,\n", version);
	fprintf(f, "\"verdesc\":\"%s\",\n", verdesc);
	fprintf(f, "\"tables\":{\n");

	// do stuff
	int rc = 0;
	int comma = 0;

	if (NULL == prefix || strncmp(prefix, "crp", 3) == 0) {
		if (comma++ > 0) fprintf(f, ",\n");
		rc = create_crp(f);
		if (rc != 0) {
			close_handles();
			fclose(f);
			return 1;
		}
	}

	if (NULL == prefix || strncmp(prefix, "dgm", 3) == 0) {
		if (comma++ > 0) fprintf(f, ",\n");
		rc = create_dgm(f, cert_yaml);
		if (rc != 0) {
			close_handles();
			fclose(f);
			return 1;
		}
	}

	if (NULL == prefix || strncmp(prefix, "inv", 3) == 0) {
		if (comma++ > 0) fprintf(f, ",\n");
		rc = create_inv(f, typeids_yaml, iconids_yaml);
		if (rc != 0) {
			close_handles();
			fclose(f);
			return 1;
		}
	}

	if (NULL == prefix || strncmp(prefix, "map", 3) == 0) {
		if (comma++ > 0) fprintf(f, ",\n");
		rc = create_map(f);
		if (0 != rc) {
			close_handles();
			fclose(f);
			return 1;
		}
	}

	if (NULL == prefix || strncmp(prefix, "ram", 3) == 0) {
		if (comma++ > 0) fprintf(f, ",\n");
		ret = create_ram(f, blueprints_yaml);
		if (!SQL_SUCCEEDED(ret)) {
			close_handles();
			fclose(f);
			return 1;
		}
	}

	if (NULL == prefix || strncmp(prefix, "sta", 3) == 0) {
		if (comma++ > 0) fprintf(f, ",\n");
		ret = create_sta(f);
		if (!SQL_SUCCEEDED(ret)) {
			close_handles();
			fclose(f);
			return 1;
		}
	}

	fprintf(f, "\n}\n"); // end of sources

	// clean up connections
	fprintf(f, "}\n");
	fclose(f);
	printf("metainf - ", metafile);
	post_file("metainf");

	close_handles();

	free(datadir);
	free(verdesc);
	free(verstr);
	free(prefix);
	free(JSON_DIR);

	printf("\nall done!\n");

	return 0;
}