00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00023 #if defined(OLD_STDCPP) || defined(NEW_STDCPP)
00024
00025 #ifndef _UCOMMON_STRING_H_
00026 #include <ucommon/string.h>
00027 #endif
00028
00029 #ifndef _UCOMMON_MEMORY_H_
00030 #include <ucommon/memory.h>
00031 #endif
00032
00033 #ifndef _UCOMMON_SHELL_H_
00034 #define _UCOMMON_SHELL_H_
00035
00036 NAMESPACE_UCOMMON
00037
00045 class __EXPORT shell : public mempager
00046 {
00047 private:
00048 char **_argv;
00049 int _argc;
00050 char *argv0;
00051
00052 class __LOCAL args
00053 {
00054 public:
00055 args *next;
00056 char *item;
00057 } *first, *last;
00058
00062 void expand(void);
00063
00067 void collapse(void);
00068
00072 void set0(void);
00073
00074 public:
00082 class __EXPORT Option
00083 {
00084 private:
00085 friend class shell;
00086
00087 static Option *root;
00088
00089 Option *next;
00090
00091 protected:
00092 char short_option;
00093 const char *long_option;
00094 bool uses_value;
00095 const char *help_string;
00096
00097 static const char *errmsg[];
00098
00099 enum {
00100 ERR_NO_VALUE = 0,
00101 ERR_IMPROPER_USAGE = 1,
00102 ERR_VALUE_MISSING = 2,
00103 ERR_INVALID_OPTION = 3
00104 };
00105
00106 public:
00114 Option(char shortoption = 0, const char *longoption = NULL, bool value = false, const char *help = NULL);
00115
00116 virtual ~Option();
00117
00118 protected:
00124 virtual const char *assign(const char *value) = 0;
00125 };
00126
00134 shell(const char *string, size_t pagesize = 0);
00135
00143 shell(char **argv, size_t pagesize = 0);
00144
00149 shell(size_t pagesize = 0);
00150
00158 static int system(const char *command, const char **env = NULL);
00159
00166 static int systemf(const char *format, ...) __PRINTF(1,2);
00167
00173 char **parse(const char *string);
00174
00182 int expand(int *argc, char ***argv);
00183
00190 static int parse(int argc, char **argv);
00191
00196 inline char **get(void)
00197 {return _argv;};
00198
00205 inline static char **parse(shell &args, const char *string)
00206 {return args.parse(string);};
00207
00216 inline static int expand(shell &args, int *argc, char ***argv)
00217 {return args.expand(argc, argv);};
00218 };
00219
00220 END_NAMESPACE
00221
00222 #endif
00223
00224 #endif