int builtin_exec_from_history(cmd_t* cmd, job_list_t* jobs, history_t* hist) { int index = (int) strtol(cmd->args[0], NULL, 10); cmd_t* past_cmd = get_from_history(hist, index); if (past_cmd) { cmd_t* new_cmd = copycmd(past_cmd); printcmd(new_cmd, stdout); return executecmd(new_cmd, jobs, hist); } return COMMAND_NOT_FOUND; }
void deal(u8 * buf,u8 len) { u8 i = 0; for(int k = 0;k< 256;k++) cmdBuf[k] = 0; while(i<len) { switch(state) { case NEEDHEAD: if(buf[i] == HEAD) { i++; state = NEEDDOT; } else { i++; } break; case NEEDDOT: if(buf[i] == DOT) { i++; state = NEEDPARA; } else { state = NEEDHEAD; i++; } break; case NEEDPARA: if(buf[i] == END)//如果检测到";"则结束,将命令缓冲区数据复制到命令列表 { i++; copycmd(&ctr[count],cmdBuf,j);//j是cmdbuf的数据长度 count++; if(count == MAX)count = 0; j=0; state = NEEDHEAD; } else if(buf[i] != DOT)//如果不是",",则将字符数据复制到缓冲区 { if(j<MAX_LENGTH + 2)//最大限制参数22字节 cmdBuf[j] = buf[i];//复制数据 else { //错误帧,直接抛弃所有本次接受的内容 state = NEEDHEAD; i = 0; j = 0; count = 0; return; } j++; i++; } else if(buf[i] == DOT) { i++; } break; } } }