Skip to content

Commit

Permalink
cli: Clear buffers on re-entry
Browse files Browse the repository at this point in the history
  • Loading branch information
dd86k committed Apr 22, 2024
1 parent 5ef5b07 commit f798cb8
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions common/cli.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
module common.cli;

import adbg.platform;
import adbg.debugger.exception : adbg_exception_t, adbg_exception_name;
import adbg.machines : AdbgMachine;
import adbg.disassembler : AdbgDisSyntax;
import adbg.include.capstone : libcapstone_dynload, cs_version;
Expand All @@ -15,7 +14,6 @@ import adbg.include.d.config : GDC_VERSION, GDC_EXCEPTION_MODE, LLVM_VERSION;
import core.stdc.stdio;
import core.stdc.stdlib;
import core.stdc.string;
import core.stdc.errno;

/// Copyright string
enum COPYRIGHT = "Copyright (c) 2019-2024 dd86k <[email protected]>";
Expand Down Expand Up @@ -126,6 +124,16 @@ enum option_license = option_t(0, "license", "Show the license page and exi
//TODO: Make option functions return <0=error >0=ok, consumed arg(s)
/// Interpret options
int getopt(int argc, const(char) **argv, immutable(option_t)[] options) {
// On re-entry, clear extras and error buffers
if (getoptextras) {
free(getoptextras);
getoptextras = null;
}
if (getopterrbuf) {
free(getopterrbuf);
getopterrbuf = null;
}

const(char) *arg = void;
const(char) *val = void;
CLI: for (int argi = 1; argi < argc; ++argi) {
Expand Down Expand Up @@ -207,14 +215,12 @@ int getopt(int argc, const(char) **argv, immutable(option_t)[] options) {
return -1;
} else {
getoptaddextra(argc, arg);
//*entry = arg;
continue CLI;
}
}

return 0;
}
//TODO: These unittests!
unittest {
}

Expand Down Expand Up @@ -310,6 +316,7 @@ private:
//

//TODO: Interface with machine module instead
// Needs a filter at the disassembler level: adbg_dasm_machine_available()

struct setting_platform_t {
AdbgMachine val;
Expand Down Expand Up @@ -375,7 +382,7 @@ int cli_syntax(const(char) *val) {
}

int cli_build_info() {
__gshared immutable(char) *page =
static immutable char *page =
"Compiler "~__VENDOR__~" "~__D_VERSION__~"\n"~
"Target "~TARGET_TRIPLE~"\n"~
"Object "~TARGET_OBJFMT~"\n"~
Expand Down

0 comments on commit f798cb8

Please sign in to comment.