daihuws
Posts: 2
Joined: Thu May 01, 2014 8:04 pm

DOS, Unix and RISC OS textfiles

Thu May 01, 2014 8:39 pm

I was having a play around with the RISC OS Pico distribution earlier, and had a bit of trouble trying to open and read text files from within BASIC.

I tried to do something along these lines, as per the examples in the old BBC Micro User Guide:

Y=OPENIN "README/TXT"
INPUT#Y, A$

Unfortunately I got a type mismatch error. How would I open a text file that originally comes from DOS or Unix in BBC BASIC? I'd naively assumed that it was all ASCII text and would be interchangeable.


A related question: I tried opening some of the BASIC example programs from the Pico zipfile on my laptop (running Linux Mint), but the text was garbled; I could make out some of the BASIC instructions, but it wasn't very readable, to say the least.

Anybody know of a way of converting these files to DOS or Unix type text?

Thanks!

User avatar
Burngate
Posts: 6063
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: DOS, Unix and RISC OS textfiles

Fri May 02, 2014 10:00 am

Y=OPENIN "README/TXT"
INPUT#Y, A$
Unfortunately the INPUT# statement is expecting the data in the file to be in a particular format - not plain ASCII.
It's something along the lines of blocks consisting of header - data, with (assuming it's a string) the header containing information about the type and its length, and the data containing the ASCII
What's more, the string will be reversed!

As for the BASIC examples, unlike python, BASIC keywords are stored as tokens, which saves space and time (both at a premium when you're storing stuff on a cassette!) so they won't be readable by a standard text editor

SEDev
Posts: 34
Joined: Thu Aug 02, 2012 10:55 pm

Re: DOS, Unix and RISC OS textfiles

Fri May 02, 2014 12:14 pm

daihuws wrote:How would I open a text file that originally comes from DOS or Unix in BBC BASIC?
The INPUT# statement is for reading information that was written out using PRINT#. To read a plain text file in BBC BASIC you need to use something like this:

Code: Select all

  fh% = OPENIN "README/TXT"
  IF fh% > 0 THEN
    WHILE NOT EOF#fh%
      line$ = GET$#fh%
      REM code to process
      REM line goes here
    ENDWHILE
    CLOSE#fh%
  ENDIF
BBC BASIC assumes that text lines have a single character newline (in RISC OS it's LF). DOS text files will have CR, LF line endings so the above code would return a line as two strings, the text up to CR followed by an empty string (the LF on its own).
daihuws wrote:Anybody know of a way of converting these files to DOS or Unix type text?
The BASIC files can be converted to plain text using the BASIC command line:

Code: Select all

  LOAD "<input file>"
  TEXTSAVE "<output file>"
If you want to have some control over the output format use TEXTSAVEO instead.

Another option is to look at the files using the full RISC OS distro as RISC OS text editors will be able to display them in text form.

daihuws
Posts: 2
Joined: Thu May 01, 2014 8:04 pm

Re: DOS, Unix and RISC OS textfiles

Mon May 05, 2014 4:16 am

Ah, I see - thanks for the responses! :D

Return to “RISCOS”