mirror of
https://github.com/ilyakooo0/Idris-dev.git
synced 2024-11-14 03:14:14 +03:00
Merge pull request #2143 from soimort/getLine-inconsistency
Fix getLine inconsistency
This commit is contained in:
commit
f6414691de
@ -346,7 +346,7 @@ partial
|
||||
printLn : Show a => a -> IO' ffi ()
|
||||
printLn x = putStrLn (show x)
|
||||
|
||||
||| Read one line of input from stdin
|
||||
||| Read one line of input from stdin, without the trailing newline
|
||||
partial
|
||||
getLine : IO' ffi String
|
||||
getLine = prim_read
|
||||
@ -545,5 +545,7 @@ readFile fn = do h <- openFile fn Read
|
||||
readFile' h contents =
|
||||
do x <- feof h
|
||||
if not x then do l <- fread h
|
||||
readFile' h (contents ++ l)
|
||||
case contents of
|
||||
"" => readFile' h l
|
||||
_ => readFile' h (contents ++ "\n" ++ l)
|
||||
else return contents
|
||||
|
@ -504,17 +504,20 @@ VAL idris_strlen(VM* vm, VAL l) {
|
||||
}
|
||||
|
||||
VAL idris_readStr(VM* vm, FILE* h) {
|
||||
VAL ret;
|
||||
char *buffer = NULL;
|
||||
size_t n = 0;
|
||||
ssize_t len;
|
||||
len = getline(&buffer, &n, h);
|
||||
strtok(buffer, "\n");
|
||||
|
||||
if (len <= 0) {
|
||||
return MKSTR(vm, "");
|
||||
ret = MKSTR(vm, "");
|
||||
} else {
|
||||
return MKSTR(vm, buffer);
|
||||
ret = MKSTR(vm, buffer);
|
||||
}
|
||||
free(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
VAL idris_strHead(VM* vm, VAL str) {
|
||||
|
@ -1,2 +1 @@
|
||||
foo
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
["HELLO!!!\n", "WORLD!!!\n", ""]
|
||||
["HELLO!!!", "WORLD!!!", ""]
|
||||
3
|
||||
15
|
||||
Answer: 99
|
||||
|
@ -13,4 +13,5 @@ World!
|
||||
3
|
||||
4
|
||||
Last line
|
||||
|
||||
---
|
||||
|
@ -13,7 +13,7 @@ dumpFile fn = do { h <- openFile fn Read
|
||||
x <- feof h
|
||||
return (not x) })
|
||||
(do { l <- fread h
|
||||
putStr l })
|
||||
putStrLn l })
|
||||
closeFile h }
|
||||
|
||||
main : IO ()
|
||||
|
Loading…
Reference in New Issue
Block a user