Quash Shell  0.1
A simple yet powerfull shell program
Functions
command.c File Reference

Implements functions used to generate and manage commands. More...

#include "command.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

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 **strs)
 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...
 

Detailed Description

Implements functions used to generate and manage commands.

Function Documentation

void debug_print_script ( const CommandHolder holders)

Print all commands in the script with print_command()

Note
This only works when the DEBUG macro is defined
Parameters
holdersCommandHolder array to print
See also
CommandHolder
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.

Parameters
holderCommandHolder from which this function extracts the CommandType
Returns
The resulting CommandType of the cmd parameter
See also
CommandType, CommandHolder, SimpleCommand
CommandType 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.

Parameters
cmdCommand from which this function extracts the CommandType
Returns
The resulting CommandType of the cmd parameter
See also
CommandType, Command, SimpleCommand
Command mk_cd_command ( char *  dir)

Create a CDCommand structure and return a copy.

Parameters
dirPath to the directory we wish to change to
Returns
Copy of constructed CDCommand as a Command
See also
realpath(), Command, CDCommand
CommandHolder mk_command_holder ( char *  redirect_in,
char *  redirect_out,
char  flags,
Command  cmd 
)

Create a CommandHolder structure and return a copy.

Parameters
redirect_inIf 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_outIf 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
flagsA 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:
  • REDIRECT_IN
  • REDIRECT_OUT
  • REDIRECT_APPEND
  • PIPE_IN
  • PIPE_OUT
  • BACKGROUND
cmdThe Command the CommandHolder should copy and hold on to
Returns
Copy of constructed CommandHolder
See also
CommandType, REDIRECT_IN, REDIRECT_OUT, REDIRECT_APPEND, PIPE_IN, PIPE_OUT, BACKGROUND, Command, CommandHolder
Command mk_echo_command ( char **  args)

Create a EchoCommand structure and return a copy.

Parameters
argsA NULL terminated array of strings containing the strings passed to echo
Returns
Copy of constructed EchoCommand as a Command
See also
Command, EchoCommand
Command mk_eoc ( )

Create a EOCCommand structure and return a copy.

Returns
Copy of constructed EOCCommand as a Command
See also
Command, EOCCommand
Command mk_exit_command ( )

Create a ExitCommand structure and return a copy.

Returns
Copy of constructed ExitCommand as a Command
See also
Command, ExitCommand
Command mk_export_command ( char *  env_var,
char *  val 
)

Create a ExportCommand structure and return a copy.

Parameters
env_varName of environment variable to set
valString that should be stored in env_var environment variable
Returns
Copy of constructed ExportCommand as a Command
See also
lookup_env(), write_env(), Command, ExportCommand
Command mk_generic_command ( char **  args)

Create a GenericCommand structure and return a copy.

Parameters
argsA NULL terminated array of strings ready to pass to the exec family of functions
Returns
Copy of constructed GenericCommand as a Command
See also
Command, GenericCommand
Command mk_jobs_command ( )

Create a JobsCommand structure and return a copy.

Returns
Copy of constructed JobsCommand as a Command
See also
Command, JobsCommand
Command mk_kill_command ( char *  sig,
char *  job 
)

Create a KillCommand structure and return a copy.

Parameters
sigSignal to send to the job
jobJob id number
Returns
Copy of constructed KillCommand as a Command
See also
Command, KillCommand
Command mk_pwd_command ( )

Create a PWDCommand structure and return a copy.

Returns
Copy of constructed PWDCommand as a Command
See also
Command, PWDCommand