Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
shell
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
coms352
shell
Commits
a4dface0
Commit
a4dface0
authored
Mar 01, 2018
by
Matthew Burket
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
worked on cd
parent
fa2172be
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
9 deletions
+16
-9
main.c
main.c
+16
-9
No files found.
main.c
View file @
a4dface0
...
...
@@ -16,8 +16,6 @@ int main() {
int
should_run
=
1
;
char
*
readBuff
=
malloc
(
BUFFSIZE
);
char
*
HOME
=
getenv
(
"HOME"
);
char
*
HISTORY_FILE
=
HOME
;
strcat
(
HISTORY_FILE
,
"/.bsh_history"
);
// Copyright statement
fprintf
(
stdout
,
"Welcome to Burket Shell (bsh)
\n
"
);
fprintf
(
stdout
,
"Copyright 2018 Matthew Burket
\n
"
);
...
...
@@ -28,12 +26,9 @@ int main() {
fprintf
(
stdout
,
"bsh # "
);
// Getting User Input
fgets
(
readBuff
,
sizeof
(
char
)
*
5000
,
stdin
);
//
If input wr
//
History store stuff
if
(
strlen
(
readBuff
)
>
0
)
{
FILE
*
fp
=
fopen
(
HISTORY_FILE
,
"a+"
);
write
(
fp
->
_fileno
,
readBuff
,
BUFFSIZE
);
close
(
fp
->
_fileno
);
//
}
// Remove the newline from fgets
strtok
(
readBuff
,
"
\n
"
);
...
...
@@ -50,7 +45,16 @@ int main() {
fprintf
(
stderr
,
"bsh: expected one argument for cd"
);
continue
;
}
else
{
chdir
(
tokens
[
1
]);
if
(
strcmp
(
tokens
[
1
],
"~"
)
==
0
)
{
chdir
(
getenv
(
"HOME"
));
strcpy
(
tokens
[
1
],
getenv
(
"HOME"
));
}
else
if
(
strcmp
(
tokens
[
1
],
"-"
)
==
0
)
{
chdir
(
getenv
(
"OLDPWD"
));
strcpy
(
tokens
[
1
],
getenv
(
"OLDPWD"
));
}
else
{
chdir
(
tokens
[
1
]);
}
}
}
...
...
@@ -61,7 +65,10 @@ int main() {
}
if
(
fork
()
==
0
)
{
execvp
(
tokens
[
0
],
tokens
);
int
returnCode
=
execvp
(
tokens
[
0
],
tokens
);
if
(
returnCode
==
-
1
)
{
fprintf
(
stdout
,
"bsh: Command not found
\n
"
);
}
}
else
{
if
(
runInBackground
==
0
)
{
wait
(
NULL
);
...
...
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