Getting corruption from adding key input events

4 posts / 0 new
Last post
hypex
hypex's picture
Offline
Last seen: 1 day 2 hours ago
Joined: 2011-09-09 16:20
Getting corruption from adding key input events

Hi guys.

I've noticed lately that I've been getting coruption when adding key input events. I'm using the tried and true method I've used for years without problems. That is the combo of CX and AmigaLib.

So what I'm doing is building up a string from other strings, converting it to input events and sending them out. Namely, functions like cx_lib/InvertStringRev(), which would call on InvertKeyMap(), then send it out using AddIEvents().

I've noticed the problem when the string has a new line. Ideally I want to send newlines as well. But I have noticed that newlines inside a string don't cause a newline in the output and all the text gets bunched together. And a newline on the end tends to corrupt the end of the string somehow. It's strange.

I ran my code in a debugger and it acted fine. The string I bullt looks fine to me! But gets corrupted when printed to screen. Odyssey text editor, NotePad, Shell and even FileX all show corruption.

I wondered if all the newlines needed to be converted to "\n". But upon checking InvertStringRev() it converts that to a byte code anyway. However, strings only have one 10 for LF, and the Amiga tends to use 13, 10. But I've never seen it cause corruption before. :-?

Has anyone else encountered this?

hypex
hypex's picture
Offline
Last seen: 1 day 2 hours ago
Joined: 2011-09-09 16:20
Re: Getting corruption from adding key input events

I found the issue. Some strings I was processing weren't null terminated. So I was getting a slight buffer overrun with garbage appended. Easily fixed as all string lengths were known. Though I was surprised that a string wasn't terminated.

I also solved the other issue of what codes are needed for a new line. They simply need to be CR. Any LF needs to be converted to CR to produce a new line in output. Any CR/LF double combo can be left. This makes sense as CR would code for the return key. There is an apparent discrepancy here as system string clips can have LF only, where lines are broken, despite CR/LF being the Amiga standard.

thomas
thomas's picture
Offline
Last seen: 2 days 5 hours ago
Joined: 2011-05-16 14:23
Re: Getting corruption from adding key input events

CR/LF being the Amiga standard

CR/LF is Windows / MS-DOS standard. AmigaOS always had LF only, like Unix.

For example if you use CR/LF in scripts they won't work. You'll have to end each line with a ; to make the CR a comment.

If you load a file with CR/LF into Ed you'll get an empty line inserted after each line.

hypex
hypex's picture
Offline
Last seen: 1 day 2 hours ago
Joined: 2011-09-09 16:20
Re: Getting corruption from adding key input events

@thomas

CR/LF is Windows / MS-DOS standard. AmigaOS always had LF only, like Unix.

Oops. I had that backwards. :-)

Too many CR and LF around. :-D

For example if you use CR/LF in scripts they won't work. You'll have to end each line with a ; to make the CR a comment.

I would have thought it would skip over it. Didn't know it would cancel out the LF. What about LF/CR? ;-)

If you load a file with CR/LF into Ed you'll get an empty line inserted after each line.

Double spaced. Sounds more readable than when foreign files have all the lines bunched up together. Which happens all too often.

Log in or register to post comments