compiles and works
This commit is contained in:
87
bs/main.c
87
bs/main.c
@@ -2,6 +2,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
|
||||
@@ -9,6 +10,7 @@
|
||||
#include "utils.h"
|
||||
#include "init.h"
|
||||
#include "args.h"
|
||||
#include "script/script.h"
|
||||
|
||||
// int main(int argc, char *argv[]) {
|
||||
// int success = 0;
|
||||
@@ -58,63 +60,70 @@
|
||||
// return error;
|
||||
// }
|
||||
|
||||
jtag_core *jc = NULL;
|
||||
script_ctx *sctx = NULL;
|
||||
|
||||
// int execute_command(jtag_core *jc, int argc, char **argv) {
|
||||
// int error = 0;
|
||||
// if (argv[0] == NULL) {
|
||||
// return 0;
|
||||
// }
|
||||
// Fonction de gestion du signal
|
||||
void handle_sigint(int sig) {
|
||||
bsexp_deinit(jc, sctx);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// for (int i = 0; commands[i].name != NULL; i++) {
|
||||
// if (strcmp(argv[0], commands[i].name) == 0) {
|
||||
// error = commands[i].cmd_call(jc, argc, argv);
|
||||
// return error;
|
||||
// }
|
||||
// }
|
||||
// error = -1;
|
||||
// printf("Command not found\n");
|
||||
// }
|
||||
int execute_command(script_ctx *sctx, char *line)
|
||||
{
|
||||
int error = 0;
|
||||
error = execute_line_script(sctx, line);
|
||||
return error;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
char *line = NULL;
|
||||
int error = 0;
|
||||
int cmd_argc=0;
|
||||
char *cmd_argv[MAX_ARGS] = {0};
|
||||
jtag_core *jc = NULL;
|
||||
int cmd_argc = 0;
|
||||
|
||||
jc = bsexp_init();
|
||||
if (NULL == jc) {
|
||||
bsexp_init(&jc, &sctx);
|
||||
script_print(sctx, MSG_NONE, "\n");
|
||||
if ((NULL == jc) || (NULL == sctx))
|
||||
{
|
||||
error = JTAG_CORE_MEM_ERROR;
|
||||
printf("JTAG Core execution failed");
|
||||
goto err;
|
||||
printf("JTAG Core initialization failed!\n");
|
||||
goto err_no_deinit;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
signal(SIGINT, handle_sigint);
|
||||
while (1)
|
||||
{
|
||||
line = readline("bs_explorer> ");
|
||||
if (line == NULL) {
|
||||
if (line == NULL)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (*line) {
|
||||
if (*line)
|
||||
{
|
||||
add_history(line);
|
||||
}
|
||||
parse_command(line, &cmd_argc, cmd_argv);
|
||||
if (cmd_argv[0] == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (strcmp(cmd_argv[0], "exit") == 0) {
|
||||
if (strcmp(line, "exit") == 0) {
|
||||
break;
|
||||
}
|
||||
// error = execute_command(jc, cmd_argc, cmd_argv);
|
||||
// printf("\n");
|
||||
// if (0 == error) {
|
||||
// } else {
|
||||
// printf("Command failed with code: %d", error);
|
||||
// }
|
||||
if (strcmp(line, "quit") == 0) {
|
||||
break;
|
||||
}
|
||||
error = execute_command(sctx, line);
|
||||
if (0 == error)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Command failed with code: %d\n", error);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
err_no_deinit:
|
||||
exit(error);
|
||||
err:
|
||||
return error;
|
||||
printf("Failed with error (%d)", error);
|
||||
end:
|
||||
bsexp_deinit(jc);
|
||||
bsexp_deinit(jc, sctx);
|
||||
exit(error);
|
||||
}
|
||||
Reference in New Issue
Block a user