diff options
| author | Ben Winston | 2024-05-30 22:10:26 -0400 |
|---|---|---|
| committer | Ben Winston | 2024-05-30 22:10:26 -0400 |
| commit | b3ee3e63493d53805fe3d81567f794bbf621a985 (patch) | |
| tree | b1876faa7e44dbca6febebfb7dbbbbdba6e72e5f /booki.c | |
| parent | a0bcdfb2d76c08fc816d5e7375d8d5830b630adf (diff) | |
initial commit of 'add', with defaults
Diffstat (limited to 'booki.c')
| -rw-r--r-- | booki.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -622,6 +622,42 @@ void search(int argc, char* argv[], char* booki_file) { } } } +void add(char *booki_file) { + FILE* edit_file = fopen(EDIT_FILE, "w"); + + // 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); + fputs("\n", edit_file); + + // open the file for editing + fclose(edit_file); + open(EDIT_FILE); + + // read in file, add to booki file + FILE* output = fopen(booki_file, "a"); + char* data = load_file(EDIT_FILE); + char* cur_data = data; + struct Book book; + while ((cur_data = next_book(cur_data)) != NULL) { + init_book(&book); + parse_book(cur_data, &book); + print_book(book, true); + write_book(book, output); + free_book(book); + } + free(data); + fclose(output); + unlink(EDIT_FILE); +} + void help(bool err) { printf("booki! it's a thing\n"); @@ -645,6 +681,8 @@ int main(int argc, char* argv[]) { open(booki_file); } else if (strcmp(argv[1], "search") == 0) { search(argc - 1, argv + 1, booki_file); + } else if (strcmp(argv[1], "add") == 0) { + add(booki_file); } else { printf("unknown subcommand: '%s'\n", argv[1]); return 1; |
