repo.or.cz
/
mit-jos.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
initial commit
[mit-jos.git]
/
lib
/
readline.c
blob
7c631bdb53384cec7520f85a76be9703ca537876
1
#include <inc/stdio.h>
2
#include <inc/error.h>
3
4
#define BUFLEN 1024
5
static char
buf
[
BUFLEN
];
6
7
char
*
8
readline
(
const char
*
prompt
)
9
{
10
int
i
,
c
,
echoing
;
11
12
if
(
prompt
!=
NULL
)
13
cprintf
(
"%s"
,
prompt
);
14
15
i
=
0
;
16
echoing
=
iscons
(
0
);
17
while
(
1
) {
18
c
=
getchar
();
19
if
(
c
<
0
) {
20
cprintf
(
"read error: %e
\n
"
,
c
);
21
return
NULL
;
22
}
else if
(
c
>=
' '
&&
i
<
BUFLEN
-
1
) {
23
if
(
echoing
)
24
cputchar
(
c
);
25
buf
[
i
++] =
c
;
26
}
else if
(
c
==
'
\b
'
&&
i
>
0
) {
27
if
(
echoing
)
28
cputchar
(
c
);
29
i
--;
30
}
else if
(
c
==
'
\n
'
||
c
==
'
\r
'
) {
31
if
(
echoing
)
32
cputchar
(
c
);
33
buf
[
i
] =
0
;
34
return
buf
;
35
}
36
}
37
}
38