Skip to content

Commit

Permalink
apply customizations
Browse files Browse the repository at this point in the history
  • Loading branch information
luisguilhermemsalmeida committed Mar 14, 2024
1 parent b9288fc commit 34f6a2e
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 66 deletions.
66 changes: 33 additions & 33 deletions btcdeb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ bool get_debug_flag(const std::string& name, const std::set<std::string>& debug_

int main(int argc, char* const* argv)
{
pipe_in = !isatty(fileno(stdin)) || std::getenv("DEBUG_SET_PIPE_IN");
pipe_out = !isatty(fileno(stdout)) || std::getenv("DEBUG_SET_PIPE_OUT");
pipe_in = false;
pipe_out = false;
if (pipe_in || pipe_out) btc_logf = btc_logf_dummy;

cliargs ca;
Expand Down Expand Up @@ -341,38 +341,38 @@ int main(int argc, char* const* argv)
); else if (!quiet) btc_logf("note: there is a for-clarity preamble (use --verbose for details)\n");
}

if (pipe_in || pipe_out) {
if (!ContinueScript(*env)) {
fprintf(stderr, "error: %s\n", ScriptErrorString(*env->serror).c_str());
print_dualstack();
return 1;
}

print_stack(env->stack, true);
return 0;
} else {
kerl_set_history_file(".btcdeb_history");
kerl_set_repeat_on_empty(true);
kerl_set_enable_sensitivity();
kerl_set_comment_char('#');
kerl_register("step", fn_step, "Execute one instruction and iterate in the script.");
kerl_register("rewind", fn_rewind, "Go back in time one instruction.");
kerl_register("stack", fn_stack, "Print stack content.");
kerl_register("altstack", fn_altstack, "Print altstack content.");
kerl_register("vfexec", fn_vfexec, "Print vfexec content.");
kerl_register("exec", fn_exec, "Execute command.");
kerl_register("tf", fn_tf, "Transform a value using a given function.");
kerl_set_completor("exec", compl_exec, true);
kerl_set_completor("tf", compl_tf, false);
kerl_register("print", fn_print, "Print script.");
kerl_register_help("help");
if (!quiet) btc_logf("%d op script loaded. type `help` for usage information\n", count);
print_dualstack();
if (env->curr_op_seq < count) {
printf("%s\n", script_lines[env->curr_op_seq]);
}
kerl_run("btcdeb> ");
// if (pipe_in || pipe_out) {
// if (!ContinueScript(*env)) {
// fprintf(stderr, "error: %s\n", ScriptErrorString(*env->serror).c_str());
// print_dualstack();
// return 1;
// }

// print_stack(env->stack, true);
// return 0;
// } else {
kerl_set_history_file(".btcdeb_history");
kerl_set_repeat_on_empty(true);
kerl_set_enable_sensitivity();
kerl_set_comment_char('#');
kerl_register("step", fn_step, "Execute one instruction and iterate in the script.");
kerl_register("rewind", fn_rewind, "Go back in time one instruction.");
kerl_register("stack", fn_stack, "Print stack content.");
kerl_register("altstack", fn_altstack, "Print altstack content.");
kerl_register("vfexec", fn_vfexec, "Print vfexec content.");
kerl_register("exec", fn_exec, "Execute command.");
kerl_register("tf", fn_tf, "Transform a value using a given function.");
kerl_set_completor("exec", compl_exec, true);
kerl_set_completor("tf", compl_tf, false);
kerl_register("print", fn_print, "Print script.");
kerl_register_help("help");
if (!quiet) btc_logf("%d op script loaded. type `help` for usage information\n", count);
print_dualstack();
if (env->curr_op_seq < count) {
printf("%s\n", script_lines[env->curr_op_seq]);
}
kerl_run("btcdeb> ");
// }
}

static const char* opnames[] = {
Expand Down
77 changes: 44 additions & 33 deletions functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ char** script_lines;
#define fail(msg...) do { fprintf(stderr, msg); return 0; } while (0)

int fn_step(const char* arg) {
if (env->done) fail("at end of script\n");
if (env->done) fail("end_of_script\n");
if (!instance.step()) fail("error: %s\n", instance.error_string().c_str());
print_dualstack();
if (env->curr_op_seq < count) {
Expand Down Expand Up @@ -145,46 +145,57 @@ void print_dualstack() {
// }
// }

if (glmax < lmax) glmax = lmax;
if (grmax < rmax) grmax = rmax;
lmax = glmax; rmax = grmax;
int lcap = //66, rcap = 66; //
lmax > 66 ? 66 : lmax, rcap = rmax > 66 ? 66 : rmax;
char lfmt[15], rfmt[14];
snprintf(lfmt, 15, "%%-%ds", lcap + 1);
snprintf(rfmt, 14, "%%%ds", rcap);
printf(lfmt, "script");
printf("| ");
printf(rfmt, "stack ");
printf("\n");
for (int i = 0; i < lcap; i++) printf("-");
printf("-+-");
for (int i = 0; i < rcap; i++) printf("-");
printf("\n");
// if (glmax < lmax) glmax = lmax;
// if (grmax < rmax) grmax = rmax;
// lmax = glmax; rmax = grmax;
// int lcap = //66, rcap = 66; //
// lmax > 66 ? 66 : lmax, rcap = rmax > 66 ? 66 : rmax;
// char lfmt[15], rfmt[14];
// snprintf(lfmt, 15, "%%-%ds", lcap + 1);
// snprintf(rfmt, 14, "%%%ds", rcap);
// printf(lfmt, "script");
// printf("| ");
// printf(rfmt, "stack ");
// printf("\n");
// for (int i = 0; i < lcap; i++) printf("-");
// printf("-+-");
// for (int i = 0; i < rcap; i++) printf("-");
// printf("\n");
int li = 0, ri = 0;
while (li < l.size() || ri < r.size()) {
while (li < l.size()) {
if (li < l.size()) {
auto s = l[li++];
if (s.length() > lcap) s = s.substr(0, lcap-3) + "...";
printf(lfmt, s.c_str());
} else {
printf(lfmt, "");
btc_logf("script: %s\n", s.c_str());
// if (s.length() > lcap) s = s.substr(0, lcap-3) + "...";
// printf(lfmt, s.c_str());
// } else {
// printf(lfmt, "");
// }
// printf("| ");
// if (ri < r.size()) {
// auto s = r[ri++];
// // if (ms_start > ri) {
// // printing stack items; right-align, no ansi
// if (s.length() > rcap) s = s.substr(0, rcap-3) + "...";
// printf(rfmt, s.c_str());
// // } else {
// // // printing miniscript tree; left-align, ansi enabled
// // if (ansi::length(s) > rcap) s = ansi::substring(s, 0, rcap-3) + "...";
// // printf("%s", s.c_str());
// // }
// }
// printf("\n");
}
printf("| ");
}

while (ri < r.size()) {
if (ri < r.size()) {
auto s = r[ri++];
// if (ms_start > ri) {
// printing stack items; right-align, no ansi
if (s.length() > rcap) s = s.substr(0, rcap-3) + "...";
printf(rfmt, s.c_str());
// } else {
// // printing miniscript tree; left-align, ansi enabled
// if (ansi::length(s) > rcap) s = ansi::substring(s, 0, rcap-3) + "...";
// printf("%s", s.c_str());
// }
btc_logf("stack: %s\n", s.c_str());
}
printf("\n");
}

btc_logf("end_of_stack\n");
}

int print_stack(std::vector<valtype>& stack, bool raw) {
Expand Down

0 comments on commit 34f6a2e

Please sign in to comment.