From 55daca6a2f6e4401ae50523aad082f2c0785222b Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 13 Oct 2019 19:34:16 -0700 Subject: [PATCH] More code cleanup, including tweaking matches_cmd() to figure out if there are required arguments or not, and refactoring run_bbcmd() to no longer return a value (which was ignored), but instead just spit out error messages to stderr if necessary. --- bb.c | 97 ++++++++++++++++++++++++++++-------------------------------- bb.h | 12 ++++++-- 2 files changed, 54 insertions(+), 55 deletions(-) diff --git a/bb.c b/bb.c index 8858097..22c8065 100644 --- a/bb.c +++ b/bb.c @@ -27,8 +27,8 @@ void bb_browse(bb_t *bb, const char *path) bb->scroll = 0; bb->cursor = 0; bb->dirty = 0; + bb->should_quit = 0; - init_term(); goto force_check_cmds; while (!bb->should_quit) { @@ -400,11 +400,13 @@ entry_t* load_entry(bb_t *bb, const char *path, int clear_dots) /* * Return whether a string matches a command - * e.g. matches_cmd("cd:..", "cd") == 1, matches_cmd("q", "quit") == 1 + * e.g. matches_cmd("sel:x", "select:") == 1, matches_cmd("q", "quit") == 1 */ static inline int matches_cmd(const char *str, const char *cmd) { - while (*str == *cmd && *cmd) ++str, ++cmd; + if ((strchr(cmd, ':') == NULL) != (strchr(str, ':') == NULL)) + return 0; + while (*str == *cmd && *cmd && *cmd != ':') ++str, ++cmd; return *str == '\0' || *str == ':'; } @@ -568,7 +570,7 @@ void print_bindings(int fd) * Run a bb internal command (e.g. "+refresh") and return an indicator of what * needs to happen next. */ -bb_result_t run_bbcmd(bb_t *bb, const char *cmd) +void run_bbcmd(bb_t *bb, const char *cmd) { if (cmd[0] == '+') ++cmd; else if (strncmp(cmd, "bb +", 4) == 0) cmd = &cmd[4]; @@ -581,14 +583,15 @@ bb_result_t run_bbcmd(bb_t *bb, const char *cmd) } else if (matches_cmd(cmd, ".")) { // +. set_bool(bb->show_dot); populate_files(bb, 1); - } else if (matches_cmd(cmd, "bind")) { // +bind::