From 51bd38e8d2448350afe349f2f64367d1af9b27cc Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Mon, 11 Oct 2004 12:44:47 +0000 Subject: added import feature added import feature --- src/PSEditor.H | 3 ++- src/PSEditor.cxx | 43 ++++++++++++++++++++++++++++++++++++++++--- src/flpsed.cxx | 10 +++++++++- 3 files changed, 51 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/PSEditor.H b/src/PSEditor.H index 5484ced..dc7545c 100644 --- a/src/PSEditor.H +++ b/src/PSEditor.H @@ -1,5 +1,5 @@ // -// "$Id: PSEditor.H,v 1.2 2004/07/18 20:49:43 hofmann Exp $" +// "$Id: PSEditor.H,v 1.3 2004/10/11 14:44:47 hofmann Exp $" // // X11 header file for the Fast Light Tool Kit (FLTK). // @@ -40,6 +40,7 @@ public: PSEditor(int X,int Y,int W, int H); int load(char *f); int save(const char* savefile); + int import(char *f); int modified(); int file_loaded(); void set_ps_level(int l); diff --git a/src/PSEditor.cxx b/src/PSEditor.cxx index 308d0dd..963c9fb 100644 --- a/src/PSEditor.cxx +++ b/src/PSEditor.cxx @@ -1,5 +1,5 @@ // -// "$Id: PSEditor.cxx,v 1.8 2004/07/28 20:15:48 hofmann Exp $" +// "$Id: PSEditor.cxx,v 1.9 2004/10/11 14:44:47 hofmann Exp $" // // PSEditor routines. // @@ -110,14 +110,21 @@ int PSEditor::file_loaded() { return loaded; } + int PSEditor::load(char *f) { - FILE *fp = fopen(f, "r"); + FILE *fp; char tmpname[256]; char linebuf[1024]; int size, ret, ret1, ret2; PSParser *p1 = new PSParser_1(this); PSParser *p2 = new PSParser_2(this); + 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) { @@ -129,7 +136,6 @@ int PSEditor::load(char *f) { 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)) { @@ -137,6 +143,7 @@ int PSEditor::load(char *f) { } } } + fclose(fp); lseek(tmp_fd, 0L, SEEK_SET); @@ -175,6 +182,36 @@ int PSEditor::save(const char* savefile) { return 0; } +int PSEditor::import(char *f) { + FILE *fp; + char linebuf[1024]; + PSParser *p1; + PSParser *p2; + + if (!file_loaded()) { + return 1; + } + + fp = fopen(f, "r"); + if (!fp) { + fprintf(stderr, "Could not open file %s.\n", f); + return 1; + } + + p1 = new PSParser_1(this); + p2 = new PSParser_2(this); + while (fgets(linebuf, 1024, fp) != NULL) { + if (!p2->parse(linebuf)) { + p1->parse(linebuf); + } + } + + delete(p1); + delete(p2); + + mod = 1; +} + int PSEditor::get_ps_level() { return ps_level; } diff --git a/src/flpsed.cxx b/src/flpsed.cxx index a0575bf..6482d9d 100644 --- a/src/flpsed.cxx +++ b/src/flpsed.cxx @@ -1,5 +1,5 @@ // -// "$Id: flpsed.cxx,v 1.12 2004/07/09 17:22:55 hofmann Exp $" +// "$Id: flpsed.cxx,v 1.13 2004/10/11 14:44:47 hofmann Exp $" // // flpsed program. // @@ -80,6 +80,13 @@ void open_cb() { } } +void import_cb() { + char *file = fl_file_chooser("Import Overlay from File?", "*.ps", filename); + if(file != NULL) { + gsw_p->import(file); + } +} + void first_cb() { gsw_p->reload(); } @@ -147,6 +154,7 @@ Fl_Menu_Item menuitems[] = { { "&File", 0, 0, 0, FL_SUBMENU }, { "&Open File...", FL_CTRL + 'o', (Fl_Callback *)open_cb }, { "&Save File as...", FL_CTRL + 's', (Fl_Callback *)save_cb }, + { "I&mport Tags from File...", FL_CTRL + 'm', (Fl_Callback *)import_cb }, { "&Print...", FL_CTRL + 'p', (Fl_Callback *)print_cb, 0, FL_MENU_DIVIDER }, { "&Quit", FL_CTRL + 'q', (Fl_Callback *)quit_cb, 0 }, { 0 }, -- cgit v1.2.3