Read-only archive of the All About Symbian forum (2001–2013) · About this archive

Opening UNICODE / BINARY-Files in OPL on ER6 (9210)

12 replies · 7,042 views · Started 14 January 2003

Hi!

The following example for reading in and viewing a file is listet in the. DOC-Files (Advanced Section) of Epoc Release 5 (ER5), which came with the ER6-Developer-Tool.

If I run this on the the Nokia 9210 (=ER6),
I�m getting Error-Code -134, meaning Bad Allignment.
I think that�s coming because I�m trying to open a file
which is in Unicode-Format (as most of the file under ER6)
Can someone please alter the example, so it can be run
under ER6:

Example � displaying a plain text file
This program opens a plain text file � such as one created with the Export as text option in the File menu of the Program editor � and types it to the screen. Press Esc to quit and any other key to pause the typing to the screen.

PROC ioType:
LOCAL ret%,fName$(128),txt$(255),address&
LOCAL handle%,mode%,k%
PRINT "Filename?", :INPUT fName$ : CLS
mode%=$0400 OR $0020 REM open=$0000,text=$0020,share=$0400
ret%=IOOPEN(handle%,fName$,mode%)
IF ret%<0
showErr😞ret%)
RETURN
ENDIF
address&=ADDR(txt$)
WHILE 1
k%=KEY
IF k% REM if keypress
IF k%=27 REM Esc pressed
RETURN REM otherwise wait for a key
ELSEIF GET=27
RETURN REM Esc pressed
ENDIF
ENDIF
ret%=IOREAD(handle%,address&+1,255)
IF ret%<0
IF ret%<>-36 REM NOT EOF
showErr😞ret%)
ENDIF
BREAK
ELSE
POKEB address&,ret% REM leading byte count
PRINT txt$
ENDIF
ENDWH
ret%=IOCLOSE(handle%)
IF ret%
showErr😞ret%)
ENDIF
PAUSE -100 :KEY
ENDP

PROC showErr😞val%)
PRINT "Error",val%,err$(val%)
GET
ENDP

More Infos about Unicode-File-Access can be found in the
"Crystal v6.00 OPL Porting Guide.doc", which comes with the OPL Developer-Pack for the 9210. This Document covers very important
information for all who want to programm OPL on the 9210 / ER6.

Cheers!

Luzie

I'm having a very similar problem as well. Trying to open a simple text file and I'm getting the same results.and that only when I set the mode to $0000. If I set the mode to $0420, I get ;

OPL E32USER-CBase, Reason 46 error.

Has anybody managed to read a text file in OPL? How did you do it?

[quote="Crystal v6.00 OPL Porting Guide"]
Symbian OS v6.0 introduced support for new processor types, including that of the ARM Thumb CPU. When running on this processor, OPL must store strings in a different format compared to ER5. Because of this
potential hardware change, all OPL strings now have a two-byte header instead of a single byte. However, it is important to note that they still have a 255-character limit.

This change in internal format is generally transparent and most developers can ignore this section. However, this section should be understood if you have code which makes assumptions about the string format in OPL applications - for example, if string data is read using IO commands. Previously, data would be read into a buffer one byte beyond the single byte header:

[quote=""]
pBuf&=ADDR(Buffer$)
Len%=IOREAD(Handle%, pBuf&+1, MaxBytes%) rem Note the +1 on pBuf&
...
POKE pBuf&,Len%
[/quote]

That method will no longer work as expected, because the code incorrectly assumes the string contents are one byte beyond the string header. From Symbian OS v6.0 onwards the string contents begin two bytes from the
start:

[quote=""]
CONST KOplAligment%=1
pBuf&=ADDR(Buffer$)
Len%=IOREAD(Handle%, pBuf&+1+KOplAlignment%, MaxBytes%)
...
POKE pBuf&,Len%
[/quote]

where an extra byte is added to the pointer buffer. If the alignment is incorrect, the keyword will fail with a �Bad alignment� error (error code KErrBadAlignment% = -134)

This issue is further complicated by the support for Unicode introduced in V6 of the OS. Because of this, MaxBytes% needs to be twice as large to handle the Unicode string. Developers may find using the new SIZE
keyword helpful here, as it returns the size of a string in bytes, rather than the number of characters. See the section below for more information.
To sum up, the changes to allow for both Thumb and Unicode support ean that the internal format of the string �Symbian� has changed from:

7 S y m b i a n

to

7 x S 0 y 0 m 0 b 0 i 0 a 0 n 0

where x is the indeterminate second byte in the string length header, and the 0s represent the second byte per character as required by Unicode.

OPX developers should be aware that the ARM Thumb CPU prohibits directly accessing 16-bit values that are not word boundary aligned. As OPL variables passed by reference to an OPX procedure are not uaranteed to be word-aligned, these data types must be accessed using the new OplAPI functions PutWord() and GetWord(). These are used in addition to the existing PutLong(), GetLong() and PutFloat(), GetFloat() functions.
[/quote]

RTFM then I suppose 😮ops:

Never mind, small steps in the right direction are better than no steps at all!

There's an example in the porting guide on dealing with with both ASCII and Unicode text files at the end of the current Porting Guide doc (just after the bit quoted above). Also, DemoOPL's INI file routines are a good start for writing and reading a non-text file.

Regards,

Phil

Hi. Here's a PROCedure I wrote when was faced with similar problem of reading a non-unicode file. For performance, I designed it to read file in larger chunks, so it should be faster than the example in ER6 porting guide. It assumes that the file is line-oriented (each line ending with LF), and returns the string at a line. By calling it repeatedly, you will scan through the whole file. There's some more documentation in the file itself and example of it's usage. Hope it's useful.

Regards, Jouni

OK. thanks too 😊

If I RTFM, I can see in the "Crystal v6.00 OPL Porting Guide.doc"
that different from ER5 this behaviour is INTENDED by ER6:

PRINT "Attempting to reading back from ASCII LPRINT file (in TEXT mode)..."
ret%=IOOPEN(h%,"C:\Documents\OPL_A_LPRINT.txt",$0020)
IF ret%<0
PRINT "FAILED: ";ERR$(ret%)
PRINT "NOTE: This is INTENDED behaviour in v6.0! We should use binary mode instead."

Regards to you all,
and have many fun programming in OPL!

Luzie

Dear Jouni!

Thanks lots for giving us your sample for reading in ASCII-Files.

Could you please re-write it, to open UNICODE-Files such as the *.LNK-Notice-Files under c:\system\favourites\

Regards,

Luzie

Sorry that I ask again.

But can this really be true ... NOBODY here needs to open file BINARY ?!

I just need a good and fast routine to read in files
into strings (Standard-ASCII because the above example reads in UNICODE-Files) ...

HELP 😉

Luzie

Hi!

I�m currently working on a simple OPL-program
which converts the notice-files from the communicators
c:\system\favourites\*.lnk into standard-ASCII.TXT-Files
reading them im BINARY.

SIMPLY I use the commands

IOOPEN(h%,file$,$0000)
and
RET%=IOREAD(h%,ADDR(Buffer%()),8000)

to read in up to 8000 Bytes (max possible is 16 KBytes at once)
into an Buffer-Array. From there it�s easily possible to get the Bytes with

Byte%=PEEKB(ADDR(Buffer%())

If I finish my conversion-program I�ll post it here.

Regards,

Luzie

btw. I think there�s VERY low response in this forum.
Many people want to program in OPL, but as the OPL-commands
are not that clearly documented / explained / demonstrated by Symbian
(especially for news of ER6 like UNICODE-support) I think it�s sadly a little bit to hard for real programming beginners...

Luzie,

Yes there is a lack of cuurent documentation fo ER6 OPL Commands. The honest answer here is that those who could previously do the documentation were the same people struggle to find spare tiem to polish the runtimes.

Certainly now there is an opportunity to really push forward with Tutorials, code examples, re-writing the manuals and other stuff now we have a stable 9210 runtime.

(Looks over at SwitchBlade...)

And I think that updated documentation for the commands is something that should appear soon.

OK, I just want to add a link to another tread on this forum,
where download-link to a superb OPL-introduction.PDF-File
(manual) can be found. It for Psion computers up to ER5,
but still the most will run on ER6 of the 9210 too:

http://www.allaboutsymbian.com/phpBB2/viewtopic.php?t=4354

If some of the missing ER6-Command like CvUnicode$:
are explained, all will get better, and we can get some more people
to develop in the easy-to-use-language OPL.

With the add of .OPX-File (Subroutines programmed in C),
we can even have great programming-control over the 9210
from OPL.

btw. Could you please tell me, where I can found Informations
about Symbian releasing OPL to GNU (or something like that
which i ment to read about some week ago).

Regards,

Luzie