aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-11-11 10:48:12 -0800
committerBruce Hill <bruce@bruce-hill.com>2019-11-11 10:48:12 -0800
commitff1a1388f1dd80d8d818736237c790e163a46c1d (patch)
tree7c7cc821d54ebcf5932680958e4015946902bd65
parentb2f4d849850052ad7915771397396c60c2e0ad9e (diff)
Rearranged bb_browse() a little to include more of the setup work.
-rw-r--r--bb.c33
-rw-r--r--bb.h2
2 files changed, 17 insertions, 18 deletions
diff --git a/bb.c b/bb.c
index 232dee1..86c334b 100644
--- a/bb.c
+++ b/bb.c
@@ -19,12 +19,16 @@ static int dirty = 1;
/*
* Use bb to browse the filesystem.
*/
-void bb_browse(bb_t *bb)
+void bb_browse(bb_t *bb, const char *initial_path)
{
static long cmdpos = 0;
int check_cmds = 1;
dirty = 1;
+ if (populate_files(bb, initial_path))
+ err("Could not find initial path: \"%s\"", initial_path);
+ run_script(bb, runstartup);
+
goto force_check_cmds;
while (!bb->should_quit) {
@@ -1259,13 +1263,6 @@ int main(int argc, char *argv[])
for (int i = 0; i < sizeof(signals)/sizeof(signals[0]); i++)
sigaction(signals[i], &sa, NULL);
- bb_t *bb = memcheck(calloc(1, sizeof(bb_t)));
- strcpy(bb->columns, "*smpn");
- strcpy(bb->sort, "+n");
- if (populate_files(bb, full_initial_path))
- err("Could not find initial path: \"%s\"", initial_path);
-
- run_script(bb, runstartup);
write(cmdfd, "\0", 1);
for (int i = 0; i < argc; i++) {
if (argv[i][0] == '+') {
@@ -1284,27 +1281,29 @@ int main(int argc, char *argv[])
close(cmdfd); cmdfd = -1;
init_term();
- bb_browse(bb);
+ bb_t bb = {
+ .columns = "*smpn",
+ .sort = "+n"
+ };
+ bb_browse(&bb, full_initial_path);
fputs(T_LEAVE_BBMODE, tty_out);
cleanup();
- if (bb->selected && print_selection) {
- for (entry_t *e = bb->selected; e; e = e->selected.next) {
+ if (bb.selected && print_selection) {
+ for (entry_t *e = bb.selected; e; e = e->selected.next) {
write(STDOUT_FILENO, e->fullname, strlen(e->fullname));
write(STDOUT_FILENO, &sep, 1);
}
fflush(stdout);
}
if (print_dir)
- printf("%s\n", bb->path);
+ printf("%s\n", bb.path);
// Cleanup:
- populate_files(bb, NULL);
- while (bb->selected)
- set_selected(bb, bb->selected, 0);
- free(bb);
+ populate_files(&bb, NULL);
+ while (bb.selected)
+ set_selected(&bb, bb.selected, 0);
if (cmdfilename) free(cmdfilename);
-
return 0;
}
diff --git a/bb.h b/bb.h
index fc7e3af..5ea35ae 100644
--- a/bb.h
+++ b/bb.h
@@ -191,7 +191,7 @@ const column_t columns[] = {
};
// Functions
-void bb_browse(bb_t *bb);
+void bb_browse(bb_t *bb, const char *initial_path);
static void cleanup(void);
static void cleanup_and_raise(int sig);
static const char* color_of(mode_t mode);