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
825ac899
Commit
825ac899
authored
Mar 02, 2018
by
Matthew Burket
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve code and comments
parent
bc475ad0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
4 deletions
+17
-4
main.c
main.c
+17
-4
No files found.
main.c
View file @
825ac899
...
...
@@ -146,32 +146,43 @@ int main() {
if
(
returnCode
==
-
1
)
{
fprintf
(
stdout
,
"bsh: Command not found
\n
"
);
}
// Clean up and we are done;
printf
(
"
\n
"
);
exit
(
1
);
}
else
{
// Wait where if no & and not a pipe
if
(
runInBackground
==
0
&&
doMoreCheck
==
0
)
{
wait
(
NULL
);
}
// Reset the background thing
runInBackground
=
0
;
}
// Do if more fork, otherwise short cricut and move on with life
if
(
doMoreCheck
!=
0
&&
fork
()
==
0
)
{
// Close Stdin
close
(
STDIN_FILENO
);
// Make stdin the pipe
dup
(
thePipe
[
0
]);
// Close the pipes
close
(
thePipe
[
1
]);
close
(
thePipe
[
0
]);
char
*
moreCmd
[]
=
{
"more"
,
0
};
// During recitation the TA stated only supporting more is okay
// The NULL is important, Pro tip.
char
*
moreCmd
[]
=
{
"more"
,
NULL
};
execvp
(
moreCmd
[
0
],
moreCmd
);
// We done, exit
exit
(
1
);
}
else
if
(
doMoreCheck
!=
0
)
{
// Close pipes
close
(
thePipe
[
0
]);
close
(
thePipe
[
1
]);
wait
(
0
);
wait
(
0
);
// Wait on the children to finish playing
wait
(
NULL
);
wait
(
NULL
);
}
// Free the tokens
free
(
tokens
);
}
}
...
...
@@ -183,6 +194,8 @@ void storeHist(char **readBuff, int *historyPos, char historyBuff[50][5000], int
for
(
int
i
=
0
;
i
<
numTokens
-
1
;
i
++
)
{
strcat
(
historyBuff
[
*
historyPos
],
readBuff
[
i
]);
int
nextIter
=
i
+
1
;
// No space the end
//
if
(
nextIter
<
numTokens
-
1
)
{
strcat
(
historyBuff
[
*
historyPos
],
" "
);
}
...
...
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