diff options
Diffstat (limited to 'booki.c')
| -rw-r--r-- | booki.c | 34 |
1 files changed, 32 insertions, 2 deletions
@@ -7,8 +7,8 @@ #include <sys/wait.h> #include <unistd.h> -#define EDIT_FILE "edit.toml" -#define FIXED_FILE "fixed.toml" +#define EDIT_FILE "/tmp/booki-edit.toml" +#define FIXED_FILE "/tmp/booki-fixed.toml" #define MAX_SEARCH_OPTS 5 @@ -488,6 +488,24 @@ void open(char* filepath) { } } +bool copy(char* src, char* dest) { + pid_t pid; + int status; + switch((pid = fork())) { + case -1: + printf("fork failed\n"); + return false; + case 0: + execl("/bin/cp", "/bin/cp", src, dest, NULL); + printf("copy failed\n"); + return false; + default: + // wait for the chlid to finish + pid = wait(&status); + return true; + } +} + void free_es(struct es* str) { if (str == NULL) return; struct es* tmp; @@ -572,8 +590,11 @@ void search(int argc, char* argv[], char* booki_file) { // if we're editing, both files are open at this point if (search_opts.edit) { + // first, close and let the user edit fclose(edit_file); open(EDIT_FILE); + + // after they've edited, read it in and add it to fixed_file data = load_file(EDIT_FILE); if (!data) { printf("can't open edit file\n"); @@ -588,6 +609,15 @@ void search(int argc, char* argv[], char* booki_file) { } fclose(fixed_file); + + // copy the fixed_file to booki file + bool success = copy(FIXED_FILE, booki_file); + if (!success) { + printf("failed! fixed file is here: %s\n", FIXED_FILE); + } else { + unlink(EDIT_FILE); + unlink(FIXED_FILE); + } } } |
