rush
Revamped UNIX Shell
|
Helper functions for shell implementations. More...
#include <limits.h>
#include <stdbool.h>
Go to the source code of this file.
Data Structures | |
struct | ShCommand |
The ShCommand structure contains a parsed command. More... | |
Macros | |
#define | MAX_CMDLINE_LEN 1048576 |
Maximum length of the command line (including '\0' ). | |
Functions | |
void | shPrompt (void) |
Prints a prompt symbol including the shell's current working directory. More... | |
ShCommand * | shParseCmdLine (char cmdLine[]) |
Parses a command line. More... | |
Helper functions for shell implementations.
This module offers the following functionality to facilitate implementing a simple UNIX shell:
ShCommand * shParseCmdLine | ( | char | cmdLine[] | ) |
Parses a command line.
This function parses a command-line string that may contain '&'
(for background execution) as well as '<'
and '>'
for stdin
and stdout
redirection, respectively. shParseCmdLine() will generate the argv
array for the given command line and return an ShCommand structure containing the result. The members of the argv
array will point into the original string, whose contents are modified for this purpose.
The returned ShCommand structure lies in statically allocated memory and is overwritten by subsequent calls to shParseCmdLine().
cmdLine | The command line to be parsed. This string is tokenized during shParseCmdLine(). It must be no more than MAX_CMDLINE_LEN characters long (including the terminating '\0' ), otherwise NULL is returned and errno is set to EINVAL . |
NULL
on error, with errno
set appropriately. In case a custom error message is supplied, the function returns an ShCommand structure that has its parseError
field set to a custom error message. If the parseError
field is set to a value other than NULL
, parsing the command line has failed and the remaining fields of the ShCommand structure must not be interpreted.void shPrompt | ( | void | ) |
Prints a prompt symbol including the shell's current working directory.
stderr
.