/* Copyright Yann Weber This file is part of asmsh. asmsh is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. asmsh is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with asmsh. If not, see . */ #include "config.h" #include #include #include #define CHILD_EXEC_PATH "./child" #include "logger.h" #include "shell.h" #include "completion.h" #include "history.h" int main(int argc, char *argv[], char *envp[]) { asmsh_logger_t *logger; asmsh_t sh; int ret = 0; char prompt[64]; bzero(prompt, sizeof(prompt)); logger = asmsh_logger_new(ASMSH_INFO); asmsh_logger_setup(logger); if(asmsh_init(&sh, CHILD_EXEC_PATH)) { asmsh_log_error("Unable to init shell : %s", strerror(errno)); asmsh_logger_dprint(2, logger); return 1; } rl_special_prefixes=""; rl_basic_word_break_characters=" \t\n"; rl_attempted_completion_function = asmsh_rl_completion; char * hpath = history_filename_init(NULL); load_history(hpath, add_history); while(1) { char *cmd; snprintf(prompt, sizeof(prompt)-1, "asmsh@%p > ", (void*)sh.env->regs.rip); cmd = readline(prompt); if(!cmd) { break; } ret = asmsh_exec(&sh, cmd); asmsh_logger_dprint_fmt(2, logger, asmsh_log_lvl_fmt); if(ret > 0) { //unrecoverable error or exit (if ret == 1) ret--; // exit status if(ret) { dprintf(2, "Exit with status %d\n", ret); } break; } //else if (ret < 0) {} //recoverable errors add_history(cmd); } asmsh_cleanup(&sh); HIST_ENTRY **hist = history_list(); int hist_count = 0; for(HIST_ENTRY **p=hist; *p;p++){ hist_count++; } const char *hstr[(hist_count+1)*sizeof(char*)]; for(int i=0; iline; } hstr[hist_count]=NULL; save_history(hpath, hstr); free(hpath); return ret; }