Quash Shell  0.1
A simple yet powerfull shell program
Functions
execute.h File Reference

Functions for interpreting and running commands. More...

#include <stdbool.h>
#include <unistd.h>
#include "command.h"

Go to the source code of this file.

Functions

const char * lookup_env (const char *env_var)
 Function to get environment variable values. More...
 
void write_env (const char *env_var, const char *val)
 Function to set and define environment variable values. More...
 
char * get_current_directory (bool *should_free)
 Get the real current working directory. More...
 
void check_jobs_bg_status ()
 Check on background jobs to see if they have exited.
 
void print_job (int job_id, pid_t pid, const char *cmd)
 Print a job to standard out. More...
 
void print_job_bg_start (int job_id, pid_t pid, const char *cmd)
 Print the start up of a background job to standard out. More...
 
void print_job_bg_complete (int job_id, pid_t pid, const char *cmd)
 Print the completion of a background job to standard out. More...
 
void run_generic (GenericCommand cmd)
 Run a generic (non-builtin) command. More...
 
void run_echo (EchoCommand cmd)
 Run the builtin echo command. More...
 
void run_export (ExportCommand cmd)
 Run the builtin export command. More...
 
void run_cd (CDCommand cmd)
 Run the builtin cd (change directory) command. More...
 
void run_kill (KillCommand cmd)
 Run the builtin kill command. More...
 
void run_pwd ()
 Run the builtin pwd (print working directory) command. More...
 
void run_jobs ()
 Run the builtin jobs command to show the jobs list. More...
 
void run_script (CommandHolder *holders)
 Common entry point for all commands. More...
 

Detailed Description

Functions for interpreting and running commands.

Function Documentation

char* get_current_directory ( bool *  should_free)

Get the real current working directory.

This is not necessarily the same as the PWD environment variable and setting PWD does not actually change the current working directory.

Parameters
[out]should_freeSet this to true if the returned string should be free'd by the caller and false otherwise.
Returns
A string representing the current working directory
const char* lookup_env ( const char *  env_var)

Function to get environment variable values.

Parameters
env_varEnvironment variable to lookup
Returns
String containing the value of the environment variable env_var
void print_job ( int  job_id,
pid_t  pid,
const char *  cmd 
)

Print a job to standard out.

We use the minimum of what a Job structure should contain to pass to this function.

Parameters
job_idJob identifier number.
pidProcess id of a process belonging to this job.
cmdString holding an approximation of what the user typed in for the command.
void print_job_bg_complete ( int  job_id,
pid_t  pid,
const char *  cmd 
)

Print the completion of a background job to standard out.

We use the minimum of what a Job should contain to pass to this function.

Parameters
job_idJob identifier number.
pidProcess id of a process belonging to this job.
cmdString holding an aproximation of what the user typed in for the command.
void print_job_bg_start ( int  job_id,
pid_t  pid,
const char *  cmd 
)

Print the start up of a background job to standard out.

We use the minimum of what a Job should contain to pass to this function.

Parameters
job_idJob identifier number.
pidProcess id of a process belonging to this job.
cmdString holding an aproximation of what the user typed in for the command.
void run_cd ( CDCommand  cmd)

Run the builtin cd (change directory) command.

Parameters
cmdAn CDCommand
See also
CDCommand
void run_echo ( EchoCommand  cmd)

Run the builtin echo command.

Parameters
cmdAn EchoCommand
See also
EchoCommand
void run_export ( ExportCommand  cmd)

Run the builtin export command.

Parameters
cmdAn ExportCommand
See also
ExportCommand
void run_generic ( GenericCommand  cmd)

Run a generic (non-builtin) command.

Parameters
cmdA GenericCommand command
See also
GenericCommand
void run_jobs ( )

Run the builtin jobs command to show the jobs list.

See also
PWDCommand
void run_kill ( KillCommand  cmd)

Run the builtin kill command.

Parameters
cmdA KillCommand
See also
KillCommand
void run_pwd ( )

Run the builtin pwd (print working directory) command.

See also
PWDCommand
void run_script ( CommandHolder holders)

Common entry point for all commands.

This function resolves the type of the command and calls the relevant run function

Parameters
holdersAn array of command holders
See also
Command
void write_env ( const char *  env_var,
const char *  val 
)

Function to set and define environment variable values.

Parameters
env_varEnvironment variable to set
valString with the value to set the environment variable env_var