on master help sign in
Merge pull request #2143 from soimort/getLine-inconsistency
f641469Edwin Brady
libs/prelude/Prelude.idr+4−2
@@ -346,7 +346,7 @@ partial
346printLn : Show a => a -> IO' ffi ()
346printLn : Show a => a -> IO' ffi ()
347printLn x = putStrLn (show x)
347printLn x = putStrLn (show x)
348
348
349−||| Read one line of input from stdin
349+||| Read one line of input from stdin, without the trailing newline
350partial
350partial
351getLine : IO' ffi String
351getLine : IO' ffi String
352getLine = prim_read
352getLine = prim_read
@@ -545,5 +545,7 @@ readFile fn = do h <- openFile fn Read
545 readFile' h contents =
545 readFile' h contents =
546 do x <- feof h
546 do x <- feof h
547 if not x then do l <- fread h
547 if not x then do l <- fread h
548+ case contents of
549+ "" => readFile' h l
548− readFile' h (contents ++ l)
550+ _ => readFile' h (contents ++ "\n" ++ l)
549 else return contents
551 else return contents
rts/idris_rts.c+5−2
@@ -504,17 +504,20 @@ VAL idris_strlen(VM* vm, VAL l) {
504}
504}
505
505
506VAL idris_readStr(VM* vm, FILE* h) {
506VAL idris_readStr(VM* vm, FILE* h) {
507+ VAL ret;
507 char *buffer = NULL;
508 char *buffer = NULL;
508 size_t n = 0;
509 size_t n = 0;
509 ssize_t len;
510 ssize_t len;
510 len = getline(&buffer, &n, h);
511 len = getline(&buffer, &n, h);
512+ strtok(buffer, "\n");
511
513
512 if (len <= 0) {
514 if (len <= 0) {
513− return MKSTR(vm, "");
515+ ret = MKSTR(vm, "");
514 } else {
516 } else {
515− return MKSTR(vm, buffer);
517+ ret = MKSTR(vm, buffer);
516 }
518 }
517 free(buffer);
519 free(buffer);
520+ return ret;
518}
521}
519
522
520VAL idris_strHead(VM* vm, VAL str) {
523VAL idris_strHead(VM* vm, VAL str) {
test/dsl002/expected−1
@@ -1,2 +1 @@
1foo
1foo
2−
test/effects001/expected+1−1
@@ -1,4 +1,4 @@
1−["HELLO!!!\n", "WORLD!!!\n", ""]
1+["HELLO!!!", "WORLD!!!", ""]
23
23
315
315
4Answer: 99
4Answer: 99
test/io001/expected+1
@@ -13,4 +13,5 @@ World!
133
133
144
144
15Last line
15Last line
16+
16---
17---
test/io001/test004.idr+1−1
@@ -13,7 +13,7 @@ dumpFile fn = do { h <- openFile fn Read
13 x <- feof h
13 x <- feof h
14 return (not x) })
14 return (not x) })
15 (do { l <- fread h
15 (do { l <- fread h
16− putStr l })
16+ putStrLn l })
17 closeFile h }
17 closeFile h }
18
18
19main : IO ()
19main : IO ()