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
6525cb92
Commit
6525cb92
authored
Nov 30, 2021
by
Lindsay Knupp
Browse files
End of lab
parent
9896b97d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Labs/Lab10/fdump.c
View file @
6525cb92
...
...
@@ -8,4 +8,9 @@
#include <stdio.h>
#include <unistd.h>
#include "hexdump.h"
int
main
(
int
argc
,
char
*
argv
[]){
}
Labs/Lab10/prelab.txt
View file @
6525cb92
...
...
@@ -2,4 +2,9 @@ Lindsay Knupp
11/30/21
Lab 10 - prelab.txt
1 1 0 1 0 0 0 0 0
push first three bits to the right hand side, shift by 6 bits
so that it's the only thing in that number
1 1 0 & 1 0 0 or 0 1 0 or 0 0 1 to say which permission user has
Labs/Lab9/Makefile
View file @
6525cb92
CC
=
gcc
-lreadline
CFLAGS
=
-std
=
gnu99
-Wall
-g
#-DDEBUG
EXECS
=
ishell
EXECS
=
ishell
maybeishell
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 @
6525cb92
...
...
@@ -34,60 +34,53 @@ int main (int argc, char *argv[]){
printf
(
"ishell> "
);
//parse user input and split into tokens
line
=
NULL
;
//get user input from terminal
getline
(
&
line
,
&
length
,
stdin
);
length
=
strlen
(
line
);
line
[
length
-
1
]
=
0
;
line
[
length
-
1
]
=
0
;
for
(
int
i
=
0
;
i
<
MAXCNT
;
i
++
){
tokens
[
i
]
=
(
char
*
)
malloc
(
MAXLEN
);
tokens1
[
i
]
=
(
char
*
)
malloc
(
MAXLEN
);
tokens2
[
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
;
}
strcpy
(
tokens
[
token_count
]
,
token
)
;
tokens
[
token_count
]
=
token
;
token_count
++
;
}
tokens
[
token_count
]
=
NULL
;
int
command2
=
0
;
for
(
int
i
=
0
;
i
<
MAXCNT
;
i
++
){
if
(
strcmp
(
tokens
[
i
],
";"
)
==
0
){
command2
=
i
;
break
;
}
//int command2 = 0;
//for (int i = 0; i<MAXCNT; i++){
// if(strcmp(tokens[i],";") == 0){
// command2 = i;
// break;
// }
//}
}
//printf("command index %d\n",command2);
if
(
command2
!=
0
){
for
(
int
i
=
0
;
i
<
command2
;
i
++
){
strcpy
(
tokens1
[
i
],
tokens
[
i
]);
}
tokens1
[
command2
]
=
NULL
;
//
if (command2 != 0){
//
for (int i = 0; i < command2;i++){
//
strcpy(tokens1[i],tokens[i]);
//
}
//
tokens1[command2] = NULL;
for
(
int
i
=
command2
;
i
<
token_count
;
i
++
){
strcpy
(
tokens2
[
i
],
tokens
[
i
]);
}
tokens2
[
token_count
]
=
NULL
;
//
for (int i = command2;i<token_count;i++){
//
strcpy(tokens2[i],tokens[i]);
//
}
//
tokens2[token_count] = NULL;
strcpy
(
path2
,
"/usr/bin/"
);
strcpy
(
path
,
"/usr/bin/"
);
strcat
(
path
,
tokens1
[
0
]);
strcat
(
path
,
tokens2
[
0
]);
//strcpy(path2, "/usr/bin/");
//strcpy(path, "/usr/bin/");
}
tokens
[
token_count
]
=
NULL
;
//strcat(path, tokens1[0]);
//strcat(path, tokens2[0]);
//}
strcpy
(
path
,
"/usr/bin/"
);
strcat
(
path
,
tokens
[
0
]);
free
(
line
);
...
...
@@ -99,17 +92,13 @@ int main (int argc, char *argv[]){
// child branch
if
(
pid
==
0
){
if
(
command2
!=
0
){
execv
(
path
,
tokens1
);
execv
(
path2
,
tokens2
);
}
execv
(
path
,
tokens
);
}
// parent branch
else
{
wait
(
&
status
);
fflush
(
stdout
);
wait
(
&
status
);
int
es
=
WEXITSTATUS
(
status
);
if
(
es
==
0
){
printf
(
"[ishell: program terminated successfully]
\n
"
);
...
...
@@ -117,10 +106,6 @@ 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
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