Added comments and tips for code

This commit is contained in:
TriantaTV 2022-10-27 19:57:26 -05:00
parent 9f28625f1a
commit 72c42aa825
2 changed files with 132 additions and 113 deletions

View File

@ -4,6 +4,7 @@
#include "Common.h" #include "Common.h"
const char* GetHomeDir(void); const char* GetHomeDir(void);
void ioRedirection(char *inputString, CommandStruct *command);
void IntegratedCheck(CommandStruct* command); void IntegratedCheck(CommandStruct* command);
void GetInput(char* inputString); void GetInput(char* inputString);
void ParseInput(char* inputString, CommandStruct* command); void ParseInput(char* inputString, CommandStruct* command);

View File

@ -18,7 +18,6 @@ const char* GetHomeDir(void)
return homeDir; return homeDir;
} }
// Checks for commands that are built into Pish // Checks for commands that are built into Pish
void IntegratedCheck(CommandStruct *command) void IntegratedCheck(CommandStruct *command)
{ {
@ -31,7 +30,6 @@ void IntegratedCheck(CommandStruct* command)
return; return;
} }
// Prints a prompt and then reads a command from the terminal // Prints a prompt and then reads a command from the terminal
void GetInput(char *inputString) void GetInput(char *inputString)
{ {
@ -89,15 +87,24 @@ void ReadPishrc(CommandStruct* command, char* inputString)
} }
assert(close(fd) >= 0); assert(close(fd) >= 0);
} }
// i/o redirection // i/o redirection
// TODO: Work on one symbol at a time
// inputString may not be useful here, only *command
// Try to add a layer of abstraction where possible
// I.E. think about using function instead for checking
void ioRedirection(char *inputString, CommandStruct *command) void ioRedirection(char *inputString, CommandStruct *command)
{ {
int newfd; int newfd;
// check command standard output // check command standard output
// TODO: Check command->argv[] for symbol instead
if (strchr(inputString, '>') != NULL) if (strchr(inputString, '>') != NULL)
{ {
// TODO: Throwing an error here and line 108 for using command
newfd = open((command, O_CREAT |O_TRUNC | O_WRONLY, 0644)) <0) { // Check if targeting a specific string in command->argv works
newfd = (open((command, O_CREAT |O_TRUNC | O_WRONLY, 0644)) < 0);
// No if statement for fail checking, brackets just exist here
{
// failed // failed
perror(command); perror(command);
exit(1); exit(1);
@ -108,46 +115,57 @@ if (strchr(inputString, '>' )!= NULL)
} // this is supposed to close if statement?? } // this is supposed to close if statement??
// check command standard input // check command standard input
if(strchr(inputString, '<') != NULL) // if (strchr(inputString, '<') != NULL)
{ // {
newfd = open((command, O_CREAT |O_TRUNC | O_WRONLY, 0644)) <0) { // newfd = open((command, O_CREAT |O_TRUNC | O_WRONLY, 0644)) < 0);
//failed // // No if statement for fail checking, brackets just exist here
perror(command); // {
exit(1); // // failed
} // perror(command);
dup2(newfd,0); // exit(1);
} // }
// dup2(newfd, 0);
// }
// check pipe // check pipe
if(strchr(command, '|') != NULL) // TODO: Check for pipe symbol
{ // Check in command->argv[] instead
// if (strchr(command, '|') != NULL)
} // {
// ;
// }
// check append // check append
if (strpbrk(command, ">>") != NULL) // TODO: Implement append
newfd = open((command, O_CREAT |O_TRUNC | O_WRONLY, 0644)) <0) { // if (strpbrk(command, ">>") != NULL)
//failed // {
perror(command); // newfd = open((command, O_CREAT |O_TRUNC | O_WRONLY, 0644)) < 0);
exit(1); // // No if statement for fail checking, brackets just exist here
} // {
dup2(newfd,0); // // failed
} // perror(command);
// exit(1);
// }
// dup2(newfd, 0);
// }
// check pipe // check pipe
if(strchr(command, '|') != NULL) // TODO: Check pipe already exists above, maybe loop?
{ // if (strchr(command, '|') != NULL)
// {
} // ;
// }
// check append // check append
if (strpbrk(command, ">>") != NULL) // TODO: Check append already exists above, maybe loop?
{ // if (strpbrk(command, ">>") != NULL)
// {
// ;
// }
}
}
}
// Environment varibles // Environment varibles
void varibles(char str, int count) // TODO: Add this function to CommandStruct
{ // Environment Variables can just be a part of the struct
char var[1000]; // void varibles(char str, int count)
var[count]= str; // {
// char var[1000];
} // var[count] = str;
// }