29 #ifndef _UCOMMON_STRING_H_ 33 #ifndef _UCOMMON_MEMORY_H_ 37 #ifndef _UCOMMON_SHELL_H_ 38 #define _UCOMMON_SHELL_H_ 41 #define INVALID_PID_VALUE INVALID_HANDLE_VALUE 43 #define INVALID_PID_VALUE -1 93 void set0(
char *argv0);
99 typedef enum {NOARGS = 0, NOARGUMENT, INVARGUMENT, BADOPTION, OPTION_USED, BAD_VALUE, NUMERIC_SET} errmsg_t;
104 typedef enum {NONE = 0, CONSOLE_LOG, USER_LOG, SYSTEM_LOG, SECURITY_LOG} logmode_t;
109 typedef enum {FAIL = 0, ERR, WARN, NOTIFY, INFO, DEBUG0} loglevel_t;
114 typedef enum {NO_NUMERIC, NUMERIC_PLUS, NUMERIC_DASH, NUMERIC_ALL} numeric_t;
120 PROGRAM_CONFIG, SERVICE_CONFIG, USER_DEFAULTS, SERVICE_CONTROL,
121 USER_HOME = USER_DEFAULTS + 3, SERVICE_DATA, SYSTEM_TEMP, USER_CACHE,
122 SERVICE_CACHE, USER_DATA, USER_CONFIG, SYSTEM_CFG, SYSTEM_ETC,
123 SYSTEM_VAR, SYSTEM_PREFIX, SYSTEM_SHARE, PROGRAM_PLUGINS,
124 PROGRAM_TEMP} path_t;
129 typedef bool (*logproc_t)(
loglevel_t level,
const char *text);
139 typedef void (*exitproc_t)(void);
142 typedef HANDLE
pid_t;
156 static const char *errmsg(
errmsg_t id);
164 static void errmsg(
errmsg_t id,
const char *text);
193 const char *long_option;
194 const char *uses_option;
195 const char *help_string;
205 Option(
char short_option = 0,
const char *long_option = NULL,
const char *value_type = NULL,
const char *help = NULL);
222 virtual const char *assign(
const char *value) = 0;
224 static void reset(
void);
240 virtual const char *assign(
const char *value);
245 flagopt(
char short_option,
const char *long_option = NULL,
const char *help = NULL,
bool single_use =
true);
247 inline operator bool()
const {
251 inline bool operator!()
const {
255 inline operator unsigned()
const {
259 inline unsigned operator*()
const {
263 inline void set(
unsigned value = 1) {
267 inline flagopt& operator=(
unsigned value) {
281 virtual const char *assign(
const char *value);
305 virtual const char *assign(
const char *value);
308 stringopt(
char short_option,
const char *long_option = NULL,
const char *help = NULL,
const char *type =
"text",
const char *def_text = NULL);
310 inline void set(
const char *
string) {
314 inline stringopt& operator=(
const char *
string) {
319 inline operator bool()
const {
323 inline bool operator!()
const {
327 inline operator const char *()
const {
331 inline const char *operator*()
const {
352 virtual const char *assign(
const char *value);
355 charopt(
char short_option,
const char *long_option = NULL,
const char *help = NULL,
const char *type =
"char",
char default_code =
' ');
357 inline void set(
char value) {
361 inline charopt& operator=(
char value) {
366 inline operator bool()
const {
370 inline bool operator!()
const {
374 inline operator char()
const {
378 inline char operator*()
const {
399 virtual const char *assign(
const char *value);
402 numericopt(
char short_option,
const char *long_option = NULL,
const char *help = NULL,
const char *type =
"numeric",
long def_value = 0);
404 inline void set(
long value) {
413 inline operator bool()
const {
417 inline bool operator!()
const {
421 inline operator long()
const {
425 inline long operator*()
const {
448 virtual const char *assign(
const char *value);
451 counteropt(
char short_option,
const char *long_option = NULL,
const char *help = NULL,
const char *type =
"numeric",
long def_value = 0);
453 inline void set(
long value) {
462 inline operator bool()
const {
466 inline bool operator!()
const {
470 inline operator long()
const {
474 inline long operator*()
const {
486 shell(
const char *
string,
size_t pagesize = 0);
496 shell(
int argc,
char **argv,
size_t pagesize = 0);
502 shell(
size_t pagesize = 0);
506 static long getNumeric(
void);
511 static void help(
void);
520 static int system(
const char *command,
const char **env = NULL);
528 static int systemf(
const char *format, ...) __PRINTF(1,2);
534 static
void relocate(const
char *argv0);
548 static
String userid(
void);
563 static
String path(
String& prefix, const
char *directory);
576 static
void bind(const
char *name);
587 static
void rebind(const
char *name = NULL);
594 char **parse(const
char *
string);
604 void parse(
int argc,
char **argv);
613 const
char *getenv(const
char *name, const
char *value = NULL);
621 const
char *getsym(const
char *name, const
char *value = NULL);
628 void setsym(const
char *name, const
char *value);
635 bool is_sym(const
char *name) const;
642 char *getargv0(
char **argv);
651 char **getargv(
char **argv);
659 void restart(
char *argv0,
char **argv,
char **list);
664 inline const
char *argv0()
const 677 static void errlog(
const char *format, ...) __PRINTF(1, 2);
684 static
void errexit(
int exitcode, const
char *format = NULL, ...) __PRINTF(2, 3);
691 static inline
int condition(
bool test,
int exitcode) {
692 return (test) ? exitcode : 0;
700 static void debug(
unsigned level,
const char *format, ...) __PRINTF(2, 3);
707 static
void log(loglevel_t level, const
char *format, ...) __PRINTF(2, 3);
714 static
void security(loglevel_t level, const
char *format, ...) __PRINTF(2, 3);
723 static
void log(const
char *name, loglevel_t level = ERR, logmode_t mode = USER_LOG, logproc_t handler = (logproc_t)NULL);
725 static
size_t printf(const
char *format, ...) __PRINTF(1, 2);
732 inline
unsigned argc(
void)
const 750 {
return _argv[offset];}
752 static void exiting(exitproc_t);
757 void detach(mainproc_t mainentry = (mainproc_t)NULL);
775 static shell::pid_t spawn(
const char *path,
char **argv,
char **env = NULL, fd_t *stdio = NULL);
785 static void priority(
int pri = 1);
796 static int detach(
const char *path,
char **argv,
char **env = NULL, fd_t *stdio = NULL);
802 static void release(
int exit_code = 0);
837 static const char *text(
const char *
string);
848 static const char *texts(
const char *singular,
const char *plural,
unsigned long count);
855 static unsigned count(
char **argv);
859 static inline fd_t input(
void)
860 {
return GetStdHandle(STD_INPUT_HANDLE);}
862 static inline fd_t output(
void)
863 {
return GetStdHandle(STD_OUTPUT_HANDLE);}
865 static inline fd_t
error(
void)
866 {
return GetStdHandle(STD_ERROR_HANDLE);}
869 static inline fd_t input(
void)
872 static inline fd_t output(
void)
875 static inline fd_t
error(
void)
879 static int inkey(
const char *prompt = NULL);
881 static char *getpass(
const char *prompt,
char *buffer,
size_t size);
883 static char *getline(
const char *prompt,
char *buffer,
size_t size);
898 #define _STR(x) ((const char *)(x)) 899 #define __STR(x) (static_cast<const char *>(x)) 911 inline const char *_TEXT(
const char *s)
Flag option for shell parsing.
shell shell_t
Convenience type to manage and pass shell objects.
Counter option for shell parsing.
Text option for shell parsing.
A copy-on-write string class that operates by reference count.
A base class used to create parsable shell options.
cpr_service_t mainproc_t
Main handler.
char ** argv(void) const
Get saved internal argv count for items in this shell object.
Numeric option for shell parsing.
loglevel_t
Level of error logging.
AppLog & error(AppLog &sl)
Manipulator for error level.
path_t
Path types to retrieve.
A common string class and character string support functions.
const char * execdir() const
Get the exec directory.
Private heaps, pools, and associations.
unsigned operator()(void) const
Return argc count.
static const char * errmsg(errmsg_t id)
This can be used to get internationalized error messages.
A managed private heap for small allocations.
static const char * text(const char *string)
Text translation and localization.
int pid_t
Standard type of process id for shell class.
Common namespace for all ucommon objects.
Automatic integer counting class.
const char * __TEXT(const char *s)
Invoke translation lookup if available.
A linked object base class for ordered objects.
numeric_t
Numeric mode of parser.
errmsg_t
Error table index.
A class to redefine error messages.
const char * operator[](unsigned offset)
Return parser argv element.
Common base class for all objects that can be formed into a linked list.
Character option for shell parsing.
A utility class for generic shell operations.