summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2007-07-17 18:39:08 +0200
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2007-07-17 18:39:08 +0200
commitcbd0c8a0cb782887a0868edfd8c8c234c2c8e32e (patch)
tree461efdf78e2fb91114f6f97ef9702c7f05a8464a /src
parent4269e5747c6ea6c159c57519c7fee4b533590de9 (diff)
ask before overwriting files
Diffstat (limited to 'src')
-rw-r--r--src/flpsed.cxx14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/flpsed.cxx b/src/flpsed.cxx
index b5b0f60..363aa3f 100644
--- a/src/flpsed.cxx
+++ b/src/flpsed.cxx
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
@@ -75,6 +76,15 @@ int check_save(void) {
return (r == 2) ? 1 : 0;
}
+static int
+confirm_overwrite(const char *f) {
+ struct stat sb;
+ if (stat(f, &sb) == 0) {
+ return fl_choice("The file exists.\n", "Cancel", "Overwrite", NULL);
+ } else {
+ return 1;
+ }
+}
char filename[256] = "";
@@ -161,7 +171,7 @@ void export_pdf_cb() {
pid_t pid;
file = fl_file_chooser("Open File?", "*.pdf", filename);
- if(file != NULL) {
+ if(file != NULL && confirm_overwrite(file)) {
args[0] = "ps2pdf";
args[1] = "-";
args[2] = file;
@@ -215,7 +225,7 @@ void quit_cb() {
void save_cb() {
char *file = fl_file_chooser("Open File?", "*.ps", filename);
- if (file != NULL) {
+ if (file != NULL && confirm_overwrite(file)) {
psed_p->save(file);
}
}