Skip to content

Commit c15eafc

Browse files
committed
Pipeless and works
1 parent 0785ad4 commit c15eafc

File tree

12 files changed

+2178375
-15
lines changed

12 files changed

+2178375
-15
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ In order to exit the shell, type `exit`
5050
- [x] I/O Redirection
5151
- [x] Command Redirection, pipes
5252
- [x] I/O+pipes
53-
- [ ] setenv, getenv
53+
- [x] setenv, getenv
5454
- [ ] jobs, kjo, overkill
5555
- [ ] fg, bg, ^Z
5656
- [ ] quit, ^C

global.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
typedef struct {
2+
char name[2048];
3+
int id;
4+
int fore;
5+
} process;
6+
7+
int backCount = 0;
8+
process currentProcess;
9+
char bgProcess[2048];

include/builtins.h

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ int shexit();
44
int shecho(char **argv, int argc);
55
int remind(char **argv, int argc);
66
int shsetenv(char **argv, int argc);
7+
int shunsetenv(char **argv, int argc);

include/global.h

Whitespace-only changes.

include/util.h

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ char **splitlines(char *line, int *num);
33
void sig_child(int signum);
44
void sig_stop(int signum);
55
void sig_int(int signum);
6+
void sig_tstp(int signum);

makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ IDIR = include
33
CC=gcc
44
CFLAGS=-I$(IDIR) -Wall
55

6-
FILES = smain.c disp.c util.c operation.c builtins.c ls.c pinfo.c redirection.c pipe.c
6+
FILES = smain.c disp.c util.c operation.c builtins.c ls.c pinfo.c redirection.c pipe.c global.c
77

88
install:
99
$(CC) $(CFLAGS) $(FILES) -o shell

operation.c

+31-12
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,28 @@ int run(char **argv, int argc) {
3232
else if (strcmp(argv[0], "setenv") == 0) {
3333
return shsetenv(argv, argc);
3434
}
35+
else if (strcmp(argv[0], "unsetenv") == 0) {
36+
return shunsetenv(argv, argc);
37+
}
38+
39+
40+
prex(argv);
41+
return 1;
3542

3643
// Flow: check for all pipes, split commands and parent/child processes
3744
// accordingly. Then for each of these, process with redirection etc as
3845
// per normal
3946

4047

48+
49+
// Stores all comss
4150
char *args[128][128];
4251

4352
int m = 0, n = 0;
4453
for (int i = 0; i < argc; i++) {
4554
if (strcmp(argv[i],"|") != 0) {
4655
args[m][n++] = argv[i];
56+
strcat(args[m][n], "\0");
4757
}
4858
else {
4959
args[m][n] = NULL;
@@ -54,6 +64,15 @@ int run(char **argv, int argc) {
5464
args[++m][0] = NULL;
5565

5666

67+
printf("THIS IS A TEST\n");
68+
for(int i = 0; *args[i] != NULL; i++) {
69+
for(int j = 0; args[i][j] != NULL; i++) {
70+
printf("%s", args[i][j]);
71+
}
72+
printf("\n");
73+
}
74+
75+
5776
int fdes[2] = {0, 0}, ret;
5877
pid_t pid;
5978
int fd_in = 0;
@@ -109,18 +128,18 @@ int prex(char **argv) {
109128
while(argv[argc] != NULL)
110129
argc++;
111130

112-
printf("Printing command that's gonna be executed\n");
113-
for(int i = 0; i < argc; i++) {
114-
printf("%s ", argv[i]);
115-
}
116-
printf("\n\n");
117-
118-
for(int i = 0; i < argc; i++) {
119-
for(int j = 0; j < strlen(argv[i]); j++)
120-
printf("%d ", (int)argv[i][j]);
121-
printf("\t");
122-
}
123-
printf("\n\n");
131+
// printf("Printing command that's gonna be executed\n");
132+
// for(int i = 0; i < argc; i++) {
133+
// printf("%s ", argv[i]);
134+
// }
135+
// printf("\n\n");
136+
//
137+
// for(int i = 0; i < argc; i++) {
138+
// for(int j = 0; j < strlen(argv[i]); j++)
139+
// printf("%d ", (int)argv[i][j]);
140+
// printf("\t");
141+
// }
142+
// printf("\n\n");
124143

125144
for(int i = 0; i < argc; i++) {
126145
if (argv[i][0] == '<' || argv[i][0] == '>') {

shell

72 Bytes
Binary file not shown.

smain.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ int loop() {
4747

4848
signal(SIGINT, sig_int);
4949
signal(SIGSTOP, sig_stop);
50+
signal(SIGTSTP, sig_tstp);
5051
// Print any process IDs
51-
signal(SIGCHLD, sig_child);
5252
do {
5353

5454
// FLOW: Display prompt and get input

test/test10

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Inside process: thing running is
2+
cat test1
3+
4+
nothing
5+
nothing
6+
nothing
7+
oona

0 commit comments

Comments
 (0)