Added command line flags

This commit is contained in:
Bruce Hill 2019-05-21 04:06:50 -07:00
parent ab46185843
commit f7e99b3077

23
bb.c
View File

@ -357,7 +357,7 @@ static int term_get_event()
return -1; return -1;
} }
static void explore(char *path) static void explore(char *path, int print_dir, int print_selection)
{ {
char *tmp = path; char *tmp = path;
path = malloc(strlen(tmp) + 1); path = malloc(strlen(tmp) + 1);
@ -716,6 +716,9 @@ static void explore(char *path)
} }
done: done:
close_term(); close_term();
if (print_dir)
printf("%s\n", state.path);
if (print_selection)
write_selection(STDOUT_FILENO, state.firstselected); write_selection(STDOUT_FILENO, state.firstselected);
return; return;
} }
@ -723,10 +726,22 @@ done:
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
init_term(); init_term();
char path[MAX_PATH]; char _realpath[MAX_PATH];
if (!realpath(argc > 1 ? argv[1] : ".", 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"); err("realpath failed");
explore(path); explore(_realpath, print_dir, print_selection);
done: done:
return 0; return 0;
} }