00001
00002
00003
00004 #ifdef __GNUC__
00005 #pragma interface
00006 #endif
00007
00008 #ifndef _GetLongOpt_h_
00009 #define _GetLongOpt_h_
00010
00011 #include <iostream>
00012 #include <string.h>
00013
00014 namespace sc {
00015
00017 class GetLongOpt {
00018 public:
00021 enum OptType {
00022 NoValue, OptionalValue, MandatoryValue
00023 };
00024 private:
00025 struct Cell {
00026 const char *option;
00027 OptType type;
00028 const char *description;
00029 const char *value;
00030 Cell *next;
00031
00032 Cell() { option = description = value = 0; next = 0; }
00033 };
00034 private:
00035 Cell *table;
00036 const char *ustring;
00037 char *pname;
00038 char optmarker;
00039
00040 int enroll_done;
00041 Cell *last;
00042
00043 private:
00044 char *basename(char * const p) const;
00045 int setcell(Cell *c, const char *valtoken, const char *nexttoken, const char *p);
00046 public:
00049 GetLongOpt(const char optmark = '-');
00050 ~GetLongOpt();
00051
00057 int parse(int argc, char * const *argv);
00063 int parse(char * const str, char * const p);
00064
00070 int enroll(const char * const opt, const OptType t,
00071 const char * const desc, const char * const val);
00074 const char *retrieve(const char * const opt) const;
00075
00078 void usage(std::ostream &outfile = std::cout) const;
00081 void usage(const char *str) { ustring = str; }
00082 };
00083
00084 }
00085
00086 #endif