home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume35 / getlongopt / part01 / GetLongOpt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-21  |  1.4 KB  |  53 lines

  1. /* $Id: GetLongOpt.h,v 1.1 1993/01/23 14:35:44 mano Exp mano $ */
  2. /* S Manoharan. Advanced Computer Research Institute. Lyon. France */
  3.  
  4. #ifndef _GetLongOpt_h_
  5. #define _GetLongOpt_h_
  6.  
  7. #include <iostream.h>
  8. #include <string.h>
  9.  
  10. class GetLongOpt {
  11. public:
  12.    enum OptType { 
  13.       NoValue, OptionalValue, MandatoryValue
  14.    };
  15. private:
  16.    struct Cell {
  17.       const char *option;    // option name
  18.       OptType type;        // option type
  19.       const char *description;    // a description of option
  20.       const char *value;    // value of option (string)
  21.       Cell *next;        // pointer to the next cell
  22.  
  23.       Cell() { option = description = value = 0; next = 0; }
  24.    };
  25. private:
  26.   Cell *table;                // option table
  27.   const char *ustring;            // usage message
  28.   char *pname;                // program basename
  29.   char optmarker;            // option marker
  30.  
  31.   int enroll_done;            // finished enrolling
  32.   Cell *last;                // last entry in option table 
  33.  
  34. private:
  35.   char *basename(char * const p) const;
  36.   int setcell(Cell *c, char *valtoken, char *nexttoken, char *p);
  37. public:
  38.    GetLongOpt(const char optmark = '-');
  39.    ~GetLongOpt();
  40.  
  41.    int parse(int argc, char * const *argv);
  42.    int parse(char * const str, char * const p);
  43.  
  44.    int enroll(const char * const opt, const OptType t,
  45.       const char * const desc, const char * const val);
  46.    const char *retrieve(const char * const opt) const;
  47.  
  48.    void usage(ostream &outfile = cout) const;
  49.    void usage(const char *str)        { ustring = str; }
  50. };
  51.  
  52. #endif /* _GetLongOpt_h_ */
  53.