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
This commit is contained in:
Matthias Melcher 2010-01-24 00:20:26 +00:00
parent 416f5b0dcd
commit 092c86c704
2 changed files with 42 additions and 2 deletions

View File

@ -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$".
//

View File

@ -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();