Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Alexandru Dura
pintos-public
Commits
02df7297
Commit
02df7297
authored
Mar 27, 2021
by
Alexandru Dura
Browse files
Add a no prompt option (-n) to the shell
parent
8c0a3e01
Changes
1
Hide whitespace changes
Inline
Side-by-side
shell/sh.c
View file @
02df7297
...
...
@@ -16,7 +16,7 @@
#define MAXBUF (512)
/* max length of input line. */
#define MAX_ARG (100)
/* max number of cmd line arguments. */
typedef
enum
{
typedef
enum
{
AMPERSAND
,
/* & */
NEWLINE
,
/* end of line reached. */
NORMAL
,
/* file name or command option. */
...
...
@@ -113,19 +113,19 @@ int gettoken(char** outptr)
case
'<'
:
type
=
INPUT
;
break
;
case
'>'
:
type
=
OUTPUT
;
break
;
case
'&'
:
type
=
AMPERSAND
;
break
;
case
'|'
:
type
=
PIPE
;
type
=
PIPE
;
break
;
default:
type
=
NORMAL
;
...
...
@@ -134,7 +134,7 @@ int gettoken(char** outptr)
}
*
token
++
=
0
;
/* null-terminate the string. */
return
type
;
}
...
...
@@ -168,13 +168,13 @@ void run_program(char** argv, int argc, bool foreground, bool doing_pipe)
* is true then basically you should wait but when we are
* running a command in a pipe such as PROG1 | PROG2 you might
* not want to wait for each of PROG1 and PROG2...
*
*
* hints:
* snprintf is useful for constructing strings.
* access is useful for checking wether a path refers to an
* access is useful for checking wether a path refers to an
* executable program.
*
*
*
*
*/
}
...
...
@@ -192,7 +192,7 @@ void parse_line(void)
argc
=
0
;
for
(;;)
{
foreground
=
true
;
doing_pipe
=
false
;
...
...
@@ -206,7 +206,7 @@ void parse_line(void)
case
INPUT
:
type
=
gettoken
(
&
argv
[
argc
]);
if
(
type
!=
NORMAL
)
{
error
(
"expected file name: but found %s"
,
error
(
"expected file name: but found %s"
,
argv
[
argc
]);
return
;
}
...
...
@@ -221,7 +221,7 @@ void parse_line(void)
case
OUTPUT
:
type
=
gettoken
(
&
argv
[
argc
]);
if
(
type
!=
NORMAL
)
{
error
(
"expected file name: but found %s"
,
error
(
"expected file name: but found %s"
,
argv
[
argc
]);
return
;
}
...
...
@@ -247,7 +247,7 @@ void parse_line(void)
if
(
argc
==
0
)
return
;
argv
[
argc
]
=
NULL
;
run_program
(
argv
,
argc
,
foreground
,
doing_pipe
);
...
...
@@ -275,8 +275,8 @@ static void init_search_path(void)
path
=
getenv
(
"PATH"
);
/* path may look like "/bin:/usr/bin:/usr/local/bin"
* and this function makes a list with strings
/* path may look like "/bin:/usr/bin:/usr/local/bin"
* and this function makes a list with strings
* "/bin" "usr/bin" "usr/local/bin"
*
*/
...
...
@@ -320,7 +320,7 @@ static void init_search_path(void)
#if 0
do {
printf("%s\n", (char*)p->data);
p = p->succ;
p = p->succ;
} while (p != path_dir_list);
#endif
}
...
...
@@ -328,11 +328,15 @@ static void init_search_path(void)
/* main: main program of simple shell. */
int
main
(
int
argc
,
char
**
argv
)
{
char
*
prompt
=
(
argc
>=
2
&&
!
strncmp
(
argv
[
1
],
"-n"
,
3
))
?
""
:
"% "
;
progname
=
argv
[
0
];
init_search_path
();
init_search_path
();
while
(
fetch_line
(
"% "
)
!=
EOF
)
while
(
fetch_line
(
prompt
)
!=
EOF
)
parse_line
();
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