Esempio n. 1
0
static bool match(UChar **items, int32_t *item_lengths, uint32_t item_count, UChar *needle, Match *match_results, int32_t *final_positions, int32_t needle_char_len, UChar *level1, UChar *level2, UChar *level3) {
    Stack stack = {0};
    int32_t i = 0, maxhl = 0; 
    int32_t r = 0, *positions = NULL;
    MatchInfo *matches = NULL;
    bool ok = FALSE;
    MemoryItem ***memo = NULL;
    int32_t needle_len = u_strlen(needle);

    if (needle_len <= 0 || item_count <= 0) {
        for (i = 0; i < (int32_t)item_count; i++) match_results[i].score = 0.0;
        ok = TRUE;
        goto end;
    }

    matches = (MatchInfo*)calloc(item_count, sizeof(MatchInfo));
    positions = (int32_t*)calloc(2*needle_len, sizeof(int32_t)); // One set of positions is the final answer and one set is working space
    if (matches == NULL || positions == NULL) {PyErr_NoMemory(); goto end;}

    for (i = 0; i < (int32_t)item_count; i++) {
        matches[i].haystack = items[i];
        matches[i].haystack_len = item_lengths[i];
        matches[i].needle = needle;
        matches[i].needle_len = needle_len;
        matches[i].max_score_per_char = (1.0 / matches[i].haystack_len + 1.0 / needle_len) / 2.0;
        matches[i].level1 = level1;
        matches[i].level2 = level2;
        matches[i].level3 = level3;
        maxhl = MAX(maxhl, matches[i].haystack_len);
    }

    if (maxhl <= 0) {
        for (i = 0; i < (int32_t)item_count; i++) match_results[i].score = 0.0;
        ok = TRUE;
        goto end;
    }

    alloc_stack(&stack, needle_len, maxhl);
    memo = alloc_memory(needle_len, maxhl);
    if (stack.items == NULL || memo == NULL) {PyErr_NoMemory(); goto end;}

    for (i = 0; i < (int32_t)item_count; i++) {
        for (r = 0; r < needle_len; r++) {
            positions[r] = -1;
        }
        stack_clear(&stack);
        clear_memory(memo, needle_len, matches[i].haystack_len);
        matches[i].memo = memo;
        match_results[i].score = process_item(&matches[i], &stack, positions);
        convert_positions(positions, final_positions + i, matches[i].haystack, needle_char_len, needle_len, match_results[i].score);
    }

    ok = TRUE;
end:
    nullfree(positions);
    nullfree(stack.items);
    nullfree(matches);
    nullfree(memo);
    return ok;
}
Esempio n. 2
0
void delaunay(int n,LKH::LKHAlg *Alg)
{
    edge *l_cw, *r_ccw;
    point **p_sorted;
    LKH::LKHAlg::Node *N = Alg->FirstNode;
    int i, j;

    alloc_memory(n);
    for (i = 0; i < n; i++) {
        p_array.get()[i].x = N->X;
        p_array.get()[i].y = N->Y;
        p_array.get()[i].id = N->Id;
        p_array.get()[i].entry_pt = 0;
        N = N->Suc;
    }

    assert(p_sorted = (point **) malloc(n * sizeof(point *)));
    for (i = 0; i < n; i++)
        p_sorted[i] = p_array.get() + i;
    qsort(p_sorted, n, sizeof(point *), compare);

    /* Perturb duplicate points a bit in their Y-coordinate */
    for (i = 0; i < n; i++) {
        for (j = i + 1; j < n; j++)
            if ((float) p_sorted[j]->x != (float) p_sorted[i]->x ||
                (float) p_sorted[j]->y != (float) p_sorted[i]->y)
                break;
        for (j--; i < j; i++)
            p_sorted[i + 1]->y =
                nextafterf((float) p_sorted[i]->y, FLT_MAX);
    }

    divide(p_sorted, 0, n - 1, &l_cw, &r_ccw);
    free(p_sorted);
}
Esempio n. 3
0
int sw_encode_init (uint32_t width, uint32_t height, uint32_t bytes_per_pixel)
{
	int adjust = 0;

	LOG_D("%s: %d\n", __func__, __LINE__);
	/*
	dummy_buf = malloc(1024 * 1024 * 100);

	if (dummy_buf)
	{
		*(dummy_buf + 1024 * 1024 * 5) = 0xFF;
		*dummy_buf = 0xFF;
	}
	*/

	if (-1 == alloc_memory (&out_buf_ptr, MAX_BUFFER_SIZE))
	{
		LOG_D ("Malloc memory error!\n");
		return -1;
	}
	adjust = (width + 15) & 0xfffffff0;
	if (-1 == alloc_memory (&in_buf, adjust * height * bytes_per_pixel))
	{
		LOG_D ("Malloc memory error!\n");
		return -1;
	}

	if (-1 == alloc_memory (&in_buf_qcom, adjust * height * bytes_per_pixel))
	{
		LOG_D ("Malloc memory error!\n");
		return -1;
	}

	if (-1 == alloc_memory (&in_buf_rotation, adjust * height * bytes_per_pixel))
	{
		LOG_D ("Malloc memory error!\n");
		return -1;
	}

	if (-1 == alloc_memory (&rgb_buf, MAX_RGB_BUFFER))
	{
		LOG_D ("Malloc memory error!\n");
		return -1;
	}

	return 0;
}
int main(void) {
    char *** test = alloc_memory(16,32);
    
    while(1){
        zero_memory(16,32,test);
        initialize_random(16,32,test); 
        mutate(16,32,test);
        print_memory(16,32,test);
    }
	
}
void object_array::set_index(unsigned long index,void* index_data) {
    object_index* last_object_index_point=NULL;
    for (object_index* object_index_point=(object_index*)this->array_index;
                       object_index_point!=NULL;
                       object_index_point=object_index_point->next_object_index) {
        last_object_index_point=object_index_point;
        if (object_index_point->object_index_number==index) {
            memcpy(&object_index_point->object_data,index_data,sizeof(javascript_variant_struct));
            return;
        }
    }
    if (NULL!=last_object_index_point) {
        last_object_index_point->next_object_index=(object_index*)alloc_memory(sizeof(object_index));
        memset(last_object_index_point->next_object_index,0,sizeof(object_index));
    }
}
Esempio n. 6
0
char *get_ptn_size(struct fastboot_data *fb_data, char *buf, const char *ptn)
{
	int i = 0;
	int ret = 0;
	u32 sz_mb;
	u64 sz = 0;
	struct ptable *gpt;
	int sector_sz = fb_data->storage_ops->get_sector_size();
	u64 ptbl_sectors = 0;

	gpt = (struct ptable *)alloc_memory(sizeof(struct ptable));
	if (!gpt) {
		printf("Unable to alloc memory for gpt\n");
		return buf;
	}

	if (sector_sz != 512) {
		printf("Unknown sector size: %d\n", sector_sz);
		goto ptn_error;
	} else
		ptbl_sectors = sizeof(struct ptable) >> 9;

	ret = fb_data->storage_ops->read(0, ptbl_sectors, (void *)gpt);
	if (ret != 0) {
		printf("error reading primary GPT\n");
		goto ptn_error;
	}

	if (memcmp(gpt->header.magic, "EFI PART", 8)) {
		printf("efi partition table not found\n");
		goto ptn_error;
	}

	for (i = 0; i < EFI_ENTRIES; i++) {
		sz = get_entry_size_kb(&gpt->entry[i], ptn);
		if (sz)
			break;
	}

	if (sz >= 0xFFFFFFFF) {
		sz_mb = (u32)(sz >> 20);
		DBG("sz is > 0xFFFFFFFF\n");
		sprintf(buf, "0x%d MB", sz_mb);
	} else {
Esempio n. 7
0
/**
* @brief  Main routine for MSC class application
* @param  None
* @retval int
*/
int main(void)
{
	NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0xC000);//初始化启动项
	gpio_init();//初始化所有定义的gpio寄存器
	cpu_run();
	flash_stop();
//	rs485_recv();//使能485接受数据
	FLASH_ON();
	remote_init();
	LOOP_ON();//使能环流
//	uart_init(9600);//设置波特率为9600  串口初始化
	delay_ms(1);//定时器
	SPI_Flash_Init();//初始化spi flash外围驱动
	get_cfg_from_flash();//得到配置信息 (获取cfg文件的配置)
	get_line_from_flash();	 	
	message_state |= MESSAGE_LINE_NEW;
	message_state |= MESSAGE_LEFT_NEW;
	message_state |= MESSAGE_RIGHT_NEW;
	message_state |= MESSAGE_BRAKE_NEW;
	alloc_memory(); //初始化缓存
	
	wwdg_init(0x7F, 0x5F, WWDG_Prescaler_8); //计数器值为7f,窗口寄存器为5f,分频数为8 (使用窗口看门狗的原因是他可以被中断)
	while (1)
	{
		if(uart_get_flag)
		{
			uart_get_flag = 0;
			data_process();
			LED_OK = 1;
		}
		get_disp_state();		//左转右转还有刹车的判断报站;
		if(bflag)
		{
			LED_DispString(1, 1, disp_buff);    //固定显示
		}
		else
		{
			
			
			LED_ScrollDispHZ(1, 1, disp_buff);//滚动显示
		}
	}
}
Esempio n. 8
0
int load_ptbl(struct storage_specific_functions *storage, u8 silent)
{
	u32 sector_sz = storage->get_sector_size();
	u64 ptbl_sectors = 0;
	int i = 0, r = 0;

	struct ptable *gpt;
	int gpt_size = sizeof(struct ptable);

	gpt =  (struct ptable *) alloc_memory(gpt_size);
	if (!gpt) {
		r = 0;
		goto fail;
	}

	ptbl_sectors = (u64)(gpt_size / sector_sz);

	r = storage->read(0, ptbl_sectors, (void *)gpt);
	if (r != 0) {
		printf("error reading GPT\n");
		return r;
		goto fail;
	}

	if (memcmp(gpt->header.magic, "EFI PART", 8)) {
		if (!silent)
			printf("efi partition table not found\n");
		r = -1;
		goto fail;
	}

	for (i = 0; i < EFI_ENTRIES; i++)
		import_efi_partition(&gpt->entry[i], i, silent);

fail:
	free_memory((void *)gpt);
	return r;
}
Esempio n. 9
0
void		re_size_column(int signo)
{
	struct winsize	s;
	t_data			*data;

	data = NULL;
	if (signo == SIGWINCH)
	{
		if (!g_argv)
			return ;
		if (!(data = alloc_memory(data, s)))
			return ;
		ioctl(0, TIOCGWINSZ, &s);
		data = get_column(data, g_argv, (s.ws_row - 2));
		if (g_pos)
			data->pos = g_pos;
		ft_putstr(CLEAR_SCREEN);
		if (check_column_size(data, s.ws_col))
			print_columns(data, 0, 0, get_bigger(data));
		else
			ft_putstr("Windows size is too small !\n");
	}
}
Esempio n. 10
0
char* TestMemoryAllocator::allocMemoryLeakNode(size_t size)
{
    return alloc_memory(size, "MemoryLeakNode", 1);
}
Esempio n. 11
0
object_array::object_array(unsigned long init_length) {
    this->array_length=1;
    this->array_type_=OBJECT_ARRAY_CLASS;
    this->array_index=alloc_memory(sizeof(object_index)*init_length);
    memset(&this->array_index,0,sizeof(object_index)*init_length);
}
Esempio n. 12
0
object_array::object_array() {
    this->array_length=1;
    this->array_type_=OBJECT_ARRAY_CLASS;
    this->array_index=alloc_memory(sizeof(object_index));
    memset(&this->array_index,0,sizeof(object_index));
}
Esempio n. 13
0
int_array::int_array(unsigned long init_length) {
    this->array_length=init_length;
    this->array_type_=INT_ARRAY_CLASS;
    this->array_index=alloc_memory(4*init_length);
    memset(&this->array_index,0,4*init_length);
}
Esempio n. 14
0
base_array::base_array() {
    this->array_length=1;
    this->array_type_=BASE_ARRAY_CLASS;
    this->array_index=alloc_memory(4);
    *(unsigned long*)this->array_index=0;
}
static bool execute_calculation_express(string& express) {
    long next_calculation_flag=get_next_calculation_flag(express);
    if ('+'==express[next_calculation_flag]) {
        string left_express(express.substr(0,next_calculation_flag));
        trim(left_express);
        express_type left_express_type=get_express_type(left_express);
        unsigned long left_express_calcu_value=0;
        support_javascript_variant_type left_express_calcu_value_type=NONE;
        if (EXPRESSION_UNKNOW==left_express_type)  //  12kk4+321 or +321
            return false;
        if (EXPRESSION_VARIANT==left_express_type) {
            get_variant(left_express,(void*)&left_express_calcu_value,&left_express_calcu_value_type);
        } else if (EXPRESSION_EXPRESS==left_express_type) {  //  (123+321)+1
            if (!execute_calculation_express(left_express))
                return false;
            get_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)&left_express_calcu_value,&left_express_calcu_value_type);
        } else if (EXPRESSION_STRING==left_express_type) { //  'AAA'+'A'
            left_express=left_express.substr(1,left_express.length()-2);
        }
        if (NUMBER==left_express_calcu_value_type || 
            EXPRESSION_NUMBER_DECIMAL==left_express_type || EXPRESSION_NUMBER_HEX==left_express_type) {
            left_express_type=EXPRESSION_NUMBER_DECIMAL;
        } else {
            left_express_type=EXPRESSION_STRING;
        }

        string right_express(express.substr(next_calculation_flag+1));
        trim(right_express);
        express_type right_express_type=get_express_type(right_express);
        unsigned long right_express_calcu_value=0;
        support_javascript_variant_type right_express_calcu_value_type=NONE;
        if (EXPRESSION_UNKNOW==right_express_type)  //  321+12kk4 or 321+
            return false;
        if (EXPRESSION_VARIANT==right_express_type) {
            get_variant(right_express,(void*)&right_express_calcu_value,&right_express_calcu_value_type);
        } else if (EXPRESSION_EXPRESS==right_express_type) {  //  123+123+123
            if (!execute_calculation_express(right_express))
                return false;
            get_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)&right_express_calcu_value,&right_express_calcu_value_type);
        } else if (EXPRESSION_STRING==right_express_type) {  //  'AAA'+'A'
            right_express=right_express.substr(1,right_express.length()-2);
        }
        if (NUMBER==right_express_calcu_value_type || 
            EXPRESSION_NUMBER_DECIMAL==right_express_type || EXPRESSION_NUMBER_HEX==right_express_type) {
            right_express_type=EXPRESSION_NUMBER_DECIMAL;
        } else {
            right_express_type=EXPRESSION_STRING;
        }
        //  123+123 or (123+321)+123+123 or '123'+'123' or '123'+123
        if (EXPRESSION_STRING==left_express_type && EXPRESSION_STRING!=right_express_type) {
            if (NONE!=right_express_calcu_value_type) {
                string connect_string(left_express);
                connect_string+=right_express;
                set_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)connect_string.c_str(),STRING);
            } else {
                char conver_buffer[0x20]={0};
                sprintf(conver_buffer,"%d",right_express_calcu_value);
                string connect_string(left_express);
                connect_string+=conver_buffer;
                set_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)connect_string.c_str(),STRING);
            }
        } else if (EXPRESSION_STRING!=left_express_type && EXPRESSION_STRING==right_express_type) {
            if (NONE==left_express_calcu_value_type) {
                string connect_string(left_express);
                connect_string+=right_express;
                set_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)connect_string.c_str(),STRING);
            } else {
                char conver_buffer[0x20]={0};
                sprintf(conver_buffer,"%d",left_express_calcu_value);
                string connect_string(conver_buffer);
                connect_string+=right_express;
                set_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)connect_string.c_str(),STRING);
            }
        } else if (EXPRESSION_STRING==left_express_type && EXPRESSION_STRING==right_express_type) {  //  alloc in heap ..
            //string connect_string;
            unsigned long connect_string_length=0;
            if (NONE!=left_express_calcu_value_type)
                connect_string_length=strlen((char*)left_express_calcu_value);
            else
                connect_string_length=left_express.length();
            if (NONE!=right_express_calcu_value_type)
                connect_string_length+=strlen((char*)right_express_calcu_value);
            else
                connect_string_length+=right_express.length();

            char* connect_string=(char*)alloc_memory(connect_string_length+1);
            unsigned long copy_offset=0;
            if (NONE!=left_express_calcu_value_type) {
                copy_offset=strlen((char*)left_express_calcu_value);
                memcpy(connect_string,(const void*)left_express_calcu_value,copy_offset);
            } else {
                copy_offset=left_express.length();
                memcpy(connect_string,left_express.c_str(),copy_offset);
            }
            if (NONE!=right_express_calcu_value_type)
                memcpy((void*)((unsigned long)connect_string+copy_offset),(const void*)right_express_calcu_value,strlen((char*)right_express_calcu_value));
            else
                memcpy((void*)((unsigned long)connect_string+copy_offset),right_express.c_str(),right_express.length());

            set_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)connect_string,STRING);
        } else {
            long left_express_value=0;
            if (NONE!=left_express_calcu_value_type) {
                left_express_value=left_express_calcu_value;
            } else {
                if (EXPRESSION_NUMBER_HEX==left_express_calcu_value_type)
                    left_express_value=hex_string_to_number(left_express);
                else
                    left_express_value=atoi(left_express.c_str());
            }
            long right_express_value=0;
            if (NONE!=right_express_calcu_value_type) {
                right_express_value=right_express_calcu_value;
            } else {
                if (EXPRESSION_NUMBER_HEX==right_express_calcu_value_type)
                    right_express_value=hex_string_to_number(right_express);
                else
                    right_express_value=atoi(right_express.c_str());
            }
            left_express_value+=right_express_value;
            set_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)left_express_value,NUMBER);
        }
        return true;
    } else if ('-'==express[next_calculation_flag]) {
        string left_express(express.substr(0,next_calculation_flag));
        trim(left_express);
        express_type left_express_type=get_express_type(left_express);
        unsigned long left_express_calcu_value=0;
        support_javascript_variant_type left_express_calcu_value_type=NONE;
        if (EXPRESSION_UNKNOW==left_express_type)
            return false;
        if (EXPRESSION_EXPRESS==left_express_type || EXPRESSION_VARIANT==left_express_type) {
            if (!execute_calculation_express(left_express))
                return false;
            get_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)&left_express_calcu_value,&left_express_calcu_value_type);
            if (NUMBER==left_express_calcu_value_type)
                left_express_type=EXPRESSION_NUMBER_DECIMAL;
        } else if (EXPRESSION_NUMBER_HEX==left_express_type) {
            left_express_calcu_value=hex_string_to_number(left_express);
        } else if (EXPRESSION_NUMBER_DECIMAL==left_express_type) {
            left_express_calcu_value=atoi(left_express.c_str());
        }

        string right_express(express.substr(next_calculation_flag+1));
        trim(right_express);
        express_type right_express_type=get_express_type(right_express);
        unsigned long right_express_calcu_value=0;
        support_javascript_variant_type right_express_calcu_value_type=NONE;
        if (EXPRESSION_UNKNOW==right_express_type)
            return false;
        if (EXPRESSION_EXPRESS==right_express_type || EXPRESSION_VARIANT==right_express_type) {
            if (!execute_calculation_express(right_express))
                return false;
            get_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)&right_express_calcu_value,&right_express_calcu_value_type);
            if (NUMBER==right_express_calcu_value_type)
                right_express_type=EXPRESSION_NUMBER_DECIMAL;
        } else if (EXPRESSION_NUMBER_HEX==right_express_type) {
            right_express_calcu_value=hex_string_to_number(right_express);
        } else if (EXPRESSION_NUMBER_DECIMAL==right_express_type) {
            right_express_calcu_value=atoi(right_express.c_str());
        }
        left_express_calcu_value-=right_express_calcu_value;
        set_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)left_express_calcu_value,NUMBER);
        return true;
    } else if ('*'==express[next_calculation_flag]) {
        string left_express(express.substr(0,next_calculation_flag));
        trim(left_express);
        express_type left_express_type=get_express_type(left_express);
        unsigned long left_express_calcu_value=0;
        support_javascript_variant_type left_express_calcu_value_type=NONE;
        if (EXPRESSION_UNKNOW==left_express_type)
            return false;
        if (EXPRESSION_EXPRESS==left_express_type || EXPRESSION_VARIANT==left_express_type) {
            if (!execute_calculation_express(left_express))
                return false;
            get_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)&left_express_calcu_value,&left_express_calcu_value_type);
            if (NUMBER==left_express_calcu_value_type)
                left_express_type=EXPRESSION_NUMBER_DECIMAL;
        } else if (EXPRESSION_NUMBER_HEX==left_express_type) {
            left_express_calcu_value=hex_string_to_number(left_express);
        } else if (EXPRESSION_NUMBER_DECIMAL==left_express_type) {
            left_express_calcu_value=atoi(left_express.c_str());
        }

        string right_express(express.substr(next_calculation_flag+1));
        trim(right_express);
        express_type right_express_type=get_express_type(right_express);
        unsigned long right_express_calcu_value=0;
        support_javascript_variant_type right_express_calcu_value_type=NONE;
        if (EXPRESSION_UNKNOW==right_express_type)
            return false;
        if (EXPRESSION_EXPRESS==right_express_type || EXPRESSION_VARIANT==right_express_type) {
            if (!execute_calculation_express(right_express))
                return false;
            get_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)&right_express_calcu_value,&right_express_calcu_value_type);
            if (NUMBER==right_express_calcu_value_type)
                right_express_type=EXPRESSION_NUMBER_DECIMAL;
        } else if (EXPRESSION_NUMBER_HEX==right_express_type) {
            right_express_calcu_value=hex_string_to_number(right_express);
        } else if (EXPRESSION_NUMBER_DECIMAL==right_express_type) {
            right_express_calcu_value=atoi(right_express.c_str());
        }
        left_express_calcu_value*=right_express_calcu_value;
        set_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)left_express_calcu_value,NUMBER);
        return true;
    } else if ('/'==express[next_calculation_flag]) {
        string left_express(express.substr(0,next_calculation_flag));
        trim(left_express);
        express_type left_express_type=get_express_type(left_express);
        unsigned long left_express_calcu_value=0;
        support_javascript_variant_type left_express_calcu_value_type=NONE;
        if (EXPRESSION_UNKNOW==left_express_type)
            return false;
        if (EXPRESSION_EXPRESS==left_express_type || EXPRESSION_VARIANT==left_express_type) {
            if (!execute_calculation_express(left_express))
                return false;
            get_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)&left_express_calcu_value,&left_express_calcu_value_type);
            if (NUMBER==left_express_calcu_value_type)
                left_express_type=EXPRESSION_NUMBER_DECIMAL;
        } else if (EXPRESSION_NUMBER_HEX==left_express_type) {
            left_express_calcu_value=hex_string_to_number(left_express);
        } else if (EXPRESSION_NUMBER_DECIMAL==left_express_type) {
            left_express_calcu_value=atoi(left_express.c_str());
        }

        string right_express(express.substr(next_calculation_flag+1));
        trim(right_express);
        express_type right_express_type=get_express_type(right_express);
        unsigned long right_express_calcu_value=0;
        support_javascript_variant_type right_express_calcu_value_type=NONE;
        if (EXPRESSION_UNKNOW==right_express_type)
            return false;
        if (EXPRESSION_EXPRESS==right_express_type || EXPRESSION_VARIANT==right_express_type) {
            if (!execute_calculation_express(right_express))
                return false;
            get_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)&right_express_calcu_value,&right_express_calcu_value_type);
            if (NUMBER==right_express_calcu_value_type)
                right_express_type=EXPRESSION_NUMBER_DECIMAL;
        } else if (EXPRESSION_NUMBER_HEX==right_express_type) {
            right_express_calcu_value=hex_string_to_number(right_express);
        } else if (EXPRESSION_NUMBER_DECIMAL==right_express_type) {
            right_express_calcu_value=atoi(right_express.c_str());
        }
        left_express_calcu_value/=right_express_calcu_value;
        set_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)left_express_calcu_value,NUMBER);
        return true;
    } else if ('('==express[next_calculation_flag]) {
        string resolve_express(express);
        for (unsigned long left_bracket_index=resolve_express.find('(');
                           left_bracket_index!=INVALID_VALUE;
                           left_bracket_index=resolve_express.find('(')) {
            unsigned long next_right_bracket=get_matching_outside_right_bracket(express,0);
            if (!next_right_bracket)
                return false;
            if (!execute_calculation_express(resolve_express.substr(left_bracket_index+1,next_right_bracket-left_bracket_index-1)))
                return false;
            unsigned long express_calcu_result_value=0;
            support_javascript_variant_type express_calcu_result_value_type=NONE;
            get_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)&express_calcu_result_value,&express_calcu_result_value_type);
            resolve_express=express.substr(0,left_bracket_index);
            if (NUMBER==express_calcu_result_value_type) {
                char conver_buffer[0x20]={0};
                sprintf(conver_buffer,"%d",express_calcu_result_value);
                resolve_express+=conver_buffer;
            } else {
                resolve_express+="\'";
                resolve_express+=(const char*)express_calcu_result_value;
                resolve_express+="\'";
            }
            resolve_express+=express.substr(next_right_bracket+1);
        }
        if (!execute_calculation_express(resolve_express))
            return false;
        return true;
    }
    if (is_exist_variant(express)) {  //  test_var
        copy_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,express);
        return true;
    } else if (INVALID_VALUE!=express.find('[') && INVALID_VALUE!=express.find(']')) {  //  test_array
        unsigned long left_brcket_index=express.find('[');
        unsigned long right_brcket_index=express.find(']');
        string array_name(express.substr(0,left_brcket_index));
        trim(array_name);
        string array_index_string(express.substr(left_brcket_index+1,right_brcket_index-left_brcket_index-1));
        trim(array_index_string);
        if (!express_calcu(array_index_string))
            return false;
        unsigned long array_index=0;
        support_javascript_variant_type array_index_type=NONE;
        get_variant(JAVASCRIPT_VARIANT_KEYNAME_CALCULATION_RESULT,(void*)&array_index,&array_index_type);
        unsigned long array_index_data=0;
        support_javascript_variant_type array_index_data_type=NONE;
        get_variant_array(array_name,array_index,(void*)&array_index_data,&array_index_data_type);
        set_variant(JAVASCRIPT_VARIANT_KEYNAME_FUNCTION_RESULT,(void*)array_index_data,array_index_data_type);
        return true;
    }
    return false;  //  TIPS ! all bug had been debug success ..
}
Esempio n. 16
0
int do_gpt_format(struct fastboot_data *fb_data)
{
	/* For testing need to pass this in better */
	struct ptable *ptbl;
	u64 total_sectors = 0;
	u64 next;
	int n;
	u32 sector_sz = fb_data->storage_ops->get_sector_size();
	u64 ptbl_sectors = 0;
	int ret = 0;

#ifdef DEBUG
	int i = 0; int j = 0;
	u8 *data;
	u32 *blocksp = &total_sectors;
	data = (u8 *)alloc_memory(sizeof(struct ptable));
#endif

	DBG("do_format\n");

	ptbl_sectors = sizeof(struct ptable) / sector_sz;

	total_sectors = fb_data->storage_ops->get_total_sectors();
	DBG("sector_sz %u\n", sector_sz);
	DBG("total_sectors 0x%x%08x\n", blocksp[1], blocksp[0]);

	ptbl = (struct ptable *) alloc_memory(sizeof(struct ptable));
	if (!ptbl) {
		printf("%s: Unable to alloc mem for ptbl\n", __func__);
		return -1;
	}
	start_ptbl(ptbl, total_sectors);
	if (fb_data->board_ops->board_get_part_tbl)
		partitions = fb_data->board_ops->board_get_part_tbl();

	n = 0;
	next = 0;
	for (n = 0, next = 0; partitions[n].name; n++) {
		u64 sz_sectors = 0;
		sz_sectors = (u64)partitions[n].size_kb << 1;
		if (!strcmp(partitions[n].name, "-")) {
			next += sz_sectors;
			continue;
		}
		if (sz_sectors == 0)
			sz_sectors = total_sectors - next;

		if (add_ptn(ptbl, next, next + sz_sectors - 1,
				partitions[n].name)) {
			printf("Unable to add_ptn\n");
			ret = -1;
			goto format_err;
		}

		next += sz_sectors;
	}

	end_ptbl(ptbl);

	DBG("writing ptable to disk: %d #of sectors\n", ptbl_sectors);
	ret = fb_data->storage_ops->write(0, ptbl_sectors, (void *)ptbl);
	if (ret) {
		printf("Write PTBL failed\n");
		goto format_err;
	}

	DBG("writing the GUID Table disk ...\n");
#ifdef DEBUG
	ret = fb_data->storage_ops->read(0, ptbl_sectors, (void *)data);
	if (ret != 0) {
		printf("error reading MBR\n");
		return ret;
	} else {
			printf("printing ptable\n");
			for (i = 0; i < sizeof(struct ptable); i++)
				printf("%02X ", data[i]);
			printf("\n");
		}
#endif
	DBG("\nnew partition table:\n");
	ret = load_ptbl(fb_data->storage_ops, 0);
	if (ret != 0) {
		printf("Failed to load partition table\n");
		goto format_err;
	}
format_err:
	free_memory(ptbl);
#ifdef DEBUG
	free_memory(data);
#endif
	return ret;
}