Local SPOOL file.

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
User avatar
hellomike
Posts: 184
Joined: Sat 09 Jun 2018, 09:47
Location: Amsterdam

Local SPOOL file.

Post by hellomike »

Hi,

In BB4W 6.15a I try using the following code/idea:

Code: Select all

      DEF PROCprettyPrint(spoolname$)
      LOCAL !536 : REM LOCAL SPOOL channel number

      VDU 21
      OSCLI"SPOOL " + spoolname$

      <code that has PRINT statements>

      *SPOOL
      VDU 6
      ENDPROC
So the main program has a SPOOL file open and I mask its channel number in the PROC, and then make PRINT output go to a new SPOOL file.

It works but I think the editor crashed sometimes....
Can't reproduce the crash but I can imagine that, suspending main SPOOL output like this and then creating a new, local SPOOL and restoring the SPOOL channel number for the main code upon exiting the PROC, could maybe mess up the interpreter internally. I.e. buffering maybe?

All, I need to know is, if it's wise to do this trick. I.e. should it technically work?

Thanks

Mike
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: Local SPOOL file.

Post by Richard Russell »

hellomike wrote: Mon 21 Oct 2024, 15:16 All, I need to know is, if it's wise to do this trick. I.e. should it technically work?
Whether it should "technically work" I'm unsure, but it's definitely unwise.

Can you not achieve the effect you want by closing the existing spool file (*SPOOL), spooling the new file, and then resuming the original spool file with *SPOOLON? It would mean you need to know the path to the original spool file, rather than just its handle, but as it's using entirely legal commands it should be reliable.

If you're only interested in it working in Windows, there is an API function which returns the path name of a file of which you only have the handle.
User avatar
hellomike
Posts: 184
Joined: Sat 09 Jun 2018, 09:47
Location: Amsterdam

Re: Local SPOOL file.

Post by hellomike »

Thanks for the fast reply Richard.

Yes I could achieve what I want that way, or instead by writing lines in the procedure to an output file with OPENOUT / BPUT#localhandle, txt$.
The illustrated method is more transparant as by suspending the original handle, using LOCAL !536, I had hoped it would just be restored after leaving the PROC and continue with writing to the main SPOOL file.

I.e. both outside as inside the PROC they are two different handles pointing to different file(names).

What kind of info will be lost by using LOCAL !536?

Regards,

Mike
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: Local SPOOL file.

Post by Richard Russell »

hellomike wrote: Mon 21 Oct 2024, 18:56 Yes I could achieve what I want that way, or instead by writing lines in the procedure to an output file with OPENOUT / BPUT#localhandle, txt$.
Wouldn't it be closer to your original to use *OUTPUT? For example:

Code: Select all

      DEF PROCprettyPrint(spoolname$)
      LOCAL F%

      F% = OPENOUT(spoolname$)
      OSCLI "OUTPUT " + STR$F%

      REM <code that has PRINT statements>

      *OUTPUT 0
      CLOSE #F%
      ENDPROC
What kind of info will be lost by using LOCAL !536?
You said yourself that it possibly made the BB4W editor unstable, I would have thought that was quite enough reason not to use it!

Another objection is that !536 isn't the location of the *SPOOL handle in 64-bit editions of BBC BASIC.
User avatar
hellomike
Posts: 184
Joined: Sat 09 Jun 2018, 09:47
Location: Amsterdam

Re: Local SPOOL file.

Post by hellomike »

Good morning,

Actually your advise is a very elegant alternative and works like a charm.
I always forget/underestimate the *OUTPUT command.

Thanks a lot.

Mike