phase 1: cleanup, REPL polish, README

- 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>
This commit is contained in:
2026-05-20 22:22:05 +02:00
parent 9e0ca10a71
commit 7cb3627754
17 changed files with 247 additions and 481 deletions

182
bs/main.c
View File

@@ -1,5 +1,4 @@
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
@@ -7,123 +6,116 @@
#include <readline/history.h>
#include "config/bs_defines.h"
#include "utils.h"
#include "init.h"
#include "args.h"
#include "config/version.h"
#include "jtag_core/jtag_core.h"
#include "script/script.h"
#include "init.h"
// int main(int argc, char *argv[]) {
// int success = 0;
// int n_probes = 0;
// int i = 0;
// int error = 0;
// jtag_core *jc = NULL;
#define PROMPT "bs_explorer> "
// struct args a = {0};
// struct probe probes[PROBES_MAX_NUM] = {0};
// unsigned long dev_ids[DEVICES_SCAN_MAX] = {0};
// int ndevs = 0;
static jtag_core *jc = NULL;
static script_ctx *sctx = NULL;
// success = parse_args(&a, argc, argv);
// if (EXIT_FAILURE == success) exit(EXIT_FAILURE);
// jc = bsexp_init();
// if (NULL == jc) {
// error = JTAG_CORE_MEM_ERROR;
// goto err;
// }
// /* List the probes (and display if asked) */
// n_probes = list_probes(jc, probes, a.list);
// i = 0;
// while ((i<MAX_COMMANDS) && (a.cmds[i] != NO_COMMAND)) {
// switch (a.cmds[i]) {
// case COMMAND_SCAN:
// if ((0 >= a.probe) || (a.probe > MIN(n_probes, PROBES_MAX_NUM))) goto err;
// error = scan(jc, probes[a.probe-1].probe_id, &ndevs, dev_ids, 1);
// break;
// default:
// printf("Unknown command.");
// goto err;
// }
// i++;
// }
// goto end;
// err:
// printf("Exited with error (%d).\n", error);
// end:
// jtagcore_deinit(jc);
// return error;
// }
jtag_core *jc = NULL;
script_ctx *sctx = NULL;
// Fonction de gestion du signal
void handle_sigint(int sig) {
static void handle_sigint(int sig)
{
(void)sig;
fputs("\n", stdout);
bsexp_deinit(jc, sctx);
exit(0);
}
int execute_command(script_ctx *sctx, char *line)
static char *command_generator(const char *text, int state)
{
int error = 0;
error = execute_line_script(sctx, line);
return error;
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;
}
int main()
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;
int cmd_argc = 0;
bsexp_init(&jc, &sctx);
script_print(sctx, MSG_NONE, "\n");
if ((NULL == jc) || (NULL == sctx))
{
error = JTAG_CORE_MEM_ERROR;
printf("JTAG Core initialization failed!\n");
goto err_no_deinit;
if (NULL == jc || NULL == sctx) {
fputs("JTAG Core initialization failed!\n", stderr);
return JTAG_CORE_MEM_ERROR;
}
signal(SIGINT, handle_sigint);
while (1)
{
line = readline("bs_explorer> ");
if (line == NULL)
{
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;
}
if (*line)
{
add_history(line);
}
if (strcmp(line, "exit") == 0) {
break;
}
if (strcmp(line, "quit") == 0) {
break;
}
error = execute_command(sctx, line);
if (0 == error)
{
}
else
{
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);
}
err_no_deinit:
exit(error);
err:
printf("Failed with error (%d)", error);
end:
bsexp_deinit(jc, sctx);
exit(error);
}
return 0;
}