From 25da85de6a1eca08de94bbc9f1b63ae9a7c87841 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Sun, 24 Oct 2004 16:28:37 +0000 Subject: move parsing from PSEditor to PSEditModel. move parsing from PSEditor to PSEditModel. --- src/GsWidget.cxx | 10 +++++----- src/PSEditModel.H | 3 ++- src/PSEditModel.cxx | 46 +++++++++++++++++++++++++++++++++++++++++++++- src/PSEditor.cxx | 48 ++++++++++-------------------------------------- 4 files changed, 62 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/GsWidget.cxx b/src/GsWidget.cxx index 946e0c0..7765e1b 100644 --- a/src/GsWidget.cxx +++ b/src/GsWidget.cxx @@ -1,5 +1,5 @@ // -// "$Id: GsWidget.cxx,v 1.8 2004/10/12 17:14:16 hofmann Exp $" +// "$Id: GsWidget.cxx,v 1.9 2004/10/24 18:28:37 hofmann Exp $" // // GsWidget routines. // @@ -67,7 +67,7 @@ void GsWidget::setProps() { atoms[4] = XInternAtom(fl_display,"DONE" , false); snprintf(data, 512, "%lu %d %d %d %d %d %g %g", - 0, 0, 0, 0, paper_x, paper_y, xdpi, ydpi); + 0, 0, 0, 0, paper_x, paper_y, xdpi, ydpi); int xid = fl_xid(window()); @@ -84,7 +84,7 @@ void GsWidget::setProps() { void GsWidget::kill_gs() { int status; - + fprintf(stderr, "Killing...\n"); if (gs_pid > 0) { kill(gs_pid, SIGTERM); waitpid(gs_pid, &status, 0); @@ -219,8 +219,8 @@ int GsWidget::handleX11(int ev) { damage(FL_DAMAGE_ALL); fl_cursor(FL_CURSOR_DEFAULT); } else if(fl_xevent->xclient.message_type == atoms[4] ) { - kill_gs(); // DONE received - fl_cursor(FL_CURSOR_DEFAULT); + kill_gs(); + fl_cursor(FL_CURSOR_DEFAULT); // DONE received } return 1; } diff --git a/src/PSEditModel.H b/src/PSEditModel.H index e601afc..bfe1b98 100644 --- a/src/PSEditModel.H +++ b/src/PSEditModel.H @@ -1,5 +1,5 @@ // -// "$Id: PSEditModel.H,v 1.4 2004/10/23 19:57:14 hofmann Exp $" +// "$Id: PSEditModel.H,v 1.5 2004/10/24 18:28:37 hofmann Exp $" // // X11 header file for the Fast Light Tool Kit (FLTK). // @@ -60,6 +60,7 @@ public: int ps_to_display_y(int y1); int ps_x(int x1); int ps_y(int y1); + int PSEditModel::load(char *f); }; #endif diff --git a/src/PSEditModel.cxx b/src/PSEditModel.cxx index 368a667..75f96ee 100644 --- a/src/PSEditModel.cxx +++ b/src/PSEditModel.cxx @@ -1,5 +1,5 @@ // -// "$Id: PSEditModel.cxx,v 1.4 2004/10/23 19:57:14 hofmann Exp $" +// "$Id: PSEditModel.cxx,v 1.5 2004/10/24 18:28:37 hofmann Exp $" // // PSEditWidget routines. // @@ -27,6 +27,7 @@ #include #include +#include "Postscript.H" #include "PSEditText.H" #include "PSEditModel.H" @@ -215,3 +216,46 @@ int PSEditModel::ps_x(int x1) { int PSEditModel::ps_y(int y1) { return paper_y - (int)((float) y1 * 72.0 / ydpi); } + +int PSEditModel::load(char *f) { + FILE *fp; + char tmpname[256]; + char linebuf[1024]; + int ret; + PSParser *p1 = new PSParser_1(this); + PSParser *p2 = new PSParser_2(this); + int tmp_fd; + + fp = fopen(f, "r"); + if (!fp) { + fprintf(stderr, "Could not open file %s.\n", f); + return -1; + } + + strncpy(tmpname, "/tmp/PSEditorXXXXXX", 256); + tmp_fd = mkstemp(tmpname); + if (tmp_fd < 0) { + fprintf(stderr, "Could not create temporary file (errno %d).\n", errno); + return -1; + } + unlink(tmpname); + + clear(); + + while (fgets(linebuf, 1024, fp) != NULL) { + if (!p2->parse(linebuf) && !p1->parse(linebuf)) { + ret = write(tmp_fd, linebuf, strlen(linebuf)); + if (ret != strlen(linebuf)) { + fprintf(stderr, "Error while writing to temporary file\n"); + } + } + } + + fclose(fp); + lseek(tmp_fd, 0L, SEEK_SET); + + delete(p1); + delete(p2); + + return tmp_fd; +} diff --git a/src/PSEditor.cxx b/src/PSEditor.cxx index d263360..bc4541e 100644 --- a/src/PSEditor.cxx +++ b/src/PSEditor.cxx @@ -1,5 +1,5 @@ // -// "$Id: PSEditor.cxx,v 1.14 2004/10/23 19:57:14 hofmann Exp $" +// "$Id: PSEditor.cxx,v 1.15 2004/10/24 18:28:37 hofmann Exp $" // // PSEditor routines. // @@ -116,47 +116,19 @@ int PSEditor::handle(int event) { int PSEditor::load(char *f) { - FILE *fp; - char tmpname[256]; - char linebuf[1024]; - int ret; - PSParser *p1 = new PSParser_1(model); - PSParser *p2 = new PSParser_2(model); - - fp = fopen(f, "r"); - if (!fp) { - fprintf(stderr, "Could not open file %s.\n", f); - return 1; + if (tmp_fd) { + close(tmp_fd); + tmp_fd = -1; } - - strncpy(tmpname, "/tmp/PSEditorXXXXXX", 256); - tmp_fd = mkstemp(tmpname); + + tmp_fd = model->load(f); if (tmp_fd < 0) { - fprintf(stderr, "Could not create temporary file (errno %d).\n", errno); return 1; + } else { + mod = 0; + loaded = 1; + return GsWidget::load(tmp_fd); } - unlink(tmpname); - - clear_text(); - - while (fgets(linebuf, 1024, fp) != NULL) { - if (!p2->parse(linebuf) && !p1->parse(linebuf)) { - ret = write(tmp_fd, linebuf, strlen(linebuf)); - if (ret != strlen(linebuf)) { - fprintf(stderr, "Error while writing to temporary file\n"); - } - } - } - - fclose(fp); - lseek(tmp_fd, 0L, SEEK_SET); - - delete(p1); - delete(p2); - - mod = 0; - loaded = 1; - return GsWidget::load(tmp_fd); } int PSEditor::save(const char* savefile) { -- cgit v1.2.3