Rearranged bb_browse() a little to include more of the setup work.
This commit is contained in:
parent
b2f4d84985
commit
ff1a1388f1
33
bb.c
33
bb.c
@ -19,12 +19,16 @@ static int dirty = 1;
|
|||||||
/*
|
/*
|
||||||
* Use bb to browse the filesystem.
|
* 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;
|
static long cmdpos = 0;
|
||||||
int check_cmds = 1;
|
int check_cmds = 1;
|
||||||
dirty = 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;
|
goto force_check_cmds;
|
||||||
|
|
||||||
while (!bb->should_quit) {
|
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++)
|
for (int i = 0; i < sizeof(signals)/sizeof(signals[0]); i++)
|
||||||
sigaction(signals[i], &sa, NULL);
|
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);
|
write(cmdfd, "\0", 1);
|
||||||
for (int i = 0; i < argc; i++) {
|
for (int i = 0; i < argc; i++) {
|
||||||
if (argv[i][0] == '+') {
|
if (argv[i][0] == '+') {
|
||||||
@ -1284,27 +1281,29 @@ int main(int argc, char *argv[])
|
|||||||
close(cmdfd); cmdfd = -1;
|
close(cmdfd); cmdfd = -1;
|
||||||
|
|
||||||
init_term();
|
init_term();
|
||||||
bb_browse(bb);
|
bb_t bb = {
|
||||||
|
.columns = "*smpn",
|
||||||
|
.sort = "+n"
|
||||||
|
};
|
||||||
|
bb_browse(&bb, full_initial_path);
|
||||||
fputs(T_LEAVE_BBMODE, tty_out);
|
fputs(T_LEAVE_BBMODE, tty_out);
|
||||||
cleanup();
|
cleanup();
|
||||||
|
|
||||||
if (bb->selected && print_selection) {
|
if (bb.selected && print_selection) {
|
||||||
for (entry_t *e = bb->selected; e; e = e->selected.next) {
|
for (entry_t *e = bb.selected; e; e = e->selected.next) {
|
||||||
write(STDOUT_FILENO, e->fullname, strlen(e->fullname));
|
write(STDOUT_FILENO, e->fullname, strlen(e->fullname));
|
||||||
write(STDOUT_FILENO, &sep, 1);
|
write(STDOUT_FILENO, &sep, 1);
|
||||||
}
|
}
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
if (print_dir)
|
if (print_dir)
|
||||||
printf("%s\n", bb->path);
|
printf("%s\n", bb.path);
|
||||||
|
|
||||||
// Cleanup:
|
// Cleanup:
|
||||||
populate_files(bb, NULL);
|
populate_files(&bb, NULL);
|
||||||
while (bb->selected)
|
while (bb.selected)
|
||||||
set_selected(bb, bb->selected, 0);
|
set_selected(&bb, bb.selected, 0);
|
||||||
free(bb);
|
|
||||||
if (cmdfilename) free(cmdfilename);
|
if (cmdfilename) free(cmdfilename);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
bb.h
2
bb.h
@ -191,7 +191,7 @@ const column_t columns[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
void bb_browse(bb_t *bb);
|
void bb_browse(bb_t *bb, const char *initial_path);
|
||||||
static void cleanup(void);
|
static void cleanup(void);
|
||||||
static void cleanup_and_raise(int sig);
|
static void cleanup_and_raise(int sig);
|
||||||
static const char* color_of(mode_t mode);
|
static const char* color_of(mode_t mode);
|
||||||
|
Loading…
Reference in New Issue
Block a user