66 for ( argc = 0 ; argv[argc] ; argc++ ) {}
91 rc =
cmd->exec ( argc, (
char ** ) argv );
184 int ( **process_next ) (
int rc ) ) {
188 for ( i = 0 ; tokens[i] ; i++ ) {
189 if ( tokens[i][0] ==
'#' ) {
192 }
else if (
strcmp ( tokens[i],
"||" ) == 0 ) {
196 }
else if (
strcmp ( tokens[i],
"&&" ) == 0 ) {
200 }
else if (
strcmp ( tokens[i],
";" ) == 0 ) {
208 *process_next =
NULL;
252 for ( i = 0 ; i < argc ; i++ ) {
255 goto err_expand_settings;
262 for ( ; i >= 0 ; i-- )
289 char *all_tokens[
count + 1 ];
290 int ( * process_next ) (
int rc );
299 if ( ! command_copy )
308 for ( tokens = all_tokens ; ; tokens += ( argc + 1 ) ) {
315 char *argv[ argc + 1 ];
336 if ( ! process_next )
344 free ( command_copy );
366 for ( arg = args ; *arg ; arg++ )
376 for ( arg = args ; *arg ; arg++ ) {
378 ( ( arg == args ) ?
"" :
" " ), *arg );
424 printf (
"%s%s", text, (
opts.no_newline ?
"" :
"\n" ) );
455 unsigned int exit_code = 0;
524 "<value1> <value2>" );
int parse_integer(char *text, unsigned int *value)
Parse integer value.
#define EINVAL
Invalid argument.
static struct option_descriptor sleep_opts[]
"sleep" option list
static struct option_descriptor exit_opts[]
"exit" option list
struct arbelprm_rc_send_wqe rc
int printf(const char *fmt,...)
Write a formatted string to the console.
int optind
Current option index.
int no_newline
Do not print trailing newline.
static int isset_exec(int argc, char **argv)
"isset" command
int system(const char *command)
Execute command line.
#define ENOEXEC
Exec format error.
#define sprintf(buf, fmt,...)
Write a formatted string to a buffer.
struct command echo_command __command
"echo" command
static struct command_descriptor sleep_cmd
"sleep" command descriptor
#define ENOENT
No such file or directory.
static void free_tokens(char **argv)
Free an expanded token list.
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
char * expand_settings(const char *string)
Expand variables within string.
void shell_stop(int stop)
Set shell stop state.
#define ECANCELED
Operation canceled.
static int expand_tokens(int argc, char **tokens, char **argv)
Expand settings within a token list.
#define ENOMEM
Not enough space.
Stop processing current command line.
#define __unused
Declare a variable or data structure as unused.
Parse command-line options.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static int process_always(int rc __unused)
Process next command regardless of status from previous command.
static struct option_descriptor echo_opts[]
"echo" option list
int errno
Global "last error" number.
static int echo_exec(int argc, char **argv)
"echo" command
static struct command_descriptor isset_cmd
"isset" command descriptor
#define MAX_ARGUMENTS
No maximum number of arguments.
static struct command_descriptor exit_cmd
"exit" command descriptor
static struct option_descriptor isset_opts[]
"isset" option list
uint16_t count
Number of entries.
char * concat_args(char **args)
Concatenate arguments.
static int sleep_exec(int argc, char **argv)
"sleep" command
int parse_flag(char *text __unused, int *flag)
Parse flag.
#define ERANGE
Result too large.
static void(* free)(struct refcnt *refcnt))
void * zalloc(size_t size)
Allocate cleared memory.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
static int process_on_failure(int rc)
Process next command only if previous command failed.
char * strdup(const char *src)
Duplicate string.
Command line option parsing.
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
int isspace(int character)
Check to see if character is a space.
size_t strlen(const char *src)
Get length of string.
Option does not take an argument.
static struct option_descriptor iseq_opts[]
"iseq" option list
static int iseq_exec(int argc, char **argv)
"iseq" command
static void reset_getopt(void)
Reset getopt() internal state.
static struct command_descriptor echo_cmd
"echo" command descriptor
const char * name
Name of the command.
int shell_stopped(int stop)
Test and consume shell stop state.
static int exit_exec(int argc, char **argv)
"exit" command
static int stop_state
Shell stop state.
int strcmp(const char *first, const char *second)
Compare strings.
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Stop processing commands.
A command-line option descriptor.
UINT16_t seconds
Elapsed time.
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
static int command_terminator(char **tokens, int(**process_next)(int rc))
Find command terminator.
static struct command_descriptor iseq_cmd
"iseq" command descriptor
static int process_on_success(int rc)
Process next command only if previous command succeeded.
static int split_command(char *command, char **tokens)
Split command line into tokens.
#define DBG(...)
Print a debugging message.
static union @438 opts
"cert<xxx>" option list
unsigned int sleep(unsigned int secs)
Sleep (interruptibly) for a fixed number of seconds.
#define NULL
NULL pointer (VOID *)
struct bofm_section_header done
int execv(const char *command, char *const argv[])
Execute command.