Quash Shell  0.1
A simple yet powerfull shell program
 All Classes Files Functions Variables Typedefs Enumerations Macros
Macros | Functions
execute.c File Reference

Implements interface functions between Quash and the environment and functions that interpret an execute commands. More...

#include "execute.h"
#include <stdio.h>
#include "quash.h"

Macros

#define IMPLEMENT_ME()   fprintf(stderr, "IMPLEMENT ME: %s(line %d): %s()\n", __FILE__, __LINE__, __FUNCTION__)
 Note calls to any function that requires implementation.
 

Functions

char * get_current_directory (bool *should_free)
 Get the real current working directory. More...
 
const char * lookup_env (const char *env_var)
 Function to get environment variable values. 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 child_run_command (Command cmd)
 A dispatch function to resolve the correct Command variant function for child processes. More...
 
void parent_run_command (Command cmd)
 A dispatch function to resolve the correct Command variant function for the quash process. More...
 
void create_process (CommandHolder holder)
 Creates one new process centered around the Command in the CommandHolder setting up redirects and pipes where needed. More...
 
void run_script (CommandHolder *holders)
 Common entry point for all commands. More...
 

Detailed Description

Implements interface functions between Quash and the environment and functions that interpret an execute commands.

Note
As you add things to this file you may want to change the method signature

Function Documentation

void child_run_command ( Command  cmd)

A dispatch function to resolve the correct Command variant function for child processes.

This version of the function is tailored to commands that should be run in the child process of a fork.

Parameters
cmdThe Command to try to run
See Also
Command
void create_process ( CommandHolder  holder)

Creates one new process centered around the Command in the CommandHolder setting up redirects and pipes where needed.

Note
Processes are not the same as jobs. A single job can have multiple processes running under it. This function creates a process that is part of a larger job.
Not all commands should be run in the child process. A few need to change the quash process in some way
Parameters
holderThe CommandHolder to try to run
See Also
Command CommandHolder
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 parent_run_command ( Command  cmd)

A dispatch function to resolve the correct Command variant function for the quash process.

This version of the function is tailored to commands that should be run in the parent process (quash).

Parameters
cmdThe Command to try to run
See Also
Command
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