Quash Shell
0.1
A simple yet powerfull shell program
|
Command structures and functions for defining and managing commands. More...
#include <stdbool.h>
Go to the source code of this file.
Classes | |
struct | SimpleCommand |
A command which has no arguments. More... | |
struct | GenericCommand |
Commands that take any number of arguments and are not built into Quash. More... | |
struct | ExportCommand |
Command to set environment variables. More... | |
struct | CDCommand |
Command to change directories. More... | |
struct | KillCommand |
Command to kill a process based on it's job id. More... | |
union | Command |
Make all command types the same size and interchangeable. More... | |
struct | CommandHolder |
Contains information about the properties of the command. More... | |
Macros | |
#define | REDIRECT_IN (0x01) |
Flag bit indicating whether a GenericCommand should read from standard in. | |
#define | REDIRECT_OUT (0x04) |
Flag bit indicating whether a GenericCommand should write to standard out truncating the original file. | |
#define | REDIRECT_APPEND (0x08) |
Flag bit indicating whether a GenericCommand should write to standard out appending its output. | |
#define | PIPE_IN (0x10) |
Flag bit indicating whether a GenericCommand should read from a pipe. | |
#define | PIPE_OUT (0x20) |
Flag bit indicating whether a GenericCommand should write to a pipe. | |
#define | BACKGROUND (0x40) |
Flag bit indicating whether a GenericCommand should be run in the background. | |
Typedefs | |
typedef enum CommandType | CommandType |
All possible types of commands. More... | |
typedef struct SimpleCommand | SimpleCommand |
A command which has no arguments. More... | |
typedef struct GenericCommand | GenericCommand |
Commands that take any number of arguments and are not built into Quash. More... | |
typedef GenericCommand | EchoCommand |
Alias for GenericCommand to denote a command to print strings. More... | |
typedef struct ExportCommand | ExportCommand |
Command to set environment variables. More... | |
typedef struct CDCommand | CDCommand |
Command to change directories. More... | |
typedef struct KillCommand | KillCommand |
Command to kill a process based on it's job id. More... | |
typedef SimpleCommand | PWDCommand |
Alias for SimpleCommand to denote a print working directory command. More... | |
typedef SimpleCommand | JobsCommand |
Alias for SimpleCommand to denote a print jobs list. More... | |
typedef SimpleCommand | ExitCommand |
Alias for SimpleCommand to denote a termination of the program. More... | |
typedef SimpleCommand | EOCCommand |
Alias for SimpleCommand to denote the end of a command. More... | |
typedef union Command | Command |
Make all command types the same size and interchangeable. More... | |
typedef struct CommandHolder | CommandHolder |
Contains information about the properties of the command. More... | |
Enumerations | |
enum | CommandType { EOC = 0, GENERIC, ECHO, EXPORT, KILL, CD, PWD, JOBS, EXIT } |
All possible types of commands. More... | |
Functions | |
CommandHolder | mk_command_holder (char *redirect_in, char *redirect_out, char flags, Command cmd) |
Create a CommandHolder structure and return a copy. More... | |
Command | mk_generic_command (char **args) |
Create a GenericCommand structure and return a copy. More... | |
Command | mk_echo_command (char **args) |
Create a EchoCommand structure and return a copy. More... | |
Command | mk_export_command (char *env_var, char *val) |
Create a ExportCommand structure and return a copy. More... | |
Command | mk_cd_command (char *dir) |
Create a CDCommand structure and return a copy. More... | |
Command | mk_kill_command (char *sig, char *job) |
Create a KillCommand structure and return a copy. More... | |
Command | mk_pwd_command () |
Create a PWDCommand structure and return a copy. More... | |
Command | mk_jobs_command () |
Create a JobsCommand structure and return a copy. More... | |
Command | mk_exit_command () |
Create a ExitCommand structure and return a copy. More... | |
Command | mk_eoc () |
Create a EOCCommand structure and return a copy. More... | |
CommandType | get_command_type (Command cmd) |
Get the type of the command. More... | |
CommandType | get_command_holder_type (CommandHolder holder) |
Get the type of the Command in the CommandHolder. More... | |
void | debug_print_script (const CommandHolder *holders) |
Print all commands in the script with print_command() More... | |
Command structures and functions for defining and managing commands.
Make all command types the same size and interchangeable.
This is useful for arrays or making a common entry point for all command types. The exact type information can be recovered later with the get_command_type() function.
typedef struct CommandHolder CommandHolder |
Contains information about the properties of the command.
typedef enum CommandType CommandType |
typedef GenericCommand EchoCommand |
Alias for GenericCommand to denote a command to print strings.
typedef SimpleCommand EOCCommand |
Alias for SimpleCommand to denote the end of a command.
typedef SimpleCommand ExitCommand |
Alias for SimpleCommand to denote a termination of the program.
typedef struct ExportCommand ExportCommand |
Command to set environment variables.
typedef struct GenericCommand GenericCommand |
Commands that take any number of arguments and are not built into Quash.
typedef SimpleCommand JobsCommand |
Alias for SimpleCommand to denote a print jobs list.
typedef struct KillCommand KillCommand |
Command to kill a process based on it's job id.
typedef SimpleCommand PWDCommand |
Alias for SimpleCommand to denote a print working directory command.
typedef struct SimpleCommand SimpleCommand |
A command which has no arguments.
All command structures can be correctly read as a SimpleCommand since they all have the CommandType field as the first field.
enum CommandType |
void debug_print_script | ( | const CommandHolder * | holders | ) |
Print all commands in the script with print_command()
holders | CommandHolder array to print |
CommandType get_command_holder_type | ( | CommandHolder | holder | ) |
Get the type of the Command in the CommandHolder.
Uses the property that all Command variants can be cast to SimpleCommand to extract the CommandType of the Command.
holder | CommandHolder from which this function extracts the CommandType |
cmd
parameterCommandType get_command_type | ( | Command | cmd | ) |
Get the type of the command.
Uses the property that all Command variants can be cast to SimpleCommand to extract the CommandType of the Command.
cmd | Command from which this function extracts the CommandType |
cmd
parameterCommand mk_cd_command | ( | char * | dir | ) |
CommandHolder mk_command_holder | ( | char * | redirect_in, |
char * | redirect_out, | ||
char | flags, | ||
Command | cmd | ||
) |
Create a CommandHolder structure and return a copy.
redirect_in | If the REDIRECT_IN flag is set, Quash should redirect the standard input stream of the command to read from a file stored in this string |
redirect_out | If the REDIRECT_OUT flag is set, Quash should redirect the standard output stream of the command to write to a file stored in this string |
flags | A set of bits that hold information about how to execute the command. The properties can be extracted from the flags field by using a bit-wise & (i.e. flags & PIPE_IN) are macro defined as:
|
cmd | The Command the CommandHolder should copy and hold on to |
Command mk_echo_command | ( | char ** | args | ) |
Create a EchoCommand structure and return a copy.
args | A NULL terminated array of strings containing the strings passed to echo |
Command mk_eoc | ( | ) |
Create a EOCCommand structure and return a copy.
Command mk_exit_command | ( | ) |
Create a ExitCommand structure and return a copy.
Command mk_export_command | ( | char * | env_var, |
char * | val | ||
) |
Create a ExportCommand structure and return a copy.
env_var | Name of environment variable to set |
val | String that should be stored in env_var environment variable |
Command mk_generic_command | ( | char ** | args | ) |
Create a GenericCommand structure and return a copy.
args | A NULL terminated array of strings ready to pass to the exec family of functions |
Command mk_jobs_command | ( | ) |
Create a JobsCommand structure and return a copy.
Command mk_kill_command | ( | char * | sig, |
char * | job | ||
) |
Create a KillCommand structure and return a copy.
sig | Signal to send to the job |
job | Job id number |
Command mk_pwd_command | ( | ) |
Create a PWDCommand structure and return a copy.