summaryrefslogtreecommitdiff
path: root/src/PSEditor.cxx
diff options
context:
space:
mode:
authorJohannes Hofmann <johannes.hofmann@gmx.de>2004-10-11 12:44:47 +0000
committerJohannes Hofmann <johannes.hofmann@gmx.de>2004-10-11 12:44:47 +0000
commit51bd38e8d2448350afe349f2f64367d1af9b27cc (patch)
tree12ed5779428d57df613421677bc29eb92dc166d8 /src/PSEditor.cxx
parentfcbe89c0c06b39a1fab26e2908788b01283e4f87 (diff)
added import feature
added import feature
Diffstat (limited to 'src/PSEditor.cxx')
-rw-r--r--src/PSEditor.cxx43
1 files changed, 40 insertions, 3 deletions
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;
}