void script_exec(const char* filename) { int fd; char line[128]; int line_len, line_no; struct finsh_parser parser; fd = open(filename, O_RDONLY, 0); if (fd >= 0) { /* create a finsh shell environment */ finsh_init(&parser); line_no = 0; while (1) { /* read line and execute it */ line_len = read_line(fd, line, sizeof(line) - 1); if (line_len > 0) { line[line_len] = '\0'; line_no ++; { finsh_parser_run(&parser, (unsigned char*)line); /* compile node root */ if (finsh_errno() == 0) { finsh_compiler_run(parser.root); } else { const char* err_str; err_str = finsh_error_string(finsh_errno()); rt_kprintf("%s:%d: error %s\n", line_no, err_str); } /* run virtual machine */ if (finsh_errno() == 0) { finsh_vm_run(); } finsh_flush(&parser); } } else break; } close(fd); } }
void finsh_run_line(struct finsh_parser *parser, const char *line) { const char *err_str; if(shell->echo_mode) rt_kprintf("\n"); finsh_parser_run(parser, (unsigned char *)line); /* compile node root */ if (finsh_errno() == 0) { finsh_compiler_run(parser->root); } else { err_str = finsh_error_string(finsh_errno()); rt_kprintf("%s\n", err_str); } /* run virtual machine */ if (finsh_errno() == 0) { char ch; finsh_vm_run(); ch = (unsigned char)finsh_stack_bottom(); if (ch > 0x20 && ch < 0x7e) { rt_kprintf("\t'%c', %d, 0x%08x\n", (unsigned char)finsh_stack_bottom(), (unsigned int)finsh_stack_bottom(), (unsigned int)finsh_stack_bottom()); } else { rt_kprintf("\t%d, 0x%08x\n", (unsigned int)finsh_stack_bottom(), (unsigned int)finsh_stack_bottom()); } } finsh_flush(parser); }