summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Hofmann <johannes.hofmann@gmx.de>2004-10-25 18:58:55 +0000
committerJohannes Hofmann <johannes.hofmann@gmx.de>2004-10-25 18:58:55 +0000
commita6c28e22fcfca80231bd1061d906195e5735fb37 (patch)
tree98bb976ac8a50e6ae0e6bf202f94cfdfc320f554 /src
parent25da85de6a1eca08de94bbc9f1b63ae9a7c87841 (diff)
implement batch mode (needs cleanup)
implement batch mode (needs cleanup)
Diffstat (limited to 'src')
-rw-r--r--src/PSEditModel.H6
-rw-r--r--src/PSEditModel.cxx30
-rw-r--r--src/PSEditor.cxx25
-rw-r--r--src/flpsed.cxx87
4 files changed, 98 insertions, 50 deletions
diff --git a/src/PSEditModel.H b/src/PSEditModel.H
index bfe1b98..f69bf1f 100644
--- a/src/PSEditModel.H
+++ b/src/PSEditModel.H
@@ -1,5 +1,5 @@
//
-// "$Id: PSEditModel.H,v 1.5 2004/10/24 18:28:37 hofmann Exp $"
+// "$Id: PSEditModel.H,v 1.6 2004/10/25 20:58:55 hofmann Exp $"
//
// X11 header file for the Fast Light Tool Kit (FLTK).
//
@@ -60,7 +60,9 @@ public:
int ps_to_display_y(int y1);
int ps_x(int x1);
int ps_y(int y1);
- int PSEditModel::load(char *f);
+ int PSEditModel::load(char *f);
+ int save(const char* savefile, int tmp_fd);
+
};
#endif
diff --git a/src/PSEditModel.cxx b/src/PSEditModel.cxx
index 75f96ee..b6bcbd2 100644
--- a/src/PSEditModel.cxx
+++ b/src/PSEditModel.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: PSEditModel.cxx,v 1.5 2004/10/24 18:28:37 hofmann Exp $"
+// "$Id: PSEditModel.cxx,v 1.6 2004/10/25 20:58:55 hofmann Exp $"
//
// PSEditWidget routines.
//
@@ -259,3 +259,31 @@ int PSEditModel::load(char *f) {
return tmp_fd;
}
+
+
+
+int PSEditModel::save(const char* savefile, int tmp_fd) {
+ off_t pos = lseek(tmp_fd, 0, SEEK_CUR); // save current position
+
+ if (pos == -1) {
+ perror("lseek");
+ return 1;
+ }
+
+ FILE *fp = fdopen(tmp_fd, "r");
+
+ rewind(fp);
+ FILE *sfp = fopen(savefile, "w");
+ PSWriter *pw;
+
+ pw = new PSLevel1Writer(this);
+
+ pw->write(fp, sfp);
+
+ delete(pw);
+
+ fclose(sfp);
+ lseek(tmp_fd, pos, SEEK_SET); // restore current position
+
+ return 0;
+}
diff --git a/src/PSEditor.cxx b/src/PSEditor.cxx
index bc4541e..590a46f 100644
--- a/src/PSEditor.cxx
+++ b/src/PSEditor.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: PSEditor.cxx,v 1.15 2004/10/24 18:28:37 hofmann Exp $"
+// "$Id: PSEditor.cxx,v 1.16 2004/10/25 20:58:55 hofmann Exp $"
//
// PSEditor routines.
//
@@ -32,6 +32,7 @@ PSEditor::PSEditor(int X,int Y,int W, int H) : PSEditWidget(X, Y, W, H) {
ps_level = 1;
}
+
int PSEditor::handle(int event) {
int mark_x, mark_y;
@@ -118,10 +119,10 @@ int PSEditor::handle(int event) {
int PSEditor::load(char *f) {
if (tmp_fd) {
close(tmp_fd);
- tmp_fd = -1;
}
tmp_fd = model->load(f);
+
if (tmp_fd < 0) {
return 1;
} else {
@@ -132,28 +133,14 @@ int PSEditor::load(char *f) {
}
int PSEditor::save(const char* savefile) {
- off_t pos = lseek(tmp_fd, 0, SEEK_CUR); // save current position
-
if (!file_loaded()) {
return 1;
}
- FILE *fp = fdopen(tmp_fd, "r");
- rewind(fp);
- FILE *sfp = fopen(savefile, "w");
- PSWriter *pw;
- if (ps_level == 2) {
- pw = new PSLevel2Writer(model);
- } else {
- pw = new PSLevel1Writer(model);
+ if (model->save(savefile, tmp_fd) != 0) {
+ return 1;
}
-
- pw->write(fp, sfp);
-
- delete(pw);
-
- fclose(sfp);
- lseek(tmp_fd, pos, SEEK_SET); // restore current position
+
mod = 0;
return 0;
}
diff --git a/src/flpsed.cxx b/src/flpsed.cxx
index 0b4d0c4..333f85c 100644
--- a/src/flpsed.cxx
+++ b/src/flpsed.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: flpsed.cxx,v 1.18 2004/10/21 21:02:05 hofmann Exp $"
+// "$Id: flpsed.cxx,v 1.19 2004/10/25 20:58:55 hofmann Exp $"
//
// flpsed program.
//
@@ -201,36 +201,23 @@ Fl_Menu_Item menuitems[] = {
{ 0 }
};
+#define TV_LEN 256
+
int main(int argc, char** argv) {
char c, *sep, *tmp;
- int err;
+ int err, batch = 0;
Fl_Window *win;
Fl_Menu_Bar* m;
Fl_Scroll *scroll;
-
- win = new Fl_Window(600,700);
- m = new Fl_Menu_Bar(0, 0, 600, 30);
- m->menu(menuitems);
- scroll = new Fl_Scroll(0, 30, win->w(), win->h()-30);
- gsw_p = new PSEditor(0, 0, 700, 900);
- scroll->end();
-
- fl_open_display();
- Fl::add_handler(xev_handler);
-
- win->resizable(scroll);
-
- win->end();
- win->callback((Fl_Callback *)quit_cb);
- win->show(1, argv);
-
- if (argc > 1) {
- gsw_p->load(argv[argc - 1]);
- }
+ struct {char *tag; char *value;} tv[TV_LEN];
+ int tv_idx = 0;
err = 0;
- while ((c = getopt(argc, argv, "t:")) != EOF) {
- switch (c) {
+ while ((c = getopt(argc, argv, "bt:")) != EOF) {
+ switch (c) {
+ case 'b':
+ batch = 1;
+ break;
case 't':
tmp = strdup(optarg);
if (!tmp) {
@@ -244,7 +231,15 @@ int main(int argc, char** argv) {
continue;
}
*sep = '\0';
- gsw_p->replace_tag(tmp, sep+1);
+
+ if (tv_idx >= TV_LEN) {
+ fprintf(stderr, "More than %d tag/value pairs; ignoring %s->%s\n",
+ TV_LEN, tmp, sep+1);
+ } else {
+ tv[tv_idx].tag = strdup(tmp);
+ tv[tv_idx].value = strdup(sep+1);
+ tv_idx++;
+ }
free(tmp);
break;
default:
@@ -256,10 +251,46 @@ int main(int argc, char** argv) {
exit(1);
}
+ // argc -= optind;
+ // argv += optind;
+ if (batch) {
+ PSEditModel *m = new PSEditModel(594, 841, 75.0, 75.0);
+ int tmp_fd = m->load(argv[argc - 2]);
+ if (tmp_fd == -1) {
+ fprintf(stderr, "Could not load %s\n", argv[argc - 2]);
+ exit(1);
+ }
+
+ for(int i=0; i<tv_idx; i++) {
+ m->replace_tag(tv[i].tag, tv[i].value);
+ free(tv[i].tag);
+ free(tv[i].value);
+ }
+
+ m->save(argv[argc - 1], tmp_fd);
+
+ exit(0);
+ }
+
+
+
+
+ win = new Fl_Window(600,700);
+ m = new Fl_Menu_Bar(0, 0, 600, 30);
+ m->menu(menuitems);
+ scroll = new Fl_Scroll(0, 30, win->w(), win->h()-30);
+ gsw_p = new PSEditor(0, 0, 700, 900);
+ scroll->end();
+
+ fl_open_display();
+ Fl::add_handler(xev_handler);
+
+ win->resizable(scroll);
+
+ win->end();
+ win->callback((Fl_Callback *)quit_cb);
+ win->show(1, argv);
- argc -= optind;
- argv += optind;
-
return Fl::run();
}