     1	
     2	#include <stdio.h>
     3	#include <stdlib.h>
     4	#include <unistd.h>
     5	#include <string.h>
     6	#include <sys/types.h>
     7	#include <signal.h>
     8	#include <sys/wait.h>
     9	#include <fcntl.h>
    10	#include <termios.h>
    11	#define TRUE 1
    12	#define FALSE !TRUE
    13	
    14	
    15	
    16	#define BUFFER_MAX_LENGTH 50
    17	static char* currentDirectory;
    18	static char userInput = '\0';
    19	static char buffer[BUFFER_MAX_LENGTH];
    20	static int bufferChars = 0;
    21	
    22	static char *commandArgv[5];
    23	static int commandArgc = 0;
    24	
    25	
    26	#define FOREGROUND 'F'
    27	#define BACKGROUND 'B'
    28	#define SUSPENDED 'S'
    29	#define WAITING_INPUT 'W'
    30	
    31	
    32	#define STDIN 1
    33	#define STDOUT 2
    34	
    35	
    36	#define BY_PROCESS_ID 1
    37	#define BY_JOB_ID 2
    38	#define BY_JOB_STATUS 3
    39	
    40	static int numActiveJobs = 0;
    41	
    42	typedef struct job {
    43	        int id;
    44	        char *name;
    45	        pid_t pid;
    46	        pid_t pgid;
    47	        int status;
    48	        char *descriptor;
    49	        struct job *next;
    50	} t_job;
    51	
    52	static t_job* jobsList = NULL;
    53	
    54	
    55	
    56	static pid_t MSH_PID;
    57	static pid_t MSH_PGID;
    58	static int MSH_TERMINAL, MSH_IS_INTERACTIVE;
    59	static struct termios MSH_TMODES;
    60	
    61	void pipelining(int);
    62	void getTextLine();
    63	
    64	void populateCommand();
    65	
    66	void destroyCommand();
    67	
    68	t_job * insertJob(pid_t pid, pid_t pgid, char* name, char* descriptor,
    69	                  int status);
    70	
    71	t_job* delJob(t_job* job);
    72	
    73	t_job* getJob(int searchValue, int searchParameter);
    74	
    75	void printJobs();
    76	
    77	void welcomeScreen();
    78	
    79	void shellPrompt();
    80	void handleUserCommand();
    81	
    82	int checkBuiltInCommands();
    83	
    84	void executeCommand(char *command[], char *file, int newDescriptor,
    85	                    int executionMode);
    86	
    87	void launchJob(char *command[], char *file, int newDescriptor,
    88	               int executionMode);
    89	
    90	void putJobForeground(t_job* job, int continueJob);
    91	
    92	void putJobBackground(t_job* job, int continueJob);
    93	
    94	void waitJob(t_job* job);
    95	
    96	void killJob(int jobId);
    97	
    98	void changeDirectory();
    99	
   100	void init();
   101	
   102	void signalHandler_child(int p);
