diff options
| author | Ben Winston | 2024-05-07 21:00:44 -0400 |
|---|---|---|
| committer | Ben Winston | 2024-05-07 21:03:08 -0400 |
| commit | 0828cd6ff91c083dd470cf0e511914cd06b9ffff (patch) | |
| tree | 4f9249ee6b66a3103f93d0df46f3bb3f3ce41f48 | |
| parent | ec4545806552880edad3e1e609060b93652bb925 (diff) | |
fix --show
| -rw-r--r-- | booki.c | 41 |
1 files changed, 17 insertions, 24 deletions
@@ -259,8 +259,23 @@ struct search_opt parse_search_options(int argc, char* argv[]) { return opt_out; } -void print_book(struct Book book) { +void print_book(struct Book book, bool all_fields) { printf("%.*s by %.*s\n", book.title.len, book.title.ptr, book.author.len, book.author.ptr); + if (all_fields) { + char* esfmt = " - %s: %.*s\n"; + char* intfmt = " - %s: %d\n"; + if (book.isbn.ptr) + printf(esfmt, "isbn", book.isbn.len, book.isbn.ptr); + if (book.pages != 0) + printf(intfmt, "pages", book.pages); + if (book.published) + printf(esfmt, "published", book.published); + if (book.language.ptr) + printf(esfmt, "language", book.language.len, book.language.ptr); + if (book.translator.ptr) + printf(esfmt, "translator", book.translator.len, book.translator.ptr); + + } } char** search(int argc, char* argv[]) { @@ -301,29 +316,7 @@ char** search(int argc, char* argv[]) { print = i == search_opts.count; if (print) { - print_book(book); - - /* TODO fix - if (search_opts.show) { - //toml_datum_t d; - for (int i = 0; ; i++) { - const char* key = toml_key_in(book, i); - if (!key) break; - - // currently we support strings and ints - toml_datum_t s = toml_string_in(book, key); - if (s.ok) { - printf(" - %s: %s\n", key, s.u.s); - free(s.u.s); - } - toml_datum_t i = toml_int_in(book, key); - if (i.ok) { - printf(" - %s: %d\n", key, i.u.i); - } - - } - } - */ + print_book(book, search_opts.show); } } |
