Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lindsay Knupp
csci315
Commits
fe06e2d0
Commit
fe06e2d0
authored
Nov 30, 2021
by
Lindsay Knupp
Browse files
Lab 9.1 and 9.2 completed
parent
6525cb92
Changes
2
Hide whitespace changes
Inline
Side-by-side
Labs/Lab9/Makefile
View file @
fe06e2d0
CC
=
gcc
-lreadline
CFLAGS
=
-std
=
gnu99
-Wall
-g
#-DDEBUG
EXECS
=
ishell
maybeishell
EXECS
=
ishell
all
:
$(EXECS)
ishell
:
ishell.c
$(CC)
$(CFLAGS)
-o
$@
$<
maybeishell
:
maybeishell.c
$(CC)
$(CFLAGS)
-o
$@
$<
.PHONY
:
clean
clean
:
/bin/rm
-f
*
.o
$(EXECS)
Labs/Lab9/ishell.c
View file @
fe06e2d0
...
...
@@ -20,13 +20,13 @@ int main (int argc, char *argv[]){
int
status
;
char
path
[
1024
];
char
path2
[
1024
];
//
char path2[1024];
char
*
saveptr
;
char
*
str
;
char
*
token
;
char
*
tokens
[
MAXCNT
];
char
*
tokens1
[
MAXCNT
];
char
*
tokens2
[
MAXCNT
];
//
char* tokens1[MAXCNT];
//
char* tokens2[MAXCNT];
char
*
line
=
NULL
;
size_t
length
;
...
...
@@ -41,13 +41,18 @@ int main (int argc, char *argv[]){
length
=
strlen
(
line
);
line
[
length
-
1
]
=
0
;
for
(
int
i
=
0
;
i
<
MAXCNT
;
i
++
){
tokens
[
i
]
=
(
char
*
)
malloc
(
MAXLEN
);
}
int
token_count
=
0
;
for
(
str
=
line
;
;
str
=
NULL
){
token
=
strtok_r
(
str
,
" "
,
&
saveptr
);
if
(
token_count
>=
MAXCNT
||
token
==
NULL
){
break
;
}
tokens
[
token_count
]
=
token
;
}
strcpy
(
tokens
[
token_count
],
token
);
//tokens[token_count] = token;
token_count
++
;
}
tokens
[
token_count
]
=
NULL
;
...
...
@@ -79,9 +84,30 @@ int main (int argc, char *argv[]){
//strcat(path, tokens1[0]);
//strcat(path, tokens2[0]);
//}
strcpy
(
path
,
"/usr/bin/"
);
// for (int i = 0; i< token_count;i++){
// strcat(path,tokens[i]);
// if (i != (token_count-1)){
// strcat(path," ");
// }
// printf("token: %s\n",tokens[i]);
// }
strcat
(
path
,
tokens
[
0
]);
//printf("path %s\n",path);
for
(
int
i
=
0
;
i
<
token_count
;
i
++
){
//printf("token: %s\n",tokens[i]);
}
free
(
line
);
...
...
@@ -93,7 +119,6 @@ int main (int argc, char *argv[]){
// child branch
if
(
pid
==
0
){
execv
(
path
,
tokens
);
}
// parent branch
...
...
@@ -106,6 +131,10 @@ int main (int argc, char *argv[]){
else
{
printf
(
"[ishell: program terminated abnormally][%d]
\n
"
,
es
);
}
for
(
int
i
=
0
;
i
<
token_count
;
i
++
){
free
(
tokens
[
i
]);
}
}
}
return
0
;
...
...
Write
Preview
Supports
Markdown
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