From 34f6a2e8db0d6d3d37c619994f246a2559c0d2eb Mon Sep 17 00:00:00 2001 From: Luis Almeida Date: Thu, 14 Mar 2024 15:40:05 +0000 Subject: [PATCH] apply customizations --- btcdeb.cpp | 66 +++++++++++++++++++++---------------------- functions.cpp | 77 +++++++++++++++++++++++++++++---------------------- 2 files changed, 77 insertions(+), 66 deletions(-) diff --git a/btcdeb.cpp b/btcdeb.cpp index 8f3fb71b..c6468bb4 100644 --- a/btcdeb.cpp +++ b/btcdeb.cpp @@ -110,8 +110,8 @@ bool get_debug_flag(const std::string& name, const std::set& 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; @@ -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[] = { diff --git a/functions.cpp b/functions.cpp index 7a5c1cb2..115e71a0 100644 --- a/functions.cpp +++ b/functions.cpp @@ -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) { @@ -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& stack, bool raw) {