Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSEP551
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Krishna Vinnakota
CSEP551
Commits
44e6909a
Commit
44e6909a
authored
18 years ago
by
kaashoek
Browse files
Options
Downloads
Patches
Plain Diff
more simplifying
parent
e00baa9f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sh.c
+12
-15
12 additions, 15 deletions
sh.c
with
12 additions
and
15 deletions
sh.c
+
12
−
15
View file @
44e6909a
...
...
@@ -6,7 +6,7 @@
#define BUFSIZ 512
#define MAXARGS 10
#define MAX
NODE
2
#define MAX
IO
2
#define MAXCMD 2
// an embarrassingly naive shell
...
...
@@ -22,7 +22,7 @@ struct cmd {
char
argv0buf
[
BUFSIZ
];
int
argc
;
int
token
;
struct
ionode
iolist
[
MAX
NODE
];
struct
ionode
iolist
[
MAX
IO
];
struct
ionode
*
io
;
};
struct
cmd
cmdlist
[
MAXCMD
];
...
...
@@ -75,30 +75,28 @@ parse(char *s)
cmd
->
argv
[
cmd
->
argc
++
]
=
t
;
break
;
case
'<'
:
// Input redirection
case
'>'
:
// Input and output redirection
case
'<'
:
// Grab the filename from the argument list
if
(
gettoken
(
0
,
&
t
)
!=
'w'
)
{
printf
(
2
,
"syntax error:
<
not followed by word
\n
"
);
printf
(
2
,
"syntax error:
>
not followed by word
\n
"
);
return
-
1
;
}
cmd
->
io
->
token
=
'<'
;
cmd
->
io
->
s
=
t
;
cmd
->
io
++
;
break
;
case
'>'
:
// Output redirection
// Grab the filename from the argument list
if
(
gettoken
(
0
,
&
t
)
!=
'w'
)
{
printf
(
2
,
"syntax error: > not followed by word
\n
"
);
if
(
cmd
->
io
-
cmd
->
iolist
>=
MAXIO
)
{
printf
(
2
,
"too many redirections
\n
"
);
return
-
1
;
}
cmd
->
io
->
token
=
'>'
;
cmd
->
io
->
token
=
c
;
cmd
->
io
->
s
=
t
;
cmd
->
io
++
;
break
;
case
';'
:
// command sequence
case
'|'
:
// pipe
if
(
cmd
->
io
-
cmd
->
iolist
>=
MAXIO
)
{
printf
(
2
,
"too many redirections
\n
"
);
return
-
1
;
}
cmd
->
token
=
c
;
cmd
++
;
break
;
...
...
@@ -114,7 +112,6 @@ parse(char *s)
}
}
void
runcmd
(
void
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment