Esempio n. 1
0
static void
set_enum_one(struct pbc_env *p, struct file_t *file, const char *name, int start, int sz) {
	struct map_kv *table = malloc(sz * sizeof(struct map_kv));
	int i;
	for (i=0;i<sz;i++) {
		pbc_var id;
		pbc_var string;
		_pbcA_index(file->enum_id, start+i, id);
		_pbcA_index(file->enum_string, start+i, string);
		table[i].id = (int)id->integer.low;
		table[i].pointer = (void *)string->s.str;
	}
	_pbcP_push_enum(p,name,table,sz);

	free(table);
}
Esempio n. 2
0
static void
_register_enum(struct pbc_env *p, struct _stringpool *pool, struct pbc_rmessage * enum_type, const char *prefix, int prefix_sz) {
	int field_count = pbc_rmessage_size(enum_type, "value");
	struct map_kv *table = malloc(field_count * sizeof(struct map_kv));
	int i;
	for (i=0;i<field_count;i++) {
		struct pbc_rmessage * value = pbc_rmessage_message(enum_type, "value", i);
		int enum_name_sz;
		const char *enum_name = pbc_rmessage_string(value , "name" , 0 , &enum_name_sz);
		table[i].pointer = (void *)_pbcS_build(pool, enum_name , enum_name_sz);
		table[i].id = pbc_rmessage_integer(value , "number", 0 , 0);
	}
	int name_sz;
	const char * name = pbc_rmessage_string(enum_type, "name", 0 , &name_sz);
	const char *temp = _concat_name(pool, prefix , prefix_sz , name , name_sz, NULL);

	_pbcP_push_enum(p,temp,table,field_count);
	free(table);
}