Example #1
0
static void context_builtin(Context *context)
{
	map_put(context->map, "+", value_new_function(forsh_plus));
	map_put(context->map, "-", value_new_function(forsh_minus));
	map_put(context->map, "*", value_new_function(forsh_star));
	map_put(context->map, "/", value_new_function(forsh_slash));
}
Example #2
0
void ginit(int argc, char** argv) {
	ni = ni_get(0);
	ni->config = map_create(8, map_string_hash, map_string_equals, malloc, free);
	map_put(ni->config, "ip", (void*)(uint64_t)0xc0a80a99);	// 192.168.10.153
	map_put(ni->config, "netmask", (void*)(uint64_t)0xffffff00);

	init_list();
}
Example #3
0
static void
init_fh_map (void)
{
  fh_map = map_create (20);                     // 20 simultaneous open files
  map_put (fh_map, stdin, &finfo_list[0]);      //  should be enough to start with
  map_put (fh_map, stdout, &finfo_list[0]);
  map_put (fh_map, stderr, &finfo_list[0]);
}
Example #4
0
CONS*
system_info()
{
	CONS* info = NIL;
	
	info = map_put(info, ATOM("Program"), ATOM(_Program));
	info = map_put(info, ATOM("Version"), ATOM(_Version));
	info = map_put(info, ATOM("Copyright"), ATOM(_Copyright));
	return info;
}
Example #5
0
int main(){
map_t* newList = malloc(sizeof(map_t));
map_init(newList);
const char* passString ="a";
const char* secondString="2";
map_put(newList,"3","3");
map_put(newList,"7","34");
map_put(newList,"a","45");
map_put(newList,passString,secondString);
map_get(newList,secondString);
}
Example #6
0
/*
>> INITALIZING MAP ...
>> ADDING ENTRIES       PASSED
>> ***---DUPLICATE KEY        FAILED ****
>> GETTING VALID KEY    PASSED
>> GETTING INVALID KEY  PASSED
>> ***CHECKING SIZE (4)    FAILED ****
>> REMOVING KEY         PASSED
>> ***GETTING INVALID KEY  FAILED ****
>> GETTING VALID KEY    PASSED
>> ***REMOVING INVALID KEY FAILED ****
>> REMOVING KEY         PASSED
>> REMOVING KEY         PASSED
>> SERIALIZING          PASSED
*/
int main(int argc,char *argv[])
{
	map_t cool_map;
	printf("INITIALIZING MAP ...\r\n");
	map_init(&cool_map);
	printf("ADDING ENTRIES\t");
	map_put(&cool_map,"bom","bom");
	map_put(&cool_map,"bam","bam");
	printf("PASSED\r\nDUPLICATE KEY\t");
	printf("%d\r\n",map_put(&cool_map,"bom","bom"));
	printf("%d\r\n",map_size(&cool_map));
	printf("%d\r\n",map_remove(&cool_map,"fkkka"));
	printf("%s\r\n",map_get(&cool_map,"f**k"));

}
Example #7
0
FILE *
popen2 (const char *command, const char *mode)
{
#undef  popen
#if     defined _WIN32 || defined AMIGA
#define popen _popen
#endif
  int compressed = 0;
  fmode2_t fmode = FM_NORMAL;
  st_finfo_t *finfo;
  FILE *file;

  if (fh_map == NULL)
    init_fh_map ();

  file = popen (command, mode);
  if ((file = popen (command, mode)) == NULL)
    return NULL;

  finfo = &finfo_list[fmode * 2 + compressed];
  fh_map = map_put (fh_map, file, finfo);

  return file;
#undef  popen
#define popen   popen2
}
Example #8
0
File: vis.c Project: 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);
}
Example #9
0
void hdata_object_put(hdata_t data,hcchar * key,hdata_t value,InvokeTickDeclare){
	if(DATA_STRUCT_ASSET(data) && key && value && _hdata_type(data,InvokeTickArg) == HDATA_TYPE_OBJECT){
		data_t *d = (data_t *)data;
		hdata_object_tick_t * tick = hdata_object_tick_alloc(key,value,InvokeTickArg);
		hdata_object_tick_dealloc(map_put(d->value.object_value, tick->key, tick),InvokeTickArg);
	}
}
Example #10
0
bool socket_add(NetworkInterface* ni, uint32_t ip, uint16_t port, Socket* socket) {
	Map* sockets = ni_config_get(ni, SOCKETS);
	if(!sockets) {
		sockets = map_create(16, NULL, NULL, ni->pool);
		if(!sockets) {
			printf("Can'nt create socket table\n");
			return false;
		}

		if(!ni_config_put(ni, SOCKETS, sockets)) {
			map_destroy(sockets);
			return false;
		}
	}

	uint64_t key = (uint64_t)ip << 32 | (uint64_t)port;
	if(!map_put(sockets, (void*)key, socket)) {
		if(map_is_empty(sockets)) {
			map_destroy(sockets);
			ni_config_remove(ni, SOCKETS);
		}
		return false;
	}

	return true;
}
Example #11
0
hint32 hdata_set_tree(hdata_set_t data_set, hdata_set_tree_key_t key,hdata_set_tree_key_t parent_key,hash_code_t key_hash,equal_t key_equal,list_compare_t comparator,hany param,InvokeTickDeclare){
	data_set_t * ds = (data_set_t *)data_set;
	hany k;
	hany pk;
	hint32 i,c;
	hdata_t items,item;
	data_set_tree_item_t * tree_item,*tree_pitem;
	data_set_tree_item_compare_param_t compare_param;
	if(ds && key && parent_key){
		data_set_tree_item_dealloc(ds->tree_root,InvokeTickArg);
		ds->tree_root = data_set_tree_item_alloc( NULL, ext_data(ds->data),NULL,NULL,NULL,InvokeTickArg);
		ds->tree_level = 0;
		if(ds->tree_cache == NULL){
			ds->tree_cache = map_alloc( key_hash, key_equal);
		}
		else{
			map_clear(ds->tree_cache);
		}
		items = ext_data(ds->data);
		c = hdata_array_size(ext_data_class(ds->data), items);
		for(i=0;i<c;i++){
			item = hdata_array(ext_data_class(ds->data),items,i);
			k = (*key)(data_set,item,param,InvokeTickArg);
			pk = (*parent_key)(data_set,item,param,InvokeTickArg);
			tree_pitem = map_get(ds->tree_cache, pk);
			tree_item = data_set_tree_item_alloc( k, item, tree_pitem == NULL?ds->tree_root:tree_pitem,comparator,param,InvokeTickArg);
			data_set_tree_item_dealloc( map_put(ds->tree_cache, k, tree_item),InvokeTickArg);
			if(ds->tree_level < tree_item->level){
				ds->tree_level = tree_item->level;
			}
		}
		c = list_count(ds->tree_root->childs);
		for(i=0;i<c;i++){
			tree_item = list_get(ds->tree_root->childs, i);
			pk = (*parent_key)(data_set,tree_item->data,param,InvokeTickArg);
			tree_pitem = map_get(ds->tree_cache, pk);
			if(tree_pitem){
				list_remove_at(ds->tree_root->childs, i--);
				c = list_count(ds->tree_root->childs);
				if(tree_pitem->childs==NULL){
					tree_pitem->childs = list_alloc(20, 20);
				}
				if(comparator){
					compare_param.compare = comparator;
					compare_param.param = param;
					list_add_and_order(tree_pitem->childs, tree_item, data_set_tree_item_compare, &compare_param);
				}
				else{
					list_add(tree_pitem->childs,tree_item);
				}
				tree_item->level = tree_pitem->level +1;
				if(ds->tree_level < tree_item->level){
					ds->tree_level = tree_item->level;
				}
			}	
		}
		return ds->tree_level;
	}
	return 0;
}
Example #12
0
Service* service_alloc(Endpoint* service_endpoint) {
	bool service_add(NetworkInterface* ni, Service* service) {
		Map* services = ni_config_get(ni, SERVICES);
		if(!services) {
			services = map_create(16, NULL, NULL, ni->pool);
			if(!services)
				return false;
			if(!ni_config_put(ni, SERVICES, services))
				return false;
		}

		uint64_t key = (uint64_t)service->endpoint.protocol << 48 | (uint64_t)service->endpoint.addr << 16 | (uint64_t)service->endpoint.port;

		if(!map_put(services, (void*)key, service)) {
			if(map_is_empty(services)) {
				ni_config_remove(ni, SERVICES);
				map_destroy(services);
			}

			return false;
		} 
		printf("here???\n");

		return true;
	}
Example #13
0
Error *context_interpret(Context *context, const char *str)
{
	Value *value;
	if (context->defining_variable) {  // 変数定義
		context->defining_variable = FALSE;
		value = value_new_symbol(str);
		if (NULL == value) {  // エラー (変数名不正など)
			return error_new(IllegalVariableError, NULL);
		}
		map_put(context->map, value_symbol_name(value), value);
	} else if (str_is_integer(str)) {  // 整数
		value = value_new_integer_str(str);
		stack_push(context->stack, value);
	} else if (0 == strcmp(str, "VARIABLE")) {  // 変数定義の開始
		context->defining_variable = TRUE;
	} else if (NULL != (value = context_resolve(context, str))) {  // シンボル
		ForshFunc *func;
		switch (value->type) {
		case TYPE_FUNCTION:
			func = value_function(value);
			return func(context->stack);
		default:
			stack_push(context->stack, value);
			break;
		}
	} else {
		fprintf(stderr, "Failed to interpret: %s\n", str);
	}
	return NULL;
}
Example #14
0
void new_symbol_expr_guess(const char *symbol, struct expr *arg)
{
    /* Set a soft symbol only if it is not set */
    if(map_get(s->guesses, symbol) == NULL)
    {
        map_put(s->guesses, symbol, arg);
    }
}
Example #15
0
static void test_map_stack(void) {
    Map *m1 = make_map(NULL);
    map_put(m1, "x", (void *)1);
    map_put(m1, "y", (void *)2);
    assert_int(1, (int)(intptr_t)map_get(m1, "x"));

    Map *m2 = make_map(m1);
    assert_int(1, (int)(intptr_t)map_get(m2, "x"));
    map_put(m2, "x", (void *)3);
    assert_int(3, (int)(intptr_t)map_get(m2, "x"));
    assert_int(1, (int)(intptr_t)map_get(m1, "x"));

    MapIter *iter = map_iter(m2);
    assert_string("x", map_next(iter, NULL));
    assert_string("y", map_next(iter, NULL));
    assert_null(map_next(iter, NULL));
}
Example #16
0
void
start_ticker(CONFIG* cfg, int count)
{
	CONS* actor;
	CONS* state;
	CONS* msg;
	
	DBUG_ENTER("start_ticker");
	DBUG_PRINT("", ("count=%d", count));
	state = map_put(NIL, ATOM("count"), NUMBER(count));
	actor = CFG_ACTOR(cfg, each_second, state);
	
	state = map_put(NIL, ATOM("sec"), actor);
	msg = map_put(NIL, ATOM("time"), tick_time());
	CFG_SEND(cfg, CFG_ACTOR(cfg, time_ticker, state), msg);
	DBUG_RETURN;
}
Example #17
0
File: prtzl.c Project: gl2483/prtzl
struct node* insert_vertex(struct graph* g, char* label){

	struct node* new_vert = _init_vertex(label);

	map_put(g->vertices, label, new_vert);

	return new_vert;

}
Example #18
0
SDL_Surface*
graphics_load(graphics g, char* file_name) {
  struct graphics_t *gfx = g;
  if (!map_contains(gfx->sprite_sheets, file_name)) {
    map_put(gfx->sprite_sheets, file_name, IMG_Load(file_name),
        sizeof(SDL_Surface));
  }
  return map_get(gfx->sprite_sheets, file_name);
}
Example #19
0
void new_symbol_expr(const char *symbol, struct expr *arg)
{
    if(map_put(s->sym_table, symbol, arg) != NULL)
    {
        /* error, symbol redefinition not allowed */
        LOG(LOG_ERROR, ("not allowed to redefine symbol %s\n", symbol));
        exit(1);
    }
}
Example #20
0
File: sam.c Project: ewqasd200g/vis
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;
}
Example #21
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);
}
Example #22
0
static void test_map(void) {
    Map *m = make_map(NULL);
    assert_null(map_get(m, "abc"));

    // Insert 10000 values
    for (int i = 0; i < 10000; i++) {
        char *k = format("%d", i);
        map_put(m, k, (void *)(intptr_t)i);
        assert_int(i, (int)(intptr_t)map_get(m, k));
    }

    // Insert again
    for (int i = 0; i < 1000; i++) {
        char *k = format("%d", i);
        map_put(m, k, (void *)(intptr_t)i);
        assert_int(i, (int)(intptr_t)map_get(m, k));
    }

    // Verify that the iterator iterates over all the elements
    {
	bool x[10000];
	for (int i = 0; i < 10000; i++)
	    x[i] = 0;
	MapIter *iter = map_iter(m);
	void *v;
	char *k = map_next(iter, &v);
	for (; k; k = map_next(iter, &v)) {
	    int i = (intptr_t)v;
	    x[i] = 1;
	}
	for (int i = 0; i < 10000; i++)
	    assert_true(x[i] == 1);
    }

    // Remove them
    for (int i = 0; i < 10000; i++) {
        char *k = format("%d", i);
        assert_int(i, (intptr_t)map_get(m, k));
        map_remove(m, k);
        assert_null(map_get(m, k));
    }
}
Example #23
0
int main() {
	void* Map = map_create();
	void* MapF = map_create_func();
	
	printf("Simple map operation\n");
	map_put(Map, 1, "Test 1");
	map_get(Map, 1);
	map_put(Map, 2, "Test 2");
	map_get(Map, 2);
	printf("\n");

	printf("Map function pointer operation\n");
	map_put_func(MapF, "Marco", &f);
	map_get_func(MapF, "Marco");
	printf("\n");
	
	map_destroy(Map);
	map_destroy(MapF);
	return 0;
}
Example #24
0
void map_drawTile(_S_MAP_OBJECT *pObj, int posX, int posY, _S_MAP_OBJECT *pTarget)
{
    for( int i = 0 ; i < pObj->m_header.m_nHeight ; i++)
    {
        for(int j = 0 ; j < pObj->m_header.m_nWidth ; j++)
        {
            map_put(pTarget, j + posX, i + posY, 
            pObj->m_pBuf[(i * pObj->m_header.m_nWidth) + j]);
        }
    }
}
Example #25
0
File: websh.c Project: zhemao/websh
void setheader(vector * vec){
	char * header, * value;
	vector * subvec;
	if(vec->length > 2){
		header = vector_get(vec, 1);
		subvec = subvector(vec, 2, vec->length);
		value = str_join((char**)subvec->data, "", subvec->length);
		map_put(headers, header, value, strlen(value)+1);
		destroy_vector(subvec);
		free(value);
	}
}
Example #26
0
map_t map_put(map_t map, key_t key, value_t value){
 	if (map == NULL){
        map = calloc(1, sizeof(struct _node_t));
        map->leftnode = NULL;
        map->key = key;
        map->value = value;
        map->rightnode = NULL;
	}
	else if(string_eq(map->key, key)){
        string_destroy(map->value);		
        map->value = value;
        string_destroy(map->key);		
        map->key = key;
		}
		else if(string_less(key, map->key)){
				map->leftnode = map_put(map->leftnode, key, value);
		    }
			else {
				map->rightnode = map_put(map->rightnode, key, value);
			}
	return map;
}
Example #27
0
static message_fifo_t *add_fifo(receiver_t *self, atom_t a)
{
    message_fifo_t *fifo = get_fifo(self, a);

    TRACE2("adding fifo: '%s'\n", atom_get_cstring_value(a));
    if (!fifo) {
        fifo = message_fifo_instantiate_toplevel(NULL);
        fifo->atom = a;
        fifo->end = NULL;
        map_put(&self->fifos, (unsigned long)a, fifo);
    }

    return fifo;
}
Example #28
0
void
test_sample(CONFIG* cfg)
{
	CONS* actor;
	CONS* state;
	CONS* msg;

	DBUG_ENTER("test_sample");
	TRACE(printf("--test_sample--\n"));
	state = map_put(NIL, ATOM("text"), ATOM("Actor"));
	actor = CFG_ACTOR(cfg, say_hello, state);
	
	msg = map_put(NIL, ATOM("name"), ATOM("World!"));
	CFG_SEND(cfg, actor, msg);
	
	msg = NIL;
	msg = map_put(msg, ATOM("name"), NUMBER(42));
	msg = map_put(msg, ATOM("addr"), actor);
	CFG_SEND(cfg, actor, msg);
	
	report_configuration(cfg);
	DBUG_RETURN;
}
Example #29
0
void malloced(void* caller, size_t size, void* ptr) {
	debug_malloc_count++;
	if(is_debug) {
		is_debug = false;
		
		if(!map_contains(statistics, caller)) {
			Stat* stat = malloc(sizeof(Stat));
			stat->count = 0;
			stat->size = 0;
			map_put(statistics, caller, stat);
		}
		
		Stat* stat = map_get(statistics, caller);
		stat->count++;
		stat->size += size;
		
		Trace* trace = malloc(sizeof(Trace));
		trace->caller = caller;
		trace->size = size;
		map_put(tracing, ptr, trace);
		
		is_debug = true;
	}
}
Example #30
0
File: gen.c Project: 4ker/8cc
static void maybe_print_source_line(char *file, int line) {
    if (!dumpsource)
        return;
    char **lines = map_get(source_lines, file);
    if (!lines) {
        lines = read_source_file(file);
        if (!lines)
            return;
        map_put(source_lines, file, lines);
    }
    int len = 0;
    for (char **p = lines; *p; p++)
        len++;
    emit_nostack("# %s", lines[line - 1]);
}