diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2006-02-09 18:16:10 +0100 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2006-02-09 18:16:10 +0100 |
commit | bed947bd0e8a76d458e6997eec1c82c95842cb27 (patch) | |
tree | cb2c2d90ef02ed535b7e54a21ecc92e685a967e0 | |
parent | 13278eaedfccf32ea897ef187d82d047af903557 (diff) |
new version without extra feeder process
-rw-r--r-- | src/GsWidget.H | 10 | ||||
-rw-r--r-- | src/GsWidget.cxx | 88 | ||||
-rw-r--r-- | src/PSEditor.H | 4 | ||||
-rw-r--r-- | src/PSEditor.cxx | 8 | ||||
-rw-r--r-- | src/flpsed.cxx | 7 |
5 files changed, 62 insertions, 55 deletions
diff --git a/src/GsWidget.H b/src/GsWidget.H index 0735607..370de14 100644 --- a/src/GsWidget.H +++ b/src/GsWidget.H @@ -58,10 +58,12 @@ public: GsWidget(int X,int Y,int W, int H); ~GsWidget(); - - int load(char *f); + + int open_file(char *f); - int load(int fd); + int open_file(int fd); + + int load(); int load_page(int p); @@ -84,8 +86,6 @@ private: int fd_copy(int to, int from, size_t len); - int feed_page(int p); - bool gs_active(); }; #endif diff --git a/src/GsWidget.cxx b/src/GsWidget.cxx index 14d77f9..888d599 100644 --- a/src/GsWidget.cxx +++ b/src/GsWidget.cxx @@ -29,6 +29,7 @@ #include <errno.h> #include <sys/wait.h> #include <fcntl.h> +#include <signal.h> #include <FL/fl_draw.H> @@ -68,7 +69,7 @@ void GsWidget::setProps() { atoms[3] = XInternAtom(fl_display,"PAGE" , false); atoms[4] = XInternAtom(fl_display,"DONE" , false); - snprintf(data, 512, "%d %d %d %d %d %d %d.0 %d.0", + snprintf(data, sizeof(data), "%d %d %d %d %d %d %d.0 %d.0", 0, 0, 0, 0, paper_x, paper_y, xdpi, ydpi); int xid = fl_xid(window()); @@ -77,7 +78,7 @@ void GsWidget::setProps() { XA_STRING, 8, PropModeReplace, (unsigned char*) data, strlen(data)); - snprintf(data, 512, "%s %d %d", "Color", + snprintf(data, sizeof(data), "%s %d %d", "Color", (int) BlackPixel(fl_display, DefaultScreen(fl_display)), (int) WhitePixel(fl_display, DefaultScreen(fl_display))); @@ -123,18 +124,16 @@ GsWidget::~GsWidget() { } } -int GsWidget::load(char *f) { +int GsWidget::open_file(char *f) { int fd = open(f, O_RDONLY); if (fd == -1) { perror("open"); return 1; } - return load(fd); + return open_file(fd); } -int GsWidget::load(int fd) { - pid_t pid; - +int GsWidget::open_file(int fd) { if (in_fd >= 0 && fd != in_fd) { close (in_fd); } @@ -150,6 +149,17 @@ int GsWidget::load(int fd) { paper_y = bb_h; } + return 0; +} + + +int GsWidget::load() { + pid_t pid; + + if (in_fd < 0) { + return 1; + } + lseek(in_fd, 0L, SEEK_SET); fl_cursor(FL_CURSOR_WAIT); @@ -177,6 +187,11 @@ int GsWidget::load(int fd) { int GsWidget::load_page(int p) { pid_t pid; + int pdes[2]; + + if (in_fd < 0) { + return 1; + } if (p < 1 || p > dsc->get_pages()) { fprintf(stderr, "Page %d not found in document\n", p); @@ -186,51 +201,46 @@ GsWidget::load_page(int p) { fl_cursor(FL_CURSOR_WAIT); kill_gs(); - setProps(); - - pid = fork(); - - if (pid == (pid_t) 0) { - feed_page(p); - exit(0); - } else { - gs_pid = pid; - } -} - -int GsWidget::feed_page(int p) { - pid_t pid; - int pdes[2]; - if (pipe(pdes) < 0) { - return 1; + perror("pipe"); + return 1; } - pid = fork(); + lseek(in_fd, 0L, SEEK_SET); + setProps(); + pid = fork(); if (pid == (pid_t) 0) { + close(in_fd); close(pdes[1]); dup2(pdes[0], STDIN_FILENO); exec_gs(); } else { size_t len; + gs_pid = pid; + page = p; + close(pdes[0]); lseek(in_fd, 0L, SEEK_SET); len = dsc->get_setup_len(); if (fd_copy(pdes[1], in_fd, len) != 0) { - exit(1); + close(pdes[1]); + return 1; } - + lseek(in_fd, dsc->get_page_off(p), SEEK_SET); len = dsc->get_page_len(p); if (fd_copy(pdes[1], in_fd, len) != 0) { - exit(1); + close(pdes[1]); + return 1; } - } + close(pdes[1]); + } + return 0; } int GsWidget::fd_copy(int to, int from, size_t len) { @@ -239,13 +249,15 @@ int GsWidget::fd_copy(int to, int from, size_t len) { n = 0; while(len > 0) { + Fl::check(); // let fltk do its stuff - otherwise + // gs can't get the GHOSTVIEW property r = read(from, buf, MIN(sizeof(buf), len)); - write(STDOUT_FILENO, buf, r); if (r < 0) { perror("read"); return 1; } + write(to, buf, r); len -= r; } @@ -259,9 +271,9 @@ void GsWidget::exec_gs() { int d_null = open("/dev/null", O_WRONLY); dup2(d_null, STDOUT_FILENO); - close(d_null); - snprintf(gvenv, 256, "%d %d", (int) fl_xid(window()), (int) offscreen); + snprintf(gvenv, sizeof(gvenv), "%d %d", + (int) fl_xid(window()), (int) offscreen); setenv("GHOSTVIEW", gvenv, 1); argv[0] = "gs"; @@ -269,8 +281,9 @@ void GsWidget::exec_gs() { argv[2] = "-dQUIET"; argv[3] = "-sDEVICE=x11alpha"; argv[4] = "-dNOPLATFONTS"; - argv[5] = "-"; - argv[6] = NULL; + argv[5] = "-dNOPAUSE"; + argv[6] = "-"; + argv[7] = NULL; execvp(argv[0], argv); perror("exec"); fprintf(stderr, "Please install ghostscript and make sure 'gs' " @@ -282,12 +295,7 @@ int GsWidget::reload() { int ret; if (in_fd >= 0) { - ret = lseek(in_fd, 0L, SEEK_SET); - if (ret == -1) { - perror("lseek"); - return 1; - } - load(in_fd); + open_file(in_fd); return 0; } else { return 1; diff --git a/src/PSEditor.H b/src/PSEditor.H index 6bba6d3..a1926ee 100644 --- a/src/PSEditor.H +++ b/src/PSEditor.H @@ -37,9 +37,9 @@ class PSEditor : public PSEditWidget { public: PSEditor(int X,int Y,int W, int H); - int load(FILE *fp); + int open_file(FILE *fp); - int load(const char *f); + int open_file(const char *f); int save(FILE *fp); diff --git a/src/PSEditor.cxx b/src/PSEditor.cxx index cc620d4..a2df43f 100644 --- a/src/PSEditor.cxx +++ b/src/PSEditor.cxx @@ -110,7 +110,7 @@ int PSEditor::handle(int event) { } -int PSEditor::load(FILE *fp) { +int PSEditor::open_file(FILE *fp) { if (tmp_fd) { close(tmp_fd); } @@ -122,11 +122,11 @@ int PSEditor::load(FILE *fp) { } else { mod = 0; loaded = 1; - return GsWidget::load(tmp_fd); + return GsWidget::open_file(tmp_fd); } } -int PSEditor::load(const char *f) { +int PSEditor::open_file(const char *f) { FILE *fp; int ret; @@ -136,7 +136,7 @@ int PSEditor::load(const char *f) { return 1; } - ret = load(fp); + ret = open_file(fp); fclose(fp); return ret; diff --git a/src/flpsed.cxx b/src/flpsed.cxx index a341fc2..596d1ac 100644 --- a/src/flpsed.cxx +++ b/src/flpsed.cxx @@ -24,7 +24,6 @@ #include <stdio.h> #include <string.h> #include <unistd.h> -#include <signal.h> #include <stdlib.h> #include <sys/types.h> #include <sys/wait.h> @@ -81,8 +80,8 @@ void open_cb() { if (!check_save()) return; char *file = fl_file_chooser("Open File?", "*.ps", filename); if(file != NULL) { - psed_p->load(file); + psed_p->open_file(file); psed_p->load_page(2); } } @@ -105,7 +104,7 @@ void import_pdf_cb() { p = pexecvp("pdftops", args, &pid, "r"); if (p) { - psed_p->load(p); + psed_p->open_file(p); fclose(p); waitpid(pid, &status, 0); if (WEXITSTATUS(status) == 127 || WEXITSTATUS(status) == 126) { @@ -531,7 +530,7 @@ int main(int argc, char** argv) { if (in_fp) { sleep(1); // this seems to be necessary on fast systems to make the // GHOSTVIEW property available to ghostsscript. - psed_p->load(in_fp); + psed_p->open_file(in_fp); fclose(in_fp); } |