Merge pull request #2143 from soimort/getLine-inconsistency

Fix getLine inconsistency
This commit is contained in:
Edwin Brady 2015-04-14 20:10:50 +01:00
commit f6414691de
6 changed files with 12 additions and 7 deletions

View File

@ -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

View File

@ -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) {

View File

@ -1,2 +1 @@
foo

View File

@ -1,4 +1,4 @@
["HELLO!!!\n", "WORLD!!!\n", ""]
["HELLO!!!", "WORLD!!!", ""]
3
15
Answer: 99

View File

@ -13,4 +13,5 @@ World!
3
4
Last line
---

View File

@ -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 ()