aboutsummaryrefslogtreecommitdiff
path: root/booki.c
diff options
context:
space:
mode:
authorBen Winston2024-06-07 23:05:19 -0400
committerBen Winston2024-06-07 23:05:19 -0400
commit1a7ee1a66cb0878189ee3f2b31d3ef4a48bfd63a (patch)
tree223b3f99a5156d15be8ebf3520dac4f2b2586644 /booki.c
parent0f7d71e15e2671125330dbea0104ac58b9353188 (diff)
when adding a new book, use the defined fields
Diffstat (limited to 'booki.c')
-rw-r--r--booki.c23
1 files 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