Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposed unified code formatting #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions command.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include <unistd.h>
#include "command.h"
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/wait.h>
#include "command.h"
#include <unistd.h>
#include "const.h"
#include "source.h"
#include "variable.h"

void executeCommand(char* input)
{
void executeCommand(char* input) {
char* args[MAX_ARGS + 1] = {NULL};
input[strlen(input) - 1] = '\0'; // terminate with null, rather than with \n

char* args[MAX_ARGS + 1] = { NULL };
input[strlen(input) - 1] = '\0'; //terminate with null, rather than with \n
Expand All @@ -23,26 +24,23 @@ void executeCommand(char* input)
if(args[0] == NULL) return;

// if command includes "=" set variable with the value after "=" as sting
if (strchr(args[0], '=') != NULL)
{
//printf("variable set, %s\n", args[0]);
addVariable(args[0]);
}
else if (strcmp(args[0], "exit") == 0) // exit shell
if (strchr(args[0], '=') != NULL) {
// printf("variable set, %s\n", args[0]);
addVariable(args[0]);
} else if (strcmp(args[0], "exit") == 0) // exit shell
{
exit(0);
}
else if (strcmp(args[0], "env") == 0) // display all variables
exit(0);
} else if (strcmp(args[0], "env") == 0) // display all variables
{
displayVariable();
}
else if (strcmp(args[0], "source") == 0) // source command
{
printf("source command\n");
sourceCommand(args);
}
else
displayVariable();
} else if (strcmp(args[0], "source") == 0) // source command
{
printf("source command\n");
sourceCommand(args);
} else {
if (fork() == 0) // if inside the child process
{
int comm_res = execvp(args[0], args);

if (fork() == 0) // if inside the child process
{
Expand Down