Skip to content

Commit

Permalink
some fix
Browse files Browse the repository at this point in the history
  • Loading branch information
arwin-swapna committed Feb 6, 2024
1 parent 731e9a4 commit 9fb046a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 10 deletions.
29 changes: 29 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch with input redirection",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/rush",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
18 changes: 15 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
rush: rush.c
$ gcc -o rush rush.c
CC = gcc
CFLAGS = -Wall -Wextra -g

# List your source files here
SOURCES = rush.c

# Name for your executable
EXECUTABLE = rush

all: $(EXECUTABLE)

$(EXECUTABLE): $(SOURCES)
$(CC) $(CFLAGS) $(SOURCES) -o $(EXECUTABLE)

.PHONY: clean
clean:
rm -f rush
rm -f $(EXECUTABLE)
Binary file modified rush
Binary file not shown.
13 changes: 10 additions & 3 deletions rush.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,20 @@ void rushExecute(char **args, char **path)
{
pid_t pid;
int status;

pid = fork();
if(pid == 0)
{
int redir_count = 0;
int redir_index = -1;
for (int i = 0; args[i] != NULL; i++) {
if (strcmp(args[i], ">") == 0) {
redir_count++;
redir_index = i;
break;
if (redir_count > 1) {
printErrorMessage();
exit(EXIT_FAILURE);
}
}
}

Expand Down Expand Up @@ -142,6 +147,7 @@ int main(int argc, char *argv[])
printErrorMessage();
return EXIT_FAILURE;
}

char *input;
char **args;
char *initialPath[2];
Expand Down Expand Up @@ -173,8 +179,9 @@ int main(int argc, char *argv[])
path = generatePath(args);
}else {
if(path[0] == NULL)
{
continue;
}
rushExecute(args, path);
}

Expand Down
4 changes: 0 additions & 4 deletions test.txt

This file was deleted.

0 comments on commit 9fb046a

Please sign in to comment.