summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <johannes.hofmann@gmx.de>2004-10-26 14:41:40 +0000
committerJohannes Hofmann <johannes.hofmann@gmx.de>2004-10-26 14:41:40 +0000
commit95a26f47d0f801f5218c6e708c8e3e6c40a3b118 (patch)
tree4615b2c27ca13971099ecf0b305db4ecbffb07b1
parentd2b86baae9e361de2f1a06cfefa0218f0c66ca8a (diff)
implement dump mode
implement dump mode
-rw-r--r--README24
-rw-r--r--src/PSEditModel.H3
-rw-r--r--src/PSEditModel.cxx20
-rw-r--r--src/flpsed.cxx60
4 files changed, 85 insertions, 22 deletions
diff --git a/README b/README
index 87b383c..2213303 100644
--- a/README
+++ b/README
@@ -8,7 +8,7 @@ edit existing PostScript documents, but you can add arbitrary text lines to
existing documents.
It is useful for filling in forms etc.
-Usage:
+Quick Start:
- open an existing PostScript document.
- click anywhere on the document and type a text line.
- the frame around the text shows, which text line has the focus.
@@ -23,7 +23,9 @@ Features:
- reedit text, that has been added with flpsed.
- the overall structure of the PostScript document is not
modified. flpsed only adds the additional text.
-
+- lines can be given names ("tags"). The text of these lines can
+ be replaced in batch mode (no X11 required).
+
Restrictions:
- flpsed probably does not work on all existing PostScript documents.
You simply have to test it for your documents.
@@ -35,3 +37,21 @@ Building:
- you need to have ghostscript installed.
- you need to have fltk-1.1.x from www.fltk.org installed.
- unpack the tarball and type "make".
+
+
+
+Tags and Batch Mode:
+
+to use batch mode, add text lines to your PostScript document as usual.
+Give all or some of the lines tag names (Tags->Edit Tag).
+Save the document. Now you can replace the text of the tagged line in batch
+mode using the -t flag (see usage).
+Example:
+Lets assume you have added text lines with tags "name", and "street"
+to your document letter.ps with flpsed in interactive mode and saved the
+result in letter-templ.ps.
+You can now call flpsed in batch mode to set the actual values:
+
+flpsed -b -t name="Hans Meier" -t street="Haupstr. 14" letter-templ.ps out.ps
+
+
diff --git a/src/PSEditModel.H b/src/PSEditModel.H
index eeff69c..fb43553 100644
--- a/src/PSEditModel.H
+++ b/src/PSEditModel.H
@@ -1,5 +1,5 @@
//
-// "$Id: PSEditModel.H,v 1.7 2004/10/26 16:12:19 hofmann Exp $"
+// "$Id: PSEditModel.H,v 1.8 2004/10/26 16:41:40 hofmann Exp $"
//
// X11 header file for the Fast Light Tool Kit (FLTK).
//
@@ -56,6 +56,7 @@ public:
PSEditText *get_text(int p);
PSEditText *get_cur_text();
int replace_tag(char* tag, char* text);
+ int dump_tags();
int ps_to_display_x(int x1);
int ps_to_display_y(int y1);
int ps_x(int x1);
diff --git a/src/PSEditModel.cxx b/src/PSEditModel.cxx
index 2b5cb07..38c98af 100644
--- a/src/PSEditModel.cxx
+++ b/src/PSEditModel.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: PSEditModel.cxx,v 1.7 2004/10/26 16:12:19 hofmann Exp $"
+// "$Id: PSEditModel.cxx,v 1.8 2004/10/26 16:41:40 hofmann Exp $"
//
// PSEditWidget routines.
//
@@ -193,6 +193,24 @@ int PSEditModel::replace_tag(char *tag, char *txt) {
return ret;
}
+int PSEditModel::dump_tags() {
+ PSEditText *t;
+ int p, ret = 0;
+
+ for (p = 0; p < max_pages; p++) {
+ t = get_text(p);
+ while (t) {
+ if (t->get_tag()) {
+ printf("%s=%s\n", t->get_tag(), t->get_text());
+ ret++;
+ }
+ t = t->get_next();
+ }
+ }
+
+ return ret;
+}
+
PSEditText *PSEditModel::get_text(int p) {
if (p >= max_pages) {
return 0;
diff --git a/src/flpsed.cxx b/src/flpsed.cxx
index 301a273..436f1ed 100644
--- a/src/flpsed.cxx
+++ b/src/flpsed.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: flpsed.cxx,v 1.20 2004/10/26 16:12:19 hofmann Exp $"
+// "$Id: flpsed.cxx,v 1.21 2004/10/26 16:41:40 hofmann Exp $"
//
// flpsed program.
//
@@ -201,11 +201,25 @@ Fl_Menu_Item menuitems[] = {
{ 0 }
};
+
+void usage() {
+ fprintf(stderr,
+ "usage: flpsed [-d] [-b] [-t <tag>=<value>] [<infile>] [<outfile>]\n"
+ " -b batch mode (no gui)\n"
+ " -d dump tags and values from a document\n"
+ " to stdout (this implies -b)\n"
+ " -t <tag>=<value> set text to <value> where tag is <tag>\n"
+ " <infile> optional input file; in batch mode if no\n"
+ " input file is given, input is read from stdin\n"
+ " <outfile> optional output file for batch mode; if no\n"
+ " output file is given, output is written to stdout\n");
+}
+
#define TV_LEN 256
int main(int argc, char** argv) {
char c, *sep, *tmp, **my_argv;
- int err, batch = 0;
+ int err, bflag = 0, dflag = 0;
Fl_Window *win;
Fl_Menu_Bar* m;
Fl_Scroll *scroll;
@@ -214,10 +228,13 @@ int main(int argc, char** argv) {
FILE *in_fp = NULL, *out_fp = NULL;
err = 0;
- while ((c = getopt(argc, argv, "bt:")) != EOF) {
+ while ((c = getopt(argc, argv, "dbt:")) != EOF) {
switch (c) {
case 'b':
- batch = 1;
+ bflag = 1;
+ break;
+ case 'd':
+ dflag = 1;
break;
case 't':
tmp = strdup(optarg);
@@ -249,6 +266,7 @@ int main(int argc, char** argv) {
}
if (err) {
+ usage();
exit(1);
}
@@ -263,7 +281,7 @@ int main(int argc, char** argv) {
}
}
- if (batch) {
+ if (bflag || dflag) {
//
// Batch Mode
//
@@ -275,15 +293,6 @@ int main(int argc, char** argv) {
in_fp = stdin;
}
- if (my_argc >= 2) {
- out_fp = fopen(my_argv[1], "w");
- if (!in_fp) {
- perror("fopen");
- exit(1);
- }
- } else {
- out_fp = stdout;
- }
tmp_fd= m->load(in_fp);
@@ -301,11 +310,26 @@ int main(int argc, char** argv) {
free(tv[i].tag);
free(tv[i].value);
}
-
- m->save(out_fp, tmp_fd);
- if (out_fp != stdout) {
- fclose(out_fp);
+
+ if (bflag) {
+ if (my_argc >= 2) {
+ out_fp = fopen(my_argv[1], "w");
+ if (!in_fp) {
+ perror("fopen");
+ exit(1);
+ }
+ } else {
+ out_fp = stdout;
+ }
+
+ m->save(out_fp, tmp_fd);
+
+ if (out_fp != stdout) {
+ fclose(out_fp);
+ }
+ } else { // dump tags
+ m->dump_tags();
}
} else {