Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
1b25f3b0
提交
1b25f3b0
8月 28, 2007
创建
作者:
rsc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
New shell.
上级
f0d11fea
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
398 行增加
和
263 行删除
+398
-263
sh.c
sh.c
+398
-263
没有找到文件。
sh.c
浏览文件 @
1b25f3b0
// Shell.
#include "types.h"
#include "types.h"
#include "stat.h"
#include "user.h"
#include "user.h"
#include "fcntl.h"
#include "fcntl.h"
#define BUFSIZ 512
// Parsed command representation
#define MAXARGS 10
#define EXEC 1
#define MAXIO 2
#define REDIR 2
#define MAXCMD 2
#define PIPE 3
#define LIST 4
#define BACK 5
// an embarrassingly naive shell
#define MAXARGS 10
// some day a real parse tree; for now ad-hoc
struct
cmd
{
struct
ionode
{
int
type
;
int
token
;
char
*
s
;
};
};
struct
cmd
{
struct
execcmd
{
int
type
;
char
*
argv
[
MAXARGS
];
char
*
argv
[
MAXARGS
];
char
argv0buf
[
BUFSIZ
];
char
*
eargv
[
MAXARGS
];
int
argc
;
};
int
token
;
struct
ionode
iolist
[
MAXIO
];
struct
redircmd
{
struct
ionode
*
io
;
int
type
;
struct
cmd
*
cmd
;
char
*
file
;
char
*
efile
;
int
mode
;
int
fd
;
};
struct
pipecmd
{
int
type
;
struct
cmd
*
left
;
struct
cmd
*
right
;
};
};
struct
cmd
cmdlist
[
MAXCMD
];
struct
cmd
*
cmd
;
char
buf
[
BUFSIZ
];
struct
listcmd
{
int
debug
;
int
type
;
struct
cmd
*
left
;
struct
cmd
*
right
;
};
int
parse
(
char
*
s
);
struct
backcmd
{
void
runcmd
(
void
);
int
type
;
int
getcmd
(
char
*
buf
,
int
nbuf
);
struct
cmd
*
cmd
;
int
ioredirection
(
struct
ionode
*
iolist
,
int
nio
);
};
int
gettoken
(
char
*
s
,
char
**
token
);
int
_gettoken
(
char
*
s
,
char
**
p1
,
char
**
p2
);
struct
cmd
*
parsecmd
(
char
*
);
void
panic
(
char
*
);
int
int
main
(
void
)
fork1
(
void
)
{
{
while
(
getcmd
(
buf
,
sizeof
(
buf
))
>=
0
)
{
int
pid
;
if
(
parse
(
buf
)
>=
0
)
runcmd
();
pid
=
fork
();
if
(
pid
==
-
1
)
panic
(
"fork"
);
return
pid
;
}
// Execute cmd. Never returns.
void
runcmd
(
struct
cmd
*
cmd
)
{
int
p
[
2
];
struct
backcmd
*
bcmd
;
struct
execcmd
*
ecmd
;
struct
listcmd
*
lcmd
;
struct
pipecmd
*
pcmd
;
struct
redircmd
*
rcmd
;
if
(
cmd
==
0
)
return
;
switch
(
cmd
->
type
){
default:
panic
(
"runcmd"
);
case
EXEC
:
ecmd
=
(
struct
execcmd
*
)
cmd
;
if
(
ecmd
->
argv
[
0
]
==
0
)
exit
();
exec
(
ecmd
->
argv
[
0
],
ecmd
->
argv
);
printf
(
2
,
"exec %s failed
\n
"
,
ecmd
->
argv
[
0
]);
break
;
case
REDIR
:
rcmd
=
(
struct
redircmd
*
)
cmd
;
close
(
rcmd
->
fd
);
if
(
open
(
rcmd
->
file
,
rcmd
->
mode
)
<
0
){
printf
(
2
,
"open %s failed
\n
"
,
rcmd
->
file
);
exit
();
}
runcmd
(
rcmd
->
cmd
);
break
;
case
PIPE
:
pcmd
=
(
struct
pipecmd
*
)
cmd
;
if
(
pipe
(
p
)
<
0
)
panic
(
"pipe"
);
if
(
fork1
()
==
0
){
close
(
1
);
dup
(
p
[
1
]);
close
(
p
[
0
]);
close
(
p
[
1
]);
runcmd
(
pcmd
->
left
);
}
if
(
fork1
()
==
0
){
close
(
0
);
dup
(
p
[
0
]);
close
(
p
[
0
]);
close
(
p
[
1
]);
runcmd
(
pcmd
->
right
);
}
close
(
p
[
0
]);
close
(
p
[
1
]);
wait
();
wait
();
break
;
case
LIST
:
lcmd
=
(
struct
listcmd
*
)
cmd
;
if
(
fork1
()
==
0
)
runcmd
(
lcmd
->
left
);
wait
();
runcmd
(
lcmd
->
right
);
break
;
case
BACK
:
bcmd
=
(
struct
backcmd
*
)
cmd
;
if
(
fork1
()
==
0
)
runcmd
(
bcmd
->
cmd
);
break
;
}
}
exit
();
exit
();
}
}
...
@@ -59,282 +152,324 @@ getcmd(char *buf, int nbuf)
...
@@ -59,282 +152,324 @@ getcmd(char *buf, int nbuf)
}
}
int
int
parse
(
char
*
s
)
main
(
void
)
{
{
char
*
t
;
static
char
buf
[
100
];
int
c
,
i
;
gettoken
(
s
,
0
);
cmd
=
&
cmdlist
[
0
];
while
(
getcmd
(
buf
,
sizeof
(
buf
))
>=
0
)
{
for
(
i
=
0
;
i
<
MAXCMD
;
i
++
)
{
if
(
fork1
()
==
0
)
cmdlist
[
i
].
argc
=
0
;
runcmd
(
parsecmd
(
buf
));
cmdlist
[
i
].
token
=
0
;
wait
();
cmdlist
[
i
].
io
=
cmdlist
[
i
].
iolist
;
}
}
for
(;;){
exit
();
switch
((
c
=
gettoken
(
0
,
&
t
)))
{
}
case
'w'
:
// Add an argument
void
if
(
cmd
->
argc
>=
MAXARGS
)
{
panic
(
char
*
s
)
printf
(
2
,
"too many arguments
\n
"
);
{
return
-
1
;
printf
(
2
,
"%s
\n
"
,
s
);
}
exit
();
cmd
->
argv
[
cmd
->
argc
++
]
=
t
;
}
break
;
case
'>'
:
// Input and output redirection
// Constructors
case
'<'
:
// Grab the filename from the argument list
if
(
gettoken
(
0
,
&
t
)
!=
'w'
)
{
printf
(
2
,
"syntax error: > not followed by word
\n
"
);
return
-
1
;
}
if
(
cmd
->
io
-
cmd
->
iolist
>=
MAXIO
)
{
printf
(
2
,
"too many redirections
\n
"
);
return
-
1
;
}
cmd
->
io
->
token
=
c
;
cmd
->
io
->
s
=
t
;
cmd
->
io
++
;
break
;
case
';'
:
// command sequence
struct
cmd
*
case
'|'
:
// pipe
execcmd
(
void
)
if
(
cmd
->
io
-
cmd
->
iolist
>=
MAXIO
)
{
{
printf
(
2
,
"too many redirections
\n
"
);
struct
execcmd
*
cmd
;
return
-
1
;
}
cmd
->
token
=
c
;
cmd
++
;
break
;
case
0
:
// String is complete
cmd
=
malloc
(
sizeof
(
*
cmd
));
return
0
;
memset
(
cmd
,
0
,
sizeof
(
*
cmd
));
cmd
->
type
=
EXEC
;
return
(
struct
cmd
*
)
cmd
;
}
default:
struct
cmd
*
printf
(
2
,
"syntax error: bad return %d from gettoken"
,
c
);
redircmd
(
struct
cmd
*
subcmd
,
char
*
file
,
char
*
efile
,
int
mode
,
int
fd
)
return
-
1
;
{
struct
redircmd
*
cmd
;
cmd
=
malloc
(
sizeof
(
*
cmd
));
memset
(
cmd
,
0
,
sizeof
(
*
cmd
));
cmd
->
type
=
REDIR
;
cmd
->
cmd
=
subcmd
;
cmd
->
file
=
file
;
cmd
->
efile
=
efile
;
cmd
->
mode
=
mode
;
cmd
->
fd
=
fd
;
return
(
struct
cmd
*
)
cmd
;
}
}
struct
cmd
*
}
pipecmd
(
struct
cmd
*
left
,
struct
cmd
*
right
)
{
struct
pipecmd
*
cmd
;
cmd
=
malloc
(
sizeof
(
*
cmd
));
memset
(
cmd
,
0
,
sizeof
(
*
cmd
));
cmd
->
type
=
PIPE
;
cmd
->
left
=
left
;
cmd
->
right
=
right
;
return
(
struct
cmd
*
)
cmd
;
}
}
void
struct
cmd
*
runcmd
(
void
)
listcmd
(
struct
cmd
*
left
,
struct
cmd
*
right
)
{
{
int
i
,
r
,
pid
,
tfd
;
struct
listcmd
*
cmd
;
int
fdarray
[
2
];
struct
cmd
*
c
;
cmd
=
malloc
(
sizeof
(
*
cmd
));
struct
ionode
*
io
;
memset
(
cmd
,
0
,
sizeof
(
*
cmd
));
cmd
->
type
=
LIST
;
// Return immediately if command line was empty.
cmd
->
left
=
left
;
if
(
cmdlist
[
0
].
argc
==
0
)
{
cmd
->
right
=
right
;
if
(
debug
)
return
(
struct
cmd
*
)
cmd
;
printf
(
2
,
"EMPTY COMMAND
\n
"
);
}
return
;
}
for
(
c
=
&
cmdlist
[
0
];
c
<=
cmd
;
c
++
)
{
struct
cmd
*
// Clean up command line.
backcmd
(
struct
cmd
*
subcmd
)
// Read all commands from the filesystem: add an initial '/' to
{
// the command name.
struct
backcmd
*
cmd
;
// This essentially acts like 'PATH=/'.
if
(
c
->
argv
[
0
][
0
]
!=
'/'
)
{
c
->
argv0buf
[
0
]
=
'/'
;
strcpy
(
c
->
argv0buf
+
1
,
c
->
argv
[
0
]);
c
->
argv
[
0
]
=
c
->
argv0buf
;
}
c
->
argv
[
c
->
argc
]
=
0
;
// Print the command.
if
(
debug
)
{
printf
(
2
,
"[%d] SPAWN:"
,
getpid
());
for
(
i
=
0
;
c
->
argv
[
i
];
i
++
)
printf
(
2
,
" %s"
,
c
->
argv
[
i
]);
for
(
io
=
c
->
iolist
;
io
<=
c
->
io
;
io
++
)
{
printf
(
2
,
"%c %s"
,
io
->
token
,
io
->
s
);
}
printf
(
2
,
"
\n
"
);
}
if
(
strcmp
(
c
->
argv
[
0
],
"/cd"
)
==
0
)
{
cmd
=
malloc
(
sizeof
(
*
cmd
));
if
(
debug
)
memset
(
cmd
,
0
,
sizeof
(
*
cmd
));
printf
(
2
,
"/cd %s is build in
\n
"
,
c
->
argv
[
1
])
;
cmd
->
type
=
BACK
;
chdir
(
c
->
argv
[
1
])
;
cmd
->
cmd
=
subcmd
;
return
;
return
(
struct
cmd
*
)
cmd
;
}
}
if
(
c
->
token
==
'|'
)
// Parsing
if
(
pipe
(
fdarray
)
<
0
)
printf
(
2
,
"cmd %d pipe failed
\n
"
,
c
);
pid
=
fork
();
char
whitespace
[]
=
"
\t\r\n\v
"
;
if
(
pid
==
0
)
{
char
symbols
[]
=
"<|>&;()"
;
if
(
c
->
token
==
'|'
)
{
if
(
close
(
1
)
<
0
)
int
printf
(
2
,
"close 1 failed
\n
"
);
peek
(
char
**
ps
,
char
*
es
,
char
*
toks
)
if
((
tfd
=
dup
(
fdarray
[
1
]))
<
0
)
{
printf
(
2
,
"dup failed
\n
"
);
char
*
s
;
if
(
close
(
fdarray
[
0
])
<
0
)
printf
(
2
,
"close fdarray[0] failed
\n
"
);
s
=
*
ps
;
if
(
close
(
fdarray
[
1
])
<
0
)
while
(
s
<
es
&&
strchr
(
whitespace
,
*
s
))
printf
(
2
,
"close fdarray[1] failed
\n
"
);
s
++
;
}
*
ps
=
s
;
if
(
c
>
cmdlist
&&
(
c
-
1
)
->
token
==
'|'
)
{
return
*
s
&&
strchr
(
toks
,
*
s
);
if
(
close
(
0
)
<
0
)
printf
(
2
,
"close 0 failed
\n
"
);
if
((
tfd
=
dup
(
fdarray
[
0
]))
<
0
)
printf
(
2
,
"dup failed
\n
"
);
if
(
close
(
fdarray
[
0
])
<
0
)
printf
(
2
,
"close fdarray[0] failed
\n
"
);
if
(
close
(
fdarray
[
1
])
<
0
)
printf
(
2
,
"close fdarray[1] failed
\n
"
);
}
if
(
ioredirection
(
c
->
iolist
,
c
->
io
-
c
->
iolist
)
<
0
)
exit
();
if
((
r
=
exec
(
c
->
argv0buf
,
(
char
**
)
c
->
argv
))
<
0
)
{
printf
(
2
,
"exec %s: %d
\n
"
,
c
->
argv
[
0
],
r
);
exit
();
}
}
else
if
(
pid
>
0
)
{
int
p
;
if
(
debug
)
printf
(
2
,
"[%d] FORKED child %d
\n
"
,
getpid
(),
pid
);
if
(
c
>
cmdlist
&&
(
c
-
1
)
->
token
==
'|'
)
{
close
(
fdarray
[
0
]);
close
(
fdarray
[
1
]);
}
if
(
c
->
token
!=
'|'
)
{
if
(
debug
)
printf
(
2
,
"[%d] WAIT for children
\n
"
,
getpid
());
do
{
p
=
wait
();
if
(
debug
)
printf
(
2
,
"[%d] WAIT child %d finished
\n
"
,
getpid
(),
p
);
}
while
(
p
>
0
);
if
(
debug
)
printf
(
2
,
"[%d] wait finished
\n
"
,
getpid
());
}
}
}
}
}
int
int
ioredirection
(
struct
ionode
*
iolist
,
int
nio
)
gettoken
(
char
**
ps
,
char
*
es
,
char
**
q
,
char
**
eq
)
{
{
int
fd
;
char
*
s
;
struct
ionode
*
io
;
int
ret
;
for
(
io
=
iolist
;
io
<
&
iolist
[
nio
];
io
++
)
{
s
=
*
ps
;
switch
(
io
->
token
)
{
while
(
s
<
es
&&
strchr
(
whitespace
,
*
s
))
s
++
;
if
(
q
)
*
q
=
s
;
ret
=
*
s
;
switch
(
*
s
){
case
0
:
break
;
case
'|'
:
case
'('
:
case
')'
:
case
';'
:
case
'&'
:
case
'<'
:
case
'<'
:
if
(
close
(
0
)
<
0
)
s
++
;
printf
(
2
,
"close 0 failed
\n
"
);
if
((
fd
=
open
(
io
->
s
,
O_RDONLY
))
<
0
)
{
printf
(
2
,
"failed to open %s for read: %d"
,
io
->
s
,
fd
);
return
-
1
;
}
if
(
debug
)
printf
(
2
,
"redirect 0 from %s
\n
"
,
io
->
s
);
break
;
break
;
case
'>'
:
case
'>'
:
if
(
close
(
1
)
<
0
)
s
++
;
printf
(
2
,
"close 1 failed
\n
"
);
if
(
*
s
==
'>'
){
if
((
fd
=
open
(
io
->
s
,
O_WRONLY
|
O_CREATE
))
<
0
)
{
ret
=
'+'
;
printf
(
2
,
"failed to open %s for write: %d"
,
io
->
s
,
fd
);
s
++
;
exit
();
}
}
if
(
debug
)
break
;
printf
(
2
,
"redirect 1 to %s
\n
"
,
io
->
s
);
default:
ret
=
'a'
;
while
(
s
<
es
&&
!
strchr
(
whitespace
,
*
s
)
&&
!
strchr
(
symbols
,
*
s
))
s
++
;
break
;
break
;
}
}
}
if
(
eq
)
return
0
;
*
eq
=
s
;
while
(
s
<
es
&&
strchr
(
whitespace
,
*
s
))
s
++
;
*
ps
=
s
;
return
ret
;
}
}
// gettoken(s, 0) prepares gettoken for subsequent calls and returns 0.
void
nulterminate
(
struct
cmd
*
);
// gettoken(0, token) parses a shell token from the previously set string,
struct
cmd
*
parseline
(
char
**
,
char
*
);
// null-terminates that token, stores the token pointer in '*token',
struct
cmd
*
parsepipe
(
char
**
,
char
*
);
// and returns a token ID (0, '<', '>', '|', or 'w').
struct
cmd
*
parseredirs
(
struct
cmd
*
,
char
**
,
char
*
);
// Subsequent calls to 'gettoken(0, token)' will return subsequent
struct
cmd
*
parseblock
(
char
**
,
char
*
);
// tokens from the string.
struct
cmd
*
parseexec
(
char
**
,
char
*
);
int
struct
cmd
*
gettoken
(
char
*
s
,
char
**
p1
)
parsecmd
(
char
*
s
)
{
{
static
int
c
,
nc
;
char
*
es
;
static
char
*
np1
,
*
np2
;
struct
cmd
*
cmd
;
if
(
s
)
{
es
=
s
+
strlen
(
s
);
nc
=
_gettoken
(
s
,
&
np1
,
&
np2
);
cmd
=
parseline
(
&
s
,
es
);
return
0
;
peek
(
&
s
,
es
,
""
);
if
(
s
!=
es
){
printf
(
2
,
"leftovers: %s
\n
"
,
s
);
panic
(
"syntax"
);
}
}
c
=
nc
;
nulterminate
(
cmd
);
*
p1
=
np1
;
return
cmd
;
nc
=
_gettoken
(
np2
,
&
np1
,
&
np2
);
return
c
;
}
}
struct
cmd
*
parseline
(
char
**
ps
,
char
*
es
)
{
struct
cmd
*
cmd
;
// Get the next token from string s.
cmd
=
parsepipe
(
ps
,
es
);
// Set *p1 to the beginning of the token and *p2 just past the token.
while
(
peek
(
ps
,
es
,
"&"
)){
// Returns
gettoken
(
ps
,
es
,
0
,
0
);
// 0 for end-of-string;
cmd
=
backcmd
(
cmd
);
// < for <;
}
// > for >;
if
(
peek
(
ps
,
es
,
";"
)){
// | for |;
gettoken
(
ps
,
es
,
0
,
0
);
// w for a word.
cmd
=
listcmd
(
cmd
,
parseline
(
ps
,
es
));
//
}
// Eventually (once we parse the space where the \0 will go),
return
cmd
;
// words get nul-terminated.
}
#define WHITESPACE " \t\r\n"
#define SYMBOLS "<|>&;()"
int
struct
cmd
*
_gettoken
(
char
*
s
,
char
**
p1
,
char
**
p2
)
parsepipe
(
char
**
ps
,
char
*
es
)
{
{
int
t
;
struct
cmd
*
cmd
;
if
(
s
==
0
)
{
cmd
=
parseexec
(
ps
,
es
);
if
(
debug
>
1
)
if
(
peek
(
ps
,
es
,
"|"
)){
printf
(
2
,
"GETTOKEN 0
\n
"
);
gettoken
(
ps
,
es
,
0
,
0
);
return
0
;
cmd
=
pipecmd
(
cmd
,
parsepipe
(
ps
,
es
))
;
}
}
return
cmd
;
}
if
(
debug
>
1
)
struct
cmd
*
printf
(
2
,
"GETTOKEN: %s
\n
"
,
s
);
parseblock
(
char
**
ps
,
char
*
es
)
{
*
p1
=
0
;
struct
cmd
*
cmd
;
*
p2
=
0
;
if
(
!
peek
(
ps
,
es
,
"("
))
panic
(
"parseblock"
);
gettoken
(
ps
,
es
,
0
,
0
);
cmd
=
parseline
(
ps
,
es
);
if
(
!
peek
(
ps
,
es
,
")"
))
panic
(
"syntax - missing )"
);
gettoken
(
ps
,
es
,
0
,
0
);
cmd
=
parseredirs
(
cmd
,
ps
,
es
);
return
cmd
;
}
while
(
strchr
(
WHITESPACE
,
*
s
))
struct
cmd
*
*
s
++
=
0
;
parseredirs
(
struct
cmd
*
cmd
,
char
**
ps
,
char
*
es
)
if
(
*
s
==
0
)
{
{
if
(
debug
>
1
)
int
tok
;
printf
(
2
,
"EOL
\n
"
);
char
*
q
,
*
eq
;
return
0
;
while
(
peek
(
ps
,
es
,
"<>"
)){
tok
=
gettoken
(
ps
,
es
,
0
,
0
);
if
(
gettoken
(
ps
,
es
,
&
q
,
&
eq
)
!=
'a'
)
panic
(
"missing file for redirection"
);
switch
(
tok
){
case
'<'
:
cmd
=
redircmd
(
cmd
,
q
,
eq
,
O_RDONLY
,
0
);
break
;
case
'>'
:
cmd
=
redircmd
(
cmd
,
q
,
eq
,
O_WRONLY
|
O_CREATE
,
1
);
break
;
case
'+'
:
// >>
cmd
=
redircmd
(
cmd
,
q
,
eq
,
O_WRONLY
|
O_CREATE
,
1
);
break
;
}
}
if
(
strchr
(
SYMBOLS
,
*
s
))
{
t
=
*
s
;
*
p1
=
s
;
*
s
++
=
0
;
*
p2
=
s
;
if
(
debug
>
1
)
printf
(
2
,
"TOK %c
\n
"
,
t
);
return
t
;
}
}
*
p1
=
s
;
return
cmd
;
while
(
*
s
&&
!
strchr
(
WHITESPACE
SYMBOLS
,
*
s
))
}
s
++
;
*
p2
=
s
;
struct
cmd
*
if
(
debug
>
1
)
{
parseexec
(
char
**
ps
,
char
*
es
)
t
=
**
p2
;
{
**
p2
=
0
;
char
*
q
,
*
eq
;
printf
(
2
,
"WORD: %s
\n
"
,
*
p1
);
int
tok
,
argc
;
**
p2
=
t
;
struct
execcmd
*
cmd
;
struct
cmd
*
ret
;
if
(
peek
(
ps
,
es
,
"("
))
return
parseblock
(
ps
,
es
);
ret
=
execcmd
();
cmd
=
(
struct
execcmd
*
)
ret
;
argc
=
0
;
ret
=
parseredirs
(
ret
,
ps
,
es
);
while
(
!
peek
(
ps
,
es
,
"|)&;"
)){
if
((
tok
=
gettoken
(
ps
,
es
,
&
q
,
&
eq
))
==
0
)
break
;
if
(
tok
!=
'a'
)
panic
(
"syntax"
);
cmd
->
argv
[
argc
]
=
q
;
cmd
->
eargv
[
argc
]
=
eq
;
argc
++
;
if
(
argc
>=
MAXARGS
)
panic
(
"too many args"
);
ret
=
parseredirs
(
ret
,
ps
,
es
);
}
}
return
'w'
;
cmd
->
argv
[
argc
]
=
0
;
cmd
->
eargv
[
argc
]
=
0
;
return
ret
;
}
}
// NUL-terminate all the counted strings.
void
nulterminate
(
struct
cmd
*
cmd
)
{
int
i
;
struct
backcmd
*
bcmd
;
struct
execcmd
*
ecmd
;
struct
listcmd
*
lcmd
;
struct
pipecmd
*
pcmd
;
struct
redircmd
*
rcmd
;
if
(
cmd
==
0
)
return
;
switch
(
cmd
->
type
){
case
EXEC
:
ecmd
=
(
struct
execcmd
*
)
cmd
;
for
(
i
=
0
;
ecmd
->
argv
[
i
];
i
++
)
*
ecmd
->
eargv
[
i
]
=
0
;
break
;
case
REDIR
:
rcmd
=
(
struct
redircmd
*
)
cmd
;
nulterminate
(
rcmd
->
cmd
);
*
rcmd
->
efile
=
0
;
break
;
case
PIPE
:
pcmd
=
(
struct
pipecmd
*
)
cmd
;
nulterminate
(
pcmd
->
left
);
nulterminate
(
pcmd
->
right
);
break
;
case
LIST
:
lcmd
=
(
struct
listcmd
*
)
cmd
;
nulterminate
(
lcmd
->
left
);
nulterminate
(
lcmd
->
right
);
break
;
case
BACK
:
bcmd
=
(
struct
backcmd
*
)
cmd
;
nulterminate
(
bcmd
->
cmd
);
break
;
}
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论