-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheggshell.h
More file actions
97 lines (68 loc) · 3.93 KB
/
eggshell.h
File metadata and controls
97 lines (68 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#pragma once
/* imports used for various function calls */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>
#include "linenoise.h"
#include <ctype.h>
#include <fcntl.h>
#include <signal.h>
/* Constants defined */
#define MAX_HISTORY 20 //maximum number of commands to add to history
#define MAX_ARGS 30 //maximum number of arguments made acceptable by user input
#define MAX_CHAR 300 //maximum number of characters in a character array (used for string buffers)
#define MAX_PATHS 30 //maximum amount of paths to parse through when looking for external command file location
#define MAX_COMMANDS 20 //maximum amount of commands in the pipeline
#define MAX_SUSPENDED 20 //maximum amount of suspended processes
/* --in vrblController.c-- */
//Struct Declarations
typedef struct shellVariable Var; //instance of a shell variable
typedef struct variableArray VarArr; //stores multiple shell variables
//Method Declarations
int validateVarName(char* name); //check inputted varName for validity
void addVar(char* name, char* content); //adds variable to initialised variable storage
char * getVarValue(const char * variableName); //gets the variable value by name
void setCWD(void); //sets the current working directory variable
void setShellSpecific(void); //calls setCWD() and sets TERMINAL variable
void setSV(void); //sets the variable SHELL (put in other method for neatness)
void setPROMPT(void); //sets PROMPT variable using CWD
void initShellVariables(void); //initialises variable storage and adds initial variables
void printAllVar(void); //prints all the variables stored in the shell
void freeAllVar(void); //frees all variables stored (freeing variable storage platform)
/* --in cmdController.c-- */
/* Method Declarations */
void checkCmd(char * args[MAX_ARGS]); //makes sense of the user inputted command for internal or external
void execEggShell(void); //executes the shell, considered as the main method of the eggShell
/* --in intrnlCmdParser.c-- */
/* Method Declarations */
void parseVrblCmd(char * args[MAX_ARGS]); //parses VARNAME=value
void parsePrintCmd(char * args[MAX_ARGS]); //parses print
void parseChdirCmd(char * args[MAX_ARGS]); //parses chdr
void parseSourceCmd(char * args[MAX_ARGS]); //parses source
/* --in extrnlCmdParser.c-- */
/* Method Declarations */
void fillPaths(char * paths[ MAX_PATHS], char * fileName); //fills all possible paths, appending "/fileName"
char * findSuccPath(char * paths[MAX_PATHS]); //finds valid path from all possible paths for external command
void externalCmd(char * args[MAX_ARGS]); //gets called when command isn't recognized
/* --in ioController.c-- */
/* Method Declarations */
int stdinToFile(char * fileName); //sets stdin to input from file
void stdinToNormal(int fd2); //resets stdin back to normal
void redirectInputString(char * cmd[MAX_ARGS], char * stringArray[MAX_ARGS]); //redirects input fom String
void redirectInputFile(char * cmd[MAX_ARGS], char * fileName); //redirects input from file
int stdoutToFile(char * fileName, int flag); //sets stdout to output to file
void stdoutToNormal(int fd2); //resets stdout back to normal
void redirectOutput(char * cmd[MAX_ARGS], char * fileName, int flag); //redirects output to file
void checkInputOutput(char * args[MAX_ARGS]); //checks for any I/O redirection before parseCmd()
/* --in pipeController-- */
/* Method Declarations */
void pipePipeLine(char * cmdArray[MAX_COMMANDS][MAX_ARGS], int cmdAmnt); //pipes pipeLine containing more than one command
void checkPipeLine(char * args[MAX_ARGS]); //parses pipeline constructing an array of commands
/* --in sigHandler.c-- */
/* Method Declarations */
void resumeSuspended(int resumeTo); //resumes the last suspended process
void signalHandler(int signo); //sets the signal handler method for CTRL+C and CTRL+Z
void checkForSignals(void); //checks for signals, called in the execEggShell() method
pid_t current_pid; //used for the current process id in signal handling