Beispiel #1
0
static void test_unstr_reverse(void)
{
	unstr_t *ret = 0;
	unstr_t *tmp = 0;
	unstr_t *emp = unstr_init_memory(1);
	unstr_t *source1 = unstr_init("1234567890");
	unstr_t *source2 = unstr_init("123456789");

	ret = unstr_reverse(NULL);
	check_null(ret);
	unstr_free(ret);
	ret = unstr_reverse(emp);
	check_null(ret);
	unstr_free(ret);

	ret = unstr_reverse(source1);
	check_unstr_char(ret, "0987654321");
	unstr_free(ret);

	ret = unstr_reverse(source2);
	check_unstr_char(ret, "987654321");
	unstr_free(ret);

	ret = unstr_reverse(source1);
	tmp = unstr_reverse(ret);
	check_unstr(source1, tmp);
	unstr_free(ret);
	unstr_free(tmp);

	unstr_delete(5, source1, source2, ret, emp, tmp);
}
Beispiel #2
0
static void test_unstr_explode(void)
{
	size_t i = 0;
	size_t len = 0;
	unstr_t *str = unstr_init("1 2 3 4 5 6 7 8 9 0 ");
	char *delim = " ";
	char *ans[11] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", ""};
	unstr_t *emp = unstr_init_memory(1);
	unstr_t **ret = 0;
	check_null(unstr_explode(NULL, delim, &len));
	check_null(unstr_explode(emp, delim, &len));
	check_null(unstr_explode(str, NULL, &len));
	check_null(unstr_explode(str, "", &len));
	check_null(unstr_explode(str, delim, NULL));

	len = 1234;
	ret = unstr_explode(str, delim, &len);
	check_assert(len < 1234);
	for(i = 0; i < len; i++){
		check_unstr_char(ret[i], ans[i]);
		unstr_free(ret[i]);
	}
	unstr_delete(2, str, emp);
	free(ret);
}
Beispiel #3
0
static void test_unstr_itoa(void)
{
	unstr_t *ret = 0;

	ret = unstr_itoa(0, 1);
	check_null(ret);
	unstr_free(ret);
	ret = unstr_itoa(0, 37);
	check_null(ret);
	unstr_free(ret);

	ret = unstr_itoa(1234567890, 2);
	check_unstr_char(ret, "1001001100101100000001011010010");
	unstr_free(ret);

	ret = unstr_itoa(1234567890, 10);
	check_unstr_char(ret, "1234567890");
	unstr_free(ret);

	// マイナス対応は今のところ10進数のみ
	ret = unstr_itoa(-1234567890, 10);
	check_unstr_char(ret, "-1234567890");
	unstr_free(ret);

	ret = unstr_itoa(1234567890, 16);
	check_unstr_char(ret, "499602d2");
	unstr_free(ret);

	unstr_free(ret);
}
Beispiel #4
0
int lp_parse(lp_parse_env* lp_p)
{
	check_null(lp_p, LP_FAIL);
	check_null(lp_p->token_list, LP_FAIL);
	
	while(lp_p->read_inx < lp_p->token_list->list_len)
	{
		lp_token* lp_t = lp_at_token(lp_p);
		assert(lp_t);
		switch(lp_t->type)
		{
		case t_Kmessage:
			check_fail(lp_parse_message(lp_p, NULL), LP_FAIL);
			break;
		case t_Kextern:
			check_fail(lp_parse_extern(lp_p), LP_FAIL);
			break;
		default:
			print("parse[error line: %d] the error token!\n", lp_t->line);
			return LP_FAIL;
		}
	}

	return LP_TRUE;
}
Beispiel #5
0
void
astar_heap_add (asheap_t * heap, uint32_t val, square_t * square)
{
	assert (heap != NULL);

	// Is is full?
	if (heap->length == heap->alloc) {
		heap->alloc += heap->delta;
		heap->data = (uint32_t *) realloc (heap->data, sizeof (uint32_t) * heap->alloc);
		check_null (heap->data, "heap_add(), growing data block");
		heap->squares = (square_t **) realloc (heap->squares,
						       sizeof (square_t *) * heap->alloc);
		check_null (heap->squares, "heap_add(), growing payload block");
	}

	// Is it empty? Trivial case.
	if (heap->length == 0) {
		heap->data[0] = val;
		heap->squares[0] = square;
		heap->length = 1;
		return;
	}

	// Stick the new value at the end.
	heap->data [heap->length] = val;
	heap->squares [heap->length] = square;

	// Bubble up.
	register uint32_t parent_val, parent_ofs;
	register uint32_t i = heap->length;
	void * parent_payload;
	while (i > 0) {

		// Get parent value.
		parent_ofs = PARENT_OF(i);
		parent_val = heap->data [parent_ofs];
		parent_payload = heap->squares [parent_ofs];
		
		// If the parent is greater then val, swap them.
		if (parent_val > val) {
			heap->data [i] = parent_val;
			heap->data [parent_ofs] = val;

			heap->squares [i] = parent_payload;
			heap->squares [parent_ofs] = square;

			// Loop again.
			i = parent_ofs;
		} else {
			// Not greater, end bubbling up.
			break;
		}
	}

	// Increase the number of elements.
	heap->length++;
}
Beispiel #6
0
int get_parse_env(lp_parse_env* lp_p, lp_list* token_list)
{
	check_null(lp_p, LP_FAIL);
	check_null(token_list, LP_FAIL);
	lp_list_new(&lp_p->parse_out, sizeof(byte), NULL, NULL);
	lp_table_new(&lp_p->parse_table);
	
	lp_p->mes_name = lp_string_new("");
	lp_p->token_list = token_list;
	lp_p->read_inx = 0;
	lp_p->line = 0;
	return LP_TRUE;
}
Beispiel #7
0
int ilG_trackPositionable(ilG_context* ctx, il_positionable* self)
{
#define check_null(n) if(!n) {il_error("Null " #n); return 0; }
    // make sure we have valid parameters, several bugs have been caught here
    check_null(ctx);
    check_null(self);
    //check_null(ctx->world);
    //check_null(ctx->world->id);
    check_null(self->drawable);
    check_null(self->material);
    check_null(self->texture);
    check_null(self->drawable->id);
    check_null(self->material->id);
    check_null(self->texture->id);
#undef check_null

    unsigned int i;
    for (i = 0; i < ctx->positionables.length; i++) {
        il_positionable* pos = ctx->positionables.data[i];
        if (pos->drawable->id > self->drawable->id) goto insert;
        if (pos->material->id > self->material->id) goto insert;
        if (pos->texture->id  > self->texture->id)  goto insert;
        continue;
insert:
        IL_INSERT(ctx->positionables, i, self);
        return 1;
    }
    // if we even reach here it means that there are no other drawable-material-texture pairs in the list
    IL_APPEND(ctx->positionables, self);
    return 1;
}
Beispiel #8
0
struct a2_io*  a2_io_open(struct a2_env* env_p, const char* file_name){
	struct a2_io* ret = NULL;
	FILE* fp = NULL;
	check_null(file_name, NULL);
	fp  = fopen(file_name, "rb");
	if(fp == NULL) {
		a2_error(env_p, e_io_error, "[io error]: the file is null!\n");
		return NULL;
	}
	ret = (struct a2_io*)malloc(sizeof(*ret));
	ret->env_p = env_p;
	ret->size = MAX_IO_BUFFER;
	ret->buf = (byte*)malloc(sizeof(byte)*MAX_IO_BUFFER);

	fseek(fp, 0L, SEEK_END);
	ret->len = ftell(fp);
	fseek(fp, 0L, SEEK_SET);
	ret->fp = fp;
	ret->seek = 0;
	ret->rsize = 0;
	size_t len = fread(ret->buf, sizeof(byte), ret->size, ret->fp);
	if(len<=0)
		a2_error(env_p, e_io_error, "io error.\n");
	return ret;
}
void script_command_parser::add_script_command(std::string& input) {
    std::transform(input.begin(), input.end(), input.begin(), ::tolower);

    std::regex check_binary(".*b:.+?\\s(.+?)\\s.+");
    std::smatch matches;
    if (std::regex_match(input, matches, check_binary)) {
        if (isscript_command((std::string)matches[1], script_command::Type::LEFT_RIGHT)) { return; }
        script_command command = script_command(matches[1], script_command::Type::LEFT_RIGHT);
        commands.push_back(command);
    }
    else {
        std::regex check_unary(".*u:(.+)?\\s.+");
        if (std::regex_match(input, matches, check_unary)) {
            if (isscript_command((std::string)matches[1], script_command::Type::RIGHT)) { return; }
            script_command command = script_command(matches[1], script_command::Type::RIGHT);
            commands.push_back(command);
        } 
        else {
            std::regex check_null(".*n:(.+)");
            if (std::regex_match(input, matches, check_null)) {
                if (isscript_command((std::string)matches[1], script_command::Type::NONE)) { return; }
                script_command command = script_command(matches[1], script_command::Type::NONE);
                commands.push_back(command);
            }
        }
    }
}
Beispiel #10
0
void test_default_ctor()
{
    const any value;

    check_true(value.empty(), "empty");
    check_null(any_cast<int>(&value), "any_cast<int>");
    check_equal(value.type(), typeid(void), "type");
}
Beispiel #11
0
asheap_t *
astar_heap_new (uint32_t initial_length, uint32_t delta)
{
	asheap_t * heap = (asheap_t *) malloc (sizeof (asheap_t));
	check_null (heap, "heap_new(), allocating memory");

	// Set initial values.
	heap->length = 0;
	heap->delta = delta;
	heap->alloc = initial_length;
	heap->data = (uint32_t *) malloc (sizeof (uint32_t) * heap->alloc);
	check_null (heap->data, "heap_new(), allocating data block");
	heap->squares = (square_t **) malloc (sizeof (square_t *) * heap->alloc);
	check_null (heap->squares, "heap_new(), allocating payload block");

	return heap;
}
Beispiel #12
0
static void test_unstr_strstr_char(void)
{
	char *ret = 0;
	char *ans1 = "4567890";
	char *ans2 = "7890";
	char *s1 = "45";
	char *s2 = "7890";
	char *s3 = "hoge";
	unstr_t *str = unstr_init("1234567890");
	unstr_t *emp = unstr_init_memory(1);
	check_null(unstr_strstr_char(NULL, s1));
	check_null(unstr_strstr_char(NULL, ""));
	check_null(unstr_strstr_char(str, NULL));
	check_null(unstr_strstr_char(emp, NULL));
	check_null(unstr_strstr_char(str, ""));
	check_null(unstr_strstr_char(emp, s1));
	check_null(unstr_strstr_char(str, s3));

	ret = unstr_strstr_char(str, s1);
	check_assert(ret != NULL);
	check_char(ret, ans1);

	ret = unstr_strstr_char(str, s2);
	check_assert(ret != NULL);
	check_char(ret, ans2);

	unstr_delete(2, str, emp);
}
Beispiel #13
0
int llp_out_close(slice* out)
{
	check_null(out, LP_FAIL);
	if(out->b_sp)
		free(out->b_sp);
	memset(out, 0, sizeof(*out));

	return LP_TRUE;
}
Beispiel #14
0
static int sl_relloc(slice* sl)
{
	byte* re_p = (byte*)realloc(sl->b_sp, sl->sp_size+EXT_SLI_LENS);
	check_null(re_p, LP_FAIL);
	sl->sp = re_p+(sl->sp-sl->b_sp);
	sl->b_sp = re_p;
	sl->sp_size += EXT_SLI_LENS;
	return LP_TRUE;
}
Beispiel #15
0
int lp_parse_push(lp_parse_env* lp_p, void* data, unsigned int len)
{
	unsigned int i=0;
	check_null(data, LP_FAIL);
	
	for(i=0; i<len; i++)
		lp_list_add(&lp_p->parse_out, ((byte*)data)+i);
	return LP_TRUE;
}
Beispiel #16
0
int read_file(char* file_name, slice* sp)
{
	FILE* fp = NULL;
	long fs = 0;
	
	check_null(file_name, (print("parse file not exist!\n"), LP_FAIL));
	fp = fopen(file_name, "rb");
	fs = f_size(fp);
	check_null(fp, (print("read file: %s is error!\n", file_name), LP_FAIL));
	sp->sp_size = (size_t)fs + 2;
	sp->sp = (byte*)malloc(sp->sp_size);
	memset(sp->sp, 0, sp->sp_size);
	sp->b_sp = sp->sp;
	
	if(fread(sp->sp, sizeof(char), sp->sp_size, fp) <0)
		return LP_FAIL;
	return LP_TRUE;
}
Beispiel #17
0
int free_parse_env(lp_parse_env* lp_p)
{
	check_null(lp_p, LP_FAIL);
	
	lp_list_free(&lp_p->parse_out);
	lp_table_free(&lp_p->parse_table);
	lp_string_free(&lp_p->mes_name);

	return LP_TRUE;
}
Beispiel #18
0
static void test_unstr_replace(void)
{
	unstr_t *ret = 0;
	unstr_t *emp = unstr_init_memory(1);
	unstr_t *data = unstr_init_memory(1);
	unstr_t *search = unstr_init_memory(1);
	unstr_t *replace = unstr_init_memory(1);

	unstr_strcpy_char(data, "unkokkokokkokokkokokekokko");
	unstr_strcpy_char(search, "ko");
	unstr_strcpy_char(replace, "unko");

	ret = unstr_replace(NULL, search, replace);
	check_null(ret);
	unstr_free(ret);
	ret = unstr_replace(emp, search, replace);
	check_null(ret);
	unstr_free(ret);
	ret = unstr_replace(data, NULL, replace);
	check_null(ret);
	unstr_free(ret);
	ret = unstr_replace(data, emp, replace);
	check_null(ret);
	unstr_free(ret);
	ret = unstr_replace(data, search, NULL);
	check_null(ret);
	unstr_free(ret);

	unstr_strcpy_char(data, "unkokkokokkokokkokokekokko");
	unstr_strcpy_char(search, "ko");
	unstr_strcpy_char(replace, "unko");

	ret = unstr_replace(data, search, emp);
	check_unstr_char(ret, "unkkkkek");
	unstr_free(ret);

	ret = unstr_replace(data, search, replace);
	check_unstr_char(ret, "ununkokunkounkokunkounkokunkounkokeunkokunko");
	unstr_free(ret);

	unstr_delete(5, ret, emp, data, search, replace);
}
Beispiel #19
0
static void test_unstr_repeat_char(void)
{
	unstr_t *ret = 0;
	char *str = "unko";

	ret = unstr_repeat_char(NULL, 10);
	check_null(ret);
	unstr_free(ret);
	ret = unstr_repeat_char("", 10);
	check_null(ret);
	unstr_free(ret);
	ret = unstr_repeat_char(str, 0);
	check_null(ret);
	unstr_free(ret);

	ret = unstr_repeat_char(str, 5);
	check_unstr_char(ret, "unkounkounkounkounko");
	unstr_free(ret);

	unstr_free(ret);
}
Beispiel #20
0
static void test_unstr_repeat(void)
{
	unstr_t *ret = 0;
	unstr_t *emp = unstr_init_memory(1);
	unstr_t *str = unstr_init("unko");

	ret = unstr_repeat(NULL, 10);
	check_null(ret);
	unstr_free(ret);
	ret = unstr_repeat(emp, 10);
	check_null(ret);
	unstr_free(ret);
	ret = unstr_repeat(str, 0);
	check_null(ret);
	unstr_free(ret);

	ret = unstr_repeat(str, 5);
	check_unstr_char(ret, "unkounkounkounkounko");
	unstr_free(ret);

	unstr_delete(3, ret, emp, str);
}
Beispiel #21
0
static void test_unstr_copy(void)
{
	unstr_t *tmp = 0;
	unstr_t *str = unstr_init("1234567890");
	tmp = unstr_copy(NULL);
	check_null(tmp);
	unstr_free(tmp);

	tmp = unstr_copy(str);
	check_int(unstr_strlen(str), unstr_strlen(tmp));
	check_unstr(str, tmp);

	unstr_delete(2, str, tmp);
}
Beispiel #22
0
int  llp_out_open(slice* out)
{
	check_null(out, LP_FAIL);
	if(out->sp_size == 0)
	{
		out->sp = (byte*)malloc(EXT_SLI_LENS*sizeof(byte));
		out->b_sp = out->sp;
		out->sp_size = EXT_SLI_LENS;
	}
	else
		llp_out_clr(out);

	return LP_TRUE;
}
Beispiel #23
0
static void test_unstr_strtok(void)
{
	size_t index = 0;
	size_t i = 0;
	unstr_t *ret = 0;
	unstr_t *emp = unstr_init_memory(1);
	unstr_t *text = unstr_init("1<>2<>3<>4<>5<>6<>7<>8<>9<>0");
	char *search = "<>";
	char *ans[11] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", ""};

	ret = unstr_strtok(NULL, search, &index);
	check_null(ret);
	unstr_free(ret);
	ret = unstr_strtok(emp, search, &index);
	check_null(ret);
	unstr_free(ret);
	ret = unstr_strtok(text, NULL, &index);
	check_null(ret);
	unstr_free(ret);
	ret = unstr_strtok(text, "", &index);
	check_null(ret);
	unstr_free(ret);
	ret = unstr_strtok(text, search, NULL);
	check_null(ret);
	unstr_free(ret);

	i = 0;
	index = 0;
	while((ret = unstr_strtok(text, search, &index)) != NULL){
		check_unstr_char(ret, ans[i]);
		unstr_free(ret);
		i++;
	}
	check_int(i, 10);

	unstr_delete(3, ret, emp, text);
}
Beispiel #24
0
static void test_unstr_init(void)
{
	char *s = "1234567890";
	unstr_t *str = 0;
	{
		str = unstr_init(NULL);
		check_null(str);
		unstr_free(str);
	}{
		str = unstr_init(s);
		check_int(unstr_strlen(str), 10);
		check_unstr_char(str, s);
		unstr_free(str);
	}
}
Beispiel #25
0
void test_converting_ctor()
{
    stl::string text = "test message";
    any value (text);

    check_false(value.empty(), "empty");
    check_equal(value.type(), typeid(stl::string), "type");
    check_null(any_cast<int>(&value), "any_cast<int>");
    check_non_null(any_cast<stl::string>(&value), "any_cast<stl::string>");
    check_equal(
        any_cast<stl::string>(value), text,
        "comparing cast copy against original text");
    check_unequal(
        any_cast<stl::string>(&value), &text,
        "comparing address in copy against original text");
}
Beispiel #26
0
void test_converting_assign()
{
    stl::string text = "test message";
    any value;
    any * assign_result = &(value = text);

    check_false(value.empty(), "type");
    check_equal(value.type(), typeid(stl::string), "type");
    check_null(any_cast<int>(&value), "any_cast<int>");
    check_non_null(any_cast<stl::string>(&value), "any_cast<stl::string>");
    check_equal(
        any_cast<stl::string>(value), text,
        "comparing cast copy against original text");
    check_unequal(
        any_cast<stl::string>(&value),
        &text,
        "comparing address in copy against original text");
    check_equal(assign_result, &value, "address of assignment result");
}
Beispiel #27
0
static int lp_parse_extern(lp_parse_env* lp_p)
{
	check_null(lp_p, LP_FAIL);
	lp_watch(lp_p, t_Kextern);

	for(;;)
	{
		lp_token* lp_t;
		lp_string mes = lp_string_new("");
		
		if(lp_parse_mes(lp_p, &mes) ==LP_FAIL)
		{
			lp_string_free(&mes);
			return LP_FAIL;
		}
		
		if(lp_table_add(&lp_p->parse_table, (char*)mes.str.list_p, fmes_extern) == LP_EXIST)
		{
			print("parse[error line:%d] the extern message name \"%s\" is already def!\n", 
				  lp_p->line, (char*)mes.str.list_p);
			lp_string_free(&mes);
			return LP_FAIL;
		}

		lp_string_free(&mes);
		if( (lp_t=lp_at_token(lp_p))==NULL )
			lp_check(lp_p, t_end);
		
		switch(lp_t->type)
		{
		case t_end:
			lp_watch(lp_p, t_end);
			goto E_END;
		case t_ca:
		default:
			lp_watch(lp_p, t_ca);
			break;
		}
	}

E_END:
	return LP_TRUE;
}
Beispiel #28
0
static void test_unstr_init_memory(void)
{
	unstr_t *str = 0;
	size_t size = 0;
	{
		str = unstr_init_memory(0);
		check_null(str);
		unstr_free(str);
	}{
		size = 10;
		str = unstr_init_memory(size);
		check_assert(str->heap >= size);
		unstr_free(str);
	}{
		size = 1024 * 1024 * 1024;
		str = unstr_init_memory(size);
		check_assert(str->heap >= size);
		unstr_free(str);
	}
}
Beispiel #29
0
		void add_reserved_word(std::string input_) {
			std::regex check_binary(".*b:.+?\\s(.+?)\\s.+");
			std::smatch matches;
			if (std::regex_match(input_, matches, check_binary)) {
				reserved_words.insert(matches[1]);
			}
			else {
				std::regex check_unary(".*u:(.+)?\\s.+");
				if (std::regex_match(input_, matches, check_unary)) {
					reserved_words.insert(matches[1]);
				}
				else {
					std::regex check_null(".*n:(.+)");
					if (std::regex_match(input_, matches, check_null)) {
						reserved_words.insert(matches[1]);
					}
				}
			}
            script_command_parser::add_script_command(input_);
		}
Beispiel #30
0
void display(const char* lbl, Morph obj) {
    const size_t len = alt::length(obj);
    printf("%s %i: { ", lbl, len); fflush(stdout);
    if (len == 0) {printf("NONE");}
    else { void* p;
        for (size_t i=0; i<len;) {
            p = alt::getter(obj, i);
            if (p != NULL) {
                if (check_null(p, alt::sizes(obj, i, false) * alt::sizes(obj, i, true))) {
                    printf("....");
                } else {
                    switch (alt::typer(obj, i)) {
                        case 0: {
                            printf("NULL");
                            break;
                        }
                        case 1: {
                            printf("%c", (*((char *)p)));
                            break;
                        }
                        case 3: {
                            printf("%d", (*((int  *)p)));
                            break;
                        }
                        case 5: {
                            printf("%f", (*((float*)p)));
                        }
                    }
                }
                if (++i != len) {printf(" , ");}
            } else {
                printf("null");
                i++;
            }
            fflush(stdout);
        }
    }
    printf(" }\n");
    fflush(stdout);
}