Example #1
0
linked_list* build_list_from_file(FILE* file, bool reverse) {
    linked_list* new_list = new_linked_list();
    int ch;
    bool still_reading = true;
    bool first_val_read = false;
    int number = 0;
    while (!first_val_read && still_reading && (ch = getc(file)) != EOF) {
        switch(ch) {
            case SPACE:
                break; // ignore spaces
            case RETURN:
            case NEWLINE:
                still_reading = false;
                break;
            case COMMA:
                ll_init_add(new_list, number);
                number = 0;
                first_val_read = true;
                break;

            // NUMBER ENCOUNTERED
            default: 
                number = number*10 + char_to_num(ch); 
        }
    }
    while (still_reading && (ch = getc(file)) != EOF) {
        switch(ch) {
            case SPACE:
                break; // ignore spaces
            case RETURN:
            case NEWLINE:
                still_reading = false;
                break;
            case COMMA:
                if (reverse) {
                    ll_add_to_head(new_list, number);
                }
                else {
                    ll_add_to_tail(new_list, number);
                }
                number = 0;
                break;

            // NUMBER ENCOUNTERED
            default: 
                number = number*10 + char_to_num(ch); 
        }
    }
    if (reverse) {
        ll_add_to_head(new_list, number);
    }
    else {
        ll_add_to_tail(new_list, number);
    }
    return new_list;
}
Example #2
0
u8  task_send_msg(u8 to, MSG_TYPE_ENUM  type, u32 value)
{
	/*1.将消息添加到系统的消息缓冲区*/
		/*1.1 申请消息ID*/
	u8 MSG_ID = ll_add_to_tail(MSG_list , value);
	if( 0 == MSG_ID)
	{
			return false;
	}

		/*1.2 填充消息*/
	MSG_s _MSG;
	_MSG.from = task_global.current_TID;
	_MSG.to = to;
	_MSG.type = type;
	_MSG.value = value;
	MSG[MSG_ID] = _MSG;

	/*2. 通知内核将消息发送到指定task*/
	_MSG.from = task_global.current_TID;
	_MSG.to = 0;
	_MSG.type = MSG_SEND;
	_MSG.value = MSG_ID;
	task_info[0].MSG = _MSG;

	/*进入死循环判断是否发送成功*/
	u32 timer_value = os_timer_ctrl.value;
	while( timer_value == os_timer_ctrl.value ){}

	return true;
}