Exemple #1
0
/* add a block descriptor to a descriptor list */ 
static Map *map_add(Map **head, int fblock, int cblock) { 
    Map *b; 
    if (!*head || fblock<(*head)->fblock) { 
	Map *c = map_new(fblock,cblock); 
	c->next=*head; *head=c; 
	ASSERT(cblock>=0 && cblock<storage_blocks); 
	ASSERT(storage_used[cblock]==0); 
	storage_remember(cblock); 
	return c; 
    } 
    for (b=*head; b->next && b->fblock!=fblock; b=b->next) ; 
    if (b->fblock==fblock) { 
	if (cblock!=b->cblock) { 
	    flog("using new cblock location %d (old %d) for block %d",
	 	cblock,b->cblock,fblock);
	    ASSERT(b->cblock>=0 && b->cblock<storage_blocks); 
	    ASSERT(storage_used[b->cblock]!=0); 
	    storage_forget(b->cblock); 
	    b->cblock=cblock; 
	    storage_remember(b->cblock); 
	} 
	ASSERT(storage_used[b->cblock]!=0); 
	return b; 
    } else { 
	Map *c = map_new(fblock,cblock); 
	c->next=NULL; b->next=c; 
	ASSERT(cblock>=0 && cblock<storage_blocks); 
	ASSERT(storage_used[cblock]==0); 
	storage_remember(cblock); 
        return c;
    } 
} 
Exemple #2
0
void
build_login_gui()
{
	int  i;
	rect_t  r0 = {.x = login_usr_x, .y = login_usr_y, .w = login_usr_w, .h = login_usr_h};
	rect_t  r = {.x = login_ent_x, .y = login_ent_y0, .w = login_ent_w, .h = login_ent_h};
	
	load_superusr();

	mwin = utk_desktop_new();
	utk_widget_show_before(mwin, prepare_login, NULL);

	build_tip_lbl(&pwderr, mwin, (LCD_W-tip_w)/2, (LCD_H-tip_h)/2, LBL_PWDERR, 2);
	for (i = 0; i < MAXUSR+1; ++i) {
		r0.y = login_usr_y - i*login_usr_h;
		ulbl[i] = label_new(mwin, LBL_USR, NULL, RGB_BLACK, &r0);
		ump[i] = map_new(mwin, &r0, NULL, (void *)select_user, (void*)i);
		utk_widget_disable(ump[i]);
	}

	uinp = label_new(mwin, NULL, NULL, RGB_BLACK, &r);
	umap = map_new(mwin, &r, NULL, (void *)show_user, (void*)0);

	r.y = login_ent_y1;
	pmap = map_new(mwin, &r, NULL, (void *)prepare_pinput, (void*)0);

	build_passwd_dot(mwin, (void**)pdot, MAXPLEN, login_ent_x + 8, login_ent_y1 + (login_ent_h - 14)/2);
	build_keybar(&lkbar, mwin, (LCD_W - keybar_w)>>1, (174 - keybar_h)/2 + (LCD_H - 174), &pkop, 0);

	cfm = utk_button_new();
	utk_button_set_bg(cfm, BN_LOGIN0);
	utk_button_set_bg(cfm, BN_LOGIN1);
	utk_signal_connect(cfm, "clicked", user_identify, 0);
	utk_widget_add_cntl(mwin, cfm, bn_login_x, bn_login_y);
}
Exemple #3
0
int main(void)
{
    _S_MAP_OBJECT test_map;
    _S_MAP_OBJECT test_map2;
    map_init(&test_map);
    map_init(&test_map2);

    map_new(&test_map, 8, 8);
    map_dump(&test_map);

    map_new(&test_map2, 4, 4);
    map_dump(&test_map2);

    return 0;
}
Exemple #4
0
t_map	*solve(t_list *list)
{
	t_map	*map;
	int		size;

	size = high_sqrt(ft_lstcount(list) * 4);
	map = map_new(size);
	while (!solve_map(map, list))
	{
		size++;
		free_map(map);
		map = map_new(size);
	}
	return (map);
}
Exemple #5
0
int main()
{
	_S_MAP_OBJECT ScreenBuf;

	map_init(&ScreenBuf);
	map_new(&ScreenBuf,35,17);
	
	system("clear");
	gotoxy(0,0);

	double angle=0;

	for(int i=0;i<35;i++){
		angle=(double)i*(180/35);
		//printf("%f\r\n",sin((i/180)*PI));
		double my=sin((angle/180)*PI)*8.0;
		map_PutTile(&ScreenBuf,i,8+my,1);

		my=cos((angle/180)*PI)*8;
		map_PutTile(&ScreenBuf,i,8+my,2);
	}
	
	map_dump(&ScreenBuf,Default_Tilepalete);


	return 0;
}
Exemple #6
0
int main()
{
	_S_MAP_OBJECT screenBuf;
	map_init(&screenBuf);
	map_new(&screenBuf,16,16);

	map_PutTile(&screenBuf,6,5,4);
	map_PutTile(&screenBuf,5,5,4);
	map_PutTile(&screenBuf,4,5,4);
	map_PutTile(&screenBuf,6,6,4);
	map_PutTile(&screenBuf,5,6,4);
	map_PutTile(&screenBuf,4,6,4);
	map_PutTile(&screenBuf,6,7,4);
	map_PutTile(&screenBuf,5,7,4);
	map_PutTile(&screenBuf,4,7,4);

	_S_MAP_OBJECT humanObj;
	map_init(&humanObj);
	map_load(&humanObj,"human.dat");
	puts("\r\n-------------------------");
	map_drawTile_trn(&humanObj,5,5,&screenBuf);
	map_dump(&screenBuf,Default_Tilepalete);

	


	//map_dump(&carObj,Tilepalette);
	//map_dump(&screenBuffer,Tilepalette);


	return 0;
}
Exemple #7
0
struct map_t *file_to_new_map( const char * filename)
{
    FILE *in_file = fopen( filename, "r");
    if( in_file == NULL)
    {
        return NULL;
    }
    scalar x = 0, y = 0;
    fscanf( in_file, "%u\n", &x);
    fscanf( in_file, "%u\n", &y);

    struct map_t *new_map = map_new( x, y);
    for( int j = 0; j < y; j++)
    {
        for( int i = 0; i < x; i++)
        {
            char symbol = 0, space = 0;
            fscanf( in_file, "%c%c", &symbol, &space);
            map_set( new_map, i, j, symbol);
        }
    }
    fclose( in_file);
    
    return new_map;
}
Exemple #8
0
static int map_resize(map_t map, int newsize, int force)
{
	if ((newsize = map_calc_size(newsize)) == -1)
		return -1;

	if (force || newsize > map->size)
	{
		map_t newmap;
		int i;
		bucket_t *b;

		newmap = map_new(newsize, map->hashf, map->compf, map->allocf, map->freef);
		if (!newmap)
			return -1;
		for (i = 0; i < map->size; ++i)
		{
			b = map->buckets[i];
			while (b)
			{
				map_set(newmap, b->key, b->data, 0);
				b = b->next;
			}
		}
		map_set_buckets(map, newmap->buckets, newsize);
		free(newmap);
	}
	return map->size;
}
Exemple #9
0
Fichier : vis.c Projet : tycho/vis
bool vis_action_register(Vis *vis, const KeyAction *action) {
	if (!vis->actions)
		vis->actions = map_new();
	if (!vis->actions)
		return false;
	return map_put(vis->actions, action->name, action);
}
Exemple #10
0
static void push_fnc(struct context *context, struct byte_array *program)
{
    uint32_t num_closures = serial_decode_int(program);
    struct map *closures = NULL;

    for (int i=0; i<num_closures; i++) {
        struct byte_array *name = serial_decode_string(program);
        if (context->runtime) {
            if (!closures)
                closures = map_new();
            struct variable *c = find_var(context, name);
            c = variable_copy(context, c);
            map_insert(closures, name, c);
        }
    }

    struct byte_array *body = serial_decode_string(program);

    DEBUGPRINT("FNC %u,%u\n", num_closures, body->length);
    //display_code(context, body);

    if (context->runtime) {
        struct variable *f = variable_new_fnc(context, body, closures);
        variable_push(context, f);
    }
}
Exemple #11
0
Context *context_new(void)
{
	Context *context;
	context = (Context *) malloc(sizeof(Context));
	if (NULL == context) {
		goto err_malloc;
	}
	context->stack = stack_new((FreeFunc *) value_free_ignoring_symbols);
	if (NULL == context->stack) {
		goto err_malloc_stack;
	}
	context->map = map_new((FreeFunc *) value_free);
	if (NULL == context->map) {
		goto err_malloc_map;
	}
	context_builtin(context);
	context->defining_variable = FALSE;
	return context;
err_malloc_map:
	free(context->stack);
err_malloc_stack:
	free(context);
err_malloc:
	return NULL;
}
Exemple #12
0
int main()
{	
	system("clear");

	for(int i=0;i<2;i++){
		map_init(&gScreenBuffer[i]);
		map_new(&gScreenBuffer[i],35,16);
	}

	map_init(&gAlienModel);
	map_load(&gAlienModel,"alien.dat");

	map_init(&gPlasmaModel);
	map_load(&gPlasmaModel,"plasma.dat");

	map_init(&gAlienModel);
	map_load(&gAlienModel,"alien.dat");
	
	double TablePosition[] = {0,6.0};

	for(int i=0;i<2;i++)
	{
		_S_ALIEN_OBJECT *pObj = &gAlienObjects[i];
		alien_init(pObj,&gAlienModel);
		pObj->m_fXpos = 0;:
		pObj->m_fYpos = 2;
		pObj->m_nFSM = 1;
	}
Exemple #13
0
/* Make a copy of an existing map
 */
Map *map_copy(const Map * map)
{
	Map *copy = map_new();
	int x, y;

	copy->y = map->y;
	copy->x_size = map->x_size;
	copy->y_size = map->y_size;
	for (y = 0; y < MAP_SIZE; y++)
		for (x = 0; x < MAP_SIZE; x++)
			copy->grid[y][x] = copy_hex(copy, map->grid[y][x]);
	map_traverse(copy, build_network, NULL);
	map_traverse(copy, connect_network, NULL);
	map_traverse_const(map, set_nosetup_nodes, copy);
	if (map->robber_hex == NULL)
		copy->robber_hex = NULL;
	else
		copy->robber_hex =
		    copy->grid[map->robber_hex->y][map->robber_hex->x];
	if (map->pirate_hex == NULL)
		copy->pirate_hex = NULL;
	else
		copy->pirate_hex =
		    copy->grid[map->pirate_hex->y][map->pirate_hex->x];
	copy->shrink_left = map->shrink_left;
	copy->shrink_right = map->shrink_right;
	copy->has_moved_ship = map->has_moved_ship;
	copy->have_bridges = map->have_bridges;
	copy->has_pirate = map->has_pirate;
	copy->shrink_left = map->shrink_left;
	copy->shrink_right = map->shrink_right;
	copy->chits = copy_int_list(map->chits);

	return copy;
}
Exemple #14
0
int
main() {
	struct map * m = map_new(MAX);
	test(m);
	map_delete(m);
	return 0;
}
Exemple #15
0
Fichier : vis.c Projet : tycho/vis
Vis *vis_new(Ui *ui, VisEvent *event) {
	if (!ui)
		return NULL;
	Vis *vis = calloc(1, sizeof(Vis));
	if (!vis)
		return NULL;
	vis->ui = ui;
	vis->ui->init(vis->ui, vis);
	vis->tabwidth = 8;
	vis->textwidth = 0;
	vis->expandtab = false;
	vis->registers[VIS_REG_BLACKHOLE].type = REGISTER_BLACKHOLE;
	vis->registers[VIS_REG_CLIPBOARD].type = REGISTER_CLIPBOARD;
	array_init(&vis->motions);
	array_init(&vis->textobjects);
	action_reset(&vis->action);
	if (!(vis->command_file = file_new_internal(vis, NULL)))
		goto err;
	if (!(vis->search_file = file_new_internal(vis, NULL)))
		goto err;
	if (!(vis->keymap = map_new()))
		goto err;
	vis->mode_prev = vis->mode = &vis_modes[VIS_MODE_NORMAL];
	vis->event = event;
	if (event && event->vis_start)
		event->vis_start(vis);
	vis->ui->start(vis->ui);
	return vis;
err:
	vis_free(vis);
	return NULL;
}
Exemple #16
0
int
main(int argc, char *argv[])
{
	if (argc < 3 || argc > 4) {
		printf("usage: %s hashmap_tx|hashmap_atomic|ctree|btree|rbtree"
				" file-name [<seed>]\n", argv[0]);
		return 1;
	}

	const struct map_ops *ops = NULL;
	const char *path = argv[2];
	const char *type = argv[1];
	if (strcmp(type, "hashmap_tx") == 0) {
		ops = MAP_HASHMAP_TX;
	} else if (strcmp(type, "hashmap_atomic") == 0) {
		ops = MAP_HASHMAP_ATOMIC;
	} else if (strcmp(type, "ctree") == 0) {
		ops = MAP_CTREE;
	} else if (strcmp(type, "btree") == 0) {
		ops = MAP_BTREE;
	} else if (strcmp(type, "rbtree") == 0) {
		ops = MAP_RBTREE;
	} else {
		fprintf(stderr, "invalid hasmap type -- '%s'\n", type);
		return 1;
	}

	if (access(path, F_OK) != 0) {
		pop = pmemobj_create(path, POBJ_LAYOUT_NAME(map),
				PM_HASHSET_POOL_SIZE, S_IRUSR | S_IWUSR);
		if (pop == NULL) {
			fprintf(stderr, "failed to create pool: %s\n",
					pmemobj_errormsg());
			return 1;
		}

		struct hashmap_args args;

		if (argc > 3)
			args.seed = atoi(argv[3]);
		else
			args.seed = time(NULL);
		srand(args.seed);


		mapc = map_ctx_init(ops, pop);
		if (!mapc) {
			pmemobj_close(pop);
			perror("map_ctx_init");
			return 1;
		}

		root = POBJ_ROOT(pop, struct root);

		printf("seed: %u\n", args.seed);
		map_new(mapc, &D_RW(root)->map, &args);

		map = D_RO(root)->map;
	} else {
Exemple #17
0
int main()
{
	_S_MAP_OBJECT test_map;
	map_init(&test_map);

	_S_MAP_OBJECT test_map2;
	map_init(&test_map2);

	//test_map.new(8,8);
	map_new(&test_map,8,8);
	map_dump(&test_map,title_palette);

	map_new(&test_map2,4,4);
	map_dump(&test_map2,title_palette);

	return 0;
}
Exemple #18
0
struct mread_pool *
mread_create(int port , int max , int buffer_size) {
	int listen_fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
	if (listen_fd == -1) {
		return NULL;
	}
	int reuse = 1;
	setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(int));

	struct sockaddr_in my_addr;
	memset(&my_addr, 0, sizeof(struct sockaddr_in));
	my_addr.sin_family = AF_INET;
	my_addr.sin_port = htons(port);
	my_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); // INADDR_ANY;
	printf("MREAD bind %s:%u\n",inet_ntoa(my_addr.sin_addr),ntohs(my_addr.sin_port));
	if (bind(listen_fd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) {
		close(listen_fd);
		return NULL;
	}
	if (listen(listen_fd, BACKLOG) == -1) {
		close(listen_fd);
		return NULL;
	}

	int epoll_fd = epoll_create(max + 1);
	if (epoll_fd == -1) {
		close(listen_fd);
		return NULL;
	}
	struct epoll_event ev;
	ev.events = EPOLLIN;
	ev.data.fd = listen_fd;
	if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, listen_fd, &ev) == -1) {
		close(listen_fd);
		close(epoll_fd);
		return NULL;
	}

	struct mread_pool * self = malloc(sizeof(*self));
	self->listen_fd = listen_fd;
	self->epoll_fd = epoll_fd;
	self->max_connection = max;
	self->closed = 0;
	self->active = -1;
	self->skip = 0;
	self->sockets = _create_sockets(max);
	self->free_socket = &self->sockets[0];
	self->socket_hash = map_new(max);
	self->queue_len = 0;
	self->queue_head = 0;
	if (buffer_size == 0) {
		self->rb = _create_rb(RINGBUFFER_DEFAULT);
	} else {
		self->rb = _create_rb(buffer_size);
	}

	return self;
}
Exemple #19
0
static void load_game(const gchar * file, gboolean is_reload)
{
	const gchar *gamefile;
	GameParams *new_params;
	gchar *new_filename;
	gint i;

	if (file == NULL)
		gamefile = default_game;
	else
		gamefile = file;

	new_params = params_load_file(gamefile);
	if (new_params == NULL) {
		error_dialog(_("Failed to load '%s'"), file);
		return;
	}

	if (file == NULL) {
		g_free(new_params->title);
		new_params->title = g_strdup("Untitled");
		map_free(new_params->map);
		new_params->map = map_new();
		for (i = 0; i < 6; i++) {
			map_modify_row_count(new_params->map,
					     MAP_MODIFY_INSERT,
					     MAP_MODIFY_ROW_BOTTOM);
		}
		for (i = 0; i < 11; i++) {
			map_modify_column_count(new_params->map,
						MAP_MODIFY_INSERT,
						MAP_MODIFY_COLUMN_RIGHT);
		}
		new_params->map->chits =
		    g_array_new(FALSE, FALSE, sizeof(gint));
		new_filename = NULL;
	} else {
		new_filename = g_strdup(file);
		config_set_string("editor/last-game", new_filename);
	}

	guimap_reset(gmap);
	if (params != NULL)
		params_free(params);
	params = new_params;
	apply_params(params);
	if (open_filename != NULL)
		g_free(open_filename);
	open_filename = new_filename;
	map_move_robber(gmap->map, -1, -1);
	fill_map(gmap->map);
	if (is_reload) {
		scale_map(gmap);
		guimap_display(gmap);
	}
	update_resize_buttons();
}
t_map	*ft_enlarge_map(int size, t_map *map)
{
	int tmp;

	tmp = map->nbtetri;
	map = map_new(size);
	map->nbtetri = tmp;
	return (map);
}
Exemple #21
0
struct maps *
maps_new(struct attr *parent, struct attr **attrs)
{
	struct attr *data,**attrs_dup;
	if (!parent) {
		dbg(lvl_error,"No parent\n");
		return NULL;
	}
	if (parent->type != attr_mapset) {
		dbg(lvl_error,"Parent must be mapset\n");
		return NULL;
	}
	dbg(lvl_debug,"enter\n");
	attrs_dup=attr_list_dup(attrs);
	data=attr_search(attrs_dup, NULL, attr_data);
	if (data) {
		struct file_wordexp *wexp=file_wordexp_new(data->u.str);
		int i,count=file_wordexp_get_count(wexp);
		char **array=file_wordexp_get_array(wexp);
		struct attr *name;
		struct attr *name_provided = attr_search(attrs_dup, NULL, attr_name);

		// if no name was provided, fill the name with the location
		if (!name_provided) {
			struct attr name_tmp;
			name_tmp.type = attr_name;
			name_tmp.u.str="NULL";
			attrs_dup=attr_generic_add_attr(attrs_dup, &name_tmp);
			name = attr_search(attrs_dup, NULL, attr_name);
		}

		for (i = 0 ; i < count ; i++) {
			struct attr map;
			g_free(data->u.str);
			data->u.str=g_strdup(array[i]);

			if (!name_provided) {
				g_free(name->u.str);
				name->u.str=g_strdup(array[i]);
			}

			map.type=attr_map;
			map.u.map=map_new(parent, attrs_dup);

			if (map.u.map) {
				mapset_add_attr(parent->u.mapset, &map);
				navit_object_unref(map.u.navit_object);
			}
			
		}
		file_wordexp_destroy(wexp);	
	} else {
		dbg(lvl_error,"no data attribute\n");
	}
	attr_list_free(attrs_dup);
	return NULL;
}
Exemple #22
0
Map initRoom() {
  Map m = map_new();
  unsigned short tileMap[] = {
    2, 2, 2, 2, 2, 2, 2, 2,
    2, 2, 2, 2, 2, 2, 2, 2,
    2, 2, 2, 2, 2, 2, 2, 2,
    2, 2, 2, 2, 2, 2, 2, 2,
    2, 2, 2, 2, 2, 2, 2, 2,
    2, 2, 2, 2, 2, 2, 2, 2,
    2, 2, 2, 2, 2, 2, 2, 2,
    2, 2, 2, 2, 2, 2, 2, 2,
    
    2, 2, 2, 2, 2, 2, 2, 2,
    2, 0, 0, 0, 0, 0, 0, 2,
    2, 0, 0, 0, 0, 0, 0, 2,
    2, 0, 0, 0, 0, 0, 0, 2,
    2, 0, 0, 0, 0, 0, 0, 2,
    2, 0, 0, 0, 0, 0, 0, 2,
    2, 0, 0, 0, 0, 0, 0, 2,
    2, 2, 2, 2, 2, 2, 2, 2,    
    
    2, 2, 2, 2, 2, 2, 2, 2,
    2, 0, 0, 0, 0, 0, 0, 2,
    2, 0, 0, 0, 0, 0, 0, 2,
    2, 0, 0, 0, 0, 0, 0, 2,
    2, 0, 0, 0, 0, 0, 0, 2,
    2, 0, 0, 0, 0, 0, 0, 2,
    2, 0, 0, 0, 0, 0, 0, 2,
    2, 0, 0, 2, 2, 2, 2, 2,    
    
    2, 2, 2, 2, 2, 2, 2, 2,
    2, 1, 1, 1, 1, 1, 1, 1,
    2, 1, 1, 1, 1, 1, 1, 1,
    2, 1, 1, 2, 2, 1, 1, 2,
    2, 1, 1, 2, 2, 1, 1, 2,
    2, 1, 1, 1, 1, 1, 1, 2,
    2, 1, 1, 1, 1, 1, 1, 2,
    2, 1, 1, 2, 1, 1, 2, 2   
    };
  m = map_init(m, 
    "cage", 
    (mapVec){8, 8, 4}, 
    tileMap,
    3
  ); 
  Tile floorTile = tile_init(
    tile_new(), 
    0
  );
  Tile wallTile = tile_init(
    tile_new(), 
    3
  );
  map_add_tile(m, floorTile);
  map_add_tile(m, wallTile);
  return m;
}
Exemple #23
0
int main()
{
	system("clear");

	for(int i=0;i<2;i++) {
		map_init(&gScreenBuf[i]);
		map_new(&gScreenBuf[i],35,16);
	
	
	}

	map_init(&gPlayer);
	map_load(&gPlayer,"plane1.dat");
	
	Plane_init(&gPlayerObject,&gPlayer,17,10);
	
	set_conio_terminal_mode();
	acc_tick = last_tick = 0;

	while(bLoop) {

		//타이밍처리
		clock_gettime(CLOCK_MONOTONIC,&work_timer);
		double cur_tick = work_timer.tv_sec + (double)(work_timer.tv_nsec * 1e-9);
		double delta_tick = cur_tick - last_tick;
		last_tick = cur_tick;

		//실시간입력	
		if(kbhit() != 0) {
			char ch = getch();
			if(ch == 'q') {
				bLoop = 0;
				puts("bye~\r");
			}
			//gPlayerObject.fpApply(&gPlayerObject,delta_tick,ch);
			gPlayerObject.fpApply(&gPlayerObject,delta_tick,ch);
		}

		//타이밍계산
		acc_tick += delta_tick;
		if(acc_tick > 0.1) {
			//puts("tick...\r");
			gotoxy(0,0);
			map_drawTile(&gScreenBuf[0],0,0,&gScreenBuf[1]);
			
			gPlayerObject.fpDraw(&gPlayerObject,&gScreenBuf[1]);
			//Plane_Draw(&gPlayerObject,&gScreenBuf[1]);

			map_dump(&gScreenBuf[1],Default_Tilepalete);
			acc_tick = 0;
		}
	}


	return 0;
}
Exemple #24
0
bool sam_init(Vis *vis) {
	if (!(vis->cmds = map_new()))
		return false;
	bool ret = true;
	for (const CommandDef *cmd = cmds; cmd && cmd->name[0]; cmd++) {
		for (const char *const *name = cmd->name; *name; name++)
			ret &= map_put(vis->cmds, *name, cmd);
	}
	return ret;
}
Exemple #25
0
static bool mode_map(Mode *mode, const char *key, const KeyBinding *binding) {
	if (!mode)
		return false;
	if (!mode->bindings) {
		mode->bindings = map_new();
		if (!mode->bindings)
			return false;
	}
	return map_put(mode->bindings, key, binding);
}
Exemple #26
0
void _map_test()
{
    int a = 5, b = 12, c = 12345, d = 54321;
    int *aa, *bb, *cc, *dd, *ff;
    int repeat = 1;
    char *e = "Immanuel Kant",
          *ee;

    struct _map *map = map_new();
    assert(map != NULL);

    map_add(map, "rest not", &a);
    map_add(map, "life is sweeping by", &b);
    map_add(map, "go and do before you die", &c);
    map_add(map, "something mighty and sublime", &d);
    map_add(map, "leave behind to conquer time", e);

_repeat:
    aa = map_get(map, "rest not");
    if (repeat)
        assert(*aa == 5);
    else
        assert(aa == NULL);

    bb = map_get(map, "life is sweeping by");
    if (repeat)
        assert(*bb == 12);
    else
        assert(bb == NULL);
    cc = map_get(map, "go and do before you die");
    if (repeat)
        assert(*cc == 12345);
    else
        assert(cc == NULL);
    dd = map_get(map, "something mighty and sublime");
    if (repeat)
        assert(*dd == 54321);
    else
        assert(dd == NULL);
    ee = map_get(map, "leave behind to conquer time");
    if (repeat)
        assert(ee == e);
    else
        assert(ee == NULL);
    ff = map_get(map, "this is a nonexistent key");
    assert(ff == NULL);
    if (repeat) {
        repeat = 0;
        map_clear(map);
        goto _repeat;
    }
    fprintf(stdout, "%s: all tests passed\n", __func__);
    map_free(map);
}
Exemple #27
0
Map* count(Tree tree) {
    Map* accum = map_new();
    char c;
    for (c = MIN_ITEM; c <= MAX_ITEM; c++) {
        int* i = malloc(sizeof(int));
        *i = 0;
        map_insert(accum, c, i);
    }
    count_accum(tree, accum);
    return accum;
}
Exemple #28
0
static void init_task( ) {
  static int init = 0;

  while (!atomic_int_cas(&init, 1, 1)) {
    task_key = lc_local_new(task_key_deleter);
    lock = lc_spin_new();
    tasks = map_new(cmp_task, dup_task, rel_task);
    INFO("Initialized task");
    init = 1;
  }
}
Exemple #29
0
int main()
{

	char title_palette[] = {'.','#','@'};
	
	_S_MAP_OBJECT test_map;
	map_init(&test_map);
	
	_S_MAP_OBJECT test_map2;
	map_init(&test_map2);


	map_new(&test_map,8,8);
	map_dump(&test_map,title_palette);

	map_new(&test_map2,4,4);
	map_dump(&test_map2,title_palette);

	return 0;
}
Exemple #30
0
void test1(void)
{
	int i;
	map_t * map = map_new(strcmp);

	for (i = 0; test1_vals[i].key != NULL; i++)
		map_insert(map, test1_vals[i].key, test1_vals[i].val);
	for (i = 0; test1_vals[i].key != NULL; i++)
		assert(strcmp((char*)map_get(map, test1_vals[i].key), test1_vals[i].val) == 0);

	map_free(map);
}