summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBastian Wissler2008-07-10 20:28:51 +0200
committerBastian Wissler2008-07-10 20:28:51 +0200
commit5a370521b41321ed959ed5b024d31feb425997ab (patch)
tree0516d432dcdf51fc15a1be5e83091f08f05a1d05
parentvmchooser changes: (diff)
downloadvmchooser-5a370521b41321ed959ed5b024d31feb425997ab.tar.gz
vmchooser-5a370521b41321ed959ed5b024d31feb425997ab.tar.xz
vmchooser-5a370521b41321ed959ed5b024d31feb425997ab.zip
vmchooser change:
* cancel button added * anyoption.{h,cxx} added * priorities enabled (lowest to highest) git-svn-id: http://svn.openslx.org/svn/openslx/openslx-src-tools/trunk/os-plugins/plugins/vmchooser@1924 95ad53e4-c205-0410-b2fa-d234c58c8868
-rw-r--r--vmchooser/Makefile2
-rw-r--r--vmchooser/SWindow.cxx11
-rw-r--r--vmchooser/inc/SWindow.h28
-rw-r--r--vmchooser/inc/anyoption.h270
-rw-r--r--vmchooser/inc/constants.h7
-rw-r--r--vmchooser/main.cxx2
6 files changed, 293 insertions, 27 deletions
diff --git a/vmchooser/Makefile b/vmchooser/Makefile
index ea75cfd..7225138 100644
--- a/vmchooser/Makefile
+++ b/vmchooser/Makefile
@@ -7,7 +7,7 @@ LDFLAGS=-L../fltk-2/lib/ ../fltk-2/lib/libfltk2.a -lpng ../fltk-2/lib/libfltk2_i
all: main.o anyoption.o SWindow.o readXmlDir.o readLinSess.o runImage.o addPrinters.o addScanners.o
${CXX} ${STATIC} main.o anyoption.o SWindow.o runImage.o readLinSess.o readXmlDir.o addPrinters.o addScanners.o -o vmchooser ${LDFLAGS} ${BOOST}
- strip vmchooser
+ #strip vmchooser
main.o: main.cxx
${CXX} ${CFLAGS} -c main.cxx -o main.o
diff --git a/vmchooser/SWindow.cxx b/vmchooser/SWindow.cxx
index 8df3a78..2c718bd 100644
--- a/vmchooser/SWindow.cxx
+++ b/vmchooser/SWindow.cxx
@@ -55,13 +55,6 @@ void SWindow::cb_select()
// }
}
-/**
- * Callback for TextDisplay at the bottom - change it?
- */
-void SWindow::cb_info()
-{
-}
-
/**********************************************************
* Put entries in a Linux-Session Group into Browser
@@ -170,6 +163,8 @@ char** SWindow::get_symbol(DataEntry* dat) {
/******************************************************
* Sort entries to consider priorities
+ *
+ * -> puts smallest priority number on top
******************************************************/
void SWindow::sort_entries() {
if(this->ent == NULL ) {
@@ -180,7 +175,7 @@ void SWindow::sort_entries() {
// worst case sort - but it is enough for this few entries
for(int i=0; ent[i] != '\0'; i++) {
for(int j=0; ent[j] != '\0'; j++) {
- if(ent[j]->priority > ent[i]->priority && j>i) {
+ if(ent[j]->priority < ent[i]->priority && j > i) {
// swap element i with j (as i is alway larger j)
ptr = ent[i];
ent[i] = ent[j];
diff --git a/vmchooser/inc/SWindow.h b/vmchooser/inc/SWindow.h
index 48739d3..4e8ccb2 100644
--- a/vmchooser/inc/SWindow.h
+++ b/vmchooser/inc/SWindow.h
@@ -24,15 +24,13 @@ class SWindow : public fltk::Window {
private:
// ReturnButton to start the session
fltk::ReturnButton go;
+
+ // Button to exit
+ fltk::Button exit_btn;
// Browser to select sessions
fltk::Browser sel;
- // TextDisplay to display info about current session
-// fltk::TextDisplay info;
- // TextBuffer buf is used for info
-// fltk::TextBuffer buf;
-
// currently selected Browser-Item
fltk::Item* curr;
@@ -52,25 +50,21 @@ private:
*/
SWindow(char* p = "Choose your session!") :
fltk::Window(fltk::USEDEFAULT,fltk::USEDEFAULT,500,550,p, true),
- go(10,520, 490, 20, "Ausführen"),
- sel(10,10, 480, 500) //,
-// info(10, 510, 480, 110),
-// buf()
+ go(160, 520, 320, 20, "Ausführen"),
+ exit_btn(10, 520, 140, 20, "Abbrechen"),
+ sel(10,10, 480, 500)
{
border(false);
go.callback(cb_return,this);
sel.callback(cb_select, this);
-
+ exit_btn.callback(cb_exit, this);
// Array for width of Select-Columns
// (one Column for a lock-symbol)
int widths[] = { 450, 20 };
sel.column_widths(widths);
-// info.callback(cb_info, this);
resizable(sel);
end();
-
-// info.wrap_mode(true, 0);
//sel.style(fltk::Browser::default_style);
sel.indented(1);
};
@@ -93,13 +87,13 @@ public:
static void cb_select(fltk::Widget*, void* w) {
((SWindow*)w)->cb_select();
};
- static void cb_info(fltk::Widget*, void* w) {
- ((SWindow*)w)->cb_info();
- };
+
+ static void cb_exit(fltk::Widget*, void* w) {
+ exit(0);
+ }
void cb_return();
void cb_select();
- void cb_info();
void set_entries(DataEntry** ent, char* slxgroup);
void set_lin_entries(DataEntry** ent, char* slxgroup);
diff --git a/vmchooser/inc/anyoption.h b/vmchooser/inc/anyoption.h
new file mode 100644
index 0000000..3f7a5de
--- /dev/null
+++ b/vmchooser/inc/anyoption.h
@@ -0,0 +1,270 @@
+#ifndef _ANYOPTION_H
+#define _ANYOPTION_H
+
+#include <iostream>
+#include <fstream>
+#include <stdlib.h>
+#include <string>
+
+#define COMMON_OPT 1
+#define COMMAND_OPT 2
+#define FILE_OPT 3
+#define COMMON_FLAG 4
+#define COMMAND_FLAG 5
+#define FILE_FLAG 6
+
+#define COMMAND_OPTION_TYPE 1
+#define COMMAND_FLAG_TYPE 2
+#define FILE_OPTION_TYPE 3
+#define FILE_FLAG_TYPE 4
+#define UNKNOWN_TYPE 5
+
+#define DEFAULT_MAXOPTS 10
+#define MAX_LONG_PREFIX_LENGTH 2
+
+#define DEFAULT_MAXUSAGE 3
+#define DEFAULT_MAXHELP 10
+
+#define TRUE_FLAG "true"
+
+using namespace std;
+
+class AnyOption
+{
+
+public: /* the public interface */
+ AnyOption();
+ AnyOption(int maxoptions );
+ AnyOption(int maxoptions , int maxcharoptions);
+ ~AnyOption();
+
+ /*
+ * following set methods specifies the
+ * special characters and delimiters
+ * if not set traditional defaults will be used
+ */
+
+ void setCommandPrefixChar( char _prefix ); /* '-' in "-w" */
+ void setCommandLongPrefix( char *_prefix ); /* '--' in "--width" */
+ void setFileCommentChar( char _comment ); /* '#' in shellscripts */
+ void setFileDelimiterChar( char _delimiter );/* ':' in "width : 100" */
+
+ /*
+ * provide the input for the options
+ * like argv[] for commndline and the
+ * option file name to use;
+ */
+
+ void useCommandArgs( int _argc, char **_argv );
+ void useFiileName( const char *_filename );
+
+ /*
+ * turn off the POSIX style options
+ * this means anything starting with a '-' or "--"
+ * will be considered a valid option
+ * which alo means you cannot add a bunch of
+ * POIX options chars together like "-lr" for "-l -r"
+ *
+ */
+
+ void noPOSIX();
+
+ /*
+ * prints warning verbose if you set anything wrong
+ */
+ void setVerbose();
+
+
+ /*
+ * there are two types of options
+ *
+ * Option - has an associated value ( -w 100 )
+ * Flag - no value, just a boolean flag ( -nogui )
+ *
+ * the options can be either a string ( GNU style )
+ * or a character ( traditional POSIX style )
+ * or both ( --width, -w )
+ *
+ * the options can be common to the commandline and
+ * the optionfile, or can belong only to either of
+ * commandline and optionfile
+ *
+ * following set methods, handle all the aboove
+ * cases of options.
+ */
+
+ /* options comman to command line and option file */
+ void setOption( const char *opt_string );
+ void setOption( char opt_char );
+ void setOption( const char *opt_string , char opt_char );
+ void setFlag( const char *opt_string );
+ void setFlag( char opt_char );
+ void setFlag( const char *opt_string , char opt_char );
+
+ /* options read from commandline only */
+ void setCommandOption( const char *opt_string );
+ void setCommandOption( char opt_char );
+ void setCommandOption( const char *opt_string , char opt_char );
+ void setCommandFlag( const char *opt_string );
+ void setCommandFlag( char opt_char );
+ void setCommandFlag( const char *opt_string , char opt_char );
+
+ /* options read from an option file only */
+ void setFileOption( const char *opt_string );
+ void setFileOption( char opt_char );
+ void setFileOption( const char *opt_string , char opt_char );
+ void setFileFlag( const char *opt_string );
+ void setFileFlag( char opt_char );
+ void setFileFlag( const char *opt_string , char opt_char );
+
+ /*
+ * process the options, registerd using
+ * useCommandArgs() and useFileName();
+ */
+ void processOptions();
+ void processCommandArgs();
+ void processCommandArgs( int max_args );
+ bool processFile();
+
+ /*
+ * process the specified options
+ */
+ void processCommandArgs( int _argc, char **_argv );
+ void processCommandArgs( int _argc, char **_argv, int max_args );
+ bool processFile( const char *_filename );
+
+ /*
+ * get the value of the options
+ * will return NULL if no value is set
+ */
+ char *getValue( const char *_option );
+ bool getFlag( const char *_option );
+ char *getValue( char _optchar );
+ bool getFlag( char _optchar );
+
+ /*
+ * Print Usage
+ */
+ void printUsage();
+ void printAutoUsage();
+ void addUsage( const char *line );
+ void printHelp();
+ /* print auto usage printing for unknown options or flag */
+ void autoUsagePrint(bool flag);
+
+ /*
+ * get the argument count and arguments sans the options
+ */
+ int getArgc();
+ char* getArgv( int index );
+ bool hasOptions();
+
+private: /* the hidden data structure */
+ int argc; /* commandline arg count */
+ char **argv; /* commndline args */
+ const char* filename; /* the option file */
+ char* appname; /* the application name from argv[0] */
+
+ int *new_argv; /* arguments sans options (index to argv) */
+ int new_argc; /* argument count sans the options */
+ int max_legal_args; /* ignore extra arguments */
+
+
+ /* option strings storage + indexing */
+ int max_options; /* maximum number of options */
+ const char **options; /* storage */
+ int *optiontype; /* type - common, command, file */
+ int *optionindex; /* index into value storage */
+ int option_counter; /* counter for added options */
+
+ /* option chars storage + indexing */
+ int max_char_options; /* maximum number options */
+ char *optionchars; /* storage */
+ int *optchartype; /* type - common, command, file */
+ int *optcharindex; /* index into value storage */
+ int optchar_counter; /* counter for added options */
+
+ /* values */
+ char **values; /* common value storage */
+ int g_value_counter; /* globally updated value index LAME! */
+
+ /* help and usage */
+ const char **usage; /* usage */
+ int max_usage_lines; /* max usage lines reseverd */
+ int usage_lines; /* number of usage lines */
+
+ bool command_set; /* if argc/argv were provided */
+ bool file_set; /* if a filename was provided */
+ bool mem_allocated; /* if memory allocated in init() */
+ bool posix_style; /* enables to turn off POSIX style options */
+ bool verbose; /* silent|verbose */
+ bool print_usage; /* usage verbose */
+ bool print_help; /* help verbose */
+
+ char opt_prefix_char; /* '-' in "-w" */
+ char long_opt_prefix[MAX_LONG_PREFIX_LENGTH]; /* '--' in "--width" */
+ char file_delimiter_char; /* ':' in width : 100 */
+ char file_comment_char; /* '#' in "#this is a comment" */
+ char equalsign;
+ char comment;
+ char delimiter;
+ char endofline;
+ char whitespace;
+ char nullterminate;
+
+ bool set; //was static member
+ bool once; //was static member
+
+ bool hasoptions;
+ bool autousage;
+
+private: /* the hidden utils */
+ void init();
+ void init(int maxopt, int maxcharopt );
+ bool alloc();
+ void cleanup();
+ bool valueStoreOK();
+
+ /* grow storage arrays as required */
+ bool doubleOptStorage();
+ bool doubleCharStorage();
+ bool doubleUsageStorage();
+
+ bool setValue( const char *option , char *value );
+ bool setFlagOn( const char *option );
+ bool setValue( char optchar , char *value);
+ bool setFlagOn( char optchar );
+
+ void addOption( const char* option , int type );
+ void addOption( char optchar , int type );
+ void addOptionError( const char *opt);
+ void addOptionError( char opt);
+ bool findFlag( char* value );
+ void addUsageError( const char *line );
+ bool CommandSet();
+ bool FileSet();
+ bool POSIX();
+
+ char parsePOSIX( char* arg );
+ int parseGNU( char *arg );
+ bool matchChar( char c );
+ int matchOpt( char *opt );
+
+ /* dot file methods */
+ char *readFile();
+ char *readFile( const char* fname );
+ bool consumeFile( char *buffer );
+ void processLine( char *theline, int length );
+ char *chomp( char *str );
+ void valuePairs( char *type, char *value );
+ void justValue( char *value );
+
+ void printVerbose( const char *msg );
+ void printVerbose( char *msg );
+ void printVerbose( char ch );
+ void printVerbose( );
+
+
+};
+
+#endif /* ! _ANYOPTION_H */
diff --git a/vmchooser/inc/constants.h b/vmchooser/inc/constants.h
new file mode 100644
index 0000000..6f04451
--- /dev/null
+++ b/vmchooser/inc/constants.h
@@ -0,0 +1,7 @@
+#ifndef CONSTANTS_H
+#define CONSTANTS_H
+
+
+const char* filterscript = "xmlfilter.sh";
+
+#endif
diff --git a/vmchooser/main.cxx b/vmchooser/main.cxx
index 42484c6..9f8087f 100644
--- a/vmchooser/main.cxx
+++ b/vmchooser/main.cxx
@@ -49,7 +49,7 @@ int main(int argc, char** argv) {
/** HELP */
if(opt->getFlag("help") || opt->getFlag('h')) {
opt->printUsage();
- return 1;
+ return 0;
}
/** XML - PATH */