- fix format-string in jprint/script_print (printf(msg) -> fputs)
- fix bsexp_deinit: deinit_script guarded by sctx, not jc
- silence "config.script not found" when the optional override is absent
- remove dead code: bs/cmds/, bs/args.{c,h}, bs/utils.h, commented blocks
- REPL: welcome banner with version, readline tab-completion on
script_commands_list, skip blank lines, clean Ctrl-D exit
- README: build, REPL usage, typical SPI flow, command table, probes,
Xilinx STARTUPE3/CCLK caveat
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
122 lines
2.6 KiB
C
122 lines
2.6 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <signal.h>
|
|
#include <readline/readline.h>
|
|
#include <readline/history.h>
|
|
|
|
#include "config/bs_defines.h"
|
|
#include "config/version.h"
|
|
#include "jtag_core/jtag_core.h"
|
|
#include "script/script.h"
|
|
#include "init.h"
|
|
|
|
#define PROMPT "bs_explorer> "
|
|
|
|
static jtag_core *jc = NULL;
|
|
static script_ctx *sctx = NULL;
|
|
|
|
static void handle_sigint(int sig)
|
|
{
|
|
(void)sig;
|
|
fputs("\n", stdout);
|
|
bsexp_deinit(jc, sctx);
|
|
exit(0);
|
|
}
|
|
|
|
static char *command_generator(const char *text, int state)
|
|
{
|
|
static int idx;
|
|
static size_t len;
|
|
const char *name;
|
|
|
|
if (!state) {
|
|
idx = 0;
|
|
len = strlen(text);
|
|
}
|
|
|
|
while ((name = script_commands_list[idx].command) != NULL) {
|
|
idx++;
|
|
if (strncmp(name, text, len) == 0) {
|
|
return strdup(name);
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
static char **bs_completion(const char *text, int start, int end)
|
|
{
|
|
(void)end;
|
|
rl_attempted_completion_over = 0;
|
|
if (start == 0) {
|
|
return rl_completion_matches(text, command_generator);
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
static int is_blank(const char *s)
|
|
{
|
|
while (*s) {
|
|
if (*s != ' ' && *s != '\t') return 0;
|
|
s++;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
static void print_banner(void)
|
|
{
|
|
int n_drv = jtagcore_get_number_of_probes_drv(jc);
|
|
|
|
printf("\n");
|
|
printf(" Boundary Scan Explorer " APP_VER_STR(APP_VER) "\n");
|
|
printf(" Based on Viveris jtag-boundary-scanner\n");
|
|
printf("\n");
|
|
printf(" %d probe driver(s) available.\n", n_drv);
|
|
printf(" Type 'help' or '?' to list commands, 'exit' or Ctrl-D to quit.\n");
|
|
printf(" <Tab> completes commands.\n");
|
|
printf("\n");
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
char *line = NULL;
|
|
int error = 0;
|
|
|
|
bsexp_init(&jc, &sctx);
|
|
if (NULL == jc || NULL == sctx) {
|
|
fputs("JTAG Core initialization failed!\n", stderr);
|
|
return JTAG_CORE_MEM_ERROR;
|
|
}
|
|
|
|
signal(SIGINT, handle_sigint);
|
|
rl_attempted_completion_function = bs_completion;
|
|
rl_readline_name = "bs_explorer";
|
|
|
|
print_banner();
|
|
|
|
while ((line = readline(PROMPT)) != NULL) {
|
|
if (is_blank(line)) {
|
|
free(line);
|
|
continue;
|
|
}
|
|
if (strcmp(line, "exit") == 0 || strcmp(line, "quit") == 0) {
|
|
free(line);
|
|
break;
|
|
}
|
|
add_history(line);
|
|
|
|
error = execute_line_script(sctx, line);
|
|
if (error != JTAG_CORE_NO_ERROR && error != JTAG_CORE_NOT_FOUND) {
|
|
printf("Command failed with code: %d\n", error);
|
|
}
|
|
free(line);
|
|
}
|
|
|
|
if (line == NULL) {
|
|
fputs("\n", stdout);
|
|
}
|
|
|
|
bsexp_deinit(jc, sctx);
|
|
return 0;
|
|
}
|