summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2010-01-24 00:20:26 +0000
committerMatthias Melcher <fltk@matthiasm.com>2010-01-24 00:20:26 +0000
commit092c86c7048a6633a0d8c37538d48d2416840ff1 (patch)
treec6f360edd32670b0ee123614fc0e7f9dff33bf4f
parent416f5b0dcd3e2cf4993acf4dff02a7477be835e2 (diff)
This is a very simple implementation of the host side of plugins. Plugins can be linked at compile time to extend Fluid with new command line options. A sample plugin will follow soon.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7024 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--fluid/Fl_Type.h18
-rw-r--r--fluid/fluid.cxx26
2 files changed, 42 insertions, 2 deletions
diff --git a/fluid/Fl_Type.h b/fluid/Fl_Type.h
index cfe1292d2..e80842ab8 100644
--- a/fluid/Fl_Type.h
+++ b/fluid/Fl_Type.h
@@ -36,6 +36,7 @@
#include <FL/Fl_Widget.H>
#include <FL/Fl_Menu.H>
+#include <FL/Fl_Plugin.H>
#include "Fluid_Image.h"
#include <FL/fl_draw.H>
@@ -792,6 +793,23 @@ int storestring(const char *n, const char * & p, int nostrip=0);
extern int include_H_from_C;
extern int use_FL_COMMAND;
+/*
+ * This class is needed for additional command line plugins.
+ */
+class Fl_Commandline_Plugin : public Fl_Plugin {
+public:
+ Fl_Commandline_Plugin(const char *name)
+ : Fl_Plugin(klass(), name) { }
+ virtual const char *klass() { return "commandline"; }
+ // return a unique name for this plugin
+ virtual const char *name() = 0;
+ // return a help text for all supported commands
+ virtual const char *help() = 0;
+ // handle a command and return the number of args used, or 0
+ virtual int arg(int argc, char **argv, int &i) = 0;
+};
+
+
//
// End of "$Id$".
//
diff --git a/fluid/fluid.cxx b/fluid/fluid.cxx
index 6355d100f..774bad231 100644
--- a/fluid/fluid.cxx
+++ b/fluid/fluid.cxx
@@ -34,6 +34,7 @@
#include <FL/Fl_Hold_Browser.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Input.H>
+#include <FL/Fl_Plugin.H>
#include <FL/fl_ask.H>
#include <FL/fl_draw.H>
#include <FL/Fl_File_Chooser.H>
@@ -632,6 +633,7 @@ void new_cb(Fl_Widget *, void *v) {
undo_clear();
}
+int exit_early = 0;
int compile_only = 0;
int compile_strings = 0;
int header_file_set = 0;
@@ -2247,6 +2249,13 @@ static int arg(int argc, char** argv, int& i) {
i += 2;
return 2;
}
+ Fl_Plugin_Manager pm("commandline");
+ int j, n = pm.plugins();
+ for (j=0; j<n; j++) {
+ Fl_Commandline_Plugin *pi = (Fl_Commandline_Plugin*)pm.plugin(j);
+ int r = pi->arg(argc, argv, i);
+ if (r) return r;
+ }
return 0;
}
@@ -2272,17 +2281,30 @@ static void sigint(SIGARG) {
}
#endif
+
int main(int argc,char **argv) {
int i = 1;
+
if (!Fl::args(argc,argv,i,arg) || i < argc-1) {
- fprintf(stderr,"usage: %s <switches> name.fl\n"
+ fprintf(stderr,
+"usage: %s <switches> name.fl\n"
" -c : write .cxx and .h and exit\n"
" -cs : write .cxx and .h and strings and exit\n"
" -o <name> : .cxx output filename, or extension if <name> starts with '.'\n"
" -h <name> : .h output filename, or extension if <name> starts with '.'\n"
-"%s\n", argv[0], Fl::help);
+ , argv[0]);
+ Fl_Plugin_Manager pm("commandline");
+ int i, n = pm.plugins();
+ for (i=0; i<n; i++) {
+ Fl_Commandline_Plugin *pi = (Fl_Commandline_Plugin*)pm.plugin(i);
+ if (pi) puts(pi->help());
+ }
+ fprintf(stderr, "%s\n", Fl::help);
return 1;
}
+ if (exit_early)
+ exit(0);
+
const char *c = argv[i];
fl_register_images();