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 class GetLongOpt {
00015 public:
00016 enum OptType {
00017 NoValue, OptionalValue, MandatoryValue
00018 };
00019 private:
00020 struct Cell {
00021 const char *option;
00022 OptType type;
00023 const char *description;
00024 const char *value;
00025 Cell *next;
00026
00027 Cell() { option = description = value = 0; next = 0; }
00028 };
00029 private:
00030 Cell *table;
00031 const char *ustring;
00032 char *pname;
00033 char optmarker;
00034
00035 int enroll_done;
00036 Cell *last;
00037
00038 private:
00039 char *basename(char * const p) const;
00040 int setcell(Cell *c, const char *valtoken, const char *nexttoken, const char *p);
00041 public:
00042 GetLongOpt(const char optmark = '-');
00043 ~GetLongOpt();
00044
00045 int parse(int argc, char * const *argv);
00046 int parse(char * const str, char * const p);
00047
00048 int enroll(const char * const opt, const OptType t,
00049 const char * const desc, const char * const val);
00050 const char *retrieve(const char * const opt) const;
00051
00052 void usage(std::ostream &outfile = std::cout) const;
00053 void usage(const char *str) { ustring = str; }
00054 };
00055
00056 #endif