From 886a904459e87f46f3f43df434307a294f85e52d Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Mon, 28 Feb 2005 16:56:51 +0000 Subject: implement pdf export / import implement pdf export / import --- src/flpsed.cxx | 67 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 23 deletions(-) (limited to 'src/flpsed.cxx') diff --git a/src/flpsed.cxx b/src/flpsed.cxx index c3e13e0..3c712c2 100644 --- a/src/flpsed.cxx +++ b/src/flpsed.cxx @@ -1,5 +1,5 @@ // -// "$Id: flpsed.cxx,v 1.30 2005/02/03 18:10:17 hofmann Exp $" +// "$Id: flpsed.cxx,v 1.31 2005/02/28 17:56:51 hofmann Exp $" // // flpsed program. // @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -41,6 +42,7 @@ #include #include "PSEditor.H" +#include "util.h" PSEditor *psed_p = NULL; Fl_Scroll *scroll = NULL; @@ -82,52 +84,72 @@ void open_cb() { } void import_pdf_cb() { + char *file; + FILE *p; + int status; + char *args[32]; + pid_t pid; + if (!check_save()) return; - char *file = fl_file_chooser("Open File?", "*.pdf", filename); + file = fl_file_chooser("Open File?", "*.pdf", filename); if(file != NULL) { - FILE *p; - int ret; - char cmd[1000]; + args[0] = "pdftops"; + args[1] = file; + args[2] = "-"; + args[3] = NULL; + + p = pexecvp("pdftops", args, &pid, "r"); - snprintf(cmd, sizeof(cmd), "pdftops \"%s\" -", file); - p = popen(cmd, "r"); if (p) { psed_p->load(p); - ret = pclose(p); - if (WEXITSTATUS(ret) == 127 || WEXITSTATUS(ret) == 126) { + fclose(p); + waitpid(pid, &status, 0); + if (WEXITSTATUS(status) == 127 || WEXITSTATUS(status) == 126) { fl_message("PDF import depends on pdftops from xpdf.\n" "Make sure pdftops is available on your system.\n"); - } else if (WEXITSTATUS(ret) != 0) { + } else if (WEXITSTATUS(status) != 0) { fl_message("PDF import failed\n"); } } else { - perror("popen"); + perror("pexecvp"); } } } void export_pdf_cb() { - if (!check_save()) return; - char *file = fl_file_chooser("Open File?", "*.pdf", filename); + char *file; + FILE *p; + int status; + char *args[32]; + pid_t pid; + + file = fl_file_chooser("Open File?", "*.pdf", filename); if(file != NULL) { - FILE *p; - int ret; - char cmd[1000]; + args[0] = "ps2pdf"; + args[1] = "-"; + args[2] = file; + args[3] = NULL; + + signal(SIGPIPE, SIG_IGN); - snprintf(cmd, sizeof(cmd), "ps2pdf - \"%s\"", file); - p = popen(cmd, "w"); + p = pexecvp("ps2pdf", args, &pid, "w"); + if (p) { psed_p->save(p); - ret = pclose(p); - if (WEXITSTATUS(ret) == 127 || WEXITSTATUS(ret) == 126) { + + fclose(p); + waitpid(pid, &status, 0); + if (WEXITSTATUS(status) == 127 || WEXITSTATUS(status) == 126) { fl_message("PDF export depends on ps2pdf from ghostscript.\n" "Make sure ps2pdf is available on your system.\n"); - } else if (WEXITSTATUS(ret) != 0) { + } else if (WEXITSTATUS(status) != 0) { fl_message("PDF export failed\n"); } } else { - perror("pclose"); + perror("pexecvp"); } + + signal(SIGPIPE, SIG_DFL); } } @@ -297,7 +319,6 @@ int main(int argc, char** argv) { int err, bflag = 0, dflag = 0; Fl_Window *win; Fl_Menu_Bar *m; - Fl_Int_Input *x_in, *y_in; struct {char *tag; char *value;} tv[TV_LEN]; int tv_idx = 0, my_argc; FILE *in_fp = NULL, *out_fp = NULL; -- cgit v1.2.3