ucommon  7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

ucommon::shell Class Reference

#include <shell.h>

Inheritance diagram for ucommon::shell:
[legend]
Collaboration diagram for ucommon::shell:
[legend]

Classes

class  args
 
class  charopt
 
class  counteropt
 
class  errormap
 
class  flagopt
 
class  groupopt
 
class  numericopt
 
class  Option
 
class  stringopt
 
class  syms
 

Public Types

enum  errmsg_t {
  NOARGS = 0, NOARGUMENT, INVARGUMENT, BADOPTION,
  OPTION_USED, BAD_VALUE, NUMERIC_SET
}
 
enum  logmode_t {
  NONE = 0, CONSOLE_LOG, USER_LOG, SYSTEM_LOG,
  SECURITY_LOG
}
 
enum  loglevel_t {
  FAIL = 0, ERR, WARN, NOTIFY,
  INFO, DEBUG0
}
 
enum  numeric_t { NO_NUMERIC, NUMERIC_PLUS, NUMERIC_DASH, NUMERIC_ALL }
 
enum  path_t {
  PROGRAM_CONFIG, SERVICE_CONFIG, USER_DEFAULTS, SERVICE_CONTROL,
  USER_HOME = USER_DEFAULTS + 3, SERVICE_DATA, SYSTEM_TEMP, USER_CACHE,
  SERVICE_CACHE, USER_DATA, USER_CONFIG, SYSTEM_CFG,
  SYSTEM_ETC, SYSTEM_VAR, SYSTEM_PREFIX, SYSTEM_SHARE,
  PROGRAM_PLUGINS, PROGRAM_TEMP
}
 
typedef bool(* logproc_t) (loglevel_t level, const char *text)
 
typedef cpr_service_t mainproc_t
 
typedef void(* exitproc_t) (void)
 
typedef int pid_t
 

Public Member Functions

 shell (const char *string, size_t pagesize=0)
 
 shell (int argc, char **argv, size_t pagesize=0)
 
 shell (size_t pagesize=0)
 
char ** parse (const char *string)
 
void parse (int argc, char **argv)
 
const char * getenv (const char *name, const char *value=NULL)
 
const char * getsym (const char *name, const char *value=NULL)
 
void setsym (const char *name, const char *value)
 
bool is_sym (const char *name) const
 
char * getargv0 (char **argv)
 
char ** getargv (char **argv)
 
void restart (char *argv0, char **argv, char **list)
 
const char * argv0 () const
 
const char * execdir () const
 
static size_t unsigned argc (void) const
 
char ** argv (void) const
 
const char * operator[] (unsigned offset)
 
void detach (mainproc_t mainentry=(mainproc_t) NULL)
 
void restart (void)
 
unsigned operator() (void) const
 
- Public Member Functions inherited from ucommon::mempager
 mempager (size_t page=0)
 
 mempager (const mempager &copy)
 
virtual ~mempager ()
 
unsigned utilization (void)
 
void purge (void)
 
virtual void dealloc (void *memory)
 
void assign (mempager &source)
 
- Public Member Functions inherited from ucommon::memalloc
 memalloc (size_t page=0)
 
 memalloc (const memalloc &copy)
 
virtual ~memalloc ()
 
unsigned pages (void) const
 
unsigned max (void) const
 
size_t size (void) const
 
unsigned utilization (void) const
 
void purge (void)
 
void assign (memalloc &source)
 

Static Public Member Functions

static const char * errmsg (errmsg_t id)
 
static void errmsg (errmsg_t id, const char *text)
 
static void setNumeric (numeric_t)
 
static long getNumeric (void)
 
static void help (void)
 
static int system (const char *command, const char **env=NULL)
 
static int systemf (const char *format,...) __PRINTF(1
 
static int static void relocate (const char *argv0)
 
static String path (path_t id)
 
static String userid (void)
 
static String path (path_t id, const char *directory)
 
static String path (String &prefix, const char *directory)
 
static void bind (const char *name)
 
static void rebind (const char *name=NULL)
 
static void errlog (const char *format,...) __PRINTF(1
 
static void static void errexit (int exitcode, const char *format=NULL,...) __PRINTF(2
 
static void static void static int condition (bool test, int exitcode)
 
static void debug (unsigned level, const char *format,...) __PRINTF(2
 
static void static void log (loglevel_t level, const char *format,...) __PRINTF(2
 
static void static void static void security (loglevel_t level, const char *format,...) __PRINTF(2
 
static void static void static void static void log (const char *name, loglevel_t level=ERR, logmode_t mode=USER_LOG, logproc_t handler=(logproc_t) NULL)
 
static size_t printf (const char *format,...) __PRINTF(1
 
static void exiting (exitproc_t)
 
static shell::pid_t spawn (const char *path, char **argv, char **env=NULL, fd_t *stdio=NULL)
 
static void priority (int pri=1)
 
static int detach (const char *path, char **argv, char **env=NULL, fd_t *stdio=NULL)
 
static void release (int exit_code=0)
 
static int wait (shell::pid_t pid)
 
static int cancel (shell::pid_t pid)
 
static const char * text (const char *string)
 
static const char * texts (const char *singular, const char *plural, unsigned long count)
 
static unsigned count (char **argv)
 
static fd_t input (void)
 
static fd_t output (void)
 
static fd_t error (void)
 
static int inkey (const char *prompt=NULL)
 
static char * getpass (const char *prompt, char *buffer, size_t size)
 
static char * getline (const char *prompt, char *buffer, size_t size)
 

Private Member Functions

 __DELETE_COPY (shell)
 
void collapse (LinkedObject *first)
 
void set0 (char *argv0)
 

Private Attributes

char ** _argv
 
unsigned _argc
 
char * _argv0
 
char * _exedir
 
LinkedObject_syms
 

Additional Inherited Members

- Protected Member Functions inherited from ucommon::mempager
virtual void _lock (void) __OVERRIDE
 
virtual void _unlock (void) __OVERRIDE
 
virtual void * _alloc (size_t size) __OVERRIDE
 
- Protected Member Functions inherited from ucommon::memalloc
page_tpager (void)
 
- Protected Attributes inherited from ucommon::memalloc
unsigned limit
 

Detailed Description

A utility class for generic shell operations. This includes utilities to parse and expand arguments, and to call system shell services. This also includes a common shell class to parse and process command line arguments which are managed through a local heap.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 59 of file shell.h.

Member Typedef Documentation

◆ exitproc_t

typedef void(* ucommon::shell::exitproc_t) (void)

Exit handler.

Definition at line 139 of file shell.h.

◆ logproc_t

typedef bool(* ucommon::shell::logproc_t) (loglevel_t level, const char *text)

Log process handler.

Definition at line 129 of file shell.h.

◆ mainproc_t

Main handler.

Definition at line 134 of file shell.h.

◆ pid_t

typedef int ucommon::shell::pid_t

Standard type of process id for shell class.

Definition at line 147 of file shell.h.

Member Enumeration Documentation

◆ errmsg_t

Error table index.

Enumerator
NOARGS 
NOARGUMENT 
INVARGUMENT 
BADOPTION 
OPTION_USED 
BAD_VALUE 
NUMERIC_SET 

Definition at line 99 of file shell.h.

◆ loglevel_t

Level of error logging.

Enumerator
FAIL 
ERR 
WARN 
NOTIFY 
INFO 
DEBUG0 

Definition at line 109 of file shell.h.

◆ logmode_t

Type of error logging we are using.

Enumerator
NONE 
CONSOLE_LOG 
USER_LOG 
SYSTEM_LOG 
SECURITY_LOG 

Definition at line 104 of file shell.h.

◆ numeric_t

Numeric mode of parser.

Enumerator
NO_NUMERIC 
NUMERIC_PLUS 
NUMERIC_DASH 
NUMERIC_ALL 

Definition at line 114 of file shell.h.

◆ path_t

Path types to retrieve.

Enumerator
PROGRAM_CONFIG 
SERVICE_CONFIG 
USER_DEFAULTS 
SERVICE_CONTROL 
USER_HOME 
SERVICE_DATA 
SYSTEM_TEMP 
USER_CACHE 
SERVICE_CACHE 
USER_DATA 
USER_CONFIG 
SYSTEM_CFG 
SYSTEM_ETC 
SYSTEM_VAR 
SYSTEM_PREFIX 
SYSTEM_SHARE 
PROGRAM_PLUGINS 
PROGRAM_TEMP 

Definition at line 119 of file shell.h.

Constructor & Destructor Documentation

◆ shell() [1/3]

ucommon::shell::shell ( const char *  string,
size_t  pagesize = 0 
)

Construct a shell argument list by parsing a simple command string. This separates a string into a list of command line arguments which can be used with exec functions.

Parameters
stringto parse.
pagesizefor local heap.

Definition at line 345 of file shell.cpp.

References _argc, _argv, _argv0, _syms, and parse().

◆ shell() [2/3]

ucommon::shell::shell ( int  argc,
char **  argv,
size_t  pagesize = 0 
)

Construct a shell argument list from existing arguments. This copies and on some platforms expands the argument list originally passed to main.

Parameters
argcfrom main.
argvfrom main.
pagesizefor local heap.

Definition at line 356 of file shell.cpp.

References _argc, _argv, _argv0, _syms, argc(), argv(), and parse().

◆ shell() [3/3]

ucommon::shell::shell ( size_t  pagesize = 0)

Construct an empty shell parser argument list.

Parameters
pagesizefor local heap.

Definition at line 335 of file shell.cpp.

References _argc, _argv, _argv0, _exedir, and _syms.

Member Function Documentation

◆ __DELETE_COPY()

ucommon::shell::__DELETE_COPY ( shell  )
private

◆ argc()

static size_t unsigned ucommon::shell::argc ( void  ) const
inline

Get saved internal argc count for items. This may be items that remain after shell expansion and options have been parsed.

Returns
count of remaining arguments.

Definition at line 732 of file shell.h.

Referenced by restart(), and shell().

◆ argv()

char** ucommon::shell::argv ( void  ) const
inline

Get saved internal argv count for items in this shell object. This may be filename items only that remain after shell expansion and options that have been parsed.

Returns
list of remaining arguments.

Definition at line 741 of file shell.h.

Referenced by collapse(), count(), detach(), getargv(), getargv0(), main(), parse(), restart(), shell(), and spawn().

◆ argv0()

const char* ucommon::shell::argv0 ( ) const
inline

Get program name (argv0).

Definition at line 664 of file shell.h.

Referenced by main(), relocate(), restart(), and set0().

◆ bind()

void ucommon::shell::bind ( const char *  name)
static

Bind application to text domain for internationalization. This is useful if the argv0 argument can vary because of a symlinked executable. This is the name of the .po/.mo message files for your application. If bind is not called before shell processing, then the argv0 is used as the bind name. Bind can be called multiple times to change the default message catalog name of the application, and this usage may be needed for plugins, though it's generally recommended to use only once, and at the start of main().

Parameters
nameof text domain for the application.

Definition at line 2113 of file shell.cpp.

References ucommon::_domain, bindtextdomain, path(), setlocale, SYSTEM_SHARE, and textdomain.

Referenced by main(), and set0().

◆ cancel()

int ucommon::shell::cancel ( shell::pid_t  pid)
static

Cancel a child process.

Parameters
pidof child process to cancel.
Returns
exit code of process, -1 if fails or pid is invalid.

Definition at line 2083 of file shell.cpp.

References wait().

Referenced by ucommon::pipestream::terminate().

◆ collapse()

void ucommon::shell::collapse ( LinkedObject first)
private

Collapse argument list. This is used internally to collapse args that are created in a pool heap when they need to be turned into an argv style array.

Definition at line 280 of file shell.cpp.

References ucommon::mempager::_alloc(), _argc, _argv, argv(), ucommon::is(), ucommon::shell::args::item, and ucommon::linked_pointer< T >::next().

Referenced by getargv(), and parse().

◆ condition()

static void static void static int ucommon::shell::condition ( bool  test,
int  exitcode 
)
inlinestatic

Convert condition to exit code if true.

Parameters
testcondition.
exitcodeto use if true.

Definition at line 691 of file shell.h.

◆ count()

unsigned ucommon::shell::count ( char **  argv)
static

Get argc count for an existing array.

Parameters
argvto count items in.
Returns
argc count of array.

Definition at line 398 of file shell.cpp.

References argv().

Referenced by getpass(), help(), and restart().

◆ debug()

void ucommon::shell::debug ( unsigned  level,
const char *  format,
  ... 
)
static

Print a debug message by debug level.

Parameters
levelof debug message.
formatstring to use.

Definition at line 2173 of file shell.cpp.

References DEBUG0, ucommon::errlevel, and ucommon::errname.

◆ detach() [1/2]

int ucommon::shell::detach ( const char *  path,
char **  argv,
char **  env = NULL,
fd_t stdio = NULL 
)
static

Create a detached process. This creates a new child process that is completely detached from the current process.

Parameters
pathto executable.
argvlist of command arguments for the child process.
envof child process can be explicitly set.
stdiohandles for stdin, stdout, and stderr.
Returns
0 if success, -1 on error.

Definition at line 1903 of file shell.cpp.

References argv(), INVALID_HANDLE_VALUE, ucommon::memalloc::max(), path(), and ucommon::String::set().

◆ detach() [2/2]

void ucommon::shell::detach ( mainproc_t  mainentry = (mainproc_t)NULL)

Detach current process to daemon for service entry.

Definition at line 1846 of file shell.cpp.

References _PATH_TTY, and crit.

Referenced by main().

◆ errexit()

void ucommon::shell::errexit ( int  exitcode,
const char *  format = NULL,
  ... 
)
static

Print error message and exit. Ignored if exitcode == 0.

Parameters
exitcodeto return to parent process.
formatstring to use.

Definition at line 828 of file shell.cpp.

References ucommon::eq(), ucommon::errlevel, ucommon::errmode, ucommon::errname, FAIL, NONE, and ucommon::String::set().

Referenced by binarydecode(), getargv(), getargv0(), main(), process(), report(), result(), streamdecode(), and zerofill().

◆ errlog()

void ucommon::shell::errlog ( const char *  format,
  ... 
)
static

Print error message and continue.

Parameters
formatstring to use.

Definition at line 787 of file shell.cpp.

References ucommon::eq(), ERR, ucommon::errlevel, ucommon::errmode, ucommon::errname, NONE, and ucommon::String::set().

◆ errmsg() [1/2]

const char * ucommon::shell::errmsg ( errmsg_t  id)
static

This can be used to get internationalized error messages. The internal text for shell parser errors are passed through here.

Parameters
idof error message to use.
Returns
published text of error message.

Definition at line 377 of file shell.cpp.

References dgettext, and ucommon::msgs.

Referenced by ucommon::shell::flagopt::assign(), ucommon::shell::stringopt::assign(), ucommon::shell::charopt::assign(), ucommon::shell::numericopt::assign(), ucommon::shell::counteropt::assign(), ucommon::shell::errormap::errormap(), getargv(), and getargv0().

◆ errmsg() [2/2]

void ucommon::shell::errmsg ( errmsg_t  id,
const char *  text 
)
static

This is used to set internationalized error messages for the shell parser.

Parameters
idof message to set.
textfor error message.

Definition at line 382 of file shell.cpp.

References ucommon::msgs, and text().

◆ error()

static fd_t ucommon::shell::error ( void  )
inlinestatic

Definition at line 875 of file shell.h.

◆ execdir()

const char* ucommon::shell::execdir ( ) const
inline

Get the exec directory.

Definition at line 670 of file shell.h.

◆ exiting()

void ucommon::shell::exiting ( exitproc_t  handler)
static

Definition at line 1771 of file shell.cpp.

References ucommon::_exitproc, ucommon::abort_handler(), and ucommon::exit_handler().

Referenced by main().

◆ getargv()

◆ getargv0()

char * ucommon::shell::getargv0 ( char **  argv)

Parse and extract the argv0 filename alone.

Parameters
argvfrom main.
Returns
argv0 simple path name.

Definition at line 561 of file shell.cpp.

References _argv0, argv(), errexit(), errmsg(), NOARGS, and set0().

Referenced by parse().

◆ getenv()

const char * ucommon::shell::getenv ( const char *  name,
const char *  value = NULL 
)

Get an environment variable. This creates a local copy of the variable in pager memory.

Parameters
nameof symbol.
valueof symbol if not found.
Returns
value of symbol.

Definition at line 1665 of file shell.cpp.

References ucommon::dup().

Referenced by getsym(), path(), and userid().

◆ getline()

char * ucommon::shell::getline ( const char *  prompt,
char *  buffer,
size_t  size 
)
static

◆ getNumeric()

long ucommon::shell::getNumeric ( void  )
static

Definition at line 393 of file shell.cpp.

References ucommon::numeric_value.

◆ getpass()

char * ucommon::shell::getpass ( const char *  prompt,
char *  buffer,
size_t  size 
)
static

Definition at line 1483 of file shell.cpp.

References buffer, count(), ucommon::echo(), ucommon::noecho(), and ucommon::memalloc::size().

Referenced by main().

◆ getsym()

const char * ucommon::shell::getsym ( const char *  name,
const char *  value = NULL 
)

Get a local symbol. This uses getenv if no local symbol is found.

Parameters
nameof symbol.
valueof symbol if not found.
Returns
value of symbol.

Definition at line 2450 of file shell.cpp.

References _syms, ucommon::Mutex::acquire(), ucommon::eq(), getenv(), ucommon::is(), ucommon::shell::syms::name, ucommon::Mutex::release(), ucommon::symlock, and ucommon::shell::syms::value.

◆ help()

◆ inkey()

int ucommon::shell::inkey ( const char *  prompt = NULL)
static

Definition at line 1506 of file shell.cpp.

References ch, ucommon::echo(), ucommon::fsys::is_tty(), and ucommon::noecho().

Referenced by process().

◆ input()

static fd_t ucommon::shell::input ( void  )
inlinestatic

Definition at line 869 of file shell.h.

Referenced by digest(), encodestream(), and getline().

◆ is_sym()

bool ucommon::shell::is_sym ( const char *  name) const

Test if symbol exists.

Parameters
nameof symbol.
Returns
true if found.

Definition at line 2433 of file shell.cpp.

References ucommon::Mutex::acquire(), ucommon::eq(), ucommon::is(), ucommon::shell::syms::name, ucommon::Mutex::release(), and ucommon::symlock.

◆ log() [1/2]

void ucommon::shell::log ( const char *  name,
loglevel_t  level = ERR,
logmode_t  mode = USER_LOG,
logproc_t  handler = (logproc_t)NULL 
)
static

Set logging level and state.

Parameters
nameof logging entity.
levelof error conditions to log.
modeof logging.
handlerfor log messages.

Definition at line 2334 of file shell.cpp.

References ucommon::errlevel, ucommon::errmode, ucommon::errname, and ucommon::errproc.

◆ log() [2/2]

void ucommon::shell::log ( loglevel_t  level,
const char *  format,
  ... 
)
static

Print generic error message at specific error level.

Parameters
levelof error condition.
formatstring to use.

Definition at line 2367 of file shell.cpp.

References cpr_runtime_error(), DEBUG0, ucommon::errlevel, ucommon::errmode, ucommon::errname, ucommon::errproc, FAIL, and NONE.

◆ operator()()

unsigned ucommon::shell::operator() ( void  ) const
inline

Return argc count.

Returns
argc count.

Definition at line 822 of file shell.h.

◆ operator[]()

const char* ucommon::shell::operator[] ( unsigned  offset)
inline

Return parser argv element.

Parameters
offsetinto array.
Returns
argument string.

Definition at line 749 of file shell.h.

◆ output()

static fd_t ucommon::shell::output ( void  )
inlinestatic

Definition at line 872 of file shell.h.

◆ parse() [1/2]

char ** ucommon::shell::parse ( const char *  string)

Parse a string as a series of arguments for use in exec calls.

Parameters
stringto parse.
Returns
argument array.

Definition at line 489 of file shell.cpp.

References ucommon::mempager::_alloc(), _argc, _argv, ucommon::OrderedIndex::begin(), collapse(), ucommon::dup(), ucommon::OrderedObject::enlist(), ucommon::shell::args::item, quote, and set0().

Referenced by shell().

◆ parse() [2/2]

void ucommon::shell::parse ( int  argc,
char **  argv 
)

Parse the command line arguments using the option table. File arguments will be expanded for wildcards on some platforms. The argv will be set to the first file argument after all options are parsed.

Parameters
argcfrom main.
argvfrom main.

Definition at line 552 of file shell.cpp.

References ucommon::_orig, argv(), getargv(), and getargv0().

◆ path() [1/3]

String ucommon::shell::path ( path_t  id)
static

Get a system path. This is used to get directories for application specific data stores and default paths for config keys.

Parameters
idof path to return.
Returns
path string or emptry string if not supported.

Definition at line 1551 of file shell.cpp.

References ucommon::_domain, ucommon::dir::create(), getenv(), ucommon::fsys::OWNER_PRIVATE, PROGRAM_CONFIG, PROGRAM_PLUGINS, PROGRAM_TEMP, result(), SERVICE_CACHE, SERVICE_CONFIG, SERVICE_CONTROL, SERVICE_DATA, ucommon::str(), SYSTEM_CFG, SYSTEM_ETC, SYSTEM_PREFIX, ucommon::system_prefix, SYSTEM_SHARE, SYSTEM_TEMP, SYSTEM_VAR, USER_CACHE, USER_CONFIG, USER_DATA, USER_DEFAULTS, and USER_HOME.

Referenced by bind(), detach(), ucommon::secure::oscerts(), path(), and spawn().

◆ path() [2/3]

String ucommon::shell::path ( path_t  id,
const char *  directory 
)
static

Get a merged path. If the path requested is a full path, then the prefix is ignored.

Parameters
idof prefix.
directorypath to merge with prefix.

Definition at line 2500 of file shell.cpp.

References path(), and result().

◆ path() [3/3]

String ucommon::shell::path ( String prefix,
const char *  directory 
)
static

Join a prefix with a path.

Parameters
prefixto merge with.
directoryor file path to merge.

Definition at line 2489 of file shell.cpp.

References prefix, and ucommon::str().

◆ printf()

size_t ucommon::shell::printf ( const char *  format,
  ... 
)
static

Definition at line 874 of file shell.cpp.

References EOF, and result().

Referenced by cleanup(), getline(), help(), main(), report(), result(), scrub(), and zerofill().

◆ priority()

void ucommon::shell::priority ( int  pri = 1)
static

Set priority level and enable priority scheduler. This activates the realtime priority scheduler when a priority > 0 is requested for the process, assuming scheduler support exists and the process is sufficiently privileged. Negative priorities are essentially the same as nice.

Parameters
prilevel for process.

Definition at line 2143 of file shell.cpp.

References ucommon::memalloc::max(), and ucommon::min().

◆ rebind()

void ucommon::shell::rebind ( const char *  name = NULL)
static

Rebind is used to change the text domain. This may be needed in applications which have separately built plugins that have thier own message catalogs. Normally the plugin would call bind itself at initialization, and then use rebind to select either the application's domain, or the plugins. On systems without internationalization, this has no effect.

Parameters
nameof text domain of plugin or NULL to restore application.

Definition at line 2130 of file shell.cpp.

References ucommon::_domain, and textdomain.

◆ release()

void ucommon::shell::release ( int  exit_code = 0)
static

Detach and release from parent process with exit code.

Parameters
exit_codeto send to parent process.

Definition at line 1785 of file shell.cpp.

References _PATH_TTY, crit, and exit_code.

◆ relocate()

void ucommon::shell::relocate ( const char *  argv0)
static

Set relative prefix. Used for OS/X relocatable applications.

Parameters
argv0path of executable.

Definition at line 1520 of file shell.cpp.

References argv0(), ucommon::eq(), and ucommon::system_prefix.

◆ restart() [1/2]

void ucommon::shell::restart ( char *  argv0,
char **  argv,
char **  list 
)

Execute front-end like gdb based on stripped first argument.

Parameters
argv0of our executable.
argvto pass to child.
listof arguments to execute in front of argv.

Definition at line 2407 of file shell.cpp.

References ucommon::mempager::_alloc(), argc(), argv(), argv0(), and count().

◆ restart() [2/2]

void ucommon::shell::restart ( void  )

Make current process restartable.

Definition at line 1728 of file shell.cpp.

References WIFEXITED, and WTERMSIG.

◆ security()

void ucommon::shell::security ( loglevel_t  level,
const char *  format,
  ... 
)
static

Print security error message at specific error level.

Parameters
levelof error condition.
formatstring to use.

Definition at line 2344 of file shell.cpp.

References cpr_runtime_error(), DEBUG0, ucommon::errmode, ucommon::errname, FAIL, and NONE.

◆ set0()

void ucommon::shell::set0 ( char *  argv0)
private

Set argv0. This gets the simple filename of argv[0].

Definition at line 291 of file shell.cpp.

References _argv0, ucommon::_domain, _exedir, ucommon::String::add(), argv0(), bind(), ucommon::dup(), ucommon::eq(), ucommon::eq_case(), prefix, ucommon::fsys::prefix(), and ucommon::String::set().

Referenced by getargv0(), and parse().

◆ setNumeric()

void ucommon::shell::setNumeric ( numeric_t  mode)
static

Definition at line 387 of file shell.cpp.

References ucommon::numeric_mode, and ucommon::numeric_value.

◆ setsym()

void ucommon::shell::setsym ( const char *  name,
const char *  value 
)

◆ spawn()

shell::pid_t ucommon::shell::spawn ( const char *  path,
char **  argv,
char **  env = NULL,
fd_t stdio = NULL 
)
static

Spawn a child process. This creates a new child process. If the executable path is a pure filename, then the $PATH will be used to find it. The argv array may be created from a string with the shell string parser.

Parameters
pathto executable.
argvlist of command arguments for the child process.
envof child process can be explicitly set.
stdiohandles for stdin, stdout, and stderr.
Returns
process id of child or INVALID_PID_VALUE if fails.

Definition at line 2012 of file shell.cpp.

References argv(), INVALID_HANDLE_VALUE, INVALID_PID_VALUE, ucommon::memalloc::max(), path(), and ucommon::String::set().

Referenced by ucommon::fsys::exec(), and ucommon::pipestream::open().

◆ system()

int ucommon::shell::system ( const char *  command,
const char **  env = NULL 
)
static

A shell system call. This uses the native system shell to invoke the command.

Parameters
commandstring..
envarray to optionally use.
Returns
error code of child process.

Definition at line 1674 of file shell.cpp.

References ucommon::memalloc::max(), and ucommon::String::set().

Referenced by systemf().

◆ systemf()

int ucommon::shell::systemf ( const char *  format,
  ... 
)
static

A shell system call that can be issued using a formatted string. This uses the native system shell to invoke the command.

Parameters
formatof/command string.
Returns
error code of child process.

Definition at line 540 of file shell.cpp.

References buffer, and system().

◆ text()

const char * ucommon::shell::text ( const char *  string)
static

Text translation and localization. This function does nothing but return the original string if no internationalization support is available. If internationalization support exists, then it may return a substituted translation based on the current locale. This offers a single function that can be safely used either when internationalization support is present, or it is absent, eliminating the need for the application to be coded differently based on awareness of support.

Parameters
stringto translate.
Returns
translation if found or original text.

Definition at line 2104 of file shell.cpp.

References gettext.

Referenced by ucommon::__TEXT(), ucommon::_TEXT(), ucommon::shell::stringopt::assign(), errmsg(), getargv(), and help().

◆ texts()

const char * ucommon::shell::texts ( const char *  singular,
const char *  plural,
unsigned long  count 
)
static

Plural text translation and localization. This does nothing but return single or plural forms if no internationalization is enabled. Else it uses ngettext().

Parameters
singularstring to translate.
pluralstring to translate.
countof objects.
Returns
string to use.

Definition at line 2092 of file shell.cpp.

◆ userid()

String ucommon::shell::userid ( void  )
static

Get the system login id.

Returns
login id.

Definition at line 1541 of file shell.cpp.

References getenv(), and ucommon::str().

◆ wait()

int ucommon::shell::wait ( shell::pid_t  pid)
static

Wait for a child process to terminate. This operation blocks.

Parameters
pidof process to wait for.
Returns
exit code of process, -1 if fails or pid is invalid.

Definition at line 2070 of file shell.cpp.

References INVALID_PID_VALUE, and WEXITSTATUS.

Referenced by cancel(), ucommon::pipestream::close(), and ucommon::fsys::exec().

Member Data Documentation

◆ _argc

unsigned ucommon::shell::_argc
private

Definition at line 63 of file shell.h.

Referenced by collapse(), getargv(), parse(), and shell().

◆ _argv

char** ucommon::shell::_argv
private

Definition at line 62 of file shell.h.

Referenced by collapse(), getargv(), parse(), and shell().

◆ _argv0

char* ucommon::shell::_argv0
private

Definition at line 64 of file shell.h.

Referenced by getargv(), getargv0(), set0(), and shell().

◆ _exedir

char* ucommon::shell::_exedir
private

Definition at line 65 of file shell.h.

Referenced by set0(), and shell().

◆ _syms

LinkedObject* ucommon::shell::_syms
private

Definition at line 66 of file shell.h.

Referenced by getsym(), setsym(), and shell().


The documentation for this class was generated from the following files: