From 1a7ee1a66cb0878189ee3f2b31d3ef4a48bfd63a Mon Sep 17 00:00:00 2001 From: Ben Winston Date: Fri, 7 Jun 2024 23:05:19 -0400 Subject: when adding a new book, use the defined fields --- booki.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/booki.c b/booki.c index d9ecfbb..d076720 100644 --- a/booki.c +++ b/booki.c @@ -959,14 +959,21 @@ void add(char *booki_file) { // load an empty book to the edit file fputs("[[books]]\n", edit_file); - fputs("#isbn = \"\"\n", edit_file); - fputs("title = \"\"\n", edit_file); - fputs("author = \"\"\n", edit_file); - fputs("#pages = 0\n", edit_file); - fputs("#published = 0\n", edit_file); - fputs("language = \"English\"\n", edit_file); - fputs("#translator = \"\"\n", edit_file); - fputs("#on = \"\"\n", edit_file); + DataField datafield; + for (int i = 0; i < BOOK_FIELDS_COUNT; i++) { + datafield = BOOK_FIELDS[i]; + // skip ID for new books + if (ATTR_MATCH(datafield.name, "id")) + continue; + // otherwise, always write the name first + fputs(datafield.name, edit_file); + if (datafield.type == booki_string) + fputs(" = \"\"\n", edit_file); + else if (datafield.type == booki_number) + fputs(" = 0\n", edit_file); + else + fputs(" = ?\n", edit_file); + } fputs("\n", edit_file); // open the file for editing -- cgit v1.2.3