Quash Shell  0.1
A simple yet powerfull shell program
 All Classes Files Functions Variables Typedefs Enumerations Macros
command.h
Go to the documentation of this file.
1 
7 #ifndef SRC_COMMAND_H
8 #define SRC_COMMAND_H
9 
10 #include <stdbool.h>
11 
48 #define REDIRECT_IN (0x01)
49 #define REDIRECT_OUT (0x04)
50 #define REDIRECT_APPEND (0x08)
51 #define PIPE_IN (0x10)
52 #define PIPE_OUT (0x20)
53 #define BACKGROUND (0x40)
54 
63 typedef enum CommandType {
64  EOC = 0, // pseudo-command for marking the end of a script
65  GENERIC,
66  ECHO,
67  EXPORT,
68  KILL,
69  CD,
70  PWD,
71  JOBS,
72  EXIT
73 } CommandType;
74 
75 // Command Structures
76 //
77 // All command structures must begin with the `CommandType type` field since this
78 // is used to determine what the structure is after it is placed in a `union
79 // Command` structure.
80 
89 typedef struct SimpleCommand {
92 
99 typedef struct GenericCommand {
101  char** args;
104 
113 
119 typedef struct ExportCommand {
121  char* env_var;
122  char* val;
124 } ExportCommand;
125 
131 typedef struct CDCommand {
133  char* dir;
134 } CDCommand;
135 
141 typedef struct KillCommand {
143  int sig;
144  int job;
145  char* sig_str;
146  char* job_str;
147 } KillCommand;
148 
155 
162 
169 
176 
188 typedef union Command {
190  GenericCommand generic;
199 } Command;
200 
207 typedef struct CommandHolder {
208  char* redirect_in;
210  char* redirect_out;
212  char flags;
222 } CommandHolder;
223 
224 // Command structure constructors
225 
254 CommandHolder mk_command_holder(char* redirect_in, char* redirect_out, char flags, Command cmd);
255 
266 Command mk_generic_command(char** args);
267 
278 Command mk_echo_command(char** args);
279 
291 Command mk_export_command(char* env_var, char* val);
292 
302 Command mk_cd_command(char* dir);
303 
315 Command mk_kill_command(char* sig, char* job);
316 
325 
334 
343 
351 Command mk_eoc();
352 
366 
381 
391 void debug_print_script(const CommandHolder* holders);
392 
393 #endif
char * dir
Definition: command.h:133
JobsCommand jobs
Definition: command.h:196
char * env_var
Definition: command.h:121
CommandType
All possible types of commands.
Definition: command.h:63
CommandType get_command_holder_type(CommandHolder holder)
Get the type of the Command in the CommandHolder.
Definition: command.c:139
Contains information about the properties of the command.
Definition: command.h:207
Command cmd
Definition: command.h:221
Command mk_echo_command(char **args)
Create a EchoCommand structure and return a copy.
Definition: command.c:39
CommandType type
Definition: command.h:120
char flags
Definition: command.h:212
Command to set environment variables.
Definition: command.h:119
SimpleCommand simple
Definition: command.h:189
GenericCommand EchoCommand
Alias for GenericCommand to denote a command to print strings.
Definition: command.h:112
char * job_str
Definition: command.h:146
union Command Command
Make all command types the same size and interchangeable.
Command to kill a process based on it's job id.
Definition: command.h:141
struct SimpleCommand SimpleCommand
A command which has no arguments.
ExportCommand export
Definition: command.h:192
SimpleCommand PWDCommand
Alias for SimpleCommand to denote a print working directory command.
Definition: command.h:154
A command which has no arguments.
Definition: command.h:89
char * redirect_out
Definition: command.h:210
struct CDCommand CDCommand
Command to change directories.
Command mk_exit_command()
Create a ExitCommand structure and return a copy.
Definition: command.c:113
char * redirect_in
Definition: command.h:208
Command mk_kill_command(char *sig, char *job)
Create a KillCommand structure and return a copy.
Definition: command.c:76
void debug_print_script(const CommandHolder *holders)
Print all commands in the script with print_command()
Definition: command.c:270
Make all command types the same size and interchangeable.
Definition: command.h:188
int job
Definition: command.h:144
CommandHolder mk_command_holder(char *redirect_in, char *redirect_out, char flags, Command cmd)
Create a CommandHolder structure and return a copy.
Definition: command.c:14
CommandType type
Definition: command.h:132
Command to change directories.
Definition: command.h:131
struct CommandHolder CommandHolder
Contains information about the properties of the command.
Command mk_export_command(char *env_var, char *val)
Create a ExportCommand structure and return a copy.
Definition: command.c:51
Command mk_cd_command(char *dir)
Create a CDCommand structure and return a copy.
Definition: command.c:64
Command mk_pwd_command()
Create a PWDCommand structure and return a copy.
Definition: command.c:91
char * val
Definition: command.h:122
Command mk_jobs_command()
Create a JobsCommand structure and return a copy.
Definition: command.c:102
SimpleCommand ExitCommand
Alias for SimpleCommand to denote a termination of the program.
Definition: command.h:168
KillCommand kill
Definition: command.h:194
PWDCommand pwd
Definition: command.h:195
struct KillCommand KillCommand
Command to kill a process based on it's job id.
SimpleCommand JobsCommand
Alias for SimpleCommand to denote a print jobs list.
Definition: command.h:161
EOCCommand eoc
Definition: command.h:198
int sig
Definition: command.h:143
CommandType type
Definition: command.h:142
struct GenericCommand GenericCommand
Commands that take any number of arguments and are not built into Quash.
Command mk_generic_command(char **args)
Create a GenericCommand structure and return a copy.
Definition: command.c:27
CommandType get_command_type(Command cmd)
Get the type of the command.
Definition: command.c:135
EchoCommand echo
Definition: command.h:191
char * sig_str
Definition: command.h:145
struct ExportCommand ExportCommand
Command to set environment variables.
CommandType type
Definition: command.h:90
ExitCommand exit
Definition: command.h:197
CDCommand cd
Definition: command.h:193
char ** args
Definition: command.h:101
SimpleCommand EOCCommand
Alias for SimpleCommand to denote the end of a command.
Definition: command.h:175
CommandType type
Definition: command.h:100
Commands that take any number of arguments and are not built into Quash.
Definition: command.h:99
Command mk_eoc()
Create a EOCCommand structure and return a copy.
Definition: command.c:124