code / bb

Lines2.7K C1.8K Shell331 YAML273 Markdown197 make44
(87 lines)
1 //
2 // types.h
3 // Copyright 2020 Bruce Hill
4 // Released under the MIT license with the Commons Clause
5 //
6 // This file contains definitions of different types.
7 //
8 #ifndef FILE_TYPES__H
9 #define FILE_TYPES__H
11 #include <limits.h>
12 #include <sys/stat.h>
13 #include <sys/types.h>
14 #include <unistd.h>
16 #define MAX_COLS 12
17 #define MAX_SORT (2 * MAX_COLS)
18 #define HASH_SIZE 1024
19 #define HASH_MASK (HASH_SIZE - 1)
21 //
22 // Datastructure for file/directory entries.
23 // entry_t uses intrusive linked lists. This means entries can only belong to
24 // one list at a time, in this case the list of selected entries. 'atme' is an
25 // indirect pointer to either the 'next' field of the previous list member, or
26 // the variable that points to the first list member. In other words,
27 // item->next->atme == &item->next and firstitem->atme == &firstitem.
28 //
29 typedef struct entry_s {
30 struct {
31 struct entry_s *next, **atme;
32 } selected, hash;
33 char *name, *linkname;
34 struct stat info;
35 mode_t linkedmode;
36 int no_esc : 1;
37 int link_no_esc : 1;
38 int shufflepos;
39 int index;
40 char fullname[1];
41 // ------- fullname must be last! --------------
42 // When entries are allocated, extra space on the end is reserved to fill
43 // in fullname.
44 } entry_t;
46 // For keeping track of child processes:
47 typedef struct proc_s {
48 pid_t pid;
49 struct {
50 struct proc_s *next, **atme;
51 } running;
52 } proc_t;
54 // History of paths
55 typedef struct bb_history_s {
56 char path[PATH_MAX];
57 struct bb_history_s *prev, *next;
58 } bb_history_t;
60 // Structure for bb program state:
61 typedef struct bb_s {
62 entry_t *hash[HASH_SIZE];
63 entry_t **files;
64 entry_t *selected;
65 char path[PATH_MAX];
66 bb_history_t *history;
67 int nfiles, nselected;
68 int scroll, cursor;
70 char *globpats;
71 char sort[MAX_SORT + 1];
72 char columns[MAX_COLS + 1];
73 unsigned int interleave_dirs : 1;
74 unsigned int should_quit : 1;
75 unsigned int dirty : 1;
76 proc_t *running_procs;
77 } bb_t;
79 // Key bindings:
80 typedef struct {
81 int key;
82 const char *script;
83 const char *description;
84 } binding_t;
86 #endif
87 // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0