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