Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

program.h

Go to the documentation of this file.
00001 //
00002 // "Program" is the command line user interface class.
00003 //
00004 // It currently lives in $STARLAB_PATH/src/std/pjt but will move into
00005 // $STARLAB_PATH/src/std when things are ironed out.
00006 // The code however is already being added to the 'std' library libstd.a
00007 //
00008 //
00009 #include <iostream.h>
00010 #include "stdinc.h"
00011 #include "stdarg.h"
00012 
00013 #ifndef _PROGRAM_H
00014 #define _PROGRAM_H
00015 
00016 
00017 typedef char *string;           // this should really become a class
00018 
00019                                 // "Keyword" should also become a class
00020 
00021 typedef struct keyword {    // holds old all keyword information            
00022     string keyval;              // pointer to original R/O [not used]
00023     char option;                // short option
00024     string key;                 // keyword (same as long option)
00025     string val;                 // value
00026     string help;                // help
00027     int count;                  // update/reference count; 0=original default
00028     int upd;                    // 0=read 1=unread original 2=unread updated
00029     int system;                 // system keyword ? (0=no 1=yes)
00030 //  struct keyword *next;       // next one in linked list (not used)
00031 } Keyword;
00032 
00033 
00034 class Program {                 // NOTE: one instance of this class will exist
00035 
00036   private:
00037 
00038     // static strings to be defined by programmer - or 
00039     // dummy lib inherited, see p_*.C
00040 
00041     static string keywords[];   // array of keywords + defaults + help
00042     static string usage;        // one line usage
00043     static string version;      // N.M date author
00044     static string description;  // longer description
00045     static string examples;     // example(s) of usage
00046 
00047     //
00048 
00049     string package;             // optional package name (NEMO, STARLAB)
00050     string progname;            // short program name without path
00051     int argc;                   // argument count, for completeness
00052     string *argv;               // 0 terminated array of CL strings
00053 
00054     int nkeys;                  // number of keywords + 1
00055     Keyword *keys;              // 0=not used 1=first keyword etc.
00056 
00057     static Program *self;       // trick to find yourself again in classless
00058 
00059   public:
00060 
00061     Program();                  
00062     Program(string);            
00063     ~Program();
00064 
00065     // Initialize and program flow
00066 
00067     void init(int argc, string *argv);
00068     void append(string skeyvalhelp);
00069     void parse(void);
00070     int go(void);
00071     void fini(void);
00072     Program *main(void);
00073 
00074     // debugging
00075 
00076     void show(void);            // for debugging
00077 
00078     // getting and setting parameters
00079 
00080     string get(string key);     // get keyword value
00081     int count(string key);      // get keyword access count
00082     int get_debug(void);        // get debug_level
00083     int dec_error(void);        // decrement and return error_level
00084 
00085     int get_argc(void);
00086     char **get_argv(void);
00087 
00088   private:
00089 
00090     int debug_level;            //  debug= or $XXX_DEBUG
00091     int error_level;            //  error= or $XXX_ERROR
00092     int help_level;             //  help=  or $XXX_HELP
00093 
00094     void set_debug(string);     // set 
00095     void set_error(string);
00096     void set_help(string);
00097 
00098     void help(void);
00099     void addkey(int, string, int);
00100     int findkey(string);
00101 
00102 };
00103 
00104 //  getparam.C
00105 
00106 extern int    hasvalue(string);
00107 extern int    isdefault(string);
00108 
00109 extern string getparam(string);
00110 extern real   getrparam(string);
00111 extern int    getiparam(string);
00112 
00113 extern int    getflag(string);
00114 
00115 extern int    get_argc(void);
00116 extern char **get_argv(void);
00117 
00118 extern void   Error(char * ...);
00119 extern void   Warning(char *, ...);
00120 extern void   Dprintf(int, char *, ...);
00121 
00122 #endif

Generated at Sun Feb 24 09:57:12 2002 for STARLAB by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001