diff options
| -rw-r--r-- | booki.c | 21 |
1 files changed, 6 insertions, 15 deletions
@@ -53,8 +53,6 @@ struct Book* init_book(struct Book* book) { return book; } -char* BOOKI_FILE; - int PARSE_LINE = 1; const char* get_last_word(const char* str) { @@ -383,12 +381,12 @@ void print_book(struct Book book, bool all_fields) { } } -char** search(int argc, char* argv[]) { +char** search(int argc, char* argv[], char* booki_file) { struct search_opt search_opts = parse_search_options(argc, argv); bool print = false; // get the books array - char* data = load_file(BOOKI_FILE); + char* data = load_file(booki_file); if (!data) { printf("no such array: 'books'"); return NULL; @@ -451,13 +449,7 @@ char** search(int argc, char* argv[]) { } -void open() { - - char* home = getenv("HOME"); - if (!home) { - printf("no home?\n"); - home = "/"; // no way - } +void open(char* filepath) { char* editor = getenv("EDITOR"); if (!editor) editor = "nano"; @@ -469,7 +461,7 @@ void open() { printf("fork has failed!\n"); break; case 0: - execlp(editor, editor, BOOKI_FILE, NULL); + execlp(editor, editor, filepath, NULL); printf("child failed :(\n"); break; default: @@ -491,16 +483,15 @@ int main(int argc, char* argv[]) { char* home = getenv("HOME"); char booki_file[strlen(home) + strlen(BOOKI_FILE_REL) + 1]; sprintf(booki_file, "%s/%s", home, BOOKI_FILE_REL); - BOOKI_FILE = booki_file; char** remaining = NULL; if (argc == 1) { help(false); return 0; } else if (strcmp(argv[1], "open") == 0) { - open(); + open(booki_file); } else if (strcmp(argv[1], "search") == 0) { - remaining = search(argc - 1, argv + 1); + remaining = search(argc - 1, argv + 1, booki_file); } return 0; |
