Re: Trouble with reading from stdin

2017-02-12 Thread cblake
I believe what you are running into is this terminal driver issue:

> [http://unix.stackexchange.com/questions/131105/how-to-read-over-4k-input-without-new-lines-on-a-terminal](http://unix.stackexchange.com/questions/131105/how-to-read-over-4k-input-without-new-lines-on-a-terminal)


Re: Trouble with reading from stdin

2017-02-12 Thread zio_tom78
I wasn't aware of this kind of limitation with standard input. Perhaps you can 
find some clues about how to fix this by having a look at the source code of 
[pv](http://www.ivarch.com/programs/pv.shtml). I often use it to process data 
read through stdin, and I have never encountered problems with large data 
files. Its source code seems very well written and easy to follow: 
[https://github.com/icetee/pv](https://github.com/icetee/pv)


Re: Trouble with reading from stdin

2017-02-11 Thread perturbation2
I think you're right - this is not a bug with Nim, but something to do with the 
buffer size for STDIN. You could try wrapping setvbuf and setting options on 
STDIN buffer size that way? maybe?

I get the same behavior with the Python script


from sys import stdin, stdout

input_eqn = stdin.read()
stdout.write(input_eqn)


giving weird results if I copy-paste directly (and working correctly if I cat 
the input from a file and pipe it to the script).


Re: Trouble with reading from stdin

2017-02-10 Thread def_pri_pub
Is it something related to stdin's default buffer size? Default is around 4096 
character IIRC.


Re: Trouble with reading from stdin

2017-02-10 Thread perturbation2
I think it's running into a problem when the line length is greater than 
BufSize - in your example above, the equation is a little > 4000 chars long, 
and 
[readAllBuffer](https://github.com/nim-lang/Nim/blob/master/lib/system/sysio.nim#L171)
 is ultimately what's called.

I don't see obvious bugs, but I'm getting weird output for a test program: 


let buf = readAll(stdin)
stdout.write(buf)


with pasting in your sample program as input when running ^^^ manually. I'll 
check again this weekend - if I can find the issue I'll make a PR, if not I"ll 
create an issue on the Github.


Re: Trouble with reading from stdin

2017-02-09 Thread def_pri_pub
When I ran a debug build, I got this stack of errors:


Traceback (most recent call last)
random_art.nim(185)  random_art
equationParser.nim(51)   parseEquation
equationParser.nim(73)   buildEquation
ModExpr.nim(72)  buildMod
equationParser.nim(75)   buildEquation
WellExpr.nim(56) buildWell
equationParser.nim(79)   buildEquation
SinExpr.nim(84)  buildSin
equationParser.nim(79)   buildEquation
SinExpr.nim(84)  buildSin
equationParser.nim(75)   buildEquation
WellExpr.nim(56) buildWell
equationParser.nim(77)   buildEquation
TentExpr.nim(57) buildTent
equationParser.nim(73)   buildEquation
ModExpr.nim(73)  buildMod
equationParser.nim(77)   buildEquation
TentExpr.nim(57) buildTent
equationParser.nim(73)   buildEquation
ModExpr.nim(73)  buildMod
equationParser.nim(71)   buildEquation
ProductExpr.nim(59)  buildProduct
equationParser.nim(83)   buildEquation
MixExpr.nim(63)  buildMix
equationParser.nim(83)   buildEquation
MixExpr.nim(64)  buildMix
equationParser.nim(79)   buildEquation
SinExpr.nim(84)  buildSin
equationParser.nim(83)   buildEquation
MixExpr.nim(63)  buildMix
equationParser.nim(69)   buildEquation
SumExpr.nim(62)  buildSum
equationParser.nim(77)   buildEquation
TentExpr.nim(57) buildTent
equationParser.nim(69)   buildEquation
SumExpr.nim(61)  buildSum
equationParser.nim(67)   buildEquation
ConstExpr.nim(88)buildConst
strutils.nim parseFloat
Error: unhandled exception: invalid float: - [ValueError]


But I need to reiterate, it only happens when I copy and paste into a terminal 
using standard input. If it's piped in, there is no error what soever and 
renders fine.


Re: Trouble with reading from stdin

2017-02-09 Thread Krux02
I don't have the crash report. In the stack trace there might be information 
that helps to solve this problem.