aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--booki.c41
1 files changed, 17 insertions, 24 deletions
diff --git a/booki.c b/booki.c
index 96d42a9..060a4af 100644
--- a/booki.c
+++ b/booki.c
@@ -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);
}
}