6/* a shared library designed to be LD_PRELOADed into SQLite CLI
8If PRYBAR_QUIET is set in the environment, then this suppresses the "Loading
9resources" message due to the CLI's `-init` flag, and also hides the version
10header and help message.
12What happens in SQLite CLI:
141. fprintf to stderr containing the "Loading resources..." message
152. printf containing version and help string
17We need to suppress the output if the PRYBAR_QUIET env var is set. So, we wait
18for the CLI to make calls to libc print functions and intercept them. If they're
19what we expect, then we don't print anything and then advance the state as
22Check out the SQLite CLI code to see what it does:
23https://www.sqlite.org/src/artifact/4e1bcf8c70b8fb97
27// this macro lets us roll up the varargs once instead of in four separate
29#define VAR_PRINT(out, format) \
32 va_start(arg, format); \
33 int rc = vfprintf(out, format, arg); \
39 - no output suppressed
40 - suppressed "Loading resources..." message on stderr
41 - suppressed version and help string on stdout
47} current_state = INITIAL;
49int __fprintf_chk(FILE *out, int flag, const char *format, ...) {
50 // don't do anything; pass through print
51 if (current_state != INITIAL) {
52 VAR_PRINT(out, format);
55 // check if this is the first time we're seeing the output that we're aiming
57 const char *expected = "-- Loading resources from %s\n";
58 if (getenv("PRYBAR_QUIET") && out == stderr &&
59 strcmp(format, expected) == 0) {
60 // advance to next state and suppress output
61 current_state = LOADING_SUPPRESSED;
65 // this isn't the output we were looking for...
66 VAR_PRINT(out, format);
69int __printf_chk(int flag, const char *format, ...) {
70 // don't do anything; pass through print
71 if (current_state != LOADING_SUPPRESSED) {
72 VAR_PRINT(stdout, format);
75 // check if this is the first time we're seeing the output that we're aiming
77 const char *expected = "SQLite version %s %.19s\nEnter \".help\" for usage "
79 if (getenv("PRYBAR_QUIET") && strcmp(format, expected) == 0) {
80 // advance to next state and suppress output
81 current_state = VERSION_SUPPRESSED;
85 // this isn't the output we were looking for...
86 VAR_PRINT(stdout, format);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list