home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / CL187A.ZIP / CMDLN.H < prev    next >
C/C++ Source or Header  |  1994-03-15  |  885b  |  47 lines

  1. //    cmdln.h -- command line option parser
  2. //    (C) Copyright 1994  John Webster Small
  3. //    All rights reserved
  4.  
  5. #ifndef cmdln_h
  6. #define cmdln_h
  7.  
  8. #include <iostream.h>
  9.  
  10. struct argument {
  11.  
  12.     enum OPT_TYPE {
  13.         NA, FLAG, STR, NUM, UNKNOWN, PARAM
  14.     };
  15.     enum OPT_TYPE optType;
  16.     char optCh, optNot;
  17.     char * optArg, * param;
  18.     int  optOff, optNum;
  19.     void reset();
  20.     argument& operator=(const argument& a);
  21.     argument() { reset(); }
  22.     argument(const argument& a)  { *this = a; }
  23. };
  24.  
  25. extern ostream& operator<<(ostream& os, argument& a);
  26.  
  27. class CmdLn : public argument  {
  28.  
  29.     char **argv, *options, *optCluster;
  30.     int  argc, argvEnd;
  31.     int  argi;
  32.     static  char switches[];
  33.  
  34. public:
  35.  
  36.     void parse(int argc, char *argv[],
  37.         char *options);
  38.     CmdLn(int argc = 0, char *argv[] = 0,
  39.         char *options = 0)
  40.         { parse(argc,argv,options); }
  41.     int  getOption(void);
  42.  
  43. };
  44.  
  45. #endif
  46.  
  47.