diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/PSEditModel.H | 3 | ||||
-rw-r--r-- | src/PSEditModel.cxx | 20 | ||||
-rw-r--r-- | src/flpsed.cxx | 60 |
3 files changed, 63 insertions, 20 deletions
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 { |