From f7e99b30775e9684df9ad4c57cb5f6706b0726a0 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 21 May 2019 04:06:50 -0700 Subject: [PATCH] Added command line flags --- bb.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/bb.c b/bb.c index 237795d..56250ed 100644 --- a/bb.c +++ b/bb.c @@ -357,7 +357,7 @@ static int term_get_event() return -1; } -static void explore(char *path) +static void explore(char *path, int print_dir, int print_selection) { char *tmp = path; path = malloc(strlen(tmp) + 1); @@ -716,17 +716,32 @@ static void explore(char *path) } done: close_term(); - write_selection(STDOUT_FILENO, state.firstselected); + if (print_dir) + printf("%s\n", state.path); + if (print_selection) + write_selection(STDOUT_FILENO, state.firstselected); return; } int main(int argc, char *argv[]) { init_term(); - char path[MAX_PATH]; - if (!realpath(argc > 1 ? argv[1] : ".", path)) + char _realpath[MAX_PATH]; + char *path = "."; + int print_dir = 0, print_selection = 0; + for (int i = 1; i < argc; i++) { + if (strcmp(argv[i], "-d") == 0) { + print_dir = 1; + } else if (strcmp(argv[i], "-s") == 0) { + print_selection = 1; + } else { + path = argv[i]; + break; + } + } + if (!realpath(path, _realpath)) err("realpath failed"); - explore(path); + explore(_realpath, print_dir, print_selection); done: return 0; }