Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lindsay Knupp
csci315
Commits
3abe8bb0
Commit
3abe8bb0
authored
Dec 01, 2021
by
Lindsay Knupp
Browse files
Lab 9.4 completed
parent
1dd6e827
Changes
1
Hide whitespace changes
Inline
Side-by-side
Labs/Lab9/ishell.c
View file @
3abe8bb0
...
...
@@ -12,8 +12,6 @@
#include <sys/wait.h>
#include <signal.h>
#include "ishell.h"
#define MAXCNT 10
#define MAXLEN 20
...
...
@@ -34,10 +32,15 @@ int main (int argc, char *argv[]){
char
*
tokens2
[
MAXCNT
];
char
*
line
=
NULL
;
size_t
length
;
int
entertwice
;
char
*
enter
=
NULL
;
size_t
enter_length
;
// Ask user for input
while
(
1
){
entertwice
=
-
1
;
printf
(
"ishell> "
);
strcpy
(
path
,
"/usr/bin/"
);
...
...
@@ -47,10 +50,17 @@ int main (int argc, char *argv[]){
//get user input from terminal
getline
(
&
line
,
&
length
,
stdin
);
length
=
strlen
(
line
);
line
[
length
-
1
]
=
0
;
char
*
arr
[]
=
{
"ls"
,
NULL
};
if
(
line
[
0
]
==
'\n'
){
getline
(
&
enter
,
&
enter_length
,
stdin
);
//char* arr[] = {"ls",NULL};
entertwice
=
0
;
}
else
{
length
=
strlen
(
line
);
line
[
length
-
1
]
=
0
;
}
// initialize arrays for clean strings
for
(
int
i
=
0
;
i
<
MAXCNT
;
i
++
){
semitokens
[
i
]
=
(
char
*
)
malloc
(
MAXLEN
);
...
...
@@ -59,7 +69,6 @@ int main (int argc, char *argv[]){
tokens
[
i
]
=
(
char
*
)
malloc
(
MAXLEN
);
}
// split command(s) by semicolon
int
semi_token_count
=
0
;
for
(
str
=
line
;
;
str
=
NULL
){
...
...
@@ -120,7 +129,13 @@ int main (int argc, char *argv[]){
// child branch
if
(
pid
==
0
){
execv
(
path
,
tokens
);
// enter was hit twice
if
(
entertwice
==
0
){
execv
(
"/usr/bin/ls"
,
arr
);
}
else
{
execv
(
path
,
tokens
);
}
}
// parent branch
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment